Linux block layer
 help / color / mirror / Atom feed
From: Ming Lei <tom.leiming@gmail.com>
To: linux-block@vger.kernel.org
Cc: Ming Lei <tom.leiming@gmail.com>, Jens Axboe <axboe@kernel.dk>,
	Caleb Sander Mateos <csander@purestorage.com>,
	Josef Bacik <josef@toxicpanda.com>
Subject: [PATCH v2 06/11] ublk: allow a NULL io->cmd in the cancel callback
Date: Thu,  8 Oct 2026 06:39:02 -0500	[thread overview]
Message-ID: <20261008113907.4000838-7-tom.leiming@gmail.com> (raw)
In-Reply-To: <20261008113907.4000838-1-tom.leiming@gmail.com>

A cancel from the control path, like STOP_DEV's ublk_cancel_dev() after
dropping ub->mutex, takes the command and clears io->cmd under
cancel_lock, then completes it with io_uring_cmd_done(), which takes
uring_lock to remove it from the cancelable list. The server's io_uring
cancel runs ublk_uring_cmd_cancel_fn() under uring_lock in between:

  control path cancel                    io_uring cancel (uring_lock)
  io->cmd = NULL, CANCELED
  io_uring_cmd_done()
    waits for uring_lock                 cmd still on the list
                                         ublk_uring_cmd_cancel_fn(cmd)
                                           io->cmd == NULL: WARN

ublk_cancel_cmd() then sees CANCELED and leaves the command alone, so
nothing is wrong; only warn if io->cmd holds another command.

Fixes: ab03a61c6614 ("ublk: have a per-io daemon instead of a per-queue daemon")
Tested-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/block/ublk_drv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 162a4d1a2e2a..2fd0c265ed20 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -2896,6 +2896,7 @@ static void ublk_uring_cmd_cancel_fn(struct io_uring_cmd *cmd,
 {
 	struct ublk_uring_cmd_pdu *pdu = ublk_get_uring_cmd_pdu(cmd);
 	struct ublk_queue *ubq = pdu->ubq;
+	struct io_uring_cmd *cur;
 	struct task_struct *task;
 	struct ublk_io *io;
 
@@ -2912,7 +2913,9 @@ static void ublk_uring_cmd_cancel_fn(struct io_uring_cmd *cmd,
 
 	ublk_start_cancel(ubq->dev);
 
-	WARN_ON_ONCE(io->cmd != cmd);
+	/* NULL if a cancel from the control path took it meanwhile */
+	cur = READ_ONCE(io->cmd);
+	WARN_ON_ONCE(cur && cur != cmd);
 	ublk_cancel_cmd(ubq, pdu->tag, issue_flags);
 }
 
-- 
2.55.0


  parent reply	other threads:[~2026-10-08 11:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08 11:38 [PATCH v2 00/11] ublk: don't dispatch to canceled io commands Ming Lei
2026-10-08 11:38 ` [PATCH v2 01/11] ublk: keep a canceled FETCH round canceling until the server is gone Ming Lei
2026-10-08 11:38 ` [PATCH v2 02/11] ublk: mark the io command cancelable before publishing it Ming Lei
2026-10-08 11:38 ` [PATCH v2 03/11] ublk: mark the batch fetch command cancelable before linking it Ming Lei
2026-10-08 11:39 ` [PATCH v2 04/11] ublk: reset the FETCH round in release also without a disk Ming Lei
2026-10-08 11:39 ` [PATCH v2 05/11] ublk: reset the FETCH round under ub->mutex Ming Lei
2026-10-08 11:39 ` Ming Lei [this message]
2026-10-08 11:39 ` [PATCH v2 07/11] ublk: let STOP_DEV cancel the server's commands before its release Ming Lei
2026-10-08 11:39 ` [PATCH v2 08/11] ublk: refuse to go live after an io command was canceled Ming Lei
2026-10-08 11:39 ` [PATCH v2 09/11] selftests: ublk: move the control command helpers into ctrl.c Ming Lei
2026-10-08 11:39 ` [PATCH v2 10/11] selftests: ublk: stop a batch thread when PREP_IO_CMDS fails Ming Lei
2026-10-08 11:39 ` [PATCH v2 11/11] selftests: ublk: add test for going live over canceled io commands 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=20261008113907.4000838-7-tom.leiming@gmail.com \
    --to=tom.leiming@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@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