From: "lorenzo@kernel.org" <lorenzo@kernel.org>
To: "Sujuan Chen (陈素娟)" <Sujuan.Chen@mediatek.com>
Cc: "Bo Jiao (焦波)" <Bo.Jiao@mediatek.com>,
"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
"Shayne Chen (陳軒丞)" <Shayne.Chen@mediatek.com>,
"nbd@nbd.name" <nbd@nbd.name>,
"Evelyn Tsai (蔡珊鈺)" <Evelyn.Tsai@mediatek.com>,
"Ryder Lee" <Ryder.Lee@mediatek.com>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>
Subject: Re: [PATCH v2] wifi: mt76: fix potential memory leakage
Date: Wed, 21 Dec 2022 11:26:21 +0100 [thread overview]
Message-ID: <Y6LfTUoSZ8W/gJ0Y@lore-desk> (raw)
In-Reply-To: <9d8aa92e3650128c94af91435a222c00ff2acb1c.camel@mediatek.com>
[-- Attachment #1: Type: text/plain, Size: 2733 bytes --]
[...]
> Hi Lore,
Hi Sujuan,
>
> we love your patch, but we have another patch to avoid memory
> fragmentation by duplicating the rx skb after mt76_dma_dequeue(). it
> requires mt76_get_rxwi() be placed before page_frag_alloc().
>
> the below patch(need rebase) will be sent after the current patch is
> accepted.
>
> --- a/drivers/net/wireless/mediatek/mt76/dma.c
> +++ b/drivers/net/wireless/mediatek/mt76/dma.c
> @@ -386,9 +386,11 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct
> mt76_queue *q, int idx,
> SKB_WITH_OVERHEAD(q->buf_size),
> DMA_FROM_DEVICE);
>
> - buf = t->ptr;
> + buf = page_frag_alloc(&q->rx_page, q->buf_size,
> GFP_ATOMIC);
> + if (!buf)
> + return NULL;
> + memcpy(buf, t->ptr, SKB_WITH_OVERHEAD(q->buf_size));
We this approach we still need to allocate the buffer (in mt76_dma_get_buf()
instead of mt76_dma_rx_fill()) but we need even to copy the full buffer that
can be pretty expensive instead of relying on the DMA, so I would avoid this
approach.
Regards,
Lorenzo
> t->dma_addr = 0;
> - t->ptr = NULL;
>
> mt76_put_rxwi(dev, t);
>
> @@ -569,6 +571,7 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct
> mt76_queue *q)
> while (q->queued < q->ndesc - 1) {
> struct mt76_txwi_cache *t = NULL;
> struct mt76_queue_buf qbuf;
> + bool skip_alloc = false;
> void *buf = NULL;
>
> if ((q->flags & MT_QFLAG_WED) &&
> @@ -576,11 +579,19 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct
> mt76_queue *q)
> t = mt76_get_rxwi(dev);
> if (!t)
> break;
> +
> + if (t->ptr) {
> + skip_alloc = true;
> + buf = t->ptr;
> + }
> }
>
> - buf = page_frag_alloc(&q->rx_page, q->buf_size,
> GFP_ATOMIC);
> - if (!buf)
> - break;
> + if (!skip_alloc) {
> + buf = page_frag_alloc(&q->rx_page, q->buf_size,
> + GFP_ATOMIC);
> + if (!buf)
> + break;
> + }
>
> addr = dma_map_single(dev->dma_dev, buf, len,
> DMA_FROM_DEVICE);
> if (unlikely(dma_mapping_error(dev->dma_dev, addr))) {
> --
> 2.18.0
>
> > > --
> > > 2.18.0
> > >
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2022-12-21 10:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-19 4:48 [PATCH v2] wifi: mt76: fix potential memory leakage Bo Jiao
2022-12-19 9:55 ` Lorenzo Bianconi
2022-12-20 4:42 ` Sujuan Chen (陈素娟)
2022-12-21 10:26 ` lorenzo [this message]
2022-12-21 14:48 ` Sujuan Chen (陈素娟)
2022-12-21 15:12 ` Felix Fietkau
2022-12-21 18:02 ` Lorenzo Bianconi
2022-12-22 8:51 ` Sujuan Chen (陈素娟)
2022-12-22 9:44 ` lorenzo
2022-12-22 14:01 ` Sujuan Chen (陈素娟)
2022-12-22 14:26 ` lorenzo
2022-12-22 23:57 ` lorenzo
2023-01-06 4:04 ` Sujuan Chen (陈素娟)
2023-01-03 1:55 ` Sujuan Chen (陈素娟)
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=Y6LfTUoSZ8W/gJ0Y@lore-desk \
--to=lorenzo@kernel.org \
--cc=Bo.Jiao@mediatek.com \
--cc=Evelyn.Tsai@mediatek.com \
--cc=Ryder.Lee@mediatek.com \
--cc=Shayne.Chen@mediatek.com \
--cc=Sujuan.Chen@mediatek.com \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=nbd@nbd.name \
/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