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 X-Spam-Level: X-Spam-Status: No, score=-6.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B03B2C433E0 for ; Tue, 16 Mar 2021 09:57:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79B2661606 for ; Tue, 16 Mar 2021 09:57:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236049AbhCPJ5I (ORCPT ); Tue, 16 Mar 2021 05:57:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:50768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236480AbhCPJ4o (ORCPT ); Tue, 16 Mar 2021 05:56:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CBAD665014; Tue, 16 Mar 2021 09:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615888603; bh=VZtm7TSm8SzD7rqru+ra4hRXldt8i3ssgmXztshpEgA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YLqiHjh4YLI55r4/HmzYiPyoGVqrBh0rM8DG4WoZaSI+TH2KpSaCyH6jmC6+pp4XZ EAf9FImMvb3TI7Jw5iZGA/9WdRHTESg53CzDcxzD7ssQzk2S17FMJipTbR8cq0muYl rsbtApe/1UYMj1DNbDGjsj7jQWhu9JyUbV1MVMhiAqfXtJ1DXyvsmkHiejZCgMT4n4 bIJ8LTykBSwiN8p5qmGfDC/JeXWvHwZW08JAfmFJgrOWltqQldMVFYMmJ6+bb8Sx/1 NazFbM/dcO9FgvDXx9VHa6LKTOfbsYaZV/+Pp3BayS1EBcuAFn5cf4L6C01AOlbSHw pXCCNyERqxH8A== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lM6Ra-0000aJ-QE; Tue, 16 Mar 2021 10:56:55 +0100 Date: Tue, 16 Mar 2021 10:56:54 +0100 From: Johan Hovold To: Krzysztof Kozlowski Cc: Greg Kroah-Hartman , Jiri Slaby , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, marcan@marcan.st, arnd@kernel.org, Andy Shevchenko Subject: Re: [PATCH] tty: serial: samsung_tty: remove spinlock flags in interrupt handlers Message-ID: References: <20210315181212.113217-1-krzysztof.kozlowski@canonical.com> <7f348e4c-3051-13cf-d461-eeda0ef53fdd@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7f348e4c-3051-13cf-d461-eeda0ef53fdd@canonical.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org On Tue, Mar 16, 2021 at 10:47:53AM +0100, Krzysztof Kozlowski wrote: > On 16/03/2021 10:02, Johan Hovold wrote: > > On Mon, Mar 15, 2021 at 07:12:12PM +0100, Krzysztof Kozlowski wrote: > >> Since interrupt handler is called with disabled local interrupts, there > >> is no need to use the spinlock primitives disabling interrupts as well. > > > > This isn't generally true due to "threadirqs" and that can lead to > > deadlocks if the console code is called from hard irq context. > > > > Now, this is *not* the case for this particular driver since it doesn't > > even bother to take the port lock in console_write(). That should > > probably be fixed instead. > > > > See https://lore.kernel.org/r/X7kviiRwuxvPxC8O@localhost. > > Thanks for the link, quite interesting! For one type of device we have > two interrupts (RX and TX) so I guess it's a valid point/risk. However > let me try to understand it more. > > Assuming we had only one interrupt line, how this interrupt handler with > threadirqs could be called from hardirq context? No, it's console_write() which can end up being called in hard irq context and if that path takes the port lock after the now threaded interrupt handler has been preempted you have a deadlock. > You wrote there: > > For console drivers this can even happen for the same interrupt as the > > generic interrupt code can call printk(), and so can any other handler > > that isn't threaded (e.g. hrtimers or explicit IRQF_NO_THREAD). > > However I replaced here only interrupt handler's spin lock to non-irq. > This code path will be executed only when interrupt is masked therefore > for one interrupt line there is *no possibility of*: > > -> s3c64xx_serial_handle_irq > - interrupts are masked > - s3c24xx_serial_tx_irq > - spin_lock() > -> hrtimers or other IRQF_NO_THREAD > - console_write() or something > - s3c64xx_serial_handle_irq You don't end up in s3c64xx_serial_handle_irq() here. It's just that console_write() (typically) takes the port lock which is already held by the preempted s3c24xx_serial_tx_irq(). > - s3c24xx_serial_tx_irq > - spin_lock() 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 X-Spam-Level: X-Spam-Status: No, score=-4.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BC90C433E0 for ; Tue, 16 Mar 2021 09:58:13 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C71F161606 for ; Tue, 16 Mar 2021 09:58:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C71F161606 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=gLjfkfZW/1oCA+Oruz86sbpUAaw6s6E7/LqYIUyWpJs=; b=iBhwy3S3lzSks9LRwza15uGJl 1cFAPwiVhaw/nSXnGZ5BQ8lkcH2ObVWVr3lY7gRtohxSAv6/b5/UVsyusloCe2wheD+kC6x7GqkEU CSTXrrqA73VcDwxZya5oVzw5p2QKEzlmthvqCj4fmlxNah9CifGPHMNyEo3qilaNX7ZDWgDtUUGKW t8t6ip7z2bs6bZfQI6OseLy79nZNbWZK/4sapIUPk3RxucYrAiHOHGX3lwhreV9GfbnXBLcqlxNFR ZroeV5DiXpIafrEpi9rZRI1/pWySWUx3YgCzYOFvKtP0v85xZfNWL5xvOCanejloA/dOTEqrCTRZO h4POQw5aA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lM6RW-000Kdy-QT; Tue, 16 Mar 2021 09:56:50 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lM6RR-000Kc4-Al for linux-arm-kernel@lists.infradead.org; Tue, 16 Mar 2021 09:56:48 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id CBAD665014; Tue, 16 Mar 2021 09:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615888603; bh=VZtm7TSm8SzD7rqru+ra4hRXldt8i3ssgmXztshpEgA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YLqiHjh4YLI55r4/HmzYiPyoGVqrBh0rM8DG4WoZaSI+TH2KpSaCyH6jmC6+pp4XZ EAf9FImMvb3TI7Jw5iZGA/9WdRHTESg53CzDcxzD7ssQzk2S17FMJipTbR8cq0muYl rsbtApe/1UYMj1DNbDGjsj7jQWhu9JyUbV1MVMhiAqfXtJ1DXyvsmkHiejZCgMT4n4 bIJ8LTykBSwiN8p5qmGfDC/JeXWvHwZW08JAfmFJgrOWltqQldMVFYMmJ6+bb8Sx/1 NazFbM/dcO9FgvDXx9VHa6LKTOfbsYaZV/+Pp3BayS1EBcuAFn5cf4L6C01AOlbSHw pXCCNyERqxH8A== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lM6Ra-0000aJ-QE; Tue, 16 Mar 2021 10:56:55 +0100 Date: Tue, 16 Mar 2021 10:56:54 +0100 From: Johan Hovold To: Krzysztof Kozlowski Cc: Greg Kroah-Hartman , Jiri Slaby , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, marcan@marcan.st, arnd@kernel.org, Andy Shevchenko Subject: Re: [PATCH] tty: serial: samsung_tty: remove spinlock flags in interrupt handlers Message-ID: References: <20210315181212.113217-1-krzysztof.kozlowski@canonical.com> <7f348e4c-3051-13cf-d461-eeda0ef53fdd@canonical.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <7f348e4c-3051-13cf-d461-eeda0ef53fdd@canonical.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210316_095645_546461_3B23FF51 X-CRM114-Status: GOOD ( 24.58 ) 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 Tue, Mar 16, 2021 at 10:47:53AM +0100, Krzysztof Kozlowski wrote: > On 16/03/2021 10:02, Johan Hovold wrote: > > On Mon, Mar 15, 2021 at 07:12:12PM +0100, Krzysztof Kozlowski wrote: > >> Since interrupt handler is called with disabled local interrupts, there > >> is no need to use the spinlock primitives disabling interrupts as well. > > > > This isn't generally true due to "threadirqs" and that can lead to > > deadlocks if the console code is called from hard irq context. > > > > Now, this is *not* the case for this particular driver since it doesn't > > even bother to take the port lock in console_write(). That should > > probably be fixed instead. > > > > See https://lore.kernel.org/r/X7kviiRwuxvPxC8O@localhost. > > Thanks for the link, quite interesting! For one type of device we have > two interrupts (RX and TX) so I guess it's a valid point/risk. However > let me try to understand it more. > > Assuming we had only one interrupt line, how this interrupt handler with > threadirqs could be called from hardirq context? No, it's console_write() which can end up being called in hard irq context and if that path takes the port lock after the now threaded interrupt handler has been preempted you have a deadlock. > You wrote there: > > For console drivers this can even happen for the same interrupt as the > > generic interrupt code can call printk(), and so can any other handler > > that isn't threaded (e.g. hrtimers or explicit IRQF_NO_THREAD). > > However I replaced here only interrupt handler's spin lock to non-irq. > This code path will be executed only when interrupt is masked therefore > for one interrupt line there is *no possibility of*: > > -> s3c64xx_serial_handle_irq > - interrupts are masked > - s3c24xx_serial_tx_irq > - spin_lock() > -> hrtimers or other IRQF_NO_THREAD > - console_write() or something > - s3c64xx_serial_handle_irq You don't end up in s3c64xx_serial_handle_irq() here. It's just that console_write() (typically) takes the port lock which is already held by the preempted s3c24xx_serial_tx_irq(). > - s3c24xx_serial_tx_irq > - spin_lock() Johan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel