From: Sean Christopherson <seanjc@google.com>
To: Kai Huang <kai.huang@intel.com>
Cc: "vipinsh@google.com" <vipinsh@google.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/3] KVM: x86: Allocate kvm_vmx/kvm_svm structures using kzalloc()
Date: Thu, 24 Apr 2025 11:31:03 -0700 [thread overview]
Message-ID: <aAqDZ_QEdL5RhAOz@google.com> (raw)
In-Reply-To: <8e64fb0f97479ea237d2dba459b095b1c7281006.camel@intel.com>
On Wed, Apr 23, 2025, Kai Huang wrote:
> On Wed, 2025-04-23 at 10:07 -0700, Sean Christopherson wrote:
> > On Tue, Apr 22, 2025, Kai Huang wrote:
> > > On Wed, 2025-04-16 at 12:57 -0700, Sean Christopherson wrote:
> > > > On Wed, Apr 16, 2025, Vipin Sharma wrote:
> > > > > 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?
> >
> > If it helps, here's the changelog I plan on posting for v3:
> >
> > Allocate VM structs via kvzalloc(), i.e. try to use a contiguous physical
> > allocation before falling back to __vmalloc(), to avoid the overhead of
> > establishing the virtual mappings. The SVM and VMX (and TDX) structures
> > are now just above 4096 bytes, i.e. are order-1 allocations, and will
> > likely remain that way for quite some time.
> >
> > Add compile-time assertions in vendor code to ensure the size is an
> > order-0 or order-1 allocation, i.e. to prevent unknowingly letting the
> > size balloon in the future. There's nothing fundamentally wrong with a
> > larger kvm_{svm,vmx,tdx} size, but given that the size is barely above
> > 4096 after 18+ years of existence, exceeding exceed 8192 bytes would be
> > quite notable.
>
> Yeah looks reasonable.
>
> Nit: I am not quite following "falling back to __vmalloc()" part. We are
> replacing __vmalloc() with kzalloc() AFAICT, therefore there should be no
> "falling back"?
Correct, not in this version. In the next version, my plan is to use kvzalloc()
(though honestly, I'm not sure that's worth doing; it'll be an order-1 allocation,
and if that fails...).
next prev parent reply other threads:[~2025-04-24 18:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-01 15:57 [PATCH v2 0/3] KVM: x86: Dynamically allocate hashed page list Sean Christopherson
2025-04-01 15:57 ` [PATCH v2 1/3] KVM: x86/mmu: Dynamically allocate shadow MMU's " Sean Christopherson
2025-04-16 15:53 ` Vipin Sharma
2025-04-01 15:57 ` [PATCH v2 2/3] KVM: x86: Allocate kvm_vmx/kvm_svm structures using kzalloc() Sean Christopherson
2025-04-16 18:24 ` Vipin Sharma
2025-04-16 19:06 ` Vipin Sharma
2025-04-16 19:57 ` Sean Christopherson
2025-04-22 22:53 ` Huang, Kai
2025-04-23 17:07 ` Sean Christopherson
2025-04-23 21:46 ` Huang, Kai
2025-04-24 18:31 ` Sean Christopherson [this message]
2025-04-01 15:57 ` [PATCH v2 3/3] KVM: x86/mmu: Defer allocation of shadow MMU's hashed page list Sean Christopherson
2025-04-15 20:06 ` Vipin Sharma
2025-04-15 21:52 ` Sean Christopherson
2025-04-22 0:24 ` Sean Christopherson
2025-04-25 17:45 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aAqDZ_QEdL5RhAOz@google.com \
--to=seanjc@google.com \
--cc=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=vipinsh@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.