lan966x: Fix sleeping in atomic context
Subsystems (3)
Horatiu Vultur
maintainerPATCH 1/1 lan966x: Fix sleeping in atomic context
The following warning was seen when we try to connect using ssh to the device.
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:575 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 104, name: dropbear preempt_count: 1, expected: 0 INFO: lockdep is turned off. CPU: 0 UID: 0 PID: 104 Comm: dropbear Tainted: G W 6.18.0-rc2-00399-g6f1ab1b109b9-dirty #530 NONE Tainted: [W]=WARN Hardware name: Generic DT based system Call trace: unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x7c/0xac dump_stack_lvl from __might_resched+0x16c/0x2b0 __might_resched from __mutex_lock+0x64/0xd34 __mutex_lock from mutex_lock_nested+0x1c/0x24 mutex_lock_nested from lan966x_stats_get+0x5c/0x558 lan966x_stats_get from dev_get_stats+0x40/0x43c dev_get_stats from dev_seq_printf_stats+0x3c/0x184 dev_seq_printf_stats from dev_seq_show+0x10/0x30 dev_seq_show from seq_read_iter+0x350/0x4ec seq_read_iter from seq_read+0xfc/0x194 seq_read from proc_reg_read+0xac/0x100 proc_reg_read from vfs_read+0xb0/0x2b0 vfs_read from ksys_read+0x6c/0xec ksys_read from ret_fast_syscall+0x0/0x1c Exception stack(0xf0b11fa8 to 0xf0b11ff0)
1fa0: 00000001 00001000 00000008 be9048d8 00001000 00000001
1fc0: 00000001 00001000 00000008 00000003 be905920 0000001e 00000000 00000001 1fe0: 0005404c be9048c0 00018684 b6ec2cd8
It seems that we are using a mutex in a atomic context which is wrong. Change the mutex with a spinlock.
--- .../microchip/lan966x/lan966x_ethtool.c | 18 +++++++++--------- .../ethernet/microchip/lan966x/lan966x_main.c | 2 -- .../ethernet/microchip/lan966x/lan966x_main.h | 4 ++-- .../microchip/lan966x/lan966x_vcap_impl.c | 8 ++++---- 4 files changed, 15 insertions(+), 17 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c +9 -9
@@ -294,7 +294,7 @@ static void lan966x_stats_update(struct lan966x *lan966x) {int i, j; -mutex_lock (&lan966x->stats_lock); +spin_lock (&lan966x->stats_lock);for (i =0 ; i < lan966x->num_phys_ports; i++) {uint idx = i * lan966x->num_stats;
@@ -310,7 +310,7 @@ static void lan966x_stats_update(struct lan966x *lan966x) } } -mutex_unlock (&lan966x->stats_lock); +spin_unlock (&lan966x->stats_lock); }static int lan966x_get_sset_count (struct net_device *dev,int sset)
@@ -365,7 +365,7 @@ static void lan966x_get_eth_mac_stats(struct net_device *dev, idx = port->chip_port * lan966x->num_stats; -mutex_lock (&lan966x->stats_lock); +spin_lock (&lan966x->stats_lock); mac_stats->FramesTransmittedOK = lan966x->stats[idx + SYS_COUNT_TX_UC] +
@@ -416,7 +416,7 @@ static void lan966x_get_eth_mac_stats(struct net_device *dev, lan966x->stats[idx +SYS_COUNT_RX_LONG ] + lan966x->stats[idx +SYS_COUNT_RX_PMAC_LONG ]; -mutex_unlock (&lan966x->stats_lock); +spin_unlock (&lan966x->stats_lock); }static const struct ethtool_rmon_hist_range lan966x_rmon_ranges[] = {
@@ -442,7 +442,7 @@ static void lan966x_get_eth_rmon_stats(struct net_device *dev, idx = port->chip_port * lan966x->num_stats; -mutex_lock (&lan966x->stats_lock); +spin_lock (&lan966x->stats_lock); rmon_stats->undersize_pkts = lan966x->stats[idx + SYS_COUNT_RX_SHORT] +
@@ -500,7 +500,7 @@ static void lan966x_get_eth_rmon_stats(struct net_device *dev, lan966x->stats[idx +SYS_COUNT_TX_SZ_1024_1526 ] + lan966x->stats[idx +SYS_COUNT_TX_PMAC_SZ_1024_1526 ]; -mutex_unlock (&lan966x->stats_lock); +spin_unlock (&lan966x->stats_lock); *ranges = lan966x_rmon_ranges; }
@@ -603,7 +603,7 @@ void lan966x_stats_get(struct net_device *dev, idx = port->chip_port * lan966x->num_stats; -mutex_lock (&lan966x->stats_lock); +spin_lock (&lan966x->stats_lock); stats->rx_bytes = lan966x->stats[idx +SYS_COUNT_RX_OCT ] + lan966x->stats[idx +SYS_COUNT_RX_PMAC_OCT ];
@@ -685,7 +685,7 @@ void lan966x_stats_get(struct net_device *dev, stats->collisions = lan966x->stats[idx +SYS_COUNT_TX_COL ]; -mutex_unlock (&lan966x->stats_lock); +spin_unlock (&lan966x->stats_lock); }int lan966x_stats_init (struct lan966x *lan966x)
@@ -701,7 +701,7 @@ int lan966x_stats_init(struct lan966x *lan966x)return -ENOMEM ;/* Init stats worker */ -mutex_init (&lan966x->stats_lock); +spin_lock_init (&lan966x->stats_lock);snprintf (queue_name,sizeof (queue_name),"%s-stats" ,dev_name (lan966x->dev)); lan966x->stats_queue =create_singlethread_workqueue (queue_name);
drivers/net/ethernet/microchip/lan966x/lan966x_main.c +0 -2
@@ -1261,7 +1261,6 @@ static int lan966x_probe(struct platform_device *pdev)cancel_delayed_work_sync (&lan966x->stats_work);destroy_workqueue (lan966x->stats_queue); -mutex_destroy (&lan966x->stats_lock);debugfs_remove_recursive (lan966x->debugfs_root);
@@ -1279,7 +1278,6 @@ static void lan966x_remove(struct platform_device *pdev)cancel_delayed_work_sync (&lan966x->stats_work);destroy_workqueue (lan966x->stats_queue); -mutex_destroy (&lan966x->stats_lock);lan966x_mac_purge_entries (lan966x);lan966x_mdb_deinit (lan966x);
drivers/net/ethernet/microchip/lan966x/lan966x_main.h +2 -2
@@ -295,8 +295,8 @@ struct lan966x {const struct lan966x_stat_layout *stats_layout;u32 num_stats; -/* workqueue for reading stats */ -struct mutex stats_lock; +/* lock for reading stats */ +spinlock_t stats_lock;u64 *stats;struct delayed_work stats_work;struct workqueue_struct *stats_queue;
drivers/net/ethernet/microchip/lan966x/lan966x_vcap_impl.c +4 -4
@@ -403,11 +403,11 @@ static void lan966x_es0_read_esdx_counter(struct lan966x *lan966x,u32 counter; id = id &0xff ;/* counter limit */ -mutex_lock (&lan966x->stats_lock); +spin_lock (&lan966x->stats_lock);lan_wr (SYS_STAT_CFG_STAT_VIEW_SET (id), lan966x,SYS_STAT_CFG ); counter =lan_rd (lan966x,SYS_CNT (LAN966X_STAT_ESDX_GRN_PKTS )) +lan_rd (lan966x,SYS_CNT (LAN966X_STAT_ESDX_YEL_PKTS )); -mutex_unlock (&lan966x->stats_lock); +spin_unlock (&lan966x->stats_lock);if (counter) admin->cache.counter = counter; }
@@ -417,14 +417,14 @@ static void lan966x_es0_write_esdx_counter(struct lan966x *lan966x, { id = id &0xff ;/* counter limit */ -mutex_lock (&lan966x->stats_lock); +spin_lock (&lan966x->stats_lock);lan_wr (SYS_STAT_CFG_STAT_VIEW_SET (id), lan966x,SYS_STAT_CFG );lan_wr (0 , lan966x,SYS_CNT (LAN966X_STAT_ESDX_GRN_BYTES ));lan_wr (admin->cache.counter, lan966x,SYS_CNT (LAN966X_STAT_ESDX_GRN_PKTS ));lan_wr (0 , lan966x,SYS_CNT (LAN966X_STAT_ESDX_YEL_BYTES ));lan_wr (0 , lan966x,SYS_CNT (LAN966X_STAT_ESDX_YEL_PKTS )); -mutex_unlock (&lan966x->stats_lock); +spin_unlock (&lan966x->stats_lock); } static void lan966x_vcap_cache_write(struct net_device *dev,
Signature · 1 line
2.34.1
Quoted 26 lines · Horatiu Vultur
The following warning was seen when we try to connect using ssh to the device.
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:575 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 104, name: dropbear preempt_count: 1, expected: 0 INFO: lockdep is turned off. CPU: 0 UID: 0 PID: 104 Comm: dropbear Tainted: G W 6.18.0-rc2-00399-g6f1ab1b109b9-dirty #530 NONE Tainted: [W]=WARN Hardware name: Generic DT based system Call trace: unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x7c/0xac dump_stack_lvl from __might_resched+0x16c/0x2b0 __might_resched from __mutex_lock+0x64/0xd34 __mutex_lock from mutex_lock_nested+0x1c/0x24 mutex_lock_nested from lan966x_stats_get+0x5c/0x558 lan966x_stats_get from dev_get_stats+0x40/0x43c dev_get_stats from dev_seq_printf_stats+0x3c/0x184 dev_seq_printf_stats from dev_seq_show+0x10/0x30 dev_seq_show from seq_read_iter+0x350/0x4ec seq_read_iter from seq_read+0xfc/0x194 seq_read from proc_reg_read+0xac/0x100 proc_reg_read from vfs_read+0xb0/0x2b0 vfs_read from ksys_read+0x6c/0xec ksys_read from ret_fast_syscall+0x0/0x1c Exception stack(0xf0b11fa8 to 0xf0b11ff0)
Quoted 7 lines
1fa0: 00000001 00001000 00000008
be9048d800001000 00000001
1fc0: 00000001 00001000 00000008 00000003be9059200000001e00000000 00000001 1fe0:0005404cbe9048c000018684b6ec2cd8It seems that we are using a mutex in a atomic context which is wrong. Change the mutex with a spinlock.
Its a bit hard from just the diff context to confirm that a spinlock is ok. I checked all the uses of stats_lock and they appear to be covering only simple register reads and counter accumulations. None of the blocks looked terribly lock, so a spin lock is probably fine.
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 26 lines · On Wed, 5 Nov 2025 08:49:55 +0100 you wrote:
The following warning was seen when we try to connect using ssh to the device.
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:575 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 104, name: dropbear preempt_count: 1, expected: 0 INFO: lockdep is turned off. CPU: 0 UID: 0 PID: 104 Comm: dropbear Tainted: G W 6.18.0-rc2-00399-g6f1ab1b109b9-dirty #530 NONE Tainted: [W]=WARN Hardware name: Generic DT based system Call trace: unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x7c/0xac dump_stack_lvl from __might_resched+0x16c/0x2b0 __might_resched from __mutex_lock+0x64/0xd34 __mutex_lock from mutex_lock_nested+0x1c/0x24 mutex_lock_nested from lan966x_stats_get+0x5c/0x558 lan966x_stats_get from dev_get_stats+0x40/0x43c dev_get_stats from dev_seq_printf_stats+0x3c/0x184 dev_seq_printf_stats from dev_seq_show+0x10/0x30 dev_seq_show from seq_read_iter+0x350/0x4ec seq_read_iter from seq_read+0xfc/0x194 seq_read from proc_reg_read+0xac/0x100 proc_reg_read from vfs_read+0xb0/0x2b0 vfs_read from ksys_read+0x6c/0xec ksys_read from ret_fast_syscall+0x0/0x1c Exception stack(0xf0b11fa8 to 0xf0b11ff0)
Quoted 5 lines
1fa0: 00000001 00001000 00000008
be9048d800001000 00000001
1fc0: 00000001 00001000 00000008 00000003be9059200000001e00000000 00000001 1fe0:0005404cbe9048c000018684b6ec2cd8[...]
Here is the summary with links:
- [net] lan966x: Fix sleeping in atomic context
https://git.kernel.org/netdev/net/c/0216721ce712
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html