[PATCH 00/13] KVM: arm64: De-specialise the timer UAPI

Marc Zyngier
2025-09-29T16:05:05Z

Since the beginning of the KVM/arm64 port, the timer registers were
handled out of the normal sysreg flow when it came to userspace
access, leading to extra complexity and a bit of code duplication.

When NV was introduced, the decision was made early to handle the new
timer registers as part of the generic infrastructure. However, the
EL0 timers were left behind until someone could be bothered to
entangle that mess.

Said mess is more complicated than it looks, due to a nasty bug
documented in 290a6bb06de9e ("arm64: KVM: Add UAPI notes for swapped
registers"), where it was realised that CNTV_CVAL_EL0 and CNTVCT_EL0
have had their encoding swapped at the user interface level. Handling
of this issue is spread all over the place instead of being contained
in a single location, and it needs to be contained.

Finally, it was noticed that we expose the CNTHV_*_EL2 registers to
userspace for nVHE guest, while the architecture is clear that they do
not exist in that configuration.

This series aims at fixing all of the above, moving the handling of
the timer sysregs to sys_regs.c, fix a corner case with WFxT, handle
the nVHE issue described above, and finally improve the testing by
introducing an E2H==0 configuration.

If excluding the selftests, this is a net deletion of code. What's not
to like?

Marc Zyngier (13):
KVM: arm64: Hide CNTHV_*_EL2 from userspace for nVHE guests
KVM: arm64: Introduce timer_context_to_vcpu() helper
KVM: arm64: Replace timer context vcpu pointer with timer_id
KVM: arm64: Make timer_set_offset() generally accessible
KVM: arm64: Add timer UAPI workaround to sysreg infrastructure
KVM: arm64: Move CNT*_CTL_EL0 userspace accessors to generic
infrastructure
KVM: arm64: Move CNT*_CVAL_EL0 userspace accessors to generic
infrastructure
KVM: arm64: Move CNT*CT_EL0 userspace accessors to generic
infrastructure
KVM: arm64: Fix WFxT handling of nested virt
KVM: arm64: Kill leftovers of ad-hoc timer userspace access
KVM: arm64: selftests: Make dependencies on VHE-specific registers
explicit
KVM: arm64: selftests: Add an E2H=0-specific configuration to
get_reg_list
KVM: arm64: selftest: Fix misleading comment about virtual timer
encoding

arch/arm64/kvm/arch_timer.c | 105 ++-------------
arch/arm64/kvm/guest.c | 70 ----------
arch/arm64/kvm/handle_exit.c | 7 +-
arch/arm64/kvm/sys_regs.c | 123 +++++++++++++++---
arch/arm64/kvm/sys_regs.h | 6 +
include/kvm/arm_arch_timer.h | 24 ++--
.../selftests/kvm/arm64/get-reg-list.c | 99 +++++++++++++-
7 files changed, 240 insertions(+), 194 deletions(-)

--
2.47.3