* [PATCH bpf] xsk: always clear DMA mapping information when unmapping the pool
@ 2024-11-22 11:29 Larysa Zaremba
2024-11-25 22:30 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Larysa Zaremba @ 2024-11-22 11:29 UTC (permalink / raw)
To: bpf
Cc: Larysa Zaremba, Björn Töpel, Magnus Karlsson,
Maciej Fijalkowski, Jonathan Lemon, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Simon Horman,
Przemek Kitszel, Jacob Keller, netdev, linux-kernel,
Alasdair McWilliam
When the umem is shared, the DMA mapping is also shared between the xsk
pools, therefore it should stay valid as long as at least 1 user remains.
However, the pool also keeps the copies of DMA-related information that are
initialized in the same way in xp_init_dma_info(), but cleared by
xp_dma_unmap() only for the last remaining pool, this causes the problems
below.
The first one is that the commit adbf5a42341f ("ice: remove af_xdp_zc_qps
bitmap") relies on pool->dev to determine the presence of a ZC pool on a
given queue, avoiding internal bookkeeping. This works perfectly fine if
the UMEM is not shared, but reliably fails otherwise as stated in the
linked report.
The second one is pool->dma_pages which is dynamically allocated and
only freed in xp_dma_unmap(), this leads to a small memory leak. kmemleak
does not catch it, but by printing the allocation results after terminating
the userspace program it is possible to see that all addresses except the
one belonging to the last detached pool are still accessible through the
kmemleak dump functionality.
Always clear the DMA mapping information from the pool and free
pool->dma_pages when unmapping the pool, so that the only difference
between results of the last remaining user's call and the ones before would
be the destruction of the DMA mapping.
Fixes: adbf5a42341f ("ice: remove af_xdp_zc_qps bitmap")
Fixes: 921b68692abb ("xsk: Enable sharing of dma mappings")
Reported-by: Alasdair McWilliam <alasdair.mcwilliam@outlook.com>
Closes: https://lore.kernel.org/PA4P194MB10056F208AF221D043F57A3D86512@PA4P194MB1005.EURP194.PROD.OUTLOOK.COM
Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
---
net/xdp/xsk_buff_pool.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index 521a2938e50a..0662d34b09ee 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -387,10 +387,9 @@ void xp_dma_unmap(struct xsk_buff_pool *pool, unsigned long attrs)
return;
}
- if (!refcount_dec_and_test(&dma_map->users))
- return;
+ if (refcount_dec_and_test(&dma_map->users))
+ __xp_dma_unmap(dma_map, attrs);
- __xp_dma_unmap(dma_map, attrs);
kvfree(pool->dma_pages);
pool->dma_pages = NULL;
pool->dma_pages_cnt = 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH bpf] xsk: always clear DMA mapping information when unmapping the pool
2024-11-22 11:29 [PATCH bpf] xsk: always clear DMA mapping information when unmapping the pool Larysa Zaremba
@ 2024-11-25 22:30 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-11-25 22:30 UTC (permalink / raw)
To: Larysa Zaremba
Cc: bpf, bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon,
davem, edumazet, kuba, pabeni, ast, daniel, hawk, john.fastabend,
horms, przemyslaw.kitszel, jacob.e.keller, netdev, linux-kernel,
alasdair.mcwilliam
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Fri, 22 Nov 2024 12:29:09 +0100 you wrote:
> When the umem is shared, the DMA mapping is also shared between the xsk
> pools, therefore it should stay valid as long as at least 1 user remains.
> However, the pool also keeps the copies of DMA-related information that are
> initialized in the same way in xp_init_dma_info(), but cleared by
> xp_dma_unmap() only for the last remaining pool, this causes the problems
> below.
>
> [...]
Here is the summary with links:
- [bpf] xsk: always clear DMA mapping information when unmapping the pool
https://git.kernel.org/bpf/bpf/c/ac9a48a6f161
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-11-25 22:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-22 11:29 [PATCH bpf] xsk: always clear DMA mapping information when unmapping the pool Larysa Zaremba
2024-11-25 22:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox