Re: [PATCH v4 5/6] scsi: core: Protect host state changes with the host lock
Bart Van Assche <[email protected]> Mon, 3 Aug 2026 10:11:17 -0700
| Newsgroups | org.kernel.vger.linux-scsi |
|---|---|
| Message-ID | <[email protected]> |
On 8/3/26 10:01 AM, John Garry wrote:
> On 31/07/2026 22:52, Bart Van Assche wrote:
>> @@ -411,8 +413,8 @@ struct Scsi_Host *scsi_host_alloc(const struct=20
>> scsi_host_template *sht, int priv
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return NULL;
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 shost->host_lock =3D &shost->default_lo=
ck;
>> -=C2=A0=C2=A0=C2=A0 spin_lock_init(shost->host_lock);
>> -=C2=A0=C2=A0=C2=A0 shost->shost_state =3D SHOST_CREATED;
>> +=C2=A0=C2=A0=C2=A0 scoped_guard(spinlock_init, shost->host_lock)
>=20
> Please forgive my ignorance, but what does spinlock_init do here in=20
> relation to setting shost->shost_state?
>=20
> Elsewhere we have scoped_guard(spinlock_irq, shost->host_lock) for=20
> protecting setting shost->shost_state and this makes sense to me.=20
> However I am curious what scoped_guard(spinlock_init, ...) does.
Support for scoped_guard(*_init, ...) and guard(*_init)(...) was
introduced in January of this year. My understanding of commit
d084a73714f8 ("compiler-context-analysis: Introduce scoped init guards")
is as follows:
* The referenced synchronization object is initialized. In this case
that means calling spinlock_init(shost->host_lock).
* Compiler warnings triggered by __guarded_by() are suppressed for the
referenced synchronization object. In this case, the compiler is told
not to assume that shost->host_lock is acquired at the start of the
guarded code block and released at the end of the guarded code block.
Marco, please correct me if I got this wrong.
Thanks,
Bart.