Add SEV-SNP BTB Isolation and IBPB-on-Entry guest features
v5 cover Add SEV-SNP BTB Isolation and IBPB-on-Entry guest features
This series advertises two SEV-SNP guest-selectable side-channel protections through KVM's vmsa_features ABI -- BTB Isolation (SEV_FEATURES bit 7) and IBPB-on-Entry (SEV_FEATURES bit 21) -- along with SVM_SEV_FEAT_SNP_ACTIVE, and fixes two x86 mitigation-selection bugs that stand in the way.
The cpu/bugs patches come first because they are prerequisites, not drive-by cleanups:
- Patch 1 fixes spectre_v2=eibrs silently selecting retpolines instead of AutoIBRS on SNP hosts. Commit acaa4b5c4c85 ("x86/speculation: Do not enable Automatic IBRS if SEV-SNP is enabled") suppressed AutoIBRS by never setting X86_FEATURE_IBRS_ENHANCED, which also disabled the explicit spectre_v2=eibrs request. Set the feature bit and move the SNP-prefers-retpoline decision into the default/auto case, where it belongs.
- Patch 2 allows spectre_v2=ibrs on non-Intel vendors. BTB Isolation uses legacy SPEC_CTRL.IBRS toggling to optimize the SNP VM exit-to-re-entry path, so AMD needs to be able to select it. It also makes EFER.AUTOIBRS explicitly track the selected mitigation, which matters across kexec since head_64.S preserves incoming EFER bits.
Patches 3-6 are small width/ABI cleanups and the SNP_ACTIVE and SNP-only-feature-mask groundwork, and patches 7-8 add IBPB-on-Entry and BTB Isolation themselves.
Note that BTB Isolation is advertised unconditionally on SNP-capable parts. That is deliberate: the APM defines it as architecturally present on every SEV-SNP-capable processor, so unlike IBPB-on-Entry there is no host enumeration bit to gate on. Patch 8 spells this out.
Changes since v4:
https://lore.kernel.org/all/[email protected]/
- Patch 1 ("x86/bugs: Allow forcing Automatic IBRS with SNP active using spectre_v2=eibrs"): only prefer retpoline over AutoIBRS on SNP hosts when CONFIG_MITIGATION_RETPOLINE is actually built in. This folds v4's patch 3 into the same condition and avoids the select-then-fall-back ping pong. Suggested in review:
https://lore.kernel.org/all/lctyimdlenyb5kvfxarzajs2ggzkwn4yehxu233lojynqwa7ej@wjur3lh6szlr/
- Patch 2 ("x86/bugs: Allow spectre_v2=ibrs on x86 vendors other than Intel"): move the EFER.AUTOIBRS kexec cleanup out of spectre_v2_apply_mitigation() and up to the top of cpu_select_mitigations(), next to the existing SPEC_CTRL kexec cleanup, so stale state is dropped before mitigation selection rather than during it. spectre_v2_apply_mitigation() now only sets the bit, which keeps it much closer to its original shape. Suggested in review:
https://lore.kernel.org/all/ga63o6nf7xebndlo66qqasjx7axpopyph7ilkwhvx3enfaqs4w@r4qfr6eo6kcw/
- Subject prefix fixes, per review:
https://lore.kernel.org/all/20260818232204.GBaoTpHK8k7wD9mMk4@fat_crate.local/
The two x86 patches go from "cpu/bugs:" to "x86/bugs:" to match the tip tree convention. Patch 3 goes from "KVM: SEV:" to "KVM: SVM:", since it only touches arch/x86/include/asm/svm.h.
- Tag cleanup, per review:
https://lore.kernel.org/all/20260818232204.GBaoTpHK8k7wD9mMk4@fat_crate.local/
Dropped Cc: [email protected] from both x86/bugs patches. Patch 2 drops its Fixes: too -- it enables spectre_v2=ibrs on a vendor that never had a use for the option rather than fixing a bug anyone is hitting, so neither tag was right. Patch 1 drops the kernel test robot Reported-by:/Closes: pair; that report was against an earlier posting of this patch rather than against upstream, so there was nothing there for it to close. The part of patch 1 that is genuinely -stable material -- an SNP host with CONFIG_MITIGATION_RETPOLINE=n booting with Spectre v2 unmitigated -- will be sent separately as a minimal backport once this lands.
- Dropped v4's patch 3 ("cpu/bugs: Fall back to AutoIBRS when retpoline unavailable on SNP CPUs"). Its fallback is now subsumed by the CONFIG_MITIGATION_RETPOLINE test above.
- Dropped v4's patch 1 ("x86/bugs: Only log missing retpoline when it's actually the missing mitigation"). After the rework above this series no longer needs it, but it still fixes a real spurious "no mitigation available!" on Intel + RETBleed with CONFIG_MITIGATION_IBRS_ENTRY=y, CONFIG_MITIGATION_RETPOLINE=n and spectre_v2=auto, where spectre_v2_update_mitigation() afterwards promotes SPECTRE_V2_NONE to SPECTRE_V2_IBRS. Being posted separately as a standalone fix:
https://lore.kernel.org/lkml/[email protected]/
- Added Tom's Reviewed-by to patch 8
Kim Phillips (8):
x86/bugs: Allow forcing Automatic IBRS with SNP active using
spectre_v2=eibrs
x86/bugs: Allow spectre_v2=ibrs on x86 vendors other than Intel
KVM: SVM: Define SVM_SEV_FEAT_* flags using BIT_ULL()
KVM: selftests: sev_init2: Use BIT_ULL for VMSA feature bit definition
KVM: SEV: Disallow setting SNP-only features for non-SNP guests via a
single mask
KVM: SEV: Advertise SVM_SEV_FEAT_SNP_ACTIVE
KVM: SEV: Add support for IBPB-on-Entry
KVM: SEV: Add support for SNP BTB Isolation
arch/x86/Kconfig | 7 ++- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/svm.h | 17 ++++-- arch/x86/kernel/cpu/bugs.c | 59 ++++++++++++++----- arch/x86/kernel/cpu/common.c | 6 +- arch/x86/kvm/svm/sev.c | 21 ++++++- tools/arch/x86/include/asm/cpufeatures.h | 1 + .../selftests/kvm/x86/sev_init2_tests.c | 20 +++++-- 8 files changed, 96 insertions(+), 36 deletions(-)
base-commit: ec8477a492cb24f2c334847c8734ca56c7ffdd29
Signature · 1 line
2.43.0
PATCH v5 1/8 x86/bugs: Allow forcing Automatic IBRS with SNP active using spectre_v2=eibrs
spectre_v2=eibrs currently enables retpolines when SNP is enabled, instead of AutoIBRS (EIBRS) because the commit that disabled AutoIBRS if SNP is enabled stopped short of enabling X86_FEATURE_IBRS_ENHANCED.
Change the logic to enable X86_FEATURE_IBRS_ENHANCED, and move the decision to switch to retpolines in the default/"auto" case in spectre_v2_select_mitigation(). This allows the existing spectre_v2=eibrs logic to work as intended.
Condition that switch on CONFIG_MITIGATION_RETPOLINE being built in. Otherwise spectre_v2_select_retpoline() returns SPECTRE_V2_NONE and an SNP host with AutoIBRS available would be left completely unmitigated against Spectre v2 in the default/auto case, which is worse than the userspace indirect branch performance loss AutoIBRS costs.
Also emit a performance loss warning for using AutoIBRS with SNP enabled. AutoIBRS is activated for all three eIBRS modes via spectre_v2_in_eibrs_mode(), so use that helper to cover spectre_v2=eibrs, spectre_v2=eibrs,lfence, and spectre_v2=eibrs,retpoline uniformly. Word the warning in terms of the eIBRS mitigation enabling AutoIBRS, rather than naming AutoIBRS as the selected mitigation, so it reads correctly for the ,lfence and ,retpoline variants where another component is also active.
--- arch/x86/kernel/cpu/bugs.c | 15 ++++++++++++++- arch/x86/kernel/cpu/common.c | 6 +----- 2 files changed, 15 insertions(+), 6 deletions(-)
arch/x86/kernel/cpu/bugs.c +14 -1
@@ -1672,6 +1672,7 @@ static inline bool retpoline_seq_enabled(void) { return false; }#define SPECTRE_V2_LFENCE_MSG "WARNING: LFENCE mitigation is not recommended for this CPU, data leaks possible!\n"#define SPECTRE_V2_EIBRS_EBPF_MSG "WARNING: Unprivileged eBPF is enabled with eIBRS on, data leaks possible via Spectre v2 BHB attacks!\n"#define SPECTRE_V2_EIBRS_LFENCE_EBPF_SMT_MSG "WARNING: Unprivileged eBPF is enabled with eIBRS+LFENCE mitigation and SMT, data leaks possible via Spectre v2 BHB attacks!\n" +#define SPECTRE_V2_EIBRS_SNP_PERF_MSG "WARNING: eIBRS mitigation enables AutoIBRS on SEV-SNP enabled CPU, this may cause performance loss\n"#define SPECTRE_V2_IBRS_PERF_MSG "WARNING: IBRS mitigation selected on Enhanced IBRS CPU, this may cause unnecessary performance loss\n"#ifdef CONFIG_BPF_SYSCALL
@@ -2194,7 +2195,15 @@ static void __init spectre_v2_select_mitigation(void)break ; fallthrough;case SPECTRE_V2_CMD_FORCE : -if (boot_cpu_has (X86_FEATURE_IBRS_ENHANCED )) { +/* +* Prefer retpoline when SNP is enabled because AutoIBRS +* degrades host userspace indirect branch performance. Only +* do so if retpoline is actually built in, otherwise AutoIBRS +* is better than leaving the system unmitigated. +*/ +if (boot_cpu_has (X86_FEATURE_IBRS_ENHANCED ) && + !(boot_cpu_has (X86_FEATURE_SEV_SNP ) && +IS_ENABLED (CONFIG_MITIGATION_RETPOLINE ))) { spectre_v2_enabled =SPECTRE_V2_EIBRS ;break ; }
@@ -2286,6 +2295,10 @@ static void __init spectre_v2_apply_mitigation(void) } } +if (spectre_v2_in_eibrs_mode (spectre_v2_enabled) && +boot_cpu_has (X86_FEATURE_SEV_SNP )) +pr_warn (SPECTRE_V2_EIBRS_SNP_PERF_MSG ); +switch (spectre_v2_enabled) {case SPECTRE_V2_NONE :return ;
arch/x86/kernel/cpu/common.c +1 -5
@@ -1496,13 +1496,9 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)/* * AMD's AutoIBRS is equivalent to Intel's eIBRS - use the Intel feature * flag and protect from vendor-specific bugs via the whitelist. -* -* Don't use AutoIBRS when SNP is enabled because it degrades host -* userspace indirect branch performance. */ if ((x86_arch_cap_msr &ARCH_CAP_IBRS_ALL ) || - (cpu_has (c,X86_FEATURE_AUTOIBRS ) && - !cpu_feature_enabled (X86_FEATURE_SEV_SNP ))) { +cpu_has (c,X86_FEATURE_AUTOIBRS )) {setup_force_cpu_cap (X86_FEATURE_IBRS_ENHANCED );if (!cpu_matches (cpu_vuln_whitelist,NO_EIBRS_PBRSB ) && !(x86_arch_cap_msr &ARCH_CAP_PBRSB_NO ))
Signature · 1 line
2.43.0
Re: [PATCH v5 1/8] x86/bugs: Allow forcing Automatic IBRS with SNP active using spectre_v2=eibrs
Quoted 25 lines · Kim Phillips
spectre_v2=eibrs currently enables retpolines when SNP is enabled, instead of AutoIBRS (EIBRS) because the commit that disabled AutoIBRS if SNP is enabled stopped short of enabling
X86_FEATURE_IBRS_ENHANCED.Change the logic to enable
X86_FEATURE_IBRS_ENHANCED, and move the decision to switch to retpolines in the default/"auto" case inspectre_v2_select_mitigation(). This allows the existing spectre_v2=eibrs logic to work as intended.Condition that switch on
CONFIG_MITIGATION_RETPOLINEbeing built in. Otherwisespectre_v2_select_retpoline()returnsSPECTRE_V2_NONEand an SNP host with AutoIBRS available would be left completely unmitigated against Spectre v2 in the default/auto case, which is worse than the userspace indirect branch performance loss AutoIBRS costs.Also emit a performance loss warning for using AutoIBRS with SNP enabled. AutoIBRS is activated for all three eIBRS modes via
spectre_v2_in_eibrs_mode(), so use that helper to cover spectre_v2=eibrs, spectre_v2=eibrs,lfence, and spectre_v2=eibrs,retpoline uniformly. Word the warning in terms of the eIBRS mitigation enabling AutoIBRS, rather than naming AutoIBRS as the selected mitigation, so it reads correctly for the ,lfence and ,retpoline variants where another component is also active.
Quoted 7 lines
Fixes acaa4b5c4c85 ("x86/speculation: Do not enable Automatic IBRS if SEV-SNP is enabled")Reported-by Tom Lendacky <[email protected]>Cc Borislav Petkov (AMD) <[email protected]>Cc Pawan Gupta <[email protected]>Cc Dave Hansen <[email protected]>Cc Sean Christopherson <[email protected]>Signed-off-by Kim Phillips <[email protected]>
Borislav Petkov
maintainerRe: [PATCH v5 1/8] x86/bugs: Allow forcing Automatic IBRS with SNP active using spectre_v2=eibrs
In reply to Kim PhillipsQuoted 4 lines · Kim Phillips
spectre_v2=eibrs currently enables retpolines when SNP is enabled, instead of AutoIBRS (EIBRS) because the commit that disabled AutoIBRS if SNP is enabled stopped short of enabling
X86_FEATURE_IBRS_ENHANCED.
This and the comment below in spectre_v2_select_mitigation() is somewhat hinting on what you're trying to do here, and I can only guess. But I shouldn't be guessing. Rather, the text should explain it clearly.
Quoted 11 lines
Change the logic to enable
X86_FEATURE_IBRS_ENHANCED, and move the decision to switch to retpolines in the default/"auto" case inspectre_v2_select_mitigation(). This allows the existing spectre_v2=eibrs logic to work as intended.Condition that switch on
CONFIG_MITIGATION_RETPOLINEbeing built in. Otherwisespectre_v2_select_retpoline()returnsSPECTRE_V2_NONEand an SNP host with AutoIBRS available would be left completely unmitigated against Spectre v2 in the default/auto case, which is worse than the userspace indirect branch performance loss AutoIBRS costs.
Quoted 8 lines
Also emit a performance loss warning for using AutoIBRS with SNP enabled. AutoIBRS is activated for all three eIBRS modes via
spectre_v2_in_eibrs_mode(), so use that helper to cover spectre_v2=eibrs, spectre_v2=eibrs,lfence, and spectre_v2=eibrs,retpoline uniformly. Word the warning in terms of the eIBRS mitigation enabling AutoIBRS, rather than naming AutoIBRS as the selected mitigation, so it reads correctly for the ,lfence and ,retpoline variants where another component is also active.
This whole text is explaining the diff. Never write about the "what" - but the "why". Why does this patch exist?
Please structure your commit message something like this:
1. Prepare the context for the explanation briefly.
2. Explain the problem at hand.
3. "It happens because of <...>"
4. "Fix it by doing X"
5. "(Potentially do Y)."
And some of those above are optional depending on the issue being explained.
But do not explain the patch. If there are questions about it, I will ask.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v5 1/8] x86/bugs: Allow forcing Automatic IBRS with SNP active using spectre_v2=eibrs
Quoted 41 lines · Borislav Petkov
Quoted 4 lines · Kim Phillips
spectre_v2=eibrs currently enables retpolines when SNP is enabled, instead of AutoIBRS (EIBRS) because the commit that disabled AutoIBRS if SNP is enabled stopped short of enabling
X86_FEATURE_IBRS_ENHANCED.This and the comment below in
spectre_v2_select_mitigation()is somewhat hinting on what you're trying to do here, and I can only guess. But I shouldn't be guessing. Rather, the text should explain it clearly.Quoted 11 lines
Change the logic to enable
X86_FEATURE_IBRS_ENHANCED, and move the decision to switch to retpolines in the default/"auto" case inspectre_v2_select_mitigation(). This allows the existing spectre_v2=eibrs logic to work as intended.Condition that switch on
CONFIG_MITIGATION_RETPOLINEbeing built in. Otherwisespectre_v2_select_retpoline()returnsSPECTRE_V2_NONEand an SNP host with AutoIBRS available would be left completely unmitigated against Spectre v2 in the default/auto case, which is worse than the userspace indirect branch performance loss AutoIBRS costs.Quoted 8 lines
Also emit a performance loss warning for using AutoIBRS with SNP enabled. AutoIBRS is activated for all three eIBRS modes via
spectre_v2_in_eibrs_mode(), so use that helper to cover spectre_v2=eibrs, spectre_v2=eibrs,lfence, and spectre_v2=eibrs,retpoline uniformly. Word the warning in terms of the eIBRS mitigation enabling AutoIBRS, rather than naming AutoIBRS as the selected mitigation, so it reads correctly for the ,lfence and ,retpoline variants where another component is also active.This whole text is explaining the diff. Never write about the "what" - but the "why". Why does this patch exist?
Please structure your commit message something like this:
1. Prepare the context for the explanation briefly.
2. Explain the problem at hand.
3. "It happens because of <...>"
4. "Fix it by doing X"
Quoted 9 lines
5. "(Potentially do Y)."
And some of those above are optional depending on the issue being explained.
But do not explain the patch. If there are questions about it, I will ask.
Thx.
How about the following as the new commit text?:
AMD's AutoIBRS is the hardware implementation of eIBRS. When SNP is active, AutoIBRS also applies to host userspace, which costs indirect branch performance there, so commit acaa4b5c4c85 ("x86/speculation: Do not enable Automatic IBRS if SEV-SNP is enabled") made SNP hosts use retpolines instead.
That fallback cannot be overridden. An admin running an SNP host whose workload is dominated by guest activity rather than host userspace may well prefer AutoIBRS, but asking for it with spectre_v2=eibrs silently yields retpolines instead.
It happens because the SNP check sits in cpu_set_bug_bits() and simply leaves X86_FEATURE_IBRS_ENHANCED clear. Without that feature bit, the command line parser cannot distinguish "this CPU has no eIBRS" from "this CPU has eIBRS but policy turned it off", so spectre_v2=eibrs has nothing left to select and falls back to auto.
Fix it by setting X86_FEATURE_IBRS_ENHANCED whenever the hardware supports AutoIBRS, and moving the SNP policy decision into spectre_v2_select_mitigation() where it applies to the default/auto case only. The default behaviour stays as it is today, and spectre_v2=eibrs now means what it says.
Keep AutoIBRS in the default case when CONFIG_MITIGATION_RETPOLINE is not built in: there is nothing to fall back to and an unmitigated SNP host is worse than the userspace performance loss.
Finally, warn when eIBRS does end up enabling AutoIBRS on an SNP host so that the performance cost is not silent.
Thanks,
Kim
Borislav Petkov
maintainerRe: [PATCH v5 1/8] x86/bugs: Allow forcing Automatic IBRS with SNP active using spectre_v2=eibrs
Quoted 3 lines · Kim Phillips
That fallback cannot be overridden. An admin running an SNP host whose workload is dominated by guest activity rather than host userspace may well prefer AutoIBRS
Why would she/he prefer to do that? Any persuasive arguments to make her/him do that?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v5 1/8] x86/bugs: Allow forcing Automatic IBRS with SNP active using spectre_v2=eibrs
Quoted 6 lines · Borislav Petkov
Quoted 3 lines · Kim Phillips
That fallback cannot be overridden. An admin running an SNP host whose workload is dominated by guest activity rather than host userspace may well prefer AutoIBRS
Why would she/he prefer to do that? Any persuasive arguments to make her/him do that?
On the same silicon with SNP off, the kernel's own default is AutoIBRS, not retpoline. Enabling SNP doesn't make retpoline the better mitigation; it just adds a host-userspace cost to AutoIBRS. So the admin is being pushed off the recommended hardware mitigation onto a software one, with no say in it.
What each side actually costs: retpoline taxes every indirect call in the kernel, and a virtualization host lives in the kernel - VM exit handling, networking, storage. AutoIBRS costs nothing on entry/exit and additionally covers indirect branches the kernel never compiled (EFI runtime services, prebuilt out-of-tree modules). Its penalty falls on host userspace, which on a dedicated SNP host is thin and mostly parked in KVM_RUN.
For a guest-dominated host that trade plausibly goes the other way, and only the admin knows their deployment.
Kim
Borislav Petkov
maintainerRe: [PATCH v5 1/8] x86/bugs: Allow forcing Automatic IBRS with SNP active using spectre_v2=eibrs
Quoted 2 lines · Kim Phillips
For a guest-dominated host that trade plausibly goes the other way, and only the admin knows their deployment.
Just holding down the current arguments here *without* AI:
We have had an internal discussion in the past about this already. It can potentially cause performance disadvantages in certain scenarios.
If this is ever going to go anywhere, I would like to see:
- a proper use case which people are *actually* asking for
- have it properly documented in Documentation/admin-guide/hw-vuln/ along with the potential impact so that people can make an *informed* decision whether they really want it
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v5 1/8] x86/bugs: Allow forcing Automatic IBRS with SNP active using spectre_v2=eibrs
Quoted 9 lines · Borislav Petkov
Quoted 2 lines · Kim Phillips
For a guest-dominated host that trade plausibly goes the other way, and only the admin knows their deployment.
Just holding down the current arguments here *without* AI:
We have had an internal discussion in the past about this already. It can potentially cause performance disadvantages in certain scenarios.
Quoted 7 lines
If this is ever going to go anywhere, I would like to see:
- a proper use case which people are *actually* asking for
- have it properly documented in
Documentation/admin-guide/hw-vuln/along with the potential impact so that people can make an *informed* decision whether they really want it
This patch can be dropped for now then.
Please continue your review on patch 2/8.
Thanks,
Kim
PATCH v5 2/8 x86/bugs: Allow spectre_v2=ibrs on x86 vendors other than Intel
In reply to Kim PhillipsPrepare for legacy IBRS toggling on AMD, where the BTB Isolation SEV-SNP feature uses it to optimize the VM exit-to-re-entry path. Commit 7c693f54c873 ("x86/speculation: Add spectre_v2=ibrs option to support Kernel IBRS") restricted the option to Intel because that was the only vendor that needed it at the time; nothing about the mechanism is Intel-specific.
Keep the IBRS-trumps-retbleed logic in retbleed_update_mitigation() Intel-only. Legacy SPEC_CTRL.IBRS does not mitigate AMD's Branch Type Confusion RETBleed variant (RET prediction uses the Return Address Predictor, not the indirect branch predictors IBRS restricts), so letting SPECTRE_V2_IBRS trump retbleed on AMD would silently drop the UNRET/IBPB mitigation that does cover it.
On AMD the decoupling is total: retbleed mitigation selection never consults spectre_v2=, so spectre_v2=ibrs neither adds nor removes RETBleed coverage. A kernel built without MITIGATION_UNRET_ENTRY and MITIGATION_IBPB_ENTRY already reports RETBleed as "Vulnerable" via the retbleed sysfs node and boot log regardless of the spectre_v2= value, so there is no silent gap in the spectre_v2=ibrs path to warn about -- and a warning there would wrongly imply the Intel-style IBRS/RETBleed coupling exists on AMD.
Also drop CPU_SUP_INTEL from CONFIG_MITIGATION_IBRS_ENTRY's depends
line: the IBRS_ENTER/IBRS_EXIT macros are vendor-neutral, and the Intel-only restriction would silently redirect spectre_v2=ibrs to AUTO on AMD-only kernels.
In spectre_v2_apply_mitigation(), route AutoIBRS-capable CPUs to EFER.AUTOIBRS only for the eIBRS modes. Previously any IBRS mode used EFER.AUTOIBRS when the CPU had AutoIBRS, which was unreachable while spectre_v2=ibrs was Intel-only, but would now hand spectre_v2=ibrs the always-on AutoIBRS behaviour instead of the toggleable SPEC_CTRL.IBRS the option asks for.
Finally, clear EFER.AUTOIBRS at the top of cpu_select_mitigations(), alongside the existing SPEC_CTRL kexec cleanup. head_64.S preserves incoming EFER bits, so a kexec from a kernel that ran in AutoIBRS mode carries the bit into the new kernel; without an explicit clear the CPU stays in AutoIBRS mode while sysfs reports e.g. "Mitigation: IBRS" or a retpoline mode, diverging from the actual hardware state. On a normal cold boot the bit is already clear, so the msr_clear_bit() is a no-op there. Clearing on the boot CPU suffices for APs, since it precedes the init_real_mode() EFER snapshot used by the AP trampoline.
--- arch/x86/Kconfig | 7 +++--- arch/x86/kernel/cpu/bugs.c | 44 +++++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 16 deletions(-)
arch/x86/Kconfig +4 -3
@@ -2496,12 +2496,13 @@ config MITIGATION_IBPB_ENTRY config MITIGATION_IBRS_ENTRY bool "Enable IBRS on kernel entry" - depends on CPU_SUP_INTEL && X86_64 + depends on X86_64 default y help Compile the kernel with support for the spectre_v2=ibrs mitigation. - This mitigates both spectre_v2 and retbleed at great cost to - performance. + This mitigates spectre_v2 at great cost to performance. On Intel, + it also mitigates retbleed. On AMD/Hygon, retbleed mitigation + requires MITIGATION_UNRET_ENTRY or MITIGATION_IBPB_ENTRY. config MITIGATION_SRSO bool "Mitigate speculative RAS overflow on AMD"
arch/x86/kernel/cpu/bugs.c +31 -13
68 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v5 2/8] x86/bugs: Allow spectre_v2=ibrs on x86 vendors other than Intel
Quoted 45 lines · Kim Phillips
Prepare for legacy IBRS toggling on AMD, where the BTB Isolation SEV-SNP feature uses it to optimize the VM exit-to-re-entry path. Commit
7c693f54c873("x86/speculation: Add spectre_v2=ibrs option to support Kernel IBRS") restricted the option to Intel because that was the only vendor that needed it at the time; nothing about the mechanism is Intel-specific.Keep the IBRS-trumps-retbleed logic in
retbleed_update_mitigation()Intel-only. Legacy SPEC_CTRL.IBRS does not mitigate AMD's Branch Type Confusion RETBleed variant (RET prediction uses the Return Address Predictor, not the indirect branch predictors IBRS restricts), so lettingSPECTRE_V2_IBRStrump retbleed on AMD would silently drop the UNRET/IBPB mitigation that does cover it.On AMD the decoupling is total: retbleed mitigation selection never consults spectre_v2=, so spectre_v2=ibrs neither adds nor removes RETBleed coverage. A kernel built without
MITIGATION_UNRET_ENTRYandMITIGATION_IBPB_ENTRYalready reports RETBleed as "Vulnerable" via the retbleed sysfs node and boot log regardless of the spectre_v2= value, so there is no silent gap in the spectre_v2=ibrs path to warn about -- and a warning there would wrongly imply the Intel-style IBRS/RETBleed coupling exists on AMD.Also drop
CPU_SUP_INTELfrom CONFIG_MITIGATION_IBRS_ENTRY's depends
line: the IBRS_ENTER/IBRS_EXIT macros are vendor-neutral, and the Intel-only restriction would silently redirect spectre_v2=ibrs to AUTO on AMD-only kernels.In
spectre_v2_apply_mitigation(), route AutoIBRS-capable CPUs to EFER.AUTOIBRS only for the eIBRS modes. Previously any IBRS mode used EFER.AUTOIBRS when the CPU had AutoIBRS, which was unreachable while spectre_v2=ibrs was Intel-only, but would now hand spectre_v2=ibrs the always-on AutoIBRS behaviour instead of the toggleable SPEC_CTRL.IBRS the option asks for.Finally, clear EFER.AUTOIBRS at the top of
cpu_select_mitigations(), alongside the existingSPEC_CTRLkexec cleanup.head_64.Spreserves incoming EFER bits, so a kexec from a kernel that ran in AutoIBRS mode carries the bit into the new kernel; without an explicit clear the CPU stays in AutoIBRS mode while sysfs reports e.g. "Mitigation: IBRS" or a retpoline mode, diverging from the actual hardware state. On a normal cold boot the bit is already clear, so themsr_clear_bit()is a no-op there. Clearing on the boot CPU suffices for APs, since it precedes theinit_real_mode()EFER snapshot used by the AP trampoline.
Quoted 4 lines
Reported-by Tom Lendacky <[email protected]>Cc Pawan Gupta <[email protected]>Cc Borislav Petkov (AMD) <[email protected]>Signed-off-by Kim Phillips <[email protected]>
Borislav Petkov
maintainerRe: [PATCH v5 2/8] x86/bugs: Allow spectre_v2=ibrs on x86 vendors other than Intel
In reply to Kim PhillipsQuoted 1 line · Kim Phillips
Prepare for legacy IBRS toggling on AMD, where the BTB Isolation
Same question as before: why?
This commit message is explaining what the patch does. It needs to explain the why.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v5 2/8] x86/bugs: Allow spectre_v2=ibrs on x86 vendors other than Intel
Quoted 7 lines · Borislav Petkov
Quoted 1 line · Kim Phillips
Prepare for legacy IBRS toggling on AMD, where the BTB Isolation
Same question as before: why?
This commit message is explaining what the patch does. It needs to explain the why.
ok how about this as the new commit text?:
SPEC_CTRL.IBRS is architectural and behaves on AMD just like it does on Intel, but the kernel offers spectre_v2=ibrs on Intel only: the option is rejected at parse time on other vendors, and MITIGATION_IBRS_ENTRY cannot even be built into an AMD-only kernel.
AMD's SNP BTB Isolation needs the kernel to toggle legacy IBRS in order to optimize the VM exit-to-re-entry path, and right now there is no way to ask for kernel IBRS on an AMD machine at all.
It happens for historical reasons only. Commit 7c693f54c873 ("x86/speculation: Add spectre_v2=ibrs option to support Kernel IBRS") gated the option on Intel because Intel was the only vendor that needed it back then - there, kernel IBRS doubles as a RETBleed mitigation. Nothing in the IBRS_ENTER/IBRS_EXIT mechanism itself is vendor-specific.
Fix it by dropping the vendor check from the command line parsing and CPU_SUP_INTEL from MITIGATION_IBRS_ENTRY's depends line.
Keep the IBRS-trumps-retbleed logic in retbleed_update_mitigation() Intel-only, though: legacy SPEC_CTRL.IBRS does not cover AMD's Branch Type Confusion RETBleed variant because RET prediction comes from the Return Address Predictor rather than from the indirect branch predictors IBRS restricts. Letting SPECTRE_V2_IBRS trump retbleed on AMD would silently drop the UNRET/IBPB mitigation that does cover it. RETBleed selection on AMD never consults spectre_v2=, so spectre_v2=ibrs neither adds nor removes RETBleed coverage there and the retbleed sysfs node keeps reporting the truth on its own.
Two more things need handling once the option becomes reachable on AMD:
AutoIBRS-capable CPUs would take the EFER.AUTOIBRS path for any IBRS mode, handing spectre_v2=ibrs the always-on AutoIBRS behaviour instead of the toggleable SPEC_CTRL.IBRS the option asks for. Restrict that path to the eIBRS modes.
And EFER.AUTOIBRS survives kexec because head_64.S preserves the incoming EFER bits, so a kernel that ran in AutoIBRS mode leaves the next one in AutoIBRS mode while its sysfs reports "Mitigation: IBRS" or a retpoline mode. Clear the bit at the top of cpu_select_mitigations() next to the existing SPEC_CTRL kexec cleanup - a cold boot has it clear already, and that spot precedes the init_real_mode() EFER snapshot the AP trampoline uses.
Thanks,
Kim
Borislav Petkov
maintainerRe: [PATCH v5 2/8] x86/bugs: Allow spectre_v2=ibrs on x86 vendors other than Intel
Quoted 8 lines · Kim Phillips
SPEC_CTRL.IBRS is architectural and behaves on AMD just like it does on Intel, but the kernel offers spectre_v2=ibrs on Intel only: the option is rejected at parse time on other vendors, and
MITIGATION_IBRS_ENTRYcannot even be built into an AMD-only kernel.AMD's SNP BTB Isolation needs the kernel to toggle legacy IBRS in order to optimize the VM exit-to-re-entry path, and right now there is no way to ask for kernel IBRS on an AMD machine at all.
Same comments as to the other one: We need:
- a proper use case which is *actually* useful to users
- have it properly documented in Documentation/admin-guide/hw-vuln/ along with the potential impact so that people can make an *informed* decision whether they really want it
Without any justification for the added complexity to what already is a maintenance nightmare, there's no point.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v5 2/8] x86/bugs: Allow spectre_v2=ibrs on x86 vendors other than Intel
@Sean, @Paolo, Please consider merging the rest of this patchseries (patches 3-8), as they can go through the KVM tree directly as-is because they does not depend on this or the prior patch 1/8 other than for performance reasons. Thank you!
Quoted 6 lines · Borislav Petkov
Quoted 5 lines · Kim Phillips
SPEC_CTRL.IBRS is architectural and behaves on AMD just like it does on Intel, but the kernel offers spectre_v2=ibrs on Intel only: the option is rejected at parse time on other vendors, and
MITIGATION_IBRS_ENTRYcannot even be built into an AMD-only kernel.
Quoted 6 lines
Quoted 3 lines
AMD's SNP BTB Isolation needs the kernel to toggle legacy IBRS in order to optimize the VM exit-to-re-entry path, and right now there is no way to ask for kernel IBRS on an AMD machine at all.
Same comments as to the other one: We need:
- a proper use case which is *actually* useful to users
How is optimizing the VM exit-to-re-entry path not "*actually* useful to users"?
If BTB Isolation users want to use BTB Isolation, they'd want what the AMD APM recommends: To use spectre_v2=ibrs: what is wrong with that?
For this Node-ID getting cpuid script that causes lots of VMEXITS:
for i in \seq 0 1000\; do sudo taskset -c 0 cpuid -1 -k -l 0x8000001e > c0; done
I get these stats:
v2=(retpolines), btb-isol=off v2=(retpolines), btb-isol=on
8135634850 l1btb-accesses 8237924785 l1btb-accesses 101% 2292830105 l1btb-misses 2479438191 l1btb-misses 108% 2254370689 l2btb-misses 2462526637 l2btb-misses 109% 38479671 l2btb-hits 16912146 l2btb-hits 44% 2292846687 l2btb-accesses 2479437240 l2btb-accesses 108%
6.591965727 seconds time 6.410626779 seconds time elapsed 97%
v2=ibrs, btb-isol=off v2=ibrs, btb-isol=on
9079195678 l1btb-accesses 7735439435 l1btb-accesses 85% 3420759821 l1btb-misses 2264575904 l1btb-misses 66% 3385686214 l2btb-misses 2226743253 l2btb-misses 66% 35073337 l2btb-hits 37834099 l2btb-hits 108% 3420753266 l2btb-accesses 2264587491 l2btb-accesses 66%
7.019508776 seconds time 6.408415958 seconds time elapsed 91%
Does *that* help?
Kim
Quoted 10 lines
- have it properly documented in
Documentation/admin-guide/hw-vuln/along with the potential impact so that people can make an *informed* decision whether they really want itWithout any justification for the added complexity to what already is a maintenance nightmare, there's no point.
Thx.
Borislav Petkov
maintainerRe: [PATCH v5 2/8] x86/bugs: Allow spectre_v2=ibrs on x86 vendors other than Intel
Quoted 2 lines · Kim Phillips
How is optimizing the VM exit-to-re-entry path not "*actually* useful to users"?
Let me try one last time:
Back then we did this:
commit acaa4b5c4c854b5009f4d4a5395b2609ad0f4937
Author: Kim Phillips <[email protected]> Date: Thu Jan 25 22:11:02 2024 -0600
x86/speculation: Do not enable Automatic IBRS if SEV-SNP is enabled
Without SEV-SNP, Automatic IBRS protects only the kernel. But when SEV-SNP is enabled, the Automatic IBRS protection umbrella widens to all host-side code, including userspace. This protection comes at a cost:
reduced userspace indirect branch performance.
To avoid this performance loss, don't use Automatic IBRS on SEV-SNP hosts and all back to retpolines instead.
Now, in order to be able to prevent indirect branches from influencing other indirect branches in another mode (HV in this case), one needs to be able to switch to plain IBRS, which brings us back to the toggling of the IBRS MSR bit.
I.e.:
"After setting IBRS to 1, if software subsequently
* clears IBRS to 0: The processor may allow older indirect branches that a occurred when IBRS was previously 0 to influence future indirect branch predictions.
* writes another 1 to IBRS: The processor starts a new window where older indirect branches do not influence future indirect branch predictions."
So in order to allow that, you need all that code complication from your patch.
And, for the Nth time, I would understand if there's any real justification for adding all that additional complexity to bugs.c which already is a nightmare to maintain.
But so far I haven't seen a real justification for it. As in: spectre_v2=ibrs on AMD is good for cases A, B or C and this is going to be used in this and that scenario so having that capability upstream is worth the added maintentance effort. Not it "might be useful" to users. "might"'s not good enough for this.
And there's at least a *suspected* perf impact here which has not been measured yet. And no, not with some script but with real workloads.
And it is perfectly fine if those workloads prove that some of them benefit from this setting.
But because there is a potential perf impact - impact which we have not quantified yet - then this is not ready. We need to know what that performance impact is and that needs to be documented so that people can make an informed decision here.
And so that they don't come to us and complain that this setting is causing performance issues and everyone needs to stop the presses and the world is ending.
These are basically the same two things I asked you for, this time I tried to explain them in more detail.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePATCH v5 3/8 KVM: SVM: Define SVM_SEV_FEAT_* flags using BIT_ULL()
In reply to Kim PhillipsThe VMSA's SEV_FEATURES field is 64 bits wide: struct sev_es_save_area's sev_features is u64, as are the VMCB allowed_sev_features/guest_sev_features controls and KVM's vmsa_features / sev_supported_vmsa_features tracking. Define the SVM_SEV_FEAT_* flags with BIT_ULL() instead of BIT() to match that width.
No functional change on x86-64, where unsigned long is already 64 bits and every flag defined today is below bit 32. It makes the flag type match the architectural field, keeps composite masks such as the upcoming SVM_SEV_FEAT_SNP_ONLY_MASK 64-bit, and avoids a latent trap should a future flag land above bit 31. The adjacent VMCB_ALLOWED_SEV_FEATURES_VALID already uses BIT_ULL(63).
--- arch/x86/include/asm/svm.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/include/asm/svm.h +5 -5
@@ -305,11 +305,11 @@ static_assert((AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == AVIC_MAX_static_assert ((X2AVIC_MAX_PHYSICAL_ID &AVIC_PHYSICAL_MAX_INDEX_MASK ) ==X2AVIC_MAX_PHYSICAL_ID );static_assert ((X2AVIC_4K_MAX_PHYSICAL_ID &AVIC_PHYSICAL_MAX_INDEX_MASK ) ==X2AVIC_4K_MAX_PHYSICAL_ID ); -#define SVM_SEV_FEAT_SNP_ACTIVE BIT(0) -#define SVM_SEV_FEAT_RESTRICTED_INJECTION BIT(3) -#define SVM_SEV_FEAT_ALTERNATE_INJECTION BIT(4) -#define SVM_SEV_FEAT_DEBUG_SWAP BIT(5) -#define SVM_SEV_FEAT_SECURE_TSC BIT(9) +#define SVM_SEV_FEAT_SNP_ACTIVE BIT_ULL(0) +#define SVM_SEV_FEAT_RESTRICTED_INJECTION BIT_ULL(3) +#define SVM_SEV_FEAT_ALTERNATE_INJECTION BIT_ULL(4) +#define SVM_SEV_FEAT_DEBUG_SWAP BIT_ULL(5) +#define SVM_SEV_FEAT_SECURE_TSC BIT_ULL(9)#define VMCB_ALLOWED_SEV_FEATURES_VALID BIT_ULL(63)
Signature · 1 line
2.43.0
PATCH v5 4/8 KVM: selftests: sev_init2: Use BIT_ULL for VMSA feature bit definition
In reply to Kim PhillipsSVM_SEV_FEAT_DEBUG_SWAP was defined as 32u, a 32-bit unsigned literal. The kernel's supported_vmsa_features is a u64 and uses BIT(5) for this feature. Redefine the selftest macro with BIT_ULL(5) to match that 64-bit semantic and the BIT_ULL(n) form used by the additional feature bits introduced later in this series, so every feature-bit definition in the file is uniformly 64-bit wide. The value is unchanged (0x20); this is a width/consistency cleanup only.
--- tools/testing/selftests/kvm/x86/sev_init2_tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/x86/sev_init2_tests.c +1 -1
@@ -13,7 +13,7 @@#include "svm_util.h" #include "kselftest.h" -#define SVM_SEV_FEAT_DEBUG_SWAP 32u +#define SVM_SEV_FEAT_DEBUG_SWAP BIT_ULL(5)/* * Some features may have hidden dependencies, or may only work
Signature · 1 line
2.43.0
PATCH v5 5/8 KVM: SEV: Disallow setting SNP-only features for non-SNP guests via a single mask
In reply to Kim PhillipsAs SNP-only features get added, adding them to the valid_vmsa_features mask in __sev_guest_init() often gets neglected. Add SVM_SEV_FEAT_SNP_ONLY_MASK to help group these common features together.
Also establish SNP_ONLY_FEATURES in the sev_init2 selftest as the corresponding mask for features that must be rejected for non-SNP guests, populate it with SVM_SEV_FEAT_SECURE_TSC, and exercise the rejection path by masking those bits out of the features passed for SEV-ES guests. Define the selftest's SNP_ONLY_FEATURES as ULL so future bits can use BIT_ULL() there without truncation against the u64 supported_vmsa_features.
--- arch/x86/include/asm/svm.h | 2 ++ arch/x86/kvm/svm/sev.c | 2 +- tools/testing/selftests/kvm/x86/sev_init2_tests.c | 12 +++++++----- 3 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/include/asm/svm.h +2 -0
@@ -311,6 +311,8 @@ static_assert((X2AVIC_4K_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AV#define SVM_SEV_FEAT_DEBUG_SWAP BIT_ULL(5)#define SVM_SEV_FEAT_SECURE_TSC BIT_ULL(9) +#define SVM_SEV_FEAT_SNP_ONLY_MASK (SVM_SEV_FEAT_SECURE_TSC) +#define VMCB_ALLOWED_SEV_FEATURES_VALID BIT_ULL(63)struct vmcb_seg {
arch/x86/kvm/svm/sev.c +1 -1
@@ -506,7 +506,7 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,return -EINVAL ;if (!snp_active) - valid_vmsa_features &= ~SVM_SEV_FEAT_SECURE_TSC ; + valid_vmsa_features &= ~SVM_SEV_FEAT_SNP_ONLY_MASK ;if (data->vmsa_features & ~valid_vmsa_features)return -EINVAL ;
tools/testing/selftests/kvm/x86/sev_init2_tests.c +7 -5
@@ -14,16 +14,18 @@#include "kselftest.h" #define SVM_SEV_FEAT_DEBUG_SWAP BIT_ULL(5) +#define SVM_SEV_FEAT_SECURE_TSC BIT_ULL(9) + +/* Features valid only for SNP guests, rejected for SEV-ES and below. */ +#define SNP_ONLY_FEATURES (SVM_SEV_FEAT_SECURE_TSC)/* * Some features may have hidden dependencies, or may only work * for certain VM types. Err on the side of safety and don't * expect that all supported features can be passed one by one * to KVM_SEV_INIT2. -* -* (Well, right now there's only one...) */ -#define KNOWN_FEATURES SVM_SEV_FEAT_DEBUG_SWAP +#define KNOWN_FEATURES (SVM_SEV_FEAT_DEBUG_SWAP | SNP_ONLY_FEATURES)int kvm_fd;u64 supported_vmsa_features;
@@ -108,7 +110,7 @@ void test_features(u32 vm_type, u64 supported_features)if (!(supported_features &BIT_ULL (i)))test_init2_invalid (vm_type, &(struct kvm_sev_init ){ .vmsa_features =BIT_ULL (i) }, -"unknown feature" ); +"unknown or unsupported feature for VM type" );else if (KNOWN_FEATURES &BIT_ULL (i))test_init2 (vm_type, &(struct kvm_sev_init ){ .vmsa_features =BIT_ULL (i) });
@@ -157,7 +159,7 @@ int main(int argc, char *argv[])test_features (KVM_X86_SEV_VM ,0 );if (have_sev_es) -test_features (KVM_X86_SEV_ES_VM , supported_vmsa_features); +test_features (KVM_X86_SEV_ES_VM , supported_vmsa_features & ~SNP_ONLY_FEATURES );if (have_snp)test_features (KVM_X86_SNP_VM , supported_vmsa_features);
Signature · 1 line
2.43.0
PATCH v5 6/8 KVM: SEV: Advertise SVM_SEV_FEAT_SNP_ACTIVE
In reply to Kim PhillipsAllow userspace to set the feature in kvm_sev_init.vmsa_features.
KVM still needs to set the flag for backwards compatibility, but disallowing SVM_SEV_FEAT_SNP_ACTIVE for an SNP guest is "bizarre."
--- arch/x86/include/asm/svm.h | 3 ++- arch/x86/kvm/svm/sev.c | 8 ++++++-- tools/testing/selftests/kvm/x86/sev_init2_tests.c | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-)
arch/x86/include/asm/svm.h +2 -1
@@ -311,7 +311,8 @@ static_assert((X2AVIC_4K_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AV#define SVM_SEV_FEAT_DEBUG_SWAP BIT_ULL(5)#define SVM_SEV_FEAT_SECURE_TSC BIT_ULL(9) -#define SVM_SEV_FEAT_SNP_ONLY_MASK (SVM_SEV_FEAT_SECURE_TSC) +#define SVM_SEV_FEAT_SNP_ONLY_MASK (SVM_SEV_FEAT_SNP_ACTIVE | \ + SVM_SEV_FEAT_SECURE_TSC)#define VMCB_ALLOWED_SEV_FEATURES_VALID BIT_ULL(63)
arch/x86/kvm/svm/sev.c +6 -2
@@ -3257,8 +3257,12 @@ void __init sev_hardware_setup(void) cpu_feature_enabled(X86_FEATURE_NO_NESTED_DATA_BP)) sev_supported_vmsa_features |=SVM_SEV_FEAT_DEBUG_SWAP ; -if (sev_snp_enabled && tsc_khz &&cpu_feature_enabled (X86_FEATURE_SNP_SECURE_TSC )) - sev_supported_vmsa_features |=SVM_SEV_FEAT_SECURE_TSC ; +if (sev_snp_enabled) { + sev_supported_vmsa_features |=SVM_SEV_FEAT_SNP_ACTIVE ; + +if (tsc_khz &&cpu_feature_enabled (X86_FEATURE_SNP_SECURE_TSC )) + sev_supported_vmsa_features |=SVM_SEV_FEAT_SECURE_TSC ; + } }void sev_hardware_unsetup (void )
tools/testing/selftests/kvm/x86/sev_init2_tests.c +3 -1
@@ -13,11 +13,13 @@#include "svm_util.h" #include "kselftest.h" +#define SVM_SEV_FEAT_SNP_ACTIVE BIT_ULL(0)#define SVM_SEV_FEAT_DEBUG_SWAP BIT_ULL(5)#define SVM_SEV_FEAT_SECURE_TSC BIT_ULL(9)/* Features valid only for SNP guests, rejected for SEV-ES and below. */ -#define SNP_ONLY_FEATURES (SVM_SEV_FEAT_SECURE_TSC) +#define SNP_ONLY_FEATURES (SVM_SEV_FEAT_SNP_ACTIVE | \ + SVM_SEV_FEAT_SECURE_TSC)/* * Some features may have hidden dependencies, or may only work
Signature · 1 line
2.43.0
PATCH v5 7/8 KVM: SEV: Add support for IBPB-on-Entry
In reply to Kim PhillipsAMD EPYC 5th generation and above processors support IBPB-on-Entry for SNP guests, while 3rd and 4th generation processors can via microcode patches. By invoking an Indirect Branch Prediction Barrier (IBPB) on VMRUN, old indirect branch predictions are prevented from influencing indirect branches within the guest.
SNP guests may choose to enable IBPB-on-Entry by setting SEV_FEATURES bit 21 (IbpbOnEntry).
Host support for IBPB on Entry is indicated by CPUID Fn8000_001F_EAX[IbpbOnEntry], bit 31.
If supported, indicate support for IBPB on Entry in sev_supported_vmsa_features bit 21 (IbpbOnEntry).
Also add SVM_SEV_FEAT_IBPB_ON_ENTRY to the sev_init2 selftest's SNP_ONLY_FEATURES and KNOWN_FEATURES to validate it is accepted for SNP guests and rejected for SEV-ES.
For more info, refer to page 615, Section 15.36.17 "Side-Channel Protection", AMD64 Architecture Programmer's Manual Volume 2: System Programming Part 2, Pub. 24593 Rev. 3.42 - March 2024 (see Link).
--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/svm.h | 4 +++- arch/x86/kvm/svm/sev.c | 3 +++ tools/arch/x86/include/asm/cpufeatures.h | 1 + tools/testing/selftests/kvm/x86/sev_init2_tests.c | 4 +++- 5 files changed, 11 insertions(+), 2 deletions(-)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -472,6 +472,7 @@#define X86_FEATURE_ALLOWED_SEV_FEATURES (19*32+27)/* Allowed SEV Features */ #define X86_FEATURE_SVSM (19*32+28)/* "svsm" SVSM present */ #define X86_FEATURE_HV_INUSE_WR_ALLOWED (19*32+30)/* Allow Write to in-use hypervisor-owned pages */ +#define X86_FEATURE_SNP_IBPB_ON_ENTRY (19*32+31)/* SEV-SNP IBPB on VM Entry */ /* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* No Nested Data Breakpoints */
arch/x86/include/asm/svm.h +3 -1
@@ -310,9 +310,11 @@ static_assert((X2AVIC_4K_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AV#define SVM_SEV_FEAT_ALTERNATE_INJECTION BIT_ULL(4)#define SVM_SEV_FEAT_DEBUG_SWAP BIT_ULL(5)#define SVM_SEV_FEAT_SECURE_TSC BIT_ULL(9) +#define SVM_SEV_FEAT_IBPB_ON_ENTRY BIT_ULL(21)#define SVM_SEV_FEAT_SNP_ONLY_MASK (SVM_SEV_FEAT_SNP_ACTIVE | \ - SVM_SEV_FEAT_SECURE_TSC) + SVM_SEV_FEAT_SECURE_TSC | \ + SVM_SEV_FEAT_IBPB_ON_ENTRY)#define VMCB_ALLOWED_SEV_FEATURES_VALID BIT_ULL(63)
arch/x86/kvm/svm/sev.c +3 -0
@@ -3262,6 +3262,9 @@ void __init sev_hardware_setup(void)if (tsc_khz &&cpu_feature_enabled (X86_FEATURE_SNP_SECURE_TSC )) sev_supported_vmsa_features |=SVM_SEV_FEAT_SECURE_TSC ; + +if (cpu_feature_enabled (X86_FEATURE_SNP_IBPB_ON_ENTRY )) + sev_supported_vmsa_features |=SVM_SEV_FEAT_IBPB_ON_ENTRY ; } }
tools/arch/x86/include/asm/cpufeatures.h +1 -0
@@ -460,6 +460,7 @@#define X86_FEATURE_ALLOWED_SEV_FEATURES (19*32+27)/* Allowed SEV Features */ #define X86_FEATURE_SVSM (19*32+28)/* "svsm" SVSM present */ #define X86_FEATURE_HV_INUSE_WR_ALLOWED (19*32+30)/* Allow Write to in-use hypervisor-owned pages */ +#define X86_FEATURE_SNP_IBPB_ON_ENTRY (19*32+31)/* SEV-SNP IBPB on VM Entry */ /* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* No Nested Data Breakpoints */
tools/testing/selftests/kvm/x86/sev_init2_tests.c +3 -1
@@ -16,10 +16,12 @@#define SVM_SEV_FEAT_SNP_ACTIVE BIT_ULL(0)#define SVM_SEV_FEAT_DEBUG_SWAP BIT_ULL(5)#define SVM_SEV_FEAT_SECURE_TSC BIT_ULL(9) +#define SVM_SEV_FEAT_IBPB_ON_ENTRY BIT_ULL(21)/* Features valid only for SNP guests, rejected for SEV-ES and below. */ #define SNP_ONLY_FEATURES (SVM_SEV_FEAT_SNP_ACTIVE | \ - SVM_SEV_FEAT_SECURE_TSC) + SVM_SEV_FEAT_SECURE_TSC | \ + SVM_SEV_FEAT_IBPB_ON_ENTRY)/* * Some features may have hidden dependencies, or may only work
Signature · 1 line
2.43.0
PATCH v5 8/8 KVM: SEV: Add support for SNP BTB Isolation
In reply to Kim PhillipsAdvertise support for BTB Isolation via SEV_VMSA_FEATURES when SNP is enabled. BTB Isolation is an optional feature that can be enabled by the guest to ensure its guest Branch Target Buffers (BTBs) are not affected by any context outside that guest.
SNP-active guests may choose to enable the Branch Target Buffer Isolation mode through SEV_FEATURES bit 7 (BTBIsolation).
Unlike the sibling features advertised here (Secure TSC, IBPB-on-Entry), BTB Isolation is advertised unconditionally. This is deliberate, not an
oversight: the AMD64 APM (Vol. 2, Section 15.36.17 "Side-Channel Protection") defines BTB Isolation as architecturally present on every SEV-SNP-capable processor. There is therefore no host enumeration bit for it (no CPUID leaf or MSR capability), by design -- unlike IBPB-on-Entry, whose host support is enumerated via
CPUID Fn8000_001F[IbpbOnEntry] bit 31 precisely because it is not universal. A per-feature host gate is thus neither possible nor meaningful; if SNP is supported, BTB Isolation is present.
Nor does the guest have to take the host's word for it. SEV_FEATURES is written into the VMSA by sev_es_sync_vmsa() and measured by SNP_LAUNCH_UPDATE with SNP_PAGE_TYPE_VMSA, so bit 7 is covered by the launch measurement and appears in the attestation report. At runtime the guest can additionally read the active state from SEV_STATUS bit 9 (MSR_AMD64_SNP_BTB_ISOLATION, dumped as "BTBIsol" by sev_status_feat_names[] in arch/x86/coco/sev/core.c). A guest requiring BTB Isolation can therefore confirm it is active rather than trusting what the host advertised.
Also add SVM_SEV_FEAT_BTB_ISOLATION to the sev_init2 selftest's SNP_ONLY_FEATURES and KNOWN_FEATURES to validate it is accepted for SNP guests and rejected for SEV-ES.
For more info, refer to page 615, Section 15.36.17 "Side-Channel Protection", AMD64 Architecture Programmer's Manual Volume 2: System Programming Part 2, Pub. 24593 Rev. 3.42 - March 2024 (see Link).
--- arch/x86/include/asm/svm.h | 2 ++ arch/x86/kvm/svm/sev.c | 8 ++++++++ tools/testing/selftests/kvm/x86/sev_init2_tests.c | 2 ++ 3 files changed, 12 insertions(+)
arch/x86/include/asm/svm.h +2 -0
@@ -309,10 +309,12 @@ static_assert((X2AVIC_4K_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AV#define SVM_SEV_FEAT_RESTRICTED_INJECTION BIT_ULL(3)#define SVM_SEV_FEAT_ALTERNATE_INJECTION BIT_ULL(4)#define SVM_SEV_FEAT_DEBUG_SWAP BIT_ULL(5) +#define SVM_SEV_FEAT_BTB_ISOLATION BIT_ULL(7)#define SVM_SEV_FEAT_SECURE_TSC BIT_ULL(9)#define SVM_SEV_FEAT_IBPB_ON_ENTRY BIT_ULL(21)#define SVM_SEV_FEAT_SNP_ONLY_MASK (SVM_SEV_FEAT_SNP_ACTIVE | \ + SVM_SEV_FEAT_BTB_ISOLATION | \ SVM_SEV_FEAT_SECURE_TSC | \ SVM_SEV_FEAT_IBPB_ON_ENTRY)
arch/x86/kvm/svm/sev.c +8 -0
@@ -3260,6 +3260,14 @@ void __init sev_hardware_setup(void)if (sev_snp_enabled) { sev_supported_vmsa_features |=SVM_SEV_FEAT_SNP_ACTIVE ; +/* +* Unlike Secure TSC and IBPB-on-Entry below, BTB Isolation has +* no host enumeration bit to gate on: the APM defines it as +* architecturally present on every SEV-SNP-capable processor. +* If SNP is supported, BTB Isolation is available. +*/ + sev_supported_vmsa_features |=SVM_SEV_FEAT_BTB_ISOLATION ; +if (tsc_khz &&cpu_feature_enabled (X86_FEATURE_SNP_SECURE_TSC )) sev_supported_vmsa_features |=SVM_SEV_FEAT_SECURE_TSC ;
tools/testing/selftests/kvm/x86/sev_init2_tests.c +2 -0
@@ -15,11 +15,13 @@#define SVM_SEV_FEAT_SNP_ACTIVE BIT_ULL(0)#define SVM_SEV_FEAT_DEBUG_SWAP BIT_ULL(5) +#define SVM_SEV_FEAT_BTB_ISOLATION BIT_ULL(7)#define SVM_SEV_FEAT_SECURE_TSC BIT_ULL(9)#define SVM_SEV_FEAT_IBPB_ON_ENTRY BIT_ULL(21)/* Features valid only for SNP guests, rejected for SEV-ES and below. */ #define SNP_ONLY_FEATURES (SVM_SEV_FEAT_SNP_ACTIVE | \ + SVM_SEV_FEAT_BTB_ISOLATION | \ SVM_SEV_FEAT_SECURE_TSC | \ SVM_SEV_FEAT_IBPB_ON_ENTRY)
Signature · 1 line
2.43.0