From patchwork Mon Jul 1 10:56:53 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: 13717902 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 A4D32C2BD09 for ; Mon, 1 Jul 2024 11:04:05 +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:References:In-Reply-To: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:List-Owner; bh=zEGdA9t+YC6ECkr5w6/6t9cS+dhhNbOxtOrmytTbblk=; b=11ObbcTx0JJar7THjq63cSlqO8 /x9f3MHEQRzsbfyhouQWZuBBUDJtoCyl6jVqroIryr9M4LShQruRApFjxvOuq0pfBJxfnH/xFC/EF ww4OTWiPMec+v6cJRjpYG6H/B5ZjTymQJKpFcCTpVkCtKkQhOZWhpKkiGlR466wi1Fkg/Yic4xlgD yHRH/hY+i8RXLOCLI5bKGTAaYk04spxgakomFRgfSb4fztYmxEQiAZzRJCOOuT+lU6Uobx29Hqyxq D8ikoHk9D07fnwlpuGXojJRXY3u6Qd2CTlEmRIRnMgbkOKMpx21/qpdbEfvQ5t2S5Pj13utLmFKUI cNv79SgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOEp6-00000002pdT-3udz; Mon, 01 Jul 2024 11:03:53 +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 1sOEom-00000002pYM-2xa5 for linux-arm-kernel@lists.infradead.org; Mon, 01 Jul 2024 11:03:36 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719831811; 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=zEGdA9t+YC6ECkr5w6/6t9cS+dhhNbOxtOrmytTbblk=; b=E7ZG+uc/LET+c76kAXr6CXEBkX9Z/HreEVnt4pqzewibHEwCZcJ+WmHLBG5DG/qwrL1gFl GJfZuSdcsyv91YAGGGzKt/HaalpE4kiaWmSCG/Ha5UAhNcSmFbejdbLTP9V7lTBjo7ztSk GgL1qWXeEYJ3u5FtNfjRuXy8Ee3w6DR8P3tuJkwTIoBpA8MRmJ6tYo5N0y94B42W5JCxI8 Cc3h+8FAu2UvzNlRy7BQnUi04JHit14S4BJft9MD36HTrwedAPyOcFRNX94uCChWxXPSTm EAeuZ71s/KhR5YxJkdCyGVrgX7HR7izGPODhNebQvMp5zMtzVSYIIlMQ/vp0gQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719831811; 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=zEGdA9t+YC6ECkr5w6/6t9cS+dhhNbOxtOrmytTbblk=; b=pfYa7lKUUh+NylJBSXEkVokZqpbeNXcQQiGRG2vWZf5ZeFo03g3hK3ClcZQzvuSerCmVHM ipH0yoWIsacGGvCA== To: linux-arm-kernel@lists.infradead.org Cc: Arnd Bergmann , Russell King , Thomas Gleixner , Sebastian Andrzej Siewior , Ard Biesheuvel Subject: [PATCH v6 1/4] ARM: vfp: Provide vfp_state_hold() for VFP locking. Date: Mon, 1 Jul 2024 12:56:53 +0200 Message-ID: <20240701110317.99631-2-bigeasy@linutronix.de> In-Reply-To: <20240701110317.99631-1-bigeasy@linutronix.de> References: <20240701110317.99631-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240701_040332_920273_4D7DF430 X-CRM114-Status: GOOD ( 13.71 ) 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_state_hold() 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..63de164c7fc7b 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_state_release() 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_state_hold(void) +{ + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) + local_bh_disable(); + else + preempt_disable(); +} + +static void vfp_state_release(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_state_hold(); /* * 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_state_release(); } EXPORT_SYMBOL(kernel_neon_end); From patchwork Mon Jul 1 10:56:54 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: 13717905 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 8B7A7C2BD09 for ; Mon, 1 Jul 2024 11:04:27 +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:References:In-Reply-To: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:List-Owner; bh=s6GnQ90TAizPCumEOLD6neigcNHuWHXShBrqIm6g/lI=; b=FX3vOGXOPO6/MEAk7TvIbDEZUq hxmi0EcoDrenrmWieZl7HI1ezLGtqZUhWwwAUQPwDmkkEigBvt9qcLloAIgYi6/nzNqaIOBO5pcNh j6vkoJwI8zfyuqWSc7KwoA3sUKnNLlykQRvT8NVJi4omKJ9Sv5RMErFiaCUSTvYTS7q4ypcIDgrlt 0AGR9P4eM3dIWgDUhqjOA19Bc+WN6IqsbtuSLlgldY5K86TzoI7lq7thTSFt01f+riczb9bRelBX0 0NK738mny0qqeR0K1zzWUoCngjnNANA3+B14/0BDwWGyaawKZ8oPp8U5abKL6XgNbjGXIM4hYohoV t8y9Sk6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOEpU-00000002pne-3dxV; Mon, 01 Jul 2024 11:04:16 +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 1sOEom-00000002pYP-43n6 for linux-arm-kernel@lists.infradead.org; Mon, 01 Jul 2024 11:03:41 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719831811; 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=s6GnQ90TAizPCumEOLD6neigcNHuWHXShBrqIm6g/lI=; b=S0SGR0mT/Ro2AzfDVZDBN88zQHeqcKROo8w0uUlWTSh6KjCCAlo1rX+ZToenkZTJX+nSx+ XYyZQ5kNE1a22zxgH6OvgV/Y0c8x6wUAKixNcb/T6U+2vF7WJPCMQ9ZTyyeyN8iCuOnzoF Sfy5zcSXfuRIQh3fgUt1wWR29GXdOriyJmdpMCrn4EDN6J3xHbgj0hm3Xc9MHHNsSDL6Bu Mxp8b3gcs93sAPnQ/3f/LxInRxdq8eDJcG5wrv8aqjy+rZAdwS2PMKl4PucNKpV+xf3mpb l2Rd6Rhu3EQXT2iKKwDHe7d8xkU0w5RHpPCshu6P6JOZEXevN8CawgJaIe8BSA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719831811; 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=s6GnQ90TAizPCumEOLD6neigcNHuWHXShBrqIm6g/lI=; b=GPSM6WYG9lndGGrhsnBKauQfSLBYHqXp9Db0VJ22fvZOhRpkrcwJ7LKH5fVbFg/lX+e7t4 BbMlCqxhwYlUb/BQ== To: linux-arm-kernel@lists.infradead.org Cc: Arnd Bergmann , Russell King , Thomas Gleixner , Sebastian Andrzej Siewior , Ard Biesheuvel Subject: [PATCH v6 2/4] ARM: vfp: Use vfp_state_hold() in vfp_sync_hwstate(). Date: Mon, 1 Jul 2024 12:56:54 +0200 Message-ID: <20240701110317.99631-3-bigeasy@linutronix.de> In-Reply-To: <20240701110317.99631-1-bigeasy@linutronix.de> References: <20240701110317.99631-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240701_040333_174585_DE136A7F X-CRM114-Status: GOOD ( 12.07 ) 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_state_hold() 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 63de164c7fc7b..1726db0500760 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_state_hold(); - 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_state_release(); } /* Ensure that the thread reloads the hardware VFP state on the next use. */ From patchwork Mon Jul 1 10:56:55 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: 13717904 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 DCA52C30659 for ; Mon, 1 Jul 2024 11:04:21 +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:References:In-Reply-To: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:List-Owner; bh=u7q2gwGmp9PLpG/AVWR2W/15Jj9bUM2hgcZVmvsL1Ro=; b=IVNKrC7o7RaqW/K+bgjpCUzSej lPREpW2bTDHuaI+itX5WItyUatr5roQUhdOIW+si/KBgP5e9kS5RypjZcooCPm+LPzjDTUWwki5jh /wtBMeFAbkcp2z5YFQOi8NYq3FVKiFa1PrO20ni5DQBA7chIpjf1S72Tkj+I1EApv4pMxF9VLwj1K yup65cTjHsYzMhhZTD2vNysfo5B92KWnbaDd3oV0gftevV+a0ZgDXaBND5PF3ihY7VyU0Js1TfJd6 +6H2+WsYnATnrdTKYz2G7jm1CMYkWiMA5H+W0GP5pZ7WKdgZuCSlXIqnDiUZz/I2BNB+wRYvBhXTR 9gvmMjow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOEpN-00000002pkM-0DIY; Mon, 01 Jul 2024 11:04:09 +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 1sOEon-00000002pYZ-15vp for linux-arm-kernel@lists.infradead.org; Mon, 01 Jul 2024 11:03:39 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719831811; 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=u7q2gwGmp9PLpG/AVWR2W/15Jj9bUM2hgcZVmvsL1Ro=; b=D7zrgBGJbI0nmVJr0i5WJ1fEknlzJAt3egiEIFdjKxyEHrPr+HHCSKsvjhWp7yWNsNDMup m2qPxJWwRgGvdbALZykLUvfw+FLnBeLgz1eBxHDz2zr1YsaRNaLWcmupaYq5bEnG4Ww66W VpY6vTadSmf70ep3+pSsULL0u0wDlDO5QhEQk+rn/yLJDX2t2WBG4vBTG4uXe0yIfOUkN2 Sk3DFDNOS1JgjmfaDilya1ib8DXJd0g5r2Mf7FE1qDd2OTKef+ib+J/qpmmOO8rTzEd8Yo yDOD2mxWFdfULGRyysauDk1VK598fkYkLAUChkGZB732zVcJwYFT8gonyYaxWg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719831811; 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=u7q2gwGmp9PLpG/AVWR2W/15Jj9bUM2hgcZVmvsL1Ro=; b=qJJcXpaK2b8tvCMglzhXkvy6/HkvtXPgQMpYXKw0qSGOkkmexJaPz6QBHccB088+ichKO8 uAPN6wGzh3xlD0Cw== To: linux-arm-kernel@lists.infradead.org Cc: Arnd Bergmann , Russell King , Thomas Gleixner , Sebastian Andrzej Siewior , Ard Biesheuvel Subject: [PATCH v6 3/4] ARM: vfp: Use vfp_state_hold() in vfp_support_entry(). Date: Mon, 1 Jul 2024 12:56:55 +0200 Message-ID: <20240701110317.99631-4-bigeasy@linutronix.de> In-Reply-To: <20240701110317.99631-1-bigeasy@linutronix.de> References: <20240701110317.99631-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240701_040333_480163_CFA44D6A X-CRM114-Status: UNSURE ( 9.96 ) 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_state_hold() 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 1726db0500760..28dafae7758b8 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_state_hold(); 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_state_release(); return -ENOEXEC; } fpexc |= FPEXC_DEX; @@ -797,7 +797,7 @@ bounce: regs->ARM_pc += 4; VFP_bounce(trigger, fpexc, regs); } - local_bh_enable(); + vfp_state_release(); return 0; } From patchwork Mon Jul 1 10:56:56 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: 13717903 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 54133C30653 for ; Mon, 1 Jul 2024 11:04:14 +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:References:In-Reply-To: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:List-Owner; bh=O3gsIZXWFKDJfK8qiwOP19hnqVbTAclkcj2XykKQHB0=; b=Ck35SUDmeoYeAZzBnH/3+1FzOh 4gRbKqfhfS7F0+InUCjb0FIFd5PT2v7nkmVIU7QO9E4ZmTRC8IT7RbJUxvxcFKqYdvEmw+/vRISDv ZyYfvmswRjK+6BPyLMS2TxptpHgjI895DsvFUMrWBoA2GkmIOm5cmF6YDEIJYQ9tVJ/Fizzo5bOQL YcQZf/VWWyT+nXAGo4bjq/8GyDdcUCKpMVVvRPhygerlIG9RmNkALJo6oSjCC3+GyvIQBRcOYzAFi 6jy1d2mJ1ZRrv1otGGTuOb3aot1iScFb+X0Wh/SKiT5ebXMitWEQt7ev5qdFnFtnZpafwtECciGaO 3tTUNS1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOEpF-00000002pho-1AxG; Mon, 01 Jul 2024 11:04:01 +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 1sOEon-00000002pYa-1xfy for linux-arm-kernel@lists.infradead.org; Mon, 01 Jul 2024 11:03:40 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719831812; 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=O3gsIZXWFKDJfK8qiwOP19hnqVbTAclkcj2XykKQHB0=; b=3KguhDufaMY6qYDJ45mvokp4dnSTGJ7jocSBkGSNvx+NAyt2AFLB32ylhmHvevbl2+yq7n jzGxKPBubS4TBTgLx7Zmg5qU+F/HN1kgUMiy/ipAhWGfnDkIQdTuL9/PanwNHqmMmo42IO di3C4SmgTCqYuDdH5bev8AjUuZnx/s+SLJ0xRcdi6IQyUk3vk3u36velxapuiCxqYUQsS0 DCMYUYDMGOK15njO6Vgt1nmIR9K9R+9utPPIV6DGRkiV7tjNF876yYqAkwBAWHIl5ZSZ0z DGakQnKs4wIZHKumRjdlzJ9VvVqjffUMoBJ4GAOLj00qW3N+nNHtf/OWt3Fymg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719831812; 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=O3gsIZXWFKDJfK8qiwOP19hnqVbTAclkcj2XykKQHB0=; b=CLrQDrN6d7s6cnx2mf13AObMwQyTY5Gq5KPv8OCuL0KEE1VBHAOh5Cnc7j6ur/x6w4YqSD +osNmMPtC61Bn0Cg== To: linux-arm-kernel@lists.infradead.org Cc: Arnd Bergmann , Russell King , Thomas Gleixner , Sebastian Andrzej Siewior , Ard Biesheuvel Subject: [PATCH v6 4/4] ARM: vfp: Move sending signals outside of vfp_state_hold()ed section. Date: Mon, 1 Jul 2024 12:56:56 +0200 Message-ID: <20240701110317.99631-5-bigeasy@linutronix.de> In-Reply-To: <20240701110317.99631-1-bigeasy@linutronix.de> References: <20240701110317.99631-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240701_040333_816684_3451E438 X-CRM114-Status: GOOD ( 14.06 ) 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_state_hold() 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 28dafae7758b8..d44867fc0c5ee 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_state_release(); + 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_state_release(); } 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_state_release() */ VFP_bounce(trigger, fpexc, regs); } - vfp_state_release(); return 0; }