Skip to content

Commit f0dfc4c

Browse files
rkannoth1Paolo Abeni
authored andcommitted
octeontx2-pf: Fix SQE threshold checking
Current way of checking available SQE count which is based on HW updated SQB count could result in driver submitting an SQE even before CQE for the previously transmitted SQE at the same index is processed in NAPI resulting losing SKB pointers, hence a leak. Fix this by checking a consumer index which is updated once CQE is processed. Fixes: 3ca6c4c ("octeontx2-pf: Add packet transmission support") Signed-off-by: Ratheesh Kannoth <[email protected]> Reviewed-by: Sunil Kovvuri Goutham <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent b0c09c7 commit f0dfc4c

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@ static int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16 sqb_aura)
898898
}
899899

900900
sq->head = 0;
901+
sq->cons_head = 0;
901902
sq->sqe_per_sqb = (pfvf->hw.sqb_size / sq->sqe_size) - 1;
902903
sq->num_sqbs = (qset->sqe_cnt + sq->sqe_per_sqb) / sq->sqe_per_sqb;
903904
/* Set SQE threshold to 10% of total SQEs */

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ static int otx2_tx_napi_handler(struct otx2_nic *pfvf,
441441
struct otx2_cq_queue *cq, int budget)
442442
{
443443
int tx_pkts = 0, tx_bytes = 0, qidx;
444+
struct otx2_snd_queue *sq;
444445
struct nix_cqe_tx_s *cqe;
445446
int processed_cqe = 0;
446447

@@ -451,25 +452,30 @@ static int otx2_tx_napi_handler(struct otx2_nic *pfvf,
451452
return 0;
452453

453454
process_cqe:
455+
qidx = cq->cq_idx - pfvf->hw.rx_queues;
456+
sq = &pfvf->qset.sq[qidx];
457+
454458
while (likely(processed_cqe < budget) && cq->pend_cqe) {
455459
cqe = (struct nix_cqe_tx_s *)otx2_get_next_cqe(cq);
456460
if (unlikely(!cqe)) {
457461
if (!processed_cqe)
458462
return 0;
459463
break;
460464
}
465+
461466
if (cq->cq_type == CQ_XDP) {
462-
qidx = cq->cq_idx - pfvf->hw.rx_queues;
463-
otx2_xdp_snd_pkt_handler(pfvf, &pfvf->qset.sq[qidx],
464-
cqe);
467+
otx2_xdp_snd_pkt_handler(pfvf, sq, cqe);
465468
} else {
466-
otx2_snd_pkt_handler(pfvf, cq,
467-
&pfvf->qset.sq[cq->cint_idx],
468-
cqe, budget, &tx_pkts, &tx_bytes);
469+
otx2_snd_pkt_handler(pfvf, cq, sq, cqe, budget,
470+
&tx_pkts, &tx_bytes);
469471
}
472+
470473
cqe->hdr.cqe_type = NIX_XQE_TYPE_INVALID;
471474
processed_cqe++;
472475
cq->pend_cqe--;
476+
477+
sq->cons_head++;
478+
sq->cons_head &= (sq->sqe_cnt - 1);
473479
}
474480

475481
/* Free CQEs to HW */
@@ -1072,17 +1078,17 @@ bool otx2_sq_append_skb(struct net_device *netdev, struct otx2_snd_queue *sq,
10721078
{
10731079
struct netdev_queue *txq = netdev_get_tx_queue(netdev, qidx);
10741080
struct otx2_nic *pfvf = netdev_priv(netdev);
1075-
int offset, num_segs, free_sqe;
1081+
int offset, num_segs, free_desc;
10761082
struct nix_sqe_hdr_s *sqe_hdr;
10771083

1078-
/* Check if there is room for new SQE.
1079-
* 'Num of SQBs freed to SQ's pool - SQ's Aura count'
1080-
* will give free SQE count.
1084+
/* Check if there is enough room between producer
1085+
* and consumer index.
10811086
*/
1082-
free_sqe = (sq->num_sqbs - *sq->aura_fc_addr) * sq->sqe_per_sqb;
1087+
free_desc = (sq->cons_head - sq->head - 1 + sq->sqe_cnt) & (sq->sqe_cnt - 1);
1088+
if (free_desc < sq->sqe_thresh)
1089+
return false;
10831090

1084-
if (free_sqe < sq->sqe_thresh ||
1085-
free_sqe < otx2_get_sqe_count(pfvf, skb))
1091+
if (free_desc < otx2_get_sqe_count(pfvf, skb))
10861092
return false;
10871093

10881094
num_segs = skb_shinfo(skb)->nr_frags + 1;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct sg_list {
7979
struct otx2_snd_queue {
8080
u8 aura_id;
8181
u16 head;
82+
u16 cons_head;
8283
u16 sqe_size;
8384
u32 sqe_cnt;
8485
u16 num_sqbs;

0 commit comments

Comments
 (0)