diff options
author | Sean Christopherson <seanjc@google.com> | 2022-02-26 03:15:28 +0300 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2022-03-08 17:31:52 +0300 |
commit | 0e587aa7335588ac5e12ef707f7979ff91b11751 (patch) | |
tree | 832b7a195e3aa0b7989cfab3f5b408bb480b7178 /arch/x86/kvm/mmu/tdp_iter.h | |
parent | a151aceca1e46be1defdaceea7c28108fa0ad022 (diff) | |
download | linux-0e587aa7335588ac5e12ef707f7979ff91b11751.tar.xz |
KVM: x86/mmu: Add helpers to read/write TDP MMU SPTEs and document RCU
Add helpers to read and write TDP MMU SPTEs instead of open coding
rcu_dereference() all over the place, and to provide a convenient
location to document why KVM doesn't exempt holding mmu_lock for write
from having to hold RCU (and any future changes to the rules).
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
Message-Id: <20220226001546.360188-11-seanjc@google.com>
Reviewed-by: Mingwei Zhang <mizhang@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/mmu/tdp_iter.h')
-rw-r--r-- | arch/x86/kvm/mmu/tdp_iter.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/arch/x86/kvm/mmu/tdp_iter.h b/arch/x86/kvm/mmu/tdp_iter.h index 216ebbe76ddd..bb9b581f1ee4 100644 --- a/arch/x86/kvm/mmu/tdp_iter.h +++ b/arch/x86/kvm/mmu/tdp_iter.h @@ -10,6 +10,22 @@ typedef u64 __rcu *tdp_ptep_t; /* + * TDP MMU SPTEs are RCU protected to allow paging structures (non-leaf SPTEs) + * to be zapped while holding mmu_lock for read. Holding RCU isn't required for + * correctness if mmu_lock is held for write, but plumbing "struct kvm" down to + * the lower depths of the TDP MMU just to make lockdep happy is a nightmare, so + * all accesses to SPTEs are done under RCU protection. + */ +static inline u64 kvm_tdp_mmu_read_spte(tdp_ptep_t sptep) +{ + return READ_ONCE(*rcu_dereference(sptep)); +} +static inline void kvm_tdp_mmu_write_spte(tdp_ptep_t sptep, u64 val) +{ + WRITE_ONCE(*rcu_dereference(sptep), val); +} + +/* * A TDP iterator performs a pre-order walk over a TDP paging structure. */ struct tdp_iter { |