Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7280584imu; Wed, 14 Nov 2018 14:47:37 -0800 (PST) X-Google-Smtp-Source: AJdET5ftrXroTGCU+USVP8+TvD1TATSi2a7PS681pkfXB7w/z9/8VsPIsHr8FLjJG2zBUkh+j1fl X-Received: by 2002:a63:dd55:: with SMTP id g21mr3445646pgj.86.1542235657888; Wed, 14 Nov 2018 14:47:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235657; cv=none; d=google.com; s=arc-20160816; b=KgvIi857kIJgIOmdF52+g2xhIKAfqWVcsYc42iHz9cyxccidkQEf709DW2JegaAw39 uITWlVfVAoq3UqcNFm6dO9YxLidYl3ei+KWh2UyqLBHPPDB+Ie/IClFtebo07mHYH/IJ MatJDTj2k8mhC5J8jRHTc/I8ArdYy3Gea6gj7Wr8JT8UzJHQdbO6FoCgZ1wOdNG96pyL N2Ikpdi0mTeoR3GTtqb8n2UHZqjgcUHmP2vZpVM4K5IR72rbA+WahenfILzTCXHbT3uW P6joTIQd+IGFy32eHW8TCvAyYeBgZdRtl5Rl/voEuWUP/CwOmu9BOFfziQyvivHeDDik WgGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=H0a9xmkNsaBCSrLmo5jHxmcvOOS5rHjicSf6fiebdfQ=; b=AhwAfWpn0wyt3mGp6q/nfbQOB98VgBjiTba91rQISGy8O0eDzYGTwV5SupcEi9ZwLZ 37nrFP+JE2fnxG5FqwbmOCoUxoDVSHy3AoK4jDXY2qOWbwcu7SdlYAN+qKjIvsHTdF9N JQeE1+7q1fIvHq4KSulXFSxHZGgJ2JxVO4xDi3l4qerV9CW9iT5UY/MLPWbQXK6hPgdE ppl7ecqmZ+KPuUXB5m3wj73ndC4A1h3DaRIDX0WTi4NvzQ6DVJe8WB0uG0KkU23IFYW5 pTN2QONenNg0plSHe4PNBve8W9ApywP5dk4Vqp/5b84z+JMLG7F3Yidn8k/uE/U9uGp4 EKcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QjCFDEsg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si24632865pgm.154.2018.11.14.14.47.23; Wed, 14 Nov 2018 14:47:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QjCFDEsg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729099AbeKOIur (ORCPT + 99 others); Thu, 15 Nov 2018 03:50:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:34402 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728214AbeKOI1P (ORCPT ); Thu, 15 Nov 2018 03:27:15 -0500 Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A9FB222511; Wed, 14 Nov 2018 22:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542234132; bh=KcquHZ7K1YB+PSdWcvkktHBoJpVFoYegvtaupJDrfxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QjCFDEsgOeo7xPjx5SePTid6hhYGN9QHaLfoaIqOD6osLx6s1OtVjNj0jI5/phuUn nimUoHCJ3a92chrksJQcHWxQDd/Gwu44Db1cbaS4LqFR98dxfg53idYx5+mh0PBPu2 2ZwByVvafB9eBGK7kpuWCMv9C7cmCrGB8c7VDaIo= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Doug Berger , Florian Fainelli , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL 4.19 18/73] net: bcmgenet: protect stop from timeout Date: Wed, 14 Nov 2018 17:21:12 -0500 Message-Id: <20181114222207.98701-18-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114222207.98701-1-sashal@kernel.org> References: <20181114222207.98701-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Doug Berger [ Upstream commit 09e805d2570a3a94f13dd9c9ad2bcab23da76e09 ] A timing hazard exists when the network interface is stopped that allows a watchdog timeout to be processed by a separate core in parallel. This creates the potential for the timeout handler to wake the queues while the driver is shutting down, or access registers after their clocks have been removed. The more common case is that the watchdog timeout will produce a warning message which doesn't lead to a crash. The chances of this are greatly increased by the fact that bcmgenet_netif_stop stops the transmit queues which can easily precipitate a watchdog time- out because of stale trans_start data in the queues. This commit corrects the behavior by ensuring that the watchdog timeout is disabled before enterring bcmgenet_netif_stop. There are currently only two users of the bcmgenet_netif_stop function: close and suspend. The close case already handles the issue by exiting the RUNNING state before invoking the driver close service. The suspend case now performs the netif_device_detach to exit the PRESENT state before the call to bcmgenet_netif_stop rather than after it. These behaviors prevent any future scheduling of the driver timeout service during the window. The netif_tx_stop_all_queues function in bcmgenet_netif_stop is replaced with netif_tx_disable to ensure synchronization with any transmit or timeout threads that may already be executing on other cores. For symmetry, the netif_device_attach call upon resume is moved to after the call to bcmgenet_netif_start. Since it wakes the transmit queues it is not necessary to invoke netif_tx_start_all_queues from bcmgenet_netif_start so it is moved into the driver open service. Fixes: 1c1008c793fa ("net: bcmgenet: add main driver file") Signed-off-by: Doug Berger Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c index 20c1681bb1af..2d6f090bf644 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -2855,7 +2855,6 @@ static void bcmgenet_netif_start(struct net_device *dev) umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, true); - netif_tx_start_all_queues(dev); bcmgenet_enable_tx_napi(priv); /* Monitor link interrupts now */ @@ -2937,6 +2936,8 @@ static int bcmgenet_open(struct net_device *dev) bcmgenet_netif_start(dev); + netif_tx_start_all_queues(dev); + return 0; err_irq1: @@ -2958,7 +2959,7 @@ static void bcmgenet_netif_stop(struct net_device *dev) struct bcmgenet_priv *priv = netdev_priv(dev); bcmgenet_disable_tx_napi(priv); - netif_tx_stop_all_queues(dev); + netif_tx_disable(dev); /* Disable MAC receive */ umac_enable_set(priv, CMD_RX_EN, false); @@ -3620,13 +3621,13 @@ static int bcmgenet_suspend(struct device *d) if (!netif_running(dev)) return 0; + netif_device_detach(dev); + bcmgenet_netif_stop(dev); if (!device_may_wakeup(d)) phy_suspend(dev->phydev); - netif_device_detach(dev); - /* Prepare the device for Wake-on-LAN and switch to the slow clock */ if (device_may_wakeup(d) && priv->wolopts) { ret = bcmgenet_power_down(priv, GENET_POWER_WOL_MAGIC); @@ -3700,8 +3701,6 @@ static int bcmgenet_resume(struct device *d) /* Always enable ring 16 - descriptor ring */ bcmgenet_enable_dma(priv, dma_ctrl); - netif_device_attach(dev); - if (!device_may_wakeup(d)) phy_resume(dev->phydev); @@ -3710,6 +3709,8 @@ static int bcmgenet_resume(struct device *d) bcmgenet_netif_start(dev); + netif_device_attach(dev); + return 0; out_clk_disable: -- 2.17.1