From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4036E29A2; Sat, 20 Jul 2024 09:49:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721468973; cv=none; b=e9wJGS+wmPvvDMMDXh6EXNYr2xmcXH68hzdo7y77hpcf9BcGaHgNMFm7jMHvNIa6aE+Z/97uFv/4+KB9G9L/RIRYTqNNngo+0LGy2Hh3V0Zkg3tWf3E/Cc2ajihhNYzNMNvnNOF8DJCAHTlTMlJktRsqmPwh62R+NuZPeOyPnBQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721468973; c=relaxed/simple; bh=Fabkemm15d9bvyMMdzbPwEmfBhmRHwNU94q62xcaQfs=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=JtqHswOlydg2T6HNW5cVfrBgqVKjak0xhj1SOWIR1DJd+7/utcf/AxlafgnW8bfA97k+9wH6Fl4qvDXaRb+suAvmnxP0oU2BWvFVLPbESR+gb4mkcaa1sXdb2tJwR4HkpcqfafpKxo6K2ICxBr8RrFeDgWokbA9m4uIH3iOrnKU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nr4cr50O; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nr4cr50O" 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) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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.