public inbox for netdev@vger.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@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH 2/2] net: thunderbolt: Fix lockdep issue during tunnel tear down
Date: Mon, 27 Apr 2026 10:16:23 +0200	[thread overview]
Message-ID: <20260427081623.2338179-2-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20260427081623.2338179-1-mika.westerberg@linux.intel.com>

When unplugging cable with lockdep enabled it triggers following:

 ======================================================
 WARNING: possible circular locking dependency detected
 6.18.0-rc4+ #1636 Tainted: G S
 ------------------------------------------------------
 kworker/u56:2/416 is trying to acquire lock:
 ffff88818642c8a8 ((work_completion)(&ring->work)){+.+.}-{0:0}, at: __flush_work+0x562/0xde0

 but task is already holding lock:
 ffff888184b30fa8 (&net->connection_lock){+.+.}-{4:4}, at: tbnet_tear_down+0x110/0x6f0 [thunderbolt_net]

We actually don't need to net->hold the connection_lock any more than
necessary to figure out if the connection is up or not, and can return
early if it is not.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/net/thunderbolt/main.c | 59 +++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/drivers/net/thunderbolt/main.c b/drivers/net/thunderbolt/main.c
index 631af237998d..d8fcf18fc55c 100644
--- a/drivers/net/thunderbolt/main.c
+++ b/drivers/net/thunderbolt/main.c
@@ -372,48 +372,47 @@ static void tbnet_free_buffers(struct tbnet_ring *ring)
 
 static void tbnet_tear_down(struct tbnet *net, bool send_logout)
 {
+	int ret, retries = TBNET_LOGOUT_RETRIES;
+
 	netif_carrier_off(net->dev);
 	netif_stop_queue(net->dev);
 
 	stop_login(net);
 
 	mutex_lock(&net->connection_lock);
+	if (!net->login_sent || !net->login_received) {
+		mutex_unlock(&net->connection_lock);
+		return;
+	}
+	net->login_sent = false;
+	net->login_received = false;
+	mutex_unlock(&net->connection_lock);
 
-	if (net->login_sent && net->login_received) {
-		int ret, retries = TBNET_LOGOUT_RETRIES;
+	while (send_logout && retries-- > 0) {
+		netdev_dbg(net->dev, "sending logout request %u\n",
+			   retries);
+		ret = tbnet_logout_request(net);
+		if (ret != -ETIMEDOUT)
+			break;
+	}
 
-		while (send_logout && retries-- > 0) {
-			netdev_dbg(net->dev, "sending logout request %u\n",
-				   retries);
-			ret = tbnet_logout_request(net);
-			if (ret != -ETIMEDOUT)
-				break;
-		}
+	tb_ring_stop(net->rx_ring.ring);
+	tb_ring_stop(net->tx_ring.ring);
+	tbnet_free_buffers(&net->rx_ring);
+	tbnet_free_buffers(&net->tx_ring);
 
-		tb_ring_stop(net->rx_ring.ring);
-		tb_ring_stop(net->tx_ring.ring);
-		tbnet_free_buffers(&net->rx_ring);
-		tbnet_free_buffers(&net->tx_ring);
-
-		ret = tb_xdomain_disable_paths(net->xd,
-					       net->local_transmit_path,
-					       net->tx_ring.ring->hop,
-					       net->remote_transmit_path,
-					       net->rx_ring.ring->hop);
-		if (ret)
-			netdev_warn(net->dev, "failed to disable DMA paths\n");
-
-		tb_xdomain_release_in_hopid(net->xd, net->remote_transmit_path);
-		net->remote_transmit_path = 0;
-	}
+	ret = tb_xdomain_disable_paths(net->xd,
+				       net->local_transmit_path,
+				       net->tx_ring.ring->hop,
+				       net->remote_transmit_path,
+				       net->rx_ring.ring->hop);
+	if (ret)
+		netdev_warn(net->dev, "failed to disable DMA paths\n");
 
-	net->login_retries = 0;
-	net->login_sent = false;
-	net->login_received = false;
+	tb_xdomain_release_in_hopid(net->xd, net->remote_transmit_path);
+	net->remote_transmit_path = 0;
 
 	netdev_dbg(net->dev, "network traffic stopped\n");
-
-	mutex_unlock(&net->connection_lock);
 }
 
 static int tbnet_handle_packet(const void *buf, size_t size, void *data)
-- 
2.50.1


      reply	other threads:[~2026-04-27  8:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-27  8:16 [PATCH 1/2] net: thunderbolt: Call tbnet_stop() upon shutdown Mika Westerberg
2026-04-27  8:16 ` Mika Westerberg [this message]

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=20260427081623.2338179-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@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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