mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adi Prasan <itsadi2409@gmail.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: alex.aring@gmail.com, stefan@datenfreihafen.org,
	linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org,
	Adi Prasan <itsadi2409@gmail.com>
Subject: [PATCH v2] net: mac802154: fix race between slave_close() and in-flight async tx
Date: Fri,  2 Oct 2026 14:48:27 +0000	[thread overview]
Message-ID: <20261002144827.3479-1-itsadi2409@gmail.com> (raw)
In-Reply-To: <87ik3tn1nn.fsf@bootlin.com>

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().

Signed-off-by: Adi Prasan <itsadi2409@gmail.com>
---
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(-)

diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 31353795fa24..929ccd464772 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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;
 }
-- 
2.43.0


  reply	other threads:[~2026-10-02 14:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20 17:06 [PATCH] mac802154: synchronize pending transmissions before stopping the hardware Adi Prasan
2026-09-25  9:03 ` Miquel Raynal
2026-10-02 14:48   ` Adi Prasan [this message]
2026-10-04 14:46     ` [PATCH v2] net: mac802154: fix race between slave_close() and in-flight async tx Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261002144827.3479-1-itsadi2409@gmail.com \
    --to=itsadi2409@gmail.com \
    --cc=alex.aring@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wpan@vger.kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=stefan@datenfreihafen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®