Alexander Sverdlin
4dc0484e90
net: dsa: lan9303: consequently nested-lock physical MDIO
...
commit 5a22fbcc10f3f7d94c5d88afbbffa240a3677057 upstream.
When LAN9303 is MDIO-connected two callchains exist into
mdio->bus->write():
1. switch ports 1&2 ("physical" PHYs):
virtual (switch-internal) MDIO bus (lan9303_switch_ops->phy_{read|write})->
lan9303_mdio_phy_{read|write} -> mdiobus_{read|write}_nested
2. LAN9303 virtual PHY:
virtual MDIO bus (lan9303_phy_{read|write}) ->
lan9303_virt_phy_reg_{read|write} -> regmap -> lan9303_mdio_{read|write}
If the latter functions just take
mutex_lock(&sw_dev->device->bus->mdio_lock) it triggers a LOCKDEP
false-positive splat. It's false-positive because the first
mdio_lock in the second callchain above belongs to virtual MDIO bus, the
second mdio_lock belongs to physical MDIO bus.
Consequent annotation in lan9303_mdio_{read|write} as nested lock
(similar to lan9303_mdio_phy_{read|write}, it's the same physical MDIO bus)
prevents the following splat:
WARNING: possible circular locking dependency detected
5.15.71 #1 Not tainted
------------------------------------------------------
kworker/u4:3/609 is trying to acquire lock:
ffff000011531c68 (lan9303_mdio:131:(&lan9303_mdio_regmap_config)->lock){+.+.}-{3:3}, at: regmap_lock_mutex
but task is already holding lock:
ffff0000114c44d8 (&bus->mdio_lock){+.+.}-{3:3}, at: mdiobus_read
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&bus->mdio_lock){+.+.}-{3:3}:
lock_acquire
__mutex_lock
mutex_lock_nested
lan9303_mdio_read
_regmap_read
regmap_read
lan9303_probe
lan9303_mdio_probe
mdio_probe
really_probe
__driver_probe_device
driver_probe_device
__device_attach_driver
bus_for_each_drv
__device_attach
device_initial_probe
bus_probe_device
deferred_probe_work_func
process_one_work
worker_thread
kthread
ret_from_fork
-> #0 (lan9303_mdio:131:(&lan9303_mdio_regmap_config)->lock){+.+.}-{3:3}:
__lock_acquire
lock_acquire.part.0
lock_acquire
__mutex_lock
mutex_lock_nested
regmap_lock_mutex
regmap_read
lan9303_phy_read
dsa_slave_phy_read
__mdiobus_read
mdiobus_read
get_phy_device
mdiobus_scan
__mdiobus_register
dsa_register_switch
lan9303_probe
lan9303_mdio_probe
mdio_probe
really_probe
__driver_probe_device
driver_probe_device
__device_attach_driver
bus_for_each_drv
__device_attach
device_initial_probe
bus_probe_device
deferred_probe_work_func
process_one_work
worker_thread
kthread
ret_from_fork
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&bus->mdio_lock);
lock(lan9303_mdio:131:(&lan9303_mdio_regmap_config)->lock);
lock(&bus->mdio_lock);
lock(lan9303_mdio:131:(&lan9303_mdio_regmap_config)->lock);
*** DEADLOCK ***
5 locks held by kworker/u4:3/609:
#0 : ffff000002842938 ((wq_completion)events_unbound){+.+.}-{0:0}, at: process_one_work
#1 : ffff80000bacbd60 (deferred_probe_work){+.+.}-{0:0}, at: process_one_work
#2 : ffff000007645178 (&dev->mutex){....}-{3:3}, at: __device_attach
#3 : ffff8000096e6e78 (dsa2_mutex){+.+.}-{3:3}, at: dsa_register_switch
#4 : ffff0000114c44d8 (&bus->mdio_lock){+.+.}-{3:3}, at: mdiobus_read
stack backtrace:
CPU: 1 PID: 609 Comm: kworker/u4:3 Not tainted 5.15.71 #1
Workqueue: events_unbound deferred_probe_work_func
Call trace:
dump_backtrace
show_stack
dump_stack_lvl
dump_stack
print_circular_bug
check_noncircular
__lock_acquire
lock_acquire.part.0
lock_acquire
__mutex_lock
mutex_lock_nested
regmap_lock_mutex
regmap_read
lan9303_phy_read
dsa_slave_phy_read
__mdiobus_read
mdiobus_read
get_phy_device
mdiobus_scan
__mdiobus_register
dsa_register_switch
lan9303_probe
lan9303_mdio_probe
...
Cc: stable@vger.kernel.org
Fixes: dc7005831523 ("net: dsa: LAN9303: add MDIO managed mode support")
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20231027065741.534971-1-alexander.sverdlin@siemens.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-11-28 16:55:00 +00:00
..
2023-11-28 16:54:56 +00:00
2023-09-19 12:20:19 +02:00
2023-08-16 18:21:00 +02:00
2023-10-25 11:54:23 +02:00
2023-11-28 16:54:51 +00:00
2023-11-20 11:06:55 +01:00
2023-10-10 21:53:36 +02:00
2023-11-28 16:55:00 +00:00
2023-10-10 21:53:31 +02:00
2023-11-20 11:06:50 +01:00
2023-11-28 16:54:57 +00:00
2023-11-28 16:54:49 +00:00
2023-10-25 11:54:16 +02:00
2023-11-28 16:54:59 +00:00
2023-09-19 12:20:15 +02:00
2023-11-20 11:06:50 +01:00
2023-07-27 08:44:00 +02:00
2023-11-20 11:06:45 +01:00
2023-11-28 16:54:58 +00:00
2023-08-30 16:23:19 +02:00
2023-05-17 11:47:39 +02:00
2023-07-27 08:44:04 +02:00
2023-11-28 16:54:57 +00:00
2023-05-17 11:47:55 +02:00
2023-09-19 12:20:18 +02:00
2023-10-25 11:54:25 +02:00
2023-11-28 16:54:53 +00:00
2023-11-28 16:54:52 +00:00
2023-06-28 10:28:07 +02:00
2023-11-20 11:06:48 +01:00
2023-09-19 12:20:18 +02:00
2023-11-28 16:55:00 +00:00
2023-11-28 16:54:58 +00:00
2023-11-08 17:30:45 +01:00
2023-11-28 16:54:51 +00:00
2023-11-20 11:06:55 +01:00
2023-11-20 11:06:53 +01:00
2023-09-19 12:20:18 +02:00
2023-11-08 17:30:48 +01:00
2023-08-16 18:21:01 +02:00
2023-11-20 11:06:52 +01:00
2023-05-17 11:48:00 +02:00
2023-07-27 08:44:08 +02:00
2023-11-28 16:54:58 +00:00
2023-10-10 21:53:39 +02:00
2023-11-28 16:54:55 +00:00
2023-07-27 08:43:48 +02:00
2023-07-27 08:43:40 +02:00
2023-05-30 12:57:49 +01:00
2023-11-20 11:06:52 +01:00
2023-11-28 16:54:52 +00:00
2023-11-28 16:54:58 +00:00
2023-11-28 16:54:58 +00:00
2023-11-28 16:55:00 +00:00
2023-06-28 10:28:14 +02:00
2023-09-19 12:20:22 +02:00
2023-07-27 08:43:31 +02:00
2023-11-20 11:06:50 +01:00
2023-10-25 11:54:25 +02:00
2023-11-08 17:30:44 +01:00
2023-10-10 21:53:39 +02:00
2023-09-19 12:20:07 +02:00
2023-10-10 21:53:32 +02:00
2023-11-28 16:55:00 +00:00
2023-11-20 11:06:54 +01:00
2023-10-25 11:54:13 +02:00
2023-10-25 11:54:26 +02:00
2023-10-25 11:54:24 +02:00
2023-11-28 16:54:50 +00:00
2023-10-10 21:53:31 +02:00
2023-07-27 08:43:34 +02:00
2023-11-28 16:54:54 +00:00
2023-11-20 11:06:55 +01:00
2023-10-25 11:54:23 +02:00
2023-05-30 12:57:48 +01:00
2023-11-08 17:30:48 +01:00
2023-11-20 11:06:54 +01:00
2023-10-10 21:53:37 +02:00
2023-11-28 16:54:55 +00:00
2023-11-20 11:06:49 +01:00
2023-08-11 11:57:55 +02:00
2023-11-20 11:06:57 +01:00
2023-05-17 11:47:59 +02:00
2023-11-20 11:06:55 +01:00
2023-10-10 21:53:38 +02:00
2023-10-25 11:54:16 +02:00
2023-11-20 11:06:45 +01:00
2023-10-25 11:54:20 +02:00
2023-11-28 16:54:59 +00:00
2023-11-28 16:54:59 +00:00
2023-03-11 16:39:45 +01:00
2023-09-19 12:20:14 +02:00
2023-06-14 11:09:57 +02:00
2023-11-20 11:06:57 +01:00
2023-11-08 17:30:40 +01:00
2023-07-27 08:44:02 +02:00
2023-10-10 21:53:34 +02:00
2023-11-28 16:54:54 +00:00