From patchwork Tue Sep 10 20:21:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13799295 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 EA7DEEDE9B4 for ; Tue, 10 Sep 2024 20:27:29 +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: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:In-Reply-To:References:List-Owner; bh=9zwGcL6deKEVZiVhidJ4mdLp9R/KzaZZmoUSfO6/GQM=; b=zs+rk+AEYKLc8CjncpsUDp6oWO lrruVKGtS+3P9yN4dvWkUu8L29zPvw14d0uzkwLuzkvmpPgNq/+x+HfwxtMtxc8j33phh1eoosu5u 97+t2+ftbQZmrooEbnh7BGWu67+r/PvkBRNk+iqWk/cWljAnI63ZXZlXjrH69muGbmVf7vg+d5ifn 9+ZMLVMBm5vWDkZWBKaPONKkvvGsT2XJHqNtD+dZY/ktZtv3MByAIjAHfX0YUQCKEclMxs4PmmG5m do41FTmKSap1WWnMkladOOCN+22iA2+Qn79A5HHf9rJcpEcngWBXPwJLiQYu/SjmrTpGs4R+/MJTl iy4543kg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1so7SI-000000071Nr-04nK; Tue, 10 Sep 2024 20:27:18 +0000 Received: from nyc.source.kernel.org ([147.75.193.91]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1so7RF-000000071Ir-0vw6 for linux-arm-kernel@lists.infradead.org; Tue, 10 Sep 2024 20:26:14 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id AF4D8A41704; Tue, 10 Sep 2024 20:26:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A9B3C4CEC3; Tue, 10 Sep 2024 20:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725999971; bh=/vRC6UW5TKpXSnzoNSBj6lJfT63gnYyuAM0O5g3j+7U=; h=From:Date:Subject:To:Cc:From; b=IVpLwP3PN5TyPmbrRqw1W0DMCfJhFrKyDJadAo4MTiFrd+NEaiaeyOu9wmWUkEbQs NvtNVo4V9yXvAfmT1Eq8kpdfG2Z+F4+TFFZpDpMDnGSCsob0RJc6Zsc6kkGcciIlll LlZ7pxUTP6R/4PX3mrSNDpviRRPv/9p5VcaMy7CtYu934yFVt2izSkqzAKsVWg9WLn 4P02gs7VIZN63MeZl3FcdE3psz+nnWPEHKfyx/59Q/19n/4HlURh/Cw7di6CwDeYHd qqr4RcOc1ZCgiDoir1vlwK/PbvGDE+GLtPtznQVmJ4rXcktL0Yd6j8dcUSXv8aT9b+ lM5aZgWGbdv4Q== From: Mark Brown Date: Tue, 10 Sep 2024 21:21:17 +0100 Subject: [PATCH] KVM: arm64: Constrain the host to the maximum shared SVE VL with pKVM MIME-Version: 1.0 Message-Id: <20240910-kvm-arm64-limit-guest-vl-v1-1-54df40b95ffb@kernel.org> X-B4-Tracking: v=1; b=H4sIADyq4GYC/x3MQQ5AMBBA0avIrE1SgoariEXVqAlF2mok4u4ay 7f4/wFPjslDlz3gKLLnY08o8gz0onZDyFMylKKsRFsIXKNF5WxT4caWA5qLfMC44VTPoxJaai1 HSPnpaOb7X/fD+370TlaQagAAAA== To: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Catalin Marinas , Will Deacon , Fuad Tabba Cc: Dave Martin , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-99b12 X-Developer-Signature: v=1; a=openpgp-sha256; l=2951; i=broonie@kernel.org; h=from:subject:message-id; bh=/vRC6UW5TKpXSnzoNSBj6lJfT63gnYyuAM0O5g3j+7U=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBm4KtgcGbqP1jiMA0U/QcL+yIVnZS3mIQtN3BHVkLk 4xEBMuaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZuCrYAAKCRAk1otyXVSH0NRNB/ 9XT/BOpsS6KyJqP7dJyHRnbt2jwFRAsoob01rk9CYemGuCAfn1bn6pN+6N0RA9ES9oYMzOPiZEIVp4 BOtvReHeQdsP6UgU2oNuJJJtH1GhZwySs/fZuqtUc8f1a8wTQwNxFp0s1Vmei0l9AC9NGQIDSKm2SQ ATsU+dJMFccAbu2Oj38S669xLUhrEg3C8UbXRPu1PoonmI3bVeI1CVx5QKD4XyiQ2BHAsEvC76jPCt p63n7FvwLJx2OudS9fLMc5waRvjv059MECo7nAIWU2MKSVIdQVAZYaFBATL4iHylY7TuIOPLgh5emD reohv4tECOV66tjrhaOjFAxuvYnFwu 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-20240910_132613_430562_E7E66421 X-CRM114-Status: GOOD ( 17.21 ) 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 When pKVM saves and restores the host floating point state on a SVE system it programs the vector length in ZCR_EL2.LEN to be whatever the maximum VL for the PE is but uses a buffer allocated with kvm_host_sve_max_vl, the maximum VL shared by all PEs in the system. This means that if we run on a system where the maximum VLs are not consistent we will overflow the buffer on PEs which support larger VLs. Since the host will not currently attempt to make use of non-shared VLs fix this by explicitly setting the EL2 VL to be the maximum shared VL when we save and restore. This will enforce the limit on host VL usage. Should we wish to support asymmetric VLs this code will need to be updated along with the required changes for the host, patches have previously been posted: https://lore.kernel.org/r/20240730-kvm-arm64-fix-pkvm-sve-vl-v6-0-cae8a2e0bd66@kernel.org Fixes: b5b9955617bc ("KVM: arm64: Eagerly restore host fpsimd/sve state in pKVM") Signed-off-by: Mark Brown --- arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) --- base-commit: 7c626ce4bae1ac14f60076d00eafe71af30450ba change-id: 20240910-kvm-arm64-limit-guest-vl-d5fba0c7cc7b Best regards, diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index f59ccfe11ab9..ab1425baf0e9 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -339,7 +339,7 @@ static inline void __hyp_sve_save_host(void) struct cpu_sve_state *sve_state = *host_data_ptr(sve_state); sve_state->zcr_el1 = read_sysreg_el1(SYS_ZCR); - write_sysreg_s(ZCR_ELx_LEN_MASK, SYS_ZCR_EL2); + write_sysreg_s(sve_vq_from_vl(kvm_host_sve_max_vl), SYS_ZCR_EL2); __sve_save_state(sve_state->sve_regs + sve_ffr_offset(kvm_host_sve_max_vl), &sve_state->fpsr, true); diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index f43d845f3c4e..90ff79950912 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -45,10 +45,11 @@ static void __hyp_sve_restore_host(void) * the host. The layout of the data when saving the sve state depends * on the VL, so use a consistent (i.e., the maximum) host VL. * - * Setting ZCR_EL2 to ZCR_ELx_LEN_MASK sets the effective length - * supported by the system (or limited at EL3). + * Note that this constrains the PE to the maximum shared VL + * that was discovered, if we wish to use larger VLs this will + * need to be revisited. */ - write_sysreg_s(ZCR_ELx_LEN_MASK, SYS_ZCR_EL2); + write_sysreg_s(sve_vq_from_vl(kvm_host_sve_max_vl), SYS_ZCR_EL2); __sve_restore_state(sve_state->sve_regs + sve_ffr_offset(kvm_host_sve_max_vl), &sve_state->fpsr, true);