Skip to content

Commit 0910778

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: selftests: Use hyp timer IRQs when test runs at EL2
Arch timer registers are redirected to their hypervisor counterparts when running in VHE EL2. This is great, except for the fact that the hypervisor timers use different PPIs. Use the correct INTIDs when that is the case. Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent d72543a commit 0910778

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

tools/testing/selftests/kvm/arm64/arch_timer.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,8 @@ static void guest_code(void)
165165
static void test_init_timer_irq(struct kvm_vm *vm)
166166
{
167167
/* Timer initid should be same for all the vCPUs, so query only vCPU-0 */
168-
vcpu_device_attr_get(vcpus[0], KVM_ARM_VCPU_TIMER_CTRL,
169-
KVM_ARM_VCPU_TIMER_IRQ_PTIMER, &ptimer_irq);
170-
vcpu_device_attr_get(vcpus[0], KVM_ARM_VCPU_TIMER_CTRL,
171-
KVM_ARM_VCPU_TIMER_IRQ_VTIMER, &vtimer_irq);
168+
ptimer_irq = vcpu_get_ptimer_irq(vcpus[0]);
169+
vtimer_irq = vcpu_get_vtimer_irq(vcpus[0]);
172170

173171
sync_global_to_guest(vm, ptimer_irq);
174172
sync_global_to_guest(vm, vtimer_irq);

tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,10 +924,8 @@ static void test_run(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
924924

925925
static void test_init_timer_irq(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
926926
{
927-
vcpu_device_attr_get(vcpu, KVM_ARM_VCPU_TIMER_CTRL,
928-
KVM_ARM_VCPU_TIMER_IRQ_PTIMER, &ptimer_irq);
929-
vcpu_device_attr_get(vcpu, KVM_ARM_VCPU_TIMER_CTRL,
930-
KVM_ARM_VCPU_TIMER_IRQ_VTIMER, &vtimer_irq);
927+
ptimer_irq = vcpu_get_ptimer_irq(vcpu);
928+
vtimer_irq = vcpu_get_vtimer_irq(vcpu);
931929

932930
sync_global_to_guest(vm, ptimer_irq);
933931
sync_global_to_guest(vm, vtimer_irq);

tools/testing/selftests/kvm/include/arm64/arch_timer.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,28 @@ static inline void timer_set_next_tval_ms(enum arch_timer timer, uint32_t msec)
155155
timer_set_tval(timer, msec_to_cycles(msec));
156156
}
157157

158+
static inline u32 vcpu_get_vtimer_irq(struct kvm_vcpu *vcpu)
159+
{
160+
u32 intid;
161+
u64 attr;
162+
163+
attr = vcpu_has_el2(vcpu) ? KVM_ARM_VCPU_TIMER_IRQ_HVTIMER :
164+
KVM_ARM_VCPU_TIMER_IRQ_VTIMER;
165+
vcpu_device_attr_get(vcpu, KVM_ARM_VCPU_TIMER_CTRL, attr, &intid);
166+
167+
return intid;
168+
}
169+
170+
static inline u32 vcpu_get_ptimer_irq(struct kvm_vcpu *vcpu)
171+
{
172+
u32 intid;
173+
u64 attr;
174+
175+
attr = vcpu_has_el2(vcpu) ? KVM_ARM_VCPU_TIMER_IRQ_HPTIMER :
176+
KVM_ARM_VCPU_TIMER_IRQ_PTIMER;
177+
vcpu_device_attr_get(vcpu, KVM_ARM_VCPU_TIMER_CTRL, attr, &intid);
178+
179+
return intid;
180+
}
181+
158182
#endif /* SELFTEST_KVM_ARCH_TIMER_H */

0 commit comments

Comments
 (0)