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 44B3CC3DA49 for ; Sat, 20 Jul 2024 09:50:16 +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=/TKE1+fuiQ3lufB3HVlD/8ZhFJ/3TDZrvQK/xVQbcn4=; b=GmHaeGahdQyUU2M8w2zk0J0Xa4 29DZrcc3PtM+KR2lUqrFLwR0h2DC3te43a9Z6AroyEbOlr4xqO2d2S/0r9xm6QHhM3beUXIlK/bCi pEyAg52GoHQhWXH79u23gSjAMy66ea3D3xnmHU4WQFwnTyjXAxc3pjCdHjwqQvfJ/FOiOcOajrBxd Pcrey1Ro9CGhKMTkEHC+nIi4jAPFrGhBpHnAtVdaEAwrAkB5PiIMI/ihe+8eeFZypcxN9Svq1zCKM ghmomtcRjY+TPbIOsm9nI6BKwlDuBX8MZO3im+AD+ePna0uPbVyfKVsLk9Lj7GMkBV1SDCVsyHJKi O1fq0WVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sV6j2-00000004riV-2Rqd; Sat, 20 Jul 2024 09:50:00 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sV6if-00000004rfY-39Kg for linux-arm-kernel@lists.infradead.org; Sat, 20 Jul 2024 09:49:39 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 870A9CE010F; Sat, 20 Jul 2024 09:49:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFD29C2BD10; Sat, 20 Jul 2024 09:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721468972; bh=Fabkemm15d9bvyMMdzbPwEmfBhmRHwNU94q62xcaQfs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=nr4cr50ORl9NgCybFuvIypLJ61NrnhHyoeI4ZNI0ykz7OP1wiOaYHimSIUbWbOfEM SpQmSnu65Pd7ADtJevbNw3EflKszAOViU2dwcOrHWXqEEyg4QdKvC4ztm1cnfn2psR 7rV78Qaj2vDMA8jmE5samKyVNQWFWJpyG/+M36JACNKb/KOYLrxfrXKs2xLKDgGLcP LYB/2Ml7I+fuJbU7u/ZxJhoX/7a1pndggvsMSKx2Pjhs9n1oYziy9/S35/aMLjugcg UbGuu8ZcvNsM9Ffln5FPpXSsr6nQpHXDaVQD9yOUHtTpdHRMuCbJadDvtGRAU1RxsI syVLgH3dgNbPg== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.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 1sV6iY-00DuaU-HH; Sat, 20 Jul 2024 10:49:30 +0100 Date: Sat, 20 Jul 2024 10:49:29 +0100 Message-ID: <878qxw5r6e.wl-maz@kernel.org> From: Marc Zyngier To: Alexandru Elisei Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Joey Gouly Subject: Re: [PATCH 08/12] KVM: arm64: nv: Add emulation of AT S12E{0,1}{R,W} In-Reply-To: References: <20240625133508.259829-1-maz@kernel.org> <20240625133508.259829-9-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/28.2 (x86_64-pc-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: alexandru.elisei@arm.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, joey.gouly@arm.com 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-20240720_024938_182866_A5399521 X-CRM114-Status: GOOD ( 24.89 ) 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 Thu, 18 Jul 2024 16:10:20 +0100, Alexandru Elisei wrote: > > Hi, > > On Tue, Jun 25, 2024 at 02:35:07PM +0100, Marc Zyngier wrote: > > On the face of it, AT S12E{0,1}{R,W} is pretty simple. It is the > > combination of AT S1E{0,1}{R,W}, followed by an extra S2 walk. > > > > However, there is a great deal of complexity coming from combining > > the S1 and S2 attributes to report something consistent in PAR_EL1. > > > > This is an absolute mine field, and I have a splitting headache. > > > > [..] > > +static u8 compute_sh(u8 attr, u64 desc) > > +{ > > + /* Any form of device, as well as NC has SH[1:0]=0b10 */ > > + if (MEMATTR_IS_DEVICE(attr) || attr == MEMATTR(NC, NC)) > > + return 0b10; > > + > > + return FIELD_GET(PTE_SHARED, desc) == 0b11 ? 0b11 : 0b10; > > If shareability is 0b00 (non-shareable), the PAR_EL1.SH field will be 0b10 > (outer-shareable), which seems to be contradicting PAREncodeShareability(). Yup, well caught. > > + par |= FIELD_PREP(SYS_PAR_EL1_SH, > > + compute_sh(final_attr, tr->desc)); > > + > > + return par; > > > > It seems that the code doesn't combine shareability attributes, as per rule > RGDTNP and S2CombineS1MemAttrs() or S2ApplyFWBMemAttrs(), which both end up > calling S2CombineS1Shareability(). That as well. See below what I'm stashing on top. Thanks, M. diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c index e66c97fc1fd3..28c4344d1c34 100644 --- a/arch/arm64/kvm/at.c +++ b/arch/arm64/kvm/at.c @@ -459,13 +459,34 @@ static u8 combine_s1_s2_attr(u8 s1, u8 s2) return final; } +#define ATTR_NSH 0b00 +#define ATTR_RSV 0b01 +#define ATTR_OSH 0b10 +#define ATTR_ISH 0b11 + static u8 compute_sh(u8 attr, u64 desc) { + u8 sh; + /* Any form of device, as well as NC has SH[1:0]=0b10 */ if (MEMATTR_IS_DEVICE(attr) || attr == MEMATTR(NC, NC)) - return 0b10; + return ATTR_OSH; + + sh = FIELD_GET(PTE_SHARED, desc); + if (sh == ATTR_RSV) /* Reserved, mapped to NSH */ + sh = ATTR_NSH; + + return sh; +} + +static u8 combine_sh(u8 s1_sh, u8 s2_sh) +{ + if (s1_sh == ATTR_OSH || s2_sh == ATTR_OSH) + return ATTR_OSH; + if (s1_sh == ATTR_ISH || s2_sh == ATTR_ISH) + return ATTR_ISH; - return FIELD_GET(PTE_SHARED, desc) == 0b11 ? 0b11 : 0b10; + return ATTR_NSH; } static u64 compute_par_s12(struct kvm_vcpu *vcpu, u64 s1_par, @@ -540,7 +561,8 @@ static u64 compute_par_s12(struct kvm_vcpu *vcpu, u64 s1_par, par = FIELD_PREP(SYS_PAR_EL1_ATTR, final_attr); par |= tr->output & GENMASK(47, 12); par |= FIELD_PREP(SYS_PAR_EL1_SH, - compute_sh(final_attr, tr->desc)); + combine_sh(FIELD_GET(SYS_PAR_EL1_SH, s1_par), + compute_sh(final_attr, tr->desc))); return par; } -- Without deviation from the norm, progress is not possible.