[PATCH] arm64: spectre: Avoid locking on v4 mitigation enable path
Lorenzo Pieralisi
lorenzo.pieralisi at arm.com
Thu Feb 18 06:04:09 EST 2021
On Thu, Feb 18, 2021 at 09:10:43AM +0000, Will Deacon wrote:
[...]
> > > -static enum mitigation_state spectre_v4_enable_hw_mitigation(void)
> > > +static void spectre_v4_register_undef_hook(void)
> > > {
> > > static bool undef_hook_registered = false;
> > > static DEFINE_RAW_SPINLOCK(hook_lock);
> > > +
> > > + if (READ_ONCE(undef_hook_registered))
> > > + return;
> > > +
> > > + raw_spin_lock(&hook_lock);
> > > + if (!undef_hook_registered) {
> > > + register_undef_hook(&ssbs_emulation_hook);
> > > + smp_store_release(&undef_hook_registered, true);
> > > + }
> > > + raw_spin_unlock(&hook_lock);
> > > +}
> >
> > I have a question: is there ever a use case when we have to call this
> > function from suspend exit where undef_hook_registered can be == false ?
> >
> > I don't get why a resuming CPU would have to register a hook if on
> > suspend the hook was not registered already but I think that's because I
> > don't know well enough how spectre v4 mitigations are handled, so I am
> > asking.
>
> No, on the resume path we don't need to register the hook and with this
> patch we avoid it entirely. However, having a completely different
> mitigation path for resume is also quite horrible, especially given how
> complicated the control flow is for the mitigation logic already. At least,
> I couldn't figure out how to structure it without passing in an extra
> parameter to say we were resuming.
Agreed - that's what I was alluding to but it is not prettier.
> However, Paul McKenney suggested using RCU_NONIDLE() as an alternative
> solution, so I'll spin a v2 with that.
Thanks,
Lorenzo
More information about the linux-arm-kernel
mailing list