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 44E5DC3DA64 for ; Thu, 18 Jul 2024 15:11:04 +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=8gTePJ/lYKGlQ/v7+da1OfX9rvua1w/rbwp8tMj04Xk=; b=S8UkbrQleAQNpf1wDaEV8ADshO DK7/2E+dvrFiE09ne37pVpTbiZnrmCtkz3hhbQ9u0702/vVntvcMUxuuVYlw0eI98Rm1ShSuJKYZx 3AqaUcYJzkUa3U3CzQfJqRBSAMjJdjdNhZqNQCh2076VP91DXzPbvKxOlgFMY7PM6xgvjXYXJW17u JxIu6jf8THlJQXEtkJaevBloPzOEGnfRKVGDKLVxUxaGYdHE7J48iIBNFSSaBKGfOF2TFr4pIyit3 Hbmsod0gWRdFvHATV5ebNmTyP3kgl0ZZBZd9MWwMil6WgwbEwW1g/6eFqqDYgdO+c5j1L9IXI8eBD 9J3HnmkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUSmQ-0000000HPMp-0OlJ; Thu, 18 Jul 2024 15:10:50 +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 1sUSm3-0000000HPFF-3Zem for linux-arm-kernel@lists.infradead.org; Thu, 18 Jul 2024 15:10:29 +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 C52061063; Thu, 18 Jul 2024 08:10:49 -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 140533F762; Thu, 18 Jul 2024 08:10:22 -0700 (PDT) Date: Thu, 18 Jul 2024 16:10:20 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240625133508.259829-9-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240718_081028_029395_9F45C894 X-CRM114-Status: GOOD ( 20.34 ) 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 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(). > +} > + > +static u64 compute_par_s12(struct kvm_vcpu *vcpu, u64 s1_par, > + struct kvm_s2_trans *tr) > +{ > + u8 s1_parattr, s2_memattr, final_attr; > + u64 par; > + > + /* If S2 has failed to translate, report the damage */ > + if (tr->esr) { > + par = SYS_PAR_EL1_RES1; > + par |= SYS_PAR_EL1_F; > + par |= SYS_PAR_EL1_S; > + par |= FIELD_PREP(SYS_PAR_EL1_FST, tr->esr); > + return par; > + } > + > + s1_parattr = FIELD_GET(SYS_PAR_EL1_ATTR, s1_par); > + s2_memattr = FIELD_GET(GENMASK(5, 2), tr->desc); > + > + if (__vcpu_sys_reg(vcpu, HCR_EL2) & HCR_FWB) { > + if (!kvm_has_feat(vcpu->kvm, ID_AA64PFR2_EL1, MTEPERM, IMP)) > + s2_memattr &= ~BIT(3); > + > + /* Combination of R_VRJSW and R_RHWZM */ > + switch (s2_memattr) { > + case 0b0101: > + if (MEMATTR_IS_DEVICE(s1_parattr)) > + final_attr = s1_parattr; > + else > + final_attr = MEMATTR(NC, NC); > + break; > + case 0b0110: > + case 0b1110: > + final_attr = MEMATTR(WbRaWa, WbRaWa); > + break; > + case 0b0111: > + case 0b1111: > + /* Preserve S1 attribute */ > + final_attr = s1_parattr; > + break; > + case 0b0100: > + case 0b1100: > + case 0b1101: > + /* Reserved, do something non-silly */ > + final_attr = s1_parattr; > + break; > + default: > + /* MemAttr[2]=0, Device from S2 */ > + final_attr = s2_memattr & GENMASK(1,0) << 2; > + } > + } else { > + /* Combination of R_HMNDG, R_TNHFM and R_GQFSF */ > + u8 s2_parattr = s2_memattr_to_attr(s2_memattr); > + > + if (MEMATTR_IS_DEVICE(s1_parattr) || > + MEMATTR_IS_DEVICE(s2_parattr)) { > + final_attr = min(s1_parattr, s2_parattr); > + } else { > + /* At this stage, this is memory vs memory */ > + final_attr = combine_s1_s2_attr(s1_parattr & 0xf, > + s2_parattr & 0xf); > + final_attr |= combine_s1_s2_attr(s1_parattr >> 4, > + s2_parattr >> 4) << 4; > + } > + } > + > + if ((__vcpu_sys_reg(vcpu, HCR_EL2) & HCR_CD) && > + !MEMATTR_IS_DEVICE(final_attr)) > + final_attr = MEMATTR(NC, NC); > + > + 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)); > + > + 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(). Thanks, Alex