Skip to content

Commit 5db8432

Browse files
rogerqkuba-moo
authored andcommitted
net: ethernet: ti: am65-cpsw: fix memleak in certain XDP cases
If the XDP program doesn't result in XDP_PASS then we leak the memory allocated by am65_cpsw_build_skb(). It is pointless to allocate SKB memory before running the XDP program as we would be wasting CPU cycles for cases other than XDP_PASS. Move the SKB allocation after evaluating the XDP program result. This fixes the memleak. A performance boost is seen for XDP_DROP test. XDP_DROP test: Before: 460256 rx/s 0 err/s After: 784130 rx/s 0 err/s Fixes: 8acacc4 ("net: ethernet: ti: am65-cpsw: Add minimal XDP support") Signed-off-by: Roger Quadros <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent b698b9a commit 5db8432

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

drivers/net/ethernet/ti/am65-cpsw-nuss.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,8 @@ static void am65_cpsw_nuss_tx_cleanup(void *data, dma_addr_t desc_dma)
842842

843843
static struct sk_buff *am65_cpsw_build_skb(void *page_addr,
844844
struct net_device *ndev,
845-
unsigned int len)
845+
unsigned int len,
846+
unsigned int headroom)
846847
{
847848
struct sk_buff *skb;
848849

@@ -852,7 +853,7 @@ static struct sk_buff *am65_cpsw_build_skb(void *page_addr,
852853
if (unlikely(!skb))
853854
return NULL;
854855

855-
skb_reserve(skb, AM65_CPSW_HEADROOM);
856+
skb_reserve(skb, headroom);
856857
skb->dev = ndev;
857858

858859
return skb;
@@ -1315,16 +1316,8 @@ static int am65_cpsw_nuss_rx_packets(struct am65_cpsw_rx_flow *flow,
13151316
dev_dbg(dev, "%s rx csum_info:%#x\n", __func__, csum_info);
13161317

13171318
dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE);
1318-
13191319
k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
13201320

1321-
skb = am65_cpsw_build_skb(page_addr, ndev,
1322-
AM65_CPSW_MAX_PACKET_SIZE);
1323-
if (unlikely(!skb)) {
1324-
new_page = page;
1325-
goto requeue;
1326-
}
1327-
13281321
if (port->xdp_prog) {
13291322
xdp_init_buff(&xdp, PAGE_SIZE, &port->xdp_rxq[flow->id]);
13301323
xdp_prepare_buff(&xdp, page_addr, AM65_CPSW_HEADROOM,
@@ -1334,9 +1327,16 @@ static int am65_cpsw_nuss_rx_packets(struct am65_cpsw_rx_flow *flow,
13341327
if (*xdp_state != AM65_CPSW_XDP_PASS)
13351328
goto allocate;
13361329

1337-
/* Compute additional headroom to be reserved */
1338-
headroom = (xdp.data - xdp.data_hard_start) - skb_headroom(skb);
1339-
skb_reserve(skb, headroom);
1330+
headroom = xdp.data - xdp.data_hard_start;
1331+
} else {
1332+
headroom = AM65_CPSW_HEADROOM;
1333+
}
1334+
1335+
skb = am65_cpsw_build_skb(page_addr, ndev,
1336+
AM65_CPSW_MAX_PACKET_SIZE, headroom);
1337+
if (unlikely(!skb)) {
1338+
new_page = page;
1339+
goto requeue;
13401340
}
13411341

13421342
ndev_priv = netdev_priv(ndev);

0 commit comments

Comments
 (0)