From: "Fang Hongjie(方洪杰)" <hongjiefang@asrmicro.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: "James.Bottomley@hansenpartnership.com"
<James.Bottomley@hansenpartnership.com>,
"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
"jgarzik@redhat.com" <jgarzik@redhat.com>,
"bvanassche@acm.org" <bvanassche@acm.org>,
"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v2] scsi: core: pair EH runtime PM get and put
Date: Tue, 28 Jul 2026 02:22:29 +0000 [thread overview]
Message-ID: <f66bc8e5bf88459083e36fa508a7f4f7@exch02.asrmicro.com> (raw)
In-Reply-To: <a432da46-7b3e-46a8-8c6d-1269d51b44b8@rowland.harvard.edu>
> > diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
> > index 147127fb4db9..a216f56044d9 100644
> > --- a/drivers/scsi/scsi_error.c
> > +++ b/drivers/scsi/scsi_error.c
> > @@ -2342,6 +2342,7 @@ static void scsi_unjam_host(struct Scsi_Host
> *shost)
> > int scsi_error_handler(void *data)
> > {
> > struct Scsi_Host *shost = data;
> > + bool eh_noresume;
> >
> > /*
> > * We use TASK_INTERRUPTIBLE so that the thread is not
> > @@ -2383,7 +2384,8 @@ int scsi_error_handler(void *data)
> > * what we need to do to get it up and online again (if we
> can).
> > * If we fail, we end up taking the thing offline.
> > */
> > - if (!shost->eh_noresume &&
> scsi_autopm_get_host(shost) != 0) {
> > + eh_noresume = shost->eh_noresume;
>
> You should be aware that simply reading a variable does not snapshot its
> value unless the read is protected by a lock or something else. In this
> case, the compiler is allowed to eliminate the eh_noresume variable and
> use shost->eh_noresume instead, both here and below, under the
> assumption that shost->eh_noresume doesn't change in the meantime.
>
> To truly snapshot the the value in a way that's immune to changes from
> other threads, you have to use READ_ONCE():
>
> eh_noresume = READ_ONCE(shost->eh_noresume);
>
> The compiler is then not allowed to assume that shost->eh_noresume
> remains unchanged later on. This is all explained (along with a _lot_
> of other material -- search for "READ_ONCE") in
> Documentation/memory-barriers.txt.
>
Thanks Alan.
I agree that a plain local variable is not enough for a compiler-level
snapshot.
There is one extra detail here: shost->eh_noresume is currently a
bitfield:
unsigned eh_noresume:1;
so READ_ONCE(shost->eh_noresume) cannot be used directly because
READ_ONCE() takes the address of its argument.
My plan for v3 is to first make eh_noresume a regular bool, then use
READ_ONCE() in scsi_error_handler() to snapshot it once per EH iteration.
I will also use WRITE_ONCE() for the writer that changes eh_noresume while
SCSI EH may observe it.
Does this approach look reasonable to you?
Best.
next prev parent reply other threads:[~2026-07-28 2:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 5:56 Hongjie Fang
2026-07-27 14:11 ` Alan Stern
2026-07-28 2:22 ` Fang Hongjie(方洪杰) [this message]
2026-07-28 15:16 ` Alan Stern
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=f66bc8e5bf88459083e36fa508a7f4f7@exch02.asrmicro.com \
--to=hongjiefang@asrmicro.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=bvanassche@acm.org \
--cc=jgarzik@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=stern@rowland.harvard.edu \
/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
all inboxes | Powered by JetHome®