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 1/5] powerpc/rtas: Handle ibm,open-errinjct return format
Date: Tue, 4 Aug 2026 11:22:12 +0530 [thread overview]
Message-ID: <c4e58e48-a7a6-44b7-8984-7f03b3251160@linux.ibm.com> (raw)
In-Reply-To: <20260721033815.5300-2-nnmlinux@linux.ibm.com>
On 21/07/26 09:08, Narayana Murty N wrote:
> PAPR specifies that ibm,open-errinjct has a unique return-cell layout:
>
> rets[0] = injection session token (output parameter)
> rets[1] = status code
>
> This differs from every other RTAS call, where:
>
> rets[0] = status code
> rets[1..] = output parameters
>
> As a result, the existing rtas_call() convention — return value is the
> RTAS status, outputs[] receives the non-status output values — must be
> preserved while correctly extracting status from rets[1] for this one
> call.
>
> Add rtas_token_is_open_errinjct() and rtas_status_from_args() helpers.
> rtas_status_from_args() selects the correct status cell based on the
> token, and the output-copy loop in rtas_call() is updated so that for
> ibm,open-errinjct:
>
> rtas_call() return = rets[1] (RTAS status)
> outputs[0] = rets[0] (session token)
>
> For all other calls the behaviour is unchanged: return value is rets[0]
> and outputs[] receives rets[1..nret-1].
>
> The sys_rtas userspace path is not modified: copy_to_user() still
> copies raw RTAS return cells (rets[0..nret-1]) to userspace.
>
> Callers passing a single output int (nret == 2) are safe because we
> write at most nret-1 values into outputs[], never all nret cells.
>
> Also move the '/* A -1 return code...*/' comment to immediately precede
> the if (ret == -1) check it describes, and remove the redundant stale
> else branch that re-assigned ret.
>
> Reference: OpenPOWER PAPR documentation
> https://files.openpower.foundation/s/XFgfMaqLMD5Bcm8
>
> Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
> ---
> arch/powerpc/kernel/rtas.c | 51 ++++++++++++++++++++++++++++++++------
> 1 file changed, 44 insertions(+), 7 deletions(-)
>
> diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
> index 8d81c1e7a8db..27d53f34494d 100644
> --- a/arch/powerpc/kernel/rtas.c
> +++ b/arch/powerpc/kernel/rtas.c
> @@ -1117,6 +1117,29 @@ static bool token_is_restricted_errinjct(s32 token)
> token == rtas_function_token(RTAS_FN_IBM_ERRINJCT);
> }
>
> +/**
> + * rtas_token_is_open_errinjct() - Test whether @token identifies ibm,open-errinjct.
> + */
> +static bool rtas_token_is_open_errinjct(int token)
> +{
> + return token == rtas_function_token(RTAS_FN_IBM_OPEN_ERRINJCT);
> +}
The above function is a god candidate for an inline function.
> +
> +/**
> + * rtas_status_from_args() - Extract the RTAS status code from a completed
> + * call's return-cell array.
> + *
> + * For ibm,open-errinjct the status lives in rets[1]; for every other
> + * RTAS function it lives in rets[0].
> + */
> +static int rtas_status_from_args(int token, struct rtas_args *args, int nret)
> +{
> + if (rtas_token_is_open_errinjct(token) && nret > 1)
Do we know what RTAS returns when nret is less than 2 for the
ibm,open-errinjct RTAS call?
I assume RTAS treats this as a parameter error. However, since there is
no rets buffer available
to store the status code, I'm not sure how RTAS would convey the
parameter error back to the kernel.
The way the RTAS status code is extracted when nret is less than 2 for
the ibm,open-errinjct RTAS
call seems problematic me, especially when nret == 1. When nret == 1,
this function returns args->rets[0],
which is supposed to contain the session token.
Are we sure that RTAS places the call status in rets[0] when nret == 1
for the ibm,open-errinjct RTAS call?
- Sourabh Jain
> + 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.
> @@ -1213,15 +1236,29 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)
> va_rtas_call_unlocked(args, token, nargs, nret, list);
> va_end(list);
>
> - /* 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)
> + 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 (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;
> + if (nret > 1 && outputs != NULL) {
> + if (rtas_token_is_open_errinjct(token)) {
> + /*
> + * ibm,open-errinjct: rets[0]=session token, rets[1]=status.
> + * Expose session token in outputs[0]; skip rets[1] (status).
> + */
> + outputs[0] = be32_to_cpu(args->rets[0]);
> + for (i = 1; i < nret - 1; ++i)
> + outputs[i] = be32_to_cpu(args->rets[i + 1]);
> + } else {
> + 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);
next prev parent reply other threads:[~2026-08-04 5:52 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 [this message]
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
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=c4e58e48-a7a6-44b7-8984-7f03b3251160@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.