From: Bart Van Assche <bvanassche@acm.org>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, Marco Elver <elver@google.com>,
Bart Van Assche <bvanassche@acm.org>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Subject: [PATCH v2 55/56] scsi: core: Enable lock context analysis
Date: Thu, 30 Apr 2026 11:20:25 -0700 [thread overview]
Message-ID: <20260430182130.1978347-56-bvanassche@acm.org> (raw)
In-Reply-To: <20260430182130.1978347-1-bvanassche@acm.org>
Document which functions expect that shost->scan_mutex is held. Inform
the compiler about synchronization object aliases with __assume_ctx_lock().
Enable lock context analysis for the SCSI core and also for all drivers
in the drivers/scsi/ directory.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/Makefile | 1 +
drivers/scsi/device_handler/Makefile | 3 +++
drivers/scsi/scsi_scan.c | 12 ++++++++++++
include/scsi/scsi_host.h | 2 ++
4 files changed, 18 insertions(+)
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 16de3e41f94c..07e8280bcb1e 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -14,6 +14,7 @@
# satisfy certain initialization assumptions in the SCSI layer.
# *!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!
+CONTEXT_ANALYSIS := y
CFLAGS_aha152x.o = -DAHA152X_STAT -DAUTOCONF
diff --git a/drivers/scsi/device_handler/Makefile b/drivers/scsi/device_handler/Makefile
index 0a603aefd2bb..5aa282a63e24 100644
--- a/drivers/scsi/device_handler/Makefile
+++ b/drivers/scsi/device_handler/Makefile
@@ -2,6 +2,9 @@
#
# SCSI Device Handler
#
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_DH_RDAC) += scsi_dh_rdac.o
obj-$(CONFIG_SCSI_DH_HP_SW) += scsi_dh_hp_sw.o
obj-$(CONFIG_SCSI_DH_EMC) += scsi_dh_emc.o
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index ef22a4228b85..283f9a32d48a 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1182,6 +1182,7 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
struct scsi_device **sdevp,
enum scsi_scan_mode rescan,
void *hostdata)
+ __must_hold(&dev_to_shost(starget->dev.parent)->scan_mutex)
{
struct scsi_device *sdev;
unsigned char *result;
@@ -1338,6 +1339,7 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
static void scsi_sequential_lun_scan(struct scsi_target *starget,
blist_flags_t bflags, int scsi_level,
enum scsi_scan_mode rescan)
+ __must_hold(&dev_to_shost(starget->dev.parent)->scan_mutex)
{
uint max_dev_lun;
u64 sparse_lun, lun;
@@ -1429,6 +1431,7 @@ static void scsi_sequential_lun_scan(struct scsi_target *starget,
**/
static int scsi_report_lun_scan(struct scsi_target *starget, blist_flags_t bflags,
enum scsi_scan_mode rescan)
+ __must_hold(&dev_to_shost(starget->dev.parent)->scan_mutex)
{
unsigned char scsi_cmd[MAX_COMMAND_SIZE];
unsigned int length;
@@ -1626,6 +1629,8 @@ struct scsi_device *__scsi_add_device(struct Scsi_Host *shost, uint channel,
scsi_autopm_get_target(starget);
mutex_lock(&shost->scan_mutex);
+ /* Tell the compiler that dev_to_shost(...) == shost. */
+ __assume_ctx_lock(&dev_to_shost(starget->dev.parent)->scan_mutex);
if (!shost->async_scan)
scsi_complete_async_scans();
@@ -1754,6 +1759,7 @@ EXPORT_SYMBOL(scsi_rescan_device);
static void __scsi_scan_target(struct device *parent, unsigned int channel,
unsigned int id, u64 lun, enum scsi_scan_mode rescan)
+ __must_hold(&dev_to_shost(parent)->scan_mutex)
{
struct Scsi_Host *shost = dev_to_shost(parent);
blist_flags_t bflags = 0;
@@ -1769,6 +1775,8 @@ static void __scsi_scan_target(struct device *parent, unsigned int channel,
starget = scsi_alloc_target(parent, channel, id);
if (!starget)
return;
+ /* Tell the compiler that dev_to_shost(...) == shost. */
+ __assume_ctx_lock(&dev_to_shost(starget->dev.parent)->scan_mutex);
scsi_autopm_get_target(starget);
if (lun != SCAN_WILD_CARD) {
@@ -1850,9 +1858,13 @@ EXPORT_SYMBOL(scsi_scan_target);
static void scsi_scan_channel(struct Scsi_Host *shost, unsigned int channel,
unsigned int id, u64 lun,
enum scsi_scan_mode rescan)
+ __must_hold(&shost->scan_mutex)
{
uint order_id;
+ /* Tell the compiler that dev_to_shost(...) == shost. */
+ __assume_ctx_lock(&dev_to_shost(&shost->shost_gendev)->scan_mutex);
+
if (id == SCAN_WILD_CARD)
for (id = 0; id < shost->max_id; ++id) {
/*
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 7e2011830ba4..2bbe7cb0060b 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -534,6 +534,8 @@ struct scsi_host_template {
enum scsi_qc_status rc; \
\
spin_lock_irqsave(shost->host_lock, irq_flags); \
+ /* Tell the compiler that cmd->device->host == shost. */\
+ __assume_ctx_lock(cmd->device->host->host_lock); \
rc = func_name##_lck(cmd); \
spin_unlock_irqrestore(shost->host_lock, irq_flags); \
return rc; \
next prev parent reply other threads:[~2026-04-30 18:25 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 01/56] PCI: Convert to_pci_dev() into an inline function Bart Van Assche
2026-04-30 22:19 ` Bjorn Helgaas
2026-04-30 18:19 ` [PATCH v2 02/56] scsi: scsi_debug: Prepare for enabling lock context analysis Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 03/56] scsi: sg: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 04/56] scsi: st: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 05/56] scsi: BusLogic: Introduce a local variable Bart Van Assche
2026-05-01 18:01 ` Khalid Aziz
2026-04-30 18:19 ` [PATCH v2 06/56] scsi: BusLogic: Prepare for enabling lock context analysis Bart Van Assche
2026-05-01 18:02 ` Khalid Aziz
2026-04-30 18:19 ` [PATCH v2 07/56] scsi: NCR5380: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 08/56] scsi: aacraid: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 09/56] scsi: aic7xxx: Enable " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 10/56] scsi: aha152x: Prepare for enabling " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 11/56] scsi: aic7xxx: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 12/56] scsi: aic94xx: Enable " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 13/56] scsi: arcmsr: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 14/56] scsi: arm: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 15/56] scsi: be2iscsi: Prepare for enabling " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 16/56] scsi: be2iscsi: Enable " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 17/56] scsi: cxgbi: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 18/56] scsi: bfa: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 19/56] scsi: bnx2fc: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 20/56] scsi: bnx2i: Introduce a local variable Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 21/56] scsi: bnx2i: Enable lock context analysis Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 22/56] scsi: csiostor: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 23/56] scsi: elx: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 24/56] scsi: esas2r: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 25/56] scsi: fcoe: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 26/56] scsi: fnic: " Bart Van Assche
2026-05-04 17:45 ` Karan Tilak Kumar (kartilak)
2026-04-30 18:19 ` [PATCH v2 27/56] scsi: hisi_sas: " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 28/56] scsi: hpsa: Prepare for enabling " Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 29/56] scsi: ibmvscsi: Enable " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 30/56] scsi: ibmvscsi_tgt: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 31/56] scsi: ipr: Prepare for enabling " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 32/56] scsi: ips: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 33/56] scsi: isci: Enable " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 34/56] scsi: libfc: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 35/56] scsi: libiscsi: Prepare for enabling " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 36/56] scsi: libsas: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 37/56] scsi: libsas: Enable " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 38/56] scsi: lpfc: Prepare for enabling " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 39/56] scsi: megaraid_sas: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 40/56] scsi: megaraid: Enable " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 41/56] scsi: mpt3sas: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 42/56] scsi: mvsas: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 43/56] scsi: pcmcia: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 44/56] scsi: pm8001: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 45/56] scsi: qedf: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 46/56] scsi: qedi: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 47/56] scsi: qla1280: Prepare for enabling " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 48/56] scsi: qla2xxx: Enable " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 49/56] scsi: qla4xxx: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 50/56] scsi: ufs: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 51/56] scsi: iSCSI transport: Prepare for enabling " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 52/56] scsi: smartpqi: Enable " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 53/56] scsi: snic: " Bart Van Assche
2026-05-01 19:08 ` Narsimhulu Musini (nmusini)
2026-04-30 18:20 ` [PATCH v2 54/56] scsi: sym53c8xx_2: " Bart Van Assche
2026-04-30 18:20 ` Bart Van Assche [this message]
2026-04-30 18:20 ` [PATCH v2 56/56] scsi: core: Protect host state changes with the host lock 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=20260430182130.1978347-56-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=elver@google.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