netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] mv88e6xxx: Avoid false positive Lockdep splats
@ 2019-02-23 16:43 Andrew Lunn
  2019-02-23 16:43 ` [PATCH net-next 1/2] net: dsa: mv88e6xxx: Add lockdep classes to fix false positive splat Andrew Lunn
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Lunn @ 2019-02-23 16:43 UTC (permalink / raw)
  To: David Miller; +Cc: Vivien Didelot, Russell King, netdev, Andrew Lunn

When acquiring the GPIO interrupt line for the switch, it is possible
to trigger lockdep splats. These are false positives, the mutex is in
a different IRQ descriptor. But fix it anyway, since it could mask
real locking issues.

Andrew Lunn (2):
  net: dsa: mv88e6xxx: Add lockdep classes to fix false positive splat
  net: dsa: mv88e6xxx: Release lock while requesting IRQ

 drivers/net/dsa/mv88e6xxx/chip.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

-- 
2.20.1


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

* [PATCH net-next 1/2] net: dsa: mv88e6xxx: Add lockdep classes to fix false positive splat
  2019-02-23 16:43 [PATCH net-next 0/2] mv88e6xxx: Avoid false positive Lockdep splats Andrew Lunn
@ 2019-02-23 16:43 ` Andrew Lunn
  2019-02-23 16:43 ` [PATCH net-next 2/2] net: dsa: mv88e6xxx: Release lock while requesting IRQ Andrew Lunn
  2019-02-25  6:21 ` [PATCH net-next 0/2] mv88e6xxx: Avoid false positive Lockdep splats David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2019-02-23 16:43 UTC (permalink / raw)
  To: David Miller; +Cc: Vivien Didelot, Russell King, netdev, Andrew Lunn

The following false positive lockdep splat has been observed.

======================================================
WARNING: possible circular locking dependency detected
4.20.0+ #302 Not tainted
------------------------------------------------------
systemd-udevd/160 is trying to acquire lock:
edea6080 (&chip->reg_lock){+.+.}, at: __setup_irq+0x640/0x704

but task is already holding lock:
edff0340 (&desc->request_mutex){+.+.}, at: __setup_irq+0xa0/0x704

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #1 (&desc->request_mutex){+.+.}:
       mutex_lock_nested+0x1c/0x24
       __setup_irq+0xa0/0x704
       request_threaded_irq+0xd0/0x150
       mv88e6xxx_probe+0x41c/0x694 [mv88e6xxx]
       mdio_probe+0x2c/0x54
       really_probe+0x200/0x2c4
       driver_probe_device+0x5c/0x174
       __driver_attach+0xd8/0xdc
       bus_for_each_dev+0x58/0x7c
       bus_add_driver+0xe4/0x1f0
       driver_register+0x7c/0x110
       mdio_driver_register+0x24/0x58
       do_one_initcall+0x74/0x2e8
       do_init_module+0x60/0x1d0
       load_module+0x1968/0x1ff4
       sys_finit_module+0x8c/0x98
       ret_fast_syscall+0x0/0x28
       0xbedf2ae8

-> #0 (&chip->reg_lock){+.+.}:
       __mutex_lock+0x50/0x8b8
       mutex_lock_nested+0x1c/0x24
       __setup_irq+0x640/0x704
       request_threaded_irq+0xd0/0x150
       mv88e6xxx_g2_irq_setup+0xcc/0x1b4 [mv88e6xxx]
       mv88e6xxx_probe+0x44c/0x694 [mv88e6xxx]
       mdio_probe+0x2c/0x54
       really_probe+0x200/0x2c4
       driver_probe_device+0x5c/0x174
       __driver_attach+0xd8/0xdc
       bus_for_each_dev+0x58/0x7c
       bus_add_driver+0xe4/0x1f0
       driver_register+0x7c/0x110
       mdio_driver_register+0x24/0x58
       do_one_initcall+0x74/0x2e8
       do_init_module+0x60/0x1d0
       load_module+0x1968/0x1ff4
       sys_finit_module+0x8c/0x98
       ret_fast_syscall+0x0/0x28
       0xbedf2ae8

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&desc->request_mutex);
                               lock(&chip->reg_lock);
                               lock(&desc->request_mutex);
  lock(&chip->reg_lock);

&desc->request_mutex refer to two different mutex. #1 is the GPIO for
the chip interrupt. #2 is the chained interrupt between global 1 and
global 2.

Add lockdep classes to the GPIO interrupt to avoid this.

Reported-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/dsa/mv88e6xxx/chip.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index cc7ce06b6d58..7ee8607bf3a6 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -442,12 +442,20 @@ static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
 
 static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
 {
+	static struct lock_class_key lock_key;
+	static struct lock_class_key request_key;
 	int err;
 
 	err = mv88e6xxx_g1_irq_setup_common(chip);
 	if (err)
 		return err;
 
+	/* These lock classes tells lockdep that global 1 irqs are in
+	 * a different category than their parent GPIO, so it won't
+	 * report false recursion.
+	 */
+	irq_set_lockdep_class(chip->irq, &lock_key, &request_key);
+
 	err = request_threaded_irq(chip->irq, NULL,
 				   mv88e6xxx_g1_irq_thread_fn,
 				   IRQF_ONESHOT | IRQF_SHARED,
-- 
2.20.1


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

* [PATCH net-next 2/2] net: dsa: mv88e6xxx: Release lock while requesting IRQ
  2019-02-23 16:43 [PATCH net-next 0/2] mv88e6xxx: Avoid false positive Lockdep splats Andrew Lunn
  2019-02-23 16:43 ` [PATCH net-next 1/2] net: dsa: mv88e6xxx: Add lockdep classes to fix false positive splat Andrew Lunn
@ 2019-02-23 16:43 ` Andrew Lunn
  2019-02-25  6:21 ` [PATCH net-next 0/2] mv88e6xxx: Avoid false positive Lockdep splats David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2019-02-23 16:43 UTC (permalink / raw)
  To: David Miller; +Cc: Vivien Didelot, Russell King, netdev, Andrew Lunn

There is no need to hold the register lock while requesting the GPIO
interrupt. By not holding it we can also avoid a false positive
lockdep splat.

Reported-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/dsa/mv88e6xxx/chip.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 7ee8607bf3a6..9cb17d3ef590 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -456,10 +456,12 @@ static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
 	 */
 	irq_set_lockdep_class(chip->irq, &lock_key, &request_key);
 
+	mutex_unlock(&chip->reg_lock);
 	err = request_threaded_irq(chip->irq, NULL,
 				   mv88e6xxx_g1_irq_thread_fn,
 				   IRQF_ONESHOT | IRQF_SHARED,
 				   dev_name(chip->dev), chip);
+	mutex_lock(&chip->reg_lock);
 	if (err)
 		mv88e6xxx_g1_irq_free_common(chip);
 
-- 
2.20.1


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

* Re: [PATCH net-next 0/2] mv88e6xxx: Avoid false positive Lockdep splats
  2019-02-23 16:43 [PATCH net-next 0/2] mv88e6xxx: Avoid false positive Lockdep splats Andrew Lunn
  2019-02-23 16:43 ` [PATCH net-next 1/2] net: dsa: mv88e6xxx: Add lockdep classes to fix false positive splat Andrew Lunn
  2019-02-23 16:43 ` [PATCH net-next 2/2] net: dsa: mv88e6xxx: Release lock while requesting IRQ Andrew Lunn
@ 2019-02-25  6:21 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-02-25  6:21 UTC (permalink / raw)
  To: andrew; +Cc: vivien.didelot, rmk+kernel, netdev

From: Andrew Lunn <andrew@lunn.ch>
Date: Sat, 23 Feb 2019 17:43:55 +0100

> When acquiring the GPIO interrupt line for the switch, it is possible
> to trigger lockdep splats. These are false positives, the mutex is in
> a different IRQ descriptor. But fix it anyway, since it could mask
> real locking issues.

Series applied, thanks.

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

end of thread, other threads:[~2019-02-25  6:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-23 16:43 [PATCH net-next 0/2] mv88e6xxx: Avoid false positive Lockdep splats Andrew Lunn
2019-02-23 16:43 ` [PATCH net-next 1/2] net: dsa: mv88e6xxx: Add lockdep classes to fix false positive splat Andrew Lunn
2019-02-23 16:43 ` [PATCH net-next 2/2] net: dsa: mv88e6xxx: Release lock while requesting IRQ Andrew Lunn
2019-02-25  6:21 ` [PATCH net-next 0/2] mv88e6xxx: Avoid false positive Lockdep splats David Miller

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).