Alexander Sverdlin
5a22fbcc10
net: dsa: lan9303: consequently nested-lock physical MDIO
...
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>
2023-11-02 10:48:09 +01:00
..
2023-11-01 06:28:35 -10:00
2023-11-01 15:28:33 -10:00
2023-10-17 13:37:35 -05:00
2023-10-30 09:47:13 -10:00
2023-11-01 12:50:12 -10:00
2023-10-10 12:41:17 +02:00
2023-09-29 14:48:31 -07:00
2023-11-01 14:46:51 -10:00
2023-11-01 12:30:07 -10:00
2023-10-23 11:04:51 -07:00
2023-11-01 14:46:51 -10:00
2023-10-26 09:42:37 +02:00
2023-10-02 20:04:58 -06:00
2023-09-28 12:12:07 -06:00
2023-11-01 15:28:33 -10:00
2023-11-01 14:46:51 -10:00
2023-11-01 09:34:55 -10:00
2023-10-24 10:53:45 +02:00
2023-10-02 13:13:15 +02:00
2023-11-01 15:28:33 -10:00
2023-09-29 14:48:31 -07:00
2023-10-18 11:30:06 -04:00
2023-09-22 14:31:04 -07:00
2023-10-19 21:21:16 +09:00
2023-10-13 08:52:57 -07:00
2023-10-05 11:05:58 +02:00
2023-10-15 16:08:25 +01:00
2023-10-30 19:09:55 -10:00
2023-10-27 10:00:19 +09:00
2023-11-01 15:28:33 -10:00
2023-10-24 19:32:39 +02:00
2023-10-31 17:21:54 -10:00
2023-11-01 15:28:33 -10:00
2023-11-01 06:28:35 -10:00
2023-10-31 18:32:51 -10:00
2023-10-31 17:44:17 -10:00
2023-09-20 10:46:30 +01:00
2023-10-31 17:21:54 -10:00
2023-10-17 12:45:03 +02:00
2023-10-07 11:33:28 +02:00
2023-10-17 20:25:32 +01:00
2023-10-31 05:10:11 -10:00
2023-11-01 15:28:33 -10:00
2023-11-01 15:28:33 -10:00
2023-11-01 09:34:55 -10:00
2023-10-30 19:09:55 -10:00
2023-09-19 15:16:23 +01:00
2023-10-31 15:33:26 -10:00
2023-10-05 09:50:14 +02:00
2023-11-01 12:55:54 -10:00
2023-11-01 15:28:33 -10:00
2023-10-16 23:00:46 +02:00
2023-09-27 12:13:18 +02:00
2023-10-05 11:03:20 -07:00
2023-11-01 15:28:33 -10:00
2023-10-27 12:00:35 +02:00
2023-10-31 17:21:54 -10:00
2023-11-02 10:48:09 +01:00
2023-11-01 12:30:07 -10:00
2023-10-16 21:00:08 +02:00
2023-10-31 18:50:13 -10:00
2023-10-17 11:11:28 +05:30
2023-10-30 14:54:40 +01:00
2023-11-01 15:28:33 -10:00
2023-11-01 09:34:55 -10:00
2023-10-22 07:11:10 -10:00
2023-10-31 17:21:54 -10:00
2023-10-31 17:53:00 -10:00
2023-11-01 14:46:51 -10:00
2023-10-20 19:50:40 +02:00
2023-10-21 00:57:55 +02:00
2023-10-24 22:07:07 +02:00
2023-10-19 15:51:52 -07:00
2023-10-30 13:14:27 +00:00
2023-10-24 14:10:04 -07:00
2023-10-31 05:10:11 -10:00
2023-11-01 12:50:12 -10:00
2023-11-01 14:46:51 -10:00
2023-09-21 11:31:33 +02:00
2023-10-30 13:20:58 +00:00
2023-10-19 10:26:26 +03:00
2023-11-01 06:28:35 -10:00
2023-10-28 13:29:19 +02:00
2023-10-12 11:52:23 -07:00
2023-10-31 15:28:37 -10:00
2023-10-17 19:25:42 +02:00
2023-11-01 15:28:33 -10:00
2023-10-09 21:33:30 -04:00
2023-11-01 06:28:35 -10:00
2023-10-18 11:29:41 -04:00
2023-10-09 15:56:09 -06:00
2023-10-26 13:46:28 -07:00
2023-11-01 15:28:33 -10:00
2023-10-30 19:09:55 -10:00
2023-10-18 11:30:12 -04:00
2023-11-01 10:46:48 -10:00
2023-11-01 13:09:46 -10:00
2023-09-17 11:50:20 +01:00