From: Harsh Prateek Bora <harshpb@linux.ibm.com>
To: Aditya Gupta <adityag@linux.ibm.com>, qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, Nicholas Piggin <npiggin@gmail.com>,
Daniel Henrique Barboza <danielhb413@gmail.com>,
Sourabh Jain <sourabhjain@linux.ibm.com>,
Mahesh J Salgaonkar <mahesh@linux.ibm.com>,
Hari Bathini <hbathini@linux.ibm.com>
Subject: Re: [PATCH 3/6] hw/ppc: Preserve memory regions registered for fadump
Date: Wed, 5 Mar 2025 12:10:35 +0530 [thread overview]
Message-ID: <f5494f6f-599f-427b-8c37-42cc5396c35d@linux.ibm.com> (raw)
In-Reply-To: <20250217071711.83735-4-adityag@linux.ibm.com>
On 2/17/25 12:47, Aditya Gupta wrote:
> While the first kernel boots, it registers memory regions for fadump
> such as:
> * CPU state data (has to be populated by the platform)
> * HPTE state data (has to be populated by the platform)
> * Real Mode Regions (platform should copy it to requested
> destination addresses)
> * OS defined regions (such as parameter save area)
>
> Platform is also expected to modify the 'bytes_dumped' to the length of
> data preserved/copied by platform (ideally same as the source length
> passed by kernel).
>
> The kernel passes source address and length for the memory regions, and
> a destination address to where the memory is to be copied.
>
> Implement the preserving/copying of the Real Mode Regions and the
> Parameter Save Area in QEMU Pseries
>
> Signed-off-by: Aditya Gupta <adityag@linux.ibm.com>
> ---
> hw/ppc/spapr_rtas.c | 117 ++++++++++++++++++++++++++++++++++++++++-
> include/hw/ppc/spapr.h | 27 +++++++++-
> 2 files changed, 142 insertions(+), 2 deletions(-)
>
> diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
> index 01c82375f03d..9b29cadab2c9 100644
> --- a/hw/ppc/spapr_rtas.c
> +++ b/hw/ppc/spapr_rtas.c
> @@ -344,6 +344,120 @@ static void rtas_ibm_set_system_parameter(PowerPCCPU *cpu,
> struct fadump_metadata fadump_metadata;
> bool is_next_boot_fadump;
>
> +/* Preserve the memory locations registered for fadump */
> +static bool fadump_preserve_mem(void)
> +{
> + struct rtas_fadump_mem_struct *fdm = &fadump_metadata.registered_fdm;
> + uint64_t next_section_addr;
> + int dump_num_sections, data_type;
> + uint64_t src_addr, src_len, dest_addr;
> + void *copy_buffer;
> +
> + assert(fadump_metadata.fadump_registered);
> + assert(fadump_metadata.fdm_addr != -1);
> +
> + /* Read the fadump header passed during fadump registration */
> + cpu_physical_memory_read(fadump_metadata.fdm_addr,
> + &fdm->header, sizeof(fdm->header));
> +
> + /* Verify that we understand the fadump header version */
> + if (fdm->header.dump_format_version != cpu_to_be32(FADUMP_VERSION)) {
> + /*
> + * Dump format version is unknown and likely changed from the time
> + * of fadump registration. Back out now.
> + */
> + return false;
> + }
> +
> + dump_num_sections = be16_to_cpu(fdm->header.dump_num_sections);
> +
> + if (dump_num_sections > FADUMP_MAX_SECTIONS) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "FADUMP: Too many sections: %d\n", fdm->header.dump_num_sections);
> + return false;
> + }
> +
> + next_section_addr =
> + fadump_metadata.fdm_addr +
> + be32_to_cpu(fdm->header.offset_first_dump_section);
> +
> + /*
> + * Handle all sections
> + *
> + * CPU State Data and HPTE regions are handled in their own cases
> + *
> + * RMR regions and any custom OS reserved regions such as parameter
> + * save area, are handled by simply copying the source region to
> + * destination address
> + */
> + for (int i = 0; i < dump_num_sections; ++i) {
> + /* Read the fadump section from memory */
> + cpu_physical_memory_read(next_section_addr,
> + &fdm->rgn[i], sizeof(fdm->rgn[i]));
> +
> + next_section_addr += sizeof(fdm->rgn[i]);
> +
> + data_type = be16_to_cpu(fdm->rgn[i].source_data_type);
> + src_addr = be64_to_cpu(fdm->rgn[i].source_address);
> + src_len = be64_to_cpu(fdm->rgn[i].source_len);
> + dest_addr = be64_to_cpu(fdm->rgn[i].destination_address);
> +
> + /* Reset error_flags & bytes_dumped for now */
> + fdm->rgn[i].error_flags = 0;
> + fdm->rgn[i].bytes_dumped = 0;
> +
> + if (be32_to_cpu(fdm->rgn[i].request_flag) != FADUMP_REQUEST_FLAG) {
> + qemu_log_mask(LOG_UNIMP,
> + "FADUMP: Skipping copying region as not requested\n");
> + continue;
> + }
> +
> + switch (data_type) {
> + case FADUMP_CPU_STATE_DATA:
> + /* TODO: Add CPU state data */
> + break;
> + case FADUMP_HPTE_REGION:
> + /* TODO: Add hpte state data */
> + break;
> + case FADUMP_REAL_MODE_REGION:
> + case FADUMP_PARAM_AREA:
> + /* Skip copy if source and destination are same (eg. param area) */
> + if (src_addr != dest_addr) {
> + copy_buffer = g_malloc(src_len + 1);
> + if (copy_buffer == NULL) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "FADUMP: Failed allocating memory for copying reserved memory regions\n");
> + fdm->rgn[i].error_flags =
> + cpu_to_be16(FADUMP_ERROR_LENGTH_EXCEEDS_SOURCE);
> +
> + continue;
> + }
> +
> + /* Copy the source region to destination */
> + cpu_physical_memory_read(src_addr, copy_buffer, src_len);
> + cpu_physical_memory_write(dest_addr, copy_buffer, src_len);
> + g_free(copy_buffer);
> + }
> +
> + /*
> + * Considering cpu_physical_memory_write would have copied the
> + * complete region
> + */
> + fdm->rgn[i].bytes_dumped = cpu_to_be64(src_len);
Is this really valid for FADUMP_PARAM_AREA where we intend to skip copy?
> +
> + break;
> + default:
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "FADUMP: Skipping unknown source data type: %d\n", data_type);
> +
> + fdm->rgn[i].error_flags =
> + cpu_to_be16(FADUMP_ERROR_INVALID_DATA_TYPE);
> + }
> + }
> +
> + return true;
> +}
> +
> static void trigger_fadump_boot(target_ulong spapr_retcode)
> {
> /*
> @@ -353,7 +467,8 @@ static void trigger_fadump_boot(target_ulong spapr_retcode)
> */
> pause_all_vcpus();
>
> - if (true /* TODO: Preserve memory registered for fadump */) {
> + /* Preserve the memory locations registered for fadump */
> + if (!fadump_preserve_mem()) {
This change can be avoided as suggested in previous patch.
> /* Failed to preserve the registered memory regions */
> rtas_st(spapr_retcode, 0, RTAS_OUT_HW_ERROR);
>
> diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
> index efa2f891a8a7..a80704187583 100644
> --- a/include/hw/ppc/spapr.h
> +++ b/include/hw/ppc/spapr.h
> @@ -776,7 +776,32 @@ void push_sregs_to_kvm_pr(SpaprMachineState *spapr);
> #define FADUMP_CMD_UNREGISTER 2
> #define FADUMP_CMD_INVALIDATE 3
>
> -#define FADUMP_VERSION 1
> +#define FADUMP_VERSION 1
This change can be avoided if taken care initially.
Thanks
Harsh
> +
> +/*
> + * The Firmware Assisted Dump Memory structure supports a maximum of 10 sections
> + * in the dump memory structure. Presently, three sections are used for
> + * CPU state data, HPTE & Parameters area, while the remaining seven sections
> + * can be used for boot memory regions.
> + */
> +#define FADUMP_MAX_SECTIONS 10
> +#define RTAS_FADUMP_MAX_BOOT_MEM_REGS 7
> +
> +/* Firmware provided dump sections */
> +#define FADUMP_CPU_STATE_DATA 0x0001
> +#define FADUMP_HPTE_REGION 0x0002
> +#define FADUMP_REAL_MODE_REGION 0x0011
> +
> +/* OS defined sections */
> +#define FADUMP_PARAM_AREA 0x0100
> +
> +/* Dump request flag */
> +#define FADUMP_REQUEST_FLAG 0x00000001
> +
> +/* Dump status flag */
> +#define FADUMP_ERROR_INVALID_DATA_TYPE 0x8000
> +#define FADUMP_ERROR_INVALID_SOURCE_ADDR 0x4000
> +#define FADUMP_ERROR_LENGTH_EXCEEDS_SOURCE 0x2000
>
> /*
> * The Firmware Assisted Dump Memory structure supports a maximum of 10 sections
next prev parent reply other threads:[~2025-03-05 6:41 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-17 7:17 [PATCH 0/6] Implement Firmware Assisted Dump for PSeries Aditya Gupta
2025-02-17 7:17 ` [PATCH 1/6] hw/ppc: Implement skeleton code for fadump in PSeries Aditya Gupta
2025-02-27 3:07 ` Nicholas Piggin
2025-02-27 6:49 ` Aditya Gupta
2025-02-27 8:48 ` Nicholas Piggin
2025-02-27 12:15 ` Aditya Gupta
2025-03-04 9:01 ` Harsh Prateek Bora
2025-03-06 4:08 ` Aditya Gupta
2025-02-17 7:17 ` [PATCH 2/6] hw/ppc: Trigger Fadump boot if fadump is registered Aditya Gupta
2025-02-27 3:14 ` Nicholas Piggin
2025-02-27 6:56 ` Aditya Gupta
2025-03-04 9:21 ` Harsh Prateek Bora
2025-03-06 4:11 ` Aditya Gupta
2025-02-17 7:17 ` [PATCH 3/6] hw/ppc: Preserve memory regions registered for fadump Aditya Gupta
2025-03-05 6:40 ` Harsh Prateek Bora [this message]
2025-03-06 4:16 ` Aditya Gupta
2025-02-17 7:17 ` [PATCH 4/6] hw/ppc: Implement saving CPU state in Fadump Aditya Gupta
2025-02-27 3:27 ` Nicholas Piggin
2025-02-27 7:01 ` Aditya Gupta
2025-03-05 7:23 ` Harsh Prateek Bora
2025-03-06 4:22 ` Aditya Gupta
2025-02-17 7:17 ` [PATCH 5/6] hw/ppc: Pass device tree properties for Fadump Aditya Gupta
2025-02-27 3:28 ` Nicholas Piggin
2025-02-27 7:02 ` Aditya Gupta
2025-03-05 7:34 ` Harsh Prateek Bora
2025-02-17 7:17 ` [PATCH 6/6] hw/ppc: Enable Fadump for PSeries Aditya Gupta
2025-02-27 3:33 ` Nicholas Piggin
2025-02-27 7:07 ` Aditya Gupta
2025-02-27 8:52 ` Nicholas Piggin
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=f5494f6f-599f-427b-8c37-42cc5396c35d@linux.ibm.com \
--to=harshpb@linux.ibm.com \
--cc=adityag@linux.ibm.com \
--cc=danielhb413@gmail.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).