From: Yuansheng Yang <0xbeac@gmail.com>
To: Marcin Wojtas <marcin.s.wojtas@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH net] net: mvpp2: clear rxq->descs after dma_free_coherent() on init failure
Date: Sun, 6 Dec 2026 11:05:18 +0800 [thread overview]
Message-ID: <20261206030518.2273300-1-0xbeac@gmail.com> (raw)
In mvpp2_rxq_init(), if xdp_rxq_info_reg() or
xdp_rxq_info_reg_mem_model() fails after dma_alloc_coherent() has
succeeded, the err_free_dma unwind path calls dma_free_coherent() for
rxq->descs without resetting rxq->descs to NULL or rxq->descs_dma to 0.
On error return from mvpp2_rxq_init(), mvpp2_setup_rxqs() jumps to
err_cleanup and calls mvpp2_cleanup_rxqs() -> mvpp2_rxq_deinit(). Because
rxq->descs is still non-NULL on the failing queue, mvpp2_rxq_deinit()
invokes dma_free_coherent() a second time on the already-freed DMA
allocation:
DMA-API: platform mvpp2_repro: device driver tries to free DMA memory it has not allocated [size=512 bytes]
Call Trace:
check_unmap
debug_dma_free_coherent
dma_free_attrs
mvpp2_cleanup_rxqs
mvpp2_setup_rxqs
Clear rxq->descs and rxq->descs_dma after freeing them on the error path
of mvpp2_rxq_init() so subsequent cleanup in mvpp2_rxq_deinit() skips the
already-freed descriptor ring.
Fixes: b27db2274ba8 ("mvpp2: use page_pool allocator")
Cc: stable@vger.kernel.org
Signed-off-by: Yuansheng Yang <0xbeac@gmail.com>
---
Compiled drivers/net/ethernet/marvell/mvpp2/mvpp2_main.o with W=1 on
x86_64 (0 warnings, 0 errors) and verified on v7.4-rc5 in an x86_64
KASAN + DMA-API debug QEMU guest via mvpp2_setup_rxqs() failing XDP
memory model registration followed by mvpp2_cleanup_rxqs(): before this
fix, DMA-API reports freeing unallocated DMA memory in
mvpp2_cleanup_rxqs(); after this fix, 10/10 iterations unwind cleanly
with rxq->descs == NULL and 0 DMA-API, KASAN, BUG, or WARNING
diagnostics.
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 35adcee9a..1dfefd355 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -3021,6 +3021,8 @@ static int mvpp2_rxq_init(struct mvpp2_port *port,
dma_free_coherent(port->dev->dev.parent,
rxq->size * MVPP2_DESC_ALIGNED_SIZE,
rxq->descs, rxq->descs_dma);
+ rxq->descs = NULL;
+ rxq->descs_dma = 0;
return err;
}
--
2.53.0
next reply other threads:[~2026-12-06 3:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 3:05 Yuansheng Yang [this message]
2026-12-06 3:08 ` [PATCH net] net: mvpp2: clear rxq->descs after dma_free_coherent() on init failure netdev-bot+sinfo
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=20261206030518.2273300-1-0xbeac@gmail.com \
--to=0xbeac@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=marcin.s.wojtas@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
/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