Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2879378pxb; Fri, 12 Feb 2021 03:58:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+se54bRSEZa6S7hXfMw7emx6DY4UluQd/dukzrwi/D/FBTxYs5NNadySomyfKh6Rt8Bcv X-Received: by 2002:a05:6402:1cc1:: with SMTP id ds1mr2998991edb.10.1613131099536; Fri, 12 Feb 2021 03:58:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613131099; cv=none; d=google.com; s=arc-20160816; b=TW6uD5A1YxqyaxZF7B3PY/kbNz+fPZcvvcKJEQ95TvnTbYX7+vxAzD8jdD2h2X35iC zzBw5xu5jCFFhfTb5TmxjWw1f1n7znwKxv8ReY2OJj7G/yY9dj3up2OIQESTQfDeJbXZ nxbk7D9gd+Vka5YsPlDJhi2O8vbQVPSDqJZtxfOn2+aAMnPY5oA+Jw1gc4UC9ZgEWShJ pSphQQnc/wqIYMKeQm/8CvVDOU+9o2c6le08DRu9xdxqOdfR34QcGGlRWyxHd6T1+uUt crZBB8Z5VkfGU4GSiSpr3BCPgXEhf2OELj7+l8wWr1cdrHo4s0hIcrEWJHS6OzmbMTYY pfxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=fBXXLq6KfeaXtjCrONVqVRjVy8lzIgiUm/maW9F9qvQ=; b=sz3cuUssWtO0WJ11GUO/BHQm5w7de6bggjnsn3lVeraSrxZXuoQf7+I6zsP0rMEvvL sSp+3e/lxE6kf8UjQ6NauobfiEfJ4EuTOz4Ie71Z65I2zPGjoDBBB+cfC2qigMqQlz3c eHV7LZCvshHmrJnpOrqmfmD6IkvDA/uPfE+MiA/1UlirSCbKtsayPoU84weKvCX7TSOd blz79h7oHV+HgSxFddOBbATBZg22PW8HexwgD/3WDnZSUwkMD0zmB88NQos0yeWT946U Ybkzw2LXeuYJsXCUQ4vrmFFEXw6npBSB5forMFcn/zCLaM/u/77ZkRbe2TIcFx0qeHS8 qXeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=eEMwLeXA; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb8si6301738ejc.477.2021.02.12.03.57.56; Fri, 12 Feb 2021 03:58:19 -0800 (PST) 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=@ti.com header.s=ti-com-17Q1 header.b=eEMwLeXA; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229991AbhBLLzI (ORCPT + 99 others); Fri, 12 Feb 2021 06:55:08 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:50784 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230499AbhBLLyr (ORCPT ); Fri, 12 Feb 2021 06:54:47 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 11CBrJfK053185; Fri, 12 Feb 2021 05:53:19 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1613130799; bh=fBXXLq6KfeaXtjCrONVqVRjVy8lzIgiUm/maW9F9qvQ=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=eEMwLeXAj1ozQgUECeXOg/2JT1IEbuKUiLK6kj/DtT2TkMQD7CyIIg9G5DdZCJgTp VrPFTY7nnNHzhgyrWcb1MvDgChPFLEIbhC/lJIaEFFO04yvINClSbToqz+0Cp9zdyw j1aUHR4XHrsk0OjI3Hlq3iRXG3uoEEC32sNsU3wU= Received: from DFLE101.ent.ti.com (dfle101.ent.ti.com [10.64.6.22]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 11CBrJh3123338 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 12 Feb 2021 05:53:19 -0600 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Fri, 12 Feb 2021 05:53:18 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Fri, 12 Feb 2021 05:53:19 -0600 Received: from [10.250.100.73] (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 11CBrEVs093445; Fri, 12 Feb 2021 05:53:15 -0600 Subject: Re: [Linuxarm] Re: [PATCH for next v1 1/2] gpio: omap: Replace raw_spin_lock_irqsave with raw_spin_lock in omap_gpio_irq_handler() To: "Song Bao Hua (Barry Song)" , Andy Shevchenko CC: Arnd Bergmann , luojiaxing , Linus Walleij , Santosh Shilimkar , Kevin Hilman , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , "linuxarm@openeuler.org" References: <1612774577-55943-1-git-send-email-luojiaxing@huawei.com> <1612774577-55943-2-git-send-email-luojiaxing@huawei.com> <2a12cf7a21f74a0c9e2552a467b77fae@hisilicon.com> From: Grygorii Strashko Message-ID: <33720e72-a438-8ffe-1b5f-38756738ad9b@ti.com> Date: Fri, 12 Feb 2021 13:53:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/02/2021 13:29, Song Bao Hua (Barry Song) wrote: > > >> -----Original Message----- >> From: Andy Shevchenko [mailto:andy.shevchenko@gmail.com] >> Sent: Friday, February 12, 2021 11:57 PM >> To: Song Bao Hua (Barry Song) >> Cc: Grygorii Strashko ; Arnd Bergmann >> ; luojiaxing ; Linus Walleij >> ; Santosh Shilimkar ; Kevin >> Hilman ; open list:GPIO SUBSYSTEM >> ; linux-kernel@vger.kernel.org; >> linuxarm@openeuler.org >> Subject: Re: [Linuxarm] Re: [PATCH for next v1 1/2] gpio: omap: Replace >> raw_spin_lock_irqsave with raw_spin_lock in omap_gpio_irq_handler() >> >> On Fri, Feb 12, 2021 at 10:42:19AM +0000, Song Bao Hua (Barry Song) wrote: >>>> From: Grygorii Strashko [mailto:grygorii.strashko@ti.com] >>>> Sent: Friday, February 12, 2021 11:28 PM >>>> On 12/02/2021 11:45, Arnd Bergmann wrote: >>>>> On Fri, Feb 12, 2021 at 6:05 AM Song Bao Hua (Barry Song) >>>>> wrote: >> >>>>>>> Note. there is also generic_handle_irq() call inside. >>>>>> >>>>>> So generic_handle_irq() is not safe to run in thread thus requires >>>>>> an interrupt-disabled environment to run? If so, I'd rather this >>>>>> irqsave moved into generic_handle_irq() rather than asking everyone >>>>>> calling it to do irqsave. >>>>> >>>>> In a preempt-rt kernel, interrupts are run in task context, so they clearly >>>>> should not be called with interrupts disabled, that would defeat the >>>>> purpose of making them preemptible. >>>>> >>>>> generic_handle_irq() does need to run with in_irq()==true though, >>>>> but this should be set by the caller of the gpiochip's handler, and >>>>> it is not set by raw_spin_lock_irqsave(). >>>> >>>> It will produce warning from __handle_irq_event_percpu(), as this is IRQ >>>> dispatcher >>>> and generic_handle_irq() will call one of handle_level_irq or >> handle_edge_irq. >>>> >>>> The history behind this is commit 450fa54cfd66 ("gpio: omap: convert to >> use >>>> generic irq handler"). >>>> >>>> The resent related discussion: >>>> https://lkml.org/lkml/2020/12/5/208 >>> >>> Ok, second thought. irqsave before generic_handle_irq() won't defeat >>> the purpose of preemption too much as the dispatched irq handlers by >>> gpiochip will run in their own threads but not in the thread of >>> gpiochip's handler. >>> >>> so looks like this patch can improve by: >>> * move other raw_spin_lock_irqsave to raw_spin_lock; >>> * keep the raw_spin_lock_irqsave before generic_handle_irq() to mute >>> the warning in genirq. >> >> Isn't the idea of irqsave is to prevent dead lock from the process context when >> we get interrupt on the *same* CPU? > > Anyway, gpiochip is more tricky as it is also a irq dispatcher. Moving > spin_lock_irq to spin_lock in the irq handler of non-irq dispatcher > driver is almost always correct. > > But for gpiochip, would the below be true though it is almost alway true > for non-irq dispatcher? > > 1. While gpiochip's handler runs in hardIRQ, interrupts are disabled, so no more > interrupt on the same cpu -> No deadleak. > > 2. While gpiochip's handler runs in threads > * other non-threaded interrupts such as timer tick might come on same cpu, > but they are an irrelevant driver and thus they are not going to get the > lock gpiochip's handler has held. -> no deadlock. > * other devices attached to this gpiochip might get interrupts, since > gpiochip's handler is running in threads, raw_spin_lock can help avoid > messing up the critical data by two threads -> still no deadlock. The worst RT case I can imagine is when gpio API is still called from hard IRQ context by some other device driver - some toggling for example. Note. RT or "threadirqs" does not mean gpiochip become sleepable. In this case: threaded handler raw_spin_lock IRQ from other device hard_irq handler gpiod_x() raw_spin_lock_irqsave() -- oops But in general, what are the benefit of such changes at all, except better marking call context annotation, so we are spending so much time on it? -- Best regards, grygorii