Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7280244imu; Wed, 14 Nov 2018 14:47:11 -0800 (PST) X-Google-Smtp-Source: AJdET5ex1+QJACr6OoC6r0F3JJPvtiOYSOsjso/Zd0T7frlN/0eaW/sWnbQYD0t2dOPgQ479J7HU X-Received: by 2002:a17:902:b091:: with SMTP id p17-v6mr3687217plr.222.1542235631807; Wed, 14 Nov 2018 14:47:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235631; cv=none; d=google.com; s=arc-20160816; b=LfNcY6a7Pg2tUZE6Ahh7ufBPPT0+EmitSQ+PcGQd1SqQOjKzo/E4qoM/jBWEuijgxq MeZphe/XRTGjteSq9FjMqPFG2xH9CUp2r/ylMW9fmBKQ/Y6fUiWODBHPfJ9uAxNaye2p CQ16/0sZanhBO4EuzRhDssZnHIAQ8eEX4P6KRJmGUcukEtDwypdiNaPj+Xaly5T9utTb v3lkc9yyBMjqkivG1Y2V8RxCExRWuc3wVUlqxnOcfyCydyuDpE1tDvanocDniupO9OPh X+BzBsIYS4d8NxTPgYU43y4/jKxydbn/CL3gNEH3CyV8qKZJLy5M4hShdqhiphRZEujf g8+g== 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=kDe25UByrzjmW/KGLr9UwL0JPHyys/ubj4DhZSSfYxs=; b=cDFTqcj38PhWwFsYFHbFZE8HZCxNGwr68pHUbdmDfo6zdrXDywjdr2euAc2eHr9lhO 1dBmQGm9sRBOu42StajY6QIxtDvGwzwBYQaOjAysKfSugOivprmLHTSKCNxh9lKWWkYE 5roWzrVc0kwpUy5aRKXkyyg6u39BzufH2MG9/9hvX0opXFEEmBtodw8o78NaoKJbR1Fl FudUyrAkCum/4xO6UdaY7G903Tef+SVr63V0b8svi8sukEM4SVXJzBT5Bju8TRU9FT+2 V1dxow4AGAo7dIHzvSdl0VVVNrtsxkq95YNyq5ioQZZuI+oWlHnmkSlMeOqwojYscPDv WzFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yQxxZWpj; 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 x33-v6si25789245plb.49.2018.11.14.14.46.57; Wed, 14 Nov 2018 14:47:11 -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=yQxxZWpj; 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 S1728825AbeKOIuV (ORCPT + 99 others); Thu, 15 Nov 2018 03:50:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:34470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726951AbeKOI1Q (ORCPT ); Thu, 15 Nov 2018 03:27:16 -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 DB3A42251A; 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=2TTQFocgT3ezfiiUrNNK/Dclq28T0ozXQ9HBRSIR2lM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yQxxZWpjJNGu7ConNYWcqeIoopgsHWIUumWvoevQ8X6CZOGa335llAEY5+83xsifH h9Vzo0PvL/PyxI/WQJuZXBr/O5mOWWBkN4H5fzSwsLOeYzqZAWqfTzQ81m6TcfKCCs 0VyzhW+1jYic2Q7PiZqirkf/5Ofs2gHyG8mpWTCo= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Florian Fainelli , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL 4.19 19/73] net: systemport: Protect stop from timeout Date: Wed, 14 Nov 2018 17:21:13 -0500 Message-Id: <20181114222207.98701-19-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: Florian Fainelli [ Upstream commit 7cb6a2a2c72c1ed8f42fb01f1a661281b568dead ] 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 bcm_sysport_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 bcm_sysport_netif_stop. There are currently only two users of the bcm_sysport_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 bcm_sysport_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 bcm_sysport_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 bcm_sysport_netif_start. Since it wakes the transmit queues it is not necessary to invoke netif_tx_start_all_queues from bcm_sysport_netif_start so it is moved into the driver open service. Fixes: 40755a0fce17 ("net: systemport: add suspend and resume support") Fixes: 80105befdb4b ("net: systemport: add Broadcom SYSTEMPORT Ethernet MAC driver") Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/broadcom/bcmsysport.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c index c57238fce863..7b6859e4924e 100644 --- a/drivers/net/ethernet/broadcom/bcmsysport.c +++ b/drivers/net/ethernet/broadcom/bcmsysport.c @@ -1897,9 +1897,6 @@ static void bcm_sysport_netif_start(struct net_device *dev) intrl2_1_mask_clear(priv, 0xffffffff); else intrl2_0_mask_clear(priv, INTRL2_0_TDMA_MBDONE_MASK); - - /* Last call before we start the real business */ - netif_tx_start_all_queues(dev); } static void rbuf_init(struct bcm_sysport_priv *priv) @@ -2045,6 +2042,8 @@ static int bcm_sysport_open(struct net_device *dev) bcm_sysport_netif_start(dev); + netif_tx_start_all_queues(dev); + return 0; out_clear_rx_int: @@ -2068,7 +2067,7 @@ static void bcm_sysport_netif_stop(struct net_device *dev) struct bcm_sysport_priv *priv = netdev_priv(dev); /* stop all software from updating hardware */ - netif_tx_stop_all_queues(dev); + netif_tx_disable(dev); napi_disable(&priv->napi); cancel_work_sync(&priv->dim.dim.work); phy_stop(dev->phydev); @@ -2654,12 +2653,12 @@ static int __maybe_unused bcm_sysport_suspend(struct device *d) if (!netif_running(dev)) return 0; + netif_device_detach(dev); + bcm_sysport_netif_stop(dev); phy_suspend(dev->phydev); - netif_device_detach(dev); - /* Disable UniMAC RX */ umac_enable_set(priv, CMD_RX_EN, 0); @@ -2743,8 +2742,6 @@ static int __maybe_unused bcm_sysport_resume(struct device *d) goto out_free_rx_ring; } - netif_device_attach(dev); - /* RX pipe enable */ topctrl_writel(priv, 0, RX_FLUSH_CNTL); @@ -2789,6 +2786,8 @@ static int __maybe_unused bcm_sysport_resume(struct device *d) bcm_sysport_netif_start(dev); + netif_device_attach(dev); + return 0; out_free_rx_ring: -- 2.17.1