Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Oliver Upton and committed by
Marc Zyngier
0910778e d72543ac

+28 -8
+2 -4
tools/testing/selftests/kvm/arm64/arch_timer.c
··· 165 165 static void test_init_timer_irq(struct kvm_vm *vm) 166 166 { 167 167 /* 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]); 172 170 173 171 sync_global_to_guest(vm, ptimer_irq); 174 172 sync_global_to_guest(vm, vtimer_irq);
+2 -4
tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
··· 924 924 925 925 static void test_init_timer_irq(struct kvm_vm *vm, struct kvm_vcpu *vcpu) 926 926 { 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); 931 929 932 930 sync_global_to_guest(vm, ptimer_irq); 933 931 sync_global_to_guest(vm, vtimer_irq);
+24
tools/testing/selftests/kvm/include/arm64/arch_timer.h
··· 155 155 timer_set_tval(timer, msec_to_cycles(msec)); 156 156 } 157 157 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 + 158 182 #endif /* SELFTEST_KVM_ARCH_TIMER_H */