Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1309644pxb; Fri, 6 Nov 2020 06:34:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwCFRN8lTFAEFBlXhtt+pmJLtreLfG2HSvM55Psr6b6FAF0vqaSYqw4iGw8qve2CRs2ady X-Received: by 2002:a17:906:c298:: with SMTP id r24mr2324444ejz.76.1604673242118; Fri, 06 Nov 2020 06:34:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604673242; cv=none; d=google.com; s=arc-20160816; b=GsOzPaxgO8IrcI6/EEKMQ9W/nyXQerZgnsZ0Fx9Dpsw0BBLKmuNKpH5KThutj8tnvM xGXddlV/N6hNhu54+t0x2DsfSXYCw8FD5xhk1VW1p+kmJV/f/mAU8UjwU4q3CGmfLKv/ 3o8ujbpWQqJS6xXUkn1M/9jYQqbEw8pzUjzxn6nqUqaoOP9ts50N5vjbIxPf/2odtCO2 cDxsVkCm6j+IIvlRPVxPd41BRN7KUymxPM8xtdwLP061Lb43nxCxdIezSyU9kl/3YACF ShKjNLwlQTMEnMR+HHuT62wrsAkEflDhGXlZT8PmXmazYr0kgaFAktG2YctnUiZ4z1H4 f03A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=oB1Imkum9eDeaPIc2hKzTYzV0vCEPBOSK4bPPbyIfFo=; b=TjhYrjBoVMAQ5ZxtYrSnntlhtW3rjI1GJwI20g5VHnw8sQsDoWcXHkWYtln/5/iXzJ P1SDRDSguL5oEBqJJ/MPNtZVrLpv9D1diHVO/o0xYmB4wut1V7fzp3ndNPh+uj10ubJI 5mf68qLT8HpgnFo2OauqMks/vc91+cdAv7sdHHHcFJJlXPcRDJ6RhVTESqkk7rpJlGam e+djQ7lk6CtjV+8Nk91oSMHaVRXOvQRZeLzl2m6im0QvDgCwrLL6acvElaFarg1qCWqR OZNTrIstVb6YUAY46W1MelY2j/kkH6g9G+FDwEUZKev923StDvysJQ2cV2dbwd5Da3L9 /r6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=MJZxZb9N; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a10si1050901eda.423.2020.11.06.06.33.39; Fri, 06 Nov 2020 06:34:02 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=MJZxZb9N; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727214AbgKFOcA (ORCPT + 99 others); Fri, 6 Nov 2020 09:32:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726565AbgKFOcA (ORCPT ); Fri, 6 Nov 2020 09:32:00 -0500 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37836C0613D3 for ; Fri, 6 Nov 2020 06:32:00 -0800 (PST) Received: by mail-ed1-x542.google.com with SMTP id cq7so1275750edb.4 for ; Fri, 06 Nov 2020 06:32:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oB1Imkum9eDeaPIc2hKzTYzV0vCEPBOSK4bPPbyIfFo=; b=MJZxZb9Np7qkyYy2+/tuO+PJ7RD8i5hCMCSDVGIKwTmGEMUp8jBXPxbi+ypenl2uOX qJ+L1g3+lrM0rI9q1py697lLpVRpbpkvaX0ElM8ptuKvrrkiH2JpsDBGnsMgMYG1cxgj rf004YD74RsbNxZw9n64cR/SXbBsAMzl7nmG9y4aWGHYSDiJIASZMOZKw1AJaZ4GgIvq dlNw/F+0nf0rg9hu3C2ImbB6PPdVRLjidafVVXKzFiq/1l+5YdtMlfZc6GuqsDe5Vz4T jjDqLv8LS3Z8+gbHNi8Btm42PrEaRycBGPh5rEGzK7ffR3uGl6alKh5Vqg0qZUM0QFth YvKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oB1Imkum9eDeaPIc2hKzTYzV0vCEPBOSK4bPPbyIfFo=; b=aWLwzq1qgdWg4ngplCrCwC5cCRCj3dZQznHe31sQEOyrDmb4jJseXlb9jbgAhBzc4k Qj5sSyAj9WP7YFwA1cPiS+QaSG9pZxgvRmRuMngFxyBguq+9MCxiOTK3e+f816jygAMa 3yroBPRa1W//bkEvyStz/YYAvoK4GeyWQ3uBOfyddLKsi05LmOIUCcVjDQNqSM9DF3sk bMzYZXuIaYX6HRhpPpKMAtegm64FxsYacJNPpD4iCxLpQZgyE3Ov1sgSYHLirgmEtktc Vf7KhzwC5zWYukcXpcaF6RnV9DnZ/A/PY8qemQkkMvbPOKcTEMoni+o1WNRP6fZ8bpZM h7GQ== X-Gm-Message-State: AOAM530YQYi9jp08r9sc7UweMAEZNhu3fnDmTGRbhlCcguBM+Yegl7// AOCMtUS5ODh5l3IgLu8GbtCtcG452gKf+IdLzBdvfg== X-Received: by 2002:a50:ab15:: with SMTP id s21mr2279062edc.88.1604673118970; Fri, 06 Nov 2020 06:31:58 -0800 (PST) MIME-Version: 1.0 References: <20201104170423.23436-1-digetx@gmail.com> <20201104170423.23436-2-digetx@gmail.com> In-Reply-To: <20201104170423.23436-2-digetx@gmail.com> From: Bartosz Golaszewski Date: Fri, 6 Nov 2020 15:31:48 +0100 Message-ID: Subject: Re: [PATCH v2 2/2] gpio: tegra: Use raw_spinlock To: Dmitry Osipenko Cc: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Linus Walleij , Andy Shevchenko , Peter Geis , linux-tegra@vger.kernel.org, linux-gpio , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 4, 2020 at 6:04 PM Dmitry Osipenko wrote: > > Use raw_spinlock in order to fix spurious messages about invalid context > when spinlock debugging is enabled. This happens because there is a legit > nested raw_spinlock->spinlock locking usage within IRQ-related code. IRQ > core uses raw spinlock and then Tegra GPIO driver uses a nested spinlock. > The debug code can't recognize and handle this case, hence we need to use > raw spinlock in the GPIO driver. > > [ BUG: Invalid wait context ] > ... > (dump_stack) from (__lock_acquire) > (__lock_acquire) from (lock_acquire) > (lock_acquire) from (_raw_spin_lock_irqsave) > (_raw_spin_lock_irqsave) from (tegra_gpio_irq_set_type) > (tegra_gpio_irq_set_type) from (__irq_set_trigger) > (__irq_set_trigger) from (__setup_irq) > (__setup_irq) from (request_threaded_irq) > (request_threaded_irq) from (devm_request_threaded_irq) > (devm_request_threaded_irq) from (elants_i2c_probe) > (elants_i2c_probe) from (i2c_device_probe) > ... > > Tested-by: Peter Geis > Signed-off-by: Dmitry Osipenko > --- > > Changelog: > > v2: - Only lvl_lock is converted to raw_spinlock. The dbc_lock doesn't > relate to IRQ and doesn't need the conversion. > > - Improved commit message by clarifying that IRQ core uses raw > spinlock. > > - Added clarifying comment to the code for the lvl_lock. > > drivers/gpio/gpio-tegra.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c > index 98fc78739ebf..e19ebff6018c 100644 > --- a/drivers/gpio/gpio-tegra.c > +++ b/drivers/gpio/gpio-tegra.c > @@ -61,8 +61,16 @@ struct tegra_gpio_info; > struct tegra_gpio_bank { > unsigned int bank; > unsigned int irq; > - spinlock_t lvl_lock[4]; > - spinlock_t dbc_lock[4]; /* Lock for updating debounce count register */ > + > + /* > + * IRQ-core code uses raw locking, and thus, nested locking also > + * should be raw in order not to trip spinlock debug warnings. > + */ > + raw_spinlock_t lvl_lock[4]; > + > + /* Lock for updating debounce count register */ > + spinlock_t dbc_lock[4]; > + > #ifdef CONFIG_PM_SLEEP > u32 cnf[4]; > u32 out[4]; > @@ -334,14 +342,14 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) > return -EINVAL; > } > > - spin_lock_irqsave(&bank->lvl_lock[port], flags); > + raw_spin_lock_irqsave(&bank->lvl_lock[port], flags); > > val = tegra_gpio_readl(tgi, GPIO_INT_LVL(tgi, gpio)); > val &= ~(GPIO_INT_LVL_MASK << GPIO_BIT(gpio)); > val |= lvl_type << GPIO_BIT(gpio); > tegra_gpio_writel(tgi, val, GPIO_INT_LVL(tgi, gpio)); > > - spin_unlock_irqrestore(&bank->lvl_lock[port], flags); > + raw_spin_unlock_irqrestore(&bank->lvl_lock[port], flags); > > tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, gpio), gpio, 0); > tegra_gpio_enable(tgi, gpio); > @@ -675,7 +683,7 @@ static int tegra_gpio_probe(struct platform_device *pdev) > tegra_gpio_irq_handler, bank); > > for (j = 0; j < 4; j++) { > - spin_lock_init(&bank->lvl_lock[j]); > + raw_spin_lock_init(&bank->lvl_lock[j]); > spin_lock_init(&bank->dbc_lock[j]); > } > } > -- > 2.27.0 > Patch applied, thanks! Bartosz