Skip to content

Commit

Permalink
KVM: arm/arm64: Don't enable/disable physical timer access on VHE
Browse files Browse the repository at this point in the history
After the timer optimization rework we accidentally end up calling
physical timer enable/disable functions on VHE systems, which is neither
needed nor correct, since the CNTHCTL_EL2 register format is
different when HCR_EL2.E2H is set.

The CNTHCTL_EL2 is initialized when CPUs become online in
kvm_timer_init_vhe() and we don't have to call these functions on VHE
systems, which also allows us to inline the non-VHE functionality.

Reported-by: Jintack Lim <[email protected]>
Signed-off-by: Christoffer Dall <[email protected]>
  • Loading branch information
chazy committed Nov 29, 2017
1 parent 4fbd8d1 commit ec6449a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 37 deletions.
3 changes: 0 additions & 3 deletions include/kvm/arm_arch_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,4 @@ void kvm_timer_init_vhe(void);
#define vcpu_vtimer(v) (&(v)->arch.timer_cpu.vtimer)
#define vcpu_ptimer(v) (&(v)->arch.timer_cpu.ptimer)

void enable_el1_phys_timer_access(void);
void disable_el1_phys_timer_access(void);

#endif
6 changes: 0 additions & 6 deletions virt/kvm/arm/arch_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,6 @@ void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu)

vtimer_restore_state(vcpu);

if (has_vhe())
disable_el1_phys_timer_access();

/* Set the background timer for the physical timer emulation. */
phys_timer_emulate(vcpu);
}
Expand Down Expand Up @@ -510,9 +507,6 @@ void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu)
if (unlikely(!timer->enabled))
return;

if (has_vhe())
enable_el1_phys_timer_access();

vtimer_save_state(vcpu);

/*
Expand Down
48 changes: 20 additions & 28 deletions virt/kvm/arm/hyp/timer-sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,34 @@ void __hyp_text __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high)
write_sysreg(cntvoff, cntvoff_el2);
}

void __hyp_text enable_el1_phys_timer_access(void)
{
u64 val;

/* Allow physical timer/counter access for the host */
val = read_sysreg(cnthctl_el2);
val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN;
write_sysreg(val, cnthctl_el2);
}

void __hyp_text disable_el1_phys_timer_access(void)
{
u64 val;

/*
* Disallow physical timer access for the guest
* Physical counter access is allowed
*/
val = read_sysreg(cnthctl_el2);
val &= ~CNTHCTL_EL1PCEN;
val |= CNTHCTL_EL1PCTEN;
write_sysreg(val, cnthctl_el2);
}

void __hyp_text __timer_disable_traps(struct kvm_vcpu *vcpu)
{
/*
* We don't need to do this for VHE since the host kernel runs in EL2
* with HCR_EL2.TGE ==1, which makes those bits have no impact.
*/
if (!has_vhe())
enable_el1_phys_timer_access();
if (!has_vhe()) {
u64 val;

/* Allow physical timer/counter access for the host */
val = read_sysreg(cnthctl_el2);
val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN;
write_sysreg(val, cnthctl_el2);
}
}

void __hyp_text __timer_enable_traps(struct kvm_vcpu *vcpu)
{
if (!has_vhe())
disable_el1_phys_timer_access();
if (!has_vhe()) {
u64 val;

/*
* Disallow physical timer access for the guest
* Physical counter access is allowed
*/
val = read_sysreg(cnthctl_el2);
val &= ~CNTHCTL_EL1PCEN;
val |= CNTHCTL_EL1PCTEN;
write_sysreg(val, cnthctl_el2);
}
}

0 comments on commit ec6449a

Please sign in to comment.