KVM: x86/mmu: Check for usable TDP MMU root while holding mmu_lock for read
authorSean Christopherson <seanjc@google.com>
Thu, 11 Jan 2024 02:00:46 +0000 (18:00 -0800)
committerSean Christopherson <seanjc@google.com>
Fri, 23 Feb 2024 00:28:45 +0000 (16:28 -0800)
commitf5238c2a60f1e0eb48ce21037bce6f4781afa37f
tree0c4b42d809c9aea798d8213540c903af985551d7
parentd746182337c205660fd4d8eaa5fdc4f4e8320b9a
KVM: x86/mmu: Check for usable TDP MMU root while holding mmu_lock for read

When allocating a new TDP MMU root, check for a usable root while holding
mmu_lock for read and only acquire mmu_lock for write if a new root needs
to be created.  There is no need to serialize other MMU operations if a
vCPU is simply grabbing a reference to an existing root, holding mmu_lock
for write is "necessary" (spoiler alert, it's not strictly necessary) only
to ensure KVM doesn't end up with duplicate roots.

Allowing vCPUs to get "new" roots in parallel is beneficial to VM boot and
to setups that frequently delete memslots, i.e. which force all vCPUs to
reload all roots.

Link: https://lore.kernel.org/r/20240111020048.844847-7-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/mmu/mmu.c
arch/x86/kvm/mmu/tdp_mmu.c
arch/x86/kvm/mmu/tdp_mmu.h