From patchwork Fri Feb 14 01:57:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13974351 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 10539C021A0 for ; Fri, 14 Feb 2025 02:12: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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8lGuyHWuxFz6OYFI8+q3ZVAd+TMwOruimegr3QIg4HI=; b=whCCyTp6gFFHUxmNw6PvxYzR0p VOyviZAkKJOU/3r9FoRWa85GfSWBIK0HoL1xC3nWEqroLnkHEWhbX8Klyorxp/DHmXxY4XbrkDJ61 dFcM3+CzyDg68S7XoUAfR5wpa9fecYi7ZCKP+4ZH8/j0Z4yQw3LsLU3Qp/s4na+smwiWtfICW08b2 ZD3JhEgYcayAGGyLvQqJLm1Be7oKAkvQYTxUUqeFRbK/q3rHr5qb027EHVGpOmx+Cxed2Wu8hKMaH lQGhdBPHWfj8NmTwNMtJr0eUP0f0Twqf0gW63fbIrLrSaZRvVzSmdXGblO3DX1/lHMPVuBqVdMdRO lBITy+/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tilC4-0000000DJL4-3lOB; Fri, 14 Feb 2025 02:12:40 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1til1D-0000000DFFa-1y7D for linux-arm-kernel@lists.infradead.org; Fri, 14 Feb 2025 02:01:28 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7D2FF5C5D2B; Fri, 14 Feb 2025 02:00:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B4EDC4CED1; Fri, 14 Feb 2025 02:01:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739498486; bh=ST8cvmEJlmmZZoglNVpZrkW7z4enEIPEfasznNtVTCQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OFTcAcZZd1OnkLlymvGvZ7PaeLBLX/x8RW3R9r40OtIad5SSN3FqHOnxl2DBojztY 4w9+unQOVdxfRhkOE9oX6KkGR5IUtY5Oxy5pQxMFX4RS4/fdkPMOU5AfE3tG3AnrSX ofolpzzj2ODEt6sjZXiVKZLnLHK7RqKkh1e0tgFtewRSinkd37JNdborIhKG9wVAA3 ZvKlT/PoJujmrDA0m6CeuTc3tvQ/WJWNWaVIxzVTl65aww6lrH4itmdbyl42NPzcDI SALjBGVmWcFxV0WlLUtYaw/13YM41S8bA/8vfDU2gysvKYXACEzEIsv91aX9RPr3yM cOCxn6PV7wLrQ== From: Mark Brown Date: Fri, 14 Feb 2025 01:57:50 +0000 Subject: [PATCH v4 07/27] KVM: arm64: Pull ctxt_has_ helpers to start of sysreg-sr.h MIME-Version: 1.0 Message-Id: <20250214-kvm-arm64-sme-v4-7-d64a681adcc2@kernel.org> References: <20250214-kvm-arm64-sme-v4-0-d64a681adcc2@kernel.org> In-Reply-To: <20250214-kvm-arm64-sme-v4-0-d64a681adcc2@kernel.org> To: Marc Zyngier , Oliver Upton , Joey Gouly , Catalin Marinas , Suzuki K Poulose , Will Deacon , Paolo Bonzini , Jonathan Corbet , Shuah Khan Cc: Dave Martin , Fuad Tabba , Mark Rutland , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-1b0d6 X-Developer-Signature: v=1; a=openpgp-sha256; l=3314; i=broonie@kernel.org; h=from:subject:message-id; bh=ST8cvmEJlmmZZoglNVpZrkW7z4enEIPEfasznNtVTCQ=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBnrqPFTI+XTXydWt3dsh69De8TwYqweuNewVUYsHNV 073HGsSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZ66jxQAKCRAk1otyXVSH0IvCB/ 95sal3p7n1BoGOj5DL94/59IWLjclRI+C8m4TkdMzSBzs2ARYfbmAtiElcpw1gKP5q321j10CNUZK0 EJp0hVcVx8dSzSMXD3WINQWtAmSR+X/S2ugEWcus1OwDxr4SOjWVvm8uCU4YNJFtGNEIaw+ZfZ3/Q7 p6n9V+Nqw3OSHBL7V8YE0CnO+egiIdjiro9m5SmSkI18AjCnHQn3r7Ighh51eHvLE++n6bjcQ2IVbn 6cHItw4+TgOKqpmzhmhxlDNvqAYSkSUIIUBF4vOBTo0ALd2WRpXm9WcU1NEgkCH/CkI+MW9YWKgRr4 6pmu3BF2wAdkbESkzTd1RzN1fgBNFy X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250213_180127_609868_42A680FE X-CRM114-Status: GOOD ( 11.64 ) 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 Rather than add earlier prototypes of specific ctxt_has_ helpers let's just pull all their definitions to the top of sysreg-sr.h so they're all available to all the individual save/restore functions. Signed-off-by: Mark Brown --- arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 62 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h index 76ff095c6b6ebf336aab3018ec1f384a5f19949e..7a4ad8a4c3727e4628b375cbefc5e0d3533687de 100644 --- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h @@ -16,8 +16,6 @@ #include #include -static inline bool ctxt_has_s1poe(struct kvm_cpu_context *ctxt); - static inline struct kvm_vcpu *ctxt_to_vcpu(struct kvm_cpu_context *ctxt) { struct kvm_vcpu *vcpu = ctxt->__hyp_running_vcpu; @@ -28,36 +26,6 @@ static inline struct kvm_vcpu *ctxt_to_vcpu(struct kvm_cpu_context *ctxt) return vcpu; } -static inline bool ctxt_is_guest(struct kvm_cpu_context *ctxt) -{ - return host_data_ptr(host_ctxt) != ctxt; -} - -static inline u64 *ctxt_mdscr_el1(struct kvm_cpu_context *ctxt) -{ - struct kvm_vcpu *vcpu = ctxt_to_vcpu(ctxt); - - if (ctxt_is_guest(ctxt) && kvm_host_owns_debug_regs(vcpu)) - return &vcpu->arch.external_mdscr_el1; - - return &ctxt_sys_reg(ctxt, MDSCR_EL1); -} - -static inline void __sysreg_save_common_state(struct kvm_cpu_context *ctxt) -{ - *ctxt_mdscr_el1(ctxt) = read_sysreg(mdscr_el1); - - // POR_EL0 can affect uaccess, so must be saved/restored early. - if (ctxt_has_s1poe(ctxt)) - ctxt_sys_reg(ctxt, POR_EL0) = read_sysreg_s(SYS_POR_EL0); -} - -static inline void __sysreg_save_user_state(struct kvm_cpu_context *ctxt) -{ - ctxt_sys_reg(ctxt, TPIDR_EL0) = read_sysreg(tpidr_el0); - ctxt_sys_reg(ctxt, TPIDRRO_EL0) = read_sysreg(tpidrro_el0); -} - static inline bool ctxt_has_mte(struct kvm_cpu_context *ctxt) { struct kvm_vcpu *vcpu = ctxt_to_vcpu(ctxt); @@ -98,6 +66,36 @@ static inline bool ctxt_has_s1poe(struct kvm_cpu_context *ctxt) return kvm_has_s1poe(kern_hyp_va(vcpu->kvm)); } +static inline bool ctxt_is_guest(struct kvm_cpu_context *ctxt) +{ + return host_data_ptr(host_ctxt) != ctxt; +} + +static inline u64 *ctxt_mdscr_el1(struct kvm_cpu_context *ctxt) +{ + struct kvm_vcpu *vcpu = ctxt_to_vcpu(ctxt); + + if (ctxt_is_guest(ctxt) && kvm_host_owns_debug_regs(vcpu)) + return &vcpu->arch.external_mdscr_el1; + + return &ctxt_sys_reg(ctxt, MDSCR_EL1); +} + +static inline void __sysreg_save_common_state(struct kvm_cpu_context *ctxt) +{ + *ctxt_mdscr_el1(ctxt) = read_sysreg(mdscr_el1); + + // POR_EL0 can affect uaccess, so must be saved/restored early. + if (ctxt_has_s1poe(ctxt)) + ctxt_sys_reg(ctxt, POR_EL0) = read_sysreg_s(SYS_POR_EL0); +} + +static inline void __sysreg_save_user_state(struct kvm_cpu_context *ctxt) +{ + ctxt_sys_reg(ctxt, TPIDR_EL0) = read_sysreg(tpidr_el0); + ctxt_sys_reg(ctxt, TPIDRRO_EL0) = read_sysreg(tpidrro_el0); +} + static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt) { ctxt_sys_reg(ctxt, SCTLR_EL1) = read_sysreg_el1(SYS_SCTLR);