s390: correct nospec auto detection init order
authorMartin Schwidefsky <schwidefsky@de.ibm.com>
Fri, 27 Apr 2018 05:36:42 +0000 (07:36 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 29 Apr 2018 09:33:16 +0000 (11:33 +0200)
[ Upstream commit 6a3d1e81a434fc311f224b8be77258bafc18ccc6 ]

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/s390/include/asm/nospec-branch.h
arch/s390/kernel/nospec-branch.c
arch/s390/kernel/setup.c

index 35bf28f..b4bd8c4 100644 (file)
@@ -9,6 +9,7 @@
 extern int nospec_disable;
 
 void nospec_init_branches(void);
+void nospec_auto_detect(void);
 void nospec_revert(s32 *start, s32 *end);
 
 #endif /* __ASSEMBLY__ */
index 73c06d4..9f3b5b3 100644 (file)
@@ -73,7 +73,7 @@ static int __init nospectre_v2_setup_early(char *str)
 }
 early_param("nospectre_v2", nospectre_v2_setup_early);
 
-static int __init spectre_v2_auto_early(void)
+void __init nospec_auto_detect(void)
 {
        if (IS_ENABLED(CC_USING_EXPOLINE)) {
                /*
@@ -88,11 +88,7 @@ static int __init spectre_v2_auto_early(void)
         * nobp setting decides what is done, this depends on the
         * CONFIG_KERNEL_NP option and the nobp/nospec parameters.
         */
-       return 0;
 }
-#ifdef CONFIG_EXPOLINE_AUTO
-early_initcall(spectre_v2_auto_early);
-#endif
 
 static int __init spectre_v2_setup_early(char *str)
 {
@@ -103,7 +99,7 @@ static int __init spectre_v2_setup_early(char *str)
        if (str && !strncmp(str, "off", 3))
                nospec_disable = 1;
        if (str && !strncmp(str, "auto", 4))
-               spectre_v2_auto_early();
+               nospec_auto_detect();
        return 0;
 }
 early_param("spectre_v2", spectre_v2_setup_early);
index 63d5cbb..98c1f79 100644 (file)
@@ -897,6 +897,9 @@ void __init setup_arch(char **cmdline_p)
        init_mm.end_data = (unsigned long) &_edata;
        init_mm.brk = (unsigned long) &_end;
 
+       if (IS_ENABLED(CONFIG_EXPOLINE_AUTO))
+               nospec_auto_detect();
+
        parse_early_param();
 #ifdef CONFIG_CRASH_DUMP
        /* Deactivate elfcorehdr= kernel parameter */