[PATCH 18/16] KVM: SVM: Bound the SNP plane count by the architectural VMPL limit

David Woodhouse dwmw2 at infradead.org
Thu Nov 12 16:29:48 PST 2026


From: David Woodhouse <dwmw at amazon.co.uk>

sev_snp_max_planes() reports the VMPL count straight from CPUID
0x8000001f EBX[15:12], a 4-bit field the host provides. A value above
four lets userspace create SNP planes that no VMPL switch can ever
reach, because the switch already refuses a VMPL at or above
SVM_SEV_VMPL_MAX.

Clamp the count to between one and SVM_SEV_VMPL_MAX, so that a
VM's plane count never exceeds what the architecture defines.

Fixes the plane count in "kvm: svm: Implement max_planes x86
operation".

Fixes: https://lore.kernel.org/all/20260608144252.351443-60-joro@8bytes.org/
Signed-off-by: David Woodhouse <dwmw at amazon.co.uk>
---
 arch/x86/kvm/svm/sev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index c8a9f808dcc4..eefa8641100b 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -6010,8 +6010,10 @@ bool sev_snp_blocked(enum inject_type type, struct kvm_vcpu *vcpu)
 int sev_snp_max_planes(struct kvm *kvm)
 {
 	/*
-	 * CPUID 0x8000001f EBX[15:12] is host-provided data; a zero there
-	 * must not report "no planes at all" (plane 0 always exists).
+	 * CPUID 0x8000001f EBX[15:12] is host-provided data.  A zero there
+	 * must not report "no planes at all" (plane 0 always exists), and
+	 * the architecture defines no more than SVM_SEV_VMPL_MAX VMPLs, the
+	 * bound the VMPL switch already enforces.
 	 */
-	return max(vmpl_levels, 1U);
+	return clamp(vmpl_levels, 1U, SVM_SEV_VMPL_MAX);
 }
-- 
2.50.1




More information about the kvm-riscv mailing list