* [PATCH net-next v4 1/5] net: page_pool: rename page_pool_alloc_netmem to *_netmems
2024-12-11 21:20 [PATCH net-next v4 0/5] devmem TCP fixes Mina Almasry
@ 2024-12-11 21:20 ` Mina Almasry
2024-12-11 21:20 ` [PATCH net-next v4 2/5] net: page_pool: create page_pool_alloc_netmem Mina Almasry
` (4 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Mina Almasry @ 2024-12-11 21:20 UTC (permalink / raw)
To: netdev, Jakub Kicinski, Mina Almasry, Pavel Begunkov,
Willem de Bruijn, Kaiyuan Zhang, Samiullah Khawaja, linux-doc,
linux-kernel
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jonathan Corbet, Jesper Dangaard Brouer, Ilias Apalodimas,
Stanislav Fomichev
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.
Signed-off-by: Mina Almasry <almasrymina@google.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
---
include/net/page_pool/types.h | 2 +-
net/core/page_pool.c | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h
index 1ea16b0e9c79..bd1170e16cff 100644
--- a/include/net/page_pool/types.h
+++ b/include/net/page_pool/types.h
@@ -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,
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 4c85b77cfdac..3c0e19e13e64 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -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;
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v4 2/5] net: page_pool: create page_pool_alloc_netmem
2024-12-11 21:20 [PATCH net-next v4 0/5] devmem TCP fixes Mina Almasry
2024-12-11 21:20 ` [PATCH net-next v4 1/5] net: page_pool: rename page_pool_alloc_netmem to *_netmems Mina Almasry
@ 2024-12-11 21:20 ` Mina Almasry
2024-12-11 21:20 ` [PATCH net-next v4 3/5] page_pool: Set `dma_sync` to false for devmem memory provider Mina Almasry
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Mina Almasry @ 2024-12-11 21:20 UTC (permalink / raw)
To: netdev, Jakub Kicinski, Mina Almasry, Pavel Begunkov,
Willem de Bruijn, Kaiyuan Zhang, Samiullah Khawaja, linux-doc,
linux-kernel
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jonathan Corbet, Jesper Dangaard Brouer, Ilias Apalodimas,
Stanislav Fomichev
Create 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.
Signed-off-by: Mina Almasry <almasrymina@google.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
---
include/net/page_pool/helpers.h | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
index 26caa2c20912..95af7f0b029e 100644
--- a/include/net/page_pool/helpers.h
+++ b/include/net/page_pool/helpers.h
@@ -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));
}
/**
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v4 3/5] page_pool: Set `dma_sync` to false for devmem memory provider
2024-12-11 21:20 [PATCH net-next v4 0/5] devmem TCP fixes Mina Almasry
2024-12-11 21:20 ` [PATCH net-next v4 1/5] net: page_pool: rename page_pool_alloc_netmem to *_netmems Mina Almasry
2024-12-11 21:20 ` [PATCH net-next v4 2/5] net: page_pool: create page_pool_alloc_netmem Mina Almasry
@ 2024-12-11 21:20 ` Mina Almasry
2024-12-11 21:20 ` [PATCH net-next v4 4/5] page_pool: disable sync for cpu for dmabuf " Mina Almasry
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Mina Almasry @ 2024-12-11 21:20 UTC (permalink / raw)
To: netdev, Jakub Kicinski, Mina Almasry, Pavel Begunkov,
Willem de Bruijn, Kaiyuan Zhang, Samiullah Khawaja, linux-doc,
linux-kernel
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jonathan Corbet, Jesper Dangaard Brouer, Ilias Apalodimas,
Jason Gunthorpe
From: Samiullah Khawaja <skhawaja@google.com>
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.
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
Signed-off-by: Mina Almasry <almasrymina@google.com>
---
v4:
- Improve comment (Jakub)
---
net/core/devmem.c | 9 ++++-----
net/core/page_pool.c | 3 +++
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/net/core/devmem.c b/net/core/devmem.c
index 11b91c12ee11..3ebdeed2bf18 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -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;
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 3c0e19e13e64..060450082342 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -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__,
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v4 4/5] page_pool: disable sync for cpu for dmabuf memory provider
2024-12-11 21:20 [PATCH net-next v4 0/5] devmem TCP fixes Mina Almasry
` (2 preceding siblings ...)
2024-12-11 21:20 ` [PATCH net-next v4 3/5] page_pool: Set `dma_sync` to false for devmem memory provider Mina Almasry
@ 2024-12-11 21:20 ` Mina Almasry
2024-12-11 21:20 ` [PATCH net-next v4 5/5] net: Document netmem driver support Mina Almasry
2024-12-13 3:00 ` [PATCH net-next v4 0/5] devmem TCP fixes patchwork-bot+netdevbpf
5 siblings, 0 replies; 11+ messages in thread
From: Mina Almasry @ 2024-12-11 21:20 UTC (permalink / raw)
To: netdev, Jakub Kicinski, Mina Almasry, Pavel Begunkov,
Willem de Bruijn, Kaiyuan Zhang, Samiullah Khawaja, linux-doc,
linux-kernel
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jonathan Corbet, Jesper Dangaard Brouer, Ilias Apalodimas,
Alexander Lobakin, Jason Gunthorpe
dmabuf 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.
Cc: Alexander Lobakin <aleksander.lobakin@intel.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Signed-off-by: Mina Almasry <almasrymina@google.com>
---
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(-)
diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
index 95af7f0b029e..e555921e5233 100644
--- a/include/net/page_pool/helpers.h
+++ b/include/net/page_pool/helpers.h
@@ -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)
diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h
index bd1170e16cff..6ae003d3647c 100644
--- a/include/net/page_pool/types.h
+++ b/include/net/page_pool/types.h
@@ -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
diff --git a/net/core/devmem.c b/net/core/devmem.c
index 3ebdeed2bf18..0b6ed7525b22 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -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;
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 060450082342..51b8264de74a 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -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)
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v4 5/5] net: Document netmem driver support
2024-12-11 21:20 [PATCH net-next v4 0/5] devmem TCP fixes Mina Almasry
` (3 preceding siblings ...)
2024-12-11 21:20 ` [PATCH net-next v4 4/5] page_pool: disable sync for cpu for dmabuf " Mina Almasry
@ 2024-12-11 21:20 ` Mina Almasry
2024-12-11 22:58 ` Nelson, Shannon
2024-12-13 2:53 ` Jakub Kicinski
2024-12-13 3:00 ` [PATCH net-next v4 0/5] devmem TCP fixes patchwork-bot+netdevbpf
5 siblings, 2 replies; 11+ messages in thread
From: Mina Almasry @ 2024-12-11 21:20 UTC (permalink / raw)
To: netdev, Jakub Kicinski, Mina Almasry, Pavel Begunkov,
Willem de Bruijn, Kaiyuan Zhang, Samiullah Khawaja, linux-doc,
linux-kernel
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jonathan Corbet, Jesper Dangaard Brouer, Ilias Apalodimas
Document expectations from drivers looking to add support for device
memory tcp or other netmem based features.
Signed-off-by: Mina Almasry <almasrymina@google.com>
---
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
diff --git a/Documentation/networking/index.rst b/Documentation/networking/index.rst
index 46c178e564b3..058193ed2eeb 100644
--- a/Documentation/networking/index.rst
+++ b/Documentation/networking/index.rst
@@ -86,6 +86,7 @@ Contents:
netdevices
netfilter-sysctl
netif-msg
+ netmem
nexthop-group-resilient
nf_conntrack-sysctl
nf_flowtable
diff --git a/Documentation/networking/netmem.rst b/Documentation/networking/netmem.rst
new file mode 100644
index 000000000000..f9f03189c53c
--- /dev/null
+++ b/Documentation/networking/netmem.rst
@@ -0,0 +1,62 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+================
+Netmem
+================
+
+
+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.
+
+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
+
+ 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 almasrymina@google.com for help adding the netmem API.
+
+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.
+ - 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
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH net-next v4 5/5] net: Document netmem driver support
2024-12-11 21:20 ` [PATCH net-next v4 5/5] net: Document netmem driver support Mina Almasry
@ 2024-12-11 22:58 ` Nelson, Shannon
2024-12-17 19:27 ` Mina Almasry
2024-12-13 2:53 ` Jakub Kicinski
1 sibling, 1 reply; 11+ messages in thread
From: Nelson, Shannon @ 2024-12-11 22:58 UTC (permalink / raw)
To: Mina Almasry, netdev, Jakub Kicinski, Pavel Begunkov,
Willem de Bruijn, Kaiyuan Zhang, Samiullah Khawaja, linux-doc,
linux-kernel
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jonathan Corbet, Jesper Dangaard Brouer, Ilias Apalodimas
On 12/11/2024 1:20 PM, Mina Almasry wrote:
>
> Document expectations from drivers looking to add support for device
> memory tcp or other netmem based features.
>
> Signed-off-by: Mina Almasry <almasrymina@google.com>
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.
>
> ---
>
> 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
>
> diff --git a/Documentation/networking/index.rst b/Documentation/networking/index.rst
> index 46c178e564b3..058193ed2eeb 100644
> --- a/Documentation/networking/index.rst
> +++ b/Documentation/networking/index.rst
> @@ -86,6 +86,7 @@ Contents:
> netdevices
> netfilter-sysctl
> netif-msg
> + netmem
> nexthop-group-resilient
> nf_conntrack-sysctl
> nf_flowtable
> diff --git a/Documentation/networking/netmem.rst b/Documentation/networking/netmem.rst
> new file mode 100644
> index 000000000000..f9f03189c53c
> --- /dev/null
> +++ b/Documentation/networking/netmem.rst
> @@ -0,0 +1,62 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +================
> +Netmem
> +================
> +
> +
> +Introduction
> +============
> +
> +Device memory TCP, and likely more upcoming features, are reliant on netmem
Device memory TCP is singular, so s/are/is/
> +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.
> +
> +
> +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
> +
> + 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 almasrymina@google.com 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.
> +
> +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
> + - 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
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next v4 5/5] net: Document netmem driver support
2024-12-11 22:58 ` Nelson, Shannon
@ 2024-12-17 19:27 ` Mina Almasry
2024-12-17 19:40 ` Nelson, Shannon
0 siblings, 1 reply; 11+ messages in thread
From: Mina Almasry @ 2024-12-17 19:27 UTC (permalink / raw)
To: Nelson, Shannon
Cc: netdev, Jakub Kicinski, Pavel Begunkov, Willem de Bruijn,
Kaiyuan Zhang, Samiullah Khawaja, linux-doc, linux-kernel,
David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jonathan Corbet, Jesper Dangaard Brouer, Ilias Apalodimas
On Wed, Dec 11, 2024 at 2:58 PM Nelson, Shannon <shannon.nelson@amd.com> wrote:
> > +
> > +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
> > +
> > + 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 almasrymina@google.com 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.
>
If it's OK with you, I'll change this to "the maintainers and/or
almasrymina@google.com".
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!
--
Thanks,
Mina
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next v4 5/5] net: Document netmem driver support
2024-12-17 19:27 ` Mina Almasry
@ 2024-12-17 19:40 ` Nelson, Shannon
0 siblings, 0 replies; 11+ messages in thread
From: Nelson, Shannon @ 2024-12-17 19:40 UTC (permalink / raw)
To: Mina Almasry
Cc: netdev, Jakub Kicinski, Pavel Begunkov, Willem de Bruijn,
Kaiyuan Zhang, Samiullah Khawaja, linux-doc, linux-kernel,
David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jonathan Corbet, Jesper Dangaard Brouer, Ilias Apalodimas
On 12/17/2024 11:27 AM, Mina Almasry wrote:
> On Wed, Dec 11, 2024 at 2:58 PM Nelson, Shannon <shannon.nelson@amd.com> wrote:
>>> +
>>> +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
>>> +
>>> + 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 almasrymina@google.com 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.
>>
>
> If it's OK with you, I'll change this to "the maintainers and/or
> almasrymina@google.com".
> > 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.
Fine with me, thanks for the note.
>
> Will address all the other points, thanks!
>
> --
> Thanks,
> Mina
Cheers,
sln
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next v4 5/5] net: Document netmem driver support
2024-12-11 21:20 ` [PATCH net-next v4 5/5] net: Document netmem driver support Mina Almasry
2024-12-11 22:58 ` Nelson, Shannon
@ 2024-12-13 2:53 ` Jakub Kicinski
1 sibling, 0 replies; 11+ messages in thread
From: Jakub Kicinski @ 2024-12-13 2:53 UTC (permalink / raw)
To: Mina Almasry
Cc: netdev, Pavel Begunkov, Willem de Bruijn, Kaiyuan Zhang,
Samiullah Khawaja, linux-doc, linux-kernel, David S. Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Jonathan Corbet,
Jesper Dangaard Brouer, Ilias Apalodimas
On Wed, 11 Dec 2024 21:20:32 +0000 Mina Almasry wrote:
> +
> +================
> +Netmem
> +================
The length of the ==== lines must match the title.
> +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.
> +2. The driver must support the tcp-data-split ethtool option.
> +
> +3. The driver must use the page_pool netmem APIs.
We should probably mention that this is only for payload pages?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next v4 0/5] devmem TCP fixes
2024-12-11 21:20 [PATCH net-next v4 0/5] devmem TCP fixes Mina Almasry
` (4 preceding siblings ...)
2024-12-11 21:20 ` [PATCH net-next v4 5/5] net: Document netmem driver support Mina Almasry
@ 2024-12-13 3:00 ` patchwork-bot+netdevbpf
5 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-12-13 3:00 UTC (permalink / raw)
To: Mina Almasry
Cc: netdev, kuba, asml.silence, willemb, kaiyuanz, skhawaja,
linux-doc, linux-kernel, davem, edumazet, pabeni, horms, corbet,
hawk, ilias.apalodimas
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
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_netmem for 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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 11+ messages in thread