[RFC PATCH 16/56] x86/bugs: Reset ITS mitigation

David Kaplan posted 56 patches 2 months, 1 week ago
[RFC PATCH 16/56] x86/bugs: Reset ITS mitigation
Posted by David Kaplan 2 months, 1 week ago
Add function to reset ITS mitigation back to boot-time default.

Signed-off-by: David Kaplan <david.kaplan@amd.com>
---
 arch/x86/kernel/cpu/bugs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 67561e5c2154..bf5de097e1a9 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -1744,6 +1744,17 @@ static void __init its_apply_mitigation(void)
 	}
 }
 
+#ifdef CONFIG_DYNAMIC_MITIGATIONS
+static void its_reset_mitigation(void)
+{
+	setup_clear_cpu_cap(X86_FEATURE_INDIRECT_THUNK_ITS);
+	setup_clear_cpu_cap(X86_FEATURE_RETHUNK);
+	x86_return_thunk = __x86_return_thunk;
+	its_mitigation = IS_ENABLED(CONFIG_MITIGATION_ITS) ?
+		ITS_MITIGATION_AUTO : ITS_MITIGATION_OFF;
+}
+#endif
+
 #undef pr_fmt
 #define pr_fmt(fmt)	"Transient Scheduler Attacks: " fmt
 
@@ -3966,5 +3977,6 @@ void arch_cpu_reset_mitigations(void)
 	srso_reset_mitigation();
 	gds_reset_mitigation();
 	bhi_reset_mitigation();
+	its_reset_mitigation();
 }
 #endif
-- 
2.34.1