KVM: arm64: Take the SRCU lock for page table walks in fault injection and AT emulation
Subsystems (3)
PATCH v2 1/1 KVM: arm64: Take the SRCU lock for page table walks in fault injection and AT emulation
walk_s1() and kvm_walk_nested_s2() expect to be called while holding kvm->srcu to guard against memslot changes. While this is generally the case, __kvm_at_s12() and __kvm_find_s1_desc_level() call into the respective walkers without taking kvm->srcu.
Fix by acquiring kvm->srcu prior to the table walk in both instances.
---
Changes in v2:
- Wrap only the walker calls with scoped_guard() and move the injection lock into __kvm_find_s1_desc_level(), as suggested by Oliver.
- Reword the commit message as suggested.
- v1: https://lore.kernel.org/all/ah7_BAAzHggzdZeI@v4bel/
--- arch/arm64/kvm/at.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/kvm/at.c +4 -2
@@ -1569,7 +1569,8 @@ int __kvm_at_s12(struct kvm_vcpu *vcpu, u32 op, u64 vaddr)/* Do the stage-2 translation */ ipa = (par &GENMASK_ULL (47 ,12 )) | (vaddr &GENMASK_ULL (11 ,0 )); out.esr =0 ; - ret =kvm_walk_nested_s2 (vcpu, ipa, &out); +scoped_guard (srcu, &vcpu->kvm->srcu) + ret = kvm_walk_nested_s2(vcpu, ipa, &out);if (ret <0 )return ret;
@@ -1665,7 +1666,8 @@ int __kvm_find_s1_desc_level(struct kvm_vcpu *vcpu, u64 va, u64 ipa, int *level) }/* Walk the guest's PT, looking for a match along the way */ - ret =walk_s1 (vcpu, &wi, &wr, va); +scoped_guard (srcu, &vcpu->kvm->srcu) + ret = walk_s1(vcpu, &wi, &wr, va);switch (ret) {case -EINTR :/* We interrupted the walk on a match, return the level */
Signature · 1 line
2.43.0
Quoted 5 lines · Hyunwoo Kim
walk_s1()andkvm_walk_nested_s2()expect to be called while holdingkvm->srcuto guard against memslot changes. While this is generally the case,__kvm_at_s12()and__kvm_find_s1_desc_level()call into the respective walkers without takingkvm->srcu.
Quoted 7 lines
Fix by acquiring
kvm->srcuprior to the table walk in both instances.Fixes 50f77dc87f13 ("KVM: arm64: Populate level on S1PTW SEA injection")Fixes be04cebf3e78 ("KVM: arm64: nv: Add emulation of AT S12E{0,1}{R,W}")Suggested-by Oliver Upton <[email protected]>Signed-off-by Hyunwoo Kim <[email protected]>
Signature · 2 lines
Thanks, Oliver