Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 0/5] ionic: fix register reads racing the BAR unmap on PCI reset
@ 2026-12-04 22:04 Nikhil P. Rao
  2026-12-04 22:04 ` [PATCH net v2 1/5] ionic: fix devcmds " Nikhil P. Rao
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Nikhil P. Rao @ 2026-12-04 22:04 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Richard Cochran
  Cc: netdev, linux-kernel, Eric Joyner, Abhijit Gangurde, Allen Hubbe,
	Nikhil P. Rao, stable

A PCI reset of an ionic device runs ionic_reset_prepare(), which ends
in ionic_clear_pci(): it clears the driver's pointers into BAR0 and
unmaps it. Several readers test one of those pointers and then read
through it without synchronizing with that teardown, so a reset that
lands between the test and the read makes them access the unmapped
BAR. This series closes those windows.

Patch 1 clears and sets the device command registers under
dev_cmd_lock and takes the lock in the two readers that did not.

Patch 2 turns the lockless device info readers (firmware status,
heartbeat and the ethtool register dump) into RCU readers and has the
teardown wait for them.

Patch 3 clears the PHC counter registers under phc->lock when the
reset starts and has the PHC operations check them under that lock.

Patch 4 holds queue_lock while ethtool -C writes the interrupt control
registers, so the update cannot race the queue teardown of either reset.

Patch 5 cancels a queue's DIM work after NAPI is disabled, so a poll
cannot queue it again before the queue is freed and BAR0 unmapped.

The firmware up handler, run from deferred work, also reads the device
info registers. A reset's own admin commands can queue that work after
the reset has cancelled it; a separate series keeps the deferred work
stopped across a reset.

The races in patches 1-3 were reproduced on an AMD Pensando NIC, on a
kernel with KASAN and lockdep, by holding the reader between its check
and its access with a test-only kprobe module while a PCI reset ran:
without the series the access faults on the unmapped BAR, with it the
reset waits for the reader or the reader backs off. The races in patches
4 and 5 were not reproduced. The series was also run through 30 PCI
resets per test under concurrent ethtool, devlink and PHC load with
lockdep enabled, without regressions.

The races in patches 1-3 and 5 were found by Sashiko and the one in
patch 4 by a Claude Code review; Claude Code was also used in developing
and testing the fixes.

Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
---
Changes in v2:
- Patch 1: note in dev_cmd_lock's comment that it protects
  idev.dev_cmd_regs (Sashiko).
- Patch 2: note that dev_info_regs is RCU protected (Sashiko).
- Patch 4: cover the firmware reset path too, retitle, add
  Fixes: c672412f6172 (Sashiko).
- New patch 5: cancel the DIM work after napi_disable() and reset its
  state (Sashiko).
- Link to v1: https://patch.msgid.link/20261202-b4-pr60-v1-0-b1f6706e065b@amd.com

---
Nikhil P. Rao (5):
      ionic: fix devcmds racing the BAR unmap on PCI reset
      ionic: fix device info register reads racing the BAR unmap on PCI reset
      ionic: fix PHC reads racing the BAR unmap on PCI reset
      ionic: fix ethtool coalesce updates racing a reset
      ionic: fix DIM work racing the queue teardown

 drivers/net/ethernet/pensando/ionic/ionic.h        |  3 +-
 .../net/ethernet/pensando/ionic/ionic_bus_pci.c    | 21 ++++++++++++-
 drivers/net/ethernet/pensando/ionic/ionic_dev.c    | 34 +++++++++++++---------
 drivers/net/ethernet/pensando/ionic/ionic_dev.h    |  1 +
 .../net/ethernet/pensando/ionic/ionic_ethtool.c    | 18 ++++++++++--
 drivers/net/ethernet/pensando/ionic/ionic_fw.c     |  6 ++++
 drivers/net/ethernet/pensando/ionic/ionic_lif.c    |  3 +-
 drivers/net/ethernet/pensando/ionic/ionic_lif.h    |  2 +-
 drivers/net/ethernet/pensando/ionic/ionic_phc.c    | 20 +++++++++++--
 9 files changed, 85 insertions(+), 23 deletions(-)
---
base-commit: e9d78fc6741ac06d438cf64e314c28e57014432a
change-id: 20261118-b4-pr60-5fd83c966e7a

Best regards,
--  
Nikhil P. Rao <nikhil.rao@amd.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH net v2 1/5] ionic: fix devcmds racing the BAR unmap on PCI reset
  2026-12-04 22:04 [PATCH net v2 0/5] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
@ 2026-12-04 22:04 ` Nikhil P. Rao
  2026-12-05 23:06   ` netdev-bot+sashiko
  2026-12-04 22:04 ` [PATCH net v2 2/5] ionic: fix device info register reads " Nikhil P. Rao
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Nikhil P. Rao @ 2026-12-04 22:04 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Richard Cochran
  Cc: netdev, linux-kernel, Eric Joyner, Abhijit Gangurde, Allen Hubbe,
	Nikhil P. Rao

ionic_clear_pci() clears idev.dev_cmd_regs and unmaps BAR0 without
dev_cmd_lock, so a devcmd from ethtool or devlink that has just tested
the pointer can access the registers after the unmap.

Make dev_cmd_lock protect dev_cmd_regs. ionic_dev_setup() publishes
dev_info_regs inside the same lock, so a devcmd never finds the
firmware running without its command registers. The identify and port
setup devcmds are left unchanged: they run only from probe and
recovery, which do not race a reset.

Reproduced on an AMD Pensando NIC, on a kernel with KASAN and lockdep,
by holding ethtool -d between the dev_cmd_regs check and its read with
a test-only kprobe module while a PCI reset ran, flushing the local TLB
so the stale mapping faults: without this patch the read faults, with
it the reset waits for the reader.

Fixes: a79b559e99be ("ionic: add FLR recovery support")
Fixes: 7662fad348ac ("ionic: check cmd_regs before copying in or out")
Reported-by: Sashiko AI review <netdev-bot+sashiko@kernel.org>
Closes: https://lore.kernel.org/netdev/179539559673.3135.12079878343644861835@kernel.org/
Reviewed-by: Brett Creeley <brett.creeley@amd.com>
Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
---
 drivers/net/ethernet/pensando/ionic/ionic.h         | 3 ++-
 drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c | 2 ++
 drivers/net/ethernet/pensando/ionic/ionic_dev.c     | 4 ++++
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c | 5 ++++-
 drivers/net/ethernet/pensando/ionic/ionic_fw.c      | 6 ++++++
 5 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic.h b/drivers/net/ethernet/pensando/ionic/ionic.h
index 85198e6a806e6..712718de028bd 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic.h
+++ b/drivers/net/ethernet/pensando/ionic/ionic.h
@@ -42,7 +42,8 @@ struct ionic {
 	struct device *dev;
 	struct devlink_port dl_port;
 	struct ionic_dev idev;
-	struct mutex dev_cmd_lock;	/* lock for dev_cmd operations */
+	/* lock for dev_cmd operations and idev.dev_cmd_regs */
+	struct mutex dev_cmd_lock;
 	struct dentry *dentry;
 	struct ionic_dev_bar bars[IONIC_BARS_MAX];
 	unsigned int num_bars;
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
index ddc2f9770df45..49941fc6bbc41 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
@@ -219,7 +219,9 @@ static void ionic_clear_pci(struct ionic *ionic)
 {
 	if (ionic->num_bars) {
 		ionic->idev.dev_info_regs = NULL;
+		mutex_lock(&ionic->dev_cmd_lock);
 		ionic->idev.dev_cmd_regs = NULL;
+		mutex_unlock(&ionic->dev_cmd_lock);
 		ionic->idev.intr_status = NULL;
 		ionic->idev.intr_ctrl = NULL;
 
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_dev.c b/drivers/net/ethernet/pensando/ionic/ionic_dev.c
index 648d9d24be856..bd41bbcd37a02 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_dev.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_dev.c
@@ -409,8 +409,10 @@ int ionic_dev_setup(struct ionic *ionic)
 		return -EFAULT;
 	}
 
+	mutex_lock(&ionic->dev_cmd_lock);
 	idev->dev_info_regs = bar->vaddr + IONIC_BAR0_DEV_INFO_REGS_OFFSET;
 	idev->dev_cmd_regs = bar->vaddr + IONIC_BAR0_DEV_CMD_REGS_OFFSET;
+	mutex_unlock(&ionic->dev_cmd_lock);
 	idev->intr_status = bar->vaddr + IONIC_BAR0_INTR_STATUS_OFFSET;
 	idev->intr_ctrl = bar->vaddr + IONIC_BAR0_INTR_CTRL_OFFSET;
 
@@ -811,8 +813,10 @@ void ionic_vf_start(struct ionic *ionic)
 	if (!(ionic->ident.dev.capabilities & cpu_to_le64(IONIC_DEV_CAP_VF_CTRL)))
 		return;
 
+	mutex_lock(&ionic->dev_cmd_lock);
 	ionic_dev_cmd_go(&ionic->idev, &cmd);
 	ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
+	mutex_unlock(&ionic->dev_cmd_lock);
 }
 
 /* LIF commands */
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
index 24fd34b4cfccc..d899e44c39027 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
@@ -108,7 +108,10 @@ static void ionic_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
 
 	offset += size;
 	size = IONIC_DEV_CMD_REG_COUNT * sizeof(u32);
-	memcpy_fromio(p + offset, idev->dev_cmd_regs->words, size);
+	mutex_lock(&lif->ionic->dev_cmd_lock);
+	if (idev->dev_cmd_regs)
+		memcpy_fromio(p + offset, idev->dev_cmd_regs->words, size);
+	mutex_unlock(&lif->ionic->dev_cmd_lock);
 }
 
 static void ionic_get_link_ext_stats(struct net_device *netdev,
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_fw.c b/drivers/net/ethernet/pensando/ionic/ionic_fw.c
index 3c209c1a23373..f946c49bc5f6e 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_fw.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_fw.c
@@ -131,6 +131,12 @@ int ionic_firmware_update(struct ionic_lif *lif, const struct firmware *fw,
 
 		copy_sz = min_t(unsigned int, buf_sz, fw->size - offset);
 		mutex_lock(&ionic->dev_cmd_lock);
+		if (!idev->dev_cmd_regs) {
+			mutex_unlock(&ionic->dev_cmd_lock);
+			err = -ENXIO;
+			NL_SET_ERR_MSG_MOD(extack, "Device reset during flash");
+			goto err_out;
+		}
 		memcpy_toio(&idev->dev_cmd_regs->data, fw->data + offset, copy_sz);
 		ionic_dev_cmd_firmware_download(idev,
 						offsetof(union ionic_dev_cmd_regs, data),

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net v2 2/5] ionic: fix device info register reads racing the BAR unmap on PCI reset
  2026-12-04 22:04 [PATCH net v2 0/5] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
  2026-12-04 22:04 ` [PATCH net v2 1/5] ionic: fix devcmds " Nikhil P. Rao
@ 2026-12-04 22:04 ` Nikhil P. Rao
  2026-12-04 22:04 ` [PATCH net v2 3/5] ionic: fix PHC " Nikhil P. Rao
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Nikhil P. Rao @ 2026-12-04 22:04 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Richard Cochran
  Cc: netdev, linux-kernel, Eric Joyner, Abhijit Gangurde, Allen Hubbe,
	Nikhil P. Rao

ionic_clear_pci() clears idev.dev_info_regs and unmaps BAR0 while
lockless readers that only NULL-check it can still be running: the
firmware status and heartbeat checks and the ethtool register dump. A
PCI reset can unmap the BAR between their check and their read.

The readers run in atomic context (the watchdog timer, and
ionic_adminq_post() under adminq_lock), so protect the pointer with RCU
rather than a lock. The pointer is __iomem and sparse allows only one
address space, so the RCU accessors are open-coded.

Reproduced on an AMD Pensando NIC, on a kernel with KASAN and lockdep,
by holding ethtool -d between the dev_info_regs check and its read with
a test-only kprobe module while a PCI reset ran, flushing the local TLB
so the stale mapping faults: without this patch the read faults, with
it the reset waits for the reader.

Fixes: a79b559e99be ("ionic: add FLR recovery support")
Fixes: 219e183272b4 ("ionic: no fw read when PCI reset failed")
Reported-by: sashiko-bot@kernel.org # Running on a local machine
Reviewed-by: Brett Creeley <brett.creeley@amd.com>
Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
---
 .../net/ethernet/pensando/ionic/ionic_bus_pci.c    |  3 ++-
 drivers/net/ethernet/pensando/ionic/ionic_dev.c    | 28 +++++++++++++---------
 drivers/net/ethernet/pensando/ionic/ionic_dev.h    |  1 +
 .../net/ethernet/pensando/ionic/ionic_ethtool.c    | 10 ++++++--
 4 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
index 49941fc6bbc4..07bc61d6f964 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
@@ -218,12 +218,13 @@ static int ionic_sriov_configure(struct pci_dev *pdev, int num_vfs)
 static void ionic_clear_pci(struct ionic *ionic)
 {
 	if (ionic->num_bars) {
-		ionic->idev.dev_info_regs = NULL;
+		WRITE_ONCE(ionic->idev.dev_info_regs, NULL);
 		mutex_lock(&ionic->dev_cmd_lock);
 		ionic->idev.dev_cmd_regs = NULL;
 		mutex_unlock(&ionic->dev_cmd_lock);
 		ionic->idev.intr_status = NULL;
 		ionic->idev.intr_ctrl = NULL;
+		synchronize_rcu();
 
 		ionic_unmap_bars(ionic);
 		pci_release_regions(ionic->pdev);
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_dev.c b/drivers/net/ethernet/pensando/ionic/ionic_dev.c
index bd41bbcd37a0..5ec5af41141a 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_dev.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_dev.c
@@ -410,7 +410,9 @@ int ionic_dev_setup(struct ionic *ionic)
 	}
 
 	mutex_lock(&ionic->dev_cmd_lock);
-	idev->dev_info_regs = bar->vaddr + IONIC_BAR0_DEV_INFO_REGS_OFFSET;
+	/* Pairs with READ_ONCE() in the RCU readers of dev_info_regs */
+	smp_store_release(&idev->dev_info_regs,
+			  bar->vaddr + IONIC_BAR0_DEV_INFO_REGS_OFFSET);
 	idev->dev_cmd_regs = bar->vaddr + IONIC_BAR0_DEV_CMD_REGS_OFFSET;
 	mutex_unlock(&ionic->dev_cmd_lock);
 	idev->intr_status = bar->vaddr + IONIC_BAR0_INTR_STATUS_OFFSET;
@@ -477,21 +479,17 @@ void ionic_dev_teardown(struct ionic *ionic)
 /* Devcmd Interface */
 static bool __ionic_is_fw_running(struct ionic_dev *idev, u8 *status_ptr)
 {
+	union ionic_dev_info_regs __iomem *info_regs;
 	u8 fw_status;
 
-	if (!idev->dev_info_regs) {
-		if (status_ptr)
-			*status_ptr = 0xff;
-		return false;
-	}
+	rcu_read_lock();
+	info_regs = READ_ONCE(idev->dev_info_regs);
+	fw_status = info_regs ? ioread8(&info_regs->fw_status) : 0xff;
+	rcu_read_unlock();
 
-	fw_status = ioread8(&idev->dev_info_regs->fw_status);
 	if (status_ptr)
 		*status_ptr = fw_status;
 
-	/* firmware is useful only if the running bit is set and
-	 * fw_status != 0xff (bad PCI read)
-	 */
 	return (fw_status != 0xff) && (fw_status & IONIC_FW_STS_F_RUNNING);
 }
 
@@ -502,6 +500,7 @@ bool ionic_is_fw_running(struct ionic_dev *idev)
 
 int ionic_heartbeat_check(struct ionic *ionic)
 {
+	union ionic_dev_info_regs __iomem *info_regs;
 	unsigned long check_time, last_check_time;
 	struct ionic_dev *idev = &ionic->idev;
 	struct ionic_lif *lif = ionic->lif;
@@ -598,7 +597,14 @@ int ionic_heartbeat_check(struct ionic *ionic)
 	if (time_before(check_time, last_check_time + DEVCMD_TIMEOUT * 2 * HZ))
 		return 0;
 
-	fw_hb = ioread32(&idev->dev_info_regs->fw_heartbeat);
+	rcu_read_lock();
+	info_regs = READ_ONCE(idev->dev_info_regs);
+	if (!info_regs) {
+		rcu_read_unlock();
+		return -ENXIO;
+	}
+	fw_hb = ioread32(&info_regs->fw_heartbeat);
+	rcu_read_unlock();
 	fw_hb_ready = fw_hb != idev->last_fw_hb;
 
 	/* early FW version had no heartbeat, so fake it */
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_dev.h b/drivers/net/ethernet/pensando/ionic/ionic_dev.h
index 4b3e244e6bbb..6e2366663b48 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_dev.h
+++ b/drivers/net/ethernet/pensando/ionic/ionic_dev.h
@@ -154,6 +154,7 @@ struct ionic_devinfo {
 };
 
 struct ionic_dev {
+	/* RCU: cleared before BAR0 unmap */
 	union ionic_dev_info_regs __iomem *dev_info_regs;
 	union ionic_dev_cmd_regs __iomem *dev_cmd_regs;
 	struct ionic_hwstamp_regs __iomem *hwstamp_regs;
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
index d899e44c3902..1360a3dfb7c6 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
@@ -91,6 +91,7 @@ static int ionic_get_regs_len(struct net_device *netdev)
 static void ionic_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
 			   void *p)
 {
+	union ionic_dev_info_regs __iomem *info_regs;
 	struct ionic_lif *lif = netdev_priv(netdev);
 	struct ionic_dev *idev;
 	unsigned int offset;
@@ -99,12 +100,17 @@ static void ionic_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
 	regs->version = IONIC_DEV_CMD_REG_VERSION;
 
 	idev = &lif->ionic->idev;
-	if (!idev->dev_info_regs)
+	rcu_read_lock();
+	info_regs = READ_ONCE(idev->dev_info_regs);
+	if (!info_regs) {
+		rcu_read_unlock();
 		return;
+	}
 
 	offset = 0;
 	size = IONIC_DEV_INFO_REG_COUNT * sizeof(u32);
-	memcpy_fromio(p + offset, lif->ionic->idev.dev_info_regs->words, size);
+	memcpy_fromio(p + offset, info_regs->words, size);
+	rcu_read_unlock();
 
 	offset += size;
 	size = IONIC_DEV_CMD_REG_COUNT * sizeof(u32);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net v2 3/5] ionic: fix PHC reads racing the BAR unmap on PCI reset
  2026-12-04 22:04 [PATCH net v2 0/5] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
  2026-12-04 22:04 ` [PATCH net v2 1/5] ionic: fix devcmds " Nikhil P. Rao
  2026-12-04 22:04 ` [PATCH net v2 2/5] ionic: fix device info register reads " Nikhil P. Rao
@ 2026-12-04 22:04 ` Nikhil P. Rao
  2026-12-04 22:04 ` [PATCH net v2 4/5] ionic: fix ethtool coalesce updates racing a reset Nikhil P. Rao
  2026-12-04 22:04 ` [PATCH net v2 5/5] ionic: fix DIM work racing the queue teardown Nikhil P. Rao
  4 siblings, 0 replies; 9+ messages in thread
From: Nikhil P. Rao @ 2026-12-04 22:04 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Richard Cochran
  Cc: netdev, linux-kernel, Eric Joyner, Abhijit Gangurde, Allen Hubbe,
	Nikhil P. Rao

ionic_dev_setup() points idev.hwstamp_regs into the BAR0 mapping, but a
PCI reset unmaps BAR0 with the pointer still set. The PHC stays
registered across the reset, and its operations test FW_RESET without a
lock before reading the counter, so one that passed the test just before
the reset reads the unmapped BAR.

Make phc->lock protect the pointer. The timecounter reads the counter
through a callback that cannot report a failure, so each operation has
to check the pointer before it starts the update, and the pointer must
not change until the update ends. ionic_dev_setup() no longer sets the
pointer, since it also runs during reset done, outside phc->lock.

Reproduced on an AMD Pensando NIC, on a kernel with KASAN and lockdep,
by holding phc_ctl get after the FW_RESET test in ionic_phc_gettimex64()
with a test-only kprobe module while a PCI reset ran, flushing the local
TLB so the stale mapping faults: without this patch the counter read
faults, with it the read finds hwstamp_regs cleared.

Fixes: a79b559e99be ("ionic: add FLR recovery support")
Reported-by: sashiko-bot@kernel.org # Running on a local machine
Reviewed-by: Brett Creeley <brett.creeley@amd.com>
Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
---
 drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c | 16 ++++++++++++++++
 drivers/net/ethernet/pensando/ionic/ionic_dev.c     |  2 --
 drivers/net/ethernet/pensando/ionic/ionic_lif.h     |  2 +-
 drivers/net/ethernet/pensando/ionic/ionic_phc.c     | 20 +++++++++++++++++---
 4 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
index 07bc61d6f964..1c283280ce83 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
@@ -444,6 +444,19 @@ static void ionic_remove(struct pci_dev *pdev)
 	ionic_devlink_free(ionic);
 }
 
+static void ionic_phc_set_regs(struct ionic_lif *lif,
+			       struct ionic_hwstamp_regs __iomem *regs)
+{
+	unsigned long irqflags;
+
+	if (!lif->phc)
+		return;
+
+	spin_lock_irqsave(&lif->phc->lock, irqflags);
+	lif->ionic->idev.hwstamp_regs = regs;
+	spin_unlock_irqrestore(&lif->phc->lock, irqflags);
+}
+
 static void ionic_reset_prepare(struct pci_dev *pdev)
 {
 	struct ionic *ionic = pci_get_drvdata(pdev);
@@ -452,6 +465,7 @@ static void ionic_reset_prepare(struct pci_dev *pdev)
 	dev_dbg(ionic->dev, "%s: device stopping\n", __func__);
 
 	set_bit(IONIC_LIF_F_FW_RESET, lif->state);
+	ionic_phc_set_regs(lif, NULL);
 
 	timer_delete_sync(&ionic->watchdog_timer);
 	cancel_work_sync(&lif->deferred.work);
@@ -480,6 +494,8 @@ static void ionic_reset_done(struct pci_dev *pdev)
 	if (err)
 		goto err_out;
 
+	ionic_phc_set_regs(lif, &ionic->idev.dev_info_regs->hwstamp);
+
 	ionic_debugfs_add_sizes(ionic);
 	ionic_debugfs_add_lif(ionic->lif);
 
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_dev.c b/drivers/net/ethernet/pensando/ionic/ionic_dev.c
index 5ec5af41141a..ce6944f24734 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_dev.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_dev.c
@@ -418,8 +418,6 @@ int ionic_dev_setup(struct ionic *ionic)
 	idev->intr_status = bar->vaddr + IONIC_BAR0_INTR_STATUS_OFFSET;
 	idev->intr_ctrl = bar->vaddr + IONIC_BAR0_INTR_CTRL_OFFSET;
 
-	idev->hwstamp_regs = &idev->dev_info_regs->hwstamp;
-
 	sig = ioread32(&idev->dev_info_regs->signature);
 	if (sig != IONIC_DEV_INFO_SIGNATURE) {
 		dev_err(dev, "Incompatible firmware signature %x", sig);
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.h b/drivers/net/ethernet/pensando/ionic/ionic_lif.h
index e790f6b9441e..5def4ae13863 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_lif.h
+++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.h
@@ -248,7 +248,7 @@ struct ionic_lif {
 };
 
 struct ionic_phc {
-	spinlock_t lock; /* lock for state_page, cc and tc */
+	spinlock_t lock; /* lock for state_page, cc, tc and idev.hwstamp_regs */
 	struct cyclecounter cc;
 	struct timecounter tc;
 
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_phc.c b/drivers/net/ethernet/pensando/ionic/ionic_phc.c
index 388150cbf7e4..2631bc3e9580 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_phc.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_phc.c
@@ -377,6 +377,10 @@ static int ionic_phc_adjfine(struct ptp_clock_info *info, long scaled_ppm)
 	adj += phc->init_cc_mult;
 
 	spin_lock_irqsave(&phc->lock, irqflags);
+	if (!phc->lif->ionic->idev.hwstamp_regs) {
+		spin_unlock_irqrestore(&phc->lock, irqflags);
+		return -EBUSY;
+	}
 
 	/* update the point-in-time basis to now, before adjusting the rate */
 	timecounter_read(&phc->tc);
@@ -437,6 +441,10 @@ static int ionic_phc_settime64(struct ptp_clock_info *info,
 	ns = timespec64_to_ns(ts);
 
 	spin_lock_irqsave(&phc->lock, irqflags);
+	if (!phc->lif->ionic->idev.hwstamp_regs) {
+		spin_unlock_irqrestore(&phc->lock, irqflags);
+		return -EBUSY;
+	}
 
 	timecounter_init(&phc->tc, &phc->cc, ns);
 
@@ -466,6 +474,10 @@ static int ionic_phc_gettimex64(struct ptp_clock_info *info,
 		return -EBUSY;
 
 	spin_lock_irqsave(&phc->lock, irqflags);
+	if (!ionic->idev.hwstamp_regs) {
+		spin_unlock_irqrestore(&phc->lock, irqflags);
+		return -EBUSY;
+	}
 
 	tick = ionic_hwstamp_read(ionic, sts);
 
@@ -495,6 +507,10 @@ static long ionic_phc_aux_work(struct ptp_clock_info *info)
 		return phc->aux_work_delay;
 
 	spin_lock_irqsave(&phc->lock, irqflags);
+	if (!phc->lif->ionic->idev.hwstamp_regs) {
+		spin_unlock_irqrestore(&phc->lock, irqflags);
+		return phc->aux_work_delay;
+	}
 
 	/* update point-in-time basis to now */
 	timecounter_read(&phc->tc);
@@ -576,9 +592,6 @@ void ionic_lif_alloc_phc(struct ionic_lif *lif)
 	u64 features;
 	u32 shift;
 
-	if (!ionic->idev.hwstamp_regs)
-		return;
-
 	features = le64_to_cpu(ionic->ident.lif.eth.config.features);
 	if (!(features & (IONIC_ETH_HW_TIMESTAMP | IONIC_ETH_HW_RDMA_TIMESTAMP)))
 		return;
@@ -672,6 +685,7 @@ void ionic_lif_alloc_phc(struct ionic_lif *lif)
 	/* frequency adjustments are relative to the initial multiplier */
 	phc->init_cc_mult = phc->cc.mult;
 
+	ionic->idev.hwstamp_regs = &ionic->idev.dev_info_regs->hwstamp;
 	timecounter_init(&phc->tc, &phc->cc, ktime_get_real_ns());
 
 	/* Update cycle_last at 1/4 the wrap period, or IONIC_PHC_UPDATE_NS */

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net v2 4/5] ionic: fix ethtool coalesce updates racing a reset
  2026-12-04 22:04 [PATCH net v2 0/5] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
                   ` (2 preceding siblings ...)
  2026-12-04 22:04 ` [PATCH net v2 3/5] ionic: fix PHC " Nikhil P. Rao
@ 2026-12-04 22:04 ` Nikhil P. Rao
  2026-12-05 23:06   ` netdev-bot+sashiko
  2026-12-04 22:04 ` [PATCH net v2 5/5] ionic: fix DIM work racing the queue teardown Nikhil P. Rao
  4 siblings, 1 reply; 9+ messages in thread
From: Nikhil P. Rao @ 2026-12-04 22:04 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Richard Cochran
  Cc: netdev, linux-kernel, Eric Joyner, Abhijit Gangurde, Allen Hubbe,
	Nikhil P. Rao, stable

ionic_set_coalesce() runs under rtnl only. It saves the new settings,
tests LIF_F_UP and writes each queue's interrupt control register in
BAR0. A PCI reset or a firmware reset clears LIF_F_UP and frees the
queues without rtnl, and the PCI reset also unmaps BAR0, so an update
that passed the test just before the reset reads freed queues and can
write the unmapped BAR. The restart after either reset also programs
the new queues from the saved settings without rtnl, so it can pick up
a half-written update.

The teardown and the restart of both resets run under queue_lock, so
take it for the whole update. ethtool's ring and channel changes
already take queue_lock under rtnl.

Found by an AI code review of this series and confirmed by reading the
code. Not reproduced, as there is no call between the test and the
register write where a test module could hold the update. Tested on an
AMD Pensando NIC, on a kernel with KASAN and lockdep, with ethtool -C
running during 30 PCI resets.

Fixes: c672412f6172 ("ionic: remove lifs on fw reset")
Fixes: a79b559e99be ("ionic: add FLR recovery support")
Cc: <stable@vger.kernel.org> # 5.10.x: 2624d95972db: ionic: widen queue_lock use around lif init and deinit
Cc: <stable@vger.kernel.org> # 5.10.x
Reviewed-by: Brett Creeley <brett.creeley@amd.com>
Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
---
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
index 1360a3dfb7c6..bc0601dbcf63 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
@@ -555,6 +555,8 @@ static int ionic_set_coalesce(struct net_device *netdev,
 	    tx_coal > IONIC_INTR_CTRL_COAL_MAX)
 		return -ERANGE;
 
+	mutex_lock(&lif->queue_lock);
+
 	/* Save the new values */
 	lif->rx_coalesce_usecs = coalesce->rx_coalesce_usecs;
 	lif->rx_coalesce_hw = rx_coal;
@@ -598,6 +600,7 @@ static int ionic_set_coalesce(struct net_device *netdev,
 			}
 		}
 	}
+	mutex_unlock(&lif->queue_lock);
 
 	return 0;
 }

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net v2 5/5] ionic: fix DIM work racing the queue teardown
  2026-12-04 22:04 [PATCH net v2 0/5] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
                   ` (3 preceding siblings ...)
  2026-12-04 22:04 ` [PATCH net v2 4/5] ionic: fix ethtool coalesce updates racing a reset Nikhil P. Rao
@ 2026-12-04 22:04 ` Nikhil P. Rao
  2026-12-05 23:06   ` netdev-bot+sashiko
  4 siblings, 1 reply; 9+ messages in thread
From: Nikhil P. Rao @ 2026-12-04 22:04 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Richard Cochran
  Cc: netdev, linux-kernel, Eric Joyner, Abhijit Gangurde, Allen Hubbe,
	Nikhil P. Rao

ionic_qcq_disable() cancels a queue's DIM work before it masks the
interrupt and disables NAPI, so a poll that runs in between can queue
the work again. The queue is freed when the interface goes down or a
reset tears it down, and a PCI reset also unmaps BAR0, so the requeued
work then writes the interrupt control register through the freed
queue and can write the unmapped BAR.

Cancel the work once NAPI is disabled, when no poll can queue it again.
A work item the cancel drops is what would have returned DIM to
measuring, so reset its state there too; otherwise DIM stays stuck when
the queues restart on the same qcq after a link flap or reconfiguration.

Found by an AI code review of the previous version of this series and
confirmed by reading the code. Not reproduced, as nothing can hold a
NAPI poll between the cancel and napi_disable(). Tested on an AMD
Pensando NIC, on a kernel with KASAN and lockdep, with the PCI reset
tests.

Fixes: 04a834592bf5 ("ionic: dynamic interrupt moderation")
Reported-by: Sashiko AI review <netdev-bot+sashiko@kernel.org>
Closes: https://lore.kernel.org/netdev/179625854521.3146.11030796304497825514@kernel.org/
Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
---
 drivers/net/ethernet/pensando/ionic/ionic_lif.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
index 339a3c4c5b43..909781f06496 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
@@ -358,13 +358,14 @@ static int ionic_qcq_disable(struct ionic_lif *lif, struct ionic_qcq *qcq, int f
 
 		if (lif->doorbell_wa)
 			cancel_work_sync(&qcq->doorbell_napi_work);
-		cancel_work_sync(&qcq->dim.work);
 		ionic_intr_mask(idev->intr_ctrl, qcq->intr.index,
 				IONIC_INTR_MASK_SET);
 		synchronize_irq(qcq->intr.vector);
 		irq_set_affinity_notifier(qcq->intr.vector, NULL);
 		irq_set_affinity_hint(qcq->intr.vector, NULL);
 		napi_disable(&qcq->napi);
+		cancel_work_sync(&qcq->dim.work);
+		qcq->dim.state = DIM_START_MEASURE;
 	}
 
 	/* If there was a previous fw communcation error, don't bother with

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH net v2 1/5] ionic: fix devcmds racing the BAR unmap on PCI reset
  2026-12-04 22:04 ` [PATCH net v2 1/5] ionic: fix devcmds " Nikhil P. Rao
@ 2026-12-05 23:06   ` netdev-bot+sashiko
  0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 23:06 UTC (permalink / raw)
  To: nikhil.rao
  Cc: brett.creeley, andrew+netdev, davem, edumazet, kuba, pabeni,
	richardcochran, netdev, linux-kernel, eric.joyner,
	abhijit.gangurde, allen.hubbe

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] ionic: commit message omits ionic_vf_start() fix and misstates
  callers

--

> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_dev.c b/drivers/net/ethernet/pensando/ionic/ionic_dev.c
> --- a/drivers/net/ethernet/pensando/ionic/ionic_dev.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_dev.c
> @@ -811,8 +813,10 @@ void ionic_vf_start(struct ionic *ionic)
>  	if (!(ionic->ident.dev.capabilities & cpu_to_le64(IONIC_DEV_CAP_VF_CTRL)))
>  		return;
>  
> +	mutex_lock(&ionic->dev_cmd_lock);
>  	ionic_dev_cmd_go(&ionic->idev, &cmd);
>  	ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
> +	mutex_unlock(&ionic->dev_cmd_lock);
>  }
>  
>  /* LIF commands */

[Severity: Low]
The ionic_vf_start() hunk does more than apply the new rule. Before
this patch, ionic_vf_start() issued IONIC_CMD_VF_CTRL through
ionic_dev_cmd_go() and ionic_dev_cmd_wait() without dev_cmd_lock.
That let it interleave with any other devcmd, whether or not a reset
was in progress. This is a separate fix, and the commit message does
not mention it. Could you call it out in the changelog? Is the
existing Fixes: list right for it, or does it need its own tag?

The changelog also says the identify and port setup devcmds "run only
from probe and recovery". That is not quite accurate:
ionic_port_identify() is also called from ionic_link_status_check()
on link-up.

If I read it right, that path is still safe. It takes dev_cmd_lock,
and ionic_dev_teardown() destroys ionic->wq before ionic_clear_pci()
runs. Please have the changelog give that reasoning instead of
claiming these devcmds never run outside probe and recovery.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-pr60-v2-0-9e0b5408a68e%40amd.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net v2 4/5] ionic: fix ethtool coalesce updates racing a reset
  2026-12-04 22:04 ` [PATCH net v2 4/5] ionic: fix ethtool coalesce updates racing a reset Nikhil P. Rao
@ 2026-12-05 23:06   ` netdev-bot+sashiko
  0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 23:06 UTC (permalink / raw)
  To: nikhil.rao
  Cc: brett.creeley, andrew+netdev, davem, edumazet, kuba, pabeni,
	richardcochran, netdev, linux-kernel, eric.joyner,
	abhijit.gangurde, allen.hubbe

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

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

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).

- [Medium] ionic_set_coalesce()
  (drivers/net/ethernet/pensando/ionic/ionic_ethtool.c) reads…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the ethtool -S
  callback in the same file has the same race the patch fixes for…

--

ionic: fix ethtool coalesce updates racing a reset

This patch holds lif->queue_lock across the whole update in
ionic_set_coalesce(). That covers saving the new settings and writing
each queue's interrupt control register. The PCI and firmware reset
paths tear down and restart the queues under queue_lock without rtnl,
so the lock keeps the coalesce update from racing them.

> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
> index 1360a3dfb7c66..bc0601dbcf63a 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
> @@ -555,6 +555,8 @@ static int ionic_set_coalesce(struct net_device *netdev,
>  	    tx_coal > IONIC_INTR_CTRL_COAL_MAX)
>  		return -ERANGE;
>  
> +	mutex_lock(&lif->queue_lock);
> +
>  	/* Save the new values */
>  	lif->rx_coalesce_usecs = coalesce->rx_coalesce_usecs;
>  	lif->rx_coalesce_hw = rx_coal;

[Severity: Medium]
Can rx_coal and tx_coal still be computed from a half-rewritten ident
during a reset? ionic_set_coalesce() reads the ident values and does
the conversions before it takes the lock:

	ident = &lif->ionic->ident;
	if (ident->dev.intr_coal_div == 0) {
	...
	rx_coal = ionic_coal_usec_to_hw(lif->ionic, coalesce->rx_coalesce_usecs);
	if (!rx_coal && coalesce->rx_coalesce_usecs)
		rx_coal = 1;

During PCI reset recovery, ionic_reset_done()->ionic_setup_one()->
ionic_identify() rewrites ident. It holds neither rtnl nor queue_lock:

ionic_identify() {
	memset(ident, 0, sizeof(*ident));
	...
	err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
	if (!err) {
		sz = min(sizeof(ident->dev), sizeof(idev->dev_cmd_regs->data));
		memcpy_fromio(&ident->dev, &idev->dev_cmd_regs->data, sz);
	}
	...
}

The firmware-up path does the same through ionic_lif_handle_fw_up()->
ionic_identify(). ionic_reset_prepare() doesn't call
netif_device_detach(), so ethtool -C can run during this window.
Nothing in ionic_set_coalesce() checks IONIC_LIF_F_FW_RESET.

If ethtool -C reads the zeroed divisor, it returns a spurious -EIO.

It can also pass the divisor check just before the memset, or read mult
and div at different points in the rewrite. In both cases
ionic_coal_usec_to_hw() returns 0:

	if (!div || !mult)
		return 0;

Any non-zero request is then forced to 1. Under the new lock, that 1 is
stored in lif->rx_coalesce_hw and lif->tx_coalesce_hw. Then
ionic_restart_lif()->ionic_txrx_alloc() programs it into every new
queue.

The commit message says the restart "can pick up a half-written update"
and that taking queue_lock for the whole update fixes this. Is that
fully covered while the inputs are still read outside the lock, from
state the reset rewrites?

Would it help to move the conversion under queue_lock and return -EBUSY
while IONIC_LIF_F_FW_RESET is set, as ionic_set_channels() already
does?

> @@ -598,6 +600,7 @@ static int ionic_set_coalesce(struct net_device *netdev,
>  			}
>  		}
>  	}
> +	mutex_unlock(&lif->queue_lock);
>  
>  	return 0;
>  }

[Severity: High]
This is a pre-existing issue and was not introduced by this patch.
ionic_get_stats() in the same file looks like it has the same
check-then-use race against the reset paths:

ionic_get_stats() {
	...
	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
		return;

	memset(buf, 0, stats->n_stats * sizeof(*buf));
	for (i = 0; i < ionic_num_stats_grps; i++)
		ionic_stats_groups[i].get_values(lif, &buf);
}

This runs under rtnl only. The get_values callbacks reach these
functions:

  ionic_sw_stats_get_values()->ionic_get_lif_stats()->
      ionic_add_lif_txq_stats() / ionic_add_lif_rxq_stats()
  ionic_sw_stats_get_txq_values() / ionic_sw_stats_get_rxq_values()

All of them index &lif->txqstats[q_num] and &lif->rxqstats[q_num] for
each queue.

ionic_reset_prepare() and ionic_lif_handle_fw_down() both set
IONIC_LIF_F_FW_RESET. They then call ionic_qcqs_free() under queue_lock,
without rtnl:

ionic_qcqs_free() {
	...
	if (lif->rxqcqs) {
		devm_kfree(dev, lif->rxqstats);
		lif->rxqstats = NULL;
	...
	if (lif->txqcqs) {
		devm_kfree(dev, lif->txqstats);
		lif->txqstats = NULL;
	...
}

ionic_reset_prepare() never calls netif_device_detach(), so the
netif_device_present() check in the ethtool core doesn't block callers
during a PCI reset. In the firmware reset path, the detach happens after
a caller may already have passed that check.

Suppose ethtool -S passes the IONIC_LIF_F_FW_RESET test just before the
reset sets the bit. Can it still be in the read loop when these arrays
are freed? It would then copy freed memory into the user's stats buffer,
or read through a NULL base and oops.

Does ionic_get_stats() need the same queue_lock treatment as
ionic_set_coalesce()?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-pr60-v2-0-9e0b5408a68e%40amd.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net v2 5/5] ionic: fix DIM work racing the queue teardown
  2026-12-04 22:04 ` [PATCH net v2 5/5] ionic: fix DIM work racing the queue teardown Nikhil P. Rao
@ 2026-12-05 23:06   ` netdev-bot+sashiko
  0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 23:06 UTC (permalink / raw)
  To: nikhil.rao
  Cc: brett.creeley, andrew+netdev, davem, edumazet, kuba, pabeni,
	richardcochran, netdev, linux-kernel, eric.joyner,
	abhijit.gangurde, allen.hubbe

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

Critical: 0 · High: 1 · Medium: 0 · 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's stated claim, "Cancel the work once NAPI is
  disabled, when no poll can queue it again", does not hold for ionic,…
- [Low] When cancel_work_sync(&qcq->dim.work) in ionic_qcq_disable()
  drops a pending ionic_dim_work(), the patch copies only the handler's…

--

ionic: fix DIM work racing the queue teardown

This moves cancel_work_sync(&qcq->dim.work) in ionic_qcq_disable() so it
runs after napi_disable(). The goal is that a NAPI poll can no longer
requeue the DIM work on a queue that is about to be freed. It also resets
qcq->dim.state to DIM_START_MEASURE in place of a dropped work item.

Closes: https://lore.kernel.org/netdev/179625854521.3146.11030796304497825514@kernel.org/

> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> index 339a3c4c5b432..909781f064967 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> @@ -358,13 +358,14 @@ static int ionic_qcq_disable(struct ionic_lif *lif, struct ionic_qcq *qcq, int f
>  
>  		if (lif->doorbell_wa)
>  			cancel_work_sync(&qcq->doorbell_napi_work);
> -		cancel_work_sync(&qcq->dim.work);
>  		ionic_intr_mask(idev->intr_ctrl, qcq->intr.index,
>  				IONIC_INTR_MASK_SET);
>  		synchronize_irq(qcq->intr.vector);
>  		irq_set_affinity_notifier(qcq->intr.vector, NULL);
>  		irq_set_affinity_hint(qcq->intr.vector, NULL);
>  		napi_disable(&qcq->napi);
> +		cancel_work_sync(&qcq->dim.work);

[Severity: High]
The commit message says:

  Cancel the work once NAPI is disabled, when no poll can queue it again.

Does that hold for ionic? In ionic_tx_napi(), ionic_rx_napi() and
ionic_txrx_napi(), ionic_dim_update() is only called after
napi_complete_done() has returned true:

drivers/net/ethernet/pensando/ionic/ionic_txrx.c:ionic_tx_napi() {
    ...
	if (work_done < budget && napi_complete_done(napi, work_done)) {
		ionic_dim_update(qcq, IONIC_LIF_F_TX_DIM_INTR);
    ...
}

At that point napi_complete_done() has already cleared NAPIF_STATE_SCHED.
napi_disable_locked() only waits while NAPIF_STATE_SCHED or
NAPIF_STATE_NPSVC is set.

So napi_disable() can return while the poll is still running on another
CPU. That poll may not yet have reached ionic_dim_update()->net_dim(),
which calls schedule_work(&dim->work).

Could this interleaving happen?

CPU0 (NAPI poll)                 CPU1 (ionic_qcq_disable)
napi_complete_done()
  clears NAPIF_STATE_SCHED
                                 ionic_intr_mask()
                                 synchronize_irq()
                                 napi_disable()   /* returns */
                                 cancel_work_sync(&qcq->dim.work)
                                 qcq->dim.state = DIM_START_MEASURE
ionic_dim_update()
  net_dim()
    dim->state = DIM_APPLY_NEW_PROFILE
    schedule_work(&dim->work)

This is the only cancel of dim.work in the driver. Teardown then goes
through ionic_txrx_deinit()->ionic_lif_qcq_deinit(). There,
netif_napi_del() waits for the poll to return, but by then the work is
already queued.

After that, ionic_txrx_free()->ionic_qcq_free() and devm_kfree() free the
qcq that embeds dim.work.

On the PCI reset path, ionic_reset_prepare() also reaches
ionic_clear_pci(), which does:

		ionic->idev.intr_ctrl = NULL;
		synchronize_rcu();

		ionic_unmap_bars(ionic);

A late ionic_dim_work() would then use container_of() to get back to the
freed qcq. It could also call ionic_intr_coal_init() through a NULL or
unmapped intr_ctrl.

Isn't that the same use-after-free and unmapped BAR write this patch is
meant to fix?

The window is short on non-RT kernels. A hardirq on CPU0 makes it wider,
and on PREEMPT_RT the NAPI poll can be preempted.

Would either of these close it?

- Cancel dim.work and reset the DIM state only once the poll is known to
  have returned, for example after netif_napi_del() in
  ionic_lif_qcq_deinit().
- Add synchronize_net() between napi_disable() and cancel_work_sync().

> +		qcq->dim.state = DIM_START_MEASURE;

[Severity: Low]
When cancel_work_sync() drops a pending ionic_dim_work(), this line copies
only the handler's last step. Is resetting dim.state alone enough to keep
DIM consistent with the hardware?

net_dim_decision() has already moved dim->profile_ix forward before
net_dim() sets DIM_APPLY_NEW_PROFILE and queues the work.
ionic_dim_work() is the only place where profile_ix is written to the
hardware:

drivers/net/ethernet/pensando/ionic/ionic_lif.c:ionic_dim_work() {
    ...
	intr = &qcq->intr;
	if (intr->dim_coal_hw != new_coal) {
		intr->dim_coal_hw = new_coal;

		ionic_intr_coal_init(lif->ionic->idev.intr_ctrl,
				     intr->index, intr->dim_coal_hw);
	}

	dim->state = DIM_START_MEASURE;
}

After the drop, the coalesce register and intr->dim_coal_hw still hold
the old profile's value, while profile_ix names the new profile.

The coalesce value is also not reapplied when the queues restart on the
same qcq. The path ionic_stop_queues(), then ionic_start_queues() and
ionic_qcq_enable(), never writes it.

If DIM then parks on top with steady traffic, it will not change profile
again. The hardware could stay on the value DIM decided to leave until
DIM changes profile again.

Would flush_work() here, or rolling profile_ix back, keep DIM in sync
with the hardware? flush_work() should still be safe at this point,
because ionic_intr_mask() earlier in the same block already writes
through intr_ctrl.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-pr60-v2-0-9e0b5408a68e%40amd.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-12-05 23:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 22:04 [PATCH net v2 0/5] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
2026-12-04 22:04 ` [PATCH net v2 1/5] ionic: fix devcmds " Nikhil P. Rao
2026-12-05 23:06   ` netdev-bot+sashiko
2026-12-04 22:04 ` [PATCH net v2 2/5] ionic: fix device info register reads " Nikhil P. Rao
2026-12-04 22:04 ` [PATCH net v2 3/5] ionic: fix PHC " Nikhil P. Rao
2026-12-04 22:04 ` [PATCH net v2 4/5] ionic: fix ethtool coalesce updates racing a reset Nikhil P. Rao
2026-12-05 23:06   ` netdev-bot+sashiko
2026-12-04 22:04 ` [PATCH net v2 5/5] ionic: fix DIM work racing the queue teardown Nikhil P. Rao
2026-12-05 23:06   ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox