x86/cpu: Fix migration safety with X86_BUG_NULL_SEL
PATCH 1/1 x86/cpu: Fix migration safety with X86_BUG_NULL_SEL
commit 415de44076640483648d6c0f6d645a9ee61328ad upstream.
Currently, Linux probes for X86_BUG_NULL_SEL unconditionally which makes it unsafe to migrate in a virtualised environment as the properties across the migration pool might differ.
To be specific, the case which goes wrong is:
1. Zen1 (or earlier) and Zen2 (or later) in a migration pool
2. Linux boots on Zen2, probes and finds the absence of X86_BUG_NULL_SEL
3. Linux is then migrated to Zen1
Linux is now running on a X86_BUG_NULL_SEL-impacted CPU while believing that the bug is fixed.
The only way to address the problem is to fully trust the "no longer affected" CPUID bit when virtualised, because in the above case it would be clear deliberately to indicate the fact "you might migrate to somewhere which has this behaviour".
Zen3 adds the NullSelectorClearsBase CPUID bit to indicate that loading a NULL segment selector zeroes the base and limit fields, as well as just attributes. Zen2 also has this behaviour but doesn't have the NSCB bit.
[ bp: Minor touchups. ]
---
Backport to 4.19. Drop Hygon modifications.
--- arch/x86/kernel/cpu/amd.c | 2 ++ arch/x86/kernel/cpu/common.c | 44 +++++++++++++++++++++++++++++++++++++------- arch/x86/kernel/cpu/cpu.h | 1 + 3 files changed, 40 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/amd.c +2 -0
@@ -993,6 +993,8 @@ static void init_amd(struct cpuinfo_x86 *c)if (cpu_has (c,X86_FEATURE_IRPERF ) && !cpu_has_amd_erratum (c, amd_erratum_1054))msr_set_bit (MSR_K7_HWCR ,MSR_K7_HWCR_IRPERF_EN_BIT ); + +check_null_seg_clears_base (c); }#ifdef CONFIG_X86_32
arch/x86/kernel/cpu/common.c +37 -7
64 lines not on this page · raw message
arch/x86/kernel/cpu/cpu.h +1 -0
@@ -76,6 +76,7 @@ extern int detect_extended_topology_early(struct cpuinfo_x86 *c);extern int detect_extended_topology (struct cpuinfo_x86 *c);extern int detect_ht_early (struct cpuinfo_x86 *c);extern void detect_ht (struct cpuinfo_x86 *c); +extern void check_null_seg_clears_base (struct cpuinfo_x86 *c);unsigned int aperfmperf_get_khz (int cpu);
Signature · 1 line
2.11.0
Quoted 25 lines · Jane Malalane
commit
415de44076640483648d6c0f6d645a9ee61328adupstream.Currently, Linux probes for
X86_BUG_NULL_SELunconditionally which makes it unsafe to migrate in a virtualised environment as the properties across the migration pool might differ.To be specific, the case which goes wrong is:
1. Zen1 (or earlier) and Zen2 (or later) in a migration pool
2. Linux boots on Zen2, probes and finds the absence ofX86_BUG_NULL_SEL
3. Linux is then migrated to Zen1Linux is now running on a X86_BUG_NULL_SEL-impacted CPU while believing that the bug is fixed.
The only way to address the problem is to fully trust the "no longer affected" CPUID bit when virtualised, because in the above case it would be clear deliberately to indicate the fact "you might migrate to somewhere which has this behaviour".
Zen3 adds the NullSelectorClearsBase CPUID bit to indicate that loading a NULL segment selector zeroes the base and limit fields, as well as just attributes. Zen2 also has this behaviour but doesn't have the NSCB bit.
Quoted 8 lines
[ bp: Minor touchups. ]
Signed-off-by Jane Malalane <[email protected]>Signed-off-by Borislav Petkov <[email protected]>CC <[email protected]>---
Backport to 4.19. Drop Hygon modifications.
Now queued up, thanks.
greg k-h