From patchwork Wed Oct 9 19:00:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13829191 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 805F5CEE343 for ; Wed, 9 Oct 2024 20:10:35 +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=Ycxh5rox9HhaNw3AIr0DZE2DTW/34fR+p7ZUBZff9ck=; b=waIZTik7poOjrlhIcRBNjwHukB vesCdtvtlBSueMbCGa1KBmtpwvJ0qyTO+gFtqjGUkLiCYv3vixO4IQeTvv0UQmbjRbIZYvM5hFEdT qQUr3UdJYPUUucwHWYCLuOLJ6NIUkyiatbZd3lLoLkbKHixcPMBjsXNMlGVAiNvqI22ey2bAf3Sfm b6uHRu8UVwUZWs7bVJa05OtVRYUwwbD+vRHjLlfrelo0IeZBhz7NIcmtjPtLWx+TEBWlr5DQSw8uX 1DV6GRKI3xmNqOdUhy3WE7bRg/4eS0CZ6Cb7R5/xUCQueVOrnurcxnV352k8rPYs/5TMtLtcxgax7 QyPF7jDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syd0o-0000000Aa7e-0oeM; Wed, 09 Oct 2024 20:10:22 +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-0000000ARRl-1Esh 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=Ycxh5rox9HhaNw3AIr0DZE2DTW/34fR+p7ZUBZff9ck=; b=XQ8B7Ax0G362S0I4SlTM54SGne BAM4XYhJsk4gzqzq5QXUfEvGwdSwXqfypQTqdu/OuKw0+h8KYNlt423P82Ve7wxZVPJBES2m88p8+ mXLTw6Sr5BZl/KVrTmgJ7JGeGZ+ns2FJWcwz1WCYOaI13AKBOgBQ7d4Pn9a7iJ1mGk09nfNewmiJt WNHltqQ2HxHlP+ppXEb+F6pol7wD+HnBoj138MGFi2euU0IP9+VG8oTrj/BcTGM2eIB4d4ykLcwUu CNxCKq3mLJ35gPGwAKmP0D3FhwlS4euy/9YK8WWi/CFfQnIuKo9IaAhBMQC+Set9tnywiNwacRsoc VkI4Xvwg==; 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 1sybvb-000000055np-375r for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 19:00:57 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 319425C5C98; Wed, 9 Oct 2024 19:00:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DE38C4CEC3; Wed, 9 Oct 2024 19:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728500448; bh=2MWftYygg8uIBjl90XXJMB7RiCbzJSCjHPiHWt2IHTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n9Yece0FlprB/TjuDIKdFHlBt5jDQ905j2CvG4eJXV2FkG/8UcZoS5TyOsM30uCYj Qw+nWMlWAvpem9LW/B9gg0mH6RbIZFCK6dNq8iZ38HlEZXJ6FkhvMkpPPYSUvnuI8e FmFLjJsH+Xm3FUwCr4tbZyq34hHcitRwv+X5SkVaCouYIq7cMyI9yZt8t0VMSL5K+6 uGF6vlDBcpZvZb3J7lCFnJoL5RCm32GacEUJP6dGZPfUxZ+bD4jqQtVpjrXtDBM9cL EPspELq8MNs2is3yVBbf2+jiyzR6Asu7MwAjTCVxhc8DFs3qzYoVF18Sgyab9oBdEE AY/vB/+NZlfew== 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 1sybvS-001wcY-Be; Wed, 09 Oct 2024 20:00:46 +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 27/36] KVM: arm64: Add a composite EL2 visibility helper Date: Wed, 9 Oct 2024 20:00:10 +0100 Message-Id: <20241009190019.3222687-28-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_290798_9600A7B6 X-CRM114-Status: GOOD ( 12.95 ) 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 We are starting to have a bunch of visibility helpers checking for EL2 + something else, and we are going to add more. Simplify things somehow by introducing a helper that implement extractly that by taking a visibility helper as a parameter, and convert the existing ones to that. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index b5c2662662af9..6c20de8607b2d 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -2277,16 +2277,18 @@ static u64 reset_hcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) return __vcpu_sys_reg(vcpu, r->reg) = val; } +static unsigned int __el2_visibility(const struct kvm_vcpu *vcpu, + const struct sys_reg_desc *rd, + unsigned int (*fn)(const struct kvm_vcpu *, + const struct sys_reg_desc *)) +{ + return el2_visibility(vcpu, rd) ?: fn(vcpu, rd); +} + static unsigned int sve_el2_visibility(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd) { - unsigned int r; - - r = el2_visibility(vcpu, rd); - if (r) - return r; - - return sve_visibility(vcpu, rd); + return __el2_visibility(vcpu, rd, sve_visibility); } static bool access_zcr_el2(struct kvm_vcpu *vcpu, @@ -2332,13 +2334,7 @@ static unsigned int tcr2_visibility(const struct kvm_vcpu *vcpu, static unsigned int tcr2_el2_visibility(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd) { - unsigned int r; - - r = el2_visibility(vcpu, rd); - if (r) - return r; - - return tcr2_visibility(vcpu, rd); + return __el2_visibility(vcpu, rd, tcr2_visibility); } static unsigned int s1pie_visibility(const struct kvm_vcpu *vcpu, @@ -2353,13 +2349,7 @@ static unsigned int s1pie_visibility(const struct kvm_vcpu *vcpu, static unsigned int s1pie_el2_visibility(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd) { - unsigned int r; - - r = el2_visibility(vcpu, rd); - if (r) - return r; - - return s1pie_visibility(vcpu, rd); + return __el2_visibility(vcpu, rd, s1pie_visibility); } /*