Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3310670imu; Sun, 11 Nov 2018 12:06:52 -0800 (PST) X-Google-Smtp-Source: AJdET5f/ph05SAkM67+sp1+O4d0eMWgFuAtblxfqQdnSxIKk/ic+1vTmq6vv8mLZSLQGfpVecYQV X-Received: by 2002:a63:3d03:: with SMTP id k3mr14983433pga.191.1541966812366; Sun, 11 Nov 2018 12:06:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541966812; cv=none; d=google.com; s=arc-20160816; b=mfVvy6RnwJcoEG39YTIq4t1ZLEvMEaAw2L/DKZEu1tMTQnsZXjg8f6ZJk6abDfSWKt NWm0TGoZ7IXYcZ9fHL+Q6jA4s5QhM7P6cMGrLULTCW8kH57fbrQhr9uXR54z2y934rLw qpNOUvAv2g97Qkza66h7y5dc5zxJ0w99RDsRpfY+iyqUI4OxS2SaU2rHoVv012xz9KjX Z8M2YwJomp4trMUDv3rfAQEbr3kCpCI3P1AFLm5kl1E0tHPsEUbmzI5YyIGLjqf7JEJB CEN95g+yefVizJKXmnw/qyNKaNxV55w27B/qrjk5ChhfiW/mol7+OC5mVE96AFTs8fDf wVpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=2VB7ZMAxGX3H9lr2FO0NcR31led6pworcoCHb9H+Xpc=; b=iNegbiaZbIVFFYWS/HFZrN3UcKfY8j1NQiUQhIlOLuzuJcWmzU3BFQSsCy0Bgsy/2D VBYaSoHcapI6GnLb0w0i9G6K4MAE9FAskDbEEsa06wqanq2oks4dZX1NC7Ag75yV2OJU q5OxU+pNrwtmRein20LNRSFml1nCmvwmehEuxj/517SbUcqv7rfNeqwJbnR1qcJVFUqI XJQ0eZY+phP9x1Jt/iPWVA/LCQMFUVGnhT6aVz0v+rZHjQAvfNO1nMWa4mKr3yqZRVaz FyoEnB6vyihkF9iXRpSn27SX+Xm+eJcb44WY4YRmQFaUslV4jp9+YzH0nRFVPItRLH74 7R3A== ARC-Authentication-Results: i=1; mx.google.com; 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 a5-v6si13293873pgw.352.2018.11.11.12.06.37; Sun, 11 Nov 2018 12:06:52 -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; 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 S1731120AbeKLFyA (ORCPT + 99 others); Mon, 12 Nov 2018 00:54:00 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:51684 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726508AbeKLFx7 (ORCPT ); Mon, 12 Nov 2018 00:53:59 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvss-0000l6-6Q; Sun, 11 Nov 2018 19:59:02 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsV-0001i5-Sh; Sun, 11 Nov 2018 19:58:39 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "David S. Miller" , "Sergei Shtylyov" , "Vladimir Zapolskiy" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 239/366] sh_eth: fix invalid context bug while changing link options by ethtool In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Vladimir Zapolskiy commit 5cb3f52a11e18628fc4bee76dd14b1f0b76349de upstream. The change fixes sleep in atomic context bug, which is encountered every time when link settings are changed by ethtool. Since commit 35b5f6b1a82b ("PHYLIB: Locking fixes for PHY I/O potentially sleeping") phy_start_aneg() function utilizes a mutex to serialize changes to phy state, however that helper function is called in atomic context under a grabbed spinlock, because phy_start_aneg() is called by phy_ethtool_ksettings_set() and by replaced phy_ethtool_sset() helpers from phylib. Now duplex mode setting is enforced in sh_eth_adjust_link() only, also now RX/TX is disabled when link is put down or modifications to E-MAC registers ECMR and GECMR are expected for both cases of checked and ignored link status pin state from E-MAC interrupt handler. For reference the change is a partial rework of commit 1e1b812bbe10 ("sh_eth: fix handling of no LINK signal"). Fixes: dc19e4e5e02f ("sh: sh_eth: Add support ethtool") Signed-off-by: Vladimir Zapolskiy Reviewed-by: Sergei Shtylyov Signed-off-by: David S. Miller [bwh: Backported to 3.16: - Keep using phy_ethtool_sset() - Adjust context] Signed-off-by: Ben Hutchings --- --- a/drivers/net/ethernet/renesas/sh_eth.c +++ b/drivers/net/ethernet/renesas/sh_eth.c @@ -1727,8 +1727,15 @@ static void sh_eth_adjust_link(struct ne { struct sh_eth_private *mdp = netdev_priv(ndev); struct phy_device *phydev = mdp->phydev; + unsigned long flags; int new_state = 0; + spin_lock_irqsave(&mdp->lock, flags); + + /* Disable TX and RX right over here, if E-MAC change is ignored */ + if (mdp->cd->no_psr || mdp->no_ether_link) + sh_eth_rcv_snd_disable(ndev); + if (phydev->link) { if (phydev->duplex != mdp->duplex) { new_state = 1; @@ -1749,18 +1756,21 @@ static void sh_eth_adjust_link(struct ne ECMR); new_state = 1; mdp->link = phydev->link; - if (mdp->cd->no_psr || mdp->no_ether_link) - sh_eth_rcv_snd_enable(ndev); } } else if (mdp->link) { new_state = 1; mdp->link = 0; mdp->speed = 0; mdp->duplex = -1; - if (mdp->cd->no_psr || mdp->no_ether_link) - sh_eth_rcv_snd_disable(ndev); } + /* Enable TX and RX right over here, if E-MAC change is ignored */ + if ((mdp->cd->no_psr || mdp->no_ether_link) && phydev->link) + sh_eth_rcv_snd_enable(ndev); + + mmiowb(); + spin_unlock_irqrestore(&mdp->lock, flags); + if (new_state && netif_msg_link(mdp)) phy_print_status(phydev); } @@ -1843,35 +1853,8 @@ static int sh_eth_set_settings(struct ne struct ethtool_cmd *ecmd) { struct sh_eth_private *mdp = netdev_priv(ndev); - unsigned long flags; - int ret; - - spin_lock_irqsave(&mdp->lock, flags); - /* disable tx and rx */ - sh_eth_rcv_snd_disable(ndev); - - ret = phy_ethtool_sset(mdp->phydev, ecmd); - if (ret) - goto error_exit; - - if (ecmd->duplex == DUPLEX_FULL) - mdp->duplex = 1; - else - mdp->duplex = 0; - - if (mdp->cd->set_duplex) - mdp->cd->set_duplex(ndev); - -error_exit: - mdelay(1); - - /* enable tx and rx */ - sh_eth_rcv_snd_enable(ndev); - - spin_unlock_irqrestore(&mdp->lock, flags); - - return ret; + return phy_ethtool_sset(mdp->phydev, ecmd); } static int sh_eth_nway_reset(struct net_device *ndev)