All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: netdev@vger.kernel.org
Cc: Yehezkel Bernat <YehezkelShB@gmail.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Mika Westerberg <westeri@kernel.org>
Subject: [PATCH v3 1/4] net: thunderbolt: Fix race condition when the link is torn down
Date: Mon, 30 Nov 2026 12:36:54 +0100	[thread overview]
Message-ID: <20261130113657.3440005-2-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20261130113657.3440005-1-mika.westerberg@linux.intel.com>

From: "Mika Westerberg (Intel)" <westeri@kernel.org>

When the link is torn down tbnet_tear_down() cancels connected_work
before taking connection_lock, but a ThunderboltIP login from the peer
can queue it again right after. That connected_work can run concurrently
with the teardown and restart the rings after they were stopped and the
buffers released.

Fix this by disabling login_work and connected_work for the duration of
the teardown, and release the data path resources only when the carrier
is on, which tbnet_connected_work() sets once they all are set up.

Fixes: e69b6c02b4c3 ("net: Add support for networking over Thunderbolt cable")
Cc: stable@vger.kernel.org
Signed-off-by: Mika Westerberg (Intel) <westeri@kernel.org>
---
 drivers/net/thunderbolt/main.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/net/thunderbolt/main.c b/drivers/net/thunderbolt/main.c
index cf51b9c39f4e..ede105cdc3a3 100644
--- a/drivers/net/thunderbolt/main.c
+++ b/drivers/net/thunderbolt/main.c
@@ -368,15 +368,22 @@ static void tbnet_free_buffers(struct tbnet_ring *ring)
 
 static void tbnet_tear_down(struct tbnet *net, bool send_logout)
 {
-	netif_carrier_off(net->dev);
-	netif_stop_queue(net->dev);
+	bool connected;
+	int ret;
 
-	stop_login(net);
+	disable_delayed_work_sync(&net->login_work);
+	disable_work_sync(&net->connected_work);
 
 	mutex_lock(&net->connection_lock);
 
+	connected = netif_carrier_ok(net->dev) && net->login_sent &&
+		    net->login_received;
+
+	netif_carrier_off(net->dev);
+	netif_stop_queue(net->dev);
+
 	if (net->login_sent && net->login_received) {
-		int ret, retries = TBNET_LOGOUT_RETRIES;
+		int retries = TBNET_LOGOUT_RETRIES;
 
 		while (send_logout && retries-- > 0) {
 			netdev_dbg(net->dev, "sending logout request %u\n",
@@ -385,7 +392,9 @@ static void tbnet_tear_down(struct tbnet *net, bool send_logout)
 			if (ret != -ETIMEDOUT)
 				break;
 		}
+	}
 
+	if (connected) {
 		/* Tear the paths down before stopping the rings.  This mirrors
 		 * tbnet_connected_work(), which enables the paths last so the
 		 * Rx ring is primed before packets can arrive.  Stopping a
@@ -419,6 +428,9 @@ static void tbnet_tear_down(struct tbnet *net, bool send_logout)
 
 	netdev_dbg(net->dev, "network traffic stopped\n");
 
+	enable_work(&net->connected_work);
+	enable_delayed_work(&net->login_work);
+
 	mutex_unlock(&net->connection_lock);
 }
 
@@ -645,7 +657,8 @@ static void tbnet_connected_work(struct work_struct *work)
 		return;
 
 	mutex_lock(&net->connection_lock);
-	connected = net->login_sent && net->login_received;
+	connected = net->login_sent && net->login_received &&
+		   netif_running(net->dev) && netif_device_present(net->dev);
 	mutex_unlock(&net->connection_lock);
 
 	if (!connected)
-- 
2.50.1


  reply	other threads:[~2026-11-30 11:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 11:36 [PATCH v3 0/4] net: thunderbolt: Various fixes Mika Westerberg
2026-11-30 11:36 ` Mika Westerberg [this message]
2026-12-01 12:17   ` [PATCH v3 1/4] net: thunderbolt: Fix race condition when the link is torn down netdev-bot+sashiko
2026-11-30 11:36 ` [PATCH v3 2/4] net: thunderbolt: Stop queueing Rx buffers if allocation fails Mika Westerberg
2026-12-01 12:17   ` netdev-bot+sashiko
2026-11-30 11:36 ` [PATCH v3 3/4] net: thunderbolt: Prevent Tx descriptor leak in tbnet_start_xmit() Mika Westerberg
2026-11-30 11:36 ` [PATCH v3 4/4] net: thunderbolt: Free partially completed skb when the link is torn down Mika Westerberg
2026-11-30 11:39 ` [PATCH v3 0/4] net: thunderbolt: Various fixes netdev-bot+sinfo

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=20261130113657.3440005-2-mika.westerberg@linux.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=YehezkelShB@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=westeri@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.