Skip to content

Commit 0e45981

Browse files
author
Marc Zyngier
committed
KVM: arm64: timer: Don't adjust the EL2 virtual timer offset
The way we deal with the EL2 virtual timer is a bit odd. We try to cope with E2H being flipped, and adjust which offset applies to that timer depending on the current E2H value. But that's a complexity we shouldn't have to worry about. What we have to deal with is either E2H being RES1, in which case there is no offset, or E2H being RES0, and the virtual timer simply does not exist. Drop the adjusting of the timer offset, which makes things a bit simpler. At the same time, make sure that accessing the HV timer when E2H is RES0 results in an UNDEF in the guest. Suggested-by: Oliver Upton <oliver.upton@linux.dev> Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Link: https://lore.kernel.org/r/20250204110050.150560-4-maz@kernel.org Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 1b8705a commit 0e45981

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

arch/arm64/kvm/arch_timer.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -759,21 +759,6 @@ static void kvm_timer_vcpu_load_nested_switch(struct kvm_vcpu *vcpu,
759759
timer_irq(map->direct_ptimer),
760760
&arch_timer_irq_ops);
761761
WARN_ON_ONCE(ret);
762-
763-
/*
764-
* The virtual offset behaviour is "interesting", as it
765-
* always applies when HCR_EL2.E2H==0, but only when
766-
* accessed from EL1 when HCR_EL2.E2H==1. So make sure we
767-
* track E2H when putting the HV timer in "direct" mode.
768-
*/
769-
if (map->direct_vtimer == vcpu_hvtimer(vcpu)) {
770-
struct arch_timer_offset *offs = &map->direct_vtimer->offset;
771-
772-
if (vcpu_el2_e2h_is_set(vcpu))
773-
offs->vcpu_offset = NULL;
774-
else
775-
offs->vcpu_offset = &__vcpu_sys_reg(vcpu, CNTVOFF_EL2);
776-
}
777762
}
778763
}
779764

arch/arm64/kvm/sys_regs.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,16 @@ static bool access_arch_timer(struct kvm_vcpu *vcpu,
14521452
return true;
14531453
}
14541454

1455+
static bool access_hv_timer(struct kvm_vcpu *vcpu,
1456+
struct sys_reg_params *p,
1457+
const struct sys_reg_desc *r)
1458+
{
1459+
if (!vcpu_el2_e2h_is_set(vcpu))
1460+
return undef_access(vcpu, p, r);
1461+
1462+
return access_arch_timer(vcpu, p, r);
1463+
}
1464+
14551465
static s64 kvm_arm64_ftr_safe_value(u32 id, const struct arm64_ftr_bits *ftrp,
14561466
s64 new, s64 cur)
14571467
{
@@ -3099,9 +3109,9 @@ static const struct sys_reg_desc sys_reg_descs[] = {
30993109
EL2_REG(CNTHP_CTL_EL2, access_arch_timer, reset_val, 0),
31003110
EL2_REG(CNTHP_CVAL_EL2, access_arch_timer, reset_val, 0),
31013111

3102-
{ SYS_DESC(SYS_CNTHV_TVAL_EL2), access_arch_timer },
3103-
EL2_REG(CNTHV_CTL_EL2, access_arch_timer, reset_val, 0),
3104-
EL2_REG(CNTHV_CVAL_EL2, access_arch_timer, reset_val, 0),
3112+
{ SYS_DESC(SYS_CNTHV_TVAL_EL2), access_hv_timer },
3113+
EL2_REG(CNTHV_CTL_EL2, access_hv_timer, reset_val, 0),
3114+
EL2_REG(CNTHV_CVAL_EL2, access_hv_timer, reset_val, 0),
31053115

31063116
{ SYS_DESC(SYS_CNTKCTL_EL12), access_cntkctl_el12 },
31073117

0 commit comments

Comments
 (0)