On 31/03/21 23:08, Ben Gardon wrote:
Protect the contents of the TDP MMU roots list with RCU in preparation
for a future patch which will allow the iterator macro to be used under
the MMU lock in read mode.

Signed-off-by: Ben Gardon<[email protected]>
---
  arch/x86/kvm/mmu/tdp_mmu.c | 64 +++++++++++++++++++++-----------------
  1 file changed, 36 insertions(+), 28 deletions(-)

diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
+       spin_lock(&kvm->arch.tdp_mmu_pages_lock);
+       list_del_rcu(&root->link);
+       spin_unlock(&kvm->arch.tdp_mmu_pages_lock);


Please update the comment above tdp_mmu_pages_lock in arch/x86/include/asm/kvm_host.h as well.

 /* Only safe under the MMU lock in write mode, without yielding. */
 #define for_each_tdp_mmu_root(_kvm, _root)                             \
-       list_for_each_entry(_root, &_kvm->arch.tdp_mmu_roots, link)
+       list_for_each_entry_rcu(_root, &_kvm->arch.tdp_mmu_roots, link,  \
+                               lockdep_is_held_write(&kvm->mmu_lock))

This should also add "... || lockdep_is_help(&kvm->arch.tdp_mmu_pages_lock)", if only for documentation purposes.

Paolo

Reply via email to