diff mbox series

[net-next,v2,3/5] page_pool: Set `dma_sync` to false for devmem memory provider

Message ID 20241107212309.3097362-4-almasrymina@google.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series devmem TCP fixes | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 5 maintainers not CCed: christian.koenig@amd.com dri-devel@lists.freedesktop.org sumit.semwal@linaro.org linaro-mm-sig@lists.linaro.org linux-media@vger.kernel.org
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 3 this patch: 3
netdev/source_inline success Was 0 now: 0

Commit Message

Mina Almasry Nov. 7, 2024, 9:23 p.m. UTC
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>

---
 net/core/devmem.c    | 9 ++++-----
 net/core/page_pool.c | 3 +++
 2 files changed, 7 insertions(+), 5 deletions(-)

Comments

Stanislav Fomichev Nov. 8, 2024, 3:53 p.m. UTC | #1
On 11/07, Mina Almasry wrote:
> 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>

Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Pavel Begunkov Nov. 8, 2024, 4:34 p.m. UTC | #2
On 11/7/24 21:23, Mina Almasry wrote:
> 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>
> 
> ---
>   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..826d0b00159f 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 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 77de79c1933b..528dd4d18eab 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)

Is there a reason why ->dma_sync is enforced for all providers?
It sounds like a devmem fix, on the other hand I don't really
care as we don't have drivers yet implementing queue api / etc.
but not passing PP_FLAG_DMA_SYNC_DEV.

Also, putting fixes first in the series or sending them separately
reduces backporting headache.
Jakub Kicinski Nov. 12, 2024, 2:34 a.m. UTC | #3
On Thu,  7 Nov 2024 21:23:07 +0000 Mina Almasry wrote:
> 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.

Let's start from specifying the expectations from the drivers,
and documenting them under Documentation/

We should require that drivers set PP_FLAG_DMA_SYNC_DEV on the page
pool and always use (a new form of) page_pool_dma_sync_for_cpu()
to sync for CPU.

Behind the scenes we will configure the PP to act accordingly.
For dmabuf backed PP I suspect we just say "syncing is
the responsibility of userspace", and configure the PP
to do no syncing at all.

For other providers we can keep the syncing enabled. But drivers
shouldn't be allowed to use any netmem if they don't set
PP_FLAG_DMA_SYNC_DEV, just to keep things uniform.
diff mbox series

Patch

diff --git a/net/core/devmem.c b/net/core/devmem.c
index 11b91c12ee11..826d0b00159f 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 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 77de79c1933b..528dd4d18eab 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__,