Skip to contentSkip to conversation

KVM: arm64: Take the SRCU lock for page table walks in fault injection and AT emulation

PATCH In review Hyunwoo Kim 2 participants 3 messages Jun 9 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: arm64: Take the SRCU lock for page table walks in fault injection and AT emulation

[ Upstream commit f2ca45b50d4216c9cc7ffabf50d9ad1932209251 ]

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.

Fixes 50f77dc87f13 ("KVM: arm64: Populate level on S1PTW SEA injection")
Fixes be04cebf3e78 ("KVM: arm64: nv: Add emulation of AT S12E{0,1}{R,W}")

[ Hyunwoo Kim: __kvm_at_s12() returns void in 6.12.y, so the context
differs from upstream (return; instead of return ret;). The __kvm_find_s1_desc_level() hunk (Fixes: 50f77dc87f13) is dropped, as that function is v6.18+ and absent here; only the __kvm_at_s12() / kvm_walk_nested_s2() change (Fixes: be04cebf3e78) applies. ]

---
 arch/arm64/kvm/at.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kvm/at.c +2 -1
index 39f0e87a340e..8192bc0bbc87 100644
@@ -1087,7 +1087,8 @@ void __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;
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 18 lines · Hyunwoo Kim

[ Upstream commit f2ca45b50d4216c9cc7ffabf50d9ad1932209251 ]

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.

Fixes 50f77dc87f13 ("KVM: arm64: Populate level on S1PTW SEA injection")
Fixes be04cebf3e78 ("KVM: arm64: nv: Add emulation of AT S12E{0,1}{R,W}")
Quoted 6 lines

[ Hyunwoo Kim: __kvm_at_s12() returns void in 6.12.y, so the context
differs from upstream (return; instead of return ret;). The __kvm_find_s1_desc_level() hunk (Fixes: 50f77dc87f13) is dropped, as that function is v6.18+ and absent here; only the __kvm_at_s12() / kvm_walk_nested_s2() change (Fixes: be04cebf3e78) applies. ]

I don't think this is necessary. 6.12 doesn't actually have NV support (it was enabled only from userspace in 6.17), therefore the ATS12 emulation isn't reachable.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#2 lore raw
Quoted 27 lines · Marc Zyngier
Quoted 18 lines · Hyunwoo Kim

[ Upstream commit f2ca45b50d4216c9cc7ffabf50d9ad1932209251 ]

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.

Fixes 50f77dc87f13 ("KVM: arm64: Populate level on S1PTW SEA injection")
Fixes be04cebf3e78 ("KVM: arm64: nv: Add emulation of AT S12E{0,1}{R,W}")
Quoted 6 lines

[ Hyunwoo Kim: __kvm_at_s12() returns void in 6.12.y, so the context
differs from upstream (return; instead of return ret;). The __kvm_find_s1_desc_level() hunk (Fixes: 50f77dc87f13) is dropped, as that function is v6.18+ and absent here; only the __kvm_at_s12() / kvm_walk_nested_s2() change (Fixes: be04cebf3e78) applies. ]

Quoted 3 lines

I don't think this is necessary. 6.12 doesn't actually have NV support (it was enabled only from userspace in 6.17), therefore the ATS12 emulation isn't reachable.

Ah, I see. Thank you for the review.

Quoted 7 lines

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.

Best regards,
Hyunwoo Kim