Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9176880pxu; Mon, 28 Dec 2020 08:29:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1ouzmyi64GOsv5/3MLNPfMvG6grDli/NvGSueRGIj1hcTpv5qbwjQt2LAkjd/+OfMz+7l X-Received: by 2002:aa7:d0c5:: with SMTP id u5mr41503192edo.46.1609172975071; Mon, 28 Dec 2020 08:29:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609172975; cv=none; d=google.com; s=arc-20160816; b=A/7OhyNKAYjSlRn0iD8dkwGBReHMWZKPIj2g7+YTXAl8znsPID4RNm1QyTtYEtcomZ AIufFTgW2cJsHXztlk0I1NvK9FtM55IMYKgQflAY82Ck+Mk9pZlKnEgO1zkOEgfTnLrm Qu+ys7q4y7gM5oip72A77LzJnFUvy2+0pIz3/WU8B7MUZx4NqynLwTSZmjoc8eXLBkEL Rhf5vybjihm8UUs8IPEtthfU5C/rKsduqmwGzkD4Cdd5JPG3Y3NrNVO2ZX4S99gwQ69J BBM9n8kTZN6+a6bP3lJSyaenjF/HW5diUvsFq2fGo+ujbGQjeIwRRM9SkEAkIa3ZLZ9A 5jRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=O3E5gTkvOjvpeDNULPKF5xUbTYRVnM9z51T/5zl5794=; b=ZOn4+I5ks/QkBwT0sskTxCFiucsnsiXKVDBFGlWQ08E7IHFgwOKv6E2gYJAU6drwJE vW21RNaHIyDk821qxlusqXa13Fz8flxirBNk/POJyOT3douZkaDI2qgPdTjpDTWveuhU VDDzGQuNInIhJDxEwmsvoZSeTKbHm4uoWyjisSt7UZF5fwBI9HIjrd2SVUJhKuhKeoSb eCBXOgrVyL4cy3o10krhcpyZAfQLp1X0VmfI5NiZQGsLDnbzqaYx8LS1hqK8X28j3zQA UG9CGBArvggKmTYZJRo+7lDOrQnVpX0VaYMhZt0neKzo4gfOS3lgFEU2j9b6Bqqfc8Ze xHqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PdXw0x9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si18015985ejf.698.2020.12.28.08.29.09; Mon, 28 Dec 2020 08:29:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PdXw0x9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2633309AbgL1Q1j (ORCPT + 99 others); Mon, 28 Dec 2020 11:27:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:36018 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730893AbgL1NIT (ORCPT ); Mon, 28 Dec 2020 08:08:19 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3FD232242A; Mon, 28 Dec 2020 13:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160857; bh=pm2huu2Z72gk00xjWAXQG5QhEIA27tHDi5N8MBYVjPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PdXw0x9ns5UWUn0K+Mr+jLBSH27HfLCYQfiH3kGFdF6aCBNsu+1E5zRmr5oZDUOl7 bvlq254bM6pCr1Vd4HCHQCPdnl7A9TjrWXWfGfrHIh1Amz7gEn2qWfGW2jhkY4yHIM Dm38ZT+mi6j0+59gOb7oHr7gAUozVh79tk9AbouQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Moshe Shemesh , Tariq Toukan , "David S. Miller" Subject: [PATCH 4.14 019/242] net/mlx4_en: Avoid scheduling restart task if it is already running Date: Mon, 28 Dec 2020 13:47:04 +0100 Message-Id: <20201228124905.612749029@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Moshe Shemesh [ Upstream commit fed91613c9dd455dd154b22fa8e11b8526466082 ] Add restarting state flag to avoid scheduling another restart task while such task is already running. Change task name from watchdog_task to restart_task to better fit the task role. Fixes: 1e338db56e5a ("mlx4_en: Fix a race at restart task") Signed-off-by: Moshe Shemesh Signed-off-by: Tariq Toukan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 20 +++++++++++++------- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 7 ++++++- 2 files changed, 19 insertions(+), 8 deletions(-) --- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c @@ -1389,8 +1389,10 @@ static void mlx4_en_tx_timeout(struct ne } priv->port_stats.tx_timeout++; - en_dbg(DRV, priv, "Scheduling watchdog\n"); - queue_work(mdev->workqueue, &priv->watchdog_task); + if (!test_and_set_bit(MLX4_EN_STATE_FLAG_RESTARTING, &priv->state)) { + en_dbg(DRV, priv, "Scheduling port restart\n"); + queue_work(mdev->workqueue, &priv->restart_task); + } } @@ -1839,6 +1841,7 @@ int mlx4_en_start_port(struct net_device local_bh_enable(); } + clear_bit(MLX4_EN_STATE_FLAG_RESTARTING, &priv->state); netif_tx_start_all_queues(dev); netif_device_attach(dev); @@ -2009,7 +2012,7 @@ void mlx4_en_stop_port(struct net_device static void mlx4_en_restart(struct work_struct *work) { struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, - watchdog_task); + restart_task); struct mlx4_en_dev *mdev = priv->mdev; struct net_device *dev = priv->dev; @@ -2388,7 +2391,7 @@ static int mlx4_en_change_mtu(struct net if (netif_running(dev)) { mutex_lock(&mdev->state_lock); if (!mdev->device_up) { - /* NIC is probably restarting - let watchdog task reset + /* NIC is probably restarting - let restart task reset * the port */ en_dbg(DRV, priv, "Change MTU called with card down!?\n"); } else { @@ -2397,7 +2400,9 @@ static int mlx4_en_change_mtu(struct net if (err) { en_err(priv, "Failed restarting port:%d\n", priv->port); - queue_work(mdev->workqueue, &priv->watchdog_task); + if (!test_and_set_bit(MLX4_EN_STATE_FLAG_RESTARTING, + &priv->state)) + queue_work(mdev->workqueue, &priv->restart_task); } } mutex_unlock(&mdev->state_lock); @@ -2883,7 +2888,8 @@ static int mlx4_xdp_set(struct net_devic if (err) { en_err(priv, "Failed starting port %d for XDP change\n", priv->port); - queue_work(mdev->workqueue, &priv->watchdog_task); + if (!test_and_set_bit(MLX4_EN_STATE_FLAG_RESTARTING, &priv->state)) + queue_work(mdev->workqueue, &priv->restart_task); } } @@ -3284,7 +3290,7 @@ int mlx4_en_init_netdev(struct mlx4_en_d priv->counter_index = MLX4_SINK_COUNTER_INDEX(mdev->dev); spin_lock_init(&priv->stats_lock); INIT_WORK(&priv->rx_mode_task, mlx4_en_do_set_rx_mode); - INIT_WORK(&priv->watchdog_task, mlx4_en_restart); + INIT_WORK(&priv->restart_task, mlx4_en_restart); INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate); INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats); INIT_DELAYED_WORK(&priv->service_task, mlx4_en_service_task); --- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h @@ -525,6 +525,10 @@ struct mlx4_en_stats_bitmap { struct mutex mutex; /* for mutual access to stats bitmap */ }; +enum { + MLX4_EN_STATE_FLAG_RESTARTING, +}; + struct mlx4_en_priv { struct mlx4_en_dev *mdev; struct mlx4_en_port_profile *prof; @@ -590,7 +594,7 @@ struct mlx4_en_priv { struct mlx4_en_cq *rx_cq[MAX_RX_RINGS]; struct mlx4_qp drop_qp; struct work_struct rx_mode_task; - struct work_struct watchdog_task; + struct work_struct restart_task; struct work_struct linkstate_task; struct delayed_work stats_task; struct delayed_work service_task; @@ -637,6 +641,7 @@ struct mlx4_en_priv { u32 pflags; u8 rss_key[MLX4_EN_RSS_KEY_SIZE]; u8 rss_hash_fn; + unsigned long state; }; enum mlx4_en_wol {