mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laurence Oberman <loberman@redhat.com>
To: mkp@kernel.org
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	bvanassche@acm.org, michael.christie@oracle.com,
	mlombard@redhat.com, linux-kernel@vger.kernel.org
Subject: [PATCH v6 1/4] scsi: target: Do not re-enable interrupts in compare_and_write_post()
Date: Tue, 27 Oct 2026 08:28:34 -0400	[thread overview]
Message-ID: <20261027122837.2148074-2-loberman@redhat.com> (raw)
In-Reply-To: <20261027122837.2148074-1-loberman@redhat.com>

target_complete_cmd() may be called by a backend driver from interrupt
context, as the comment above target_complete_cmd_with_sense() says. For a
command that has been aborted it calls target_cmd_interrupted(), which
invokes cmd->transport_complete_callback(). Once the WRITE phase of a
COMPARE AND WRITE has been set up that callback is
compare_and_write_post(), which takes t_state_lock with spin_lock_irq()
and drops it with spin_unlock_irq(), unconditionally enabling interrupts
in a caller that had them disabled.

Use spin_lock_irqsave() / spin_unlock_irqrestore() instead.

compare_and_write_callback() has the same pattern, but its
spin_lock_irq() is on the path taken after a successful compare, which is
reached only from target_complete_ok_work() in process context; the
success == false path returns long before it. It is left alone.

Signed-off-by: Laurence Oberman <loberman@redhat.com>
---

Notes:
    Pre-existing, and not needed by the rest of the series, but
    compare_and_write_post() is modified by patch 2 and the mismatch between
    its spin_lock_irq() and the spin_lock_irqsave() a few lines below would be
    confusing to leave in place.
    
    No Fixes: tag -- the pattern predates target_cmd_interrupted().

 drivers/target/target_core_sbc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index 21f5cb8..8c52e1e 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -352,15 +352,16 @@ static sense_reason_t compare_and_write_post(struct se_cmd *cmd, bool success,
 {
 	struct se_device *dev = cmd->se_dev;
 	sense_reason_t ret = TCM_NO_SENSE;
+	unsigned long flags;
 
-	spin_lock_irq(&cmd->t_state_lock);
+	spin_lock_irqsave(&cmd->t_state_lock, flags);
 	if (success) {
 		*post_ret = 1;
 
 		if (cmd->scsi_status == SAM_STAT_CHECK_CONDITION)
 			ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 	}
-	spin_unlock_irq(&cmd->t_state_lock);
+	spin_unlock_irqrestore(&cmd->t_state_lock, flags);
 
 	/*
 	 * Unlock ->caw_sem originally obtained during sbc_compare_and_write()
-- 
2.43.0


  reply	other threads:[~2026-10-27 12:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 12:28 [PATCH v6 0/4] scsi: target: fix LUN_RESET hang on aborted iSCSI WRITEs Laurence Oberman
2026-10-27 12:28 ` Laurence Oberman [this message]
2026-10-27 12:28 ` [PATCH v6 2/4] scsi: target: Only release caw_sem if this command took it Laurence Oberman
2026-10-27 12:28 ` [PATCH v6 3/4] scsi: target: Queue the abort of a command at most once Laurence Oberman
2026-10-27 12:28 ` [PATCH v6 4/4] scsi: target: iscsi: Complete an aborted WRITE stuck before the first R2T Laurence Oberman

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=20261027122837.2148074-2-loberman@redhat.com \
    --to=loberman@redhat.com \
    --cc=bvanassche@acm.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=michael.christie@oracle.com \
    --cc=mkp@kernel.org \
    --cc=mlombard@redhat.com \
    --cc=target-devel@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

all inboxes | Powered by JetHome®