From patchwork Mon Nov 13 18:09:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13454303 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 E982DC4332F for ; Mon, 13 Nov 2023 18:14:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id: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=PYkJi/CH1b0naF8H+aHnIPK8TJnZFmwySHkqH4/Y4hw=; b=kucHq7pELpCVf9 IVw9Uc0V+ywuBLWO4/u6OcHO0XXAIpZfflsbue6Jd+xoiEjAlo3od9LZKbaporKOyGXeTd/LlG1Cw 1gRfk14GgKPH7Ct9T4ueYLCFo3xbUPYYorjULqnCCSHU8OtgVujrvENsbtuA0R4RlSXSaOKJPMG07 qHfp79IxrY8JY71X2qRqccp2bZyErEVS9OaNTyLHMzf0t7fHhZZHugkv2XEz1Y8Dp1VyiA87fVflw YybmW/kk7og4vd1LUYRr8qRFKQnFKSV+rEXqToap+xMy8NOzFDSNlX8ZRjzk3vpI6TJxKSI7O6aZR cTVrPT7Bf5zQ/qzj9JVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2bRN-00EU5q-2M; Mon, 13 Nov 2023 18:13:41 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2bRK-00EU50-0A for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 18:13:39 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id BDF57CE17C4; Mon, 13 Nov 2023 18:13:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14064C433C8; Mon, 13 Nov 2023 18:13:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699899214; bh=zZ0ABhBNzUrMEKoajMk2OiQ2peqB51tlUR1tmzcZ7QE=; h=From:Date:Subject:To:Cc:From; b=Ufk8Ipnjch8hRwP6kbw4DrHyq2lNTBAttobjsEfozAApeXtbIhKWESGA1N7GxluFU bRyOsDwvEESSDsNuukk7lbmMVOO1uWNnwqE67u8ZsAtezZNhFpyLZpCo6A4myaDrWS d0xBeVYbC6q66VGw4Lk46kZav7VJUMdsxz7rnLDbj+9vx23VEDL0FJCOAYgPoNB1QI rhDG7/OOF3JZpKZYNWOTx2hX7NyVjsB97EMWmveu8M4vyVFnJPA6Etsom8QFK9RJog mjTKPPP0L0XbsbdnqyWMJ/m4ySgOIsojmDxIutBb4VsNRz+lNXbgqSFFVUc7OB4WX4 0N5nCdXlwgxMA== From: Mark Brown Date: Mon, 13 Nov 2023 18:09:18 +0000 Subject: [PATCH v2] KVM: arm64: Only default to enabling SVE when present MIME-Version: 1.0 Message-Id: <20231113-kvm-arm64-fp-init-v2-1-98867e5fd97f@kernel.org> X-B4-Tracking: v=1; b=H4sIAE5mUmUC/22NQQ6CMBBFr0Jm7RgKxRRX3sOwqGWACVLIlDQaw t2txKXL95L//gaBhCnANdtAKHLg2ScoThm4wfqekNvEUORFmde5wTFOaGW6aOwWZM8rmloba9q qIq0h7Rahjl9H894kHjiss7yPi6i+9ldT5Z9aVKjQOKofVjmnnb6NJJ6e51l6aPZ9/wB8q9PIs wAAAA== To: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=2474; i=broonie@kernel.org; h=from:subject:message-id; bh=zZ0ABhBNzUrMEKoajMk2OiQ2peqB51tlUR1tmzcZ7QE=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlUmdKzgYWsfK8IY0vjDLIDyiKtEJ/MwZ6WMxi7mip PI6CWymJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZVJnSgAKCRAk1otyXVSH0I2zB/ 9/GohuiyHT41TGPna2JwnANYxSkfsGRbWEfszNUz92/SIPL07c93Ca2nyhCwjqj6pdZsUzGJ68VovD gAMIr+RkYLVGkx4li6CfsXGFkZsIc+6uhqTyDy2f3jLoo7cWt5xAa+nuCeiwd2axTdKEAIdMfzL1Gh mN4KU+VzCgV6mzKoIwj2E4BPrg1nLE+zNHa8STplZjHilVi/rx+DWBOg7pwgQD1N5wjtpNCt5ZrjuP UeuTS+bv5we7VKG8NPgYO+5I2lMgOfbXg0h+MSfbYKRXbsVvQ45hwcJnVn/Lf3s3KEIYp4MPAPyz+S cT+h8WCaXBOhuy6fdzf7iyPY1eZ1+T 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-20231113_101338_425201_888AE9FD X-CRM114-Status: GOOD ( 15.09 ) 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 For unclear reasons our handling of SVE and SME when setting the default value of CPTR_EL2 for VHE mode is inconsistent. For normal VHE we unconditionally set CPTR_EL2.ZEN to 0b01 but only set the equivalent field CPTR_EL2.SMEN to 0b01 if SME is present, for hVHE we will always set the field 0b11 if SVE is not supported. Given the similarities between the two extensions it would generally be expected that the code handling SVE and SME would be very similar. Since CPTR_ELx.ZEN is RES0 when SVE is not implemented it is probably not harmful to try to set the bits but it is better practice to not set unimplemented bits so resolve the inconsistency in favour of checking if SVE is present too. FPSIMD is also in theory optional though there's probably much more work to handle the case where it is not implemented properly and that is not something we see in practical systems. Signed-off-by: Mark Brown --- Changes in v2: - Rebase onto v6.7-rc1. - Link to v1: https://lore.kernel.org/r/20230913-kvm-arm64-fp-init-v1-1-8ce9ba1cc4c4@kernel.org --- arch/arm64/include/asm/kvm_emulate.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86 change-id: 20230908-kvm-arm64-fp-init-8948a8d55e44 Best regards, diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index 78a550537b67..b6f1ddff796c 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -583,15 +583,17 @@ static __always_inline u64 kvm_get_reset_cptr_el2(struct kvm_vcpu *vcpu) u64 val; if (has_vhe()) { - val = (CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN | - CPACR_EL1_ZEN_EL1EN); + val = (CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN); + if (cpus_have_final_cap(ARM64_SVE)) + val |= CPACR_EL1_ZEN_EL1EN; if (cpus_have_final_cap(ARM64_SME)) val |= CPACR_EL1_SMEN_EL1EN; } else if (has_hvhe()) { val = (CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN); - if (!vcpu_has_sve(vcpu) || - (vcpu->arch.fp_state != FP_STATE_GUEST_OWNED)) + if (cpus_have_final_cap(ARM64_SVE) && + (!vcpu_has_sve(vcpu) || + (vcpu->arch.fp_state != FP_STATE_GUEST_OWNED))) val |= CPACR_EL1_ZEN_EL1EN | CPACR_EL1_ZEN_EL0EN; if (cpus_have_final_cap(ARM64_SME)) val |= CPACR_EL1_SMEN_EL1EN | CPACR_EL1_SMEN_EL0EN;