Re: RFC: Petition Intel/AMD to add POPF_IF insn

From: Andy Lutomirski
Date: Wed Aug 17 2016 - 17:43:54 EST


On Wed, Aug 17, 2016 at 2:35 PM, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Wed, Aug 17, 2016 at 2:26 PM, Linus Torvalds
> <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>>
>> Of course, if somebody uses native_restore_fl() to actually *disable*
>> interrupts (when they weren't already disabled), then this untested
>> patch will just not work. But why would you do somethign so stupid?
>> Famous last words...
>
> Looking around, the vsmp code actually uses "native_restore_fl()" to
> not just set the interrupt flag, but AC as well.
>
> And the PV spinlock case has that "push;popf" sequence encoded in an alternate.
>
> So that trivial patch may (or may not - still not tested) work for
> some quick testing, but needs more effort for any *real* use.
>

It shouldn't be *too* bad, since xen_restore_fl only affects "IF".
And even if native_restore_fl needs to be able to turn IRQs off as
well as on, we can just do:

if (likely(flags & X86_EFLAGS_IF))
sti();
else
cli();

at some cost to code size but hopefully little to no runtime cost for
the sane cases.