Skip to content

Commit 3ed0b51

Browse files
author
Marc Zyngier
committed
KVM: arm64: nv: Compute NV view of idregs as a one-off
Now that we have a full copy of the idregs for each VM, there is no point in repainting the sysregs on each access. Instead, we can simply perform the transmation as a one-off and be done with it. Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 111903d commit 3ed0b51

5 files changed

Lines changed: 23 additions & 14 deletions

File tree

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ struct kvm_arch {
306306
* Atomic access to multiple idregs are guarded by kvm_arch.config_lock.
307307
*/
308308
#define IDREG_IDX(id) (((sys_reg_CRm(id) - 1) << 3) | sys_reg_Op2(id))
309+
#define IDX_IDREG(idx) sys_reg(3, 0, 0, ((idx) >> 3) + 1, (idx) & Op2_mask)
309310
#define IDREG(kvm, id) ((kvm)->arch.id_regs[IDREG_IDX(id)])
310311
#define KVM_ARM_ID_REG_NUM (IDREG_IDX(sys_reg(3, 0, 0, 7, 7)) + 1)
311312
u64 id_regs[KVM_ARM_ID_REG_NUM];

arch/arm64/include/asm/kvm_nested.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ static inline bool vcpu_has_nv(const struct kvm_vcpu *vcpu)
1414

1515
extern bool __check_nv_sr_forward(struct kvm_vcpu *vcpu);
1616

17-
struct sys_reg_params;
18-
struct sys_reg_desc;
19-
20-
void access_nested_id_reg(struct kvm_vcpu *v, struct sys_reg_params *p,
21-
const struct sys_reg_desc *r);
17+
int kvm_init_nv_sysregs(struct kvm *kvm);
2218

2319
#endif /* __ARM64_KVM_NESTED_H */

arch/arm64/kvm/arm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,12 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)
669669
return ret;
670670
}
671671

672+
if (vcpu_has_nv(vcpu)) {
673+
ret = kvm_init_nv_sysregs(vcpu->kvm);
674+
if (ret)
675+
return ret;
676+
}
677+
672678
ret = kvm_timer_enable(vcpu);
673679
if (ret)
674680
return ret;

arch/arm64/kvm/nested.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@
2323
* This list should get updated as new features get added to the NV
2424
* support, and new extension to the architecture.
2525
*/
26-
void access_nested_id_reg(struct kvm_vcpu *v, struct sys_reg_params *p,
27-
const struct sys_reg_desc *r)
26+
static u64 limit_nv_id_reg(u32 id, u64 val)
2827
{
29-
u32 id = reg_to_encoding(r);
30-
u64 val, tmp;
31-
32-
val = p->regval;
28+
u64 tmp;
3329

3430
switch (id) {
3531
case SYS_ID_AA64ISAR0_EL1:
@@ -158,5 +154,17 @@ void access_nested_id_reg(struct kvm_vcpu *v, struct sys_reg_params *p,
158154
break;
159155
}
160156

161-
p->regval = val;
157+
return val;
158+
}
159+
int kvm_init_nv_sysregs(struct kvm *kvm)
160+
{
161+
mutex_lock(&kvm->arch.config_lock);
162+
163+
for (int i = 0; i < KVM_ARM_ID_REG_NUM; i++)
164+
kvm->arch.id_regs[i] = limit_nv_id_reg(IDX_IDREG(i),
165+
kvm->arch.id_regs[i]);
166+
167+
mutex_unlock(&kvm->arch.config_lock);
168+
169+
return 0;
162170
}

arch/arm64/kvm/sys_regs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,8 +1505,6 @@ static bool access_id_reg(struct kvm_vcpu *vcpu,
15051505
return write_to_read_only(vcpu, p, r);
15061506

15071507
p->regval = read_id_reg(vcpu, r);
1508-
if (vcpu_has_nv(vcpu))
1509-
access_nested_id_reg(vcpu, p, r);
15101508

15111509
return true;
15121510
}

0 commit comments

Comments
 (0)