From mboxrd@z Thu Jan 1 00:00:00 1970 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 022EAC00140 for ; Mon, 15 Aug 2022 13:39:32 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LwDSHFxKljeb+j90r6snjOXOD9zkZK9BSmDptfjkxo8=; b=ewa+tmbBujOhWd ecfbM20bnhcWGe7e9bXVlm/TE1eA9HkIBy1lGO3qDYKCbAnMNaIHjeIbgE/fSjj8YT6sgI7JSbp0X sxs/GAOL4Yu5lhM3UiHt+Qy2zo9Z5uwlTA4E+UPskv0M4QsKUFUY0VbW77APtCGmEZNdhmkz4Stqf k/YLnSp6gNwpWFwxqu9OGHJSdc7qS5d9G83CIwoVN/cSR+JeCd/f5YAGU2uUg/WKHuIGLQDxr78ww MJBg+eIreVsLwU9c0iAUArmHTZACgwy+H0Z+RowA88qoXmzRWEXu6tUbM2TAScAXNxxMvFnTQx/1w 0kQH91qyqTyTQKlWquUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNaIH-00GvFn-Hs; Mon, 15 Aug 2022 13:38:14 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNa9k-00Goas-3w for linux-arm-kernel@lists.infradead.org; Mon, 15 Aug 2022 13:29:26 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B4271B80EB9; Mon, 15 Aug 2022 13:29:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70874C43470; Mon, 15 Aug 2022 13:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660570161; bh=dUdn2bjC6QO1bFxnyWQVFe2rBdElIIX9Bkv2PvfMXx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N51n37yGuSkEDX6sTEsna04Il7Jqy7zp6BpD8jEaJU/GcQwYBZrHJ4kuKOCg6SmS1 15p9wCxL/uCWdLROIlLONGe1SzNuXh5ZDujiGokNxZ6tfh9y4ZplGWSInCo4dp3SIF vgCDNPXdG+2GVe4+v6dnthgBSAnYqHqtvamoKfDAsbAtBgC8mJXeRJX2/KurLbkme4 glvX8UeuRPzJBctiL4BvRkNe1/EUZWBGYZZhLoatgVZ/GhX63qzfTliIKPzSX4CHnY f682Xn37z02eZiI5QGJ5CDO1SwvYIvkkO83owk06NOQ3uNgR3PSXaB/Lm7ALwoUOFs 1TDJqAWUZJZLg== From: Mark Brown To: Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v2 3/4] arm64/sme: Don't flush SVE register state when allocating SME storage Date: Mon, 15 Aug 2022 14:28:33 +0100 Message-Id: <20220815132834.229769-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815132834.229769-1-broonie@kernel.org> References: <20220815132834.229769-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4871; i=broonie@kernel.org; h=from:subject; bh=dUdn2bjC6QO1bFxnyWQVFe2rBdElIIX9Bkv2PvfMXx8=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBi+koB3Catj54c/PpOCszn1nDWGvAO8swMthujdD/Y g+5NjtGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYvpKAQAKCRAk1otyXVSH0NqmB/ wLzHFHGkLBlXxOHcO859tfN2jHa3FDvaPL8573Ya5zpPIcqYb3iDbaM1FJ2dcOFb06O8fBRjPo9NGb jfFWX4zG06reLVzQbPWFWqzAnkTqf9ae/cTIlDF5qgDHJt1vFKHjEbHwYDRbZgzRV3f1tECUAf4ncB H0WfL9VFrYD1LtqoxznK6fFRUO+ai8/k6hqSh5VH8+QxJ7xmT0fF0sGkFRZdca+DJcS5Av3URQl/pt AfJbG5Mquw8kEgDsoCrYTl5Uzy+/NgdUGdE6jLGkMvITHK2Oj0p1K4eIAh4A6aEHUX8BuVji4n80Ag KgpE8Ie+YCmqbX2WpmfHBpMg1rIpn0 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-20220815_062924_534901_7A1F699B X-CRM114-Status: GOOD ( 20.00 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently when taking a SME access trap we allocate storage for the SVE register state in order to be able to handle storage of streaming mode SVE. Due to the original usage in a purely SVE context the SVE register state allocation this also flushes the register state for SVE if storage was already allocated but in the SME context this is not desirable. For a SME access trap to be taken the task must not be in streaming mode so either there already is SVE register state present for regular SVE mode which would be corrupted or the task does not have TIF_SVE and the flush is redundant. Fix this by adding a flag to sve_alloc() indicating if we are in a SVE context and need to flush the state. Freshly allocated storage is always zeroed either way. Fixes: 8bd7f91c03d88 ("arm64/sme: Implement traps and syscall handling for SME") Signed-off-by: Mark Brown --- arch/arm64/include/asm/fpsimd.h | 4 ++-- arch/arm64/kernel/fpsimd.c | 10 ++++++---- arch/arm64/kernel/ptrace.c | 6 +++--- arch/arm64/kernel/signal.c | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h index 9bb1873f5295..6f86b7ab6c28 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -153,7 +153,7 @@ struct vl_info { #ifdef CONFIG_ARM64_SVE -extern void sve_alloc(struct task_struct *task); +extern void sve_alloc(struct task_struct *task, bool flush); extern void fpsimd_release_task(struct task_struct *task); extern void fpsimd_sync_to_sve(struct task_struct *task); extern void fpsimd_force_sync_to_sve(struct task_struct *task); @@ -256,7 +256,7 @@ size_t sve_state_size(struct task_struct const *task); #else /* ! CONFIG_ARM64_SVE */ -static inline void sve_alloc(struct task_struct *task) { } +static inline void sve_alloc(struct task_struct *task, bool flush) { } static inline void fpsimd_release_task(struct task_struct *task) { } static inline void sve_sync_to_fpsimd(struct task_struct *task) { } static inline void sve_sync_from_fpsimd_zeropad(struct task_struct *task) { } diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index dd63ffc3a2fa..b9ae9827e6e8 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -715,10 +715,12 @@ size_t sve_state_size(struct task_struct const *task) * do_sve_acc() case, there is no ABI requirement to hide stale data * written previously be task. */ -void sve_alloc(struct task_struct *task) +void sve_alloc(struct task_struct *task, bool flush) { if (task->thread.sve_state) { - memset(task->thread.sve_state, 0, sve_state_size(task)); + if (flush) + memset(task->thread.sve_state, 0, + sve_state_size(task)); return; } @@ -1388,7 +1390,7 @@ void do_sve_acc(unsigned long esr, struct pt_regs *regs) return; } - sve_alloc(current); + sve_alloc(current, true); if (!current->thread.sve_state) { force_sig(SIGKILL); return; @@ -1439,7 +1441,7 @@ void do_sme_acc(unsigned long esr, struct pt_regs *regs) return; } - sve_alloc(current); + sve_alloc(current, false); sme_alloc(current); if (!current->thread.sve_state || !current->thread.za_state) { force_sig(SIGKILL); diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 21da83187a60..eb7c08dfb834 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -882,7 +882,7 @@ static int sve_set_common(struct task_struct *target, * state and ensure there's storage. */ if (target->thread.svcr != old_svcr) - sve_alloc(target); + sve_alloc(target, true); } /* Registers: FPSIMD-only case */ @@ -912,7 +912,7 @@ static int sve_set_common(struct task_struct *target, goto out; } - sve_alloc(target); + sve_alloc(target, true); if (!target->thread.sve_state) { ret = -ENOMEM; clear_tsk_thread_flag(target, TIF_SVE); @@ -1082,7 +1082,7 @@ static int za_set(struct task_struct *target, /* Ensure there is some SVE storage for streaming mode */ if (!target->thread.sve_state) { - sve_alloc(target); + sve_alloc(target, false); if (!target->thread.sve_state) { clear_thread_flag(TIF_SME); ret = -ENOMEM; diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 0c227f57def5..f00e8b33170a 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -310,7 +310,7 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user) fpsimd_flush_task_state(current); /* From now, fpsimd_thread_switch() won't touch thread.sve_state */ - sve_alloc(current); + sve_alloc(current, true); if (!current->thread.sve_state) { clear_thread_flag(TIF_SVE); return -ENOMEM; -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel