Patch "xsk: always clear DMA mapping information when unmapping the pool" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    xsk: always clear DMA mapping information when unmapping the pool

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     xsk-always-clear-dma-mapping-information-when-unmapp.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 44a7eb700bc8cd9c1c6dfb0388e0692a925bdda8
Author: Larysa Zaremba <larysa.zaremba@xxxxxxxxx>
Date:   Fri Nov 22 12:29:09 2024 +0100

    xsk: always clear DMA mapping information when unmapping the pool
    
    [ Upstream commit ac9a48a6f1610b094072b815e884e1668aea4401 ]
    
    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@xxxxxxxxxxx>
    Closes: https://lore.kernel.org/PA4P194MB10056F208AF221D043F57A3D86512@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    Acked-by: Maciej Fijalkowski <maciej.fijalkowski@xxxxxxxxx>
    Signed-off-by: Larysa Zaremba <larysa.zaremba@xxxxxxxxx>
    Link: https://lore.kernel.org/r/20241122112912.89881-1-larysa.zaremba@xxxxxxxxx
    Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index ed6c71826d31f..3321ca7eb76c2 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -356,10 +356,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_cnt = 0;
 	pool->dev = NULL;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux