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

From: Yan Zhao

Date: Fri Apr 10 2026 - 04:35:01 EST


On Thu, Apr 09, 2026 at 11:48:28AM -0700, Sean Christopherson wrote:
> On Thu, Apr 09, 2026, Yan Zhao wrote:
> > On Tue, Mar 10, 2026 at 04:48:20PM -0700, Sean Christopherson wrote:
> > > + 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;
> > }
> > }
>
> I'll squash the above.
>
> How did you find this? E.g. did you cherry pick the commits into a different
I just pulled the tag kvm-x86-next-2026.04.04, and compiled it with
"CONFIG_KVM_WERROR=y && CONFIG_BUG=n".

> tree or something? AFAICT, thanks to commit 11bb4944f014 ("x86/bug: Implement
> WARN_ONCE()"), WARN() and WARN_ONCE() currently don't have any validation of
> the format. I posted a patch to address that gap[*], but it's driving me crazy
> that I can't reproduce the issue without explicitly removing the definition of
> HAVE_ARCH_BUG_FORMAT_ARGS. :-)
I think it's because CONFIG_GENERIC_BUG relies on CONFIG_BUG, so when
CONFIG_BUG=n, CONFIG_GENERIC_BUG=n and HAVE_ARCH_BUG_FORMAT_ARGS is undefined.

So, in my env, the WARN_ONCE() defined in include/asm-generic/bug.h under
!CONFIG_BUG was used, which is:

#ifndef WARN
#define WARN(condition, format...) ({ \
int __ret_warn_on = !!(condition); \
no_printk(format); \
unlikely(__ret_warn_on); \
})
#endif

#define WARN_ONCE(condition, format...) WARN(condition, format)

If I turn CONFIG_BUG=y, then WARN_ONCE() defined in arch/x86/include/asm/bug.h
under HAVE_ARCH_BUG_FORMAT_ARGS is effective, and then I also need [*] to
trigger the reported error :)

> [*] https://lore.kernel.org/all/20260409182941.1912856-1-seanjc@xxxxxxxxxx