All of lore.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 V3 01/17] ublk: validate ublk server pid
Date: Wed, 16 Jul 2025 06:39:30 +0800	[thread overview]
Message-ID: <aHbYosQjY2cxkH2b@fedora> (raw)
In-Reply-To: <CADUfDZq86kMtc=OLCK6jUNwgRf6+VTmVqzHXqyD+5zK0FEqfSw@mail.gmail.com>

On Tue, Jul 15, 2025 at 11:48:12AM -0400, Caleb Sander Mateos wrote:
> On Tue, Jul 15, 2025 at 11:42 AM Ming Lei <ming.lei@redhat.com> wrote:
> >
> > On Tue, Jul 15, 2025 at 10:50:39AM -0400, Caleb Sander Mateos wrote:
> > > On Sun, Jul 13, 2025 at 10:34 AM Ming Lei <ming.lei@redhat.com> wrote:
> > > >
> > > > ublk server pid(the `tgid` of the process opening the ublk device) is stored
> > > > in `ublk_device->ublksrv_tgid`. This `tgid` is then checked against the
> > > > `ublksrv_pid` in `ublk_ctrl_start_dev` and `ublk_ctrl_end_recovery`.
> > > >
> > > > This ensures that correct ublk server pid is stored in device info.
> > > >
> > > > Fixes: 71f28f3136af ("ublk_drv: add io_uring based userspace block driver")
> > > > Signed-off-by: Ming Lei <ming.lei@redhat.com>
> > > > ---
> > > >  drivers/block/ublk_drv.c | 9 +++++++++
> > > >  1 file changed, 9 insertions(+)
> > > >
> > > > diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> > > > index a1a700c7e67a..2b894de29823 100644
> > > > --- a/drivers/block/ublk_drv.c
> > > > +++ b/drivers/block/ublk_drv.c
> > > > @@ -237,6 +237,7 @@ struct ublk_device {
> > > >         unsigned int            nr_privileged_daemon;
> > > >         struct mutex cancel_mutex;
> > > >         bool canceling;
> > > > +       pid_t   ublksrv_tgid;
> > > >  };
> > > >
> > > >  /* header of ublk_params */
> > > > @@ -1528,6 +1529,7 @@ static int ublk_ch_open(struct inode *inode, struct file *filp)
> > > >         if (test_and_set_bit(UB_STATE_OPEN, &ub->state))
> > > >                 return -EBUSY;
> > > >         filp->private_data = ub;
> > > > +       ub->ublksrv_tgid = current->tgid;
> > > >         return 0;
> > > >  }
> > > >
> > > > @@ -1542,6 +1544,7 @@ static void ublk_reset_ch_dev(struct ublk_device *ub)
> > > >         ub->mm = NULL;
> > > >         ub->nr_queues_ready = 0;
> > > >         ub->nr_privileged_daemon = 0;
> > > > +       ub->ublksrv_tgid = -1;
> > >
> > > Should this be reset to 0? The next patch checks whether ublksrv_tgid
> > > is 0 in ublk_timeout().
> >
> > No, swapper pid is 0.
> >
> > The check in next patch just tries to double check if ublk char device
> > is opened.
> >
> > > Also, the accesses to it should probably be
> > > using {READ,WRITE}_ONCE() since ublk server open/close can happen
> > > concurrently with ublk I/O timeout handling.
> >
> > ublk_abort_queue() is called in ublk_ch_release(), and any inflight request
> > is either requeued or failed, so ublk I/O timeout handling won't happen
> > concurrently with ublk char open()/close().
> 
> Thanks for explaining. If the ublk server closing the char device
> ensures there are no in-flight requests, does that make the
> ublksrv_tgid check in ublk_timeout() unnecessary?

Yes, the check should have been WARN_ON_ONCE().

Thanks,
Ming


  reply	other threads:[~2025-07-15 22:39 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-13 14:33 [PATCH V3 00/17] ublk: cleanup for supporting batch IO command Ming Lei
2025-07-13 14:33 ` [PATCH V3 01/17] ublk: validate ublk server pid Ming Lei
2025-07-15 14:50   ` Caleb Sander Mateos
2025-07-15 15:42     ` Ming Lei
2025-07-15 15:48       ` Caleb Sander Mateos
2025-07-15 22:39         ` Ming Lei [this message]
2025-07-13 14:33 ` [PATCH V3 02/17] ublk: look up ublk task via its pid in timeout handler Ming Lei
2025-07-13 14:33 ` [PATCH V3 03/17] ublk: move fake timeout logic into __ublk_complete_rq() Ming Lei
2025-07-13 14:33 ` [PATCH V3 04/17] ublk: let ublk_fill_io_cmd() cover more things Ming Lei
2025-07-15 15:22   ` Caleb Sander Mateos
2025-07-13 14:34 ` [PATCH V3 05/17] ublk: avoid to pass `struct ublksrv_io_cmd *` to ublk_commit_and_fetch() Ming Lei
2025-07-13 14:34 ` [PATCH V3 06/17] ublk: move auto buffer register handling into one dedicated helper Ming Lei
2025-07-13 14:34 ` [PATCH V3 07/17] ublk: store auto buffer register data into `struct ublk_io` Ming Lei
2025-07-13 14:34 ` [PATCH V3 08/17] ublk: add helper ublk_check_fetch_buf() Ming Lei
2025-07-13 14:34 ` [PATCH V3 09/17] ublk: remove ublk_commit_and_fetch() Ming Lei
2025-07-15 15:38   ` Caleb Sander Mateos
2025-07-13 14:34 ` [PATCH V3 10/17] ublk: pass 'const struct ublk_io *' to ublk_[un]map_io() Ming Lei
2025-07-13 14:34 ` [PATCH V3 11/17] selftests: ublk: remove `tag` parameter of ->tgt_io_done() Ming Lei
2025-07-13 14:34 ` [PATCH V3 12/17] selftests: ublk: pass 'ublk_thread *' to ->queue_io() and ->tgt_io_done() Ming Lei
2025-07-13 14:34 ` [PATCH V3 13/17] selftests: ublk: pass 'ublk_thread *' to more common helpers Ming Lei
2025-07-13 14:34 ` [PATCH V3 14/17] selftests: ublk: remove ublk queue self-defined flags Ming Lei
2025-07-13 14:34 ` [PATCH V3 15/17] selftests: ublk: improve flags naming Ming Lei
2025-07-13 14:34 ` [PATCH V3 16/17] selftests: ublk: add helper ublk_handle_uring_cmd() for handle ublk command Ming Lei
2025-07-13 14:34 ` [PATCH V3 17/17] selftests: ublk: add utils.h Ming Lei
2025-07-15 14:07 ` [PATCH V3 00/17] ublk: cleanup for supporting batch IO command Jens Axboe

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=aHbYosQjY2cxkH2b@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.