* [PATCH net 0/4] ionic: fix register reads racing the BAR unmap on PCI reset
@ 2026-12-02 0:38 Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 1/4] ionic: fix devcmds " Nikhil P. Rao
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Nikhil P. Rao @ 2026-12-02 0:38 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
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.
The races in patches 1-3 were reproduced on an AMD Pensando NIC under
KASAN 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 race in patch 4 was 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 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>
---
Nikhil P. Rao (4):
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 PCI reset
.../net/ethernet/pensando/ionic/ionic_bus_pci.c | 21 ++++++++++++-
drivers/net/ethernet/pensando/ionic/ionic_dev.c | 34 +++++++++++++---------
.../net/ethernet/pensando/ionic/ionic_ethtool.c | 18 ++++++++++--
drivers/net/ethernet/pensando/ionic/ionic_fw.c | 6 ++++
drivers/net/ethernet/pensando/ionic/ionic_lif.h | 2 +-
drivers/net/ethernet/pensando/ionic/ionic_phc.c | 20 +++++++++++--
6 files changed, 80 insertions(+), 21 deletions(-)
---
base-commit: 0e4c3240b03093264d501ab24c65726d29921987
change-id: 20261118-b4-pr60-5fd83c966e7a
Best regards,
--
Nikhil P. Rao <nikhil.rao@amd.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net 1/4] ionic: fix devcmds racing the BAR unmap on PCI reset
2026-12-02 0:38 [PATCH net 0/4] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
@ 2026-12-02 0:38 ` Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 2/4] ionic: fix device info register reads " Nikhil P. Rao
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Nikhil P. Rao @ 2026-12-02 0:38 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 under KASAN 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_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 ++++++
4 files changed, 16 insertions(+), 1 deletion(-)
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 [flat|nested] 5+ messages in thread
* [PATCH net 2/4] ionic: fix device info register reads racing the BAR unmap on PCI reset
2026-12-02 0:38 [PATCH net 0/4] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 1/4] ionic: fix devcmds " Nikhil P. Rao
@ 2026-12-02 0:38 ` Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 3/4] ionic: fix PHC " Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 4/4] ionic: fix ethtool coalesce updates racing a " Nikhil P. Rao
3 siblings, 0 replies; 5+ messages in thread
From: Nikhil P. Rao @ 2026-12-02 0:38 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 under KASAN 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 +++++++++++++---------
.../net/ethernet/pensando/ionic/ionic_ethtool.c | 10 ++++++--
3 files changed, 27 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_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 [flat|nested] 5+ messages in thread
* [PATCH net 3/4] ionic: fix PHC reads racing the BAR unmap on PCI reset
2026-12-02 0:38 [PATCH net 0/4] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 1/4] ionic: fix devcmds " Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 2/4] ionic: fix device info register reads " Nikhil P. Rao
@ 2026-12-02 0:38 ` Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 4/4] ionic: fix ethtool coalesce updates racing a " Nikhil P. Rao
3 siblings, 0 replies; 5+ messages in thread
From: Nikhil P. Rao @ 2026-12-02 0:38 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 under KASAN 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 [flat|nested] 5+ messages in thread
* [PATCH net 4/4] ionic: fix ethtool coalesce updates racing a PCI reset
2026-12-02 0:38 [PATCH net 0/4] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
` (2 preceding siblings ...)
2026-12-02 0:38 ` [PATCH net 3/4] ionic: fix PHC " Nikhil P. Rao
@ 2026-12-02 0:38 ` Nikhil P. Rao
3 siblings, 0 replies; 5+ messages in thread
From: Nikhil P. Rao @ 2026-12-02 0:38 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_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 clears LIF_F_UP, frees the queues and unmaps BAR0
without rtnl, so an update that passed the test just before the reset
reads freed queues and writes the unmapped BAR. The restart after the
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 both 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 under KASAN and lockdep with ethtool -C running during
30 PCI resets.
Fixes: a79b559e99be ("ionic: add FLR recovery support")
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 [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-02 0:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 0:38 [PATCH net 0/4] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 1/4] ionic: fix devcmds " Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 2/4] ionic: fix device info register reads " Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 3/4] ionic: fix PHC " Nikhil P. Rao
2026-12-02 0:38 ` [PATCH net 4/4] ionic: fix ethtool coalesce updates racing a " Nikhil P. Rao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®