From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Nadav Amit <nadav.amit@gmail.com>,
linux-block@vger.kernel.org, ming.lei@redhat.com
Subject: Re: Potential hang on ublk_ctrl_del_dev()
Date: Wed, 4 Jan 2023 15:50:11 +0800 [thread overview]
Message-ID: <Y7Uvs6uGJbzsxpE5@T590> (raw)
In-Reply-To: <974410c0-46e8-c240-388c-9b0c339fcd09@kernel.dk>
On Tue, Jan 03, 2023 at 02:51:20PM -0700, Jens Axboe wrote:
> On 1/3/23 2:47?PM, Nadav Amit wrote:
> > Hello Ming,
> >
> > I am trying the ublk and it seems very exciting.
> >
> > However, I encounter an issue when I remove a ublk device that is mounted or
> > in use.
> >
> > In ublk_ctrl_del_dev(), shouldn?t we *not* wait if ublk_idr_freed() is false?
> > It seems to me that it is saner to return -EBUSY in such a case and let
> > userspace deal with the results.
> >
> > For instance, if I run the following (using ubdsrv):
> >
> > $ mkfs.ext4 /dev/ram0
> > $ ./ublk add -t loop -f /dev/ram0
> > $ sudo mount /dev/ublkb0 tmp
> > $ sudo ./ublk del -a
> >
> > ublk_ctrl_del_dev() would not be done until the partition is unmounted, and you
> > can get a splat that is similar to the one below.
> >
> > What do you say? Would you agree to change the behavior to return -EBUSY?
> >
> > Thanks,
> > Nadav
> >
> >
> > [ 974.149938] INFO: task ublk:2250 blocked for more than 120 seconds.
> > [ 974.157786] Not tainted 6.1.0 #30
> > [ 974.162369] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
> > [ 974.171417] task:ublk state:D stack:0 pid:2250 ppid:2249 flags:0x00004004
> > [ 974.181054] Call Trace:
> > [ 974.184097] <TASK>
> > [ 974.186726] __schedule+0x37e/0xe10
> > [ 974.190915] ? __this_cpu_preempt_check+0x13/0x20
> > [ 974.196463] ? lock_release+0x133/0x2a0
> > [ 974.201043] schedule+0x67/0xe0
> > [ 974.204846] ublk_ctrl_uring_cmd+0xf45/0x1110
> > [ 974.210016] ? lock_is_held_type+0xdd/0x130
> > [ 974.214990] ? var_wake_function+0x60/0x60
> > [ 974.219872] ? rcu_read_lock_sched_held+0x4f/0x80
> > [ 974.225443] io_uring_cmd+0x9a/0x130
> > [ 974.229743] ? io_uring_cmd_prep+0xf0/0xf0
> > [ 974.234638] io_issue_sqe+0xfe/0x340
> > [ 974.238946] io_submit_sqes+0x231/0x750
> > [ 974.243553] __x64_sys_io_uring_enter+0x22b/0x640
> > [ 974.249134] ? trace_hardirqs_on+0x3c/0xe0
> > [ 974.254042] do_syscall_64+0x35/0x80
> > [ 974.258361] entry_SYSCALL_64_after_hwframe+0x46/0xb0
>
> Ming, this also looks like ublk doesn't always honor
> IO_URING_F_NONBLOCK, we can't be sleeping like that under issue. Then it
> should be bounced with -EAGAIN and retried from an io-wq worker.
Yeah, you are right, and looks the following change is needed and all
ublk control commands are actually handled in sync style from userspace.
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 144eda037646..8011ae1f20d5 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -2264,6 +2264,9 @@ static int ublk_ctrl_uring_cmd(struct io_uring_cmd *cmd,
struct ublk_device *ub = NULL;
int ret = -EINVAL;
+ if (issue_flags & IO_URING_F_NONBLOCK)
+ return -EAGAIN;
+
ublk_ctrl_cmd_dump(cmd);
if (!(issue_flags & IO_URING_F_SQE128))
thanks,
Ming
next prev parent reply other threads:[~2023-01-04 7:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-03 21:47 Potential hang on ublk_ctrl_del_dev() Nadav Amit
2023-01-03 21:51 ` Jens Axboe
2023-01-04 7:50 ` Ming Lei [this message]
2023-01-04 5:42 ` Ming Lei
2023-01-04 18:13 ` Nadav Amit
2023-01-05 3:16 ` Ming Lei
2023-01-05 17:52 ` Nadav Amit
2023-01-06 1:40 ` 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=Y7Uvs6uGJbzsxpE5@T590 \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=nadav.amit@gmail.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;
as well as URLs for NNTP newsgroup(s).