From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8336C4332F for ; Tue, 27 Dec 2022 14:56:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229801AbiL0O4x (ORCPT ); Tue, 27 Dec 2022 09:56:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbiL0O4w (ORCPT ); Tue, 27 Dec 2022 09:56:52 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 328931005 for ; Tue, 27 Dec 2022 06:56:51 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DFAA0B8106C for ; Tue, 27 Dec 2022 14:56:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AB84C433F0; Tue, 27 Dec 2022 14:56:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672153008; bh=bJ+XHdK7jEWRBA/2KeMxWPYu+OlRSkwMzYqcmBqueCc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MgrHQ2iCh1ZEESHLKpHBiBOZ4hTW9oHQnygLGgHQiLYSHG65T9r1A9ip+LArAlUlz vOaA1ZtufXbHW/vtf3hW5OjIXyXzIwhjgnv/i46mZNP4b3nMQ3PTBgdGAJor8hBNxq 9tV9Br6USc1ukmBXSsgT4/yufbukr1VbYA7G23QiO/0Bo3ChnwPnMtQvEmCBZ8vtL+ mPi9lqCpQ10E/jyIYaJvhwtZIEC1GywKDAZ3jxT6EEnVGUzrvtjvCgWjSllMphB9xQ RSGrtfTTzY+y0a6Z4Z5Ftl2JeDji41iVTdUdmAFP6FU8bwAyXZQ0GTYZBdvmkzHU5h 5GKQf/TN3fnxg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pABNn-0006GC-ID; Tue, 27 Dec 2022 15:56:48 +0100 Date: Tue, 27 Dec 2022 15:56:47 +0100 From: Johan Hovold To: Marek Vasut Cc: linux-serial@vger.kernel.org, Sebastian Andrzej Siewior , Alexandre Torgue , Erwan Le Ray , Greg Kroah-Hartman , Jiri Slaby , Maxime Coquelin , Thomas Gleixner , Valentin Caron , linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com Subject: Re: [PATCH v3] serial: stm32: Merge hard IRQ and threaded IRQ handling into single IRQ handler Message-ID: References: <20221216115338.7150-1-marex@denx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221216115338.7150-1-marex@denx.de> Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org On Fri, Dec 16, 2022 at 12:53:38PM +0100, Marek Vasut wrote: > Requesting an interrupt with IRQF_ONESHOT will run the primary handler > in the hard-IRQ context even in the force-threaded mode. The > force-threaded mode is used by PREEMPT_RT in order to avoid acquiring > sleeping locks (spinlock_t) in hard-IRQ context. This combination > makes it impossible and leads to "sleeping while atomic" warnings. > > Use one interrupt handler for both handlers (primary and secondary) > and drop the IRQF_ONESHOT flag which is not needed. > > Fixes: e359b4411c283 ("serial: stm32: fix threaded interrupt handling") I don't think a Fixes tag is warranted as this is only needed due to this undocumented quirk of PREEMPT_RT. And this should not be backported in any case. > Reviewed-by: Sebastian Andrzej Siewior > Signed-off-by: Marek Vasut > --- > Cc: Alexandre Torgue > Cc: Erwan Le Ray > Cc: Greg Kroah-Hartman > Cc: Jiri Slaby > Cc: Maxime Coquelin > Cc: Sebastian Andrzej Siewior > Cc: Thomas Gleixner > Cc: Valentin Caron > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-stm32@st-md-mailman.stormreply.com > To: linux-serial@vger.kernel.org > --- > V2: - Update patch subject, was: > serial: stm32: Move hard IRQ handling to threaded interrupt context > - Use request_irq() instead, rename the IRQ handler function > V3: - Update the commit message per suggestion from Sebastian > - Add RB from Sebastian > - Add Fixes tag > --- > drivers/tty/serial/stm32-usart.c | 29 +++++++---------------------- > 1 file changed, 7 insertions(+), 22 deletions(-) > > diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c > index dfdbcf092facc..bbbab8dc2bfa9 100644 > --- a/drivers/tty/serial/stm32-usart.c > +++ b/drivers/tty/serial/stm32-usart.c > @@ -752,8 +752,9 @@ static irqreturn_t stm32_usart_interrupt(int irq, void *ptr) > struct tty_port *tport = &port->state->port; > struct stm32_port *stm32_port = to_stm32_port(port); > const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; > - u32 sr; > + unsigned long flags; > unsigned int size; > + u32 sr; > > sr = readl_relaxed(port->membase + ofs->isr); > > @@ -793,27 +794,13 @@ static irqreturn_t stm32_usart_interrupt(int irq, void *ptr) > } > > if ((sr & USART_SR_TXE) && !(stm32_port->tx_ch)) { > - spin_lock(&port->lock); > + spin_lock_irqsave(&port->lock, flags); > stm32_usart_transmit_chars(port); > - spin_unlock(&port->lock); > + spin_unlock_irqrestore(&port->lock, flags); This is not needed as the handler runs with interrupts disabled. > } > > - if (stm32_usart_rx_dma_enabled(port)) > - return IRQ_WAKE_THREAD; > - else > - return IRQ_HANDLED; > -} > - > -static irqreturn_t stm32_usart_threaded_interrupt(int irq, void *ptr) > -{ > - struct uart_port *port = ptr; > - struct tty_port *tport = &port->state->port; > - struct stm32_port *stm32_port = to_stm32_port(port); > - unsigned int size; > - unsigned long flags; > - > /* Receiver timeout irq for DMA RX */ > - if (!stm32_port->throttled) { > + if (stm32_usart_rx_dma_enabled(port) && !stm32_port->throttled) { > spin_lock_irqsave(&port->lock, flags); But you could change this to spin_lock() now. > size = stm32_usart_receive_chars(port, false); > uart_unlock_and_check_sysrq_irqrestore(port, flags); > @@ -1016,10 +1003,8 @@ static int stm32_usart_startup(struct uart_port *port) > u32 val; > int ret; > > - ret = request_threaded_irq(port->irq, stm32_usart_interrupt, > - stm32_usart_threaded_interrupt, > - IRQF_ONESHOT | IRQF_NO_SUSPEND, > - name, port); > + ret = request_irq(port->irq, stm32_usart_interrupt, > + IRQF_NO_SUSPEND, name, port); > if (ret) > return ret; You should also remove /* * Using DMA and threaded handler for the console could lead to * deadlocks. */ if (uart_console(port)) return -ENODEV; from stm32_usart_of_dma_rx_probe() when removing the threaded handler. Johan From mboxrd@z Thu Jan 1 00:00:00 1970 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 05F5DC4332F for ; Tue, 27 Dec 2022 14:57: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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dq5FPHmpIUG2m5B65MY7Q1rXBzSxPB0c+3VxxP2+RkI=; b=gQLALZ1TdOEUp8 pxivmKr1yPeyw1yGLB8Y51eQ42ESJ5z4mqxyUZLw6oHVewtezOuhy6ymrpta6S0Pe+vUyGbL4PURz 38LCSxWyBIuH6eztk2puAkzrgEXa92sIZ41rOijnxN3UY6RqahCMkVgOCV+0pCgH+c91Y9HuCQuxP pFap3pl3IE13xztUhSOvkKuLnKOvQ7zBFKJfUYPX2qyhojhgw+GrzL+afvMfpGmx7CwwCZf4v5z+R /AqYzAILsYQzLT/7w130Nr6vUhNKO1Evxh6jUj3MZLk4Y8qmKB78P6grLFRUEfdyZkQ4J9hzYER68 LtJHGcw0nJm7KwCO/fyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pABNu-00DqNE-8f; Tue, 27 Dec 2022 14:56:54 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pABNq-00DqLT-Bq for linux-arm-kernel@lists.infradead.org; Tue, 27 Dec 2022 14:56:52 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F34DA6116E; Tue, 27 Dec 2022 14:56:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AB84C433F0; Tue, 27 Dec 2022 14:56:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672153008; bh=bJ+XHdK7jEWRBA/2KeMxWPYu+OlRSkwMzYqcmBqueCc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MgrHQ2iCh1ZEESHLKpHBiBOZ4hTW9oHQnygLGgHQiLYSHG65T9r1A9ip+LArAlUlz vOaA1ZtufXbHW/vtf3hW5OjIXyXzIwhjgnv/i46mZNP4b3nMQ3PTBgdGAJor8hBNxq 9tV9Br6USc1ukmBXSsgT4/yufbukr1VbYA7G23QiO/0Bo3ChnwPnMtQvEmCBZ8vtL+ mPi9lqCpQ10E/jyIYaJvhwtZIEC1GywKDAZ3jxT6EEnVGUzrvtjvCgWjSllMphB9xQ RSGrtfTTzY+y0a6Z4Z5Ftl2JeDji41iVTdUdmAFP6FU8bwAyXZQ0GTYZBdvmkzHU5h 5GKQf/TN3fnxg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pABNn-0006GC-ID; Tue, 27 Dec 2022 15:56:48 +0100 Date: Tue, 27 Dec 2022 15:56:47 +0100 From: Johan Hovold To: Marek Vasut Cc: linux-serial@vger.kernel.org, Sebastian Andrzej Siewior , Alexandre Torgue , Erwan Le Ray , Greg Kroah-Hartman , Jiri Slaby , Maxime Coquelin , Thomas Gleixner , Valentin Caron , linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com Subject: Re: [PATCH v3] serial: stm32: Merge hard IRQ and threaded IRQ handling into single IRQ handler Message-ID: References: <20221216115338.7150-1-marex@denx.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221216115338.7150-1-marex@denx.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221227_065650_523040_DA4B2F50 X-CRM114-Status: GOOD ( 30.23 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Dec 16, 2022 at 12:53:38PM +0100, Marek Vasut wrote: > Requesting an interrupt with IRQF_ONESHOT will run the primary handler > in the hard-IRQ context even in the force-threaded mode. The > force-threaded mode is used by PREEMPT_RT in order to avoid acquiring > sleeping locks (spinlock_t) in hard-IRQ context. This combination > makes it impossible and leads to "sleeping while atomic" warnings. > > Use one interrupt handler for both handlers (primary and secondary) > and drop the IRQF_ONESHOT flag which is not needed. > > Fixes: e359b4411c283 ("serial: stm32: fix threaded interrupt handling") I don't think a Fixes tag is warranted as this is only needed due to this undocumented quirk of PREEMPT_RT. And this should not be backported in any case. > Reviewed-by: Sebastian Andrzej Siewior > Signed-off-by: Marek Vasut > --- > Cc: Alexandre Torgue > Cc: Erwan Le Ray > Cc: Greg Kroah-Hartman > Cc: Jiri Slaby > Cc: Maxime Coquelin > Cc: Sebastian Andrzej Siewior > Cc: Thomas Gleixner > Cc: Valentin Caron > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-stm32@st-md-mailman.stormreply.com > To: linux-serial@vger.kernel.org > --- > V2: - Update patch subject, was: > serial: stm32: Move hard IRQ handling to threaded interrupt context > - Use request_irq() instead, rename the IRQ handler function > V3: - Update the commit message per suggestion from Sebastian > - Add RB from Sebastian > - Add Fixes tag > --- > drivers/tty/serial/stm32-usart.c | 29 +++++++---------------------- > 1 file changed, 7 insertions(+), 22 deletions(-) > > diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c > index dfdbcf092facc..bbbab8dc2bfa9 100644 > --- a/drivers/tty/serial/stm32-usart.c > +++ b/drivers/tty/serial/stm32-usart.c > @@ -752,8 +752,9 @@ static irqreturn_t stm32_usart_interrupt(int irq, void *ptr) > struct tty_port *tport = &port->state->port; > struct stm32_port *stm32_port = to_stm32_port(port); > const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; > - u32 sr; > + unsigned long flags; > unsigned int size; > + u32 sr; > > sr = readl_relaxed(port->membase + ofs->isr); > > @@ -793,27 +794,13 @@ static irqreturn_t stm32_usart_interrupt(int irq, void *ptr) > } > > if ((sr & USART_SR_TXE) && !(stm32_port->tx_ch)) { > - spin_lock(&port->lock); > + spin_lock_irqsave(&port->lock, flags); > stm32_usart_transmit_chars(port); > - spin_unlock(&port->lock); > + spin_unlock_irqrestore(&port->lock, flags); This is not needed as the handler runs with interrupts disabled. > } > > - if (stm32_usart_rx_dma_enabled(port)) > - return IRQ_WAKE_THREAD; > - else > - return IRQ_HANDLED; > -} > - > -static irqreturn_t stm32_usart_threaded_interrupt(int irq, void *ptr) > -{ > - struct uart_port *port = ptr; > - struct tty_port *tport = &port->state->port; > - struct stm32_port *stm32_port = to_stm32_port(port); > - unsigned int size; > - unsigned long flags; > - > /* Receiver timeout irq for DMA RX */ > - if (!stm32_port->throttled) { > + if (stm32_usart_rx_dma_enabled(port) && !stm32_port->throttled) { > spin_lock_irqsave(&port->lock, flags); But you could change this to spin_lock() now. > size = stm32_usart_receive_chars(port, false); > uart_unlock_and_check_sysrq_irqrestore(port, flags); > @@ -1016,10 +1003,8 @@ static int stm32_usart_startup(struct uart_port *port) > u32 val; > int ret; > > - ret = request_threaded_irq(port->irq, stm32_usart_interrupt, > - stm32_usart_threaded_interrupt, > - IRQF_ONESHOT | IRQF_NO_SUSPEND, > - name, port); > + ret = request_irq(port->irq, stm32_usart_interrupt, > + IRQF_NO_SUSPEND, name, port); > if (ret) > return ret; You should also remove /* * Using DMA and threaded handler for the console could lead to * deadlocks. */ if (uart_console(port)) return -ENODEV; from stm32_usart_of_dma_rx_probe() when removing the threaded handler. Johan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel