Re: [tip:x86/pti] x86/speculation: Use IBRS if available before calling into firmware
From: Tim Chen
Date: Wed Feb 14 2018 - 14:20:55 EST
On 02/14/2018 12:56 AM, Peter Zijlstra wrote:
>
> At the very least this must disable and re-enable preemption, such that
> we guarantee we inc/dec the same counter. ISTR some firmware calls (EFI)
> actually are preemptible so that wouldn't work.
>
> Further, consider:
>
> this_cpu_inc_return() // 0->1
> <NMI>
> this_cpu_inc_return() // 1->2
> call_broken_arse_firmware()
> this_cpu_dec_return() // 2->1
> </NMI>
> wrmsr(SPEC_CTRL, IBRS);
>
> /* from dodgy firmware crap */
>
> this_cpu_dec_return() // 1->0
> wrmsr(SPEC_CTRL, 0);
>
How about the following patch.
Thanks.
Tim
---