KVM: x86/mmu: handle cmpxchg failure in kvm_tdp_mmu_get_root
authorBen Gardon <bgardon@google.com>
Thu, 1 Apr 2021 23:37:30 +0000 (16:37 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 19 Apr 2021 13:05:25 +0000 (09:05 -0400)
commitfb10129335ca6cc7a229226b03f54394757d773d
treed52fd20442893820e085ba32230b948ca2a7c3e4
parent11cccf5c04721c8a08f9d72a1a5e7281a4041d86
KVM: x86/mmu: handle cmpxchg failure in kvm_tdp_mmu_get_root

To reduce dependence on the MMU write lock, don't rely on the assumption
that the atomic operation in kvm_tdp_mmu_get_root will always succeed.
By not relying on that assumption, threads do not need to hold the MMU
lock in write mode in order to take a reference on a TDP MMU root.

In the root iterator, this change means that some roots might have to be
skipped if they are found to have a zero refcount. This will still never
happen as of this patch, but a future patch will need that flexibility to
make the root iterator safe under the MMU read lock.

Signed-off-by: Ben Gardon <bgardon@google.com>
Message-Id: <20210401233736.638171-8-bgardon@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/tdp_mmu.c
arch/x86/kvm/mmu/tdp_mmu.h