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. 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. Decouples the VFIO/EEH interface from OPAL implementation details. No change to existing userspace ABI or PowerNV behavior. Signed-off-by: Narayana Murty N <[email protected]> --- arch/powerpc/platforms/powernv/eeh-powernv.c | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/platforms/powernv/eeh-powernv.c b/arch/powerpc/platforms/powernv/eeh-powernv.c index db3370d1673c..01dae760cecb 100644 --- a/arch/powerpc/platforms/powernv/eeh-powernv.c +++ b/arch/powerpc/platforms/powernv/eeh-powernv.c @@ -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", -- 2.54.0
