The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Sourabh Jain <sourabhjain@linux.ibm.com>
To: Narayana Murty N <nnmlinux@linux.ibm.com>,
	mahesh@linux.ibm.com, maddy@linux.ibm.com, mpe@ellerman.id.au,
	christophe.leroy@csgroup.eu, gregkh@linuxfoundation.org,
	oohall@gmail.com, npiggin@gmail.com
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	tyreld@linux.ibm.com, vaibhav@linux.ibm.com, sbhat@linux.ibm.com,
	ganeshgr@linux.ibm.com, haren@linux.ibm.com, thuth@redhat.com
Subject: Re: [PATCH v3 4/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection
Date: Tue, 4 Aug 2026 23:56:22 +0530	[thread overview]
Message-ID: <1f8f70a4-2e5c-4e41-a8f1-9a32f37286d0@linux.ibm.com> (raw)
In-Reply-To: <20260721033815.5300-5-nnmlinux@linux.ibm.com>



On 21/07/26 09:08, Narayana Murty N wrote:
> Replace legacy MMIO error injection with full PAPR-compliant RTAS error
> injection supporting 14+ error types via
>    - ibm,open-errinjct
>    - ibm,errinjct
>    - ibm,close-errinjct.
>
> Key features:
>    - Complete open-session-inject-close cycle management
>    - Special handling for ibm,open-errinjct output format (token,status)
>    - Comprehensive buffer preparation per PAPR layouts
>    - All pr_* logging uses pr_fmt("EEH: ") prefix
>
> Tested with corresponding QEMU patches:
> https://lore.kernel.org/all/20251029150618.186803-1-nnmlinux@linux.ibm.com/
>
> Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
> ---
>   arch/powerpc/platforms/pseries/eeh_pseries.c | 121 +++++++++++++++----
>   1 file changed, 95 insertions(+), 26 deletions(-)
>
> diff --git a/arch/powerpc/platforms/pseries/eeh_pseries.c b/arch/powerpc/platforms/pseries/eeh_pseries.c
> index 25aad86c696d..d32a84009fdc 100644
> --- a/arch/powerpc/platforms/pseries/eeh_pseries.c
> +++ b/arch/powerpc/platforms/pseries/eeh_pseries.c
> @@ -1037,40 +1037,109 @@ static int prepare_errinjct_buffer(void *buf, struct eeh_pe *pe,
>   }
>   
>   /**
> - * 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
> + * pseries_eeh_err_inject - Inject specified error into the indicated PE
> + * @pe:   the indicated PE
> + * @type: generic EEH error type (EEH_ERR_TYPE_*)
> + * @func: error function selector (EEH_ERR_FUNC_*)
> + * @addr: target address, if applicable
> + * @mask: address mask, if applicable
> + *
> + * Implements the EEH error-injection callback for pseries using the RTAS
> + * ibm,open-errinjct / ibm,errinjct / ibm,close-errinjct firmware services.
> + *
> + * Generic EEH error types are translated to RTAS firmware type codes via
> + * pseries_eeh_type_to_rtas() before the injection session is opened.
> + * Unsupported generic types are rejected with -EINVAL before any RTAS call
> + * is made.  Existing userspace is unaffected.
> + *
> + * Return: 0 on success, negative errno or RTAS error code on failure.
>    */
>   static int pseries_eeh_err_inject(struct eeh_pe *pe, int type, int func,
>   				  unsigned long addr, unsigned long mask)
>   {
> -	struct	eeh_dev	*pdev;
> -
> -	/* Check on PCI error type */
> -	if (type != EEH_ERR_TYPE_32 && type != EEH_ERR_TYPE_64)
> -		return -EINVAL;
> +	int open_token, errinjct_token, close_token;
> +	int session_token = 0;
> +	bool session_open = false;
> +	void *buf;
> +	u32 buf_phys;
> +	int rc;
> +	int rtas_type;
>   
> -	switch (func) {
> -	case EEH_ERR_FUNC_LD_MEM_ADDR:
> -	case EEH_ERR_FUNC_LD_MEM_DATA:
> -	case EEH_ERR_FUNC_ST_MEM_ADDR:
> -	case EEH_ERR_FUNC_ST_MEM_DATA:
> -		/* injects a MMIO error for all pdev's belonging to PE */
> -		pci_lock_rescan_remove();
> -		list_for_each_entry(pdev, &pe->edevs, entry)
> -			eeh_pe_inject_mmio_error(pdev->pdev);
> -		pci_unlock_rescan_remove();
> -		break;
> -	default:
> +	/* Guard: buffer must fit in 32 bits for RTAS */
> +	if (WARN_ON_ONCE(upper_32_bits(rtas_errinjct_buf)))
>   		return -ERANGE;
> +
> +	/* Map generic EEH ABI to RTAS-internal error type */
> +	rtas_type = pseries_eeh_type_to_rtas(type);
> +	if (rtas_type < 0) {
> +		pr_err("unsupported EEH error type %#x\n", type);
> +		return rtas_type;

How about -EINVAL instead?

>   	}
>   
> -	return 0;
> +	/* Verify all three RTAS tokens are available before touching firmware */
> +	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) {
> +		pr_err("ibm,open/errinjct/close-errinjct not available\n");
> +		return -ENODEV;
> +	}
> +
> +	buf      = __va(rtas_errinjct_buf);
> +	buf_phys = lower_32_bits(rtas_errinjct_buf);
> +
> +	mutex_lock(&rtas_errinjct_mutex);
> +
> +	/* Step 1: open injection session */
> +	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);
> +		goto out_unlock;
> +	}
> +	session_open = true;
> +
> +	/* Step 2: prepare the work buffer */
> +	rc = prepare_errinjct_buffer(buf, pe, rtas_type, func, addr, mask);
> +	if (rc) {
> +		pr_err("failed to prepare errinjct buffer: rc=%d\n", rc);
> +		goto out_close;
> +	}
> +
> +	/* Step 3: inject the error */
> +	do {
> +		rc = rtas_call(errinjct_token, 3, 1, NULL,
> +			       rtas_type, session_token, buf_phys);
> +	} while (rtas_busy_delay(rc));
> +
> +	if (rc)
> +		pr_err("ibm,errinjct failed: status=%d\n", rc);
> +
> +out_close:
> +	/* Step 4: always close the session */
> +	{
> +		int close_rc;

Why are having separate rc variable for close close token call?

> +
> +		if (session_open) {

is session_open variable really needed?

> +			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);
> +		}
> +	}
> +
> +out_unlock:
> +	mutex_unlock(&rtas_errinjct_mutex);
> +	return rc;
>   }
>   
>   static struct eeh_ops pseries_eeh_ops = {


  reply	other threads:[~2026-08-04 18:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21  3:38 [PATCH v3 0/5] powerpc/eeh: Add RTAS-based error injection support on pSeries Narayana Murty N
2026-07-21  3:38 ` [PATCH v3 1/5] powerpc/rtas: Handle ibm,open-errinjct return format Narayana Murty N
2026-08-04  5:52   ` Sourabh Jain
2026-07-21  3:38 ` [PATCH v3 2/5] powerpc/rtas: Allocate ibm,errinjct buffer below RTAS limit Narayana Murty N
2026-08-04  7:22   ` Sourabh Jain
2026-07-21  3:38 ` [PATCH v3 3/5] powerpc/pseries/eeh: Add RTAS error validation helpers Narayana Murty N
2026-08-04 18:05   ` Sourabh Jain
2026-07-21  3:38 ` [PATCH v3 4/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection Narayana Murty N
2026-08-04 18:26   ` Sourabh Jain [this message]
2026-07-21  3:38 ` [PATCH v3 5/5] powerpc/powernv/eeh: Map VFIO EEH error injection to OPAL Narayana Murty N
2026-08-04 18:31   ` Sourabh Jain
2026-08-05  6:23     ` Narayana Murty N
2026-08-09 12:00       ` Sourabh Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1f8f70a4-2e5c-4e41-a8f1-9a32f37286d0@linux.ibm.com \
    --to=sourabhjain@linux.ibm.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=ganeshgr@linux.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=haren@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mahesh@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=nnmlinux@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=oohall@gmail.com \
    --cc=sbhat@linux.ibm.com \
    --cc=thuth@redhat.com \
    --cc=tyreld@linux.ibm.com \
    --cc=vaibhav@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox