cregit-Linux how code gets into the kernel

Release 4.14 arch/powerpc/kernel/fadump.c

/*
 * Firmware Assisted dump: A robust mechanism to get reliable kernel crash
 * dump with assistance from firmware. This approach does not use kexec,
 * instead firmware assists in booting the kdump kernel while preserving
 * memory contents. The most of the code implementation has been adapted
 * from phyp assisted dump implementation written by Linas Vepstas and
 * Manish Ahuja
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Copyright 2011 IBM Corporation
 * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
 */


#undef DEBUG

#define pr_fmt(fmt) "fadump: " fmt

#include <linux/string.h>
#include <linux/memblock.h>
#include <linux/delay.h>
#include <linux/seq_file.h>
#include <linux/crash_dump.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>

#include <asm/debugfs.h>
#include <asm/page.h>
#include <asm/prom.h>
#include <asm/rtas.h>
#include <asm/fadump.h>
#include <asm/setup.h>


static struct fw_dump fw_dump;

static struct fadump_mem_struct fdm;

static const struct fadump_mem_struct *fdm_active;

static DEFINE_MUTEX(fadump_mutex);

struct fad_crash_memory_ranges crash_memory_ranges[INIT_CRASHMEM_RANGES];

int crash_mem_ranges;

/* Scan the Firmware Assisted dump configuration details. */

int __init early_init_dt_scan_fw_dump(unsigned long node, const char *uname, int depth, void *data) { const __be32 *sections; int i, num_sections; int size; const __be32 *token; if (depth != 1 || strcmp(uname, "rtas") != 0) return 0; /* * Check if Firmware Assisted dump is supported. if yes, check * if dump has been initiated on last reboot. */ token = of_get_flat_dt_prop(node, "ibm,configure-kernel-dump", NULL); if (!token) return 1; fw_dump.fadump_supported = 1; fw_dump.ibm_configure_kernel_dump = be32_to_cpu(*token); /* * The 'ibm,kernel-dump' rtas node is present only if there is * dump data waiting for us. */ fdm_active = of_get_flat_dt_prop(node, "ibm,kernel-dump", NULL); if (fdm_active) fw_dump.dump_active = 1; /* Get the sizes required to store dump data for the firmware provided * dump sections. * For each dump section type supported, a 32bit cell which defines * the ID of a supported section followed by two 32 bit cells which * gives teh size of the section in bytes. */ sections = of_get_flat_dt_prop(node, "ibm,configure-kernel-dump-sizes", &size); if (!sections) return 1; num_sections = size / (3 * sizeof(u32)); for (i = 0; i < num_sections; i++, sections += 3) { u32 type = (u32)of_read_number(sections, 1); switch (type) { case FADUMP_CPU_STATE_DATA: fw_dump.cpu_state_data_size = of_read_ulong(&sections[1], 2); break; case FADUMP_HPTE_REGION: fw_dump.hpte_region_size = of_read_ulong(&sections[1], 2); break; } } return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar22196.51%240.00%
Hari Bathini41.75%120.00%
Rob Herring20.87%120.00%
Gavin Shan20.87%120.00%
Total229100.00%5100.00%

/* * If fadump is registered, check if the memory provided * falls within boot memory area. */
int is_fadump_boot_memory_area(u64 addr, ulong size) { if (!fw_dump.dump_registered) return 0; return (addr + size) > RMA_START && addr <= fw_dump.boot_memory_size; }

Contributors

PersonTokensPropCommitsCommitProp
Hari Bathini36100.00%1100.00%
Total36100.00%1100.00%


int should_fadump_crash(void) { if (!fw_dump.dump_registered || !fw_dump.fadumphdr_addr) return 0; return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Nicholas Piggin25100.00%1100.00%
Total25100.00%1100.00%


int is_fadump_active(void) { return fw_dump.dump_active; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar12100.00%2100.00%
Total12100.00%2100.00%

/* * Returns 1, if there are no holes in boot memory area, * 0 otherwise. */
static int is_boot_memory_area_contiguous(void) { struct memblock_region *reg; unsigned long tstart, tend; unsigned long start_pfn = PHYS_PFN(RMA_START); unsigned long end_pfn = PHYS_PFN(RMA_START + fw_dump.boot_memory_size); unsigned int ret = 0; for_each_memblock(memory, reg) { tstart = max(start_pfn, memblock_region_memory_base_pfn(reg)); tend = min(end_pfn, memblock_region_memory_end_pfn(reg)); if (tstart < tend) { /* Memory hole from start_pfn to tstart */ if (tstart > start_pfn) break; if (tend == end_pfn) { ret = 1; break; } start_pfn = tend + 1; } } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Hari Bathini117100.00%1100.00%
Total117100.00%1100.00%

/* Print firmware assisted dump configurations for debugging purpose. */
static void fadump_show_config(void) { pr_debug("Support for firmware-assisted dump (fadump): %s\n", (fw_dump.fadump_supported ? "present" : "no support")); if (!fw_dump.fadump_supported) return; pr_debug("Fadump enabled : %s\n", (fw_dump.fadump_enabled ? "yes" : "no")); pr_debug("Dump Active : %s\n", (fw_dump.dump_active ? "yes" : "no")); pr_debug("Dump section sizes:\n"); pr_debug(" CPU state data size: %lx\n", fw_dump.cpu_state_data_size); pr_debug(" HPTE region size : %lx\n", fw_dump.hpte_region_size); pr_debug("Boot memory size : %lx\n", fw_dump.boot_memory_size); }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar93100.00%2100.00%
Total93100.00%2100.00%


static unsigned long init_fadump_mem_struct(struct fadump_mem_struct *fdm, unsigned long addr) { if (!fdm) return 0; memset(fdm, 0, sizeof(struct fadump_mem_struct)); addr = addr & PAGE_MASK; fdm->header.dump_format_version = cpu_to_be32(0x00000001); fdm->header.dump_num_sections = cpu_to_be16(3); fdm->header.dump_status_flag = 0; fdm->header.offset_first_dump_section = cpu_to_be32((u32)offsetof(struct fadump_mem_struct, cpu_state_data)); /* * Fields for disk dump option. * We are not using disk dump option, hence set these fields to 0. */ fdm->header.dd_block_size = 0; fdm->header.dd_block_offset = 0; fdm->header.dd_num_blocks = 0; fdm->header.dd_offset_disk_path = 0; /* set 0 to disable an automatic dump-reboot. */ fdm->header.max_time_auto = 0; /* Kernel dump sections */ /* cpu state data section. */ fdm->cpu_state_data.request_flag = cpu_to_be32(FADUMP_REQUEST_FLAG); fdm->cpu_state_data.source_data_type = cpu_to_be16(FADUMP_CPU_STATE_DATA); fdm->cpu_state_data.source_address = 0; fdm->cpu_state_data.source_len = cpu_to_be64(fw_dump.cpu_state_data_size); fdm->cpu_state_data.destination_address = cpu_to_be64(addr); addr += fw_dump.cpu_state_data_size; /* hpte region section */ fdm->hpte_region.request_flag = cpu_to_be32(FADUMP_REQUEST_FLAG); fdm->hpte_region.source_data_type = cpu_to_be16(FADUMP_HPTE_REGION); fdm->hpte_region.source_address = 0; fdm->hpte_region.source_len = cpu_to_be64(fw_dump.hpte_region_size); fdm->hpte_region.destination_address = cpu_to_be64(addr); addr += fw_dump.hpte_region_size; /* RMA region section */ fdm->rmr_region.request_flag = cpu_to_be32(FADUMP_REQUEST_FLAG); fdm->rmr_region.source_data_type = cpu_to_be16(FADUMP_REAL_MODE_REGION); fdm->rmr_region.source_address = cpu_to_be64(RMA_START); fdm->rmr_region.source_len = cpu_to_be64(fw_dump.boot_memory_size); fdm->rmr_region.destination_address = cpu_to_be64(addr); addr += fw_dump.boot_memory_size; return addr; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar27785.23%266.67%
Hari Bathini4814.77%133.33%
Total325100.00%3100.00%

/** * fadump_calculate_reserve_size(): reserve variable boot area 5% of System RAM * * Function to find the largest memory size we need to reserve during early * boot process. This will be the size of the memory that is required for a * kernel to boot successfully. * * This function has been taken from phyp-assisted dump feature implementation. * * returns larger of 256MB or 5% rounded down to multiples of 256MB. * * TODO: Come up with better approach to find out more accurate memory size * that is required for a kernel to boot successfully. * */
static inline unsigned long fadump_calculate_reserve_size(void) { int ret; unsigned long long base, size; if (fw_dump.reserve_bootvar) pr_warn("'fadump_reserve_mem=' parameter is deprecated in favor of 'crashkernel=' parameter.\n"); /* * Check if the size is specified through crashkernel= cmdline * option. If yes, then use that but ignore base as fadump reserves * memory at a predefined offset. */ ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &size, &base); if (ret == 0 && size > 0) { unsigned long max_size; if (fw_dump.reserve_bootvar) pr_info("Using 'crashkernel=' parameter for memory reservation.\n"); fw_dump.reserve_bootvar = (unsigned long)size; /* * Adjust if the boot memory size specified is above * the upper limit. */ max_size = memblock_phys_mem_size() / MAX_BOOT_MEM_RATIO; if (fw_dump.reserve_bootvar > max_size) { fw_dump.reserve_bootvar = max_size; pr_info("Adjusted boot memory size to %luMB\n", (fw_dump.reserve_bootvar >> 20)); } return fw_dump.reserve_bootvar; } else if (fw_dump.reserve_bootvar) { /* * 'fadump_reserve_mem=' is being used to reserve memory * for firmware-assisted dump. */ return fw_dump.reserve_bootvar; } /* divide by 20 to get 5% of value */ size = memblock_phys_mem_size() / 20; /* round it down in multiples of 256 */ size = size & ~0x0FFFFFFFUL; /* Truncate to memory_limit. We don't want to over reserve the memory.*/ if (memory_limit && size > memory_limit) size = memory_limit; return (size > MIN_BOOT_MEM ? size : MIN_BOOT_MEM); }

Contributors

PersonTokensPropCommitsCommitProp
Hari Bathini11965.38%466.67%
Mahesh Salgaonkar6334.62%233.33%
Total182100.00%6100.00%

/* * Calculate the total memory size required to be reserved for * firmware-assisted dump registration. */
static unsigned long get_fadump_area_size(void) { unsigned long size = 0; size += fw_dump.cpu_state_data_size; size += fw_dump.hpte_region_size; size += fw_dump.boot_memory_size; size += sizeof(struct fadump_crash_info_header); size += sizeof(struct elfhdr); /* ELF core header.*/ size += sizeof(struct elf_phdr); /* place holder for cpu notes */ /* Program headers for crash memory regions. */ size += sizeof(struct elf_phdr) * (memblock_num_regions(memory) + 2); size = PAGE_ALIGN(size); return size; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar87100.00%4100.00%
Total87100.00%4100.00%


int __init fadump_reserve_mem(void) { unsigned long base, size, memory_boundary; if (!fw_dump.fadump_enabled) return 0; if (!fw_dump.fadump_supported) { printk(KERN_INFO "Firmware-assisted dump is not supported on" " this hardware\n"); fw_dump.fadump_enabled = 0; return 0; } /* * Initialize boot memory size * If dump is active then we have already calculated the size during * first kernel. */ if (fdm_active) fw_dump.boot_memory_size = be64_to_cpu(fdm_active->rmr_region.source_len); else fw_dump.boot_memory_size = fadump_calculate_reserve_size(); /* * Calculate the memory boundary. * If memory_limit is less than actual memory boundary then reserve * the memory for fadump beyond the memory_limit and adjust the * memory_limit accordingly, so that the running kernel can run with * specified memory_limit. */ if (memory_limit && memory_limit < memblock_end_of_DRAM()) { size = get_fadump_area_size(); if ((memory_limit + size) < memblock_end_of_DRAM()) memory_limit += size; else memory_limit = memblock_end_of_DRAM(); printk(KERN_INFO "Adjusted memory_limit for firmware-assisted" " dump, now %#016llx\n", memory_limit); } if (memory_limit) memory_boundary = memory_limit; else memory_boundary = memblock_end_of_DRAM(); if (fw_dump.dump_active) { printk(KERN_INFO "Firmware-assisted dump is active.\n"); /* * If last boot has crashed then reserve all the memory * above boot_memory_size so that we don't touch it until * dump is written to disk by userspace tool. This memory * will be released for general use once the dump is saved. */ base = fw_dump.boot_memory_size; size = memory_boundary - base; memblock_reserve(base, size); printk(KERN_INFO "Reserved %ldMB of memory at %ldMB " "for saving crash dump\n", (unsigned long)(size >> 20), (unsigned long)(base >> 20)); fw_dump.fadumphdr_addr = be64_to_cpu(fdm_active->rmr_region.destination_address) + be64_to_cpu(fdm_active->rmr_region.source_len); pr_debug("fadumphdr_addr = %p\n", (void *) fw_dump.fadumphdr_addr); } else { size = get_fadump_area_size(); /* * Reserve memory at an offset closer to bottom of the RAM to * minimize the impact of memory hot-remove operation. We can't * use memblock_find_in_range() here since it doesn't allocate * from bottom to top. */ for (base = fw_dump.boot_memory_size; base <= (memory_boundary - size); base += size) { if (memblock_is_region_memory(base, size) && !memblock_is_region_reserved(base, size)) break; } if ((base > (memory_boundary - size)) || memblock_reserve(base, size)) { pr_err("Failed to reserve memory\n"); return 0; } pr_info("Reserved %ldMB of memory at %ldMB for firmware-" "assisted dump (System RAM: %ldMB)\n", (unsigned long)(size >> 20), (unsigned long)(base >> 20), (unsigned long)(memblock_phys_mem_size() >> 20)); } fw_dump.reserve_dump_area_start = base; fw_dump.reserve_dump_area_size = size; return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar28377.75%250.00%
Hari Bathini8122.25%250.00%
Total364100.00%4100.00%


unsigned long __init arch_reserved_kernel_pages(void) { return memblock_reserved_size() / PAGE_SIZE; }

Contributors

PersonTokensPropCommitsCommitProp
Srikar Dronamraju15100.00%1100.00%
Total15100.00%1100.00%

/* Look for fadump= cmdline option. */
static int __init early_fadump_param(char *p) { if (!p) return 1; if (strncmp(p, "on", 2) == 0) fw_dump.fadump_enabled = 1; else if (strncmp(p, "off", 3) == 0) fw_dump.fadump_enabled = 0; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar61100.00%1100.00%
Total61100.00%1100.00%

early_param("fadump", early_fadump_param); /* * Look for fadump_reserve_mem= cmdline option * TODO: Remove references to 'fadump_reserve_mem=' parameter, * the sooner 'crashkernel=' parameter is accustomed to. */
static int __init early_fadump_reserve_mem(char *p) { if (p) fw_dump.reserve_bootvar = memparse(p, &p); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Hari Bathini30100.00%1100.00%
Total30100.00%1100.00%

early_param("fadump_reserve_mem", early_fadump_reserve_mem);
static int register_fw_dump(struct fadump_mem_struct *fdm) { int rc, err; unsigned int wait_time; pr_debug("Registering for firmware-assisted kernel dump...\n"); /* TODO: Add upper time limit for the delay */ do { rc = rtas_call(fw_dump.ibm_configure_kernel_dump, 3, 1, NULL, FADUMP_REGISTER, fdm, sizeof(struct fadump_mem_struct)); wait_time = rtas_busy_delay_time(rc); if (wait_time) mdelay(wait_time); } while (wait_time); err = -EIO; switch (rc) { default: pr_err("Failed to register. Unknown Error(%d).\n", rc); break; case -1: printk(KERN_ERR "Failed to register firmware-assisted kernel" " dump. Hardware Error(%d).\n", rc); break; case -3: if (!is_boot_memory_area_contiguous()) pr_err("Can't have holes in boot memory area while " "registering fadump\n"); printk(KERN_ERR "Failed to register firmware-assisted kernel" " dump. Parameter Error(%d).\n", rc); err = -EINVAL; break; case -9: printk(KERN_ERR "firmware-assisted kernel dump is already " " registered."); fw_dump.dump_registered = 1; err = -EEXIST; break; case 0: printk(KERN_INFO "firmware-assisted kernel dump registration" " is successful\n"); fw_dump.dump_registered = 1; err = 0; break; } return err; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar14175.40%250.00%
Michal Suchanek3418.18%125.00%
Hari Bathini126.42%125.00%
Total187100.00%4100.00%


void crash_fadump(struct pt_regs *regs, const char *str) { struct fadump_crash_info_header *fdh = NULL; int old_cpu, this_cpu; if (!should_fadump_crash()) return; /* * old_cpu == -1 means this is the first CPU which has come here, * go ahead and trigger fadump. * * old_cpu != -1 means some other CPU has already on it's way * to trigger fadump, just keep looping here. */ this_cpu = smp_processor_id(); old_cpu = cmpxchg(&crashing_cpu, -1, this_cpu); if (old_cpu != -1) { /* * We can't loop here indefinitely. Wait as long as fadump * is in force. If we race with fadump un-registration this * loop will break and then we go down to normal panic path * and reboot. If fadump is in force the first crashing * cpu will definitely trigger fadump. */ while (fw_dump.dump_registered) cpu_relax(); return; } fdh = __va(fw_dump.fadumphdr_addr); fdh->crashing_cpu = crashing_cpu; crash_save_vmcoreinfo(); if (regs) fdh->regs = *regs; else ppc_save_regs(&fdh->regs); fdh->online_mask = *cpu_online_mask; /* Call ibm,os-term rtas call to trigger firmware assisted dump */ rtas_os_term((char *)str); }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar12597.66%250.00%
Nicholas Piggin21.56%125.00%
Rasmus Villemoes10.78%125.00%
Total128100.00%4100.00%

#define GPR_MASK 0xffffff0000000000
static inline int fadump_gpr_index(u64 id) { int i = -1; char str[3]; if ((id & GPR_MASK) == REG_ID("GPR")) { /* get the digits at the end */ id &= ~GPR_MASK; id >>= 24; str[2] = '\0'; str[1] = id & 0xff; str[0] = (id >> 8) & 0xff; sscanf(str, "%d", &i); if (i > 31) i = -1; } return i; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar100100.00%1100.00%
Total100100.00%1100.00%


static inline void fadump_set_regval(struct pt_regs *regs, u64 reg_id, u64 reg_val) { int i; i = fadump_gpr_index(reg_id); if (i >= 0) regs->gpr[i] = (unsigned long)reg_val; else if (reg_id == REG_ID("NIA")) regs->nip = (unsigned long)reg_val; else if (reg_id == REG_ID("MSR")) regs->msr = (unsigned long)reg_val; else if (reg_id == REG_ID("CTR")) regs->ctr = (unsigned long)reg_val; else if (reg_id == REG_ID("LR")) regs->link = (unsigned long)reg_val; else if (reg_id == REG_ID("XER")) regs->xer = (unsigned long)reg_val; else if (reg_id == REG_ID("CR")) regs->ccr = (unsigned long)reg_val; else if (reg_id == REG_ID("DAR")) regs->dar = (unsigned long)reg_val; else if (reg_id == REG_ID("DSISR")) regs->dsisr = (unsigned long)reg_val; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar207100.00%1100.00%
Total207100.00%1100.00%


static struct fadump_reg_entry* fadump_read_registers(struct fadump_reg_entry *reg_entry, struct pt_regs *regs) { memset(regs, 0, sizeof(struct pt_regs)); while (be64_to_cpu(reg_entry->reg_id) != REG_ID("CPUEND")) { fadump_set_regval(regs, be64_to_cpu(reg_entry->reg_id), be64_to_cpu(reg_entry->reg_value)); reg_entry++; } reg_entry++; return reg_entry; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar6688.00%150.00%
Hari Bathini912.00%150.00%
Total75100.00%2100.00%


static u32 *fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs) { struct elf_prstatus prstatus; memset(&prstatus, 0, sizeof(prstatus)); /* * FIXME: How do i get PID? Do I really need it? * prstatus.pr_pid = ???? */ elf_core_copy_kernel_regs(&prstatus.pr_reg, regs); buf = append_elf_note(buf, CRASH_CORE_NOTE_NAME, NT_PRSTATUS, &prstatus, sizeof(prstatus)); return buf; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar6496.97%150.00%
Hari Bathini23.03%150.00%
Total66100.00%2100.00%


static void fadump_update_elfcore_header(char *bufp) { struct elfhdr *elf; struct elf_phdr *phdr; elf = (struct elfhdr *)bufp; bufp += sizeof(struct elfhdr); /* First note is a place holder for cpu notes info. */ phdr = (struct elf_phdr *)bufp; if (phdr->p_type == PT_NOTE) { phdr->p_paddr = fw_dump.cpu_notes_buf; phdr->p_offset = phdr->p_paddr; phdr->p_filesz = fw_dump.cpu_notes_buf_size; phdr->p_memsz = fw_dump.cpu_notes_buf_size; } return; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar90100.00%1100.00%
Total90100.00%1100.00%


static void *fadump_cpu_notes_buf_alloc(unsigned long size) { void *vaddr; struct page *page; unsigned long order, count, i; order = get_order(size); vaddr = (void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, order); if (!vaddr) return NULL; count = 1 << order; page = virt_to_page(vaddr); for (i = 0; i < count; i++) SetPageReserved(page + i); return vaddr; }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar94100.00%1100.00%
Total94100.00%1100.00%


static void fadump_cpu_notes_buf_free(unsigned long vaddr, unsigned long size) { struct page *page; unsigned long order, count, i; order = get_order(size); count = 1 << order; page = virt_to_page(vaddr); for (i = 0; i < count; i++) ClearPageReserved(page + i); __free_pages(page, order); }

Contributors

PersonTokensPropCommitsCommitProp
Mahesh Salgaonkar74100.00%1100.00%
Total74100.00%1100.00%

/* * Read CPU state dump data and convert it into ELF notes. * The CPU dump starts with magic number "REGSAVE". NumCpusOffset should be * used to access the data to allow for additional fields to be added without * affecting compatibility. Each list of registers for a CPU starts with * "CPUSTRT" and ends with "CPUEND". Each register entry is of 16 bytes, * 8 Byte ASCII identifier and 8 Byte register value. The register entry * with identifier "CPUSTRT" and "CPUEND" contains 4 byte cpu id as part * of register value. For more details refer to PAPR document. * * Only for the crashing cpu we ignore the CPU dump data and get exact * state from fadump crash info structure populated by first kernel at the * time of crash. */
static int __init fadump_build_cpu_notes(const struct fadump_mem_struct *fdm) { struct fadump_reg_save_area_header *reg_header; struct fadump_reg_entry *reg_entry; struct fadump_crash_info_header *fdh = NULL; void *vaddr; unsigned long addr; u32 num_cpus, *note_buf; struct pt_regs regs; int i, rc = 0, cpu = 0; if (!fdm->cpu_state_data.bytes_dumped) return -EINVAL; addr = be64_to_cpu(fdm->cpu_state_data.destination_address); vaddr = __va(addr); reg_header = vaddr; if (be64_to_cpu(reg_header->magic_number) != REGSAVE_AREA_MAGIC) { printk(KERN_ERR "Unable to read register save area.\n"); return -ENOENT; } pr_debug("--------CPU State Data------------\n"); pr_debug("Magic Number: %llx\n", be64_to_cpu(reg_header->magic_number)); pr_debug("NumCpuOffset: %x\n", be32_to_cpu(reg_header->num_cpu_offset)); vaddr += be32_to_cpu(reg_header->num_cpu_offset); num_cpus = be32_to_cpu(*((__be32 *)(vaddr))); pr_debug