* [PATCH v2 01/56] PCI: Convert to_pci_dev() into an inline function
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 ` 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
` (54 subsequent siblings)
55 siblings, 1 reply; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Bjorn Helgaas,
Nathan Chancellor
Clang's context analysis checker performs alias analysis on expressions
passed to annotations like __acquires(). Clang's alias analysis does not
support container_of(). Convert to_pci_dev() from a macro into an inline
function such that Clang recognizes multiple to_pci_dev() expressions as
identical if the 'dev' argument is the same.
It is on purpose that to_pci_dev() accepts a const pointer and returns a
pointer that is not const. Any other choice, e.g. accepting a non-const
pointer or returning a const pointer, triggers compiler errors.
While _Generic() could be used to support const and non-const struct
device pointers in a more elegant way, Clang's alias analysis does not
support _Generic().
Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
include/linux/pci.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 2c4454583c11..f5989267a537 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -606,7 +606,10 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
struct pci_dev *pci_alloc_dev(struct pci_bus *bus);
-#define to_pci_dev(n) container_of(n, struct pci_dev, dev)
+static inline struct pci_dev *to_pci_dev(const struct device *dev)
+{
+ return container_of(dev, struct pci_dev, dev);
+}
#define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
#define for_each_pci_dev_reverse(d) \
while ((d = pci_get_device_reverse(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
^ permalink raw reply related [flat|nested] 62+ messages in thread* Re: [PATCH v2 01/56] PCI: Convert to_pci_dev() into an inline function
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
0 siblings, 0 replies; 62+ messages in thread
From: Bjorn Helgaas @ 2026-04-30 22:19 UTC (permalink / raw)
To: Bart Van Assche
Cc: Martin K . Petersen, linux-scsi, Marco Elver, Bjorn Helgaas,
Nathan Chancellor
On Thu, Apr 30, 2026 at 11:19:31AM -0700, Bart Van Assche wrote:
> Clang's context analysis checker performs alias analysis on expressions
> passed to annotations like __acquires(). Clang's alias analysis does not
> support container_of(). Convert to_pci_dev() from a macro into an inline
> function such that Clang recognizes multiple to_pci_dev() expressions as
> identical if the 'dev' argument is the same.
>
> It is on purpose that to_pci_dev() accepts a const pointer and returns a
> pointer that is not const. Any other choice, e.g. accepting a non-const
> pointer or returning a const pointer, triggers compiler errors.
>
> While _Generic() could be used to support const and non-const struct
> device pointers in a more elegant way, Clang's alias analysis does not
> support _Generic().
>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
> ---
> include/linux/pci.h | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 2c4454583c11..f5989267a537 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -606,7 +606,10 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
>
> struct pci_dev *pci_alloc_dev(struct pci_bus *bus);
>
> -#define to_pci_dev(n) container_of(n, struct pci_dev, dev)
> +static inline struct pci_dev *to_pci_dev(const struct device *dev)
> +{
> + return container_of(dev, struct pci_dev, dev);
> +}
> #define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
> #define for_each_pci_dev_reverse(d) \
> while ((d = pci_get_device_reverse(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v2 02/56] scsi: scsi_debug: Prepare for enabling lock context analysis
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 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 03/56] scsi: sg: " Bart Van Assche
` (53 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley,
Nathan Chancellor
Suppress lock context analysis for the functions that perform conditional
locking to prevent that the Clang thread-safety analyzer complains about
these functions.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/scsi_debug.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 1515495fd9ea..c4a1582ab1fa 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -4014,6 +4014,7 @@ static inline struct sdeb_store_info *devip2sip(struct sdebug_dev_info *devip,
static inline void
sdeb_read_lock(rwlock_t *lock)
+ __context_unsafe(conditional locking)
{
if (sdebug_no_rwlock)
__acquire(lock);
@@ -4023,6 +4024,7 @@ sdeb_read_lock(rwlock_t *lock)
static inline void
sdeb_read_unlock(rwlock_t *lock)
+ __context_unsafe(conditional locking)
{
if (sdebug_no_rwlock)
__release(lock);
@@ -4032,6 +4034,7 @@ sdeb_read_unlock(rwlock_t *lock)
static inline void
sdeb_write_lock(rwlock_t *lock)
+ __context_unsafe(conditional locking)
{
if (sdebug_no_rwlock)
__acquire(lock);
@@ -4041,6 +4044,7 @@ sdeb_write_lock(rwlock_t *lock)
static inline void
sdeb_write_unlock(rwlock_t *lock)
+ __context_unsafe(conditional locking)
{
if (sdebug_no_rwlock)
__release(lock);
@@ -4050,6 +4054,7 @@ sdeb_write_unlock(rwlock_t *lock)
static inline void
sdeb_data_read_lock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
BUG_ON(!sip);
@@ -4058,6 +4063,7 @@ sdeb_data_read_lock(struct sdeb_store_info *sip)
static inline void
sdeb_data_read_unlock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
BUG_ON(!sip);
@@ -4066,6 +4072,7 @@ sdeb_data_read_unlock(struct sdeb_store_info *sip)
static inline void
sdeb_data_write_lock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
BUG_ON(!sip);
@@ -4074,6 +4081,7 @@ sdeb_data_write_lock(struct sdeb_store_info *sip)
static inline void
sdeb_data_write_unlock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
BUG_ON(!sip);
@@ -4082,6 +4090,7 @@ sdeb_data_write_unlock(struct sdeb_store_info *sip)
static inline void
sdeb_data_sector_read_lock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
BUG_ON(!sip);
@@ -4090,6 +4099,7 @@ sdeb_data_sector_read_lock(struct sdeb_store_info *sip)
static inline void
sdeb_data_sector_read_unlock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
BUG_ON(!sip);
@@ -4098,6 +4108,7 @@ sdeb_data_sector_read_unlock(struct sdeb_store_info *sip)
static inline void
sdeb_data_sector_write_lock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
BUG_ON(!sip);
@@ -4106,6 +4117,7 @@ sdeb_data_sector_write_lock(struct sdeb_store_info *sip)
static inline void
sdeb_data_sector_write_unlock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
BUG_ON(!sip);
@@ -4164,6 +4176,7 @@ sdeb_data_sector_unlock(struct sdeb_store_info *sip, bool do_write)
static inline void
sdeb_meta_read_lock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
if (sdebug_no_rwlock) {
if (sip)
@@ -4180,6 +4193,7 @@ sdeb_meta_read_lock(struct sdeb_store_info *sip)
static inline void
sdeb_meta_read_unlock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
if (sdebug_no_rwlock) {
if (sip)
@@ -4196,6 +4210,7 @@ sdeb_meta_read_unlock(struct sdeb_store_info *sip)
static inline void
sdeb_meta_write_lock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
if (sdebug_no_rwlock) {
if (sip)
@@ -4212,6 +4227,7 @@ sdeb_meta_write_lock(struct sdeb_store_info *sip)
static inline void
sdeb_meta_write_unlock(struct sdeb_store_info *sip)
+ __context_unsafe(conditional locking)
{
if (sdebug_no_rwlock) {
if (sip)
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 03/56] scsi: sg: Prepare for enabling lock context analysis
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 18:19 ` [PATCH v2 02/56] scsi: scsi_debug: Prepare for enabling lock context analysis Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 04/56] scsi: st: " Bart Van Assche
` (52 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Doug Gilbert,
James E.J. Bottomley
Annotate open_wait() with __must_hold() since it unlocks and locks a
mutex.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/sg.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 2b4b2a1a8e44..ec405cb56a40 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -245,6 +245,7 @@ static int sg_allow_access(struct file *filp, unsigned char *cmd)
static int
open_wait(Sg_device *sdp, int flags)
+ __must_hold(sdp->open_rel_lock)
{
int retval = 0;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 04/56] scsi: st: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (2 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 03/56] scsi: sg: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 05/56] scsi: BusLogic: Introduce a local variable Bart Van Assche
` (51 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Kai Mäkisara,
James E.J. Bottomley
Document what mutex is released by st_common_ioctl().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/st.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index f1c3c4946637..234482e1b70b 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -3535,6 +3535,7 @@ static int partition_tape(struct scsi_tape *STp, int size)
static long st_common_ioctl(struct scsi_tape *STp, struct st_modedef *STm,
struct file *file, unsigned int cmd_in,
unsigned long arg)
+ __releases(&STp->lock)
{
int i, retval = 0;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 05/56] scsi: BusLogic: Introduce a local variable
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (3 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 04/56] scsi: st: " Bart Van Assche
@ 2026-04-30 18:19 ` 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
` (50 subsequent siblings)
55 siblings, 1 reply; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Khalid Aziz,
James E.J. Bottomley
Introduce a new local variable to prepare for enabling thread-safety
analysis. No functionality has been changed.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/BusLogic.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index 5304d2febd63..e3790ff24e56 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -2886,6 +2886,7 @@ static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command)
struct blogic_tgt_flags *tgt_flags =
&adapter->tgt_flags[command->device->id];
struct blogic_tgt_stats *tgt_stats = adapter->tgt_stats;
+ struct Scsi_Host *const shost = command->device->host;
unsigned char *cdb = command->cmnd;
int cdblen = command->cmd_len;
int tgt_id = command->device->id;
@@ -2915,9 +2916,9 @@ static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command)
*/
ccb = blogic_alloc_ccb(adapter);
if (ccb == NULL) {
- spin_unlock_irq(adapter->scsi_host->host_lock);
+ spin_unlock_irq(shost->host_lock);
blogic_delay(1);
- spin_lock_irq(adapter->scsi_host->host_lock);
+ spin_lock_irq(shost->host_lock);
ccb = blogic_alloc_ccb(adapter);
if (ccb == NULL) {
command->result = DID_ERROR << 16;
@@ -3062,10 +3063,10 @@ static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command)
be initiated soon.
*/
if (!blogic_write_outbox(adapter, BLOGIC_MBOX_START, ccb)) {
- spin_unlock_irq(adapter->scsi_host->host_lock);
+ spin_unlock_irq(shost->host_lock);
blogic_warn("Unable to write Outgoing Mailbox - Pausing for 1 second\n", adapter);
blogic_delay(1);
- spin_lock_irq(adapter->scsi_host->host_lock);
+ spin_lock_irq(shost->host_lock);
if (!blogic_write_outbox(adapter, BLOGIC_MBOX_START,
ccb)) {
blogic_warn("Still unable to write Outgoing Mailbox - Host Adapter Dead?\n", adapter);
^ permalink raw reply related [flat|nested] 62+ messages in thread* Re: [PATCH v2 05/56] scsi: BusLogic: Introduce a local variable
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
0 siblings, 0 replies; 62+ messages in thread
From: Khalid Aziz @ 2026-05-01 18:01 UTC (permalink / raw)
To: Bart Van Assche, Martin K . Petersen
Cc: linux-scsi, Marco Elver, James E.J. Bottomley
On 4/30/26 12:19 PM, Bart Van Assche wrote:
> Introduce a new local variable to prepare for enabling thread-safety
> analysis. No functionality has been changed.
>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> drivers/scsi/BusLogic.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
> index 5304d2febd63..e3790ff24e56 100644
> --- a/drivers/scsi/BusLogic.c
> +++ b/drivers/scsi/BusLogic.c
> @@ -2886,6 +2886,7 @@ static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command)
> struct blogic_tgt_flags *tgt_flags =
> &adapter->tgt_flags[command->device->id];
> struct blogic_tgt_stats *tgt_stats = adapter->tgt_stats;
> + struct Scsi_Host *const shost = command->device->host;
> unsigned char *cdb = command->cmnd;
> int cdblen = command->cmd_len;
> int tgt_id = command->device->id;
> @@ -2915,9 +2916,9 @@ static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command)
> */
> ccb = blogic_alloc_ccb(adapter);
> if (ccb == NULL) {
> - spin_unlock_irq(adapter->scsi_host->host_lock);
> + spin_unlock_irq(shost->host_lock);
> blogic_delay(1);
> - spin_lock_irq(adapter->scsi_host->host_lock);
> + spin_lock_irq(shost->host_lock);
> ccb = blogic_alloc_ccb(adapter);
> if (ccb == NULL) {
> command->result = DID_ERROR << 16;
> @@ -3062,10 +3063,10 @@ static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command)
> be initiated soon.
> */
> if (!blogic_write_outbox(adapter, BLOGIC_MBOX_START, ccb)) {
> - spin_unlock_irq(adapter->scsi_host->host_lock);
> + spin_unlock_irq(shost->host_lock);
> blogic_warn("Unable to write Outgoing Mailbox - Pausing for 1 second\n", adapter);
> blogic_delay(1);
> - spin_lock_irq(adapter->scsi_host->host_lock);
> + spin_lock_irq(shost->host_lock);
> if (!blogic_write_outbox(adapter, BLOGIC_MBOX_START,
> ccb)) {
> blogic_warn("Still unable to write Outgoing Mailbox - Host Adapter Dead?\n", adapter);
Acked-by: Khalid Aziz <khalid@gonehiking.org>
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v2 06/56] scsi: BusLogic: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (4 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 05/56] scsi: BusLogic: Introduce a local variable Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-05-01 18:02 ` Khalid Aziz
2026-04-30 18:19 ` [PATCH v2 07/56] scsi: NCR5380: " Bart Van Assche
` (49 subsequent siblings)
55 siblings, 1 reply; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Khalid Aziz,
James E.J. Bottomley
Document locking requirements with __must_hold().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/BusLogic.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index e3790ff24e56..bb5a63baf897 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -2879,6 +2879,7 @@ static int blogic_hostreset(struct scsi_cmnd *SCpnt)
*/
static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command)
+ __must_hold(command->device->host->host_lock)
{
void (*comp_cb)(struct scsi_cmnd *) = scsi_done;
struct blogic_adapter *adapter =
@@ -3183,6 +3184,7 @@ static int blogic_abort(struct scsi_cmnd *command)
*/
static int blogic_resetadapter(struct blogic_adapter *adapter, bool hard_reset)
+ __must_hold(adapter->scsi_host->host_lock)
{
struct blogic_ccb *ccb;
int tgt_id;
^ permalink raw reply related [flat|nested] 62+ messages in thread* Re: [PATCH v2 06/56] scsi: BusLogic: Prepare for enabling lock context analysis
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
0 siblings, 0 replies; 62+ messages in thread
From: Khalid Aziz @ 2026-05-01 18:02 UTC (permalink / raw)
To: Bart Van Assche, Martin K . Petersen
Cc: linux-scsi, Marco Elver, James E.J. Bottomley
On 4/30/26 12:19 PM, Bart Van Assche wrote:
> Document locking requirements with __must_hold().
>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> drivers/scsi/BusLogic.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
> index e3790ff24e56..bb5a63baf897 100644
> --- a/drivers/scsi/BusLogic.c
> +++ b/drivers/scsi/BusLogic.c
> @@ -2879,6 +2879,7 @@ static int blogic_hostreset(struct scsi_cmnd *SCpnt)
> */
>
> static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command)
> + __must_hold(command->device->host->host_lock)
> {
> void (*comp_cb)(struct scsi_cmnd *) = scsi_done;
> struct blogic_adapter *adapter =
> @@ -3183,6 +3184,7 @@ static int blogic_abort(struct scsi_cmnd *command)
> */
>
> static int blogic_resetadapter(struct blogic_adapter *adapter, bool hard_reset)
> + __must_hold(adapter->scsi_host->host_lock)
> {
> struct blogic_ccb *ccb;
> int tgt_id;
Acked-by: Khalid Aziz <khalid@gonehiking.org>
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v2 07/56] scsi: NCR5380: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (5 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 06/56] scsi: BusLogic: Prepare for enabling lock context analysis Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 08/56] scsi: aacraid: " Bart Van Assche
` (48 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Finn Thain,
Michael Schmitz, James E.J. Bottomley
Expand 'hostdata' in the lock context annotations because 'hostdata' is
not a function argument.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/NCR5380.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 006dcf981218..029fe6362629 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -961,7 +961,7 @@ static irqreturn_t __maybe_unused NCR5380_intr(int irq, void *dev_id)
*/
static bool NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
- __releases(&hostdata->lock) __acquires(&hostdata->lock)
+ __must_hold(&((struct NCR5380_hostdata *)shost_priv(instance))->lock)
{
struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned char tmp[3], phase;
@@ -1657,7 +1657,7 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
*/
static void NCR5380_information_transfer(struct Scsi_Host *instance)
- __releases(&hostdata->lock) __acquires(&hostdata->lock)
+ __must_hold(&((struct NCR5380_hostdata *)shost_priv(instance))->lock)
{
struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned char msgout = NOP;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 08/56] scsi: aacraid: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (6 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 07/56] scsi: NCR5380: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 09/56] scsi: aic7xxx: Enable " Bart Van Assche
` (47 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche,
Adaptec OEM Raid Solutions, James E.J. Bottomley
Document the aac_send_reset_adapter() locking requirements with
__must_hold(). Annotate functions that perform conditional locking with
__no_context_analysis.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/aacraid/Makefile | 2 ++
drivers/scsi/aacraid/commctrl.c | 1 +
drivers/scsi/aacraid/commsup.c | 3 +++
3 files changed, 6 insertions(+)
diff --git a/drivers/scsi/aacraid/Makefile b/drivers/scsi/aacraid/Makefile
index 8f0eec682bb6..415e0ed5ad24 100644
--- a/drivers/scsi/aacraid/Makefile
+++ b/drivers/scsi/aacraid/Makefile
@@ -1,6 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only
# Adaptec aacraid
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_AACRAID) := aacraid.o
aacraid-objs := linit.o aachba.o commctrl.o comminit.o commsup.o \
diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
index bd82aeb679ae..77238e610db4 100644
--- a/drivers/scsi/aacraid/commctrl.c
+++ b/drivers/scsi/aacraid/commctrl.c
@@ -1043,6 +1043,7 @@ struct aac_reset_iop {
};
static int aac_send_reset_adapter(struct aac_dev *dev, void __user *arg)
+ __must_hold(dev->ioctl_mutex)
{
struct aac_reset_iop reset;
int retval;
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index c4485629f792..fb4d78233c6d 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -475,6 +475,7 @@ int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_fib * hw
int aac_fib_send(u16 command, struct fib *fibptr, unsigned long size,
int priority, int wait, int reply, fib_callback callback,
void *callback_data)
+ __context_unsafe(conditional locking)
{
struct aac_dev * dev = fibptr->dev;
struct hw_fib * hw_fib = fibptr->hw_fib_va;
@@ -698,6 +699,7 @@ int aac_fib_send(u16 command, struct fib *fibptr, unsigned long size,
int aac_hba_send(u8 command, struct fib *fibptr, fib_callback callback,
void *callback_data)
+ __context_unsafe(conditional locking)
{
struct aac_dev *dev = fibptr->dev;
int wait;
@@ -1466,6 +1468,7 @@ static void aac_schedule_bus_scan(struct aac_dev *aac)
}
static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
+ __context_unsafe(conditional locking)
{
int index, quirks;
int retval;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 09/56] scsi: aic7xxx: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (7 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 08/56] scsi: aacraid: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 10/56] scsi: aha152x: Prepare for enabling " Bart Van Assche
` (46 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Hannes Reinecke,
James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/aic7xxx/Makefile | 2 ++
drivers/scsi/aic7xxx/aicasm/Makefile | 3 +++
2 files changed, 5 insertions(+)
diff --git a/drivers/scsi/aic7xxx/Makefile b/drivers/scsi/aic7xxx/Makefile
index 853c72a81ae0..2da370d3d904 100644
--- a/drivers/scsi/aic7xxx/Makefile
+++ b/drivers/scsi/aic7xxx/Makefile
@@ -5,6 +5,8 @@
# $Id: //depot/linux-aic79xx-2.5.0/drivers/scsi/aic7xxx/Makefile#8 $
#
+CONTEXT_ANALYSIS := y
+
# Let kbuild descend into aicasm when cleaning
subdir- += aicasm
diff --git a/drivers/scsi/aic7xxx/aicasm/Makefile b/drivers/scsi/aic7xxx/aicasm/Makefile
index a3f2357a3f08..152ca676d0a2 100644
--- a/drivers/scsi/aic7xxx/aicasm/Makefile
+++ b/drivers/scsi/aic7xxx/aicasm/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+
+CONTEXT_ANALYSIS := y
+
PROG= aicasm
OUTDIR ?= ./
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 10/56] scsi: aha152x: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (8 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 09/56] scsi: aic7xxx: Enable " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 11/56] scsi: aic7xxx: " Bart Van Assche
` (45 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Juergen E. Fischer,
James E.J. Bottomley
Annotate is_complete() with __context_unsafe() because it performs
conditional locking.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/aha152x.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/scsi/aha152x.c b/drivers/scsi/aha152x.c
index e3ccb6bb62c0..c16dcb9274eb 100644
--- a/drivers/scsi/aha152x.c
+++ b/drivers/scsi/aha152x.c
@@ -2319,6 +2319,7 @@ static void rsti_run(struct Scsi_Host *shpnt)
*
*/
static void is_complete(struct Scsi_Host *shpnt)
+ __context_unsafe(conditional locking)
{
int dataphase;
unsigned long flags;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 11/56] scsi: aic7xxx: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (9 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 10/56] scsi: aha152x: Prepare for enabling " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 12/56] scsi: aic94xx: Enable " Bart Van Assche
` (44 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Hannes Reinecke,
James E.J. Bottomley
Document locking requirements with __acquires() and __releases().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/aic7xxx/aic79xx_osm.h | 2 ++
drivers/scsi/aic7xxx/aic7xxx_osm.h | 2 ++
2 files changed, 4 insertions(+)
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.h b/drivers/scsi/aic7xxx/aic79xx_osm.h
index 793fe19993a9..c6eb2b97e929 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.h
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.h
@@ -376,12 +376,14 @@ ahd_lockinit(struct ahd_softc *ahd)
static inline void
ahd_lock(struct ahd_softc *ahd, unsigned long *flags)
+ __acquires(&ahd->platform_data->spin_lock)
{
spin_lock_irqsave(&ahd->platform_data->spin_lock, *flags);
}
static inline void
ahd_unlock(struct ahd_softc *ahd, unsigned long *flags)
+ __releases(&ahd->platform_data->spin_lock)
{
spin_unlock_irqrestore(&ahd->platform_data->spin_lock, *flags);
}
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.h b/drivers/scsi/aic7xxx/aic7xxx_osm.h
index 51d9f4de0734..5e78fe7d3f32 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.h
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.h
@@ -389,12 +389,14 @@ ahc_lockinit(struct ahc_softc *ahc)
static inline void
ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
+ __acquires(&ahc->platform_data->spin_lock)
{
spin_lock_irqsave(&ahc->platform_data->spin_lock, *flags);
}
static inline void
ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
+ __releases(&ahc->platform_data->spin_lock)
{
spin_unlock_irqrestore(&ahc->platform_data->spin_lock, *flags);
}
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 12/56] scsi: aic94xx: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (10 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 11/56] scsi: aic7xxx: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 13/56] scsi: arcmsr: " Bart Van Assche
` (43 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/aic94xx/Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/aic94xx/Makefile b/drivers/scsi/aic94xx/Makefile
index db9fbe3a8e4c..4ab04ce6edf2 100644
--- a/drivers/scsi/aic94xx/Makefile
+++ b/drivers/scsi/aic94xx/Makefile
@@ -6,6 +6,8 @@
# Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
#
+CONTEXT_ANALYSIS := y
+
ccflags-$(CONFIG_AIC94XX_DEBUG) := -DASD_DEBUG -DASD_ENTER_EXIT
obj-$(CONFIG_SCSI_AIC94XX) += aic94xx.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 13/56] scsi: arcmsr: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (11 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 12/56] scsi: aic94xx: Enable " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 14/56] scsi: arm: " Bart Van Assche
` (42 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/arcmsr/Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/arcmsr/Makefile b/drivers/scsi/arcmsr/Makefile
index 9051f66cae36..6c12d36994da 100644
--- a/drivers/scsi/arcmsr/Makefile
+++ b/drivers/scsi/arcmsr/Makefile
@@ -2,6 +2,8 @@
# File: drivers/arcmsr/Makefile
# Makefile for the ARECA PCI-X PCI-EXPRESS SATA RAID controllers SCSI driver.
+CONTEXT_ANALYSIS := y
+
arcmsr-objs := arcmsr_attr.o arcmsr_hba.o
obj-$(CONFIG_SCSI_ARCMSR) := arcmsr.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 14/56] scsi: arm: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (12 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 13/56] scsi: arcmsr: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 15/56] scsi: be2iscsi: Prepare for enabling " Bart Van Assche
` (41 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Russell King,
James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/arm/Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/arm/Makefile b/drivers/scsi/arm/Makefile
index b576d9276f71..417d47644a8d 100644
--- a/drivers/scsi/arm/Makefile
+++ b/drivers/scsi/arm/Makefile
@@ -3,6 +3,8 @@
# Makefile for drivers/scsi/arm
#
+CONTEXT_ANALYSIS := y
+
acornscsi_mod-objs := acornscsi.o acornscsi-io.o
obj-$(CONFIG_SCSI_ACORNSCSI_3) += acornscsi_mod.o queue.o msgqueue.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 15/56] scsi: be2iscsi: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (13 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 14/56] scsi: arm: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 16/56] scsi: be2iscsi: Enable " Bart Van Assche
` (40 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Ketan Mukadam,
James E.J. Bottomley
Document locking requirements with __must_hold().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/be2iscsi/be_main.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index fd18d4d3d219..289d9d18482c 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -1185,6 +1185,7 @@ static void
be_complete_logout(struct beiscsi_conn *beiscsi_conn,
struct iscsi_task *task,
struct common_sol_cqe *csol_cqe)
+ __must_hold(&beiscsi_conn->conn->session->back_lock)
{
struct iscsi_logout_rsp *hdr;
struct beiscsi_io_task *io_task = task->dd_data;
@@ -1212,6 +1213,7 @@ static void
be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
struct iscsi_task *task,
struct common_sol_cqe *csol_cqe)
+ __must_hold(&beiscsi_conn->conn->session->back_lock)
{
struct iscsi_tm_rsp *hdr;
struct iscsi_conn *conn = beiscsi_conn->conn;
@@ -1268,6 +1270,7 @@ static void
be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
struct iscsi_task *task,
struct common_sol_cqe *csol_cqe)
+ __must_hold(&beiscsi_conn->conn->session->back_lock)
{
struct iscsi_nopin *hdr;
struct iscsi_conn *conn = beiscsi_conn->conn;
@@ -1423,6 +1426,7 @@ static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
static unsigned int
beiscsi_complete_pdu(struct beiscsi_conn *beiscsi_conn,
struct pdu_base *phdr, void *pdata, unsigned int dlen)
+ __must_hold(&beiscsi_conn->conn->session->back_lock)
{
struct beiscsi_hba *phba = beiscsi_conn->phba;
struct iscsi_conn *conn = beiscsi_conn->conn;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 16/56] scsi: be2iscsi: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (14 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 15/56] scsi: be2iscsi: Prepare for enabling " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 17/56] scsi: cxgbi: " Bart Van Assche
` (39 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Ketan Mukadam,
James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/be2iscsi/Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/be2iscsi/Makefile b/drivers/scsi/be2iscsi/Makefile
index 910885343a75..73d47c687007 100644
--- a/drivers/scsi/be2iscsi/Makefile
+++ b/drivers/scsi/be2iscsi/Makefile
@@ -4,6 +4,8 @@
#
#
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_BE2ISCSI) += be2iscsi.o
be2iscsi-y := be_iscsi.o be_main.o be_mgmt.o be_cmds.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 17/56] scsi: cxgbi: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (15 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 16/56] scsi: be2iscsi: Enable " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 18/56] scsi: bfa: " Bart Van Assche
` (38 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/cxgbi/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/cxgbi/Makefile b/drivers/scsi/cxgbi/Makefile
index abfd38a26fec..c614afa18a33 100644
--- a/drivers/scsi/cxgbi/Makefile
+++ b/drivers/scsi/cxgbi/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
+
+CONTEXT_ANALYSIS := y
+
ccflags-y += -I $(srctree)/drivers/net/ethernet/chelsio/libcxgb
obj-$(CONFIG_SCSI_CXGB3_ISCSI) += libcxgbi.o cxgb3i/
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 18/56] scsi: bfa: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (16 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 17/56] scsi: cxgbi: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 19/56] scsi: bnx2fc: " Bart Van Assche
` (37 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Anil Gurumurthy,
Sudarsana Kalluru, James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/bfa/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/bfa/Makefile b/drivers/scsi/bfa/Makefile
index 442fc3db8f1f..50c16fcfb01c 100644
--- a/drivers/scsi/bfa/Makefile
+++ b/drivers/scsi/bfa/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_BFA_FC) := bfa.o
bfa-y := bfad.o bfad_im.o bfad_attr.o bfad_debugfs.o bfad_bsg.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 19/56] scsi: bnx2fc: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (17 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 18/56] scsi: bfa: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 20/56] scsi: bnx2i: Introduce a local variable Bart Van Assche
` (36 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Saurav Kashyap,
Javed Hasan, GR-QLogic-Storage-Upstream, James E.J. Bottomley
Document the locking requirements with __must_hold(). Inform the
compiler about aliases for synchronization objects with
__assume_ctx_lock(). Make the argument names in the definition and the
declaration of bnx2fc_process_seq_cleanup_compl() consistent.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/bnx2fc/Makefile | 3 +++
drivers/scsi/bnx2fc/bnx2fc.h | 5 +++--
drivers/scsi/bnx2fc/bnx2fc_els.c | 2 ++
drivers/scsi/bnx2fc/bnx2fc_hwi.c | 3 +++
drivers/scsi/bnx2fc/bnx2fc_io.c | 6 +++++-
5 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/bnx2fc/Makefile b/drivers/scsi/bnx2fc/Makefile
index 1d72e279a97d..3feb6b4dae64 100644
--- a/drivers/scsi/bnx2fc/Makefile
+++ b/drivers/scsi/bnx2fc/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_BNX2X_FCOE) += bnx2fc.o
bnx2fc-y := bnx2fc_els.o bnx2fc_fcoe.o bnx2fc_hwi.o bnx2fc_io.o bnx2fc_tgt.o \
diff --git a/drivers/scsi/bnx2fc/bnx2fc.h b/drivers/scsi/bnx2fc/bnx2fc.h
index 8c8968ec8cb4..566632d7e880 100644
--- a/drivers/scsi/bnx2fc/bnx2fc.h
+++ b/drivers/scsi/bnx2fc/bnx2fc.h
@@ -592,9 +592,10 @@ int bnx2fc_send_stat_req(struct bnx2fc_hba *hba);
int bnx2fc_post_io_req(struct bnx2fc_rport *tgt, struct bnx2fc_cmd *io_req);
int bnx2fc_send_rec(struct bnx2fc_cmd *orig_io_req);
int bnx2fc_send_srr(struct bnx2fc_cmd *orig_io_req, u32 offset, u8 r_ctl);
-void bnx2fc_process_seq_cleanup_compl(struct bnx2fc_cmd *seq_clnup_req,
+void bnx2fc_process_seq_cleanup_compl(struct bnx2fc_cmd *seq_clnp_req,
struct fcoe_task_ctx_entry *task,
- u8 rx_state);
+ u8 rx_state)
+ __must_hold(&seq_clnp_req->cb_arg->aborted_io_req->tgt->tgt_lock);
int bnx2fc_initiate_seq_cleanup(struct bnx2fc_cmd *orig_io_req, u32 offset,
enum fc_rctl r_ctl);
diff --git a/drivers/scsi/bnx2fc/bnx2fc_els.c b/drivers/scsi/bnx2fc/bnx2fc_els.c
index 749e30aaf926..1f333a135879 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_els.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_els.c
@@ -263,6 +263,7 @@ int bnx2fc_send_rls(struct bnx2fc_rport *tgt, struct fc_frame *fp)
}
static void bnx2fc_srr_compl(struct bnx2fc_els_cb_arg *cb_arg)
+ __must_hold(&cb_arg->aborted_io_req->tgt->tgt_lock)
{
struct bnx2fc_mp_req *mp_req;
struct fc_frame_header *fc_hdr, *fh;
@@ -373,6 +374,7 @@ static void bnx2fc_srr_compl(struct bnx2fc_els_cb_arg *cb_arg)
}
static void bnx2fc_rec_compl(struct bnx2fc_els_cb_arg *cb_arg)
+ __must_hold(&cb_arg->aborted_io_req->tgt->tgt_lock)
{
struct bnx2fc_cmd *orig_io_req, *new_io_req;
struct bnx2fc_cmd *rec_req;
diff --git a/drivers/scsi/bnx2fc/bnx2fc_hwi.c b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
index a5ecb87d5b2d..a3670c48900b 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_hwi.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
@@ -880,6 +880,9 @@ void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe,
return;
}
+ /* Tell the compiler that there is an alias for tgt->tgt_lock. */
+ __assume_ctx_lock(&io_req->cb_arg->aborted_io_req->tgt->tgt_lock);
+
/* Timestamp IO completion time */
cmd_type = io_req->cmd_type;
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index 9c7a541a4523..351c72404b5f 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -1080,7 +1080,7 @@ int bnx2fc_eh_device_reset(struct scsi_cmnd *sc_cmd)
}
static int bnx2fc_abts_cleanup(struct bnx2fc_cmd *io_req)
- __must_hold(&tgt->tgt_lock)
+ __must_hold(&io_req->tgt->tgt_lock)
{
struct bnx2fc_rport *tgt = io_req->tgt;
unsigned int time_left;
@@ -1207,6 +1207,8 @@ int bnx2fc_eh_abort(struct scsi_cmnd *sc_cmd)
if (cancel_delayed_work(&io_req->timeout_work))
kref_put(&io_req->refcount,
bnx2fc_cmd_release); /* drop timer hold */
+ /* Tell the compiler that io_req->tgt == tgt. */
+ __assume_ctx_lock(&io_req->tgt->tgt_lock);
/*
* We don't want to hold off the upper layer timer so simply
* cleanup the command and return that I/O was successfully
@@ -1258,6 +1260,8 @@ int bnx2fc_eh_abort(struct scsi_cmnd *sc_cmd)
/* Let the scsi-ml try to recover this command */
printk(KERN_ERR PFX "abort failed, xid = 0x%x\n",
io_req->xid);
+ /* Tell the compiler that io_req->tgt == tgt. */
+ __assume_ctx_lock(&io_req->tgt->tgt_lock);
/*
* Cleanup firmware residuals before returning control back
* to SCSI ML.
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 20/56] scsi: bnx2i: Introduce a local variable
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (18 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 19/56] scsi: bnx2fc: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 21/56] scsi: bnx2i: Enable lock context analysis Bart Van Assche
` (35 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Nilesh Javali,
Manish Rangankar, GR-QLogic-Storage-Upstream,
James E.J. Bottomley
Prepare for adding a new statement that will use the new local variable
'conn'. No functionality has been changed.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/bnx2i/bnx2i_hwi.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c
index d24cc2c795d6..4fb68ec8e9b0 100644
--- a/drivers/scsi/bnx2i/bnx2i_hwi.c
+++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
@@ -1741,6 +1741,7 @@ static void bnx2i_process_async_mesg(struct iscsi_session *session,
struct bnx2i_conn *bnx2i_conn,
struct cqe *cqe)
{
+ struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
struct bnx2i_async_msg *async_cqe;
struct iscsi_async *resp_hdr;
u8 async_event;
@@ -1751,7 +1752,7 @@ static void bnx2i_process_async_mesg(struct iscsi_session *session,
async_event = async_cqe->async_event;
if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
- iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
+ iscsi_conn_printk(KERN_ALERT, conn,
"async: scsi events not supported\n");
return;
}
@@ -1773,8 +1774,7 @@ static void bnx2i_process_async_mesg(struct iscsi_session *session,
resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
- __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
- (struct iscsi_hdr *)resp_hdr, NULL, 0);
+ __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
spin_unlock(&session->back_lock);
}
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 21/56] scsi: bnx2i: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (19 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 20/56] scsi: bnx2i: Introduce a local variable Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 22/56] scsi: csiostor: " Bart Van Assche
` (34 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Nilesh Javali,
Manish Rangankar, GR-QLogic-Storage-Upstream,
James E.J. Bottomley
Document locking requirements with __must_hold(). Use
__assume_ctx_lock() to inform the compiler about aliases for
synchronization objects.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/bnx2i/Makefile | 3 +++
drivers/scsi/bnx2i/bnx2i_hwi.c | 8 ++++++++
drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 +
3 files changed, 12 insertions(+)
diff --git a/drivers/scsi/bnx2i/Makefile b/drivers/scsi/bnx2i/Makefile
index 25378671bb1e..2d8e8f0fdd29 100644
--- a/drivers/scsi/bnx2i/Makefile
+++ b/drivers/scsi/bnx2i/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
+
+CONTEXT_ANALYSIS := y
+
bnx2i-y := bnx2i_init.o bnx2i_hwi.o bnx2i_iscsi.o bnx2i_sysfs.o
obj-$(CONFIG_SCSI_BNX2_ISCSI) += bnx2i.o
diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c
index 4fb68ec8e9b0..5d927880d297 100644
--- a/drivers/scsi/bnx2i/bnx2i_hwi.c
+++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
@@ -1347,6 +1347,7 @@ int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
resp_cqe = (struct bnx2i_cmd_response *)cqe;
spin_lock_bh(&session->back_lock);
+ __assume_ctx_lock(&conn->session->back_lock);
task = iscsi_itt_to_task(conn,
resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
if (!task)
@@ -1443,6 +1444,7 @@ static int bnx2i_process_login_resp(struct iscsi_session *session,
login = (struct bnx2i_login_response *) cqe;
spin_lock(&session->back_lock);
+ __assume_ctx_lock(&conn->session->back_lock);
task = iscsi_itt_to_task(conn,
login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
if (!task)
@@ -1511,6 +1513,7 @@ static int bnx2i_process_text_resp(struct iscsi_session *session,
text = (struct bnx2i_text_response *) cqe;
spin_lock(&session->back_lock);
+ __assume_ctx_lock(&conn->session->back_lock);
task = iscsi_itt_to_task(conn, text->itt & ISCSI_LOGIN_RESPONSE_INDEX);
if (!task)
goto done;
@@ -1570,6 +1573,7 @@ static int bnx2i_process_tmf_resp(struct iscsi_session *session,
tmf_cqe = (struct bnx2i_tmf_response *)cqe;
spin_lock(&session->back_lock);
+ __assume_ctx_lock(&conn->session->back_lock);
task = iscsi_itt_to_task(conn,
tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
if (!task)
@@ -1609,6 +1613,7 @@ static int bnx2i_process_logout_resp(struct iscsi_session *session,
logout = (struct bnx2i_logout_response *) cqe;
spin_lock(&session->back_lock);
+ __assume_ctx_lock(&conn->session->back_lock);
task = iscsi_itt_to_task(conn,
logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
if (!task)
@@ -1698,6 +1703,7 @@ static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
nop_in = (struct bnx2i_nop_in_msg *)cqe;
spin_lock(&session->back_lock);
+ __assume_ctx_lock(&conn->session->back_lock);
hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
memset(hdr, 0, sizeof(struct iscsi_hdr));
hdr->opcode = nop_in->op_code;
@@ -1758,6 +1764,7 @@ static void bnx2i_process_async_mesg(struct iscsi_session *session,
}
spin_lock(&session->back_lock);
+ __assume_ctx_lock(&conn->session->back_lock);
resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
resp_hdr->opcode = async_cqe->op_code;
@@ -1803,6 +1810,7 @@ static void bnx2i_process_reject_mesg(struct iscsi_session *session,
bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
spin_lock(&session->back_lock);
+ __assume_ctx_lock(&conn->session->back_lock);
hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
memset(hdr, 0, sizeof(struct iscsi_hdr));
hdr->opcode = reject->op_code;
diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index 6c80e5b514fd..c868eada72c3 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -1154,6 +1154,7 @@ static void bnx2i_cpy_scsi_cdb(struct scsi_cmnd *sc, struct bnx2i_cmd *cmd)
}
static void bnx2i_cleanup_task(struct iscsi_task *task)
+ __must_hold(&task->conn->session->back_lock)
{
struct iscsi_conn *conn = task->conn;
struct bnx2i_conn *bnx2i_conn = conn->dd_data;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 22/56] scsi: csiostor: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (20 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 21/56] scsi: bnx2i: Enable lock context analysis Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 23/56] scsi: elx: " Bart Van Assche
` (33 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley,
Thomas Gleixner, Ingo Molnar, Kees Cook, Colin Ian King
Document lock context requirements with __must_hold().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/csiostor/Makefile | 2 ++
drivers/scsi/csiostor/csio_hw.c | 12 ++++++++++++
drivers/scsi/csiostor/csio_lnode.c | 3 +++
drivers/scsi/csiostor/csio_rnode.c | 6 ++++++
drivers/scsi/csiostor/csio_scsi.c | 6 ++++++
5 files changed, 29 insertions(+)
diff --git a/drivers/scsi/csiostor/Makefile b/drivers/scsi/csiostor/Makefile
index d047e22eac0d..a19031efa7c4 100644
--- a/drivers/scsi/csiostor/Makefile
+++ b/drivers/scsi/csiostor/Makefile
@@ -4,6 +4,8 @@
#
##
+CONTEXT_ANALYSIS := y
+
ccflags-y += -I$(srctree)/drivers/net/ethernet/chelsio/cxgb4
obj-$(CONFIG_SCSI_CHELSIO_FCOE) += csiostor.o
diff --git a/drivers/scsi/csiostor/csio_hw.c b/drivers/scsi/csiostor/csio_hw.c
index df9f81f29950..4b4d3c42667f 100644
--- a/drivers/scsi/csiostor/csio_hw.c
+++ b/drivers/scsi/csiostor/csio_hw.c
@@ -914,6 +914,7 @@ csio_hw_dev_ready(struct csio_hw *hw)
*/
static int
csio_do_hello(struct csio_hw *hw, enum csio_dev_state *state)
+ __must_hold(&hw->lock)
{
struct csio_mb *mbp;
int rv = 0;
@@ -2050,6 +2051,7 @@ csio_hw_flash_config(struct csio_hw *hw, u32 *fw_cfg_param, char *path)
*/
static int
csio_hw_use_fwconfig(struct csio_hw *hw, int reset, u32 *fw_cfg_param)
+ __must_hold(&hw->lock)
{
struct csio_mb *mbp = NULL;
struct fw_caps_config_cmd *caps_cmd;
@@ -2475,6 +2477,7 @@ static int csio_hw_check_fwver(struct csio_hw *hw)
*/
static void
csio_hw_configure(struct csio_hw *hw)
+ __must_hold(&hw->lock)
{
int reset = 1;
int rv;
@@ -2604,6 +2607,7 @@ csio_hw_configure(struct csio_hw *hw)
*/
static void
csio_hw_initialize(struct csio_hw *hw)
+ __must_hold(&hw->lock)
{
struct csio_mb *mbp;
enum fw_retval retval;
@@ -2778,6 +2782,7 @@ csio_hw_fatal_err(struct csio_hw *hw)
*/
static void
csio_hws_uninit(struct csio_hw *hw, enum csio_hw_ev evt)
+ __must_hold(&hw->lock)
{
hw->prev_evt = hw->cur_evt;
hw->cur_evt = evt;
@@ -2803,6 +2808,7 @@ csio_hws_uninit(struct csio_hw *hw, enum csio_hw_ev evt)
*/
static void
csio_hws_configuring(struct csio_hw *hw, enum csio_hw_ev evt)
+ __must_hold(&hw->lock)
{
hw->prev_evt = hw->cur_evt;
hw->cur_evt = evt;
@@ -2988,6 +2994,7 @@ csio_hws_quiescing(struct csio_hw *hw, enum csio_hw_ev evt)
*/
static void
csio_hws_quiesced(struct csio_hw *hw, enum csio_hw_ev evt)
+ __must_hold(&hw->lock)
{
hw->prev_evt = hw->cur_evt;
hw->cur_evt = evt;
@@ -3013,6 +3020,7 @@ csio_hws_quiesced(struct csio_hw *hw, enum csio_hw_ev evt)
*/
static void
csio_hws_resetting(struct csio_hw *hw, enum csio_hw_ev evt)
+ __must_hold(&hw->lock)
{
hw->prev_evt = hw->cur_evt;
hw->cur_evt = evt;
@@ -3074,6 +3082,7 @@ csio_hws_removing(struct csio_hw *hw, enum csio_hw_ev evt)
*/
static void
csio_hws_pcierr(struct csio_hw *hw, enum csio_hw_ev evt)
+ __must_hold(&hw->lock)
{
hw->prev_evt = hw->cur_evt;
hw->cur_evt = evt;
@@ -3763,6 +3772,7 @@ csio_hw_mb_timer(struct timer_list *t)
*/
static void
csio_hw_mbm_cleanup(struct csio_hw *hw)
+ __must_hold(&hw->lock)
{
LIST_HEAD(cbfn_q);
@@ -3883,6 +3893,7 @@ csio_free_evt(struct csio_hw *hw, struct csio_evt_msg *evt_entry)
void
csio_evtq_flush(struct csio_hw *hw)
+ __must_hold(&hw->lock)
{
uint32_t count;
count = 30;
@@ -4142,6 +4153,7 @@ csio_mgmt_tmo_handler(struct timer_list *t)
static void
csio_mgmtm_cleanup(struct csio_mgmtm *mgmtm)
+ __must_hold(&mgmtm->hw->lock)
{
struct csio_hw *hw = mgmtm->hw;
struct csio_ioreq *io_req;
diff --git a/drivers/scsi/csiostor/csio_lnode.c b/drivers/scsi/csiostor/csio_lnode.c
index 78d5ecd14f65..161973957976 100644
--- a/drivers/scsi/csiostor/csio_lnode.c
+++ b/drivers/scsi/csiostor/csio_lnode.c
@@ -872,6 +872,7 @@ csio_ln_read_fcf_entry(struct csio_lnode *ln,
static void
csio_handle_link_up(struct csio_hw *hw, uint8_t portid, uint32_t fcfi,
uint32_t vnpi)
+ __must_hold(&hw->lock)
{
struct csio_lnode *ln = NULL;
@@ -1165,6 +1166,7 @@ csio_lns_uninit(struct csio_lnode *ln, enum csio_ln_ev evt)
*/
static void
csio_lns_online(struct csio_lnode *ln, enum csio_ln_ev evt)
+ __must_hold(&csio_lnode_to_hw(ln)->lock)
{
struct csio_hw *hw = csio_lnode_to_hw(ln);
@@ -1216,6 +1218,7 @@ csio_lns_online(struct csio_lnode *ln, enum csio_ln_ev evt)
*/
static void
csio_lns_ready(struct csio_lnode *ln, enum csio_ln_ev evt)
+ __must_hold(&csio_lnode_to_hw(ln)->lock)
{
struct csio_hw *hw = csio_lnode_to_hw(ln);
diff --git a/drivers/scsi/csiostor/csio_rnode.c b/drivers/scsi/csiostor/csio_rnode.c
index 713e13adf4dc..74ef1e858cf3 100644
--- a/drivers/scsi/csiostor/csio_rnode.c
+++ b/drivers/scsi/csiostor/csio_rnode.c
@@ -546,6 +546,7 @@ csio_rn_verify_rparams(struct csio_lnode *ln, struct csio_rnode *rn,
static void
__csio_reg_rnode(struct csio_rnode *rn)
+ __must_hold(&csio_lnode_to_hw(csio_rnode_to_lnode(rn))->lock)
{
struct csio_lnode *ln = csio_rnode_to_lnode(rn);
struct csio_hw *hw = csio_lnode_to_hw(ln);
@@ -563,6 +564,7 @@ __csio_reg_rnode(struct csio_rnode *rn)
static void
__csio_unreg_rnode(struct csio_rnode *rn)
+ __must_hold(&csio_lnode_to_hw(csio_rnode_to_lnode(rn))->lock)
{
struct csio_lnode *ln = csio_rnode_to_lnode(rn);
struct csio_hw *hw = csio_lnode_to_hw(ln);
@@ -602,6 +604,7 @@ __csio_unreg_rnode(struct csio_rnode *rn)
*/
static void
csio_rns_uninit(struct csio_rnode *rn, enum csio_rn_ev evt)
+ __must_hold(&csio_rnode_to_lnode(rn)->hwp->lock)
{
struct csio_lnode *ln = csio_rnode_to_lnode(rn);
int ret = 0;
@@ -642,6 +645,7 @@ csio_rns_uninit(struct csio_rnode *rn, enum csio_rn_ev evt)
*/
static void
csio_rns_ready(struct csio_rnode *rn, enum csio_rn_ev evt)
+ __must_hold(&csio_rnode_to_lnode(rn)->hwp->lock)
{
struct csio_lnode *ln = csio_rnode_to_lnode(rn);
int ret = 0;
@@ -727,6 +731,7 @@ csio_rns_ready(struct csio_rnode *rn, enum csio_rn_ev evt)
*/
static void
csio_rns_offline(struct csio_rnode *rn, enum csio_rn_ev evt)
+ __must_hold(&csio_rnode_to_lnode(rn)->hwp->lock)
{
struct csio_lnode *ln = csio_rnode_to_lnode(rn);
int ret = 0;
@@ -786,6 +791,7 @@ csio_rns_offline(struct csio_rnode *rn, enum csio_rn_ev evt)
*/
static void
csio_rns_disappeared(struct csio_rnode *rn, enum csio_rn_ev evt)
+ __must_hold(&csio_rnode_to_lnode(rn)->hwp->lock)
{
struct csio_lnode *ln = csio_rnode_to_lnode(rn);
int ret = 0;
diff --git a/drivers/scsi/csiostor/csio_scsi.c b/drivers/scsi/csiostor/csio_scsi.c
index b1de615cf316..b74fed463640 100644
--- a/drivers/scsi/csiostor/csio_scsi.c
+++ b/drivers/scsi/csiostor/csio_scsi.c
@@ -1157,6 +1157,7 @@ csio_scsi_cmpl_handler(struct csio_hw *hw, void *wr, uint32_t len,
*/
void
csio_scsi_cleanup_io_q(struct csio_scsim *scm, struct list_head *q)
+ __must_hold(&scm->hw->lock)
{
struct csio_hw *hw = scm->hw;
struct csio_ioreq *ioreq;
@@ -1231,6 +1232,7 @@ csio_abrt_cls(struct csio_ioreq *ioreq, struct scsi_cmnd *scmnd)
*/
static int
csio_scsi_abort_io_q(struct csio_scsim *scm, struct list_head *q, uint32_t tmo)
+ __must_hold(&scm->hw->lock)
{
struct csio_hw *hw = scm->hw;
struct list_head *tmp, *next;
@@ -1271,6 +1273,7 @@ csio_scsi_abort_io_q(struct csio_scsim *scm, struct list_head *q, uint32_t tmo)
*/
int
csio_scsim_cleanup_io(struct csio_scsim *scm, bool abort)
+ __must_hold(&scm->hw->lock)
{
struct csio_hw *hw = scm->hw;
int rv = 0;
@@ -1316,6 +1319,7 @@ csio_scsim_cleanup_io(struct csio_scsim *scm, bool abort)
*/
int
csio_scsim_cleanup_io_lnode(struct csio_scsim *scm, struct csio_lnode *ln)
+ __must_hold(&scm->hw->lock)
{
struct csio_hw *hw = scm->hw;
struct csio_scsi_level_data sld;
@@ -2192,6 +2196,8 @@ csio_eh_lun_reset_handler(struct scsi_cmnd *cmnd)
* completes, we gather pending I/Os after the LUN reset.
*/
spin_lock_irq(&hw->lock);
+ /* Tell the compiler that scsim->hw == hw. */
+ __assume_ctx_lock(&scsim->hw->lock);
csio_scsi_gather_active_ios(scsim, &sld, &local_q);
retval = csio_scsi_abort_io_q(scsim, &local_q, 30000);
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 23/56] scsi: elx: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (21 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 22/56] scsi: csiostor: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 24/56] scsi: esas2r: " Bart Van Assche
` (32 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Ram Vegesna,
James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/elx/Makefile | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/scsi/elx/Makefile b/drivers/scsi/elx/Makefile
index a8537d7a2a6e..0ed508e379fb 100644
--- a/drivers/scsi/elx/Makefile
+++ b/drivers/scsi/elx/Makefile
@@ -4,6 +4,7 @@
# * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
# */
+CONTEXT_ANALYSIS := y
obj-$(CONFIG_SCSI_EFCT) := efct.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 24/56] scsi: esas2r: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (22 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 23/56] scsi: elx: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 25/56] scsi: fcoe: " Bart Van Assche
` (31 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/esas2r/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/esas2r/Makefile b/drivers/scsi/esas2r/Makefile
index 279d9cb3ca69..325fa0e634fa 100644
--- a/drivers/scsi/esas2r/Makefile
+++ b/drivers/scsi/esas2r/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_ESAS2R) += esas2r.o
esas2r-objs := esas2r_log.o esas2r_disc.o esas2r_flash.o esas2r_init.o \
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 25/56] scsi: fcoe: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (23 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 24/56] scsi: esas2r: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 26/56] scsi: fnic: " Bart Van Assche
` (30 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Hannes Reinecke,
James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/fcoe/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/fcoe/Makefile b/drivers/scsi/fcoe/Makefile
index 1183e80a09e7..5e7121231801 100644
--- a/drivers/scsi/fcoe/Makefile
+++ b/drivers/scsi/fcoe/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_FCOE) += fcoe.o
obj-$(CONFIG_LIBFCOE) += libfcoe.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 26/56] scsi: fnic: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (24 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 25/56] scsi: fcoe: " Bart Van Assche
@ 2026-04-30 18:19 ` 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
` (29 subsequent siblings)
55 siblings, 1 reply; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Satish Kharat,
Sesidhar Baddela, Karan Tilak Kumar, James E.J. Bottomley
Document locking requirements with __must_hold(). Suppress complaints
about conditional locking in fnic_device_reset() with __acquire() and
__release().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/fnic/Makefile | 3 ++
drivers/scsi/fnic/fdls_disc.c | 52 +++++++++++++++++++++++++++++++++--
drivers/scsi/fnic/fip.c | 2 ++
drivers/scsi/fnic/fnic_fcs.c | 6 ++++
drivers/scsi/fnic/fnic_scsi.c | 4 +++
5 files changed, 65 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/fnic/Makefile b/drivers/scsi/fnic/Makefile
index c025e875009e..4cd6c7972d05 100644
--- a/drivers/scsi/fnic/Makefile
+++ b/drivers/scsi/fnic/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_FCOE_FNIC) += fnic.o
fnic-y := \
diff --git a/drivers/scsi/fnic/fdls_disc.c b/drivers/scsi/fnic/fdls_disc.c
index 554dea767885..0ac12edb7df1 100644
--- a/drivers/scsi/fnic/fdls_disc.c
+++ b/drivers/scsi/fnic/fdls_disc.c
@@ -391,6 +391,7 @@ static void fdls_reset_oxid_pool(struct fnic_iport_s *iport)
}
void fnic_del_fabric_timer_sync(struct fnic *fnic)
+ __must_hold(&fnic->fnic_lock)
{
fnic->iport.fabric.del_timer_inprogress = 1;
spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
@@ -399,8 +400,8 @@ void fnic_del_fabric_timer_sync(struct fnic *fnic)
fnic->iport.fabric.del_timer_inprogress = 0;
}
-void fnic_del_tport_timer_sync(struct fnic *fnic,
- struct fnic_tport_s *tport)
+void fnic_del_tport_timer_sync(struct fnic *fnic, struct fnic_tport_s *tport)
+ __must_hold(&fnic->fnic_lock)
{
tport->del_timer_inprogress = 1;
spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
@@ -411,6 +412,7 @@ void fnic_del_tport_timer_sync(struct fnic *fnic,
static void
fdls_start_fabric_timer(struct fnic_iport_s *iport, int timeout)
+ __must_hold(&iport->fnic->fnic_lock)
{
u64 fabric_tov;
struct fnic *fnic = iport->fnic;
@@ -436,6 +438,7 @@ fdls_start_fabric_timer(struct fnic_iport_s *iport, int timeout)
static void
fdls_start_tport_timer(struct fnic_iport_s *iport,
struct fnic_tport_s *tport, int timeout)
+ __must_hold(&iport->fnic->fnic_lock)
{
u64 fabric_tov;
struct fnic *fnic = iport->fnic;
@@ -631,6 +634,7 @@ fdls_send_logo_resp(struct fnic_iport_s *iport,
void
fdls_send_tport_abts(struct fnic_iport_s *iport,
struct fnic_tport_s *tport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
uint8_t s_id[3];
@@ -674,7 +678,9 @@ fdls_send_tport_abts(struct fnic_iport_s *iport,
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_tport_timer(iport, tport, 2 * iport->e_d_tov);
}
+
static void fdls_send_fabric_abts(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
uint8_t s_id[3];
@@ -846,6 +852,7 @@ static void fdls_send_fdmi_abts(struct fnic_iport_s *iport)
}
static void fdls_send_fabric_flogi(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
struct fc_std_flogi *pflogi;
@@ -906,6 +913,7 @@ static void fdls_send_fabric_flogi(struct fnic_iport_s *iport)
}
static void fdls_send_fabric_plogi(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
struct fc_std_flogi *pplogi;
@@ -998,6 +1006,7 @@ static void fdls_send_fdmi_plogi(struct fnic_iport_s *iport)
}
static void fdls_send_rpn_id(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
struct fc_std_rpn_id *prpn_id;
@@ -1057,6 +1066,7 @@ static void fdls_send_rpn_id(struct fnic_iport_s *iport)
}
static void fdls_send_scr(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
struct fc_std_scr *pscr;
@@ -1112,6 +1122,7 @@ static void fdls_send_scr(struct fnic_iport_s *iport)
}
static void fdls_send_gpn_ft(struct fnic_iport_s *iport, int fdls_state)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
struct fc_std_gpn_ft *pgpn_ft;
@@ -1171,6 +1182,7 @@ static void fdls_send_gpn_ft(struct fnic_iport_s *iport, int fdls_state)
static void
fdls_send_tgt_adisc(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
struct fc_std_els_adisc *padisc;
@@ -1236,6 +1248,7 @@ fdls_send_tgt_adisc(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
}
bool fdls_delete_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic_tport_event_s *tport_del_evt;
struct fnic *fnic = iport->fnic;
@@ -1293,6 +1306,7 @@ bool fdls_delete_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
static void
fdls_send_tgt_plogi(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
struct fc_std_flogi *pplogi;
@@ -1361,6 +1375,7 @@ fnic_fc_plogi_rsp_rdf(struct fnic_iport_s *iport,
}
static void fdls_send_register_fc4_types(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
struct fc_std_rft_id *prft_id;
@@ -1421,6 +1436,7 @@ static void fdls_send_register_fc4_types(struct fnic_iport_s *iport)
}
static void fdls_send_register_fc4_features(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
struct fc_std_rff_id *prff_id;
@@ -1480,6 +1496,7 @@ static void fdls_send_register_fc4_features(struct fnic_iport_s *iport)
static void
fdls_send_tgt_prli(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
struct fc_std_els_prli *pprli;
@@ -1553,6 +1570,7 @@ fdls_send_tgt_prli(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
* Currently this assumes to be called with fnic lock held.
*/
void fdls_send_fabric_logo(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint8_t *frame;
struct fc_std_logo *plogo;
@@ -1652,6 +1670,7 @@ void fdls_tgt_logout(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
}
static void fdls_tgt_discovery_start(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic_tport_s *tport, *next;
u32 old_link_down_cnt = iport->fnic->link_down_cnt;
@@ -1702,6 +1721,7 @@ static void fdls_tgt_discovery_start(struct fnic_iport_s *iport)
* pointing to it will be freed later
*/
static void fdls_target_restart_nexus(struct fnic_tport_s *tport)
+ __must_hold(&((struct fnic_iport_s *)tport->iport)->fnic->fnic_lock)
{
struct fnic_iport_s *iport = tport->iport;
struct fnic_tport_s *new_tport = NULL;
@@ -2482,6 +2502,7 @@ static void fdls_tport_timer_callback(struct timer_list *t)
}
static void fnic_fdls_start_flogi(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
iport->fabric.retry_counter = 0;
fdls_send_fabric_flogi(iport);
@@ -2490,6 +2511,7 @@ static void fnic_fdls_start_flogi(struct fnic_iport_s *iport)
}
static void fnic_fdls_start_plogi(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
iport->fabric.retry_counter = 0;
fdls_send_fabric_plogi(iport);
@@ -2508,6 +2530,7 @@ static void fnic_fdls_start_plogi(struct fnic_iport_s *iport)
static void
fdls_process_tgt_adisc_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint32_t tgt_fcid;
struct fnic_tport_s *tport;
@@ -2598,6 +2621,7 @@ fdls_process_tgt_adisc_rsp(struct fnic_iport_s *iport,
static void
fdls_process_tgt_plogi_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint32_t tgt_fcid;
struct fnic_tport_s *tport;
@@ -2632,6 +2656,8 @@ fdls_process_tgt_plogi_rsp(struct fnic_iport_s *iport,
if (tport->state != FDLS_TGT_STATE_PLOGI) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PLOGI rsp recvd in wrong state. Drop the frame and restart nexus");
+ /* Tell the compiler that tport->iport == iport. */
+ __assume_ctx_lock(&((struct fnic_iport_s *)tport->iport)->fnic->fnic_lock);
fdls_target_restart_nexus(tport);
return;
}
@@ -2719,9 +2745,11 @@ fdls_process_tgt_plogi_rsp(struct fnic_iport_s *iport,
fdls_set_tport_state(tport, FDLS_TGT_STATE_PRLI);
fdls_send_tgt_prli(iport, tport);
}
+
static void
fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint32_t tgt_fcid;
struct fnic_tport_s *tport;
@@ -2758,6 +2786,8 @@ fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport,
if (tport->state != FDLS_TGT_STATE_PRLI) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PRLI rsp recvd in wrong state. Drop frame. Restarting nexus");
+ /* Tell the compiler that tport->iport == iport. */
+ __assume_ctx_lock(&((struct fnic_iport_s *)tport->iport)->fnic->fnic_lock);
fdls_target_restart_nexus(tport);
return;
}
@@ -2872,6 +2902,7 @@ fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport,
static void
fdls_process_rff_id_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic *fnic = iport->fnic;
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
@@ -2945,6 +2976,7 @@ fdls_process_rff_id_rsp(struct fnic_iport_s *iport,
static void
fdls_process_rft_id_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fc_std_rft_id *rft_rsp = (struct fc_std_rft_id *) fchdr;
@@ -3020,6 +3052,7 @@ fdls_process_rft_id_rsp(struct fnic_iport_s *iport,
static void
fdls_process_rpn_id_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fc_std_rpn_id *rpn_rsp = (struct fc_std_rpn_id *) fchdr;
@@ -3090,6 +3123,7 @@ fdls_process_rpn_id_rsp(struct fnic_iport_s *iport,
static void
fdls_process_scr_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fc_std_scr *scr_rsp = (struct fc_std_scr *) fchdr;
@@ -3162,6 +3196,7 @@ fdls_process_scr_rsp(struct fnic_iport_s *iport,
static void
fdls_process_gpn_ft_tgt_list(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr, int len)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fc_gpn_ft_rsp_iu *gpn_ft_tgt;
struct fnic_tport_s *tport, *next;
@@ -3260,6 +3295,7 @@ fdls_process_gpn_ft_tgt_list(struct fnic_iport_s *iport,
static void
fdls_process_gpn_ft_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr, int len)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fc_std_gpn_ft *gpn_ft_rsp = (struct fc_std_gpn_ft *) fchdr;
@@ -3396,6 +3432,7 @@ fdls_process_gpn_ft_rsp(struct fnic_iport_s *iport,
static void
fdls_process_fabric_logo_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fc_std_flogi *flogo_rsp = (struct fc_std_flogi *) fchdr;
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
@@ -3449,6 +3486,7 @@ fdls_process_fabric_logo_rsp(struct fnic_iport_s *iport,
static void
fdls_process_flogi_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr, void *rx_frame)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic_fdls_fabric_s *fabric = &iport->fabric;
struct fc_std_flogi *flogi_rsp = (struct fc_std_flogi *) fchdr;
@@ -3586,6 +3624,7 @@ fdls_process_flogi_rsp(struct fnic_iport_s *iport,
static void
fdls_process_fabric_plogi_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fc_std_flogi *plogi_rsp = (struct fc_std_flogi *) fchdr;
struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *) fchdr;
@@ -3847,6 +3886,7 @@ static void fdls_process_fdmi_abts_rsp(struct fnic_iport_s *iport,
static void
fdls_process_fabric_abts_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint32_t s_id;
struct fc_std_abts_ba_acc *ba_acc = (struct fc_std_abts_ba_acc *)fchdr;
@@ -4204,6 +4244,7 @@ fdls_process_els_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr,
static void
fdls_process_tgt_abts_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
uint32_t s_id;
struct fnic_tport_s *tport;
@@ -4393,6 +4434,7 @@ fdls_process_plogi_req(struct fnic_iport_s *iport,
static void
fdls_process_logo_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fc_std_logo *logo = (struct fc_std_logo *)fchdr;
uint32_t nport_id;
@@ -4433,6 +4475,8 @@ fdls_process_logo_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"tport fcid 0x%x: Canceling disc timer\n",
tport->fcid);
+ /* Tell the compiler that tport->iport == iport. */
+ __assume_ctx_lock(&((struct fnic_iport_s *)tport->iport)->fnic->fnic_lock);
fnic_del_tport_timer_sync(fnic, tport);
tport->timer_pending = 0;
}
@@ -4470,6 +4514,7 @@ fdls_process_logo_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
static void
fdls_process_rscn(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fc_std_rscn *rscn;
struct fc_els_rscn_page *rscn_port = NULL;
@@ -4603,6 +4648,7 @@ fdls_process_rscn(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
}
void fnic_fdls_disc_start(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic *fnic = iport->fnic;
@@ -4943,6 +4989,7 @@ fnic_fdls_validate_and_get_frame_type(struct fnic_iport_s *iport,
void fnic_fdls_recv_frame(struct fnic_iport_s *iport, void *rx_frame,
int len, int fchdr_offset)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fc_frame_header *fchdr;
uint32_t s_id = 0;
@@ -5061,6 +5108,7 @@ void fnic_fdls_disc_init(struct fnic_iport_s *iport)
}
void fnic_fdls_link_down(struct fnic_iport_s *iport)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic_tport_s *tport, *next;
struct fnic *fnic = iport->fnic;
diff --git a/drivers/scsi/fnic/fip.c b/drivers/scsi/fnic/fip.c
index 132f00512ee1..da8a8e9ffea4 100644
--- a/drivers/scsi/fnic/fip.c
+++ b/drivers/scsi/fnic/fip.c
@@ -610,6 +610,7 @@ void fnic_common_fip_cleanup(struct fnic *fnic)
* and clean up and restart the vlan discovery.
*/
void fnic_fcoe_process_cvl(struct fnic *fnic, struct fip_header *fiph)
+ __must_hold(&fnic->fnic_lock)
{
struct fnic_iport_s *iport = &fnic->iport;
struct fip_cvl *cvl_msg = (struct fip_cvl *)fiph;
@@ -687,6 +688,7 @@ void fnic_fcoe_process_cvl(struct fnic *fnic, struct fip_header *fiph)
* @frame: Received ethernet frame
*/
int fdls_fip_recv_frame(struct fnic *fnic, void *frame)
+ __must_hold(&fnic->fnic_lock)
{
struct ethhdr *eth = (struct ethhdr *)frame;
struct fip_header *fiph;
diff --git a/drivers/scsi/fnic/fnic_fcs.c b/drivers/scsi/fnic/fnic_fcs.c
index 063eb864a5cd..99f9fe13dfe4 100644
--- a/drivers/scsi/fnic/fnic_fcs.c
+++ b/drivers/scsi/fnic/fnic_fcs.c
@@ -925,6 +925,7 @@ void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
void
fnic_fdls_add_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport,
unsigned long flags)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic *fnic = iport->fnic;
struct fc_rport *rport;
@@ -964,6 +965,7 @@ fnic_fdls_add_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport,
void
fnic_fdls_remove_tport(struct fnic_iport_s *iport,
struct fnic_tport_s *tport, unsigned long flags)
+ __must_hold(&iport->fnic->fnic_lock)
{
struct fnic *fnic = iport->fnic;
struct rport_dd_data_s *rdd_data;
@@ -1013,6 +1015,8 @@ void fnic_delete_fcp_tports(struct fnic *fnic)
unsigned long flags;
spin_lock_irqsave(&fnic->fnic_lock, flags);
+ /* Tell the compiler that fnic->iport.fnic == fnic. */
+ __assume_ctx_lock(&fnic->iport.fnic->fnic_lock);
list_for_each_entry_safe(tport, next, &fnic->iport.tport_list, links) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"removing fcp rport fcid: 0x%x", tport->fcid);
@@ -1037,6 +1041,8 @@ void fnic_tport_event_handler(struct work_struct *work)
struct fnic_tport_s *tport;
spin_lock_irqsave(&fnic->fnic_lock, flags);
+ /* Tell the compiler that fnic->iport.fnic == fnic. */
+ __assume_ctx_lock(&fnic->iport.fnic->fnic_lock);
list_for_each_entry_safe(cur_evt, next, &fnic->tport_event_list, links) {
tport = cur_evt->arg1;
switch (cur_evt->event) {
diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
index 6ee3c559e129..a757b20756ad 100644
--- a/drivers/scsi/fnic/fnic_scsi.c
+++ b/drivers/scsi/fnic/fnic_scsi.c
@@ -2617,6 +2617,8 @@ int fnic_device_reset(struct scsi_cmnd *sc)
* allocated by mid layer.
*/
mutex_lock(&fnic->sgreset_mutex);
+ /* Fake __release() to keep the lock context analyzer happy. */
+ __release(&fnic->sgreset_mutex);
mqtag = fnic->fnic_max_tag_id;
new_sc = 1;
} else {
@@ -2803,6 +2805,8 @@ int fnic_device_reset(struct scsi_cmnd *sc)
if (new_sc) {
fnic->sgreset_sc = NULL;
+ /* Fake __acquire() to keep the lock context analyzer happy. */
+ __acquire(&fnic->sgreset_mutex);
mutex_unlock(&fnic->sgreset_mutex);
}
^ permalink raw reply related [flat|nested] 62+ messages in thread* RE: [PATCH v2 26/56] scsi: fnic: Enable lock context analysis
2026-04-30 18:19 ` [PATCH v2 26/56] scsi: fnic: " Bart Van Assche
@ 2026-05-04 17:45 ` Karan Tilak Kumar (kartilak)
0 siblings, 0 replies; 62+ messages in thread
From: Karan Tilak Kumar (kartilak) @ 2026-05-04 17:45 UTC (permalink / raw)
To: Bart Van Assche, Martin K . Petersen
Cc: linux-scsi@vger.kernel.org, Marco Elver, Satish Kharat (satishkh),
Sesidhar Baddela (sebaddel), James E.J. Bottomley,
Arulprabhu Ponnusamy (arulponn), Gian Carlo Boffa (gcboffa),
Arun Easi (aeasi)
On Thursday, April 30, 2026 11:20 AM, Bart Van Assche <bvanassche@acm.org> wrote:
>
> Document locking requirements with __must_hold(). Suppress complaints
> about conditional locking in fnic_device_reset() with __acquire() and
> __release().
>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> drivers/scsi/fnic/Makefile | 3 ++
> drivers/scsi/fnic/fdls_disc.c | 52 +++++++++++++++++++++++++++++++++--
> drivers/scsi/fnic/fip.c | 2 ++
> drivers/scsi/fnic/fnic_fcs.c | 6 ++++
> drivers/scsi/fnic/fnic_scsi.c | 4 +++
> 5 files changed, 65 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/fnic/Makefile b/drivers/scsi/fnic/Makefile
> index c025e875009e..4cd6c7972d05 100644
> --- a/drivers/scsi/fnic/Makefile
> +++ b/drivers/scsi/fnic/Makefile
> @@ -1,4 +1,7 @@
> # SPDX-License-Identifier: GPL-2.0
> +
> +CONTEXT_ANALYSIS := y
> +
> obj-$(CONFIG_FCOE_FNIC) += fnic.o
>
> fnic-y := \
> diff --git a/drivers/scsi/fnic/fdls_disc.c b/drivers/scsi/fnic/fdls_disc.c
> index 554dea767885..0ac12edb7df1 100644
> --- a/drivers/scsi/fnic/fdls_disc.c
> +++ b/drivers/scsi/fnic/fdls_disc.c
> @@ -391,6 +391,7 @@ static void fdls_reset_oxid_pool(struct fnic_iport_s *iport)
> }
>
> void fnic_del_fabric_timer_sync(struct fnic *fnic)
> + __must_hold(&fnic->fnic_lock)
> {
> fnic->iport.fabric.del_timer_inprogress = 1;
> spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
> @@ -399,8 +400,8 @@ void fnic_del_fabric_timer_sync(struct fnic *fnic)
> fnic->iport.fabric.del_timer_inprogress = 0;
> }
>
> -void fnic_del_tport_timer_sync(struct fnic *fnic,
> - struct fnic_tport_s *tport)
> +void fnic_del_tport_timer_sync(struct fnic *fnic, struct fnic_tport_s *tport)
> + __must_hold(&fnic->fnic_lock)
> {
> tport->del_timer_inprogress = 1;
> spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
> @@ -411,6 +412,7 @@ void fnic_del_tport_timer_sync(struct fnic *fnic,
>
> static void
> fdls_start_fabric_timer(struct fnic_iport_s *iport, int timeout)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> u64 fabric_tov;
> struct fnic *fnic = iport->fnic;
> @@ -436,6 +438,7 @@ fdls_start_fabric_timer(struct fnic_iport_s *iport, int timeout)
> static void
> fdls_start_tport_timer(struct fnic_iport_s *iport,
> struct fnic_tport_s *tport, int timeout)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> u64 fabric_tov;
> struct fnic *fnic = iport->fnic;
> @@ -631,6 +634,7 @@ fdls_send_logo_resp(struct fnic_iport_s *iport,
> void
> fdls_send_tport_abts(struct fnic_iport_s *iport,
> struct fnic_tport_s *tport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> uint8_t s_id[3];
> @@ -674,7 +678,9 @@ fdls_send_tport_abts(struct fnic_iport_s *iport,
> /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
> fdls_start_tport_timer(iport, tport, 2 * iport->e_d_tov);
> }
> +
> static void fdls_send_fabric_abts(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> uint8_t s_id[3];
> @@ -846,6 +852,7 @@ static void fdls_send_fdmi_abts(struct fnic_iport_s *iport)
> }
>
> static void fdls_send_fabric_flogi(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> struct fc_std_flogi *pflogi;
> @@ -906,6 +913,7 @@ static void fdls_send_fabric_flogi(struct fnic_iport_s *iport)
> }
>
> static void fdls_send_fabric_plogi(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> struct fc_std_flogi *pplogi;
> @@ -998,6 +1006,7 @@ static void fdls_send_fdmi_plogi(struct fnic_iport_s *iport)
> }
>
> static void fdls_send_rpn_id(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> struct fc_std_rpn_id *prpn_id;
> @@ -1057,6 +1066,7 @@ static void fdls_send_rpn_id(struct fnic_iport_s *iport)
> }
>
> static void fdls_send_scr(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> struct fc_std_scr *pscr;
> @@ -1112,6 +1122,7 @@ static void fdls_send_scr(struct fnic_iport_s *iport)
> }
>
> static void fdls_send_gpn_ft(struct fnic_iport_s *iport, int fdls_state)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> struct fc_std_gpn_ft *pgpn_ft;
> @@ -1171,6 +1182,7 @@ static void fdls_send_gpn_ft(struct fnic_iport_s *iport, int fdls_state)
>
> static void
> fdls_send_tgt_adisc(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> struct fc_std_els_adisc *padisc;
> @@ -1236,6 +1248,7 @@ fdls_send_tgt_adisc(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
> }
>
> bool fdls_delete_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic_tport_event_s *tport_del_evt;
> struct fnic *fnic = iport->fnic;
> @@ -1293,6 +1306,7 @@ bool fdls_delete_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
>
> static void
> fdls_send_tgt_plogi(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> struct fc_std_flogi *pplogi;
> @@ -1361,6 +1375,7 @@ fnic_fc_plogi_rsp_rdf(struct fnic_iport_s *iport,
> }
>
> static void fdls_send_register_fc4_types(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> struct fc_std_rft_id *prft_id;
> @@ -1421,6 +1436,7 @@ static void fdls_send_register_fc4_types(struct fnic_iport_s *iport)
> }
>
> static void fdls_send_register_fc4_features(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> struct fc_std_rff_id *prff_id;
> @@ -1480,6 +1496,7 @@ static void fdls_send_register_fc4_features(struct fnic_iport_s *iport)
>
> static void
> fdls_send_tgt_prli(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> struct fc_std_els_prli *pprli;
> @@ -1553,6 +1570,7 @@ fdls_send_tgt_prli(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
> * Currently this assumes to be called with fnic lock held.
> */
> void fdls_send_fabric_logo(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint8_t *frame;
> struct fc_std_logo *plogo;
> @@ -1652,6 +1670,7 @@ void fdls_tgt_logout(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
> }
>
> static void fdls_tgt_discovery_start(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic_tport_s *tport, *next;
> u32 old_link_down_cnt = iport->fnic->link_down_cnt;
> @@ -1702,6 +1721,7 @@ static void fdls_tgt_discovery_start(struct fnic_iport_s *iport)
> * pointing to it will be freed later
> */
> static void fdls_target_restart_nexus(struct fnic_tport_s *tport)
> + __must_hold(&((struct fnic_iport_s *)tport->iport)->fnic->fnic_lock)
> {
> struct fnic_iport_s *iport = tport->iport;
> struct fnic_tport_s *new_tport = NULL;
> @@ -2482,6 +2502,7 @@ static void fdls_tport_timer_callback(struct timer_list *t)
> }
>
> static void fnic_fdls_start_flogi(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> iport->fabric.retry_counter = 0;
> fdls_send_fabric_flogi(iport);
> @@ -2490,6 +2511,7 @@ static void fnic_fdls_start_flogi(struct fnic_iport_s *iport)
> }
>
> static void fnic_fdls_start_plogi(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> iport->fabric.retry_counter = 0;
> fdls_send_fabric_plogi(iport);
> @@ -2508,6 +2530,7 @@ static void fnic_fdls_start_plogi(struct fnic_iport_s *iport)
> static void
> fdls_process_tgt_adisc_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint32_t tgt_fcid;
> struct fnic_tport_s *tport;
> @@ -2598,6 +2621,7 @@ fdls_process_tgt_adisc_rsp(struct fnic_iport_s *iport,
> static void
> fdls_process_tgt_plogi_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint32_t tgt_fcid;
> struct fnic_tport_s *tport;
> @@ -2632,6 +2656,8 @@ fdls_process_tgt_plogi_rsp(struct fnic_iport_s *iport,
> if (tport->state != FDLS_TGT_STATE_PLOGI) {
> FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
> "PLOGI rsp recvd in wrong state. Drop the frame and restart nexus");
> + /* Tell the compiler that tport->iport == iport. */
> + __assume_ctx_lock(&((struct fnic_iport_s *)tport->iport)->fnic->fnic_lock);
> fdls_target_restart_nexus(tport);
> return;
> }
> @@ -2719,9 +2745,11 @@ fdls_process_tgt_plogi_rsp(struct fnic_iport_s *iport,
> fdls_set_tport_state(tport, FDLS_TGT_STATE_PRLI);
> fdls_send_tgt_prli(iport, tport);
> }
> +
> static void
> fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint32_t tgt_fcid;
> struct fnic_tport_s *tport;
> @@ -2758,6 +2786,8 @@ fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport,
> if (tport->state != FDLS_TGT_STATE_PRLI) {
> FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
> "PRLI rsp recvd in wrong state. Drop frame. Restarting nexus");
> + /* Tell the compiler that tport->iport == iport. */
> + __assume_ctx_lock(&((struct fnic_iport_s *)tport->iport)->fnic->fnic_lock);
> fdls_target_restart_nexus(tport);
> return;
> }
> @@ -2872,6 +2902,7 @@ fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport,
> static void
> fdls_process_rff_id_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic *fnic = iport->fnic;
> struct fnic_fdls_fabric_s *fdls = &iport->fabric;
> @@ -2945,6 +2976,7 @@ fdls_process_rff_id_rsp(struct fnic_iport_s *iport,
> static void
> fdls_process_rft_id_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic_fdls_fabric_s *fdls = &iport->fabric;
> struct fc_std_rft_id *rft_rsp = (struct fc_std_rft_id *) fchdr;
> @@ -3020,6 +3052,7 @@ fdls_process_rft_id_rsp(struct fnic_iport_s *iport,
> static void
> fdls_process_rpn_id_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic_fdls_fabric_s *fdls = &iport->fabric;
> struct fc_std_rpn_id *rpn_rsp = (struct fc_std_rpn_id *) fchdr;
> @@ -3090,6 +3123,7 @@ fdls_process_rpn_id_rsp(struct fnic_iport_s *iport,
> static void
> fdls_process_scr_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic_fdls_fabric_s *fdls = &iport->fabric;
> struct fc_std_scr *scr_rsp = (struct fc_std_scr *) fchdr;
> @@ -3162,6 +3196,7 @@ fdls_process_scr_rsp(struct fnic_iport_s *iport,
> static void
> fdls_process_gpn_ft_tgt_list(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr, int len)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fc_gpn_ft_rsp_iu *gpn_ft_tgt;
> struct fnic_tport_s *tport, *next;
> @@ -3260,6 +3295,7 @@ fdls_process_gpn_ft_tgt_list(struct fnic_iport_s *iport,
> static void
> fdls_process_gpn_ft_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr, int len)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic_fdls_fabric_s *fdls = &iport->fabric;
> struct fc_std_gpn_ft *gpn_ft_rsp = (struct fc_std_gpn_ft *) fchdr;
> @@ -3396,6 +3432,7 @@ fdls_process_gpn_ft_rsp(struct fnic_iport_s *iport,
> static void
> fdls_process_fabric_logo_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fc_std_flogi *flogo_rsp = (struct fc_std_flogi *) fchdr;
> struct fnic_fdls_fabric_s *fdls = &iport->fabric;
> @@ -3449,6 +3486,7 @@ fdls_process_fabric_logo_rsp(struct fnic_iport_s *iport,
> static void
> fdls_process_flogi_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr, void *rx_frame)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic_fdls_fabric_s *fabric = &iport->fabric;
> struct fc_std_flogi *flogi_rsp = (struct fc_std_flogi *) fchdr;
> @@ -3586,6 +3624,7 @@ fdls_process_flogi_rsp(struct fnic_iport_s *iport,
> static void
> fdls_process_fabric_plogi_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fc_std_flogi *plogi_rsp = (struct fc_std_flogi *) fchdr;
> struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *) fchdr;
> @@ -3847,6 +3886,7 @@ static void fdls_process_fdmi_abts_rsp(struct fnic_iport_s *iport,
> static void
> fdls_process_fabric_abts_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint32_t s_id;
> struct fc_std_abts_ba_acc *ba_acc = (struct fc_std_abts_ba_acc *)fchdr;
> @@ -4204,6 +4244,7 @@ fdls_process_els_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr,
> static void
> fdls_process_tgt_abts_rsp(struct fnic_iport_s *iport,
> struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> uint32_t s_id;
> struct fnic_tport_s *tport;
> @@ -4393,6 +4434,7 @@ fdls_process_plogi_req(struct fnic_iport_s *iport,
>
> static void
> fdls_process_logo_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fc_std_logo *logo = (struct fc_std_logo *)fchdr;
> uint32_t nport_id;
> @@ -4433,6 +4475,8 @@ fdls_process_logo_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
> FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
> "tport fcid 0x%x: Canceling disc timer\n",
> tport->fcid);
> + /* Tell the compiler that tport->iport == iport. */
> + __assume_ctx_lock(&((struct fnic_iport_s *)tport->iport)->fnic->fnic_lock);
> fnic_del_tport_timer_sync(fnic, tport);
> tport->timer_pending = 0;
> }
> @@ -4470,6 +4514,7 @@ fdls_process_logo_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
>
> static void
> fdls_process_rscn(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fc_std_rscn *rscn;
> struct fc_els_rscn_page *rscn_port = NULL;
> @@ -4603,6 +4648,7 @@ fdls_process_rscn(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
> }
>
> void fnic_fdls_disc_start(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic *fnic = iport->fnic;
>
> @@ -4943,6 +4989,7 @@ fnic_fdls_validate_and_get_frame_type(struct fnic_iport_s *iport,
>
> void fnic_fdls_recv_frame(struct fnic_iport_s *iport, void *rx_frame,
> int len, int fchdr_offset)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fc_frame_header *fchdr;
> uint32_t s_id = 0;
> @@ -5061,6 +5108,7 @@ void fnic_fdls_disc_init(struct fnic_iport_s *iport)
> }
>
> void fnic_fdls_link_down(struct fnic_iport_s *iport)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic_tport_s *tport, *next;
> struct fnic *fnic = iport->fnic;
> diff --git a/drivers/scsi/fnic/fip.c b/drivers/scsi/fnic/fip.c
> index 132f00512ee1..da8a8e9ffea4 100644
> --- a/drivers/scsi/fnic/fip.c
> +++ b/drivers/scsi/fnic/fip.c
> @@ -610,6 +610,7 @@ void fnic_common_fip_cleanup(struct fnic *fnic)
> * and clean up and restart the vlan discovery.
> */
> void fnic_fcoe_process_cvl(struct fnic *fnic, struct fip_header *fiph)
> + __must_hold(&fnic->fnic_lock)
> {
> struct fnic_iport_s *iport = &fnic->iport;
> struct fip_cvl *cvl_msg = (struct fip_cvl *)fiph;
> @@ -687,6 +688,7 @@ void fnic_fcoe_process_cvl(struct fnic *fnic, struct fip_header *fiph)
> * @frame: Received ethernet frame
> */
> int fdls_fip_recv_frame(struct fnic *fnic, void *frame)
> + __must_hold(&fnic->fnic_lock)
> {
> struct ethhdr *eth = (struct ethhdr *)frame;
> struct fip_header *fiph;
> diff --git a/drivers/scsi/fnic/fnic_fcs.c b/drivers/scsi/fnic/fnic_fcs.c
> index 063eb864a5cd..99f9fe13dfe4 100644
> --- a/drivers/scsi/fnic/fnic_fcs.c
> +++ b/drivers/scsi/fnic/fnic_fcs.c
> @@ -925,6 +925,7 @@ void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
> void
> fnic_fdls_add_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport,
> unsigned long flags)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic *fnic = iport->fnic;
> struct fc_rport *rport;
> @@ -964,6 +965,7 @@ fnic_fdls_add_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport,
> void
> fnic_fdls_remove_tport(struct fnic_iport_s *iport,
> struct fnic_tport_s *tport, unsigned long flags)
> + __must_hold(&iport->fnic->fnic_lock)
> {
> struct fnic *fnic = iport->fnic;
> struct rport_dd_data_s *rdd_data;
> @@ -1013,6 +1015,8 @@ void fnic_delete_fcp_tports(struct fnic *fnic)
> unsigned long flags;
>
> spin_lock_irqsave(&fnic->fnic_lock, flags);
> + /* Tell the compiler that fnic->iport.fnic == fnic. */
> + __assume_ctx_lock(&fnic->iport.fnic->fnic_lock);
> list_for_each_entry_safe(tport, next, &fnic->iport.tport_list, links) {
> FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
> "removing fcp rport fcid: 0x%x", tport->fcid);
> @@ -1037,6 +1041,8 @@ void fnic_tport_event_handler(struct work_struct *work)
> struct fnic_tport_s *tport;
>
> spin_lock_irqsave(&fnic->fnic_lock, flags);
> + /* Tell the compiler that fnic->iport.fnic == fnic. */
> + __assume_ctx_lock(&fnic->iport.fnic->fnic_lock);
> list_for_each_entry_safe(cur_evt, next, &fnic->tport_event_list, links) {
> tport = cur_evt->arg1;
> switch (cur_evt->event) {
> diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
> index 6ee3c559e129..a757b20756ad 100644
> --- a/drivers/scsi/fnic/fnic_scsi.c
> +++ b/drivers/scsi/fnic/fnic_scsi.c
> @@ -2617,6 +2617,8 @@ int fnic_device_reset(struct scsi_cmnd *sc)
> * allocated by mid layer.
> */
> mutex_lock(&fnic->sgreset_mutex);
> + /* Fake __release() to keep the lock context analyzer happy. */
> + __release(&fnic->sgreset_mutex);
> mqtag = fnic->fnic_max_tag_id;
> new_sc = 1;
> } else {
> @@ -2803,6 +2805,8 @@ int fnic_device_reset(struct scsi_cmnd *sc)
>
> if (new_sc) {
> fnic->sgreset_sc = NULL;
> + /* Fake __acquire() to keep the lock context analyzer happy. */
> + __acquire(&fnic->sgreset_mutex);
> mutex_unlock(&fnic->sgreset_mutex);
> }
>
Acked-by: Karan Tilak Kumar <kartilak@cisco.com>
Regards,
Karan
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v2 27/56] scsi: hisi_sas: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (25 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 26/56] scsi: fnic: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 28/56] scsi: hpsa: Prepare for enabling " Bart Van Assche
` (28 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Yihang Li,
James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/hisi_sas/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/hisi_sas/Makefile b/drivers/scsi/hisi_sas/Makefile
index 742e732cd51d..8576c78d4afe 100644
--- a/drivers/scsi/hisi_sas/Makefile
+++ b/drivers/scsi/hisi_sas/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_HISI_SAS) += hisi_sas_main.o
obj-$(CONFIG_SCSI_HISI_SAS) += hisi_sas_v1_hw.o hisi_sas_v2_hw.o
obj-$(CONFIG_SCSI_HISI_SAS_PCI) += hisi_sas_v3_hw.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 28/56] scsi: hpsa: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (26 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 27/56] scsi: hisi_sas: " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:19 ` [PATCH v2 29/56] scsi: ibmvscsi: Enable " Bart Van Assche
` (27 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Don Brace,
James E.J. Bottomley, Nathan Chancellor
mutex_lock_interruptible() returns a negative value upon failure or zero
upon success. Since the Clang thread-safety analyzer only supports == 0
and != 0 tests for functions that perform conditional locking, change
the == -EINTR test into != 0. This change does not modify the behavior
of hpsa_do_reset().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/hpsa.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index a1b116cd4723..1b3595c6e036 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -3163,7 +3163,7 @@ static int hpsa_do_reset(struct ctlr_info *h, struct hpsa_scsi_dev_t *dev,
int rc = 0;
/* We can really only handle one reset at a time */
- if (mutex_lock_interruptible(&h->reset_mutex) == -EINTR) {
+ if (mutex_lock_interruptible(&h->reset_mutex)) {
dev_warn(&h->pdev->dev, "concurrent reset wait interrupted.\n");
return -EINTR;
}
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 29/56] scsi: ibmvscsi: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (27 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 28/56] scsi: hpsa: Prepare for enabling " Bart Van Assche
@ 2026-04-30 18:19 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 30/56] scsi: ibmvscsi_tgt: " Bart Van Assche
` (26 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Madhavan Srinivasan,
Michael Ellerman, James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/ibmvscsi/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/ibmvscsi/Makefile b/drivers/scsi/ibmvscsi/Makefile
index 5eb1cb1a0028..a497c6c0985a 100644
--- a/drivers/scsi/ibmvscsi/Makefile
+++ b/drivers/scsi/ibmvscsi/Makefile
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_IBMVSCSI) += ibmvscsi.o
obj-$(CONFIG_SCSI_IBMVFC) += ibmvfc.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 30/56] scsi: ibmvscsi_tgt: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (28 preceding siblings ...)
2026-04-30 18:19 ` [PATCH v2 29/56] scsi: ibmvscsi: Enable " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 31/56] scsi: ipr: Prepare for enabling " Bart Van Assche
` (25 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Tyrel Datwyler,
James E.J. Bottomley
Document locking requirements with __must_hold().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/ibmvscsi_tgt/Makefile | 3 +++
drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 7 +++++++
2 files changed, 10 insertions(+)
diff --git a/drivers/scsi/ibmvscsi_tgt/Makefile b/drivers/scsi/ibmvscsi_tgt/Makefile
index cc7a8256dcf8..7ae12ee9a347 100644
--- a/drivers/scsi/ibmvscsi_tgt/Makefile
+++ b/drivers/scsi/ibmvscsi_tgt/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_IBMVSCSIS) += ibmvscsis.o
ibmvscsis-y := libsrp.o ibmvscsi_tgt.o
diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
index 61f682800765..8e532a195bf9 100644
--- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
+++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
@@ -251,6 +251,7 @@ static void ibmvscsis_delete_client_info(struct scsi_info *vscsi,
* Process level, interrupt lock is held
*/
static long ibmvscsis_free_command_q(struct scsi_info *vscsi)
+ __must_hold(&vscsi->intr_lock)
{
int bytes;
u32 flags_under_lock;
@@ -874,6 +875,7 @@ static long ibmvscsis_establish_new_q(struct scsi_info *vscsi)
* Process environment, called with interrupt lock held
*/
static void ibmvscsis_reset_queue(struct scsi_info *vscsi)
+ __must_hold(&vscsi->intr_lock)
{
int bytes;
long rc = ADAPT_SUCCESS;
@@ -974,6 +976,7 @@ static void ibmvscsis_free_cmd_resources(struct scsi_info *vscsi,
* Process or interrupt environment called with interrupt lock held
*/
static long ibmvscsis_ready_for_suspend(struct scsi_info *vscsi, bool idle)
+ __must_hold(&vscsi->intr_lock)
{
long rc = 0;
struct viosrp_crq *crq;
@@ -1030,6 +1033,7 @@ static long ibmvscsis_ready_for_suspend(struct scsi_info *vscsi, bool idle)
*/
static long ibmvscsis_trans_event(struct scsi_info *vscsi,
struct viosrp_crq *crq)
+ __must_hold(&vscsi->intr_lock)
{
long rc = ADAPT_SUCCESS;
@@ -1166,6 +1170,7 @@ static long ibmvscsis_trans_event(struct scsi_info *vscsi,
* intr_lock must be held
*/
static void ibmvscsis_poll_cmd_q(struct scsi_info *vscsi)
+ __must_hold(&vscsi->intr_lock)
{
struct viosrp_crq *crq;
long rc;
@@ -1310,6 +1315,7 @@ static struct ibmvscsis_cmd *ibmvscsis_get_free_cmd(struct scsi_info *vscsi)
* Process environment called with interrupt lock held
*/
static void ibmvscsis_adapter_idle(struct scsi_info *vscsi)
+ __must_hold(&vscsi->intr_lock)
{
int free_qs = false;
long rc = 0;
@@ -2520,6 +2526,7 @@ static long ibmvscsis_ping_response(struct scsi_info *vscsi)
*/
static long ibmvscsis_parse_command(struct scsi_info *vscsi,
struct viosrp_crq *crq)
+ __must_hold(&vscsi->intr_lock)
{
long rc = ADAPT_SUCCESS;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 31/56] scsi: ipr: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (29 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 30/56] scsi: ibmvscsi_tgt: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 32/56] scsi: ips: " Bart Van Assche
` (24 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Brian King,
James E.J. Bottomley
Document locking requirements with __must_hold().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/ipr.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index d207e5e81afe..51092834876c 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -1016,6 +1016,7 @@ static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
void (*timeout_func) (struct timer_list *),
u32 timeout)
+ __must_hold(ipr_cmd->ioa_cfg->host->host_lock)
{
struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
@@ -5012,6 +5013,7 @@ static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
**/
static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
struct ipr_resource_entry *res)
+ __must_hold(ioa_cfg->host->host_lock)
{
struct ipr_cmnd *ipr_cmd;
struct ipr_ioarcb *ioarcb;
@@ -5020,6 +5022,8 @@ static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
ENTER;
ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
+ /* Tell the compiler that ipr_cmd->ioa_cfg == ioa_cfg. */
+ __assume_ctx_lock(ipr_cmd->ioa_cfg->host->host_lock);
ioarcb = &ipr_cmd->ioarcb;
cmd_pkt = &ioarcb->cmd_pkt;
@@ -5050,6 +5054,7 @@ static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
* SUCCESS / FAILED
**/
static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
+ __must_hold(scsi_cmd->device->host->host_lock)
{
struct ipr_ioa_cfg *ioa_cfg;
struct ipr_resource_entry *res;
@@ -5069,6 +5074,9 @@ static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
return FAILED;
+ /* Tell the compiler that ioa_cfg->host == scsi_cmd->device->host. */
+ __assume_ctx_lock(ioa_cfg->host->host_lock);
+
res->resetting_device = 1;
scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
@@ -5189,6 +5197,7 @@ static void ipr_abort_timeout(struct timer_list *t)
* SUCCESS / FAILED
**/
static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
+ __must_hold(scsi_cmd->device->host->host_lock)
{
struct ipr_cmnd *ipr_cmd;
struct ipr_ioa_cfg *ioa_cfg;
@@ -5239,6 +5248,8 @@ static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
return SUCCESS;
ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
+ /* Tell the compiler that ipr_cmd->ioa_cfg == ioa_cfg. */
+ __assume_ctx_lock(ipr_cmd->ioa_cfg->host->host_lock);
ipr_cmd->ioarcb.res_handle = res->res_handle;
cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 32/56] scsi: ips: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (30 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 31/56] scsi: ipr: Prepare for enabling " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 33/56] scsi: isci: Enable " Bart Van Assche
` (23 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche,
Adaptec OEM Raid Solutions, James E.J. Bottomley
Annotate ips_next() with __no_context_analysis because it performs
conditional locking.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/ips.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index 41ed73966a48..5ef70f058ecd 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -2506,6 +2506,7 @@ ips_hainit(ips_ha_t * ha)
/****************************************************************************/
static void
ips_next(ips_ha_t * ha, int intr)
+ __context_unsafe(conditional locking)
{
ips_scb_t *scb;
struct scsi_cmnd *SC;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 33/56] scsi: isci: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (31 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 32/56] scsi: ips: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 34/56] scsi: libfc: " Bart Van Assche
` (22 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/isci/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/isci/Makefile b/drivers/scsi/isci/Makefile
index da6f04cae272..00fd5c1a8d39 100644
--- a/drivers/scsi/isci/Makefile
+++ b/drivers/scsi/isci/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_ISCI) += isci.o
isci-objs := init.o phy.o request.o \
remote_device.o port.o \
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 34/56] scsi: libfc: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (32 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 33/56] scsi: isci: Enable " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 35/56] scsi: libiscsi: Prepare for enabling " Bart Van Assche
` (21 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Hannes Reinecke,
James E.J. Bottomley
Document locking requirements with __must_hold().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/libfc/Makefile | 2 ++
drivers/scsi/libfc/fc_disc.c | 6 +++++-
drivers/scsi/libfc/fc_exch.c | 6 ++++++
drivers/scsi/libfc/fc_fcp.c | 4 ++++
4 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/libfc/Makefile b/drivers/scsi/libfc/Makefile
index 65396f86c307..b265cf2a84a2 100644
--- a/drivers/scsi/libfc/Makefile
+++ b/drivers/scsi/libfc/Makefile
@@ -1,6 +1,8 @@
# SPDX-License-Identifier: GPL-2.0
# $Id: Makefile
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_LIBFC) += libfc.o
libfc-objs := \
diff --git a/drivers/scsi/libfc/fc_disc.c b/drivers/scsi/libfc/fc_disc.c
index 7792724d5b97..e2fd076ee15b 100644
--- a/drivers/scsi/libfc/fc_disc.c
+++ b/drivers/scsi/libfc/fc_disc.c
@@ -37,7 +37,7 @@
#define FC_DISC_RETRY_LIMIT 3 /* max retries */
#define FC_DISC_RETRY_DELAY 500UL /* (msecs) delay */
-static void fc_disc_gpn_ft_req(struct fc_disc *);
+static void fc_disc_gpn_ft_req(struct fc_disc *disc) __must_hold(disc->disc_mutex);
static void fc_disc_gpn_ft_resp(struct fc_seq *, struct fc_frame *, void *);
static void fc_disc_done(struct fc_disc *, enum fc_disc_event);
static void fc_disc_timeout(struct work_struct *);
@@ -200,6 +200,7 @@ static void fc_disc_recv_req(struct fc_lport *lport, struct fc_frame *fp)
* @disc: The discovery object to be restarted
*/
static void fc_disc_restart(struct fc_disc *disc)
+ __must_hold(disc->disc_mutex)
{
lockdep_assert_held(&disc->disc_mutex);
@@ -250,6 +251,7 @@ static void fc_disc_start(void (*disc_callback)(struct fc_lport *,
* @event: The discovery completion status
*/
static void fc_disc_done(struct fc_disc *disc, enum fc_disc_event event)
+ __must_hold(disc->disc_mutex)
{
struct fc_lport *lport = fc_disc_lport(disc);
struct fc_rport_priv *rdata;
@@ -294,6 +296,7 @@ static void fc_disc_done(struct fc_disc *disc, enum fc_disc_event event)
* @fp: The error code encoded as a frame pointer
*/
static void fc_disc_error(struct fc_disc *disc, struct fc_frame *fp)
+ __must_hold(disc->disc_mutex)
{
struct fc_lport *lport = fc_disc_lport(disc);
unsigned long delay = 0;
@@ -374,6 +377,7 @@ static void fc_disc_gpn_ft_req(struct fc_disc *disc)
* Goes through the list of IDs and names resulting from a request.
*/
static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len)
+ __must_hold(disc->disc_mutex)
{
struct fc_lport *lport;
struct fc_gpn_ft_resp *np;
diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index 9183a0e9568a..9057a95d8612 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -811,6 +811,7 @@ static void fc_exch_timeout(struct work_struct *work)
*/
static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
struct fc_exch_mgr *mp)
+ __context_unsafe(conditionally acquires &_res->ex_lock)
{
struct fc_exch *ep;
unsigned int cpu;
@@ -904,6 +905,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
*/
static struct fc_exch *fc_exch_alloc(struct fc_lport *lport,
struct fc_frame *fp)
+ __context_unsafe(conditionally acquires &_res->ex_lock)
{
struct fc_exch_mgr_anchor *ema;
struct fc_exch *ep;
@@ -996,6 +998,8 @@ static struct fc_exch *fc_exch_resp(struct fc_lport *lport,
ep = fc_exch_alloc(lport, fp);
if (ep) {
+ /* Acquired by fc_exch_alloc(). */
+ __acquire(&ep->ex_lock);
ep->class = fc_frame_class(fp);
/*
@@ -2191,6 +2195,8 @@ struct fc_seq *fc_exch_seq_send(struct fc_lport *lport,
fc_frame_free(fp);
return NULL;
}
+ /* Acquired by fc_exch_alloc(). */
+ __acquire(&ep->ex_lock);
ep->esb_stat |= ESB_ST_SEQ_INIT;
fh = fc_frame_header_get(fp);
fc_exch_set_addr(ep, ntoh24(fh->fh_s_id), ntoh24(fh->fh_d_id));
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index a5139e43ca4c..9ba31a8a5250 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -207,6 +207,7 @@ static void fc_fcp_pkt_destroy(struct fc_seq *seq, void *fsp)
* needed.
*/
static inline int fc_fcp_lock_pkt(struct fc_fcp_pkt *fsp)
+ __cond_acquires(0, &fsp->scsi_pkt_lock)
{
spin_lock_bh(&fsp->scsi_pkt_lock);
if (fsp->state & FC_SRB_COMPL) {
@@ -224,6 +225,7 @@ static inline int fc_fcp_lock_pkt(struct fc_fcp_pkt *fsp)
* @fsp: The FCP packet to be unlocked and decremented
*/
static inline void fc_fcp_unlock_pkt(struct fc_fcp_pkt *fsp)
+ __releases(&fsp->scsi_pkt_lock)
{
spin_unlock_bh(&fsp->scsi_pkt_lock);
fc_fcp_pkt_release(fsp);
@@ -1242,6 +1244,7 @@ static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
* Called to send an abort and then wait for abort completion
*/
static int fc_fcp_pkt_abort(struct fc_fcp_pkt *fsp)
+ __must_hold(&fsp->scsi_pkt_lock)
{
int rc = FAILED;
unsigned long ticks_left;
@@ -1950,6 +1953,7 @@ EXPORT_SYMBOL(fc_queuecommand);
* The fcp packet lock must be held when calling.
*/
static void fc_io_compl(struct fc_fcp_pkt *fsp)
+ __must_hold(&fsp->scsi_pkt_lock)
{
struct fc_fcp_internal *si;
struct scsi_cmnd *sc_cmd;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 35/56] scsi: libiscsi: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (33 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 34/56] scsi: libfc: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 36/56] scsi: libsas: " Bart Van Assche
` (20 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Lee Duncan, Chris Leech,
Mike Christie, James E.J. Bottomley
Document locking requirements with __must_hold().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/libiscsi.c | 19 ++++++++++++++++++-
include/scsi/libiscsi.h | 5 +++--
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 25857d6ed6e8..b89c048b4034 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -1088,6 +1088,7 @@ static int iscsi_nop_out_rsp(struct iscsi_task *task,
static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
char *data, int datalen)
+ __must_hold(&conn->session->back_lock)
{
struct iscsi_reject *reject = (struct iscsi_reject *)hdr;
struct iscsi_hdr rejected_pdu;
@@ -1500,6 +1501,7 @@ static int iscsi_check_cmdsn_window_closed(struct iscsi_conn *conn)
static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task,
bool was_requeue)
+ __must_hold(&conn->session->frwd_lock)
{
int rc;
@@ -1915,7 +1917,8 @@ static void iscsi_tmf_timedout(struct timer_list *t)
static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
struct iscsi_tm *hdr, int age,
int timeout)
- __must_hold(&session->frwd_lock)
+ __must_hold(&conn->session->frwd_lock)
+ __must_hold(&conn->session->eh_mutex)
{
struct iscsi_session *session = conn->session;
@@ -1962,6 +1965,7 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
* Fail commands. session frwd lock held and xmit thread flushed.
*/
static void fail_scsi_tasks(struct iscsi_conn *conn, u64 lun, int error)
+ __must_hold(&conn->session->frwd_lock)
{
struct iscsi_session *session = conn->session;
struct iscsi_task *task;
@@ -2408,6 +2412,9 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
ISCSI_DBG_EH(session, "aborting [sc %p itt 0x%x]\n", sc, task->itt);
conn = session->leadconn;
+ /* Tell the compiler that conn->session == session. */
+ __assume_ctx_lock(&conn->session->eh_mutex);
+ __assume_ctx_lock(&conn->session->frwd_lock);
iscsi_get_conn(conn->cls_conn);
conn->eh_abort_cnt++;
age = session->age;
@@ -2531,6 +2538,9 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc)
if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN)
goto unlock;
conn = session->leadconn;
+ /* Tell the compiler that conn->session == session. */
+ __assume_ctx_lock(&conn->session->frwd_lock);
+ __assume_ctx_lock(&conn->session->eh_mutex);
/* only have one tmf outstanding at a time */
if (session->tmf_state != TMF_INITIAL)
@@ -2564,6 +2574,8 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc)
iscsi_suspend_tx(conn);
spin_lock_bh(&session->frwd_lock);
+ /* Tell the compiler that conn->session == session. */
+ __assume_ctx_lock(&conn->session->frwd_lock);
memset(hdr, 0, sizeof(*hdr));
fail_scsi_tasks(conn, sc->device->lun, DID_ERROR);
session->tmf_state = TMF_INITIAL;
@@ -2693,6 +2705,9 @@ static int iscsi_eh_target_reset(struct scsi_cmnd *sc)
if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN)
goto unlock;
conn = session->leadconn;
+ /* Tell the compiler that conn->session == session. */
+ __assume_ctx_lock(&conn->session->eh_mutex);
+ __assume_ctx_lock(&conn->session->frwd_lock);
/* only have one tmf outstanding at a time */
if (session->tmf_state != TMF_INITIAL)
@@ -2726,6 +2741,8 @@ static int iscsi_eh_target_reset(struct scsi_cmnd *sc)
iscsi_suspend_tx(conn);
spin_lock_bh(&session->frwd_lock);
+ /* Tell the compiler that conn->session == session. */
+ __assume_ctx_lock(&conn->session->frwd_lock);
memset(hdr, 0, sizeof(*hdr));
fail_scsi_tasks(conn, -1, DID_ERROR);
session->tmf_state = TMF_INITIAL;
diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h
index 3d765c77bcd9..d39b5b268e6f 100644
--- a/include/scsi/libiscsi.h
+++ b/include/scsi/libiscsi.h
@@ -474,8 +474,9 @@ extern int iscsi_conn_send_pdu(struct iscsi_cls_conn *, struct iscsi_hdr *,
char *, uint32_t);
extern int iscsi_complete_pdu(struct iscsi_conn *, struct iscsi_hdr *,
char *, int);
-extern int __iscsi_complete_pdu(struct iscsi_conn *, struct iscsi_hdr *,
- char *, int);
+extern int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *,
+ char *, int)
+ __must_hold(&conn->session->back_lock);
extern int iscsi_verify_itt(struct iscsi_conn *, itt_t);
extern struct iscsi_task *iscsi_itt_to_ctask(struct iscsi_conn *, itt_t);
extern struct iscsi_task *iscsi_itt_to_task(struct iscsi_conn *, itt_t);
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 36/56] scsi: libsas: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (34 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 35/56] scsi: libiscsi: Prepare for enabling " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 37/56] scsi: libsas: Enable " Bart Van Assche
` (19 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley,
Nathan Chancellor, Damien Le Moal, Jason Yan, John Garry,
Niklas Cassel, Kees Cook
Since Clang requires that lock context annotations only refer to
variables that are visible, modify a __must_hold() annotation.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/libsas/sas_ata.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 61368e55bf86..2340790c9f6b 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -153,7 +153,7 @@ static void sas_ata_task_done(struct sas_task *task)
}
static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
- __must_hold(ap->lock)
+ __must_hold(qc->ap->lock)
{
struct sas_task *task;
struct scatterlist *sg;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 37/56] scsi: libsas: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (35 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 36/56] scsi: libsas: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 38/56] scsi: lpfc: Prepare for enabling " Bart Van Assche
` (18 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/libsas/Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/libsas/Makefile b/drivers/scsi/libsas/Makefile
index 9dc32736cf21..6f6f1336b438 100644
--- a/drivers/scsi/libsas/Makefile
+++ b/drivers/scsi/libsas/Makefile
@@ -6,6 +6,8 @@
# Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
#
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_SAS_LIBSAS) += libsas.o
libsas-y += sas_init.o \
sas_phy.o \
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 38/56] scsi: lpfc: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (36 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 37/56] scsi: libsas: Enable " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 39/56] scsi: megaraid_sas: " Bart Van Assche
` (17 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Justin Tee, Paul Ely,
James E.J. Bottomley
Annotate the functions that perform conditional locking with
__no_context_analysis.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/lpfc/lpfc_els.c | 2 ++
drivers/scsi/lpfc/lpfc_nportdisc.c | 1 +
drivers/scsi/lpfc/lpfc_scsi.c | 1 +
drivers/scsi/lpfc/lpfc_sli.c | 2 ++
4 files changed, 6 insertions(+)
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 4e3fe89283e4..938f5af2d01d 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -9597,6 +9597,7 @@ lpfc_els_timeout(struct timer_list *t)
**/
void
lpfc_els_timeout_handler(struct lpfc_vport *vport)
+ __context_unsafe(conditional locking)
{
struct lpfc_hba *phba = vport->phba;
struct lpfc_sli_ring *pring;
@@ -9719,6 +9720,7 @@ lpfc_els_timeout_handler(struct lpfc_vport *vport)
**/
void
lpfc_els_flush_cmd(struct lpfc_vport *vport)
+ __context_unsafe(conditional locking)
{
LIST_HEAD(abort_list);
LIST_HEAD(cancel_list);
diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c
index 9c449055a55e..79e5e876c879 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -220,6 +220,7 @@ lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
*/
void
lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
+ __context_unsafe(conditional locking)
{
LIST_HEAD(abort_list);
LIST_HEAD(drv_cmpl_list);
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 1dce33b79beb..028f7cf065f8 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -5520,6 +5520,7 @@ void lpfc_vmid_vport_cleanup(struct lpfc_vport *vport)
**/
static int
lpfc_abort_handler(struct scsi_cmnd *cmnd)
+ __context_unsafe(conditional locking)
{
struct Scsi_Host *shost = cmnd->device->host;
struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index d38fb374b379..14a4d4953657 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -3721,6 +3721,7 @@ lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
static int
lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
struct lpfc_iocbq *saveq)
+ __context_unsafe(conditional locking)
{
struct lpfc_iocbq *cmdiocbp;
unsigned long iflag;
@@ -12871,6 +12872,7 @@ lpfc_sli_abort_iocb(struct lpfc_vport *vport, u16 tgt_id, u64 lun_id,
int
lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
+ __context_unsafe(conditional locking)
{
struct lpfc_hba *phba = vport->phba;
struct lpfc_io_buf *lpfc_cmd;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 39/56] scsi: megaraid_sas: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (37 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 38/56] scsi: lpfc: Prepare for enabling " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 40/56] scsi: megaraid: Enable " Bart Van Assche
` (16 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Kashyap Desai,
Sumit Saxena, Shivasharan S, Chandrakanth patil,
James E.J. Bottomley
Document locking requirements with __must_hold().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/megaraid/megaraid_sas.h | 9 ++++++---
drivers/scsi/megaraid/megaraid_sas_base.c | 15 ++++++++++++---
drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 ++
3 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 8ee2bfe47571..67713173793a 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -2696,15 +2696,18 @@ __le16 get_updated_dev_handle(struct megasas_instance *instance,
struct MR_DRV_RAID_MAP_ALL *drv_map);
void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL *map,
struct LD_LOAD_BALANCE_INFO *lbInfo);
-int megasas_get_ctrl_info(struct megasas_instance *instance);
+int megasas_get_ctrl_info(struct megasas_instance *instance)
+ __must_hold(&instance->reset_mutex);
/* PD sequence */
int
megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend);
void megasas_set_dynamic_target_properties(struct scsi_device *sdev,
struct queue_limits *lim, bool is_target_prop);
int megasas_get_target_prop(struct megasas_instance *instance,
- struct scsi_device *sdev);
-void megasas_get_snapdump_properties(struct megasas_instance *instance);
+ struct scsi_device *sdev)
+ __must_hold(&instance->reset_mutex);
+void megasas_get_snapdump_properties(struct megasas_instance *instance)
+ __must_hold(&instance->reset_mutex);
int megasas_set_crash_dump_params(struct megasas_instance *instance,
u8 crash_buf_state);
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index ecd365d78ae3..ccefe5841a17 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -132,14 +132,16 @@ MODULE_AUTHOR("megaraidlinux.pdl@broadcom.com");
MODULE_DESCRIPTION("Broadcom MegaRAID SAS Driver");
int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
-static int megasas_get_pd_list(struct megasas_instance *instance);
+static int megasas_get_pd_list(struct megasas_instance *instance)
+ __must_hold(&instance->reset_mutex);
static int megasas_ld_list_query(struct megasas_instance *instance,
u8 query_type);
static int megasas_issue_init_mfi(struct megasas_instance *instance);
static int megasas_register_aen(struct megasas_instance *instance,
u32 seq_num, u32 class_locale_word);
static void megasas_get_pd_info(struct megasas_instance *instance,
- struct scsi_device *sdev);
+ struct scsi_device *sdev)
+ __must_hold(&instance->reset_mutex);
static void
megasas_set_ld_removed_by_fw(struct megasas_instance *instance);
@@ -229,7 +231,8 @@ megasas_adp_reset_gen2(struct megasas_instance *instance,
struct megasas_register_set __iomem *reg_set);
static irqreturn_t megasas_isr(int irq, void *devp);
static u32
-megasas_init_adapter_mfi(struct megasas_instance *instance);
+megasas_init_adapter_mfi(struct megasas_instance *instance)
+ __must_hold(&instance->reset_mutex);
u32
megasas_build_and_issue_cmd(struct megasas_instance *instance,
struct scsi_cmnd *scmd);
@@ -4754,6 +4757,7 @@ megasas_get_pd_list(struct megasas_instance *instance)
*/
static int
megasas_get_ld_list(struct megasas_instance *instance)
+ __must_hold(&instance->reset_mutex)
{
int ret = 0, ld_index = 0, ids = 0;
struct megasas_cmd *cmd;
@@ -4871,6 +4875,7 @@ megasas_get_ld_list(struct megasas_instance *instance)
*/
static int
megasas_ld_list_query(struct megasas_instance *instance, u8 query_type)
+ __must_hold(&instance->reset_mutex)
{
int ret = 0, ld_index = 0, ids = 0;
struct megasas_cmd *cmd;
@@ -4993,6 +4998,7 @@ megasas_ld_list_query(struct megasas_instance *instance, u8 query_type)
static int
megasas_host_device_list_query(struct megasas_instance *instance,
bool is_probe)
+ __must_hold(&instance->reset_mutex)
{
int ret, i, target_id;
struct megasas_cmd *cmd;
@@ -5874,6 +5880,7 @@ static void megasas_setup_reply_map(struct megasas_instance *instance)
*/
static
int megasas_get_device_list(struct megasas_instance *instance)
+ __must_hold(&instance->reset_mutex)
{
if (instance->enable_fw_dev_list) {
if (megasas_host_device_list_query(instance, true))
@@ -7789,6 +7796,7 @@ megasas_suspend(struct device *dev)
*/
static int __maybe_unused
megasas_resume(struct device *dev)
+ __must_hold(&((struct megasas_instance *)dev_get_drvdata(dev))->reset_mutex)
{
int rval;
struct Scsi_Host *host;
@@ -8765,6 +8773,7 @@ static inline void megasas_remove_scsi_device(struct scsi_device *sdev)
static
int megasas_update_device_list(struct megasas_instance *instance,
int event_type)
+ __must_hold(&instance->reset_mutex)
{
int dcmd_ret;
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 2699e4e09b5b..664bec111474 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1792,6 +1792,7 @@ static inline void megasas_free_ioc_init_cmd(struct megasas_instance *instance)
*/
static u32
megasas_init_adapter_fusion(struct megasas_instance *instance)
+ __must_hold(&instance->reset_mutex)
{
struct fusion_context *fusion;
u32 scratch_pad_1;
@@ -4530,6 +4531,7 @@ static int
megasas_issue_tm(struct megasas_instance *instance, u16 device_handle,
uint channel, uint id, u16 smid_task, u8 type,
struct MR_PRIV_DEVICE *mr_device_priv_data)
+ __must_hold(&instance->reset_mutex)
{
struct MR_TASK_MANAGE_REQUEST *mr_request;
struct MPI2_SCSI_TASK_MANAGE_REQUEST *mpi_request;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 40/56] scsi: megaraid: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (38 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 39/56] scsi: megaraid_sas: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 41/56] scsi: mpt3sas: " Bart Van Assche
` (15 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Kashyap Desai,
Sumit Saxena, Shivasharan S, Chandrakanth patil,
James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/megaraid/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/megaraid/Makefile b/drivers/scsi/megaraid/Makefile
index 12177e4cae65..9a6976a4dc22 100644
--- a/drivers/scsi/megaraid/Makefile
+++ b/drivers/scsi/megaraid/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_MEGARAID_MM) += megaraid_mm.o
obj-$(CONFIG_MEGARAID_MAILBOX) += megaraid_mbox.o
obj-$(CONFIG_MEGARAID_SAS) += megaraid_sas.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 41/56] scsi: mpt3sas: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (39 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 40/56] scsi: megaraid: Enable " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 42/56] scsi: mvsas: " Bart Van Assche
` (14 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Sathya Prakash,
Sreekanth Reddy, Suganath Prabu Subramani, Ranjan Kumar,
James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/mpt3sas/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/mpt3sas/Makefile b/drivers/scsi/mpt3sas/Makefile
index e76d994dbed3..5653baeae26c 100644
--- a/drivers/scsi/mpt3sas/Makefile
+++ b/drivers/scsi/mpt3sas/Makefile
@@ -1,5 +1,8 @@
# SPDX-License-Identifier: GPL-2.0
# mpt3sas makefile
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_MPT3SAS) += mpt3sas.o
mpt3sas-y += mpt3sas_base.o \
mpt3sas_config.o \
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 42/56] scsi: mvsas: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (40 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 41/56] scsi: mpt3sas: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 43/56] scsi: pcmcia: " Bart Van Assche
` (13 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley,
Damien Le Moal, Thomas Gleixner, Ingo Molnar, Niklas Cassel,
Thomas Fourier, Kees Cook
Document locking requirements with __must_hold(). Annotate functions
that perform conditional locking with __no_context_analysis.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/mvsas/Makefile | 2 ++
drivers/scsi/mvsas/mv_sas.c | 7 +++++++
2 files changed, 9 insertions(+)
diff --git a/drivers/scsi/mvsas/Makefile b/drivers/scsi/mvsas/Makefile
index 75849258e898..7f45cca38127 100644
--- a/drivers/scsi/mvsas/Makefile
+++ b/drivers/scsi/mvsas/Makefile
@@ -7,6 +7,8 @@
# Copyright 2009-2011 Marvell. <yuxiangl@marvell.com>
#
+CONTEXT_ANALYSIS := y
+
ccflags-$(CONFIG_SCSI_MVSAS_DEBUG) := -DMV_DEBUG
obj-$(CONFIG_SCSI_MVSAS) += mvsas.o
diff --git a/drivers/scsi/mvsas/mv_sas.c b/drivers/scsi/mvsas/mv_sas.c
index 359226e80eae..f63e0dc1abd2 100644
--- a/drivers/scsi/mvsas/mv_sas.c
+++ b/drivers/scsi/mvsas/mv_sas.c
@@ -1055,6 +1055,7 @@ void mvs_update_phyinfo(struct mvs_info *mvi, int i, int get_st)
}
static void mvs_port_notify_formed(struct asd_sas_phy *sas_phy, int lock)
+ __context_unsafe(conditional locking)
{
struct sas_ha_struct *sas_ha = sas_phy->ha;
struct mvs_info *mvi = NULL; int i = 0, hi;
@@ -1153,6 +1154,7 @@ static void mvs_free_dev(struct mvs_device *mvi_dev)
}
static int mvs_dev_found_notify(struct domain_device *dev, int lock)
+ __context_unsafe(conditional locking)
{
unsigned long flags = 0;
int res = 0;
@@ -1517,6 +1519,7 @@ static int mvs_slot_err(struct mvs_info *mvi, struct sas_task *task,
}
int mvs_slot_complete(struct mvs_info *mvi, u32 rx_desc, u32 flags)
+ __must_hold(&mvi->lock)
{
u32 slot_idx = rx_desc & RXQ_SLOT_MASK;
struct mvs_slot_info *slot = &mvi->slot_info[slot_idx];
@@ -1644,6 +1647,7 @@ int mvs_slot_complete(struct mvs_info *mvi, u32 rx_desc, u32 flags)
void mvs_do_release_task(struct mvs_info *mvi,
int phy_no, struct domain_device *dev)
+ __must_hold(&mvi->lock)
{
u32 slot_idx;
struct mvs_phy *phy;
@@ -1677,6 +1681,7 @@ void mvs_do_release_task(struct mvs_info *mvi,
void mvs_release_task(struct mvs_info *mvi,
struct domain_device *dev)
+ __must_hold(&mvi->lock)
{
int i, phyno[WIDE_PORT_MAX_PHY], num;
num = mvs_find_dev_phyno(dev, phyno);
@@ -1769,6 +1774,7 @@ static void mvs_sig_time_out(struct timer_list *t)
}
void mvs_int_port(struct mvs_info *mvi, int phy_no, u32 events)
+ __must_hold(&mvi->lock)
{
u32 tmp;
struct mvs_phy *phy = &mvi->phy[phy_no];
@@ -1862,6 +1868,7 @@ void mvs_int_port(struct mvs_info *mvi, int phy_no, u32 events)
}
int mvs_int_rx(struct mvs_info *mvi, bool self_clear)
+ __must_hold(&mvi->lock)
{
u32 rx_prod_idx, rx_desc;
bool attn = false;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 43/56] scsi: pcmcia: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (41 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 42/56] scsi: mvsas: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 44/56] scsi: pm8001: " Bart Van Assche
` (12 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/pcmcia/Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/pcmcia/Makefile b/drivers/scsi/pcmcia/Makefile
index 02f5b44a2685..06ea2bfcd42a 100644
--- a/drivers/scsi/pcmcia/Makefile
+++ b/drivers/scsi/pcmcia/Makefile
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+CONTEXT_ANALYSIS := y
+
ccflags-y := -I $(srctree)/drivers/scsi
# 16-bit client drivers
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 44/56] scsi: pm8001: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (42 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 43/56] scsi: pcmcia: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 45/56] scsi: qedf: " Bart Van Assche
` (11 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Jack Wang,
James E.J. Bottomley
Document locking requirements with __must_hold().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/pm8001/Makefile | 1 +
drivers/scsi/pm8001/pm80xx_hwi.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/drivers/scsi/pm8001/Makefile b/drivers/scsi/pm8001/Makefile
index bbb51b7312f1..b236359810fe 100644
--- a/drivers/scsi/pm8001/Makefile
+++ b/drivers/scsi/pm8001/Makefile
@@ -4,6 +4,7 @@
#
# Copyright (C) 2008-2009 USI Co., Ltd.
+CONTEXT_ANALYSIS := y
obj-$(CONFIG_SCSI_PM8001) += pm80xx.o
diff --git a/drivers/scsi/pm8001/pm80xx_hwi.c b/drivers/scsi/pm8001/pm80xx_hwi.c
index 954f307352e6..5f7501af482b 100644
--- a/drivers/scsi/pm8001/pm80xx_hwi.c
+++ b/drivers/scsi/pm8001/pm80xx_hwi.c
@@ -2287,6 +2287,7 @@ static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
static void
mpi_sata_completion(struct pm8001_hba_info *pm8001_ha,
struct outbound_queue_table *circularQ, void *piomb)
+ __must_hold(&circularQ->oq_lock)
{
struct sas_task *t;
struct pm8001_ccb_info *ccb;
@@ -3849,6 +3850,7 @@ static int ssp_coalesced_comp_resp(struct pm8001_hba_info *pm8001_ha,
*/
static void process_one_iomb(struct pm8001_hba_info *pm8001_ha,
struct outbound_queue_table *circularQ, void *piomb)
+ __must_hold(&circularQ->oq_lock)
{
__le32 pHeader = *(__le32 *)piomb;
u32 opc = (u32)((le32_to_cpu(pHeader)) & 0xFFF);
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 45/56] scsi: qedf: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (43 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 44/56] scsi: pm8001: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 46/56] scsi: qedi: " Bart Van Assche
` (10 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Saurav Kashyap,
Javed Hasan, GR-QLogic-Storage-Upstream, James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/qedf/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/qedf/Makefile b/drivers/scsi/qedf/Makefile
index c46287826fb8..465982ba5dae 100644
--- a/drivers/scsi/qedf/Makefile
+++ b/drivers/scsi/qedf/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_QEDF) := qedf.o
qedf-y = qedf_dbg.o qedf_main.o qedf_io.o qedf_fip.o \
qedf_attr.o qedf_els.o drv_scsi_fw_funcs.o drv_fcoe_fw_funcs.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 46/56] scsi: qedi: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (44 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 45/56] scsi: qedf: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 47/56] scsi: qla1280: Prepare for enabling " Bart Van Assche
` (9 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Nilesh Javali,
Manish Rangankar, GR-QLogic-Storage-Upstream,
James E.J. Bottomley
Annotate qedi_cleanup_all_io() with __no_context_analysis since it
performs conditional locking.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/qedi/Makefile | 3 +++
drivers/scsi/qedi/qedi_fw.c | 1 +
2 files changed, 4 insertions(+)
diff --git a/drivers/scsi/qedi/Makefile b/drivers/scsi/qedi/Makefile
index d84eedfd031b..f081d047b6eb 100644
--- a/drivers/scsi/qedi/Makefile
+++ b/drivers/scsi/qedi/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_QEDI) := qedi.o
qedi-y := qedi_main.o qedi_iscsi.o qedi_fw.o qedi_sysfs.o \
qedi_dbg.o qedi_fw_api.o
diff --git a/drivers/scsi/qedi/qedi_fw.c b/drivers/scsi/qedi/qedi_fw.c
index 854efa4f61d8..e162061ca49c 100644
--- a/drivers/scsi/qedi/qedi_fw.c
+++ b/drivers/scsi/qedi/qedi_fw.c
@@ -1134,6 +1134,7 @@ int qedi_send_iscsi_logout(struct qedi_conn *qedi_conn,
int qedi_cleanup_all_io(struct qedi_ctx *qedi, struct qedi_conn *qedi_conn,
struct iscsi_task *task, bool in_recovery)
+ __context_unsafe(conditional locking)
{
int rval;
struct iscsi_task *ctask;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 47/56] scsi: qla1280: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (45 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 46/56] scsi: qedi: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 48/56] scsi: qla2xxx: Enable " Bart Van Assche
` (8 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley
Document locking requirements with __must_hold().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/qla1280.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index cdd6fe002c32..ebc878068684 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -737,6 +737,7 @@ static void qla1280_mailbox_timeout(struct timer_list *t)
static int
_qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp,
struct completion *wait)
+ __must_hold(ha->host->host_lock)
{
int status = FAILED;
struct scsi_cmnd *cmd = sp->cmd;
@@ -754,6 +755,7 @@ _qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp,
static int
qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp)
+ __must_hold(ha->host->host_lock)
{
DECLARE_COMPLETION_ONSTACK(wait);
@@ -763,6 +765,7 @@ qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp)
static int
qla1280_wait_for_pending_commands(struct scsi_qla_host *ha, int bus, int target)
+ __must_hold(ha->host->host_lock)
{
int cnt;
int status;
@@ -809,6 +812,7 @@ qla1280_wait_for_pending_commands(struct scsi_qla_host *ha, int bus, int target)
**************************************************************************/
static int
qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
+ __must_hold(cmd->device->host->host_lock)
{
struct scsi_qla_host *ha;
int bus, target, lun;
@@ -822,6 +826,10 @@ qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
ENTER("qla1280_error_action");
ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
+
+ /* Tell the compiler that ha->host == cmd->device->host. */
+ __assume_ctx_lock(ha->host->host_lock);
+
sp = scsi_cmd_priv(cmd);
bus = SCSI_BUS_32(cmd);
target = SCSI_TCN_32(cmd);
@@ -1490,6 +1498,7 @@ qla1280_initialize_adapter(struct scsi_qla_host *ha)
*/
static const struct firmware *
qla1280_request_firmware(struct scsi_qla_host *ha)
+ __must_hold(ha->host->host_lock)
{
const struct firmware *fw;
int err;
@@ -1655,6 +1664,7 @@ qla1280_chip_diag(struct scsi_qla_host *ha)
static int
qla1280_load_firmware_pio(struct scsi_qla_host *ha)
+ __must_hold(ha->host->host_lock)
{
/* enter with host_lock acquired */
@@ -1705,6 +1715,7 @@ qla1280_load_firmware_pio(struct scsi_qla_host *ha)
#define DUMP_IT_BACK 0 /* for debug of RISC loading */
static int
qla1280_load_firmware_dma(struct scsi_qla_host *ha)
+ __must_hold(ha->host->host_lock)
{
/* enter with host_lock acquired */
const struct firmware *fw;
@@ -1844,6 +1855,7 @@ qla1280_start_firmware(struct scsi_qla_host *ha)
static int
qla1280_load_firmware(struct scsi_qla_host *ha)
+ __must_hold(ha->host->host_lock)
{
/* enter with host_lock taken */
int err;
@@ -2413,6 +2425,7 @@ qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
*/
static int
qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
+ __must_hold(ha->host->host_lock)
{
struct device_reg __iomem *reg = ha->iobase;
int status = 0;
@@ -2538,6 +2551,7 @@ qla1280_poll(struct scsi_qla_host *ha)
*/
static int
qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
+ __must_hold(ha->host->host_lock)
{
uint16_t mb[MAILBOX_REGISTER_COUNT];
uint16_t reset_delay;
@@ -2598,6 +2612,7 @@ qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
*/
static int
qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
+ __must_hold(ha->host->host_lock)
{
uint16_t mb[MAILBOX_REGISTER_COUNT];
int status;
@@ -2632,6 +2647,7 @@ qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
*/
static int
qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
+ __must_hold(ha->host->host_lock)
{
uint16_t mb[MAILBOX_REGISTER_COUNT];
unsigned int bus, target, lun;
@@ -3749,6 +3765,7 @@ qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
*/
static int
qla1280_abort_isp(struct scsi_qla_host *ha)
+ __must_hold(ha->host->host_lock)
{
struct device_reg __iomem *reg = ha->iobase;
struct srb *sp;
@@ -3881,6 +3898,7 @@ qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
static void
qla1280_get_target_parameters(struct scsi_qla_host *ha,
struct scsi_device *device)
+ __must_hold(ha->host->host_lock)
{
uint16_t mb[MAILBOX_REGISTER_COUNT];
int bus, target, lun;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 48/56] scsi: qla2xxx: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (46 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 47/56] scsi: qla1280: Prepare for enabling " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 49/56] scsi: qla4xxx: " Bart Van Assche
` (7 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Nilesh Javali,
GR-QLogic-Storage-Upstream, James E.J. Bottomley
Make several code blocks with conditional locking compatible with
thread-safety analysis. Annotate functions that perform conditional
locking with __no_context_analysis. No functionality has been changed.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/qla2xxx/Makefile | 3 +++
drivers/scsi/qla2xxx/qla_nx.c | 2 ++
drivers/scsi/qla2xxx/qla_target.c | 29 ++++++++++++++++++-----------
drivers/scsi/qla2xxx/qla_tmpl.c | 1 +
4 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/drivers/scsi/qla2xxx/Makefile b/drivers/scsi/qla2xxx/Makefile
index cbc1303e761e..095657510cc3 100644
--- a/drivers/scsi/qla2xxx/Makefile
+++ b/drivers/scsi/qla2xxx/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+
+CONTEXT_ANALYSIS := y
+
qla2xxx-y := qla_os.o qla_init.o qla_mbx.o qla_iocb.o qla_isr.o qla_gs.o \
qla_dbg.o qla_sup.o qla_attr.o qla_mid.o qla_dfs.o qla_bsg.o \
qla_nx.o qla_mr.o qla_nx2.o qla_target.o qla_tmpl.o qla_nvme.o \
diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c
index 298c060c1292..1950583c5734 100644
--- a/drivers/scsi/qla2xxx/qla_nx.c
+++ b/drivers/scsi/qla2xxx/qla_nx.c
@@ -431,6 +431,7 @@ static int qla82xx_crb_win_lock(struct qla_hw_data *ha)
int
qla82xx_wr_32(struct qla_hw_data *ha, ulong off_in, u32 data)
+ __context_unsafe(conditional locking)
{
void __iomem *off;
unsigned long flags = 0;
@@ -461,6 +462,7 @@ qla82xx_wr_32(struct qla_hw_data *ha, ulong off_in, u32 data)
int
qla82xx_rd_32(struct qla_hw_data *ha, ulong off_in)
+ __context_unsafe(conditional locking)
{
void __iomem *off;
unsigned long flags = 0;
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index e47da45e93a0..687ffd4bfdce 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -383,11 +383,13 @@ static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *vha,
vha->vp_idx, entry->vp_index);
break;
}
- if (!ha_locked)
+ if (!ha_locked) {
spin_lock_irqsave(&host->hw->hardware_lock, flags);
- qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio);
- if (!ha_locked)
+ qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio);
spin_unlock_irqrestore(&host->hw->hardware_lock, flags);
+ } else {
+ qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio);
+ }
break;
}
@@ -3774,6 +3776,7 @@ static int __qlt_send_term_exchange(struct qla_qpair *qpair,
*/
void qlt_send_term_exchange(struct qla_qpair *qpair,
struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked)
+ __context_unsafe(conditional locking)
{
struct scsi_qla_host *vha;
unsigned long flags = 0;
@@ -6727,11 +6730,13 @@ qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair,
if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha))
return 0;
- if (!ha_locked)
+ if (!ha_locked) {
spin_lock_irqsave(&ha->hardware_lock, flags);
- qlt_send_busy(qpair, atio, qla_sam_status);
- if (!ha_locked)
+ qlt_send_busy(qpair, atio, qla_sam_status);
spin_unlock_irqrestore(&ha->hardware_lock, flags);
+ } else {
+ qlt_send_busy(qpair, atio, qla_sam_status);
+ }
return 1;
}
@@ -6740,6 +6745,7 @@ qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair,
/* called via callback from qla2xxx */
static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha,
struct atio_from_isp *atio, uint8_t ha_locked)
+ __context_unsafe(conditional locking)
{
struct qla_hw_data *ha = vha->hw;
struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
@@ -6766,12 +6772,13 @@ static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha,
"qla_target(%d): ATIO_TYPE7 "
"received with UNKNOWN exchange address, "
"sending QUEUE_FULL\n", vha->vp_idx);
- if (!ha_locked)
+ if (!ha_locked) {
spin_lock_irqsave(&ha->hardware_lock, flags);
- qlt_send_busy(ha->base_qpair, atio, qla_sam_status);
- if (!ha_locked)
- spin_unlock_irqrestore(&ha->hardware_lock,
- flags);
+ qlt_send_busy(ha->base_qpair, atio, qla_sam_status);
+ spin_unlock_irqrestore(&ha->hardware_lock, flags);
+ } else {
+ qlt_send_busy(ha->base_qpair, atio, qla_sam_status);
+ }
break;
}
diff --git a/drivers/scsi/qla2xxx/qla_tmpl.c b/drivers/scsi/qla2xxx/qla_tmpl.c
index b0a74b036cf4..f31bd7aeb8dc 100644
--- a/drivers/scsi/qla2xxx/qla_tmpl.c
+++ b/drivers/scsi/qla2xxx/qla_tmpl.c
@@ -1004,6 +1004,7 @@ qla27xx_fwdt_template_valid(void *p)
void
qla27xx_mpi_fwdump(scsi_qla_host_t *vha, int hardware_locked)
+ __context_unsafe(conditional locking)
{
ulong flags = 0;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 49/56] scsi: qla4xxx: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (47 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 48/56] scsi: qla2xxx: Enable " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 50/56] scsi: ufs: " Bart Van Assche
` (6 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Nilesh Javali,
Manish Rangankar, GR-QLogic-Storage-Upstream,
James E.J. Bottomley
Annotate the functions that perform conditional locking with
__no_context_analysis.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/qla4xxx/Makefile | 3 +++
drivers/scsi/qla4xxx/ql4_nx.c | 2 ++
2 files changed, 5 insertions(+)
diff --git a/drivers/scsi/qla4xxx/Makefile b/drivers/scsi/qla4xxx/Makefile
index 1f8a9096c744..2178d139f3ca 100644
--- a/drivers/scsi/qla4xxx/Makefile
+++ b/drivers/scsi/qla4xxx/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
+
+CONTEXT_ANALYSIS := y
+
qla4xxx-y := ql4_os.o ql4_init.o ql4_mbx.o ql4_iocb.o ql4_isr.o \
ql4_nx.o ql4_nvram.o ql4_dbg.o ql4_attr.o ql4_bsg.o ql4_83xx.o
diff --git a/drivers/scsi/qla4xxx/ql4_nx.c b/drivers/scsi/qla4xxx/ql4_nx.c
index f7340cfc990a..513e9e95c888 100644
--- a/drivers/scsi/qla4xxx/ql4_nx.c
+++ b/drivers/scsi/qla4xxx/ql4_nx.c
@@ -406,6 +406,7 @@ void qla4_82xx_crb_win_unlock(struct scsi_qla_host *ha)
void
qla4_82xx_wr_32(struct scsi_qla_host *ha, ulong off, u32 data)
+ __context_unsafe(conditional locking)
{
unsigned long flags = 0;
int rv;
@@ -429,6 +430,7 @@ qla4_82xx_wr_32(struct scsi_qla_host *ha, ulong off, u32 data)
}
uint32_t qla4_82xx_rd_32(struct scsi_qla_host *ha, ulong off)
+ __context_unsafe(conditional locking)
{
unsigned long flags = 0;
int rv;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 50/56] scsi: ufs: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (48 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 49/56] scsi: qla4xxx: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 51/56] scsi: iSCSI transport: Prepare for enabling " Bart Van Assche
` (5 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley,
Can Guo, Bean Huo, Avri Altman, Peter Wang, Adrian Hunter,
Ajay Neeli, Sai Krishna Potthuri
Annotate functions that modify the state of a synchronization object.
Remove the struct semaphore annotations because lock context annotations
are not supported for semaphores.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/ufs/core/Makefile | 2 ++
drivers/ufs/core/ufs-debugfs.c | 8 ++++++--
drivers/ufs/core/ufshcd.c | 14 ++++++++++++++
drivers/ufs/host/Makefile | 2 ++
4 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/drivers/ufs/core/Makefile b/drivers/ufs/core/Makefile
index ce7d16d2cf35..67ab9ffbdf5d 100644
--- a/drivers/ufs/core/Makefile
+++ b/drivers/ufs/core/Makefile
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o
ufshcd-core-y += ufshcd.o ufs-sysfs.o ufs-mcq.o ufs-txeq.o
ufshcd-core-$(CONFIG_RPMB) += ufs-rpmb.o
diff --git a/drivers/ufs/core/ufs-debugfs.c b/drivers/ufs/core/ufs-debugfs.c
index e3dd81d6fe82..814816810388 100644
--- a/drivers/ufs/core/ufs-debugfs.c
+++ b/drivers/ufs/core/ufs-debugfs.c
@@ -65,8 +65,10 @@ static int ee_usr_mask_get(void *data, u64 *val)
return 0;
}
+token_context_lock(ufs_debugfs);
+
static int ufs_debugfs_get_user_access(struct ufs_hba *hba)
-__acquires(&hba->host_sem)
+ __cond_acquires(0, ufs_debugfs)
{
down(&hba->host_sem);
if (!ufshcd_is_user_access_allowed(hba)) {
@@ -74,14 +76,16 @@ __acquires(&hba->host_sem)
return -EBUSY;
}
ufshcd_rpm_get_sync(hba);
+ __acquire(ufs_debugfs);
return 0;
}
static void ufs_debugfs_put_user_access(struct ufs_hba *hba)
-__releases(&hba->host_sem)
+ __releases(ufs_debugfs)
{
ufshcd_rpm_put_sync(hba);
up(&hba->host_sem);
+ __release(ufs_debugfs);
}
static int ee_usr_mask_set(void *data, u64 val)
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 4805e40ed4d7..6fed3f38c010 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -1376,6 +1376,8 @@ static int ufshcd_wait_for_pending_cmds(struct ufs_hba *hba,
* On failure, all acquired locks are released and the tagset is unquiesced.
*/
int ufshcd_pause_command_processing(struct ufs_hba *hba, u64 timeout_us)
+ __cond_acquires(0, &hba->host->scan_mutex)
+ __cond_acquires(0, &hba->clk_scaling_lock)
{
int ret = 0;
@@ -1400,6 +1402,8 @@ int ufshcd_pause_command_processing(struct ufs_hba *hba, u64 timeout_us)
* This function resumes command submissions.
*/
void ufshcd_resume_command_processing(struct ufs_hba *hba)
+ __releases(&hba->clk_scaling_lock)
+ __releases(&hba->host->scan_mutex)
{
up_write(&hba->clk_scaling_lock);
blk_mq_unquiesce_tagset(&hba->host->tag_set);
@@ -1469,6 +1473,9 @@ static int ufshcd_scale_gear(struct ufs_hba *hba, u32 target_gear, bool scale_up
* Return: 0 upon success; -EBUSY upon timeout.
*/
static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba, u64 timeout_us)
+ __cond_acquires(0, &hba->host->scan_mutex)
+ __cond_acquires(0, &hba->wb_mutex)
+ __cond_acquires(0, &hba->clk_scaling_lock)
{
int ret = 0;
/*
@@ -1498,6 +1505,9 @@ static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba, u64 timeout_us)
}
static void ufshcd_clock_scaling_unprepare(struct ufs_hba *hba, int err)
+ __releases(&hba->clk_scaling_lock)
+ __releases(&hba->wb_mutex)
+ __releases(&hba->host->scan_mutex)
{
up_write(&hba->clk_scaling_lock);
mutex_unlock(&hba->wb_mutex);
@@ -3301,6 +3311,8 @@ ufshcd_dev_cmd_completion(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
}
static void ufshcd_dev_man_lock(struct ufs_hba *hba)
+ __acquires(&hba->dev_cmd.lock)
+ __acquires_shared(&hba->clk_scaling_lock)
{
ufshcd_hold(hba);
mutex_lock(&hba->dev_cmd.lock);
@@ -3308,6 +3320,8 @@ static void ufshcd_dev_man_lock(struct ufs_hba *hba)
}
static void ufshcd_dev_man_unlock(struct ufs_hba *hba)
+ __releases_shared(&hba->clk_scaling_lock)
+ __releases(&hba->dev_cmd.lock)
{
up_read(&hba->clk_scaling_lock);
mutex_unlock(&hba->dev_cmd.lock);
diff --git a/drivers/ufs/host/Makefile b/drivers/ufs/host/Makefile
index 65d8bb23ab7b..7d8db67eb23c 100644
--- a/drivers/ufs/host/Makefile
+++ b/drivers/ufs/host/Makefile
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_UFS_DWC_TC_PCI) += tc-dwc-g210-pci.o ufshcd-dwc.o tc-dwc-g210.o
obj-$(CONFIG_SCSI_UFS_DWC_TC_PLATFORM) += tc-dwc-g210-pltfrm.o ufshcd-dwc.o tc-dwc-g210.o
obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 51/56] scsi: iSCSI transport: Prepare for enabling lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (49 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 50/56] scsi: ufs: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 52/56] scsi: smartpqi: Enable " Bart Van Assche
` (4 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Lee Duncan, Chris Leech,
Mike Christie, James E.J. Bottomley
Document locking requirements with __must_hold().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/scsi_transport_iscsi.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 8aa76f813bcd..129f12bb7271 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -2243,6 +2243,7 @@ static void iscsi_ep_disconnect(struct iscsi_cls_conn *conn, bool is_active)
static void iscsi_if_disconnect_bound_ep(struct iscsi_cls_conn *conn,
struct iscsi_endpoint *ep,
bool is_active)
+ __must_hold(conn->ep_mutex)
{
/* Check if this was a conn error and the kernel took ownership */
spin_lock_irq(&conn->lock);
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 52/56] scsi: smartpqi: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (50 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 51/56] scsi: iSCSI transport: Prepare for enabling " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 53/56] scsi: snic: " Bart Van Assche
` (3 subsequent siblings)
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Tomas Henzl, Don Brace,
James E.J. Bottomley
Document locking requirements with __acquires(), __releases() and
__must_hold(). Annotate functions that perform conditional locking with
__no_context_analysis.
Cc: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/smartpqi/Makefile | 3 +++
drivers/scsi/smartpqi/smartpqi_init.c | 33 +++++++++++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/drivers/scsi/smartpqi/Makefile b/drivers/scsi/smartpqi/Makefile
index 28985e508b5c..71db5cd96284 100644
--- a/drivers/scsi/smartpqi/Makefile
+++ b/drivers/scsi/smartpqi/Makefile
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_SMARTPQI) += smartpqi.o
smartpqi-objs := smartpqi_init.o smartpqi_sis.o smartpqi_sas_transport.o
diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index b4ed991976d0..f99eef39ede4 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -306,12 +306,14 @@ static inline void pqi_save_fw_triage_setting(struct pqi_ctrl_info *ctrl_info, b
}
static inline void pqi_ctrl_block_scan(struct pqi_ctrl_info *ctrl_info)
+ __acquires(ctrl_info->scan_mutex)
{
ctrl_info->scan_blocked = true;
mutex_lock(&ctrl_info->scan_mutex);
}
static inline void pqi_ctrl_unblock_scan(struct pqi_ctrl_info *ctrl_info)
+ __releases(ctrl_info->scan_mutex)
{
ctrl_info->scan_blocked = false;
mutex_unlock(&ctrl_info->scan_mutex);
@@ -323,11 +325,13 @@ static inline bool pqi_ctrl_scan_blocked(struct pqi_ctrl_info *ctrl_info)
}
static inline void pqi_ctrl_block_device_reset(struct pqi_ctrl_info *ctrl_info)
+ __acquires(ctrl_info->lun_reset_mutex)
{
mutex_lock(&ctrl_info->lun_reset_mutex);
}
static inline void pqi_ctrl_unblock_device_reset(struct pqi_ctrl_info *ctrl_info)
+ __releases(ctrl_info->lun_reset_mutex)
{
mutex_unlock(&ctrl_info->lun_reset_mutex);
}
@@ -430,11 +434,13 @@ static inline bool pqi_device_offline(struct pqi_scsi_dev *device)
}
static inline void pqi_ctrl_ofa_start(struct pqi_ctrl_info *ctrl_info)
+ __acquires(ctrl_info->ofa_mutex)
{
mutex_lock(&ctrl_info->ofa_mutex);
}
static inline void pqi_ctrl_ofa_done(struct pqi_ctrl_info *ctrl_info)
+ __releases(ctrl_info->ofa_mutex)
{
mutex_unlock(&ctrl_info->ofa_mutex);
}
@@ -2299,6 +2305,7 @@ static void pqi_update_device_list(struct pqi_ctrl_info *ctrl_info,
* requests before removal.
*/
if (pqi_ofa_in_progress(ctrl_info)) {
+ __acquire(&ctrl_info->lun_reset_mutex);
list_for_each_entry_safe(device, next, &delete_list, delete_list_entry)
if (pqi_is_device_added(device))
pqi_device_remove_start(device);
@@ -3661,6 +3668,8 @@ static void pqi_process_soft_reset(struct pqi_ctrl_info *ctrl_info)
pqi_save_ctrl_mode(ctrl_info, SIS_MODE);
rc = pqi_ofa_ctrl_restart(ctrl_info, delay_secs);
pqi_host_free_buffer(ctrl_info, &ctrl_info->ofa_memory);
+ /* What guarantees that &ctrl_info->ofa_mutex is held here? */
+ __acquire(&ctrl_info->ofa_mutex);
pqi_ctrl_ofa_done(ctrl_info);
dev_info(&ctrl_info->pci_dev->dev,
"Online Firmware Activation: %s\n",
@@ -3672,6 +3681,8 @@ static void pqi_process_soft_reset(struct pqi_ctrl_info *ctrl_info)
if (ctrl_info->soft_reset_handshake_supported)
pqi_clear_soft_reset_status(ctrl_info);
pqi_host_free_buffer(ctrl_info, &ctrl_info->ofa_memory);
+ /* What guarantees that &ctrl_info->ofa_mutex is held here? */
+ __acquire(&ctrl_info->ofa_mutex);
pqi_ctrl_ofa_done(ctrl_info);
pqi_ofa_ctrl_unquiesce(ctrl_info);
break;
@@ -3682,6 +3693,8 @@ static void pqi_process_soft_reset(struct pqi_ctrl_info *ctrl_info)
"unexpected Online Firmware Activation reset status: 0x%x\n",
reset_status);
pqi_host_free_buffer(ctrl_info, &ctrl_info->ofa_memory);
+ /* What guarantees that &ctrl_info->ofa_mutex is held here? */
+ __acquire(&ctrl_info->ofa_mutex);
pqi_ctrl_ofa_done(ctrl_info);
pqi_ofa_ctrl_unquiesce(ctrl_info);
pqi_take_ctrl_offline(ctrl_info, PQI_OFA_RESPONSE_TIMEOUT);
@@ -3698,6 +3711,8 @@ static void pqi_ofa_memory_alloc_worker(struct work_struct *work)
pqi_ctrl_ofa_start(ctrl_info);
pqi_host_setup_buffer(ctrl_info, &ctrl_info->ofa_memory, ctrl_info->ofa_bytes_requested, ctrl_info->ofa_bytes_requested);
pqi_host_memory_update(ctrl_info, &ctrl_info->ofa_memory, PQI_VENDOR_GENERAL_OFA_MEMORY_UPDATE);
+ /* This function acquires &ctrl_info->ofa_mutex and doesn't release it. */
+ __release(&ctrl_info->ofa_mutex);
}
static void pqi_ofa_quiesce_worker(struct work_struct *work)
@@ -3738,6 +3753,8 @@ static bool pqi_ofa_process_event(struct pqi_ctrl_info *ctrl_info,
"received Online Firmware Activation cancel request: reason: %u\n",
ctrl_info->ofa_cancel_reason);
pqi_host_free_buffer(ctrl_info, &ctrl_info->ofa_memory);
+ /* What guarantees that &ctrl_info->ofa_mutex is held here? */
+ __acquire(&ctrl_info->ofa_mutex);
pqi_ctrl_ofa_done(ctrl_info);
break;
default:
@@ -8726,6 +8743,7 @@ static int pqi_ctrl_init_resume(struct pqi_ctrl_info *ctrl_info)
}
if (pqi_ofa_in_progress(ctrl_info)) {
+ __acquire(&ctrl_info->scan_mutex);
pqi_ctrl_unblock_scan(ctrl_info);
if (ctrl_info->ctrl_logging_supported) {
if (!ctrl_info->ctrl_log_memory.host_memory)
@@ -8938,6 +8956,8 @@ static void pqi_remove_ctrl(struct pqi_ctrl_info *ctrl_info)
}
static void pqi_ofa_ctrl_quiesce(struct pqi_ctrl_info *ctrl_info)
+ __acquires(&ctrl_info->scan_mutex)
+ __acquires(&ctrl_info->lun_reset_mutex)
{
pqi_ctrl_block_scan(ctrl_info);
pqi_scsi_block_requests(ctrl_info);
@@ -8948,6 +8968,8 @@ static void pqi_ofa_ctrl_quiesce(struct pqi_ctrl_info *ctrl_info)
}
static void pqi_ofa_ctrl_unquiesce(struct pqi_ctrl_info *ctrl_info)
+ __releases(&ctrl_info->lun_reset_mutex)
+ __releases(&ctrl_info->scan_mutex)
{
pqi_start_heartbeat_timer(ctrl_info);
pqi_ctrl_unblock_requests(ctrl_info);
@@ -9410,6 +9432,7 @@ static void pqi_shutdown(struct pci_dev *pci_dev)
pqi_ctrl_block_device_reset(ctrl_info);
pqi_ctrl_block_requests(ctrl_info);
pqi_ctrl_wait_until_quiesced(ctrl_info);
+ __release(&ctrl_info->lun_reset_mutex);
if (system_state == SYSTEM_RESTART)
shutdown_event = RESTART;
@@ -9486,6 +9509,8 @@ static inline enum bmic_flush_cache_shutdown_event pqi_get_flush_cache_shutdown_
}
static int pqi_suspend_or_freeze(struct device *dev, bool suspend)
+ __acquires(&((struct pqi_ctrl_info *)pci_get_drvdata(to_pci_dev(dev)))->scan_mutex)
+ __acquires(&((struct pqi_ctrl_info *)pci_get_drvdata(to_pci_dev(dev)))->lun_reset_mutex)
{
struct pci_dev *pci_dev;
struct pqi_ctrl_info *ctrl_info;
@@ -9519,11 +9544,15 @@ static int pqi_suspend_or_freeze(struct device *dev, bool suspend)
}
static __maybe_unused int pqi_suspend(struct device *dev)
+ __acquires(&((struct pqi_ctrl_info *)pci_get_drvdata(to_pci_dev(dev)))->scan_mutex)
+ __acquires(&((struct pqi_ctrl_info *)pci_get_drvdata(to_pci_dev(dev)))->lun_reset_mutex)
{
return pqi_suspend_or_freeze(dev, true);
}
static int pqi_resume_or_restore(struct device *dev)
+ __cond_releases(0, &((struct pqi_ctrl_info *)pci_get_drvdata(to_pci_dev(dev)))->lun_reset_mutex)
+ __cond_releases(0, &((struct pqi_ctrl_info *)pci_get_drvdata(to_pci_dev(dev)))->scan_mutex)
{
int rc;
struct pci_dev *pci_dev;
@@ -9547,11 +9576,15 @@ static int pqi_resume_or_restore(struct device *dev)
}
static int pqi_freeze(struct device *dev)
+ __acquires(&((struct pqi_ctrl_info *)pci_get_drvdata(to_pci_dev(dev)))->scan_mutex)
+ __acquires(&((struct pqi_ctrl_info *)pci_get_drvdata(to_pci_dev(dev)))->lun_reset_mutex)
{
return pqi_suspend_or_freeze(dev, false);
}
static int pqi_thaw(struct device *dev)
+ __cond_releases(0, &((struct pqi_ctrl_info *)pci_get_drvdata(to_pci_dev(dev)))->lun_reset_mutex)
+ __cond_releases(0, &((struct pqi_ctrl_info *)pci_get_drvdata(to_pci_dev(dev)))->scan_mutex)
{
int rc;
struct pci_dev *pci_dev;
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 53/56] scsi: snic: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (51 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 52/56] scsi: smartpqi: Enable " Bart Van Assche
@ 2026-04-30 18:20 ` 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
` (2 subsequent siblings)
55 siblings, 1 reply; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Karan Tilak Kumar,
Narsimhulu Musini, Sesidhar Baddela, James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/snic/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/snic/Makefile b/drivers/scsi/snic/Makefile
index 41546e3cb701..b12563cb174d 100644
--- a/drivers/scsi/snic/Makefile
+++ b/drivers/scsi/snic/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_SNIC) += snic.o
snic-y := \
^ permalink raw reply related [flat|nested] 62+ messages in thread* Re: [PATCH v2 53/56] scsi: snic: Enable lock context analysis
2026-04-30 18:20 ` [PATCH v2 53/56] scsi: snic: " Bart Van Assche
@ 2026-05-01 19:08 ` Narsimhulu Musini (nmusini)
0 siblings, 0 replies; 62+ messages in thread
From: Narsimhulu Musini (nmusini) @ 2026-05-01 19:08 UTC (permalink / raw)
To: Bart Van Assche, Martin K . Petersen
Cc: linux-scsi@vger.kernel.org, Marco Elver,
Karan Tilak Kumar (kartilak), Sesidhar Baddela (sebaddel),
James E.J. Bottomley
________________________________________
From: Bart Van Assche <bvanassche@acm.org>
Sent: 30 April 2026 11:20 AM
To: Martin K . Petersen <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org <linux-scsi@vger.kernel.org>; Marco Elver <elver@google.com>; Bart Van Assche <bvanassche@acm.org>; Karan Tilak Kumar (kartilak) <kartilak@cisco.com>; Narsimhulu Musini (nmusini) <nmusini@cisco.com>; Sesidhar Baddela (sebaddel) <sebaddel@cisco.com>; James E.J. Bottomley <James.Bottomley@HansenPartnership.com>
Subject: [PATCH v2 53/56] scsi: snic: Enable lock context analysis
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Acked-by: Narsimhulu Musini <nmusini@cisco.com>
---
drivers/scsi/snic/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/snic/Makefile b/drivers/scsi/snic/Makefile
index 41546e3cb701..b12563cb174d 100644
--- a/drivers/scsi/snic/Makefile
+++ b/drivers/scsi/snic/Makefile
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_SNIC) += snic.o
snic-y := \
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH v2 54/56] scsi: sym53c8xx_2: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (52 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 53/56] scsi: snic: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 55/56] scsi: core: " Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 56/56] scsi: core: Protect host state changes with the host lock Bart Van Assche
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Matthew Wilcox,
James E.J. Bottomley
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/sym53c8xx_2/Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/sym53c8xx_2/Makefile b/drivers/scsi/sym53c8xx_2/Makefile
index 0751e2a0cd82..c28fb2b65622 100644
--- a/drivers/scsi/sym53c8xx_2/Makefile
+++ b/drivers/scsi/sym53c8xx_2/Makefile
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
# Makefile for the NCR/SYMBIOS/LSI 53C8XX PCI SCSI controllers driver.
+CONTEXT_ANALYSIS := y
+
sym53c8xx-objs := sym_fw.o sym_glue.o sym_hipd.o sym_malloc.o sym_nvram.o
obj-$(CONFIG_SCSI_SYM53C8XX_2) := sym53c8xx.o
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 55/56] scsi: core: Enable lock context analysis
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (53 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 54/56] scsi: sym53c8xx_2: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
2026-04-30 18:20 ` [PATCH v2 56/56] scsi: core: Protect host state changes with the host lock Bart Van Assche
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, James E.J. Bottomley
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; \
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v2 56/56] scsi: core: Protect host state changes with the host lock
2026-04-30 18:19 [PATCH v2 00/56] Enable lock context analysis for the SCSI subsystem Bart Van Assche
` (54 preceding siblings ...)
2026-04-30 18:20 ` [PATCH v2 55/56] scsi: core: " Bart Van Assche
@ 2026-04-30 18:20 ` Bart Van Assche
55 siblings, 0 replies; 62+ messages in thread
From: Bart Van Assche @ 2026-04-30 18:20 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Marco Elver, Bart Van Assche, Jianzhou Zhao,
James E.J. Bottomley, Kashyap Desai, Sumit Saxena, Shivasharan S,
Chandrakanth patil, Sathya Prakash, Sreekanth Reddy,
Suganath Prabu Subramani, Ranjan Kumar, Nilesh Javali,
Manish Rangankar, GR-QLogic-Storage-Upstream
Some but not all SCSI host state changes are protected with the SCSI
host lock. Annotate the SCSI host state with __guarded_by(&host_lock),
protect all SCSI host state changes with the SCSI host lock and use
READ_ONCE() for all SCSI host state reads. This patch prevents that
KCSAN complains about data races when accessing the SCSI host state.
Reported-by: Jianzhou Zhao <luckd0g@163.com>
Closes: https://lore.kernel.org/all/36d59d0e.6db0.19cdbeee01b.Coremail.luckd0g@163.com/
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/hosts.c | 13 ++++++++-----
drivers/scsi/megaraid/megaraid_sas_base.c | 2 +-
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 2 +-
drivers/scsi/qla4xxx/ql4_os.c | 6 ++----
drivers/scsi/scsi_lib.c | 3 +--
drivers/scsi/scsi_sysfs.c | 7 ++++---
include/scsi/scsi_host.h | 23 ++++++++++++++++-------
7 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index e047747d4ecf..7482ae7777c8 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -278,7 +278,8 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
if (error)
goto out_disable_runtime_pm;
- scsi_host_set_state(shost, SHOST_RUNNING);
+ scoped_guard(spinlock_irq, shost->host_lock)
+ scsi_host_set_state(shost, SHOST_RUNNING);
get_device(shost->shost_gendev.parent);
device_enable_async_suspend(&shost->shost_dev);
@@ -352,6 +353,7 @@ EXPORT_SYMBOL(scsi_add_host_with_dma);
static void scsi_host_dev_release(struct device *dev)
{
struct Scsi_Host *shost = dev_to_shost(dev);
+ enum scsi_host_state host_state = scsi_get_host_state(shost);
struct device *parent = dev->parent;
/* Wait for functions invoked through call_rcu(&scmd->rcu, ...) */
@@ -364,7 +366,7 @@ static void scsi_host_dev_release(struct device *dev)
if (shost->work_q)
destroy_workqueue(shost->work_q);
- if (shost->shost_state == SHOST_CREATED) {
+ if (host_state == SHOST_CREATED) {
/*
* Free the shost_dev device name and remove the proc host dir
* here if scsi_host_{alloc,put}() have been called but neither
@@ -380,7 +382,7 @@ static void scsi_host_dev_release(struct device *dev)
ida_free(&host_index_ida, shost->host_no);
- if (shost->shost_state != SHOST_CREATED)
+ if (host_state != SHOST_CREATED)
put_device(parent);
kfree(shost);
}
@@ -414,7 +416,8 @@ struct Scsi_Host *scsi_host_alloc(const struct scsi_host_template *sht, int priv
shost->host_lock = &shost->default_lock;
spin_lock_init(shost->host_lock);
- shost->shost_state = SHOST_CREATED;
+ scoped_guard(spinlock_init, shost->host_lock)
+ shost->shost_state = SHOST_CREATED;
INIT_LIST_HEAD(&shost->__devices);
INIT_LIST_HEAD(&shost->__targets);
INIT_LIST_HEAD(&shost->eh_abort_list);
@@ -600,7 +603,7 @@ EXPORT_SYMBOL(scsi_host_lookup);
**/
struct Scsi_Host *scsi_host_get(struct Scsi_Host *shost)
{
- if ((shost->shost_state == SHOST_DEL) ||
+ if (scsi_get_host_state(shost) == SHOST_DEL ||
!get_device(&shost->shost_gendev))
return NULL;
return shost;
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index ccefe5841a17..97a81a86db82 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -3075,7 +3075,7 @@ static int megasas_reset_bus_host(struct scsi_cmnd *scmd)
scmd_printk(KERN_INFO, scmd,
"SCSI host state: %d SCSI host busy: %d FW outstanding: %d\n",
- scmd->device->host->shost_state,
+ scsi_get_host_state(scmd->device->host),
scsi_host_busy(scmd->device->host),
atomic_read(&instance->fw_outstanding));
/*
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 6ff788557294..e40913d2479e 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -5460,7 +5460,7 @@ static enum scsi_qc_status scsih_qcmd(struct Scsi_Host *shost,
* Avoid error handling escallation when device is disconnected
*/
if (handle == MPT3SAS_INVALID_DEVICE_HANDLE || sas_device_priv_data->block) {
- if (scmd->device->host->shost_state == SHOST_RECOVERY &&
+ if (scsi_get_host_state(scmd->device->host) == SHOST_RECOVERY &&
scmd->cmnd[0] == TEST_UNIT_READY) {
scsi_build_sense(scmd, 0, UNIT_ATTENTION, 0x29, 0x07);
scsi_done(scmd);
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index d598ab4126f8..c9d9fc7c81fb 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -9411,11 +9411,9 @@ static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
* This routine finds that if reset host is called in EH
* scenario or from some application like sg_reset
**/
-static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
+static bool qla4xxx_is_eh_active(struct Scsi_Host *shost)
{
- if (shost->shost_state == SHOST_RECOVERY)
- return 1;
- return 0;
+ return scsi_get_host_state(shost) == SHOST_RECOVERY;
}
/**
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 6e8c7a42603e..5f7580b089e9 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1638,10 +1638,9 @@ static enum scsi_qc_status scsi_dispatch_cmd(struct scsi_cmnd *cmd)
goto done;
}
- if (unlikely(host->shost_state == SHOST_DEL)) {
+ if (scsi_get_host_state(host) == SHOST_DEL) {
cmd->result = (DID_NO_CONNECT << 16);
goto done;
-
}
trace_scsi_dispatch_cmd_start(cmd);
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index dfc3559e7e04..9480432f650b 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -214,8 +214,9 @@ store_shost_state(struct device *dev, struct device_attribute *attr,
if (!state)
return -EINVAL;
- if (scsi_host_set_state(shost, state))
- return -EINVAL;
+ scoped_guard(spinlock_irq, shost->host_lock)
+ if (scsi_host_set_state(shost, state))
+ return -EINVAL;
return count;
}
@@ -223,7 +224,7 @@ static ssize_t
show_shost_state(struct device *dev, struct device_attribute *attr, char *buf)
{
struct Scsi_Host *shost = class_to_shost(dev);
- const char *name = scsi_host_state_name(shost->shost_state);
+ const char *name = scsi_host_state_name(scsi_get_host_state(shost));
if (!name)
return -EINVAL;
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 2bbe7cb0060b..9841402e8bdf 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -729,7 +729,7 @@ struct Scsi_Host {
unsigned int irq;
- enum scsi_host_state shost_state;
+ enum scsi_host_state shost_state __guarded_by(&host_lock);
/* ldm bits */
struct device shost_gendev, shost_dev;
@@ -787,11 +787,18 @@ static inline struct Scsi_Host *dev_to_shost(struct device *dev)
return container_of(dev, struct Scsi_Host, shost_gendev);
}
+static inline enum scsi_host_state scsi_get_host_state(struct Scsi_Host *shost)
+{
+ return context_unsafe(READ_ONCE(shost->shost_state));
+}
+
static inline int scsi_host_in_recovery(struct Scsi_Host *shost)
{
- return shost->shost_state == SHOST_RECOVERY ||
- shost->shost_state == SHOST_CANCEL_RECOVERY ||
- shost->shost_state == SHOST_DEL_RECOVERY ||
+ enum scsi_host_state state = scsi_get_host_state(shost);
+
+ return state == SHOST_RECOVERY ||
+ state == SHOST_CANCEL_RECOVERY ||
+ state == SHOST_DEL_RECOVERY ||
shost->tmf_in_progress;
}
@@ -837,8 +844,9 @@ static inline struct device *scsi_get_device(struct Scsi_Host *shost)
**/
static inline int scsi_host_scan_allowed(struct Scsi_Host *shost)
{
- return shost->shost_state == SHOST_RUNNING ||
- shost->shost_state == SHOST_RECOVERY;
+ enum scsi_host_state state = scsi_get_host_state(shost);
+
+ return state == SHOST_RUNNING || state == SHOST_RECOVERY;
}
extern void scsi_unblock_requests(struct Scsi_Host *);
@@ -942,6 +950,7 @@ static inline unsigned char scsi_host_get_guard(struct Scsi_Host *shost)
return shost->prot_guard_type;
}
-extern int scsi_host_set_state(struct Scsi_Host *, enum scsi_host_state);
+int scsi_host_set_state(struct Scsi_Host *shost, enum scsi_host_state state)
+ __must_hold(&shost->host_lock);
#endif /* _SCSI_SCSI_HOST_H */
^ permalink raw reply related [flat|nested] 62+ messages in thread