From patchwork Sat Feb 3 13:00:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 196303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp1013336dyc; Sat, 3 Feb 2024 05:19:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGftNx2AB+clO7zRpQxi8mVDoP8cf7nKRY6a0f4Js7Zl2zInvyHs1Hf7k7OvIAo8uCF1u+2 X-Received: by 2002:a6b:c301:0:b0:7bf:cfc2:1619 with SMTP id t1-20020a6bc301000000b007bfcfc21619mr8300061iof.6.1706966392627; Sat, 03 Feb 2024 05:19:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706966392; cv=pass; d=google.com; s=arc-20160816; b=eweaWtGbMNYIuDqGKY+8Rsl50AercvofC3ycCDAtJMxu5hkZyh7/h4J39TSOuXGGE9 tJx8wNOdbnuqqgaMvyezEX7suRvW2Cqw+EtKNMoMxiE/Rbky1MSiax0LwgLhjOpF/jN3 7N8RdqTWEMwwNIg0fceuwWftdf4B0UHNQBpRDjxpNdOOpz7LZFKHeyeoW65n+nkWLHTf aO7dm5sOxeE9LFYSC08dgkSoxhQUu2Hv2zaI0Q0jjehO/bmkZpGMFEBaUm3li8P+4DWO GJcSl9tRoENxPS8f+E0JAqxjj9yoc5q+LLG9zE9cDuFQkjm+CcHEuxCZTdscq83ERGmA vvnA== 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=HH7Cf7/K2wEfvzQqk4EqozsBGRNBfYYliYt3834lprY=; fh=glwWOPj80/gzRru6umfXGIpi93az1pqZAiEKPUAinaA=; b=OT01joSg52bcRJ8iOW6yTtJomfNSF8Vtsu7N4hXuZta1fXLizwZyvxCYbPfWBsNbSw 6mA082UqRwr0yHD+WoKKL2SIwEEsJAeB/SsH9yw3a9cqCyZG3WXW2yfYc4CxL1uoYC9I jMBedw+1W9UZ31IZT6DhHQmskMoIKYPK47MO/chTsrXGVNzn7tZmnu93CD1cdBjt9h++ HgZKSLnbWIFB2CMHijJKnqosKpE0Ku1F5w/3ZHGKVnH5/9O2saH/0cX7tjPbywNO8P1C 5qF1bbQ0xjI+ilkMZ+pt4n9gAWwqzqgYj1FkEAy7jRifwqy1fTBinato/Z08npsFUIjz 2CUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OAcGWw6b; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-51097-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51097-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUpH4eEUly3Xf7RiRj3GBbF5D4hH7LEnGUHWUv6VVDK0CIKpF1vxwk14o+ul0GwIUmFhvtw2JqKVDV21eYocOZ5uSdYvg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y33-20020a634961000000b005d8e2f56d7bsi3218344pgk.864.2024.02.03.05.19.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 05:19:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51097-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OAcGWw6b; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-51097-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51097-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 3D4AAB26E20 for ; Sat, 3 Feb 2024 13:02:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0ED275EE9E; Sat, 3 Feb 2024 13:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OAcGWw6b" 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 3D2405DF31 for ; Sat, 3 Feb 2024 13:01:26 +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=1706965287; cv=none; b=G/XoWUP9lgEE7uf3kDu4E8oaArW3M5utc3heZmLj0AVVx0myk9unuomzs11+WmqY4DGP+6xucJQdCRlwcjdEg9bxz4MEYYKYnregGyZSE6gx25mUh4I2VUl+Y+q5VC3JJMw/8OQ+Ji4U0WAc6dV77jkCXzzW2NqBxXE9pDVLd0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706965287; c=relaxed/simple; bh=WYAnHqfh3wc9ALgAbEUHjU8HQPMdcTokUkC4neL2YMY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TsDlC2jxkxjGUXRqg2PD33f60ORzT+TiuUp7QCgaA++FNrH9kB+VDMtyUrtGxXo/tUYrvPrYUoBRj0sZjLIwRFc5wDDIrb81WXhC1/sHX1yLF54kpVo6Zg+bTNim7Oq7S6FcVw36wAYdwRU43p0upS6H4moRF1+c47vt+wRhu7Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OAcGWw6b; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61C37C433F1; Sat, 3 Feb 2024 13:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706965286; bh=WYAnHqfh3wc9ALgAbEUHjU8HQPMdcTokUkC4neL2YMY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OAcGWw6b+tKUCj4Q377dOFpF7STHZVNvqfUkyXTA2ysBn2YSoUwb/AZrXbLrw5dlc nizLkVJ/AB1XG5lU0OkCOfWtlw6AzoeHR+khV6mtYcJ+wuGv2ssgxN9AUCxRi2uOAK ZXiLEvWZneAR2MYGywMhKDpfu5SrYL8NMer/HQGNWM5NSnhzuK9iZun9h9+A/D1SwT F+FyAgLYI9HPt8JvSIky1P2loBRB7bRikq26UDtKflHQ23OxS9QBMo//TYOOTMNh4Q so87FS1bPJz6LfqZXQVqBOAP/f9o9lkRJ23oTW7C06GnndYhrPdHl2lIs16PLh7SiJ Td7YiWkxEr2Zw== From: Mark Brown Date: Sat, 03 Feb 2024 13:00:40 +0000 Subject: [PATCH v2 1/2] arm64/sme: Restore SMCR 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: <20240203-arm64-sme-resume-v2-1-a1fbaddc4425@kernel.org> References: <20240203-arm64-sme-resume-v2-0-a1fbaddc4425@kernel.org> In-Reply-To: <20240203-arm64-sme-resume-v2-0-a1fbaddc4425@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=2862; i=broonie@kernel.org; h=from:subject:message-id; bh=WYAnHqfh3wc9ALgAbEUHjU8HQPMdcTokUkC4neL2YMY=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlvjkT4aXhtj2CXSu9FybDljHxn75/w4PZuyUtMHq8 5JNnjk+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZb45EwAKCRAk1otyXVSH0KvAB/ 4p6ZI3LJRELdmOTD9CJIEHYV2hSnM8GWKgCbf0qVwltqR5PUoAEAybmvK8z5CALDug3oOu96fr2ucZ 2WyGJJHflFpa6vswKo75XB5/UqQsqk6TVtnJMIlfy2zVgcuck7xVFNbu94vkXdIjO/oNZ3/65lEDQA pUIVXfzo5VACviPzWlj6VMiod0YQyaB1dlQYZltzpB3oOeY9rBuYlFajhb0dFDC/Ll0s0Wr83/kHXg phoPtN8/K2Q8SAgLD4AOXKsU+xWTQ64sc+HcVEQWfFdz0h836fPeG438rraqLStyUi8B+TgDi5nXEb m/T5LTZui/D2SJwL0F30oTzI0STmMt X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789883992148267062 X-GMAIL-MSGID: 1789883992148267062 The fields in SMCR_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(); }