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