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 C4E2AC3DA5D for ; Mon, 22 Jul 2024 10:34:28 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From: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=Udrf+vnaQKC2YlQEGmE9AL3YD+6gvia8KmC9csNB9No=; b=If3uHxfMYviw+1BQ93gE6pLqC1 5SMBGBPykUqQ+0kqF+WXnpkTj9nTV6rOYoq03wvcozqStsjVLhcGS4BpI/iWzICK1blaRqRfHUqdI Q8usrpEUbOniglQdPhE/fExFFv1EMCaXY9jSSYLpxm1TsvcuWztFRdM01leThkCQ7aNnfgMGfwrVu zH9eIaqi2FO2+uCl7+vAZs1Ey3mA9J4k38fcQaDM3twXdLAN72AbaCnHYpSzTHVSpSTMvkdWRScw1 ysOS1kIDbjIF8kChplu/Ooj9QAtAW19RVR0376e3/LsJdWOrE10cycVjtARZ/ZIbWphgOuWlgjN4h NYxPpirQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sVqN0-00000009Ggi-2LiA; Mon, 22 Jul 2024 10:34:18 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sVqMd-00000009Gds-2GWr for linux-arm-kernel@lists.infradead.org; Mon, 22 Jul 2024 10:33:56 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E5658FEC; Mon, 22 Jul 2024 03:34:17 -0700 (PDT) Received: from raptor (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DF3B43F73F; Mon, 22 Jul 2024 03:33:50 -0700 (PDT) Date: Mon, 22 Jul 2024 11:33:47 +0100 From: Alexandru Elisei To: Marc Zyngier 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} Message-ID: References: <20240625133508.259829-1-maz@kernel.org> <20240625133508.259829-9-maz@kernel.org> <878qxw5r6e.wl-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878qxw5r6e.wl-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240722_033355_684895_B7D3686A X-CRM114-Status: GOOD ( 26.82 ) 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 Hi, On Sat, Jul 20, 2024 at 10:49:29AM +0100, Marc Zyngier wrote: > 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 Matches Table D8-89 from DDI 0487K.a. > + > 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; > +} Matches PAREncodeShareability(). > + > +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; > } Matches S2CombineS1Shareability(). > > 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))); Looks good. Thanks, Alex > > return par; > } > > -- > Without deviation from the norm, progress is not possible.