Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1082857pxk; Fri, 25 Sep 2020 05:56:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFRPAubMe1F1CrjaIcDP1IAgEphrjakAxGrSSqkreIXfIPZ0DK2mJ16ULD1pcXY+M054+K X-Received: by 2002:a05:6402:b72:: with SMTP id cb18mr1081862edb.299.1601038594544; Fri, 25 Sep 2020 05:56:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601038594; cv=none; d=google.com; s=arc-20160816; b=CXy9MzehuYciFCwhhlLHO+r7W0jmDA9JaRknKNBwrgLPyZLmaDNDl/oP4Yd/TqKygO urOhXnkgp4MgAbR+8r4Ut25d5DUg+K4QGHddkKWVuE/KIQ/ai4RZcXvlcnQadh9tRCl9 OU1sj0iJKBM+zwQxr0q0q25nkdvgWPQ92VAJHj5P0hU3vIbWTBoKL5rVGq/A4vpubF0m PEOFyFQ/S3FV/u+9W0ri2zj933buQiSRg8ltiGzSzOWI4/yW4BRg0RgKLTvuYG8QiqDX EmtJfoipXnqGNmLFml2qcmqOsHkHi7Tcpt/lgY+Duxzy4qlcoYQ7UUArARyw1iJCU1qN GGfQ== 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=RgWxWqKfaWUHt+185ExdQH0nnECQGWFbiF9JC6n3yuQ=; b=bVoxgqg3zEmqGmzCVDn6UKfcnEmvVCssLCdIE3bkOabdaJRCQpor3bxp1K1xqd+pfi n9Sz3UZO6rLLEyJzhXmyX80emG8q7eNj4KbepkKBCNgNuRRWxMwe+sFQtojYJ8CkVT8o ZIZBIQ2LyZdke119biqtXZ3KKFC5PjxYCOqjW6ZSKXC+/Ezig6wrV9LZg5d6fg3EAgyN I6kgw5Rq1Rwa+02sCh6NhRI9U+q4kcq9IL4YuP1PEuk1Pess0lkm1Tpq/BzoOx2VvC/8 hfdxxkyVWhbiWSSe3wMOhOw/t/OJtjqPLUksGRQz4LldmYPQUI9qFv//kNPPT/FmDouC 2JuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=t64iFHsE; 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=fail (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 lt17si1779215ejb.56.2020.09.25.05.56.11; Fri, 25 Sep 2020 05:56:34 -0700 (PDT) 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=@kernel.org header.s=default header.b=t64iFHsE; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729509AbgIYMyB (ORCPT + 99 others); Fri, 25 Sep 2020 08:54:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:60220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729484AbgIYMx7 (ORCPT ); Fri, 25 Sep 2020 08:53:59 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 7CE382075E; Fri, 25 Sep 2020 12:53:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601038439; bh=0YzHSosHnylmhANNGtZ0amjWEIPc7DVm4bYLqV8Cdy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t64iFHsEc7aujDQ9nqrOZUu4rtSEGuCpWPW6IOLegkxd6p3UTQCx0h8gMAR2I5rVr BaAq6BAV5v7djglrjciniyUi8HbhmTkRkCMN4M5H6rvaAhccZPcQe/PDlo/I8byUSq GLquN4rrWEZafT7C1dpbAHgb/+C3T5vSEIW0i1Hg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Edwin Peer , Michael Chan , "David S. Miller" Subject: [PATCH 4.19 19/37] bnxt_en: Protect bnxt_set_eee() and bnxt_set_pauseparam() with mutex. Date: Fri, 25 Sep 2020 14:48:47 +0200 Message-Id: <20200925124723.825295419@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200925124720.972208530@linuxfoundation.org> References: <20200925124720.972208530@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: Michael Chan [ Upstream commit a53906908148d64423398a62c4435efb0d09652c ] All changes related to bp->link_info require the protection of the link_lock mutex. It's not sufficient to rely just on RTNL. Fixes: 163e9ef63641 ("bnxt_en: Fix race when modifying pause settings.") Reviewed-by: Edwin Peer Signed-off-by: Michael Chan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 31 ++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c @@ -1369,9 +1369,12 @@ static int bnxt_set_pauseparam(struct ne if (!BNXT_SINGLE_PF(bp)) return -EOPNOTSUPP; + mutex_lock(&bp->link_lock); if (epause->autoneg) { - if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) - return -EINVAL; + if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { + rc = -EINVAL; + goto pause_exit; + } link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; if (bp->hwrm_spec_code >= 0x10201) @@ -1392,11 +1395,11 @@ static int bnxt_set_pauseparam(struct ne if (epause->tx_pause) link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; - if (netif_running(dev)) { - mutex_lock(&bp->link_lock); + if (netif_running(dev)) rc = bnxt_hwrm_set_pause(bp); - mutex_unlock(&bp->link_lock); - } + +pause_exit: + mutex_unlock(&bp->link_lock); return rc; } @@ -2113,8 +2116,7 @@ static int bnxt_set_eee(struct net_devic struct bnxt *bp = netdev_priv(dev); struct ethtool_eee *eee = &bp->eee; struct bnxt_link_info *link_info = &bp->link_info; - u32 advertising = - _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); + u32 advertising; int rc = 0; if (!BNXT_SINGLE_PF(bp)) @@ -2123,19 +2125,23 @@ static int bnxt_set_eee(struct net_devic if (!(bp->flags & BNXT_FLAG_EEE_CAP)) return -EOPNOTSUPP; + mutex_lock(&bp->link_lock); + advertising = _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); if (!edata->eee_enabled) goto eee_ok; if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { netdev_warn(dev, "EEE requires autoneg\n"); - return -EINVAL; + rc = -EINVAL; + goto eee_exit; } if (edata->tx_lpi_enabled) { if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi || edata->tx_lpi_timer < bp->lpi_tmr_lo)) { netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n", bp->lpi_tmr_lo, bp->lpi_tmr_hi); - return -EINVAL; + rc = -EINVAL; + goto eee_exit; } else if (!bp->lpi_tmr_hi) { edata->tx_lpi_timer = eee->tx_lpi_timer; } @@ -2145,7 +2151,8 @@ static int bnxt_set_eee(struct net_devic } else if (edata->advertised & ~advertising) { netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n", edata->advertised, advertising); - return -EINVAL; + rc = -EINVAL; + goto eee_exit; } eee->advertised = edata->advertised; @@ -2157,6 +2164,8 @@ eee_ok: if (netif_running(dev)) rc = bnxt_hwrm_set_link_setting(bp, false, true); +eee_exit: + mutex_unlock(&bp->link_lock); return rc; }