Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2418109imu; Wed, 21 Nov 2018 11:17:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/WutuYrYtvxGD3uFvkvWM4JtKxr62de8FN/tWl7E6CALMKhk2bBIeKjBoNxbkewnfr2/8nG X-Received: by 2002:a17:902:42e4:: with SMTP id h91mr8220942pld.18.1542827877993; Wed, 21 Nov 2018 11:17:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542827877; cv=none; d=google.com; s=arc-20160816; b=Cg9QDPL4BsdGsdMyvpKfvS004wvYfbk2EHNE/CjaehV5MQYLVx6SRW9lltCtHwJ2Fb WobHFk55gfhzfje3qW1+RUbqbd8cYdmmA9EbcIqH0m8DxFPzcdtHK5RsoIZ1UrNNGi68 JItc0Xv8KO+qt1Mxovidm4s67axLyOyg3KQVM2oPJXwhzzW9kKOklE7cNOahF3R3S+7L kTuziuOeCw2PfbvjPW9vu/KpPYOEfp1np3O+coTHUb1sn4fogMfJ2bmuZPlZdK3Rhl5t KNt9mITMiuNM3AMQWR0nSXebLBIxa8hTrhFYBK5YoytRo6nM1ruddNvLkiwuuM6Z5mb0 Av1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=neMEiRRX5jRO1RZU6jwPMurrBpU9UTpMmC0rpNAjwQM=; b=to+SibqUgyWDq2Fa1YEUqovyH2VmqI4KGezLvxuHne3Zpq+lCI8LHFhjvBO4W86NrX YSWXtVppeIDaJAKUibGe9Hhe//2vMmv9vITCdg8Ia4EdtKd8apo0aykE4h4QJBW4qvWI OP6teKrsryXj+FP+5hpqQZNyDPe8oFCWhkoEULp04z9hZKFz3CQVRmwOt0byatlgK2a1 QWw12G2VAEhY0SKmSengsE+NAy1ewIhGEn1C8dYEWdkCb794lJqtr2eV49lPwQ5quNRE lzYnWNrbF66LET03ppqiaAjqFwriYtx+18nlSXRCgdIt/qyYyrYQbn4VXhUsVqOEZwxE Zn8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jeCpPlQY; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f16si12300553pgg.173.2018.11.21.11.17.43; Wed, 21 Nov 2018 11:17:57 -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=jeCpPlQY; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388190AbeKVFny (ORCPT + 99 others); Thu, 22 Nov 2018 00:43:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:38762 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388124AbeKVFnx (ORCPT ); Thu, 22 Nov 2018 00:43:53 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6DC9C214D9; Wed, 21 Nov 2018 19:08:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542827300; bh=JUyhDgnWNRD9CcDBttIBQ7je20zz6A27h/O82UTRUx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jeCpPlQY/Glg4DW4hSYZhIUyspVtPbiEACvUS0Wp5CnnS38NdIcJXe2GoFKn7Weh5 J6OnvGbZdQ1YF3wQIMN3zFkfUPvhZ4qJG8FzE44LBpJipDTic2G6JIQl6b8ppE5RQj GbFIO67FLoWds2X/aUv0lZ0OdLXQANkGx+PHGBIg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Doug Berger , Florian Fainelli , "David S. Miller" Subject: [PATCH 4.19 06/42] net: bcmgenet: protect stop from timeout Date: Wed, 21 Nov 2018 20:05:42 +0100 Message-Id: <20181121183148.245710803@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181121183147.869199006@linuxfoundation.org> References: <20181121183147.869199006@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Doug Berger 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. [ Upstream commit 09e805d2570a3a94f13dd9c9ad2bcab23da76e09 ] 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: Greg Kroah-Hartman --- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) --- 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 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_devi bcmgenet_netif_start(dev); + netif_tx_start_all_queues(dev); + return 0; err_irq1: @@ -2958,7 +2959,7 @@ static void bcmgenet_netif_stop(struct n 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 devic 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 /* 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 bcmgenet_netif_start(dev); + netif_device_attach(dev); + return 0; out_clk_disable: