Skip to contentSkip to conversation

powerpc: Add RTAS based error injection support for pSeries

PATCH New Narayana Murty N 1 participant 5 messages Nov 23

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v7 cover powerpc: Add RTAS based error injection support for pSeries

The pSeries EEH error-injection backend currently implements a limited software-generated MMIO failure and does not use the error-injection services provided by RTAS.

This series replaces that implementation with the PAPR-defined RTAS workflow based on:

- ibm,open-errinjct
- ibm,errinjct
- ibm,close-errinjct

The implementation opens an RTAS error-injection session, allocates and prepares an RTAS-accessible work area, performs the requested injection, releases the work area, and closes the session on both success and failure paths.

The existing EEH userspace ABI is preserved. EEH_ERR_TYPE_32 and EEH_ERR_TYPE_64 continue to represent generic 32-bit and 64-bit IOA bus-error injection requests. The pSeries backend maps these values to the corresponding RTAS error types, while the PowerNV backend explicitly maps them to the corresponding OPAL types.

Additional generic EEH error types (EEH_ERR_TYPE_RECOVERED_SPECIAL_EVENT, EEH_ERR_TYPE_CORRUPTED_PAGE, and the cache/TLB corruption types) are defined in the UAPI header and mapped explicitly to RTAS firmware encodings by the pSeries backend. Platform backends that do not support a valid generic type return -EOPNOTSUPP.

No existing userspace ABI values are changed.

The injection path can be exercised for VFIO-assigned devices through VFIO_EEH_PE_INJECT_ERR. The guest or userspace VFIO application continues to use the same generic EEH type and function values, independent of whether the host platform uses RTAS or OPAL.

For IOA bus-error injection, the VFIO sPAPR path normalizes a Linux BAR resource address to the corresponding PCI bus address before dispatching the request to the platform EEH backend. Address normalization is restricted to memory and IO load/store functions whose addr argument is a BAR-backed PCI address. Config-space and DMA functions are passed through without translation because their addr arguments represent PCI config register offsets and IOVA/TCE addresses respectively. The no-address form is represented by both address and mask being zero.

The series also handles the unusual return format of ibm,open-errinjct:

rets[0] = error-injection session token
rets[1] = RTAS status

rtas_call() returns rets[1] as the status and places the session token in outputs[0], preserving the normal kernel rtas_call() convention.

sys_rtas() continues to expose the raw RTAS return cells to userspace. For ibm,open-errinjct, it validates that at least two return cells were requested before entering RTAS and uses the RTAS status cell for last-error handling. Userspace therefore continues to receive the session token and status in their PAPR-defined positions.

The pSeries backend uses the existing RTAS work-area allocator for the error-injection parameter buffer. The work area is allocated only after ibm,open-errinjct succeeds and is released before ibm,close-errinjct. RTAS work areas reside below RTAS_INSTANTIATE_MAX, so the physical address fits in the 32-bit RTAS argument passed to firmware.

The complete open, inject, and close sequence is serialized with a mutex. RTAS busy and extended-delay return values are handled for all three calls. Once a session has been opened, ibm,close-errinjct is attempted even when parameter preparation or error injection fails.

The patches are organized as follows:

1. Handle the special ibm,open-errinjct return format in rtas_call().
2. Add pSeries RTAS error-injection validation and buffer helpers.
3. Implement RTAS-based pSeries EEH error injection.
4. Normalize VFIO sPAPR IOA error-injection addresses.
5. Explicitly map generic EEH error types to OPAL types on PowerNV.

Testing was performed on PowerVM with firmware providing the RTAS error-injection services and with corresponding QEMU support.

The corresponding QEMU v6 series is posted here:
https://lore.kernel.org/qemu-devel/[email protected]/

---

Change Log:
V6 -> V7:
Changes since v6:
https://lore.kernel.org/all/[email protected]/
- Address review comments from Sourabh Jain and Sashiko.
- Merge the pSeries RTAS helper and implementation patches to keep related functionality together. (Sourabh Jain, Sashiko)
- Fix RTAS return-cell handling, tracing and documentation. (Sourabh Jain, Sashiko)
- Obtain error-injection class tokens from the device tree instead of using hardcoded values. (Sashiko)
- Improve pSeries BAR validation and RTAS error handling. (Sourabh Jain, Sashiko)
- Refine VFIO address normalization using IOMMU group iteration, with pSeries-specific handling and correct BAR resource matching. (Sourabh Jain, Sashiko)
- Retain the PowerNV error-type mapping from v6 without functional changes, and clarify its relationship to the pSeries RTAS patches. Both backends translate generic EEH types to firmware-specific RTAS or OPAL values. (Sourabh Jain)

V5 -> V6:
https://lore.kernel.org/all/[email protected]/
* Addressed v5 review comments from Sashiko.

* Patch 1:
- No changes.

* Patch 2:
- Fix false BAR matches against unassigned or disabled BARs in validate_addr_mask_in_pe(): use pci_resource_len() instead of resource_size() (which returns 1 for zero-initialized BARs), and explicitly reject BARs with IORESOURCE_UNSET or IORESOURCE_DISABLED.
- Move validate_errinjct_args() and prepare_errinjct_buffer() to Patch 3 alongside their callers so each intermediate commit builds cleanly with CONFIG_WERROR=y without unused-function warnings.

* Patch 3:
- Include <asm/rtas-work-area.h> for the RTAS work-area API used by the pSeries error-injection implementation.
- Introduce validate_errinjct_args() and prepare_errinjct_buffer() here alongside their callers (moved from Patch 2).
- Fix eeh_break_device() visibility: keep it under #ifdef CONFIG_DEBUG_FS to prevent unused-function compiler warnings when CONFIG_DEBUG_FS=n.
- Add pseries_eeh_func_needs_bar_addr() to identify error functions whose addr argument is a BAR-backed MMIO/IO address. Guard validate_addr_mask_in_pe() in prepare_errinjct_buffer() with this predicate so config offsets and DMA/IOVA addresses bypass BAR membership validation.
- Demote the validate_addr_mask_in_pe() diagnostic message from pr_err() to pr_debug() since invalid user-supplied inputs do not represent internal kernel errors.
- Update prepare_errinjct_buffer() kernel-doc comments to document function-specific addr semantics (MEM/IO = BAR, CFG = offset, DMA = IOVA).

* Patch 4:
- Restrict address normalization to error functions carrying BAR-backed PCI MMIO/IO addresses (memory and IO load/store). Config-space and DMA functions bypass normalization rather than incorrectly returning -EINVAL.
- Fix false matches against unassigned/disabled BARs in vfio_spapr_eeh_normalize_addr() using pci_resource_len() and checking IORESOURCE_UNSET / IORESOURCE_DISABLED.
- Remove the misleading ", injection may fail" suffix from the pr_debug() message since the caller returns -EINVAL immediately.
- Update commit description to accurately reflect function-specific address domains.

* Patch 5:
- No changes.

V4 -> V5:
https://lore.kernel.org/all/[email protected]/

* Addressed v4 review comments from Sourabh Jain.
* Return -EINVAL when ibm,open-errinjct is used with an invalid return-cell count.
* Validate the ibm,open-errinjct return-cell count in sys_rtas() before entering RTAS and use the common status helper for last-error handling.
* Rework the pSeries helper description to describe validation and RTAS parameter-buffer construction first.
* Rename rtas_type to rtas_err_type to distinguish the mapped RTAS type from the generic EEH type.
* Keep common error-function validation in validate_errinjct_args() and remove duplicate check from prepare_errinjct_buffer().
* Protect PE device and BAR traversal with pci_rescan_remove_lock.
* Rename pseries_errinjct_mutex to errinjct_mutex.
* Allocate RTAS work area only after ibm,open-errinjct succeeds and release it before ibm,close-errinjct.
* Ensure ibm,close-errinjct is attempted after a successful open when parameter preparation or error injection subsequently fails.
* Remove caller-side RTAS work-area address check and truncation, relying on RTAS work-area allocation guarantees for the 32-bit RTAS argument.
* Remove unnecessary error message for unencodable 32-bit IOA address or mask and retain the buffer-ready debug message.
* Remove eeh_pe_inject_mmio_error() and its declaration after removing its last caller.
* Reorder the VFIO address-normalization patch after the pSeries RTAS implementation.
* Remove the one-use VFIO error-type helper and check IOA error types directly at call site.
* Treat only addr == 0 && mask == 0 as a no-address IOA injection.
* Limit address matching to standard PCI BARs and add debug message when supplied address does not match a BAR.
* Expand PowerNV commit message to explain generic EEH-to-OPAL type mapping and rename opal_type to opal_err_type.
* Preserve -ERANGE for unsupported PowerNV error types.

V3 -> V4:
https://lore.kernel.org/all/[email protected]/

* Use the RTAS work area allocator instead of adding a dedicated global error-injection buffer.
* Keep sys_rtas() raw return-cell semantics unchanged while handling the special ibm,open-errinjct return format in rtas_call().
* Treat ibm,open-errinjct with fewer than two return cells as invalid rtas_call() usage instead of interpreting rets[0] as status.
* Use normal Linux errno values in internal validation helpers instead of RTAS status values.
* Simplify the pSeries RTAS open/inject/close flow.
* Keep close-session failure as cleanup reporting without overwriting the primary operation status.
* Add VFIO sPAPR-side address normalization before dispatching IOA error injection to the platform EEH backend.
* Normalize IOA addresses based on the IOA error type, not only selected function codes.
* Keep the generic EEH ABI values unchanged and keep pSeries RTAS and PowerNV OPAL mappings explicit.

V2 -> V3:

* Fixed ibm,open-errinjct return handling to correctly process firmware responses.
* Allocate the error-injection buffer in RTAS-accessible memory instead of general kernel memory.
* Pass the physical address of the error-injection buffer to firmware (previously incorrect address type).
* Accept session token zero as a valid token (previously rejected erroneously).
* Handle RTAS busy and extended-delay return codes for open, inject, and close calls.
* Simplified the validation helper -- reduced complexity and removed redundant checks.
* Simplified the buffer-preparation helper for cleaner, more maintainable code.
* Validate that all required RTAS tokens are present before attempting to open a session.
* Added explicit generic EEH-to-OPAL error-type mapping for the PowerNV platform.

v1 -> v2:
https://lore.kernel.org/all/[email protected]/

* Addressed all review comments from Sourabh Jain
* Removed unnecessary empty line in rtas_call()
* Enhanced comment to explain PAPR specification requirements
* Corrected misleading comment about output handling
* Improved else block comment for better code clarity
* Fixed kernel test robot warnings
* Fixed kernel-doc warning for __maybe_unused parameter
* Confirmed sparse warnings are false positives (correct endianness handling)
* Added PowerNV platform abstraction layer (new Patch 5)
* Maps EEH error types to OPAL-specific types
* Simplifies type handling by direct variable update
* Improved code comments and documentation throughout
* Added Reported-by tags for kernel test robot findings
* Split into logical 5-patch series for better review

RFC -> v1:
https://lore.kernel.org/all/[email protected]/

* Initial 4-patch series
* Fixed PAPR ibm,open-errinjct output format (token,status order)
* Added pr_fmt handling for EEH subsystem compatibility
* Implemented comprehensive validation helpers

RFC:
https://lore.kernel.org/all/[email protected]/

* Initial RFC implementation

Narayana Murty N (4):
powerpc/rtas: Handle ibm,open-errinjct return format powerpc/pseries/eeh: Implement RTAS-based EEH error injection vfio/spapr_tce: Normalize EEH IOA error injection addresses powerpc/powernv/eeh: Map generic EEH error types to OPAL

 arch/powerpc/include/asm/eeh.h               |  26 +-
 arch/powerpc/include/asm/trace.h             |  26 +-
 arch/powerpc/kernel/eeh.c                    |  10 +-
 arch/powerpc/kernel/rtas.c                   |  83 ++++-
 arch/powerpc/platforms/powernv/eeh-powernv.c |  22 +-
 arch/powerpc/platforms/pseries/eeh_pseries.c | 334 +++++++++++++++++--
 drivers/vfio/vfio_iommu_spapr_tce.c          | 131 +++++++-
 7 files changed, 573 insertions(+), 59 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH v7 1/4 powerpc/rtas: Handle ibm,open-errinjct return format

ibm,open-errinjct returns the session token in rets[0] and the status in rets[1], unlike other RTAS functions, which return the status in rets[0]. rtas_call() would report the session token as the status and drop the real status.

Take the status from rets[1] for this function and return the session token in outputs[0]. This needs exactly two return cells, so reject any other count from kernel callers with -EINVAL and a one-time warning, and document the exception in the rtas_call() kernel-doc.

Give the rtas_output tracepoint the index of the status cell, so that it reports rets[1] as the status and the session token as an additional output for this function. A call with no return cells reports status 0 instead of reading a cell that does not exist.

Ensure __fetch_rtas_last_error() and sys_rtas() initialize rtas_args.rets to point into rtas_args.args[] after copying local arguments, preventing tracepoint handlers from dereferencing uninitialized memory or reading stale on-stack values.

sys_rtas() still copies the raw return cells to userspace. It uses the status from the right cell for hardware-error (-1) detection and, after the lockdown check, rejects fewer than two return cells for this function.

---
 arch/powerpc/include/asm/trace.h | 26 +++++++---
 arch/powerpc/kernel/rtas.c       | 83 ++++++++++++++++++++++++++------
 2 files changed, 88 insertions(+), 21 deletions(-)
arch/powerpc/include/asm/trace.h +19 -7
index a7b69b25296b..d731f70aead7 100644
@@ -146,25 +146,37 @@ TRACE_EVENT(rtas_input,
 	)
 );
 
+/*
+ * @status_idx is the index in rets[] of the status cell: 1 for
+ * ibm,open-errinjct, which returns its session token in rets[0], and 0 for
+ * every other function.  The remaining cells are reported as other outputs.
+ */
 TRACE_EVENT(rtas_output,
 
-	TP_PROTO(struct rtas_args *rtas_args, const char *name),
+	TP_PROTO(struct rtas_args *rtas_args, const char *name,
+		 unsigned int status_idx),
 
-	TP_ARGS(rtas_args, name),
+	TP_ARGS(rtas_args, name, status_idx),
 
 	TP_STRUCT__entry(
 		__field(__u32, nr_other)
 		__field(__s32, status)
 		__string(name, name)
-		__dynamic_array(__u32, other_outputs, be32_to_cpu(rtas_args->nret) - 1)
+		__dynamic_array(__u32, other_outputs,
+				be32_to_cpu(rtas_args->nret) ?
+				be32_to_cpu(rtas_args->nret) - 1 : 0)
 	),
 
 	TP_fast_assign(
-		__entry->nr_other = be32_to_cpu(rtas_args->nret) - 1;
-		__entry->status = be32_to_cpu(rtas_args->rets[0]);
+		u32 nret = be32_to_cpu(rtas_args->nret);
+		u32 *other = __get_dynamic_array(other_outputs);
+		u32 i;
+
+		__entry->nr_other = nret ? nret - 1 : 0;
+		__entry->status = nret ? be32_to_cpu(rtas_args->rets[status_idx]) : 0;
 		__assign_str(name);
-		be32_to_cpu_array(__get_dynamic_array(other_outputs),
-				  &rtas_args->rets[1], __entry->nr_other);
+		for (i = 0; i < __entry->nr_other; i++)
+			other[i] = be32_to_cpu(rtas_args->rets[i < status_idx ? i : i + 1]);
 	),
 
 	TP_printk("%s status: %d, other outputs: %s", __get_str(name), __entry->status,
arch/powerpc/kernel/rtas.c +69 -14

145 lines not on this page · raw message

Signature · 1 line
2.54.0
#2 lore raw

PATCH v7 2/4 powerpc/pseries/eeh: Implement RTAS-based EEH error injection

In reply to Narayana Murty N

pseries_eeh_err_inject() only emulates MMIO errors in software and ignores the address and mask. Use the PAPR RTAS services ibm,open-errinjct, ibm,errinjct and ibm,close-errinjct instead, so the platform raises the error for a given IOA bus address.

EEH_ERR_TYPE_32 and EEH_ERR_TYPE_64 select the ioa-bus-error and ioa-bus-error-64 classes and the matching parameter buffer layout. The class token is read from the "ibm,errinjct-tokens" property of /rtas; if the class is not advertised the request fails with -EOPNOTSUPP. The buffer comes from the RTAS work area allocator, and the session is closed on every exit path after a successful open. A mutex serializes sessions started through this backend. Statuses specific to these services, such as "already open", are mapped to errno locally; rtas_error_rc() is unchanged.

For memory and I/O load/store functions the address must be a PCI bus address within an assigned standard BAR (BAR0-BAR5) of the matching type, memory or I/O, of a device in the PE. pci_lock_rescan_remove() protects the PE device list walk and snapshots the PE address and BUID before releasing the lock and opening the RTAS session. Config-space and DMA functions, and requests with address and mask both zero, are not checked. The mask is passed to firmware unchanged.

Remove eeh_pe_inject_mmio_error(). eeh_break_device() is now used only by debugfs, so build it only with CONFIG_DEBUG_FS.

Firmware without the ERRINJCT services or class token no longer gets the software-emulated injection; the request fails with -ENODEV or -EOPNOTSUPP.

---
 arch/powerpc/include/asm/eeh.h               |  26 +-
 arch/powerpc/kernel/eeh.c                    |  10 +-
 arch/powerpc/platforms/pseries/eeh_pseries.c | 334 +++++++++++++++++--
 3 files changed, 338 insertions(+), 32 deletions(-)
arch/powerpc/include/asm/eeh.h +25 -1
index b7ebb4ac2c71..f7743dcf75a4 100644
@@ -9,6 +9,7 @@
 #ifdef __KERNEL__
 
 #include <linux/init.h>
+#include <linux/ioport.h>
 #include <linux/list.h>
 #include <linux/string.h>
 #include <linux/time.h>
@@ -310,7 +311,30 @@ int eeh_pe_reset(struct eeh_pe *pe, int option, bool include_passed);
 int eeh_pe_configure(struct eeh_pe *pe);
 int eeh_pe_inject_err(struct eeh_pe *pe, int type, int func,
 		      unsigned long addr, unsigned long mask);
-int eeh_pe_inject_mmio_error(struct pci_dev *pdev);
+
+/*
+ * Return the resource type (IORESOURCE_MEM or IORESOURCE_IO) of the BAR that
+ * error function @func addresses, or 0 if it does not take a BAR address.
+ * Config-space functions take a config register offset and DMA functions
+ * take a DMA address.
+ */
+static inline unsigned long eeh_err_func_to_res_type(int func)
+{
+	switch (func) {
+	case EEH_ERR_FUNC_LD_MEM_ADDR:
+	case EEH_ERR_FUNC_LD_MEM_DATA:
+	case EEH_ERR_FUNC_ST_MEM_ADDR:
+	case EEH_ERR_FUNC_ST_MEM_DATA:
+		return IORESOURCE_MEM;
+	case EEH_ERR_FUNC_LD_IO_ADDR:
+	case EEH_ERR_FUNC_LD_IO_DATA:
+	case EEH_ERR_FUNC_ST_IO_ADDR:
+	case EEH_ERR_FUNC_ST_IO_DATA:
+		return IORESOURCE_IO;
+	default:
+		return 0;
+	}
+}
 
 /**
  * EEH_POSSIBLE_ERROR() -- test for possible MMIO failure.
arch/powerpc/kernel/eeh.c +2 -8
index 2d7898ef6b8c..d4c018849787 100644
@@ -1571,6 +1571,8 @@ static int proc_eeh_show(struct seq_file *m, void *v)
 }
 #endif /* CONFIG_PROC_FS */
 
+#ifdef CONFIG_DEBUG_FS
+
 static int eeh_break_device(struct pci_dev *pdev)
 {
 	struct resource *bar = NULL;
@@ -1664,14 +1666,6 @@ static int eeh_break_device(struct pci_dev *pdev)
 	return 0;
 }
 
-int eeh_pe_inject_mmio_error(struct pci_dev *pdev)
-{
-	return eeh_break_device(pdev);
-}
-
-#ifdef CONFIG_DEBUG_FS
-
-
 static struct pci_dev *eeh_debug_lookup_pdev(struct file *filp,
 					     const char __user *user_buf,
 					     size_t count, loff_t *ppos)
arch/powerpc/platforms/pseries/eeh_pseries.c +311 -23

371 lines not on this page · raw message

Signature · 1 line
2.54.0
#3 lore raw

PATCH v7 3/4 vfio/spapr_tce: Normalize EEH IOA error injection addresses

In reply to Narayana Murty N

On pseries, RTAS error injection takes a PCI bus address for memory and I/O load/store functions. VFIO_EEH_PE_INJECT_ERR callers such as QEMU pass an address within a BAR as the sysfs "resource" file exports it: a CPU address for a memory BAR and a PCI bus address for an I/O BAR. A CPU address can differ from the PCI bus address because of PHB window translation.

On pseries, convert the address before calling eeh_pe_inject_err() to the PCI bus address of the matching standard BAR (BAR0-BAR5) of a device in the IOMMU group, keeping its offset. Memory functions match memory BARs and I/O functions match I/O BARs. Unassigned and disabled BARs are never matched, and an address that matches no BAR fails with -EINVAL.

Config-space and DMA functions, requests with address and mask both zero, and requests on other platforms are not changed. The mask is never modified.

---
 drivers/vfio/vfio_iommu_spapr_tce.c | 131 +++++++++++++++++++++++++++-
 1 file changed, 130 insertions(+), 1 deletion(-)
drivers/vfio/vfio_iommu_spapr_tce.c +130 -1
index 1c0eec228cc6..c56b649d7094 100644
@@ -23,9 +23,11 @@
 #include <linux/mm.h>
 #include "vfio.h"
 
+#include <asm/eeh.h>
 #include <asm/iommu.h>
 #include <asm/tce.h>
 #include <asm/mmu_context.h>
+#include <asm/machdep.h>
 
 #define DRIVER_VERSION  "0.1"
 #define DRIVER_AUTHOR   "[email protected]"
@@ -774,12 +776,116 @@ static long tce_iommu_create_default_window(struct tce_container *container)
 	return ret;
 }
 
+/*
+ * Look for @addr in the standard BARs (BAR0-BAR5) of @pdev whose resource
+ * type is @res_type, and translate it to the PCI bus address RTAS expects,
+ * keeping the offset into the BAR. Expansion ROM, SR-IOV resources and
+ * bridge windows are not supported.
+ *
+ * @addr is in the domain the sysfs "resource" file exports: the CPU address
+ * for a memory BAR and the PCI bus address for an I/O BAR.  Each type has a
+ * single domain, so a match is unambiguous.
+ *
+ * Unassigned BARs are zero-based and flagged IORESOURCE_UNSET on pseries,
+ * so they are skipped, as are disabled ones.
+ */
+static bool vfio_spapr_eeh_normalize_pdev_addr(struct pci_dev *pdev,
+					       unsigned long res_type,
+					       unsigned long addr,
+					       unsigned long *normalized)
+{
+	struct pci_bus_region region;
+	struct resource *res;
+	resource_size_t len, start;
+	int bar;
+
+	for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
+		res = &pdev->resource[bar];
+
+		if (resource_type(res) != res_type)
+			continue;
+
+		if (res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED))
+			continue;
+
+		len = pci_resource_len(pdev, bar);
+		if (!len)
+			continue;
+
+		pcibios_resource_to_bus(pdev->bus, &region, res);
+		start = res_type == IORESOURCE_IO ? region.start : res->start;
+
+		if (addr >= start && addr - start < len) {
+			*normalized = region.start + (addr - start);
+			return true;
+		}
+	}
+
+	return false;
+}
+
+struct vfio_spapr_eeh_addr_lookup {
+	unsigned long res_type;
+	unsigned long addr;
+	unsigned long normalized;
+	bool found;
+};
+
+static int vfio_spapr_eeh_match_dev(struct device *dev, void *data)
+{
+	struct vfio_spapr_eeh_addr_lookup *lookup = data;
+	struct pci_dev *pdev;
+
+	if (!dev_is_pci(dev))
+		return 0;
+
+	pdev = to_pci_dev(dev);
+	if (vfio_spapr_eeh_normalize_pdev_addr(pdev, lookup->res_type,
+					       lookup->addr,
+					       &lookup->normalized)) {
+		lookup->found = true;
+		return 1;
+	}
+
+	return 0;
+}
+
+/*
+ * Convert @addr to a PCI bus address using the BARs of type @res_type of the
+ * devices in @group.
+ */
+static int vfio_spapr_eeh_normalize_addr(struct iommu_group *group,
+					 unsigned long res_type,
+					 unsigned long addr,
+					 unsigned long *normalized)
+{
+	struct vfio_spapr_eeh_addr_lookup lookup = {
+		.res_type = res_type,
+		.addr = addr,
+	};
+	int ret;
+
+	ret = iommu_group_for_each_dev(group, &lookup,
+				       vfio_spapr_eeh_match_dev);
+	if (ret < 0)
+		return ret;
+
+	if (lookup.found) {
+		*normalized = lookup.normalized;
+		return 0;
+	}
+
+	pr_debug("vfio EEH: addr=0x%lx not found in any matching BAR of group\n",
+		 addr);
+	return -EINVAL;
+}
+
 static long vfio_spapr_ioctl_eeh_pe_op(struct iommu_group *group,
 				       unsigned long arg)
 {
 	struct eeh_pe *pe;
 	struct vfio_eeh_pe_op op;
-	unsigned long minsz;
+	unsigned long minsz, res_type;
 
 	pe = eeh_iommu_group_to_pe(group);
 	if (!pe)
@@ -818,6 +924,29 @@ static long vfio_spapr_ioctl_eeh_pe_op(struct iommu_group *group,
 		if (copy_from_user(&op, (void __user *)arg, minsz))
 			return -EFAULT;
 
+		/*
+		 * Only the pSeries RTAS backend takes a PCI bus address, so
+		 * PowerNV requests are passed through unchanged.  Config and
+		 * DMA functions do not carry BAR addresses, and an address
+		 * and mask of zero carries no address.
+		 */
+		res_type = eeh_err_func_to_res_type(op.err.func);
+		if (machine_is(pseries) && res_type &&
+		    (op.err.type == EEH_ERR_TYPE_32 ||
+		     op.err.type == EEH_ERR_TYPE_64) &&
+		    (op.err.addr || op.err.mask)) {
+			unsigned long normalized;
+			int ret;
+
+			ret = vfio_spapr_eeh_normalize_addr(group, res_type,
+							    op.err.addr,
+							    &normalized);
+			if (ret)
+				return ret;
+
+			op.err.addr = normalized;
+		}
+
 		return eeh_pe_inject_err(pe, op.err.type, op.err.func,
 					 op.err.addr, op.err.mask);
 	default:
Signature · 1 line
2.54.0
#4 lore raw

PATCH v7 4/4 powerpc/powernv/eeh: Map generic EEH error types to OPAL

In reply to Narayana Murty N

eeh_pe_inject_err() is called with generic EEH error types defined in the VFIO/EEH userspace ABI (EEH_ERR_TYPE_32, EEH_ERR_TYPE_64). The PowerNV backend previously compared these generic values directly against OPAL firmware constants (OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR and OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64).

This is fragile: it relies on the generic EEH ABI values being numerically identical to OPAL-specific values, and would silently misbehave if they ever diverged.

The preceding patches introduce RTAS-based error injection on pSeries, mapping generic EEH error types to PAPR error-injection classes. Apply the same explicit translation in the PowerNV backend, which uses OPAL instead of RTAS.

Add an explicit mapping in pnv_eeh_err_inject() that translates:
EEH_ERR_TYPE_32 -> OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR EEH_ERR_TYPE_64 -> OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64

Return -ERANGE for unsupported error types, preserving the behavior of the original code. This decouples the VFIO/EEH interface from OPAL implementation details.

No change to the existing userspace ABI or PowerNV behavior.

---
 arch/powerpc/platforms/powernv/eeh-powernv.c | 22 +++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
arch/powerpc/platforms/powernv/eeh-powernv.c +17 -5
index db3370d1673c..01dae760cecb 100644
@@ -1167,12 +1167,24 @@ static int pnv_eeh_err_inject(struct eeh_pe *pe, int type, int func,
 {
 	struct pci_controller *hose = pe->phb;
 	struct pnv_phb *phb = hose->private_data;
+	int opal_err_type;
 	s64 rc;
 
-	if (type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR &&
-	    type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64) {
-		pr_warn("%s: Invalid error type %d\n",
-			__func__, type);
+	/*
+	 * eeh_pe_inject_err() receives generic EEH error types from the
+	 * VFIO/EEH userspace ABI.  The PowerNV backend must not rely on
+	 * these generic values being numerically identical to OPAL firmware
+	 * values.  Translate to OPAL-specific types before calling firmware.
+	 */
+	switch (type) {
+	case EEH_ERR_TYPE_32:
+		opal_err_type = OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR;
+		break;
+	case EEH_ERR_TYPE_64:
+		opal_err_type = OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64;
+		break;
+	default:
+		pr_warn("%s: Invalid error type %d\n", __func__, type);
 		return -ERANGE;
 	}
 
@@ -1192,7 +1204,7 @@ static int pnv_eeh_err_inject(struct eeh_pe *pe, int type, int func,
 
 	/* Do error injection */
 	rc = opal_pci_err_inject(phb->opal_id, pe->addr,
-				 type, func, addr, mask);
+				 opal_err_type, func, addr, mask);
 	if (rc != OPAL_SUCCESS) {
 		pr_warn("%s: Failure %lld injecting error "
 			"%d-%d to PHB#%x-PE#%x\n",
Signature · 1 line
2.54.0