Skip to content

Commit 4c2264e

Browse files
Zenghui Yu (Huawei)Marc Zyngier
authored andcommitted
KVM: arm64: nv: Check S2 limits based on implemented PA size
check_base_s2_limits() checks the validity of SL0 and inputsize against ia_size (inputsize again!) but the pseudocode from DDI0487 G.a AArch64.TranslationTableWalk() says that we should check against the implemented PA size. We would otherwise fail to walk S2 with a valid configuration. E.g., granule size = 4KB, inputsize = 40 bits, initial lookup level = 0 (no concatenation) on a system with 48 bits PA range supported is allowed by architecture. Fix it by obtaining PA size by kvm_get_pa_bits(). Note that kvm_get_pa_bits() returns the fixed limit now and should eventually reflect the per VM PARange (one day!). Given that the configured PARange should not be greater that kvm_ipa_limit, it at least fixes the problem described above. While at it, inject a level 0 translation fault to guest if check_base_s2_limits() fails, as per the pseudocode. Fixes: 61e30b9 ("KVM: arm64: nv: Implement nested Stage-2 page table walk logic") Signed-off-by: Zenghui Yu (Huawei) <zenghui.yu@linux.dev> Link: https://patch.msgid.link/20260225173515.20490-2-zenghui.yu@linux.dev Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 8531d5a commit 4c2264e

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

arch/arm64/kvm/nested.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,31 +152,31 @@ static int get_ia_size(struct s2_walk_info *wi)
152152
return 64 - wi->t0sz;
153153
}
154154

155-
static int check_base_s2_limits(struct s2_walk_info *wi,
155+
static int check_base_s2_limits(struct kvm_vcpu *vcpu, struct s2_walk_info *wi,
156156
int level, int input_size, int stride)
157157
{
158-
int start_size, ia_size;
158+
int start_size, pa_max;
159159

160-
ia_size = get_ia_size(wi);
160+
pa_max = kvm_get_pa_bits(vcpu->kvm);
161161

162162
/* Check translation limits */
163163
switch (BIT(wi->pgshift)) {
164164
case SZ_64K:
165-
if (level == 0 || (level == 1 && ia_size <= 42))
165+
if (level == 0 || (level == 1 && pa_max <= 42))
166166
return -EFAULT;
167167
break;
168168
case SZ_16K:
169-
if (level == 0 || (level == 1 && ia_size <= 40))
169+
if (level == 0 || (level == 1 && pa_max <= 40))
170170
return -EFAULT;
171171
break;
172172
case SZ_4K:
173-
if (level < 0 || (level == 0 && ia_size <= 42))
173+
if (level < 0 || (level == 0 && pa_max <= 42))
174174
return -EFAULT;
175175
break;
176176
}
177177

178178
/* Check input size limits */
179-
if (input_size > ia_size)
179+
if (input_size > pa_max)
180180
return -EFAULT;
181181

182182
/* Check number of entries in starting level table */
@@ -269,9 +269,11 @@ static int walk_nested_s2_pgd(struct kvm_vcpu *vcpu, phys_addr_t ipa,
269269
if (input_size > 48 || input_size < 25)
270270
return -EFAULT;
271271

272-
ret = check_base_s2_limits(wi, level, input_size, stride);
273-
if (WARN_ON(ret))
272+
ret = check_base_s2_limits(vcpu, wi, level, input_size, stride);
273+
if (WARN_ON(ret)) {
274+
out->esr = compute_fsc(0, ESR_ELx_FSC_FAULT);
274275
return ret;
276+
}
275277

276278
base_lower_bound = 3 + input_size - ((3 - level) * stride +
277279
wi->pgshift);

0 commit comments

Comments
 (0)