From patchwork Tue Aug 13 10:05:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13761724 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 13B44C52D7C for ; Tue, 13 Aug 2024 10:12:38 +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=EDOsUyfGJ2VOhlE+5LyyYLl7fNjtrqcFovQ0TyLxjik=; b=syj+1dT3narHk1Pnt+Dhi8ecNT sxrPrht1ab1plgD9EX5T5vSJGFYTFx6ji4ErN2rXzofUrxw76t7VtUKqHBhJGFjKDtNDalHuCPBrY sw02yYkxFnUlDc805Nt/ucXhpPnhF+rMslwXu4nnZozgY9yanmi1yfzJYsmOUy/8ELeuQM40a2WPf X9FP/3ax5yiOe7PFd5ivHig4rbTDMOeJw+lbIaoNlERi35RCzDY9phw4EdXRrC5jqRs+v8pSGM1mO Hkk968FmRwhIga+PzBSuFSR+tmdpsgq04MMJFpW+07h2pTe6mk9RG24DY0Hz47+TTbn+5kFS0TFeW DhhZtuiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdoVw-00000003IAZ-2dyR; Tue, 13 Aug 2024 10:12:28 +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 1sdoQ4-00000003GPw-2F35 for linux-arm-kernel@lists.infradead.org; Tue, 13 Aug 2024 10:06:26 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BCB1261616; Tue, 13 Aug 2024 10:06:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C5FFC4AF12; Tue, 13 Aug 2024 10:06:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723543583; bh=vSHhjuKzB4XiKT8IC31iaRepSYA94uoZc8/lCfNk+mU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C54js7vh+jUxyAnie49ehuXwSaF8cTk++XqfbsBy09wi2Pdsszoz78IjhRy2Gqg9r G2ESrh3ZiwnPp0ND6rgmuBKJn8eVEpwbF436pnKGNIZ2sjqKsRGOFyBu1qhuBHomr3 rk4HXeezTqpVvFdnXCynPGY8s/6mAsg1CpnrXO7zUXIBE5fV2GpzNNO66qL2alyYRS UFqcUsdJHf2/tu3x1N3Hynt4hXa4fOZphPtYFV3asz/RAX46Ie6eB/VTN+MWkemo8f bFCDGNUQrELTJUy3FZELu7BLph+GvBXihzsyy/+5G5t3egJBZMsSCz6m2Xwt3rlPNX FRx3NHxddKH6Q== 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 1sdoQ1-003INM-QA; Tue, 13 Aug 2024 11:06:21 +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 , Anshuman Khandual , Przemyslaw Gaj Subject: [PATCH v3 10/18] KVM: arm64: nv: Add basic emulation of AT S1E1{R,W}P Date: Tue, 13 Aug 2024 11:05:32 +0100 Message-Id: <20240813100540.1955263-11-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240813100540.1955263-1-maz@kernel.org> References: <20240813100540.1955263-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, anshuman.khandual@arm.com, pgaj@cadence.com 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-20240813_030624_711798_5BB47F00 X-CRM114-Status: GOOD ( 12.19 ) 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 Building on top of our primitive AT S1E{0,1}{R,W} emulation, add minimal support for the FEAT_PAN2 instructions, momentary context-switching PSTATE.PAN so that it takes effect in the context of the guest. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/at.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c index da378ad834cd..92df948350e1 100644 --- a/arch/arm64/kvm/at.c +++ b/arch/arm64/kvm/at.c @@ -49,6 +49,28 @@ static void __mmu_config_restore(struct mmu_config *config) write_sysreg(config->vtcr, vtcr_el2); } +static bool at_s1e1p_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) +{ + u64 host_pan; + bool fail; + + host_pan = read_sysreg_s(SYS_PSTATE_PAN); + write_sysreg_s(*vcpu_cpsr(vcpu) & PSTATE_PAN, SYS_PSTATE_PAN); + + switch (op) { + case OP_AT_S1E1RP: + fail = __kvm_at(OP_AT_S1E1RP, vaddr); + break; + case OP_AT_S1E1WP: + fail = __kvm_at(OP_AT_S1E1WP, vaddr); + break; + } + + write_sysreg_s(host_pan, SYS_PSTATE_PAN); + + return fail; +} + /* * Return the PAR_EL1 value as the result of a valid translation. * @@ -105,6 +127,10 @@ static u64 __kvm_at_s1e01_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) isb(); switch (op) { + case OP_AT_S1E1RP: + case OP_AT_S1E1WP: + fail = at_s1e1p_fast(vcpu, op, vaddr); + break; case OP_AT_S1E1R: fail = __kvm_at(OP_AT_S1E1R, vaddr); break;