Enable lock context analysis for the SCSI subsystem
Subsystems (41)
Bart Van Assche
reviewerv2 cover Enable lock context analysis for the SCSI subsystem
Hi Martin,
This patch series enables lock context analysis for all SCSI drivers and also for the SCSI core. The advantages are as follows:
- The compiler (only Clang) verifies whether the lock and unlock calls match what has been declared via __must_hold(), __acquires() or __releases(). This is useful for catching locking bugs in error paths.
- Support for __guarded_by() is enabled. If a member variable is annotated with __guarded_by(lock), the compiler will issue a warning if that member variable is accessed without holding 'lock'.
Additionally, a patch is included that suppresses KCSAN complaints about SCSI host state changes.
More information about lock context analysis is available in the cover letter of [PATCH v5 00/36] Compiler-Based Context- and Locking-Analysis
(https://lore.kernel.org/lkml/[email protected]/).
Please consider this patch series for the next merge window.
Thanks,
Bart.
Changes compared to v1:
- Split patch "Enable lock context analysis" into one patch per driver.
Bart Van Assche (56):
PCI: Convert to_pci_dev() into an inline function
scsi: scsi_debug: Prepare for enabling lock context analysis
scsi: sg: Prepare for enabling lock context analysis
scsi: st: Prepare for enabling lock context analysis
scsi: BusLogic: Introduce a local variable
scsi: BusLogic: Prepare for enabling lock context analysis
scsi: NCR5380: Prepare for enabling lock context analysis
scsi: aacraid: Prepare for enabling lock context analysis
scsi: aic7xxx: Enable lock context analysis
scsi: aha152x: Prepare for enabling lock context analysis
scsi: aic7xxx: Prepare for enabling lock context analysis
scsi: aic94xx: Enable lock context analysis
scsi: arcmsr: Enable lock context analysis
scsi: arm: Enable lock context analysis
scsi: be2iscsi: Prepare for enabling lock context analysis
scsi: be2iscsi: Enable lock context analysis
scsi: cxgbi: Enable lock context analysis
scsi: bfa: Enable lock context analysis
scsi: bnx2fc: Enable lock context analysis
scsi: bnx2i: Introduce a local variable
scsi: bnx2i: Enable lock context analysis
scsi: csiostor: Enable lock context analysis
scsi: elx: Enable lock context analysis
scsi: esas2r: Enable lock context analysis
scsi: fcoe: Enable lock context analysis
scsi: fnic: Enable lock context analysis
scsi: hisi_sas: Enable lock context analysis
scsi: hpsa: Prepare for enabling lock context analysis
scsi: ibmvscsi: Enable lock context analysis
scsi: ibmvscsi_tgt: Enable lock context analysis
scsi: ipr: Prepare for enabling lock context analysis
scsi: ips: Prepare for enabling lock context analysis
scsi: isci: Enable lock context analysis
scsi: libfc: Enable lock context analysis
scsi: libiscsi: Prepare for enabling lock context analysis
scsi: libsas: Prepare for enabling lock context analysis
scsi: libsas: Enable lock context analysis
scsi: lpfc: Prepare for enabling lock context analysis
scsi: megaraid_sas: Prepare for enabling lock context analysis
scsi: megaraid: Enable lock context analysis
scsi: mpt3sas: Enable lock context analysis
scsi: mvsas: Enable lock context analysis
scsi: pcmcia: Enable lock context analysis
scsi: pm8001: Enable lock context analysis
scsi: qedf: Enable lock context analysis
scsi: qedi: Enable lock context analysis
scsi: qla1280: Prepare for enabling lock context analysis
scsi: qla2xxx: Enable lock context analysis
scsi: qla4xxx: Enable lock context analysis
scsi: ufs: Enable lock context analysis
scsi: iSCSI transport: Prepare for enabling lock context analysis
scsi: smartpqi: Enable lock context analysis
scsi: snic: Enable lock context analysis
scsi: sym53c8xx_2: Enable lock context analysis
scsi: core: Enable lock context analysis
scsi: core: Protect host state changes with the host lock
drivers/scsi/BusLogic.c | 11 +++-- drivers/scsi/Makefile | 1 + drivers/scsi/NCR5380.c | 4 +- drivers/scsi/aacraid/Makefile | 2 + drivers/scsi/aacraid/commctrl.c | 1 + drivers/scsi/aacraid/commsup.c | 3 ++ drivers/scsi/aha152x.c | 1 + drivers/scsi/aic7xxx/Makefile | 2 + drivers/scsi/aic7xxx/aic79xx_osm.h | 2 + drivers/scsi/aic7xxx/aic7xxx_osm.h | 2 + drivers/scsi/aic7xxx/aicasm/Makefile | 3 ++ drivers/scsi/aic94xx/Makefile | 2 + drivers/scsi/arcmsr/Makefile | 2 + drivers/scsi/arm/Makefile | 2 + drivers/scsi/be2iscsi/Makefile | 2 + drivers/scsi/be2iscsi/be_main.c | 4 ++ drivers/scsi/bfa/Makefile | 3 ++ 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 ++- drivers/scsi/bnx2i/Makefile | 3 ++ drivers/scsi/bnx2i/bnx2i_hwi.c | 14 ++++-- drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 + 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 +++ drivers/scsi/cxgbi/Makefile | 3 ++ drivers/scsi/device_handler/Makefile | 3 ++ drivers/scsi/elx/Makefile | 1 + drivers/scsi/esas2r/Makefile | 3 ++ drivers/scsi/fcoe/Makefile | 3 ++ 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 ++ drivers/scsi/hisi_sas/Makefile | 3 ++ drivers/scsi/hosts.c | 13 ++++-- drivers/scsi/hpsa.c | 2 +- drivers/scsi/ibmvscsi/Makefile | 3 ++ drivers/scsi/ibmvscsi_tgt/Makefile | 3 ++ drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 7 +++ drivers/scsi/ipr.c | 11 +++++ drivers/scsi/ips.c | 1 + drivers/scsi/isci/Makefile | 3 ++ 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 ++ drivers/scsi/libiscsi.c | 19 +++++++- drivers/scsi/libsas/Makefile | 2 + drivers/scsi/libsas/sas_ata.c | 2 +- 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 + drivers/scsi/megaraid/Makefile | 3 ++ drivers/scsi/megaraid/megaraid_sas.h | 9 ++-- drivers/scsi/megaraid/megaraid_sas_base.c | 17 +++++-- drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 + drivers/scsi/mpt3sas/Makefile | 3 ++ drivers/scsi/mpt3sas/mpt3sas_scsih.c | 2 +- drivers/scsi/mvsas/Makefile | 2 + drivers/scsi/mvsas/mv_sas.c | 7 +++ drivers/scsi/pcmcia/Makefile | 2 + drivers/scsi/pm8001/Makefile | 1 + drivers/scsi/pm8001/pm80xx_hwi.c | 2 + drivers/scsi/qedf/Makefile | 3 ++ drivers/scsi/qedi/Makefile | 3 ++ drivers/scsi/qedi/qedi_fw.c | 1 + drivers/scsi/qla1280.c | 18 +++++++ 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 + drivers/scsi/qla4xxx/Makefile | 3 ++ drivers/scsi/qla4xxx/ql4_nx.c | 2 + drivers/scsi/qla4xxx/ql4_os.c | 6 +-- drivers/scsi/scsi_debug.c | 16 +++++++ drivers/scsi/scsi_lib.c | 3 +- drivers/scsi/scsi_scan.c | 12 +++++ drivers/scsi/scsi_sysfs.c | 7 +-- drivers/scsi/scsi_transport_iscsi.c | 1 + drivers/scsi/sg.c | 1 + drivers/scsi/smartpqi/Makefile | 3 ++ drivers/scsi/smartpqi/smartpqi_init.c | 33 +++++++++++++ drivers/scsi/snic/Makefile | 3 ++ drivers/scsi/st.c | 1 + drivers/scsi/sym53c8xx_2/Makefile | 2 + drivers/ufs/core/Makefile | 2 + drivers/ufs/core/ufs-debugfs.c | 8 +++- drivers/ufs/core/ufshcd.c | 14 ++++++ drivers/ufs/host/Makefile | 2 + include/linux/pci.h | 5 +- include/scsi/libiscsi.h | 5 +- include/scsi/scsi_host.h | 25 +++++++--- 100 files changed, 487 insertions(+), 63 deletions(-)
Bart Van Assche
reviewerPATCH v2 1/56 PCI: Convert to_pci_dev() into an inline function
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().
--- include/linux/pci.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/pci.h +4 -1
@@ -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)
Bart Van Assche
reviewerPATCH v2 2/56 scsi: scsi_debug: Prepare for enabling lock context analysis
In reply to Bart Van AsscheSuppress lock context analysis for the functions that perform conditional locking to prevent that the Clang thread-safety analyzer complains about these functions.
--- drivers/scsi/scsi_debug.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/scsi/scsi_debug.c +16 -0
@@ -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)
Bart Van Assche
reviewerPATCH v2 3/56 scsi: sg: Prepare for enabling lock context analysis
In reply to Bart Van AsscheAnnotate open_wait() with __must_hold() since it unlocks and locks a mutex.
--- drivers/scsi/sg.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/sg.c +1 -0
@@ -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 ;
Bart Van Assche
reviewerPATCH v2 4/56 scsi: st: Prepare for enabling lock context analysis
In reply to Bart Van AsscheDocument what mutex is released by st_common_ioctl().
--- drivers/scsi/st.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/st.c +1 -0
@@ -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 ;
Bart Van Assche
reviewerPATCH v2 5/56 scsi: BusLogic: Introduce a local variable
In reply to Bart Van AsscheIntroduce a new local variable to prepare for enabling thread-safety analysis. No functionality has been changed.
--- drivers/scsi/BusLogic.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/scsi/BusLogic.c +5 -4
@@ -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);
Bart Van Assche
reviewerPATCH v2 6/56 scsi: BusLogic: Prepare for enabling lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold().
--- drivers/scsi/BusLogic.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/BusLogic.c +2 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 7/56 scsi: NCR5380: Prepare for enabling lock context analysis
In reply to Bart Van AsscheExpand 'hostdata' in the lock context annotations because 'hostdata' is not a function argument.
--- drivers/scsi/NCR5380.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/NCR5380.c +2 -2
@@ -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 ;
Bart Van Assche
reviewerPATCH v2 8/56 scsi: aacraid: Prepare for enabling lock context analysis
In reply to Bart Van AsscheDocument the aac_send_reset_adapter() locking requirements with __must_hold(). Annotate functions that perform conditional locking with __no_context_analysis.
--- drivers/scsi/aacraid/Makefile | 2 ++ drivers/scsi/aacraid/commctrl.c | 1 + drivers/scsi/aacraid/commsup.c | 3 +++ 3 files changed, 6 insertions(+)
drivers/scsi/aacraid/Makefile +2 -0
@@ -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 \
drivers/scsi/aacraid/commctrl.c +1 -0
@@ -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;
drivers/scsi/aacraid/commsup.c +3 -0
@@ -475,6 +475,7 @@ int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_fib * hwint 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;
Bart Van Assche
reviewerPATCH v2 9/56 scsi: aic7xxx: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/aic7xxx/Makefile | 2 ++ drivers/scsi/aic7xxx/aicasm/Makefile | 3 +++ 2 files changed, 5 insertions(+)
drivers/scsi/aic7xxx/Makefile +2 -0
@@ -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
drivers/scsi/aic7xxx/aicasm/Makefile +3 -0
@@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 + +CONTEXT_ANALYSIS := y + PROG= aicasm OUTDIR ?= ./
Bart Van Assche
reviewerPATCH v2 10/56 scsi: aha152x: Prepare for enabling lock context analysis
In reply to Bart Van AsscheAnnotate is_complete() with __context_unsafe() because it performs conditional locking.
--- drivers/scsi/aha152x.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/aha152x.c +1 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 11/56 scsi: aic7xxx: Prepare for enabling lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __acquires() and __releases().
--- drivers/scsi/aic7xxx/aic79xx_osm.h | 2 ++ drivers/scsi/aic7xxx/aic7xxx_osm.h | 2 ++ 2 files changed, 4 insertions(+)
drivers/scsi/aic7xxx/aic79xx_osm.h +2 -0
@@ -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); }
drivers/scsi/aic7xxx/aic7xxx_osm.h +2 -0
@@ -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); }
Bart Van Assche
reviewerPATCH v2 12/56 scsi: aic94xx: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/aic94xx/Makefile | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/aic94xx/Makefile +2 -0
@@ -6,6 +6,8 @@ # Copyright (C) 2005 Luben Tuikov <[email protected]> # +CONTEXT_ANALYSIS := y + ccflags-$(CONFIG_AIC94XX_DEBUG) := -DASD_DEBUG -DASD_ENTER_EXIT obj-$(CONFIG_SCSI_AIC94XX) += aic94xx.o
Bart Van Assche
reviewerPATCH v2 13/56 scsi: arcmsr: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/arcmsr/Makefile | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/arcmsr/Makefile +2 -0
@@ -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
Bart Van Assche
reviewerPATCH v2 14/56 scsi: arm: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/arm/Makefile | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/arm/Makefile +2 -0
@@ -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
Bart Van Assche
reviewerPATCH v2 15/56 scsi: be2iscsi: Prepare for enabling lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold().
--- drivers/scsi/be2iscsi/be_main.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/scsi/be2iscsi/be_main.c +4 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 16/56 scsi: be2iscsi: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/be2iscsi/Makefile | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/be2iscsi/Makefile +2 -0
@@ -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
Bart Van Assche
reviewerPATCH v2 17/56 scsi: cxgbi: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/cxgbi/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/cxgbi/Makefile +3 -0
@@ -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/
Bart Van Assche
reviewerPATCH v2 18/56 scsi: bfa: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/bfa/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/bfa/Makefile +3 -0
@@ -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
Bart Van Assche
reviewerPATCH v2 19/56 scsi: bnx2fc: Enable lock context analysis
In reply to Bart Van AsscheDocument 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.
--- 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(-)
drivers/scsi/bnx2fc/Makefile +3 -0
@@ -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 \
drivers/scsi/bnx2fc/bnx2fc.h +3 -2
@@ -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);
drivers/scsi/bnx2fc/bnx2fc_els.c +2 -0
@@ -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;
drivers/scsi/bnx2fc/bnx2fc_hwi.c +3 -0
@@ -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;
drivers/scsi/bnx2fc/bnx2fc_io.c +5 -1
@@ -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.
Bart Van Assche
reviewerPATCH v2 20/56 scsi: bnx2i: Introduce a local variable
In reply to Bart Van AsschePrepare for adding a new statement that will use the new local variable 'conn'. No functionality has been changed.
--- drivers/scsi/bnx2i/bnx2i_hwi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/bnx2i/bnx2i_hwi.c +3 -3
@@ -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); }
Bart Van Assche
reviewerPATCH v2 21/56 scsi: bnx2i: Enable lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold(). Use __assume_ctx_lock() to inform the compiler about aliases for synchronization objects.
--- drivers/scsi/bnx2i/Makefile | 3 +++ drivers/scsi/bnx2i/bnx2i_hwi.c | 8 ++++++++ drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 + 3 files changed, 12 insertions(+)
drivers/scsi/bnx2i/Makefile +3 -0
@@ -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
drivers/scsi/bnx2i/bnx2i_hwi.c +8 -0
@@ -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;
drivers/scsi/bnx2i/bnx2i_iscsi.c +1 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 23/56 scsi: elx: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/elx/Makefile | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/elx/Makefile +1 -0
@@ -4,6 +4,7 @@ # * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. # */ +CONTEXT_ANALYSIS := y obj-$(CONFIG_SCSI_EFCT) := efct.o
Bart Van Assche
reviewerPATCH v2 24/56 scsi: esas2r: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/esas2r/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/esas2r/Makefile +3 -0
@@ -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 \
Bart Van Assche
reviewerPATCH v2 22/56 scsi: csiostor: Enable lock context analysis
In reply to Bart Van AsscheDocument lock context requirements with __must_hold().
--- 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(+)
drivers/scsi/csiostor/Makefile +2 -0
@@ -4,6 +4,8 @@ # ## +CONTEXT_ANALYSIS := y + ccflags-y += -I$(srctree)/drivers/net/ethernet/chelsio/cxgb4 obj-$(CONFIG_SCSI_CHELSIO_FCOE) += csiostor.o
drivers/scsi/csiostor/csio_hw.c +12 -0
@@ -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;
drivers/scsi/csiostor/csio_lnode.c +3 -0
@@ -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);
drivers/scsi/csiostor/csio_rnode.c +6 -0
@@ -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 ;
drivers/scsi/csiostor/csio_scsi.c +6 -0
@@ -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 );
Bart Van Assche
reviewerPATCH v2 25/56 scsi: fcoe: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/fcoe/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/fcoe/Makefile +3 -0
@@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only + +CONTEXT_ANALYSIS := y + obj-$(CONFIG_FCOE) += fcoe.o obj-$(CONFIG_LIBFCOE) += libfcoe.o
Bart Van Assche
reviewerPATCH v2 27/56 scsi: hisi_sas: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/hisi_sas/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/hisi_sas/Makefile +3 -0
@@ -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
Bart Van Assche
reviewerPATCH v2 28/56 scsi: hpsa: Prepare for enabling lock context analysis
In reply to Bart Van Asschemutex_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().
--- drivers/scsi/hpsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/hpsa.c +1 -1
@@ -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 ; }
Bart Van Assche
reviewerPATCH v2 29/56 scsi: ibmvscsi: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/ibmvscsi/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/ibmvscsi/Makefile +3 -0
@@ -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
Bart Van Assche
reviewerPATCH v2 30/56 scsi: ibmvscsi_tgt: Enable lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold().
--- drivers/scsi/ibmvscsi_tgt/Makefile | 3 +++ drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 7 +++++++ 2 files changed, 10 insertions(+)
drivers/scsi/ibmvscsi_tgt/Makefile +3 -0
@@ -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
drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c +7 -0
@@ -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 ;
Bart Van Assche
reviewerPATCH v2 26/56 scsi: fnic: Enable lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold(). Suppress complaints about conditional locking in fnic_device_reset() with __acquire() and __release().
--- 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(-)
drivers/scsi/fnic/Makefile +3 -0
@@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 + +CONTEXT_ANALYSIS := y + obj-$(CONFIG_FCOE_FNIC) += fnic.o fnic-y := \
drivers/scsi/fnic/fdls_disc.c +50 -2
320 lines not on this page · raw message
drivers/scsi/fnic/fip.c +2 -0
@@ -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;
drivers/scsi/fnic/fnic_fcs.c +6 -0
@@ -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) {
drivers/scsi/fnic/fnic_scsi.c +4 -0
@@ -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); }
Bart Van Assche
reviewerPATCH v2 31/56 scsi: ipr: Prepare for enabling lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold().
--- drivers/scsi/ipr.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/scsi/ipr.c +11 -0
@@ -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 ;
Bart Van Assche
reviewerPATCH v2 32/56 scsi: ips: Prepare for enabling lock context analysis
In reply to Bart Van AsscheAnnotate ips_next() with __no_context_analysis because it performs conditional locking.
--- drivers/scsi/ips.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/ips.c +1 -0
@@ -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 ;
Bart Van Assche
reviewerPATCH v2 33/56 scsi: isci: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/isci/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/isci/Makefile +3 -0
@@ -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 \
Bart Van Assche
reviewerPATCH v2 34/56 scsi: libfc: Enable lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold().
--- 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(-)
drivers/scsi/libfc/Makefile +2 -0
@@ -1,6 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 # $Id: Makefile +CONTEXT_ANALYSIS := y + obj-$(CONFIG_LIBFC) += libfc.o libfc-objs := \
drivers/scsi/libfc/fc_disc.c +5 -1
@@ -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;
drivers/scsi/libfc/fc_exch.c +6 -0
@@ -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));
drivers/scsi/libfc/fc_fcp.c +4 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 35/56 scsi: libiscsi: Prepare for enabling lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold().
--- drivers/scsi/libiscsi.c | 19 ++++++++++++++++++- include/scsi/libiscsi.h | 5 +++-- 2 files changed, 21 insertions(+), 3 deletions(-)
drivers/scsi/libiscsi.c +18 -1
@@ -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 ;
include/scsi/libiscsi.h +3 -2
@@ -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 );
Bart Van Assche
reviewerPATCH v2 36/56 scsi: libsas: Prepare for enabling lock context analysis
In reply to Bart Van AsscheSince Clang requires that lock context annotations only refer to variables that are visible, modify a __must_hold() annotation.
--- drivers/scsi/libsas/sas_ata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/libsas/sas_ata.c +1 -1
@@ -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;
Bart Van Assche
reviewerPATCH v2 37/56 scsi: libsas: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/libsas/Makefile | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/libsas/Makefile +2 -0
@@ -6,6 +6,8 @@ # Copyright (C) 2005 Luben Tuikov <[email protected]> # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_SCSI_SAS_LIBSAS) += libsas.o libsas-y += sas_init.o \ sas_phy.o \
Bart Van Assche
reviewerPATCH v2 38/56 scsi: lpfc: Prepare for enabling lock context analysis
In reply to Bart Van AsscheAnnotate the functions that perform conditional locking with __no_context_analysis.
--- 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(+)
drivers/scsi/lpfc/lpfc_els.c +2 -0
@@ -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);
drivers/scsi/lpfc/lpfc_nportdisc.c +1 -0
@@ -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);
drivers/scsi/lpfc/lpfc_scsi.c +1 -0
@@ -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));
drivers/scsi/lpfc/lpfc_sli.c +2 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 40/56 scsi: megaraid: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/megaraid/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/megaraid/Makefile +3 -0
@@ -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
Bart Van Assche
reviewerPATCH v2 39/56 scsi: megaraid_sas: Prepare for enabling lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold().
--- 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(-)
drivers/scsi/megaraid/megaraid_sas.h +6 -3
@@ -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);
drivers/scsi/megaraid/megaraid_sas_base.c +12 -3
@@ -132,14 +132,16 @@ MODULE_AUTHOR("[email protected]");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); u32megasas_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;
drivers/scsi/megaraid/megaraid_sas_fusion.c +2 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 41/56 scsi: mpt3sas: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/mpt3sas/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/mpt3sas/Makefile +3 -0
@@ -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 \
Bart Van Assche
reviewerPATCH v2 42/56 scsi: mvsas: Enable lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold(). Annotate functions that perform conditional locking with __no_context_analysis.
--- drivers/scsi/mvsas/Makefile | 2 ++ drivers/scsi/mvsas/mv_sas.c | 7 +++++++ 2 files changed, 9 insertions(+)
drivers/scsi/mvsas/Makefile +2 -0
@@ -7,6 +7,8 @@ # Copyright 2009-2011 Marvell. <[email protected]> # +CONTEXT_ANALYSIS := y + ccflags-$(CONFIG_SCSI_MVSAS_DEBUG) := -DMV_DEBUG obj-$(CONFIG_SCSI_MVSAS) += mvsas.o
drivers/scsi/mvsas/mv_sas.c +7 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 43/56 scsi: pcmcia: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/pcmcia/Makefile | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/pcmcia/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 +CONTEXT_ANALYSIS := y + ccflags-y := -I $(srctree)/drivers/scsi # 16-bit client drivers
Bart Van Assche
reviewerPATCH v2 44/56 scsi: pm8001: Enable lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold().
--- drivers/scsi/pm8001/Makefile | 1 + drivers/scsi/pm8001/pm80xx_hwi.c | 2 ++ 2 files changed, 3 insertions(+)
drivers/scsi/pm8001/Makefile +1 -0
@@ -4,6 +4,7 @@ # # Copyright (C) 2008-2009 USI Co., Ltd. +CONTEXT_ANALYSIS := y obj-$(CONFIG_SCSI_PM8001) += pm80xx.o
drivers/scsi/pm8001/pm80xx_hwi.c +2 -0
@@ -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 );
Bart Van Assche
reviewerPATCH v2 45/56 scsi: qedf: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/qedf/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/qedf/Makefile +3 -0
@@ -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
Bart Van Assche
reviewerPATCH v2 46/56 scsi: qedi: Enable lock context analysis
In reply to Bart Van AsscheAnnotate qedi_cleanup_all_io() with __no_context_analysis since it performs conditional locking.
--- drivers/scsi/qedi/Makefile | 3 +++ drivers/scsi/qedi/qedi_fw.c | 1 + 2 files changed, 4 insertions(+)
drivers/scsi/qedi/Makefile +3 -0
@@ -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
drivers/scsi/qedi/qedi_fw.c +1 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 47/56 scsi: qla1280: Prepare for enabling lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold().
--- drivers/scsi/qla1280.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/scsi/qla1280.c +18 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 48/56 scsi: qla2xxx: Enable lock context analysis
In reply to Bart Van AsscheMake 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.
--- 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(-)
drivers/scsi/qla2xxx/Makefile +3 -0
@@ -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 \
drivers/scsi/qla2xxx/qla_nx.c +2 -0
@@ -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 ;
drivers/scsi/qla2xxx/qla_target.c +18 -11
@@ -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 ; }
drivers/scsi/qla2xxx/qla_tmpl.c +1 -0
@@ -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 ;
Bart Van Assche
reviewerPATCH v2 49/56 scsi: qla4xxx: Enable lock context analysis
In reply to Bart Van AsscheAnnotate the functions that perform conditional locking with __no_context_analysis.
--- drivers/scsi/qla4xxx/Makefile | 3 +++ drivers/scsi/qla4xxx/ql4_nx.c | 2 ++ 2 files changed, 5 insertions(+)
drivers/scsi/qla4xxx/Makefile +3 -0
@@ -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
drivers/scsi/qla4xxx/ql4_nx.c +2 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 51/56 scsi: iSCSI transport: Prepare for enabling lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __must_hold().
--- drivers/scsi/scsi_transport_iscsi.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/scsi_transport_iscsi.c +1 -0
@@ -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);
Bart Van Assche
reviewerPATCH v2 50/56 scsi: ufs: Enable lock context analysis
In reply to Bart Van AsscheAnnotate functions that modify the state of a synchronization object. Remove the struct semaphore annotations because lock context annotations are not supported for semaphores.
--- 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(-)
drivers/ufs/core/Makefile +2 -0
@@ -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
drivers/ufs/core/ufs-debugfs.c +6 -2
@@ -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)
drivers/ufs/core/ufshcd.c +14 -0
@@ -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);
drivers/ufs/host/Makefile +2 -0
@@ -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
Bart Van Assche
reviewerPATCH v2 53/56 scsi: snic: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/snic/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/snic/Makefile +3 -0
@@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 + +CONTEXT_ANALYSIS := y + obj-$(CONFIG_SCSI_SNIC) += snic.o snic-y := \
Bart Van Assche
reviewerPATCH v2 54/56 scsi: sym53c8xx_2: Enable lock context analysis
In reply to Bart Van Assche--- drivers/scsi/sym53c8xx_2/Makefile | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/sym53c8xx_2/Makefile +2 -0
@@ -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
Bart Van Assche
reviewerPATCH v2 52/56 scsi: smartpqi: Enable lock context analysis
In reply to Bart Van AsscheDocument locking requirements with __acquires(), __releases() and __must_hold(). Annotate functions that perform conditional locking with __no_context_analysis.
--- drivers/scsi/smartpqi/Makefile | 3 +++ drivers/scsi/smartpqi/smartpqi_init.c | 33 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
drivers/scsi/smartpqi/Makefile +3 -0
@@ -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
drivers/scsi/smartpqi/smartpqi_init.c +33 -0
@@ -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;
Bart Van Assche
reviewerPATCH v2 55/56 scsi: core: Enable lock context analysis
In reply to Bart Van AsscheDocument 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.
--- 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(+)
drivers/scsi/Makefile +1 -0
@@ -14,6 +14,7 @@ # satisfy certain initialization assumptions in the SCSI layer. # *!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*! +CONTEXT_ANALYSIS := y CFLAGS_aha152x.o = -DAHA152X_STAT -DAUTOCONF
drivers/scsi/device_handler/Makefile +3 -0
@@ -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
drivers/scsi/scsi_scan.c +12 -0
@@ -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) {/*
include/scsi/scsi_host.h +2 -0
@@ -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; \
Bart Van Assche
reviewerPATCH v2 56/56 scsi: core: Protect host state changes with the host lock
In reply to Bart Van AsscheSome 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.
--- 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(-)
drivers/scsi/hosts.c +8 -5
@@ -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;
drivers/scsi/megaraid/megaraid_sas_base.c +1 -1
@@ -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));/*
drivers/scsi/mpt3sas/mpt3sas_scsih.c +1 -1
@@ -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);
drivers/scsi/qla4xxx/ql4_os.c +2 -4
@@ -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 ; }/**
drivers/scsi/scsi_lib.c +1 -2
@@ -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);
drivers/scsi/scsi_sysfs.c +4 -3
@@ -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 ;
include/scsi/scsi_host.h +16 -7
@@ -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 */
Re: [PATCH v2 01/56] PCI: Convert to_pci_dev() into an inline function
In reply to Bart Van AsscheQuoted 10 lines · Bart Van Assche
Clang's context analysis checker performs alias analysis on expressions passed to annotations like
__acquires(). Clang's alias analysis does not supportcontainer_of(). Convertto_pci_dev()from a macro into an inline function such that Clang recognizes multipleto_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.
Quoted 6 lines
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 <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Quoted 20 lines
--- include/linux/pci.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)include/linux/pci.h +4
-1@@ -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)
Re: [PATCH v2 06/56] scsi: BusLogic: Prepare for enabling lock context analysis
In reply to Bart Van AsscheQuoted 20 lines · Bart Van Assche
Document locking requirements with
__must_hold().Signed-off-by Bart Van Assche <[email protected]>--- drivers/scsi/BusLogic.c | 2 ++ 1 file changed, 2 insertions(+)drivers/scsi/BusLogic.c +1
-0@@ -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 =
drivers/scsi/BusLogic.c static int blogic_abort(struct scsi_cmnd *command) · line 3190
Quoted 7 lines
drivers/scsi/BusLogic.c +1
-0@@ -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;
Re: [PATCH v2 05/56] scsi: BusLogic: Introduce a local variable
In reply to Bart Van AsscheQuoted 35 lines · Bart Van Assche
Introduce a new local variable to prepare for enabling thread-safety analysis. No functionality has been changed.
Signed-off-by Bart Van Assche <[email protected]>--- drivers/scsi/BusLogic.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)drivers/scsi/BusLogic.c +3
-2@@ -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. */
drivers/scsi/BusLogic.c static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command) · line 3072
Quoted 10 lines
drivers/scsi/BusLogic.c +2
-2if (!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);
Re: [PATCH v2 53/56] scsi: snic: Enable lock context analysis
In reply to Bart Van Assche________________________________________
From: Bart Van Assche <[email protected]>
Sent: 30 April 2026 11:20 AM
To: Martin K . Petersen <[email protected]>
Cc: [email protected] <[email protected]>; Marco Elver <[email protected]>; Bart Van Assche <[email protected]>; Karan Tilak Kumar (kartilak) <[email protected]>; Narsimhulu Musini (nmusini) <[email protected]>; Sesidhar Baddela (sebaddel) <[email protected]>; James E.J. Bottomley <[email protected]> Subject: [PATCH v2 53/56] scsi: snic: Enable lock context analysis
---
drivers/scsi/snic/Makefile | 3 +++
1 file changed, 3 insertions(+)
drivers/scsi/snic/Makefile +0 -0
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+
+CONTEXT_ANALYSIS := y
+
obj-$(CONFIG_SCSI_SNIC) += snic.o
snic-y := \
RE: [PATCH v2 26/56] scsi: fnic: Enable lock context analysis
In reply to Bart Van AsscheQuoted 466 lines · Bart Van Assche
Document locking requirements with
__must_hold(). Suppress complaints about conditional locking infnic_device_reset()with__acquire()and__release().Signed-off-by Bart Van Assche <[email protected]>--- 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(-)drivers/scsi/fnic/Makefile +3
-0@@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 + +CONTEXT_ANALYSIS := y + obj-$(CONFIG_FCOE_FNIC) += fnic.o fnic-y := \drivers/scsi/fnic/fdls_disc.c +50
-2@@ -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;drivers/scsi/fnic/fip.c +2
-0@@ -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;drivers/scsi/fnic/fnic_fcs.c +6
-0@@ -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) {drivers/scsi/fnic/fnic_scsi.c +2
-0@@ -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 {
drivers/scsi/fnic/fnic_scsi.c int fnic_device_reset(struct scsi_cmnd *sc) · line 2812
Quoted 8 lines
drivers/scsi/fnic/fnic_scsi.c +2
-0@@ -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); }
Regards,
Karan