Skip to contentSkip to conversation

tg3: Bug fixes

PATCH Superseded Pavan Chebbi 2 participants 12 messages Nov 11 – Nov 17

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Pavan Chebbi

author maintainer
#0 lore raw

v2 cover tg3: Bug fixes

This patchset has 4 fixes. The first patch restores probe on 57766 when the 31-bit coherent DMA mask cannot be set. The second patch makes NCSI PLL lock on the TLP clock to fix WOL at 1G speed on 5720. The third patch fixes ethtool -i display on 5719/5720 when NCSI component is missing. The fourth one fixes a possible heap overflow in the NVRAM write path.

v2: Addressed Sashiko warnings on:
- patch #2 such that the PLL clock bit is set only at system suspend and power off, cleared on resume and at probe and updated under the APE lock.
- patch #4 to reject a zero NVRAM page size and to describe the buf advance fix and its reach.

v1:
https://lore.kernel.org/all/[email protected]/

Pavan Chebbi (3):
tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported
tg3: Select PLL clock when preparing for shutdown
tg3: Skip querying for management FW when no NCSI present

Shravya KN (1):
tg3: Fix heap overflow in unbuffered NVRAM write path

 drivers/net/ethernet/broadcom/tg3.c | 72 +++++++++++++++++++++++++----
 drivers/net/ethernet/broadcom/tg3.h |  6 ++-
 2 files changed, 69 insertions(+), 9 deletions(-)
Signature · 1 line
2.52.0
author maintainer
#1 lore raw

PATCH v2 1/4 tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported

Commit 614f4d166eee ("tg3: Set coherent DMA mask bits to 31 for BCM57766 chipsets") lowered the coherent DMA mask to 31 bits as a workaround for a spurious address overflow error in the hardware. The result of dma_set_coherent_mask() is fatal to probe, so on platforms that cannot satisfy such a mask the device fails to probe:

tg3 0000:01:00.0: Unable to obtain 64 bit DMA for consistent allocations tg3 0000:01:00.0: probe with driver tg3 failed with error -5

This was reported on a Mac mini (Macmini6,2, BCM57766) running a kernel built without CONFIG_ZONE_DMA and with IOMMU passthrough as the default. Without CONFIG_ZONE_DMA, dma_direct_supported() only accepts a mask narrower than 32 bits if it covers the highest physical memory address, so with direct mapping a 31-bit coherent mask is rejected whenever memory extends above 2GB.

Treat the 31-bit mask as best effort. If it is refused, warn and fall back to the mask used before 614f4d166eee, so that the device still probes. Platforms that accept the mask are unaffected. Where it is refused, 614f4d166eee never protected the device, it only stopped it from probing, so this restores the behaviour of kernels before that commit. Warn when a status block lands at an address matching the pattern described in 614f4d166eee, so that a resulting TX timeout can be identified.

---
 drivers/net/ethernet/broadcom/tg3.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/tg3.c +18 -3
index 95827df4cf6a..2cf9d2ea069b 100644
@@ -8867,6 +8867,13 @@ static int tg3_alloc_consistent(struct tg3 *tp)
 		if (!tnapi->hw_status)
 			goto err_out;
 
+		if (tg3_asic_rev(tp) == ASIC_REV_57766 &&
+		    (lower_32_bits(tnapi->status_mapping) & 0xffff0000) ==
+		    0xffff0000)
+			dev_warn(&tp->pdev->dev,
+				 "Status block at DMA address %pad may cause TX timeouts on this device\n",
+				 &tnapi->status_mapping);
+
 		sblk = tnapi->hw_status;
 
 		if (tg3_flag(tp, ENABLE_RSS)) {
@@ -17756,6 +17763,7 @@ static int tg3_init_one(struct pci_dev *pdev,
 	u64 dma_mask, persist_dma_mask;
 	netdev_features_t features = 0;
 	u8 addr[ETH_ALEN] __aligned(2);
+	u64 test_dma_mask = 0;
 
 	err = pci_enable_device(pdev);
 	if (err) {
@@ -17895,15 +17903,22 @@ static int tg3_init_one(struct pci_dev *pdev,
 		persist_dma_mask = dma_mask = DMA_BIT_MASK(64);
 
 	if (tg3_asic_rev(tp) == ASIC_REV_57766)
-		persist_dma_mask = DMA_BIT_MASK(31);
+		test_dma_mask = DMA_BIT_MASK(31);
 
 	/* Configure DMA attributes. */
 	if (dma_mask > DMA_BIT_MASK(32)) {
 		err = dma_set_mask(&pdev->dev, dma_mask);
 		if (!err) {
 			features |= NETIF_F_HIGHDMA;
-			err = dma_set_coherent_mask(&pdev->dev,
-						    persist_dma_mask);
+			if (!test_dma_mask ||
+			    dma_set_coherent_mask(&pdev->dev,
+						  test_dma_mask)) {
+				if (test_dma_mask)
+					dev_warn(&pdev->dev,
+						 "Unable to set 31 bit coherent DMA mask, workaround not applied\n");
+				err = dma_set_coherent_mask(&pdev->dev,
+							    persist_dma_mask);
+			}
 			if (err < 0) {
 				dev_err(&pdev->dev, "Unable to obtain 64 bit "
 					"DMA for consistent allocations\n");
Signature · 1 line
2.52.0
author maintainer
#2 lore raw

PATCH v2 2/4 tg3: Select PLL clock when preparing for shutdown

In reply to Pavan Chebbi

When the 5720 was linked up at 1G before power down, it may fail to wake up on a single Magic packet. This is a hardware issue, which can be avoided by locking the PLL clock source before shutdown.

On system suspend or power off with Wake-on-LAN enabled, if the last link speed recorded before power down was 1G, set CPMU_PLL_TLP_CLCK_SRC_NCSI_PLL in TG3_CPMU_PLL_CTRL_STAT, so that the NCSI PLL locks on the TLP clock. The setting is cleared on resume and at probe.

This was reported by a user, who confirmed that this change fixes it.

Fixes ba1f3c76d760 ("tg3: Enable 5720 support")
---
 drivers/net/ethernet/broadcom/tg3.c | 35 +++++++++++++++++++++++++++++
 drivers/net/ethernet/broadcom/tg3.h |  6 ++++-
 2 files changed, 40 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/tg3.c +35 -0
index 2cf9d2ea069b..98338c0792e8 100644
@@ -4267,8 +4267,38 @@ static void tg3_power_down_prepare(struct tg3 *tp)
 	return;
 }
 
+static void tg3_ncsi_pll_tlp_clk(struct tg3 *tp, bool enable)
+{
+	u32 val;
+
+	if (tg3_asic_rev(tp) != ASIC_REV_5720)
+		return;
+
+	/* The register is shared by both functions of the device. */
+	if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO))
+		return;
+
+	val = tr32(TG3_CPMU_PLL_CTRL_STAT);
+	if (enable)
+		val |= CPMU_PLL_TLP_CLCK_SRC_NCSI_PLL;
+	else
+		val &= ~CPMU_PLL_TLP_CLCK_SRC_NCSI_PLL;
+	tw32(TG3_CPMU_PLL_CTRL_STAT, val);
+
+	tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO);
+}
+
+static void tg3_wol_select_pll_clk(struct tg3 *tp)
+{
+	if (device_may_wakeup(&tp->pdev->dev) &&
+	    tg3_flag(tp, WOL_ENABLE) &&
+	    tp->link_config.active_speed == SPEED_1000)
+		tg3_ncsi_pll_tlp_clk(tp, true);
+}
+
 static void tg3_power_down(struct tg3 *tp)
 {
+	tg3_wol_select_pll_clk(tp);
 	pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE));
 	pci_set_power_state(tp->pdev, PCI_D3hot);
 }
@@ -17886,6 +17916,8 @@ static int tg3_init_one(struct pci_dev *pdev,
 		goto err_out_apeunmap;
 	}
 
+	tg3_ncsi_pll_tlp_clk(tp, false);
+
 	/* The EPB bridge inside 5714, 5715, and 5780 and any
 	 * device behind the EPB cannot support DMA addresses > 40-bit.
 	 * On 64-bit systems with IOMMU, use 40-bit dma_mask.
@@ -18222,6 +18254,7 @@ static int tg3_suspend(struct device *device)
 	tg3_full_unlock(tp);
 
 	tg3_power_down_prepare(tp);
+	tg3_wol_select_pll_clk(tp);
 
 unlock:
 	rtnl_unlock();
@@ -18241,6 +18274,8 @@ static int tg3_resume(struct device *device)
 
 	netif_device_attach(dev);
 
+	tg3_ncsi_pll_tlp_clk(tp, false);
+
 	netdev_lock(dev);
 	tg3_full_lock(tp, 0);
 
drivers/net/ethernet/broadcom/tg3.h +5 -1
index a9e7f88fa26d..631bacc515ab 100644
@@ -1168,7 +1168,11 @@
 #define  CPMU_CLCK_STAT_MAC_CLCK_62_5	 0x00000000
 #define  CPMU_CLCK_STAT_MAC_CLCK_12_5	 0x00110000
 #define  CPMU_CLCK_STAT_MAC_CLCK_6_25	 0x00130000
-/* 0x3634 --> 0x365c unused */
+/* 0x3634 unused */
+
+#define TG3_CPMU_PLL_CTRL_STAT		0x00003638
+#define  CPMU_PLL_TLP_CLCK_SRC_NCSI_PLL	0x04000000
+/* 0x363c --> 0x365c unused */
 
 #define TG3_CPMU_MUTEX_REQ		0x0000365c
 #define  CPMU_MUTEX_REQ_DRIVER		 0x00001000
Signature · 1 line
2.52.0
#3 lore raw

Re: [PATCH net v2 2/4] tg3: Select PLL clock when preparing for shutdown

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 4

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The workaround is skipped on system suspend when the interface is administratively down but Wake-on-LAN is armed.
- [Low] Claim: the commit message says the bit is set 'On system suspend or power off', but tg3_power_down() is also reached from…
- [Low] The clear in tg3_resume() (line 18277) sits behind if (!netif_running(dev)) goto unlock;.
- [Low] In tg3_resume(), the new tg3_ncsi_pll_tlp_clk(tp, false) (line 18277) does a BAR0 read-modify-write of TG3_CPMU_PLL_CTRL_STAT.
- [Low] tg3_ncsi_pll_tlp_clk() returns silently if tg3_ape_lock(tp, TG3_APE_LOCK_GPIO) fails.

--

tg3: Select PLL clock when preparing for shutdown

This commit works around a 5720 hardware issue where the device may fail to wake on a single magic packet after being linked at 1G. It sets CPMU_PLL_TLP_CLCK_SRC_NCSI_PLL in TG3_CPMU_PLL_CTRL_STAT on suspend or power off when Wake-on-LAN is enabled and the last link speed was 1G. The bit is cleared on resume and at probe.

Quoted 8 lines
drivers/net/ethernet/broadcom/tg3.c +0 -0
index 2cf9d2ea069b5..98338c0792e84 100644
@@ -4267,8 +4267,38 @@ static void tg3_power_down_prepare(struct tg3 *tp)
 	return;
 }
 

drivers/net/ethernet/broadcom/tg3.c static void tg3_power_down_prepare(struct tg3 *tp) · line 4279

Quoted 10 lines
drivers/net/ethernet/broadcom/tg3.c +10 -0
+static void tg3_ncsi_pll_tlp_clk(struct tg3 *tp, bool enable)
+{
+	u32 val;
+
+	if (tg3_asic_rev(tp) != ASIC_REV_5720)
+		return;
+
+	/* The register is shared by both functions of the device. */
+	if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO))
+		return;

[Severity: Low]
If the lock can't be taken, should this failure be reported somewhere?

On 5720 ENABLE_APE is set, so tg3_ape_lock() busy-waits for about 1ms and then returns -EBUSY. If that happens, the workaround is silently skipped on the power-down path. On the probe and resume paths, the bit silently stays set. Nothing retries and nothing is logged.

On the suspend, resume and shutdown paths, rtnl_lock keeps the two PCI functions from competing for the lock. tg3_frob_aux_power_5717() also returns silently when this lock fails. But contention from the APE/NCSI firmware, or from peer paths during probe that don't hold rtnl, isn't ruled out.

Would a netdev_warn() or a bounded retry make an intermittent WoL failure from this easier to diagnose?

Quoted 2 lines
drivers/net/ethernet/broadcom/tg3.c +2 -0
+
+	val = tr32(TG3_CPMU_PLL_CTRL_STAT);

[ ... ]

drivers/net/ethernet/broadcom/tg3.c static void tg3_power_down_prepare(struct tg3 *tp) · line 4304

Quoted 6 lines

static void tg3_power_down(struct tg3 *tp)
{

drivers/net/ethernet/broadcom/tg3.c +1 -0
+	tg3_wol_select_pll_clk(tp);
 	pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE));
 	pci_set_power_state(tp->pdev, PCI_D3hot);
 }

[Severity: Low]
This probably isn't a bug, but the commit message says "On system suspend or power off". tg3_power_down() is also reached from tg3_shutdown() on restart, halt and kexec on any system not listed in tg3_restart_snp_quirk_table:

tg3_shutdown()

	if (!dmi_first_match(tg3_restart_snp_quirk_table) ||
	    system_state == SYSTEM_POWER_OFF) {
		tg3_power_down(tp);

So the non-default TLP clock source can stay set across a warm reboot until tg3 probes the device again.

The subject line says "shutdown", which covers every .shutdown reason, and the bit can already stay set the same way after power off followed by a WoL wake. This may only be a wording issue.

Could the commit message mention the reboot case too?

[ ... ]

drivers/net/ethernet/broadcom/tg3.c static int tg3_suspend(struct device *device) · line 18257

Quoted 5 lines
drivers/net/ethernet/broadcom/tg3.c +1 -0
@@ -18222,6 +18254,7 @@ static int tg3_suspend(struct device *device)
 	tg3_full_unlock(tp);
 
 	tg3_power_down_prepare(tp);
+	tg3_wol_select_pll_clk(tp);

[Severity: High]
Is the workaround missed when the interface is down but Wake-on-LAN is armed?

tg3_suspend() exits before it gets here:

	if (!netif_running(dev))
		goto unlock;

However, tg3_close() has already armed WoL for the closed interface:

tg3_close()

	tg3_stop(tp);

	if (pci_device_is_present(tp->pdev)) {
		tg3_power_down_prepare(tp);
		...

That sets MAC_MODE_MAGIC_PKT_ENABLE and puts the PHY into WoL mode. link_config.active_speed keeps the speed recorded by the tg3_setup_phy() call in that path. On 5720, if TG3_PHYFLG_KEEP_LINK_ON_PWRDN is set, tg3_phy_copper_begin() leaves the link untouched, so the PHY can stay linked at 1G.

The PCI core then puts the WoL-armed 5720 into D3hot with PME enabled. This happens on S3 suspend, and also on platform-mode hibernation, where .poweroff is tg3_suspend through SIMPLE_DEV_PM_OPS. CPMU_PLL_TLP_CLCK_SRC_NCSI_PLL is never set on that path.

Isn't this the case the commit message describes: "On system suspend or power off with Wake-on-LAN enabled, if the last link speed recorded before power down was 1G"?

The two paths are also inconsistent. tg3_shutdown() calls tg3_power_down() after dev_close() whether or not the interface was running. So a closed interface gets the workaround on power off but not on suspend.

If the closed case gets handled, it would also need a matching clear in tg3_open() or tg3_power_up(). tg3_resume() returns early for a closed interface, and tg3_open() never clears the bit.

drivers/net/ethernet/broadcom/tg3.c static int tg3_resume(struct device *device) · line 18277

Quoted 8 lines
drivers/net/ethernet/broadcom/tg3.c +1 -0
 unlock:
 	rtnl_unlock();
@@ -18241,6 +18274,8 @@ static int tg3_resume(struct device *device)
 
 	netif_device_attach(dev);
 
+	tg3_ncsi_pll_tlp_clk(tp, false);

[Severity: Low]
Can the bit stay set after hibernation restore?

This clear sits after the same netif_running() early exit as the set in tg3_suspend(). During restore, though, the set and the clear run in different kernels.

The restore (boot) kernel runs .freeze, which is tg3_suspend(). If the 5720 interface is up there at 1G with WoL enabled, the bit gets set in hardware. WOL_ENABLE can come from NVRAM at probe.

The image kernel then runs .restore, which is tg3_resume(). If the interface was down in the image kernel, this clear is skipped. Neither tg3_open() nor tg3_power_up() clears the bit, and probe does not run again.

That would leave the bit set during normal operation, which doesn't match "The setting is cleared on resume and at probe". Would clearing it unconditionally before the netif_running() check, or in tg3_open(), avoid this?

[Severity: Low]
This read-modify-write of a BAR0 register now runs before tg3_restart_hw()->tg3_init_hw(). tg3_init_hw() first does this:

tg3_init_hw()

	/* Chip may have been just powered on. If so, the boot code may still
	 * be running initialization. Wait for it to finish to avoid races in
	 * accessing the hardware.
	 */
	tg3_enable_register_access(tp);
	tg3_poll_fw(tp);

pci_restore_state() does not restore TG3PCI_MISC_HOST_CTRL, and its swap settings affect how register data is presented.

If MISC_HOST_CTRL was reset across the D3 to D0 transition, could tr32()/tw32() here act on the wrong bits? And if bootcode is still initializing, could the read-modify-write race with it?

Before this patch, tg3_resume() only touched APE (BAR2) registers before tg3_restart_hw(). Would it be safer to move the clear after tg3_restart_hw(), or to call tg3_enable_register_access() and tg3_poll_fw() first?

Quoted 3 lines
drivers/net/ethernet/broadcom/tg3.c +0 -0
 	netdev_lock(dev);
 	tg3_full_lock(tp, 0);

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111123917.910416-1-pavan.chebbi%40broadcom.com
author maintainer
#4 lore raw

Re: [PATCH net v2 2/4] tg3: Select PLL clock when preparing for shutdown

Quoted 12 lines · On Sun, Nov 15, 2026 at 6:28 PM <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 4

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

Quoted 11 lines

- [High] The workaround is skipped on system suspend when the interface is administratively down but Wake-on-LAN is armed.
- [Low] Claim: the commit message says the bit is set 'On system suspend or power off', but tg3_power_down() is also reached from…
- [Low] The clear in tg3_resume() (line 18277) sits behind if (!netif_running(dev)) goto unlock;.
- [Low] In tg3_resume(), the new tg3_ncsi_pll_tlp_clk(tp, false) (line 18277) does a BAR0 read-modify-write of TG3_CPMU_PLL_CTRL_STAT.
- [Low] tg3_ncsi_pll_tlp_clk() returns silently if tg3_ape_lock(tp, TG3_APE_LOCK_GPIO) fails.

Agree with the findings. I will address in v3.

author maintainer
#5 lore raw

Re: [PATCH net v2 2/4] tg3: Select PLL clock when preparing for shutdown

Quoted 25 lines · Pavan Chebbi
Quoted 12 lines · On Sun, Nov 15, 2026 at 6:28 PM <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 4

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

Quoted 11 lines

- [High] The workaround is skipped on system suspend when the interface is administratively down but Wake-on-LAN is armed.
- [Low] Claim: the commit message says the bit is set 'On system suspend or power off', but tg3_power_down() is also reached from…
- [Low] The clear in tg3_resume() (line 18277) sits behind if (!netif_running(dev)) goto unlock;.
- [Low] In tg3_resume(), the new tg3_ncsi_pll_tlp_clk(tp, false) (line 18277) does a BAR0 read-modify-write of TG3_CPMU_PLL_CTRL_STAT.
- [Low] tg3_ncsi_pll_tlp_clk() returns silently if tg3_ape_lock(tp, TG3_APE_LOCK_GPIO) fails.

Quoted 1 line

Agree with the findings. I will address in v3.

Addressing all sashiko issues has changed the patch drastically from the original and needs re-validation on reported platforms which is going to take time.
I will drop this patch from the series for now until I get it tested.

author maintainer
#6 lore raw

PATCH v2 3/4 tg3: Skip querying for management FW when no NCSI present

In reply to Pavan Chebbi

On BCM5719/BCM5720, when the NCSI component is missing in the NVRAM, driver should not assume that "DASH" management FW is running by default. In this case if user runs ethtool -i command, invalid string "DASH" and garbage DASH FW version is being displayed. However, the 5719/20 chipset cannot have any "DASH" management firmware running.

Hence skip querying the APE FW version registers and adding the "DASH" string to the tp->fw_ver if NCSI is not present. Just report the bootcode version.

This was seen by a user. With this change, ethtool -i displays only the bootcode version.

Fixes ecc796486f0a ("tg3: Detect APE firmware types")
---
 drivers/net/ethernet/broadcom/tg3.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/ethernet/broadcom/tg3.c +6 -4
index 98338c0792e8..4becd1a0b009 100644
@@ -16045,19 +16045,21 @@ static void tg3_probe_ncsi(struct tg3 *tp)
 
 static void tg3_read_dash_ver(struct tg3 *tp)
 {
-	int vlen;
-	u32 apedata;
 	char *fwtype;
-
-	apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION);
+	u32 apedata;
+	int vlen;
 
 	if (tg3_flag(tp, APE_HAS_NCSI))
 		fwtype = "NCSI";
 	else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725)
 		fwtype = "SMASH";
+	else if (tg3_asic_rev(tp) == ASIC_REV_5719 ||
+		 tg3_asic_rev(tp) == ASIC_REV_5720)
+		return;
 	else
 		fwtype = "DASH";
 
+	apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION);
 	vlen = strlen(tp->fw_ver);
 
 	snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d",
Signature · 1 line
2.52.0
#7 lore raw

Re: [PATCH net v2 3/4] tg3: Skip querying for management FW when no NCSI present

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] tg3: missing APE FW readiness check in tg3_read_dash_ver() and wrong Fixes tag

--

Quoted 19 lines
drivers/net/ethernet/broadcom/tg3.c +2 -4
@@ -16045,19 +16045,21 @@ static void tg3_probe_ncsi(struct tg3 *tp)
 
 static void tg3_read_dash_ver(struct tg3 *tp)
 {
-	int vlen;
-	u32 apedata;
 	char *fwtype;
-
-	apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION);
+	u32 apedata;
+	int vlen;
 
 	if (tg3_flag(tp, APE_HAS_NCSI))
 		fwtype = "NCSI";
 	else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725)
 		fwtype = "SMASH";

drivers/net/ethernet/broadcom/tg3.c static void tg3_probe_ncsi(struct tg3 *tp) · line 16065

Quoted 10 lines
drivers/net/ethernet/broadcom/tg3.c +4 -0
+	else if (tg3_asic_rev(tp) == ASIC_REV_5719 ||
+		 tg3_asic_rev(tp) == ASIC_REV_5720)
+		return;
 	else
 		fwtype = "DASH";
 
+	apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION);
 	vlen = strlen(tp->fw_ver);
 
 	snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d",

[Severity: Low]
tg3_read_fw_ver() calls tg3_read_dash_ver() unconditionally after tg3_probe_ncsi(). That happens even when tg3_probe_ncsi() returned early because TG3_APE_SEG_SIG did not match APE_SEG_SIG_MAGIC or APE_FW_STATUS_READY was not set. Isn't the real problem "no APE firmware is present or ready", rather than something specific to 5719/5720?

With this change only 5719/5720 are skipped. Other ENABLE_APE parts such as 5717/5718, 5725, 5761, 5762 and 57764/57767/57787 may have no management firmware. On those, tg3_read_dash_ver() will still read TG3_APE_FW_VERSION out of uninitialized APE shared memory. It then appends a bogus DASH or SMASH version to tp->fw_ver, and ethtool -i reports that.

Before 165f4d1cb3d7 ("tg3: Fix the setting of the APE_HAS_NCSI flag"), tg3_read_dash_ver() did the signature and ready checks itself. tg3_ape_scratchpad_read() and tg3_ape_send_event() still do them before touching APE shared memory.

Could tg3_probe_ncsi() instead report whether valid, ready APE firmware was found? tg3_read_fw_ver() would then only call tg3_read_dash_ver() in that case. Or is there a reason 5719/5720 need to be special cased even when the APE signature and ready bit look valid?

Separately, ecc796486f0a ("tg3: Detect APE firmware types") still had those guards in tg3_read_dash_ver(). So it does not look like the commit that introduced this. Should the Fixes tag point at 165f4d1cb3d7 instead?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111123917.910416-1-pavan.chebbi%40broadcom.com
author maintainer
#8 lore raw

Re: [PATCH net v2 3/4] tg3: Skip querying for management FW when no NCSI present

Quoted 9 lines · On Sun, Nov 15, 2026 at 6:28 PM <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] tg3: missing APE FW readiness check in tg3_read_dash_ver() and wrong Fixes tag

True. Will fix in v3.

author maintainer
#9 lore raw

PATCH v2 4/4 tg3: Fix heap overflow in unbuffered NVRAM write path

In reply to Pavan Chebbi

From: Shravya KN <[email protected]>

tg3_nvram_write_block_unbuffered() reads a whole NVRAM page into a buffer of pagesize bytes, copies the caller's data into it at page_off, and writes the page back. The copy size was clamped to pagesize rather than to the room left in the page, pagesize - page_off, so a write at an offset that is not page aligned, as ETHTOOL_SEEPROM allows, copies past the end of the buffer and corrupts the kernel heap.

Clamp size to pagesize - page_off. Also advance buf by size on each iteration. Without this, a write that spans more than one page programmed every page after the first with the data of the first page, and a write that did not start on a page boundary lost the tail of the data without reporting an error.

Reject a zero nvram_pagesize, which would otherwise make the new size calculation wrap.

This was found by an AI code review scan. It has not been observed on hardware, but it can be reached with ethtool -E on devices with unbuffered flash.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/net/ethernet/broadcom/tg3.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/tg3.c +5 -1
index 4becd1a0b009..7558f4f164ac 100644
@@ -3379,6 +3379,9 @@ static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
 	u32 nvram_cmd;
 	u8 *tmp;
 
+	if (!pagesize)
+		return -EINVAL;
+
 	tmp = kmalloc(pagesize, GFP_KERNEL);
 	if (tmp == NULL)
 		return -ENOMEM;
@@ -3399,13 +3402,14 @@ static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
 			break;
 
 		page_off = offset & pagemask;
-		size = pagesize;
+		size = pagesize - page_off;
 		if (len < size)
 			size = len;
 
 		len -= size;
 
 		memcpy(tmp + page_off, buf, size);
+		buf += size;
 
 		offset = offset + (pagesize - page_off);
 
Signature · 1 line
2.52.0
#10 lore raw

Re: [PATCH net v2 4/4] tg3: Fix heap overflow in unbuffered NVRAM write path

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 (1) · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The patch does not fully fix the bug class it names ("heap overflow in unbuffered NVRAM write path"), and on SST flash its new…
- [Low] The commit message presents the new if (!pagesize) return -EINVAL; check in tg3_nvram_write_block_unbuffered() only as a guard…

Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but in tg3_nvram_write_block_unbuffered() the first WREN, the ERASE and the…

--

tg3: Fix heap overflow in unbuffered NVRAM write path

This patch clamps the copy size in tg3_nvram_write_block_unbuffered() to the room left in the current NVRAM page, and advances buf on every iteration. It also rejects a zero nvram_pagesize before the new size calculation.

drivers/net/ethernet/broadcom/tg3.c static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, · line 3384

Quoted 11 lines
drivers/net/ethernet/broadcom/tg3.c +3 -0
index 4becd1a0b0092..7558f4f164acf 100644
@@ -3379,6 +3379,9 @@ static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
 	u32 nvram_cmd;
 	u8 *tmp;
 
+	if (!pagesize)
+		return -EINVAL;
+

[Severity: Low]

The commit message describes this check only as a guard for the new calculation:

"Reject a zero nvram_pagesize, which would otherwise make the new size calculation wrap."

The check also ends an endless loop that existed before this patch.

The vendor switch in tg3_get_nvram_info() has no default case. That means nvram_pagesize can stay 0 while FLASH is set and NVRAM_BUFFERED is not, so writes go to the unbuffered path.

Before this patch, with pagesize == 0:

- pagemask is 0xffffffff.
- kmalloc(0) returns ZERO_SIZE_PTR, not NULL.
- phy_addr is 0 and the read and program loops don't run.
- size is 0, so len never decreases.
- offset = offset + (0 - page_off) sets offset back to 0.

Each iteration then issues WREN plus an ERASE at NVRAM address 0. The loop ends only if tg3_nvram_exec_cmd() times out, and it runs with rtnl_lock and the NVRAM lock held.

With this patch, ethtool -E returns -EINVAL instead. Could the commit message say so, to help with stable and backport triage?

drivers/net/ethernet/broadcom/tg3.c static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, · line 3405

Quoted 9 lines
drivers/net/ethernet/broadcom/tg3.c +1 -1
 	tmp = kmalloc(pagesize, GFP_KERNEL);
 	if (tmp == NULL)
 		return -ENOMEM;
@@ -3399,13 +3402,14 @@ static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
 			break;
 
 		page_off = offset & pagemask;
-		size = pagesize;
+		size = pagesize - page_off;

[Severity: High]

Does this still overflow tmp[] when nvram_pagesize is not a power of two?

The new check rejects only zero. On 5750 and 5780 class parts with SST flash, tg3_get_nvram_info() sets a 4098 byte page size:

drivers/net/ethernet/broadcom/tg3.h:
#define SST_25VF0X0_PAGE_SIZE 4098

drivers/net/ethernet/broadcom/tg3.c:tg3_get_nvram_info() {
    ...
		case FLASH_VENDOR_SST_SMALL:
		case FLASH_VENDOR_SST_LARGE:
			tp->nvram_jedecnum = JEDEC_SST;
			tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
			break;
    ...
}

NVRAM_BUFFERED is not set there, and FLASH comes from NVRAM_CFG1_FLASHIF_ENAB. So tg3_set_eeprom()->tg3_nvram_write_block() sends these writes to tg3_nvram_write_block_unbuffered().

With pagesize 4098, tmp comes from kmalloc(4098). The read-back loop steps by 4 and reaches j = 4096:

	for (j = 0; j < pagesize; j += 4) {
		ret = tg3_nvram_read_be32(tp, phy_addr + j,
					  (__be32 *) (tmp + j));

That stores 4 bytes at tmp + 4096, which is 2 bytes past the allocation. The program loop later reads the same 2 bytes and writes them to flash.

pagemask is 0x1001, which isn't a valid mask. Offsets are dword aligned, so page_off is either 0 or 0x1000, and phy_addr = offset & ~0x1001 is not sector aligned.

When page_off is 0x1000, the new clamp gives size = 2, so len, buf and offset each advance by only 2 bytes.

For example, take an 8192 byte write at offset 0. The first iteration copies 4098 bytes. About 2047 more iterations follow, and each one erases and reprograms a full page at phy_addr 2, 4, 6, and so on. All of those addresses are inside sector 0, so the data written by the first iteration is erased again.

Even a 4 byte write at offset 0x1000 erases and rewrites sector 0, because phy_addr is 0 there.

The NVRAM_CMD_LAST check in the program loop can never match either:

			else if (j == (pagesize - 4))
				nvram_cmd |= NVRAM_CMD_LAST;

j steps by 4 and pagesize - 4 is 4094.

The commit message says multi-page and unaligned writes are now correct. Should the fix also change SST_25VF0X0_PAGE_SIZE to 4096, or reject a pagesize that fails is_power_of_2() or is not a multiple of 4, instead of rejecting only zero?

drivers/net/ethernet/broadcom/tg3.c static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, · line 3415

Quoted 10 lines
drivers/net/ethernet/broadcom/tg3.c +1 -0
 		if (len < size)
 			size = len;
 
 		len -= size;
 
 		memcpy(tmp + page_off, buf, size);
+		buf += size;
 
 		offset = offset + (pagesize - page_off);
 

[Severity: Medium]

This isn't a bug introduced by this patch, but the erase sequence just below in tg3_nvram_write_block_unbuffered() drops errors:

drivers/net/ethernet/broadcom/tg3.c:tg3_nvram_write_block_unbuffered() {
    ...
		nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;

		if (tg3_nvram_exec_cmd(tp, nvram_cmd))
			break;

		/* Erase the target page */
		tw32(NVRAM_ADDR, phy_addr);

		nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
			NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;

		if (tg3_nvram_exec_cmd(tp, nvram_cmd))
			break;

		/* Issue another write enable to start the write. */
		nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;

		if (tg3_nvram_exec_cmd(tp, nvram_cmd))
			break;
    ...
}

The -EBUSY from tg3_nvram_exec_cmd() is never stored in ret. At this point ret is 0, because the read-back loop just succeeded.

Suppose the ERASE completes but the second WREN times out. The page is left erased and is never reprogrammed. Will the function still return 0, so that tg3_set_eeprom() and ethtool -E report success?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111123917.910416-1-pavan.chebbi%40broadcom.com
author maintainer
#11 lore raw

Re: [PATCH net v2 4/4] tg3: Fix heap overflow in unbuffered NVRAM write path

Quoted 6 lines · On Sun, Nov 15, 2026 at 6:28 PM <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 (1) · Low: 1

Quoted 8 lines

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The patch does not fully fix the bug class it names ("heap overflow in unbuffered NVRAM write path"), and on SST flash its new…

Ok will expand the check to reject any pagesize that is smaller than 4 or not a power of two

Quoted 3 lines

- [Low] The commit message presents the new if (!pagesize) return -EINVAL; check in tg3_nvram_write_block_unbuffered() only as a guard…

Yes, v3 will update.

Quoted 3 lines

Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but in tg3_nvram_write_block_unbuffered() the first WREN, the ERASE and the…

This I believe is outside the scope of this patch. Hence I wish to skip addressing this as part of this series.
To address all the remaining issues:
pw-bot: cr