Message ID | 20250217071711.83735-6-adityag@linux.ibm.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Implement Firmware Assisted Dump for PSeries | expand |
On Mon Feb 17, 2025 at 5:17 PM AEST, Aditya Gupta wrote: > Platform (ie. QEMU) is expected to pass few device tree properties for > details for fadump: > > * "ibm,configure-kernel-dump": RTAS call for fadump > * "ibm,configure-kernel-dump-sizes": Space required to store dump data > for firmware provided dump sections (ie. CPU & HPTE regions) > * "ibm,configure-kernel-dump-version": Versions of fadump supported > * "ibm,kernel-dump": Contains the Fadump Memory Structure on a fadump > boot > > Implement passing configure-kernel-dump-sizes, and > configure-kernel-dump-version device tree properties, irrespective of > whether it's a fadump boot or not, so that kernel can reserve memory to > store the firmware provided dump sections in case of a crash > > Also, in case of a fadump boot, pass the fadump memory structure to the > kernel in "ibm,kernel-dump" device tree property. > > Signed-off-by: Aditya Gupta <adityag@linux.ibm.com> > --- > hw/ppc/spapr.c | 62 ++++++++++++++++++++++++++++++++++++++++++ > include/hw/ppc/spapr.h | 2 ++ > 2 files changed, 64 insertions(+) > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index f3a4b4235d43..3602e5b5d18d 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -897,9 +897,27 @@ static int spapr_dt_rng(void *fdt) > static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt) > { You might be able to add a spapr_dt_rtas_fadump() function and do it there to help keep functions small? Thanks, Nick > MachineState *ms = MACHINE(spapr); > + MachineClass *mc = MACHINE_GET_CLASS(ms); > int rtas; > GString *hypertas = g_string_sized_new(256); > GString *qemu_hypertas = g_string_sized_new(256); > + uint32_t max_possible_cpus = mc->possible_cpu_arch_ids(ms)->len; > + uint64_t fadump_cpu_state_size = 0; > + uint16_t fadump_versions[2] = { > + FADUMP_VERSION /* min supported version */, > + FADUMP_VERSION /* max supported version */ > + }; > + uint32_t fadump_rgn_sizes[2][3] = { > + { > + cpu_to_be32(FADUMP_CPU_STATE_DATA), > + 0, 0 /* Calculated later */ > + }, > + { > + cpu_to_be32(FADUMP_HPTE_REGION), > + 0, 0 /* HPTE region not implemented */ > + } > + }; > + > uint32_t lrdr_capacity[] = { > 0, > 0, > @@ -1006,6 +1024,50 @@ static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt) > _FDT(fdt_setprop(fdt, rtas, "ibm,lrdr-capacity", > lrdr_capacity, sizeof(lrdr_capacity))); > > + /* > + * CPU State Data contains multiple fields such as header, num_cpus and > + * register entries > + * > + * Calculate the maximum CPU State Data size, according to maximum > + * possible CPUs the QEMU VM can have > + */ > + /* Reg save header */ > + fadump_cpu_state_size += sizeof(struct rtas_fadump_reg_save_area_header); > + > + /* Num_cpus */ > + fadump_cpu_state_size += sizeof(__be32); > + > + /* Register Entries */ > + fadump_cpu_state_size += max_possible_cpus * > + FADUMP_NUM_PER_CPU_REGS * > + sizeof(struct rtas_fadump_reg_entry); > + > + /* Set maximum size for CPU state data region */ > + assert(fadump_rgn_sizes[0][0] == cpu_to_be32(FADUMP_CPU_STATE_DATA)); > + > + /* Upper 32 bits of size, usually 0 */ > + fadump_rgn_sizes[0][1] = cpu_to_be32(fadump_cpu_state_size >> 32); > + > + /* Lower 32 bits of size */ > + fadump_rgn_sizes[0][2] = cpu_to_be32(fadump_cpu_state_size & 0xffffffff); > + > + /* Add device tree properties required from platform for fadump */ > + _FDT((fdt_setprop(fdt, rtas, "ibm,configure-kernel-dump-version", > + fadump_versions, sizeof(fadump_versions)))); > + _FDT((fdt_setprop(fdt, rtas, "ibm,configure-kernel-dump-sizes", > + fadump_rgn_sizes, sizeof(fadump_rgn_sizes)))); > + > + if (is_next_boot_fadump) { > + struct rtas_fadump_mem_struct *fdm = > + &fadump_metadata.registered_fdm; > + > + uint64_t fdm_size = > + sizeof(struct rtas_fadump_section_header) + > + (be16_to_cpu(fdm->header.dump_num_sections) * > + sizeof(struct rtas_fadump_section)); > + > + _FDT((fdt_setprop(fdt, rtas, "ibm,kernel-dump", fdm, fdm_size))); > + } > spapr_dt_rtas_tokens(fdt, rtas); > } > > diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h > index 0e8002bad9e0..fa63008e57ec 100644 > --- a/include/hw/ppc/spapr.h > +++ b/include/hw/ppc/spapr.h > @@ -928,6 +928,8 @@ static inline uint64_t fadump_gpr_id_to_u64(uint32_t gpr_id) > return val; > } > > +extern bool is_next_boot_fadump; > + > struct fadump_metadata { > bool fadump_registered; > bool fadump_dump_active;
On 27/02/25 08:58, Nicholas Piggin wrote: > On Mon Feb 17, 2025 at 5:17 PM AEST, Aditya Gupta wrote: >> <...snip...> >> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c >> index f3a4b4235d43..3602e5b5d18d 100644 >> --- a/hw/ppc/spapr.c >> +++ b/hw/ppc/spapr.c >> @@ -897,9 +897,27 @@ static int spapr_dt_rng(void *fdt) >> static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt) >> { > You might be able to add a spapr_dt_rtas_fadump() function > and do it there to help keep functions small? Sure. Thanks, - Aditya G > Thanks, > Nick
On 2/27/25 08:58, Nicholas Piggin wrote: > On Mon Feb 17, 2025 at 5:17 PM AEST, Aditya Gupta wrote: >> Platform (ie. QEMU) is expected to pass few device tree properties for >> details for fadump: >> >> * "ibm,configure-kernel-dump": RTAS call for fadump >> * "ibm,configure-kernel-dump-sizes": Space required to store dump data >> for firmware provided dump sections (ie. CPU & HPTE regions) >> * "ibm,configure-kernel-dump-version": Versions of fadump supported >> * "ibm,kernel-dump": Contains the Fadump Memory Structure on a fadump >> boot >> >> Implement passing configure-kernel-dump-sizes, and >> configure-kernel-dump-version device tree properties, irrespective of >> whether it's a fadump boot or not, so that kernel can reserve memory to >> store the firmware provided dump sections in case of a crash >> >> Also, in case of a fadump boot, pass the fadump memory structure to the >> kernel in "ibm,kernel-dump" device tree property. >> >> Signed-off-by: Aditya Gupta <adityag@linux.ibm.com> >> --- >> hw/ppc/spapr.c | 62 ++++++++++++++++++++++++++++++++++++++++++ >> include/hw/ppc/spapr.h | 2 ++ >> 2 files changed, 64 insertions(+) >> >> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c >> index f3a4b4235d43..3602e5b5d18d 100644 >> --- a/hw/ppc/spapr.c >> +++ b/hw/ppc/spapr.c >> @@ -897,9 +897,27 @@ static int spapr_dt_rng(void *fdt) >> static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt) >> { > > You might be able to add a spapr_dt_rtas_fadump() function > and do it there to help keep functions small? Ditto. Would look nicer coming from spapr_fadump.[ch] as suggested by Nick earlier. Thanks Harsh > > Thanks, > Nick > >> MachineState *ms = MACHINE(spapr); >> + MachineClass *mc = MACHINE_GET_CLASS(ms); >> int rtas; >> GString *hypertas = g_string_sized_new(256); >> GString *qemu_hypertas = g_string_sized_new(256); >> + uint32_t max_possible_cpus = mc->possible_cpu_arch_ids(ms)->len; >> + uint64_t fadump_cpu_state_size = 0; >> + uint16_t fadump_versions[2] = { >> + FADUMP_VERSION /* min supported version */, >> + FADUMP_VERSION /* max supported version */ >> + }; >> + uint32_t fadump_rgn_sizes[2][3] = { >> + { >> + cpu_to_be32(FADUMP_CPU_STATE_DATA), >> + 0, 0 /* Calculated later */ >> + }, >> + { >> + cpu_to_be32(FADUMP_HPTE_REGION), >> + 0, 0 /* HPTE region not implemented */ >> + } >> + }; >> + >> uint32_t lrdr_capacity[] = { >> 0, >> 0, >> @@ -1006,6 +1024,50 @@ static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt) >> _FDT(fdt_setprop(fdt, rtas, "ibm,lrdr-capacity", >> lrdr_capacity, sizeof(lrdr_capacity))); >> >> + /* >> + * CPU State Data contains multiple fields such as header, num_cpus and >> + * register entries >> + * >> + * Calculate the maximum CPU State Data size, according to maximum >> + * possible CPUs the QEMU VM can have >> + */ >> + /* Reg save header */ >> + fadump_cpu_state_size += sizeof(struct rtas_fadump_reg_save_area_header); >> + >> + /* Num_cpus */ >> + fadump_cpu_state_size += sizeof(__be32); >> + >> + /* Register Entries */ >> + fadump_cpu_state_size += max_possible_cpus * >> + FADUMP_NUM_PER_CPU_REGS * >> + sizeof(struct rtas_fadump_reg_entry); >> + >> + /* Set maximum size for CPU state data region */ >> + assert(fadump_rgn_sizes[0][0] == cpu_to_be32(FADUMP_CPU_STATE_DATA)); >> + >> + /* Upper 32 bits of size, usually 0 */ >> + fadump_rgn_sizes[0][1] = cpu_to_be32(fadump_cpu_state_size >> 32); >> + >> + /* Lower 32 bits of size */ >> + fadump_rgn_sizes[0][2] = cpu_to_be32(fadump_cpu_state_size & 0xffffffff); >> + >> + /* Add device tree properties required from platform for fadump */ >> + _FDT((fdt_setprop(fdt, rtas, "ibm,configure-kernel-dump-version", >> + fadump_versions, sizeof(fadump_versions)))); >> + _FDT((fdt_setprop(fdt, rtas, "ibm,configure-kernel-dump-sizes", >> + fadump_rgn_sizes, sizeof(fadump_rgn_sizes)))); >> + >> + if (is_next_boot_fadump) { >> + struct rtas_fadump_mem_struct *fdm = >> + &fadump_metadata.registered_fdm; >> + >> + uint64_t fdm_size = >> + sizeof(struct rtas_fadump_section_header) + >> + (be16_to_cpu(fdm->header.dump_num_sections) * >> + sizeof(struct rtas_fadump_section)); >> + >> + _FDT((fdt_setprop(fdt, rtas, "ibm,kernel-dump", fdm, fdm_size))); >> + } >> spapr_dt_rtas_tokens(fdt, rtas); >> } >> >> diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h >> index 0e8002bad9e0..fa63008e57ec 100644 >> --- a/include/hw/ppc/spapr.h >> +++ b/include/hw/ppc/spapr.h >> @@ -928,6 +928,8 @@ static inline uint64_t fadump_gpr_id_to_u64(uint32_t gpr_id) >> return val; >> } >> >> +extern bool is_next_boot_fadump; >> + >> struct fadump_metadata { >> bool fadump_registered; >> bool fadump_dump_active; >
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index f3a4b4235d43..3602e5b5d18d 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -897,9 +897,27 @@ static int spapr_dt_rng(void *fdt) static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt) { MachineState *ms = MACHINE(spapr); + MachineClass *mc = MACHINE_GET_CLASS(ms); int rtas; GString *hypertas = g_string_sized_new(256); GString *qemu_hypertas = g_string_sized_new(256); + uint32_t max_possible_cpus = mc->possible_cpu_arch_ids(ms)->len; + uint64_t fadump_cpu_state_size = 0; + uint16_t fadump_versions[2] = { + FADUMP_VERSION /* min supported version */, + FADUMP_VERSION /* max supported version */ + }; + uint32_t fadump_rgn_sizes[2][3] = { + { + cpu_to_be32(FADUMP_CPU_STATE_DATA), + 0, 0 /* Calculated later */ + }, + { + cpu_to_be32(FADUMP_HPTE_REGION), + 0, 0 /* HPTE region not implemented */ + } + }; + uint32_t lrdr_capacity[] = { 0, 0, @@ -1006,6 +1024,50 @@ static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt) _FDT(fdt_setprop(fdt, rtas, "ibm,lrdr-capacity", lrdr_capacity, sizeof(lrdr_capacity))); + /* + * CPU State Data contains multiple fields such as header, num_cpus and + * register entries + * + * Calculate the maximum CPU State Data size, according to maximum + * possible CPUs the QEMU VM can have + */ + /* Reg save header */ + fadump_cpu_state_size += sizeof(struct rtas_fadump_reg_save_area_header); + + /* Num_cpus */ + fadump_cpu_state_size += sizeof(__be32); + + /* Register Entries */ + fadump_cpu_state_size += max_possible_cpus * + FADUMP_NUM_PER_CPU_REGS * + sizeof(struct rtas_fadump_reg_entry); + + /* Set maximum size for CPU state data region */ + assert(fadump_rgn_sizes[0][0] == cpu_to_be32(FADUMP_CPU_STATE_DATA)); + + /* Upper 32 bits of size, usually 0 */ + fadump_rgn_sizes[0][1] = cpu_to_be32(fadump_cpu_state_size >> 32); + + /* Lower 32 bits of size */ + fadump_rgn_sizes[0][2] = cpu_to_be32(fadump_cpu_state_size & 0xffffffff); + + /* Add device tree properties required from platform for fadump */ + _FDT((fdt_setprop(fdt, rtas, "ibm,configure-kernel-dump-version", + fadump_versions, sizeof(fadump_versions)))); + _FDT((fdt_setprop(fdt, rtas, "ibm,configure-kernel-dump-sizes", + fadump_rgn_sizes, sizeof(fadump_rgn_sizes)))); + + if (is_next_boot_fadump) { + struct rtas_fadump_mem_struct *fdm = + &fadump_metadata.registered_fdm; + + uint64_t fdm_size = + sizeof(struct rtas_fadump_section_header) + + (be16_to_cpu(fdm->header.dump_num_sections) * + sizeof(struct rtas_fadump_section)); + + _FDT((fdt_setprop(fdt, rtas, "ibm,kernel-dump", fdm, fdm_size))); + } spapr_dt_rtas_tokens(fdt, rtas); } diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 0e8002bad9e0..fa63008e57ec 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -928,6 +928,8 @@ static inline uint64_t fadump_gpr_id_to_u64(uint32_t gpr_id) return val; } +extern bool is_next_boot_fadump; + struct fadump_metadata { bool fadump_registered; bool fadump_dump_active;
Platform (ie. QEMU) is expected to pass few device tree properties for details for fadump: * "ibm,configure-kernel-dump": RTAS call for fadump * "ibm,configure-kernel-dump-sizes": Space required to store dump data for firmware provided dump sections (ie. CPU & HPTE regions) * "ibm,configure-kernel-dump-version": Versions of fadump supported * "ibm,kernel-dump": Contains the Fadump Memory Structure on a fadump boot Implement passing configure-kernel-dump-sizes, and configure-kernel-dump-version device tree properties, irrespective of whether it's a fadump boot or not, so that kernel can reserve memory to store the firmware provided dump sections in case of a crash Also, in case of a fadump boot, pass the fadump memory structure to the kernel in "ibm,kernel-dump" device tree property. Signed-off-by: Aditya Gupta <adityag@linux.ibm.com> --- hw/ppc/spapr.c | 62 ++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 2 ++ 2 files changed, 64 insertions(+)