From: Daniel Golle <daniel@makrotopia.org>
To: Elad Yifee <eladwf@gmail.com>
Cc: Felix Fietkau <nbd@nbd.name>, Sean Wang <sean.wang@mediatek.com>,
Mark Lee <Mark-MC.Lee@mediatek.com>,
Lorenzo Bianconi <lorenzo@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Chen Lin <chen45464546@163.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: Re: [PATCH net v2] net: ethernet: mtk_eth_soc: fix memory leak in LRO rings release
Date: Mon, 12 Aug 2024 16:32:34 +0100 [thread overview]
Message-ID: <ZrorEoWOoe8inWcx@makrotopia.org> (raw)
In-Reply-To: <20240812152126.14598-1-eladwf@gmail.com>
On Mon, Aug 12, 2024 at 06:21:19PM +0300, Elad Yifee wrote:
> For LRO we allocate more than one page, yet 'skb_free_frag' is used
> to free the buffer, which only frees a single page.
> Fix it by using 'free_pages' instead.
>
> Fixes: 2f2c0d2919a1 ("net: ethernet: mtk_eth_soc: fix misuse of mem alloc interface netdev[napi]_alloc_frag")
> Signed-off-by: Elad Yifee <eladwf@gmail.com>
> ---
> v2: fixed compilation warnings
> ---
> drivers/net/ethernet/mediatek/mtk_eth_soc.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 16ca427cf4c3..e25b552d70f7 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -1762,8 +1762,10 @@ static void mtk_rx_put_buff(struct mtk_rx_ring *ring, void *data, bool napi)
> if (ring->page_pool)
> page_pool_put_full_page(ring->page_pool,
> virt_to_head_page(data), napi);
> - else
> + else if (ring->frag_size <= PAGE_SIZE)
> skb_free_frag(data);
> + else
> + free_pages(unsigned long)data, get_order(mtk_max_frag_size(ring->frag_size)));
You miss on open '(' there. Won't even compile like that.
Please always compile- and run-time test patches before sending them
to the mailing list.
> }
>
> static int mtk_xdp_frame_map(struct mtk_eth *eth, struct net_device *dev,
> @@ -2132,7 +2134,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
> ring->buf_size, DMA_FROM_DEVICE);
> if (unlikely(dma_mapping_error(eth->dma_dev,
> dma_addr))) {
> - skb_free_frag(new_data);
> + mtk_rx_put_buff(ring, new_data, true);
> netdev->stats.rx_dropped++;
> goto release_desc;
> }
> @@ -2146,7 +2148,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
> skb = build_skb(data, ring->frag_size);
> if (unlikely(!skb)) {
> netdev->stats.rx_dropped++;
> - skb_free_frag(data);
> + mtk_rx_put_buff(ring, data, true);
> goto skip_rx;
> }
>
> @@ -2691,7 +2693,7 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
> ring->buf_size, DMA_FROM_DEVICE);
> if (unlikely(dma_mapping_error(eth->dma_dev,
> dma_addr))) {
> - skb_free_frag(data);
> + mtk_rx_put_buff(ring, data, false);
> return -ENOMEM;
> }
> }
> --
> 2.45.2
>
next prev parent reply other threads:[~2024-08-12 15:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-12 15:21 [PATCH net v2] net: ethernet: mtk_eth_soc: fix memory leak in LRO rings release Elad Yifee
2024-08-12 15:32 ` Daniel Golle [this message]
2024-08-12 15:34 ` Felix Fietkau
2024-08-12 16:32 ` Elad Yifee
2024-08-13 19:05 ` kernel test robot
2024-08-13 20:56 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZrorEoWOoe8inWcx@makrotopia.org \
--to=daniel@makrotopia.org \
--cc=Mark-MC.Lee@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=chen45464546@163.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eladwf@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=lorenzo@kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=nbd@nbd.name \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sean.wang@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).