mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Narayana Murty N <nnmlinux@linux.ibm.com>
To: Sourabh Jain <sourabhjain@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 2/5] powerpc/rtas: Allocate ibm,errinjct buffer below RTAS limit
Date: Mon, 31 Aug 2026 20:24:59 +0530	[thread overview]
Message-ID: <d43bd71d-d5a3-45df-bf49-8a5e617061ac@linux.ibm.com> (raw)
In-Reply-To: <9c12964a-f35a-464a-8e65-e0e9fa674819@linux.ibm.com>

Hi Sourabh,

On 04/08/26 12:52 PM, Sourabh Jain wrote:
> Hello Narayana,
> 
> How about using the rtas_work_area_alloc() instead of allocating a new 
> dedicated buffer
> for errinjct only?
> 
> Checkout Commit 43033bc62d34 ("powerpc/pseries: add RTAS work area 
> allocator") for
> infrastructure to allocated working buffer.
> 
> Also checkout commit e27e14231eb5 ("powerpc/pseries/dlpar: use RTAS work 
> area API")
> on how to use work area API.
> 
Agreed. I reworked this in v4 to use the RTAS work area allocator 
instead of adding a dedicated global rtas_errinjct_buf.

The v3 approach allocated a separate error-injection buffer during
rtas_initialize(), but that is not necessary now that the RTAS work area
allocator already provides the right infrastructure for RTAS-accessible 
working buffers.

In v4, the pseries error-injection path allocates a work area for the 
RTAS parameter buffer, fills it using the mapped kernel address, passes 
the RTAS-visible physical address to firmware, and frees the work area 
after the open/inject/close sequence.

This also removes the extra global buffer only for error injection.

Thanks,
Narayana

> - Sourabh Jain
> 
> On 21/07/26 09:08, Narayana Murty N wrote:
>> 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);
>>   }
> 


  reply	other threads:[~2026-08-31 14:55 UTC|newest]

Thread overview: 19+ 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-08-31 14:46     ` Narayana Murty N
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-08-31 14:54     ` 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-08-04 18:05   ` Sourabh Jain
2026-08-31 15:05     ` 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-08-04 18:26   ` Sourabh Jain
2026-08-31 15:09     ` 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
2026-08-04 18:31   ` Sourabh Jain
2026-08-05  6:23     ` Narayana Murty N
2026-08-09 12:00       ` Sourabh Jain
2026-08-18 11:01 ` [PATCH v3 0/5] powerpc/eeh: Add RTAS-based error injection support on pSeries Anushree Mathur
2026-08-26  9:11   ` 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=d43bd71d-d5a3-45df-bf49-8a5e617061ac@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

all inboxes | Powered by JetHome®