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 74CCBD3B7EA for ; Tue, 9 Dec 2025 05:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=vxhzWYhMZ2zDvldAPYU2wxWc1QPEP6Epr1IjS+1v4Wk=; b=JqanLPj/OOIZAoNMU4XIgAf/kr mHYgYuM2SWf94uY17j45ec5BQZeTl3fXDpNu5reNJkHqiuEwa5maeS4j4g4+okrhyH94ZZMMfi/K8 V51AsUHDL5f6GTvC0XXsCBW6Wd98PICAXd4574rv/9MfaSAFRw1ZEtvxqcX5kXoX/9k7WYYhz3iGu w1f8q9LrdYdnsuhDGTSgpw7ysMFe7tvCp5pOealeHxP3iqoOwGTicV8az33LjQHs9D1hwExE2ZmQ2 QJFFKvwT21wN7nfwYnUKm+8ph8pPZv7lIlO/E6f7RBNNSMaQzBXfHuJfHK9G6HbNOZzQyIUpeSIGr ZMDhHpqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vSqat-0000000DrKV-48ef; Tue, 09 Dec 2025 05:49:04 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vSqaq-0000000DrK2-2HrJ for linux-arm-kernel@lists.infradead.org; Tue, 09 Dec 2025 05:49:02 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id E253B40DDC; Tue, 9 Dec 2025 05:48:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82864C4CEF5; Tue, 9 Dec 2025 05:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765259338; bh=EnPxXewT0JYL81DgO6QFNp08Dq76MYHJMEyIx30LmfE=; h=From:To:Cc:Subject:Date:From; b=rG0hfk57E0nf/ER61dqgCBdyU695Bufz0ivIecyIZBckFwTioW3qw49jFWUI47YFZ mKH1l2Vu4NElb/D5JVzEjPAERMQdX2WVAZDOw0HKfvlxtBHe0zfcDIFKAtqizWNNh4 fpQqiJR+bDS9iDrDdk7N5jDYPSt+Uqcj2eyMpkJ40R9U+GLlt0G0XrrHw8S3pMyPFb ZyvQI3aku2KeutoMHFe414NTI3yC7CsBOAz1KU8Ioa9LhNKfatjNm69InLJbEXINVW g2+ya2mv1RTLcqsDnZW6j6H84Ki/o2nyMkMCCxXuKUlM7IDKR7iV24dv0xpD1x+fco +tXwNOjSA7/4Q== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-crypto@vger.kernel.org, Ard Biesheuvel , Will Deacon , Catalin Marinas , Kees Cook , Eric Biggers Subject: [PATCH v2] arm64/simd: Avoid pointless clearing of FP/SIMD buffer Date: Tue, 9 Dec 2025 06:48:49 +0100 Message-ID: <20251209054848.998878-2-ardb@kernel.org> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2051; i=ardb@kernel.org; h=from:subject; bh=EnPxXewT0JYL81DgO6QFNp08Dq76MYHJMEyIx30LmfE=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIdN8h/M0vcfvp115H//M+f+5X+Y77E+aX1joe8n29LWOh /kCd9P/d5SyMIhxMciKKbIIzP77bufpiVK1zrNkYeawMoEMYeDiFICb3MDwv6bhTLPa++1ZMm/5 ri2eyH5yw9e2e4Y+FetL69Uj7PwE1zL8M94cZPI4zEl1g/ZpjtO2X+u9/6658+rL5dIlNou3PVg QxgIA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251208_214900_607247_E9E686F1 X-CRM114-Status: GOOD ( 11.63 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The buffer provided to kernel_neon_begin() is only used if the task is scheduled out while the FP/SIMD is in use by the kernel, or when such a section is interrupted by a softirq that also uses the FP/SIMD. IOW, this happens rarely, and even if it happened often, there is still no reason for this buffer to be cleared beforehand, which happens unconditionally, due to the use of a compound literal expression. So define that buffer variable explicitly, and mark it as __uninitialized so that it will not get cleared, even when -ftrivial-auto-var-init is in effect. This requires some preprocessor gymnastics, due to the fact that the variable must be defined throughout the entire guarded scope, and the expression ({ struct user_fpsimd_state __uninitialized st; &st; }) is problematic in that regard, even though the compilers seem to permit it. So instead, repeat for 'for ()' trick that is also used in the implementation of the guarded scope helpers. Cc: Will Deacon , Cc: Catalin Marinas , Cc: Kees Cook Cc: Eric Biggers Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/simd.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/simd.h b/arch/arm64/include/asm/simd.h index 0941f6f58a14..69ecbd69ca8c 100644 --- a/arch/arm64/include/asm/simd.h +++ b/arch/arm64/include/asm/simd.h @@ -48,6 +48,13 @@ DEFINE_LOCK_GUARD_1(ksimd, kernel_neon_begin(_T->lock), kernel_neon_end(_T->lock)) -#define scoped_ksimd() scoped_guard(ksimd, &(struct user_fpsimd_state){}) +#define __scoped_ksimd(_label) \ + for (struct user_fpsimd_state __uninitialized __st; \ + true; ({ goto _label; })) \ + if (0) { \ +_label: break; \ + } else scoped_guard(ksimd, &__st) + +#define scoped_ksimd() __scoped_ksimd(__UNIQUE_ID(label)) #endif base-commit: 3f9f0252130e7dd60d41be0802bf58f6471c691d -- 2.47.3