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] [thread-next>] [day] [month] [year] [list]
Message-ID: <waid6zxayuxacb6sntlxwgyjia3w25sfz2tzxxzb4tkqgmx63o@ndpztxeh6o32>
Date: Mon, 10 Nov 2025 09:05:26 -0600
From: Bjorn Andersson <andersson@...nel.org>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: Stefan Wahren <wahrenst@....net>, Vinod Koul <vkoul@...nel.org>, 
	Thomas Andreatta <thomasandreatta2000@...il.com>, Caleb Sander Mateos <csander@...estorage.com>, 
	dmaengine@...r.kernel.org, linux-kernel@...r.kernel.org, 
	linux-rpi-kernel@...ts.infradead.org, linux-arm-kernel@...ts.infradead.org, 
	linux-arm-msm@...r.kernel.org, Olivier Dautricourt <olivierdautricourt@...il.com>, 
	Stefan Roese <sr@...x.de>, Florian Fainelli <florian.fainelli@...adcom.com>, 
	Broadcom internal kernel review list <bcm-kernel-feedback-list@...adcom.com>, Ray Jui <rjui@...adcom.com>, 
	Scott Branden <sbranden@...adcom.com>, Lars-Peter Clausen <lars@...afoo.de>, 
	Eugeniy Paltsev <Eugeniy.Paltsev@...opsys.com>, Daniel Mack <daniel@...que.org>, 
	Haojian Zhuang <haojian.zhuang@...il.com>, Robert Jarzmik <robert.jarzmik@...e.fr>, 
	Lizhi Hou <lizhi.hou@....com>, Brian Xu <brian.xu@....com>, 
	Raj Kumar Rampelli <raj.kumar.rampelli@....com>, Michal Simek <michal.simek@....com>, 
	Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH v2 01/13] scatterlist: introduce sg_nents_for_dma() helper

On Mon, Nov 10, 2025 at 11:23:28AM +0100, Andy Shevchenko wrote:
> Sometimes the user needs to split each entry on the mapped scatter list
> due to DMA length constrains. This helper returns a number of entities
> assuming that each of them is not bigger than supplied maximum length.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
> ---
>  include/linux/scatterlist.h |  2 ++
>  lib/scatterlist.c           | 25 +++++++++++++++++++++++++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
> index 29f6ceb98d74..6de1a2434299 100644
> --- a/include/linux/scatterlist.h
> +++ b/include/linux/scatterlist.h
> @@ -441,6 +441,8 @@ static inline void sg_init_marker(struct scatterlist *sgl,
>  
>  int sg_nents(struct scatterlist *sg);
>  int sg_nents_for_len(struct scatterlist *sg, u64 len);
> +int sg_nents_for_dma(struct scatterlist *sgl, unsigned int sglen, size_t len);
> +
>  struct scatterlist *sg_last(struct scatterlist *s, unsigned int);
>  void sg_init_table(struct scatterlist *, unsigned int);
>  void sg_init_one(struct scatterlist *, const void *, unsigned int);
> diff --git a/lib/scatterlist.c b/lib/scatterlist.c
> index 4af1c8b0775a..4d1a010f863c 100644
> --- a/lib/scatterlist.c
> +++ b/lib/scatterlist.c
> @@ -64,6 +64,31 @@ int sg_nents_for_len(struct scatterlist *sg, u64 len)
>  }
>  EXPORT_SYMBOL(sg_nents_for_len);
>  
> +/**
> + * sg_nents_for_dma - return the count of DMA-capable entries in scatterlist
> + * @sgl:	The scatterlist
> + * @sglen:	The current number of entries
> + * @len:	The maximum length of DMA-capable block
> + *
> + * Description:
> + * Determines the number of entries in @sgl which would be permitted in
> + * DMA-capable transfer if list had been split accordingly, taking into
> + * account chaining as well.
> + *
> + * Returns:
> + *   the number of sgl entries needed
> + *
> + **/
> +int sg_nents_for_dma(struct scatterlist *sgl, unsigned int sglen, size_t len)
> +{
> +	struct scatterlist *sg;
> +	int i, nents = 0;
> +
> +	for_each_sg(sgl, sg, sglen, i)
> +		nents += DIV_ROUND_UP(sg_dma_len(sg), len);
> +	return nents;
> +}

We need an EXPORT_SYMBOL() here.

With that, this looks good to me.

Reviewed-by: Bjorn Andersson <andersson@...nel.org>

Regards,
Bjorn

> +
>  /**
>   * sg_last - return the last scatterlist entry in a list
>   * @sgl:	First entry in the scatterlist
> -- 
> 2.50.1
> 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ