Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: John Garry <john.g.garry@oracle.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: Marco Elver <elver@google.com>,
	linux-scsi@vger.kernel.org, Jianzhou Zhao <luckd0g@163.com>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	Kashyap Desai <kashyap.desai@broadcom.com>,
	Sumit Saxena <sumit.saxena@broadcom.com>,
	Shivasharan S <shivasharan.srikanteshwara@broadcom.com>,
	Chandrakanth patil <chandrakanth.patil@broadcom.com>,
	Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>,
	Sreekanth Reddy <sreekanth.reddy@broadcom.com>,
	Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>,
	Ranjan Kumar <ranjan.kumar@broadcom.com>,
	Nilesh Javali <njavali@marvell.com>,
	Manish Rangankar <mrangankar@marvell.com>,
	GR-QLogic-Storage-Upstream@marvell.com
Subject: Re: [PATCH v5 5/6] scsi: core: Protect host state changes with the host lock
Date: Thu, 6 Aug 2026 10:19:07 -0700	[thread overview]
Message-ID: <b861a237-eb60-45a9-b932-1bdaa29abc46@acm.org> (raw)
In-Reply-To: <6d4a31c0-308d-4f4e-9708-11a559137ee3@oracle.com>

On 8/6/26 2:13 AM, John Garry wrote:
> On 05/08/2026 22:36, Bart Van Assche wrote:
>> @@ -785,11 +785,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));
> 
> I am wondering if it may be better to protect reading this with the 
> spinlock as well. We could lose the READ_ONCE and WRITE_ONCE. And we 
> would be more symmetrical with the set function.
> 
> I really don't feel strongly about this, though.

I slightly prefer READ_ONCE() because READ_ONCE() makes it clear that a
race condition is triggered. Protecting the host state read with a
spinlock is misleading in my opinion because it suppresses data race
reports while the host state can change as soon as the spinlock has
been unlocked.

>> +int scsi_host_set_state(struct Scsi_Host *shost, enum scsi_host_state 
>> state)
>> +    __must_hold(shost->host_lock);
> 
> How come we have this in the prototype and not the actual function itself?

Adding __must_hold() to the function declaration is sufficient. Adding
__must_hold() to the function definition is optional if it has already 
been added to the function definition.

Thanks,

Bart.

  reply	other threads:[~2026-08-06 17:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 21:36 [PATCH v5 0/6] Enable lock context analysis in the SCSI core and UFS driver Bart Van Assche
2026-08-05 21:36 ` [PATCH v5 1/6] ufs: core: Set task state before io_schedule_timeout() Bart Van Assche
2026-08-05 21:36 ` [PATCH v5 2/6] ufs: core: Enable lock context analysis Bart Van Assche
2026-08-05 21:36 ` [PATCH v5 3/6] scsi: core: Pass the SCSI host pointer directly to scanning functions Bart Van Assche
2026-08-06  9:02   ` John Garry
2026-08-05 21:36 ` [PATCH v5 4/6] scsi: core: Add lock context annotations Bart Van Assche
2026-08-05 22:00   ` sashiko-bot
2026-08-06  9:03   ` John Garry
2026-08-05 21:36 ` [PATCH v5 5/6] scsi: core: Protect host state changes with the host lock Bart Van Assche
2026-08-06  9:13   ` John Garry
2026-08-06 17:19     ` Bart Van Assche [this message]
2026-08-07  8:21       ` John Garry
2026-08-07 22:26     ` Bart Van Assche
2026-08-05 21:36 ` [PATCH v5 6/6] scsi: core: Enable lock context analysis Bart Van Assche
2026-08-06  9:16   ` John Garry
2026-08-06 16:58     ` Bart Van Assche
2026-08-06  9:26 ` [PATCH v5 0/6] Enable lock context analysis in the SCSI core and UFS driver John Garry

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=b861a237-eb60-45a9-b932-1bdaa29abc46@acm.org \
    --to=bvanassche@acm.org \
    --cc=GR-QLogic-Storage-Upstream@marvell.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=chandrakanth.patil@broadcom.com \
    --cc=elver@google.com \
    --cc=john.g.garry@oracle.com \
    --cc=kashyap.desai@broadcom.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=luckd0g@163.com \
    --cc=martin.petersen@oracle.com \
    --cc=mrangankar@marvell.com \
    --cc=njavali@marvell.com \
    --cc=ranjan.kumar@broadcom.com \
    --cc=sathya.prakash@broadcom.com \
    --cc=shivasharan.srikanteshwara@broadcom.com \
    --cc=sreekanth.reddy@broadcom.com \
    --cc=suganath-prabu.subramani@broadcom.com \
    --cc=sumit.saxena@broadcom.com \
    /path/to/YOUR_REPLY

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

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