Linux-Block Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] iov_iter: fix gap alignment check
@ 2020-05-21  2:28 Keith Busch
  0 siblings, 0 replies; only message in thread
From: Keith Busch @ 2020-05-21  2:28 UTC (permalink / raw)
  To: Alexander Viro, linux-block; +Cc: Jens Axboe, Keith Busch

The block layer uses the queue's virt_boundary to enforce alignment between
vectors, but iov_iter_gap_alignment() returned the starting address or'ed
with all but the last the length. Fix it to return alignment for each
vector's starting address except the first, and each vector's ending
address except the last.

Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 lib/iov_iter.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 51595bf3af85..9cfaf2fd5cfd 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1252,12 +1252,12 @@ unsigned long iov_iter_gap_alignment(const struct iov_iter *i)
 	}
 
 	iterate_all_kinds(i, size, v,
-		(res |= (!res ? 0 : (unsigned long)v.iov_base) |
-			(size != v.iov_len ? size : 0), 0),
-		(res |= (!res ? 0 : (unsigned long)v.bv_offset) |
-			(size != v.bv_len ? size : 0)),
-		(res |= (!res ? 0 : (unsigned long)v.iov_base) |
-			(size != v.iov_len ? size : 0))
+		(res |= (size == i->count ? 0 : (unsigned long)v.iov_base) |
+			(size == v.iov_len ? 0 : (unsigned long)v.iov_base + v.iov_len), 0),
+		res |= (size == i->count ? 0 : v.bv_offset) |
+		       (size == v.bv_len ? 0 : v.bv_offset + v.bv_len),
+		res |= (size == i->count ? 0 : (unsigned long)v.iov_base) |
+		       (size == v.iov_len ? 0 : (unsigned long)v.iov_base + v.iov_len)
 		);
 	return res;
 }
-- 
2.24.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-21  2:28 [PATCH] iov_iter: fix gap alignment check Keith Busch

Linux-Block Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-block/0 linux-block/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-block linux-block/ https://lore.kernel.org/linux-block \
		linux-block@vger.kernel.org
	public-inbox-index linux-block

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-block


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git