devmem TCP fixes
Subsystems (4)
v4 cover devmem TCP fixes
Couple unrelated devmem TCP fixes bundled in a series for some convenience.
- fix naming and provide page_pool_alloc_netmem for fragged netmem.
- fix issues with dma-buf dma addresses being potentially passed to dma_sync_for_* helpers.
---
v3:
- Add documentation patch for memory providers. (Jakub)
- Drop netmem_prefetch helper (Jakub)
v2:
- Fork off the syzbot fixes to net tree, resubmit the rest here.
Mina Almasry (4):
net: page_pool: rename page_pool_alloc_netmem to *_netmems
net: page_pool: create page_pool_alloc_netmem
page_pool: disable sync for cpu for dmabuf memory provider
net: Document netmem driver support
Samiullah Khawaja (1):
page_pool: Set dma_sync to false for devmem memory provider
Documentation/networking/index.rst | 1 + Documentation/networking/netmem.rst | 62 +++++++++++++++++++++++++++++ include/net/page_pool/helpers.h | 60 +++++++++++++++++++++------- include/net/page_pool/types.h | 5 ++- net/core/devmem.c | 10 ++--- net/core/page_pool.c | 12 ++++-- 6 files changed, 125 insertions(+), 25 deletions(-) create mode 100644 Documentation/networking/netmem.rst
Signature · 1 line
2.47.0.338.g60cca15819-goog
PATCH v4 1/5 net: page_pool: rename page_pool_alloc_netmem to *_netmems
page_pool_alloc_netmem (without an s) was the mirror of page_pool_alloc_pages (with an s), which was confusing.
Rename to page_pool_alloc_netmems so it's the mirror of page_pool_alloc_pages.
--- include/net/page_pool/types.h | 2 +- net/core/page_pool.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
include/net/page_pool/types.h +1 -1
@@ -242,7 +242,7 @@ struct page_pool { };struct page *page_pool_alloc_pages (struct page_pool *pool,gfp_t gfp); -netmem_ref page_pool_alloc_netmem (struct page_pool *pool,gfp_t gfp); +netmem_ref page_pool_alloc_netmems (struct page_pool *pool,gfp_t gfp);struct page *page_pool_alloc_frag (struct page_pool *pool,unsigned int *offset,unsigned int size,gfp_t gfp); netmem_ref page_pool_alloc_frag_netmem(struct page_pool *pool,
net/core/page_pool.c +4 -4
@@ -574,7 +574,7 @@ static noinline netmem_ref __page_pool_alloc_pages_slow(struct page_pool *pool,/* For using page_pool replace: alloc_pages() API calls, but provide * synchronization guarantee for allocation side. */ -netmem_ref page_pool_alloc_netmem (struct page_pool *pool,gfp_t gfp) +netmem_ref page_pool_alloc_netmems (struct page_pool *pool,gfp_t gfp) {netmem_ref netmem;
@@ -590,11 +590,11 @@ netmem_ref page_pool_alloc_netmem(struct page_pool *pool, gfp_t gfp) netmem =__page_pool_alloc_pages_slow (pool, gfp);return netmem; } -EXPORT_SYMBOL (page_pool_alloc_netmem); +EXPORT_SYMBOL (page_pool_alloc_netmems);struct page *page_pool_alloc_pages (struct page_pool *pool,gfp_t gfp) { -return netmem_to_page (page_pool_alloc_netmem (pool, gfp)); +return netmem_to_page (page_pool_alloc_netmems (pool, gfp)); }EXPORT_SYMBOL (page_pool_alloc_pages);ALLOW_ERROR_INJECTION (page_pool_alloc_pages,NULL );
@@ -957,7 +957,7 @@ netmem_ref page_pool_alloc_frag_netmem(struct page_pool *pool, }if (!netmem) { - netmem =page_pool_alloc_netmem (pool, gfp); + netmem =page_pool_alloc_netmems (pool, gfp);if (unlikely (!netmem)) { pool->frag_page =0 ;return 0 ;
Signature · 1 line
2.47.0.338.g60cca15819-goog
PATCH v4 2/5 net: page_pool: create page_pool_alloc_netmem
In reply to Mina AlmasryCreate page_pool_alloc_netmem to be the mirror of page_pool_alloc.
This enables drivers that want currently use page_pool_alloc to transition to netmem by converting the call sites to page_pool_alloc_netmem.
--- include/net/page_pool/helpers.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
include/net/page_pool/helpers.h +16 -9
@@ -115,22 +115,22 @@ static inline struct page *page_pool_dev_alloc_frag(struct page_pool *pool,return page_pool_alloc_frag (pool, offset, size, gfp); } -static inline struct page *page_pool_alloc (struct page_pool *pool, -unsigned int *offset, -unsigned int *size,gfp_t gfp) +static inline netmem_ref page_pool_alloc_netmem (struct page_pool *pool, +unsigned int *offset, +unsigned int *size,gfp_t gfp) {unsigned int max_size =PAGE_SIZE << pool->p.order; -struct page *page; +netmem_ref netmem;if ((*size <<1 ) > max_size) { *size = max_size; *offset =0 ; -return page_pool_alloc_pages (pool, gfp); +return page_pool_alloc_netmems (pool, gfp); } - page =page_pool_alloc_frag (pool, offset, *size, gfp); -if (unlikely (!page)) -return NULL ; + netmem =page_pool_alloc_frag_netmem (pool, offset, *size, gfp); +if (unlikely (!netmem)) +return 0 ;/* There is very likely not enough space for another fragment, so append * the remaining size to the current fragment to avoid truesize
@@ -141,7 +141,14 @@ static inline struct page *page_pool_alloc(struct page_pool *pool, pool->frag_offset = max_size; } -return page; +return netmem; +} + +static inline struct page *page_pool_alloc (struct page_pool *pool, +unsigned int *offset, +unsigned int *size,gfp_t gfp) +{ +return netmem_to_page (page_pool_alloc_netmem (pool, offset, size, gfp)); }/**
Signature · 1 line
2.47.0.338.g60cca15819-goog
PATCH v4 3/5 page_pool: Set `dma_sync` to false for devmem memory provider
In reply to Mina AlmasryFrom: Samiullah Khawaja <[email protected]>
Move the dma_map and dma_sync checks to page_pool_init to make them generic. Set dma_sync to false for devmem memory provider because the dma_sync APIs should not be used for dma_buf backed devmem memory provider.
---
v4:
- Improve comment (Jakub)
--- net/core/devmem.c | 9 ++++----- net/core/page_pool.c | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-)
net/core/devmem.c +4 -5
@@ -331,11 +331,10 @@ int mp_dmabuf_devmem_init(struct page_pool *pool)if (!binding)return -EINVAL ; -if (!pool->dma_map) -return -EOPNOTSUPP ; - -if (pool->dma_sync) -return -EOPNOTSUPP ; +/* dma-buf dma addresses do not need and should not be used with +* dma_sync_for_cpu/device. Force disable dma_sync. +*/ + pool->dma_sync = false;if (pool->p.order !=0 )return -E2BIG ;
net/core/page_pool.c +3 -0
@@ -287,6 +287,9 @@ static int page_pool_init(struct page_pool *pool, }if (pool->mp_priv) { +if (!pool->dma_map || !pool->dma_sync) +return -EOPNOTSUPP ; + err =mp_dmabuf_devmem_init (pool);if (err) { pr_warn("%s() mem-provider init failed %d\n", __func__,
Signature · 1 line
2.47.0.338.g60cca15819-goog
PATCH v4 4/5 page_pool: disable sync for cpu for dmabuf memory provider
In reply to Mina Almasrydmabuf dma-addresses should not be dma_sync'd for CPU/device. Typically its the driver responsibility to dma_sync for CPU, but the driver should not dma_sync for CPU if the netmem is actually coming from a dmabuf memory provider.
The page_pool already exposes a helper for dma_sync_for_cpu:page_pool_dma_sync_for_cpu. Upgrade this existing helper to handle netmem, and have it skip dma_sync if the memory is from a dmabuf memory provider. Drivers should migrate to using this helper when adding support for netmem.
Also minimize the impact on the dma syncing performance for pages. Special case the dma-sync path for pages to not go through the overhead checks for dma-syncing and conversion to netmem.
---
v4:
- Special case pages to reduce perf overhead (Jakub)
- Add page_pool flag to set dma syncing for cpu (Jakub)
--- include/net/page_pool/helpers.h | 35 ++++++++++++++++++++++++++++----- include/net/page_pool/types.h | 3 ++- net/core/devmem.c | 1 + net/core/page_pool.c | 1 + 4 files changed, 34 insertions(+), 6 deletions(-)
include/net/page_pool/helpers.h +30 -5
@@ -422,7 +422,21 @@ static inline dma_addr_t page_pool_get_dma_addr_netmem(netmem_ref netmem)*/ static inline dma_addr_t page_pool_get_dma_addr (const struct page *page) { -return page_pool_get_dma_addr_netmem (page_to_netmem ((struct page *)page)); +dma_addr_t ret = page->dma_addr; + +if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA ) + ret <<=PAGE_SHIFT ; + +return ret; +} + +static inline void __page_pool_dma_sync_for_cpu (const struct page_pool *pool, +const dma_addr_t dma_addr, +u32 offset,u32 dma_sync_size) +{ +dma_sync_single_range_for_cpu (pool->p.dev, dma_addr, + offset + pool->p.offset, dma_sync_size, +page_pool_get_dma_dir (pool)); }/**
@@ -441,10 +455,21 @@ static inline void page_pool_dma_sync_for_cpu(const struct page_pool *pool,const struct page *page, u32 offset, u32 dma_sync_size) { - dma_sync_single_range_for_cpu(pool->p.dev, -page_pool_get_dma_addr (page ), - offset + pool->p.offset, dma_sync_size, -page_pool_get_dma_dir (pool )); +__page_pool_dma_sync_for_cpu (pool ,page_pool_get_dma_addr (page ),offset , +dma_sync_size ); +} + +static inline void +page_pool_dma_sync_netmem_for_cpu (const struct page_pool *pool, +const netmem_ref netmem,u32 offset, +u32 dma_sync_size) +{ +if (!pool->dma_sync_for_cpu) +return ; + +__page_pool_dma_sync_for_cpu (pool, +page_pool_get_dma_addr_netmem (netmem), + offset, dma_sync_size); }static inline bool page_pool_put (struct page_pool *pool)
include/net/page_pool/types.h +2 -1
@@ -164,7 +164,8 @@ struct page_pool { bool has_init_callback:1; /* slow::init_callback is set */ bool dma_map:1; /* Perform DMA mapping */ - bool dma_sync:1; /* Perform DMA sync */ + bool dma_sync:1; /* Perform DMA sync for device */ + bool dma_sync_for_cpu:1; /* Perform DMA sync for cpu */#ifdef CONFIG_PAGE_POOL_STATS bool system:1; /* This is a global percpu pool */#endif
net/core/devmem.c +1 -0
@@ -335,6 +335,7 @@ int mp_dmabuf_devmem_init(struct page_pool *pool)* dma_sync_for_cpu/device. Force disable dma_sync. */ pool->dma_sync = false; + pool->dma_sync_for_cpu = false;if (pool->p.order !=0 )return -E2BIG ;
net/core/page_pool.c +1 -0
@@ -201,6 +201,7 @@ static int page_pool_init(struct page_pool *pool,memcpy (&pool->slow, ¶ms->slow,sizeof (pool->slow)); pool->cpuid = cpuid; + pool->dma_sync_for_cpu = true;/* Validate only known flags were used */ if (pool->slow.flags & ~PP_FLAG_ALL )
Signature · 1 line
2.47.0.338.g60cca15819-goog
PATCH v4 5/5 net: Document netmem driver support
In reply to Mina AlmasryDocument expectations from drivers looking to add support for device memory tcp or other netmem based features.
---
v4:
- Address comments from Randy.
- Change docs to netmem focus (Jakub).
- Address comments from Jakub.
--- Documentation/networking/index.rst | 1 + Documentation/networking/netmem.rst | 62 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Documentation/networking/netmem.rst
Documentation/networking/index.rst +1 -0
@@ -86,6 +86,7 @@ Contents: netdevices netfilter-sysctl netif-msg + netmem nexthop-group-resilient nf_conntrack-sysctl nf_flowtable
Documentation/networking/netmem.rst new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.47.0.338.g60cca15819-goog
Re: [PATCH net-next v4 5/5] net: Document netmem driver support
Quoted 5 lines · Mina Almasry
Document expectations from drivers looking to add support for device memory tcp or other netmem based features.
Signed-off-by Mina Almasry <[email protected]>
Hi Mina,
Just a couple thoughts as this passed by me. These can be saved for a later update if the rest of this patchset is ready to go.
Quoted 33 lines
---
v4:
- Address comments from Randy.
- Change docs to netmem focus (Jakub).
- Address comments from Jakub.--- Documentation/networking/index.rst | 1 + Documentation/networking/netmem.rst | 62 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+)create mode 100644
Documentation/networking/netmem.rstDocumentation/networking/index.rst +1
-0@@ -86,6 +86,7 @@ Contents: netdevices netfilter-sysctl netif-msg + netmem nexthop-group-resilient nf_conntrack-sysctl nf_flowtableDocumentation/networking/netmem.rst new file +1
-0@@ -0,0 +1,62 @@ +.. SPDX-License-Identifier: GPL-2.0
Documentation/networking/netmem.rst line 11
Quoted 10 lines
Documentation/networking/netmem.rst new file +10
-0+ +================ +Netmem +================ + + +Introduction +============ + +Device memory TCP, and likely more upcoming features, are reliant on netmem
Device memory TCP is singular, so s/are/is/
Documentation/networking/netmem.rst line 12
Quoted 1 line
Documentation/networking/netmem.rst new file +1
-0+support in the driver. This outlines what drivers need to do to support netmem.
Can we get a summary of what netmem itself is and what it is for? There is a bit of explanation buried below in (3), but it would be good to have something here at the top.
Quoted 12 lines
Documentation/networking/netmem.rst new file +12
-0+ + +Driver support +============== + +1. The driver must support page_pool. The driver must not do its own recycling + on top of page_pool. + +2. The driver must support the tcp-data-split ethtool option. + +3. The driver must use the page_pool netmem APIs. The netmem APIs are + currently 1-to-1 correspond with page APIs. Conversion to netmem should be
Documentation/networking/netmem.rst line 34
Quoted 10 lines
Documentation/networking/netmem.rst new file +10
-0+ achievable by switching the page APIs to netmem APIs and tracking memory via + netmem_refs in the driver rather than struct page * : + + - page_pool_alloc -> page_pool_alloc_netmem + - page_pool_get_dma_addr -> page_pool_get_dma_addr_netmem + - page_pool_put_page -> page_pool_put_netmem + + Not all page APIs have netmem equivalents at the moment. If your driver + relies on a missing netmem API, feel free to add and propose to netdev@ or + reach out to [email protected] for help adding the netmem API.
You may want to replace your name with "the maintainers" and let the MAINTAINERS file keep track of who currently takes care of netmem things, rather than risk this email getting stale and forgotten.
Documentation/networking/netmem.rst line 39
Quoted 5 lines
Documentation/networking/netmem.rst new file +5
-0+ +4. The driver must use the following PP_FLAGS: + + - PP_FLAG_DMA_MAP: netmem is not dma-mappable by the driver. The driver + must delegate the dma mapping to the page_pool.
This is a bit confusing... if not dma-mappable, then why use PP_FLAG_DMA_MAP to ask page_pool to do it? A little more info might be useful such as, " ... must delegate the dma mapping to the page_pool which knows when dma-mapping is or is not appropriate".
Thanks,
sln
Quoted 27 lines
Documentation/networking/netmem.rst new file +23
-1+ - PP_FLAG_DMA_SYNC_DEV: netmem dma addr is not necessarily dma-syncable + by the driver. The driver must delegate the dma syncing to the page_pool. + - PP_FLAG_ALLOW_UNREADABLE_NETMEM. The driver must specify this flag iff + tcp-data-split is enabled. + +5. The driver must not assume the netmem is readable and/or backed by pages. + The netmem returned by the page_pool may be unreadable, in which case + netmem_address() will return NULL. The driver must correctly handle + unreadable netmem, i.e. don't attempt to handle its contents when + netmem_address() is NULL. + + Ideally, drivers should not have to check the underlying netmem type via + helpers like netmem_is_net_iov() or convert the netmem to any of its + underlying types via netmem_to_page() or netmem_to_net_iov(). In most cases, + netmem or page_pool helpers that abstract this complexity are provided + (and more can be added). + +6. The driver must use page_pool_dma_sync_netmem_for_cpu() in lieu of + dma_sync_single_range_for_cpu(). For some memory providers, dma_syncing for + CPU will be done by the page_pool, for others (particularly dmabuf memory + provider), dma syncing for CPU is the responsibility of the userspace using + dmabuf APIs. The driver must delegate the entire dma-syncing operation to + the page_pool which will do it correctly. --2.47.0.338.g60cca15819-goog
Re: [PATCH net-next v4 5/5] net: Document netmem driver support
Quoted 17 lines · Shannon
Quoted 17 lines
Documentation/networking/netmem.rst new file +17
-0+ +Driver support +============== + +1. The driver must support page_pool. The driver must not do its own recycling + on top of page_pool. + +2. The driver must support the tcp-data-split ethtool option. + +3. The driver must use the page_pool netmem APIs. The netmem APIs are + currently 1-to-1 correspond with page APIs. Conversion to netmem should be + achievable by switching the page APIs to netmem APIs and tracking memory via + netmem_refs in the driver rather than struct page * : + + - page_pool_alloc -> page_pool_alloc_netmem + - page_pool_get_dma_addr -> page_pool_get_dma_addr_netmem + - page_pool_put_page -> page_pool_put_netmem
Quoted 9 lines
Documentation/networking/netmem.rst line 34
Quoted 4 lines
Documentation/networking/netmem.rst new file +4
-0+ + Not all page APIs have netmem equivalents at the moment. If your driver + relies on a missing netmem API, feel free to add and propose to netdev@ or + reach out to [email protected] for help adding the netmem API.You may want to replace your name with "the maintainers" and let the
MAINTAINERSfile keep track of who currently takes care of netmem things, rather than risk this email getting stale and forgotten.
If it's OK with you, I'll change this to "the maintainers and/or [email protected]".
Reasoning is that currently Jakub really has reviewed all the netmem stuff very closely, and I'm hesitant to practically point to him to all future netmem questions or issues, especially since I can help with all the low hanging fruit. I don't currently show up in the maintainers file, and unless called for there is no entry for netmem maintenance. Wording the docs like this gives me the chance to help with some of the low hanging fruit without going so far as to add myself to maintainers.
If the email does go stale we can always update it and if there becomes a dedicated entry in MAINTAINERS for netmem we can always remove this.
Will address all the other points, thanks!
Signature · 2 lines
Thanks, Mina
Re: [PATCH net-next v4 5/5] net: Document netmem driver support
Quoted 39 lines · Mina Almasry
Quoted 17 lines · Shannon
Quoted 17 lines
Documentation/networking/netmem.rst new file +17
-0+ +Driver support +============== + +1. The driver must support page_pool. The driver must not do its own recycling + on top of page_pool. + +2. The driver must support the tcp-data-split ethtool option. + +3. The driver must use the page_pool netmem APIs. The netmem APIs are + currently 1-to-1 correspond with page APIs. Conversion to netmem should be + achievable by switching the page APIs to netmem APIs and tracking memory via + netmem_refs in the driver rather than struct page * : + + - page_pool_alloc -> page_pool_alloc_netmem + - page_pool_get_dma_addr -> page_pool_get_dma_addr_netmem + - page_pool_put_page -> page_pool_put_netmemQuoted 9 lines
Documentation/networking/netmem.rst line 34
Quoted 4 lines
Documentation/networking/netmem.rst new file +4
-0+ + Not all page APIs have netmem equivalents at the moment. If your driver + relies on a missing netmem API, feel free to add and propose to netdev@ or + reach out to [email protected] for help adding the netmem API.You may want to replace your name with "the maintainers" and let the
MAINTAINERSfile keep track of who currently takes care of netmem things, rather than risk this email getting stale and forgotten.If it's OK with you, I'll change this to "the maintainers and/or [email protected]".
Quoted 1 line
Reasoning is that currently Jakub really has reviewed all the netmem
stuff very closely, and I'm hesitant to practically point to him to all future netmem questions or issues, especially since I can help with all the low hanging fruit. I don't currently show up in the maintainers file, and unless called for there is no entry for netmem maintenance. Wording the docs like this gives me the chance to help with some of the low hanging fruit without going so far as to add myself to maintainers.
Quoted 3 lines
If the email does go stale we can always update it and if there becomes a dedicated entry in
MAINTAINERSfor netmem we can always remove this.
Fine with me, thanks for the note.
Quoted 6 lines
Will address all the other points, thanks!
--
Thanks,
Mina
Cheers,
sln
Jakub Kicinski
maintainerRe: [PATCH net-next v4 5/5] net: Document netmem driver support
In reply to Mina AlmasryDocumentation/networking/netmem.rst line 5
Quoted 4 lines · On Wed, 11 Dec 2024 21:20:32 +0000 Mina Almasry wrote:
Documentation/networking/netmem.rst new file +4
-0+ +================ +Netmem +================
The length of the ==== lines must match the title.
Documentation/networking/netmem.rst line 19
Quoted 12 lines
Documentation/networking/netmem.rst new file +12
-0+Introduction +============ + +Device memory TCP, and likely more upcoming features, are reliant on netmem +support in the driver. This outlines what drivers need to do to support netmem. + + +Driver support +============== + +1. The driver must support page_pool. The driver must not do its own recycling + on top of page_pool.
We discussed this one, probably needs a bit of rewording at least.
Quoted 3 lines
+2. The driver must support the tcp-data-split ethtool option. +
+3. The driver must use thepage_poolnetmem APIs.
We should probably mention that this is only for payload pages?
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 11 Dec 2024 21:20:27 +0000 you wrote:
Couple unrelated devmem TCP fixes bundled in a series for some convenience.
- fix naming and provide
page_pool_alloc_netmemfor fragged netmem.- fix issues with dma-buf dma addresses being potentially passed to dma_sync_for_* helpers.
[...]
Here is the summary with links:
- [net-next,v4,1/5] net: page_pool: rename page_pool_alloc_netmem to *_netmems
https://git.kernel.org/netdev/net-next/c/91a152cbb49c - [net-next,v4,2/5] net: page_pool: create page_pool_alloc_netmem https://git.kernel.org/netdev/net-next/c/8156c310499a - [net-next,v4,3/5] page_pool: Set `dma_sync` to false for devmem memory provider https://git.kernel.org/netdev/net-next/c/b400f4b87430 - [net-next,v4,4/5] page_pool: disable sync for cpu for dmabuf memory provider https://git.kernel.org/netdev/net-next/c/7dba339faae9
- [net-next,v4,5/5] net: Document netmem driver support (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html