]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
arm64: proton-pack: Fix hard lockup due to print in scheduler context
authorshechenglong <shechenglong@xfusion.com>
Fri, 31 Oct 2025 09:15:06 +0000 (17:15 +0800)
committerWill Deacon <will@kernel.org>
Fri, 7 Nov 2025 14:49:12 +0000 (14:49 +0000)
Relocate the printk() calls from spectre_v4_mitigations_off() and
spectre_v2_mitigations_off() into setup_system_capabilities() function,
preventing hard lockups caused by printk calls in scheduler context:

  | _raw_spin_lock_nested+168
  | ttwu_queue+180 (rq_lock(rq, &rf); 2nd acquiring the rq->__lock)
  | try_to_wake_up+548
  | wake_up_process+32
  | __up+88
  | up+100
  | __up_console_sem+96
  | console_unlock+696
  | vprintk_emit+428
  | vprintk_default+64
  | vprintk_func+220
  | printk+104
  | spectre_v4_enable_task_mitigation+344
  | __switch_to+100
  | __schedule+1028 (rq_lock(rq, &rf); 1st acquiring the rq->__lock)
  | schedule_idle+48
  | do_idle+388
  | cpu_startup_entry+44
  | secondary_start_kernel+352

Suggested-by: Mark Rutland <mark.rutland@arm.com>
Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
Suggested-by: Will Deacon <will@kernel.org>
Signed-off-by: shechenglong <shechenglong@xfusion.com>
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/spectre.h
arch/arm64/kernel/cpufeature.c
arch/arm64/kernel/proton-pack.c

index 8fef12626090112fdb308eae1d88977643b63cbd..900454aaa29264e9de06dee37c3f6a7b5e4eade3 100644 (file)
@@ -117,6 +117,7 @@ void spectre_bhb_patch_wa3(struct alt_instr *alt,
                           __le32 *origptr, __le32 *updptr, int nr_inst);
 void spectre_bhb_patch_clearbhb(struct alt_instr *alt,
                                __le32 *origptr, __le32 *updptr, int nr_inst);
+void spectre_print_disabled_mitigations(void);
 
 #endif /* __ASSEMBLY__ */
 #endif /* __ASM_SPECTRE_H */
index 5ed401ff79e3e388b63825acbd156546cf91e103..e25b0f84a22dafae5d797e1bbadffff532d31920 100644 (file)
@@ -95,6 +95,7 @@
 #include <asm/vectors.h>
 #include <asm/virt.h>
 
+#include <asm/spectre.h>
 /* Kernel representation of AT_HWCAP and AT_HWCAP2 */
 static DECLARE_BITMAP(elf_hwcap, MAX_CPU_FEATURES) __read_mostly;
 
@@ -3875,6 +3876,11 @@ static void __init setup_system_capabilities(void)
         */
        if (system_uses_ttbr0_pan())
                pr_info("emulated: Privileged Access Never (PAN) using TTBR0_EL1 switching\n");
+
+       /*
+        * Report Spectre mitigations status.
+        */
+       spectre_print_disabled_mitigations();
 }
 
 void __init setup_system_features(void)
index d833b7c1bba8fe66aea8140804d5f0629cbb232e..c7d70d04c164ca5fff67c02e22af38c7c93df249 100644 (file)
@@ -91,12 +91,7 @@ early_param("nospectre_v2", parse_spectre_v2_param);
 
 static bool spectre_v2_mitigations_off(void)
 {
-       bool ret = __nospectre_v2 || cpu_mitigations_off();
-
-       if (ret)
-               pr_info_once("spectre-v2 mitigation disabled by command line option\n");
-
-       return ret;
+       return __nospectre_v2 || cpu_mitigations_off();
 }
 
 static const char *get_bhb_affected_string(enum mitigation_state bhb_state)
@@ -421,13 +416,8 @@ early_param("ssbd", parse_spectre_v4_param);
  */
 static bool spectre_v4_mitigations_off(void)
 {
-       bool ret = cpu_mitigations_off() ||
-                  __spectre_v4_policy == SPECTRE_V4_POLICY_MITIGATION_DISABLED;
-
-       if (ret)
-               pr_info_once("spectre-v4 mitigation disabled by command-line option\n");
-
-       return ret;
+       return cpu_mitigations_off() ||
+              __spectre_v4_policy == SPECTRE_V4_POLICY_MITIGATION_DISABLED;
 }
 
 /* Do we need to toggle the mitigation state on entry to/exit from the kernel? */
@@ -1042,8 +1032,6 @@ void spectre_bhb_enable_mitigation(const struct arm64_cpu_capabilities *entry)
 
        if (arm64_get_spectre_v2_state() == SPECTRE_VULNERABLE) {
                /* No point mitigating Spectre-BHB alone. */
-       } else if (cpu_mitigations_off() || __nospectre_bhb) {
-               pr_info_once("spectre-bhb mitigation disabled by command line option\n");
        } else if (supports_ecbhb(SCOPE_LOCAL_CPU)) {
                state = SPECTRE_MITIGATED;
                set_bit(BHB_HW, &system_bhb_mitigations);
@@ -1197,3 +1185,18 @@ void unpriv_ebpf_notify(int new_state)
                pr_err("WARNING: %s", EBPF_WARN);
 }
 #endif
+
+void spectre_print_disabled_mitigations(void)
+{
+       /* Keep a single copy of the common message suffix to avoid duplication. */
+       const char *spectre_disabled_suffix = "mitigation disabled by command-line option\n";
+
+       if (spectre_v2_mitigations_off())
+               pr_info("spectre-v2 %s", spectre_disabled_suffix);
+
+       if (spectre_v4_mitigations_off())
+               pr_info("spectre-v4 %s", spectre_disabled_suffix);
+
+       if (__nospectre_bhb || cpu_mitigations_off())
+               pr_info("spectre-bhb %s", spectre_disabled_suffix);
+}