From: "Mika Westerberg (Intel)" 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) --- 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