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

s390: correct nospec auto detection init order

With CONFIG_EXPOLINE_AUTO=y the call of spectre_v2_auto_early() via
early_initcall is done *after* the early_param functions. This
overwrites any settings done with the nobp/no_spectre_v2/spectre_v2
parameters. The code patching for the kernel is done after the
evaluation of the early parameters but before the early_initcall
is done. The end result is a kernel image that is patched correctly
but the kernel modules are not.

Make sure that the nospec auto detection function is called before the
early parameters are evaluated and before the code patching is done.

Fixes: 6e179d64126b ("s390: add automatic detection of the spectre defense")
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

+6 -6
+1
arch/s390/include/asm/nospec-branch.h
··· 9 9 extern int nospec_disable; 10 10 11 11 void nospec_init_branches(void); 12 + void nospec_auto_detect(void); 12 13 void nospec_revert(s32 *start, s32 *end); 13 14 14 15 #endif /* __ASSEMBLY__ */
+2 -6
arch/s390/kernel/nospec-branch.c
··· 72 72 } 73 73 early_param("nospectre_v2", nospectre_v2_setup_early); 74 74 75 - static int __init spectre_v2_auto_early(void) 75 + void __init nospec_auto_detect(void) 76 76 { 77 77 if (IS_ENABLED(CC_USING_EXPOLINE)) { 78 78 /* ··· 87 87 * nobp setting decides what is done, this depends on the 88 88 * CONFIG_KERNEL_NP option and the nobp/nospec parameters. 89 89 */ 90 - return 0; 91 90 } 92 - #ifdef CONFIG_EXPOLINE_AUTO 93 - early_initcall(spectre_v2_auto_early); 94 - #endif 95 91 96 92 static int __init spectre_v2_setup_early(char *str) 97 93 { ··· 98 102 if (str && !strncmp(str, "off", 3)) 99 103 nospec_disable = 1; 100 104 if (str && !strncmp(str, "auto", 4)) 101 - spectre_v2_auto_early(); 105 + nospec_auto_detect(); 102 106 return 0; 103 107 } 104 108 early_param("spectre_v2", spectre_v2_setup_early);
+3
arch/s390/kernel/setup.c
··· 894 894 init_mm.end_data = (unsigned long) _edata; 895 895 init_mm.brk = (unsigned long) _end; 896 896 897 + if (IS_ENABLED(CONFIG_EXPOLINE_AUTO)) 898 + nospec_auto_detect(); 899 + 897 900 parse_early_param(); 898 901 #ifdef CONFIG_CRASH_DUMP 899 902 /* Deactivate elfcorehdr= kernel parameter */