From: Sourabh Jain <sourabhjain@linux.ibm.com>
To: Narayana Murty N <nnmlinux@linux.ibm.com>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
"Oliver O'Halloran" <oohall@gmail.com>,
Timothy Pearson <tpearson@raptorengineering.com>,
Alex Williamson <alex@shazbot.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
Christophe Leroy <chleroy@kernel.org>,
Ritesh Harjani <ritesh.list@gmail.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, sbhat@linux.ibm.com, harshpb@linux.ibm.com
Subject: Re: [PATCH v6 1/5] powerpc/rtas: Handle ibm,open-errinjct return format
Date: Wed, 18 Nov 2026 16:43:31 +0530 [thread overview]
Message-ID: <67d2b322-9a6b-41d5-9920-33acb36cb76a@linux.ibm.com> (raw)
In-Reply-To: <20261023073642.59657-2-nnmlinux@linux.ibm.com>
On 23/10/26 13:06, Narayana Murty N wrote:
> 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.
Nit: I think we should not documenting a minor comment movement
in the commit message.
> 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
> Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
> ---
> arch/powerpc/kernel/rtas.c | 78 +++++++++++++++++++++++++++++++++-----
> 1 file changed, 69 insertions(+), 9 deletions(-)
>
> diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
> index 8d81c1e7a8db..38f3d08d4228 100644
> --- a/arch/powerpc/kernel/rtas.c
> +++ b/arch/powerpc/kernel/rtas.c
> @@ -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
> + */
Nit: this comment describes rtas_status_from_args(), not
rtas_token_is_open_errinjct().
Please move it down.
> +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);
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);
> + 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]);
> + }
> + }
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.
>
> 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;
> +
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
> 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);
next prev parent reply other threads:[~2026-11-18 11:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 7:36 [PATCH v6 0/5] powerpc: Add RTAS based error injection support for pSeries Narayana Murty N
2026-10-23 7:36 ` [PATCH v6 1/5] powerpc/rtas: Handle ibm,open-errinjct return format Narayana Murty N
2026-11-18 11:13 ` Sourabh Jain [this message]
2026-10-23 7:36 ` [PATCH v6 2/5] powerpc/pseries/eeh: Add RTAS error injection helpers Narayana Murty N
2026-10-23 7:36 ` [PATCH v6 3/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection Narayana Murty N
2026-10-23 7:36 ` [PATCH v6 4/5] vfio/spapr_tce: Normalize EEH IOA error injection addresses Narayana Murty N
2026-10-23 7:36 ` [PATCH v6 5/5] powerpc/powernv/eeh: Map generic EEH error types to OPAL Narayana Murty N
2026-11-10 19:21 ` [PATCH v6 0/5] powerpc: Add RTAS based error injection support for pSeries tasmiya
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=67d2b322-9a6b-41d5-9920-33acb36cb76a@linux.ibm.com \
--to=sourabhjain@linux.ibm.com \
--cc=alex@shazbot.org \
--cc=chleroy@kernel.org \
--cc=harshpb@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=nnmlinux@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=oohall@gmail.com \
--cc=ritesh.list@gmail.com \
--cc=sbhat@linux.ibm.com \
--cc=sshegde@linux.ibm.com \
--cc=tpearson@raptorengineering.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
all inboxes | Powered by JetHome®