aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/mmu.h
diff options
context:
space:
mode:
authorBen Gardon <bgardon@google.com>2021-05-18 10:34:14 -0700
committerPaolo Bonzini <pbonzini@redhat.com>2021-06-17 13:09:27 -0400
commitd501f747ef5c0ac0c917f9a6781d04ae4ae39d63 (patch)
tree4e083219aaff30031d8df1fb0463279ba0cba222 /arch/x86/kvm/mmu.h
parentKVM: x86/mmu: Skip rmap operations if rmaps not allocated (diff)
downloadlinux-dev-d501f747ef5c0ac0c917f9a6781d04ae4ae39d63.tar.xz
linux-dev-d501f747ef5c0ac0c917f9a6781d04ae4ae39d63.zip
KVM: x86/mmu: Lazily allocate memslot rmaps
If the TDP MMU is in use, wait to allocate the rmaps until the shadow MMU is actually used. (i.e. a nested VM is launched.) This saves memory equal to 0.2% of guest memory in cases where the TDP MMU is used and there are no nested guests involved. Signed-off-by: Ben Gardon <bgardon@google.com> Message-Id: <20210518173414.450044-8-bgardon@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/mmu.h')
-rw-r--r--arch/x86/kvm/mmu.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index af09c47b1aa2..9d8550af994c 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -234,7 +234,12 @@ void kvm_mmu_pre_destroy_vm(struct kvm *kvm);
static inline bool kvm_memslots_have_rmaps(struct kvm *kvm)
{
- return kvm->arch.memslots_have_rmaps;
+ /*
+ * Read memslot_have_rmaps before rmap pointers. Hence, threads reading
+ * memslots_have_rmaps in any lock context are guaranteed to see the
+ * pointers. Pairs with smp_store_release in alloc_all_memslots_rmaps.
+ */
+ return smp_load_acquire(&kvm->arch.memslots_have_rmaps);
}
#endif