Skip to content

Commit 7f16357

Browse files
shechenglong-fusionwilldeacon
authored andcommitted
arm64: proton-pack: Fix hard lockup due to print in scheduler context
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>
1 parent 62e7246 commit 7f16357

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

arch/arm64/include/asm/spectre.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void spectre_bhb_patch_wa3(struct alt_instr *alt,
117117
__le32 *origptr, __le32 *updptr, int nr_inst);
118118
void spectre_bhb_patch_clearbhb(struct alt_instr *alt,
119119
__le32 *origptr, __le32 *updptr, int nr_inst);
120+
void spectre_print_disabled_mitigations(void);
120121

121122
#endif /* __ASSEMBLY__ */
122123
#endif /* __ASM_SPECTRE_H */

arch/arm64/kernel/cpufeature.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
#include <asm/vectors.h>
9696
#include <asm/virt.h>
9797

98+
#include <asm/spectre.h>
9899
/* Kernel representation of AT_HWCAP and AT_HWCAP2 */
99100
static DECLARE_BITMAP(elf_hwcap, MAX_CPU_FEATURES) __read_mostly;
100101

@@ -3875,6 +3876,11 @@ static void __init setup_system_capabilities(void)
38753876
*/
38763877
if (system_uses_ttbr0_pan())
38773878
pr_info("emulated: Privileged Access Never (PAN) using TTBR0_EL1 switching\n");
3879+
3880+
/*
3881+
* Report Spectre mitigations status.
3882+
*/
3883+
spectre_print_disabled_mitigations();
38783884
}
38793885

38803886
void __init setup_system_features(void)

arch/arm64/kernel/proton-pack.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,7 @@ early_param("nospectre_v2", parse_spectre_v2_param);
9191

9292
static bool spectre_v2_mitigations_off(void)
9393
{
94-
bool ret = __nospectre_v2 || cpu_mitigations_off();
95-
96-
if (ret)
97-
pr_info_once("spectre-v2 mitigation disabled by command line option\n");
98-
99-
return ret;
94+
return __nospectre_v2 || cpu_mitigations_off();
10095
}
10196

10297
static const char *get_bhb_affected_string(enum mitigation_state bhb_state)
@@ -421,13 +416,8 @@ early_param("ssbd", parse_spectre_v4_param);
421416
*/
422417
static bool spectre_v4_mitigations_off(void)
423418
{
424-
bool ret = cpu_mitigations_off() ||
425-
__spectre_v4_policy == SPECTRE_V4_POLICY_MITIGATION_DISABLED;
426-
427-
if (ret)
428-
pr_info_once("spectre-v4 mitigation disabled by command-line option\n");
429-
430-
return ret;
419+
return cpu_mitigations_off() ||
420+
__spectre_v4_policy == SPECTRE_V4_POLICY_MITIGATION_DISABLED;
431421
}
432422

433423
/* 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)
10421032

10431033
if (arm64_get_spectre_v2_state() == SPECTRE_VULNERABLE) {
10441034
/* No point mitigating Spectre-BHB alone. */
1045-
} else if (cpu_mitigations_off() || __nospectre_bhb) {
1046-
pr_info_once("spectre-bhb mitigation disabled by command line option\n");
10471035
} else if (supports_ecbhb(SCOPE_LOCAL_CPU)) {
10481036
state = SPECTRE_MITIGATED;
10491037
set_bit(BHB_HW, &system_bhb_mitigations);
@@ -1197,3 +1185,18 @@ void unpriv_ebpf_notify(int new_state)
11971185
pr_err("WARNING: %s", EBPF_WARN);
11981186
}
11991187
#endif
1188+
1189+
void spectre_print_disabled_mitigations(void)
1190+
{
1191+
/* Keep a single copy of the common message suffix to avoid duplication. */
1192+
const char *spectre_disabled_suffix = "mitigation disabled by command-line option\n";
1193+
1194+
if (spectre_v2_mitigations_off())
1195+
pr_info("spectre-v2 %s", spectre_disabled_suffix);
1196+
1197+
if (spectre_v4_mitigations_off())
1198+
pr_info("spectre-v4 %s", spectre_disabled_suffix);
1199+
1200+
if (__nospectre_bhb || cpu_mitigations_off())
1201+
pr_info("spectre-bhb %s", spectre_disabled_suffix);
1202+
}

0 commit comments

Comments
 (0)