From mboxrd@z Thu Jan 1 00:00:00 1970 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 2A593C43458 for ; Thu, 9 Jul 2026 18:41:10 +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=Hf3ZnwbaPwB7JWA6xLw/d7mljky+WZ0YaL8vLXxrCY0=; b=BPJlXWWvdcAjhF8iqLE+TF0IHP oqbOGxEVk9NE1vZq01IvqO7HeEhVDfe41aVbNBWZ1wjIIm7ZeAmnwP0dPJcI9VBI4luKNnUP8Ip+X oNNikiWsHIxljcQrr4AbR4e2jUWWMnLhrcYhfyecNmSGkN9wXMkqngscxbf26+xtVd1YVAin+pLv5 0Pzcjcf8vNVtxWiUtNxaiz3IEYctGerVhkYHxtk3FTSs10CRJZUKuhg0BlGWuhpZKKtv4HdCtw8+d k39l0EXQffSYABg9yjoTkZObsn/uGj8pZCDcPxLQzpYG7uprCukKhvchw6k/ljJD9gabFHEQ/M5BI I+CbXT4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1whtgF-00000003FhC-3t3D; Thu, 09 Jul 2026 18:41:03 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1whtgD-00000003Fdn-3Meu for linux-arm-kernel@lists.infradead.org; Thu, 09 Jul 2026 18:41:01 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 0887161386; Thu, 9 Jul 2026 18:41:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97CE41F00A3A; Thu, 9 Jul 2026 18:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783622460; bh=Hf3ZnwbaPwB7JWA6xLw/d7mljky+WZ0YaL8vLXxrCY0=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=L5rhxUX+nsrBajnjExeDBc2fTwO6wA7PYtjLR+rxXbgC4FNRZhXsenOevMrN6N0Yv PYxr4wbp4HghyqX0LCkSJ09OQrLiMVftug4jAbTG56/bV8bxbK0DR76J1ceoJfH9RD bAbNcUV98/JUN+dnEyQ1Rbyzl6T08DJqovnbjFNl8UhAvHyDCsa+eR5lcGsjv9Hbp/ ZklTydpEmNZqDF82uFA6YIHi9RHXt4jpvVHtT3e4aotJ2i3KbEoRAlD6TPx8PHp0Z+ gx/JWOyzryMiLqNieX+vARgfYp2bTHhSdnbgdRLJLxXsvr8RlsPAPPxscsTfQG8o5e XP4GopOyQu7cQ== From: Mark Brown Date: Thu, 09 Jul 2026 19:27:33 +0100 Subject: [PATCH v12 12/29] KVM: arm64: Factor SVE code out of fpsimd_lazy_switch_to_host() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260709-kvm-arm64-sme-v12-12-d0301d79ef58@kernel.org> References: <20260709-kvm-arm64-sme-v12-0-d0301d79ef58@kernel.org> In-Reply-To: <20260709-kvm-arm64-sme-v12-0-d0301d79ef58@kernel.org> To: Marc Zyngier , Joey Gouly , Catalin Marinas , Suzuki K Poulose , Will Deacon , Paolo Bonzini , Jonathan Corbet , Shuah Khan , Oliver Upton Cc: Dave Martin , Fuad Tabba , Mark Rutland , Ben Horgan , Jean-Philippe Brucker , 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, Peter Maydell , Eric Auger , Mark Brown X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2931; i=broonie@kernel.org; h=from:subject:message-id; bh=zkAz4EpB+oD/CW01W7HnqzjEzUv3OlXONmLnbiTh4s0=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBqT+rzBz3N89BPQyzmP/17vU4/T3AWJcfrSuhZ/ JFYXNl0QY+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCak/q8wAKCRAk1otyXVSH 0LLAB/9PDxD2EnCQVkTX9BSFw4Z/rLLypJJ1H37bC7t2tQINmcPe1g+gvX2b31saVOqihuJIuZE d8HnWZ3cwTNGUASY96kURWvxgxQOo1tjSGxBBm+W8VlbbJFScB5K/bUu04HBWcqS9NMsvLz1Nol YfKgsEqeLAHRQt2ZUMNgd2t8kKlrWH01TU5VJlj4l/BFA02+MIsXJZZlUIA8m/j3YQ9PmyTOj67 tsd8/0Tc4yWpeFvO8y+zjExEr+Qc65X1crRItdsT37BxRGSuJtgHtttOyLZc3W+8yRMhYDgHK62 FjAug+GTVapgPtkQzZXNF9rmv3KYdxptrqw4v9Vc2pj2LrIo X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB 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 Since the function will grow as a result of adding SME support move the SVE code out of fpsimd_lazy_switch_to_host(). No functional change, just code motion. Reviewed-by: Jean-Philippe Brucker Signed-off-by: Mark Brown --- arch/arm64/kvm/hyp/include/hyp/switch.h | 48 ++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index 33729e218c0a..e444f0a94dcf 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -519,11 +519,11 @@ static inline void fpsimd_lazy_switch_to_guest(struct kvm_vcpu *vcpu) } } -static inline void fpsimd_lazy_switch_to_host(struct kvm_vcpu *vcpu) +static inline void sve_lazy_switch_to_host(struct kvm_vcpu *vcpu) { u64 zcr_el1, zcr_el2; - if (!guest_owns_fp_regs()) + if (!vcpu_has_sve(vcpu)) return; /* @@ -534,29 +534,35 @@ static inline void fpsimd_lazy_switch_to_host(struct kvm_vcpu *vcpu) * synchronization event, we don't need an ISB here to avoid taking * traps for anything that was exposed to the guest. */ - if (vcpu_has_sve(vcpu)) { - zcr_el1 = read_sysreg_el1(SYS_ZCR); - __vcpu_assign_sys_reg(vcpu, vcpu_sve_zcr_elx(vcpu), zcr_el1); + zcr_el1 = read_sysreg_el1(SYS_ZCR); + __vcpu_assign_sys_reg(vcpu, vcpu_sve_zcr_elx(vcpu), zcr_el1); - /* - * The guest's state is always saved using the guest's max VL. - * Ensure that the host has the guest's max VL active such that - * the host can save the guest's state lazily, but don't - * artificially restrict the host to the guest's max VL. - */ - if (has_vhe()) { - zcr_el2 = vcpu_sve_max_vq(vcpu) - 1; - write_sysreg_el2(zcr_el2, SYS_ZCR); - } else { - zcr_el2 = sve_vq_from_vl(kvm_host_max_vl[ARM64_VEC_SVE]) - 1; - write_sysreg_el2(zcr_el2, SYS_ZCR); - - zcr_el1 = vcpu_sve_max_vq(vcpu) - 1; - write_sysreg_el1(zcr_el1, SYS_ZCR); - } + /* + * The guest's state is always saved using the guest's max VL. + * Ensure that the host has the guest's max VL active such + * that the host can save the guest's state lazily, but don't + * artificially restrict the host to the guest's max VL. + */ + if (has_vhe()) { + zcr_el2 = vcpu_sve_max_vq(vcpu) - 1; + write_sysreg_el2(zcr_el2, SYS_ZCR); + } else { + zcr_el2 = sve_vq_from_vl(kvm_host_max_vl[ARM64_VEC_SVE]) - 1; + write_sysreg_el2(zcr_el2, SYS_ZCR); + + zcr_el1 = vcpu_sve_max_vq(vcpu) - 1; + write_sysreg_el1(zcr_el1, SYS_ZCR); } } +static inline void fpsimd_lazy_switch_to_host(struct kvm_vcpu *vcpu) +{ + if (!guest_owns_fp_regs()) + return; + + sve_lazy_switch_to_host(vcpu); +} + static void kvm_hyp_save_fpsimd_host(struct kvm_vcpu *vcpu) { struct kvm_cpu_context *hctxt = host_data_ptr(host_ctxt); -- 2.47.3