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 v3 0/3] KVM: x86: Dynamically allocate hashed page list
Date: Fri, 16 May 2025 14:54:19 -0700 [thread overview]
Message-ID: <20250516215422.2550669-1-seanjc@google.com> (raw)
Third times a charm! Right? Right!?!?
Allocate the hashed list of shadow pages dynamically (separate from
struct kvm), and on-demand. The hashed list is 32KiB, i.e. absolutely
belongs in a separate allocation, and is worth skipping if KVM isn't
shadowing guest PTEs for the VM.
Side topic #1, a bunch of my measurements from v2 and ealier were "bad",
because I was using a PROVE_LOCKING=y kernel, which significantly inflates
the size of "struct kvm" in particular.
Side topic #2, I have a patch to dynamically allocate the memslots hash
tables (they're very conveniently either 2KiB or 4KiB in size for 64-bit
kernels), but I couldn't convince myself that the complexity is in any way
justified. I did however account for the size of the hash tables in the
assertions, if only to document where a big chunk of the per-VM memory usage
is going.
Side topic #3, AFAIK, DEBUG_KERNEL=n builds are quite rare, so I'm banking
on build bots tripping the assert (I'll also add a DEBUG_KERNEL=n config to
my own testing, probably).
v3:
- Add comments explaining the {READ,WRITE}_ONCE logic, and why it's safe
to set the list outside of mmu_lock. [Vipin]
- Make the assertions actually work. [Vipin]
- Refine the assertions so they (hopefully) won't fail on kernels with
a bunch of debug crud added.
v2:
- https://lore.kernel.org/all/20250401155714.838398-1-seanjc@google.com
- Actually defer allocation when using TDP MMU. [Vipin]
- Free allocation on MMU teardown. [Vipin]
v1: https://lore.kernel.org/all/20250315024010.2360884-1-seanjc@google.com
Sean Christopherson (3):
KVM: x86/mmu: Dynamically allocate shadow MMU's hashed page list
KVM: x86: Use kvzalloc() to allocate VM struct
KVM: x86/mmu: Defer allocation of shadow MMU's hashed page list
arch/x86/include/asm/kvm_host.h | 6 +--
arch/x86/kvm/mmu/mmu.c | 73 ++++++++++++++++++++++++++++++---
arch/x86/kvm/svm/svm.c | 2 +
arch/x86/kvm/vmx/main.c | 2 +
arch/x86/kvm/vmx/vmx.c | 2 +
arch/x86/kvm/x86.c | 5 ++-
arch/x86/kvm/x86.h | 22 ++++++++++
7 files changed, 102 insertions(+), 10 deletions(-)
base-commit: 7ef51a41466bc846ad794d505e2e34ff97157f7f
--
2.49.0.1112.g889b7c5bd8-goog
next reply other threads:[~2025-05-16 21:54 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-16 21:54 Sean Christopherson [this message]
2025-05-16 21:54 ` [PATCH v3 1/3] KVM: x86/mmu: Dynamically allocate shadow MMU's hashed page list Sean Christopherson
2025-05-16 21:54 ` [PATCH v3 2/3] KVM: x86: Use kvzalloc() to allocate VM struct Sean Christopherson
2025-05-17 12:35 ` Paolo Bonzini
2025-05-19 15:39 ` Sean Christopherson
2025-05-20 14:42 ` Paolo Bonzini
2025-05-20 22:49 ` Huang, Kai
2025-05-20 23:11 ` Sean Christopherson
2025-05-20 23:57 ` Huang, Kai
2025-05-21 17:12 ` Sean Christopherson
2025-05-21 22:43 ` Huang, Kai
2025-05-22 13:40 ` Sean Christopherson
2025-05-23 11:31 ` Huang, Kai
2025-05-20 16:15 ` Sean Christopherson
2025-05-16 21:54 ` [PATCH v3 3/3] KVM: x86/mmu: Defer allocation of shadow MMU's hashed page list Sean Christopherson
2025-05-17 12:43 ` Paolo Bonzini
2025-05-19 13:37 ` Sean Christopherson
2025-05-19 15:29 ` James Houghton
2025-05-19 15:51 ` 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=20250516215422.2550669-1-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