KVM: x86/mmu: Properly dereference rcu-protected TDP MMU sptep iterator
Sean Christopherson
maintainerPATCH 1/1 KVM: x86/mmu: Properly dereference rcu-protected TDP MMU sptep iterator
Wrap the read of iter->sptep in tdp_mmu_map_handle_target_level() with rcu_dereference(). Shadow pages in the TDP MMU, and thus their SPTEs, are protected by rcu.
This fixes a Sparse warning at tdp_mmu.c:900:51:
warning: incorrect type in argument 1 (different address spaces) expected unsigned long long [usertype] *sptep
got unsigned long long [noderef] [usertype] __rcu *[usertype] sptep
--- arch/x86/kvm/mmu/tdp_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/tdp_mmu.c +1 -1
@@ -897,7 +897,7 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu,struct kvm_page_fault *fault, struct tdp_iter *iter) { - struct kvm_mmu_page *sp = sptep_to_sp(iter->sptep); + struct kvm_mmu_page *sp = sptep_to_sp(rcu_dereference(iter->sptep));u64 new_spte;int ret =RET_PF_FIXED ;bool wrprot = false;
Signature · 1 line
2.33.1.1089.g2158813163f-goog
Quoted 5 lines · Sean Christopherson
Wrap the read of
iter->sptepintdp_mmu_map_handle_target_level()withrcu_dereference(). Shadow pages in the TDP MMU, and thus their SPTEs, are protected by rcu.
Quoted 8 lines
This fixes a Sparse warning at tdp_mmu.c:900:51:
warning: incorrect type in argument 1 (different address spaces) expected unsigned long long [usertype] *sptep
got unsigned long long [noderef] [usertype]__rcu*[usertype] sptepFixes 7158bee4b475 ("KVM: MMU: pass kvm_mmu_page struct to make_spte")Cc Ben Gardon <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
This change looks good to me. It also reminds me that the struct kvm_mmu_pages are also protected by RCU.
I wonder if it would be worth creating something similar to tdp_ptep_t for the struct kvm_mmu_pages to add RCU annotations to them as well.
Quoted 20 lines
--- arch/x86/kvm/mmu/tdp_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/mmu/tdp_mmu.c +1
-2@@ -897,7 +897,7 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu,struct kvm_page_fault *fault, struct tdp_iter *iter) { - struct kvm_mmu_page *sp = sptep_to_sp(iter->sptep); + struct kvm_mmu_page *sp = sptep_to_sp(rcu_dereference(iter->sptep));u64 new_spte;int ret =RET_PF_FIXED ;bool wrprot = false; --2.33.1.1089.g2158813163f-goog