* [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-04 22:04 ` [PATCH net v2 2/5] ionic: fix device info register reads " Nikhil P. Rao
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ 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-04 22:04 ` [PATCH net v2 5/5] ionic: fix DIM work racing the queue teardown Nikhil P. Rao
4 siblings, 0 replies; 6+ 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] 6+ 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
4 siblings, 0 replies; 6+ 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] 6+ messages in thread