From patchwork Tue Sep 26 12:54:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13399233 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 D85ABE7E62F for ; Tue, 26 Sep 2023 12:55:58 +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=kSykvOKGvKSZJLhGbZaF5o2VLsziJnzVjzQNh5T7wi0=; b=fCNq+NK7ikKE3p fvSCGmKzrsDi5lT5lUr8TmWCQNXtRY6nXW/KQSKBPUG1LbhCSwX1U3UdWTeyZczo1dUy9ywKPnX63 mdaF3jxAaOoOvHIuT7zG/2tM2KjDwXmHNmLvnwOGeIcS5KSaPnRY6FZUIZffdnzo/HWI8SM61Rzxn 0aLhuojfm2BRfwhlvpxlv3lkLIzycw5cr12LVbN8bRxUcrCUiimYGINEZelr7LDoSEx32oQzu+sD3 paKirOczhJAVPeV8kmaz+uoyLiZFrbpZAeUhqIWPFL+b5/U+UVjCOgxWRi/yLpjUzLYDxSh9/5b+m mkZAVe1oWEkqUbbycagw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ql7b9-00GPBx-39; Tue, 26 Sep 2023 12:55:31 +0000 Received: from galois.linutronix.de ([2a0a:51c0:0:12e:550::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ql7aw-00GP7O-0i for linux-arm-kernel@lists.infradead.org; Tue, 26 Sep 2023 12:55:20 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695732914; 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=dBpRnC0ApiIbGjESCAWlJj2jO+qaa+UVAXGivLH6ziI=; b=fI2sdpesxjZHbqVu80foOCEUJWqckqojVmfeF3hXdI5DbNMVZcYtcpt/KPztQYNAYFjndp O6DbL5IZUGhLtj5ce+Y3nTtZQ50cYn8DeQxv+XLNQQnmuFVIcZIAVxwAjg2XuMof8Hoyq/ iYgo1EadtG9IOjZp0oo6yWXjNAdvTaj5h9uDvOPkJ+srm76yei1kWQtpZREF+MBz4camda Z48JkvG9i46Jq9dewdkzKKZShjmGcf7+YUwLEDGnZxzIBYCMop0L+ye9bVgs30Rzhg5Rp4 vH1sLkQa13G5B575hJ7riN9AaixgPoS1ORmiD6YkFA7O4ZqTRJ1LWD1auRIMFw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695732914; 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=dBpRnC0ApiIbGjESCAWlJj2jO+qaa+UVAXGivLH6ziI=; b=c5gHvOWbwWxzz5WfO51hX3lcvvPgc9Vs/7xGX2eGi8dstd3z3Z9rbLte8+GDfVeW29kxWf Usx7WZ2dGwslq0Cw== To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: ardb@kernel.org, tglx@linutronix.de, Sebastian Andrzej Siewior Subject: [PATCH v3 1/4] ARM: vfp: Provide vfp_lock() for VFP locking. Date: Tue, 26 Sep 2023 14:54:59 +0200 Message-Id: <20230926125502.1127015-2-bigeasy@linutronix.de> In-Reply-To: <20230926125502.1127015-1-bigeasy@linutronix.de> References: <20230926125502.1127015-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230926_055518_403213_0B27C3FE X-CRM114-Status: GOOD ( 12.73 ) 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(). Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Ard Biesheuvel --- 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 7e8773a2d99d0..8d321cdb7ac58 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. @@ -819,7 +847,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 @@ -850,7 +878,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 Tue Sep 26 12:55:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13399232 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 8A4AFE7E630 for ; Tue, 26 Sep 2023 12:55: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=aJezb2e64xkTHp/vMUiunewlzex9SFL+V4JRafXUZ3E=; b=urwuP4TWTPTamp tp7fCPKaZbEbJYA6ROCq4dItWimEgM/xwUdZ9PkJDoq8MaLN0JwNMjoSTcRBmwGdrGUJV09nnON/R w01pmHsv/rSmJagug0n3N2uIUdNBSa2a8X4c1d+VGwsWvbH9BYYp3+VeYgPta5oOY/ohfFCnjdGW/ UzOQQo15W7cO5tFVJ229hQQ820zsTwBL5OprkZBY+OjHbjD0pnFcedieRxLPPW931xAqwdt5vYEbJ 47ua8uhM3phsUp0apznWEODuK7pqhUuwlAUvEOVHcSypdpx3DIi01VftUI/vbA2P+Fa7IkdJ+9jkn 4ZaSUGXkCB0hh4JoAsmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ql7b8-00GPAn-14; Tue, 26 Sep 2023 12:55:30 +0000 Received: from galois.linutronix.de ([193.142.43.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ql7av-00GP7P-2R for linux-arm-kernel@lists.infradead.org; Tue, 26 Sep 2023 12:55:19 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695732914; 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=/2onH70G0qf/Ey+4wPpHydILR3hGaEi4eJDs/I3/2lY=; b=TDRWqHnZ9i66BOzoODrKbFTEvnSJyrsMqXUVMPt6ifcplNYuYeyaJ8mG4JVBYDQx1z5530 lsBS44as9U8ty1xBxWIb79vvRKvcUmihaUIcAkfbhithCMcj1Guj+Xj0bqlRcNzdhXPWJB 3NV83jyCcvYQfj7tkIHascP65l1us8i70P35ujCNF6KtGXlDnxHkqfKMkoualA8YX1RFG7 6A59Ye/4AAKg7zQBJvz8BcdyT+/pP4PuX/DCoWUKEz/rot1s0McLaD7iZ/aEYNqZnHX7GW /CGH20TGhxlhEpmpGL4wsRGXU7MoipRxgDSJ8rH2s+OqWfMCplQMayrbASf11Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695732914; 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=/2onH70G0qf/Ey+4wPpHydILR3hGaEi4eJDs/I3/2lY=; b=orHjIGz16kcVEslZjGy3Ql4uwUeHgDaJ203rIOhut47Tr7hp8KAG/HalCTOqR6/OORAwLh JqrfLVq9ygZKGLDg== To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: ardb@kernel.org, tglx@linutronix.de, Sebastian Andrzej Siewior Subject: [PATCH v3 2/4] ARM: vfp: Use vfp_lock() in vfp_sync_hwstate(). Date: Tue, 26 Sep 2023 14:55:00 +0200 Message-Id: <20230926125502.1127015-3-bigeasy@linutronix.de> In-Reply-To: <20230926125502.1127015-1-bigeasy@linutronix.de> References: <20230926125502.1127015-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230926_055517_934678_EDD11742 X-CRM114-Status: GOOD ( 11.36 ) 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. Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Ard Biesheuvel --- 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 8d321cdb7ac58..3b9360bfc5081 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 Tue Sep 26 12:55:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13399231 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 1F01AE7E631 for ; Tue, 26 Sep 2023 12:55:56 +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=f25GdgzSuN4C8CuSZsJ8eSZU9i8Cch3rC5VgE8l7vkU=; b=JYiP3Lf2IVoumA Ue+hKucRfZR6Fu+tXl2yNbRR5QpqCcxg+lei4L48eYUDj/+FkDI/9Pl7+FidkfZgVgTglFXjg7cAn POACznIO6wfdl2bbcRL0XfIH6l+NrHh+qKKs1sMcj8qGR3GP0VnyjRZaWG+a+GfczKJA+QGxyGFGu jg3bqeE0nHsjqqy0XOBz8TI+1JzqCjZuhR53xhivA74MG2Iwx2WkXER1NANDdUvzmiKN1ULeWRdvH 1sldGqUcJKPsYdkqCh/rp9IhIDWEaP4W/gGi2P5WQi65l1R8OCHnjh8jbDCxlyZUOjXTdlp27HEkA kyhf5FUxCRJik4bhFtPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ql7b7-00GPAX-2f; Tue, 26 Sep 2023 12:55:29 +0000 Received: from galois.linutronix.de ([193.142.43.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ql7av-00GP7f-2R for linux-arm-kernel@lists.infradead.org; Tue, 26 Sep 2023 12:55:19 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695732914; 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=BBRIeUFuVF6Y+zx/7o6b0kuAGMX35N3Zaru0oBh/TdQ=; b=LC8GX/+r7+/GCWAuNowqMDfKFqsVLXKEpsRBZWGbD4Jgyi2HAhhpNzinpBtpeESy+vyuYI N9rH/mgoogMvppnduIWwMmEx40yxsvRFBGTuLstNo8ZfbLPgOmQsDr1T8a8ttRvMd1IH6+ 1iiEjiIgsOaP7S1Sjk1OMWoOa4AkdUfYCHKfn9HEBcBh7LiMSm73TV18dzX9UE2AA9ucix uvmd9cJUY8frNUmU85jlGLBRghhsCdkZ+ZhFM80/Fv9JBt53rJ5UUBRXfLXMZecxIg07dB KaExfrFRIc+MfCkN5KRxY3v/NnvZHT9Qp8Sxm0Uiga0rWQWomsuuQxIunDVtpw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695732914; 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=BBRIeUFuVF6Y+zx/7o6b0kuAGMX35N3Zaru0oBh/TdQ=; b=60uz9ayVTCsUBPzDH9m7ERZjXyDsDwoRIGFgqu34aJoNEVC1dTqmNm8YZohsWQBmXjt2WX NbbZ2s/vvmivAqCw== To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: ardb@kernel.org, tglx@linutronix.de, Sebastian Andrzej Siewior Subject: [PATCH v3 3/4] ARM: vfp: Use vfp_lock() in vfp_support_entry(). Date: Tue, 26 Sep 2023 14:55:01 +0200 Message-Id: <20230926125502.1127015-4-bigeasy@linutronix.de> In-Reply-To: <20230926125502.1127015-1-bigeasy@linutronix.de> References: <20230926125502.1127015-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230926_055517_932299_3073B715 X-CRM114-Status: UNSURE ( 9.28 ) 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. Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Ard Biesheuvel --- 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 3b9360bfc5081..9543f011d0edf 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 Tue Sep 26 12:55:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13399230 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 2BC6AE7E62E for ; Tue, 26 Sep 2023 12:55: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=u/T2KI/zsCU5BE8H4vMxKis++AV7quTCvObHzn+pJAM=; b=r8u3WvOEsddMFk OX77n3m2gQXbO/CbZMVYwKUTZ8kLa5XkkM9zonTNOMooRzLqseIFQClSjOHaMMKPKao4jUN43pJxk UxIFzyLfSXlXBBY+cdzkHLStDnzInJVWNtsbvytWVWwGG/3dA+dw0W4TGcoeG1VesMIvEntWEuApd U+Kk0TObVxuLLfFdCAZojzU9WhOp/hVlcHoH9s47gEUgd9ftv7AEqLjGZHFgYE8FYx38voaI8mTvm iuxWb2lNSNJ8DhJdRBfUKUBNswUpsydEyfB/cx+CxO7JzIdgZWRZdXbO49/N3lqzNIyKWgnLWSYOO hH4EFmX1NizL+i/yzV4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ql7b9-00GPBW-1K; Tue, 26 Sep 2023 12:55:31 +0000 Received: from galois.linutronix.de ([193.142.43.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ql7av-00GP7g-2R for linux-arm-kernel@lists.infradead.org; Tue, 26 Sep 2023 12:55:20 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695732914; 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=bFRH+6ZHyIPY0kdv98ztsysu6Y7ltAnIcqBDY3eIekk=; b=VGhv4Qb/sw+CLrGb2mCdbeotrAv0bFPRb9uOP/HbDKJHOtzaYJfREbrFV4kk1OXBcLlS1f bmEnoaMfCBPOJA1+6SQ/XCZ1yAN7y88SVGW7qEZrQXRsXtKLQ+Ftk6eC0TSCSudOpV8Wgg dyyoomCsLulxKhJtL86842W5G1wj2yNpUQWzoqb8pzGbfN3jmOAn4YbgdSMcxQNIHpa2yC +BPXIIBFis9HaUfNhbueDUr96j3mIi9N1WF5FCymxc13cgkDHsfXTB853Ub7Xx5wHPxuZp g0bd2j3Pzf4XwFXApBsFDFvvL4O5uvccr3X6t63qpoCPLdzdJfjquPOzlXhgSg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695732914; 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=bFRH+6ZHyIPY0kdv98ztsysu6Y7ltAnIcqBDY3eIekk=; b=n3p6JDU80+ujC85j7Z3Wribim1UYqPyZAEgbr1+2uwMGDQMhjuSnW0bgiTxbT/fSwzv8DX b3DtMmtZK7IjDtCw== To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: ardb@kernel.org, tglx@linutronix.de, Sebastian Andrzej Siewior Subject: [PATCH v3 4/4] ARM: vfp: Move sending signals outside of vfp_lock()ed section. Date: Tue, 26 Sep 2023 14:55:02 +0200 Message-Id: <20230926125502.1127015-5-bigeasy@linutronix.de> In-Reply-To: <20230926125502.1127015-1-bigeasy@linutronix.de> References: <20230926125502.1127015-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230926_055518_085626_C1B36F8B 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. Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Ard Biesheuvel --- 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 9543f011d0edf..9fde36fcb80c2 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; }