lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAC_iWjL6j5xS9GsLiZdLPJgJgfGNMbjKZPTMqnvX9U_9Dgq=ZQ@mail.gmail.com>
Date: Thu, 18 Apr 2024 17:56:41 +0300
From: Ilias Apalodimas <ilias.apalodimas@...aro.org>
To: Alexander Lobakin <aleksander.lobakin@...el.com>
Cc: "David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>, 
	Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>, 
	Alexander Duyck <alexanderduyck@...com>, Yunsheng Lin <linyunsheng@...wei.com>, 
	Jesper Dangaard Brouer <hawk@...nel.org>, Christoph Lameter <cl@...ux.com>, Vlastimil Babka <vbabka@...e.cz>, 
	Andrew Morton <akpm@...ux-foundation.org>, Przemek Kitszel <przemyslaw.kitszel@...el.com>, 
	nex.sw.ncis.osdt.itp.upstreaming@...el.com, netdev@...r.kernel.org, 
	intel-wired-lan@...ts.osuosl.org, linux-mm@...ck.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next v10 06/10] page_pool: add DMA-sync-for-CPU inline helper

On Thu, 18 Apr 2024 at 14:37, Alexander Lobakin
<aleksander.lobakin@...el.com> wrote:
>
> Each driver is responsible for syncing buffers written by HW for CPU
> before accessing them. Almost each PP-enabled driver uses the same
> pattern, which could be shorthanded into a static inline to make driver
> code a little bit more compact.
> Introduce a simple helper which performs DMA synchronization for the
> size passed from the driver. It can be used even when the pool doesn't
> manage DMA-syncs-for-device, just make sure the page has a correct DMA
> address set via page_pool_set_dma_addr().
>
> Signed-off-by: Alexander Lobakin <aleksander.lobakin@...el.com>
> ---
>  include/net/page_pool/helpers.h | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>
> diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
> index c7bb06750e85..873631c79ab1 100644
> --- a/include/net/page_pool/helpers.h
> +++ b/include/net/page_pool/helpers.h
> @@ -52,6 +52,8 @@
>  #ifndef _NET_PAGE_POOL_HELPERS_H
>  #define _NET_PAGE_POOL_HELPERS_H
>
> +#include <linux/dma-mapping.h>
> +
>  #include <net/page_pool/types.h>
>
>  #ifdef CONFIG_PAGE_POOL_STATS
> @@ -395,6 +397,28 @@ static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr)
>         return false;
>  }
>
> +/**
> + * page_pool_dma_sync_for_cpu - sync Rx page for CPU after it's written by HW
> + * @pool: &page_pool the @page belongs to
> + * @page: page to sync
> + * @offset: offset from page start to "hard" start if using PP frags
> + * @dma_sync_size: size of the data written to the page
> + *
> + * Can be used as a shorthand to sync Rx pages before accessing them in the
> + * driver. Caller must ensure the pool was created with ``PP_FLAG_DMA_MAP``.
> + * Note that this version performs DMA sync unconditionally, even if the
> + * associated PP doesn't perform sync-for-device.
> + */
> +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));
> +}
> +
>  static inline bool page_pool_put(struct page_pool *pool)
>  {
>         return refcount_dec_and_test(&pool->user_cnt);
> --
> 2.44.0
>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@...aro.org>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ