Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/alternatives, x86/fpu: Add 'alternatives_patched' debug flag and use it in xsave_state()

We'd like to use xsave_state() earlier, but its SYSTEM_BOOTING check
is too imprecise.

The real condition that xsave_state() would like to check is whether
alternative XSAVE instructions were patched into the kernel image
already.

Add such a (read-mostly) debug flag and use it in xsave_state().

Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>

+12 -1
+6
arch/x86/include/asm/alternative.h
··· 52 52 u8 padlen; /* length of build-time padding */ 53 53 } __packed; 54 54 55 + /* 56 + * Debug flag that can be tested to see whether alternative 57 + * instructions were patched in already: 58 + */ 59 + extern int alternatives_patched; 60 + 55 61 extern void alternative_instructions(void); 56 62 extern void apply_alternatives(struct alt_instr *start, struct alt_instr *end); 57 63
+1 -1
arch/x86/include/asm/fpu/xstate.h
··· 119 119 u32 hmask = mask >> 32; 120 120 int err = 0; 121 121 122 - WARN_ON(system_state == SYSTEM_BOOTING); 122 + WARN_ON(!alternatives_patched); 123 123 124 124 /* 125 125 * If xsaves is enabled, xsaves replaces xsaveopt because
+5
arch/x86/kernel/alternative.c
··· 21 21 #include <asm/io.h> 22 22 #include <asm/fixmap.h> 23 23 24 + int __read_mostly alternatives_patched; 25 + 26 + EXPORT_SYMBOL_GPL(alternatives_patched); 27 + 24 28 #define MAX_PATCH_LEN (255-1) 25 29 26 30 static int __initdata_or_module debug_alternative; ··· 631 627 apply_paravirt(__parainstructions, __parainstructions_end); 632 628 633 629 restart_nmi(); 630 + alternatives_patched = 1; 634 631 } 635 632 636 633 /**