Linux block layer
 help / color / mirror / Atom feed
From: Ming Lei <tom.leiming@gmail.com>
To: Caleb Sander Mateos <csander@purestorage.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/5] ublk: fail READ/WRITE if the result from the server is invalid
Date: Mon, 30 Nov 2026 20:09:21 -0600	[thread overview]
Message-ID: <aw4sUdNVBKwz5sWT@fedora-laptop> (raw)
In-Reply-To: <CADUfDZqB2rAQFXH1FgLbUpW7g=h80ZVYaeoyv_EDQn95rrVYoA@mail.gmail.com>

On Mon, Nov 30, 2026 at 10:00:42AM -0800, Caleb Sander Mateos wrote:
> On Sun, Nov 29, 2026 at 6:39 PM Ming Lei <tom.leiming@gmail.com> wrote:
> >
> > __ublk_complete_rq() passes io->res from the server straight to
> > blk_update_request(). If it isn't a multiple of the logical block size,
> > the data moves by io->res bytes but the start sector by io->res >> 9,
> > so the requeued rest is read or written at the wrong place.
> >
> > Fail a READ or WRITE with -EIO if io->res isn't a multiple of the
> > logical block size or is larger than the request, as is already done
> > for a READ that returns 0. Fail a WRITE that returns 0 too, so that it
> > can't be requeued forever once a short WRITE is completed by io->res
> > again.
> >
> > The byte count of a READ's data that is copied only in part from the
> > server's buffer has the same problem. Fail the READ if that count isn't
> > a multiple of the logical block size.
> >
> > Fixes: 71f28f3136af ("ublk_drv: add io_uring based userspace block driver")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Ming Lei <tom.leiming@gmail.com>
> > ---
> >  drivers/block/ublk_drv.c | 16 +++++++++++++---
> >  1 file changed, 13 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> > index 0699f22714fd..db1b049b7ac0 100644
> > --- a/drivers/block/ublk_drv.c
> > +++ b/drivers/block/ublk_drv.c
> > @@ -1577,8 +1577,16 @@ static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io,
> >         blk_status_t res = BLK_STS_OK;
> >         bool requeue;
> >
> > -       /* failed read IO if nothing is read */
> > -       if (!io->res && req_op(req) == REQ_OP_READ)
> > +       /*
> > +        * The result of READ and WRITE is the number of bytes done. A short
> > +        * one has to be whole logical blocks, so that a requeued rest starts
> > +        * at the right sector. Fail anything else: more than the request, not
> > +        * aligned, or nothing done.
> > +        */
> > +       if ((req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_WRITE) &&
> 
> Are these the only I/O types that need to be checked? Looks like
> partial ZONE_APPEND operations are failed in blk_update_request(), but

Patch 4 fails res < blk_rq_bytes(req) for ZONE_APPEND.

> do we still need to validate that io->res <= blk_rq_bytes(req)? How
> about for DISCARD, WRITE_ZEROES, and DRV_IN (for the zone report)? And
> what about requests without data (FLUSH, zone management, etc.)?

Yes, for correctness. Only READ and WRITE pass io->res to blk_update_request(). Every
other op goes to exit: and ublk_end_request(req, res), where only the sign of io->res
matters, so an oversized or unaligned value can't misplace anything.

> 
> > +           io->res >= 0 && unlikely(io->res != blk_rq_bytes(req)) &&
> 
> Move the unlikely() branch first?

Agree, will do.

Thanks,
Ming

  reply	other threads:[~2026-12-01  2:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  2:39 [PATCH 0/5] ublk: fix completion of short READ/WRITE Ming Lei
2026-11-30  2:39 ` [PATCH 1/5] ublk: fail READ/WRITE if the result from the server is invalid Ming Lei
2026-11-30 18:00   ` Caleb Sander Mateos
2026-12-01  2:09     ` Ming Lei [this message]
2026-11-30  2:39 ` [PATCH 2/5] selftests: ublk: complete a striped request with its full length Ming Lei
2026-11-30 18:04   ` Caleb Sander Mateos
2026-11-30  2:39 ` [PATCH 3/5] ublk: don't complete a short request in full Ming Lei
2026-11-30  2:39 ` [PATCH 4/5] ublk: fail a short zone append Ming Lei
2026-11-30  2:39 ` [PATCH 5/5] selftests: ublk: test that a short request isn't completed in full Ming Lei

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=aw4sUdNVBKwz5sWT@fedora-laptop \
    --to=tom.leiming@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.org \
    /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