KVM: arm64: Take the SRCU lock for page table walks in fault injection and AT emulation
Subsystems (2)
PATCH 1/1 KVM: arm64: Take the SRCU lock for page table walks in fault injection and AT emulation
From: Hyunwoo Kim <[email protected]>
commit f2ca45b50d4216c9cc7ffabf50d9ad1932209251 upstream.
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.
--- arch/arm64/kvm/at.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kvm/at.c +2 -1
@@ -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
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Stage-2 translation table walk failures (e.g., unbacked memory) return negative error codes without populating the ESR or updating PAR_EL1, leaving the stage-1 IPA in PAR_EL1 as a false success. --
commit 6d7bd74abe7bde3942c024259e9d4015f378779c
Author: Hyunwoo Kim <[email protected]> Date: Fri Jun 26 13:42:07 2026 +0000
KVM: arm64: Take the SRCU lock for page table walks in fault injection and AT emulation
This commit fixes missing SRCU lock acquisitions during page table walks in AT emulation and fault injection. It wraps the calls to kvm_walk_nested_s2 and __kvm_find_s1_desc_level with scoped_guard to ensure they are protected.
Quoted 4 lines
arch/arm64/kvm/at.c +0
-0
[ ... ]
arch/arm64/kvm/at.c void __kvm_at_s12(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) · line 1093
Quoted 9 lines
arch/arm64/kvm/at.c +2
-1@@ -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 ;
[Severity: High]
This is a pre-existing issue, but does this early return incorrectly skip updating PAR_EL1 with a translation fault?
If a nested guest (L1) executes an AT S12E1R instruction pointing to an unmapped IPA, __kvm_at_s1e01() successfully translates stage-1 and sets PAR_EL1 to the IPA. Then, when kvm_walk_nested_s2() attempts to read the stage-2 descriptor, it can fail (e.g., returning -EFAULT from unbacked memory in walk_nested_s2_pgd()):
walk_nested_s2_pgd() {
...
ret = wi->read_desc(paddr, &desc, wi->data);
if (ret < 0)
return ret;
...
}When this negative error code propagates back here to __kvm_at_s12(), we return immediately. Because compute_par_s12() is bypassed, PAR_EL1 is never updated with the fault status.
Could this leave the L1 guest to incorrectly observe a successful translation, mistaking the IPA for the final PA? Should this path populate the ESR and update PAR_EL1 before returning?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Marc Zyngier
maintainerQuoted 12 lines · Alexander Martyniuk
From: Hyunwoo Kim <[email protected]>
commit
f2ca45b50d4216c9cc7ffabf50d9ad1932209251upstream.
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.Fix by acquiring
kvm->srcuprior to the table walk in both instances.
Quoted 10 lines
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]>Reviewed-by Oliver Upton <[email protected]>Signed-off-by Marc Zyngier <[email protected]>[Alexander: __kvm_find_s1_desc_level() not present, patching only __kvm_at_s12()]Signed-off-by Alexander Martyniuk <[email protected]>
See thread at [1], which explains why this is not needed.
M.
[1] https://lore.kernel.org/all/aifnUC7gmeniiYPv@v4bel/
Signature · 1 line
Without deviation from the norm, progress is not possible.