Linux NFS development
 help / color / mirror / Atom feed
* Re: [PATCH 7/7] iov_iter: remove iov_iter_is_aligned
       [not found] ` <20250801234736.1913170-8-kbusch@meta.com>
@ 2025-08-02  2:02   ` Mike Snitzer
  2025-08-04 14:16     ` Keith Busch
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Snitzer @ 2025-08-02  2:02 UTC (permalink / raw)
  To: Keith Busch
  Cc: linux-block, linux-fsdevel, linux-kernel, axboe, dw, brauner,
	Keith Busch, Chuck Lever, linux-nfs

On Fri, Aug 01, 2025 at 04:47:36PM -0700, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
> 
> No more callers.
> 
> Signed-off-by: Keith Busch <kbusch@kernel.org>

You had me up until this last patch.

I'm actually making use of iov_iter_is_aligned() in a series of
changes for both NFS and NFSD.  Chuck has included some of the
NFSD changes in his nfsd-testing branch, see:
https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git/commit/?h=nfsd-testing&id=5d78ac1e674b45f9c9e3769b48efb27c44f4e4d3

And the balance of my work that is pending review/inclusion is:
https://lore.kernel.org/linux-nfs/20250731230633.89983-1-snitzer@kernel.org/
https://lore.kernel.org/linux-nfs/20250801171049.94235-1-snitzer@kernel.org/

I only need iov_iter_aligned_bvec, but recall I want to relax its
checking with this patch:
https://lore.kernel.org/linux-nfs/20250708160619.64800-5-snitzer@kernel.org/

Should I just add iov_iter_aligned_bvec() to fs/nfs_common/ so that
both NFS and NFSD can use it?

Thanks,
Mike

> ---
>  include/linux/uio.h |  2 -
>  lib/iov_iter.c      | 95 ---------------------------------------------
>  2 files changed, 97 deletions(-)
> 
> diff --git a/include/linux/uio.h b/include/linux/uio.h
> index 2e86c653186c6..5b127043a1519 100644
> --- a/include/linux/uio.h
> +++ b/include/linux/uio.h
> @@ -286,8 +286,6 @@ size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i);
>  #endif
>  
>  size_t iov_iter_zero(size_t bytes, struct iov_iter *);
> -bool iov_iter_is_aligned(const struct iov_iter *i, unsigned addr_mask,
> -			unsigned len_mask);
>  unsigned long iov_iter_alignment(const struct iov_iter *i);
>  unsigned long iov_iter_gap_alignment(const struct iov_iter *i);
>  void iov_iter_init(struct iov_iter *i, unsigned int direction, const struct iovec *iov,
> diff --git a/lib/iov_iter.c b/lib/iov_iter.c
> index f9193f952f499..2fe66a6b8789e 100644
> --- a/lib/iov_iter.c
> +++ b/lib/iov_iter.c
> @@ -784,101 +784,6 @@ void iov_iter_discard(struct iov_iter *i, unsigned int direction, size_t count)
>  }
>  EXPORT_SYMBOL(iov_iter_discard);
>  
> -static bool iov_iter_aligned_iovec(const struct iov_iter *i, unsigned addr_mask,
> -				   unsigned len_mask)
> -{
> -	const struct iovec *iov = iter_iov(i);
> -	size_t size = i->count;
> -	size_t skip = i->iov_offset;
> -
> -	do {
> -		size_t len = iov->iov_len - skip;
> -
> -		if (len > size)
> -			len = size;
> -		if (len & len_mask)
> -			return false;
> -		if ((unsigned long)(iov->iov_base + skip) & addr_mask)
> -			return false;
> -
> -		iov++;
> -		size -= len;
> -		skip = 0;
> -	} while (size);
> -
> -	return true;
> -}
> -
> -static bool iov_iter_aligned_bvec(const struct iov_iter *i, unsigned addr_mask,
> -				  unsigned len_mask)
> -{
> -	const struct bio_vec *bvec = i->bvec;
> -	unsigned skip = i->iov_offset;
> -	size_t size = i->count;
> -
> -	do {
> -		size_t len = bvec->bv_len - skip;
> -
> -		if (len > size)
> -			len = size;
> -		if (len & len_mask)
> -			return false;
> -		if ((unsigned long)(bvec->bv_offset + skip) & addr_mask)
> -			return false;
> -
> -		bvec++;
> -		size -= len;
> -		skip = 0;
> -	} while (size);
> -
> -	return true;
> -}
> -
> -/**
> - * iov_iter_is_aligned() - Check if the addresses and lengths of each segments
> - * 	are aligned to the parameters.
> - *
> - * @i: &struct iov_iter to restore
> - * @addr_mask: bit mask to check against the iov element's addresses
> - * @len_mask: bit mask to check against the iov element's lengths
> - *
> - * Return: false if any addresses or lengths intersect with the provided masks
> - */
> -bool iov_iter_is_aligned(const struct iov_iter *i, unsigned addr_mask,
> -			 unsigned len_mask)
> -{
> -	if (likely(iter_is_ubuf(i))) {
> -		if (i->count & len_mask)
> -			return false;
> -		if ((unsigned long)(i->ubuf + i->iov_offset) & addr_mask)
> -			return false;
> -		return true;
> -	}
> -
> -	if (likely(iter_is_iovec(i) || iov_iter_is_kvec(i)))
> -		return iov_iter_aligned_iovec(i, addr_mask, len_mask);
> -
> -	if (iov_iter_is_bvec(i))
> -		return iov_iter_aligned_bvec(i, addr_mask, len_mask);
> -
> -	/* With both xarray and folioq types, we're dealing with whole folios. */
> -	if (iov_iter_is_xarray(i)) {
> -		if (i->count & len_mask)
> -			return false;
> -		if ((i->xarray_start + i->iov_offset) & addr_mask)
> -			return false;
> -	}
> -	if (iov_iter_is_folioq(i)) {
> -		if (i->count & len_mask)
> -			return false;
> -		if (i->iov_offset & addr_mask)
> -			return false;
> -	}
> -
> -	return true;
> -}
> -EXPORT_SYMBOL_GPL(iov_iter_is_aligned);
> -
>  static unsigned long iov_iter_alignment_iovec(const struct iov_iter *i)
>  {
>  	const struct iovec *iov = iter_iov(i);
> -- 
> 2.47.3
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 7/7] iov_iter: remove iov_iter_is_aligned
  2025-08-02  2:02   ` [PATCH 7/7] iov_iter: remove iov_iter_is_aligned Mike Snitzer
@ 2025-08-04 14:16     ` Keith Busch
  2025-08-04 15:25       ` Mike Snitzer
  0 siblings, 1 reply; 6+ messages in thread
From: Keith Busch @ 2025-08-04 14:16 UTC (permalink / raw)
  To: Mike Snitzer
  Cc: Keith Busch, linux-block, linux-fsdevel, linux-kernel, axboe, dw,
	brauner, Chuck Lever, linux-nfs

On Fri, Aug 01, 2025 at 10:02:49PM -0400, Mike Snitzer wrote:
> On Fri, Aug 01, 2025 at 04:47:36PM -0700, Keith Busch wrote:
> > From: Keith Busch <kbusch@kernel.org>
> > 
> > No more callers.
> > 
> > Signed-off-by: Keith Busch <kbusch@kernel.org>
> 
> You had me up until this last patch.
> 
> I'm actually making use of iov_iter_is_aligned() in a series of
> changes for both NFS and NFSD.  Chuck has included some of the
> NFSD changes in his nfsd-testing branch, see:
> https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git/commit/?h=nfsd-testing&id=5d78ac1e674b45f9c9e3769b48efb27c44f4e4d3
> 
> And the balance of my work that is pending review/inclusion is:
> https://lore.kernel.org/linux-nfs/20250731230633.89983-1-snitzer@kernel.org/
> https://lore.kernel.org/linux-nfs/20250801171049.94235-1-snitzer@kernel.org/
> 
> I only need iov_iter_aligned_bvec, but recall I want to relax its
> checking with this patch:
> https://lore.kernel.org/linux-nfs/20250708160619.64800-5-snitzer@kernel.org/
> 
> Should I just add iov_iter_aligned_bvec() to fs/nfs_common/ so that
> both NFS and NFSD can use it?

If at all possible, I recommend finding a place that already walks the
vectors and do an opprotunistic check for the alignments there. This
will save CPU cycles. For example, nfsd_iter_read already iterates the
bvec while setting each page. Could you check the alignment while doing
that instead of iterating a second time immediately after?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 7/7] iov_iter: remove iov_iter_is_aligned
  2025-08-04 14:16     ` Keith Busch
@ 2025-08-04 15:25       ` Mike Snitzer
  2025-08-04 15:27         ` Mike Snitzer
  2025-08-04 22:26         ` Mike Snitzer
  0 siblings, 2 replies; 6+ messages in thread
From: Mike Snitzer @ 2025-08-04 15:25 UTC (permalink / raw)
  To: Keith Busch
  Cc: Keith Busch, linux-block, linux-fsdevel, linux-kernel, axboe, dw,
	brauner, Chuck Lever, linux-nfs

On Mon, Aug 04, 2025 at 08:16:39AM -0600, Keith Busch wrote:
> On Fri, Aug 01, 2025 at 10:02:49PM -0400, Mike Snitzer wrote:
> > On Fri, Aug 01, 2025 at 04:47:36PM -0700, Keith Busch wrote:
> > > From: Keith Busch <kbusch@kernel.org>
> > > 
> > > No more callers.
> > > 
> > > Signed-off-by: Keith Busch <kbusch@kernel.org>
> > 
> > You had me up until this last patch.
> > 
> > I'm actually making use of iov_iter_is_aligned() in a series of
> > changes for both NFS and NFSD.  Chuck has included some of the
> > NFSD changes in his nfsd-testing branch, see:
> > https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git/commit/?h=nfsd-testing&id=5d78ac1e674b45f9c9e3769b48efb27c44f4e4d3
> > 
> > And the balance of my work that is pending review/inclusion is:
> > https://lore.kernel.org/linux-nfs/20250731230633.89983-1-snitzer@kernel.org/
> > https://lore.kernel.org/linux-nfs/20250801171049.94235-1-snitzer@kernel.org/
> > 
> > I only need iov_iter_aligned_bvec, but recall I want to relax its
> > checking with this patch:
> > https://lore.kernel.org/linux-nfs/20250708160619.64800-5-snitzer@kernel.org/
> > 
> > Should I just add iov_iter_aligned_bvec() to fs/nfs_common/ so that
> > both NFS and NFSD can use it?
> 
> If at all possible, I recommend finding a place that already walks the
> vectors and do an opprotunistic check for the alignments there. This
> will save CPU cycles. For example, nfsd_iter_read already iterates the
> bvec while setting each page. Could you check the alignment while doing
> that instead of iterating a second time immediately after?

Nice goal, I'll see if I can pull it off.

I'm currently using iov_iter_is_aligned() in 3 new call sites (for
READ and WRITE) in both NFS and NFSD: nfs_local_iter_init,
nfsd_iter_read, nfsd_vfs_write

nfsd_vfs_write is the only one that doesn't iterate the bvec as-is,
but it does work that _should_ obviate the need to doable check the
alignment.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 7/7] iov_iter: remove iov_iter_is_aligned
  2025-08-04 15:25       ` Mike Snitzer
@ 2025-08-04 15:27         ` Mike Snitzer
  2025-08-04 22:26         ` Mike Snitzer
  1 sibling, 0 replies; 6+ messages in thread
From: Mike Snitzer @ 2025-08-04 15:27 UTC (permalink / raw)
  To: Keith Busch
  Cc: Keith Busch, linux-block, linux-fsdevel, linux-kernel, axboe, dw,
	brauner, Chuck Lever, linux-nfs

On Mon, Aug 04, 2025 at 11:25:08AM -0400, Mike Snitzer wrote:
> On Mon, Aug 04, 2025 at 08:16:39AM -0600, Keith Busch wrote:
> > On Fri, Aug 01, 2025 at 10:02:49PM -0400, Mike Snitzer wrote:
> > > On Fri, Aug 01, 2025 at 04:47:36PM -0700, Keith Busch wrote:
> > > > From: Keith Busch <kbusch@kernel.org>
> > > > 
> > > > No more callers.
> > > > 
> > > > Signed-off-by: Keith Busch <kbusch@kernel.org>
> > > 
> > > You had me up until this last patch.
> > > 
> > > I'm actually making use of iov_iter_is_aligned() in a series of
> > > changes for both NFS and NFSD.  Chuck has included some of the
> > > NFSD changes in his nfsd-testing branch, see:
> > > https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git/commit/?h=nfsd-testing&id=5d78ac1e674b45f9c9e3769b48efb27c44f4e4d3
> > > 
> > > And the balance of my work that is pending review/inclusion is:
> > > https://lore.kernel.org/linux-nfs/20250731230633.89983-1-snitzer@kernel.org/
> > > https://lore.kernel.org/linux-nfs/20250801171049.94235-1-snitzer@kernel.org/
> > > 
> > > I only need iov_iter_aligned_bvec, but recall I want to relax its
> > > checking with this patch:
> > > https://lore.kernel.org/linux-nfs/20250708160619.64800-5-snitzer@kernel.org/
> > > 
> > > Should I just add iov_iter_aligned_bvec() to fs/nfs_common/ so that
> > > both NFS and NFSD can use it?
> > 
> > If at all possible, I recommend finding a place that already walks the
> > vectors and do an opprotunistic check for the alignments there. This
> > will save CPU cycles. For example, nfsd_iter_read already iterates the
> > bvec while setting each page. Could you check the alignment while doing
> > that instead of iterating a second time immediately after?
> 
> Nice goal, I'll see if I can pull it off.
> 
> I'm currently using iov_iter_is_aligned() in 3 new call sites (for
> READ and WRITE) in both NFS and NFSD: nfs_local_iter_init,
> nfsd_iter_read, nfsd_vfs_write
> 
> nfsd_vfs_write is the only one that doesn't iterate the bvec as-is,
> but it does work that _should_ obviate the need to doable check the
> alignment.

Freudian typo: s/doable/double/ :)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 7/7] iov_iter: remove iov_iter_is_aligned
  2025-08-04 15:25       ` Mike Snitzer
  2025-08-04 15:27         ` Mike Snitzer
@ 2025-08-04 22:26         ` Mike Snitzer
  2025-08-04 22:57           ` Keith Busch
  1 sibling, 1 reply; 6+ messages in thread
From: Mike Snitzer @ 2025-08-04 22:26 UTC (permalink / raw)
  To: Keith Busch
  Cc: Keith Busch, linux-block, linux-fsdevel, linux-kernel, axboe, dw,
	brauner, Chuck Lever, linux-nfs

On Mon, Aug 04, 2025 at 11:25:08AM -0400, Mike Snitzer wrote:
> On Mon, Aug 04, 2025 at 08:16:39AM -0600, Keith Busch wrote:
> > On Fri, Aug 01, 2025 at 10:02:49PM -0400, Mike Snitzer wrote:
> > > On Fri, Aug 01, 2025 at 04:47:36PM -0700, Keith Busch wrote:
> > > > From: Keith Busch <kbusch@kernel.org>
> > > > 
> > > > No more callers.
> > > > 
> > > > Signed-off-by: Keith Busch <kbusch@kernel.org>
> > > 
> > > You had me up until this last patch.
> > > 
> > > I'm actually making use of iov_iter_is_aligned() in a series of
> > > changes for both NFS and NFSD.  Chuck has included some of the
> > > NFSD changes in his nfsd-testing branch, see:
> > > https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git/commit/?h=nfsd-testing&id=5d78ac1e674b45f9c9e3769b48efb27c44f4e4d3
> > > 
> > > And the balance of my work that is pending review/inclusion is:
> > > https://lore.kernel.org/linux-nfs/20250731230633.89983-1-snitzer@kernel.org/
> > > https://lore.kernel.org/linux-nfs/20250801171049.94235-1-snitzer@kernel.org/
> > > 
> > > I only need iov_iter_aligned_bvec, but recall I want to relax its
> > > checking with this patch:
> > > https://lore.kernel.org/linux-nfs/20250708160619.64800-5-snitzer@kernel.org/
> > > 
> > > Should I just add iov_iter_aligned_bvec() to fs/nfs_common/ so that
> > > both NFS and NFSD can use it?
> > 
> > If at all possible, I recommend finding a place that already walks the
> > vectors and do an opprotunistic check for the alignments there. This
> > will save CPU cycles. For example, nfsd_iter_read already iterates the
> > bvec while setting each page. Could you check the alignment while doing
> > that instead of iterating a second time immediately after?
> 
> Nice goal, I'll see if I can pull it off.
> 
> I'm currently using iov_iter_is_aligned() in 3 new call sites (for
> READ and WRITE) in both NFS and NFSD: nfs_local_iter_init,
> nfsd_iter_read, nfsd_vfs_write
> 
> nfsd_vfs_write is the only one that doesn't iterate the bvec as-is,
> but it does work that _should_ obviate the need to doable check the
> alignment.

FYI, I was able to avoid using iov_iter_is_aligned() in favor of
checks in earlier code (in both NFSD and NFS).

Thanks,
Mike

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 7/7] iov_iter: remove iov_iter_is_aligned
  2025-08-04 22:26         ` Mike Snitzer
@ 2025-08-04 22:57           ` Keith Busch
  0 siblings, 0 replies; 6+ messages in thread
From: Keith Busch @ 2025-08-04 22:57 UTC (permalink / raw)
  To: Mike Snitzer
  Cc: Keith Busch, linux-block, linux-fsdevel, linux-kernel, axboe, dw,
	brauner, Chuck Lever, linux-nfs

On Mon, Aug 04, 2025 at 06:26:55PM -0400, Mike Snitzer wrote:
> FYI, I was able to avoid using iov_iter_is_aligned() in favor of
> checks in earlier code (in both NFSD and NFS).

Excellent! I promise removing the extra iteration is totally worth it. ;)

I just know of one error case bug mentioned in patch 2, so unless I hear
anything else, I'll spin out the new version with a fix for just that
tomorrow.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-08-04 22:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250801234736.1913170-1-kbusch@meta.com>
     [not found] ` <20250801234736.1913170-8-kbusch@meta.com>
2025-08-02  2:02   ` [PATCH 7/7] iov_iter: remove iov_iter_is_aligned Mike Snitzer
2025-08-04 14:16     ` Keith Busch
2025-08-04 15:25       ` Mike Snitzer
2025-08-04 15:27         ` Mike Snitzer
2025-08-04 22:26         ` Mike Snitzer
2025-08-04 22:57           ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox