[PATCH v2 4/7] x86/its: Use switch/case to apply mitigation

Pawan Gupta posted 7 patches 6 months, 3 weeks ago
There is a newer version of this series
[PATCH v2 4/7] x86/its: Use switch/case to apply mitigation
Posted by Pawan Gupta 6 months, 3 weeks ago
Prepare to apply stuffing mitigation in its_apply_mitigation(). This is
currently only done via retbleed mitigation. Also using switch/case makes
it evident that mitigation mode like VMEXIT_ONLY doesn't need any special
handling.

Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
---
 arch/x86/kernel/cpu/bugs.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index a088302b320cf68344e28be7710b5a3582bba9ea..fbfc08f5f9f652beb677a1b5310e4322600082ac 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -1471,15 +1471,21 @@ static void __init its_update_mitigation(void)
 
 static void __init its_apply_mitigation(void)
 {
+	switch (its_mitigation) {
+	case ITS_MITIGATION_OFF:
+	case ITS_MITIGATION_AUTO:
+	case ITS_MITIGATION_VMEXIT_ONLY:
 	/* its=stuff forces retbleed stuffing and is enabled there. */
-	if (its_mitigation != ITS_MITIGATION_ALIGNED_THUNKS)
-		return;
-
-	if (!boot_cpu_has(X86_FEATURE_RETPOLINE))
-		setup_force_cpu_cap(X86_FEATURE_INDIRECT_THUNK_ITS);
+	case ITS_MITIGATION_RETPOLINE_STUFF:
+		break;
+	case ITS_MITIGATION_ALIGNED_THUNKS:
+		if (!boot_cpu_has(X86_FEATURE_RETPOLINE))
+			setup_force_cpu_cap(X86_FEATURE_INDIRECT_THUNK_ITS);
 
-	setup_force_cpu_cap(X86_FEATURE_RETHUNK);
-	set_return_thunk(its_return_thunk);
+		setup_force_cpu_cap(X86_FEATURE_RETHUNK);
+		set_return_thunk(its_return_thunk);
+		break;
+	}
 }
 
 #undef pr_fmt

-- 
2.34.1
Re: [PATCH v2 4/7] x86/its: Use switch/case to apply mitigation
Posted by Nikolay Borisov 6 months, 3 weeks ago

On 5/22/25 05:45, Pawan Gupta wrote:
> Prepare to apply stuffing mitigation in its_apply_mitigation(). This is
> currently only done via retbleed mitigation. Also using switch/case makes
> it evident that mitigation mode like VMEXIT_ONLY doesn't need any special
> handling.
> 
> Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>

Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
Re: [PATCH v2 4/7] x86/its: Use switch/case to apply mitigation
Posted by Pawan Gupta 6 months, 3 weeks ago
On Thu, May 22, 2025 at 02:15:36PM +0300, Nikolay Borisov wrote:
> 
> 
> On 5/22/25 05:45, Pawan Gupta wrote:
> > Prepare to apply stuffing mitigation in its_apply_mitigation(). This is
> > currently only done via retbleed mitigation. Also using switch/case makes
> > it evident that mitigation mode like VMEXIT_ONLY doesn't need any special
> > handling.
> > 
> > Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
> 
> Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>

Thanks.