]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
KVM: x86: Use kvzalloc() to allocate VM struct
authorSean Christopherson <seanjc@google.com>
Fri, 23 May 2025 00:11:37 +0000 (17:11 -0700)
committerSean Christopherson <seanjc@google.com>
Tue, 24 Jun 2025 19:50:48 +0000 (12:50 -0700)
commitac777fbf064f81b30e21f6d7023b6d0342a3fe1b
treee466f74aa841648a11d2894580f09e9b59dd84b1
parent039ef33e2f9346258fe2bd344f212c645942575e
KVM: x86: Use kvzalloc() to allocate VM struct

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.  For non-debug builds, The SVM and VMX
(and TDX) structures are now just below 7000 bytes in the worst case
scenario (see below), 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 of the
structures, sans the memslot hash tables, are order-0 allocations, i.e.
are less than 4KiB.  There's nothing fundamentally wrong with a larger
kvm_{svm,vmx,tdx} size, but given that the size of the structure (without
the memslots hash tables) is below 2KiB after 18+ years of existence,
more than doubling the size would be quite notable.

Add sanity checks on the memslot hash table sizes, partly to ensure they
aren't resized without accounting for the impact on VM structure size, and
partly to document that the majority of the size of VM structures comes
from the memslots.

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20250523001138.3182794-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/svm/svm.c
arch/x86/kvm/vmx/tdx.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/x86.h