From: "Nikhil P. Rao" <nikhil.rao@amd.com>
To: Brett Creeley <brett.creeley@amd.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Richard Cochran <richardcochran@gmail.com>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Eric Joyner <eric.joyner@amd.com>,
Abhijit Gangurde <abhijit.gangurde@amd.com>,
"Allen Hubbe" <allen.hubbe@amd.com>,
"Nikhil P. Rao" <nikhil.rao@amd.com>
Subject: [PATCH net 3/4] ionic: fix PHC reads racing the BAR unmap on PCI reset
Date: Wed, 2 Dec 2026 00:38:24 +0000 [thread overview]
Message-ID: <20261202-b4-pr60-v1-3-b1f6706e065b@amd.com> (raw)
In-Reply-To: <20261202-b4-pr60-v1-0-b1f6706e065b@amd.com>
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
next prev parent reply other threads:[~2026-12-02 0:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 0:38 [PATCH net 0/4] ionic: fix register " 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 [this message]
2026-12-02 0:38 ` [PATCH net 4/4] ionic: fix ethtool coalesce updates racing a " Nikhil P. Rao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202-b4-pr60-v1-3-b1f6706e065b@amd.com \
--to=nikhil.rao@amd.com \
--cc=abhijit.gangurde@amd.com \
--cc=allen.hubbe@amd.com \
--cc=andrew+netdev@lunn.ch \
--cc=brett.creeley@amd.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=eric.joyner@amd.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®