From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Caleb Sander Mateos <csander@purestorage.com>,
Uday Shankar <ushankar@purestorage.com>,
Alexander Atanasov <alex@zazolabs.com>,
Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 1/5] ublk: check list membership before cancelling batch fetch command
Date: Thu, 29 Jan 2026 11:14:55 +0800 [thread overview]
Message-ID: <20260129031501.3403688-2-ming.lei@redhat.com> (raw)
In-Reply-To: <20260129031501.3403688-1-ming.lei@redhat.com>
Add !list_empty(&fcmd->node) check in ublk_batch_cancel_cmd() to ensure
the fcmd hasn't already been removed from the list. Once an fcmd is
removed from the list, it's considered claimed by whoever removed it
and will be freed by that path.
Meantime switch to list_del_init() for deleting it from list.
Signed-off-by: Ming Lei <ming.lei@redhat.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 8a5a6ba29a1d..94470a2ec05e 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -738,7 +738,7 @@ static void ublk_batch_deinit_fetch_buf(struct ublk_queue *ubq,
int res)
{
spin_lock(&ubq->evts_lock);
- list_del(&fcmd->node);
+ list_del_init(&fcmd->node);
WARN_ON_ONCE(fcmd != ubq->active_fcmd);
__ublk_release_fcmd(ubq);
spin_unlock(&ubq->evts_lock);
@@ -2693,6 +2693,16 @@ static void ublk_cancel_cmd(struct ublk_queue *ubq, unsigned tag,
io_uring_cmd_done(io->cmd, UBLK_IO_RES_ABORT, issue_flags);
}
+/*
+ * Cancel a batch fetch command if it hasn't been claimed by another path.
+ *
+ * An fcmd can only be cancelled if:
+ * 1. It's not the active_fcmd (which is currently being processed)
+ * 2. It's still on the list (!list_empty check) - once removed from the list,
+ * the fcmd is considered claimed and will be freed by whoever removed it
+ *
+ * Use list_del_init() so subsequent list_empty() checks work correctly.
+ */
static void ublk_batch_cancel_cmd(struct ublk_queue *ubq,
struct ublk_batch_fetch_cmd *fcmd,
unsigned int issue_flags)
@@ -2700,9 +2710,9 @@ static void ublk_batch_cancel_cmd(struct ublk_queue *ubq,
bool done;
spin_lock(&ubq->evts_lock);
- done = (READ_ONCE(ubq->active_fcmd) != fcmd);
+ done = (READ_ONCE(ubq->active_fcmd) != fcmd) && !list_empty(&fcmd->node);
if (done)
- list_del(&fcmd->node);
+ list_del_init(&fcmd->node);
spin_unlock(&ubq->evts_lock);
if (done) {
--
2.47.0
next prev parent reply other threads:[~2026-01-29 3:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-29 3:14 [PATCH 0/5] ublk: misc improvement in driver and selftests Ming Lei
2026-01-29 3:14 ` Ming Lei [this message]
2026-01-29 3:14 ` [PATCH 2/5] ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag Ming Lei
2026-01-29 4:44 ` Caleb Sander Mateos
2026-01-29 8:21 ` Ming Lei
2026-01-29 5:45 ` Alexander Atanasov
2026-01-29 3:14 ` [PATCH 3/5] selftests: ublk: derive TID automatically from script name Ming Lei
2026-01-29 4:46 ` Caleb Sander Mateos
2026-01-29 9:50 ` Alexander Atanasov
2026-01-29 11:45 ` Ming Lei
2026-01-29 3:14 ` [PATCH 4/5] selftests: ublk: mark each test start and end time in dmesg Ming Lei
2026-01-29 3:14 ` [PATCH 5/5] selftests: ublk: add selftest for UBLK_F_NO_AUTO_PART_SCAN 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=20260129031501.3403688-2-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=alex@zazolabs.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