]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: arm64: timer: Don't adjust the EL2 virtual timer offset
authorMarc Zyngier <maz@kernel.org>
Tue, 4 Feb 2025 11:00:50 +0000 (11:00 +0000)
committerMarc Zyngier <maz@kernel.org>
Tue, 4 Feb 2025 15:10:38 +0000 (15:10 +0000)
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>
arch/arm64/kvm/arch_timer.c
arch/arm64/kvm/sys_regs.c

index e59836e0260cf137258b8652d3f7c603a12d563c..231c0cd9c7b4b87b844d393bf835cee5809f1e01 100644 (file)
@@ -759,21 +759,6 @@ static void kvm_timer_vcpu_load_nested_switch(struct kvm_vcpu *vcpu,
                                            timer_irq(map->direct_ptimer),
                                            &arch_timer_irq_ops);
                WARN_ON_ONCE(ret);
-
-               /*
-                * The virtual offset behaviour is "interesting", as it
-                * always applies when HCR_EL2.E2H==0, but only when
-                * accessed from EL1 when HCR_EL2.E2H==1. So make sure we
-                * track E2H when putting the HV timer in "direct" mode.
-                */
-               if (map->direct_vtimer == vcpu_hvtimer(vcpu)) {
-                       struct arch_timer_offset *offs = &map->direct_vtimer->offset;
-
-                       if (vcpu_el2_e2h_is_set(vcpu))
-                               offs->vcpu_offset = NULL;
-                       else
-                               offs->vcpu_offset = &__vcpu_sys_reg(vcpu, CNTVOFF_EL2);
-               }
        }
 }
 
index 526d66f24e34aea2eb62415f14e9cdb3858e6484..7968bee0d27ea98c867aefb4517691dfeb15d861 100644 (file)
@@ -1452,6 +1452,16 @@ static bool access_arch_timer(struct kvm_vcpu *vcpu,
        return true;
 }
 
+static bool access_hv_timer(struct kvm_vcpu *vcpu,
+                           struct sys_reg_params *p,
+                           const struct sys_reg_desc *r)
+{
+       if (!vcpu_el2_e2h_is_set(vcpu))
+               return undef_access(vcpu, p, r);
+
+       return access_arch_timer(vcpu, p, r);
+}
+
 static s64 kvm_arm64_ftr_safe_value(u32 id, const struct arm64_ftr_bits *ftrp,
                                    s64 new, s64 cur)
 {
@@ -3099,9 +3109,9 @@ static const struct sys_reg_desc sys_reg_descs[] = {
        EL2_REG(CNTHP_CTL_EL2, access_arch_timer, reset_val, 0),
        EL2_REG(CNTHP_CVAL_EL2, access_arch_timer, reset_val, 0),
 
-       { SYS_DESC(SYS_CNTHV_TVAL_EL2), access_arch_timer },
-       EL2_REG(CNTHV_CTL_EL2, access_arch_timer, reset_val, 0),
-       EL2_REG(CNTHV_CVAL_EL2, access_arch_timer, reset_val, 0),
+       { SYS_DESC(SYS_CNTHV_TVAL_EL2), access_hv_timer },
+       EL2_REG(CNTHV_CTL_EL2, access_hv_timer, reset_val, 0),
+       EL2_REG(CNTHV_CVAL_EL2, access_hv_timer, reset_val, 0),
 
        { SYS_DESC(SYS_CNTKCTL_EL12), access_cntkctl_el12 },