mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/4] x86/bugs: Adjust SRSO mitigation to new features
@ 2024-12-02 12:04 Borislav Petkov
  2024-12-02 12:04 ` [PATCH v2 1/4] x86/bugs: Add SRSO_USER_KERNEL_NO support Borislav Petkov
                   ` (5 more replies)
  0 siblings, 6 replies; 76+ messages in thread
From: Borislav Petkov @ 2024-12-02 12:04 UTC (permalink / raw)
  To: Sean Christopherson, X86 ML
  Cc: Paolo Bonzini, Josh Poimboeuf, Pawan Gupta, KVM, LKML,
	Borislav Petkov (AMD)

From: "Borislav Petkov (AMD)" <bp@alien8.de>

Hi,

here's the next revision, with hopefully all review feedback addressed.

Changelog:
v1:

https://lore.kernel.org/r/20241104101543.31885-1-bp@kernel.org

Thx.

Borislav Petkov (AMD) (4):
  x86/bugs: Add SRSO_USER_KERNEL_NO support
  KVM: x86: Advertise SRSO_USER_KERNEL_NO to userspace
  x86/bugs: KVM: Add support for SRSO_MSR_FIX
  Documentation/kernel-parameters: Fix a typo in kvm.enable_virt_at_load
    text

 Documentation/admin-guide/hw-vuln/srso.rst      | 10 ++++++++++
 Documentation/admin-guide/kernel-parameters.txt |  2 +-
 arch/x86/include/asm/cpufeatures.h              |  2 ++
 arch/x86/include/asm/msr-index.h                |  1 +
 arch/x86/kernel/cpu/bugs.c                      | 16 +++++++++++++++-
 arch/x86/kernel/cpu/common.c                    |  1 +
 arch/x86/kvm/cpuid.c                            |  2 +-
 arch/x86/kvm/svm/svm.c                          |  6 ++++++
 arch/x86/lib/msr.c                              |  2 ++
 9 files changed, 39 insertions(+), 3 deletions(-)


base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37
-- 
2.43.0


^ permalink raw reply	[flat|nested] 76+ messages in thread
* Re: [PATCH final?] x86/bugs: KVM: Add support for SRSO_MSR_FIX
@ 2025-02-26 18:45 Patrick Bellasi
  2025-02-26 19:51 ` Yosry Ahmed
  2025-03-03 14:10 ` Borislav Petkov
  0 siblings, 2 replies; 76+ messages in thread
From: Patrick Bellasi @ 2025-02-26 18:45 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Patrick Bellasi, Sean Christopherson, Yosry Ahmed, Paolo Bonzini,
	Josh Poimboeuf, Pawan Gupta, x86, kvm, linux-kernel,
	Patrick Bellasi, Brendan Jackman, David Kaplan

> On Tue, Feb 18, 2025 at 02:42:57PM +0000, Patrick Bellasi wrote:
> > Maybe a small improvement we could add on top is to have a separate and
> > dedicated cmdline option?
> > 
> > Indeed, with `X86_FEATURE_SRSO_USER_KERNEL_NO` we are not effectively using an
> > IBPB on VM-Exit anymore. Something like the diff down below?
> 
> Except that I don't see the point of this yet one more cmdline option. Our
> mitigations options space is a nightmare. Why do we want to add another one?

The changelog of the following patch provides the motivations.

Do you think something like the following self contained change can be added on
top of your change?

Best,
Patrick

---
From 62bd6151cdb5f8e3322d8c91166cf89b6ed9f5b6 Mon Sep 17 00:00:00 2001
From: Patrick Bellasi <derkling@google.com>
Date: Mon, 24 Feb 2025 17:41:30 +0000
Subject: [PATCH] x86/bugs: Add explicit BP_SPEC_REDUCE cmdline

Some AMD CPUs are vulnerable to SRSO only limited to the Guest->Host
attack vector. When no command line options are specified, the default
SRSO mitigation on these CPUs is "safe-ret", which is optimized to use
"ibpb-vmexit". A further optimization, introduced in [1], replaces IBPB
on VM-Exits with the more efficient BP_SPEC_REDUCE mitigation when the
CPU reports X86_FEATURE_SRSO_BP_SPEC_REDUCE support.

The current implementation in bugs.c automatically selects the best
mitigation for a CPU when no command line options are provided. However,
it lacks the ability to explicitly choose between IBPB and
BP_SPEC_REDUCE.
In some scenarios it could be interesting to mitigate SRSO only when the
low overhead of BP_SPEC_REDUCE is available, without overwise falling
back to an IBPB at each VM-Exit.
More in general, an explicit control is valuable for testing,
benchmarking, and comparing the behavior and overhead of IBPB versus
BP_SPEC_REDUCE.

Add a new kernel cmdline option to explicitly select BP_SPEC_REDUCE.
Do that with a minimal change that does not affect the current SafeRET
"fallback logic". Do warn when reduced speculation is required but the
support not available and properly report the vulnerability reason.

[1] https://lore.kernel.org/lkml/20250218111306.GFZ7RrQh3RD4JKj1lu@fat_crate.local/

Signed-off-by: Patrick Bellasi <derkling@google.com>
---
 arch/x86/kernel/cpu/bugs.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 7fafd98368b91..2d785b2ca4e2e 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -2523,6 +2523,7 @@ enum srso_mitigation {
 	SRSO_MITIGATION_IBPB,
 	SRSO_MITIGATION_IBPB_ON_VMEXIT,
 	SRSO_MITIGATION_BP_SPEC_REDUCE,
+	SRSO_MITIGATION_BP_SPEC_REDUCE_NA,
 };

 enum srso_mitigation_cmd {
@@ -2531,6 +2532,7 @@ enum srso_mitigation_cmd {
 	SRSO_CMD_SAFE_RET,
 	SRSO_CMD_IBPB,
 	SRSO_CMD_IBPB_ON_VMEXIT,
+	SRSO_CMD_BP_SPEC_REDUCE,
 };

 static const char * const srso_strings[] = {
@@ -2542,6 +2544,7 @@ static const char * const srso_strings[] = {
 	[SRSO_MITIGATION_IBPB]			= "Mitigation: IBPB",
 	[SRSO_MITIGATION_IBPB_ON_VMEXIT]	= "Mitigation: IBPB on VMEXIT only",
 	[SRSO_MITIGATION_BP_SPEC_REDUCE]	= "Mitigation: Reduced Speculation",
+	[SRSO_MITIGATION_BP_SPEC_REDUCE_NA]	= "Vulnerable: Reduced Speculation, not available",
 };

 static enum srso_mitigation srso_mitigation __ro_after_init = SRSO_MITIGATION_NONE;
@@ -2562,6 +2565,8 @@ static int __init srso_parse_cmdline(char *str)
 		srso_cmd = SRSO_CMD_IBPB;
 	else if (!strcmp(str, "ibpb-vmexit"))
 		srso_cmd = SRSO_CMD_IBPB_ON_VMEXIT;
+	else if (!strcmp(str, "bp-spec-reduce"))
+		srso_cmd = SRSO_CMD_BP_SPEC_REDUCE;
 	else
 		pr_err("Ignoring unknown SRSO option (%s).", str);

@@ -2672,12 +2677,8 @@ static void __init srso_select_mitigation(void)

 ibpb_on_vmexit:
 	case SRSO_CMD_IBPB_ON_VMEXIT:
-		if (boot_cpu_has(X86_FEATURE_SRSO_BP_SPEC_REDUCE)) {
-			pr_notice("Reducing speculation to address VM/HV SRSO attack vector.\n");
-			srso_mitigation = SRSO_MITIGATION_BP_SPEC_REDUCE;
-			break;
-		}
-
+		if (boot_cpu_has(X86_FEATURE_SRSO_BP_SPEC_REDUCE))
+			goto bp_spec_reduce;
 		if (IS_ENABLED(CONFIG_MITIGATION_IBPB_ENTRY)) {
 			if (has_microcode) {
 				setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);
@@ -2694,6 +2695,17 @@ static void __init srso_select_mitigation(void)
 			pr_err("WARNING: kernel not compiled with MITIGATION_IBPB_ENTRY.\n");
 		}
 		break;
+
+	case SRSO_CMD_BP_SPEC_REDUCE:
+		if (boot_cpu_has(X86_FEATURE_SRSO_BP_SPEC_REDUCE)) {
+bp_spec_reduce:
+			pr_notice("Reducing speculation to address VM/HV SRSO attack vector.\n");
+			srso_mitigation = SRSO_MITIGATION_BP_SPEC_REDUCE;
+			break;
+		} else {
+			srso_mitigation = SRSO_MITIGATION_BP_SPEC_REDUCE_NA;
+			pr_warn("BP_SPEC_REDUCE not supported!\n");
+		}
 	default:
 		break;
 	}
--
2.48.1.711.g2feabab25a-goog

^ permalink raw reply	[flat|nested] 76+ messages in thread
* Re: [PATCH final?] x86/bugs: KVM: Add support for SRSO_MSR_FIX
@ 2025-03-03 15:05 Patrick Bellasi
  2025-03-11 12:03 ` Borislav Petkov
  0 siblings, 1 reply; 76+ messages in thread
From: Patrick Bellasi @ 2025-03-03 15:05 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Patrick Bellasi, Sean Christopherson, Yosry Ahmed, Paolo Bonzini,
	Josh Poimboeuf, Pawan Gupta, x86, kvm, linux-kernel,
	Patrick Bellasi, Brendan Jackman, David Kaplan

> On Wed, Feb 26, 2025 at 06:45:40PM +0000, Patrick Bellasi wrote:
> > +
> > +	case SRSO_CMD_BP_SPEC_REDUCE:
> > +		if (boot_cpu_has(X86_FEATURE_SRSO_BP_SPEC_REDUCE)) {
> > +bp_spec_reduce:
> > +			pr_notice("Reducing speculation to address VM/HV SRSO attack vector.\n");
>
> Probably not needed anymore as that will be in srso_strings which is issued
> later.

Good point, the above can certainly be dropped.

> > +			srso_mitigation = SRSO_MITIGATION_BP_SPEC_REDUCE;
> > +			break;
> > +		} else {
> > +			srso_mitigation = SRSO_MITIGATION_BP_SPEC_REDUCE_NA;
> > +			pr_warn("BP_SPEC_REDUCE not supported!\n");
> > +		}
> 
> This is the part I'm worried about: user hears somewhere "bp-spec-reduce" is
> faster, sets it but doesn't know whether the hw even supports it. Machine
> boots, warns which is a single line and waaay buried in dmesg and continues
> unmitigated.

That's why we are also going to detect this cases and set
SRSO_MITIGATION_BP_SPEC_REDUCE_NA, so that we get a:

  "Vulnerable: Reduced Speculation, not available"

from vulnerabilities/spec_rstack_overflow, which should be the only place users
look for to assess the effective mitigation posture, ins't it?

> So *maybe* we can make this a lot more subtle and say:
> 
> srso=__dont_fall_back_to_ibpb_on_vmexit_if_bp_spec_reduce__
> 
> (joking about the name but that should be the gist of what it means)

I can think about it, but this seems something different than the common
practice, i.e. specify at cmdline what you want and be prepares on possibly
not to get it.

> and then act accordingly when that is specified along with a big fat:
> 
> WARN_ON(..."You should not use this as a mitigation option if you don't know
> what you're doing")
> 
> along with a big fat splat in dmesg.
> 
> Hmmm...?

After all the above already happens, e.g. if we ask for ibpb-vmexit but the
machine has not the ucode. In this case we still have to check the
vulnerabilities report to know that we are:

  "Vulnerable: No microcode"

--
#include <best/regards.h>

Patrick Bellasi (derkling@)

^ permalink raw reply	[flat|nested] 76+ messages in thread

end of thread, other threads:[~2025-05-05 18:25 UTC | newest]

Thread overview: 76+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-02 12:04 [PATCH v2 0/4] x86/bugs: Adjust SRSO mitigation to new features Borislav Petkov
2024-12-02 12:04 ` [PATCH v2 1/4] x86/bugs: Add SRSO_USER_KERNEL_NO support Borislav Petkov
2024-12-10  6:53   ` Josh Poimboeuf
2024-12-10 15:37     ` Borislav Petkov
2024-12-11  7:53       ` Josh Poimboeuf
2024-12-11 20:38         ` Borislav Petkov
2024-12-11 22:35           ` Sean Christopherson
2024-12-16 17:21             ` Borislav Petkov
2024-12-30 17:02   ` [tip: x86/bugs] " tip-bot2 for Borislav Petkov (AMD)
2024-12-02 12:04 ` [PATCH v2 2/4] KVM: x86: Advertise SRSO_USER_KERNEL_NO to userspace Borislav Petkov
2024-12-30 17:02   ` [tip: x86/bugs] " tip-bot2 for Borislav Petkov (AMD)
2024-12-02 12:04 ` [PATCH v2 3/4] x86/bugs: KVM: Add support for SRSO_MSR_FIX Borislav Petkov
2024-12-11 22:27   ` Sean Christopherson
2024-12-16 17:31     ` Borislav Petkov
2024-12-16 18:51       ` Sean Christopherson
2024-12-17  9:34         ` Borislav Petkov
2024-12-30 11:14         ` Borislav Petkov
2025-01-08 13:38           ` Sean Christopherson
2025-01-08 15:49             ` Borislav Petkov
2025-01-08 17:18               ` Sean Christopherson
2025-01-08 18:14                 ` Borislav Petkov
2025-01-08 18:37                   ` Jim Mattson
2025-01-08 19:14                     ` Borislav Petkov
2025-01-08 19:43                       ` Jim Mattson
2025-01-08 19:45                         ` Borislav Petkov
2025-01-11 12:52                   ` [PATCH] " Borislav Petkov
2025-01-17 18:56                     ` Sean Christopherson
2025-01-18 15:26                       ` Borislav Petkov
2025-01-23 16:25                         ` Sean Christopherson
2025-01-23 17:01                           ` Borislav Petkov
2025-01-23 18:04                             ` Sean Christopherson
2025-01-24 12:58                               ` Borislav Petkov
2025-02-11 19:19                                 ` Jim Mattson
2025-02-11 20:51                                   ` Borislav Petkov
2025-02-13 10:53                             ` Patrick Bellasi
2025-02-13 13:44                               ` Patrick Bellasi
2025-02-13 14:28                                 ` Borislav Petkov
2025-02-13 17:50                                   ` Patrick Bellasi
2025-02-14 20:10                                     ` Borislav Petkov
2025-02-15  0:57                                       ` Yosry Ahmed
2025-02-15  9:15                                         ` Borislav Petkov
2025-02-17  5:47                                           ` Yosry Ahmed
2025-02-17 15:26                                             ` Borislav Petkov
2025-02-15 12:53                                       ` Borislav Petkov
2025-02-17  5:59                                         ` Yosry Ahmed
2025-02-17 16:07                                           ` Borislav Petkov
2025-02-17 19:56                                             ` Yosry Ahmed
2025-02-17 20:20                                               ` Borislav Petkov
2025-02-17 20:32                                                 ` Yosry Ahmed
2025-02-18 11:13                                                   ` [PATCH final?] " Borislav Petkov
2025-02-18 14:42                                                     ` Patrick Bellasi
2025-02-18 15:34                                                       ` Borislav Petkov
2025-04-29 13:25                                                     ` x86/bugs: KVM: Add support for SRSO_MSR_FIX, back for moar Borislav Petkov
2025-04-30 23:33                                                       ` Sean Christopherson
2025-05-01  0:42                                                         ` Michael Larabel
2025-05-01  8:19                                                         ` Borislav Petkov
2025-05-01 16:56                                                           ` Sean Christopherson
2025-05-05 15:25                                                             ` Borislav Petkov
2025-05-05 15:40                                                               ` Kaplan, David
2025-05-05 15:47                                                                 ` Borislav Petkov
2025-05-05 16:30                                                                 ` Sean Christopherson
2025-05-05 16:42                                                                   ` Kaplan, David
2025-05-05 18:03                                                                     ` Sean Christopherson
2025-05-05 18:25                                                                       ` Kaplan, David
2024-12-02 12:04 ` [PATCH v2 4/4] Documentation/kernel-parameters: Fix a typo in kvm.enable_virt_at_load text Borislav Petkov
2024-12-30 17:21   ` [tip: x86/cleanups] " tip-bot2 for Borislav Petkov (AMD)
2024-12-03 14:30 ` [PATCH v2 0/4] x86/bugs: Adjust SRSO mitigation to new features Nikolay Borisov
2025-02-26 14:32 ` [tip: x86/bugs] x86/bugs: KVM: Add support for SRSO_MSR_FIX tip-bot2 for Borislav Petkov
2025-02-26 18:45 [PATCH final?] " Patrick Bellasi
2025-02-26 19:51 ` Yosry Ahmed
2025-03-03 13:59   ` Borislav Petkov
2025-03-03 14:10 ` Borislav Petkov
2025-03-03 15:05 Patrick Bellasi
2025-03-11 12:03 ` Borislav Petkov
2025-03-11 13:36   ` Brendan Jackman
2025-03-12 19:17     ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®