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 91FF3C61D96 for ; Tue, 21 Nov 2023 13:54:49 +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:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=toEWFINJ9xWupICBjJEaN/N0fzSkjHx3vynMhj5iyjo=; b=QkV IbG0hSb0ktxHSNc1QJbIRoiYzMVBamDU8KZfhvFnkOQ7sSNVEVz+eAB1xaSy385zWk9P1t3cTdJ3o U1/D+TO+pgjFwyD5U0mMkqxN/LCOtkvYOvPUQu48yesbax4gXwuR+k8trUIo2qfypuOzHZmN50iyo vweb2QeIczGS4erXwRp4ckC65LjXMsUkhg98sZuubdv3sHZOAzxt4e6UbtJ51iDp9vM3CVY3mnZI+ YOLq8JQ1K9x+bp92bkcNJbkX0XgMbrMO1EQSScu5upKRKwLRAI1zKxubAXq4f87K5DnlCPULjzWIo mIjcOfglMY4m5sO8dzr7s4fhc50Td2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r5RCq-00Gwfm-0L; Tue, 21 Nov 2023 13:54:24 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r5RAx-00GujY-1j for linux-arm-kernel@lists.infradead.org; Tue, 21 Nov 2023 13:52:29 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-da04fb79246so8047510276.2 for ; Tue, 21 Nov 2023 05:52:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700574745; x=1701179545; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=1tPZ+aO7eg40vvpbp94ZWWYEWUg2Gvql38kZjHVBZI4=; b=ocu+jsW5c8zEU4F2NPY6zONAfIbChrsdQXeI3+9/FlLEnajYBF33xPuItIqkkkD9DW DohTyGlWPqpfLyr2mluHeQl3CGUX+FuFvqVsH/WnqbmkoYuFjtnwEuasj8pf8PlwpqEn mN1Ed1MhT6/s8D69n03Gz9piXUx279lIUWbRzP6oDC3C9DvtjVeRjcqLkFd+xQhUOq/E UeoFYn2T1nlfmvgpuUU7hWMQF2p4MTcPCjLbJVgHnrV31aa6vKbOZXLEj74nAhweybAc HFKDKTil/40rmukInk1ozg24WkrQ9EM2eqCTEH1RwXwbDxj1VA3++qev5Hhc46mQyf1N n7Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700574745; x=1701179545; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1tPZ+aO7eg40vvpbp94ZWWYEWUg2Gvql38kZjHVBZI4=; b=K5h3WP98VpmI4kfhHWNvzM69p6JSuyrUkSWG86PzI+W6H9WPwzXmiH2MG7relLmcWe S3WgsTjspgtRgLDh1bDvNh1W+yeiWFb2OS7CS1xHXkHmk1Ij1DaqQqymqIDbUA+Hbb86 1ySF5GZLkMKJgeLvQKFeUWRaXQ3aoFByHmiPNMoVLEM6AVqm1jwGlHgtqLVxy7TtlISL 66mKtDO6NkkwQ2HyjXsKRNfMQugFUkf+yiAHCVt+NzlonEs1ahSG5lS5NJy6vNY6w8ze bHbC+ROzmnea0445JyeocjNdIux5PmkfaIaVS4KBdMI/PU9QJwLFkjTVpTNP9i4A2uZw H/Ug== X-Gm-Message-State: AOJu0YzcJIzAjCLvQncA5vxcTW2P0zqbJRXQpU68W8NFImDamsovFm1i emy5j431mGBb/faBSem/AWn8XL7dnbtZn6/5BTSUqhfqAWG/u4fO10EVkOCut1dUnyIyYNx7izu ucQHkz+EjEknwHRw9qkwxs9IE4PJ1ioQgnmGy2bqyplL6SYtvpH45JLPdKLRXgkqwAqbXa13cwZ U= X-Google-Smtp-Source: AGHT+IGB8n9VWbLR80ijglwRcf4dD1LeDdgV5L+dFWZHnIB4JtWku/Ob9RESF7bqzGeELb3g36AMrsoq X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a25:3281:0:b0:d9a:37cf:c22b with SMTP id y123-20020a253281000000b00d9a37cfc22bmr242197yby.1.1700574744634; Tue, 21 Nov 2023 05:52:24 -0800 (PST) Date: Tue, 21 Nov 2023 14:52:13 +0100 Mime-Version: 1.0 X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3245; i=ardb@kernel.org; h=from:subject; bh=msnZ8PMPHj8Ri/AXFunqayrypOxrdMnRb9vSAp5CjJQ=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JITVmG++2O085ZZTsM86JrD9uNb0vIuxi/54o9QTRy/v3+ NRwaBV2lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIkEv2D4H7Z2ut2fpaq/Z6/s C0/gDAqYxPtT6GysU4QA17z8rRMOLWD4H61n/GbREpWLBeZzVL/8Ef93cWsDe4fFxt7Wp4axkoF O3AA= X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231121135212.2235251-5-ardb@google.com> Subject: [PATCH 0/3] arm64: Run kernel mode NEON with preemption enabled From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231121_055227_606889_2AB6FA5D X-CRM114-Status: GOOD ( 17.19 ) 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 From: Ard Biesheuvel Currently, kernel mode NEON (SIMD) support is implemented in a way that requires preemption to be disabled while the SIMD registers are live. The reason for this is that those registers are not in the set that is preserved/restored on exception entry/exit and context switch, as this would impact performance generally, even for workloads where kernel mode SIMD is not the bottleneck. However, doing substantial work with preemption disabled is not great, as it affects scheduling latency, which is especially problematic for real-time use cases. So ideally, we should keep preemption enabled when we can, and find another way to ensure that this does not corrupt the NEON register state of in-kernel SIMD users. This series implements a suggestion by Mark Rutland, and introduces a thread_info flag TIF_USING_KMODE_NEON, which indicates to the thread switch machinery that the task in question has live kernel mode SIMD state which needs to be preserved and restored. The space needed for this is allocated in thread_struct. (*) Given that currently, we run kernel mode NEON with softirqs disabled (to avoid the need for preserving kernel mode NEON context belonging to task context while the SIMD unit is being used by code running in softirq context), just removing the preempt_disable/enable calls is not sufficient, and we also need to leave softirqs enabled. This means that we may need to preserve kernel mode NEON state not only on a context switch, but also when code running in softirq context takes ownership of the SIMD unit, but this is straight-forward once we add the scratch space to thread_struct. (*) We might decide to allocate this space (~512 bytes) dynamically, if the thread_struct memory footprint causes issues. However, we should also explore doing the same for the user space FPSIMD state, as kernel threads never return to user space and have no need for this allocation. Cc: Marc Zyngier Cc: Will Deacon Cc: Mark Rutland Cc: Kees Cook Cc: Catalin Marinas Cc: Mark Brown Ard Biesheuvel (3): arm64: fpsimd: Drop unneeded 'busy' flag arm64: fpsimd: preserve/restore kernel mode NEON at context switch arm64: crypto: remove conditional yield logic arch/arm64/crypto/aes-glue.c | 21 ++-- arch/arm64/crypto/aes-modes.S | 2 - arch/arm64/crypto/sha1-ce-core.S | 2 - arch/arm64/crypto/sha1-ce-glue.c | 19 +-- arch/arm64/crypto/sha2-ce-core.S | 2 - arch/arm64/crypto/sha2-ce-glue.c | 19 +-- arch/arm64/crypto/sha3-ce-core.S | 4 +- arch/arm64/crypto/sha3-ce-glue.c | 14 +-- arch/arm64/crypto/sha512-ce-core.S | 2 - arch/arm64/crypto/sha512-ce-glue.c | 16 +-- arch/arm64/include/asm/assembler.h | 29 ----- arch/arm64/include/asm/processor.h | 2 + arch/arm64/include/asm/simd.h | 11 +- arch/arm64/include/asm/thread_info.h | 1 + arch/arm64/kernel/asm-offsets.c | 4 - arch/arm64/kernel/fpsimd.c | 128 +++++++++++--------- 16 files changed, 106 insertions(+), 170 deletions(-) -- 2.43.0.rc1.413.gea7ed67945-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel