[PATCH 05/13] KVM: arm64: Add timer UAPI workaround to sysreg infrastructure

Marc Zyngier maz at kernel.org
Tue Sep 30 00:48:08 PDT 2025


On Tue, 30 Sep 2025 01:41:01 +0100,
Oliver Upton <oliver.upton at linux.dev> wrote:
> 
> 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.

Sure. That'd be 39735a3a39043 ("ARM/KVM: save and restore generic
timer registers"), but that's also the first time save/restore was
implemented at all, and there wasn't a sane version before that.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list