Skip to contentSkip to conversation

x86/virt: Treat SVM as unsupported when running as an SEV+ guest

PATCH Applied Sean Christopherson 1 participant 2 messages Apr 9 – Apr 13 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/virt: Treat SVM as unsupported when running as an SEV+ guest

When running as an SEV+ guest, treat SVM as unsupported even if CPUID (and other reporting, e.g. MSRs) enumerate support for SVM, as KVM doesn't support nested virtualization within an SEV VM (KVM would need to explicitly share all VMCBs and other assets with the untrusted host), let alone running nested VMs within SEV-ES+ guests (e.g. emulating VMLOAD, VMSAVE, and VMRUN all require access to guest register state). And outside of KVM, there is no in-tree user of SVM enabling.

Arguably, the hypervisor/VMM (e.g. QEMU) should clear SVM from guest CPUID for SEV VMs, especially for SEV-ES+, but super duper technically, it's feasible to run nested VMs in SEV+ guests (with many caveats). More importantly, Linux-as-a-guest has played nice with SVM being advertised to SEV+ guests for a long time.

Treating SVM as unsupported fixes a regression where a clean shutdown of an SEV-ES+ guest degrades into an abrupt termination. Due to a gnarly virtualization hole in SEV-ES (the architecture), where EFER must NOT be intercepted by the hypervisor (because the untrusted hypervisor can't set e.g. EFER.LME on behalf o the guest), the _host's_ EFER.SVME is visible to the guest. Because EFER.SVME must be always '1' while in guest mode, Linux-the-guest sees EFER.SVME=1 even when _its_ EFER.SVME is '0', thinks it has enabled virtualization, and ultimately can cause x86_svm_emergency_disable_virtualization_cpu() to execute STGI to ensure GIF is enabled. Executing STGI _should_ be fine, except Linux is a also wee bit paranoid when running as an SEV-ES guest.

Because L0 sees EFER.SVME=0 for the guest, a well-behaved L0 hypervisor will intercept STGI (to inject #UD), and thus generate a #VC on the STGI. Which, again, should be fine. Unfortunately, vc_check_opcode_bytes() fails to account for STGI and other SVM instructions, throws a fatal error, and triggers a termination request. In a perfect world, the #VC handler would be more forgiving of unknown intercepts, especially when the #VC happened on an instruction with exception fixup. For now, just fix the immediate regression.

Fixes 428afac5a8ea ("KVM: x86: Move bulk of emergency virtualizaton logic to virt subsystem")

---

FYI, I'm going to fast-track this into kvm-x86 vmxon, so that the initial PULL request for 7.1 isn't broken (assuming it survives a day in -next).

 arch/x86/virt/hw.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/virt/hw.c +2 -1
index c898f16fe612..f647557d38ac 100644
@@ -269,7 +269,8 @@ static __init int x86_svm_init(void)
 		.emergency_disable_virtualization_cpu = x86_svm_emergency_disable_virtualization_cpu,
 	};
 
-	if (!cpu_feature_enabled(X86_FEATURE_SVM))
+	if (!cpu_feature_enabled(X86_FEATURE_SVM) ||
+	    cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
 		return -EOPNOTSUPP;
 
 	memcpy(&virt_ops, &svm_ops, sizeof(virt_ops));

base-commit: b89df297a47e641581ee67793592e5c6ae0428f4

Signature · 1 line
2.53.0.1213.gd9a14994de-goog
author Applied
#1 lore raw
Quoted 9 lines · Sean Christopherson

When running as an SEV+ guest, treat SVM as unsupported even if CPUID (and other reporting, e.g. MSRs) enumerate support for SVM, as KVM doesn't support nested virtualization within an SEV VM (KVM would need to explicitly share all VMCBs and other assets with the untrusted host), let alone running nested VMs within SEV-ES+ guests (e.g. emulating VMLOAD, VMSAVE, and VMRUN all require access to guest register state). And outside of KVM, there is no in-tree user of SVM enabling.

[...]

Applied to kvm-x86 vmxon (last week, forgot to send "thanks").

[1/1] x86/virt: Treat SVM as unsupported when running as an SEV+ guest

      https://github.com/kvm-x86/linux/commit/e30aa03d032d

--
https://github.com/kvm-x86/linux/tree/next