* [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool
@ 2025-03-07 9:23 Yunsheng Lin
2025-03-07 9:23 ` [PATCH net-next v11 1/4] page_pool: introduce page_pool_get_pp() API Yunsheng Lin
2025-03-07 14:15 ` [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool Toke Høiland-Jørgensen
0 siblings, 2 replies; 6+ messages in thread
From: Yunsheng Lin @ 2025-03-07 9:23 UTC (permalink / raw)
To: davem, kuba, pabeni
Cc: zhangkun09, liuyonglong, fanghaiqing, Yunsheng Lin,
Alexander Lobakin, Robin Murphy, Alexander Duyck, Andrew Morton,
Gaurav Batra, Matthew Rosato, IOMMU, MM, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Matthias Brugger, AngeloGioacchino Del Regno, netdev,
intel-wired-lan, bpf, linux-kernel, linux-arm-kernel,
linux-mediatek
This patchset fix the dma API misuse problem as below:
Networking driver with page_pool support may hand over page
still with dma mapping to network stack and try to reuse that
page after network stack is done with it and passes it back
to page_pool to avoid the penalty of dma mapping/unmapping.
With all the caching in the network stack, some pages may be
held in the network stack without returning to the page_pool
soon enough, and with VF disable causing the driver unbound,
the page_pool does not stop the driver from doing it's
unbounding work, instead page_pool uses workqueue to check
if there is some pages coming back from the network stack
periodically, if there is any, it will do the dma unmmapping
related cleanup work.
As mentioned in [1], attempting DMA unmaps after the driver
has already unbound may leak resources or at worst corrupt
memory. Fundamentally, the page pool code cannot allow DMA
mappings to outlive the driver they belong to.
By using the 'struct page_pool_item' referenced by page->pp_item,
page_pool is not only able to keep track of the inflight page to
do dma unmmaping if some pages are still handled in networking
stack when page_pool_destroy() is called, and networking stack is
also able to find the page_pool owning the page when returning
pages back into page_pool:
1. When a page is added to the page_pool, an item is deleted from
pool->hold_items and set the 'pp_netmem' pointing to that page
and set item->state and item->pp_netmem accordingly in order to
keep track of that page, refill from pool->release_items when
pool->hold_items is empty or use the item from pool->slow_items
when fast items run out.
2. When a page is released from the page_pool, it is able to tell
which page_pool this page belongs to by masking off the lower
bits of the pointer to page_pool_item *item, as the 'struct
page_pool_item_block' is stored in the top of a struct page.
And after clearing the pp_item->state', the item for the
released page is added back to pool->release_items so that it
can be reused for new pages or just free it when it is from the
pool->slow_items.
3. When page_pool_destroy() is called, item->state is used to tell
if a specific item is being used/dma mapped or not by scanning
all the item blocks in pool->item_blocks, then item->netmem can
be used to do the dma unmmaping if the corresponding inflight
page is dma mapped.
From the below performance data, the overhead is not so obvious
due to performance variations in arm64 server and less than 1
ns in x86 server for time_bench_page_pool01_fast_path() and
time_bench_page_pool02_ptr_ring, and there is about 10~20ns
overhead for time_bench_page_pool03_slow(), see more detail in
[2].
arm64 server:
Before this patchset:
fast_path ptr_ring slow
1. 31.171 ns 60.980 ns 164.917 ns
2. 28.824 ns 60.891 ns 170.241 ns
3. 14.236 ns 60.583 ns 164.355 ns
With patchset:
6. 26.163 ns 53.781 ns 189.450 ns
7. 26.189 ns 53.798 ns 189.466 ns
X86 server:
| Test name |Cycles | 1-5 | | Nanosec | 1-5 | | % |
| (tasklet_*)|Before | After |diff| Before | After | diff | change |
|------------+-------+-------+----+---------+--------+--------+--------|
| fast_path | 19 | 19 | 0| 5.399 | 5.492 | 0.093 | 1.7 |
| ptr_ring | 54 | 57 | 3| 15.090 | 15.849 | 0.759 | 5.0 |
| slow | 238 | 284 | 46| 66.134 | 78.909 | 12.775 | 19.3 |
And about 16 bytes of memory is also needed for each page_pool owned
page to fix the dma API misuse problem
1. https://lore.kernel.org/lkml/8067f204-1380-4d37-8ffd-007fc6f26738@kernel.org/T/
2. https://lore.kernel.org/all/f558df7a-d983-4fc5-8358-faf251994d23@kernel.org/
CC: Alexander Lobakin <aleksander.lobakin@intel.com>
CC: Robin Murphy <robin.murphy@arm.com>
CC: Alexander Duyck <alexander.duyck@gmail.com>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Gaurav Batra <gbatra@linux.ibm.com>
CC: Matthew Rosato <mjrosato@linux.ibm.com>
CC: IOMMU <iommu@lists.linux.dev>
CC: MM <linux-mm@kvack.org>
Change log:
V11:
1. Rebase on the latest net-next.
2. Fix two compiler errors reported by Jakub and Simon.
3. Change to use __acquire() and __release() to avoid 'context
imbalance' warning.
V10:
1. Add nl API to dump item memory usage.
2. Use __acquires() and __releases() to avoid 'context imbalance'
warning.
V9.
1. Drop the fix of a possible time window problem for NPAI recycling.
2. Add design description for the fix in patch 2.
V8:
1. Drop last 3 patch as it causes observable performance degradation
for x86 system.
2. Remove rcu read lock in page_pool_napi_local().
3. Renaming item function more consistently.
V7:
1. Fix a used-after-free bug reported by KASAN as mentioned by Jakub.
2. Fix the 'netmem' variable not setting up correctly bug as mentioned
by Simon.
V6:
1. Repost based on latest net-next.
2. Rename page_pool_to_pp() to page_pool_get_pp().
V5:
1. Support unlimit inflight pages.
2. Add some optimization to avoid the overhead of fixing bug.
V4:
1. use scanning to do the unmapping
2. spilt dma sync skipping into separate patch
V3:
1. Target net-next tree instead of net tree.
2. Narrow the rcu lock as the discussion in v2.
3. Check the ummapping cnt against the inflight cnt.
V2:
1. Add a item_full stat.
2. Use container_of() for page_pool_to_pp().
Yunsheng Lin (4):
page_pool: introduce page_pool_get_pp() API
page_pool: fix IOMMU crash when driver has already unbound
page_pool: support unlimited number of inflight pages
page_pool: skip dma sync operation for inflight pages
Documentation/netlink/specs/netdev.yaml | 16 +
drivers/net/ethernet/freescale/fec_main.c | 8 +-
.../ethernet/google/gve/gve_buffer_mgmt_dqo.c | 2 +-
drivers/net/ethernet/intel/iavf/iavf_txrx.c | 6 +-
drivers/net/ethernet/intel/idpf/idpf_txrx.c | 14 +-
drivers/net/ethernet/intel/libeth/rx.c | 2 +-
.../marvell/octeontx2/nic/otx2_txrx.c | 2 +-
.../net/ethernet/mellanox/mlx5/core/en/xdp.c | 3 +-
drivers/net/netdevsim/netdev.c | 6 +-
drivers/net/wireless/mediatek/mt76/mt76.h | 2 +-
include/linux/mm_types.h | 2 +-
include/linux/skbuff.h | 1 +
include/net/libeth/rx.h | 3 +-
include/net/netmem.h | 31 +-
include/net/page_pool/helpers.h | 15 +
include/net/page_pool/memory_provider.h | 2 +-
include/net/page_pool/types.h | 46 +-
include/uapi/linux/netdev.h | 2 +
net/core/devmem.c | 6 +-
net/core/netmem_priv.h | 5 +-
net/core/page_pool.c | 426 ++++++++++++++++--
net/core/page_pool_priv.h | 12 +-
net/core/page_pool_user.c | 39 +-
tools/include/uapi/linux/netdev.h | 2 +
tools/net/ynl/samples/page-pool.c | 11 +
25 files changed, 576 insertions(+), 88 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH net-next v11 1/4] page_pool: introduce page_pool_get_pp() API 2025-03-07 9:23 [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool Yunsheng Lin @ 2025-03-07 9:23 ` Yunsheng Lin 2025-03-07 14:15 ` [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool Toke Høiland-Jørgensen 1 sibling, 0 replies; 6+ messages in thread From: Yunsheng Lin @ 2025-03-07 9:23 UTC (permalink / raw) To: davem, kuba, pabeni Cc: zhangkun09, liuyonglong, fanghaiqing, Yunsheng Lin, Wei Fang, Shenwei Wang, Clark Wang, Andrew Lunn, Eric Dumazet, Jeroen de Borst, Harshitha Ramamurthy, Tony Nguyen, Przemek Kitszel, Alexander Lobakin, Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Felix Fietkau, Lorenzo Bianconi, Ryder Lee, Shayne Chen, Sean Wang, Johannes Berg, Matthias Brugger, AngeloGioacchino Del Regno, Simon Horman, Ilias Apalodimas, imx, netdev, linux-kernel, intel-wired-lan, bpf, linux-rdma, linux-wireless, linux-arm-kernel, linux-mediatek Introduce page_pool_get_pp() API to avoid caller accessing page->pp directly, in order to make the following patch more reviewable as the following patch will change page->pp to page->pp_item to fix the DMA API misuse problem. Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com> --- drivers/net/ethernet/freescale/fec_main.c | 8 +++++--- .../net/ethernet/google/gve/gve_buffer_mgmt_dqo.c | 2 +- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 6 ++++-- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 14 +++++++++----- drivers/net/ethernet/intel/libeth/rx.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 3 ++- drivers/net/netdevsim/netdev.c | 6 ++++-- drivers/net/wireless/mediatek/mt76/mt76.h | 2 +- include/net/libeth/rx.h | 3 ++- include/net/page_pool/helpers.h | 5 +++++ 10 files changed, 34 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index a86cfebedaa8..4ade1553557a 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -1038,7 +1038,8 @@ static void fec_enet_bd_init(struct net_device *dev) struct page *page = txq->tx_buf[i].buf_p; if (page) - page_pool_put_page(page->pp, page, 0, false); + page_pool_put_page(page_pool_get_pp(page), + page, 0, false); } txq->tx_buf[i].buf_p = NULL; @@ -1576,7 +1577,7 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget) xdp_return_frame_rx_napi(xdpf); } else { /* recycle pages of XDP_TX frames */ /* The dma_sync_size = 0 as XDP_TX has already synced DMA for_device */ - page_pool_put_page(page->pp, page, 0, true); + page_pool_put_page(page_pool_get_pp(page), page, 0, true); } txq->tx_buf[index].buf_p = NULL; @@ -3343,7 +3344,8 @@ static void fec_enet_free_buffers(struct net_device *ndev) } else { struct page *page = txq->tx_buf[i].buf_p; - page_pool_put_page(page->pp, page, 0, false); + page_pool_put_page(page_pool_get_pp(page), + page, 0, false); } txq->tx_buf[i].buf_p = NULL; diff --git a/drivers/net/ethernet/google/gve/gve_buffer_mgmt_dqo.c b/drivers/net/ethernet/google/gve/gve_buffer_mgmt_dqo.c index 403f0f335ba6..87422b8828ff 100644 --- a/drivers/net/ethernet/google/gve/gve_buffer_mgmt_dqo.c +++ b/drivers/net/ethernet/google/gve/gve_buffer_mgmt_dqo.c @@ -210,7 +210,7 @@ void gve_free_to_page_pool(struct gve_rx_ring *rx, if (!page) return; - page_pool_put_full_page(page->pp, page, allow_direct); + page_pool_put_full_page(page_pool_get_pp(page), page, allow_direct); buf_state->page_info.page = NULL; } diff --git a/drivers/net/ethernet/intel/iavf/iavf_txrx.c b/drivers/net/ethernet/intel/iavf/iavf_txrx.c index 422312b8b54a..72f17eaac277 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_txrx.c +++ b/drivers/net/ethernet/intel/iavf/iavf_txrx.c @@ -1197,7 +1197,8 @@ static void iavf_add_rx_frag(struct sk_buff *skb, const struct libeth_fqe *rx_buffer, unsigned int size) { - u32 hr = rx_buffer->page->pp->p.offset; + struct page_pool *pool = page_pool_get_pp(rx_buffer->page); + u32 hr = pool->p.offset; skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page, rx_buffer->offset + hr, size, rx_buffer->truesize); @@ -1214,7 +1215,8 @@ static void iavf_add_rx_frag(struct sk_buff *skb, static struct sk_buff *iavf_build_skb(const struct libeth_fqe *rx_buffer, unsigned int size) { - u32 hr = rx_buffer->page->pp->p.offset; + struct page_pool *pool = page_pool_get_pp(rx_buffer->page); + u32 hr = pool->p.offset; struct sk_buff *skb; void *va; diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c index bdf52cef3891..0ce77a5559aa 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c @@ -385,7 +385,8 @@ static void idpf_rx_page_rel(struct libeth_fqe *rx_buf) if (unlikely(!rx_buf->page)) return; - page_pool_put_full_page(rx_buf->page->pp, rx_buf->page, false); + page_pool_put_full_page(page_pool_get_pp(rx_buf->page), rx_buf->page, + false); rx_buf->page = NULL; rx_buf->offset = 0; @@ -3096,7 +3097,8 @@ idpf_rx_process_skb_fields(struct idpf_rx_queue *rxq, struct sk_buff *skb, void idpf_rx_add_frag(struct idpf_rx_buf *rx_buf, struct sk_buff *skb, unsigned int size) { - u32 hr = rx_buf->page->pp->p.offset; + struct page_pool *pool = page_pool_get_pp(rx_buf->page); + u32 hr = pool->p.offset; skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buf->page, rx_buf->offset + hr, size, rx_buf->truesize); @@ -3128,8 +3130,10 @@ static u32 idpf_rx_hsplit_wa(const struct libeth_fqe *hdr, if (!libeth_rx_sync_for_cpu(buf, copy)) return 0; - dst = page_address(hdr->page) + hdr->offset + hdr->page->pp->p.offset; - src = page_address(buf->page) + buf->offset + buf->page->pp->p.offset; + dst = page_address(hdr->page) + hdr->offset + + page_pool_get_pp(hdr->page)->p.offset; + src = page_address(buf->page) + buf->offset + + page_pool_get_pp(buf->page)->p.offset; memcpy(dst, src, LARGEST_ALIGN(copy)); buf->offset += copy; @@ -3147,7 +3151,7 @@ static u32 idpf_rx_hsplit_wa(const struct libeth_fqe *hdr, */ struct sk_buff *idpf_rx_build_skb(const struct libeth_fqe *buf, u32 size) { - u32 hr = buf->page->pp->p.offset; + u32 hr = page_pool_get_pp(buf->page)->p.offset; struct sk_buff *skb; void *va; diff --git a/drivers/net/ethernet/intel/libeth/rx.c b/drivers/net/ethernet/intel/libeth/rx.c index 66d1d23b8ad2..8de0c3a3b146 100644 --- a/drivers/net/ethernet/intel/libeth/rx.c +++ b/drivers/net/ethernet/intel/libeth/rx.c @@ -207,7 +207,7 @@ EXPORT_SYMBOL_NS_GPL(libeth_rx_fq_destroy, "LIBETH"); */ void libeth_rx_recycle_slow(struct page *page) { - page_pool_recycle_direct(page->pp, page); + page_pool_recycle_direct(page_pool_get_pp(page), page); } EXPORT_SYMBOL_NS_GPL(libeth_rx_recycle_slow, "LIBETH"); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c index 6f3094a479e1..b6bee95db994 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c @@ -709,7 +709,8 @@ static void mlx5e_free_xdpsq_desc(struct mlx5e_xdpsq *sq, /* No need to check ((page->pp_magic & ~0x3UL) == PP_SIGNATURE) * as we know this is a page_pool page. */ - page_pool_recycle_direct(page->pp, page); + page_pool_recycle_direct(page_pool_get_pp(page), + page); } while (++n < num); break; diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 54d03b0628d2..769fbea8ccf0 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -847,7 +847,8 @@ nsim_pp_hold_write(struct file *file, const char __user *data, if (!ns->page) ret = -ENOMEM; } else { - page_pool_put_full_page(ns->page->pp, ns->page, false); + page_pool_put_full_page(page_pool_get_pp(ns->page), ns->page, + false); ns->page = NULL; } @@ -1059,7 +1060,8 @@ void nsim_destroy(struct netdevsim *ns) /* Put this intentionally late to exercise the orphaning path */ if (ns->page) { - page_pool_put_full_page(ns->page->pp, ns->page, false); + page_pool_put_full_page(page_pool_get_pp(ns->page), ns->page, + false); ns->page = NULL; } diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 132148f7b107..11a88ecf8533 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -1777,7 +1777,7 @@ static inline void mt76_put_page_pool_buf(void *buf, bool allow_direct) { struct page *page = virt_to_head_page(buf); - page_pool_put_full_page(page->pp, page, allow_direct); + page_pool_put_full_page(page_pool_get_pp(page), page, allow_direct); } static inline void * diff --git a/include/net/libeth/rx.h b/include/net/libeth/rx.h index ab05024be518..2a3991d5b7c0 100644 --- a/include/net/libeth/rx.h +++ b/include/net/libeth/rx.h @@ -137,7 +137,8 @@ static inline bool libeth_rx_sync_for_cpu(const struct libeth_fqe *fqe, return false; } - page_pool_dma_sync_for_cpu(page->pp, page, fqe->offset, len); + page_pool_dma_sync_for_cpu(page_pool_get_pp(page), page, fqe->offset, + len); return true; } diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index 582a3d00cbe2..ab91911af215 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -83,6 +83,11 @@ static inline u64 *page_pool_ethtool_stats_get(u64 *data, const void *stats) } #endif +static inline struct page_pool *page_pool_get_pp(struct page *page) +{ + return page->pp; +} + /** * page_pool_dev_alloc_pages() - allocate a page. * @pool: pool from which to allocate -- 2.33.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool 2025-03-07 9:23 [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool Yunsheng Lin 2025-03-07 9:23 ` [PATCH net-next v11 1/4] page_pool: introduce page_pool_get_pp() API Yunsheng Lin @ 2025-03-07 14:15 ` Toke Høiland-Jørgensen 2025-03-08 12:33 ` Yunsheng Lin 1 sibling, 1 reply; 6+ messages in thread From: Toke Høiland-Jørgensen @ 2025-03-07 14:15 UTC (permalink / raw) To: Yunsheng Lin, davem, kuba, pabeni Cc: zhangkun09, liuyonglong, fanghaiqing, Yunsheng Lin, Alexander Lobakin, Robin Murphy, Alexander Duyck, Andrew Morton, Gaurav Batra, Matthew Rosato, IOMMU, MM, Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, Matthias Brugger, AngeloGioacchino Del Regno, netdev, intel-wired-lan, bpf, linux-kernel, linux-arm-kernel, linux-mediatek Yunsheng Lin <linyunsheng@huawei.com> writes: > This patchset fix the dma API misuse problem as below: > Networking driver with page_pool support may hand over page > still with dma mapping to network stack and try to reuse that > page after network stack is done with it and passes it back > to page_pool to avoid the penalty of dma mapping/unmapping. > With all the caching in the network stack, some pages may be > held in the network stack without returning to the page_pool > soon enough, and with VF disable causing the driver unbound, > the page_pool does not stop the driver from doing it's > unbounding work, instead page_pool uses workqueue to check > if there is some pages coming back from the network stack > periodically, if there is any, it will do the dma unmmapping > related cleanup work. > > As mentioned in [1], attempting DMA unmaps after the driver > has already unbound may leak resources or at worst corrupt > memory. Fundamentally, the page pool code cannot allow DMA > mappings to outlive the driver they belong to. > > By using the 'struct page_pool_item' referenced by page->pp_item, > page_pool is not only able to keep track of the inflight page to > do dma unmmaping if some pages are still handled in networking > stack when page_pool_destroy() is called, and networking stack is > also able to find the page_pool owning the page when returning > pages back into page_pool: > 1. When a page is added to the page_pool, an item is deleted from > pool->hold_items and set the 'pp_netmem' pointing to that page > and set item->state and item->pp_netmem accordingly in order to > keep track of that page, refill from pool->release_items when > pool->hold_items is empty or use the item from pool->slow_items > when fast items run out. > 2. When a page is released from the page_pool, it is able to tell > which page_pool this page belongs to by masking off the lower > bits of the pointer to page_pool_item *item, as the 'struct > page_pool_item_block' is stored in the top of a struct page. > And after clearing the pp_item->state', the item for the > released page is added back to pool->release_items so that it > can be reused for new pages or just free it when it is from the > pool->slow_items. > 3. When page_pool_destroy() is called, item->state is used to tell > if a specific item is being used/dma mapped or not by scanning > all the item blocks in pool->item_blocks, then item->netmem can > be used to do the dma unmmaping if the corresponding inflight > page is dma mapped. You are making this incredibly complicated. You've basically implemented a whole new slab allocator for those page_pool_item objects, and you're tracking every page handed out by the page pool instead of just the ones that are DMA-mapped. None of this is needed. I took a stab at implementing the xarray-based tracking first suggested by Mina[0]: https://git.kernel.org/toke/c/e87e0edf9520 And, well, it's 50 lines of extra code, none of which are in the fast path. Jesper has kindly helped with testing that it works for normal packet processing, but I haven't yet verified that it resolves the original crash. Will post the patch to the list once I have verified this (help welcome!). -Toke [0] https://lore.kernel.org/all/CAHS8izPg7B5DwKfSuzz-iOop_YRbk3Sd6Y4rX7KBG9DcVJcyWg@mail.gmail.com/ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool 2025-03-07 14:15 ` [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool Toke Høiland-Jørgensen @ 2025-03-08 12:33 ` Yunsheng Lin 2025-03-08 14:40 ` Toke Høiland-Jørgensen 0 siblings, 1 reply; 6+ messages in thread From: Yunsheng Lin @ 2025-03-08 12:33 UTC (permalink / raw) To: Toke Høiland-Jørgensen, Yunsheng Lin, davem, kuba, pabeni Cc: zhangkun09, liuyonglong, fanghaiqing, Alexander Lobakin, Robin Murphy, Alexander Duyck, Andrew Morton, Gaurav Batra, Matthew Rosato, IOMMU, MM, Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, Matthias Brugger, AngeloGioacchino Del Regno, netdev, intel-wired-lan, bpf, linux-kernel, linux-arm-kernel, linux-mediatek, Eric Dumazet On 3/7/2025 10:15 PM, Toke Høiland-Jørgensen wrote: ... > > You are making this incredibly complicated. You've basically implemented > a whole new slab allocator for those page_pool_item objects, and you're > tracking every page handed out by the page pool instead of just the ones > that are DMA-mapped. None of this is needed. > > I took a stab at implementing the xarray-based tracking first suggested > by Mina[0]: I did discuss Mina' suggestion with Ilias below in case you didn't notice: https://lore.kernel.org/all/0ef315df-e8e9-41e8-9ba8-dcb69492c616@huawei.com/ Anyway, It is great that you take the effort to actually implement the idea to have some more concrete comparison here. > > https://git.kernel.org/toke/c/e87e0edf9520 > > And, well, it's 50 lines of extra code, none of which are in the fast > path. I wonder what is the overhead for the xarray idea regarding the time_bench_page_pool03_slow() testcase before we begin to discuss if xarray idea is indeed possible. > > Jesper has kindly helped with testing that it works for normal packet > processing, but I haven't yet verified that it resolves the original > crash. Will post the patch to the list once I have verified this (help > welcome!). RFC seems like a good way to show and discuss the basic idea. I only took a glance at git code above, it seems reusing the _pp_mapping_pad for pp_dma_index seems like a wrong direction as mentioned in discussion with Ilias above as the field might be used when a page is mmap'ed to user space, and reusing that field in 'struct page' seems to disable the tcp_zerocopy feature, see the below commit from Eric: https://github.com/torvalds/linux/commit/577e4432f3ac810049cb7e6b71f4d96ec7c6e894 Also, I am not sure if a page_pool owned page can be spliced into the fs subsystem yet, but if it does, I am not sure how is reusing the page->mapping possible if that page is called in __filemap_add_folio()? https://elixir.bootlin.com/linux/v6.14-rc5/source/mm/filemap.c#L882 > > -Toke > > [0] https://lore.kernel.org/all/CAHS8izPg7B5DwKfSuzz-iOop_YRbk3Sd6Y4rX7KBG9DcVJcyWg@mail.gmail.com/ > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool 2025-03-08 12:33 ` Yunsheng Lin @ 2025-03-08 14:40 ` Toke Høiland-Jørgensen 2025-03-11 13:08 ` [Intel-wired-lan] " Paolo Abeni 0 siblings, 1 reply; 6+ messages in thread From: Toke Høiland-Jørgensen @ 2025-03-08 14:40 UTC (permalink / raw) To: Yunsheng Lin, Yunsheng Lin, davem, kuba, pabeni Cc: zhangkun09, liuyonglong, fanghaiqing, Alexander Lobakin, Robin Murphy, Alexander Duyck, Andrew Morton, Gaurav Batra, Matthew Rosato, IOMMU, MM, Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, Matthias Brugger, AngeloGioacchino Del Regno, netdev, intel-wired-lan, bpf, linux-kernel, linux-arm-kernel, linux-mediatek, Eric Dumazet Yunsheng Lin <yunshenglin0825@gmail.com> writes: > On 3/7/2025 10:15 PM, Toke Høiland-Jørgensen wrote: > > ... > >> >> You are making this incredibly complicated. You've basically implemented >> a whole new slab allocator for those page_pool_item objects, and you're >> tracking every page handed out by the page pool instead of just the ones >> that are DMA-mapped. None of this is needed. > > > I took a stab at implementing the xarray-based tracking first suggested >> by Mina[0]: > > I did discuss Mina' suggestion with Ilias below in case you didn't > notice: > https://lore.kernel.org/all/0ef315df-e8e9-41e8-9ba8-dcb69492c616@huawei.com/ I didn't; thanks for the pointer. See below. > Anyway, It is great that you take the effort to actually implement > the idea to have some more concrete comparison here. :) >> >> https://git.kernel.org/toke/c/e87e0edf9520 >> >> And, well, it's 50 lines of extra code, none of which are in the fast >> path. > > I wonder what is the overhead for the xarray idea regarding the > time_bench_page_pool03_slow() testcase before we begin to discuss > if xarray idea is indeed possible. Well, just running that benchmark shows no impact: | | Baseline | xarray | | | Cycles | ns | Cycles | ns | |-------------------------------+----------+--------+--------+--------| | no-softirq-page_pool01 | 20 | 5.713 | 19 | 5.516 | | no-softirq-page_pool02 | 56 | 15.560 | 57 | 15.864 | | no-softirq-page_pool03 | 225 | 62.763 | 222 | 61.728 | | tasklet_page_pool01_fast_path | 19 | 5.399 | 19 | 5.505 | | tasklet_page_pool02_ptr_ring | 54 | 15.090 | 54 | 15.018 | | tasklet_page_pool03_slow | 238 | 66.134 | 239 | 66.498 | ...however, the benchmark doesn't actually do any DMA mapping, so it's not super surprising that it doesn't show any difference: it's not exercising any of the xarray code. Your series shows a difference on this benchmark only because it does the page_pool_item allocation regardless of whether DMA is used or not. I guess we should try to come up with a micro-benchmark that does exercise the DMA code. Or just hack up the xarray patch to do the tracking regardless, for benchmarking purposes. >> Jesper has kindly helped with testing that it works for normal packet >> processing, but I haven't yet verified that it resolves the original >> crash. Will post the patch to the list once I have verified this (help >> welcome!). > > RFC seems like a good way to show and discuss the basic idea. Sure, I can send it as an RFC straight away if you prefer. Note that I'm on my way to netdevconf, though, so will probably have limited time to pay attention to this for the next week or so. > I only took a glance at git code above, it seems reusing the > _pp_mapping_pad for pp_dma_index seems like a wrong direction > as mentioned in discussion with Ilias above as the field might > be used when a page is mmap'ed to user space, and reusing that > field in 'struct page' seems to disable the tcp_zerocopy feature, > see the below commit from Eric: > https://github.com/torvalds/linux/commit/577e4432f3ac810049cb7e6b71f4d96ec7c6e894 > > Also, I am not sure if a page_pool owned page can be spliced into the fs > subsystem yet, but if it does, I am not sure how is reusing the > page->mapping possible if that page is called in __filemap_add_folio()? > > https://elixir.bootlin.com/linux/v6.14-rc5/source/mm/filemap.c#L882 Hmm, so I did look at the mapping field, but concluded using it wouldn't interfere with anything relevant as long as it's reset back to zero before the page is returned to the page allocator. However, I definitely missed the TCP zero-copy thing, and other things as well, it would seem (cf the discussion you referred to above). However, I did consider alternatives: AFAICT there should be space in the pp_magic field (used for the PP_SIGNATURE), so that with a bit of care we can stick an ID into the upper bits and still avoid ending up with a value that could look like a valid pointer. I didn't implement that initially because I wasn't sure it was necessary, but seeing as it is, I will take another look at it. I have one or two other ideas if this turns out not to pan out. -Toke ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Intel-wired-lan] [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool 2025-03-08 14:40 ` Toke Høiland-Jørgensen @ 2025-03-11 13:08 ` Paolo Abeni 0 siblings, 0 replies; 6+ messages in thread From: Paolo Abeni @ 2025-03-11 13:08 UTC (permalink / raw) To: Toke Høiland-Jørgensen, Yunsheng Lin, Yunsheng Lin, davem, kuba Cc: zhangkun09, liuyonglong, fanghaiqing, Alexander Lobakin, Robin Murphy, Alexander Duyck, Andrew Morton, Gaurav Batra, Matthew Rosato, IOMMU, MM, Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, Matthias Brugger, AngeloGioacchino Del Regno, netdev, intel-wired-lan, bpf, linux-kernel, linux-arm-kernel, linux-mediatek, Eric Dumazet On 3/8/25 3:40 PM, Toke Høiland-Jørgensen wrote: > Yunsheng Lin <yunshenglin0825@gmail.com> writes: >> I only took a glance at git code above, it seems reusing the >> _pp_mapping_pad for pp_dma_index seems like a wrong direction >> as mentioned in discussion with Ilias above as the field might >> be used when a page is mmap'ed to user space, and reusing that >> field in 'struct page' seems to disable the tcp_zerocopy feature, >> see the below commit from Eric: >> https://github.com/torvalds/linux/commit/577e4432f3ac810049cb7e6b71f4d96ec7c6e894 >> >> Also, I am not sure if a page_pool owned page can be spliced into the fs >> subsystem yet, but if it does, I am not sure how is reusing the >> page->mapping possible if that page is called in __filemap_add_folio()? >> >> https://elixir.bootlin.com/linux/v6.14-rc5/source/mm/filemap.c#L882 > > Hmm, so I did look at the mapping field, but concluded using it wouldn't > interfere with anything relevant as long as it's reset back to zero > before the page is returned to the page allocator. However, I definitely > missed the TCP zero-copy thing, and other things as well, it would seem > (cf the discussion you referred to above). > > However, I did consider alternatives: AFAICT there should be space in > the pp_magic field (used for the PP_SIGNATURE), so that with a bit of > care we can stick an ID into the upper bits and still avoid ending up > with a value that could look like a valid pointer. > > I didn't implement that initially because I wasn't sure it was > necessary, but seeing as it is, I will take another look at it. I have > one or two other ideas if this turns out not to pan out. Another dumb option would be storing directly the page address in the xarray, and avoid entirely going through an ID. I guess it will use more memory (the array will be more sparse) and will have more overhead, but could be possibly simpler? /P ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-03-11 13:12 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-03-07 9:23 [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool Yunsheng Lin 2025-03-07 9:23 ` [PATCH net-next v11 1/4] page_pool: introduce page_pool_get_pp() API Yunsheng Lin 2025-03-07 14:15 ` [PATCH net-next v11 0/4] fix the DMA API misuse problem for page_pool Toke Høiland-Jørgensen 2025-03-08 12:33 ` Yunsheng Lin 2025-03-08 14:40 ` Toke Høiland-Jørgensen 2025-03-11 13:08 ` [Intel-wired-lan] " Paolo Abeni
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).