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 2/4] ionic: fix device info register reads racing the BAR unmap on PCI reset
Date: Wed, 2 Dec 2026 00:38:23 +0000 [thread overview]
Message-ID: <20261202-b4-pr60-v1-2-b1f6706e065b@amd.com> (raw)
In-Reply-To: <20261202-b4-pr60-v1-0-b1f6706e065b@amd.com>
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
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 " 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 [this message]
2026-12-02 0:38 ` [PATCH net 3/4] ionic: fix PHC reads " Nikhil P. Rao
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-2-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®