public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Caleb Sander Mateos <csander@purestorage.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org,
	Uday Shankar <ushankar@purestorage.com>
Subject: Re: [PATCH 05/16] ublk: move auto buffer register handling into one dedicated helper
Date: Mon, 7 Jul 2025 17:44:39 +0800	[thread overview]
Message-ID: <aGuXBzbLEreWzNJ_@fedora> (raw)
In-Reply-To: <CADUfDZpaNOqvqwMNUi_YavV9nHc8tkmPhZHKkx7UVk3W=Pbn6w@mail.gmail.com>

On Thu, Jul 03, 2025 at 04:19:50PM -0400, Caleb Sander Mateos wrote:
> On Wed, Jul 2, 2025 at 12:04 AM Ming Lei <ming.lei@redhat.com> wrote:
> >
> > Move check & clearing UBLK_IO_FLAG_AUTO_BUF_REG to
> > ublk_handle_auto_buf_reg(), also return buffer index from this helper.
> >
> > Also move ublk_set_auto_buf_reg() to this single helper too.
> >
> > Add ublk_config_io_buf() for setting up ublk io buffer, covers both
> > ublk buffer copy or auto buffer register.
> >
> > Signed-off-by: Ming Lei <ming.lei@redhat.com>
> > ---
> >  drivers/block/ublk_drv.c | 132 ++++++++++++++++++++++-----------------
> >  1 file changed, 76 insertions(+), 56 deletions(-)
> >
> > diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> > index 1780f9ce3a24..ba1b2672e7a8 100644
> > --- a/drivers/block/ublk_drv.c
> > +++ b/drivers/block/ublk_drv.c
> > @@ -48,6 +48,8 @@
> >
> >  #define UBLK_MINORS            (1U << MINORBITS)
> >
> > +#define UBLK_INVALID_BUF_IDX   ((unsigned short)-1)
> 
> u16?

Yeah.

> 
> > +
> >  /* private ioctl command mirror */
> >  #define UBLK_CMD_DEL_DEV_ASYNC _IOC_NR(UBLK_U_CMD_DEL_DEV_ASYNC)
> >  #define UBLK_CMD_UPDATE_SIZE   _IOC_NR(UBLK_U_CMD_UPDATE_SIZE)
> > @@ -1983,16 +1985,53 @@ static inline int ublk_check_cmd_op(u32 cmd_op)
> >         return 0;
> >  }
> >
> > +static inline int ublk_set_auto_buf_reg(struct io_uring_cmd *cmd)
> > +{
> > +       struct ublk_uring_cmd_pdu *pdu = ublk_get_uring_cmd_pdu(cmd);
> > +
> > +       pdu->buf = ublk_sqe_addr_to_auto_buf_reg(READ_ONCE(cmd->sqe->addr));
> > +
> > +       if (pdu->buf.reserved0 || pdu->buf.reserved1)
> > +               return -EINVAL;
> > +
> > +       if (pdu->buf.flags & ~UBLK_AUTO_BUF_REG_F_MASK)
> > +               return -EINVAL;
> > +       return 0;
> > +}
> > +
> > +static int ublk_handle_auto_buf_reg(struct ublk_io *io,
> > +                                   struct io_uring_cmd *cmd,
> > +                                   u16 *buf_idx)
> > +{
> > +       if (io->flags & UBLK_IO_FLAG_AUTO_BUF_REG) {
> > +               io->flags &= ~UBLK_IO_FLAG_AUTO_BUF_REG;
> > +
> > +               /*
> > +                * `UBLK_F_AUTO_BUF_REG` only works iff `UBLK_IO_FETCH_REQ`
> > +                * and `UBLK_IO_COMMIT_AND_FETCH_REQ` are issued from same
> > +                * `io_ring_ctx`.
> > +                *
> > +                * If this uring_cmd's io_ring_ctx isn't same with the
> > +                * one for registering the buffer, it is ublk server's
> > +                * responsibility for unregistering the buffer, otherwise
> > +                * this ublk request gets stuck.
> > +                */
> > +               if (io->buf_ctx_handle == io_uring_cmd_ctx_handle(cmd) &&
> > +                               buf_idx)
> 
> Not sure the buf_idx check here is necessary. This io->flags &
> UBLK_IO_FLAG_AUTO_BUF_REG path should only be reachable from
> ublk_commit_and_fetch(), not ublk_fetch() or UBLK_IO_NEED_GET_DATA.

Good catch, UBLK_IO_FLAG_AUTO_BUF_REG can only be set from
ublk_commit_and_fetch(), will fix it in next version.


Thanks,
Ming


  reply	other threads:[~2025-07-07  9:44 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-02  4:03 [PATCH 00/16] ublk: cleanup for supporting batch IO command Ming Lei
2025-07-02  4:03 ` [PATCH 01/16] ublk: move fake timeout logic into __ublk_complete_rq() Ming Lei
2025-07-03  2:23   ` Caleb Sander Mateos
2025-07-02  4:03 ` [PATCH 02/16] ublk: look up ublk task via its pid in timeout handler Ming Lei
2025-07-02  4:03 ` [PATCH 03/16] ublk: let ublk_fill_io_cmd() cover more things Ming Lei
2025-07-02  4:03 ` [PATCH 04/16] ublk: avoid to pass `struct ublksrv_io_cmd *` to ublk_commit_and_fetch() Ming Lei
2025-07-03  2:33   ` Caleb Sander Mateos
2025-07-02  4:03 ` [PATCH 05/16] ublk: move auto buffer register handling into one dedicated helper Ming Lei
2025-07-03 20:19   ` Caleb Sander Mateos
2025-07-07  9:44     ` Ming Lei [this message]
2025-07-02  4:03 ` [PATCH 06/16] ublk: store auto buffer register data into `struct ublk_io` Ming Lei
2025-07-08 12:15   ` Caleb Sander Mateos
2025-07-02  4:03 ` [PATCH 07/16] ublk: add helper ublk_check_fetch_buf() Ming Lei
2025-07-08 12:31   ` Caleb Sander Mateos
2025-07-13 14:13     ` Ming Lei
2025-07-02  4:03 ` [PATCH 08/16] ublk: remove ublk_commit_and_fetch() Ming Lei
2025-07-08 13:27   ` Caleb Sander Mateos
2025-07-09 11:56     ` Ming Lei
2025-07-11 14:05       ` Caleb Sander Mateos
2025-07-13 14:14         ` Ming Lei
2025-07-02  4:03 ` [PATCH 09/16] ublk: pass 'const struct ublk_io *' to ublk_[un]map_io() Ming Lei
2025-07-08 13:29   ` Caleb Sander Mateos
2025-07-02  4:03 ` [PATCH 10/16] selftests: ublk: remove `tag` parameter of ->tgt_io_done() Ming Lei
2025-07-02  4:03 ` [PATCH 11/16] selftests: ublk: pass 'ublk_thread *' to ->queue_io() and ->tgt_io_done() Ming Lei
2025-07-02  4:03 ` [PATCH 12/16] selftests: ublk: pass 'ublk_thread *' to more common helpers Ming Lei
2025-07-02  4:03 ` [PATCH 13/16] selftests: ublk: remove ublk queue self-defined flags Ming Lei
2025-07-02  4:03 ` [PATCH 14/16] selftests: ublk: improve flags naming Ming Lei
2025-07-02  4:03 ` [PATCH 15/16] selftests: ublk: add helper ublk_handle_uring_cmd() for handle ublk command Ming Lei
2025-07-02  4:03 ` [PATCH 16/16] selftests: ublk: add utils.h 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=aGuXBzbLEreWzNJ_@fedora \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=linux-block@vger.kernel.org \
    --cc=ushankar@purestorage.com \
    /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