From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31671CAC5B8 for ; Tue, 30 Sep 2025 07:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AjmlsFXsEb5dUSD8UeDmYt2O9rq54iquohjd6IFvKkQ=; b=b6CxM9pPsyUNdeILEnsROGwypD sV5gSP9L4JKruvG9e9C/YTFonF/k2adXVb7xCy2MKtsuttHao0urTi9COM+iy8OR+YvoEqTLFnCWt 5oLTCpJdee2KscdGrF1CT3A4AYDFCBlI2NwcLS317Ib7TAVqCSjmgXMWYF1i0y4jKKVgP2EHwn+2X /RTkvdVFNJYUHPXFKo/qhlCfmhQz7dLJb5381hrc2VCnPDisaf2xX20DLaFuNp/DgkAHOtUlD8SaJ BfKPojUGVPV3YGXG7m/XnAmDI7nSTUx7pbDebAcKUrw4t0OcS+OKGW3Ro85OYFadwhBoAfK549GQz qEWRueOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1v3V5q-00000004XaU-0YXi; Tue, 30 Sep 2025 07:48:14 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1v3V5o-00000004XaO-2FSR for linux-arm-kernel@lists.infradead.org; Tue, 30 Sep 2025 07:48:13 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id A67FA62796; Tue, 30 Sep 2025 07:48:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59F20C4CEF0; Tue, 30 Sep 2025 07:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759218491; bh=4T+XQXD3LHjmczUTO39ClqL11skFL4B6shLS9cZAwxg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=VEb6B3/VJCPnNK82slvGZUWFmpJmpyI1qBH3M/UFtekDuEB5dYj3Bh2HmPpUDQWG2 FUuOEQuna1z47W2eRq9cT8S7UgGr6SRNHaDXYLg/DKpH2UH2mcZFO7Jx5Z6zoTOx4B YvGLdTnc2DzGGnI9FVZwFYJ/2I4PcIZCiW1KgRyDSb7yRYQsC/qOAcOQo5hgIY0PfE +9uc9WIHYYprNuQIprPEv1V5Dj3FEN2xoBH93sWfRRIeVQ/ot9a0PUDW+cBSsizW/5 3G67FiEx+g9yi2ZPclLFzE7Obfo/dgzm/iFUCduaIr8jI6HAukBoGnqxx3B/i3w84g hJeL8R5oNmVbw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1v3V5l-0000000ASwF-0Ixc; Tue, 30 Sep 2025 07:48:09 +0000 Date: Tue, 30 Sep 2025 08:48:08 +0100 Message-ID: <86y0pwz8hz.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Joey Gouly , Suzuki K Poulose , Zenghui Yu Subject: Re: [PATCH 05/13] KVM: arm64: Add timer UAPI workaround to sysreg infrastructure In-Reply-To: References: <20250929160458.3351788-1-maz@kernel.org> <20250929160458.3351788-6-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: oliver.upton@linux.dev, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 30 Sep 2025 01:41:01 +0100, Oliver Upton 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 > > --- > > 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.