Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1399804rdb; Sat, 3 Feb 2024 05:03:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCx5wxrJY2QtynMrZ6vH7ltE97R+MTGAXWA0ihSCXSOOpJSRBMhY3qdbB8XRNBwG9yzV7t X-Received: by 2002:a05:6a00:2:b0:6dd:b12f:c394 with SMTP id h2-20020a056a00000200b006ddb12fc394mr7323791pfk.32.1706965414218; Sat, 03 Feb 2024 05:03:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706965414; cv=pass; d=google.com; s=arc-20160816; b=k+hdO+9C/am+skFQqIDDsBAQ4Q4AJk00hdtL7txzvBGYfFAevMRnDJMcGDQMCgE3IO Lb1EHPP4rz5HUGqnEcH6+ZAmNowtIXqJ7xofMEEbiQ/W0persMafKPTzQITPP6h745tn KzwlE8FE0Asm36dmet5NKeT5/tqfJZj6sFRDTDRLo290JnURm5EIa4Skc73mForiCNAQ FssbGpgx+pAbg4x1ba0wp+jDBwEeWsiSY5wnEA1bgqZ+oqe13OA8d0nVzqtdUgLcwlC1 g5kIhwN6cw8O6DUyk9uS/5HbO6MAuVR2BHtygpcFgOgdHtYLpBcUPRhKWPHbiBIUvHc/ wxEQ== 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=7sqoJW0DnFubExe+P/BOLIKjJUf4pi5Oo/K+KO0jYXM=; b=V/RMIaouXrXgPksEE2qJzgDKGUv7CqfcxpDpUj+YthgP0uIc7coj2ctZ47E6k9wRf6 EEgP0UK2yHVrM8SX5y4oggR3TbETD171DCOKlvxiSwVZM2G5L8DmT3jZ8sThtxlbqEDB QBZNXqIPB9IWZSJvfGjr5p+g478ctW7Eq0+QEjVhJHd1lapj9g6HBjtEDvW+LvoHqq1k Qzhc49iO6DBypcWdZMUO/bJwuQ4E7Hz9fsXIRXqvGB4eebwF0dDQ9qQ7XNQJBY3/Mg7W 20ImZnscQgahx0Vfkw+IDxKxWxir52d+Q2p+AElAhfzVODzCkf3bL5hoFkztEam+92tv Qnyg==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51097-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCVViPVR3DC08cYk7ildKlygW9Nt31nlNhWNpfHVkBKXwW+UccDBiQokwEqVYqmI1AmMLk8f4Gd8FaQXay9MhBudMLypD2LfGYiS3Rc7SA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e18-20020a635012000000b005d8bdc6258fsi3071045pgb.679.2024.02.03.05.03.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 05:03:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51097-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51097-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id F31A0289493 for ; Sat, 3 Feb 2024 13:01:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22BC65EE6A; Sat, 3 Feb 2024 13:01:28 +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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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(); } -- 2.30.2