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 73132C46CD2 for ; Wed, 24 Jan 2024 16:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ilOkjQ8fqMql5YhM6Y6cQdAi76G4wSPOV2AgHgLYkkU=; b=yfwbrwl26/UKos 4NaBzVOMlwqEm5puZeC4c8zesOaB1lUcbYdttR8gBPqoboaFXRz4+ZARGsiXKH0JZBCsIfG2M+Ayd EmPUmwpPshITyA2Xq8eKGpfg0b4jrGdzCZHv9wc4VfAq5yz5YaT+BA7Nw5qBsxE1x4Rl67JCkH/xn +c8MsC8RgDSST+f2Xckg+uJwAhEiScejBTF6/juvj7Z2iHJw7DEzvvq3Tz0dUcKQ/osfrD8JFkmTk vj6aQqQqUY6pEn3zzfrBhXLc4sBcXSRDGcK3FSwyNEWkZt6Y2YaFiaLZyNg28H6852fGiWqoYV8ao +AYeRMauZvZV3X+pm/8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSgFm-004EW8-2K; Wed, 24 Jan 2024 16:37:30 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSgFk-004EVQ-03 for linux-arm-kernel@lists.infradead.org; Wed, 24 Jan 2024 16:37:29 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 223D061DA4; Wed, 24 Jan 2024 16:37:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB8E9C433C7; Wed, 24 Jan 2024 16:37:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706114246; bh=EGze84r6gDmuMCfkhYzIK84AhSJ3vy8tSde0Y83n8zo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=X9QotWp65ZyiIKNBqSd+y615MIL6iA8thmLEL6/lJM70JBjufhwyOJFP5JKApFwLW gMiifPLRx4OQdKKW6cHoSpxDVJweiw2l9Bm9GeVnuQXQpXdTTZXouBEzEExcf1e8o/ Ag3FIiC78g+iOQCrtsK0WGabGBzDAVHg1gGJkFLYZzYYgTDAwH1ertQAJn+6k8MLxb pv1zy/ZtiL9HhlOSpcY2GEYHj/SjCOQf+c0kR0ASda3lzSP14btbtGCz9W0xP8B1s7 KzU7J5k5dzFURw1DxzpeyRtUPXltM1W+5VevPkwl/Uu38tQsUPJBh8mh5Jx9iwFpvp msBfUlyktSpSQ== 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.95) (envelope-from ) id 1rSgFg-00EO3o-6L; Wed, 24 Jan 2024 16:37:24 +0000 Date: Wed, 24 Jan 2024 16:37:23 +0000 Message-ID: <86a5ou8z7g.wl-maz@kernel.org> From: Marc Zyngier To: Joey Gouly Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Brown Subject: Re: [PATCH 14/25] KVM: arm64: Register AArch64 system register entries with the sysreg xarray In-Reply-To: <20240124163425.GJ1283334@e124191.cambridge.arm.com> References: <20240122201852.262057-1-maz@kernel.org> <20240122201852.262057-15-maz@kernel.org> <20240124163425.GJ1283334@e124191.cambridge.arm.com> 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/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: joey.gouly@arm.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, broonie@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240124_083728_158888_36416F72 X-CRM114-Status: GOOD ( 33.43 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 24 Jan 2024 16:34:25 +0000, Joey Gouly wrote: > > On Mon, Jan 22, 2024 at 08:18:41PM +0000, Marc Zyngier wrote: > > In order to reduce the number of lookups that we have to perform > > when handling a sysreg, register each AArch64 sysreg descriptor > > with the global xarray. The index of the descriptor is stored > > as a 10 bit field in the data word. > > > > Subsequent patches will retrieve and use the stored index. > > > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/include/asm/kvm_host.h | 3 +++ > > arch/arm64/kvm/emulate-nested.c | 39 +++++++++++++++++++++++++++++-- > > arch/arm64/kvm/sys_regs.c | 11 ++++++++- > > 3 files changed, 50 insertions(+), 3 deletions(-) > > > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > > index fe35c59214ad..e7a6219f2929 100644 > > --- a/arch/arm64/include/asm/kvm_host.h > > +++ b/arch/arm64/include/asm/kvm_host.h > > @@ -1083,6 +1083,9 @@ int kvm_handle_cp10_id(struct kvm_vcpu *vcpu); > > void kvm_reset_sys_regs(struct kvm_vcpu *vcpu); > > > > int __init kvm_sys_reg_table_init(void); > > +struct sys_reg_desc; > > +int __init populate_sysreg_config(const struct sys_reg_desc *sr, > > + unsigned int idx); > > int __init populate_nv_trap_config(void); > > > > bool lock_all_vcpus(struct kvm *kvm); > > diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c > > index 59622636b723..342d43b66fda 100644 > > --- a/arch/arm64/kvm/emulate-nested.c > > +++ b/arch/arm64/kvm/emulate-nested.c > > @@ -427,12 +427,14 @@ static const complex_condition_check ccc[] = { > > * [19:14] bit number in the FGT register (6 bits) > > * [20] trap polarity (1 bit) > > * [25:21] FG filter (5 bits) > > - * [62:26] Unused (37 bits) > > + * [35:26] Main SysReg table index (10 bits) > > + * [62:36] Unused (27 bits) > > * [63] RES0 - Must be zero, as lost on insertion in the xarray > > */ > > #define TC_CGT_BITS 10 > > #define TC_FGT_BITS 4 > > #define TC_FGF_BITS 5 > > +#define TC_MSR_BITS 10 > > > > union trap_config { > > u64 val; > > @@ -442,7 +444,8 @@ union trap_config { > > unsigned long bit:6; /* Bit number */ > > unsigned long pol:1; /* Polarity */ > > unsigned long fgf:TC_FGF_BITS; /* Fine Grained Filter */ > > - unsigned long unused:37; /* Unused, should be zero */ > > + unsigned long msr:TC_MSR_BITS; /* Main SysReg index */ > > + unsigned long unused:27; /* Unused, should be zero */ > > unsigned long mbz:1; /* Must Be Zero */ > > }; > > }; > > @@ -1862,6 +1865,38 @@ int __init populate_nv_trap_config(void) > > return ret; > > } > > > > +int __init populate_sysreg_config(const struct sys_reg_desc *sr, > > + unsigned int idx) > > +{ > > + union trap_config tc; > > + u32 encoding; > > + void *ret; > > + > > + /* > > + * 0 is a valid value for the index, but not for the storage. > > + * We'll store (idx+1), so check against an offset'd limit. > > + */ > > + if (idx >= (BIT(TC_MSR_BITS) - 1)) { > > + kvm_err("sysreg %s (%d) out of range\n", sr->name, idx); > > + return -EINVAL; > > + } > > + > > + encoding = sys_reg(sr->Op0, sr->Op1, sr->CRn, sr->CRm, sr->Op2); > > + tc = get_trap_config(encoding); > > + > > + if (tc.msr) { > > + kvm_err("sysreg %s (%d) duplicate entry (%d)\n", > > + sr->name, idx - 1, tc.msr); > > + return -EINVAL; > > + } > > + > > + tc.msr = idx + 1; > > + ret = xa_store(&sr_forward_xa, encoding, > > + xa_mk_value(tc.val), GFP_KERNEL); > > + > > + return xa_err(ret); > > +} > > + > > static enum trap_behaviour get_behaviour(struct kvm_vcpu *vcpu, > > const struct trap_bits *tb) > > { > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > > index 77cd818c23b0..65319193e443 100644 > > --- a/arch/arm64/kvm/sys_regs.c > > +++ b/arch/arm64/kvm/sys_regs.c > > @@ -3974,6 +3974,7 @@ int __init kvm_sys_reg_table_init(void) > > struct sys_reg_params params; > > bool valid = true; > > unsigned int i; > > + int ret = 0; > > > > /* Make sure tables are unique and in order. */ > > valid &= check_sysreg_table(sys_reg_descs, ARRAY_SIZE(sys_reg_descs), false); > > @@ -3997,5 +3998,13 @@ int __init kvm_sys_reg_table_init(void) > > if (!first_idreg) > > return -EINVAL; > > > > - return populate_nv_trap_config(); > > + ret = populate_nv_trap_config(); > > + > > + for (i = 0; !ret && i < ARRAY_SIZE(sys_reg_descs); i++) > > + ret = populate_sysreg_config(sys_reg_descs + i, i); > > + > > + for (i = 0; !ret && i < ARRAY_SIZE(sys_insn_descs); i++) > > + ret = populate_sysreg_config(sys_insn_descs + i, i); > > + > > + return ret; > > } > > The choice of `msr` was a tiny bit confusing due to the conflict with the asm > instruction `msr`, but not enough to warrant renaming. No, that's actually a very good point. How about SRI (Sys Reg Index)? > Reviewed-by: Joey Gouly Thanks! M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel