Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2969786pxb; Fri, 12 Feb 2021 06:14:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJye6aZpxqkYtUDddjkZV6Kn1uBo7sQjvg1uLjlSzYvY8162uhAvDz+dvioi6FKKen5aKVMe X-Received: by 2002:a05:6402:50ca:: with SMTP id h10mr3543001edb.95.1613139280318; Fri, 12 Feb 2021 06:14:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613139280; cv=none; d=google.com; s=arc-20160816; b=nwK4xNB1ItTkrf9oX2nEvcIxpGWExz12DgpSz0+kCrdaSnddoygUS9caIHGlgJ2DQS mPfROLvgURubf4s/tRoJZD9xGOcR7Wq6pPaItardxbVlu0RoDa0BQctuxtODhmb57ifU BCXV9ma/T3yvhjJPNSSBHRluv7ij6/VoRT6e3APXoV5MZhvGKidDjBIyy+sto50vHU/u YRdBQb91PdkNE75K6eJp6TJvivPT58ZZ0yOdvaKmhg7YctfyzePMCVPWv1rE+K5lp7DI nDd/7oEtRBBbgJkavLHyVmV+YkibbyA1xpiKlj3hvuNb0uVAKKHw5+X15zStN3p9WWfR Hevg== 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=uBxCxEg+TQK7Bkc4s3MNk+l0me+bcp9GAH7hic6AQQ4=; b=BCzCe++sk/HgU26bFIl+F+7uyYbdpcTOeldzpo1p0JH/DsejMS0Y7Vy6ems36KLVN1 MQ9tR/tU2TvXDVmFnKDN2k0ppo+lbHSD32mB4SXPZxJioiPtT0kYbgoqJ/Nqf82Rdqwc G3K7jLLjr5WhUlLiSxLUJhyeocNyEwtaZISXgPbWks6wuMysk1QiqwN/edhNolhhHKb0 KU6Uep2CBC8CtmQaAFG3rg9i/J2oQ2korAgwiYt+xAFZV+r8RZLQTUr1aYhBq1rsFh5D Mcg9IF/rfC9WfE3OnygW/JOm3cs64NNuLYZs4aQkxn6wnMl3AR2TDfJqiOa0ZrvMRWNl 01UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=OhxrUCnX; 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 n20si1151356edo.525.2021.02.12.06.14.15; Fri, 12 Feb 2021 06:14:40 -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=OhxrUCnX; 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 S231622AbhBLOLB (ORCPT + 99 others); Fri, 12 Feb 2021 09:11:01 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:57154 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231627AbhBLOK5 (ORCPT ); Fri, 12 Feb 2021 09:10:57 -0500 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 11CE8hBM102056; Fri, 12 Feb 2021 08:08:43 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1613138923; bh=uBxCxEg+TQK7Bkc4s3MNk+l0me+bcp9GAH7hic6AQQ4=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=OhxrUCnXbQqJETtZBIoX9wZTglI2abSZrxj53uXDRfK9jLzqI4fe9Hh+KDVZ+cN4/ HzXB16jslbzwXP5ypGuiKR1LcpVMzxWmlXda0nfAYL6LLfBWSBzIBt28ppN2eWZjrT li/Wbzi7Ui3ROK4l4k9oStSaarLmAzQCuovvGqfE= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 11CE8hU6023557 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 12 Feb 2021 08:08:43 -0600 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE109.ent.ti.com (10.64.6.30) 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 08:08:43 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) 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 via Frontend Transport; Fri, 12 Feb 2021 08:08:43 -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 11CE8fDC076514; Fri, 12 Feb 2021 08:08:41 -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> <33720e72-a438-8ffe-1b5f-38756738ad9b@ti.com> <014b2e0d2b134bfdbe629ab6146c6bb4@hisilicon.com> From: Grygorii Strashko Message-ID: <92f75957-4f04-e62e-1a3e-09933a8881b5@ti.com> Date: Fri, 12 Feb 2021 16:08:40 +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: <014b2e0d2b134bfdbe629ab6146c6bb4@hisilicon.com> 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 15:12, Song Bao Hua (Barry Song) wrote: > > >> -----Original Message----- >> From: Grygorii Strashko [mailto:grygorii.strashko@ti.com] >> Sent: Saturday, February 13, 2021 12:53 AM >> 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 >> 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 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 > > Actually no oops here. other drivers don't hold the same > spinlock of this driver. huh. driver/module A requests gpio and uses it in its hard_irq handler by calling GPIO API (Like gpiod_set_value()), those will go to this driver and end up in omap_gpio_set(). > >> >> 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? > > TBH, the benefit is really tiny except code cleanup. just curious how things could > be different while it happens in an irq dispatcher's handler. -- Best regards, grygorii