Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1201044pxf; Fri, 19 Mar 2021 01:11:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7AWQr2VTYZW1MIJltDvmsIDIcCbChJGgNkJeKs7jee6boKbNCOirqa1DsyJ0JWQt2aDZG X-Received: by 2002:a17:907:d10:: with SMTP id gn16mr2936390ejc.304.1616141497645; Fri, 19 Mar 2021 01:11:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616141497; cv=none; d=google.com; s=arc-20160816; b=Y3P4yix0TSCS4aSkImm/teJNSK9o6IWZRAhTI59qwUjpPnvghZFqH/75U0pVl/Q7NI GT0l3oPKFIjJqwOKpaec06RhtEpVUzwmEnxL7kO2o8FWjbKoW8AXH6Rl535vKPCoRUEE JNuPA/LVk2IQ4rmlPkDWT9zTqjZLr8DdTESYS7zsA7YYJj7iVEwcrtuQDf9x6K5zxRfH UFSilMzHQAb6twK5nEWSoYwiYBucjnjggUa9+4T4cnwYhYVjG1dRHsLpJvb63JP/srM4 5+0YSmT36bSJY10GWhSjgfAPaEORg2O6BDcEznzmByAVbf4AOdH0JQCBYPj0TcQg5LLa 4Mvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1heKMBnB3kKcbuLvJWaUJktj1E4MQ8ubQ+Qp3zI8rg0=; b=DK/srpXp88wdk3FpnWEwLRtTA9pqDiBqoMNmXLza9hbsFmyiDrt3oKRrxf3alzkiAM bELNSKGTpmiH89/xMhThykfjxo3IBsBz+V3Was0zwHqRMuHzofq3lUeHIcj7cuDGSrT3 51Ku+uO74+3e6qRMS13KiRnH5t3FY4INkPaeS/x+QGxOBa6H0ZMWsEAad4ICK0nNzbWm TZw2zpp2u/4RYBeGXz4WiWZ1bL/FO8dujsl6bla9XP6Zw74sDgnhUt2OhAEZzRsWrf/4 KLkRgGzZ1aIwwjmuIf3ZXpNkc8qZMNn/aLgLBJzOoE4lYUpFRZ4SmqNoV+UhwLoG31M/ lOWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Og2XGq/C"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g22si3663743ejx.518.2021.03.19.01.11.15; Fri, 19 Mar 2021 01:11:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Og2XGq/C"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234315AbhCSIKT (ORCPT + 99 others); Fri, 19 Mar 2021 04:10:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:50964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234084AbhCSIJt (ORCPT ); Fri, 19 Mar 2021 04:09:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 390DC64F68; Fri, 19 Mar 2021 08:09:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616141389; bh=8yyL1lc9w1zEvs02giHe/AkhySpLaZuLjBUihev2WZ4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Og2XGq/C9jDWrFpkn7jIMmJ42fTa76imA6COYLkGsphWC8N7QNr0CGZXcBkNn5hec FsxHbz4caYtDKM9wsahMmOLDIGuNhvPqIYWUvn7rj5TCM4+MpAWWMS+31omZS6tZHn 7Mu77FSS7n1U/61aoUqnS9/1Wfaqh2F7DaKCm9CY40cD+92yxaX7iZjp1J8wuQHCK+ XqRk4V0Qa+TomLDA9SXtKcTPKXMjZJrZhDO86Zia5TTv1vk9G+stk7fogSpQpISehZ uKgm+vhAevfpaX+HtrEfpCx9jzkB7yLVl+6NTkYm3Ciaz7Cl0vFlcAMV2IbtJePVXQ nNOnd9DXYhk3Q== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lNACu-0001jF-Ft; Fri, 19 Mar 2021 09:10:09 +0100 Date: Fri, 19 Mar 2021 09:10:08 +0100 From: Johan Hovold To: "Song Bao Hua (Barry Song)" Cc: Andy Shevchenko , Finn Thain , Krzysztof Kozlowski , Greg Kroah-Hartman , Jiri Slaby , linux-arm Mailing List , Linux Samsung SOC , "open list:SERIAL DRIVERS" , Linux Kernel Mailing List , Hector Martin , Arnd Bergmann Subject: Re: [PATCH] tty: serial: samsung_tty: remove spinlock flags in interrupt handlers Message-ID: References: <20210315181212.113217-1-krzysztof.kozlowski@canonical.com> <4771468d968a44789518bc547acf5f93@hisilicon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4771468d968a44789518bc547acf5f93@hisilicon.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 19, 2021 at 06:36:39AM +0000, Song Bao Hua (Barry Song) wrote: > > > > -----Original Message----- > > From: Andy Shevchenko [mailto:andy.shevchenko@gmail.com] > > Sent: Tuesday, March 16, 2021 10:41 PM > > To: Johan Hovold ; Finn Thain ; > > Song Bao Hua (Barry Song) > > Cc: Krzysztof Kozlowski ; Greg > > Kroah-Hartman ; Jiri Slaby ; > > linux-arm Mailing List ; Linux Samsung > > SOC ; open list:SERIAL DRIVERS > > ; Linux Kernel Mailing List > > ; Hector Martin ; Arnd > > Bergmann > > Subject: Re: [PATCH] tty: serial: samsung_tty: remove spinlock flags in > > interrupt handlers > > > > On Tue, Mar 16, 2021 at 11:02 AM 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. > > > > Finn, Barry, something to check I think? > > My understanding is that spin_lock_irqsave can't protect the context > the console_write() is called in hardirq for threaded_irq case mainly > for preempt-rt scenarios as spin_lock_irqsave doesn't disable irq in > that case at all. Forced threaded interrupts have so far run with interrupts enabled and spin_lock_irqsave() would suffice on non-RT. This is about to change though so that drivers don't need to worry about "threadirqs": https://lore.kernel.org/r/20210317143859.513307808@linutronix.de > See: > https://www.kernel.org/doc/html/latest/locking/locktypes.html > spinlock_t and PREEMPT_RT > On a PREEMPT_RT kernel spinlock_t is mapped to a separate implementation > based on rt_mutex which changes the semantics: > Preemption is not disabled. > The hard interrupt related suffixes for spin_lock / spin_unlock operations > (_irq, _irqsave / _irqrestore) do not affect the CPU’s interrupt disabled > state. > > So if console_write() can interrupt our code in hardirq, we should > move to raw_spin_lock_irqsave for this driver. No, no. RT handles this by deferring console writes apparently. > I think it is almost always wrong to call spin_lock_irqsave in hardirq. Again, no. It's even been a requirement due to "threadirqs" in some cases (e.g. hrtimers) up until now (or rather until the above patch is in mainline). Johan