Re: [PATCH 12/21] KVM: SEV: WARN on unhandled VM type when initializing VM

From: Yan Zhao

Date: Thu Apr 09 2026 - 01:52:05 EST


On Tue, Mar 10, 2026 at 04:48:20PM -0700, Sean Christopherson wrote:
> 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).
>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> ---
> arch/x86/kvm/svm/sev.c | 29 ++++++++++++++++++-----------
> 1 file changed, 18 insertions(+), 11 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index e5dae76d2986..9a907bc057d0 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2930,17 +2930,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 %lu", kvm->arch.vm_type);
After pulling the latest kvm-x86/next, I encountered this compilation warning:
"arch/x86/kvm/svm/sev.c:2954:30: error: format %lu expects argument of type long
unsigned int, but argument 2 has type int [-Werror=format=]",

So,

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 75d0c03d69bc..ca09c06d1e80 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -2951,7 +2951,7 @@ void sev_vm_init(struct kvm *kvm)
to_kvm_sev_info(kvm)->need_init = true;
break;
default:
- WARN_ONCE(1, "Unsupported VM type %lu", kvm->arch.vm_type);
+ WARN_ONCE(1, "Unsupported VM type %u", kvm->arch.vm_type);
break;
}
}


> + break;
> + }
> }
>
> void sev_vm_destroy(struct kvm *kvm)
> --
> 2.53.0.473.g4a7958ca14-goog
>
>