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 2/2] ppc/spapr: Preserve VFIO MSI-X shadow and block BAR mmap on EEH reset
Date: Mon, 23 Nov 2026 13:45:49 +0530 [thread overview]
Message-ID: <20261123081546.49210-6-nnmlinux@linux.ibm.com> (raw)
In-Reply-To: <20261123081546.49210-4-nnmlinux@linux.ibm.com>
Prepare VFIO PCI devices before a pSeries EEH hot or fundamental PE
reset without destroying the MSI-X state that the guest needs to
recover interrupts.
The existing path clears MSI-X Enable and then calls msix_reset(). On
pSeries with vfio-no-msix-emulation=true, QEMU keeps the MSI-X messages
used by ibm,change-msi in its software shadow. The Linux EEH recovery
sequence does not necessarily issue ibm,change-msi again. Clearing the
shadow with msix_reset() therefore loses the message address/data needed
when MSI-X is enabled again.
Preserve the shadow by removing msix_reset(). Read the MSI-X Message
Control value from QEMU's cached PCI config space, clear only MSI-X
Enable, and write it through pci_host_config_write_common(). This keeps
the normal VFIO MSI-X disable/enable transition while avoiding a config
read from a PE that may still be frozen.
Also block direct BAR mmap access before changing MSI-X state by calling
vfio_pci_mmap_block(). Testing with a VFIO-passed-through BCM5719
showed that restoring direct mmap after VFIO_EEH_PE_CONFIGURE can leave
the device inaccessible again during guest resume, while keeping BAR
access on the VFIO region read/write path allows the Guest-2 EEH
recovery to complete and the device to remain functional. Blocking
mmap first also prevents a subsequent MSI-X-to-INTx transition from
re-enabling the mmap path through the normal INTx policy.
The generic VFIO helper provides only the persistent mmap-block
mechanism; the decision to use it for EEH remains local to the sPAPR
recovery code. No post-configure mmap restore is added because the
current testing does not establish a safe point for reusing the direct
BAR mmap after the PE reset.
No guest-visible ABI is changed.
Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
---
hw/ppc/spapr_pci_vfio.c | 75 ++++++++++++++++++++++++++++-------------
1 file changed, 51 insertions(+), 24 deletions(-)
diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
index a748a0bf4c..c164a7a6ce 100644
--- a/hw/ppc/spapr_pci_vfio.c
+++ b/hw/ppc/spapr_pci_vfio.c
@@ -32,6 +32,8 @@
* Interfaces for IBM EEH (Enhanced Error Handling)
*/
#ifdef CONFIG_VFIO_PCI
+#include "hw/vfio/pci.h"
+
static bool vfio_eeh_container_ok(VFIOLegacyContainer *container)
{
/*
@@ -233,47 +235,72 @@ int spapr_phb_vfio_eeh_get_state(SpaprPhbState *sphb, int *state)
return RTAS_OUT_SUCCESS;
}
-static void spapr_phb_vfio_eeh_clear_dev_msix(PCIBus *bus,
- PCIDevice *pdev,
- void *opaque)
+static void spapr_phb_vfio_eeh_prepare_dev(PCIBus *bus,
+ PCIDevice *pdev,
+ void *opaque)
{
- /* Check if the device is VFIO PCI device */
+ VFIOPCIDevice *vdev;
+ uint16_t flags;
+
if (!object_dynamic_cast(OBJECT(pdev), "vfio-pci")) {
return;
}
+ vdev = VFIO_PCI_DEVICE(pdev);
+
/*
- * The MSIx table will be cleaned out by reset. We need
- * disable it so that it can be reenabled properly. Also,
- * the cached MSIx table should be cleared as it's not
- * reflecting the contents in hardware.
+ * Direct BAR mmap access may not be reliable after an EEH PE reset.
+ * Block mmap before changing MSI-X state so any resulting interrupt
+ * mode transition cannot re-enable it, and keep BAR accesses on the
+ * VFIO pread()/pwrite() path after the reset. This avoids restoring
+ * the direct mmap path at an unproven point in EEH recovery.
*/
- if (msix_enabled(pdev)) {
- uint16_t flags;
-
- flags = pci_host_config_read_common(pdev,
- pdev->msix_cap + PCI_MSIX_FLAGS,
- pci_config_size(pdev), 2);
- flags &= ~PCI_MSIX_FLAGS_ENABLE;
- pci_host_config_write_common(pdev,
- pdev->msix_cap + PCI_MSIX_FLAGS,
- pci_config_size(pdev), flags, 2);
+ vfio_pci_mmap_block(vdev);
+
+ if (!msix_enabled(pdev)) {
+ return;
}
- msix_reset(pdev);
+ /*
+ * Disable MSI-X by clearing the Enable bit in the MSI-X Message
+ * Control register. We use the cached config value to avoid a
+ * config-space read while the PE may still be frozen.
+ *
+ * Writing through pci_host_config_write_common() causes VFIO to:
+ * - release the active MSI-X vector eventfds,
+ * - remove the KVM irqchip routes,
+ * - disable the VFIO MSIX_IRQ_INDEX,
+ * so that the subsequent MSI-X Enable write from the guest driver
+ * is seen as a clean disabled-to-enabled transition and all
+ * vectors are re-armed through vfio_msix_vector_do_use().
+ *
+ * Do NOT call msix_reset() here. On pSeries, QEMU's MSI-X table
+ * is a software shadow populated by the ibm,change-msi RTAS call.
+ * The EEH recovery sequence does not necessarily re-issue
+ * ibm,change-msi, so the shadow contains the only copy of the
+ * message addresses and data that Linux EEH will restore.
+ * msix_reset() would zero those shadow entries, leaving
+ * vfio_msix_enable() with no vectors to pass to
+ * vfio_msix_vector_do_use() and the device would never recover
+ * interrupts.
+ */
+ flags = pci_get_word(pdev->config + pdev->msix_cap + PCI_MSIX_FLAGS);
+ flags &= ~PCI_MSIX_FLAGS_ENABLE;
+ pci_host_config_write_common(pdev,
+ pdev->msix_cap + PCI_MSIX_FLAGS,
+ pci_config_size(pdev), flags, 2);
}
-static void spapr_phb_vfio_eeh_clear_bus_msix(PCIBus *bus, void *opaque)
+static void spapr_phb_vfio_eeh_prepare_bus(PCIBus *bus, void *opaque)
{
- pci_for_each_device_under_bus(bus, spapr_phb_vfio_eeh_clear_dev_msix,
- NULL);
+ pci_for_each_device_under_bus(bus, spapr_phb_vfio_eeh_prepare_dev, NULL);
}
static void spapr_phb_vfio_eeh_pre_reset(SpaprPhbState *sphb)
{
- PCIHostState *phb = PCI_HOST_BRIDGE(sphb);
+ PCIHostState *phb = PCI_HOST_BRIDGE(sphb);
- pci_for_each_bus(phb->bus, spapr_phb_vfio_eeh_clear_bus_msix, NULL);
+ pci_for_each_bus(phb->bus, spapr_phb_vfio_eeh_prepare_bus, NULL);
}
int spapr_phb_vfio_eeh_reset(SpaprPhbState *sphb, int option)
--
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 ` [PATCH v3 1/2] vfio/pci: Add persistent BAR mmap blocking helper Narayana Murty N
2026-11-23 8:15 ` Narayana Murty N [this message]
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-6-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.