From patchwork Thu May 16 23:01:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13666572 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEE6A38382; Thu, 16 May 2024 23:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715900527; cv=none; b=H028+EDHbK625heQRZb1QirYdeSY9b8WcqQmoFy1Xb+kolrbjrllN02k9NyVSjCoLL9/Ov30Ni6FQK1Pzb7JHwAehyiryp2jwhrSB4/5ccqxFd2RvUB/MYsVppdkvy2jhrSAsRp8vsLcrHhgKv9314l0jWoOugytCpD1OEo5PZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715900527; c=relaxed/simple; bh=L/r+/jSr7lZ1Um5u8jIULrtQvjAXq8IPrhDlnfrhdWA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jZTDLqiv4SL8mJKaLZh4hpRK2iAoApi85wa01qHCLpbcq9Hr8oH4C3DaPZC22hPUGo2/4KHWo0oOVAzUs/KhtsjS/CCTh/z3QJkAgSycrrqBRcqr8c72R5CiE6J94YZPCcslIcpBYQGjp+7/B1W96y8lsxpJpommC+OC842key4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iJxeRdtz; arc=none smtp.client-ip=209.85.160.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iJxeRdtz" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-43e4020db92so440111cf.0; Thu, 16 May 2024 16:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715900524; x=1716505324; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bul2ptxRqfIw2xpa+3EaGbCt68B5fdbbN1CJpCg6Z3U=; b=iJxeRdtzzOT1bgiBMVrHzY7s/mmq1xdOQYuZFU/55sRUGvwV82MHWMi+eVmdh2lbSg uDTOjTDqWwsZcQACsq0EQEovVaRe97Y9g1BUPjMJKylFzgNiTtQkcOkM8qIeebEQ328N bza1BwErJJUS9+WiI14BjEKswt6TJfK0QA18GL2EhMiTbM9rGuRg5Jgxm8kY/Ot5PvkI xJwG6hKstlVP6mSJ3d3OdJ4e/b1uYudnlWU2xJ94wgGe8j1FcDecVHKLi3VtsSYj7QRA C1ZhWL0smDdekRmOvOFKib5axXwkIvgTDjlvkTxRRNcEZ3SLbI5gbqD+aUUCOoivY4pY x10A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715900524; x=1716505324; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bul2ptxRqfIw2xpa+3EaGbCt68B5fdbbN1CJpCg6Z3U=; b=dlnCzLCDOe8hb9bqq1T9CEItED1tqvmmHSdde7YEcnW9boixJOlRAzJfgwSUxvDx10 tDpuSrsVixnLVPa99EP/McmR+yLsUudJprW2hkDDpaISj0asTXKs8PAk3pnXhSn21Hho BhFyeYWnUONLX/JQ2MfBi/0G4LkHqPiT0GTt/VGuTgikHITqaLE+R1ZDRrekTkYrRRph bnMlWC1XcuxbMgTtCF5GnroeEtNxWZXXID36Hgw/M3Llexy4HqYTGj6M+BYXsIq6ZZ8X O/xMdkuPlHmrWME9RtvF8hIDZ8ChP64PKYU5ajY+ATRpauMO9Sv8ko4i518SD1/wdB7Y mGWQ== X-Forwarded-Encrypted: i=1; AJvYcCX0dFO94YMKMYiFXEp4JEX7rHNSwsJXESfdaRdiWmCXRuSTx7K1UtsfwCYYVCE8zvn0fpJZ7caG7lRq49/rx2djOiw2EFx4/7A8tJ5VBdrzpbzzezU0eTRYQnJeCGf+dhJhO7ym X-Gm-Message-State: AOJu0Yzr4jYoIk7W5LC1MxRJUXnRA6ngMM1TtTgAMbVpkvUXDcGFAdun 5b0G9DhXPYm6e0DOp0AGq4HhDaTzQUMpdgfaJwVjqY5SfjlTTbCWuZxkwQ== X-Google-Smtp-Source: AGHT+IHtwBQkDVz0O6uzqf+K7Tcs3695RC5RkoZN3QbVy3+n6sQ+v/7oaS72WpO/c+FwMd/bzl4hGA== X-Received: by 2002:ac8:71cd:0:b0:43e:607:f4d3 with SMTP id d75a77b69052e-43e0607f638mr153120191cf.48.1715900523735; Thu, 16 May 2024 16:02:03 -0700 (PDT) Received: from stbirv-lnx-1.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e251233c6sm47154851cf.84.2024.05.16.16.02.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 16:02:03 -0700 (PDT) From: Doug Berger To: stable@vger.kernel.org Cc: Doug Berger , Florian Fainelli , "David S. Miller" , bcm-kernel-feedback-list@broadcom.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Florian Fainelli Subject: [PATCH stable 5.4 1/3] net: bcmgenet: synchronize EXT_RGMII_OOB_CTRL access Date: Thu, 16 May 2024 16:01:49 -0700 Message-Id: <20240516230151.1031190-2-opendmb@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240516230151.1031190-1-opendmb@gmail.com> References: <20240516230151.1031190-1-opendmb@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org [ Upstream commit d85cf67a339685beae1d0aee27b7f61da95455be ] The EXT_RGMII_OOB_CTRL register can be written from different contexts. It is predominantly written from the adjust_link handler which is synchronized by the phydev->lock, but can also be written from a different context when configuring the mii in bcmgenet_mii_config(). The chances of contention are quite low, but it is conceivable that adjust_link could occur during resume when WoL is enabled so use the phydev->lock synchronizer in bcmgenet_mii_config() to be sure. Fixes: afe3f907d20f ("net: bcmgenet: power on MII block for all MII modes") Cc: stable@vger.kernel.org Signed-off-by: Doug Berger Acked-by: Florian Fainelli Signed-off-by: David S. Miller --- drivers/net/ethernet/broadcom/genet/bcmmii.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c index 56fad34461f7..d0b59d1f6c73 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmmii.c +++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c @@ -269,6 +269,7 @@ int bcmgenet_mii_config(struct net_device *dev, bool init) * block for the interface to work */ if (priv->ext_phy) { + mutex_lock(&phydev->lock); reg = bcmgenet_ext_readl(priv, EXT_RGMII_OOB_CTRL); reg |= id_mode_dis; if (GENET_IS_V1(priv) || GENET_IS_V2(priv) || GENET_IS_V3(priv)) @@ -276,6 +277,7 @@ int bcmgenet_mii_config(struct net_device *dev, bool init) else reg |= RGMII_MODE_EN; bcmgenet_ext_writel(priv, reg, EXT_RGMII_OOB_CTRL); + mutex_unlock(&phydev->lock); } if (init) From patchwork Thu May 16 23:01:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13666573 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FFA33B2A6; Thu, 16 May 2024 23:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715900528; cv=none; b=bdE/iqGzcNGdYuCGtatjnRP9CmiZoVFJDj8YLaN3jaRbc7vxBOp4sRFJUZAljrH6oHKHJzPYM6KjhrhFY79GWnqqLPJheBX+0IhqbJ/4ocHperCV4v4ZogcxjnXHsa9C/t18ujCZG51a7LBseoc+WnswCPsX4aEXxWFmUWhqu7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715900528; c=relaxed/simple; bh=rWhDCKDGUNLE4EoUeTeFDmTUc++hfoUGmdNIrG+/IR4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J/Wm0hi7vFfuHjN9oGWSpZoUE826VsdUKRq5aid2ZZKFj2qJH+veV4FHjzwoofEyJbBTAzQnyV+tRQLwzkIC6124qqFBedTrfXCKSXjMn0TAVgh5wN+Mx7HrKj9W2/A0N3marLRwkTxg8ECp6/BJrh4Dh40CuerxjdQL8XnNC/w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AxUUd1iG; arc=none smtp.client-ip=209.85.160.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AxUUd1iG" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-43e2bca05e8so317011cf.2; Thu, 16 May 2024 16:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715900525; x=1716505325; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tQ+YHRdKVUaH+6BWpdlpKpl2u3zSs+jY9z+FmOnpPYE=; b=AxUUd1iGusAozXVP7oRJE8WIRcsu6Rmw78KiBcq256+rCNykDMICR0grGVwrRuHOpt zrGSHkv4CtviSwhPcXQBn40a87wzxnl4KXXEa1YEkOg3+jw/IkCk+5oY4uEU/zv/XKqH RvcXPz8ciB7+U0VzYs4IVEluGJdsFV1wJa0kdFnkheGQllyQZPzTh8y/bHmWebHSKCk8 KyQ1AaUDQMgIQBnc1pOSeOBx/r5ybIVsRLPn3wlpn34mxSCHyhr5Tu+UDxukIAZo4SE9 DsGEWaNbLJkHnP1hwejm9/cvMOL+5j9fZ90x1BsufiwKJZrNykKhw1X5Cg2uMraKg0Ef cnfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715900525; x=1716505325; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tQ+YHRdKVUaH+6BWpdlpKpl2u3zSs+jY9z+FmOnpPYE=; b=rrbI1GvFYb+HP5ZZk08DRB5YWbyMfdgTDHF2I6XUe/d3r/K9e1LRcAHqV1fs/fTBzU 6PJnYLlvMloohv8d2mnkdiI8NRjsYcgRRd/o0TCgk9w1uWzbYwTIVuXU7O/wWuYG0kgx eo9DymDJKwSS3Xt7RHK+qZMyvVaZ2S7uNzJDQupWfF06OlCNauBdxO3qek2e6m8dNQj9 4GZHcjP7l6sfNTNUpOYUU8WfYEUSve1QvcPtNk7hDRE2dlALDOGQnjzxfL+IrdxkMt2z KfpemPhkZW0zAIpJo2bZyp6eUjgD245CcvwNDb+3rV/r6nJIqv/mZulYpp93Z6PfHqpj 5hBA== X-Forwarded-Encrypted: i=1; AJvYcCU6kP8x98WyaT5LO2M9Cizi1x9y9NVpqbqqdyb7O5DPlUPcbLGwPY9Zc6o6FLX05xgQCCIBBZbDvdS5ZecDnbUSqh2kv71r1vaFkj2KjWVIIoMGvzwrLkKT+rxlYdnUUmjeNr/a X-Gm-Message-State: AOJu0YwQFGrAiPPcK7k453lHP7LK/3is47uWsfWfd+VPUZpPTXbIyLw2 ta8QpMdNVwWg22e8jwnWThS79pbdi7YbikFhB8LjTT0qCQfWtXsWb+mOQQ== X-Google-Smtp-Source: AGHT+IGuRvJzQiRpV2oU5Ww6p0oIVaKIDCu2YH5Y9yCwTbh6NAgtRBM3voXr8p9zmuIAWMLMA19D5Q== X-Received: by 2002:a05:622a:1912:b0:434:b04a:20d1 with SMTP id d75a77b69052e-43dfdb1f7c3mr237392321cf.36.1715900525428; Thu, 16 May 2024 16:02:05 -0700 (PDT) Received: from stbirv-lnx-1.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e251233c6sm47154851cf.84.2024.05.16.16.02.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 16:02:05 -0700 (PDT) From: Doug Berger To: stable@vger.kernel.org Cc: Doug Berger , Florian Fainelli , "David S. Miller" , bcm-kernel-feedback-list@broadcom.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Florian Fainelli Subject: [PATCH stable 5.4 2/3] net: bcmgenet: synchronize use of bcmgenet_set_rx_mode() Date: Thu, 16 May 2024 16:01:50 -0700 Message-Id: <20240516230151.1031190-3-opendmb@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240516230151.1031190-1-opendmb@gmail.com> References: <20240516230151.1031190-1-opendmb@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org [ Upstream commit 2dbe5f19368caae63b1f59f5bc2af78c7d522b3a ] The ndo_set_rx_mode function is synchronized with the netif_addr_lock spinlock and BHs disabled. Since this function is also invoked directly from the driver the same synchronization should be applied. Fixes: 72f96347628e ("net: bcmgenet: set Rx mode before starting netif") Cc: stable@vger.kernel.org Signed-off-by: Doug Berger Acked-by: Florian Fainelli Signed-off-by: David S. Miller --- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c index bf52bd643846..e34df8da65e7 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -2874,7 +2874,9 @@ static void bcmgenet_netif_start(struct net_device *dev) struct bcmgenet_priv *priv = netdev_priv(dev); /* Start the network engine */ + netif_addr_lock_bh(dev); bcmgenet_set_rx_mode(dev); + netif_addr_unlock_bh(dev); bcmgenet_enable_rx_napi(priv); umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, true); From patchwork Thu May 16 23:01:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13666574 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 225134087F; Thu, 16 May 2024 23:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715900530; cv=none; b=HnXvag32n5SEx+SU981AQ2sngt+9vtb+B8ohRqA/YyGf13QyQUUMosw3iOeg0NlPHcYBFPOQROsYRWMRWWuAxDluJiXCGo9qzxYRT/UGz4E6pnjzlvJ5D2DlJ6zLED3V3PAaWUFUu102mpbBJQD564T4V4oJHrTIxKqkiJGkkDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715900530; c=relaxed/simple; bh=a7SEqQDNz97OSHhoT4UBY69oGPl9v7HBaYUzz/5xOiQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TUa85L6T8Hs7I7FXM70rhb4S9raK9/bt+GG9QX19/dvDNRf/exYxG0i49VnNDuPNwb/i+p4+9COI9h75D8EIpj3E/hG+g0+0bH7NzjBJDCDD9Y9ANB7PJU+YXdalUWUqdgd3OIWkJJjqpp1G4p5CZttNhj888rCS3rTZIbUWgtM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LJnh9Qi+; arc=none smtp.client-ip=209.85.161.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LJnh9Qi+" Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5b2e942171cso448749eaf.3; Thu, 16 May 2024 16:02:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715900527; x=1716505327; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VoeHJzNVkB54yDBVnMDfuwpD4ZrJsaFqixROui8d5X0=; b=LJnh9Qi+rMKRe3Ku+wZJtk6L1+wj2Zg+sgT04SPuJtUNhiJnQvV5irgYMevM1VzBE7 dly6SHCXD1ZIT5cQVeCk8/P/dEYDQN7jVJRdZZh30gwvFOBOUc6uLMebQRAKxESZCUnM I4p604/hMkXKBbLGEsM8x5Om3r1H0gaNv/YNBHr14IfbgREOaYxFt54GIb4NJhTiQMV5 I27GQOnh6yMfVkAkLKw0k2yZ2tn/7itZp99GhI92DqknLX+Vlux3F/74t5pZyt9zN6vD fjIWEzm4GeOvK/j1sOmTWcBvVRw3HmWMkTJHQkq1TGgXKID+Cf43BeFgkmd/oHdyR07j dz0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715900527; x=1716505327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VoeHJzNVkB54yDBVnMDfuwpD4ZrJsaFqixROui8d5X0=; b=h9DWA/v7OZyzQJGSG6gzVc6ObsKnAPN2uDJBQrBewWH74Cf1qmPcpO0S/JlwnkX0gT MADETJKiMBZUk0jZBwH9CIhVsSj/GOOceOZaw2l1TTURGFUG4b8wUESDbFct+zLSpFL3 QYKwle7q9Up0V6y2mddBGDJWzE4K7XPBk1IbeKWIfcUjjwHBfaEKjm4NRtWjQhCZUs6R 4IfqdhsDqdbJMn8frS3U5d2TvjCL5Sl3Lfl4jdZ3jf3FSJxBdS26leXiTFuf5UV0ziBa CUAX9hZdn0ABvZrHoMmZitOC8xFmi63dSXF3QWgT6cSzX2Zv49/aezqbJV5HYEhwmDHR 8y1Q== X-Forwarded-Encrypted: i=1; AJvYcCWTpFUj+7o8L1w35ZZmfmuowyzxbHCPTHgBJfBMKV5G7vLJLS/N9isNtj9ha+fba0ShMFgOmGYmIm4vn5MkWgpPpr/8dRR0nk8OFObHyZmHyWvqjLKYyi1cCxwsf72MwMSXvg4a X-Gm-Message-State: AOJu0YzZFnHfPgWkWsk9mNr9KFYMNrMh70+9Pb3KffSwJPSWMFAY5fWN QD6QFoZtF6Az3WwQe2ihVnry1W4kMCKFcoHZ66NGaBtoE0W8pz6XcP9DOg== X-Google-Smtp-Source: AGHT+IGyHb0zSCOVAfsCt9H6tPVqdxfL0VPhf0pPA7lbucNTv3brCKOa5YPLYQnuJpsOWCiH/E2I6g== X-Received: by 2002:a05:6358:98a5:b0:194:81b4:e96 with SMTP id e5c5f4694b2df-19481b412c2mr848089255d.30.1715900527178; Thu, 16 May 2024 16:02:07 -0700 (PDT) Received: from stbirv-lnx-1.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e251233c6sm47154851cf.84.2024.05.16.16.02.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 16:02:06 -0700 (PDT) From: Doug Berger To: stable@vger.kernel.org Cc: Doug Berger , Florian Fainelli , "David S. Miller" , bcm-kernel-feedback-list@broadcom.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Florian Fainelli Subject: [PATCH stable 5.4 3/3] net: bcmgenet: synchronize UMAC_CMD access Date: Thu, 16 May 2024 16:01:51 -0700 Message-Id: <20240516230151.1031190-4-opendmb@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240516230151.1031190-1-opendmb@gmail.com> References: <20240516230151.1031190-1-opendmb@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org [ Upstream commit 0d5e2a82232605b337972fb2c7d0cbc46898aca1 ] The UMAC_CMD register is written from different execution contexts and has insufficient synchronization protections to prevent possible corruption. Of particular concern are the acceses from the phy_device delayed work context used by the adjust_link call and the BH context that may be used by the ndo_set_rx_mode call. A spinlock is added to the driver to protect contended register accesses (i.e. reg_lock) and it is used to synchronize accesses to UMAC_CMD. Fixes: 1c1008c793fa ("net: bcmgenet: add main driver file") Cc: stable@vger.kernel.org Signed-off-by: Doug Berger Acked-by: Florian Fainelli Signed-off-by: David S. Miller --- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 12 +++++++++++- drivers/net/ethernet/broadcom/genet/bcmgenet.h | 2 ++ drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c | 6 ++++++ drivers/net/ethernet/broadcom/genet/bcmmii.c | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c index e34df8da65e7..da9df1d3662b 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -1990,14 +1990,18 @@ static void umac_enable_set(struct bcmgenet_priv *priv, u32 mask, bool enable) { u32 reg; + spin_lock_bh(&priv->reg_lock); reg = bcmgenet_umac_readl(priv, UMAC_CMD); - if (reg & CMD_SW_RESET) + if (reg & CMD_SW_RESET) { + spin_unlock_bh(&priv->reg_lock); return; + } if (enable) reg |= mask; else reg &= ~mask; bcmgenet_umac_writel(priv, reg, UMAC_CMD); + spin_unlock_bh(&priv->reg_lock); /* UniMAC stops on a packet boundary, wait for a full-size packet * to be processed @@ -2013,8 +2017,10 @@ static void reset_umac(struct bcmgenet_priv *priv) udelay(10); /* issue soft reset and disable MAC while updating its registers */ + spin_lock_bh(&priv->reg_lock); bcmgenet_umac_writel(priv, CMD_SW_RESET, UMAC_CMD); udelay(2); + spin_unlock_bh(&priv->reg_lock); } static void bcmgenet_intr_disable(struct bcmgenet_priv *priv) @@ -3140,16 +3146,19 @@ static void bcmgenet_set_rx_mode(struct net_device *dev) * 3. The number of filters needed exceeds the number filters * supported by the hardware. */ + spin_lock(&priv->reg_lock); reg = bcmgenet_umac_readl(priv, UMAC_CMD); if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) || (nfilter > MAX_MDF_FILTER)) { reg |= CMD_PROMISC; bcmgenet_umac_writel(priv, reg, UMAC_CMD); + spin_unlock(&priv->reg_lock); bcmgenet_umac_writel(priv, 0, UMAC_MDF_CTRL); return; } else { reg &= ~CMD_PROMISC; bcmgenet_umac_writel(priv, reg, UMAC_CMD); + spin_unlock(&priv->reg_lock); } /* update MDF filter */ @@ -3507,6 +3516,7 @@ static int bcmgenet_probe(struct platform_device *pdev) goto err; } + spin_lock_init(&priv->reg_lock); spin_lock_init(&priv->lock); SET_NETDEV_DEV(dev, &pdev->dev); diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h index 29bf256d13f6..9efc503a9c8b 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h @@ -608,6 +608,8 @@ struct bcmgenet_rx_ring { /* device context */ struct bcmgenet_priv { void __iomem *base; + /* reg_lock: lock to serialize access to shared registers */ + spinlock_t reg_lock; enum bcmgenet_version version; struct net_device *dev; diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c b/drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c index 8ebca6bf300e..973275d116b6 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c @@ -133,6 +133,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, } /* Can't suspend with WoL if MAC is still in reset */ + spin_lock_bh(&priv->reg_lock); reg = bcmgenet_umac_readl(priv, UMAC_CMD); if (reg & CMD_SW_RESET) reg &= ~CMD_SW_RESET; @@ -140,6 +141,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, /* disable RX */ reg &= ~CMD_RX_EN; bcmgenet_umac_writel(priv, reg, UMAC_CMD); + spin_unlock_bh(&priv->reg_lock); mdelay(10); reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL); @@ -163,6 +165,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, retries); /* Enable CRC forward */ + spin_lock_bh(&priv->reg_lock); reg = bcmgenet_umac_readl(priv, UMAC_CMD); priv->crc_fwd_en = 1; reg |= CMD_CRC_FWD; @@ -170,6 +173,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, /* Receiver must be enabled for WOL MP detection */ reg |= CMD_RX_EN; bcmgenet_umac_writel(priv, reg, UMAC_CMD); + spin_unlock_bh(&priv->reg_lock); return 0; } @@ -191,8 +195,10 @@ void bcmgenet_wol_power_up_cfg(struct bcmgenet_priv *priv, bcmgenet_umac_writel(priv, reg, UMAC_MPD_CTRL); /* Disable CRC Forward */ + spin_lock_bh(&priv->reg_lock); reg = bcmgenet_umac_readl(priv, UMAC_CMD); reg &= ~CMD_CRC_FWD; bcmgenet_umac_writel(priv, reg, UMAC_CMD); + spin_unlock_bh(&priv->reg_lock); priv->crc_fwd_en = 0; } diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c index d0b59d1f6c73..bd532e5b9f73 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmmii.c +++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c @@ -91,6 +91,7 @@ void bcmgenet_mii_setup(struct net_device *dev) reg |= RGMII_LINK; bcmgenet_ext_writel(priv, reg, EXT_RGMII_OOB_CTRL); + spin_lock_bh(&priv->reg_lock); reg = bcmgenet_umac_readl(priv, UMAC_CMD); reg &= ~((CMD_SPEED_MASK << CMD_SPEED_SHIFT) | CMD_HD_EN | @@ -103,6 +104,7 @@ void bcmgenet_mii_setup(struct net_device *dev) reg |= CMD_TX_EN | CMD_RX_EN; } bcmgenet_umac_writel(priv, reg, UMAC_CMD); + spin_unlock_bh(&priv->reg_lock); priv->eee.eee_active = phy_init_eee(phydev, 0) >= 0; bcmgenet_eee_enable_set(dev,