From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrey Zhadchenko Date: Wed, 19 Aug 2026 00:57:39 +0200 Subject: Re: [Devel] [PATCH VZ10 4/5] drivers/vhost/blk: fix sector alignment calculation In-Reply-To: <20260818150920.13123-5-andrey.zhadchenko@virtuozzo.com> References: <20260818150920.13123-1-andrey.zhadchenko@virtuozzo.com> <20260818150920.13123-5-andrey.zhadchenko@virtuozzo.com> Message-ID: <183b3c0d-8031-4cd2-9c7a-8fa6d6cb7af5@virtuozzo.com> List-Id: Actually for v2 I will replace manual calculations with IS_ALIGNED macro so we don't step on this again. On 8/18/26 17:09, Andrey Zhadchenko wrote: > SECTOR_MASK is actually a number 7, not some bitmask. Hence > the code actually checked 8 byte alignment. > Use (SECTOR_SIZE - 1) to correctly check sector alignment. > > https://virtuozzo.atlassian.net/browse/VSTOR-138640 > Fixes: a0d3b8956fb0 ("vhost-blk: rework iov and bio handling") > Signed-off-by: Andrey Zhadchenko > --- > drivers/vhost/blk.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c > index 43bc122ff17e3..2f94c987c62d8 100644 > --- a/drivers/vhost/blk.c > +++ b/drivers/vhost/blk.c > @@ -209,13 +209,13 @@ inline static bool vhost_blk_iov_need_bb(struct vhost_blk_req *req) > { > int i; > > - if (req->len & SECTOR_MASK) > + if (req->len & (SECTOR_SIZE - 1)) > return true; > > for (i = 0; i < req->iov_nr; i++) { > - if (((size_t)req->iov[i].iov_base) & SECTOR_MASK) > + if (((size_t)req->iov[i].iov_base) & (SECTOR_SIZE - 1)) > return true; > - if (req->iov[i].iov_len & SECTOR_MASK) > + if (req->iov[i].iov_len & (SECTOR_SIZE - 1)) > return true; > } > > @@ -277,7 +277,7 @@ static int vhost_blk_bio_make(struct vhost_blk_req *req, > if (unlikely(req->bi_opf & REQ_PREFLUSH)) > return vhost_blk_bio_make_simple(req, bdev); > > - if (req->bi_opf == REQ_OP_WRITE && req->len & SECTOR_MASK) { > + if (req->bi_opf == REQ_OP_WRITE && req->len & (SECTOR_SIZE - 1)) { > WARN_ONCE(1, "vhost-blk: write requests with unaligned len" > " are not supported, len = %zu", req->len); > return -EINVAL; > @@ -339,7 +339,7 @@ static int vhost_blk_bio_make(struct vhost_blk_req *req, > nr_pages = bio_iov_vecs_to_alloc(&iter, BIO_MAX_VECS); > do { > /* We can't handle next bio if it's start is not sector aligned */ > - if (pos & SECTOR_MASK) { > + if (pos & (SECTOR_SIZE - 1)) { > WARN_ONCE(1, "vhost-blk: guest provided unaligned buffers"); > ret = -EINVAL; > goto err_bio;