powerpc: Add RTAS based error injection support for pSeries
Subsystems (5)
v6 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:
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 (5):
powerpc/rtas: Handle ibm,open-errinjct return format powerpc/pseries/eeh: Add RTAS error injection helpers 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 | 2 - arch/powerpc/kernel/eeh.c | 10 +- arch/powerpc/kernel/rtas.c | 78 +++- arch/powerpc/platforms/powernv/eeh-powernv.c | 22 +- arch/powerpc/platforms/pseries/eeh_pseries.c | 375 ++++++++++++++++++- drivers/vfio/vfio_iommu_spapr_tce.c | 140 +++++++ 6 files changed, 585 insertions(+), 42 deletions(-)
Signature · 1 line
2.54.0
PATCH v6 1/5 powerpc/rtas: Handle ibm,open-errinjct return format
ibm,open-errinjct uses a non-standard RTAS return layout:
rets[0] = session token (output parameter)
rets[1] = status code
Unlike all other RTAS functions which use:
rets[0] = status code
rets[1..] = output parameters
Add rtas_token_is_open_errinjct() to identify this call, and rtas_status_from_args() to extract status from the correct position.
Add an early guard in rtas_call() that rejects ibm,open-errinjct invocations where nret < 2, since reading rets[1] would be out of bounds. This is a kernel-side call-convention error, so -EINVAL is returned rather than an RTAS firmware status code:
if (rtas_token_is_open_errinjct(token) && nret < 2) {
WARN_ON_ONCE(1);
return -EINVAL;
}Adjust the output-copy loop so that for ibm,open-errinjct:
return value = rets[1] (status)
outputs[0] = rets[0] (session token)
For all other functions the existing convention is preserved:
return value = rets[0] (status)
outputs[0..] = rets[1..] (non-status outputs)
Move the "/* A -1 return code... */" comment immediately before the ret == -1 check so it documents the check it guards.
Also fix sys_rtas() last-error status detection: add the same early nret < 2 validation at the syscall boundary (returning -EINVAL) to avoid entering RTAS with an invalid ibm,open-errinjct return layout. After that guard, use rtas_status_from_args() to obtain the RTAS status for last-error handling.
The prominent user librtas already passes nret = 2 for this function as required by PAPR, so well-formed callers are unaffected.
Reference: OpenPOWER PAPR documentation
https://files.openpower.foundation/s/XFgfMaqLMD5Bcm8
--- arch/powerpc/kernel/rtas.c | 78 +++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 9 deletions(-)
arch/powerpc/kernel/rtas.c +69 -9
@@ -1117,6 +1117,28 @@ static bool token_is_restricted_errinjct(s32 token) token ==rtas_function_token (RTAS_FN_IBM_ERRINJCT ); } +/* +* ibm,open-errinjct uses a non-standard return layout: +* rets[0] = session token (output parameter) +* rets[1] = status code +* +* All other RTAS functions use the standard layout: +* rets[0] = status code +* rets[1..] = output parameters +*/ +static inline bool rtas_token_is_open_errinjct (int token) +{ +return token ==rtas_function_token (RTAS_FN_IBM_OPEN_ERRINJCT ); +} + +static int rtas_status_from_args (int token,struct rtas_args *args,int nret) +{ +if (rtas_token_is_open_errinjct (token)) +return be32_to_cpu (args->rets[1 ]); + +return nret >0 ?be32_to_cpu (args->rets[0 ]) :0 ; +} +/** * rtas_call() - Invoke an RTAS firmware function. * @token: Identifies the function being invoked.
@@ -1198,6 +1220,16 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)return -1 ; } +/* +* ibm,open-errinjct returns rets[0]=session_token, rets[1]=status. +* We need nret >= 2 to read status from rets[1]. Reject early if +* the caller forgot to account for the extra return cell. +*/ +if (rtas_token_is_open_errinjct (token) && nret <2 ) { +WARN_ON_ONCE (1 ); +return -EINVAL ; + } +if ((mfmsr () & (MSR_IR |MSR_DR )) != (MSR_IR |MSR_DR )) {WARN_ON_ONCE (1 );return -1 ;
@@ -1213,15 +1245,33 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)va_rtas_call_unlocked (args, token, nargs, nret, list);va_end (list); + ret =rtas_status_from_args (token, args, nret); +/* A -1 return code indicates that the last command couldn't -be completed due to a hardware error. */ -if (be32_to_cpu (args->rets[0 ]) ==-1 ) +* be completed due to a hardware error. +*/ +if (ret ==-1 ) buff_copy =__fetch_rtas_last_error (NULL ); -if (nret >1 && outputs !=NULL ) -for (i =0 ; i < nret-1 ; ++i) - outputs[i] =be32_to_cpu (args->rets[i +1 ]); - ret = (nret >0 ) ?be32_to_cpu (args->rets[0 ]) :0 ; +/* +* Copy non-status outputs to the caller's buffer. +* +* For ibm,open-errinjct the layout is: +* rets[0] = session token -> outputs[0] +* rets[1] = status (returned, not copied) +* +* For all other RTAS functions: +* rets[0] = status (returned, not copied) +* rets[1..nret-1] -> outputs[0..nret-2] +*/ +if (outputs) { +if (rtas_token_is_open_errinjct (token)) { + outputs[0 ] =be32_to_cpu (args->rets[0 ]); + }else if (nret >1 ) { +for (i =0 ; i < nret -1 ; ++i) + outputs[i] =be32_to_cpu (args->rets[i +1 ]); + } + }lockdep_unpin_lock (&rtas_lock, cookie);raw_spin_unlock_irqrestore (&rtas_lock, flags);
@@ -1896,6 +1946,14 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)if (block_rtas_call (func, nargs, &args))return -EINVAL ; +/* +* ibm,open-errinjct places status at rets[1]; reject calls with +* fewer than 2 return cells before entering RTAS, since reading +* rets[1] for the -1 sentinel would be out of bounds. +*/ +if (rtas_token_is_open_errinjct (token) && nret <2 ) +return -EINVAL ; +if (token_is_restricted_errinjct (token)) {int err;
@@ -1942,9 +2000,11 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)do_enter_rtas (&rtas_args); args = rtas_args; -/* A -1 return code indicates that the last command couldn't -be completed due to a hardware error. */ -if (be32_to_cpu (args.rets[0 ]) ==-1 ) +/* +* A -1 return code indicates that the last command couldn't +* be completed due to a hardware error. +*/ +if (rtas_status_from_args (token, &args, nret) ==-1 ) errbuf =__fetch_rtas_last_error (buff_copy);lockdep_unpin_lock (&rtas_lock, cookie);
Signature · 1 line
2.54.0
Re: [PATCH v6 1/5] powerpc/rtas: Handle ibm,open-errinjct return format
Quoted 28 lines · Narayana Murty N
ibm,open-errinjct uses a non-standard RTAS return layout:
rets[0] = session token (output parameter)
rets[1] = status codeUnlike all other RTAS functions which use:
rets[0] = status code
rets[1..] = output parametersAdd
rtas_token_is_open_errinjct()to identify this call, andrtas_status_from_args()to extract status from the correct position.Add an early guard in
rtas_call()that rejects ibm,open-errinjct invocations where nret < 2, since reading rets[1] would be out of bounds. This is a kernel-side call-convention error, so-EINVALis returned rather than an RTAS firmware status code:if (rtas_token_is_open_errinjct(token) && nret < 2) { WARN_ON_ONCE(1); return -EINVAL; }Adjust the output-copy loop so that for ibm,open-errinjct:
return value = rets[1] (status)
outputs[0] = rets[0] (session token)
Quoted 7 lines
For all other functions the existing convention is preserved:
return value = rets[0] (status)
outputs[0..] = rets[1..] (non-status outputs)Move the "/* A -1 return code... */" comment immediately before the ret == -1 check so it documents the check it guards.
Nit: I think we should not documenting a minor comment movement in the commit message.
Quoted 22 lines
Also fix
sys_rtas()last-error status detection: add the same early nret < 2 validation at the syscall boundary (returning-EINVAL) to avoid entering RTAS with an invalid ibm,open-errinjct return layout. After that guard, usertas_status_from_args()to obtain the RTAS status for last-error handling.
The prominent user librtas already passes nret = 2 for this function as required by PAPR, so well-formed callers are unaffected.Reference: OpenPOWER PAPR documentation
https://files.openpower.foundation/s/XFgfMaqLMD5Bcm8Signed-off-by Narayana Murty N <[email protected]>--- arch/powerpc/kernel/rtas.c | 78 +++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 9 deletions(-)arch/powerpc/kernel/rtas.c +0
-0@@ -1117,6 +1117,28 @@ static bool token_is_restricted_errinjct(s32 token) token ==rtas_function_token (RTAS_FN_IBM_ERRINJCT ); }
arch/powerpc/kernel/rtas.c static bool token_is_restricted_errinjct(s32 token) · line 1128
Quoted 10 lines
arch/powerpc/kernel/rtas.c +9
-0+/* +* ibm,open-errinjct uses a non-standard return layout: +* rets[0] = session token (output parameter) +* rets[1] = status code +* +* All other RTAS functions use the standard layout: +* rets[0] = status code +* rets[1..] = output parameters +*/
Nit: this comment describes rtas_status_from_args(), not rtas_token_is_open_errinjct(). Please move it down.
Quoted 17 lines
arch/powerpc/kernel/rtas.c +13
-0+static inline bool rtas_token_is_open_errinjct (int token) +{ +return token ==rtas_function_token (RTAS_FN_IBM_OPEN_ERRINJCT ); +} + +static int rtas_status_from_args (int token,struct rtas_args *args,int nret) +{ +if (rtas_token_is_open_errinjct (token)) +return be32_to_cpu (args->rets[1 ]); + +return nret >0 ?be32_to_cpu (args->rets[0 ]) :0 ; +} +/** * rtas_call() - Invoke an RTAS firmware function. * @token: Identifies the function being invoked.
arch/powerpc/kernel/rtas.c int rtas_call(int token, int nargs, int nret, int *outputs, ...) · line 1229
Quoted 10 lines
arch/powerpc/kernel/rtas.c +7
-0@@ -1198,6 +1220,16 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)return -1 ; } +/* +* ibm,open-errinjct returns rets[0]=session_token, rets[1]=status. +* We need nret >= 2 to read status from rets[1]. Reject early if +* the caller forgot to account for the extra return cell. +*/ +if (rtas_token_is_open_errinjct (token) && nret <2 ) { +WARN_ON_ONCE (1 );
Nit: please switch WARN_ON_ONCE(1) to a WARN_ONCE() with a message, so the log says what the caller got wrong. For example:
WARN_ONCE(1, "rtas: ibm,open-errinjct needs nret >= 2 (got %d)\n", nret);
Quoted 20 lines
arch/powerpc/kernel/rtas.c +8
-2+return -EINVAL ; + } +if ((mfmsr () & (MSR_IR |MSR_DR )) != (MSR_IR |MSR_DR )) {WARN_ON_ONCE (1 );return -1 ;@@ -1213,15 +1245,33 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)va_rtas_call_unlocked (args, token, nargs, nret, list);va_end (list); + ret =rtas_status_from_args (token, args, nret); +/* A -1 return code indicates that the last command couldn't -be completed due to a hardware error. */ -if (be32_to_cpu (args->rets[0 ]) ==-1 ) +* be completed due to a hardware error. +*/ +if (ret ==-1 ) buff_copy =__fetch_rtas_last_error (NULL );
[...]
Quoted 13 lines
arch/powerpc/kernel/rtas.c +9
-4-if (nret >1 && outputs !=NULL ) -for (i =0 ; i < nret-1 ; ++i) - outputs[i] =be32_to_cpu (args->rets[i +1 ]); - ret = (nret >0 ) ?be32_to_cpu (args->rets[0 ]) :0 ; +/* +* Copy non-status outputs to the caller's buffer. +* +* For ibm,open-errinjct the layout is: +* rets[0] = session token -> outputs[0] +* rets[1] = status (returned, not copied) +* +* For all other RTAS functions: +* rets[0] = status (returned, not copied)
arch/powerpc/kernel/rtas.c int rtas_call(int token, int nargs, int nret, int *outputs, ...) · line 1274
Quoted 10 lines
arch/powerpc/kernel/rtas.c +10
-0+* rets[1..nret-1] -> outputs[0..nret-2] +*/ +if (outputs) { +if (rtas_token_is_open_errinjct (token)) { + outputs[0 ] =be32_to_cpu (args->rets[0 ]); + }else if (nret >1 ) { +for (i =0 ; i < nret -1 ; ++i) + outputs[i] =be32_to_cpu (args->rets[i +1 ]); + } + }
Just wondering, what is the need to copy the outputs when RTAS returns -1 (hardware error)?
However, since it has always been this way, I have no concerns regarding this aspect of the patch.
Quoted 5 lines
lockdep_unpin_lock(&rtas_lock, cookie); raw_spin_unlock_irqrestore(&rtas_lock, flags);arch/powerpc/kernel/rtas.c +0
-0@@ -1896,6 +1946,14 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)if (block_rtas_call (func, nargs, &args))
arch/powerpc/kernel/rtas.c SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs) · line 1956
Quoted 10 lines
arch/powerpc/kernel/rtas.c +8
-0return -EINVAL ; +/* +* ibm,open-errinjct places status at rets[1]; reject calls with +* fewer than 2 return cells before entering RTAS, since reading +* rets[1] for the -1 sentinel would be out of bounds. +*/ +if (rtas_token_is_open_errinjct (token) && nret <2 ) +return -EINVAL ; +
I think it makes sense to perform this check after the security lockdown check.
Otherwise, it would look confusing if the kernel first reports that the argument is less than expected, and then, when the user passes the correct argument, kernel reports that the operation cannot be executed because it is blocked by lockdown.
So, let's move this check below the security lockdown check.
- Sourabh Jain
Quoted 18 lines
arch/powerpc/kernel/rtas.c +5
-3if (token_is_restricted_errinjct (token)) {int err;@@ -1942,9 +2000,11 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)do_enter_rtas (&rtas_args); args = rtas_args; -/* A -1 return code indicates that the last command couldn't -be completed due to a hardware error. */ -if (be32_to_cpu (args.rets[0 ]) ==-1 ) +/* +* A -1 return code indicates that the last command couldn't +* be completed due to a hardware error. +*/ +if (rtas_status_from_args (token, &args, nret) ==-1 ) errbuf =__fetch_rtas_last_error (buff_copy);lockdep_unpin_lock (&rtas_lock, cookie);
Re: [PATCH v6 1/5] powerpc/rtas: Handle ibm,open-errinjct return format
Hi Sourabh,
thank you reviewing the patch series.
Quoted 33 lines · Sourabh Jain
Quoted 30 lines · Narayana Murty N
ibm,open-errinjct uses a non-standard RTAS return layout:
rets[0] = session token (output parameter)
rets[1] = status codeUnlike all other RTAS functions which use:
rets[0] = status code
rets[1..] = output parametersAdd
rtas_token_is_open_errinjct()to identify this call, andrtas_status_from_args()to extract status from the correct position.Add an early guard in
rtas_call()that rejects ibm,open-errinjct invocations where nret < 2, since reading rets[1] would be out of bounds. This is a kernel-side call-convention error, so-EINVALis returned rather than an RTAS firmware status code:if (
rtas_token_is_open_errinjct(token)&& nret < 2) {WARN_ON_ONCE(1);
return-EINVAL;
}Adjust the output-copy loop so that for ibm,open-errinjct:
return value = rets[1] (status)
outputs[0] = rets[0] (session token)For all other functions the existing convention is preserved:
Quoted 9 lines
Quoted 5 lines
return value = rets[0] (status)
outputs[0..] = rets[1..] (non-status outputs)Move the "/* A -1 return code... */" comment immediately before the ret == -1 check so it documents the check it guards.
Nit: I think we should not documenting a minor comment movement in the commit message.
Agree, I will remove.
Quoted 27 lines
Quoted 27 lines
Also fix
sys_rtas()last-error status detection: add the same early nret < 2 validation at the syscall boundary (returning-EINVAL) to avoid entering RTAS with an invalid ibm,open-errinjct return layout. After that guard, usertas_status_from_args()to obtain the RTAS status for last-error handling.
The prominent user librtas already passes nret = 2 for this function as required by PAPR, so well-formed callers are unaffected.Reference: OpenPOWER PAPR documentation
https://files.openpower.foundation/s/XFgfMaqLMD5Bcm8Signed-off-by Narayana Murty N <[email protected]>---
arch/powerpc/kernel/rtas.c| 78 +++++++++++++++++++++++++++++++++-----1 file changed, 69 insertions(+), 9 deletions(-)arch/powerpc/kernel/rtas.c +4
-0@@ -1117,6 +1117,28 @@ static bool token_is_restricted_errinjct(s32 token) token == rtas_function_token(RTAS_FN_IBM_ERRINJCT); } +/* +* ibm,open-errinjct uses a non-standard return layout: +* rets[0] = session token (output parameter) +* rets[1] = status code
Quoted 9 lines
arch/powerpc/kernel/rtas.c static bool token_is_restricted_errinjct(s32 token) · line 1128
Quoted 5 lines
arch/powerpc/kernel/rtas.c +5
-0+* +* All other RTAS functions use the standard layout: +* rets[0] = status code +* rets[1..] = output parameters +*/ Nit: this comment describes
rtas_status_from_args(), notrtas_token_is_open_errinjct(). Please move it down.
Agreed. I'll move the comment above rtas_status_from_args().
Quoted 32 lines
Quoted 18 lines
arch/powerpc/kernel/rtas.c +13
-0+static inline bool rtas_token_is_open_errinjct (int token) +{ + return token == rtas_function_token(RTAS_FN_IBM_OPEN_ERRINJCT); +} + +static int rtas_status_from_args (int token,struct rtas_args *args,int nret) +{ + if (rtas_token_is_open_errinjct(token)) + return be32_to_cpu(args->rets[1]); + + return nret > 0 ? be32_to_cpu(args->rets[0]) : 0; +} + /*** rtas_call() - Invoke an RTAS firmware function. * @token: Identifies the function being invoked.
arch/powerpc/kernel/rtas.c int rtas_call(int token, int nargs, int nret, · line 1229
Quoted 10 lines
arch/powerpc/kernel/rtas.c +7
-0@@ -1198,6 +1220,16 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...) return -1; } + /* + * ibm,open-errinjct returns rets[0]=session_token, rets[1]=status. + * We need nret >= 2 to read status from rets[1]. Reject early if + * the caller forgot to account for the extra return cell. + */ + if (rtas_token_is_open_errinjct(token) && nret < 2) { + WARN_ON_ONCE(1);Nit: please switch
WARN_ON_ONCE(1)to aWARN_ONCE()with a message, so the log says what the caller got wrong. For example:
Quoted 2 lines
WARN_ONCE(1, "rtas: ibm,open-errinjct needs nret >= 2 (got %d)\n", nret);
Makes sense. I'll use WARN_ONCE() with the suggested message.
Quoted 44 lines
Quoted 19 lines
arch/powerpc/kernel/rtas.c +8
-2+ return -EINVAL; + } + if ((mfmsr() & (MSR_IR|MSR_DR)) != (MSR_IR|MSR_DR)) { WARN_ON_ONCE(1); return -1;@@ -1213,15 +1245,33 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...) va_rtas_call_unlocked(args, token, nargs, nret, list); va_end(list); + ret = rtas_status_from_args(token, args, nret); + /* A -1 return code indicates that the last command couldn't - be completed due to a hardware error. */ - if (be32_to_cpu(args->rets[0]) == -1) + * be completed due to a hardware error. + */ + if (ret == -1) buff_copy = __fetch_rtas_last_error(NULL);[...]
Quoted 15 lines
- if (nret > 1 && outputs != NULL)
- for (i = 0; i < nret-1; ++i)
- outputs[i] =be32_to_cpu(args->rets[i + 1]); - ret = (nret > 0) ?be32_to_cpu(args->rets[0]): 0; + /*
+ * Copy non-status outputs to the caller's buffer. + *
+ * For ibm,open-errinjct the layout is:
+ * rets[0] = session token -> outputs[0] + * rets[1] = status (returned, not copied) + *
+ * For all other RTAS functions:
+ * rets[0] = status (returned, not copied) + * rets[1..nret-1] -> outputs[0..nret-2] + */Quoted 8 lines
+ if (outputs) {
+ if (rtas_token_is_open_errinjct(token)) { + outputs[0] =be32_to_cpu(args->rets[0]); + } else if (nret > 1) {
+ for (i = 0; i < nret - 1; ++i)
+ outputs[i] =be32_to_cpu(args->rets[i + 1]); + }
+ }
Quoted 5 lines
Just wondering, what is the need to copy the outputs when RTAS returns -1 (hardware error)?
However, since it has always been this way, I have no concerns regarding this aspect of the patch.
Yes, the intention here is to preserve the existing behavior of rtas_call() while handling the non-standard return layout of ibm,open-errinjct.
Quoted 17 lines
Quoted 4 lines
lockdep_unpin_lock(&rtas_lock, cookie);raw_spin_unlock_irqrestore(&rtas_lock, flags);arch/powerpc/kernel/rtas.c +0
-0@@ -1896,6 +1946,14 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)arch/powerpc/kernel/rtas.c SYSCALL_DEFINE1(rtas, struct rtas_args __user · line 1956
Quoted 10 lines
arch/powerpc/kernel/rtas.c +8
-0if (block_rtas_call(func, nargs, &args)) return -EINVAL; + /* + * ibm,open-errinjct places status at rets[1]; reject calls with + * fewer than 2 return cells before entering RTAS, since reading + * rets[1] for the -1 sentinel would be out of bounds. + */ + if (rtas_token_is_open_errinjct(token) && nret < 2) + return -EINVAL; +I think it makes sense to perform this check after the security lockdown check.
Quoted 6 lines
Otherwise, it would look confusing if the kernel first reports that the argument is less than expected, and then, when the user passes the correct argument, kernel reports that the operation cannot be executed because it is blocked by lockdown.
So, let's move this check below the security lockdown check.
Agreed. I'll move the nret validation below the security lockdown check.
Quoted 4 lines
- Sourabh Jain
Thanks,
Narayana Murty.
Quoted 17 lines
Quoted 16 lines
arch/powerpc/kernel/rtas.c +5
-3if (token_is_restricted_errinjct(token)) { int err;@@ -1942,9 +2000,11 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs) do_enter_rtas(&rtas_args); args = rtas_args; - /* A -1 return code indicates that the last command couldn't - be completed due to a hardware error. */ - if (be32_to_cpu(args.rets[0]) == -1) + /* + * A -1 return code indicates that the last command couldn't + * be completed due to a hardware error. + */ + if (rtas_status_from_args(token, &args, nret) == -1) errbuf = __fetch_rtas_last_error(buff_copy); lockdep_unpin_lock(&rtas_lock, cookie);
PATCH v6 2/5 powerpc/pseries/eeh: Add RTAS error injection helpers
In reply to Narayana Murty NPrepare the pSeries EEH backend for RTAS error injection by adding helpers that:
* map generic EEH error types to RTAS/PAPR error types;
* validate IOA addresses against the target PE.
Define pr_fmt unconditionally at the top of eeh_pseries.c so all pr_*() calls carry the "EEH: " prefix.
Define RTAS firmware error-type encodings as file-local constants. Only the two IOA bus-error types are supported; other PAPR encodings are not reachable through the generic EEH_ERR_TYPE_* UAPI:
RTAS_ERR_TYPE_IOA_BUS_ERROR 0x07
RTAS_ERR_TYPE_IOA_BUS_ERROR_64 0x0f
Add RTAS_ERRINJCT_BUF_SIZE for the ibm,errinjct work buffer size.
Add pseries_eeh_type_to_rtas() to translate the two generic EEH error types (EEH_ERR_TYPE_32, EEH_ERR_TYPE_64) into the corresponding RTAS ibm,errinjct encodings.
Add validate_addr_mask_in_pe() to verify that a caller-provided address falls within a BAR of some device in the PE. RTAS IOA bus-error injection requires a PCI/IOA bus address; validate_addr_mask_in_pe() accepts only PCI bus addresses. VFIO userspace resource addresses are normalized to PCI bus addresses in vfio_iommu_spapr_tce.c before reaching this backend; no resource-address fallback is added here.
Use pcibios_resource_to_bus() to convert each BAR resource to PCI bus address space before validating the address. Only standard BARs (BAR0..BAR5) are searched; ROM and bridge resources are not IOA bus-error targets. Hold pci_rescan_remove_lock while traversing PE devices and their BAR resources so PCI device removal cannot race the address validation.
Skip unassigned or disabled BARs explicitly: on pseries, pcibios_fixup_resources() zero-bases unassigned BARs (start=0, end=size-1) and sets IORESOURCE_UNSET, so resource_size() is non-zero for them and pcibios_resource_to_bus() treats them as bus address zero. Use pci_resource_len() (which returns 0 when end==0) instead of resource_size(), and reject BARs with IORESOURCE_UNSET or IORESOURCE_DISABLED set.
Returns -EINVAL (Linux errno) rather than a raw RTAS status.
validate_errinjct_args() and prepare_errinjct_buffer() are introduced in the next patch alongside their callers so each intermediate commit builds cleanly with CONFIG_WERROR.
pseries_eeh_err_inject() retains the existing MMIO injection body unchanged in this patch. It is replaced by the full RTAS session implementation in the next patch. This keeps the patch bisectable:
each commit builds and functions correctly independently.
--- arch/powerpc/platforms/pseries/eeh_pseries.c | 134 +++++++++++++++++++ 1 file changed, 134 insertions(+)
arch/powerpc/platforms/pseries/eeh_pseries.c +134 -0
@@ -12,6 +12,8 @@* Copyright Linas Vepstas 2005, 2006 */ +#define pr_fmt (fmt) "EEH: " fmt +#include <linux/atomic.h> #include <linux/delay.h> #include <linux/export.h>
@@ -23,6 +25,7 @@#include <linux/rbtree.h> #include <linux/sched.h> #include <linux/seq_file.h> +#include <linux/sizes.h> #include <linux/spinlock.h> #include <linux/crash_dump.h>
@@ -786,6 +789,137 @@ static int pseries_notify_resume(struct eeh_dev *edev) }#endif +/* +* RTAS firmware error-type encodings (PAPR). These are pseries-private; +* user-space sees only the generic EEH_ERR_TYPE_* values from eeh.h. +* Only IOA bus-error types are supported; other PAPR encodings are not +* reachable through the generic EEH_ERR_TYPE_* UAPI. +*/ +#define RTAS_ERR_TYPE_IOA_BUS_ERROR 0x07 +#define RTAS_ERR_TYPE_IOA_BUS_ERROR_64 0x0f + +/* Size of the ibm,errinjct work buffer as defined by PAPR */ +#define RTAS_ERRINJCT_BUF_SIZE SZ_1K + +/** +* pseries_eeh_type_to_rtas - Map generic EEH error type to RTAS encoding +* @type: generic EEH error type (EEH_ERR_TYPE_32, EEH_ERR_TYPE_64) +* +* Translates the generic VFIO/EEH error type passed from userspace into +* the RTAS-specific ibm,errinjct error type encoding defined by PAPR. +* +* Return: RTAS error type on success, -EINVAL for unknown types. +*/ +static int pseries_eeh_type_to_rtas (int type) +{ +switch (type) { +case EEH_ERR_TYPE_32 : +return RTAS_ERR_TYPE_IOA_BUS_ERROR ; +case EEH_ERR_TYPE_64 : +return RTAS_ERR_TYPE_IOA_BUS_ERROR_64 ; +default : +return -EINVAL ; + } +} + +/** +* validate_addr_mask_in_pe - Validate addr against PCI bus BAR addresses in PE +* @pe: EEH PE containing one or more PCI devices +* @addr: PCI bus address to validate +* @mask: address mask (passed to firmware unchanged) +* +* RTAS IOA bus-error injection uses PCI bus addresses. Linux PCI resources +* are CPU/resource addresses and may differ on pseries due to PHB window +* translation. Convert each BAR resource to PCI bus address space before +* validating @addr. +* +* Zero addr and mask are accepted without BAR lookup (no-address injection). +* +* Return: 0 if valid, -EINVAL on invalid input. +*/ +static int validate_addr_mask_in_pe (struct eeh_pe *pe,unsigned long addr, +unsigned long mask) +{ +struct pci_bus_region region; +struct eeh_dev *edev, *tmp; +struct pci_dev *pdev; +struct resource *res; +resource_size_t bus_start; +resource_size_t bus_len; +bool found = false; +int bar; + +if (!addr && !mask) +return 0 ; + +if (!pe) +return -EINVAL ; + +/* +* RTAS IOA bus-error injection uses PCI bus addresses. Linux PCI +* resources are CPU/resource addresses and may differ on pseries due +* to PHB window translation. Convert each BAR resource to PCI bus +* address space before validating @addr. +* +* Hold pci_rescan_remove_lock across the traversal to protect pdev +* lifetime: pci_stop_and_remove_bus_device() requires this lock. +*/ +pci_lock_rescan_remove (); +eeh_pe_for_each_dev (pe, edev, tmp) { + pdev =eeh_dev_to_pci_dev (edev); +if (!pdev) +continue ; + +/* +* Validate against standard BARs (BAR0..BAR5) only. +* ROM and bridge resources are not IOA bus-error targets. +*/ +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { + res = &pdev->resource[bar]; + +/* +* Skip unassigned or disabled BARs. On pseries, +* pcibios_fixup_resources() zero-bases unassigned BARs +* (start=0, end=size-1) and sets IORESOURCE_UNSET. +* resource_size() is non-zero for such BARs, and +* pcibios_resource_to_bus() treats them as bus address +* zero, so they must be excluded explicitly. +* Use pci_resource_len() which returns 0 when end==0. +*/ +if (!pci_resource_len (pdev, bar)) +continue ; + +if (!(res->flags & (IORESOURCE_MEM |IORESOURCE_IO ))) +continue ; + +if (res->flags & (IORESOURCE_UNSET |IORESOURCE_DISABLED )) +continue ; + +pcibios_resource_to_bus (pdev->bus, ®ion, res); + + bus_start = region.start; + bus_len =pci_resource_len (pdev, bar); + +if ((resource_size_t )addr >= bus_start && + ((resource_size_t )addr - bus_start) < bus_len) { +pr_debug ("addr=0x%lx mask=0x%lx validated in PCI bus BAR[%d] of %s: bus range 0x%llx-0x%llx\n" , + addr, mask, bar,pci_name (pdev), + (unsigned long long )region.start, + (unsigned long long )region.end); + found = true; + goto done; + } + } + } +done: +pci_unlock_rescan_remove (); + +if (!found) +pr_err ("addr=0x%lx mask=0x%lx not within any PCI bus BAR of any device in PE\n" , + addr, mask); +return found ?0 : -EINVAL ; +} +/** * pseries_eeh_err_inject - Inject specified error to the indicated PE * @pe: the indicated PE
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v6 2/5] powerpc/pseries/eeh: Add RTAS error injection helpers
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] powerpc/pseries/eeh: static RTAS helpers defined without callers --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] powerpc/pseries/eeh: static RTAS helpers defined without callers
--
commit 8b171281b038661dc89a614c1b95db68271706f4
Author: Narayana Murty N <[email protected]>
powerpc/pseries/eeh: Add RTAS error injection helpers
This patch adds static RTAS error injection helper functions, pseries_eeh_type_to_rtas() and validate_addr_mask_in_pe(), to prepare the pSeries EEH backend for RTAS-based error injection.
Quoted 4 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +0
-0
[ ... ]
Quoted 44 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +40
-0@@ -786,6 +789,137 @@ static int pseries_notify_resume(struct eeh_dev *edev) }#endif +/* +* RTAS firmware error-type encodings (PAPR). These are pseries-private; +* user-space sees only the generic EEH_ERR_TYPE_* values from eeh.h. +* Only IOA bus-error types are supported; other PAPR encodings are not +* reachable through the generic EEH_ERR_TYPE_* UAPI. +*/ +#define RTAS_ERR_TYPE_IOA_BUS_ERROR 0x07 +#define RTAS_ERR_TYPE_IOA_BUS_ERROR_64 0x0f + +/* Size of the ibm,errinjct work buffer as defined by PAPR */ +#define RTAS_ERRINJCT_BUF_SIZE SZ_1K + +/** +* pseries_eeh_type_to_rtas - Map generic EEH error type to RTAS encoding +* @type: generic EEH error type (EEH_ERR_TYPE_32, EEH_ERR_TYPE_64) +* +* Translates the generic VFIO/EEH error type passed from userspace into +* the RTAS-specific ibm,errinjct error type encoding defined by PAPR. +* +* Return: RTAS error type on success, -EINVAL for unknown types. +*/ +static int pseries_eeh_type_to_rtas (int type) +{ +switch (type) { +case EEH_ERR_TYPE_32 : +return RTAS_ERR_TYPE_IOA_BUS_ERROR ; +case EEH_ERR_TYPE_64 : +return RTAS_ERR_TYPE_IOA_BUS_ERROR_64 ; +default : +return -EINVAL ; + } +} + +/** +* validate_addr_mask_in_pe - Validate addr against PCI bus BAR addresses in PE +* @pe: EEH PE containing one or more PCI devices +* @addr: PCI bus address to validate +* @mask: address mask (passed to firmware unchanged) +* +* RTAS IOA bus-error injection uses PCI bus addresses. Linux PCI resources
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 841
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-0+* are CPU/resource addresses and may differ on pseries due to PHB window +* translation. Convert each BAR resource to PCI bus address space before +* validating @addr. +* +* Zero addr and mask are accepted without BAR lookup (no-address injection). +* +* Return: 0 if valid, -EINVAL on invalid input. +*/ +static int validate_addr_mask_in_pe (struct eeh_pe *pe,unsigned long addr, +unsigned long mask)
[Severity: Low]
Does defining pseries_eeh_type_to_rtas() and validate_addr_mask_in_pe() in arch/powerpc/platforms/pseries/eeh_pseries.c without callers or __maybe_unused cause a -Werror=unused-function build failure at this commit?
The commit message notes that validate_errinjct_args() and prepare_errinjct_buffer() were deferred to the next patch ("powerpc/pseries/eeh:
Implement RTAS-based EEH error injection") and that pseries_eeh_err_inject() retains its existing MMIO body here so each intermediate commit builds cleanly with CONFIG_WERROR:
arch/powerpc/platforms/pseries/eeh_pseries.c:pseries_eeh_err_inject() {
struct eeh_dev *pdev;
/* Check on PCI error type */
if (type != EEH_ERR_TYPE_32 && type != EEH_ERR_TYPE_64)
return -EINVAL;
...
}However, those deferred functions and the updated pseries_eeh_err_inject() are the only callers of pseries_eeh_type_to_rtas() and validate_addr_mask_in_pe(). When building with CONFIG_PPC_PSERIES=y and CONFIG_PPC_WERROR=y (in arch/powerpc/Kbuild) or CONFIG_WERROR=y (in scripts/Makefile.warn), won't this commit fail to compile with -Werror=unused-function until the follow-up patch adds their callers?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v6 2/5] powerpc/pseries/eeh: Add RTAS error injection helpers
Quoted 97 lines · On 23/10/26 1:19 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] powerpc/pseries/eeh: static RTAS helpers defined without callers
--commit
8b171281b038661dc89a614c1b95db68271706f4
Author: Narayana Murty N <[email protected]>powerpc/pseries/eeh: Add RTAS error injection helpers
This patch adds static RTAS error injection helper functions,
pseries_eeh_type_to_rtas()andvalidate_addr_mask_in_pe(), to prepare the pSeries EEH backend for RTAS-based error injection.Quoted 4 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +0
-0[ ... ]
Quoted 44 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +40
-0@@ -786,6 +789,137 @@ static int pseries_notify_resume(struct eeh_dev *edev) }#endif +/* +* RTAS firmware error-type encodings (PAPR). These are pseries-private; +* user-space sees only the generic EEH_ERR_TYPE_* values from eeh.h. +* Only IOA bus-error types are supported; other PAPR encodings are not +* reachable through the generic EEH_ERR_TYPE_* UAPI. +*/ +#define RTAS_ERR_TYPE_IOA_BUS_ERROR 0x07 +#define RTAS_ERR_TYPE_IOA_BUS_ERROR_64 0x0f + +/* Size of the ibm,errinjct work buffer as defined by PAPR */ +#define RTAS_ERRINJCT_BUF_SIZE SZ_1K + +/** +* pseries_eeh_type_to_rtas - Map generic EEH error type to RTAS encoding +* @type: generic EEH error type (EEH_ERR_TYPE_32, EEH_ERR_TYPE_64) +* +* Translates the generic VFIO/EEH error type passed from userspace into +* the RTAS-specific ibm,errinjct error type encoding defined by PAPR. +* +* Return: RTAS error type on success, -EINVAL for unknown types. +*/ +static int pseries_eeh_type_to_rtas (int type) +{ +switch (type) { +case EEH_ERR_TYPE_32 : +return RTAS_ERR_TYPE_IOA_BUS_ERROR ; +case EEH_ERR_TYPE_64 : +return RTAS_ERR_TYPE_IOA_BUS_ERROR_64 ; +default : +return -EINVAL ; + } +} + +/** +* validate_addr_mask_in_pe - Validate addr against PCI bus BAR addresses in PE +* @pe: EEH PE containing one or more PCI devices +* @addr: PCI bus address to validate +* @mask: address mask (passed to firmware unchanged) +* +* RTAS IOA bus-error injection uses PCI bus addresses. Linux PCI resources arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 841
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-0+* are CPU/resource addresses and may differ on pseries due to PHB window +* translation. Convert each BAR resource to PCI bus address space before +* validating @addr. +* +* Zero addr and mask are accepted without BAR lookup (no-address injection). +* +* Return: 0 if valid, -EINVAL on invalid input. +*/ +static int validate_addr_mask_in_pe (struct eeh_pe *pe,unsigned long addr, +unsigned long mask)[Severity: Low]
Does definingpseries_eeh_type_to_rtas()andvalidate_addr_mask_in_pe()inarch/powerpc/platforms/pseries/eeh_pseries.cwithout callers or__maybe_unusedcause a -Werror=unused-function build failure at this commit?The commit message notes that
validate_errinjct_args()andprepare_errinjct_buffer()were deferred to the next patch ("powerpc/pseries/eeh:
Implement RTAS-based EEH error injection") and thatpseries_eeh_err_inject()retains its existing MMIO body here so each intermediate commit builds cleanly withCONFIG_WERROR:arch/powerpc/platforms/pseries/eeh_pseries.c:pseries_eeh_err_inject() { struct eeh_dev *pdev; /* Check on PCI error type */ if (type != EEH_ERR_TYPE_32 && type != EEH_ERR_TYPE_64) return -EINVAL; ... }
Quoted 6 lines
However, those deferred functions and the updated
pseries_eeh_err_inject()are the only callers ofpseries_eeh_type_to_rtas()andvalidate_addr_mask_in_pe(). When building withCONFIG_PPC_PSERIES=yandCONFIG_PPC_WERROR=y(inarch/powerpc/Kbuild) orCONFIG_WERROR=y(inscripts/Makefile.warn), won't this commit fail to compile with -Werror=unused-function until the follow-up patch adds their callers?
Yes, good catch.
Although validate_errinjct_args() and prepare_errinjct_buffer() were moved to the implementation patch, the remaining two static helpers are still introduced before their first callers.
I'll merge patches 2/5 and 3/5 in the next revision so that all helpers are introduced alongside their callers, avoiding the unused-function warnings in the intermediate commit.
Regards,
Narayana Murty.
Quoted 1 line
Re: [PATCH v6 2/5] powerpc/pseries/eeh: Add RTAS error injection helpers
In reply to Narayana Murty NHello Narayana,
The commit message contains several implementation details that make it difficult to understand the actual purpose of this patch. Could you simplify and restructure it to focus on the functionality being introduced and why it is needed?
Quoted 8 lines · Narayana Murty N
Prepare the pSeries EEH backend for RTAS error injection by adding helpers that:
* map generic EEH error types to RTAS/PAPR error types;
* validate IOA addresses against the target PE.Define
pr_fmtunconditionally at the top ofeeh_pseries.cso all pr_*() calls carry the "EEH: " prefix.
I don't think there's a need to mention pr_fmt here, as it's not a key objective of the patch. This could simply be a note at the end.
Quoted 8 lines
Define RTAS firmware error-type encodings as file-local constants. Only the two IOA bus-error types are supported; other PAPR encodings are not reachable through the generic EEH_ERR_TYPE_* UAPI:
RTAS_ERR_TYPE_IOA_BUS_ERROR 0x07 RTAS_ERR_TYPE_IOA_BUS_ERROR_64 0x0fAdd
RTAS_ERRINJCT_BUF_SIZEfor the ibm,errinjct work buffer size.
I'm not sure RTAS_ERRINJCT_BUF_SIZE needs to be included in this patch, as it seems unrelated and isn't used by any of the APIs introduced here. Would it make more sense to move this to the patch where it is actually used?
Quoted 26 lines
Add
pseries_eeh_type_to_rtas()to translate the two generic EEH error types (EEH_ERR_TYPE_32,EEH_ERR_TYPE_64) into the corresponding RTAS ibm,errinjct encodings.Add
validate_addr_mask_in_pe()to verify that a caller-provided address falls within a BAR of some device in the PE. RTAS IOA bus-error injection requires a PCI/IOA bus address;validate_addr_mask_in_pe()accepts only PCI bus addresses. VFIO userspace resource addresses are normalized to PCI bus addresses invfio_iommu_spapr_tce.cbefore reaching this backend; no resource-address fallback is added here.Use
pcibios_resource_to_bus()to convert each BAR resource to PCI bus address space before validating the address. Only standard BARs (BAR0..BAR5) are searched; ROM and bridge resources are not IOA bus-error targets. Holdpci_rescan_remove_lockwhile traversing PE devices and their BAR resources so PCI device removal cannot race the address validation.Skip unassigned or disabled BARs explicitly: on pseries,
pcibios_fixup_resources()zero-bases unassigned BARs (start=0, end=size-1) and setsIORESOURCE_UNSET, soresource_size()is non-zero for them andpcibios_resource_to_bus()treats them as bus address zero. Usepci_resource_len()(which returns 0 when end==0) instead ofresource_size(), and reject BARs withIORESOURCE_UNSETorIORESOURCE_DISABLEDset.
Quoted 1 line
Returns
-EINVAL(Linux errno) rather than a raw RTAS status.
This is another example where I'm having difficulty understanding how the above statement relates to the new APIs introduced by this patch.
Quoted 6 lines
validate_errinjct_args()andprepare_errinjct_buffer()are introduced in the next patch alongside their callers so each intermediate commit builds cleanly withCONFIG_WERROR.
pseries_eeh_err_inject()retains the existing MMIO injection body unchanged in this patch.
Okay, but could you clarify how these are related to the APIs introduced in this patch?
Quoted 3 lines
It is replaced by the full RTAS session
implementation in the next patch. This keeps the patch bisectable:
each commit builds and functions correctly independently.
Could you help me understand the need to mention git bisect-ability here?
I'm also not sure why the above two paragraphs are needed. Why do we need to document the nuances of other APIs in this patch when they are introduce or modified in subsequent patches?
Quoted 3 lines
Aren't these tags intended for cases where the issue is fixed in a separate patch/commit, rather than in a revised version of the same patch? Do we really these tags?
Quoted 31 lines
Signed-off-by Narayana Murty N <[email protected]>--- arch/powerpc/platforms/pseries/eeh_pseries.c | 134 +++++++++++++++++++ 1 file changed, 134 insertions(+)arch/powerpc/platforms/pseries/eeh_pseries.c +4
-0@@ -12,6 +12,8 @@* Copyright Linas Vepstas 2005, 2006 */ +#define pr_fmt (fmt) "EEH: " fmt +#include <linux/atomic.h> #include <linux/delay.h> #include <linux/export.h> @@ -23,6 +25,7 @@#include <linux/rbtree.h> #include <linux/sched.h> #include <linux/seq_file.h> +#include <linux/sizes.h> #include <linux/spinlock.h> #include <linux/crash_dump.h> @@ -786,6 +789,137 @@ static int pseries_notify_resume(struct eeh_dev *edev) }#endif +/*
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 802
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-0+* RTAS firmware error-type encodings (PAPR). These are pseries-private; +* user-space sees only the generic EEH_ERR_TYPE_* values from eeh.h. +* Only IOA bus-error types are supported; other PAPR encodings are not +* reachable through the generic EEH_ERR_TYPE_* UAPI. +*/ +#define RTAS_ERR_TYPE_IOA_BUS_ERROR 0x07 +#define RTAS_ERR_TYPE_IOA_BUS_ERROR_64 0x0f + +/* Size of the ibm,errinjct work buffer as defined by PAPR */ +#define RTAS_ERRINJCT_BUF_SIZE SZ_1K
Wouldn't it be better to move this to the first patch where it is used?
Quoted 17 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +17
-0+ +/** +* pseries_eeh_type_to_rtas - Map generic EEH error type to RTAS encoding +* @type: generic EEH error type (EEH_ERR_TYPE_32, EEH_ERR_TYPE_64) +* +* Translates the generic VFIO/EEH error type passed from userspace into +* the RTAS-specific ibm,errinjct error type encoding defined by PAPR. +* +* Return: RTAS error type on success, -EINVAL for unknown types. +*/ +static int pseries_eeh_type_to_rtas (int type) +{ +switch (type) { +case EEH_ERR_TYPE_32 : +return RTAS_ERR_TYPE_IOA_BUS_ERROR ; +case EEH_ERR_TYPE_64 : +return RTAS_ERR_TYPE_IOA_BUS_ERROR_64 ;
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 829
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-0+default : +return -EINVAL ; + } +} + +/** +* validate_addr_mask_in_pe - Validate addr against PCI bus BAR addresses in PE +* @pe: EEH PE containing one or more PCI devices +* @addr: PCI bus address to validate +* @mask: address mask (passed to firmware unchanged)
Is the mask really necessary?
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 834
Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +5
-0+* +* RTAS IOA bus-error injection uses PCI bus addresses. Linux PCI resources +* are CPU/resource addresses and may differ on pseries due to PHB window +* translation. Convert each BAR resource to PCI bus address space before +* validating @addr.
The same comment is also present inside the function. Could we drop one to avoid duplication? I think keeping it inside the function would be better.
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 838
Quoted 4 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +4
-0+* +* Zero addr and mask are accepted without BAR lookup (no-address injection). +* +* Return: 0 if valid, -EINVAL on invalid input.
I think, -EINVAL otherwise. would be more accurate.
Quoted 17 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +17
-0+*/ +static int validate_addr_mask_in_pe (struct eeh_pe *pe,unsigned long addr, +unsigned long mask) +{ +struct pci_bus_region region; +struct eeh_dev *edev, *tmp; +struct pci_dev *pdev; +struct resource *res; +resource_size_t bus_start; +resource_size_t bus_len; +bool found = false; +int bar; + +if (!addr && !mask) +return 0 ; + +if (!pe)
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 865
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-0+return -EINVAL ; + +/* +* RTAS IOA bus-error injection uses PCI bus addresses. Linux PCI +* resources are CPU/resource addresses and may differ on pseries due +* to PHB window translation. Convert each BAR resource to PCI bus +* address space before validating @addr. +* +* Hold pci_rescan_remove_lock across the traversal to protect pdev +* lifetime: pci_stop_and_remove_bus_device() requires this lock.
Wouldn't it be more meaningful to explain why this lock is needed here rather than listing other APIs that use it?
Quoted 21 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +21
-0+*/ +pci_lock_rescan_remove (); +eeh_pe_for_each_dev (pe, edev, tmp) { + pdev =eeh_dev_to_pci_dev (edev); +if (!pdev) +continue ; + +/* +* Validate against standard BARs (BAR0..BAR5) only. +* ROM and bridge resources are not IOA bus-error targets. +*/ +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { + res = &pdev->resource[bar]; + +/* +* Skip unassigned or disabled BARs. On pseries, +* pcibios_fixup_resources() zero-bases unassigned BARs +* (start=0, end=size-1) and sets IORESOURCE_UNSET. +* resource_size() is non-zero for such BARs, and +* pcibios_resource_to_bus() treats them as bus address +* zero, so they must be excluded explicitly.
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 896
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-0+* Use pci_resource_len() which returns 0 when end==0. +*/ +if (!pci_resource_len (pdev, bar)) +continue ; + +if (!(res->flags & (IORESOURCE_MEM |IORESOURCE_IO ))) +continue ; + +if (res->flags & (IORESOURCE_UNSET |IORESOURCE_DISABLED )) +continue ;
Nit: Would it be better to check the above conditions before calling pci_resource_len()?
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 901
Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +5
-0+ +pcibios_resource_to_bus (pdev->bus, ®ion, res); + + bus_start = region.start; + bus_len =pci_resource_len (pdev, bar);
How the bus_len returned by pci_resource_len(...) is different from? bus_len = region.end - region.start + 1;
Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +9
-0+ +if ((resource_size_t )addr >= bus_start && + ((resource_size_t )addr - bus_start) < bus_len) { +pr_debug ("addr=0x%lx mask=0x%lx validated in PCI bus BAR[%d] of %s: bus range 0x%llx-0x%llx\n" , + addr, mask, bar,pci_name (pdev), + (unsigned long long )region.start, + (unsigned long long )region.end); + found = true; + goto done;
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 920
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-0+ } + } + } +done: +pci_unlock_rescan_remove (); + +if (!found) +pr_err ("addr=0x%lx mask=0x%lx not within any PCI bus BAR of any device in PE\n" , + addr, mask); +return found ?0 : -EINVAL ;
This check is repeated twice here. I think we can improve this. How about restructuring the function as follows:
static bool addr_in_pdev_bars(pdev, addr)
{
for (bar = 0; bar < 6; bar++) {
len = pci_resource_len(pdev, bar);
if (!len || !is_mem_or_io(res) || is_unset_or_disabled(res)) continue;
pcibios_resource_to_bus(pdev->bus, ®ion, res); if (addr >= region.start && addr - region.start < len) return true;
}
return false;
}
static int validate_addr_mask_in_pe(pe, addr, mask) {
if (!addr && !mask)
return 0;
if (!pe)
return -EINVAL;
pci_lock_rescan_remove(); for_each_dev(pe, pdev) {
if (pdev && addr_in_pdev_bars(pdev, addr)) { pci_unlock_rescan_remove(); return 0;
}
}
pci_unlock_rescan_remove();
pr_err("addr not in any BAR of PE\n");
return -EINVAL;
}
Splitting out the BAR check gets rid of the goto and the found flag. The lock and unlock now sit around one simple loop.
- Sourabh Jain
Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-0+} +/** * pseries_eeh_err_inject - Inject specified error to the indicated PE * @pe: the indicated PE
Re: [PATCH v6 2/5] powerpc/pseries/eeh: Add RTAS error injection helpers
Hi Sourabh,
Quoted 6 lines · Sourabh Jain
Hello Narayana,
The commit message contains several implementation details that make it difficult to understand the actual purpose of this patch. Could you simplify and restructure it to focus on the functionality being introduced and why it is needed?
Sure. I'll merge this patch with 3/5 and rework the commit message. This will also address the unused static functions reported by Sashiko.
Quoted 13 lines · Narayana Murty N
Quoted 8 lines
Prepare the pSeries EEH backend for RTAS error injection by adding helpers that:
* map generic EEH error types to RTAS/PAPR error types;
* validate IOA addresses against the target PE.Define
pr_fmtunconditionally at the top ofeeh_pseries.cso all pr_*() calls carry the "EEH: " prefix.I don't think there's a need to mention
pr_fmthere, as it's not a key objective of the patch. This could simply be a note at the end.
Agreed. I'll drop this from the commit message.
Quoted 4 lines
Quoted 4 lines
Define RTAS firmware error-type encodings as file-local constants. Only the two IOA bus-error types are supported; other PAPR encodings are not reachable through the generic EEH_ERR_TYPE_* UAPI:
Quoted 9 lines
Quoted 4 lines
RTAS_ERR_TYPE_IOA_BUS_ERROR
0x07
RTAS_ERR_TYPE_IOA_BUS_ERROR_640x0fAdd
RTAS_ERRINJCT_BUF_SIZEfor the ibm,errinjct work buffer size.I'm not sure
RTAS_ERRINJCT_BUF_SIZEneeds to be included in this patch, as it seems unrelated and isn't used by any of the APIs introduced here. Would it make more sense to move this to the patch where it is actually used?
Yes, this will be addressed by merging the two patches.
Quoted 26 lines
Quoted 26 lines
Add
pseries_eeh_type_to_rtas()to translate the two generic EEH error types (EEH_ERR_TYPE_32,EEH_ERR_TYPE_64) into the corresponding RTAS ibm,errinjct encodings.Add
validate_addr_mask_in_pe()to verify that a caller-provided address falls within a BAR of some device in the PE. RTAS IOA bus-error injection requires a PCI/IOA bus address;validate_addr_mask_in_pe()accepts only PCI bus addresses. VFIO userspace resource addresses are normalized to PCI bus addresses invfio_iommu_spapr_tce.cbefore reaching this backend; no resource-address fallback is added here.Use
pcibios_resource_to_bus()to convert each BAR resource to PCI bus address space before validating the address. Only standard BARs (BAR0..BAR5) are searched; ROM and bridge resources are not IOA bus-error targets. Holdpci_rescan_remove_lockwhile traversing PE devices and their BAR resources so PCI device removal cannot race the address validation.Skip unassigned or disabled BARs explicitly: on pseries,
pcibios_fixup_resources()zero-bases unassigned BARs (start=0, end=size-1) and setsIORESOURCE_UNSET, soresource_size()is non-zero for them andpcibios_resource_to_bus()treats them as bus address zero. Usepci_resource_len()(which returns 0 when end==0) instead ofresource_size(), and reject BARs withIORESOURCE_UNSETorIORESOURCE_DISABLEDset.
Quoted 5 lines
Quoted 1 line
Returns
-EINVAL(Linux errno) rather than a raw RTAS status.This is another example where I'm having difficulty understanding how the above statement relates to the new APIs introduced by this patch.
Agreed. This detail is unnecessary here. >> validate_errinjct_args() and prepare_errinjct_buffer() are introduced
Quoted 13 lines
Quoted 5 lines
in the next patch alongside their callers so each intermediate commit builds cleanly with
CONFIG_WERROR.
pseries_eeh_err_inject()retains the existing MMIO injection body unchanged in this patch.Okay, but could you clarify how these are related to the APIs introduced in this patch?
Quoted 3 lines
It is replaced by the full RTAS session
implementation in the next patch. This keeps the patch bisectable:
each commit builds and functions correctly independently.
Quoted 6 lines
Could you help me understand the need to mention git bisect-ability here?
I'm also not sure why the above two paragraphs are needed. Why do we need to document the nuances of other APIs in this patch when they are introduce or modified in subsequent patches?
The intention was to introduce the helpers without breaking intermediate builds. However, the current split still leaves unused static functions. I'll merge the patches and drop these explanations.
Quoted 8 lines
Quoted 3 lines
Aren't these tags intended for cases where the issue is fixed in a separate patch/commit, rather than in a revised version of the same patch? Do we really these tags?
Agreed. I'll drop these tags and retain the details in the changelog.
Quoted 35 lines
Quoted 35 lines
Signed-off-by Narayana Murty N <[email protected]>---
arch/powerpc/platforms/pseries/eeh_pseries.c| 134 +++++++++++++++++++1 file changed, 134 insertions(+)arch/powerpc/platforms/pseries/eeh_pseries.c +8
-0@@ -12,6 +12,8 @@* Copyright Linas Vepstas 2005, 2006 */ +#define pr_fmt (fmt) "EEH: " fmt + #include <linux/atomic.h> #include <linux/delay.h> #include <linux/export.h>@@ -23,6 +25,7 @@ #include <linux/rbtree.h> #include <linux/sched.h> #include <linux/seq_file.h> +#include <linux/sizes.h> #include <linux/spinlock.h> #include <linux/crash_dump.h>@@ -786,6 +789,137 @@ static int pseries_notify_resume(struct eeh_dev *edev) } #endif +/* +* RTAS firmware error-type encodings (PAPR). These are pseries- private; +* user-space sees only the generic EEH_ERR_TYPE_* values from eeh.h. +* Only IOA bus-error types are supported; other PAPR encodings are not +* reachable through the generic EEH_ERR_TYPE_* UAPI.
Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 802
Quoted 6 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +6
-0+*/ +#define RTAS_ERR_TYPE_IOA_BUS_ERROR 0x07 +#define RTAS_ERR_TYPE_IOA_BUS_ERROR_64 0x0f + +/* Size of the ibm,errinjct work buffer as defined by PAPR */ +#define RTAS_ERRINJCT_BUF_SIZE SZ_1KWouldn't it be better to move this to the first patch where it is used?
Yes. Addressed by merging 2/5 and 3/5.
Quoted 23 lines
Quoted 23 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +3
-0+ +/** +* pseries_eeh_type_to_rtas - Map generic EEH error type to RTAS encoding
+ * @type: generic EEH error type (EEH_ERR_TYPE_32,EEH_ERR_TYPE_64)
+ *
+ * Translates the generic VFIO/EEH error type passed from userspace into
+ * the RTAS-specific ibm,errinjct error type encoding defined by PAPR.
+ *
+ * Return: RTAS error type on success,-EINVALfor unknown types.
+ */arch/powerpc/platforms/pseries/eeh_pseries.c +12
-0+static int pseries_eeh_type_to_rtas (int type) +{ + switch (type) { + case EEH_ERR_TYPE_32: + return RTAS_ERR_TYPE_IOA_BUS_ERROR; + case EEH_ERR_TYPE_64: + return RTAS_ERR_TYPE_IOA_BUS_ERROR_64; + default: + return -EINVAL; + } +} +
Quoted 9 lines
Quoted 6 lines
+/**
+ *validate_addr_mask_in_pe- Validate addr against PCI bus BAR addresses in PE
+ * @pe: EEH PE containing one or more PCI devices
+ * @addr: PCI bus address to validate
+ * @mask: address mask (passed to firmware unchanged)Is the mask really necessary?
No. It is only used to identify the no-address injection case where both addr and mask are zero. I'll move that check to the caller and remove the mask argument from this helper.
Quoted 10 lines
Quoted 9 lines
+ *
+ * RTAS IOA bus-error injection uses PCI bus addresses. Linux PCI resources
+ * are CPU/resource addresses and may differ on pseries due to PHB window
+ * translation. Convert each BAR resource to PCI bus address space before
+ * validating @addr.
Quoted 4 lines
The same comment is also present inside the function. Could we drop one to avoid duplication? I think keeping it inside the function would be better.
Sure.
Quoted 8 lines
Quoted 5 lines
+ *
+ * Zero addr and mask are accepted without BAR lookup (no-address injection).
+ *
+ * Return: 0 if valid,-EINVALon invalid input.I think,
-EINVALotherwise. would be more accurate.
Agreed.
Quoted 24 lines
Quoted 24 lines
+ */
+static int validate_addr_mask_in_pe(structeeh_pe*pe, unsigned long addr,
+ unsigned long mask)arch/powerpc/platforms/pseries/eeh_pseries.c +19
-0+{ + struct pci_bus_region region; + struct eeh_dev *edev, *tmp; + struct pci_dev *pdev; + struct resource *res; + resource_size_t bus_start; + resource_size_t bus_len; + bool found = false; + int bar; + + if (!addr && !mask) + return 0; + + if (!pe) + return -EINVAL; + + /* +* RTAS IOA bus-error injection uses PCI bus addresses. Linux PCI +* resources are CPU/resource addresses and may differ on pseries due
Quoted 9 lines
Quoted 5 lines
+ * to PHB window translation. Convert each BAR resource to PCI bus + * address space before validating @addr.
+ *
+ * Holdpci_rescan_remove_lockacross the traversal to protect pdev + * lifetime:pci_stop_and_remove_bus_device()requires this lock.Wouldn't it be more meaningful to explain why this lock is needed here rather than listing other APIs that use it?
Agreed. The lock is intended to protect the traversal against concurrent PCI device removal. I'll simplify the comment.
Quoted 25 lines
Quoted 25 lines
+ */
+pci_lock_rescan_remove();
+eeh_pe_for_each_dev(pe, edev, tmp){
+ pdev =eeh_dev_to_pci_dev(edev);
+ if (!pdev)
+ continue;arch/powerpc/platforms/pseries/eeh_pseries.c +19
-0+ + /* + * Validate against standard BARs (BAR0..BAR5) only. + * ROM and bridge resources are not IOA bus-error targets. + */ + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { + res = &pdev->resource[bar]; + + /* + * Skip unassigned or disabled BARs. On pseries, + * pcibios_fixup_resources() zero-bases unassigned BARs + * (start=0, end=size-1) and sets IORESOURCE_UNSET. + * resource_size() is non-zero for such BARs, and + * pcibios_resource_to_bus() treats them as bus address + * zero, so they must be excluded explicitly. + * Use pci_resource_len() which returns 0 when end==0. + */ + if (!pci_resource_len(pdev, bar)) + continue;
Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 896
Quoted 6 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +6
-0+ + if (!(res->flags & (IORESOURCE_MEM | IORESOURCE_IO))) + continue; + + if (res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) + continue;Nit: Would it be better to check the above conditions before calling
pci_resource_len()?
Sure. I'll check the resource flags first.
Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_notify_resume(struct eeh_dev *edev) · line 901
Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +5
-0+ + pcibios_resource_to_bus(pdev->bus, ®ion, res); + + bus_start = region.start; + bus_len = pci_resource_len(pdev, bar);How the
bus_lenreturned bypci_resource_len(...)is different from?bus_len= region.end - region.start + 1;
There is no difference for a valid BAR, as the translation preserves the resource size. I'll avoid the redundant calculation.
Quoted 56 lines
Quoted 18 lines
+
+ if ((resource_size_t)addr >=bus_start&&
+ ((resource_size_t)addr -bus_start) <bus_len) { + pr_debug("addr=0x%lx mask=0x%lx validated in PCI bus BAR[%d] of %s: bus range 0x%llx-0x%llx\n",
+ addr, mask, bar,pci_name(pdev),
+ (unsigned long long)region.start,
+ (unsigned long long)region.end);
+ found = true;
+ goto done;
+ }
+ }
+ }arch/powerpc/platforms/pseries/eeh_pseries.c +5
-0+done: + pci_unlock_rescan_remove(); + + if (!found) + pr_err("addr=0x%lx mask=0x%lx not within any PCI bus BAR ofQuoted 3 lines
any device in PE\n",
+ addr, mask);
+ return found ? 0 :-EINVAL;This check is repeated twice here. I think we can improve this. How about restructuring the function as follows:
static bool
addr_in_pdev_bars(pdev, addr)
{
for (bar = 0; bar < 6; bar++) {
len =pci_resource_len(pdev, bar);
if (!len || !is_mem_or_io(res) ||is_unset_or_disabled(res)) continue;
pcibios_resource_to_bus(pdev->bus, ®ion, res); if (addr >= region.start && addr - region.start < len) return true;
}
return false;
}static int
validate_addr_mask_in_pe(pe, addr, mask){
if (!addr && !mask)
return 0;
if (!pe)
return-EINVAL;
pci_lock_rescan_remove();for_each_dev(pe, pdev){
if (pdev &&addr_in_pdev_bars(pdev, addr)) {pci_unlock_rescan_remove(); return 0;
}
}
pci_unlock_rescan_remove();
Quoted 8 lines
pr_err("addr not in any BAR of PE\n");
return-EINVAL;
}Splitting out the BAR check gets rid of the goto and the found flag. The lock and unlock now sit around one simple loop.
Agreed. I'll split the per-device BAR lookup from the PE traversal as suggested, with the no-address check moved to the caller.
Quoted 7 lines
- Sourabh Jain
Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-0+} +/**
*pseries_eeh_err_inject- Inject specified error to the indicated PE
* @pe: the indicated PE
Thnks,
Narayana Murty.
Quoted 1 line
PATCH v6 3/5 powerpc/pseries/eeh: Implement RTAS-based EEH error injection
In reply to Narayana Murty NReplace 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 eeh_pe_inject_mmio_error() and its declaration; this patch removes its only caller. The only remaining caller of eeh_break_device() is eeh_dev_break_write() inside CONFIG_DEBUG_FS, so move eeh_break_device() back inside the CONFIG_DEBUG_FS block to avoid an unused-function warning when CONFIG_DEBUG_FS=n.
Also introduce validate_errinjct_args() and prepare_errinjct_buffer() here alongside their callers, so each intermediate commit builds cleanly with CONFIG_WERROR.
The addr argument to ibm,errinjct is function-dependent. Memory and IO load/store functions (EEH_ERR_FUNC_LD/ST_MEM_* and EEH_ERR_FUNC_LD/ST_IO_*) target BAR-backed PCI bus addresses; these are validated against the PE via validate_addr_mask_in_pe(). Config-space functions carry PCI config register offsets and DMA functions carry IOVA/TCE addresses; addr for these functions is passed directly to RTAS without BAR membership validation.
For the 32-bit RTAS encoding (RTAS_ERR_TYPE_IOA_BUS_ERROR), addr and mask are checked to fit in 32 bits before buffer encoding. This is an RTAS format constraint independent of function type.
Tested with corresponding QEMU patches:
https://lore.kernel.org/all/[email protected]/
--- arch/powerpc/include/asm/eeh.h | 2 - arch/powerpc/kernel/eeh.c | 10 +- arch/powerpc/platforms/pseries/eeh_pseries.c | 246 +++++++++++++++++-- 3 files changed, 228 insertions(+), 30 deletions(-)
arch/powerpc/include/asm/eeh.h +0 -2
@@ -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. *
arch/powerpc/kernel/eeh.c +2 -8
@@ -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 +226 -20
280 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v6 3/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection
Similar to 2/5, I'm finding this commit message a bit difficult to follow. Could you please rework it to make the changes and their purpose clearer?
Quoted 6 lines · Narayana Murty N
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_mutexbecause RTAS maintains state between these calls.
I don't quite understand this point. What RTAS state are we referring to here? Also, could you clarify how keeping all three calls under a lock helps maintain the RTAS state mentioned above?
Quoted 5 lines
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.
RTAS work area is mentioned here, but the next paragraph discusses something else. The details about the RTAS work area only appear in a later paragraph. I think the flow could be improved by keeping related information together.
Quoted 18 lines
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_32andEEH_ERR_TYPE_64are unchanged; their values are defined inarch/powerpc/include/uapi/asm/eeh.hand 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 mostRTAS_INSTANTIATE_MAX= 1 GiB), so the physical address fits in the 32-bit RTAS argument without truncation.Remove
eeh_pe_inject_mmio_error()and its declaration; this patch removes its only caller. The only remaining caller ofeeh_break_device()iseeh_dev_break_write()insideCONFIG_DEBUG_FS, so moveeeh_break_device()back inside theCONFIG_DEBUG_FSblock to avoid an unused-function warning whenCONFIG_DEBUG_FS=n.
Quoted 3 lines
Also introduce
validate_errinjct_args()andprepare_errinjct_buffer()here alongside their callers, so each intermediate commit builds cleanly withCONFIG_WERROR.
Could you clarify what this intermediate commit is for?
Quoted 8 lines
The addr argument to ibm,errinjct is function-dependent. Memory and IO load/store functions (EEH_ERR_FUNC_LD/ST_MEM_* and EEH_ERR_FUNC_LD/ST_IO_*) target BAR-backed PCI bus addresses; these are validated against the PE via
validate_addr_mask_in_pe(). Config-space functions carry PCI config register offsets and DMA functions carry IOVA/TCE addresses; addr for these functions is passed directly to RTAS without BAR membership validation.
Quoted 6 lines
For the 32-bit RTAS encoding (
RTAS_ERR_TYPE_IOA_BUS_ERROR), addr and mask are checked to fit in 32 bits before buffer encoding. This is an RTAS format constraint independent of function type.Tested with corresponding QEMU patches:
https://lore.kernel.org/all/[email protected]/
Wouldn't this be better suited for the cover letter?
Quoted 25 lines
Signed-off-by Narayana Murty N <[email protected]>--- arch/powerpc/include/asm/eeh.h | 2 - arch/powerpc/kernel/eeh.c | 10 +- arch/powerpc/platforms/pseries/eeh_pseries.c | 246 +++++++++++++++++-- 3 files changed, 228 insertions(+), 30 deletions(-)arch/powerpc/include/asm/eeh.h +0
-2@@ -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. * arch/powerpc/kernel/eeh.c +0
-0
[...]
Quoted 28 lines
arch/powerpc/kernel/eeh.c +2
-8@@ -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 +0
-0
[...]
Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +1
-0@@ -35,6 +35,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;
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 920
Quoted 7 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-2@@ -915,48 +916,253 @@ static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr,pci_unlock_rescan_remove ();if (!found) -pr_err ("addr=0x%lx mask=0x%lx not within any PCI bus BAR of any device in PE\n" , - addr, mask); +pr_debug ("addr=0x%lx mask=0x%lx not within any PCI bus BAR of any device in PE\n" , + addr, mask);
IIUC, the previous patch adds pr_err(), and this patch changes it to pr_debug(). Could we avoid this intermediate change?
Quoted 8 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +0
-4return found ?0 : -EINVAL ; }/** -* pseries_eeh_err_inject - Inject specified error to the indicated PE -* @pe: the indicated PE -* @type: error type -* @func: specific error type
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 930
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +6
-4-* @addr: address -* @mask: address mask -* The routine is called to inject specified error, which is -* determined by @type and @func, to the indicated PE +* validate_errinjct_args - Top-level validation for RTAS error injection arguments +* @pe: EEH PE for the target device +* @type: generic EEH error type +* @func: error function selector +* @addr: address argument (type-dependent, may be zero) +* @mask: mask argument (type-dependent, may be zero)
Are addr and mask really needed as function arguments?
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 933
Quoted 3 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +3
-0+* +* Validates all parameters before opening an RTAS injection session. +* Returns Linux errno values; does not return raw RTAS status codes.
Wouldn't it be better for the function comment to describe what the function does, rather than how an RTAS injection session should be opened?
Quoted 20 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-4+* +* Return: 0 if all parameters are valid, negative errno otherwise. */ -static int pseries_eeh_err_inject (struct eeh_pe *pe,int type,int func, +static int validate_errinjct_args (struct eeh_pe *pe,int type,int func,unsigned long addr,unsigned long mask) { -struct eeh_dev *pdev; +if (!pe || !pe->phb) +return -EINVAL ; + +if (pseries_eeh_type_to_rtas (type) <0 ) +return -EINVAL ; -/* Check on PCI error type */ -if (type !=EEH_ERR_TYPE_32 && type !=EEH_ERR_TYPE_64 ) +if (func <EEH_ERR_FUNC_MIN || func >EEH_ERR_FUNC_MAX )return -EINVAL ; +return 0 ;
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 959
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-0+} + +/* +* pseries_eeh_func_needs_bar_addr - return true for error functions whose +* addr argument is a BAR-backed PCI MMIO or IO address. +* +* Memory and IO load/store functions target specific BAR addresses and +* require PCI bus address validation against the PE. Config-space +* functions carry PCI config register offsets and DMA functions carry +* IOVA/TCE addresses; neither is a BAR address.
This seems like useful information, but perhaps it belongs elsewhere. The function itself looks fairly simple, and the comment conveys quite a bit of information that I’m not sure how to relate to what the function actually does.
Quoted 34 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +24
-5+*/ +static bool pseries_eeh_func_needs_bar_addr (int func) +{switch (func) {case EEH_ERR_FUNC_LD_MEM_ADDR :case EEH_ERR_FUNC_LD_MEM_DATA : +case EEH_ERR_FUNC_LD_IO_ADDR : +case EEH_ERR_FUNC_LD_IO_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 (); +case EEH_ERR_FUNC_ST_IO_ADDR : +case EEH_ERR_FUNC_ST_IO_DATA : +return true; +default : +return false; + } +} + +/** +* prepare_errinjct_buffer() - Build ibm,errinjct work buffer +* @buf: RTAS error-injection work buffer +* @pe: EEH PE associated with the injection target +* @rtas_err_type: RTAS firmware error-injection type +* @func: Error function selector +* @addr: Address argument interpreted according to @func: +* MEM/IO functions: BAR-backed PCI bus address; +* CFG functions: PCI configuration-space offset; +* DMA functions: DMA/IOVA/TCE address. +* @mask: Address mask passed to firmware
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 998
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-0+* +* Zeroes @buf and populates it according to the PAPR layout for the +* selected IOA bus-error injection type. +* +* BAR membership validation is performed only for MEM/IO functions +* whose @addr is a BAR-backed PCI bus address. CFG and DMA function +* addresses are encoded directly without BAR lookup. +* +* The caller provides an exclusive per-call RTAS work-area buffer. +* Firmware session serialization is handled by pseries_eeh_err_inject().
Wouldn't this be better documented elsewhere? This function only populates the given work area; it doesn't make the RTAS call.
Quoted 25 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +25
-0+* +* Return: 0 on success or a negative errno on invalid input. +*/ +static int prepare_errinjct_buffer (void *buf,struct eeh_pe *pe, +int rtas_err_type,int func, +unsigned long addr,unsigned long mask) +{ +__be64 *buf64 = (__be64 *)buf; +__be32 *buf32 = (__be32 *)buf; +int rc; + +if (!buf || !pe || !pe->phb) +return -EINVAL ; + +memset (buf,0 ,RTAS_ERRINJCT_BUF_SIZE ); + +switch (rtas_err_type) { +case RTAS_ERR_TYPE_IOA_BUS_ERROR : +/* +* 32-bit RTAS format: addr and mask must fit in 32 bits. +* This is an RTAS encoding constraint, not BAR validation. +*/ +if (upper_32_bits (addr) ||upper_32_bits (mask)) +return -EINVAL ; +
[...]
Quoted 34 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +30
-1+if (pseries_eeh_func_needs_bar_addr (func)) { + rc =validate_addr_mask_in_pe (pe, addr, mask); +if (rc) +return rc; + } + + buf32[0 ] =cpu_to_be32 ((u32 )addr); + buf32[1 ] =cpu_to_be32 ((u32 )mask); + buf32[2 ] =cpu_to_be32 (pe->addr); + buf32[3 ] =cpu_to_be32 (BUID_HI (pe->phb->buid)); + buf32[4 ] =cpu_to_be32 (BUID_LO (pe->phb->buid)); + buf32[5 ] =cpu_to_be32 (func); +break ; + +case RTAS_ERR_TYPE_IOA_BUS_ERROR_64 : +if (pseries_eeh_func_needs_bar_addr (func)) { + rc =validate_addr_mask_in_pe (pe, addr, mask); +if (rc) +return rc; + } + + buf64[0 ] =cpu_to_be64 (addr); + buf64[1 ] =cpu_to_be64 (mask); + buf32[4 ] =cpu_to_be32 (pe->addr); + buf32[5 ] =cpu_to_be32 (BUID_HI (pe->phb->buid)); + buf32[6 ] =cpu_to_be32 (BUID_LO (pe->phb->buid)); + buf32[7 ] =cpu_to_be32 (func);break ; +default : -return -ERANGE ; +pr_err ("unsupported RTAS error injection type 0x%x\n" , rtas_err_type); +return -EINVAL ; }
[...]
Quoted 26 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +22
-0+pr_debug ("errinjct buffer ready: rtas_err_type=0x%x func=%d addr=0x%lx mask=0x%lx\n" , + rtas_err_type, func, addr, mask);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: 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.
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 1092
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-0+*/ +static int pseries_eeh_err_inject (struct eeh_pe *pe,int type,int func, +unsigned long addr,unsigned long mask) +{ +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;
The name rtas_err_type seems a bit confusing for the error injection class. Would err_injct_class or errinjct_class be clearer?
Quoted 11 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +11
-0+int close_rc; +int rc; + + rc =validate_errinjct_args (pe, type, func, addr, mask); +if (rc) +return rc; + + rtas_err_type =pseries_eeh_type_to_rtas (type); +if (rtas_err_type <0 ) +return -EINVAL ; +
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 1113
Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10
-0+ 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);
Is this lock really necessary?
- Sourabh Jain
Quoted 55 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +52
-0+ +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; + } + + 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 = { .name ="pseries" , .probe = pseries_eeh_probe,
Re: [PATCH v6 3/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection
Hi Sourah,
Quoted 4 lines · Sourabh Jain
Similar to 2/5, I'm finding this commit message a bit difficult to follow. Could you please rework it to make the changes and their purpose clearer?
Agreed. I'll merge 2/5 and 3/5 and rework the commit message.
Quoted 11 lines · Narayana Murty N
Quoted 6 lines
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_mutexbecause RTAS maintains state between these calls.I don't quite understand this point. What RTAS state are we referring to here? Also, could you clarify how keeping all three calls under a lock helps maintain the RTAS state mentioned above?
I was referring to the error injection session established by ibm,open-errinjct and identified by the returned session token.
The RTAS lock serializes individual RTAS calls, but not the complete open/inject/close sequence. The intention of errinjct_mutex is to prevent concurrent EEH injection requests from interleaving their sessions.
I'll recheck the PAPR session ownership requirements to determine whether this additional serialization is necessary.
Quoted 10 lines
Quoted 5 lines
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.
RTAS work area is mentioned here, but the next paragraph discusses something else. The details about the RTAS work area only appear in a later paragraph. I think the flow could be improved by keeping related information together.
Agreed. I'll keep the work-area allocation and lifetime details together in the revised commit message.
Quoted 19 lines
Quoted 19 lines
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_32andEEH_ERR_TYPE_64are unchanged; their values are defined inarch/powerpc/include/uapi/asm/eeh.hand 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 mostRTAS_INSTANTIATE_MAX= 1 GiB), so the physical address fits in the 32-bit RTAS argument without truncation.Remove
eeh_pe_inject_mmio_error()and its declaration; this patch removes its only caller. The only remaining caller ofeeh_break_device()iseeh_dev_break_write()insideCONFIG_DEBUG_FS, so moveeeh_break_device()back inside theCONFIG_DEBUG_FSblock to avoid an unused-function warning whenCONFIG_DEBUG_FS=n.
Quoted 6 lines
Quoted 3 lines
Also introduce
validate_errinjct_args()andprepare_errinjct_buffer()here alongside their callers, so each intermediate commit builds cleanly withCONFIG_WERROR.Could you clarify what this intermediate commit is for?
The intention was to separate the helper infrastructure from the RTAS implementation. However, given the unused static helpers and the additional complexity introduced by the split, I'll merge the two patches.
Quoted 9 lines
Quoted 9 lines
The addr argument to ibm,errinjct is function-dependent. Memory and IO load/store functions (EEH_ERR_FUNC_LD/ST_MEM_* and EEH_ERR_FUNC_LD/ ST_IO_*) target BAR-backed PCI bus addresses; these are validated against the PE via validate_addr_mask_in_pe(). Config-space functions carry PCI config register offsets and DMA functions carry IOVA/TCE addresses; addr for these functions is passed directly to RTAS without BAR membership validation.
Quoted 9 lines
Quoted 6 lines
For the 32-bit RTAS encoding (
RTAS_ERR_TYPE_IOA_BUS_ERROR), addr and mask are checked to fit in 32 bits before buffer encoding. This is an RTAS format constraint independent of function type.Tested with corresponding QEMU patches:
https://lore.kernel.org/all/20251029150618.186803-1- [email protected]/Wouldn't this be better suited for the cover letter?
Agreed. I'll move the reference to the corresponding QEMU series to the cover letter.
Quoted 68 lines
Quoted 27 lines
Signed-off-by Narayana Murty N <[email protected]>---
arch/powerpc/include/asm/eeh.h | 2 - arch/powerpc/kernel/eeh.c | 10 +-arch/powerpc/platforms/pseries/eeh_pseries.c| 246 +++++++++++++++++--3 files changed, 228 insertions(+), 30 deletions(-)arch/powerpc/include/asm/eeh.h +0
-2@@ -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. *
arch/powerpc/kernel/eeh.c +0
-0[...]
Quoted 27 lines
arch/powerpc/kernel/eeh.c +2
-8@@ -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 +0
-0[...]
Quoted 12 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +1
-1@@ -35,6 +35,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;@@ -915,48 +916,253 @@ static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, pci_unlock_rescan_remove(); if (!found) - pr_err("addr=0x%lx mask=0x%lx not within any PCI bus BAR of
Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct · line 922
Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-1any device in PE\n", - addr, mask); + pr_debug("addr=0x%lx mask=0x%lx not within any PCI bus BAR of any device in PE\n", + addr, mask);IIUC, the previous patch adds
pr_err(), and this patch changes it topr_debug(). Could we avoid this intermediate change?
Yes. I'll introduce pr_debug() directly in the merged patch.
Quoted 18 lines
Quoted 12 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +1
-8return found ? 0 : -EINVAL; } /** -* 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 +* validate_errinjct_args - Top-level validation for RTAS error Quoted 6 lines
injection arguments
+ * @pe: EEH PE for the target device
+ * @type: generic EEH error type
+ * @func: error function selector
+ * @addr: address argument (type-dependent, may be zero)
+ * @mask: mask argument (type-dependent, may be zero)
Quoted 2 lines
Are addr and mask really needed as function arguments?
No, they are not used by validate_errinjct_args(). I'll simplify the validation and avoid the duplicate error-type mapping.
Quoted 7 lines
Quoted 3 lines
+ *
+ * Validates all parameters before opening an RTAS injection session.
+ * Returns Linux errno values; does not return raw RTAS status codes.Wouldn't it be better for the function comment to describe what the function does, rather than how an RTAS injection session should be opened?
Agreed. I will shorten the comment.
Quoted 25 lines
Quoted 25 lines
+ *
+ * Return: 0 if all parameters are valid, negative errno otherwise. */arch/powerpc/platforms/pseries/eeh_pseries.c +1
-1-static int pseries_eeh_err_inject(struct eeh_pe *pe, int type, int func, +static int validate_errinjct_args(struct eeh_pe *pe, int type, int func,unsigned long addr, unsigned long mask) {
- struct eeh_dev *pdev;
+ if (!pe || !pe->phb)
+ return-EINVAL;
+
+ if (pseries_eeh_type_to_rtas(type)< 0)
+ return-EINVAL;
- /* Check on PCI error type */
- if (type !=EEH_ERR_TYPE_32&& type !=EEH_ERR_TYPE_64) + if (func <EEH_ERR_FUNC_MIN|| func >EEH_ERR_FUNC_MAX) return-EINVAL;
+ return 0;arch/powerpc/platforms/pseries/eeh_pseries.c +4
-0+} + +/* +* pseries_eeh_func_needs_bar_addr - return true for error functions whose
+ * addr argument is a BAR-backed PCI MMIO or IO address.
+ *
Quoted 9 lines
Quoted 4 lines
+ * Memory and IO load/store functions target specific BAR addresses and
+ * require PCI bus address validation against the PE. Config-space
+ * functions carry PCI config register offsets and DMA functions carry
+ * IOVA/TCE addresses; neither is a BAR address.This seems like useful information, but perhaps it belongs elsewhere. The function itself looks fairly simple, and the comment conveys quite a bit of information that I’m not sure how to relate to what the function actually does.
Agreed. I'll keep the helper comment focused.
Quoted 40 lines
Quoted 40 lines
+ */
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-0+static bool pseries_eeh_func_needs_bar_addr (int func) +{switch (func) {
caseEEH_ERR_FUNC_LD_MEM_ADDR:
caseEEH_ERR_FUNC_LD_MEM_DATA:
+ caseEEH_ERR_FUNC_LD_IO_ADDR:
+ caseEEH_ERR_FUNC_LD_IO_DATA:
caseEEH_ERR_FUNC_ST_MEM_ADDR:
caseEEH_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();
+ caseEEH_ERR_FUNC_ST_IO_ADDR:
+ caseEEH_ERR_FUNC_ST_IO_DATA:
+ return true;
+ default:
+ return false;
+ }arch/powerpc/platforms/pseries/eeh_pseries.c +18
-0+} + +/** +* prepare_errinjct_buffer() - Build ibm,errinjct work buffer +* @buf: RTAS error-injection work buffer +* @pe: EEH PE associated with the injection target +* @rtas_err_type: RTAS firmware error-injection type +* @func: Error function selector +* @addr: Address argument interpreted according to @func: +* MEM/IO functions: BAR-backed PCI bus address; +* CFG functions: PCI configuration-space offset; +* DMA functions: DMA/IOVA/TCE address. +* @mask: Address mask passed to firmware +* +* Zeroes @buf and populates it according to the PAPR layout for the +* selected IOA bus-error injection type. +* +* BAR membership validation is performed only for MEM/IO functions
Quoted 9 lines
Quoted 6 lines
+ * whose @addr is a BAR-backed PCI bus address. CFG and DMA function
+ * addresses are encoded directly without BAR lookup.
+ *
+ * The caller provides an exclusive per-call RTAS work-area buffer.
+ * Firmware session serialization is handled bypseries_eeh_err_inject().Wouldn't this be better documented elsewhere? This function only populates the given work area; it doesn't make the RTAS call.
Agreed. I'll keep the comment focused on encoding the RTAS parameter buffer and move the session-related details to the caller.
Quoted 92 lines
Quoted 25 lines
+ *
+ * Return: 0 on success or a negative errno on invalid input.
+ */arch/powerpc/platforms/pseries/eeh_pseries.c +22
-0+static int prepare_errinjct_buffer (void *buf,struct eeh_pe *pe, + int rtas_err_type, int func, + unsigned long addr, unsigned long mask) +{ + __be64 *buf64 = (__be64 *)buf; + __be32 *buf32 = (__be32 *)buf; + int rc; + + if (!buf || !pe || !pe->phb) + return -EINVAL; + + memset(buf, 0, RTAS_ERRINJCT_BUF_SIZE); + + switch (rtas_err_type) { + case RTAS_ERR_TYPE_IOA_BUS_ERROR: + /* + * 32-bit RTAS format: addr and mask must fit in 32 bits. + * This is an RTAS encoding constraint, not BAR validation. + */ + if (upper_32_bits(addr) || upper_32_bits(mask)) + return -EINVAL; +[...]
Quoted 35 lines
+ if (
pseries_eeh_func_needs_bar_addr(func)) { + rc =validate_addr_mask_in_pe(pe, addr, mask); + if (rc)
+ return rc;
+ }arch/powerpc/platforms/pseries/eeh_pseries.c +22
-0+ + buf32[0] = cpu_to_be32((u32)addr); + buf32[1] = cpu_to_be32((u32)mask); + buf32[2] = cpu_to_be32(pe->addr); + buf32[3] = cpu_to_be32(BUID_HI(pe->phb->buid)); + buf32[4] = cpu_to_be32(BUID_LO(pe->phb->buid)); + buf32[5] = cpu_to_be32(func); + break; + + case RTAS_ERR_TYPE_IOA_BUS_ERROR_64: + if (pseries_eeh_func_needs_bar_addr(func)) { + rc = validate_addr_mask_in_pe(pe, addr, mask); + if (rc) + return rc; + } + + buf64[0] = cpu_to_be64(addr); + buf64[1] = cpu_to_be64(mask); + buf32[4] = cpu_to_be32(pe->addr); + buf32[5] = cpu_to_be32(BUID_HI(pe->phb->buid)); + buf32[6] = cpu_to_be32(BUID_LO(pe->phb->buid)); + buf32[7] = cpu_to_be32(func);break;
+
default:
- return-ERANGE;
+pr_err("unsupported RTAS error injection type 0x%x\n", rtas_err_type);
+ return-EINVAL;
}[...]
Quoted 30 lines
+ pr_debug("errinjct buffer ready: rtas_err_type=0x%x func=%d addr=0x%lx mask=0x%lx\n",
+rtas_err_type, func, addr, mask);
return 0;
}arch/powerpc/platforms/pseries/eeh_pseries.c +25
-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: 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 rtas_work_area *area;
Quoted 9 lines
Quoted 5 lines
+
phys_addr_tarea_phys;
+ void *buf;
+ intopen_token,errinjct_token,close_token;
+ intsession_token;
+ intrtas_err_type;The name
rtas_err_typeseems a bit confusing for the error injection class. Woulderr_injct_classorerrinjct_classbe clearer?
Agreed. I'll use errinjct_class.
Quoted 14 lines
Quoted 14 lines
+ int
close_rc;
+ int rc;arch/powerpc/platforms/pseries/eeh_pseries.c +12
-0+ + rc = validate_errinjct_args(pe, type, func, addr, mask); + if (rc) + return rc; + + rtas_err_type = pseries_eeh_type_to_rtas(type); + if (rtas_err_type < 0) + return -EINVAL; + + 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);
Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 1113
Quoted 7 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +7
-0+ + if (open_token == RTAS_UNKNOWN_SERVICE || + errinjct_token == RTAS_UNKNOWN_SERVICE || + close_token == RTAS_UNKNOWN_SERVICE) + return -ENODEV; + + mutex_lock(&errinjct_mutex);Is this lock really necessary?
As mentioned above, the intention is to serialize complete error injection sessions initiated through the EEH backend rather than individual RTAS calls.
However, this mutex does not serialize direct userspace RTAS callers. I'll verify the firmware session ownership semantics before deciding whether to retain it.
Quoted 50 lines
- Sourabh Jain
Quoted 48 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +16
-0+ + 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; + } + + 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)
+ gotoout_free_area;arch/powerpc/platforms/pseries/eeh_pseries.c +29
-0+ + /* + * 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); + } +
Quoted 8 lines
Quoted 8 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +5
-0+out_unlock: + mutex_unlock(&errinjct_mutex); + return rc; +} +static struct
eeh_opspseries_eeh_ops= {
.name = "pseries",
.probe =pseries_eeh_probe,
Thanks,
Narayana Murty.
Quoted 1 line
Re: [PATCH v6 3/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection
Quoted 8 lines · Narayana Murty N
Hi Sourah,
Quoted 4 lines · Sourabh Jain
Similar to 2/5, I'm finding this commit message a bit difficult to follow. Could you please rework it to make the changes and their purpose clearer?
Agreed. I'll merge 2/5 and 3/5 and rework the commit message.
I didn't recommend merging 2/5 and 3/5.
Quoted 11 lines
Quoted 11 lines · Narayana Murty N
Quoted 6 lines
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_mutexbecause RTAS maintains state between these calls.I don't quite understand this point. What RTAS state are we referring to here? Also, could you clarify how keeping all three calls under a lock helps maintain the RTAS state mentioned above?
Quoted 7 lines
I was referring to the error injection session established by ibm,open-errinjct and identified by the returned session token.
The RTAS lock serializes individual RTAS calls, but not the complete open/inject/close sequence. The intention of
errinjct_mutexis to prevent concurrent EEH injection requests from interleaving their sessions.
Ok the intent is to synchronize multiple err_injection requests? So kernel would do open/inject/close together for 1 request and then move to another request do open/inject/close.....
Could you please help me understand what is wrong with concurrent EEH injection requests with an interleaved open/inject/close sequence?
Is this restriction coming from PAPR? If yes, please share the section no.
- Sourabh Jain
Quoted 464 lines
I'll recheck the PAPR session ownership requirements to determine whether this additional serialization is necessary.
Quoted 10 lines
Quoted 5 lines
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.
RTAS work area is mentioned here, but the next paragraph discusses something else. The details about the RTAS work area only appear in a later paragraph. I think the flow could be improved by keeping related information together.
Agreed. I'll keep the work-area allocation and lifetime details together in the revised commit message.
Quoted 19 lines
Quoted 19 lines
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_32andEEH_ERR_TYPE_64are unchanged; their values are defined inarch/powerpc/include/uapi/asm/eeh.hand 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 mostRTAS_INSTANTIATE_MAX= 1 GiB), so the physical address fits in the 32-bit RTAS argument without truncation.Remove
eeh_pe_inject_mmio_error()and its declaration; this patch removes its only caller. The only remaining caller ofeeh_break_device()iseeh_dev_break_write()insideCONFIG_DEBUG_FS, so moveeeh_break_device()back inside theCONFIG_DEBUG_FSblock to avoid an unused-function warning whenCONFIG_DEBUG_FS=n.Quoted 6 lines
Quoted 3 lines
Also introduce
validate_errinjct_args()andprepare_errinjct_buffer()here alongside their callers, so each intermediate commit builds cleanly withCONFIG_WERROR.Could you clarify what this intermediate commit is for?
The intention was to separate the helper infrastructure from the RTAS implementation. However, given the unused static helpers and the additional complexity introduced by the split, I'll merge the two patches.
Quoted 9 lines
Quoted 9 lines
The addr argument to ibm,errinjct is function-dependent. Memory and IO load/store functions (EEH_ERR_FUNC_LD/ST_MEM_* and EEH_ERR_FUNC_LD/ ST_IO_*) target BAR-backed PCI bus addresses; these are validated against the PE via validate_addr_mask_in_pe(). Config-space functions carry PCI config register offsets and DMA functions carry IOVA/TCE addresses; addr for these functions is passed directly to RTAS without BAR membership validation.
Quoted 9 lines
Quoted 6 lines
For the 32-bit RTAS encoding (
RTAS_ERR_TYPE_IOA_BUS_ERROR), addr and mask are checked to fit in 32 bits before buffer encoding. This is an RTAS format constraint independent of function type.Tested with corresponding QEMU patches:
https://lore.kernel.org/all/20251029150618.186803-1- [email protected]/Wouldn't this be better suited for the cover letter?
Agreed. I'll move the reference to the corresponding QEMU series to the cover letter.
Quoted 70 lines
Quoted 28 lines
Signed-off-by Narayana Murty N <[email protected]>---
arch/powerpc/include/asm/eeh.h | 2 - arch/powerpc/kernel/eeh.c | 10 +-arch/powerpc/platforms/pseries/eeh_pseries.c| 246
+++++++++++++++++--3 files changed, 228 insertions(+), 30 deletions(-)arch/powerpc/include/asm/eeh.h +0
-2@@ -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. *
arch/powerpc/kernel/eeh.c +0
-0[...]
Quoted 28 lines
arch/powerpc/kernel/eeh.c +2
-8@@ -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 +0
-0[...]
Quoted 12 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +1
-1@@ -35,6 +35,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;@@ -915,48 +916,253 @@ static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, pci_unlock_rescan_remove(); if (!found) - pr_err("addr=0x%lx mask=0x%lx not within any PCI bus BAR ofQuoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct · line 922
Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-1any device in PE\n", - addr, mask); + pr_debug("addr=0x%lx mask=0x%lx not within any PCI bus BAR of any device in PE\n", + addr, mask);IIUC, the previous patch adds
pr_err(), and this patch changes it topr_debug(). Could we avoid this intermediate change?Yes. I'll introduce
pr_debug()directly in the merged patch.Quoted 18 lines
Quoted 12 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +1
-8return found ? 0 : -EINVAL; } /** -* 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 +* validate_errinjct_args - Top-level validation for RTAS error Quoted 6 lines
injection arguments
+ * @pe: EEH PE for the target device
+ * @type: generic EEH error type
+ * @func: error function selector
+ * @addr: address argument (type-dependent, may be zero)
+ * @mask: mask argument (type-dependent, may be zero)Quoted 2 lines
Are addr and mask really needed as function arguments?
No, they are not used by
validate_errinjct_args(). I'll simplify the validation and avoid the duplicate error-type mapping.Quoted 7 lines
Quoted 3 lines
+ *
+ * Validates all parameters before opening an RTAS injection session.
+ * Returns Linux errno values; does not return raw RTAS status codes.Wouldn't it be better for the function comment to describe what the function does, rather than how an RTAS injection session should be opened?
Agreed. I will shorten the comment.
Quoted 28 lines
Quoted 28 lines
+ *
+ * Return: 0 if all parameters are valid, negative errno otherwise. */
-static int pseries_eeh_err_inject(structeeh_pe*pe, int type, int func,
+static int validate_errinjct_args(structeeh_pe*pe, int type, int func,
unsigned long addr, unsigned long mask) {
- struct eeh_dev *pdev;
+ if (!pe || !pe->phb)
+ return-EINVAL;
+
+ if (pseries_eeh_type_to_rtas(type)< 0)
+ return-EINVAL;
- /* Check on PCI error type */
- if (type !=EEH_ERR_TYPE_32&& type !=EEH_ERR_TYPE_64) + if (func <EEH_ERR_FUNC_MIN|| func >EEH_ERR_FUNC_MAX) return-EINVAL;
+ return 0;arch/powerpc/platforms/pseries/eeh_pseries.c +4
-0+} + +/* +* pseries_eeh_func_needs_bar_addr - return true for error functions whose
+ * addr argument is a BAR-backed PCI MMIO or IO address.
+ *
+ * Memory and IO load/store functions target specific BAR addressesQuoted 9 lines
Quoted 4 lines
and
+ * require PCI bus address validation against the PE. Config-space
+ * functions carry PCI config register offsets and DMA functions carry
+ * IOVA/TCE addresses; neither is a BAR address.This seems like useful information, but perhaps it belongs elsewhere. The function itself looks fairly simple, and the comment conveys quite a bit of information that I’m not sure how to relate to what the function actually does.
Agreed. I'll keep the helper comment focused.
Quoted 40 lines
Quoted 40 lines
+ */
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-0+static bool pseries_eeh_func_needs_bar_addr (int func) +{switch (func) {
caseEEH_ERR_FUNC_LD_MEM_ADDR:
caseEEH_ERR_FUNC_LD_MEM_DATA:
+ caseEEH_ERR_FUNC_LD_IO_ADDR:
+ caseEEH_ERR_FUNC_LD_IO_DATA:
caseEEH_ERR_FUNC_ST_MEM_ADDR:
caseEEH_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();
+ caseEEH_ERR_FUNC_ST_IO_ADDR:
+ caseEEH_ERR_FUNC_ST_IO_DATA:
+ return true;
+ default:
+ return false;
+ }arch/powerpc/platforms/pseries/eeh_pseries.c +18
-0+} + +/** +* prepare_errinjct_buffer() - Build ibm,errinjct work buffer +* @buf: RTAS error-injection work buffer +* @pe: EEH PE associated with the injection target +* @rtas_err_type: RTAS firmware error-injection type +* @func: Error function selector +* @addr: Address argument interpreted according to @func: +* MEM/IO functions: BAR-backed PCI bus address; +* CFG functions: PCI configuration-space offset; +* DMA functions: DMA/IOVA/TCE address. +* @mask: Address mask passed to firmware +* +* Zeroes @buf and populates it according to the PAPR layout for the +* selected IOA bus-error injection type. +* +* BAR membership validation is performed only for MEM/IO functions Quoted 9 lines
Quoted 6 lines
+ * whose @addr is a BAR-backed PCI bus address. CFG and DMA function
+ * addresses are encoded directly without BAR lookup.
+ *
+ * The caller provides an exclusive per-call RTAS work-area buffer.
+ * Firmware session serialization is handled bypseries_eeh_err_inject().Wouldn't this be better documented elsewhere? This function only populates the given work area; it doesn't make the RTAS call.
Agreed. I'll keep the comment focused on encoding the RTAS parameter buffer and move the session-related details to the caller.
Quoted 94 lines
Quoted 25 lines
+ *
+ * Return: 0 on success or a negative errno on invalid input.
+ */arch/powerpc/platforms/pseries/eeh_pseries.c +22
-0+static int prepare_errinjct_buffer (void *buf,struct eeh_pe *pe, + int rtas_err_type, int func, + unsigned long addr, unsigned long mask) +{ + __be64 *buf64 = (__be64 *)buf; + __be32 *buf32 = (__be32 *)buf; + int rc; + + if (!buf || !pe || !pe->phb) + return -EINVAL; + + memset(buf, 0, RTAS_ERRINJCT_BUF_SIZE); + + switch (rtas_err_type) { + case RTAS_ERR_TYPE_IOA_BUS_ERROR: + /* + * 32-bit RTAS format: addr and mask must fit in 32 bits. + * This is an RTAS encoding constraint, not BAR validation. + */ + if (upper_32_bits(addr) || upper_32_bits(mask)) + return -EINVAL; +[...]
Quoted 35 lines
+ if (
pseries_eeh_func_needs_bar_addr(func)) { + rc =validate_addr_mask_in_pe(pe, addr, mask); + if (rc)
+ return rc;
+ }arch/powerpc/platforms/pseries/eeh_pseries.c +22
-0+ + buf32[0] = cpu_to_be32((u32)addr); + buf32[1] = cpu_to_be32((u32)mask); + buf32[2] = cpu_to_be32(pe->addr); + buf32[3] = cpu_to_be32(BUID_HI(pe->phb->buid)); + buf32[4] = cpu_to_be32(BUID_LO(pe->phb->buid)); + buf32[5] = cpu_to_be32(func); + break; + + case RTAS_ERR_TYPE_IOA_BUS_ERROR_64: + if (pseries_eeh_func_needs_bar_addr(func)) { + rc = validate_addr_mask_in_pe(pe, addr, mask); + if (rc) + return rc; + } + + buf64[0] = cpu_to_be64(addr); + buf64[1] = cpu_to_be64(mask); + buf32[4] = cpu_to_be32(pe->addr); + buf32[5] = cpu_to_be32(BUID_HI(pe->phb->buid)); + buf32[6] = cpu_to_be32(BUID_LO(pe->phb->buid)); + buf32[7] = cpu_to_be32(func);break;
+
default:
- return-ERANGE;
+pr_err("unsupported RTAS error injection type 0x%x\n", rtas_err_type);
+ return-EINVAL;
}[...]
Quoted 32 lines
+ pr_debug("errinjct buffer ready: rtas_err_type=0x%x func=%d addr=0x%lx mask=0x%lx\n",
+rtas_err_type, func, addr, mask);
return 0;
}arch/powerpc/platforms/pseries/eeh_pseries.c +17
-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: 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(structeeh_pe*pe, int type, int func,
+ unsigned long addr, unsigned long mask) +{
+ structrtas_work_area*area;Quoted 9 lines
Quoted 5 lines
+
phys_addr_tarea_phys;
+ void *buf;
+ intopen_token,errinjct_token,close_token;
+ intsession_token;
+ intrtas_err_type;The name
rtas_err_typeseems a bit confusing for the error injection class. Woulderr_injct_classorerrinjct_classbe clearer?Agreed. I'll use
errinjct_class.Quoted 14 lines
Quoted 14 lines
+ int
close_rc;
+ int rc;arch/powerpc/platforms/pseries/eeh_pseries.c +12
-0+ + rc = validate_errinjct_args(pe, type, func, addr, mask); + if (rc) + return rc; + + rtas_err_type = pseries_eeh_type_to_rtas(type); + if (rtas_err_type < 0) + return -EINVAL; + + 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);Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 1113
Quoted 7 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +7
-0+ + if (open_token == RTAS_UNKNOWN_SERVICE || + errinjct_token == RTAS_UNKNOWN_SERVICE || + close_token == RTAS_UNKNOWN_SERVICE) + return -ENODEV; + + mutex_lock(&errinjct_mutex);Is this lock really necessary?
As mentioned above, the intention is to serialize complete error injection sessions initiated through the EEH backend rather than individual RTAS calls.
However, this mutex does not serialize direct userspace RTAS callers. I'll verify the firmware session ownership semantics before deciding whether to retain it.
Quoted 50 lines
- Sourabh Jain
Quoted 48 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +16
-0+ + 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; + } + + 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)
+ gotoout_free_area;arch/powerpc/platforms/pseries/eeh_pseries.c +29
-0+ + /* + * 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); + } +Quoted 8 lines
Quoted 8 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +5
-0+out_unlock: + mutex_unlock(&errinjct_mutex); + return rc; +} +static struct
eeh_opspseries_eeh_ops= {
.name = "pseries",
.probe =pseries_eeh_probe,Thanks,
Narayana Murty.Quoted 1 line
Re: [PATCH v6 3/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection
Hi Sourabh,
Quoted 5 lines · Sourabh Jain
Quoted 2 lines · Narayana Murty N
Hi Sourah,
Quoted 9 lines
Quoted 6 lines · Sourabh Jain
Quoted 4 lines
Similar to 2/5, I'm finding this commit message a bit difficult to follow. Could you please rework it to make the changes and their purpose clearer?
Agreed. I'll merge 2/5 and 3/5 and rework the commit message.
I didn't recommend merging 2/5 and 3/5.
Regarding merging 2/5 and 3/5, most helpers in 2/5 are used only by 3/5. I merged them to keep the helpers alongside their callers and avoid an intermediate patch with unused static functions.
Quoted 19 lines
Quoted 11 lines
Quoted 11 lines · Narayana Murty N
Quoted 6 lines
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_mutexbecause RTAS maintains state between these calls.I don't quite understand this point. What RTAS state are we referring to here? Also, could you clarify how keeping all three calls under a lock helps maintain the RTAS state mentioned above?
Quoted 7 lines
I was referring to the error injection session established by ibm,open-errinjct and identified by the returned session token.
The RTAS lock serializes individual RTAS calls, but not the complete open/inject/close sequence. The intention of
errinjct_mutexis to prevent concurrent EEH injection requests from interleaving their sessions.
Quoted 8 lines
Ok the intent is to synchronize multiple
err_injectionrequests? So kernel would do open/inject/close together for 1 request and then move to another request do open/inject/close.....Could you please help me understand what is wrong with concurrent EEH injection requests with an interleaved open/inject/close sequence?
Is this restriction coming from PAPR? If yes, please share the section no.
As per LoPAPR v1.1, Section 7.3.13 (R1-7.3.13-2 and R1-7.3.13-3), only one ERRINJCT facility can be open at a time. A concurrent ibm,open-errinjct returns -4 (already open).
The mutex serializes kernel-initiated EEH injection requests so that each open/inject/close sequence completes before the next begins, avoiding unnecessary -EBUSY failures.
It does not serialize external sys_rtas() callers. If an external process already owns the facility, firmware returns -4, which the kernel handles accordingly.
Thanks,
Narayana
Quoted 468 lines
- Sourabh Jain
Quoted 464 lines
I'll recheck the PAPR session ownership requirements to determine whether this additional serialization is necessary.
Quoted 10 lines
Quoted 5 lines
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.
RTAS work area is mentioned here, but the next paragraph discusses something else. The details about the RTAS work area only appear in a later paragraph. I think the flow could be improved by keeping related information together.
Agreed. I'll keep the work-area allocation and lifetime details together in the revised commit message.
Quoted 19 lines
Quoted 19 lines
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_32andEEH_ERR_TYPE_64are unchanged; their values are defined inarch/powerpc/include/uapi/asm/eeh.hand 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 mostRTAS_INSTANTIATE_MAX= 1 GiB), so the physical address fits in the 32-bit RTAS argument without truncation.Remove
eeh_pe_inject_mmio_error()and its declaration; this patch removes its only caller. The only remaining caller ofeeh_break_device()iseeh_dev_break_write()insideCONFIG_DEBUG_FS, so moveeeh_break_device()back inside theCONFIG_DEBUG_FSblock to avoid an unused-function warning whenCONFIG_DEBUG_FS=n.Quoted 6 lines
Quoted 3 lines
Also introduce
validate_errinjct_args()andprepare_errinjct_buffer()here alongside their callers, so each intermediate commit builds cleanly withCONFIG_WERROR.Could you clarify what this intermediate commit is for?
The intention was to separate the helper infrastructure from the RTAS implementation. However, given the unused static helpers and the additional complexity introduced by the split, I'll merge the two patches.
Quoted 9 lines
Quoted 9 lines
The addr argument to ibm,errinjct is function-dependent. Memory and IO load/store functions (EEH_ERR_FUNC_LD/ST_MEM_* and EEH_ERR_FUNC_LD/ ST_IO_*) target BAR-backed PCI bus addresses; these are validated against the PE via validate_addr_mask_in_pe(). Config-space functions carry PCI config register offsets and DMA functions carry IOVA/TCE addresses; addr for these functions is passed directly to RTAS without BAR membership validation.
Quoted 9 lines
Quoted 6 lines
For the 32-bit RTAS encoding (
RTAS_ERR_TYPE_IOA_BUS_ERROR), addr and mask are checked to fit in 32 bits before buffer encoding. This is an RTAS format constraint independent of function type.Tested with corresponding QEMU patches:
https://lore.kernel.org/all/20251029150618.186803-1- [email protected]/Wouldn't this be better suited for the cover letter?
Agreed. I'll move the reference to the corresponding QEMU series to the cover letter.
Quoted 70 lines
Quoted 28 lines
Signed-off-by Narayana Murty N <[email protected]>---
arch/powerpc/include/asm/eeh.h | 2 - arch/powerpc/kernel/eeh.c | 10 +-arch/powerpc/platforms/pseries/eeh_pseries.c| 246 +++++++++++++++
++--3 files changed, 228 insertions(+), 30 deletions(-)arch/powerpc/include/asm/eeh.h +0
-2@@ -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. *
arch/powerpc/kernel/eeh.c +0
-0[...]
Quoted 28 lines
arch/powerpc/kernel/eeh.c +2
-8@@ -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 +0
-0[...]
Quoted 12 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +1
-1@@ -35,6 +35,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;@@ -915,48 +916,253 @@ static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, pci_unlock_rescan_remove(); if (!found) - pr_err("addr=0x%lx mask=0x%lx not within any PCI bus BAR ofQuoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct · line 922
Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-1any device in PE\n", - addr, mask); + pr_debug("addr=0x%lx mask=0x%lx not within any PCI bus BAR of any device in PE\n", + addr, mask);IIUC, the previous patch adds
pr_err(), and this patch changes it topr_debug(). Could we avoid this intermediate change?Yes. I'll introduce
pr_debug()directly in the merged patch.Quoted 18 lines
Quoted 12 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +1
-8return found ? 0 : -EINVAL; } /** -* 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 +* validate_errinjct_args - Top-level validation for RTAS error Quoted 6 lines
injection arguments
+ * @pe: EEH PE for the target device
+ * @type: generic EEH error type
+ * @func: error function selector
+ * @addr: address argument (type-dependent, may be zero)
+ * @mask: mask argument (type-dependent, may be zero)Quoted 2 lines
Are addr and mask really needed as function arguments?
No, they are not used by
validate_errinjct_args(). I'll simplify the validation and avoid the duplicate error-type mapping.Quoted 7 lines
Quoted 3 lines
+ *
+ * Validates all parameters before opening an RTAS injection session.
+ * Returns Linux errno values; does not return raw RTAS status codes.Wouldn't it be better for the function comment to describe what the function does, rather than how an RTAS injection session should be opened?
Agreed. I will shorten the comment.
Quoted 28 lines
Quoted 28 lines
+ *
+ * Return: 0 if all parameters are valid, negative errno otherwise. */
-static int pseries_eeh_err_inject(structeeh_pe*pe, int type, int func,
+static int validate_errinjct_args(structeeh_pe*pe, int type, int func,
unsigned long addr, unsigned long mask) {
- struct eeh_dev *pdev;
+ if (!pe || !pe->phb)
+ return-EINVAL;
+
+ if (pseries_eeh_type_to_rtas(type)< 0)
+ return-EINVAL;
- /* Check on PCI error type */
- if (type !=EEH_ERR_TYPE_32&& type !=EEH_ERR_TYPE_64) + if (func <EEH_ERR_FUNC_MIN|| func >EEH_ERR_FUNC_MAX) return-EINVAL;
+ return 0;arch/powerpc/platforms/pseries/eeh_pseries.c +4
-0+} + +/* +* pseries_eeh_func_needs_bar_addr - return true for error functions whose
+ * addr argument is a BAR-backed PCI MMIO or IO address.
+ *
+ * Memory and IO load/store functions target specific BAR addressesQuoted 9 lines
Quoted 4 lines
and
+ * require PCI bus address validation against the PE. Config-space
+ * functions carry PCI config register offsets and DMA functions carry
+ * IOVA/TCE addresses; neither is a BAR address.This seems like useful information, but perhaps it belongs elsewhere. The function itself looks fairly simple, and the comment conveys quite a bit of information that I’m not sure how to relate to what the function actually does.
Agreed. I'll keep the helper comment focused.
Quoted 40 lines
Quoted 40 lines
+ */
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-0+static bool pseries_eeh_func_needs_bar_addr (int func) +{switch (func) {
caseEEH_ERR_FUNC_LD_MEM_ADDR:
caseEEH_ERR_FUNC_LD_MEM_DATA:
+ caseEEH_ERR_FUNC_LD_IO_ADDR:
+ caseEEH_ERR_FUNC_LD_IO_DATA:
caseEEH_ERR_FUNC_ST_MEM_ADDR:
caseEEH_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();
+ caseEEH_ERR_FUNC_ST_IO_ADDR:
+ caseEEH_ERR_FUNC_ST_IO_DATA:
+ return true;
+ default:
+ return false;
+ }arch/powerpc/platforms/pseries/eeh_pseries.c +18
-0+} + +/** +* prepare_errinjct_buffer() - Build ibm,errinjct work buffer +* @buf: RTAS error-injection work buffer +* @pe: EEH PE associated with the injection target +* @rtas_err_type: RTAS firmware error-injection type +* @func: Error function selector +* @addr: Address argument interpreted according to @func: +* MEM/IO functions: BAR-backed PCI bus address; +* CFG functions: PCI configuration-space offset; +* DMA functions: DMA/IOVA/TCE address. +* @mask: Address mask passed to firmware +* +* Zeroes @buf and populates it according to the PAPR layout for the +* selected IOA bus-error injection type. +* +* BAR membership validation is performed only for MEM/IO functions Quoted 9 lines
Quoted 6 lines
+ * whose @addr is a BAR-backed PCI bus address. CFG and DMA function
+ * addresses are encoded directly without BAR lookup.
+ *
+ * The caller provides an exclusive per-call RTAS work-area buffer.
+ * Firmware session serialization is handled bypseries_eeh_err_inject().Wouldn't this be better documented elsewhere? This function only populates the given work area; it doesn't make the RTAS call.
Agreed. I'll keep the comment focused on encoding the RTAS parameter buffer and move the session-related details to the caller.
Quoted 94 lines
Quoted 25 lines
+ *
+ * Return: 0 on success or a negative errno on invalid input.
+ */arch/powerpc/platforms/pseries/eeh_pseries.c +22
-0+static int prepare_errinjct_buffer (void *buf,struct eeh_pe *pe, + int rtas_err_type, int func, + unsigned long addr, unsigned long mask) +{ + __be64 *buf64 = (__be64 *)buf; + __be32 *buf32 = (__be32 *)buf; + int rc; + + if (!buf || !pe || !pe->phb) + return -EINVAL; + + memset(buf, 0, RTAS_ERRINJCT_BUF_SIZE); + + switch (rtas_err_type) { + case RTAS_ERR_TYPE_IOA_BUS_ERROR: + /* + * 32-bit RTAS format: addr and mask must fit in 32 bits. + * This is an RTAS encoding constraint, not BAR validation. + */ + if (upper_32_bits(addr) || upper_32_bits(mask)) + return -EINVAL; +[...]
Quoted 35 lines
+ if (
pseries_eeh_func_needs_bar_addr(func)) { + rc =validate_addr_mask_in_pe(pe, addr, mask); + if (rc)
+ return rc;
+ }arch/powerpc/platforms/pseries/eeh_pseries.c +22
-0+ + buf32[0] = cpu_to_be32((u32)addr); + buf32[1] = cpu_to_be32((u32)mask); + buf32[2] = cpu_to_be32(pe->addr); + buf32[3] = cpu_to_be32(BUID_HI(pe->phb->buid)); + buf32[4] = cpu_to_be32(BUID_LO(pe->phb->buid)); + buf32[5] = cpu_to_be32(func); + break; + + case RTAS_ERR_TYPE_IOA_BUS_ERROR_64: + if (pseries_eeh_func_needs_bar_addr(func)) { + rc = validate_addr_mask_in_pe(pe, addr, mask); + if (rc) + return rc; + } + + buf64[0] = cpu_to_be64(addr); + buf64[1] = cpu_to_be64(mask); + buf32[4] = cpu_to_be32(pe->addr); + buf32[5] = cpu_to_be32(BUID_HI(pe->phb->buid)); + buf32[6] = cpu_to_be32(BUID_LO(pe->phb->buid)); + buf32[7] = cpu_to_be32(func);break;
+
default:
- return-ERANGE;
+pr_err("unsupported RTAS error injection type 0x%x\n", rtas_err_type);
+ return-EINVAL;
}[...]
Quoted 32 lines
+ pr_debug("errinjct buffer ready: rtas_err_type=0x%x func=%d addr=0x%lx mask=0x%lx\n",
+rtas_err_type, func, addr, mask);
return 0;
}arch/powerpc/platforms/pseries/eeh_pseries.c +17
-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: 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(structeeh_pe*pe, int type, int func,
+ unsigned long addr, unsigned long mask) +{
+ structrtas_work_area*area;Quoted 9 lines
Quoted 5 lines
+
phys_addr_tarea_phys;
+ void *buf;
+ intopen_token,errinjct_token,close_token;
+ intsession_token;
+ intrtas_err_type;The name
rtas_err_typeseems a bit confusing for the error injection class. Woulderr_injct_classorerrinjct_classbe clearer?Agreed. I'll use
errinjct_class.Quoted 14 lines
Quoted 14 lines
+ int
close_rc;
+ int rc;arch/powerpc/platforms/pseries/eeh_pseries.c +12
-0+ + rc = validate_errinjct_args(pe, type, func, addr, mask); + if (rc) + return rc; + + rtas_err_type = pseries_eeh_type_to_rtas(type); + if (rtas_err_type < 0) + return -EINVAL; + + 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);Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 1113
Quoted 7 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +7
-0+ + if (open_token == RTAS_UNKNOWN_SERVICE || + errinjct_token == RTAS_UNKNOWN_SERVICE || + close_token == RTAS_UNKNOWN_SERVICE) + return -ENODEV; + + mutex_lock(&errinjct_mutex);Is this lock really necessary?
As mentioned above, the intention is to serialize complete error injection sessions initiated through the EEH backend rather than individual RTAS calls.
However, this mutex does not serialize direct userspace RTAS callers. I'll verify the firmware session ownership semantics before deciding whether to retain it.
Quoted 50 lines
- Sourabh Jain
Quoted 48 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +16
-0+ + 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; + } + + 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)
+ gotoout_free_area;arch/powerpc/platforms/pseries/eeh_pseries.c +29
-0+ + /* + * 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); + } +Quoted 8 lines
Quoted 8 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +5
-0+out_unlock: + mutex_unlock(&errinjct_mutex); + return rc; +} +static struct
eeh_opspseries_eeh_ops= {
.name = "pseries",
.probe =pseries_eeh_probe,Thanks,
Narayana Murty.Quoted 1 line
Re: [PATCH v6 3/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection
Quoted 23 lines · Narayana Murty N
Hi Sourabh,
Quoted 5 lines · Sourabh Jain
Quoted 2 lines · Narayana Murty N
Hi Sourah,
Quoted 9 lines
Quoted 6 lines · Sourabh Jain
Quoted 4 lines
Similar to 2/5, I'm finding this commit message a bit difficult to follow. Could you please rework it to make the changes and their purpose clearer?
Agreed. I'll merge 2/5 and 3/5 and rework the commit message.
I didn't recommend merging 2/5 and 3/5.
Regarding merging 2/5 and 3/5, most helpers in 2/5 are used only by 3/5. I merged them to keep the helpers alongside their callers and avoid an intermediate patch with unused static functions.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · Narayana Murty N
Quoted 3 lines
Replace the legacy MMIO stub in
pseries_eeh_err_inject()with a full PAPR-compliant RTAS error injection path.
[...]
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 7 lines
Quoted 3 lines
Serialize each ibm,open-errinjct / ibm,errinjct / ibm,close-errinjct session with
errinjct_mutexbecause RTAS maintains state between these calls.I don't quite understand this point. What RTAS state are we referring to here? Also, could you clarify how keeping all three calls under a lock helps maintain the RTAS state mentioned above?
I was referring to the error injection session established by ibm,open-errinjct and identified by the returned session token.
The RTAS lock serializes individual RTAS calls, but not the complete open/inject/close sequence. The intention of
errinjct_mutexis to prevent concurrent EEH injection requests from interleaving their sessions.
[...]
Quoted 9 lines
Quoted 8 lines
Ok the intent is to synchronize multiple
err_injectionrequests? So kernel would do open/inject/close together for 1 request and then move to another request do open/inject/close.....Could you please help me understand what is wrong with concurrent EEH injection requests with an interleaved open/inject/close sequence?
Is this restriction coming from PAPR? If yes, please share the section no.
As per LoPAPR v1.1, Section 7.3.13 (R1-7.3.13-2 and R1-7.3.13-3), only one ERRINJCT facility can be open at a time. A concurrent ibm,open-errinjct returns -4 (already open).
Yes, that's a good enough reason to protect the open/inject/close sequence with a lock. I tested the -4 condition using a kernel module by calling open-err-injection twice in succession. The second open returns -4.
Could you please add a short comment explaining this at the point where the lock is acquired?
Also, please handle the -4 case in pseries_eeh_err_inject(), as it can be interleaved with a sys_call open-err-injection call.
Quoted 4 lines
The mutex serializes kernel-initiated EEH injection requests so that each open/inject/close sequence completes before the next begins, avoiding unnecessary
-EBUSYfailures.It does not serialize external
sys_rtas()callers. If an external process already owns the facility, firmware returns -4, which the kernel handles accordingly.
Yes, open-err-injection from the sys_rtas call can still be interleaved with open-err-injection from pseries_eeh_err_inject(). However, there is nothing more we can do in this patch other than handle the -4 case in pseries_eeh_err_inject() and log the event.
- Sourabh Jain
Quoted 480 lines
Thanks,
NarayanaQuoted 476 lines
- Sourabh Jain
Quoted 472 lines
I'll recheck the PAPR session ownership requirements to determine whether this additional serialization is necessary.
Quoted 10 lines
Quoted 5 lines
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.
RTAS work area is mentioned here, but the next paragraph discusses something else. The details about the RTAS work area only appear in a later paragraph. I think the flow could be improved by keeping related information together.
Agreed. I'll keep the work-area allocation and lifetime details together in the revised commit message.
Quoted 19 lines
Quoted 19 lines
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_32andEEH_ERR_TYPE_64are unchanged; their values are defined inarch/powerpc/include/uapi/asm/eeh.hand 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 mostRTAS_INSTANTIATE_MAX= 1 GiB), so the physical address fits in the 32-bit RTAS argument without truncation.Remove
eeh_pe_inject_mmio_error()and its declaration; this patch removes its only caller. The only remaining caller ofeeh_break_device()iseeh_dev_break_write()insideCONFIG_DEBUG_FS, so moveeeh_break_device()back inside theCONFIG_DEBUG_FSblock to avoid an unused-function warning whenCONFIG_DEBUG_FS=n.Quoted 6 lines
Quoted 3 lines
Also introduce
validate_errinjct_args()andprepare_errinjct_buffer()here alongside their callers, so each intermediate commit builds cleanly withCONFIG_WERROR.Could you clarify what this intermediate commit is for?
The intention was to separate the helper infrastructure from the RTAS implementation. However, given the unused static helpers and the additional complexity introduced by the split, I'll merge the two patches.
Quoted 9 lines
Quoted 9 lines
The addr argument to ibm,errinjct is function-dependent. Memory and IO load/store functions (EEH_ERR_FUNC_LD/ST_MEM_* and EEH_ERR_FUNC_LD/ ST_IO_*) target BAR-backed PCI bus addresses; these are validated against the PE via validate_addr_mask_in_pe(). Config-space functions carry PCI config register offsets and DMA functions carry IOVA/TCE addresses; addr for these functions is passed directly to RTAS without BAR membership validation.
Quoted 9 lines
Quoted 6 lines
For the 32-bit RTAS encoding (
RTAS_ERR_TYPE_IOA_BUS_ERROR), addr and mask are checked to fit in 32 bits before buffer encoding. This is an RTAS format constraint independent of function type.Tested with corresponding QEMU patches:
https://lore.kernel.org/all/20251029150618.186803-1- [email protected]/Wouldn't this be better suited for the cover letter?
Agreed. I'll move the reference to the corresponding QEMU series to the cover letter.
Quoted 70 lines
Quoted 28 lines
Signed-off-by Narayana Murty N <[email protected]>---
arch/powerpc/include/asm/eeh.h | 2 - arch/powerpc/kernel/eeh.c | 10 +-arch/powerpc/platforms/pseries/eeh_pseries.c| 246 +++++++++++++++ ++--3 files changed, 228 insertions(+), 30 deletions(-)arch/powerpc/include/asm/eeh.h +0
-2@@ -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. *
arch/powerpc/kernel/eeh.c +0
-0[...]
Quoted 28 lines
arch/powerpc/kernel/eeh.c +2
-8@@ -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 +0
-0[...]
Quoted 12 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +1
-1@@ -35,6 +35,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;@@ -915,48 +916,253 @@ static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, pci_unlock_rescan_remove(); if (!found) - pr_err("addr=0x%lx mask=0x%lx not within any PCI bus BARQuoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct · line 922
Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-1of any device in PE\n", - addr, mask); + pr_debug("addr=0x%lx mask=0x%lx not within any PCI bus BAR of any device in PE\n", + addr, mask);IIUC, the previous patch adds
pr_err(), and this patch changes it topr_debug(). Could we avoid this intermediate change?Yes. I'll introduce
pr_debug()directly in the merged patch.Quoted 19 lines
Quoted 11 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +0
-1return found ? 0 : -EINVAL; } /** -* 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 isQuoted 8 lines
- * determined by @type and @func, to the indicated PE
+ *validate_errinjct_args- Top-level validation for RTAS error injection arguments
+ * @pe: EEH PE for the target device
+ * @type: generic EEH error type
+ * @func: error function selector
+ * @addr: address argument (type-dependent, may be zero)
+ * @mask: mask argument (type-dependent, may be zero)Quoted 2 lines
Are addr and mask really needed as function arguments?
No, they are not used by
validate_errinjct_args(). I'll simplify the validation and avoid the duplicate error-type mapping.Quoted 9 lines
Quoted 5 lines
+ *
+ * Validates all parameters before opening an RTAS injection session.
+ * Returns Linux errno values; does not return raw RTAS status codes.Wouldn't it be better for the function comment to describe what the function does, rather than how an RTAS injection session should be opened?
Agreed. I will shorten the comment.
Quoted 29 lines
Quoted 29 lines
+ *
+ * Return: 0 if all parameters are valid, negative errno otherwise. */
-static int pseries_eeh_err_inject(structeeh_pe*pe, int type, int func,
+static int validate_errinjct_args(structeeh_pe*pe, int type, int func,
unsigned long addr, unsigned long mask) {
- struct eeh_dev *pdev;
+ if (!pe || !pe->phb)
+ return-EINVAL;
+
+ if (pseries_eeh_type_to_rtas(type)< 0)
+ return-EINVAL;
- /* Check on PCI error type */
- if (type !=EEH_ERR_TYPE_32&& type !=EEH_ERR_TYPE_64) + if (func <EEH_ERR_FUNC_MIN|| func >EEH_ERR_FUNC_MAX) return-EINVAL;
+ return 0;arch/powerpc/platforms/pseries/eeh_pseries.c +4
-0+} + +/* +* pseries_eeh_func_needs_bar_addr - return true for error functions whose
+ * addr argument is a BAR-backed PCI MMIO or IO address.
+ *
+ * Memory and IO load/store functions target specific BAR addresses andQuoted 9 lines
Quoted 4 lines
+ * require PCI bus address validation against the PE. Config-space
+ * functions carry PCI config register offsets and DMA functions carry
+ * IOVA/TCE addresses; neither is a BAR address.This seems like useful information, but perhaps it belongs elsewhere. The function itself looks fairly simple, and the comment conveys quite a bit of information that I’m not sure how to relate to what the function actually does.
Agreed. I'll keep the helper comment focused.
Quoted 41 lines
Quoted 41 lines
+ */
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-0+static bool pseries_eeh_func_needs_bar_addr (int func) +{switch (func) {
caseEEH_ERR_FUNC_LD_MEM_ADDR:
caseEEH_ERR_FUNC_LD_MEM_DATA:
+ caseEEH_ERR_FUNC_LD_IO_ADDR:
+ caseEEH_ERR_FUNC_LD_IO_DATA:
caseEEH_ERR_FUNC_ST_MEM_ADDR:
caseEEH_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();
+ caseEEH_ERR_FUNC_ST_IO_ADDR:
+ caseEEH_ERR_FUNC_ST_IO_DATA:
+ return true;
+ default:
+ return false;
+ }arch/powerpc/platforms/pseries/eeh_pseries.c +19
-0+} + +/** +* prepare_errinjct_buffer() - Build ibm,errinjct work buffer +* @buf: RTAS error-injection work buffer +* @pe: EEH PE associated with the injection target +* @rtas_err_type: RTAS firmware error-injection type +* @func: Error function selector +* @addr: Address argument interpreted according to @func: +* MEM/IO functions: BAR-backed PCI bus address; +* CFG functions: PCI configuration-space offset; +* DMA functions: DMA/IOVA/TCE address. +* @mask: Address mask passed to firmware +* +* Zeroes @buf and populates it according to the PAPR layout for the +* selected IOA bus-error injection type. +* +* BAR membership validation is performed only for MEM/IO functions +* whose @addr is a BAR-backed PCI bus address. CFG and DMA Quoted 9 lines
Quoted 6 lines
function
+ * addresses are encoded directly without BAR lookup.
+ *
+ * The caller provides an exclusive per-call RTAS work-area buffer.
+ * Firmware session serialization is handled bypseries_eeh_err_inject().Wouldn't this be better documented elsewhere? This function only populates the given work area; it doesn't make the RTAS call.
Agreed. I'll keep the comment focused on encoding the RTAS parameter buffer and move the session-related details to the caller.
Quoted 96 lines
Quoted 25 lines
+ *
+ * Return: 0 on success or a negative errno on invalid input.
+ */arch/powerpc/platforms/pseries/eeh_pseries.c +22
-0+static int prepare_errinjct_buffer (void *buf,struct eeh_pe *pe, + int rtas_err_type, int func, + unsigned long addr, unsigned long mask) +{ + __be64 *buf64 = (__be64 *)buf; + __be32 *buf32 = (__be32 *)buf; + int rc; + + if (!buf || !pe || !pe->phb) + return -EINVAL; + + memset(buf, 0, RTAS_ERRINJCT_BUF_SIZE); + + switch (rtas_err_type) { + case RTAS_ERR_TYPE_IOA_BUS_ERROR: + /* + * 32-bit RTAS format: addr and mask must fit in 32 bits. + * This is an RTAS encoding constraint, not BAR validation. + */ + if (upper_32_bits(addr) || upper_32_bits(mask)) + return -EINVAL; +[...]
Quoted 35 lines
+ if (
pseries_eeh_func_needs_bar_addr(func)) { + rc =validate_addr_mask_in_pe(pe, addr, mask); + if (rc)
+ return rc;
+ }arch/powerpc/platforms/pseries/eeh_pseries.c +22
-0+ + buf32[0] = cpu_to_be32((u32)addr); + buf32[1] = cpu_to_be32((u32)mask); + buf32[2] = cpu_to_be32(pe->addr); + buf32[3] = cpu_to_be32(BUID_HI(pe->phb->buid)); + buf32[4] = cpu_to_be32(BUID_LO(pe->phb->buid)); + buf32[5] = cpu_to_be32(func); + break; + + case RTAS_ERR_TYPE_IOA_BUS_ERROR_64: + if (pseries_eeh_func_needs_bar_addr(func)) { + rc = validate_addr_mask_in_pe(pe, addr, mask); + if (rc) + return rc; + } + + buf64[0] = cpu_to_be64(addr); + buf64[1] = cpu_to_be64(mask); + buf32[4] = cpu_to_be32(pe->addr); + buf32[5] = cpu_to_be32(BUID_HI(pe->phb->buid)); + buf32[6] = cpu_to_be32(BUID_LO(pe->phb->buid)); + buf32[7] = cpu_to_be32(func);break;
+
default:
- return-ERANGE;
+pr_err("unsupported RTAS error injection type 0x%x\n", rtas_err_type);
+ return-EINVAL;
}[...]
Quoted 34 lines
+ pr_debug("errinjct buffer ready: rtas_err_type=0x%x func=%d addr=0x%lx mask=0x%lx\n",
+rtas_err_type, func, addr, mask);
return 0;
}arch/powerpc/platforms/pseries/eeh_pseries.c +5
-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: generic EEH error type (EEH_ERR_TYPE_32orEEH_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_mutexserializes 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(structeeh_pe*pe, int type, int func,
+ unsigned long addr, unsigned long mask) +{
+ structrtas_work_area*area;Quoted 9 lines
Quoted 5 lines
+
phys_addr_tarea_phys;
+ void *buf;
+ intopen_token,errinjct_token,close_token;
+ intsession_token;
+ intrtas_err_type;The name
rtas_err_typeseems a bit confusing for the error injection class. Woulderr_injct_classorerrinjct_classbe clearer?Agreed. I'll use
errinjct_class.Quoted 14 lines
Quoted 14 lines
+ int
close_rc;
+ int rc;arch/powerpc/platforms/pseries/eeh_pseries.c +12
-0+ + rc = validate_errinjct_args(pe, type, func, addr, mask); + if (rc) + return rc; + + rtas_err_type = pseries_eeh_type_to_rtas(type); + if (rtas_err_type < 0) + return -EINVAL; + + 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);Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 1113
Quoted 7 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +7
-0+ + if (open_token == RTAS_UNKNOWN_SERVICE || + errinjct_token == RTAS_UNKNOWN_SERVICE || + close_token == RTAS_UNKNOWN_SERVICE) + return -ENODEV; + + mutex_lock(&errinjct_mutex);Is this lock really necessary?
As mentioned above, the intention is to serialize complete error injection sessions initiated through the EEH backend rather than individual RTAS calls.
However, this mutex does not serialize direct userspace RTAS callers. I'll verify the firmware session ownership semantics before deciding whether to retain it.
Quoted 51 lines
- Sourabh Jain
Quoted 49 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +16
-0+ + 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; + } + + 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)
+ gotoout_free_area;arch/powerpc/platforms/pseries/eeh_pseries.c +21
-0+ + /* + * 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));arch/powerpc/platforms/pseries/eeh_pseries.c +7
-0+ + if (close_rc) { + pr_warn("ibm,close-errinjct failed: status=%d\n", close_rc); + if (!rc) + rc = rtas_error_rc(close_rc); + } +Quoted 8 lines
Quoted 8 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +5
-0+out_unlock: + mutex_unlock(&errinjct_mutex); + return rc; +} +static struct
eeh_opspseries_eeh_ops= {
.name = "pseries",
.probe =pseries_eeh_probe,Thanks,
Narayana Murty.Quoted 1 line
Re: [PATCH v6 3/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection
Quoted 51 lines · Sourabh Jain
Quoted 23 lines · Narayana Murty N
Hi Sourabh,
Quoted 5 lines · Sourabh Jain
Quoted 2 lines · Narayana Murty N
Hi Sourah,
Quoted 9 lines
Quoted 6 lines · Sourabh Jain
Quoted 4 lines
Similar to 2/5, I'm finding this commit message a bit difficult to follow. Could you please rework it to make the changes and their purpose clearer?
Agreed. I'll merge 2/5 and 3/5 and rework the commit message.
I didn't recommend merging 2/5 and 3/5.
Regarding merging 2/5 and 3/5, most helpers in 2/5 are used only by 3/5. I merged them to keep the helpers alongside their callers and avoid an intermediate patch with unused static functions.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · Narayana Murty N
Quoted 3 lines
Replace the legacy MMIO stub in
pseries_eeh_err_inject()with a full PAPR-compliant RTAS error injection path.[...]
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 7 lines
Quoted 3 lines
Serialize each ibm,open-errinjct / ibm,errinjct / ibm,close-errinjct session with
errinjct_mutexbecause RTAS maintains state between these calls.I don't quite understand this point. What RTAS state are we referring to here? Also, could you clarify how keeping all three calls under a lock helps maintain the RTAS state mentioned above?
I was referring to the error injection session established by ibm,open-errinjct and identified by the returned session token.
The RTAS lock serializes individual RTAS calls, but not the complete open/inject/close sequence. The intention of
errinjct_mutexis to prevent concurrent EEH injection requests from interleaving their sessions.[...]
Quoted 8 lines
Quoted 8 lines
Ok the intent is to synchronize multiple
err_injectionrequests? So kernel would do open/inject/close together for 1 request and then move to another request do open/inject/close.....Could you please help me understand what is wrong with concurrent EEH injection requests with an interleaved open/inject/close sequence?
Is this restriction coming from PAPR? If yes, please share the section no.
Quoted 9 lines
Quoted 1 line
As per LoPAPR v1.1, Section 7.3.13 (R1-7.3.13-2 and R1-7.3.13-3), only one ERRINJCT facility can be open at a time. A concurrent ibm,open- errinjct returns -4 (already open).
Yes, that's a good enough reason to protect the open/inject/close sequence with a lock. I tested the -4 condition using a kernel module by calling open-err-injection twice in succession. The second open returns -4.
Could you please add a short comment explaining this at the point where the lock is acquired?
Agreed, I will add inline comment.
Quoted 4 lines
Also, please handle the -4 case in
pseries_eeh_err_inject(), as it can be interleaved with asys_callopen-err-injection call.Quoted 1 line
Quoted 8 lines
Quoted 3 lines
The mutex serializes kernel-initiated EEH injection requests so that each open/inject/close sequence completes before the next begins, avoiding unnecessary
-EBUSYfailures.It does not serialize external
sys_rtas()callers. If an external process already owns the facility, firmware returns -4, which the kernel handles accordingly.Yes, open-err-injection from the
sys_rtascall can still be interleaved with open-err-injection frompseries_eeh_err_inject(). However, there is nothing more we can do in this patch other than handle the -4 case inpseries_eeh_err_inject()and log the event.
Sure, I will handle in next version.
Thanks,
Narayana Murty.
Quoted 483 lines
- Sourabh Jain
Quoted 480 lines
Thanks,
NarayanaQuoted 476 lines
- Sourabh Jain
Quoted 472 lines
I'll recheck the PAPR session ownership requirements to determine whether this additional serialization is necessary.
Quoted 10 lines
Quoted 5 lines
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.
RTAS work area is mentioned here, but the next paragraph discusses something else. The details about the RTAS work area only appear in a later paragraph. I think the flow could be improved by keeping related information together.
Agreed. I'll keep the work-area allocation and lifetime details together in the revised commit message.
Quoted 19 lines
Quoted 19 lines
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_32andEEH_ERR_TYPE_64are unchanged; their values are defined inarch/powerpc/include/uapi/asm/eeh.hand 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 mostRTAS_INSTANTIATE_MAX= 1 GiB), so the physical address fits in the 32-bit RTAS argument without truncation.Remove
eeh_pe_inject_mmio_error()and its declaration; this patch removes its only caller. The only remaining caller ofeeh_break_device()iseeh_dev_break_write()insideCONFIG_DEBUG_FS, so moveeeh_break_device()back inside theCONFIG_DEBUG_FSblock to avoid an unused-function warning whenCONFIG_DEBUG_FS=n.Quoted 6 lines
Quoted 3 lines
Also introduce
validate_errinjct_args()andprepare_errinjct_buffer()here alongside their callers, so each intermediate commit builds cleanly withCONFIG_WERROR.Could you clarify what this intermediate commit is for?
The intention was to separate the helper infrastructure from the RTAS implementation. However, given the unused static helpers and the additional complexity introduced by the split, I'll merge the two patches.
Quoted 9 lines
Quoted 9 lines
The addr argument to ibm,errinjct is function-dependent. Memory and IO load/store functions (EEH_ERR_FUNC_LD/ST_MEM_* and EEH_ERR_FUNC_LD/ ST_IO_*) target BAR-backed PCI bus addresses; these are validated against the PE via validate_addr_mask_in_pe(). Config-space functions carry PCI config register offsets and DMA functions carry IOVA/TCE addresses; addr for these functions is passed directly to RTAS without BAR membership validation.
Quoted 9 lines
Quoted 6 lines
For the 32-bit RTAS encoding (
RTAS_ERR_TYPE_IOA_BUS_ERROR), addr and mask are checked to fit in 32 bits before buffer encoding. This is an RTAS format constraint independent of function type.Tested with corresponding QEMU patches:
https://lore.kernel.org/all/20251029150618.186803-1- [email protected]/Wouldn't this be better suited for the cover letter?
Agreed. I'll move the reference to the corresponding QEMU series to the cover letter.
Quoted 70 lines
Quoted 28 lines
Signed-off-by Narayana Murty N <[email protected]>---
arch/powerpc/include/asm/eeh.h | 2 - arch/powerpc/kernel/eeh.c | 10 +-arch/powerpc/platforms/pseries/eeh_pseries.c| 246 +++++++++++++ ++ ++--3 files changed, 228 insertions(+), 30 deletions(-)arch/powerpc/include/asm/eeh.h +0
-2@@ -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. *
arch/powerpc/kernel/eeh.c +0
-0[...]
Quoted 28 lines
arch/powerpc/kernel/eeh.c +2
-8@@ -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 +0
-0[...]
Quoted 12 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +1
-1@@ -35,6 +35,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;@@ -915,48 +916,253 @@ static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, pci_unlock_rescan_remove(); if (!found) - pr_err("addr=0x%lx mask=0x%lx not within any PCI bus BARQuoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct · line 922
Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-1of any device in PE\n", - addr, mask); + pr_debug("addr=0x%lx mask=0x%lx not within any PCI bus BAR of any device in PE\n", + addr, mask);IIUC, the previous patch adds
pr_err(), and this patch changes it topr_debug(). Could we avoid this intermediate change?Yes. I'll introduce
pr_debug()directly in the merged patch.Quoted 19 lines
Quoted 11 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +0
-1return found ? 0 : -EINVAL; } /** -* 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 isQuoted 8 lines
- * determined by @type and @func, to the indicated PE
+ *validate_errinjct_args- Top-level validation for RTAS error injection arguments
+ * @pe: EEH PE for the target device
+ * @type: generic EEH error type
+ * @func: error function selector
+ * @addr: address argument (type-dependent, may be zero)
+ * @mask: mask argument (type-dependent, may be zero)Quoted 2 lines
Are addr and mask really needed as function arguments?
No, they are not used by
validate_errinjct_args(). I'll simplify the validation and avoid the duplicate error-type mapping.Quoted 9 lines
Quoted 5 lines
+ *
+ * Validates all parameters before opening an RTAS injection session.
+ * Returns Linux errno values; does not return raw RTAS status codes.Wouldn't it be better for the function comment to describe what the function does, rather than how an RTAS injection session should be opened?
Agreed. I will shorten the comment.
Quoted 29 lines
Quoted 29 lines
+ *
+ * Return: 0 if all parameters are valid, negative errno otherwise. */
-static int pseries_eeh_err_inject(structeeh_pe*pe, int type, int func,
+static int validate_errinjct_args(structeeh_pe*pe, int type, int func,
unsigned long addr, unsigned long mask) {
- struct eeh_dev *pdev;
+ if (!pe || !pe->phb)
+ return-EINVAL;
+
+ if (pseries_eeh_type_to_rtas(type)< 0)
+ return-EINVAL;
- /* Check on PCI error type */
- if (type !=EEH_ERR_TYPE_32&& type !=EEH_ERR_TYPE_64) + if (func <EEH_ERR_FUNC_MIN|| func >EEH_ERR_FUNC_MAX) return-EINVAL;
+ return 0;arch/powerpc/platforms/pseries/eeh_pseries.c +4
-0+} + +/* +* pseries_eeh_func_needs_bar_addr - return true for error functions whose
+ * addr argument is a BAR-backed PCI MMIO or IO address.
+ *
+ * Memory and IO load/store functions target specific BAR addresses andQuoted 9 lines
Quoted 4 lines
+ * require PCI bus address validation against the PE. Config-space
+ * functions carry PCI config register offsets and DMA functions carry
+ * IOVA/TCE addresses; neither is a BAR address.This seems like useful information, but perhaps it belongs elsewhere. The function itself looks fairly simple, and the comment conveys quite a bit of information that I’m not sure how to relate to what the function actually does.
Agreed. I'll keep the helper comment focused.
Quoted 41 lines
Quoted 41 lines
+ */
arch/powerpc/platforms/pseries/eeh_pseries.c +2
-0+static bool pseries_eeh_func_needs_bar_addr (int func) +{switch (func) {
caseEEH_ERR_FUNC_LD_MEM_ADDR:
caseEEH_ERR_FUNC_LD_MEM_DATA:
+ caseEEH_ERR_FUNC_LD_IO_ADDR:
+ caseEEH_ERR_FUNC_LD_IO_DATA:
caseEEH_ERR_FUNC_ST_MEM_ADDR:
caseEEH_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();
+ caseEEH_ERR_FUNC_ST_IO_ADDR:
+ caseEEH_ERR_FUNC_ST_IO_DATA:
+ return true;
+ default:
+ return false;
+ }arch/powerpc/platforms/pseries/eeh_pseries.c +19
-0+} + +/** +* prepare_errinjct_buffer() - Build ibm,errinjct work buffer +* @buf: RTAS error-injection work buffer +* @pe: EEH PE associated with the injection target +* @rtas_err_type: RTAS firmware error-injection type +* @func: Error function selector +* @addr: Address argument interpreted according to @func: +* MEM/IO functions: BAR-backed PCI bus address; +* CFG functions: PCI configuration-space offset; +* DMA functions: DMA/IOVA/TCE address. +* @mask: Address mask passed to firmware +* +* Zeroes @buf and populates it according to the PAPR layout for the +* selected IOA bus-error injection type. +* +* BAR membership validation is performed only for MEM/IO functions +* whose @addr is a BAR-backed PCI bus address. CFG and DMA Quoted 9 lines
Quoted 6 lines
function
+ * addresses are encoded directly without BAR lookup.
+ *
+ * The caller provides an exclusive per-call RTAS work-area buffer.
+ * Firmware session serialization is handled bypseries_eeh_err_inject().Wouldn't this be better documented elsewhere? This function only populates the given work area; it doesn't make the RTAS call.
Agreed. I'll keep the comment focused on encoding the RTAS parameter buffer and move the session-related details to the caller.
Quoted 96 lines
Quoted 25 lines
+ *
+ * Return: 0 on success or a negative errno on invalid input.
+ */arch/powerpc/platforms/pseries/eeh_pseries.c +22
-0+static int prepare_errinjct_buffer (void *buf,struct eeh_pe *pe, + int rtas_err_type, int func, + unsigned long addr, unsigned long mask) +{ + __be64 *buf64 = (__be64 *)buf; + __be32 *buf32 = (__be32 *)buf; + int rc; + + if (!buf || !pe || !pe->phb) + return -EINVAL; + + memset(buf, 0, RTAS_ERRINJCT_BUF_SIZE); + + switch (rtas_err_type) { + case RTAS_ERR_TYPE_IOA_BUS_ERROR: + /* + * 32-bit RTAS format: addr and mask must fit in 32 bits. + * This is an RTAS encoding constraint, not BAR validation. + */ + if (upper_32_bits(addr) || upper_32_bits(mask)) + return -EINVAL; +[...]
Quoted 35 lines
+ if (
pseries_eeh_func_needs_bar_addr(func)) { + rc =validate_addr_mask_in_pe(pe, addr, mask); + if (rc)
+ return rc;
+ }arch/powerpc/platforms/pseries/eeh_pseries.c +22
-0+ + buf32[0] = cpu_to_be32((u32)addr); + buf32[1] = cpu_to_be32((u32)mask); + buf32[2] = cpu_to_be32(pe->addr); + buf32[3] = cpu_to_be32(BUID_HI(pe->phb->buid)); + buf32[4] = cpu_to_be32(BUID_LO(pe->phb->buid)); + buf32[5] = cpu_to_be32(func); + break; + + case RTAS_ERR_TYPE_IOA_BUS_ERROR_64: + if (pseries_eeh_func_needs_bar_addr(func)) { + rc = validate_addr_mask_in_pe(pe, addr, mask); + if (rc) + return rc; + } + + buf64[0] = cpu_to_be64(addr); + buf64[1] = cpu_to_be64(mask); + buf32[4] = cpu_to_be32(pe->addr); + buf32[5] = cpu_to_be32(BUID_HI(pe->phb->buid)); + buf32[6] = cpu_to_be32(BUID_LO(pe->phb->buid)); + buf32[7] = cpu_to_be32(func);break;
+
default:
- return-ERANGE;
+pr_err("unsupported RTAS error injection type 0x%x\n", rtas_err_type);
+ return-EINVAL;
}[...]
Quoted 34 lines
+ pr_debug("errinjct buffer ready: rtas_err_type=0x%x func=%d addr=0x%lx mask=0x%lx\n",
+rtas_err_type, func, addr, mask);
return 0;
}arch/powerpc/platforms/pseries/eeh_pseries.c +5
-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: generic EEH error type (EEH_ERR_TYPE_32orEEH_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_mutexserializes 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(structeeh_pe*pe, int type, int func,
+ unsigned long addr, unsigned long mask) +{
+ structrtas_work_area*area;Quoted 9 lines
Quoted 5 lines
+
phys_addr_tarea_phys;
+ void *buf;
+ intopen_token,errinjct_token,close_token;
+ intsession_token;
+ intrtas_err_type;The name
rtas_err_typeseems a bit confusing for the error injection class. Woulderr_injct_classorerrinjct_classbe clearer?Agreed. I'll use
errinjct_class.Quoted 14 lines
Quoted 14 lines
+ int
close_rc;
+ int rc;arch/powerpc/platforms/pseries/eeh_pseries.c +12
-0+ + rc = validate_errinjct_args(pe, type, func, addr, mask); + if (rc) + return rc; + + rtas_err_type = pseries_eeh_type_to_rtas(type); + if (rtas_err_type < 0) + return -EINVAL; + + 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);Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long addr, · line 1113
Quoted 7 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +7
-0+ + if (open_token == RTAS_UNKNOWN_SERVICE || + errinjct_token == RTAS_UNKNOWN_SERVICE || + close_token == RTAS_UNKNOWN_SERVICE) + return -ENODEV; + + mutex_lock(&errinjct_mutex);Is this lock really necessary?
As mentioned above, the intention is to serialize complete error injection sessions initiated through the EEH backend rather than individual RTAS calls.
However, this mutex does not serialize direct userspace RTAS callers. I'll verify the firmware session ownership semantics before deciding whether to retain it.
Quoted 51 lines
- Sourabh Jain
Quoted 49 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +16
-0+ + 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; + } + + 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)
+ gotoout_free_area;arch/powerpc/platforms/pseries/eeh_pseries.c +21
-0+ + /* + * 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));arch/powerpc/platforms/pseries/eeh_pseries.c +7
-0+ + if (close_rc) { + pr_warn("ibm,close-errinjct failed: status=%d\n", close_rc); + if (!rc) + rc = rtas_error_rc(close_rc); + } +Quoted 8 lines
Quoted 8 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +5
-0+out_unlock: + mutex_unlock(&errinjct_mutex); + return rc; +} +static struct
eeh_opspseries_eeh_ops= {
.name = "pseries",
.probe =pseries_eeh_probe,Thanks,
Narayana Murty.Quoted 1 line
PATCH v6 4/5 vfio/spapr_tce: Normalize EEH IOA error injection addresses
In reply to Narayana Murty NVFIO_EEH_PE_INJECT_ERR receives a target address from userspace. For userspace such as QEMU, this address may be derived from the host Linux BAR resource. The platform EEH backends, however, expect the PCI/IOA bus address used by firmware error-injection interfaces.
Normalize IOA/MMIO error-injection addresses in the sPAPR VFIO EEH ioctl path before dispatching to eeh_pe_inject_err(). If the supplied address is already a PCI bus BAR address it is left unchanged. If it is a Linux resource address, translate it to the corresponding PCI bus address using the BAR-relative offset.
Normalization applies only to EEH_ERR_TYPE_32 and EEH_ERR_TYPE_64 error types whose error function targets a memory or IO BAR (load/store memory and load/store IO functions, func 0-3 and 6-9). Config-space functions carry PCI config register offsets and DMA functions carry IOVA/TCE addresses; these address domains are not PCI BAR addresses and must not be translated. Applying BAR normalization to them would incorrectly return -EINVAL, blocking injection entirely for those function codes.
An address and mask pair of zero represents a no-address injection (e.g. a function-level error with no specific IOA target) and is passed through without BAR translation.
Only standard BARs (BAR0..BAR5) are searched; ROM and bridge resources are not IOA bus-error targets. Unassigned or disabled BARs are skipped:pci_resource_len() returns 0 for zero-initialized BARs, and the IORESOURCE_UNSET and IORESOURCE_DISABLED flags are checked explicitly to avoid false matches against unassigned resources. Hold pci_rescan_remove_lock while traversing PE devices and their BAR resources to prevent PCI device removal from racing the lookup.
A pr_debug() is emitted if the address cannot be matched to any BAR, to aid debugging without producing noise in the normal path.
Keep the helper local to VFIO so the address semantics of other in-kernel EEH callers remain unchanged.
--- drivers/vfio/vfio_iommu_spapr_tce.c | 140 ++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+)
drivers/vfio/vfio_iommu_spapr_tce.c +140 -0
@@ -774,6 +774,131 @@ static long tce_iommu_create_default_window(struct tce_container *container)return ret; } +/* +* eeh_func_needs_bar_addr - return true for error functions whose addr +* argument is a PCI MMIO or IO BAR address. +* +* Memory and IO load/store functions target specific BAR addresses. +* Config-space functions carry PCI config register offsets, and DMA +* functions carry IOVA/TCE addresses; neither requires BAR translation. +*/ +static bool eeh_func_needs_bar_addr (int func) +{ +switch (func) { +case EEH_ERR_FUNC_LD_MEM_ADDR : +case EEH_ERR_FUNC_LD_MEM_DATA : +case EEH_ERR_FUNC_LD_IO_ADDR : +case EEH_ERR_FUNC_LD_IO_DATA : +case EEH_ERR_FUNC_ST_MEM_ADDR : +case EEH_ERR_FUNC_ST_MEM_DATA : +case EEH_ERR_FUNC_ST_IO_ADDR : +case EEH_ERR_FUNC_ST_IO_DATA : +return true; +default : +return false; + } +} + +static int vfio_spapr_eeh_normalize_addr (struct eeh_pe *pe, +unsigned long addr, +unsigned long mask, +unsigned long *normalized) +{ +struct pci_bus_region region; +struct eeh_dev *edev, *tmp; +struct pci_dev *pdev; +struct resource *res; +resource_size_t pci_start, pci_len; +resource_size_t res_start, res_len; +resource_size_t offset; +int bar, rc = -EINVAL ; + +if (!pe || !normalized) +return -EINVAL ; + +/* +* addr == 0 and mask == 0 indicates a no-address injection (e.g. +* function-level error with no specific IOA target). No BAR +* translation needed. +*/ +if (!addr && !mask) { + *normalized = addr; +return 0 ; + } + +/* +* Walk standard BARs (BAR0..BAR5) of all devices in the PE. +* Hold pci_rescan_remove_lock to protect pdev lifetime during the +* traversal: pci_stop_and_remove_bus_device() requires this lock. +* ROM and bridge resources are not IOA bus-error targets, so the +* search is limited to PCI_STD_NUM_BARS. +*/ +pci_lock_rescan_remove (); +eeh_pe_for_each_dev (pe, edev, tmp) { + pdev =eeh_dev_to_pci_dev (edev); +if (!pdev) +continue ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { + res = &pdev->resource[bar]; + +/* +* Skip unassigned or disabled BARs. On pseries, +* pcibios_fixup_resources() zero-bases unassigned BARs +* (start=0, end=size-1) and sets IORESOURCE_UNSET. +* Use pci_resource_len() which returns 0 when end==0. +*/ +if (!pci_resource_len (pdev, bar)) +continue ; + +if (!(res->flags & (IORESOURCE_MEM |IORESOURCE_IO ))) +continue ; + +if (res->flags & (IORESOURCE_UNSET |IORESOURCE_DISABLED )) +continue ; + +pcibios_resource_to_bus (pdev->bus, ®ion, res); + + pci_start = region.start; + pci_len =pci_resource_len (pdev, bar); + +/* +* Case 1: userspace already supplied PCI/IOA +* bus address. +*/ +if ((resource_size_t )addr >= pci_start && + ((resource_size_t )addr - pci_start) < pci_len) { + *normalized = addr; + rc =0 ; + goto done; + } + +/* +* Case 2: userspace supplied Linux resource/CPU +* address. Convert it back to PCI/IOA bus address +* before calling the platform EEH backend. +*/ + res_start = res->start; + res_len =pci_resource_len (pdev, bar); + +if ((resource_size_t )addr >= res_start && + ((resource_size_t )addr - res_start) < res_len) { + offset = (resource_size_t )addr - res_start; + *normalized = region.start + offset; + rc =0 ; + goto done; + } + } + } +done: +pci_unlock_rescan_remove (); + +if (rc) +pr_debug ("vfio EEH: addr=0x%lx not found in any PCI bus BAR of PE\n" , + addr); +return rc; +} +static long vfio_spapr_ioctl_eeh_pe_op (struct iommu_group *group,unsigned long arg) {
@@ -818,6 +943,21 @@ static long vfio_spapr_ioctl_eeh_pe_op(struct iommu_group *group,if (copy_from_user (&op, (void __user *)arg, minsz))return -EFAULT ; +if ((op.err.type ==EEH_ERR_TYPE_32 || + op.err.type ==EEH_ERR_TYPE_64 ) && +eeh_func_needs_bar_addr (op.err.func)) { +unsigned long normalized; +int ret; + + ret =vfio_spapr_eeh_normalize_addr (pe, op.err.addr, + op.err.mask, + &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
Re: [PATCH v6 4/5] vfio/spapr_tce: Normalize EEH IOA error injection addresses
I'm finding this commit message a bit difficult to follow. Could you please rework it to make the changes and their purpose clearer?
Quoted 31 lines · Narayana Murty N
VFIO_EEH_PE_INJECT_ERRreceives a target address from userspace. For userspace such as QEMU, this address may be derived from the host Linux BAR resource. The platform EEH backends, however, expect the PCI/IOA bus address used by firmware error-injection interfaces.Normalize IOA/MMIO error-injection addresses in the sPAPR VFIO EEH ioctl path before dispatching to
eeh_pe_inject_err(). If the supplied address is already a PCI bus BAR address it is left unchanged. If it is a Linux resource address, translate it to the corresponding PCI bus address using the BAR-relative offset.Normalization applies only to
EEH_ERR_TYPE_32andEEH_ERR_TYPE_64error types whose error function targets a memory or IO BAR (load/store memory and load/store IO functions, func 0-3 and 6-9). Config-space functions carry PCI config register offsets and DMA functions carry IOVA/TCE addresses; these address domains are not PCI BAR addresses and must not be translated. Applying BAR normalization to them would incorrectly return-EINVAL, blocking injection entirely for those function codes.An address and mask pair of zero represents a no-address injection (e.g. a function-level error with no specific IOA target) and is passed through without BAR translation.
Only standard BARs (BAR0..BAR5) are searched; ROM and bridge resources are not IOA bus-error targets. Unassigned or disabled BARs are skipped:
pci_resource_len()returns 0 for zero-initialized BARs, and theIORESOURCE_UNSETandIORESOURCE_DISABLEDflags are checked explicitly to avoid false matches against unassigned resources. Holdpci_rescan_remove_lockwhile traversing PE devices and their BAR resources to prevent PCI device removal from racing the lookup.
Quoted 2 lines
A
pr_debug()is emitted if the address cannot be matched to any BAR, to aid debugging without producing noise in the normal path.
Which address are you referring to?
Quoted 3 lines
Keep the helper local to VFIO so the address semantics of other in-kernel EEH callers remain unchanged.
Which helper are you referring to?
Quoted 32 lines
Signed-off-by Narayana Murty N <[email protected]>--- drivers/vfio/vfio_iommu_spapr_tce.c | 140 ++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+)drivers/vfio/vfio_iommu_spapr_tce.c +18
-0@@ -774,6 +774,131 @@ static long tce_iommu_create_default_window(struct tce_container *container)return ret; } +/* +* eeh_func_needs_bar_addr - return true for error functions whose addr +* argument is a PCI MMIO or IO BAR address. +* +* Memory and IO load/store functions target specific BAR addresses. +* Config-space functions carry PCI config register offsets, and DMA +* functions carry IOVA/TCE addresses; neither requires BAR translation. +*/ +static bool eeh_func_needs_bar_addr (int func) +{ +switch (func) { +case EEH_ERR_FUNC_LD_MEM_ADDR : +case EEH_ERR_FUNC_LD_MEM_DATA : +case EEH_ERR_FUNC_LD_IO_ADDR : +case EEH_ERR_FUNC_LD_IO_DATA : +case EEH_ERR_FUNC_ST_MEM_ADDR : +case EEH_ERR_FUNC_ST_MEM_DATA : +case EEH_ERR_FUNC_ST_IO_ADDR :
drivers/vfio/vfio_iommu_spapr_tce.c static long tce_iommu_create_default_window(struct tce_container *container) · line 804
Quoted 10 lines
drivers/vfio/vfio_iommu_spapr_tce.c +10
-0+case EEH_ERR_FUNC_ST_IO_DATA : +return true; +default : +return false; + } +} + +static int vfio_spapr_eeh_normalize_addr(struct eeh_pe *pe, + unsigned long addr, + unsigned long mask,
Do we really need mask argument?
drivers/vfio/vfio_iommu_spapr_tce.c static long tce_iommu_create_default_window(struct tce_container *container) · line 805
Quoted 1 line
drivers/vfio/vfio_iommu_spapr_tce.c +1
-0+ unsigned long *normalized)
Too much in a single function. Can you split this function as suggested for validate_addr_mask_in_pe() in 2/5.
- Sourabh Jain
Quoted 121 lines
drivers/vfio/vfio_iommu_spapr_tce.c +111
-0+{ +struct pci_bus_region region; +struct eeh_dev *edev, *tmp; +struct pci_dev *pdev; +struct resource *res; +resource_size_t pci_start, pci_len; +resource_size_t res_start, res_len; +resource_size_t offset; +int bar, rc = -EINVAL ; + +if (!pe || !normalized) +return -EINVAL ; + +/* +* addr == 0 and mask == 0 indicates a no-address injection (e.g. +* function-level error with no specific IOA target). No BAR +* translation needed. +*/ +if (!addr && !mask) { + *normalized = addr; +return 0 ; + } + +/* +* Walk standard BARs (BAR0..BAR5) of all devices in the PE. +* Hold pci_rescan_remove_lock to protect pdev lifetime during the +* traversal: pci_stop_and_remove_bus_device() requires this lock. +* ROM and bridge resources are not IOA bus-error targets, so the +* search is limited to PCI_STD_NUM_BARS. +*/ +pci_lock_rescan_remove (); +eeh_pe_for_each_dev (pe, edev, tmp) { + pdev =eeh_dev_to_pci_dev (edev); +if (!pdev) +continue ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { + res = &pdev->resource[bar]; + +/* +* Skip unassigned or disabled BARs. On pseries, +* pcibios_fixup_resources() zero-bases unassigned BARs +* (start=0, end=size-1) and sets IORESOURCE_UNSET. +* Use pci_resource_len() which returns 0 when end==0. +*/ +if (!pci_resource_len (pdev, bar)) +continue ; + +if (!(res->flags & (IORESOURCE_MEM |IORESOURCE_IO ))) +continue ; + +if (res->flags & (IORESOURCE_UNSET |IORESOURCE_DISABLED )) +continue ; + +pcibios_resource_to_bus (pdev->bus, ®ion, res); + + pci_start = region.start; + pci_len =pci_resource_len (pdev, bar); + +/* +* Case 1: userspace already supplied PCI/IOA +* bus address. +*/ +if ((resource_size_t )addr >= pci_start && + ((resource_size_t )addr - pci_start) < pci_len) { + *normalized = addr; + rc =0 ; + goto done; + } + +/* +* Case 2: userspace supplied Linux resource/CPU +* address. Convert it back to PCI/IOA bus address +* before calling the platform EEH backend. +*/ + res_start = res->start; + res_len =pci_resource_len (pdev, bar); + +if ((resource_size_t )addr >= res_start && + ((resource_size_t )addr - res_start) < res_len) { + offset = (resource_size_t )addr - res_start; + *normalized = region.start + offset; + rc =0 ; + goto done; + } + } + } +done: +pci_unlock_rescan_remove (); + +if (rc) +pr_debug ("vfio EEH: addr=0x%lx not found in any PCI bus BAR of PE\n" , + addr); +return rc; +} +static long vfio_spapr_ioctl_eeh_pe_op (struct iommu_group *group,unsigned long arg) {@@ -818,6 +943,21 @@ static long vfio_spapr_ioctl_eeh_pe_op(struct iommu_group *group,if (copy_from_user (&op, (void __user *)arg, minsz))return -EFAULT ; +if ((op.err.type ==EEH_ERR_TYPE_32 || + op.err.type ==EEH_ERR_TYPE_64 ) && +eeh_func_needs_bar_addr (op.err.func)) { +unsigned long normalized; +int ret; + + ret =vfio_spapr_eeh_normalize_addr (pe, op.err.addr, + op.err.mask, + &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 :
Re: [PATCH v6 4/5] vfio/spapr_tce: Normalize EEH IOA error injection addresses
Quoted 3 lines · Sourabh Jain
I'm finding this commit message a bit difficult to follow.
Could you please rework it to make the changes and their purpose clearer?
Agreed. I'll rework the commit message to focus on why address translation is needed in the VFIO EEH path.
Quoted 32 lines · Narayana Murty N
Quoted 31 lines
VFIO_EEH_PE_INJECT_ERRreceives a target address from userspace. For userspace such as QEMU, this address may be derived from the host Linux BAR resource. The platform EEH backends, however, expect the PCI/IOA bus address used by firmware error-injection interfaces.Normalize IOA/MMIO error-injection addresses in the sPAPR VFIO EEH ioctl path before dispatching to eeh_pe_inject_err(). If the supplied address is already a PCI bus BAR address it is left unchanged. If it is a Linux resource address, translate it to the corresponding PCI bus address using the BAR-relative offset.
Normalization applies only to
EEH_ERR_TYPE_32andEEH_ERR_TYPE_64error types whose error function targets a memory or IO BAR (load/store memory and load/store IO functions, func 0-3 and 6-9). Config-space functions carry PCI config register offsets and DMA functions carry IOVA/TCE addresses; these address domains are not PCI BAR addresses and must not be translated. Applying BAR normalization to them would incorrectly return-EINVAL, blocking injection entirely for those function codes.An address and mask pair of zero represents a no-address injection (e.g. a function-level error with no specific IOA target) and is passed through without BAR translation.
Only standard BARs (BAR0..BAR5) are searched; ROM and bridge resources are not IOA bus-error targets. Unassigned or disabled BARs are skipped:
pci_resource_len()returns 0 for zero-initialized BARs, and theIORESOURCE_UNSETandIORESOURCE_DISABLEDflags are checked explicitly to avoid false matches against unassigned resources. Holdpci_rescan_remove_lockwhile traversing PE devices and their BAR resources to prevent PCI device removal from racing the lookup.
Quoted 4 lines
Quoted 2 lines
A
pr_debug()is emitted if the address cannot be matched to any BAR, to aid debugging without producing noise in the normal path.Which address are you referring to?
The target address supplied by userspace through VFIO_EEH_PE_INJECT_ERR, which may be a Linux resource address or a PCI bus address.
I'll make this explicit in the commit message.
Quoted 7 lines
Quoted 4 lines
Keep the helper local to VFIO so the address semantics of other in-kernel EEH callers remain unchanged.
Which helper are you referring to?
I was referring to vfio_spapr_eeh_normalize_addr().
The intention is to keep the resource-to-bus address translation local to the VFIO path without changing the address semantics of other EEH callers.
Quoted 36 lines
Quoted 36 lines
Signed-off-by Narayana Murty N <[email protected]>---
drivers/vfio/vfio_iommu_spapr_tce.c| 140 ++++++++++++++++++++++++++++1 file changed, 140 insertions(+)drivers/vfio/vfio_iommu_spapr_tce.c +21
-0@@ -774,6 +774,131 @@ static long tce_iommu_create_default_window(struct tce_container *container) return ret; } +/* +* eeh_func_needs_bar_addr - return true for error functions whose addr +* argument is a PCI MMIO or IO BAR address. +* +* Memory and IO load/store functions target specific BAR addresses. +* Config-space functions carry PCI config register offsets, and DMA +* functions carry IOVA/TCE addresses; neither requires BAR translation. +*/ +static bool eeh_func_needs_bar_addr (int func) +{ + switch (func) { + case EEH_ERR_FUNC_LD_MEM_ADDR: + case EEH_ERR_FUNC_LD_MEM_DATA: + case EEH_ERR_FUNC_LD_IO_ADDR: + case EEH_ERR_FUNC_LD_IO_DATA: + case EEH_ERR_FUNC_ST_MEM_ADDR: + case EEH_ERR_FUNC_ST_MEM_DATA: + case EEH_ERR_FUNC_ST_IO_ADDR: + case EEH_ERR_FUNC_ST_IO_DATA: + return true; + default:
Quoted 9 lines
drivers/vfio/vfio_iommu_spapr_tce.c static long tce_iommu_create_default_window(struct tce_container *container) · line 804
Quoted 7 lines
drivers/vfio/vfio_iommu_spapr_tce.c +7
-0+ return false; + } +} + +static int vfio_spapr_eeh_normalize_addr(struct eeh_pe *pe, + unsigned long addr, + unsigned long mask,Do we really need mask argument?
The mask argument is currently used only to identify the no-address injection case where both addr and mask are zero.
I'll move that check to the ioctl caller and remove the mask argument from the normalization helper.
Quoted 5 lines
drivers/vfio/vfio_iommu_spapr_tce.c static long tce_iommu_create_default_window(struct tce_container *container) · line 805
Quoted 1 line
drivers/vfio/vfio_iommu_spapr_tce.c +1
-0+ unsigned long *normalized)Too much in a single function. Can you split this function as suggested for
validate_addr_mask_in_pe()in 2/5.
Agreed. I'll separate the per-device BAR matching and address.
Quoted 116 lines
- Sourabh Jain
Quoted 114 lines
drivers/vfio/vfio_iommu_spapr_tce.c +96
-0+{ + struct pci_bus_region region; + struct eeh_dev *edev, *tmp; + struct pci_dev *pdev; + struct resource *res; + resource_size_t pci_start, pci_len; + resource_size_t res_start, res_len; + resource_size_t offset; + int bar, rc = -EINVAL; + + if (!pe || !normalized) + return -EINVAL; + + /* + * addr == 0 and mask == 0 indicates a no-address injection (e.g. + * function-level error with no specific IOA target). No BAR + * translation needed. + */ + if (!addr && !mask) { + *normalized = addr; + return 0; + } + + /* + * Walk standard BARs (BAR0..BAR5) of all devices in the PE. + * Hold pci_rescan_remove_lock to protect pdev lifetime during the + * traversal: pci_stop_and_remove_bus_device() requires this lock. + * ROM and bridge resources are not IOA bus-error targets, so the + * search is limited to PCI_STD_NUM_BARS. + */ + pci_lock_rescan_remove(); + eeh_pe_for_each_dev(pe, edev, tmp) { + pdev = eeh_dev_to_pci_dev(edev); + if (!pdev) + continue; + + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { + res = &pdev->resource[bar]; + + /* + * Skip unassigned or disabled BARs. On pseries, + * pcibios_fixup_resources() zero-bases unassigned BARs + * (start=0, end=size-1) and sets IORESOURCE_UNSET. + * Use pci_resource_len() which returns 0 when end==0. + */ + if (!pci_resource_len(pdev, bar)) + continue; + + if (!(res->flags & (IORESOURCE_MEM | IORESOURCE_IO))) + continue; + + if (res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) + continue; + + pcibios_resource_to_bus(pdev->bus, ®ion, res); + + pci_start = region.start; + pci_len = pci_resource_len(pdev, bar); + + /* + * Case 1: userspace already supplied PCI/IOA + * bus address. + */ + if ((resource_size_t)addr >= pci_start && + ((resource_size_t)addr - pci_start) < pci_len) { + *normalized = addr; + rc = 0; + goto done; + } + + /* + * Case 2: userspace supplied Linux resource/CPU + * address. Convert it back to PCI/IOA bus address + * before calling the platform EEH backend. + */ + res_start = res->start; + res_len = pci_resource_len(pdev, bar); + + if ((resource_size_t)addr >= res_start && + ((resource_size_t)addr - res_start) < res_len) { + offset = (resource_size_t)addr - res_start; + *normalized = region.start + offset; + rc = 0; + goto done; + } + } + } +done: + pci_unlock_rescan_remove(); + + if (rc) + pr_debug("vfio EEH: addr=0x%lx not found in any PCI bus BAR of PE\n", + addr); + return rc; +} + static long vfio_spapr_ioctl_eeh_pe_op(struct iommu_group *group, unsigned long arg){
drivers/vfio/vfio_iommu_spapr_tce.c +10
-0@@ -818,6 +943,21 @@ static long vfio_spapr_ioctl_eeh_pe_op(struct iommu_group *group, if (copy_from_user(&op, (void __user *)arg, minsz)) return -EFAULT; + if ((op.err.type == EEH_ERR_TYPE_32 || + op.err.type == EEH_ERR_TYPE_64) && + eeh_func_needs_bar_addr(op.err.func)) { + unsigned long normalized; + int ret; + + ret = vfio_spapr_eeh_normalize_addr(pe, op.err.addr, + op.err.mask, + &normalized); + if (ret)
Quoted 8 lines
Quoted 8 lines
drivers/vfio/vfio_iommu_spapr_tce.c +5
-0+ 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:
Thanks,
Narayana Murty.
Quoted 1 line
PATCH v6 5/5 powerpc/powernv/eeh: Map generic EEH error types to OPAL
In reply to Narayana Murty Neeh_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.
--- arch/powerpc/platforms/powernv/eeh-powernv.c | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
arch/powerpc/platforms/powernv/eeh-powernv.c +17 -5
@@ -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
Re: [PATCH v6 5/5] powerpc/powernv/eeh: Map generic EEH error types to OPAL
Hello Narayana,
For my understanding, could you clarify why this change is needed as part of this series? The series is about enabling RTAS-based error injection, and PowerNV doesn't support RTAS. How does this change fit with the earlier patches in the series?
Quoted 67 lines · 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_ERRandOPAL_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_ERR64Return
-ERANGEfor 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(-)arch/powerpc/platforms/powernv/eeh-powernv.c +17
-5@@ -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",
Re: [PATCH v6 5/5] powerpc/powernv/eeh: Map generic EEH error types to OPAL
Hi Sourabh,
Quoted 6 lines · Sourabh Jain
Hello Narayana,
For my understanding, could you clarify why this change is needed as part of this series? The series is about enabling RTAS-based error injection, and PowerNV doesn't support RTAS. How does this change fit with the earlier patches in the series?
The intention was to decouple the generic EEH error types from the platform-specific OPAL encodings, similar to the explicit mapping introduced for pSeries.
However, the generic EEH error-type values remain unchanged, and the PowerNV mapping is not a prerequisite for RTAS-based error injection.
I'll drop this patch from the next revision and will post it as seperate patch.
Thanks,
Narayana Murty.
Quoted 69 lines · Narayana Murty N
Quoted 67 lines
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_ERRandOPAL_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_ERREEH_ERR_TYPE_64->OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64Return
-ERANGEfor 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(-)arch/powerpc/platforms/powernv/eeh-powernv.c +6
-4@@ -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) {
+ caseEEH_ERR_TYPE_32:
+opal_err_type=OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR; + break;
+ caseEEH_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;
}arch/powerpc/platforms/powernv/eeh-powernv.c +1
-1@@ -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",
Re: [PATCH v6 5/5] powerpc/powernv/eeh: Map generic EEH error types to OPAL
Quoted 13 lines · Narayana Murty N
Hi Sourabh,
Quoted 6 lines · Sourabh Jain
Hello Narayana,
For my understanding, could you clarify why this change is needed as part of this series? The series is about enabling RTAS-based error injection, and PowerNV doesn't support RTAS. How does this change fit with the earlier patches in the series?
The intention was to decouple the generic EEH error types from the platform-specific OPAL encodings, similar to the explicit mapping introduced for pSeries.
Quoted 5 lines
However, the generic EEH error-type values remain unchanged, and the PowerNV mapping is not a prerequisite for RTAS-based error injection.
I'll drop this patch from the next revision and will post it as seperate patch.
Thanks for the feedback, I misinterpreted your comment.
Patch 5/5 is included to keep the generic EEH error-injection interface consistent across pSeries and PowerNV.
This patch series introduce RTAS-based error injection on pSeries, where the generic EEH error types (EEH_ERR_TYPE_32/64) are mapped to the corresponding PAPR error-injection classes.
PowerNV uses the same generic EEH interface through eeh_pe_inject_err(), but its backend currently relies on the generic type values matching the OPAL error-injection constants.
Patch 5 makes this translation explicit in the PowerNV backend, similar to the pSeries RTAS implementation. It does not introduce RTAS support on PowerNV or change the userspace ABI or existing behavior.
I'll update the commit message to clarify this relationship.
Thanks,
Narayana
Quoted 74 lines
Thanks,
Narayana Murty.Quoted 70 lines · Narayana Murty N
Quoted 68 lines
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_ERRandOPAL_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_ERREEH_ERR_TYPE_64->OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64Return
-ERANGEfor 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(-)arch/powerpc/platforms/powernv/eeh-powernv.c +5
-4@@ -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) {
+ caseEEH_ERR_TYPE_32:
+opal_err_type=OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR; + break;
+ caseEEH_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;
}arch/powerpc/platforms/powernv/eeh-powernv.c +1
-1@@ -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",
Re: [PATCH v6 5/5] powerpc/powernv/eeh: Map generic EEH error types to OPAL
In reply to Narayana Murty NQuoted 13 lines · Narayana Murty N
Hi Sourabh,
Quoted 6 lines · Sourabh Jain
Hello Narayana,
For my understanding, could you clarify why this change is needed as part of this series? The series is about enabling RTAS-based error injection, and PowerNV doesn't support RTAS. How does this change fit with the earlier patches in the series?
The intention was to decouple the generic EEH error types from the platform-specific OPAL encodings, similar to the explicit mapping introduced for pSeries.
Quoted 5 lines
However, the generic EEH error-type values remain unchanged, and the PowerNV mapping is not a prerequisite for RTAS-based error injection.
I'll drop this patch from the next revision and will post it as seperate patch.
I don't mind keeping this patch as part of the series. The only thing missing is an explanation in the commit message of why and how this patch is needed for the RTAS-based error injection support for pSeries introduced by the previous patches.
It would be helpful to include a scenario explaining why these changes are needed for RTAS-based error injection support on pSeries.
- Sourabh Jain
Quoted 75 lines
Thanks,
Narayana Murty.Quoted 71 lines · Narayana Murty N
Quoted 69 lines
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_ERRandOPAL_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_ERREEH_ERR_TYPE_64->OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64Return
-ERANGEfor 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(-)arch/powerpc/platforms/powernv/eeh-powernv.c +5
-4@@ -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) {
+ caseEEH_ERR_TYPE_32:
+opal_err_type=OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR; + break;
+ caseEEH_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;
}arch/powerpc/platforms/powernv/eeh-powernv.c +1
-1@@ -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",
Re: [PATCH v6 5/5] powerpc/powernv/eeh: Map generic EEH error types to OPAL
HI,
Quoted 22 lines · Sourabh Jain
Quoted 13 lines · Narayana Murty N
Hi Sourabh,
Quoted 6 lines · Sourabh Jain
Hello Narayana,
For my understanding, could you clarify why this change is needed as part of this series? The series is about enabling RTAS-based error injection, and PowerNV doesn't support RTAS. How does this change fit with the earlier patches in the series?
The intention was to decouple the generic EEH error types from the platform-specific OPAL encodings, similar to the explicit mapping introduced for pSeries.
Quoted 5 lines
However, the generic EEH error-type values remain unchanged, and the PowerNV mapping is not a prerequisite for RTAS-based error injection.
I'll drop this patch from the next revision and will post it as seperate patch.
Quoted 9 lines
I don't mind keeping this patch as part of the series. The only thing missing is an explanation in the commit message of why and how this patch is needed for the RTAS-based error injection support for pSeries introduced by the previous patches.
It would be helpful to include a scenario explaining why these changes are needed for RTAS-based error injection support on pSeries.
- Sourabh Jain
Thanks for your feed back, I will continued this patch in V7.
Regards,
Narayana
Quoted 76 lines
Quoted 75 lines
Thanks,
Narayana Murty.Quoted 71 lines · Narayana Murty N
Quoted 69 lines
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_ERRandOPAL_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_ERREEH_ERR_TYPE_64->OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64Return
-ERANGEfor 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(-)arch/powerpc/platforms/powernv/eeh-powernv.c +5
-4@@ -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) {
+ caseEEH_ERR_TYPE_32:
+opal_err_type=OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR; + break;
+ caseEEH_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;
}arch/powerpc/platforms/powernv/eeh-powernv.c +1
-1@@ -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",
Greetings,
I have tested this patch on my KVM guest environment. I am able to inject EEH errors from host console as well as on guest console using location code for a VFIO passthrough device.
Thank you
Tasmiya
Hi Tasmiya,
Quoted 8 lines · tasmiya
Greetings,
I have tested this patch on my KVM guest environment. I am able to inject EEH errors from host console as well as on guest console using location code for a VFIO passthrough device.
Tested-by Tasmiya Nalatwad <[email protected]>Reported-by Tasmiya Nalatwad <[email protected]>
Thanks for testing both host and guest error injection paths.
I'm addressing the review comments and will post v7 with some code restructuring. It would be helpful if you could retest the next revision as well.
Quoted 3 lines
Thank you
Tasmiya
Thanks,
Narayana Murty
PATCH v7 1/4 powerpc/rtas: Handle ibm,open-errinjct return format
In reply to Narayana Murty Nibm,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
@@ -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
PATCH v7 2/4 powerpc/pseries/eeh: Implement RTAS-based EEH error injection
In reply to Narayana Murty Npseries_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
@@ -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
@@ -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
PATCH v7 3/4 vfio/spapr_tce: Normalize EEH IOA error injection addresses
In reply to Narayana Murty NOn 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
@@ -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, ®ion, 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
PATCH v7 4/4 powerpc/powernv/eeh: Map generic EEH error types to OPAL
In reply to Narayana Murty Neeh_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
@@ -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
HI All,
Thank you for the valuable feedback, I addressed the all review
comments in v7 (ressend) posted.
https://lore.kernel.org/all/[email protected]/
Thanks,
Narayana Murty
Quoted 264 lines · Narayana Murty N
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-errinjctThe 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_32andEEH_ERR_TYPE_64continue 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 kernelrtas_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]/Signed-off-by Narayana Murty N <[email protected]>---
Change Log:
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 invalidate_addr_mask_in_pe(): usepci_resource_len()instead ofresource_size()(which returns 1 for zero-initialized BARs), and explicitly reject BARs withIORESOURCE_UNSETorIORESOURCE_DISABLED.
- Movevalidate_errinjct_args()andprepare_errinjct_buffer()to Patch 3 alongside their callers so each intermediate commit builds cleanly withCONFIG_WERROR=ywithout unused-function warnings.* Patch 3:
- Include <asm/rtas-work-area.h> for the RTAS work-area API used by the pSeries error-injection implementation.
- Introducevalidate_errinjct_args()andprepare_errinjct_buffer()here alongside their callers (moved from Patch 2).
- Fixeeh_break_device()visibility: keep it under #ifdefCONFIG_DEBUG_FSto prevent unused-function compiler warnings whenCONFIG_DEBUG_FS=n.
- Addpseries_eeh_func_needs_bar_addr()to identify error functions whose addr argument is a BAR-backed MMIO/IO address. Guardvalidate_addr_mask_in_pe()inprepare_errinjct_buffer()with this predicate so config offsets and DMA/IOVA addresses bypass BAR membership validation.
- Demote thevalidate_addr_mask_in_pe()diagnostic message frompr_err()topr_debug()since invalid user-supplied inputs do not represent internal kernel errors.
- Updateprepare_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 invfio_spapr_eeh_normalize_addr()usingpci_resource_len()and checkingIORESOURCE_UNSET/IORESOURCE_DISABLED.
- Remove the misleading ", injection may fail" suffix from thepr_debug()message since the caller returns-EINVALimmediately.
- 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-EINVALwhen ibm,open-errinjct is used with an invalid return-cell count.
* Validate the ibm,open-errinjct return-cell count insys_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.
* Renamertas_typetortas_err_typeto distinguish the mapped RTAS type from the generic EEH type.
* Keep common error-function validation invalidate_errinjct_args()and remove duplicate check fromprepare_errinjct_buffer().
* Protect PE device and BAR traversal withpci_rescan_remove_lock.
* Renamepseries_errinjct_mutextoerrinjct_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.
* Removeeeh_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 renameopal_typetoopal_err_type.
* Preserve-ERANGEfor 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.
* Keepsys_rtas()raw return-cell semantics unchanged while handling the special ibm,open-errinjct return format inrtas_call().
* Treat ibm,open-errinjct with fewer than two return cells as invalidrtas_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 inrtas_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_unusedparameter
* 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 reviewRFC -> v1:
https://lore.kernel.org/all/[email protected]/* Initial 4-patch series
* Fixed PAPR ibm,open-errinjct output format (token,status order)
* Addedpr_fmthandling for EEH subsystem compatibility
* Implemented comprehensive validation helpersRFC:
https://lore.kernel.org/all/[email protected]/* Initial RFC implementation
Narayana Murty N (5):
powerpc/rtas: Handle ibm,open-errinjct return format powerpc/pseries/eeh: Add RTAS error injection helpers 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 OPALarch/powerpc/include/asm/eeh.h | 2 - arch/powerpc/kernel/eeh.c | 10 +- arch/powerpc/kernel/rtas.c | 78 +++- arch/powerpc/platforms/powernv/eeh-powernv.c | 22 +- arch/powerpc/platforms/pseries/eeh_pseries.c | 375 ++++++++++++++++++- drivers/vfio/vfio_iommu_spapr_tce.c | 140 +++++++ 6 files changed, 585 insertions(+), 42 deletions(-)