mac802154: synchronize pending transmissions before stopping the hardware
Subsystems (2)
PATCH 1/1 mac802154: synchronize pending transmissions before stopping the hardware
From: Adi <[email protected]>
syzbot reports a WARN_ON(current_phy->suspended) splat in mac80211_hwsim's mac802154 counterpart, hwsim_hw_xmit():
WARNING: CPU: 0 PID: 6038 at drivers/net/ieee802154/mac802154_hwsim.c:266 hwsim_hw_xmit+0xcbf/0x1540 Call Trace: drv_xmit_async ieee802154_tx ieee802154_subif_start_xmit __netdev_start_xmit ... packet_sendmsg
mac802154_slave_close() only calls netif_stop_queue() on the closing netdev before tearing the hardware down via ieee802154_stop_device(), which calls straight into drv_stop(). netif_stop_queue() merely marks the queue as stopped; it does not wait for a transmission that a different CPU already passed the "is the queue stopped" check for and is currently executing inside ndo_start_xmit(). That thread can still be inside drv_xmit_async() -> hwsim_hw_xmit() by the time drv_stop() runs and marks the phy suspended, which trips the WARN_ON() (and, on real hardware, could still start a transmission after ->stop() has torn down the transceiver).
ieee802154_suspend() already knows about this and synchronizes with any in-flight transmission via ieee802154_sync_and_hold_queue() plus synchronize_net() before calling ieee802154_stop_device(), releasing the queue again afterwards. mac802154_slave_close() is missing the same synchronization when the last open interface on a phy is closed.
Do the same hold/sync/release dance in mac802154_slave_close() so drv_stop() cannot race with a transmission that is already in flight.
--- net/mac802154/iface.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
net/mac802154/iface.c +12 -1
@@ -313,8 +313,19 @@ static int mac802154_slave_close(struct net_device *dev)clear_bit (SDATA_STATE_RUNNING , &sdata->state); -if (!local->open_count) +if (!local->open_count) { +/* Ensure any asynchronous transmission already accepted by +* the driver (i.e. past the netif_stop_queue() above) has +* fully completed before calling into ->stop(). Otherwise +* drv_xmit_async() can race with drv_stop(), which some +* drivers (e.g. mac802154_hwsim) do not expect. This mirrors +* the synchronization already done in ieee802154_suspend(). +*/ +ieee802154_sync_and_hold_queue (local); +synchronize_net ();ieee802154_stop_device (local); +ieee802154_release_queue (local); + }return 0 ; }
Signature · 1 line
2.43.0
Miquel Raynal
maintainerHi Adi,
Quoted 32 lines · Adi Prasan
From: Adi <[email protected]>
syzbot reports a
WARN_ON(current_phy->suspended)splat in mac80211_hwsim's mac802154 counterpart,hwsim_hw_xmit():WARNING: CPU: 0 PID: 6038 at drivers/net/ieee802154/mac802154_hwsim.c:266 hwsim_hw_xmit+0xcbf/0x1540 Call Trace: drv_xmit_async ieee802154_tx ieee802154_subif_start_xmit __netdev_start_xmit ... packet_sendmsg
mac802154_slave_close()only callsnetif_stop_queue()on the closing netdev before tearing the hardware down viaieee802154_stop_device(), which calls straight intodrv_stop().netif_stop_queue()merely marks the queue as stopped; it does not wait for a transmission that a different CPU already passed the "is the queue stopped" check for and is currently executing insidendo_start_xmit(). That thread can still be insidedrv_xmit_async()->hwsim_hw_xmit()by the timedrv_stop()runs and marks the phy suspended, which trips theWARN_ON()(and, on real hardware, could still start a transmission after ->stop() has torn down the transceiver).
ieee802154_suspend()already knows about this and synchronizes with any in-flight transmission viaieee802154_sync_and_hold_queue()plussynchronize_net()before callingieee802154_stop_device(), releasing the queue again afterwards.mac802154_slave_close()is missing the same synchronization when the last open interface on a phy is closed.
Quoted 6 lines
Do the same hold/sync/release dance in
mac802154_slave_close()sodrv_stop()cannot race with a transmission that is already in flight.Reported-by [email protected]Signed-off-by Adi <[email protected]>
We need your real identify.
Quoted 9 lines
--- net/mac802154/iface.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)net/mac802154/iface.c +0
-0
net/mac802154/iface.c static int mac802154_slave_close(struct net_device *dev) · line 321
Quoted 10 lines
net/mac802154/iface.c +6
-1@@ -313,8 +313,19 @@ static int mac802154_slave_close(struct net_device *dev)clear_bit (SDATA_STATE_RUNNING , &sdata->state); -if (!local->open_count) +if (!local->open_count) { +/* Ensure any asynchronous transmission already accepted by +* the driver (i.e. past the netif_stop_queue() above) has +* fully completed before calling into ->stop(). Otherwise +* drv_xmit_async() can race with drv_stop(), which some +* drivers (e.g. mac802154_hwsim) do not expect.
hwsim is for testing purposes, not sure this is a real use case.
net/mac802154/iface.c static int mac802154_slave_close(struct net_device *dev) · line 323
Quoted 3 lines
This mirrors
net/mac802154/iface.c +2
-0+* the synchronization already done in ieee802154_suspend(). +*/
This message is 100% AI generated and can be dropped, unless there is a real info carried, but I don't see it.
Yet, if we can get rid of these by just fixing max802154_hwsim, please do it.
net/mac802154/iface.c static int mac802154_slave_close(struct net_device *dev) · line 331
Quoted 8 lines
net/mac802154/iface.c +4
-0+ieee802154_sync_and_hold_queue (local); +synchronize_net ();ieee802154_stop_device (local); +ieee802154_release_queue (local); + }return 0 ; }
Thanks,
Miquèl
PATCH v2 1/1 net: mac802154: fix race between slave_close() and in-flight async tx
netif_stop_queue() prevents new packets from being sent to the driver, but it does not wait for a transmission that is already in progress.
drv_xmit_async() can still be running on another CPU when mac802154_slave_close() calls drv_stop(). Stopping the queue only prevents new transmissions; it does not synchronize with an already running tx operation.
This was checked against mac802154_hwsim as well. hwsim_hw_xmit() is synchronous, while hwsim_hw_stop() only sets a flag, so there is no pending work or locking in the driver that needs to be synchronized.
The race is in the core between stopping the queue and an in-flight tx operation. The fix therefore belongs in the common mac802154 code, using the same handling already used by ieee802154_suspend(): hold and synchronize the queue around ieee802154_stop_device().
---
v2: Dropped the explanatory code comment per review feedback; expanded
the commit message to explain why the fix stays in net/mac802154/iface.c rather than mac802154_hwsim. Fixed the Author/Signed-off-by name.
net/mac802154/iface.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/mac802154/iface.c +5 -1
@@ -313,8 +313,12 @@ static int mac802154_slave_close(struct net_device *dev)clear_bit (SDATA_STATE_RUNNING , &sdata->state); -if (!local->open_count) +if (!local->open_count) { +ieee802154_sync_and_hold_queue (local); +synchronize_net ();ieee802154_stop_device (local); +ieee802154_release_queue (local); + }return 0 ; }
Signature · 1 line
2.43.0
Re: [PATCH v2] net: mac802154: fix race between slave_close() and in-flight async tx
Quoted 12 lines · Adi Prasan
netif_stop_queue()prevents new packets from being sent to the driver, but it does not wait for a transmission that is already in progress.
drv_xmit_async()can still be running on another CPU whenmac802154_slave_close()callsdrv_stop(). Stopping the queue only prevents new transmissions; it does not synchronize with an already running tx operation.This was checked against
mac802154_hwsimas well.hwsim_hw_xmit()is synchronous, whilehwsim_hw_stop()only sets a flag, so there is no pending work or locking in the driver that needs to be synchronized.
Quoted 6 lines
The race is in the core between stopping the queue and an in-flight tx operation. The fix therefore belongs in the common mac802154 code, using the same handling already used by
ieee802154_suspend(): hold and synchronize the queue aroundieee802154_stop_device().Signed-off-by Adi Prasan <[email protected]>