linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] gpio: tegra: Add lockdep class
@ 2020-11-04 13:26 Dmitry Osipenko
  2020-11-04 13:26 ` [PATCH v1 2/2] gpio: tegra: Use raw_spinlock Dmitry Osipenko
  2020-11-06 14:31 ` [PATCH v1 1/2] gpio: tegra: Add lockdep class Bartosz Golaszewski
  0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Osipenko @ 2020-11-04 13:26 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Laxman Dewangan,
	Bartosz Golaszewski, Linus Walleij, Peter Geis
  Cc: linux-tegra, linux-gpio, linux-kernel

Add lockdep class in order to fix debug warnings that are coming from a
legit nested use of irq_set_irq_wake() by the Tegra GPIO driver.

 WARNING: possible recursive locking detected
 ...
  (irq_set_irq_wake) from (tegra_gpio_irq_set_wake)
  (tegra_gpio_irq_set_wake) from (irq_set_irq_wake)
  (irq_set_irq_wake) from (brcmf_sdiod_intr_register [brcmfmac])
 ...

Tested-by: Peter Geis <pgwipeout@gmail.com>
Reported-by: Peter Geis <pgwipeout@gmail.com>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/gpio/gpio-tegra.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 86568154cdb3..98fc78739ebf 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -560,6 +560,9 @@ static const struct dev_pm_ops tegra_gpio_pm_ops = {
 	SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume)
 };
 
+static struct lock_class_key gpio_lock_class;
+static struct lock_class_key gpio_request_class;
+
 static int tegra_gpio_probe(struct platform_device *pdev)
 {
 	struct tegra_gpio_info *tgi;
@@ -661,6 +664,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
 		bank = &tgi->bank_info[GPIO_BANK(gpio)];
 
 		irq_set_chip_data(irq, bank);
+		irq_set_lockdep_class(irq, &gpio_lock_class, &gpio_request_class);
 		irq_set_chip_and_handler(irq, &tgi->ic, handle_simple_irq);
 	}
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 2/2] gpio: tegra: Use raw_spinlock
  2020-11-04 13:26 [PATCH v1 1/2] gpio: tegra: Add lockdep class Dmitry Osipenko
@ 2020-11-04 13:26 ` Dmitry Osipenko
  2020-11-04 14:47   ` Andy Shevchenko
  2020-11-06 14:31 ` [PATCH v1 1/2] gpio: tegra: Add lockdep class Bartosz Golaszewski
  1 sibling, 1 reply; 5+ messages in thread
From: Dmitry Osipenko @ 2020-11-04 13:26 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Laxman Dewangan,
	Bartosz Golaszewski, Linus Walleij, Peter Geis
  Cc: linux-tegra, linux-gpio, linux-kernel

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 which debug code can't recognize and
handle.

 [ 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 <pgwipeout@gmail.com>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/gpio/gpio-tegra.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 98fc78739ebf..74a13534b9e4 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -61,8 +61,8 @@ 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 */
+	raw_spinlock_t lvl_lock[4];
+	raw_spinlock_t dbc_lock[4];	/* Lock for updating debounce count register */
 #ifdef CONFIG_PM_SLEEP
 	u32 cnf[4];
 	u32 out[4];
@@ -242,12 +242,12 @@ static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
 	/* There is only one debounce count register per port and hence
 	 * set the maximum of current and requested debounce time.
 	 */
-	spin_lock_irqsave(&bank->dbc_lock[port], flags);
+	raw_spin_lock_irqsave(&bank->dbc_lock[port], flags);
 	if (bank->dbc_cnt[port] < debounce_ms) {
 		tegra_gpio_writel(tgi, debounce_ms, GPIO_DBC_CNT(tgi, offset));
 		bank->dbc_cnt[port] = debounce_ms;
 	}
-	spin_unlock_irqrestore(&bank->dbc_lock[port], flags);
+	raw_spin_unlock_irqrestore(&bank->dbc_lock[port], flags);
 
 	tegra_gpio_mask_write(tgi, GPIO_MSK_DBC_EN(tgi, offset), offset, 1);
 
@@ -334,14 +334,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,8 +675,8 @@ 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]);
-			spin_lock_init(&bank->dbc_lock[j]);
+			raw_spin_lock_init(&bank->lvl_lock[j]);
+			raw_spin_lock_init(&bank->dbc_lock[j]);
 		}
 	}
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 2/2] gpio: tegra: Use raw_spinlock
  2020-11-04 13:26 ` [PATCH v1 2/2] gpio: tegra: Use raw_spinlock Dmitry Osipenko
@ 2020-11-04 14:47   ` Andy Shevchenko
  2020-11-04 15:03     ` Dmitry Osipenko
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2020-11-04 14:47 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Laxman Dewangan,
	Bartosz Golaszewski, Linus Walleij, Peter Geis, linux-tegra,
	open list:GPIO SUBSYSTEM, Linux Kernel Mailing List

On Wed, Nov 4, 2020 at 3:27 PM Dmitry Osipenko <digetx@gmail.com> 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 which debug code can't recognize and
> handle.

This sounds like papering over a problem that exists somewhere else.

What I would rather make as a selling point is that raw spin locks are
necessary to be in the RT kernel for IRQ chips.

> Tested-by: Peter Geis <pgwipeout@gmail.com>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 2/2] gpio: tegra: Use raw_spinlock
  2020-11-04 14:47   ` Andy Shevchenko
@ 2020-11-04 15:03     ` Dmitry Osipenko
  0 siblings, 0 replies; 5+ messages in thread
From: Dmitry Osipenko @ 2020-11-04 15:03 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Thierry Reding, Jonathan Hunter, Laxman Dewangan,
	Bartosz Golaszewski, Linus Walleij, Peter Geis, linux-tegra,
	open list:GPIO SUBSYSTEM, Linux Kernel Mailing List

04.11.2020 17:47, Andy Shevchenko пишет:
> On Wed, Nov 4, 2020 at 3:27 PM Dmitry Osipenko <digetx@gmail.com> 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 which debug code can't recognize and
>> handle.
> 
> This sounds like papering over a problem that exists somewhere else.
> 
> What I would rather make as a selling point is that raw spin locks are
> necessary to be in the RT kernel for IRQ chips.

This should be a well-known problem because other GPIO drivers also have
it.

For example this one:

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?h=next-20201104&id=023892ec80f0efcffe22045e92bb89f3f1480f2d

Although, looking at it again, I think there is no real need to change
the dbc_lock since it doesn't relate to the IRQ. Perhaps this could be
improved in a v2.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] gpio: tegra: Add lockdep class
  2020-11-04 13:26 [PATCH v1 1/2] gpio: tegra: Add lockdep class Dmitry Osipenko
  2020-11-04 13:26 ` [PATCH v1 2/2] gpio: tegra: Use raw_spinlock Dmitry Osipenko
@ 2020-11-06 14:31 ` Bartosz Golaszewski
  1 sibling, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2020-11-06 14:31 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Laxman Dewangan, Linus Walleij,
	Peter Geis, linux-tegra, linux-gpio, LKML

On Wed, Nov 4, 2020 at 2:26 PM Dmitry Osipenko <digetx@gmail.com> wrote:
>
> Add lockdep class in order to fix debug warnings that are coming from a
> legit nested use of irq_set_irq_wake() by the Tegra GPIO driver.
>
>  WARNING: possible recursive locking detected
>  ...
>   (irq_set_irq_wake) from (tegra_gpio_irq_set_wake)
>   (tegra_gpio_irq_set_wake) from (irq_set_irq_wake)
>   (irq_set_irq_wake) from (brcmf_sdiod_intr_register [brcmfmac])
>  ...
>
> Tested-by: Peter Geis <pgwipeout@gmail.com>
> Reported-by: Peter Geis <pgwipeout@gmail.com>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/gpio/gpio-tegra.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
> index 86568154cdb3..98fc78739ebf 100644
> --- a/drivers/gpio/gpio-tegra.c
> +++ b/drivers/gpio/gpio-tegra.c
> @@ -560,6 +560,9 @@ static const struct dev_pm_ops tegra_gpio_pm_ops = {
>         SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume)
>  };
>
> +static struct lock_class_key gpio_lock_class;
> +static struct lock_class_key gpio_request_class;
> +
>  static int tegra_gpio_probe(struct platform_device *pdev)
>  {
>         struct tegra_gpio_info *tgi;
> @@ -661,6 +664,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
>                 bank = &tgi->bank_info[GPIO_BANK(gpio)];
>
>                 irq_set_chip_data(irq, bank);
> +               irq_set_lockdep_class(irq, &gpio_lock_class, &gpio_request_class);
>                 irq_set_chip_and_handler(irq, &tgi->ic, handle_simple_irq);
>         }
>
> --
> 2.27.0
>

Patch applied, thanks!

Bartosz

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-06 14:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-04 13:26 [PATCH v1 1/2] gpio: tegra: Add lockdep class Dmitry Osipenko
2020-11-04 13:26 ` [PATCH v1 2/2] gpio: tegra: Use raw_spinlock Dmitry Osipenko
2020-11-04 14:47   ` Andy Shevchenko
2020-11-04 15:03     ` Dmitry Osipenko
2020-11-06 14:31 ` [PATCH v1 1/2] gpio: tegra: Add lockdep class Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).