[PATCH v5 3/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection
flat view
WARM3d
SUPERSEDED
From: Narayana Murty N <hidden>
Date: 2026-10-19 10:19:20
Also in:
kvm, lkml
Subsystem:
linux for powerpc (32-bit and 64-bit), pci enhanced error handling (eeh) for powerpc, the rest · Maintainers:
Madhavan Srinivasan, Mahesh J Salgaonkar, Linus Torvalds
Revision v5 of 2 in this series.
Revisions (2)
- v5 current
- v6 [diff vs current]
Replace the legacy MMIO stub in pseries_eeh_err_inject() with a full PAPR-compliant RTAS error injection path. Serialize each ibm,open-errinjct / ibm,errinjct / ibm,close-errinjct session with errinjct_mutex because RTAS maintains state between these calls. Once ibm,open-errinjct succeeds, ibm,close-errinjct is attempted after parameter preparation or ibm,errinjct failures. The RTAS work area is allocated after a successful open to avoid holding it while waiting for the mutex or if open fails. VFIO EEH error injection exposes a generic userspace ABI. pSeries maps the generic EEH error types to RTAS ibm,errinjct encodings via pseries_eeh_type_to_rtas(). EEH_ERR_TYPE_32 and EEH_ERR_TYPE_64 are unchanged; their values are defined in arch/powerpc/include/uapi/asm/eeh.h and are not renumbered. The RTAS work-area allocator guarantees that returned memory is within the range accessible by RTAS (below min(ppc64_rma_size, RTAS_INSTANTIATE_MAX), which is at most RTAS_INSTANTIATE_MAX = 1 GiB), so the physical address fits in the 32-bit RTAS argument without truncation. Remove the now-unused eeh_pe_inject_mmio_error() helper and its declaration; this patch removes its only caller. Tested with corresponding QEMU patches: https://lore.kernel.org/all/20251029150618.186803-1-nnmlinux@linux.ibm.com/ (local) Signed-off-by: Narayana Murty N <redacted> --- arch/powerpc/include/asm/eeh.h | 2 - arch/powerpc/kernel/eeh.c | 5 - arch/powerpc/platforms/pseries/eeh_pseries.c | 114 +++++++++++++++---- 3 files changed, 91 insertions(+), 30 deletions(-)
diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
index b7ebb4ac2c71..083ac58e7eb7 100644
--- a/arch/powerpc/include/asm/eeh.h
+++ b/arch/powerpc/include/asm/eeh.h@@ -310,8 +310,6 @@ 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); - /** * EEH_POSSIBLE_ERROR() -- test for possible MMIO failure. *
diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
index bb836f02101c..369aad298f75 100644
--- a/arch/powerpc/kernel/eeh.c
+++ b/arch/powerpc/kernel/eeh.c@@ -1664,11 +1664,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
diff --git a/arch/powerpc/platforms/pseries/eeh_pseries.c b/arch/powerpc/platforms/pseries/eeh_pseries.c
index 999b3065e09b..52d001042663 100644
--- a/arch/powerpc/platforms/pseries/eeh_pseries.c
+++ b/arch/powerpc/platforms/pseries/eeh_pseries.c@@ -24,6 +24,7 @@ #include <linux/proc_fs.h> #include <linux/rbtree.h> #include <linux/sched.h> +#include <linux/mutex.h> #include <linux/seq_file.h> #include <linux/sizes.h> #include <linux/spinlock.h>
@@ -35,6 +36,7 @@ #include <asm/machdep.h> #include <asm/ppc-pci.h> #include <asm/rtas.h> +#include <asm/rtas-work-area.h> /* RTAS tokens */ static int ibm_set_eeh_option;
@@ -1006,41 +1008,107 @@ static int prepare_errinjct_buffer(void *buf, struct eeh_pe *pe, return 0; } +/* Serializes the open/inject/close RTAS error injection session */ +static DEFINE_MUTEX(errinjct_mutex); + /** * pseries_eeh_err_inject - Inject specified error to the indicated PE * @pe: the indicated PE - * @type: error type - * @func: specific error type - * @addr: address - * @mask: address mask - * The routine is called to inject specified error, which is - * determined by @type and @func, to the indicated PE + * @type: generic EEH error type (EEH_ERR_TYPE_32 or EEH_ERR_TYPE_64) + * @func: specific error function + * @addr: address argument (type-dependent, may be zero) + * @mask: address mask (type-dependent, may be zero) + * + * Implements PAPR-compliant error injection using: + * ibm,open-errinjct -> ibm,errinjct -> ibm,close-errinjct + * + * errinjct_mutex serializes the open/inject/close session sequence + * because RTAS maintains state between these calls. A short-lived + * RTAS work area is allocated after a successful open and freed before + * close. + * + * Return: 0 on success, negative errno on failure. */ static int pseries_eeh_err_inject(struct eeh_pe *pe, int type, int func, unsigned long addr, unsigned long mask) { - struct eeh_dev *pdev; + struct rtas_work_area *area; + phys_addr_t area_phys; + void *buf; + int open_token, errinjct_token, close_token; + int session_token; + int rtas_err_type; + int close_rc; + int rc; + + rc = validate_errinjct_args(pe, type, func, addr, mask); + if (rc) + return rc; - /* Check on PCI error type */ - if (type != EEH_ERR_TYPE_32 && type != EEH_ERR_TYPE_64) + rtas_err_type = pseries_eeh_type_to_rtas(type); + if (rtas_err_type < 0) return -EINVAL; - 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: - /* injects a MMIO error for all pdev's belonging to PE */ - pci_lock_rescan_remove(); - list_for_each_entry(pdev, &pe->edevs, entry) - eeh_pe_inject_mmio_error(pdev->pdev); - pci_unlock_rescan_remove(); - break; - default: - return -ERANGE; + open_token = rtas_function_token(RTAS_FN_IBM_OPEN_ERRINJCT); + errinjct_token = rtas_function_token(RTAS_FN_IBM_ERRINJCT); + close_token = rtas_function_token(RTAS_FN_IBM_CLOSE_ERRINJCT); + + if (open_token == RTAS_UNKNOWN_SERVICE || + errinjct_token == RTAS_UNKNOWN_SERVICE || + close_token == RTAS_UNKNOWN_SERVICE) + return -ENODEV; + + mutex_lock(&errinjct_mutex); + + do { + rc = rtas_call(open_token, 0, 2, &session_token); + } while (rtas_busy_delay(rc)); + + if (rc) { + pr_err("ibm,open-errinjct failed: status=%d\n", rc); + rc = rtas_error_rc(rc); + goto out_unlock; } - return 0; + area = rtas_work_area_alloc(RTAS_ERRINJCT_BUF_SIZE); + buf = rtas_work_area_raw_buf(area); + area_phys = rtas_work_area_phys(area); + + rc = prepare_errinjct_buffer(buf, pe, rtas_err_type, func, addr, mask); + if (rc) + goto out_free_area; + + /* + * RTAS work areas are allocated below RTAS_INSTANTIATE_MAX, so + * area_phys fits in the 32-bit RTAS argument. + */ + do { + rc = rtas_call(errinjct_token, 3, 1, NULL, + rtas_err_type, session_token, + (u32)area_phys); + } while (rtas_busy_delay(rc)); + + if (rc) { + pr_err("ibm,errinjct failed: status=%d\n", rc); + rc = rtas_error_rc(rc); + } + +out_free_area: + rtas_work_area_free(area); + + do { + close_rc = rtas_call(close_token, 1, 1, NULL, session_token); + } while (rtas_busy_delay(close_rc)); + + if (close_rc) { + pr_warn("ibm,close-errinjct failed: status=%d\n", close_rc); + if (!rc) + rc = rtas_error_rc(close_rc); + } + +out_unlock: + mutex_unlock(&errinjct_mutex); + return rc; } static struct eeh_ops pseries_eeh_ops = {
--
2.54.0