From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Vipin Sharma <vipinsh@google.com>
Subject: [PATCH v2 2/3] KVM: x86: Allocate kvm_vmx/kvm_svm structures using kzalloc()
Date: Tue, 1 Apr 2025 08:57:13 -0700 [thread overview]
Message-ID: <20250401155714.838398-3-seanjc@google.com> (raw)
In-Reply-To: <20250401155714.838398-1-seanjc@google.com>
Now that the size of "struct kvm" is less than 2KiB, switch back to using
kzalloc() to allocate the VM structures. Add compile-time assertions in
vendor code to ensure the size is an order-0 allocation, i.e. to prevent
unknowingly letting the size balloon in the future.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/include/asm/kvm_host.h | 2 +-
arch/x86/kvm/svm/svm.c | 1 +
arch/x86/kvm/vmx/vmx.c | 1 +
3 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index e523d7d8a107..6c7fd7db6f11 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1940,7 +1940,7 @@ void kvm_x86_vendor_exit(void);
#define __KVM_HAVE_ARCH_VM_ALLOC
static inline struct kvm *kvm_arch_alloc_vm(void)
{
- return __vmalloc(kvm_x86_ops.vm_size, GFP_KERNEL_ACCOUNT | __GFP_ZERO);
+ return kzalloc(kvm_x86_ops.vm_size, GFP_KERNEL_ACCOUNT);
}
#define __KVM_HAVE_ARCH_VM_FREE
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 8abeab91d329..589adc5f92e0 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -5536,6 +5536,7 @@ static int __init svm_init(void)
if (r)
goto err_kvm_init;
+ BUILD_BUG_ON(get_order(sizeof(struct kvm_svm) != 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));
return 0;
err_kvm_init:
--
2.49.0.472.ge94155a9ec-goog
next prev parent reply other threads:[~2025-04-01 15:57 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 ` Sean Christopherson [this message]
2025-04-16 18:24 ` [PATCH v2 2/3] KVM: x86: Allocate kvm_vmx/kvm_svm structures using kzalloc() 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
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=20250401155714.838398-3-seanjc@google.com \
--to=seanjc@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox