From: Aditya Gupta <adityag@linux.ibm.com>
To: Harsh Prateek Bora <harshpb@linux.ibm.com>, qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, "Nicholas Piggin" <npiggin@gmail.com>,
"Frédéric Barrat" <fbarrat@linux.ibm.com>,
"Sourabh Jain" <sourabhjain@linux.ibm.com>,
"Mahesh J Salgaonkar" <mahesh@linux.ibm.com>,
"Hari Bathini" <hbathini@linux.ibm.com>
Subject: Re: [PATCH 5/7] hw/ppc: Preserve Memory Regions as per MDST/MDDT tables
Date: Fri, 14 Mar 2025 00:24:40 +0530 [thread overview]
Message-ID: <d411009c-8ee0-4889-97e2-85b27808c9cd@linux.ibm.com> (raw)
In-Reply-To: <d14b0a3b-6a74-4c55-8836-32def5504614@linux.ibm.com>
On 11/03/25 10:48, Harsh Prateek Bora wrote:
>
> On 2/17/25 12:49, Aditya Gupta wrote:
>> When MPIPL is used, OPAL/Linux registers memory regions to be preserved
>> on a Memory-Preserving boot ('crashkernel boot').
>>
>> The regions are added to two tables: MDST and MDDT (source and
>> destination tables)
>>
>> The MDST contains the start address of the region, and size of region
>>
>> The MDDT contains the destination address where the region should be
>> copied (and size of region which will be same as in MDST entry)
>>
>> Then after a crash, when hostboot (pnv_sbe.c in case of QEMU)
>> preserves the memory region, it adds the details of preserved regions to
>> MDRT (results table)
>>
>> Copy memory regions mentioned in MDST to addresses mentioned in MDDT.
>> And accordingly update the copied region details in MDRT table.
>>
>> Note: If we did not preserve the regions, and MDRT is empty then OPAL
>> simply logs "OPAL dump is not available", while kernel will assume that
>> firmware would have preserved the regions, and export /proc/vmcore, but
>> the vmcore won't have most basic kernel structures hence crash will be
>> unable to analyse the vmcore
>>
>> Signed-off-by: Aditya Gupta <adityag@linux.ibm.com>
>> ---
>> hw/ppc/pnv_sbe.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 57 insertions(+)
>>
>> diff --git a/hw/ppc/pnv_sbe.c b/hw/ppc/pnv_sbe.c
>> index 361a3854307d..ee905df4e0a6 100644
>> --- a/hw/ppc/pnv_sbe.c
>> +++ b/hw/ppc/pnv_sbe.c
>> @@ -227,6 +227,60 @@ static uint64_t
>> pnv_sbe_power9_xscom_ctrl_read(void *opaque, hwaddr addr,
>> return val;
>> }
>> +static void pnv_mpipl_preserve_mem(void)
>> +{
>> + /* Get access to metadata */
>> + struct mpipl_metadata *metadata = malloc(DUMP_METADATA_AREA_SIZE);
>> + struct mdst_table *mdst = malloc(MDST_TABLE_SIZE);
>> + struct mddt_table *mddt = malloc(MDDT_TABLE_SIZE);
>> + struct mdrt_table *mdrt = malloc(MDRT_TABLE_SIZE);
>
> Where are these getting free()ed? Mem leak ?
Yes. Thanks for catching this, it's a memory leak, will free it in v2.
>
>> + __be64 source_addr, dest_addr, bytes_to_copy;
>> + uint8_t *copy_buffer;
>> +
>> + cpu_physical_memory_read(DUMP_METADATA_AREA_BASE, metadata,
>> DUMP_METADATA_AREA_SIZE);
>> + cpu_physical_memory_read(MDST_TABLE_BASE, mdst, MDST_TABLE_SIZE);
>> + cpu_physical_memory_read(MDDT_TABLE_BASE, mddt, MDDT_TABLE_SIZE);
>> +
>> + /* HRMOR_BIT copied from skiboot */
>> + #define HRMOR_BIT (1ul << 63)
> Could be moved to pnv_sbe.h file.
Okay.
>
>> +
>> + for (int i = 0;; ++i) {
>> + /* NOTE: Assuming uninitialised will be all zeroes */
>> + if ((mdst[i].addr == 0) && (mdst[i].size == 0)) {
>> + break;
>> + }
>
> What if there is no uninitialized entry till the end of array?
> Out-of-bound access since we do not have a loop exit condition?
My bad, didn't handle that. Will limit the loop to at max MDST_MAX_SIZE
/ MDST_ENTRY_SIZE
>
>> +
>> + if (mdst[i].size != mddt[i].size) {
>> + qemu_log_mask(LOG_TRACE,
>> + "Warning: Invalid entry, size mismatch in MDST &
>> MDDT\n");
>> + continue;
>> + }
>> +
>> + if (mdst[i].data_region != mddt[i].data_region) {
>> + qemu_log_mask(LOG_TRACE,
>> + "Warning: Invalid entry, region mismatch in MDST
>> & MDDT\n");
>> + continue;
>> + }
>> +
>> + mdrt[i].src_addr = mdst[i].addr;
>> + mdrt[i].dest_addr = mddt[i].addr;
>> + mdrt[i].size = mdst[i].size;
>> + mdrt[i].data_region = mdst[i].data_region;
>> +
>> + source_addr = cpu_to_be64(mdst[i].addr) & ~HRMOR_BIT;
>> + dest_addr = cpu_to_be64(mddt[i].addr) & ~HRMOR_BIT;
>> + bytes_to_copy = cpu_to_be32(mddt[i].size);
>> +
>> + /* XXX: Am i assuming we are in big endian mode ? */
> If the patches are assuming to work only with BE, it should gracefully
> handle the LE case.
Agreed, I have to fix it, so it works in both cases, will handle with
enough cpu_to_be* for values coming from the firmware/kernel.
Thanks,
- Aditya G
>
> Thanks
> Harsh
>
>> + copy_buffer = malloc(bytes_to_copy);
>> + cpu_physical_memory_read(source_addr, copy_buffer,
>> bytes_to_copy);
>> + cpu_physical_memory_write(dest_addr, copy_buffer,
>> bytes_to_copy);
>> + free(copy_buffer);
>> + }
>> +
>> + cpu_physical_memory_write(MDRT_TABLE_BASE, mdrt, MDRT_TABLE_SIZE);
>> +}
>> +
>> static void pnv_sbe_power9_xscom_ctrl_write(void *opaque, hwaddr addr,
>> uint64_t val, unsigned size)
>> {
>> @@ -250,6 +304,9 @@ static void pnv_sbe_power9_xscom_ctrl_write(void
>> *opaque, hwaddr addr,
>> */
>> pause_all_vcpus();
>> + /* Preserve the memory locations registered for MPIPL */
>> + pnv_mpipl_preserve_mem();
>> +
>> /*
>> * TODO: Pass `mpipl` node in device tree to signify next
>> * boot is an MPIPL boot
next prev parent reply other threads:[~2025-03-13 18:55 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-17 7:19 [PATCH 0/7] Implement MPIPL for PowerNV Aditya Gupta
2025-02-17 7:19 ` [PATCH 1/7] hw/ppc: Log S0/S1 Interrupt triggers by OPAL Aditya Gupta
2025-03-11 4:38 ` Harsh Prateek Bora
2025-03-13 18:43 ` Aditya Gupta
2025-02-17 7:19 ` [PATCH 2/7] hw/ppc: Implement S0 SBE interrupt as cpu_pause then host reset Aditya Gupta
2025-03-11 4:45 ` Harsh Prateek Bora
2025-03-13 18:45 ` Aditya Gupta
2025-02-17 7:19 ` [PATCH 3/7] hw/ppc: Handle stash command in PowerNV SBE Aditya Gupta
2025-03-11 4:50 ` Harsh Prateek Bora
2025-03-13 18:46 ` Aditya Gupta
2025-02-17 7:19 ` [PATCH 4/7] hw/ppc: Add MDST/MDDT/MDRT table structures and offsets Aditya Gupta
2025-03-11 5:11 ` Harsh Prateek Bora
2025-03-13 18:50 ` Aditya Gupta
2025-02-17 7:19 ` [PATCH 5/7] hw/ppc: Preserve Memory Regions as per MDST/MDDT tables Aditya Gupta
2025-03-11 5:18 ` Harsh Prateek Bora
2025-03-13 18:54 ` Aditya Gupta [this message]
2025-02-17 7:19 ` [PATCH 6/7] hw/ppc: [WIP] Add Processor Dump Area offsets in Pnv SBE Aditya Gupta
2025-03-11 5:23 ` Harsh Prateek Bora
2025-03-13 18:56 ` Aditya Gupta
2025-02-17 7:19 ` [PATCH 7/7] hw/ppc: Implement MPIPL in PowerNV Aditya Gupta
2025-03-11 5:41 ` Harsh Prateek Bora
2025-03-13 19:00 ` Aditya Gupta
2025-02-27 3:37 ` [PATCH 0/7] Implement MPIPL for PowerNV Nicholas Piggin
2025-02-27 6:23 ` Aditya Gupta
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=d411009c-8ee0-4889-97e2-85b27808c9cd@linux.ibm.com \
--to=adityag@linux.ibm.com \
--cc=fbarrat@linux.ibm.com \
--cc=harshpb@linux.ibm.com \
--cc=hbathini@linux.ibm.com \
--cc=mahesh@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=sourabhjain@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;
as well as URLs for NNTP newsgroup(s).