From: Narayana Murty N <nnmlinux@linux.ibm.com>
To: 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, sourabhjain@linux.ibm.com,
haren@linux.ibm.com, nnmlinux@linux.ibm.com, thuth@redhat.com
Subject: [PATCH v3 2/5] powerpc/rtas: Allocate ibm,errinjct buffer below RTAS limit
Date: Tue, 21 Jul 2026 09:08:02 +0530 [thread overview]
Message-ID: <20260721033815.5300-3-nnmlinux@linux.ibm.com> (raw)
In-Reply-To: <20260721033815.5300-1-nnmlinux@linux.ibm.com>
ibm,errinjct requires a caller-provided work buffer whose physical
address is passed to RTAS firmware.
A static C array such as:
char rtas_errinjct_buf[1024] __aligned(SZ_1K);
only guarantees alignment, not physical placement. If the array lands
above the RTAS-safe range (RTAS_INSTANTIATE_MAX, 1 GB) or above 4 GB,
RTAS receives a truncated or invalid address and the injection call
will fail silently or corrupt memory.
Instead, introduce rtas_errinjct_buf as a global unsigned long storing
the physical address allocated during rtas_initialize() using
memblock_phys_alloc_range() with the same rtas_region upper bound used
for rtas_rmo_buf. This matches the existing placement model for
RTAS-accessible buffers and guarantees the physical address fits in 32
bits.
Usage:
void *buf = __va(rtas_errinjct_buf); /* kernel VA to fill */
u32 buf_phys = lower_32_bits(rtas_errinjct_buf); /* PA for RTAS */
Always check upper_32_bits(rtas_errinjct_buf) == 0 before passing the
lower 32 bits to RTAS.
Add rtas_errinjct_mutex to serialise the complete open-session /
inject / close-session firmware call sequence. A mutex is required
because the sequence involves multiple rtas_call() invocations with
possible busy/extended-delay retries that may sleep.
Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
---
arch/powerpc/include/asm/rtas.h | 26 ++++++++++++++++++++++++++
arch/powerpc/kernel/rtas.c | 17 +++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/arch/powerpc/include/asm/rtas.h b/arch/powerpc/include/asm/rtas.h
index d046bbd5017d..59e3c1296018 100644
--- a/arch/powerpc/include/asm/rtas.h
+++ b/arch/powerpc/include/asm/rtas.h
@@ -4,6 +4,7 @@
#ifdef __KERNEL__
#include <linux/mutex.h>
+#include <linux/sizes.h>
#include <linux/spinlock.h>
#include <asm/page.h>
#include <asm/rtas-types.h>
@@ -519,6 +520,31 @@ int rtas_get_error_log_max(void);
extern spinlock_t rtas_data_buf_lock;
extern char rtas_data_buf[RTAS_DATA_BUF_SIZE];
+/*
+ * RTAS error-injection work buffer.
+ *
+ * ibm,errinjct requires a caller-provided work buffer whose physical
+ * address is passed to firmware. A static C array only guarantees
+ * alignment, not physical placement; if it lands above the RTAS-safe
+ * range or above 4 GB, RTAS receives a truncated or bogus address.
+ *
+ * rtas_errinjct_buf stores the physical address allocated during
+ * rtas_initialize() using memblock_phys_alloc_range() with the same
+ * rtas_region upper bound used for rtas_rmo_buf, matching the existing
+ * placement model for RTAS-accessible buffers.
+ *
+ * Use __va(rtas_errinjct_buf) to obtain the kernel virtual address for
+ * filling the buffer, and lower_32_bits(rtas_errinjct_buf) to pass the
+ * physical address to RTAS (after checking upper_32_bits() == 0).
+ *
+ * rtas_errinjct_mutex must be held across the complete
+ * ibm,open-errinjct / ibm,errinjct / ibm,close-errinjct sequence.
+ */
+#define RTAS_ERRINJCT_BUF_SIZE SZ_1K
+
+extern unsigned long rtas_errinjct_buf;
+extern struct mutex rtas_errinjct_mutex;
+
/* RMO buffer reserved for user-space RTAS use */
extern unsigned long rtas_rmo_buf;
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index 27d53f34494d..7883f973e8c9 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -769,6 +769,17 @@ EXPORT_SYMBOL_GPL(rtas_data_buf);
unsigned long rtas_rmo_buf;
+/*
+ * Physical address of the ibm,errinjct work buffer. Allocated during
+ * rtas_initialize() using memblock_phys_alloc_range() below rtas_region
+ * so the address fits in 32 bits and is safe to pass to RTAS firmware.
+ */
+unsigned long rtas_errinjct_buf;
+EXPORT_SYMBOL_GPL(rtas_errinjct_buf);
+
+DEFINE_MUTEX(rtas_errinjct_mutex);
+EXPORT_SYMBOL_GPL(rtas_errinjct_mutex);
+
/*
* If non-NULL, this gets called when the kernel terminates.
* This is done like this so rtas_flash can be a module.
@@ -2109,6 +2120,12 @@ void __init rtas_initialize(void)
panic("ERROR: RTAS: Failed to allocate %lx bytes below %pa\n",
PAGE_SIZE, &rtas_region);
+ rtas_errinjct_buf = memblock_phys_alloc_range(RTAS_ERRINJCT_BUF_SIZE,
+ SZ_1K, 0, rtas_region);
+ if (!rtas_errinjct_buf)
+ panic("ERROR: RTAS: Failed to allocate %lu bytes below %pa\n",
+ (unsigned long)RTAS_ERRINJCT_BUF_SIZE, &rtas_region);
+
rtas_work_area_reserve_arena(rtas_region);
}
--
2.54.0
next prev parent reply other threads:[~2026-07-21 3:39 UTC|newest]
Thread overview: 6+ 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-07-21 3:38 ` Narayana Murty N [this message]
2026-07-21 3:38 ` [PATCH v3 3/5] powerpc/pseries/eeh: Add RTAS error validation helpers Narayana Murty N
2026-07-21 3:38 ` [PATCH v3 4/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection Narayana Murty N
2026-07-21 3:38 ` [PATCH v3 5/5] powerpc/powernv/eeh: Map VFIO EEH error injection to OPAL 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=20260721033815.5300-3-nnmlinux@linux.ibm.com \
--to=nnmlinux@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=npiggin@gmail.com \
--cc=oohall@gmail.com \
--cc=sbhat@linux.ibm.com \
--cc=sourabhjain@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