linux/drivers/net/dsa
Daniel Golle 07d9958739 net: dsa: mt7530: fix .get_stats64 sleeping in atomic context
The .get_stats64 callback runs in atomic context, but on
MDIO-connected switches every register read acquires the MDIO bus
mutex, which can sleep:
[   12.645973] BUG: sleeping function called from invalid context at kernel/locking/mutex.c:609
[   12.654442] in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 759, name: grep
[   12.663377] preempt_count: 0, expected: 0
[   12.667410] RCU nest depth: 1, expected: 0
[   12.671511] INFO: lockdep is turned off.
[   12.675441] CPU: 0 UID: 0 PID: 759 Comm: grep Tainted: G S      W           7.0.0+ #0 PREEMPT
[   12.675453] Tainted: [S]=CPU_OUT_OF_SPEC, [W]=WARN
[   12.675456] Hardware name: Bananapi BPI-R64 (DT)
[   12.675459] Call trace:
[   12.675462]  show_stack+0x14/0x1c (C)
[   12.675477]  dump_stack_lvl+0x68/0x8c
[   12.675487]  dump_stack+0x14/0x1c
[   12.675495]  __might_resched+0x14c/0x220
[   12.675504]  __might_sleep+0x44/0x80
[   12.675511]  __mutex_lock+0x50/0xb10
[   12.675523]  mutex_lock_nested+0x20/0x30
[   12.675532]  mt7530_get_stats64+0x40/0x2ac
[   12.675542]  dsa_user_get_stats64+0x2c/0x40
[   12.675553]  dev_get_stats+0x44/0x1e0
[   12.675564]  dev_seq_printf_stats+0x24/0xe0
[   12.675575]  dev_seq_show+0x14/0x3c
[   12.675583]  seq_read_iter+0x37c/0x480
[   12.675595]  seq_read+0xd0/0xec
[   12.675605]  proc_reg_read+0x94/0xe4
[   12.675615]  vfs_read+0x98/0x29c
[   12.675625]  ksys_read+0x54/0xdc
[   12.675633]  __arm64_sys_read+0x18/0x20
[   12.675642]  invoke_syscall.constprop.0+0x54/0xec
[   12.675653]  do_el0_svc+0x3c/0xb4
[   12.675662]  el0_svc+0x38/0x200
[   12.675670]  el0t_64_sync_handler+0x98/0xdc
[   12.675679]  el0t_64_sync+0x158/0x15c

For MDIO-connected switches, poll MIB counters asynchronously using a
delayed workqueue every second and let .get_stats64 return the cached
values under a spinlock. A mod_delayed_work() call on each read
triggers an immediate refresh so counters stay responsive when queried
more frequently.

MMIO-connected switches (MT7988, EN7581, AN7583) are not affected
because their regmap does not sleep, so they continue to read MIB
counters directly in .get_stats64.

Fixes: 88c810f35e ("net: dsa: mt7530: implement .get_stats64")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Acked-by: Chester A. Unal <chester.a.unal@arinc9.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/6940b913da2c29156f0feff74b678d3c526ee84c.1777719253.git.daniel@makrotopia.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-05-04 19:28:54 -07:00
..
b53 net: dsa: b53: skip multicast entries for fdb_dump() 2025-12-27 17:17:32 +01:00
hirschmann Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
lantiq net: dsa: mxl-gsw1xx: validate chip ID 2026-02-10 09:09:27 +01:00
microchip net: dsa: microchip: drop an outdated comment about SGMII support 2026-03-26 18:55:19 -07:00
mv88e6xxx net: dsa: mv88e6xxx: Add partial support for TCAM entries 2026-03-17 10:35:20 +01:00
mxl862xx net: dsa: mxl862xx: implement .get_stats64 2026-04-13 16:46:43 -07:00
ocelot Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
qca net: dsa: qca8k: Use the right GPIO header 2026-03-29 11:49:21 -07:00
realtek net: dsa: realtek: rtl8365mb: fix mode mask calculation 2026-04-23 10:50:33 +02:00
sja1105 net: dsa: sja1105: ensure phylink_replay_link_end() will not be missed 2026-03-06 17:48:01 -08:00
xrs700x net: dsa: xrs700x: reject unsupported HSR configurations 2025-12-01 16:45:07 -08:00
bcm_sf2_cfp.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
bcm_sf2_regs.h
bcm_sf2.c net: dsa: bcm_sf2: fix missing clk_disable_unprepare() in error paths 2026-03-19 09:26:40 -07:00
bcm_sf2.h net: dsa: use ethtool string helpers 2024-11-03 10:36:34 -08:00
dsa_loop.c net: dsa: eliminate <linux/dsa/loop.h> 2026-04-08 19:38:52 -07:00
Kconfig net: dsa: add basic initial driver for MxL862xx switches 2026-02-11 11:27:58 +01:00
ks8995.c net: dsa: ks8995: Fix incorrect OF match table name 2025-11-18 18:22:04 -08:00
lan9303_i2c.c
lan9303_mdio.c
lan9303-core.c
lan9303.h
Makefile net: dsa: add basic initial driver for MxL862xx switches 2026-02-11 11:27:58 +01:00
mt7530-mdio.c net: pcs: pcs-mtk-lynxi: pass SGMIISYS OF node to PCS 2026-01-21 19:46:58 -08:00
mt7530-mmio.c net: dsa: mt7530: Constify struct regmap_config 2025-07-13 22:28:56 +01:00
mt7530.c net: dsa: mt7530: fix .get_stats64 sleeping in atomic context 2026-05-04 19:28:54 -07:00
mt7530.h net: dsa: mt7530: fix .get_stats64 sleeping in atomic context 2026-05-04 19:28:54 -07:00
mv88e6060.c net: dsa: mv88e6060: use simple HSR offload helpers 2025-12-01 16:45:08 -08:00
mv88e6060.h
rzn1_a5psw.c net: dsa: a5psw: use simple HSR offload helpers 2025-12-01 16:45:08 -08:00
rzn1_a5psw.h
vitesse-vsc73xx-core.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
vitesse-vsc73xx-platform.c
vitesse-vsc73xx-spi.c
vitesse-vsc73xx.h
yt921x.c net: dsa: move dsa_bridge_ports() helper to dsa.h 2026-04-06 18:30:33 -07:00
yt921x.h net: dsa: yt921x: Add DCB/QoS support 2026-02-03 15:09:31 +01:00