linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@kernel.org>
To: Alexander Viro <viro@zeniv.linux.org.uk>, linux-block@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>, Keith Busch <kbusch@kernel.org>
Subject: [PATCH] iov_iter: fix gap alignment check
Date: Wed, 20 May 2020 19:28:26 -0700	[thread overview]
Message-ID: <20200521022826.3268432-1-kbusch@kernel.org> (raw)

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


                 reply	other threads:[~2020-05-21  2:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200521022826.3268432-1-kbusch@kernel.org \
    --to=kbusch@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).