netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mina Almasry <almasrymina@google.com>
To: "Toke Høiland-Jørgensen" <toke@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	 Jesper Dangaard Brouer <hawk@kernel.org>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>,
	 Tariq Toukan <tariqt@nvidia.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	 Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	 Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Simon Horman <horms@kernel.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Yonglong Liu <liuyonglong@huawei.com>,
	 Yunsheng Lin <linyunsheng@huawei.com>,
	Pavel Begunkov <asml.silence@gmail.com>,
	 Matthew Wilcox <willy@infradead.org>,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	 linux-rdma@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH net-next 2/3] page_pool: Turn dma_sync and dma_sync_cpu fields into a bitmap
Date: Fri, 21 Mar 2025 16:13:17 -0700	[thread overview]
Message-ID: <CAHS8izNPLnbZ-M=367k7H6OYts7RXbcDpbrWy_p37=62LsYYcg@mail.gmail.com> (raw)
In-Reply-To: <20250314-page-pool-track-dma-v1-2-c212e57a74c2@redhat.com>

On Fri, Mar 14, 2025 at 3:12 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>
> Change the single-bit booleans for dma_sync into an unsigned long with
> BIT() definitions so that a subsequent patch can write them both with a
> singe WRITE_ONCE() on teardown. Also move the check for the sync_cpu
> side into __page_pool_dma_sync_for_cpu() so it can be disabled for
> non-netmem providers as well.
>
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>

Reviewed-by: Mina Almasry <almasrymina@google.com>

> ---
>  include/net/page_pool/helpers.h | 6 +++---
>  include/net/page_pool/types.h   | 8 ++++++--
>  net/core/devmem.c               | 3 +--
>  net/core/page_pool.c            | 9 +++++----
>  4 files changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
> index 582a3d00cbe2315edeb92850b6a42ab21e509e45..7ed32bde4b8944deb7fb22e291e95b8487be681a 100644
> --- a/include/net/page_pool/helpers.h
> +++ b/include/net/page_pool/helpers.h
> @@ -443,6 +443,9 @@ 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)
>  {
> +       if (!(READ_ONCE(pool->dma_sync) & PP_DMA_SYNC_CPU))
> +               return;
> +
>         dma_sync_single_range_for_cpu(pool->p.dev, dma_addr,
>                                       offset + pool->p.offset, dma_sync_size,
>                                       page_pool_get_dma_dir(pool));
> @@ -473,9 +476,6 @@ 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);

I think moving the check to __page_pool_dma_sync_for_cpu is fine, but
I would have preferred to keep it as-is actually.

I think if we're syncing netmem we should check dma_sync_for_cpu,
because the netmem may not be dma-syncable. But for pages, they will
likely always be dma-syncable. Some driver may have opted to do a perf
optimizations by calling __page_pool_dma_sync_for_cpu on a dma-addr
that it knows came from a page to save some cycles of netmem checking.

> diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h
> index df0d3c1608929605224feb26173135ff37951ef8..fbe34024b20061e8bcd1d4474f6ebfc70992f1eb 100644
> --- a/include/net/page_pool/types.h
> +++ b/include/net/page_pool/types.h
> @@ -33,6 +33,10 @@
>  #define PP_FLAG_ALL            (PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV | \
>                                  PP_FLAG_SYSTEM_POOL | PP_FLAG_ALLOW_UNREADABLE_NETMEM)
>
> +/* bit values used in pp->dma_sync */
> +#define PP_DMA_SYNC_DEV        BIT(0)
> +#define PP_DMA_SYNC_CPU        BIT(1)
> +
>  /*
>   * Fast allocation side cache array/stack
>   *
> @@ -175,12 +179,12 @@ 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 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
>
> +       unsigned long dma_sync;
> +
>         __cacheline_group_begin_aligned(frag, PAGE_POOL_FRAG_GROUP_ALIGN);
>         long frag_users;
>         netmem_ref frag_page;
> diff --git a/net/core/devmem.c b/net/core/devmem.c
> index 7c6e0b5b6acb55f376ec725dfb71d1f70a4320c3..16e43752566feb510b3e47fbec2d8da0f26a6adc 100644
> --- a/net/core/devmem.c
> +++ b/net/core/devmem.c
> @@ -337,8 +337,7 @@ int mp_dmabuf_devmem_init(struct page_pool *pool)
>         /* 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;
> -       pool->dma_sync_for_cpu = false;
> +       pool->dma_sync = 0;
>
>         if (pool->p.order != 0)
>                 return -E2BIG;
> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> index acef1fcd8ddcfd1853a6f2055c1f1820ab248e8d..d51ca4389dd62d8bc266a9a2b792838257173535 100644
> --- a/net/core/page_pool.c
> +++ b/net/core/page_pool.c
> @@ -203,7 +203,7 @@ static int page_pool_init(struct page_pool *pool,
>         memcpy(&pool->slow, &params->slow, sizeof(pool->slow));
>
>         pool->cpuid = cpuid;
> -       pool->dma_sync_for_cpu = true;
> +       pool->dma_sync = PP_DMA_SYNC_CPU;
>

More pedantically this should have been pool->dma_sync |=
PP_DMA_SYNC_CPU, but it doesn't matter since this variable is 0
initialized I think.


--
Thanks,
Mina

  parent reply	other threads:[~2025-03-21 23:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14 10:10 [PATCH net-next 0/3] Fix late DMA unmap crash for page pool Toke Høiland-Jørgensen
2025-03-14 10:10 ` [PATCH net-next 1/3] page_pool: Move pp_magic check into helper functions Toke Høiland-Jørgensen
2025-03-21 17:16   ` Mina Almasry
2025-03-14 10:10 ` [PATCH net-next 2/3] page_pool: Turn dma_sync and dma_sync_cpu fields into a bitmap Toke Høiland-Jørgensen
2025-03-15  9:31   ` Yunsheng Lin
2025-03-17 14:55     ` Toke Høiland-Jørgensen
2025-03-21 23:13   ` Mina Almasry [this message]
2025-03-14 10:10 ` [PATCH net-next 3/3] page_pool: Track DMA-mapped pages and unmap them when destroying the pool Toke Høiland-Jørgensen
2025-03-15  9:46   ` Yunsheng Lin
2025-03-17 15:16     ` Toke Høiland-Jørgensen
2025-03-18 12:39       ` Yunsheng Lin
2025-03-18 20:55         ` Toke Høiland-Jørgensen
2025-03-19 11:06           ` Yunsheng Lin
2025-03-19 12:18             ` Toke Høiland-Jørgensen
2025-03-20 11:17               ` Yunsheng Lin
2025-03-20 14:34                 ` Toke Høiland-Jørgensen
2025-03-20  2:32             ` Solar Designer
2025-03-20 14:37               ` Toke Høiland-Jørgensen
2025-03-17  2:02 ` [PATCH net-next 0/3] Fix late DMA unmap crash for page pool Yonglong Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHS8izNPLnbZ-M=367k7H6OYts7RXbcDpbrWy_p37=62LsYYcg@mail.gmail.com' \
    --to=almasrymina@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=asml.silence@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linyunsheng@huawei.com \
    --cc=liuyonglong@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    --cc=toke@redhat.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).