From: Narayana Murty N <nnmlinux@linux.ibm.com>
To: Madhavan Srinivasan <maddy@linux.ibm.com>,
"Oliver O'Halloran" <oohall@gmail.com>,
Timothy Pearson <tpearson@raptorengineering.com>,
Alex Williamson <alex@shazbot.org>,
sourabhjain@linux.ibm.com
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: [PATCH v7 1/4] powerpc/rtas: Handle ibm,open-errinjct return format
Date: Mon, 23 Nov 2026 15:52:39 +0530 [thread overview]
Message-ID: <20261123102237.95860-7-nnmlinux@linux.ibm.com> (raw)
In-Reply-To: <20261123102237.95860-6-nnmlinux@linux.ibm.com>
ibm,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.
Link: https://files.openpower.foundation/s/XFgfMaqLMD5Bcm8
Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
---
arch/powerpc/include/asm/trace.h | 26 +++++++---
arch/powerpc/kernel/rtas.c | 83 ++++++++++++++++++++++++++------
2 files changed, 88 insertions(+), 21 deletions(-)
diff --git a/arch/powerpc/include/asm/trace.h b/arch/powerpc/include/asm/trace.h
index a7b69b25296b..d731f70aead7 100644
--- a/arch/powerpc/include/asm/trace.h
+++ b/arch/powerpc/include/asm/trace.h
@@ -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,
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index 8d81c1e7a8db..201be33d9bd3 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -693,6 +693,32 @@ static const struct rtas_function *rtas_token_to_function(s32 token)
/* This is here deliberately so it's only used in this file */
void enter_rtas(unsigned long);
+static inline bool rtas_token_is_open_errinjct(s32 token)
+{
+ return token == rtas_function_token(RTAS_FN_IBM_OPEN_ERRINJCT);
+}
+
+/*
+ * Return the index of the status cell in rets[]. ibm,open-errinjct returns
+ * the session token in rets[0] and the status in rets[1]. Every other RTAS
+ * function returns the status in rets[0].
+ */
+static unsigned int rtas_status_idx(s32 token, u32 nret)
+{
+ return (nret >= 2 && rtas_token_is_open_errinjct(token)) ? 1 : 0;
+}
+
+/* Return the status of a completed call, or 0 if it has no return cells. */
+static int rtas_status_from_args(s32 token, struct rtas_args *args)
+{
+ u32 nret = be32_to_cpu(args->nret);
+
+ if (!nret)
+ return 0;
+
+ return be32_to_cpu(args->rets[rtas_status_idx(token, nret)]);
+}
+
static void __do_enter_rtas(struct rtas_args *args)
{
enter_rtas(__pa(args));
@@ -719,7 +745,9 @@ static void __do_enter_rtas_trace(struct rtas_args *args)
__do_enter_rtas(args);
trace_rtas_ll_exit(args);
- trace_rtas_output(args, func->name);
+ trace_rtas_output(args, func->name,
+ rtas_status_idx(be32_to_cpu(args->token),
+ be32_to_cpu(args->nret)));
}
static void do_enter_rtas(struct rtas_args *args)
@@ -1034,6 +1062,7 @@ static char *__fetch_rtas_last_error(char *altbuf)
save_args = rtas_args;
rtas_args = err_args;
+ rtas_args.rets = &rtas_args.args[2];
do_enter_rtas(&rtas_args);
@@ -1122,20 +1151,28 @@ static bool token_is_restricted_errinjct(s32 token)
* @token: Identifies the function being invoked.
* @nargs: Number of input parameters. Does not include token.
* @nret: Number of output parameters, including the call status.
- * @outputs: Array of @nret output words.
+ * @outputs: Array of @nret - 1 output words, or NULL.
* @....: List of @nargs input parameters.
*
* Invokes the RTAS function indicated by @token, which the caller
* should obtain via rtas_function_token().
*
* The @nargs and @nret arguments must match the number of input and
- * output parameters specified for the RTAS function.
+ * output parameters specified for the RTAS function. @nret includes the
+ * status cell, so @outputs normally receives the remaining @nret - 1
+ * return cells.
*
- * rtas_call() returns RTAS status codes, not conventional Linux errno
- * values. Callers must translate any failure to an appropriate errno
- * in syscall context. Most callers of RTAS functions that can return
- * -2 or 990x should use rtas_busy_delay() to correctly handle those
- * statuses before calling again.
+ * ibm,open-errinjct is the exception: it returns its status in rets[1]
+ * and a session token in rets[0]. rtas_call() still returns the status,
+ * and @outputs[0] receives the session token. @nret must be 2 for this
+ * function; any other value fails with -EINVAL, a Linux errno rather
+ * than an RTAS status, without calling RTAS.
+ *
+ * Apart from that case, rtas_call() returns RTAS status codes, not
+ * conventional Linux errno values. Callers must translate any failure to
+ * an appropriate errno in syscall context. Most callers of RTAS functions
+ * that can return -2 or 990x should use rtas_busy_delay() to correctly
+ * handle those statuses before calling again.
*
* The return value descriptions are adapted from 7.2.8 [RTAS] Return
* Codes of the PAPR and CHRP specifications.
@@ -1198,6 +1235,12 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)
return -1;
}
+ if (rtas_token_is_open_errinjct(token) && nret != 2) {
+ WARN_ONCE(1, "rtas: ibm,open-errinjct requires exactly two return cells (got %d)\n",
+ nret);
+ return -EINVAL;
+ }
+
if ((mfmsr() & (MSR_IR|MSR_DR)) != (MSR_IR|MSR_DR)) {
WARN_ON_ONCE(1);
return -1;
@@ -1215,13 +1258,20 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)
/* 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)
+ if (rtas_status_from_args(token, args) == -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 (rtas_token_is_open_errinjct(token)) {
+ /* nret is 2: rets[0] is the session token, rets[1] the status. */
+ if (outputs)
+ outputs[0] = be32_to_cpu(args->rets[0]);
+ ret = be32_to_cpu(args->rets[1]);
+ } else {
+ 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;
+ }
lockdep_unpin_lock(&rtas_lock, cookie);
raw_spin_unlock_irqrestore(&rtas_lock, flags);
@@ -1904,6 +1954,10 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
return err;
}
+ /* ibm,open-errinjct needs rets[1] for its status. */
+ if (rtas_token_is_open_errinjct(token) && nret < 2)
+ return -EINVAL;
+
/* Need to handle ibm,suspend_me call specially */
if (token == rtas_function_token(RTAS_FN_IBM_SUSPEND_ME)) {
@@ -1939,12 +1993,13 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
cookie = lockdep_pin_lock(&rtas_lock);
rtas_args = args;
+ rtas_args.rets = &rtas_args.args[nargs];
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)
+ if (rtas_status_from_args(token, &args) == -1)
errbuf = __fetch_rtas_last_error(buff_copy);
lockdep_unpin_lock(&rtas_lock, cookie);
--
2.54.0
next prev parent reply other threads:[~2026-11-23 10:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 10:22 [PATCH v7 0/4] powerpc: Add RTAS based error injection support for pSeries Narayana Murty N
2026-11-23 10:22 ` Narayana Murty N [this message]
2026-11-23 10:22 ` [PATCH v7 2/4] powerpc/pseries/eeh: Implement RTAS-based EEH error injection Narayana Murty N
2026-11-23 10:22 ` [PATCH v7 3/4] vfio/spapr_tce: Normalize EEH IOA error injection addresses Narayana Murty N
2026-11-23 10:22 ` [PATCH v7 4/4] powerpc/powernv/eeh: Map generic EEH error types to OPAL Narayana Murty N
-- strict thread matches above, loose matches on Subject: below --
2026-10-23 7:36 [PATCH v6 0/5] powerpc: Add RTAS based error injection support for pSeries Narayana Murty N
2026-11-23 8:46 ` [PATCH v7 1/4] powerpc/rtas: Handle ibm,open-errinjct return format Narayana Murty N
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=20261123102237.95860-7-nnmlinux@linux.ibm.com \
--to=nnmlinux@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=npiggin@gmail.com \
--cc=oohall@gmail.com \
--cc=ritesh.list@gmail.com \
--cc=sbhat@linux.ibm.com \
--cc=sourabhjain@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 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.