diff options
author | Ben Gardon <bgardon@google.com> | 2021-04-01 16:37:30 -0700 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2021-04-19 09:05:25 -0400 |
commit | fb10129335ca6cc7a229226b03f54394757d773d (patch) | |
tree | d52fd20442893820e085ba32230b948ca2a7c3e4 /arch/x86/kvm/mmu/tdp_mmu.h | |
parent | 11cccf5c04721c8a08f9d72a1a5e7281a4041d86 (diff) | |
download | lwn-fb10129335ca6cc7a229226b03f54394757d773d.tar.gz lwn-fb10129335ca6cc7a229226b03f54394757d773d.zip |
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>
Diffstat (limited to 'arch/x86/kvm/mmu/tdp_mmu.h')
-rw-r--r-- | arch/x86/kvm/mmu/tdp_mmu.h | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h index 0fc9061ff2d8..25268c4ba03b 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.h +++ b/arch/x86/kvm/mmu/tdp_mmu.h @@ -7,17 +7,10 @@ hpa_t kvm_tdp_mmu_get_vcpu_root_hpa(struct kvm_vcpu *vcpu); -static inline void kvm_tdp_mmu_get_root(struct kvm *kvm, - struct kvm_mmu_page *root) +__must_check static inline bool kvm_tdp_mmu_get_root(struct kvm *kvm, + struct kvm_mmu_page *root) { - lockdep_assert_held_write(&kvm->mmu_lock); - - /* - * This should never fail since roots are removed from the roots - * list under the MMU write lock when their reference count falls - * to zero. - */ - refcount_inc_not_zero(&root->tdp_mmu_root_count); + return refcount_inc_not_zero(&root->tdp_mmu_root_count); } void kvm_tdp_mmu_put_root(struct kvm *kvm, struct kvm_mmu_page *root); |