Skip to content

Commit 7843c60

Browse files
josh8551021ferruhy
authored andcommitted
net/gve: fix mbuf allocation memory leak for DQ Rx
Currently, gve_rxq_mbufs_alloc_dqo() allocates RING_SIZE buffers, but only posts RING_SIZE - 1 of them, inevitably leaking a buffer every time queues are stopped/started. This could eventually lead to running out of mbufs if an application stops/starts traffic enough. Fixes: b044845 ("net/gve: support queue start/stop") Cc: [email protected] Signed-off-by: Joshua Washington <[email protected]> Reviewed-by: Rushil Gupta <[email protected]> Reviewed-by: Praveen Kaligineedi <[email protected]>
1 parent 0107bd5 commit 7843c60

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@ Prashant Bhole <[email protected]>
11741174
Prashant Upadhyaya <[email protected]> <[email protected]>
11751175
Prateek Agarwal <[email protected]>
11761176
Prathisna Padmasanan <[email protected]>
1177+
Praveen Kaligineedi <[email protected]>
11771178
Praveen Shetty <[email protected]>
11781179
Pravin Pathak <[email protected]>
11791180
Prince Takkar <[email protected]>

drivers/net/gve/gve_rx_dqo.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,34 +395,36 @@ static int
395395
gve_rxq_mbufs_alloc_dqo(struct gve_rx_queue *rxq)
396396
{
397397
struct rte_mbuf *nmb;
398+
uint16_t rx_mask;
398399
uint16_t i;
399400
int diag;
400401

401-
diag = rte_pktmbuf_alloc_bulk(rxq->mpool, &rxq->sw_ring[0], rxq->nb_rx_desc);
402+
rx_mask = rxq->nb_rx_desc - 1;
403+
diag = rte_pktmbuf_alloc_bulk(rxq->mpool, &rxq->sw_ring[0],
404+
rx_mask);
402405
if (diag < 0) {
403406
rxq->stats.no_mbufs_bulk++;
404-
for (i = 0; i < rxq->nb_rx_desc - 1; i++) {
407+
for (i = 0; i < rx_mask; i++) {
405408
nmb = rte_pktmbuf_alloc(rxq->mpool);
406409
if (!nmb)
407410
break;
408411
rxq->sw_ring[i] = nmb;
409412
}
410413
if (i < rxq->nb_rx_desc - 1) {
411-
rxq->stats.no_mbufs += rxq->nb_rx_desc - 1 - i;
414+
rxq->stats.no_mbufs += rx_mask - i;
412415
return -ENOMEM;
413416
}
414417
}
415418

416-
for (i = 0; i < rxq->nb_rx_desc; i++) {
417-
if (i == rxq->nb_rx_desc - 1)
418-
break;
419+
for (i = 0; i < rx_mask; i++) {
419420
nmb = rxq->sw_ring[i];
420421
rxq->rx_ring[i].buf_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
421422
rxq->rx_ring[i].buf_id = rte_cpu_to_le_16(i);
422423
}
424+
rxq->rx_ring[rx_mask].buf_id = rte_cpu_to_le_16(rx_mask);
423425

424426
rxq->nb_rx_hold = 0;
425-
rxq->bufq_tail = rxq->nb_rx_desc - 1;
427+
rxq->bufq_tail = rx_mask;
426428

427429
rte_write32(rxq->bufq_tail, rxq->qrx_tail);
428430

0 commit comments

Comments
 (0)