Skip to contentSkip to conversation

ppc/spapr: Add support for RTAS PCI error injection on pseries

RFC In review Narayana Murty N 2 participants 6 messages Oct 29, 2025 – Mar 4

lore
Share & tools
lore
#2 lore raw

RFC 2/4 ppc/spapr: Add ibm,errinjct RTAS call handler

In reply to Narayana Murty N

Implements the 'ibm,errinjct' RTAS call for PHB-level PCI error injection via firmware. This handler decodes the RTAS parameter buffer, validates arguments, and delegates the injection to the backend.

The patch includes:
- 'rtas_ibm_errinjct()' handler implementation
- Registration of 'RTAS_IBM_ERRINJCT' token
- RTAS error codes for result reporting
- Helper macros used exclusively in RTAS code path

Enables guest-initiated error injection for improved test coverage and diagnostics in EEH emulation flows.

---
 include/hw/ppc/spapr.h |   6 +-
 hw/ppc/spapr_pci.c     | 155 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 160 insertions(+), 1 deletion(-)
include/hw/ppc/spapr.h +5 -1
index 331946ee57..f762be030c 100644
@@ -715,6 +715,9 @@ void push_sregs_to_kvm_pr(SpaprMachineState *spapr);
 #define EEH_ERR_FUNC_DMA_WR_TARGET      19
 #define EEH_ERR_FUNC_MAX                EEH_ERR_FUNC_DMA_WR_TARGET
 
+#define EEH_ERR_EVENT_MODE_MIN     1
+#define EEH_ERR_EVENT_MODE_MAX     2
+
 /* RTAS PCI Error Injection Token Types */
 enum rtas_err_type {
     RTAS_ERR_TYPE_FATAL                   = 0x1,
@@ -814,8 +817,9 @@ enum rtas_err_type {
 #define RTAS_IBM_SUSPEND_ME                     (RTAS_TOKEN_BASE + 0x2A)
 #define RTAS_IBM_NMI_REGISTER                   (RTAS_TOKEN_BASE + 0x2B)
 #define RTAS_IBM_NMI_INTERLOCK                  (RTAS_TOKEN_BASE + 0x2C)
+#define RTAS_IBM_ERRINJCT                       (RTAS_TOKEN_BASE + 0x2D)
 
-#define RTAS_TOKEN_MAX                          (RTAS_TOKEN_BASE + 0x2D)
+#define RTAS_TOKEN_MAX                          (RTAS_TOKEN_BASE + 0x2E)
 
 /* RTAS ibm,get-system-parameter token values */
 #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS      20
hw/ppc/spapr_pci.c +155 -0

167 lines not on this page · raw message

Signature · 1 line
2.51.0
#0 lore raw

cover ppc/spapr: Add support for RTAS PCI error injection on pseries

This patch series introduces RTAS-based PCI error injection infrastructure for the QEMU pseries (sPAPR) platform. The goal is to enable QEMU to simulate enhanced error handling (EEH) behavior for PCI devices using RTAS interfaces, aligned with existing firmware (OPAL/RTAS) conventions on IBM Power systems.

The proposed implementation supports:

- Backend error injection via VFIO for passthrough PCI devices
- RTAS calls for injecting specific PCI errors (e.g., cache/TLB/bus errors)
- Controlled access to error injection via open/close RTAS calls
- Device Tree (DT) updates to advertise supported error injection tokens

This series tested on pseries host with kernel version v6.16.0-rc7

This series has been split into four self-contained patches for clarity:

Patch 1 introduces the VFIO error injection backend:
- Adds 'spapr_phb_vfio_errinjct()' which injects EEH-like faults
- Includes minimal enum definitions ('rtas_err_type', 'EEH_ERR_FUNC_...')
- Introduces stub and headers to integrate with the PHB VFIO path

Patch 2 implements the 'ibm,errinjct' RTAS call handler:
- Adds 'rtas_ibm_errinjct()' in spapr_pci.c
- Handles parameter parsing, validation, and backend call dispatch
- Registers the token in 'spapr_pci_rtas_init()'

Patch 3 adds support for session control:
- Introduces 'ibm,open-errinjct' and 'ibm,close-errinjct' handlers
- Tracks exclusive access using 'SpaprMachineState'
- Provides useful RTAS return codes for access errors

Patch 4 updates the device tree:
- Adds 'ibm,errinjct-tokens' under each PHB node
- Lists supported tokens for guest firmware/userspace to query
- Adds fallback blob support for token discovery

---
Narayana Murty N (4):
ppc/spapr: Add VFIO EEH error injection backend ppc/spapr: Add ibm,errinjct RTAS call handler ppc/spapr: Add support for 'ibm,open-errinjct' and
'ibm,close-errinjct'
ppc/spapr: Advertise RTAS error injection call support via FDT
property

 include/hw/pci-host/spapr.h |   7 ++
 include/hw/ppc/spapr.h      |  56 ++++++++-
 hw/ppc/spapr.c              | 106 +++++++++++++++++
 hw/ppc/spapr_pci.c          | 220 ++++++++++++++++++++++++++++++++++++
 hw/ppc/spapr_pci_vfio.c     |  53 +++++++++
 5 files changed, 441 insertions(+), 1 deletion(-)
Signature · 1 line
2.51.0
#1 lore raw

RFC 1/4 ppc/spapr: Add VFIO EEH error injection backend

Introduce 'spapr_phb_vfio_errinjct()' to inject PCI PHB error events via the VFIO passthrough backend. This function translates RTAS error injection parameters into VFIO EEH injection commands suitable for hardware emulation.

The patch adds:
- A minimal 'enum rtas_err_type' for error types used in VFIO path
- EEH function code macros ('EEH_ERR_FUNC_...')
- Backend stub and integration into 'spapr_pci_vfio.c'
- Necessary header declarations for interfacing

This forms the foundational layer for PCI error injection testing using VFIO passthrough devices on pseries guests.

---
 include/hw/pci-host/spapr.h |  7 +++++
 include/hw/ppc/spapr.h      | 44 ++++++++++++++++++++++++++++++
 hw/ppc/spapr_pci_vfio.c     | 53 +++++++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+)
include/hw/pci-host/spapr.h +7 -0
index 0db87f1281..2e91e0fb38 100644
@@ -125,6 +125,8 @@ int spapr_phb_vfio_eeh_get_state(SpaprPhbState *sphb, int *state);
 int spapr_phb_vfio_eeh_reset(SpaprPhbState *sphb, int option);
 int spapr_phb_vfio_eeh_configure(SpaprPhbState *sphb);
 void spapr_phb_vfio_reset(DeviceState *qdev);
+int spapr_phb_vfio_errinjct(SpaprPhbState *sphb, uint32_t func,
+                            uint64_t addr, uint64_t mask, uint32_t type);
 #else
 static inline bool spapr_phb_eeh_available(SpaprPhbState *sphb)
 {
@@ -151,6 +153,11 @@ static inline int spapr_phb_vfio_eeh_configure(SpaprPhbState *sphb)
 static inline void spapr_phb_vfio_reset(DeviceState *qdev)
 {
 }
+static int spapr_phb_vfio_errinjct(SpaprPhbState *sphb, uint32_t func,
+                                   uint64_t addr, uint64_t mask, uint32_t type)
+{
+    return RTAS_OUT_HW_ERROR;
+}
 #endif
 
 void spapr_phb_dma_reset(SpaprPhbState *sphb);
include/hw/ppc/spapr.h +44 -0

50 lines not on this page · raw message

hw/ppc/spapr_pci_vfio.c +53 -0

63 lines not on this page · raw message

Signature · 1 line
2.51.0
#4 lore raw

RFC 4/4 ppc/spapr: Advertise RTAS error injection call support via FDT property

In reply to Narayana Murty N

Advertise RTAS error injection call support to guests through a new "ibm,errinjct-tokens" property under the RTAS node in the device tree.

This patch introduces:
- spapr_get_errinject_tokens(), which retrieves or constructs a blob of supported error injection tokens from the host or fallback data.
- Integration of "ibm,errinjct-tokens" into the RTAS FDT node.
- Addition of "ibm,open-errinjct" and "ibm,close-errinjct" properties to advertise open/close handlers for error injection sessions.

The ibm,errinjct-tokens property allows guests to programmatically discover supported RTAS error injection facilities, enabling safe and dynamic usage. The helper routine allocates memory for the token blob, which the caller must free once it has been added to the FDT.

If the device-tree file (/proc/device-tree/rtas/ibm,errinjct-tokens) is not available, a static fallback blob is generated internally.

---
 hw/ppc/spapr.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 106 insertions(+)
hw/ppc/spapr.c +106 -0
index e0a2e5a984..0ca8c777d5 100644
@@ -114,6 +114,8 @@
 
 #define PHANDLE_INTC            0x00001111
 
+#define ERR_BLOB_MAX            512
+
 /* These two functions implement the VCPU id numbering: one to compute them
  * all and one to identify thread 0 of a VCORE. Any change to the first one
  * is likely to have an impact on the second one, so let's keep them close.
@@ -900,10 +902,104 @@ static int spapr_dt_rng(void *fdt)
     return ret ? -1 : 0;
 }
 
+/*
+ * spapr_get_errinject_tokens:
+ * ---------------------------
+ * Retrieve or construct a binary blob representing supported RTAS error
+ * injection tokens. If the host device-tree path
+ * "/proc/device-tree/rtas/ibm,errinjct-tokens" exists, it is read directly.
+ * Otherwise, a static fallback list of tokens is generated.
+ *
+ * The caller receives a dynamically allocated buffer in @out_buf and
+ * its size in @out_size, both of which must be freed by the caller
+ * once used.
+ *
+ * Returns:
+ *   0 (EXIT_SUCCESS)  - on success
+ *  -EIO, -ENOMEM      - on failure
+ */
+static int spapr_get_errinject_tokens(char **out_buf, size_t *out_size)
+{
+    char *path = NULL, *buf = NULL;
+    gsize len = 0;
+    uint8_t errinjct_blob[ERR_BLOB_MAX];
+
+    static const struct {
+        const char *name;
+        enum rtas_err_type token;
+    } errinjct_tokens[] = {
+        { "recovered-special-event", RTAS_ERR_TYPE_RECOVERED_SPECIAL_EVENT },
+        { "corrupted-page",          RTAS_ERR_TYPE_CORRUPTED_PAGE },
+        { "ioa-bus-error",           RTAS_ERR_TYPE_IOA_BUS_ERROR },
+        { "corrupted-dcache-start",  RTAS_ERR_TYPE_CORRUPTED_DCACHE_START },
+        { "corrupted-dcache-end",    RTAS_ERR_TYPE_CORRUPTED_DCACHE_END },
+        { "corrupted-icache-start",  RTAS_ERR_TYPE_CORRUPTED_ICACHE_START },
+        { "corrupted-icache-end",    RTAS_ERR_TYPE_CORRUPTED_ICACHE_END },
+        { "corrupted-tlb-start",     RTAS_ERR_TYPE_CORRUPTED_TLB_START },
+        { "corrupted-tlb-end",       RTAS_ERR_TYPE_CORRUPTED_TLB_END },
+        { "ioa-bus-error-64",        RTAS_ERR_TYPE_IOA_BUS_ERROR_64 },
+    };
+
+    path = g_strdup("/proc/device-tree/rtas/ibm,errinjct-tokens");
+
+    if (g_file_test(path, G_FILE_TEST_EXISTS)) {
+        qemu_log("RTAS: Found %s\n", path);
+
+        if (!g_file_get_contents(path, &buf, &len, NULL)) {
+            error_report("RTAS: Failed to read %s", path);
+            g_free(path);
+            return -EIO;
+        }
+
+        qemu_log("RTAS: Read %zu bytes from device-tree\n", len);
+        *out_buf = buf;
+        *out_size = len;
+        g_free(path);
+        return EXIT_SUCCESS;
+    }
+
+    qemu_log("RTAS: %s not found, building fallback blob\n", path);
+    g_free(path);
+    len = 0;
+
+    for (int i = 0; i < G_N_ELEMENTS(errinjct_tokens); i++) {
+        const char *name = errinjct_tokens[i].name;
+        size_t str_len = strlen(name) + 1;
+
+        if (len + str_len + sizeof(uint32_t) > sizeof(errinjct_blob)) {
+            error_report("RTAS: Too many tokens for static buffer");
+            return -ENOMEM;
+        }
+
+        memcpy(&errinjct_blob[len], name, str_len);
+        len += str_len;
+
+        uint32_t be_token = cpu_to_be32(errinjct_tokens[i].token);
+        memcpy(&errinjct_blob[len], &be_token, sizeof(be_token));
+        len += sizeof(be_token);
+    }
+
+    buf = g_malloc(len);
+    if (!buf) {
+        error_report("RTAS: Failed to allocate %zu bytes for blob", len);
+        return -ENOMEM;
+    }
+
+    memcpy(buf, errinjct_blob, len);
+    *out_buf = buf;
+    *out_size = len;
+
+    qemu_log("RTAS: Fallback blob built (%zu bytes)\n", len);
+    return EXIT_SUCCESS;
+}
+
+
 static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt)
 {
     MachineState *ms = MACHINE(spapr);
     int rtas;
+    size_t size_tokens = 0;
+    g_autofree char *errinject_tokens;
     GString *hypertas = g_string_sized_new(256);
     GString *qemu_hypertas = g_string_sized_new(256);
     uint64_t max_device_addr = 0;
@@ -1012,6 +1108,16 @@ static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt)
      */
     _FDT(fdt_setprop(fdt, rtas, "ibm,extended-os-term", NULL, 0));
 
+    if (!spapr_get_errinject_tokens(&errinject_tokens, &size_tokens)) {
+        _FDT(fdt_setprop(fdt, rtas, "ibm,errinjct-tokens",
+                         errinject_tokens, size_tokens));
+
+        _FDT(fdt_setprop_string(fdt, rtas, "ibm,open-errinjct",
+                                "ibm,open-errinjct"));
+        _FDT(fdt_setprop_string(fdt, rtas, "ibm,close-errinjct",
+                                "ibm,close-errinjct"));
+    }
+
     _FDT(fdt_setprop(fdt, rtas, "ibm,lrdr-capacity",
                      lrdr_capacity, sizeof(lrdr_capacity)));
 
Signature · 1 line
2.51.0
#3 lore raw

RFC 3/4 ppc/spapr: Add support for 'ibm, open-errinjct' and 'ibm, close-errinjct'

In reply to Narayana Murty N

Add support for the 'ibm,open-errinjct' and 'ibm,close-errinjct' RTAS calls. These handlers manage exclusive access to error injection facilities through a simple session-based mechanism.

Updates include:
- Implementation of rtas_ibm_open_errinjct() and rtas_ibm_close_errinjct()
- Tracking field 'spapr->errinjct_token' in SpaprMachineState
- New token definitions for the above RTAS calls
- Return codes for already open or invalid close conditions

This ensures that only one guest process can actively perform error injection at a time, improving reliability and preventing conflicts.

---

---
 include/hw/ppc/spapr.h |  8 +++++-
 hw/ppc/spapr_pci.c     | 65 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 1 deletion(-)
include/hw/ppc/spapr.h +7 -1
index f762be030c..af9617b13e 100644
@@ -283,6 +283,7 @@ struct SpaprMachineState {
     Error *fwnmi_migration_blocker;
 
     SpaprWatchdog wds[WDT_MAX_WATCHDOGS];
+    uint32_t errinjct_token;
 };
 
 #define H_SUCCESS         0
@@ -755,6 +756,9 @@ enum rtas_err_type {
 #define RTAS_OUT_PARAM_ERROR                    -3
 #define RTAS_OUT_NOT_SUPPORTED                  -3
 #define RTAS_OUT_NO_SUCH_INDICATOR              -3
+#define RTAS_OUT_ALREADY_OPEN                   -4
+#define RTAS_OUT_NOT_OPEN                       -5
+#define RTAS_OUT_CLOSE_ERROR                    -6
 #define RTAS_OUT_NOT_AUTHORIZED                 -9002
 #define RTAS_OUT_SYSPARM_PARAM_ERROR            -9999
 
@@ -818,8 +822,10 @@ enum rtas_err_type {
 #define RTAS_IBM_NMI_REGISTER                   (RTAS_TOKEN_BASE + 0x2B)
 #define RTAS_IBM_NMI_INTERLOCK                  (RTAS_TOKEN_BASE + 0x2C)
 #define RTAS_IBM_ERRINJCT                       (RTAS_TOKEN_BASE + 0x2D)
+#define RTAS_IBM_OPEN_ERRINJCT                  (RTAS_TOKEN_BASE + 0x2E)
+#define RTAS_IBM_CLOSE_ERRINJCT                 (RTAS_TOKEN_BASE + 0x2F)
 
-#define RTAS_TOKEN_MAX                          (RTAS_TOKEN_BASE + 0x2E)
+#define RTAS_TOKEN_MAX                          (RTAS_TOKEN_BASE + 0x30)
 
 /* RTAS ibm,get-system-parameter token values */
 #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS      20
hw/ppc/spapr_pci.c +65 -0

77 lines not on this page · raw message

Signature · 1 line
2.51.0
#5 lore raw
In reply to Narayana Murty N
Quoted 47 lines · Narayana Murty N

This patch series introduces RTAS-based PCI error injection infrastructure for the QEMU pseries (sPAPR) platform. The goal is to enable QEMU to simulate enhanced error handling (EEH) behavior for PCI devices using RTAS interfaces, aligned with existing firmware (OPAL/RTAS) conventions on IBM Power systems.

The proposed implementation supports:

- Backend error injection via VFIO for passthrough PCI devices
- RTAS calls for injecting specific PCI errors (e.g., cache/TLB/bus errors)
- Controlled access to error injection via open/close RTAS calls
- Device Tree (DT) updates to advertise supported error injection tokens

This series tested on pseries host with kernel version v6.16.0-rc7

This series has been split into four self-contained patches for clarity:

Patch 1 introduces the VFIO error injection backend:
- Adds 'spapr_phb_vfio_errinjct()' which injects EEH-like faults
- Includes minimal enum definitions ('rtas_err_type', 'EEH_ERR_FUNC_...')
- Introduces stub and headers to integrate with the PHB VFIO path

Patch 2 implements the 'ibm,errinjct' RTAS call handler:
- Adds 'rtas_ibm_errinjct()' in spapr_pci.c
- Handles parameter parsing, validation, and backend call dispatch
- Registers the token in 'spapr_pci_rtas_init()'

Patch 3 adds support for session control:
- Introduces 'ibm,open-errinjct' and 'ibm,close-errinjct' handlers
- Tracks exclusive access using 'SpaprMachineState'
- Provides useful RTAS return codes for access errors

Patch 4 updates the device tree:
- Adds 'ibm,errinjct-tokens' under each PHB node
- Lists supported tokens for guest firmware/userspace to query
- Adds fallback blob support for token discovery

---
Narayana Murty N (4):
ppc/spapr: Add VFIO EEH error injection backend ppc/spapr: Add ibm,errinjct RTAS call handler ppc/spapr: Add support for 'ibm,open-errinjct' and
'ibm,close-errinjct'
ppc/spapr: Advertise RTAS error injection call support via FDT
property

Quoted 7 lines
  include/hw/pci-host/spapr.h |   7 ++
  include/hw/ppc/spapr.h      |  56 ++++++++-
  hw/ppc/spapr.c              | 106 +++++++++++++++++
  hw/ppc/spapr_pci.c          | 220 ++++++++++++++++++++++++++++++++++++
  hw/ppc/spapr_pci_vfio.c     |  53 +++++++++
  5 files changed, 441 insertions(+), 1 deletion(-)

Thanks for working on this, looks good to me.