Commit f4cac27d authored by Alexander Gordeev's avatar Alexander Gordeev

s390/crash: Use old os_info to create PT_LOAD headers

This is a preparatory rework to allow uncoupling virtual
and physical addresses spaces.

The vmcore ELF program headers describe virtual memory
regions of a crashed kernel. User level tools use that
information for the kernel text and data analysis (e.g
vmcore-dmesg extracts the kernel log).

Currently the kernel image is covered by program headers
describing the identity mapping regions. But in the future
the kernel image will be mapped into separate region outside
of the identity mapping. Create the additional ELF program
header that covers kernel image only, so that vmcore tools
could locate kernel text and data.

Further, the identity mapping in crashed and capture kernels
will have different base address. Due to that __va() macro
can not be used in the capture kernel. Instead, read crashed
kernel identity mapping base address from os_info and use
it for PT_LOAD type program headers creation.
Acked-by: default avatarHeiko Carstens <hca@linux.ibm.com>
Signed-off-by: default avatarAlexander Gordeev <agordeev@linux.ibm.com>
parent 378e32aa
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
#define OS_INFO_VMEMMAP 7 #define OS_INFO_VMEMMAP 7
#define OS_INFO_AMODE31_START 8 #define OS_INFO_AMODE31_START 8
#define OS_INFO_AMODE31_END 9 #define OS_INFO_AMODE31_END 9
#define OS_INFO_IMAGE_START 10
#define OS_INFO_IMAGE_END 11
#define OS_INFO_IMAGE_PHYS 12
#define OS_INFO_FLAG_REIPL_CLEAR (1UL << 0) #define OS_INFO_FLAG_REIPL_CLEAR (1UL << 0)
......
...@@ -465,7 +465,11 @@ static void *ehdr_init(Elf64_Ehdr *ehdr, int mem_chunk_cnt) ...@@ -465,7 +465,11 @@ static void *ehdr_init(Elf64_Ehdr *ehdr, int mem_chunk_cnt)
ehdr->e_phoff = sizeof(Elf64_Ehdr); ehdr->e_phoff = sizeof(Elf64_Ehdr);
ehdr->e_ehsize = sizeof(Elf64_Ehdr); ehdr->e_ehsize = sizeof(Elf64_Ehdr);
ehdr->e_phentsize = sizeof(Elf64_Phdr); ehdr->e_phentsize = sizeof(Elf64_Phdr);
ehdr->e_phnum = mem_chunk_cnt + 1; /*
* Number of memory chunk PT_LOAD program headers plus one kernel
* image PT_LOAD program header plus one PT_NOTE program header.
*/
ehdr->e_phnum = mem_chunk_cnt + 1 + 1;
return ehdr + 1; return ehdr + 1;
} }
...@@ -501,15 +505,16 @@ static int get_mem_chunk_cnt(void) ...@@ -501,15 +505,16 @@ static int get_mem_chunk_cnt(void)
*/ */
static void loads_init(Elf64_Phdr *phdr) static void loads_init(Elf64_Phdr *phdr)
{ {
unsigned long old_identity_base = os_info_old_value(OS_INFO_IDENTITY_BASE);
phys_addr_t start, end; phys_addr_t start, end;
u64 idx; u64 idx;
for_each_physmem_range(idx, &oldmem_type, &start, &end) { for_each_physmem_range(idx, &oldmem_type, &start, &end) {
phdr->p_filesz = end - start;
phdr->p_type = PT_LOAD; phdr->p_type = PT_LOAD;
phdr->p_vaddr = old_identity_base + start;
phdr->p_offset = start; phdr->p_offset = start;
phdr->p_vaddr = (unsigned long)__va(start);
phdr->p_paddr = start; phdr->p_paddr = start;
phdr->p_filesz = end - start;
phdr->p_memsz = end - start; phdr->p_memsz = end - start;
phdr->p_flags = PF_R | PF_W | PF_X; phdr->p_flags = PF_R | PF_W | PF_X;
phdr->p_align = PAGE_SIZE; phdr->p_align = PAGE_SIZE;
...@@ -517,6 +522,25 @@ static void loads_init(Elf64_Phdr *phdr) ...@@ -517,6 +522,25 @@ static void loads_init(Elf64_Phdr *phdr)
} }
} }
/*
* Prepare PT_LOAD type program header for kernel image region
*/
static void text_init(Elf64_Phdr *phdr)
{
unsigned long start_phys = os_info_old_value(OS_INFO_IMAGE_PHYS);
unsigned long start = os_info_old_value(OS_INFO_IMAGE_START);
unsigned long end = os_info_old_value(OS_INFO_IMAGE_END);
phdr->p_type = PT_LOAD;
phdr->p_vaddr = start;
phdr->p_filesz = end - start;
phdr->p_memsz = end - start;
phdr->p_offset = start_phys;
phdr->p_paddr = start_phys;
phdr->p_flags = PF_R | PF_W | PF_X;
phdr->p_align = PAGE_SIZE;
}
/* /*
* Initialize notes (new kernel) * Initialize notes (new kernel)
*/ */
...@@ -557,6 +581,8 @@ static size_t get_elfcorehdr_size(int mem_chunk_cnt) ...@@ -557,6 +581,8 @@ static size_t get_elfcorehdr_size(int mem_chunk_cnt)
size += nt_vmcoreinfo_size(); size += nt_vmcoreinfo_size();
/* nt_final */ /* nt_final */
size += sizeof(Elf64_Nhdr); size += sizeof(Elf64_Nhdr);
/* PT_LOAD type program header for kernel text region */
size += sizeof(Elf64_Phdr);
/* PT_LOADS */ /* PT_LOADS */
size += mem_chunk_cnt * sizeof(Elf64_Phdr); size += mem_chunk_cnt * sizeof(Elf64_Phdr);
...@@ -568,7 +594,7 @@ static size_t get_elfcorehdr_size(int mem_chunk_cnt) ...@@ -568,7 +594,7 @@ static size_t get_elfcorehdr_size(int mem_chunk_cnt)
*/ */
int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size) int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size)
{ {
Elf64_Phdr *phdr_notes, *phdr_loads; Elf64_Phdr *phdr_notes, *phdr_loads, *phdr_text;
size_t alloc_size; size_t alloc_size;
int mem_chunk_cnt; int mem_chunk_cnt;
void *ptr, *hdr; void *ptr, *hdr;
...@@ -606,14 +632,19 @@ int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size) ...@@ -606,14 +632,19 @@ int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size)
/* Init program headers */ /* Init program headers */
phdr_notes = ptr; phdr_notes = ptr;
ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr)); ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr));
phdr_text = ptr;
ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr));
phdr_loads = ptr; phdr_loads = ptr;
ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr) * mem_chunk_cnt); ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr) * mem_chunk_cnt);
/* Init notes */ /* Init notes */
hdr_off = PTR_DIFF(ptr, hdr); hdr_off = PTR_DIFF(ptr, hdr);
ptr = notes_init(phdr_notes, ptr, ((unsigned long) hdr) + hdr_off); ptr = notes_init(phdr_notes, ptr, ((unsigned long) hdr) + hdr_off);
/* Init kernel text program header */
text_init(phdr_text);
/* Init loads */ /* Init loads */
hdr_off = PTR_DIFF(ptr, hdr);
loads_init(phdr_loads); loads_init(phdr_loads);
/* Finalize program headers */
hdr_off = PTR_DIFF(ptr, hdr);
*addr = (unsigned long long) hdr; *addr = (unsigned long long) hdr;
*size = (unsigned long long) hdr_off; *size = (unsigned long long) hdr_off;
BUG_ON(elfcorehdr_size > alloc_size); BUG_ON(elfcorehdr_size > alloc_size);
......
...@@ -81,6 +81,9 @@ void __init os_info_init(void) ...@@ -81,6 +81,9 @@ void __init os_info_init(void)
os_info_entry_add_val(OS_INFO_VMEMMAP, (unsigned long)vmemmap); os_info_entry_add_val(OS_INFO_VMEMMAP, (unsigned long)vmemmap);
os_info_entry_add_val(OS_INFO_AMODE31_START, AMODE31_START); os_info_entry_add_val(OS_INFO_AMODE31_START, AMODE31_START);
os_info_entry_add_val(OS_INFO_AMODE31_END, AMODE31_END); os_info_entry_add_val(OS_INFO_AMODE31_END, AMODE31_END);
os_info_entry_add_val(OS_INFO_IMAGE_START, (unsigned long)_stext);
os_info_entry_add_val(OS_INFO_IMAGE_END, (unsigned long)_end);
os_info_entry_add_val(OS_INFO_IMAGE_PHYS, __pa_symbol(_stext));
os_info.csum = os_info_csum(&os_info); os_info.csum = os_info_csum(&os_info);
abs_lc = get_abs_lowcore(); abs_lc = get_abs_lowcore();
abs_lc->os_info = __pa(&os_info); abs_lc->os_info = __pa(&os_info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment