Reset global mitigations, including attack vectors and then call the
arch-specific function to reset further mitigations.
Signed-off-by: David Kaplan <david.kaplan@amd.com>
---
include/linux/cpu.h | 3 +++
kernel/cpu.c | 18 ++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 487b3bf2e1ea..3da629a76a49 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -208,6 +208,9 @@ enum smt_mitigations {
SMT_MITIGATIONS_ON,
};
+void cpu_reset_mitigations(void);
+void arch_cpu_reset_mitigations(void);
+
#ifdef CONFIG_CPU_MITIGATIONS
extern bool cpu_mitigations_off(void);
extern bool cpu_mitigations_auto_nosmt(void);
diff --git a/kernel/cpu.c b/kernel/cpu.c
index db9f6c539b28..910249f6217a 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -3171,6 +3171,7 @@ void __init boot_cpu_hotplug_init(void)
}
#ifdef CONFIG_CPU_MITIGATIONS
+
/*
* All except the cross-thread attack vector are mitigated by default.
* Cross-thread mitigation often requires disabling SMT which is expensive
@@ -3326,3 +3327,20 @@ static int __init mitigations_parse_cmdline(char *arg)
}
#endif
early_param("mitigations", mitigations_parse_cmdline);
+
+#ifdef CONFIG_DYNAMIC_MITIGATIONS
+void __weak arch_cpu_reset_mitigations(void)
+{
+}
+
+void cpu_reset_mitigations(void)
+{
+ smt_mitigations = SMT_MITIGATIONS_AUTO;
+ cpu_mitigations = CPU_MITIGATIONS_AUTO;
+ attack_vectors[CPU_MITIGATE_USER_KERNEL] = true;
+ attack_vectors[CPU_MITIGATE_USER_USER] = true;
+ attack_vectors[CPU_MITIGATE_GUEST_HOST] = IS_ENABLED(CONFIG_KVM);
+ attack_vectors[CPU_MITIGATE_GUEST_GUEST] = IS_ENABLED(CONFIG_KVM);
+ arch_cpu_reset_mitigations();
+}
+#endif
--
2.34.1