From patchwork Wed Oct 9 19:00:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13829192 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 99C14CEE348 for ; Wed, 9 Oct 2024 20:10:37 +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-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bIpwi29lheeMwvqgDAPhuhLTmCIT2zWF92NlYWOzaGg=; b=IyqtWU6U8uOdU5wK7RVu5j7FRm WU03uPopdFt5/YySS3ugaFaDNmUUTHFK3/PY6/emTC5aca/wmindPAcF8Ii12zxFf8VxcEGhGlqD5 rth+Y2otGZLd18rSMR/ubpJU/uL51XKLZuUw+y1HdK8eAJirXqwhHcE1awxpkGs09P/rfsm0zQRpz ON0r8FbWiP5yezujfS/Aei+VZtEg9yzratHqhDMhD+AC8ehBN/RuA+ff5POVCkPaTLCJtHa1FCfLL OCc6OKX7cAk9vICTVQKnnCOYsfllUXxvbYr3vWnW2rBwV2Rb6EXA1uBa4SeXlZowb0MqFjA0M78TK zZUl4pKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syd0r-0000000AaAP-0Rgd; Wed, 09 Oct 2024 20:10:25 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sybvf-0000000ARRz-2NsJ for linux-arm-kernel@bombadil.infradead.org; Wed, 09 Oct 2024 19:00:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=bIpwi29lheeMwvqgDAPhuhLTmCIT2zWF92NlYWOzaGg=; b=bDKPAGQTekz76i7KXHQtu4qW9d jLejcXE93//HpcagDCNR31obfM2s10tAWWu7SDwCAcLyVup/BK7M07ZE4Togs4QG7NYqtblQ7dTq/ TkJ1MZWRILleRH/Il7plhqrt8jl+2nwBWklhL2RyxI8R44boJ1jhiSrGsXxhZn1y7NoOslL6YWtGA 1ZT1TqXAvQjKDWqNbv4jAwSxjRA8tW77EWwVYjbzUTi6JV2HzaoafmdmDPtgI1Q++BPrp1S8yODUw xoaUQYCZ/vxPPRSkYy/E2/Ok1EbrCO9J5ZcaYFllVmKIrplQQy/V9fvUeY6JyGAG0tlq3JsIDgKCM xguWUrKw==; Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sybvc-000000055o8-0Fbz for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 19:00:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id DC37F5C5DA7; Wed, 9 Oct 2024 19:00:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1BBCC4CECF; Wed, 9 Oct 2024 19:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728500449; bh=S+4M6AqxYHPECoZd/6otmEP6eUdum4OgU87CLXx3t/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WOu4wdTUiNh5KBiW/FnUcmsYXXFJ2fC1DTwN6DM172mEPILIK0BA2450fnqBl2TAj Xqaob6MX7WMpU7OpaUpMrRqLBK0dPAKp1SSPj1hwkdmkfRkoEABUAPrQpEw9SXvRZD P1zjGk4WvYJ0DI9AnhLC5Kj2pNFW8thsii/lodlr9E4W5Zvi071uBTCDCW5zB40w7W C9t5QhicbPWbpM3AnU5/Kr1U5gEO1fT8zHj7k78+/27NqcS80aBVPlVrZIbSq+Wj1R G05WPmTFuR/a8Uq2QRs03AqpUfYrc6x7vFjyijWPnV61zQvD/LnJeAwP2WORjFtiXn d9qWe9K2FlNhw== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sybvT-001wcY-Vg; Wed, 09 Oct 2024 20:00:48 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: Joey Gouly , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Alexandru Elisei , Mark Brown Subject: [PATCH v4 34/36] KVM: arm64: Make PAN conditions part of the S1 walk context Date: Wed, 9 Oct 2024 20:00:17 +0100 Message-Id: <20241009190019.3222687-35-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241009190019.3222687-1-maz@kernel.org> References: <20241009190019.3222687-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, alexandru.elisei@arm.com, 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-20241009_200056_491972_8B818B63 X-CRM114-Status: GOOD ( 13.12 ) 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 Move the conditions describing PAN as part of the s1_walk_info structure, in an effort to declutter the permission processing. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/at.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c index 301399f17983f..4ab87d75807ff 100644 --- a/arch/arm64/kvm/at.c +++ b/arch/arm64/kvm/at.c @@ -26,6 +26,7 @@ struct s1_walk_info { bool hpd; bool e0poe; bool poe; + bool pan; bool be; bool s2; }; @@ -151,6 +152,8 @@ static int setup_s1_walk(struct kvm_vcpu *vcpu, u32 op, struct s1_walk_info *wi, wi->regime = compute_translation_regime(vcpu, op); as_el0 = (op == OP_AT_S1E0R || op == OP_AT_S1E0W); + wi->pan = (op == OP_AT_S1E1RP || op == OP_AT_S1E1WP) && + (*vcpu_cpsr(vcpu) & PSR_PAN_BIT); va55 = va & BIT(55); @@ -1020,10 +1023,12 @@ static void compute_s1_indirect_permissions(struct kvm_vcpu *vcpu, } } -static void compute_s1_permissions(struct kvm_vcpu *vcpu, u32 op, +static void compute_s1_permissions(struct kvm_vcpu *vcpu, struct s1_walk_info *wi, struct s1_walk_result *wr) { + bool pan; + if (!s1pie_enabled(vcpu, wi->regime)) compute_s1_direct_permissions(vcpu, wi, wr); else @@ -1032,14 +1037,10 @@ static void compute_s1_permissions(struct kvm_vcpu *vcpu, u32 op, if (!wi->hpd) compute_s1_hierarchical_permissions(vcpu, wi, wr); - if (op == OP_AT_S1E1RP || op == OP_AT_S1E1WP) { - bool pan; - - pan = *vcpu_cpsr(vcpu) & PSR_PAN_BIT; - pan &= wr->ur || wr->uw || (pan3_enabled(vcpu, wi->regime) && wr->ux); - wr->pw &= !pan; - wr->pr &= !pan; - } + pan = wi->pan && (wr->ur || wr->uw || + (pan3_enabled(vcpu, wi->regime) && wr->ux)); + wr->pw &= !pan; + wr->pr &= !pan; } static u64 handle_at_slow(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) @@ -1065,7 +1066,7 @@ static u64 handle_at_slow(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) if (ret) goto compute_par; - compute_s1_permissions(vcpu, op, &wi, &wr); + compute_s1_permissions(vcpu, &wi, &wr); switch (op) { case OP_AT_S1E1RP: