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 D8C24C433DB for ; Tue, 16 Mar 2021 11:26:25 +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 671E265023 for ; Tue, 16 Mar 2021 11:26:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 671E265023 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=jSQGQ9uF7aAlVHOjjASiXhLpGSf71zkypasrBnaKju0=; b=fS7d30LwlCxwzzYQ5Qsx+8HHT gyzbmyrD/nkVLxKUs1n8rkuuAdnxAIOSx5gFvKLUZL8edu2/yFR/MUwScZ58jteoxTuri8P4D91zK VZsY6s9avUxpim6N2RdzBbnYmNVZDRFQZNslbLbgGjAkqtj9h2CVYKZNTHda2grTKe+G1r21n1wd7 8fk9bsjkSL+VLrtlbA8mos67rjIyXCqybUgOm9cD5RJMZuaslArifhz4BcfhWDkKeBjXhnceRHB01 glLBRz5aJx1JCIE3ioSM1YPhDrjSVuPmd/8WbdYcRB9TtrOjEi0Lz6kCAfYXmzaB5hiwxLMC1qj7n MaOwlBTDw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lM7ou-000Ybl-T1; Tue, 16 Mar 2021 11:25:05 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lM7op-000YbB-Lu for linux-arm-kernel@lists.infradead.org; Tue, 16 Mar 2021 11:25:01 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 129D26501D; Tue, 16 Mar 2021 11:24:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615893898; bh=Dk4y8iGJZZIjb3solFCTMP0GpGYj5vgAXWPhsjVPmNU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RV6uE8jz8lDq+x+yBjJEBLn8VIYSb5deFoou+Z4qUyBNFUyhPOywUC9efGSjTube+ s3/zR8mG6wb/PXyEChG+WSfj09KqgmQj3bsoptJ0/CDD1JJv80blR8VAFXB9og9j9G oDS4Ay5uAQVwvbMtUrF4CpoFBHcSx9Q75Tx3psmzviN3+thRtAxd5igMTIHGpslzdW +h2G69Xc3M2PVsAF8qQ8IBIAgpn5+PKjUDdjG7MCkH3bjAcp44IId/swcdFNrwAdr3 J+wp4GRzQnIF5AmidL+R7istxqUb6DosKfu25Wz+TveVVXOBpLySocjIriEQOa8JT/ bwm1MUQrVFrvA== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lM7oz-0000xf-2v; Tue, 16 Mar 2021 12:25:09 +0100 Date: Tue, 16 Mar 2021 12:25:09 +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> <816834ba-8dc2-05cd-9c81-a11d65980cfd@canonical.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <816834ba-8dc2-05cd-9c81-a11d65980cfd@canonical.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210316_112459_945188_B1B37292 X-CRM114-Status: GOOD ( 22.48 ) 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 11:11:43AM +0100, Krzysztof Kozlowski wrote: > On 16/03/2021 10:56, Johan Hovold wrote: > > 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. > > Thanks, I understand now. I see three patterns shared by serial drivers: > > 1. Do not take the lock in console_write() handler, > 2. Take the lock like: > if (port->sysrq) > locked = 0; > else if (oops_in_progress) > locked = spin_trylock_irqsave(&port->lock, flags); > else > spin_lock_irqsave(&port->lock, flags) > > 3. Take the lock like above but preceded with local_irq_save(). > > It seems the choice of pattern depends which driver was used as a base. Right, this is messy and we've been playing whack-a-mole with this for years (as usual) it seems. Some version of 2 above is probably what we want but the sysrq bits aren't handled uniformly either (e.g. since 596f63da42b9 ("serial: 8250: Process sysrq at port unlock time")). Johan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel