From: Bart Van Assche <bvanassche@acm.org>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, Bart Van Assche <bvanassche@acm.org>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Subject: [PATCH v5 07/28] scsi_debug: Abort SCSI commands via .queue_reserved_command()
Date: Wed, 24 Sep 2025 13:30:26 -0700 [thread overview]
Message-ID: <20250924203142.4073403-8-bvanassche@acm.org> (raw)
In-Reply-To: <20250924203142.4073403-1-bvanassche@acm.org>
Add a .queue_reserved_command() implementation and call it from the code
path that aborts SCSI commands. This ensures that the code for
allocating a pseudo SCSI device and also the code for processing
reserved commands gets triggered while running blktests.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/scsi_debug.c | 106 ++++++++++++++++++++++++++++++++++----
1 file changed, 97 insertions(+), 9 deletions(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 2a8638937d23..b376331c4cce 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -451,6 +451,23 @@ struct sdeb_store_info {
#define shost_to_sdebug_host(shost) \
dev_to_sdebug_host(shost->dma_dev)
+struct scsi_debug_abort_cmd {
+ u16 tag;
+ u16 hwq;
+};
+
+enum scsi_debug_internal_cmd_type {
+ SCSI_DEBUG_ABORT_CMD,
+};
+
+struct scsi_debug_internal_cmd {
+ enum scsi_debug_internal_cmd_type type;
+
+ union {
+ struct scsi_debug_abort_cmd abort_cmd;
+ };
+};
+
enum sdeb_defer_type {SDEB_DEFER_NONE = 0, SDEB_DEFER_HRT = 1,
SDEB_DEFER_WQ = 2, SDEB_DEFER_POLL = 3};
@@ -466,6 +483,8 @@ struct sdebug_defer {
struct sdebug_scsi_cmd {
spinlock_t lock;
struct sdebug_defer sd_dp;
+
+ struct scsi_debug_internal_cmd internal_cmd;
};
static atomic_t sdebug_cmnd_count; /* number of incoming commands */
@@ -6729,20 +6748,48 @@ static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd)
return false;
}
+static int scsi_debug_setup_abort_cmd(struct scsi_cmnd *cmd,
+ const struct scsi_debug_internal_cmd *internal_cmd)
+{
+ struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmd);
+
+ sdsc->internal_cmd = *internal_cmd;
+
+ return 0;
+}
+
/*
- * Called from scsi_debug_abort() only, which is for timed-out cmd.
+ * Abort a pending SCSI command. Only called from scsi_debug_abort(). Although
+ * it would be possible to call scsi_debug_stop_cmnd() directly, an internal
+ * command is allocated and submitted to use the reserved command
+ * infrastructure.
*/
static bool scsi_debug_abort_cmnd(struct scsi_cmnd *cmnd)
{
- struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd);
- unsigned long flags;
- bool res;
-
- spin_lock_irqsave(&sdsc->lock, flags);
- res = scsi_debug_stop_cmnd(cmnd);
- spin_unlock_irqrestore(&sdsc->lock, flags);
+ struct request *rq = scsi_cmd_to_rq(cmnd);
+ u32 unique_tag = blk_mq_unique_tag(rq);
+ u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag);
+ u16 tag = blk_mq_unique_tag_to_tag(unique_tag);
+ struct scsi_device *sdev = cmnd->device;
+ struct Scsi_Host *shost = sdev->host;
+ const struct scsi_debug_internal_cmd ic = {
+ .type = SCSI_DEBUG_ABORT_CMD,
+ .abort_cmd = {
+ .tag = tag,
+ .hwq = hwq,
+ },
+ };
+ struct scsi_cmnd *abort_cmd;
+ struct request *abort_rq;
- return res;
+ abort_cmd = scsi_get_internal_cmd(shost->pseudo_sdev, DMA_TO_DEVICE,
+ BLK_MQ_REQ_RESERVED);
+ if (WARN_ON_ONCE(!abort_cmd))
+ return false;
+ scsi_debug_setup_abort_cmd(abort_cmd, &ic);
+ abort_rq = scsi_cmd_to_rq(abort_cmd);
+ abort_rq->timeout = secs_to_jiffies(3);
+ return blk_execute_rq(abort_rq, true) == BLK_STS_OK;
}
/*
@@ -9197,6 +9244,45 @@ static int sdebug_fail_cmd(struct scsi_cmnd *cmnd, int *retval,
return ret;
}
+static void scsi_debug_abort_cmd(struct Scsi_Host *shost, struct scsi_cmnd *scp)
+{
+ struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(scp);
+ struct scsi_debug_abort_cmd *abort_cmd =
+ &sdsc->internal_cmd.abort_cmd;
+ struct blk_mq_tag_set *tag_set = &shost->tag_set;
+ unsigned int tag = abort_cmd->tag;
+ unsigned int hwq = abort_cmd->hwq;
+ struct blk_mq_tags *tags = tag_set->tags[hwq];
+ struct request *abort_rq = blk_mq_tag_to_rq(tags, tag);
+ struct scsi_cmnd *abort_scmd = blk_mq_rq_to_pdu(abort_rq);
+ struct sdebug_scsi_cmd *abort_sdsc = scsi_cmd_priv(abort_scmd);
+ bool res;
+
+ scoped_guard(spinlock_irqsave, &abort_sdsc->lock)
+ res = scsi_debug_stop_cmnd(abort_scmd);
+
+ scp->result = (res ? DID_OK : DID_ERROR) << 16;
+}
+
+static int scsi_debug_queue_reserved_command(struct Scsi_Host *shost,
+ struct scsi_cmnd *scp)
+{
+ struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(scp);
+
+ switch (sdsc->internal_cmd.type) {
+ case SCSI_DEBUG_ABORT_CMD:
+ scsi_debug_abort_cmd(shost, scp);
+ break;
+ default:
+ WARN_ON_ONCE(true);
+ scp->result = DID_ERROR << 16;
+ break;
+ }
+
+ scsi_done(scp);
+ return 0;
+}
+
static int scsi_debug_queuecommand(struct Scsi_Host *shost,
struct scsi_cmnd *scp)
{
@@ -9416,6 +9502,7 @@ static const struct scsi_host_template sdebug_driver_template = {
.sdev_destroy = scsi_debug_sdev_destroy,
.ioctl = scsi_debug_ioctl,
.queuecommand = scsi_debug_queuecommand,
+ .queue_reserved_command = scsi_debug_queue_reserved_command,
.change_queue_depth = sdebug_change_qdepth,
.map_queues = sdebug_map_queues,
.mq_poll = sdebug_blk_mq_poll,
@@ -9425,6 +9512,7 @@ static const struct scsi_host_template sdebug_driver_template = {
.eh_bus_reset_handler = scsi_debug_bus_reset,
.eh_host_reset_handler = scsi_debug_host_reset,
.can_queue = SDEBUG_CANQUEUE,
+ .nr_reserved_cmds = 1,
.this_id = 7,
.sg_tablesize = SG_MAX_SEGMENTS,
.cmd_per_lun = DEF_CMD_PER_LUN,
next prev parent reply other threads:[~2025-09-24 20:32 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 20:30 [PATCH v5 00/28] Optimize the hot path in the UFS driver Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 01/28] scsi: core: Support allocating reserved commands Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 02/28] scsi: core: Move two statements Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 03/28] scsi: core: Make the budget map optional Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 04/28] scsi: core: Support allocating a pseudo SCSI device Bart Van Assche
2025-09-26 7:14 ` John Garry
2025-09-26 20:01 ` Bart Van Assche
2025-09-26 22:21 ` Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 05/28] scsi: core: Introduce .queue_reserved_command() Bart Van Assche
2025-09-26 7:24 ` John Garry
2025-09-26 20:05 ` Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 06/28] scsi: core: Add scsi_{get,put}_internal_cmd() helpers Bart Van Assche
2025-09-25 16:38 ` John Garry
2025-09-24 20:30 ` Bart Van Assche [this message]
2025-09-26 7:32 ` [PATCH v5 07/28] scsi_debug: Abort SCSI commands via .queue_reserved_command() John Garry
2025-09-26 20:44 ` Bart Van Assche
2025-09-30 7:03 ` John Garry
2025-10-01 18:26 ` Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 08/28] ufs: core: Move an assignment in ufshcd_mcq_process_cqe() Bart Van Assche
2025-09-26 6:12 ` Avri Altman
2025-09-24 20:30 ` [PATCH v5 09/28] ufs: core: Change the type of one ufshcd_add_cmd_upiu_trace() argument Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 10/28] ufs: core: Only call ufshcd_add_command_trace() for SCSI commands Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 11/28] ufs: core: Change the type of one ufshcd_add_command_trace() argument Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 12/28] ufs: core: Change the type of one ufshcd_send_command() argument Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 13/28] ufs: core: Only call ufshcd_should_inform_monitor() for SCSI commands Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 14/28] ufs: core: Change the monitor function argument types Bart Van Assche
2025-09-26 6:24 ` Avri Altman
2025-09-24 20:30 ` [PATCH v5 15/28] ufs: core: Rework ufshcd_mcq_compl_pending_transfer() Bart Van Assche
2025-09-26 6:44 ` Avri Altman
2025-09-24 20:30 ` [PATCH v5 16/28] ufs: core: Rework ufshcd_eh_device_reset_handler() Bart Van Assche
2025-09-26 7:17 ` Avri Altman
2025-09-24 20:30 ` [PATCH v5 17/28] ufs: core: Rework the SCSI host queue depth calculation code Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 18/28] ufs: core: Allocate the SCSI host earlier Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 19/28] ufs: core: Call ufshcd_init_lrb() later Bart Van Assche
2025-09-27 9:39 ` Avri Altman
2025-09-24 20:30 ` [PATCH v5 20/28] ufs: core: Use hba->reserved_slot Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 21/28] ufs: core: Make the reserved slot a reserved request Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 22/28] ufs: core: Do not clear driver-private command data Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 23/28] ufs: core: Optimize the hot path Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 24/28] ufs: core: Pass a SCSI pointer instead of an LRB pointer Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 25/28] ufs: core: Remove the ufshcd_lrb task_tag member Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 26/28] ufs: core: Make blk_mq_tagset_busy_iter() skip reserved requests Bart Van Assche
2025-09-24 20:30 ` [PATCH v5 27/28] ufs: core: Move code out of ufshcd_wait_for_dev_cmd() Bart Van Assche
2025-09-27 9:11 ` Avri Altman
2025-09-24 20:30 ` [PATCH v5 28/28] ufs: core: Switch to scsi_get_internal_cmd() Bart Van Assche
2025-09-26 10:08 ` [PATCH v5 00/28] Optimize the hot path in the UFS driver John Garry
2025-09-26 17:32 ` Bart Van Assche
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=20250924203142.4073403-8-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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