From patchwork Wed Jul 31 19:40:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13749144 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 C8750C3DA64 for ; Wed, 31 Jul 2024 19:48:27 +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=iMIBYuUgdl2cTlGwq7LvdzYDkc mvdZwQGphz2cX1tSN5gV44aaNBwUbkU7MQzdJeH4IllF2NuMbq5cmMEQagBxY7Db6vm9hPJiblj8m +sZQhpk18UYDp2o6Zdf+AVA8MJSR7QVrJFdtlwGezBxk05h9eaeQCkAeafyNVN6nWnxE6LzDJcKPH MLVqhLDIt2fuh5yaSYn0ngSE1WeaH0gHpL5t8b9jafCvSC84EXMb1P0/Mj7zD7G4+4KEyYJ3QPCFy 7yrqr87Tahw767M6lE2l/gz96xup3NqvxfhZofxe1LlAVAczfeaAf/QghL157sbKzi6tlnhN3myW0 1sbi+FdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZFJ4-00000002Lzr-2ERO; Wed, 31 Jul 2024 19:48:18 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZFBz-00000002Jhr-1GOd for linux-arm-kernel@lists.infradead.org; Wed, 31 Jul 2024 19:41:02 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 4F7E7CE1804; Wed, 31 Jul 2024 19:40:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 814DBC4AF14; Wed, 31 Jul 2024 19:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722454856; bh=vSHhjuKzB4XiKT8IC31iaRepSYA94uoZc8/lCfNk+mU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fepE5hm3b3S259rwLJlthl1W/aYX/LoOe7tpgUznxAKumBl1pSc58VZK1yYVFbj7V 4G3IY+l86if/ATULD/VjqZxee9P13KxPD3Kgg6XKZC5yZQ68PS+04vFUgKwRhZOp8h WB524cWW2yJZWRyw19YEdq4l9tZNuuM7KnTBykiTgG1W7/6PGpSTCwnfIZbDfxnOvt 5BWmHL5tJsN8kGFRfqHDjjHtwX1UTBRMkEuieBj63CujF7ycJLGMczDpe9g0+b0Hf+ KkxI+0w73tRIiodMmr1Oec5+gW7hPkYgCLn6w4fWKK/99Gg7NNQqv+BLDhz6vlT2Cp Sk87TCgqihRmg== 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 1sZFBu-00H6Gh-SG; Wed, 31 Jul 2024 20:40:54 +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 v2 09/17] KVM: arm64: nv: Add basic emulation of AT S1E1{R,W}P Date: Wed, 31 Jul 2024 20:40:22 +0100 Message-Id: <20240731194030.1991237-10-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240731194030.1991237-1-maz@kernel.org> References: <20240731194030.1991237-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-20240731_124059_718396_43A8736F X-CRM114-Status: GOOD ( 12.14 ) 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;