From patchwork Tue Jan 30 15:43:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 194217 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1313988dyb; Tue, 30 Jan 2024 07:51:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxeKeQbTJfUMxuUlf42wiV1iSYA9Ki9sVYml+RqfG2nUOKqkv6JejGuacE5X/SLOujEjQp X-Received: by 2002:ad4:4eaa:0:b0:68c:5ecb:c257 with SMTP id ed10-20020ad44eaa000000b0068c5ecbc257mr2195765qvb.117.1706629874592; Tue, 30 Jan 2024 07:51:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706629874; cv=pass; d=google.com; s=arc-20160816; b=BwCyYs70Sv6K7Oy4iDEQ1Q6uXKnoIHrTWQ9+pMiupxp0iVHp7YlrtKpLRSNd00QNho d28mNm3QMv2A9GIqY6sZD91TOdGpyjamBlSiU0gsl2HPHOP9V9FoINIOvLFVmYqMsUEY eUMGogn7mbbhRV67bbz9A50HxOjKxIg4lYemV010QzN5h5dhIbnQqCsL1OjAb7Rjp4zS XEM466k+IeIfzk93FKKFvSQGiutcpmuJVNGkfXRr9iFIQ3rx0ULSPRiIgx4qLj667/90 y2jsFrUPX9UQ5SQW2yCMklVD+ZdM1VAe2IIP6TVWYOpE+XU0iQJ3UuPAvkOtVZFyl1uV LaHw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=qS69etyyx3dF5e+ilbL66dg0MSh7fOsOREWXehXNLNg=; fh=ZNc7J3bdTbqTQTBMY3yvXX2w0dKHvnGK2cDy4bjr7N0=; b=kGQISGP9EAH+qf1nMDWzQT5emQ+5ZkH7PHWhEZ4DVAXKNNK5QY74PshovJYYOl1OXE es7Z8P0ki7EXH9Nh/YV1x7Cs8DaE75W2Gix6GbX+ZmKlg+/qeqzcT1XALBes+ADAkKva reEU2ncQ8p3rEnjYApe4elWglXCnEZXEh2KVkMM5lJa5hc54hwmN2HVqnx6cNBfdFiK5 Tp9VSXiEepR+5DZkxtnfhwe0vmFIvsVO6MHLJ/wTWavJYpthRIRQxePRHwRJ0KEKd99v GKPwXCGgoFQCe4DBAoW95xzqjhajNNlJ08lwv5QpEd4Q2n/1h4ukb/O9mfahc7lyqKbp 8wRA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=M973pKRE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44875-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44875-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 12-20020a0562140ccc00b0068c4223caaasi7337645qvx.224.2024.01.30.07.51.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 07:51:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44875-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=M973pKRE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44875-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44875-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 811E71C25F40 for ; Tue, 30 Jan 2024 15:50:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87F6586AC4; Tue, 30 Jan 2024 15:50:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M973pKRE" 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 DF3417F7F8; Tue, 30 Jan 2024 15:50:12 +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=1706629813; cv=none; b=Yoc/GzbYHCccupUIOFZjet8YMa3g8JhZgfTqaGLu9XEx+eRCkYn9buaaXNUN15VBO8awiatxJFuic85g18eX8DkGmBYyeWqKVaYh/saN4+eiEmJ0IvwMSd1ZsGH7zL0Ek7AC7VGHU0aHGpeMXqQdpYQXEVuCEZuLxacsJWPu1GA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706629813; c=relaxed/simple; bh=Vk+a4/PMaLBaT+nR1i1sQXCbsnZJFcPjFylI7eVgV6Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=Y38bnktNgc2EqRUaYIwMG+VkoluOG/PjQPautmMKkO2iFhZojBJ7y8Jhx1XP59Lo5kLry++zxzx9JH1Ms4NrKMYAussksdoI1aaY0CsjuER8o8GsDo9conxKzYitoODrlDUTuF8XMUgZ8k0EyzuJ5eXj2tGHyBXqG/yYMiBbjps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M973pKRE; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 161BAC43390; Tue, 30 Jan 2024 15:50:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706629812; bh=Vk+a4/PMaLBaT+nR1i1sQXCbsnZJFcPjFylI7eVgV6Y=; h=From:Date:Subject:To:Cc:From; b=M973pKRE6MfhRjYhN/QX9P4MIQdalu8v2X3PRR4X2wkpeF5HlJSrqVSgv0cfoZRte byNduhOFiXGGCs0nEyoN+41yhcwLWbZDwKRw3/EQgJ+0PdwIj6lk2OOoq2OE3dQ/It muBxO+dRteoisnZlfjG+GpK4uz4SRL2bG+GXBk6DVkJiyNYtmENYWnA8Lqu4Z9N+V8 Tf26BdKgVrF6jKZT5aRhf94VyY5Cjssfkk+CRC5XN4Sc4nUFvTnvsUHjOCACL3HOn3 bq6fA0xPEyV0FZK3LTxxpVX06/yHXKrKED5TCF4qBBFDbtv8HoAsHChH0WjljAmYF7 ENi08H6//CVBg== From: Mark Brown Date: Tue, 30 Jan 2024 15:43:53 +0000 Subject: [PATCH v2] arm64/signal: Don't assume that TIF_SVE means we saved SVE state Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-arm64-sve-signal-regs-v2-1-9fc6f9502782@kernel.org> X-B4-Tracking: v=1; b=H4sIADgZuWUC/3WNQQ6CMBBFr2Jm7ZhOAwiuvIdhUWQojVjMjGk0h LtbSVy6fC/57y+gLIEVTrsFhFPQMMcMdr+D6+iiZwx9ZrDGFoaoRif3qkBNjBp8dBMKe8XySMS mJ1PYEvL2ITyE19a9tJnHoM9Z3ttNoq/9FZs/xURI2DVDX1FnbN24840l8nSYxUO7rusHZNnBz LsAAAA= To: Catalin Marinas , Will Deacon Cc: Dave Martin , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Brown , stable@vger.kernel.org X-Mailer: b4 0.13-dev-a684c X-Developer-Signature: v=1; a=openpgp-sha256; l=2358; i=broonie@kernel.org; h=from:subject:message-id; bh=Vk+a4/PMaLBaT+nR1i1sQXCbsnZJFcPjFylI7eVgV6Y=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBluRqyMHHatjsuh3dci6BH1TGN/k8YOn3ayYgBl2xd Ylsce+6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZbkasgAKCRAk1otyXVSH0CWgB/ 9EgqGXGKiU/cckQpSisnL3ThKknzqaZLsTFUsNS7B7DhLmSNufzrK+9UzTncwxTV3dvF6hoNg26pep iGC3J5/DWPnFOhudx5hLftkNu8HWRICd819Zl4G1UAFnL5RCL3g1JrvvbC2doFWVAOknqz3u9uro+A RA/ULVS00sIN+1vPXCeUcsjDwyfvHeN5UP2/nxHHUBz2z0Bk/sT7clfE1ngtd4Jvbt3tVIPbDmP/vA RsPakFYbyZNrrJivLxbx7FwtC11A46INvB41FdUV1Le7GUxNPlIorIMHf20CILIkaZTCXHxRa0/0g1 P1qqOvKFDLw+8aWGNm81vhM2cxFJ3l X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788522036973498706 X-GMAIL-MSGID: 1789531127055708444 When we are in a syscall we will only save the FPSIMD subset even though the task still has access to the full register set, and on context switch we will only remove TIF_SVE when loading the register state. This means that the signal handling code should not assume that TIF_SVE means that the register state is stored in SVE format, it should instead check the format that was recorded during save. Fixes: 8c845e273104 ("arm64/sve: Leave SVE enabled on syscall if we don't context switch") Signed-off-by: Mark Brown Cc: stable@vger.kernel.org --- Changes in v2: - Rebase onto v6.8-rc2. - Link to v1: https://lore.kernel.org/r/20240119-arm64-sve-signal-regs-v1-1-b9fd61b0289a@kernel.org --- arch/arm64/kernel/fpsimd.c | 2 +- arch/arm64/kernel/signal.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) --- base-commit: 41bccc98fb7931d63d03f326a746ac4d429c1dd3 change-id: 20240118-arm64-sve-signal-regs-5711e0d10425 Best regards, diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index a5dc6f764195..25ceaee6b025 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1635,7 +1635,7 @@ void fpsimd_preserve_current_state(void) void fpsimd_signal_preserve_current_state(void) { fpsimd_preserve_current_state(); - if (test_thread_flag(TIF_SVE)) + if (current->thread.fp_type == FP_STATE_SVE) sve_to_fpsimd(current); } diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 0e8beb3349ea..425b1bc17a3f 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -242,7 +242,7 @@ static int preserve_sve_context(struct sve_context __user *ctx) vl = task_get_sme_vl(current); vq = sve_vq_from_vl(vl); flags |= SVE_SIG_FLAG_SM; - } else if (test_thread_flag(TIF_SVE)) { + } else if (current->thread.fp_type == FP_STATE_SVE) { vq = sve_vq_from_vl(vl); } @@ -878,7 +878,7 @@ static int setup_sigframe_layout(struct rt_sigframe_user_layout *user, if (system_supports_sve() || system_supports_sme()) { unsigned int vq = 0; - if (add_all || test_thread_flag(TIF_SVE) || + if (add_all || current->thread.fp_type == FP_STATE_SVE || thread_sm_enabled(¤t->thread)) { int vl = max(sve_max_vl(), sme_max_vl());