Re: [PATCH net-next v5 2/2] page_pool: Track DMA-mapped pages and unmap them when destroying the pool

Alexander Lobakin
2025-03-31T16:35:50Z

From: Toke Høiland-Jørgensen <toke@redhat.com>
Date: Fri, 28 Mar 2025 13:19:09 +0100

> When enabling DMA mapping in page_pool, pages are kept DMA mapped until
> they are released from the pool, to avoid the overhead of re-mapping the
> pages every time they are used. This causes resource leaks and/or
> crashes when there are pages still outstanding while the device is torn
> down, because page_pool will attempt an unmap through a non-existent DMA
> device on the subsequent page return.

[...]

> @@ -173,10 +212,10 @@ struct page_pool {
> int cpuid;
> u32 pages_state_hold_cnt;
>
> - bool has_init_callback:1; /* slow::init_callback is set */
> + bool dma_sync; /* Perform DMA sync for device */

Have you seen my comment under v3 (sorry but I missed that there was v4
already)? Can't we just test the bit atomically?

> bool dma_map:1; /* Perform DMA mapping */
> - bool dma_sync:1; /* Perform DMA sync for device */
> bool dma_sync_for_cpu:1; /* Perform DMA sync for cpu */
> + bool has_init_callback:1; /* slow::init_callback is set */

Thanks,
Olek