From patchwork Tue Feb 13 23:06:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 200734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp872299dyb; Tue, 13 Feb 2024 15:37:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX/WeKID+X9Cta/w+WJVpb7KZc4B32bAlhy9XEETHjQ4I/7jTJJM+rXfPpQD//B7pqf1u/2xqTAD6m35m1QosZMU2J6kA== X-Google-Smtp-Source: AGHT+IEVOP6LTTLPeHn0BHr6PWvJV4lbAZ/nRD333AQTU8fYe5FVKDoJZK3ZEDOd+uMoLxYTiCM/ X-Received: by 2002:a05:6a20:9f96:b0:19e:9b9c:fc2f with SMTP id mm22-20020a056a209f9600b0019e9b9cfc2fmr1276915pzb.32.1707867461695; Tue, 13 Feb 2024 15:37:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707867461; cv=pass; d=google.com; s=arc-20160816; b=K/HzOqhBvMWyMoKZk3jY7MFGXrDiJHdvtBZ70S5ZNygSyglPTGSqDgYWkeRT84u1Kp kU5Bq6ccLJRfVLN86tLlCQRRaGh5MN8dbES09Cqjx0HvbIO3j98KjHY67B85SL6gp/bA 4MzfOYXTHBV4kx0KYcj1kW+Olb2qx2pQYeST2/59b/XFGNvvpk0KpYXSQmZi9QnYnCvN cObXNhVYr6HmkazSesw+HwXe8uBSdkngU+RoNXdhS3CauEEK94ayJmaZjIvdTc41AN9d Wxa3XiEmArBBhdykn2vhDlZyLxv3MATSgoL/fNqFwDqeIMHE4e40DLR+P5jDcJ0H199P pN3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=Ps7gokUNravTCwo3C2yzrBkuoam6D8prxT/BS+xPP5Y=; fh=S6+X5aVE9nNwZSpOIf05bcJnNq7eYpwh+ociA8BG4H0=; b=DiKw86oqWgal9yH/XIuVNCjtUdLjLsgvXCzlHGOviaTbBNoHbUfBUq7mt1D0a0+sq1 ExtxwdKkQmg/pDl08E65xOZ1Cw8paaQqvkVZJaoFHn9bLqEkJJnySLvGhH0U+FRxVcYJ NUsrdhr73ebpkE4RAi/i/WAvt5UjXZ2Aozt6qk8rk9p2TXJFioDEaAZncyEKqy6bih6O jvi67YShmjniRuVmQwqFtKfmPGj73aqxcVaatoiPc+chwhcDYhn5DHsRqMwb/3qSoVcB YatTkWgNtsXInK9HjGDDCVGvmwmK9pIqvsC4JcwyjTNTx1M3+TXeRVKdxvJRyA2I20kn Gzcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ID2Wjs2t; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64506-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCU97JSj4f4+m5IZ5rib8HfUwGkgz5/+SmOLsMo9McnCeP1vTSIaCsw5U+8LDXd2owYjhnxxnlhA+/xGqFEudBzjGNwhPQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ee15-20020a17090afc4f00b0029705da75absi124420pjb.125.2024.02.13.15.37.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 15:37:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ID2Wjs2t; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64506-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0C888B22E73 for ; Tue, 13 Feb 2024 23:08:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C3AA63404; Tue, 13 Feb 2024 23:07:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ID2Wjs2t" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7373B63099 for ; Tue, 13 Feb 2024 23:07:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707865636; cv=none; b=g0yapNqrIj6KKjPWmmF8Hj71D0G2uoOsTLm7dRqkw2ubi0T68+9hUGsCRnSFOyaVQ/tAdq29i53Gkkp/6BQxCRBOFG78f0eO5ffGcMixvYcbozO8bfGdHQJWMPcgquX1AObMkwRhqabclh5/fLGM2o3J1ljJzZAnYfrNNOjjFG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707865636; c=relaxed/simple; bh=n9u10ZS5tf3bLwSljOa4a7bDya4v/AV3Y3EVY8udHHE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pIXMDarrOgaM4HSXhGjX0hv2BAjCVI34gncgPwr0Df0ul9NeAkC66nQRRoEJF0dTq4efHkox4ULXwc5/uSnnMRBm4sfrO06it/UeL6OrIQIIicagEUtm+NxVfoRHEN4cDcdmAoA9axCHIICi7JdkpIJNQ3ggFpBH4+VRmuMfuMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ID2Wjs2t; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F077C43394; Tue, 13 Feb 2024 23:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707865636; bh=n9u10ZS5tf3bLwSljOa4a7bDya4v/AV3Y3EVY8udHHE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ID2Wjs2tRPxkGyK0RXHRa2GKVKZNd3QngdWE6h/uBwXLUCp7Oop3zt/6AU5zeen/3 ZnmJ1RijSO+Q4YgB7YzDLvy3/HUZC5XW7/EPzrWHnmKtQZVlEAT3O/0NMvhBnR29CU ETxfyssW2eXN0y3eBymg+7npKEgMTwvL7LhKHwOs3C0G9j+kk6weVBufhoUxQH5VWN hPUSIxFswmcQF/bIPHWMDfB/Yl5UIwkK81YeWOetfmpyjKcMfIFGrGh2uMA3AWRhCz Gy4JEaR/wBjZJQswRvSb7YmualUZcg6LXW0PkQYddb03zDpfdy6XRSgR0ZGpuPUJ/n eqfXMUwG5UOjw== From: Mark Brown Date: Tue, 13 Feb 2024 23:06:32 +0000 Subject: [PATCH v3 1/2] arm64/sme: Restore SME registers on exit from suspend Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240213-arm64-sme-resume-v3-1-17e05e493471@kernel.org> References: <20240213-arm64-sme-resume-v3-0-17e05e493471@kernel.org> In-Reply-To: <20240213-arm64-sme-resume-v3-0-17e05e493471@kernel.org> To: Catalin Marinas , Will Deacon Cc: Dave Martin , Jackson Cooper-Driver , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-a684c X-Developer-Signature: v=1; a=openpgp-sha256; l=2876; i=broonie@kernel.org; h=from:subject:message-id; bh=n9u10ZS5tf3bLwSljOa4a7bDya4v/AV3Y3EVY8udHHE=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBly/YeT8Zv2qklmd6Z20IViy+bBIDojKavlqTywPM7 QnEOhbqJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZcv2HgAKCRAk1otyXVSH0Eq1B/ wKayaPsmBI/+hGRSWdTXUxHsD37OXQcSNtsqAu77CQIX0HoROXuvQckQ51Ot80fWvOSZ7fo2kUYvO1 mVkodiqvR9a4v4gHsmad1dIzf61oB3X9tImInXXMvVqvPUtJWzr474R4HWroKD31tzP/kGI6D7OZR5 gC6z9hNLTsnRtS/gpy8z2KWo/nVirBNp2VOgZ0zlxvJlgiijnTE9mB0fgBv1DVoWsSejlxBQyVDPLi 7zYCVN9UVw9J1PuI0kjPk5qrs4cf1X3LwqoWU0ws4I9qjb+NRPrjikhMmQ9myItS/2kC1E+oeTj/h4 mG5SJT+HoDgYMzOzF5BxhoYcm3kgf5 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790828831878014931 X-GMAIL-MSGID: 1790828831878014931 The fields in SMCR_EL1 and SMPRI_EL1 reset to an architecturally UNKNOWN value. Since we do not otherwise manage the traps configured in this register at runtime we need to reconfigure them after a suspend in case nothing else was kind enough to preserve them for us. The vector length will be restored as part of restoring the SME state for the next SME using task. Fixes: a1f4ccd25cc2 (arm64/sme: Provide Kconfig for SME) Reported-by: Jackson Cooper-Driver Signed-off-by: Mark Brown --- arch/arm64/include/asm/fpsimd.h | 2 ++ arch/arm64/kernel/fpsimd.c | 14 ++++++++++++++ arch/arm64/kernel/suspend.c | 3 +++ 3 files changed, 19 insertions(+) diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h index 50e5f25d3024..7780d343ef08 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -386,6 +386,7 @@ extern void sme_alloc(struct task_struct *task, bool flush); extern unsigned int sme_get_vl(void); extern int sme_set_current_vl(unsigned long arg); extern int sme_get_current_vl(void); +extern void sme_suspend_exit(void); /* * Return how many bytes of memory are required to store the full SME @@ -421,6 +422,7 @@ static inline int sme_max_vl(void) { return 0; } static inline int sme_max_virtualisable_vl(void) { return 0; } static inline int sme_set_current_vl(unsigned long arg) { return -EINVAL; } static inline int sme_get_current_vl(void) { return -EINVAL; } +static inline void sme_suspend_exit(void) { } static inline size_t sme_state_size(struct task_struct const *task) { diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index a5dc6f764195..8d2a5824d5d3 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1311,6 +1311,20 @@ void __init sme_setup(void) get_sme_default_vl()); } +void sme_suspend_exit(void) +{ + u64 smcr = 0; + + if (!system_supports_sme()) + return; + + if (system_supports_fa64()) + smcr |= SMCR_ELx_FA64; + + write_sysreg_s(smcr, SYS_SMCR_EL1); + write_sysreg_s(0, SYS_SMPRI_EL1); +} + #endif /* CONFIG_ARM64_SME */ static void sve_init_regs(void) diff --git a/arch/arm64/kernel/suspend.c b/arch/arm64/kernel/suspend.c index eca4d0435211..eaaff94329cd 100644 --- a/arch/arm64/kernel/suspend.c +++ b/arch/arm64/kernel/suspend.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +81,8 @@ void notrace __cpu_suspend_exit(void) */ spectre_v4_enable_mitigation(NULL); + sme_suspend_exit(); + /* Restore additional feature-specific configuration */ ptrauth_suspend_exit(); }