Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bart Van Assche" <bvanassche@acm.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 57/57] scsi: core: Protect host state changes with the host lock
Date: Thu, 30 Jul 2026 23:32:59 +0000	[thread overview]
Message-ID: <20260730233259.929B01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <36a92f43e2f8132f517248b98de4ba26a670f249.1785451174.git.bvanassche@acm.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] The patch missed converting a direct read of `shost_state` in the `mpi3mr` driver to the new `scsi_get_host_state()` API.
- [Medium] Double initialization of `host_lock` via the `spinlock_init` guard overwrites the correct lockdep class name.
- [Medium] `scsi_host_set_state()` performs a plain write to `shost_state`, which races with the newly introduced `READ_ONCE()` lockless readers.
--

--- Patch [57]: [PATCH v3 57/57] scsi: core: Protect host state changes with the host lock ---
commit b02669cdb0e82751599147d300ebcdc8db8d8734
Author: Bart Van Assche <bvanassche@acm.org>

scsi: core: Protect host state changes with the host lock

Some but not all SCSI host state changes are protected with the SCSI
host lock. Annotate the SCSI host state with __guarded_by(host_lock),
protect all SCSI host state changes with the SCSI host lock and use
READ_ONCE() for all SCSI host state reads. This patch prevents that
KCSAN complains about data races when accessing the SCSI host state.

Reported-by: Jianzhou Zhao <luckd0g@163.com>
Closes: https://lore.kernel.org/all/36d59d0e.6db0.19cdbeee01b.Coremail.luckd0g@163.com/
Signed-off-by: Bart Van Assche <bvanassche@acm.org>

> diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
> index 08ec144f7bf77..222baa7e10680 100644
> --- a/drivers/scsi/hosts.c
> +++ b/drivers/scsi/hosts.c
[ ... ]
> @@ -413,7 +415,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;

[Severity: Medium]
Will this double-initialize the host_lock and overwrite the lockdep class name?

The previous line explicitly calls spin_lock_init(shost->host_lock) which
assigns the correct static lockdep key. Using scoped_guard(spinlock_init, ...)
immediately after calls the initialization macro again internally, overwriting
the lockdep class with a generic macro variable name (_T->lock).

[ ... ]
> diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
> index c5f85af4ba072..d0eefefdc0be8 100644
> --- a/include/scsi/scsi_host.h
> +++ b/include/scsi/scsi_host.h
[ ... ]
> @@ -790,11 +790,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));
> +}
> +

[Severity: Medium]
Does the plain write in scsi_host_set_state() need to be updated to
WRITE_ONCE() to match this new READ_ONCE()?

Since scsi_host_set_state() performs a plain write to shost->shost_state,
concurrent lockless READ_ONCE() readers could still cause KCSAN to flag data
races due to compiler tearing on the writer side. The LKMM requires
WRITE_ONCE() on the writer side when there are concurrent lockless
READ_ONCE() readers.

[ ... ]
> @@ -945,6 +953,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 */

[Severity: Medium]
Was the mpi3mr driver missed during the tree-wide conversion to the new
scsi_get_host_state() API?

It looks like mpi3mr_qcmd() in drivers/scsi/mpi3mr/mpi3mr_os.c still checks
scmd->device->host->shost_state == SHOST_RECOVERY directly without using
scsi_get_host_state() or holding the host_lock.

Will this trigger a new Sparse warning due to the newly added
__guarded_by(host_lock) annotation on shost_state?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1785451174.git.bvanassche@acm.org?part=57

      reply	other threads:[~2026-07-30 23:32 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 22:44 [PATCH v3 00/57] Enable lock context analysis for the SCSI subsystem Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 01/57] PCI: Convert to_pci_dev() into an inline function Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 02/57] scsi: scsi_debug: Prepare for enabling lock context analysis Bart Van Assche
2026-07-30 23:01   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 03/57] scsi: sg: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 04/57] scsi: st: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 05/57] scsi: BusLogic: Introduce two local variables Bart Van Assche
2026-07-30 23:01   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 06/57] scsi: BusLogic: Prepare for enabling lock context analysis Bart Van Assche
2026-07-30 23:06   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 07/57] scsi: NCR5380: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 08/57] scsi: aacraid: " Bart Van Assche
2026-07-30 23:04   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 09/57] scsi: aic7xxx: Enable " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 10/57] scsi: aha152x: Prepare for enabling " Bart Van Assche
2026-07-30 23:18   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 11/57] scsi: aic7xxx: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 12/57] scsi: aic94xx: Enable " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 13/57] scsi: arcmsr: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 14/57] scsi: arm: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 15/57] scsi: be2iscsi: Prepare for enabling " Bart Van Assche
2026-07-30 23:04   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 16/57] scsi: be2iscsi: Enable " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 17/57] scsi: cxgbi: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 18/57] scsi: bfa: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 19/57] scsi: bnx2fc: " Bart Van Assche
2026-07-30 23:01   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 20/57] scsi: bnx2i: Introduce a local variable Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 21/57] scsi: bnx2i: Enable lock context analysis Bart Van Assche
2026-07-30 23:29   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 22/57] scsi: csiostor: " Bart Van Assche
2026-07-30 23:19   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 23/57] scsi: elx: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 24/57] scsi: esas2r: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 25/57] scsi: fcoe: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 26/57] scsi: fnic: " Bart Van Assche
2026-07-30 23:11   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 27/57] scsi: hisi_sas: " Bart Van Assche
2026-07-30 23:02   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 28/57] scsi: hpsa: Prepare for enabling " Bart Van Assche
2026-07-30 23:27   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 29/57] scsi: ibmvscsi: Enable " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 30/57] scsi: ibmvscsi_tgt: " Bart Van Assche
2026-07-30 23:27   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 31/57] scsi: ipr: Prepare for enabling " Bart Van Assche
2026-07-30 23:15   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 32/57] scsi: ips: " Bart Van Assche
2026-07-30 23:15   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 33/57] scsi: isci: Enable " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 34/57] scsi: libfc: " Bart Van Assche
2026-07-30 23:19   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 35/57] scsi: libiscsi: Prepare for enabling " Bart Van Assche
2026-07-30 23:17   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 36/57] scsi: libsas: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 37/57] scsi: libsas: Enable " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 38/57] scsi: lpfc: Prepare for enabling " Bart Van Assche
2026-07-30 23:09   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 39/57] scsi: megaraid_sas: " Bart Van Assche
2026-07-30 23:15   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 40/57] scsi: megaraid: Enable " Bart Van Assche
2026-07-30 23:15   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 41/57] scsi: mpt3sas: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 42/57] scsi: mvsas: " Bart Van Assche
2026-07-30 23:18   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 43/57] scsi: pcmcia: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 44/57] scsi: pm8001: " Bart Van Assche
2026-07-30 23:31   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 45/57] scsi: qedf: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 46/57] scsi: qedi: " Bart Van Assche
2026-07-30 23:17   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 47/57] scsi: qla1280: Prepare for enabling " Bart Van Assche
2026-07-30 23:19   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 48/57] scsi: qla2xxx: Enable " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 49/57] scsi: qla4xxx: " Bart Van Assche
2026-07-30 23:25   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 50/57] scsi: ufs: " Bart Van Assche
2026-07-30 23:19   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 51/57] scsi: iSCSI transport: Prepare for enabling " Bart Van Assche
2026-07-30 23:23   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 52/57] scsi: smartpqi: Enable " Bart Van Assche
2026-07-30 23:22   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 53/57] scsi: snic: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 54/57] scsi: sym53c8xx_2: " Bart Van Assche
2026-07-30 23:27   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 55/57] scsi: core: Pass the SCSI host pointer directly Bart Van Assche
2026-07-30 23:22   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 56/57] scsi: core: Enable lock context analysis Bart Van Assche
2026-07-30 23:36   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 57/57] scsi: core: Protect host state changes with the host lock Bart Van Assche
2026-07-30 23:32   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260730233259.929B01F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox