Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp802272rwb; Thu, 15 Dec 2022 02:37:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Zav/nt3O7CQzb7f02qONyt6FgHIpA8oNHIerQWQBKDPVyiwcpituv76MjNqJ9MYXcttfC X-Received: by 2002:a17:902:eb45:b0:189:dfb1:f087 with SMTP id i5-20020a170902eb4500b00189dfb1f087mr26298318pli.24.1671100655529; Thu, 15 Dec 2022 02:37:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671100655; cv=none; d=google.com; s=arc-20160816; b=Ch+7BtGHEb8AFYPOXCvfcithiAejbrpX0GRtT4E73P5qan28A+viqLG+ONLlm4zttK x3pKlwesHMvqjj7KrNrTB4pysJKAp1apzwtA/j2ScCa9c7urnygvdnp+w5OQRyBGJDzB iFkDFIeKMml9SFk7PYsIyKa/63UICKiY+1e0Ted3eRmcRfTbGnqXDY9dhMjdZnAkLYFn UsudEQjUBrZAu4qgAfJmPAuISzGR3JxHxMfmkuZ0fv6k38eX1KSF3Z+QqLLo1XMtbH/p dLyWgTClGh1JsZIO/mX7knXsdnhedOxe2Q0trvpXB1o+osAvGeKrpMCI8RkSipt+uUhH gAGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=AwhkEbxM6tluhQHQ2bMB+VVzWMkBJMG5LjBZ53z9agQ=; b=K2ktDdAnXK32HDImXVkAaAgHBo/IzVgQClPwhmqmgPFmCcxhPZ1NyWyEnivda6C9Qt qsVLa50T1ASQFwgFWCTs+Wj0fA8CBNWvARGlWrkGvdw3kbZ4/oJP6ADFQOKmchNjS3YG O1hDzKgdt+A0ci1WD0770acmxIrJUlRyB0yoVDZgaiSx4Qs8iwm7/P78VrgIjtzF0glq Biw+9V4fXBk9nRdK5lH1a13tJErE1aqbHUMEmquNv27958yWdshnJDgnuc9dCPrT9ojc k0au6mYwqyoihY5ZKlisEwK6IZ9CYJRpo1X1OsGN+RTaWTlWMN7jVzd1ObFOSRS4Ikl1 rSKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=df6yB12z; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jf15-20020a170903268f00b001894d872b14si5276225plb.66.2022.12.15.02.37.20; Thu, 15 Dec 2022 02:37:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=df6yB12z; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230292AbiLOKX2 (ORCPT + 99 others); Thu, 15 Dec 2022 05:23:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230215AbiLOKXO (ORCPT ); Thu, 15 Dec 2022 05:23:14 -0500 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D993727909 for ; Thu, 15 Dec 2022 02:22:58 -0800 (PST) Received: by mail-yb1-xb2a.google.com with SMTP id v126so1174656ybv.2 for ; Thu, 15 Dec 2022 02:22:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=AwhkEbxM6tluhQHQ2bMB+VVzWMkBJMG5LjBZ53z9agQ=; b=df6yB12zHMgxqT0YjoTekaQalMFCuXOyvsiuJqcoR1wyiF6r3guce+kram8HT5zyk4 B9eKS2zuJ6t8894vy+P67gkGl3AunmrZHnVjiCQZluCJPUGQOL+dx4C2iYJdeMBlPuso P5d46zwMWaDRuKz+Oy4qnPFRoDbbGQm4kcXNzYY89NWdkt7QL+M0BRj5hZiAUFBMECqG itBWzkas8gonRf1N0sdEc8Zcm6Q8vJLWnHmmlXDpJBvLHF8S4ePbuxM/yfJdHSZV4WOP 44NiBLRC43/rQrcUiS/Lm5iRNWxP4Q8rrhNMdKLBygRDzs0/xbI4moDu/xg3Wq7Y8vkL zlpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AwhkEbxM6tluhQHQ2bMB+VVzWMkBJMG5LjBZ53z9agQ=; b=2OLrQ15bKUfWJqPduGkLwON9cAhuCDfjEXNDGSt/xP3q5t6k/45S6J5TFieWEbQXjI O45uYd9ccceoLDIUM+TwA4Q/D4yk+x/X5E/GAMQva/uQgC4wz4zFgzbhXY53QmblncC4 mfdRz3B+Dq22kFr8OAqqj26B/ebNJdrEc5RtiXzbwnzAFrlN4J2QvT7QVL59GgL0hn+s NvNS/2h8JcUIdNmdHTfEPv+KI/xRD26SnOee3+xswarM9Bg5eO6R0KJkrMSaYBtGB+qW VToKXXcKsJ48gfRjF95Tp3LaieRfmWAD9EhEIoDvJAqFq94PBIN1uRnkyD17f6YhqLKQ XbQw== X-Gm-Message-State: ANoB5pnOy/S4HnMk1DDw6Upa2JmfiOmHo57FpOLUQ1gVkYYykCODu1Sn LVydqElUvooQk04zUGm3Nw2N9wRkvxLSngGiewk3HU4vMuKfViqs X-Received: by 2002:a25:7648:0:b0:6fe:54d5:2524 with SMTP id r69-20020a257648000000b006fe54d52524mr24044987ybc.522.1671099777243; Thu, 15 Dec 2022 02:22:57 -0800 (PST) MIME-Version: 1.0 References: <20221207103936.2198407-1-ardb@kernel.org> <20221207103936.2198407-2-ardb@kernel.org> In-Reply-To: <20221207103936.2198407-2-ardb@kernel.org> From: Linus Walleij Date: Thu, 15 Dec 2022 11:22:46 +0100 Message-ID: Subject: Re: [PATCH v2 1/2] ARM: vfp: Manipulate VFP state with softirqs disabled To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk, linux-crypto@vger.kernel.org, Arnd Bergmann Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, Dec 7, 2022 at 11:39 AM Ard Biesheuvel wrote: > In a subsequent patch, we will relax the kernel mode NEON policy, and > permit kernel mode NEON to be used not only from task context, as is > permitted today, but also from softirq context. > > Given that softirqs may trigger over the back of any IRQ unless they are > explicitly disabled, we need to address the resulting races in the VFP > state handling, by disabling softirq processing in two distinct but > related cases: > - kernel mode NEON will leave the FPU disabled after it completes, so > any kernel code sequence that enables the FPU and subsequently accesses > its registers needs to disable softirqs until it completes; > - kernel_neon_begin() will preserve the userland VFP state in memory, > and if it interrupts the ordinary VFP state preserve sequence, the > latter will resume execution with the VFP registers corrupted, and > happily save them to memory. > > Given that disabling softirqs also disables preemption, we can replace > the existing preempt_disable/enable occurrences in the VFP state > handling asm code with new macros that dis/enable softirqs instead. > In the VFP state handling C code, add local_bh_disable/enable() calls > in those places where the VFP state is preserved. > > One thing to keep in mind is that, once we allow NEON use in softirq > context, the result of any such interruption is that the FPEXC_EN bit in > the FPEXC register will be cleared, and vfp_current_hw_state[cpu] will > be NULL. This means that any sequence that [conditionally] clears > FPEXC_EN and/or sets vfp_current_hw_state[cpu] to NULL does not need to > run with softirqs disabled, as the result will be the same. Furthermore, > the handling of THREAD_NOTIFY_SWITCH is guaranteed to run with IRQs > disabled, and so it does not need protection from softirq interruptions > either. > > Signed-off-by: Ard Biesheuvel Tricky patch, I had to read it a few times and visualize the concepts, but I am sufficiently convinced that it does the right thing. Reviewed-by: Linus Walleij Yours, Linus Walleij