From: Narayana Murty N <nnmlinux@linux.ibm.com>
To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, sbhat@linux.ibm.com,
mahesh@linux.ibm.com, sourabhjain@linux.ibm.com,
adityag@linux.ibm.com, npiggin@gmail.com, harshpb@linux.ibm.com,
alex@shazbot.org, clg@redhat.com
Cc: amachhiw@linux.ibm.com, hbathini@linux.ibm.com,
shivangu@linux.ibm.com, anushree.mathur@linux.ibm.com
Subject: [PATCH v3 1/2] vfio/pci: Add persistent BAR mmap blocking helper
Date: Mon, 23 Nov 2026 13:45:48 +0530 [thread overview]
Message-ID: <20261123081546.49210-5-nnmlinux@linux.ibm.com> (raw)
In-Reply-To: <20261123081546.49210-4-nnmlinux@linux.ibm.com>
Some platform recovery flows need to stop using direct mmap-backed BAR
subregions after a device reset. Disabling the subregions once is not
sufficient because the VFIO INTx mmap timer and interrupt-mode
transitions can later call vfio_mmap_set_enabled() with enabled=true.
Add a generic per-device mmap_blocked state and
vfio_pci_mmap_block(). Once a device is blocked, attempts to re-enable
its direct BAR mmap subregions are ignored. The helper also cancels a
pending INTx mmap re-enable timer and disables all currently active BAR
mmap subregions.
The parent VFIO MemoryRegion remains enabled, so BAR accesses continue
through vfio_region_read()/vfio_region_write() using the VFIO device fd.
The helper contains no platform or EEH policy; callers decide when a
recovery flow requires direct mmap to remain blocked.
The block is intentionally persistent for the lifetime of the VFIO
device object. No unblock operation is added until there is a proven
safe point at which an existing direct BAR mmap can be reused after such
a reset. The state is not migrated because it controls a local access
path optimization rather than guest-visible device state.
Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
---
hw/vfio/pci.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
hw/vfio/pci.h | 7 ++++++
2 files changed, 66 insertions(+)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 0da2e143b8..49d6b7d3f4 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -1949,11 +1949,70 @@ static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled)
{
int i;
+ /*
+ * Some recovery flows require direct BAR mmap to remain disabled
+ * after a device reset. Honour mmap_blocked so that INTx timer
+ * callbacks and interrupt-mode transitions cannot re-enable
+ * the direct mmap subregions once the device has been blocked.
+ */
+ if (enabled && vdev->mmap_blocked) {
+ return;
+ }
+
for (i = 0; i < PCI_ROM_SLOT; i++) {
vfio_region_mmaps_set_enabled(&vdev->bars[i].region, enabled);
}
}
+/**
+ * vfio_pci_mmap_block - Persistently block direct BAR mmap access
+ * @vdev: the VFIO PCI device
+ *
+ * Some recovery flows cannot safely resume direct BAR mmap access using
+ * mappings that were established before the device was reset. Once the
+ * device is blocked, keep accesses on the VFIO region read/write path
+ * rather than allowing later interrupt-mode or timer activity to restore
+ * the direct mmap subregions.
+ *
+ * This helper:
+ * 1. Sets mmap_blocked so that no subsequent interrupt-mode
+ * transition or INTx mmap timer callback can re-enable direct
+ * BAR mmap access.
+ * 2. Cancels any pending INTx mmap re-enable timer.
+ * 3. Disables all currently active BAR mmap subregions.
+ *
+ * The parent slow-path VFIO MemoryRegion remains enabled, so BAR
+ * accesses continue via vfio_region_read()/vfio_region_write() which
+ * use pread()/pwrite() on the VFIO device fd. This is slower than
+ * the direct mmap path but remains available while mmap is blocked.
+ *
+ * The flag is intentionally not cleared by this helper. Blocking is
+ * persistent for the lifetime of the VFIO device object unless a future
+ * change introduces an explicit, proven-safe unblock operation.
+ *
+ * The function is idempotent.
+ */
+void vfio_pci_mmap_block(VFIOPCIDevice *vdev)
+{
+ if (vdev->mmap_blocked) {
+ return;
+ }
+
+ vdev->mmap_blocked = true;
+
+ /*
+ * Cancel any pending INTx mmap re-enable timer. Without this the
+ * timer could still fire and call vfio_mmap_set_enabled() with
+ * enabled=true. That would be blocked by the flag above, but
+ * cancelling it avoids the unnecessary wakeup.
+ */
+ if (vdev->intx.mmap_timer) {
+ timer_del(vdev->intx.mmap_timer);
+ }
+
+ vfio_mmap_set_enabled(vdev, false);
+}
+
static void vfio_bar_prepare(VFIOPCIDevice *vdev, int nr)
{
VFIOBAR *bar = &vdev->bars[nr];
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index 7ff52e9a52..d4c3c9eeae 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -187,6 +187,12 @@ struct VFIOPCIDevice {
bool defer_kvm_irq_routing;
bool clear_parent_atomics_on_exit;
bool skip_vsc_check;
+ /*
+ * Block direct BAR mmap subregions for the lifetime of this
+ * VFIO device. Calls that would re-enable mmap are ignored
+ * while this flag is set.
+ */
+ bool mmap_blocked;
uint16_t vpasid_cap_offset;
OnOffAuto ats;
VFIODisplay *dpy;
@@ -243,6 +249,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp);
/* BARs */
void vfio_pci_bars_exit(VFIOPCIDevice *vdev);
void vfio_sub_page_bar_update_mappings(VFIOPCIDevice *vdev);
+void vfio_pci_mmap_block(VFIOPCIDevice *vdev);
/* Capabilities */
bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp);
--
2.54.0
next prev parent reply other threads:[~2026-11-23 8:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 8:15 [PATCH v3 0/2] ppc/spapr: Fix MSI-X shadow and BAR mmap handling during EEH PE reset Narayana Murty N
2026-11-23 8:15 ` Narayana Murty N [this message]
2026-11-23 8:15 ` [PATCH v3 2/2] ppc/spapr: Preserve VFIO MSI-X shadow and block BAR mmap on EEH reset Narayana Murty N
2026-12-01 17:57 ` [PATCH v3 0/2] ppc/spapr: Fix MSI-X shadow and BAR mmap handling during EEH PE reset Cédric Le Goater
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=20261123081546.49210-5-nnmlinux@linux.ibm.com \
--to=nnmlinux@linux.ibm.com \
--cc=adityag@linux.ibm.com \
--cc=alex@shazbot.org \
--cc=amachhiw@linux.ibm.com \
--cc=anushree.mathur@linux.ibm.com \
--cc=clg@redhat.com \
--cc=harshpb@linux.ibm.com \
--cc=hbathini@linux.ibm.com \
--cc=mahesh@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=sbhat@linux.ibm.com \
--cc=shivangu@linux.ibm.com \
--cc=sourabhjain@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.