From patchwork Wed Sep 11 13:51:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13800643 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 E15E6EE49B6 for ; Wed, 11 Sep 2024 14:17:51 +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=+uDbdEFjcbNW/F1n595pI5UMbNo1LrcnzgTT8s0XWhI=; b=kb3d3HS7gj4HyDeKSv7BG29KNz lG9APz5Jb26/Y5XIUsO6q69uMb9mxGZbSsmZJXNPXdKXvVuhh97aGQ+sBg2BZHwtdYlCKHRLrftv9 /6cItZiz7Kv0vhdWPwgYAwpSQu7IhUu811tZ89p7/47lfrTT0j65GyliU+pFkh5LgH/VlBm73aZ8t QUahUdd5h1QumodGys/XsNJWhnn5aANlCyuEs+5xSEq99+wjTXi+eYpUmVpncSjTz4k6+yaTW/GjL fsZNYp9cG6B6sq39P0Bz48J1zxeqEolBYy83swFYaQJzEqDH3idgXiXQpalL0pHJJm71JJPOOo73x lf6a16zA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soOA7-00000009rw6-3nxZ; Wed, 11 Sep 2024 14:17:39 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soNlN-00000009mUF-1A5E for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 13:52:10 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C11EE5C076B; Wed, 11 Sep 2024 13:51:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BC2AC4CEC0; Wed, 11 Sep 2024 13:52:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726062722; bh=qQWDVBIloxoZhqiqEm32EkEZjmCLRGOgrGKelqihYxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HWEHFIeTZVpcdZ5PfePhcu3QQG0xbvGz0rGYhJ3HfvAjyqONnRF6C4etTlWnZtHlb PcsYtGyEAY3bcPawGpW6G3REuLq5IhbQnenGOFZ2Eit07XRtGEhq5bVSqqRU0xIZdH HrFB9xx1hAVzmzSXc7k9qIMBU551BP3y//+Dw7VPpltqac6qRP6izj/zbzkQPV6Y4a 4o0NCgUE8J/3YOYlDeHUKGxTcdKrc2gUXeIX36aZBDSaAOxnlrXxyuSHy5WrhMVywD jiFPP6GCR/4hPD1VmWNPO2CmwhbkkqlW+Knsqw+j+mAHoMe82lAs9nBwN4gZ3cloAJ pv0NBlN0RzoUA== 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 1soNlI-00C7tL-Cs; Wed, 11 Sep 2024 14:52:00 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Joey Gouly , Alexandru Elisei , Mark Brown Subject: [PATCH v3 20/24] KVM: arm64: Implement AT S1PIE support Date: Wed, 11 Sep 2024 14:51:47 +0100 Message-Id: <20240911135151.401193-21-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240911135151.401193-1-maz@kernel.org> References: <20240911135151.401193-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, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, joey.gouly@arm.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-20240911_065205_619893_4F505829 X-CRM114-Status: GOOD ( 16.60 ) 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 It doesn't take much effort to imple,emt S1PIE support in AT. This is only a matter of using the AArch64.S1IndirectBasePermissions() encodings for the permission, ignoring GCS which has no impact on AT, and enforce FEAT_PAN3 being enabled as this is a requirement of FEAT_S1PIE. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/at.c | 119 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c index 9a922054d76cf..8a5e1c4682619 100644 --- a/arch/arm64/kvm/at.c +++ b/arch/arm64/kvm/at.c @@ -779,6 +779,9 @@ static bool pan3_enabled(struct kvm_vcpu *vcpu, enum trans_regime regime) if (!kvm_has_feat(vcpu->kvm, ID_AA64MMFR1_EL1, PAN, PAN3)) return false; + if (s1pie_enabled(vcpu, regime)) + return true; + if (regime == TR_EL10) sctlr = vcpu_read_sys_reg(vcpu, SCTLR_EL1); else @@ -862,12 +865,126 @@ static void compute_s1_hierarchical_permissions(struct kvm_vcpu *vcpu, } } +#define pi_idx(v, r, i) ((__vcpu_sys_reg((v), (r)) >> ((i) * 4)) & 0xf) + +#define set_priv_perms(p, r, w, x) \ + do { \ + (p)->pr = (r); \ + (p)->pw = (w); \ + (p)->px = (x); \ + } while (0) + +#define set_unpriv_perms(p, r, w, x) \ + do { \ + (p)->ur = (r); \ + (p)->uw = (w); \ + (p)->ux = (x); \ + } while (0) + +/* Similar to AArch64.S1IndirectBasePermissions(), without GCS */ +#define set_perms(w, p, ip) \ + do { \ + switch ((ip)) { \ + case 0b0000: \ + set_ ## w ## _perms((p), false, false, false); \ + break; \ + case 0b0001: \ + set_ ## w ## _perms((p), true , false, false); \ + break; \ + case 0b0010: \ + set_ ## w ## _perms((p), false, false, true ); \ + break; \ + case 0b0011: \ + set_ ## w ## _perms((p), true , false, true ); \ + break; \ + case 0b0100: \ + set_ ## w ## _perms((p), false, false, false); \ + break; \ + case 0b0101: \ + set_ ## w ## _perms((p), true , true , false); \ + break; \ + case 0b0110: \ + set_ ## w ## _perms((p), true , true , true ); \ + break; \ + case 0b0111: \ + set_ ## w ## _perms((p), true , true , true ); \ + break; \ + case 0b1000: \ + set_ ## w ## _perms((p), true , false, false); \ + break; \ + case 0b1001: \ + set_ ## w ## _perms((p), true , false, false); \ + break; \ + case 0b1010: \ + set_ ## w ## _perms((p), true , false, true ); \ + break; \ + case 0b1011: \ + set_ ## w ## _perms((p), false, false, false); \ + break; \ + case 0b1100: \ + set_ ## w ## _perms((p), true , true , false); \ + break; \ + case 0b1101: \ + set_ ## w ## _perms((p), false, false, false); \ + break; \ + case 0b1110: \ + set_ ## w ## _perms((p), true , true , true ); \ + break; \ + case 0b1111: \ + set_ ## w ## _perms((p), false, false, false); \ + break; \ + } \ + } while (0) + +static void compute_s1_indirect_permissions(struct kvm_vcpu *vcpu, + struct s1_walk_info *wi, + struct s1_walk_result *wr, + struct s1_perms *s1p) +{ + u8 up, pp, idx; + + idx = (FIELD_GET(GENMASK(54, 53), wr->desc) << 2 | + FIELD_GET(BIT(51), wr->desc) << 1 | + FIELD_GET(BIT(6), wr->desc)); + + switch (wi->regime) { + case TR_EL10: + pp = pi_idx(vcpu, PIR_EL1, idx); + up = pi_idx(vcpu, PIRE0_EL1, idx); + break; + case TR_EL20: + pp = pi_idx(vcpu, PIR_EL2, idx); + up = pi_idx(vcpu, PIRE0_EL2, idx); + break; + case TR_EL2: + pp = pi_idx(vcpu, PIR_EL2, idx); + up = 0; + break; + } + + set_perms(priv, s1p, pp); + + if (wi->regime != TR_EL2) + set_perms(unpriv, s1p, up); + else + set_unpriv_perms(s1p, false, false, false); + + if (s1p->px && s1p->uw) { + set_priv_perms(s1p, false, false, false); + set_unpriv_perms(s1p, false, false, false); + } +} + static void compute_s1_permissions(struct kvm_vcpu *vcpu, u32 op, struct s1_walk_info *wi, struct s1_walk_result *wr, struct s1_perms *s1p) { - compute_s1_direct_permissions(vcpu, wi, wr, s1p); + if (!s1pie_enabled(vcpu, wi->regime)) + compute_s1_direct_permissions(vcpu, wi, wr, s1p); + else + compute_s1_indirect_permissions(vcpu, wi, wr, s1p); + compute_s1_hierarchical_permissions(vcpu, wi, wr, s1p); if (op == OP_AT_S1E1RP || op == OP_AT_S1E1WP) {