]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: SEV: WARN on unhandled VM type when initializing VM
authorSean Christopherson <seanjc@google.com>
Tue, 10 Mar 2026 23:48:20 +0000 (16:48 -0700)
committerSean Christopherson <seanjc@google.com>
Thu, 9 Apr 2026 19:00:17 +0000 (12:00 -0700)
WARN if KVM encounters an unhandled VM type when setting up flags for SEV+
VMs, e.g. to guard against adding a new flavor of SEV without adding proper
recognition in sev_vm_init().

Practically speaking, no functional change intended (the new "default" case
should be unreachable).

Link: https://patch.msgid.link/20260310234829.2608037-13-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/sev.c

index 4df0f17da3e220b02b220607ca47c9f98fad8ccb..015d102b32d90fdd9edf0fef104838ab46ad5054 100644 (file)
@@ -2927,17 +2927,24 @@ static int snp_decommission_context(struct kvm *kvm)
 
 void sev_vm_init(struct kvm *kvm)
 {
-       int type = kvm->arch.vm_type;
-
-       if (type == KVM_X86_DEFAULT_VM || type == KVM_X86_SW_PROTECTED_VM)
-               return;
-
-       kvm->arch.has_protected_state = (type == KVM_X86_SEV_ES_VM ||
-                                        type == KVM_X86_SNP_VM);
-       to_kvm_sev_info(kvm)->need_init = true;
-
-       kvm->arch.has_private_mem = (type == KVM_X86_SNP_VM);
-       kvm->arch.pre_fault_allowed = !kvm->arch.has_private_mem;
+       switch (kvm->arch.vm_type) {
+       case KVM_X86_DEFAULT_VM:
+       case KVM_X86_SW_PROTECTED_VM:
+               break;
+       case KVM_X86_SNP_VM:
+               kvm->arch.has_private_mem = true;
+               fallthrough;
+       case KVM_X86_SEV_ES_VM:
+               kvm->arch.has_protected_state = true;
+               fallthrough;
+       case KVM_X86_SEV_VM:
+               kvm->arch.pre_fault_allowed = !kvm->arch.has_private_mem;
+               to_kvm_sev_info(kvm)->need_init = true;
+               break;
+       default:
+               WARN_ONCE(1, "Unsupported VM type %u", kvm->arch.vm_type);
+               break;
+       }
 }
 
 void sev_vm_destroy(struct kvm *kvm)