Skip to content

Commit 85bba00

Browse files
author
Marc Zyngier
committed
KVM: arm64: nv: Move TLBI range decoding to a helper
As we are about to expand out TLB invalidation capabilities to support recursive virtualisation, move the decoding of a TLBI by range into a helper that returns the base, the range and the ASID. Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Link: https://lore.kernel.org/r/20250514103501.2225951-6-maz@kernel.org Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent a0ec2b8 commit 85bba00

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

arch/arm64/include/asm/kvm_nested.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,38 @@ static inline u64 kvm_encode_nested_level(struct kvm_s2_trans *trans)
231231
shift; \
232232
})
233233

234+
static inline u64 decode_range_tlbi(u64 val, u64 *range, u16 *asid)
235+
{
236+
u64 base, tg, num, scale;
237+
int shift;
238+
239+
tg = FIELD_GET(GENMASK(47, 46), val);
240+
241+
switch(tg) {
242+
case 1:
243+
shift = 12;
244+
break;
245+
case 2:
246+
shift = 14;
247+
break;
248+
case 3:
249+
default: /* IMPDEF: handle tg==0 as 64k */
250+
shift = 16;
251+
break;
252+
}
253+
254+
base = (val & GENMASK(36, 0)) << shift;
255+
256+
if (asid)
257+
*asid = FIELD_GET(TLBIR_ASID_MASK, val);
258+
259+
scale = FIELD_GET(GENMASK(45, 44), val);
260+
num = FIELD_GET(GENMASK(43, 39), val);
261+
*range = __TLBI_RANGE_PAGES(num, scale) << shift;
262+
263+
return base;
264+
}
265+
234266
static inline unsigned int ps_to_output_size(unsigned int ps)
235267
{
236268
switch (ps) {

arch/arm64/kvm/sys_regs.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3546,8 +3546,7 @@ static bool handle_ripas2e1is(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
35463546
{
35473547
u32 sys_encoding = sys_insn(p->Op0, p->Op1, p->CRn, p->CRm, p->Op2);
35483548
u64 vttbr = vcpu_read_sys_reg(vcpu, VTTBR_EL2);
3549-
u64 base, range, tg, num, scale;
3550-
int shift;
3549+
u64 base, range;
35513550

35523551
if (!kvm_supported_tlbi_ipas2_op(vcpu, sys_encoding))
35533552
return undef_access(vcpu, p, r);
@@ -3557,26 +3556,7 @@ static bool handle_ripas2e1is(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
35573556
* of the guest's S2 (different base granule size, for example), we
35583557
* decide to ignore TTL and only use the described range.
35593558
*/
3560-
tg = FIELD_GET(GENMASK(47, 46), p->regval);
3561-
scale = FIELD_GET(GENMASK(45, 44), p->regval);
3562-
num = FIELD_GET(GENMASK(43, 39), p->regval);
3563-
base = p->regval & GENMASK(36, 0);
3564-
3565-
switch(tg) {
3566-
case 1:
3567-
shift = 12;
3568-
break;
3569-
case 2:
3570-
shift = 14;
3571-
break;
3572-
case 3:
3573-
default: /* IMPDEF: handle tg==0 as 64k */
3574-
shift = 16;
3575-
break;
3576-
}
3577-
3578-
base <<= shift;
3579-
range = __TLBI_RANGE_PAGES(num, scale) << shift;
3559+
base = decode_range_tlbi(p->regval, &range, NULL);
35803560

35813561
kvm_s2_mmu_iterate_by_vmid(vcpu->kvm, get_vmid(vttbr),
35823562
&(union tlbi_info) {

0 commit comments

Comments
 (0)