Skip to content

Commit

Permalink
mpipl: Rework memory reservation for OPAL dump
Browse files Browse the repository at this point in the history
During boot, OPAL reserves memory required to capture OPAL dump and
architected register data. During MPIPL, hostboot will copy OPAL dump
to this memory. Post MPIPL kernel will use this memory to create opalcore.
We use mem_reserve_fw() for this reservation. At present this reservation
happens late in the init path. It may clash with memory allocated by
local_alloc().

We have two option to fix above issue:
  - Use local_alloc() for allocating memory for OPAL dump
    This works fine on first boot. We can use this method to reserve
    memory. But Post MPIPL we still want to reserve destination
    memory to make sure no one is stomping this area. Also this reservation
    might have happened in between other local_allocations. So in Post MPIPL
    boot allocator may not find enough memory in first region for other
    local_alloc() requests and may throw mem_alloc() error before trying to
    allocate from other regions.

  - Early memory reservation for OPAL dump
    Allocate and reserve memory just after memory region init.

This patch uses second approach to fix reservation issue.

Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
  • Loading branch information
Vasant Hegde authored and oohal committed Feb 12, 2020
1 parent 958769d commit b0e0242
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
7 changes: 7 additions & 0 deletions core/init.c
Expand Up @@ -1150,6 +1150,13 @@ void __noreturn __nomcount main_cpu_entry(const void *fdt)
*/
mem_region_init();

/*
* Reserve memory required to capture OPAL dump. This should be done
* immediately after mem_region_init to avoid any clash with local
* memory allocation.
*/
opal_mpipl_reserve_mem();

/* Reserve HOMER and OCC area */
homer_init();

Expand Down
53 changes: 30 additions & 23 deletions core/opal-dump.c
Expand Up @@ -65,6 +65,7 @@ static struct opal_mpipl_fadump *opal_mpipl_cpu_data;
static u64 opal_mpipl_tags[MAX_OPAL_MPIPL_TAGS];
static int opal_mpipl_max_tags = MAX_OPAL_MPIPL_TAGS;

static u64 opal_dump_addr, opal_dump_size;

static int opal_mpipl_add_entry(u8 region, u64 src, u64 dest, u64 size)
{
Expand Down Expand Up @@ -230,42 +231,22 @@ static int opal_mpipl_remove_entry_mddt(bool remove_all, u8 region, u64 dest)
/* Register for OPAL dump. */
static void opal_mpipl_register(void)
{
u64 opal_dest, opal_size;
u64 arch_regs_dest, arch_regs_size;
struct proc_dump_area *proc_dump = (void *)(PROC_DUMP_AREA_BASE);

/* Get OPAL runtime size */
if (!dt_find_property(opal_node, "opal-runtime-size")) {
prlog(PR_DEBUG, "Could not get OPAL runtime size\n");
return;
}
opal_size = dt_prop_get_u64(opal_node, "opal-runtime-size");
if (!opal_size) {
prlog(PR_DEBUG, "OPAL runtime size is zero\n");
return;
}

/* Calculate and reserve OPAL dump destination memory */
opal_dest = SKIBOOT_BASE + opal_size;
mem_reserve_fw("ibm,firmware-dump", opal_dest, opal_size);

/* Add OPAL reservation detail to MDST/MDDT table */
opal_mpipl_add_entry(DUMP_REGION_OPAL_MEMORY,
SKIBOOT_BASE, opal_dest, opal_size);
SKIBOOT_BASE, opal_dump_addr, opal_dump_size);

/* Thread size check */
if (proc_dump->thread_size != 0) {
prlog(PR_INFO, "Thread register entry size is available, "
"but not supported.\n");
}

/* Calculate memory to capture CPU register data */
arch_regs_dest = opal_dest + opal_size;
arch_regs_size = nr_chips() * ARCH_REGS_DATA_SIZE_PER_CHIP;

/* Reserve memory used to capture architected register state */
mem_reserve_fw("ibm,firmware-arch-registers",
arch_regs_dest, arch_regs_size);
arch_regs_dest = opal_dump_addr + opal_dump_size;
arch_regs_size = nr_chips() * ARCH_REGS_DATA_SIZE_PER_CHIP;
proc_dump->alloc_addr = cpu_to_be64(arch_regs_dest | HRMOR_BIT);
proc_dump->alloc_size = cpu_to_be32(arch_regs_size);
prlog(PR_NOTICE, "Architected register dest addr : 0x%llx, "
Expand Down Expand Up @@ -510,6 +491,32 @@ void opal_mpipl_save_crashing_pir(void)
prlog(PR_NOTICE, "Crashing PIR = 0x%x\n", this_cpu()->pir);
}

void opal_mpipl_reserve_mem(void)
{
struct dt_node *opal_node, *dump_node;
u64 arch_regs_dest, arch_regs_size;

opal_node = dt_find_by_path(dt_root, "ibm,opal");
if (!opal_node)
return;

dump_node = dt_find_by_path(opal_node, "dump");
if (!dump_node)
return;

/* Calculcate and Reserve OPAL dump destination memory */
opal_dump_size = SKIBOOT_SIZE + (cpu_max_pir + 1) * STACK_SIZE;
opal_dump_addr = SKIBOOT_BASE + opal_dump_size;
mem_reserve_fw("ibm,firmware-dump",
opal_dump_addr, opal_dump_size);

/* Reserve memory to capture CPU register data */
arch_regs_dest = opal_dump_addr + opal_dump_size;
arch_regs_size = nr_chips() * ARCH_REGS_DATA_SIZE_PER_CHIP;
mem_reserve_fw("ibm,firmware-arch-registers",
arch_regs_dest, arch_regs_size);
}

void opal_mpipl_init(void)
{
void *mdst_base = (void *)MDST_TABLE_BASE;
Expand Down
3 changes: 3 additions & 0 deletions include/opal-dump.h
Expand Up @@ -124,4 +124,7 @@ extern void opal_mpipl_init(void);
/* Save metadata before triggering MPIPL */
void opal_mpipl_save_crashing_pir(void);

/* Reserve memory to capture OPAL dump */
extern void opal_mpipl_reserve_mem(void);

#endif /* __OPAL_DUMP_H */

0 comments on commit b0e0242

Please sign in to comment.