Skip to content

Commit aca1858

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Program the timer traps with VHE layout in hVHE mode
Just like the rest of the timer code, we need to shift the enable bits around when HCR_EL2.E2H is set, which is the case in hVHE mode. Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230609162200.2024064-15-maz@kernel.org Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 75c76ab commit aca1858

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

arch/arm64/kvm/hyp/nvhe/timer-sr.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@ void __kvm_timer_set_cntvoff(u64 cntvoff)
1717
}
1818

1919
/*
20-
* Should only be called on non-VHE systems.
20+
* Should only be called on non-VHE or hVHE setups.
2121
* VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe().
2222
*/
2323
void __timer_disable_traps(struct kvm_vcpu *vcpu)
2424
{
25-
u64 val;
25+
u64 val, shift = 0;
26+
27+
if (has_hvhe())
28+
shift = 10;
2629

2730
/* Allow physical timer/counter access for the host */
2831
val = read_sysreg(cnthctl_el2);
29-
val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN;
32+
val |= (CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN) << shift;
3033
write_sysreg(val, cnthctl_el2);
3134
}
3235

3336
/*
34-
* Should only be called on non-VHE systems.
37+
* Should only be called on non-VHE or hVHE setups.
3538
* VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe().
3639
*/
3740
void __timer_enable_traps(struct kvm_vcpu *vcpu)
@@ -50,5 +53,10 @@ void __timer_enable_traps(struct kvm_vcpu *vcpu)
5053
else
5154
clr |= CNTHCTL_EL1PCTEN;
5255

56+
if (has_hvhe()) {
57+
clr <<= 10;
58+
set <<= 10;
59+
}
60+
5361
sysreg_clear_set(cnthctl_el2, clr, set);
5462
}

0 commit comments

Comments
 (0)