[PATCH 05/13] KVM: arm64: Add timer UAPI workaround to sysreg infrastructure
Oliver Upton
oliver.upton at linux.dev
Mon Sep 29 17:41:01 PDT 2025
On Mon, Sep 29, 2025 at 05:04:49PM +0100, Marc Zyngier wrote:
> Amongst the numerous bugs that plague the KVM/arm64 UAPI, one of
> the most annoying thing is that the userspace view of the virtual
> timer has its CVAL and CNT encodings swapped.
>
> In order to reduce the amount of code that has to know about this,
> start by adding handling for this bug in the sys_reg code.
>
> Nothing is making use of it yet, as the code responsible for userspace
> interaction is catching the accesses early.
>
> Signed-off-by: Marc Zyngier <maz at kernel.org>
> ---
> arch/arm64/kvm/sys_regs.c | 33 ++++++++++++++++++++++++++++++---
> arch/arm64/kvm/sys_regs.h | 6 ++++++
> 2 files changed, 36 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 9f2f4e0b042e8..8e6f50f54b4bf 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -5231,15 +5231,28 @@ static int demux_c15_set(struct kvm_vcpu *vcpu, u64 id, void __user *uaddr)
> }
> }
>
> +static u64 kvm_one_reg_to_id(const struct kvm_one_reg *reg)
> +{
> + switch(reg->id) {
> + case KVM_REG_ARM_TIMER_CVAL:
> + return TO_ARM64_SYS_REG(CNTV_CVAL_EL0);
> + case KVM_REG_ARM_TIMER_CNT:
> + return TO_ARM64_SYS_REG(CNTVCT_EL0);
> + default:
> + return reg->id;
> + }
> +}
> +
Seems like a good spot to name n' blame the commit that introduced this
bug as a comment.
Thanks,
Oliver
More information about the linux-arm-kernel
mailing list