From patchwork Fri Jun 28 13:46:16 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: 13716168 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 8F5CDC3064D for ; Fri, 28 Jun 2024 13:47:32 +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=GnSyvEIlj7F9IRVbgoytJSD4TReYwLjwz36HympkhFM=; b=YuXyogosLdQV7q/iVfsTjw+f/2 e/CAbDTj2l37GKlq0D5k0xFA/EBcOkBJaXA6DeI9P1q6W5XBybkQ/Niq+XPizqUC09zBo2/BS1kOp NkGoBeD1esJGX5LoKsaOm7gCiBIGKxjqBNN/k5zwEopY9HeJk7AiX+VZxSI48SvR2Eb0f/LtAG5nk I8AydcMxD6gb/jZw7LIbd+GD8RJfnqrPAr6sPOIep/SH6uVp8CD6g8UUBXvN/woQB/4IUzrc22rrX feAHmD4NmktGcgXEa4gPuXLgsGOvbm8L2QhnIbgufVGRY2vcA+bn4u6szoW+8BH6QbnCgTu2wxy3q M0q1/D4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sNBwe-0000000DrTW-2kFn; Fri, 28 Jun 2024 13:47:20 +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 1sNBwG-0000000DrNg-3gxT for linux-arm-kernel@lists.infradead.org; Fri, 28 Jun 2024 13:47:02 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719582414; 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=GnSyvEIlj7F9IRVbgoytJSD4TReYwLjwz36HympkhFM=; b=wRgy+ei+R+OkG7SzBN94bu0IF7iyUfw0g2ZBpP6VL2KWb/eYDYaB2Xodq+V6k2vC7ago7R dlV2Pz40r6J2DAjygBKhHTh+os106S5J6r/ryCAMgdJDi0La9MZw+CwPTv3yp1wtxgfln6 LzilQeCT8qBlHrelRgkgAXaVcfs0/ELCZuWVLFU9TuxDwEuZzBUHkP/OWwBy5GXWfQGNul KyzUXuhX4r8xNwNdJr9z5FuqJu7E8jqTw2aISH0eWBQX8fdpaz3jyh+IpodghqQSbiHCdK yReztxZUDJ4zZfri0P1dEgZmznHXIBhr0eHiVAAkG5T++HP/60FPS1Nk9X/cjA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719582414; 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=GnSyvEIlj7F9IRVbgoytJSD4TReYwLjwz36HympkhFM=; b=6ZPSXdSjxl5uCUDNGjstbfx8anGJ9WhhuxMjD115GAMk7iMu98KqhOUaZ1j+i/DCe825Vn LBUYz2oR+0J8tkBA== To: linux-arm-kernel@lists.infradead.org Cc: Arnd Bergmann , Russell King , Thomas Gleixner , Sebastian Andrzej Siewior , Ard Biesheuvel Subject: [PATCH v5 1/4] ARM: vfp: Provide vfp_lock() for VFP locking. Date: Fri, 28 Jun 2024 15:46:16 +0200 Message-ID: <20240628134648.1852041-2-bigeasy@linutronix.de> In-Reply-To: <20240628134648.1852041-1-bigeasy@linutronix.de> References: <20240628134648.1852041-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240628_064657_455585_8E149CFF X-CRM114-Status: GOOD ( 13.60 ) 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 Jun 28 13:46:17 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: 13716169 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 2DB75C3064D for ; Fri, 28 Jun 2024 13:47:38 +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=J2uwro0USi9yPDkujdmIPQNGApewYYsXCGLKq5MRblc=; b=4gDjFaJg3ULMXA7MisUlboWSQv YDBAM1Pm+v7d5LR3hyM3W9usISb5teQoU4NylvG+9dABkzifUspQPNOxAdhJAz6D1bHCh01ruJS4F S/swSkokD9MEF6pJyU2kh7TYr0DlSikGg8bYRHj3TAi+o5WNuWlePgajvF74n0F0XGo1caqQOwYHd 4vZl1WLKaKPFfCB/R1F8Jk50QFHQDwZGNKUbj/uaFp0IeKUQp6CVyiP4w7TP7pPZCE302MJVpwu7G NvmnxAaVePsbxwzBx/H+azZCtkFFbFiOo4TeCpE5Nd4EXrvunfYN4CKmoCMFerefyUT3ap7/qQdKH 2uETW1eg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sNBwm-0000000DrXK-14t8; Fri, 28 Jun 2024 13:47:28 +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 1sNBwG-0000000DrNj-2dxJ for linux-arm-kernel@lists.infradead.org; Fri, 28 Jun 2024 13:47:03 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719582414; 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=J2uwro0USi9yPDkujdmIPQNGApewYYsXCGLKq5MRblc=; b=Htjx2RH+Xjjt/8sO2DqbpRfDZ4sABAdpG1cxwbTmsjPcNZ0TU5yWpPyjKiXevu65V0GxHK 6ZB70ZPCQOSlz2FMKrCvS2adBxQcxepIdtYvCz/QPAYYdKqSJxC294HIyfqgl3jNfv3hEh 74eOZnF6Acabjc4LYFzThWNrHNvBpyB5bCFeQmIdrFUtSpl07AV0U66wDFG1JnLylbDApC eUoZPXFtPhOi8kuGBShD5YxFBLrInBbNTgQhCia/KbifF5J8yN4KmShAKZdn/VtbN+RwoK e+GRSdZjEBnn8LTofP0j7S0nfJ6Tehw6UuTju2RfMxnDnT9o1X4G6GGJPs/YmQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719582414; 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=J2uwro0USi9yPDkujdmIPQNGApewYYsXCGLKq5MRblc=; b=+R9ga/1rCUCxEI4oNdf+kUVnsPb3Nnqsx2P94UMS3GKqeDJDYRTE8tdGYbOp8QeAqRdib8 PheKnPwNgUMqBvBg== To: linux-arm-kernel@lists.infradead.org Cc: Arnd Bergmann , Russell King , Thomas Gleixner , Sebastian Andrzej Siewior , Ard Biesheuvel Subject: [PATCH v5 2/4] ARM: vfp: Use vfp_lock() in vfp_sync_hwstate(). Date: Fri, 28 Jun 2024 15:46:17 +0200 Message-ID: <20240628134648.1852041-3-bigeasy@linutronix.de> In-Reply-To: <20240628134648.1852041-1-bigeasy@linutronix.de> References: <20240628134648.1852041-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240628_064656_837194_140847C8 X-CRM114-Status: GOOD ( 12.01 ) 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 Jun 28 13:46:18 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: 13716166 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 1F000C3064D for ; Fri, 28 Jun 2024 13:47: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=R6zagUyiu6p1WAPSFjGIb1VsjXTve3s0N1GUFRou7gI=; b=NUWRffZwcdU65lzekvH5GTOnmu skrRHajj8AvR5XQI947KHIBC/jT0E3rraFdSp/9xV9w7byumkOvKHa2NkD13Md/nAr54gZQ3JQ+ag cUrsV90Uc/LhfLeZCdMbGlbrMdk+6AdvAj9UQIqwVvVjsAI02W5hHeQiAzW9aUYZQ9Ok5aXG/GX8L Ii0foGHnnPJLJDDdfSuZiVq+ODm/g6dyrG3ewy3OVbRH8oyYR4TPDXqbvaOXqk1i7qPkoMvT5UUlC f9xf8wmWZ0yN0jJgo6gQXIqdWR48/iXoP5EhWZAQ1mR9MynLfVn9B8cDVNcigF26ZAsAUN/mQlpaW pYBWQPFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sNBwR-0000000DrRJ-3CNk; Fri, 28 Jun 2024 13:47:07 +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 1sNBwG-0000000DrNn-2e2Z for linux-arm-kernel@lists.infradead.org; Fri, 28 Jun 2024 13:46:59 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719582415; 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=R6zagUyiu6p1WAPSFjGIb1VsjXTve3s0N1GUFRou7gI=; b=gesk+2hoLvaS2wwRFf+Vv4TxBaIKyZ3rTdDXo2JTtSp8+24Q0VNdw/u75c00ZcPcWs4iL2 wt1xNjtMaxnM6L3cjZszvIMuphAJYMAvfYodKbdvKLFs7mtOlh6D42Ut1WeGFqz7TYtQUe YiVvdcMFe4G+1HSqDXhwm9+92OzTxjCuiT0uGpi93v2BRSIiwwq9Gku6uGBvlcneMh4AVY Sb5v61w2vaB+qykkcFnKP61I3T4PkUQWip1HcrEcIkLlVkrFua5w3k2QobMTONclnXwAG6 vLBk4WxzlDtSsQ8rs1bNAZ8RBiMU5D2x7l8PjrMyo6E1eOMB3DoLIniZ3veqwA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719582415; 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=R6zagUyiu6p1WAPSFjGIb1VsjXTve3s0N1GUFRou7gI=; b=rmYyJHIWSdLtiCLpIEBMQKFVcC6W7tTq0OhCJR/3SHtWNsop2YFkdE71O86+Ta8/ssWOtu ndQEj6gmoBebG7CQ== To: linux-arm-kernel@lists.infradead.org Cc: Arnd Bergmann , Russell King , Thomas Gleixner , Sebastian Andrzej Siewior , Ard Biesheuvel Subject: [PATCH v5 3/4] ARM: vfp: Use vfp_lock() in vfp_support_entry(). Date: Fri, 28 Jun 2024 15:46:18 +0200 Message-ID: <20240628134648.1852041-4-bigeasy@linutronix.de> In-Reply-To: <20240628134648.1852041-1-bigeasy@linutronix.de> References: <20240628134648.1852041-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240628_064656_837194_0EC29324 X-CRM114-Status: UNSURE ( 9.90 ) 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 Jun 28 13:46:19 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: 13716170 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 1FBA0C3064D for ; Fri, 28 Jun 2024 13:47:47 +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=sM38sOmfIdCFFYyDvNpvpUuwmvEwtYEx5FxOYUTWG5U=; b=SPFYBbItgoubac/hQqXx63EIRC wEoU0Fe3k3bAOGfzBbGUGwao87PakFzp2oiJgBSzwA7FA0ilcthOw/uyyEr3+Z54gFp9Zj2DCfov/ hV6lHJg9D/0KRAl2486pjFRnFDCnkm7WsmPfpB+Qhg8LVA9cnleL/iouuXPVZc+nJzQJ221Yvutln aCdCES12UGKQ+uO25EB/T6DmttfinGAYR1mYJnU+wuz5lorYDedzvC0vsIfQsVoZ0NcjHTpdm3UiB OpjAZI6FubotZLifPRuloSp4t9bticuLhnK0lYZqhLd2RKi7OEjc0bqbciiT1OP5XLQko1k1Nj1WO YZsFih7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sNBwt-0000000DrcJ-40Od; Fri, 28 Jun 2024 13:47:35 +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 1sNBwG-0000000DrNo-3i2K for linux-arm-kernel@lists.infradead.org; Fri, 28 Jun 2024 13:47:03 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719582415; 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=sM38sOmfIdCFFYyDvNpvpUuwmvEwtYEx5FxOYUTWG5U=; b=Teqlhws+geRqJFQ0r3DKmZEiLAB8JVi7eFHX90lyuLf8xwlBzgAtuM4Ac/4U7lKgts/su5 unbKOPebFa7YdBvuf6M2gg0SS8DKjS04GiZAuMyp9rhQYFpOSfI4uOJJ5PHUQ4qtmE95W6 QHI1p69Kka++spLZvHn3rziaMaqn6/9cXDU94n4rJxsrYYkVsdxp95AXFJbLMSbd7Zi5v4 q6/71nnp5uMnTmIEjicAWSN7DhEufcWAiFOunvvL4iVu3bjd5+ulRozrk/4ANlZipXb3I3 pThBY1vggt274rqUIKVgprGYRU4AbE2q4GhntkTqi1Q0Xf1y0YcdRvp2++222A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719582415; 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=sM38sOmfIdCFFYyDvNpvpUuwmvEwtYEx5FxOYUTWG5U=; b=UDah1GXViFyq6V5mimxXluqkpKKS5ZPf3cavzIUGvOBQtAkcFzyROfH5zoVBjHletetDY+ acQv1mo5GzUBZDCA== To: linux-arm-kernel@lists.infradead.org Cc: Arnd Bergmann , Russell King , Thomas Gleixner , Sebastian Andrzej Siewior , Ard Biesheuvel Subject: [PATCH v5 4/4] ARM: vfp: Move sending signals outside of vfp_lock()ed section. Date: Fri, 28 Jun 2024 15:46:19 +0200 Message-ID: <20240628134648.1852041-5-bigeasy@linutronix.de> In-Reply-To: <20240628134648.1852041-1-bigeasy@linutronix.de> References: <20240628134648.1852041-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240628_064657_483506_B6168FB7 X-CRM114-Status: GOOD ( 14.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_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; }