[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180214085614.GT25181@hirez.programming.kicks-ass.net>
Date: Wed, 14 Feb 2018 09:56:14 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Tim Chen <tim.c.chen@...ux.intel.com>
Cc: Ingo Molnar <mingo@...nel.org>, Dave Hansen <dave@...1.net>,
hpa@...or.com, tglx@...utronix.de, torvalds@...ux-foundation.org,
linux-kernel@...r.kernel.org, dwmw@...zon.co.uk,
linux-tip-commits@...r.kernel.org, Borislav Petkov <bp@...en8.de>,
Arjan van de Ven <arjan@...radead.org>
Subject: Re: [tip:x86/pti] x86/speculation: Use IBRS if available before
calling into firmware
On Tue, Feb 13, 2018 at 05:49:47PM -0800, Tim Chen wrote:
> static inline void firmware_restrict_branch_speculation_start(void)
> {
> + if (this_cpu_inc_return(spec_ctrl_ibrs_fw_depth) == 1)
> + alternative_msr_write(MSR_IA32_SPEC_CTRL, SPEC_CTRL_IBRS,
> X86_FEATURE_USE_IBRS_FW);
> }
>
> static inline void firmware_restrict_branch_speculation_end(void)
> {
> + if (this_cpu_dec_return(spec_ctrl_ibrs_fw_depth) == 0)
> + alternative_msr_write(MSR_IA32_SPEC_CTRL, 0,
> + X86_FEATURE_USE_IBRS_FW);
> }
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);
Powered by blists - more mailing lists