[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8a58261a0cc5f7927177178d65b0f0b3fa1f173c.camel@intel.com>
Date: Tue, 22 Apr 2025 22:53:38 +0000
From: "Huang, Kai" <kai.huang@...el.com>
To: "vipinsh@...gle.com" <vipinsh@...gle.com>, "seanjc@...gle.com"
<seanjc@...gle.com>
CC: "kvm@...r.kernel.org" <kvm@...r.kernel.org>, "pbonzini@...hat.com"
<pbonzini@...hat.com>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 2/3] KVM: x86: Allocate kvm_vmx/kvm_svm structures
using kzalloc()
On Wed, 2025-04-16 at 12:57 -0700, Sean Christopherson wrote:
> On Wed, Apr 16, 2025, Vipin Sharma wrote:
> > On 2025-04-16 11:24:37, Vipin Sharma wrote:
> > > On 2025-04-01 08:57:13, Sean Christopherson wrote:
> > > >
> > > > + BUILD_BUG_ON(get_order(sizeof(struct kvm_svm) != 0));
> > >
> > > There is a typo here. It is checking sizeof(struct kvm_svm) != 0, instead
> > > of checking get_order(...) != 0.
> > >
> > > > return 0;
> > > >
> > > > err_kvm_init:
> > > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> > > > index b70ed72c1783..01264842bf45 100644
> > > > --- a/arch/x86/kvm/vmx/vmx.c
> > > > +++ b/arch/x86/kvm/vmx/vmx.c
> > > > @@ -8755,6 +8755,7 @@ static int __init vmx_init(void)
> > > > if (r)
> > > > goto err_kvm_init;
> > > >
> > > > + BUILD_BUG_ON(get_order(sizeof(struct kvm_vmx) != 0));
> > >
> > > Same as above.
>
> Ugh. That's what I get for violating the kernel's "don't check for '0'" rule
> (I thought it would make the code more understandable). Bad me.
>
> > After fixing the typo build is failing.
> >
> > Checked via pahole, sizes of struct have reduced but still not under 4k.
> > After applying the patch:
> >
> > struct kvm{} - 4104
> > struct kvm_svm{} - 4320
> > struct kvm_vmx{} - 4128
> >
> > Also, this BUILD_BUG_ON() might not be reliable unless all of the ifdefs
> > under kvm_[vmx|svm] and its children are enabled. Won't that be an
> > issue?
>
> That's what build bots (and to a lesser extent, maintainers) are for. An individual
> developer might miss a particular config, but the build bots that run allyesconfig
> will very quickly detect the issue, and then we fix it.
>
> I also build what is effectively an "allkvmconfig" before officially applying
> anything, so in general things like this shouldn't even make it to the bots.
>
Just want to understand the intention here:
What if someday a developer really needs to add some new field(s) to, lets say
'struct kvm_vmx', and that makes the size exceed 4K?
What should the developer do? Is it a hard requirement that the size should
never go beyond 4K? Or, should the assert of order 0 allocation be changed to
the assert of order 1 allocation?
Powered by blists - more mailing lists