From patchwork Fri Mar 15 14:51:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13593581 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 4E70FC54E67 for ; Fri, 15 Mar 2024 14:52:55 +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=QTDha9UYr04KkAW5cLP0tjgpIJLduw1Z7wVk3bZ00gY=; b=aMpNp7rY811zgv ApZN1sKQgfugxJsL03E/R71zNw3ZlfLb4OdEwYkRhyGyKSR+DY9T9Uib6J3ee80eq/sXSsjRaIVga FhW7ymwv0anWa6knHgFQ9F+4z8d4r8RIXtuWNH2GZh0n6xpjMR555wDAEi6u3pZ3iRsMDvqqW5yrH vioAu2zAUr7RS464yV44EQEOukAb8m4yGa9L1DzAOF2zP/9G/QsW3U74Xh9R4xdBRck2fSbw41Njx w7dPfaY7ypQlYPFo2cHA5wu1ThTD0hBe0QGUHNDnn7Cj+/klVPfYrO+dH88JHttSF0FBYmlZE6tsl ALJi8YykVkmoJbiq9Swg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rl8vL-00000000Z59-0jF4; Fri, 15 Mar 2024 14:52:43 +0000 Received: from galois.linutronix.de ([193.142.43.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rl8v0-00000000YxD-3MAk for linux-arm-kernel@lists.infradead.org; Fri, 15 Mar 2024 14:52:35 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1710514338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7ectyru+WVbUpcBsyI0+gtYVBXWtkG0e5PNgSg/gvNU=; b=cR6dgGfWCLofQ3c8wGW//hat4AT25inPMcko31n2/PxBaxyYkDeyLanBKztFpQ3KoISKaA 5Rb/UQ+QmjxbcLLbHEW+jV+q1yCV2rxeP3e+6uxHbQHEzxOc/rAZJ5BY3WwO9IfIjhW95Z uMKpAcxen5mmL95oSeRcdOgQhQ5YK1AwmUr4UZLL5Pr1hcxE7t7TurfgoM+4pZkR/pkSmy 9dYtVB4P8s27TagLra90sw+96YdsxuiWwojoCsZ9MAyEIZOl2m2y4P9q3zA8aqTBnezp/l Di1gy/uOvD8fs8ZF7Pz978AALGJ2cgiFJTWRKnho7VjrVNeAZWU+oXxNF+LR5Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1710514338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7ectyru+WVbUpcBsyI0+gtYVBXWtkG0e5PNgSg/gvNU=; b=8/DiXtQ0DHJdHfA9UHTGgWlt2Pi5UCA6fVXXAsvLIaD65UdsC2cVEGemK0Y5RMw6t+h2Yd 5zG0Pf8pvkHj47Bw== To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: ardb@kernel.org, tglx@linutronix.de, Sebastian Andrzej Siewior Subject: [PATCH v4 1/4] ARM: vfp: Provide vfp_lock() for VFP locking. Date: Fri, 15 Mar 2024 15:51:00 +0100 Message-ID: <20240315145208.3598288-2-bigeasy@linutronix.de> In-Reply-To: <20240315145208.3598288-1-bigeasy@linutronix.de> References: <20240315145208.3598288-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240315_075223_032255_7B26587A X-CRM114-Status: GOOD ( 12.68 ) 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 kernel_neon_begin() uses local_bh_disable() to ensure exclusive access to the VFP unit. This is broken on PREEMPT_RT because a BH disabled section remains preemptible on PREEMPT_RT. Introduce vfp_lock() which uses local_bh_disable() and preempt_disable() on PREEMPT_RT. Since softirqs are processed always in thread context, disabling preemption is enough to ensure that the current context won't get interrupted by something that is using the VFP. Use it in kernel_neon_begin(). Reviewed-by: Ard Biesheuvel Signed-off-by: Sebastian Andrzej Siewior --- arch/arm/vfp/vfpmodule.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index b68efe643a12c..7d234fc82ebf6 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -55,6 +55,34 @@ extern unsigned int VFP_arch_feroceon __alias(VFP_arch); */ union vfp_state *vfp_current_hw_state[NR_CPUS]; +/* + * Claim ownership of the VFP unit. + * + * The caller may change VFP registers until vfp_unlock() is called. + * + * local_bh_disable() is used to disable preemption and to disable VFP + * processing in softirq context. On PREEMPT_RT kernels local_bh_disable() is + * not sufficient because it only serializes soft interrupt related sections + * via a local lock, but stays preemptible. Disabling preemption is the right + * choice here as bottom half processing is always in thread context on RT + * kernels so it implicitly prevents bottom half processing as well. + */ +static void vfp_lock(void) +{ + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) + local_bh_disable(); + else + preempt_disable(); +} + +static void vfp_unlock(void) +{ + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) + local_bh_enable(); + else + preempt_enable(); +} + /* * Is 'thread's most up to date state stored in this CPUs hardware? * Must be called from non-preemptible context. @@ -837,7 +865,7 @@ void kernel_neon_begin(void) unsigned int cpu; u32 fpexc; - local_bh_disable(); + vfp_lock(); /* * Kernel mode NEON is only allowed outside of hardirq context with @@ -868,7 +896,7 @@ void kernel_neon_end(void) { /* Disable the NEON/VFP unit. */ fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN); - local_bh_enable(); + vfp_unlock(); } EXPORT_SYMBOL(kernel_neon_end); From patchwork Fri Mar 15 14:51:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13593577 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 D1531C54E67 for ; Fri, 15 Mar 2024 14:52:39 +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=PpZzAzjnkxZBOZYKKM6AhOJPuGY43IZOxJiTBxfgxRI=; b=21+Z2+H2b8O4CX ippH2xTgL3PeLKAD3VA8BIwZ60d6XLUK95eFINgtMOR58NYzK8+a3C6sz1VU58+dO0eADywNtvY5O 7GUjPPBbzS76K3AVEDtOtwWz+jsZwAoS9OmK3mOLYUOXyOruhe4QBr95g+o0UNSuH0LCk5f2VQt5y aVpZa32rCu72vxQbzbkoY4C7UJt9iiGViGyT3EWGrj1PhT+lw7tWgqXZ1Xwr3YP57PZiyC3gvrkph zXe67QkWar/HuPcwVlL2p4bLw6oU9P5Qqt1VMkBjPMzvsax8YgMGtJ0DAvvtKyzaDMU2j8JOMqUbe I6bIIU4ZOdWvQ9tzCzmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rl8v7-00000000Z13-3Wu9; Fri, 15 Mar 2024 14:52:29 +0000 Received: from galois.linutronix.de ([193.142.43.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rl8v0-00000000YxE-3KPC for linux-arm-kernel@lists.infradead.org; Fri, 15 Mar 2024 14:52:27 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1710514339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+OAfy5jSCSE565FVlqBI8NImsy1fV4FaCH5/hqY0eJo=; b=HT/ESTnVdqzZ10e/Dm5+TfmwrXVRhrL1bj/JndSsmr0RgE4dqub2xeBWUb4zYwruscMCga /USo//4Vw7qhYuyXsB7v+eWBzMQbkrr3YSM59W0Z3a0RkhQRUr3Xyyt9hzAqdmRVj9ZLd2 jHTH8n75LaoIHwywzL7K+M/WoK5sMwX/Iu8OOqRE+0mRwz02EYamx231CPbWwAMcb8z6wZ 6R0rjIxI3Jab510eCboq00w4xmQ8HUvV2yuGkkF3Q+wtoY7+cMfEAwMMJvpk+6yAV2lkHa QuxD+6LvtoZ2nDDzpbCEd3Wd+9a1C7iE0ST+q4M7Mqqa4U7a90CMCOEm31fKMQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1710514339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+OAfy5jSCSE565FVlqBI8NImsy1fV4FaCH5/hqY0eJo=; b=DhxhWUhD+34qeJXfPn5mnpY6NpcbWM3p22JEg1ZD8UDNfw63e37rrOxjPRQjR2wS7pvQal +X+Qh4X25ayYFZCQ== To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: ardb@kernel.org, tglx@linutronix.de, Sebastian Andrzej Siewior Subject: [PATCH v4 2/4] ARM: vfp: Use vfp_lock() in vfp_sync_hwstate(). Date: Fri, 15 Mar 2024 15:51:01 +0100 Message-ID: <20240315145208.3598288-3-bigeasy@linutronix.de> In-Reply-To: <20240315145208.3598288-1-bigeasy@linutronix.de> References: <20240315145208.3598288-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240315_075223_003690_ED29DEBA X-CRM114-Status: GOOD ( 11.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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org vfp_sync_hwstate() uses preempt_disable() followed by local_bh_disable() to ensure that it won't get interrupted while checking the VFP state. This harms PREEMPT_RT because softirq handling can get preempted and local_bh_disable() synchronizes the related section with a sleeping lock which does not work with disabled preemption. Use the vfp_lock() to synchronize the access. Reviewed-by: Ard Biesheuvel Signed-off-by: Sebastian Andrzej Siewior --- arch/arm/vfp/vfpmodule.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index 7d234fc82ebf6..49ccd205ad780 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -540,11 +540,9 @@ static inline void vfp_pm_init(void) { } */ void vfp_sync_hwstate(struct thread_info *thread) { - unsigned int cpu = get_cpu(); + vfp_lock(); - local_bh_disable(); - - if (vfp_state_in_hw(cpu, thread)) { + if (vfp_state_in_hw(raw_smp_processor_id(), thread)) { u32 fpexc = fmrx(FPEXC); /* @@ -555,8 +553,7 @@ void vfp_sync_hwstate(struct thread_info *thread) fmxr(FPEXC, fpexc); } - local_bh_enable(); - put_cpu(); + vfp_unlock(); } /* Ensure that the thread reloads the hardware VFP state on the next use. */ From patchwork Fri Mar 15 14:51:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13593579 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 B6FF1C54E58 for ; Fri, 15 Mar 2024 14:52:51 +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=A/X8cqj84JToCSVuiURxqm3WkdB4TxZN3i6hNfQ9TGY=; b=sgkToEA1VNQLKF aNJ8K70UgeTELCz9s9DMUlKDDrQMBGHzPe27PufW8N+wh5OItpqND10rCjnOL2lKuEWEbXN+ddGn7 gar2pc5R8uIm5x//kfsjNitT7XvfyDXLAszOX5V9BO86vNeSjGUHxnVhPl2OFfdH5b/j9wRGuOC9k ZRVVDxhaGoZbIhwoA+brk/nVTkCOZatQXbDwn7yCoIx3AmRS6IArfI+lE+8rvYpiIgj43Y0ObK2xy 8weINGnb6z57rgAVCL75Z4m5LlacvrBxNscTI/+//gVetRIJhMTQZ46jIKmjwp2hBwiFVZU0B8uxa 04+GNaVrcIyazZ8P1XpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rl8vI-00000000Z43-2lPz; Fri, 15 Mar 2024 14:52:40 +0000 Received: from galois.linutronix.de ([193.142.43.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rl8v0-00000000YxH-3IWN for linux-arm-kernel@lists.infradead.org; Fri, 15 Mar 2024 14:52:35 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1710514339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=98gtkEVWAonVmsxkQx/Dz5eOFvA6kRM0iPjA0WUFmf0=; b=mdNMjUfEi/5XKtOvZLs80ss5FpeiCdYiaoICY1c1vIh1qRVvRRsLl0WSK1Df00rkMGUKDP MWa6uLrYxJFhvBzeBQAl03IQ/YkqM6QHyyeiSTob0XKc+BpSNYeh0kAc0/xDWo95mXv0UP jL0tuwxZJm9GJ7W5oRcVgZbqA22LMrihMNnT+i+jAQhRU9+QgNf2ErbaJ2rGdPUFN1d9af mRvE+tPSzSZ8iPkxmeaiECFNOzS3CwSDj5H4xWlloQrVatu+u16dUQpwVvnjiws1mKCa5g i98C6QIJqk6zickAzmiUVFsvhSSVtrGgxbfH5wj/s89MG2V5ZUjIGyn9x5fhdw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1710514339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=98gtkEVWAonVmsxkQx/Dz5eOFvA6kRM0iPjA0WUFmf0=; b=udrODnSr5w3KYrYvwfh7ZGKWHOeNg4EzHh5E8r4Mr1DQ7ccYonlFPSOE7kjUdFAwrdUgon di9sMrhi1Uy5c/Bw== To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: ardb@kernel.org, tglx@linutronix.de, Sebastian Andrzej Siewior Subject: [PATCH v4 3/4] ARM: vfp: Use vfp_lock() in vfp_support_entry(). Date: Fri, 15 Mar 2024 15:51:02 +0100 Message-ID: <20240315145208.3598288-4-bigeasy@linutronix.de> In-Reply-To: <20240315145208.3598288-1-bigeasy@linutronix.de> References: <20240315145208.3598288-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240315_075223_017397_B50CE083 X-CRM114-Status: UNSURE ( 8.89 ) X-CRM114-Notice: Please train this message. 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 vfp_entry() is invoked from exception handler and is fully preemptible. It uses local_bh_disable() to remain uninterrupted while checking the VFP state. This is not working on PREEMPT_RT because local_bh_disable() synchronizes the relevant section but the context remains fully preemptible. Use vfp_lock() for uninterrupted access. Reviewed-by: Ard Biesheuvel Signed-off-by: Sebastian Andrzej Siewior --- arch/arm/vfp/vfpmodule.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index 49ccd205ad780..6ebd5d4b8fa29 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -708,7 +708,7 @@ static int vfp_support_entry(struct pt_regs *regs, u32 trigger) if (!user_mode(regs)) return vfp_kmode_exception(regs, trigger); - local_bh_disable(); + vfp_lock(); fpexc = fmrx(FPEXC); /* @@ -787,7 +787,7 @@ static int vfp_support_entry(struct pt_regs *regs, u32 trigger) if (!(fpscr & FPSCR_IXE)) { if (!(fpscr & FPSCR_LENGTH_MASK)) { pr_debug("not VFP\n"); - local_bh_enable(); + vfp_unlock(); return -ENOEXEC; } fpexc |= FPEXC_DEX; @@ -797,7 +797,7 @@ bounce: regs->ARM_pc += 4; VFP_bounce(trigger, fpexc, regs); } - local_bh_enable(); + vfp_unlock(); return 0; } From patchwork Fri Mar 15 14:51:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13593580 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 11C95C54E67 for ; Fri, 15 Mar 2024 14:52:52 +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=61Apcs7eeffXPO0absXGGZKVd2PRmW0Ismo2PgPpdC4=; b=Hy/8S8N8NVTgPV bnaXA4GYo0A9pAwqNwI76K1FmT0+QmgLuXoBg/ceChYzySzszUXR+84UMuzA53pdwEZmLgVVYq3MQ LPW4wTMNJbzewjxEYccMFWpHT7EYgdjJKlNt/fc6CZLB06t7YnehqQwAVi5Dh1aCWnspvVBX7w3KU ewx5OCowQVHHzw/HFKr9unnVjbn8xSitCtpHAboCCITXVK9L/m4ZaT/WcVSqPchVhvj9FwBIx1zZ9 SNY+9Vv/PyvUE4feyA1f7h21CV4BC1HCV0s8RveTSMEikRHQ5XBimKCUroj7HDyxeQKcMf8Y09thL k+XRVU9LbucMC9K2xVuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rl8vJ-00000000Z4X-40mm; Fri, 15 Mar 2024 14:52:41 +0000 Received: from galois.linutronix.de ([2a0a:51c0:0:12e:550::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rl8v0-00000000YxI-3DPs for linux-arm-kernel@lists.infradead.org; Fri, 15 Mar 2024 14:52:35 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1710514339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BYTJDrcJfpdw8gLVlmoUe+wlBs78jjIV619RBA//dvI=; b=lCz82WgCb+GWkryDjnkBApvzBJ0IQAJWbYD5MRRX2bjfsk/odLvWmLnX8GTQkYMcs7bXMG XQbOkfoNewuBjCthw9bnzsQMDz27rzFBNoLnAJMxr83PabqsXQa2Tw3x+EMTXPZRQMdrhs vSw1OTVqk9l6+Xw8VNjSTKFcu9+7bICkEU5CHSlrU+/9QvOnGr3xFqTCrxBYnazKOuKfc3 bOgi2vILlucw/BDNZ8RC8s4ox3l1xkluiBHGqO0C/y0y3Irxv0/IuloDghCitxHzTjDLjC Zpfdr6fhmYjqUsYgl1T3VR5FQrKHh1EMspk29j4ub+QkLxLvMKB1P4lywLq2MQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1710514339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BYTJDrcJfpdw8gLVlmoUe+wlBs78jjIV619RBA//dvI=; b=BM//5S3qV1rw1sSo8QpmktAIpse23InaLIeTHJBFgdsDtCDTfZLBYrhQ51nrZ+/7xOkjjr 0PC3okwhCuuSMfBg== To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: ardb@kernel.org, tglx@linutronix.de, Sebastian Andrzej Siewior Subject: [PATCH v4 4/4] ARM: vfp: Move sending signals outside of vfp_lock()ed section. Date: Fri, 15 Mar 2024 15:51:03 +0100 Message-ID: <20240315145208.3598288-5-bigeasy@linutronix.de> In-Reply-To: <20240315145208.3598288-1-bigeasy@linutronix.de> References: <20240315145208.3598288-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240315_075223_132827_5C6731DC X-CRM114-Status: GOOD ( 13.08 ) 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 VFP_bounce() is invoked from within vfp_support_entry() and may send a signal. Sending a signal uses spinlock_t which becomes a sleeping lock on PREEMPT_RT and must not be acquired within a preempt-disabled section. Move the vfp_raise_sigfpe() block outside of the vfp_lock() section. Reviewed-by: Ard Biesheuvel Signed-off-by: Sebastian Andrzej Siewior --- arch/arm/vfp/vfpmodule.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index 6ebd5d4b8fa29..48745a3c52618 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -268,7 +268,7 @@ static void vfp_panic(char *reason, u32 inst) /* * Process bitmask of exception conditions. */ -static void vfp_raise_exceptions(u32 exceptions, u32 inst, u32 fpscr, struct pt_regs *regs) +static int vfp_raise_exceptions(u32 exceptions, u32 inst, u32 fpscr) { int si_code = 0; @@ -276,8 +276,7 @@ static void vfp_raise_exceptions(u32 exceptions, u32 inst, u32 fpscr, struct pt_ if (exceptions == VFP_EXCEPTION_ERROR) { vfp_panic("unhandled bounce", inst); - vfp_raise_sigfpe(FPE_FLTINV, regs); - return; + return FPE_FLTINV; } /* @@ -305,8 +304,7 @@ static void vfp_raise_exceptions(u32 exceptions, u32 inst, u32 fpscr, struct pt_ RAISE(FPSCR_OFC, FPSCR_OFE, FPE_FLTOVF); RAISE(FPSCR_IOC, FPSCR_IOE, FPE_FLTINV); - if (si_code) - vfp_raise_sigfpe(si_code, regs); + return si_code; } /* @@ -352,6 +350,8 @@ static u32 vfp_emulate_instruction(u32 inst, u32 fpscr, struct pt_regs *regs) static void VFP_bounce(u32 trigger, u32 fpexc, struct pt_regs *regs) { u32 fpscr, orig_fpscr, fpsid, exceptions; + int si_code2 = 0; + int si_code = 0; pr_debug("VFP: bounce: trigger %08x fpexc %08x\n", trigger, fpexc); @@ -397,8 +397,8 @@ static void VFP_bounce(u32 trigger, u32 fpexc, struct pt_regs *regs) * unallocated VFP instruction but with FPSCR.IXE set and not * on VFP subarch 1. */ - vfp_raise_exceptions(VFP_EXCEPTION_ERROR, trigger, fpscr, regs); - return; + si_code = vfp_raise_exceptions(VFP_EXCEPTION_ERROR, trigger, fpscr); + goto exit; } /* @@ -422,14 +422,14 @@ static void VFP_bounce(u32 trigger, u32 fpexc, struct pt_regs *regs) */ exceptions = vfp_emulate_instruction(trigger, fpscr, regs); if (exceptions) - vfp_raise_exceptions(exceptions, trigger, orig_fpscr, regs); + si_code2 = vfp_raise_exceptions(exceptions, trigger, orig_fpscr); /* * If there isn't a second FP instruction, exit now. Note that * the FPEXC.FP2V bit is valid only if FPEXC.EX is 1. */ if ((fpexc & (FPEXC_EX | FPEXC_FP2V)) != (FPEXC_EX | FPEXC_FP2V)) - return; + goto exit; /* * The barrier() here prevents fpinst2 being read @@ -441,7 +441,13 @@ static void VFP_bounce(u32 trigger, u32 fpexc, struct pt_regs *regs) emulate: exceptions = vfp_emulate_instruction(trigger, orig_fpscr, regs); if (exceptions) - vfp_raise_exceptions(exceptions, trigger, orig_fpscr, regs); + si_code = vfp_raise_exceptions(exceptions, trigger, orig_fpscr); +exit: + vfp_unlock(); + if (si_code2) + vfp_raise_sigfpe(si_code2, regs); + if (si_code) + vfp_raise_sigfpe(si_code, regs); } static void vfp_enable(void *unused) @@ -773,6 +779,7 @@ static int vfp_support_entry(struct pt_regs *regs, u32 trigger) * replay the instruction that trapped. */ fmxr(FPEXC, fpexc); + vfp_unlock(); } else { /* Check for synchronous or asynchronous exceptions */ if (!(fpexc & (FPEXC_EX | FPEXC_DEX))) { @@ -794,10 +801,10 @@ static int vfp_support_entry(struct pt_regs *regs, u32 trigger) } } bounce: regs->ARM_pc += 4; + /* VFP_bounce() will invoke vfp_unlock() */ VFP_bounce(trigger, fpexc, regs); } - vfp_unlock(); return 0; }