2005-06-25 21:58:21 +00:00
|
|
|
/*
|
|
|
|
* fs/proc/vmcore.c Interface for accessing the crash
|
|
|
|
* dump from the system's previous life.
|
|
|
|
* Heavily borrowed from fs/proc/kcore.c
|
|
|
|
* Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
|
|
|
|
* Copyright (C) IBM Corporation, 2004. All rights reserved
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/mm.h>
|
2013-04-11 23:10:25 +00:00
|
|
|
#include <linux/kcore.h>
|
2005-06-25 21:58:21 +00:00
|
|
|
#include <linux/user.h>
|
|
|
|
#include <linux/elf.h>
|
|
|
|
#include <linux/elfcore.h>
|
2011-05-26 20:00:52 +00:00
|
|
|
#include <linux/export.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-06-25 21:58:21 +00:00
|
|
|
#include <linux/highmem.h>
|
2013-02-28 01:03:16 +00:00
|
|
|
#include <linux/printk.h>
|
2005-06-25 21:58:21 +00:00
|
|
|
#include <linux/bootmem.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/crash_dump.h>
|
|
|
|
#include <linux/list.h>
|
2013-07-03 22:02:23 +00:00
|
|
|
#include <linux/vmalloc.h>
|
2013-09-11 21:24:51 +00:00
|
|
|
#include <linux/pagemap.h>
|
2005-06-25 21:58:21 +00:00
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/io.h>
|
2013-04-11 23:10:25 +00:00
|
|
|
#include "internal.h"
|
2005-06-25 21:58:21 +00:00
|
|
|
|
|
|
|
/* List representing chunks of contiguous memory areas and their offsets in
|
|
|
|
* vmcore file.
|
|
|
|
*/
|
|
|
|
static LIST_HEAD(vmcore_list);
|
|
|
|
|
|
|
|
/* Stores the pointer to the buffer containing kernel elf core headers. */
|
|
|
|
static char *elfcorebuf;
|
|
|
|
static size_t elfcorebuf_sz;
|
2013-07-03 22:02:14 +00:00
|
|
|
static size_t elfcorebuf_sz_orig;
|
2005-06-25 21:58:21 +00:00
|
|
|
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
static char *elfnotes_buf;
|
|
|
|
static size_t elfnotes_sz;
|
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
/* Total size of vmcore file. */
|
|
|
|
static u64 vmcore_size;
|
|
|
|
|
2014-06-06 21:37:04 +00:00
|
|
|
static struct proc_dir_entry *proc_vmcore;
|
2005-06-25 21:58:21 +00:00
|
|
|
|
2011-05-26 23:25:54 +00:00
|
|
|
/*
|
|
|
|
* Returns > 0 for RAM pages, 0 for non-RAM pages, < 0 on error
|
|
|
|
* The called function has to take care of module refcounting.
|
|
|
|
*/
|
|
|
|
static int (*oldmem_pfn_is_ram)(unsigned long pfn);
|
|
|
|
|
|
|
|
int register_oldmem_pfn_is_ram(int (*fn)(unsigned long pfn))
|
|
|
|
{
|
|
|
|
if (oldmem_pfn_is_ram)
|
|
|
|
return -EBUSY;
|
|
|
|
oldmem_pfn_is_ram = fn;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(register_oldmem_pfn_is_ram);
|
|
|
|
|
|
|
|
void unregister_oldmem_pfn_is_ram(void)
|
|
|
|
{
|
|
|
|
oldmem_pfn_is_ram = NULL;
|
|
|
|
wmb();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(unregister_oldmem_pfn_is_ram);
|
|
|
|
|
|
|
|
static int pfn_is_ram(unsigned long pfn)
|
|
|
|
{
|
|
|
|
int (*fn)(unsigned long pfn);
|
|
|
|
/* pfn is ram unless fn() checks pagetype */
|
|
|
|
int ret = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ask hypervisor if the pfn is really ram.
|
|
|
|
* A ballooned page contains no data and reading from such a page
|
|
|
|
* will cause high load in the hypervisor.
|
|
|
|
*/
|
|
|
|
fn = oldmem_pfn_is_ram;
|
|
|
|
if (fn)
|
|
|
|
ret = fn(pfn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
/* Reads a page from the oldmem device from given offset. */
|
|
|
|
static ssize_t read_from_oldmem(char *buf, size_t count,
|
2006-01-11 20:17:37 +00:00
|
|
|
u64 *ppos, int userbuf)
|
2005-06-25 21:58:21 +00:00
|
|
|
{
|
|
|
|
unsigned long pfn, offset;
|
|
|
|
size_t nr_bytes;
|
|
|
|
ssize_t read = 0, tmp;
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
offset = (unsigned long)(*ppos % PAGE_SIZE);
|
|
|
|
pfn = (unsigned long)(*ppos / PAGE_SIZE);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (count > (PAGE_SIZE - offset))
|
|
|
|
nr_bytes = PAGE_SIZE - offset;
|
|
|
|
else
|
|
|
|
nr_bytes = count;
|
|
|
|
|
2011-05-26 23:25:54 +00:00
|
|
|
/* If pfn is not ram, return zeros for sparse dump files */
|
|
|
|
if (pfn_is_ram(pfn) == 0)
|
|
|
|
memset(buf, 0, nr_bytes);
|
|
|
|
else {
|
|
|
|
tmp = copy_oldmem_page(pfn, buf, nr_bytes,
|
|
|
|
offset, userbuf);
|
|
|
|
if (tmp < 0)
|
|
|
|
return tmp;
|
|
|
|
}
|
2005-06-25 21:58:21 +00:00
|
|
|
*ppos += nr_bytes;
|
|
|
|
count -= nr_bytes;
|
|
|
|
buf += nr_bytes;
|
|
|
|
read += nr_bytes;
|
|
|
|
++pfn;
|
|
|
|
offset = 0;
|
|
|
|
} while (count);
|
|
|
|
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
2013-09-11 21:24:49 +00:00
|
|
|
/*
|
|
|
|
* Architectures may override this function to allocate ELF header in 2nd kernel
|
|
|
|
*/
|
|
|
|
int __weak elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Architectures may override this function to free header
|
|
|
|
*/
|
|
|
|
void __weak elfcorehdr_free(unsigned long long addr)
|
|
|
|
{}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Architectures may override this function to read from ELF header
|
|
|
|
*/
|
|
|
|
ssize_t __weak elfcorehdr_read(char *buf, size_t count, u64 *ppos)
|
|
|
|
{
|
|
|
|
return read_from_oldmem(buf, count, ppos, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Architectures may override this function to read from notes sections
|
|
|
|
*/
|
|
|
|
ssize_t __weak elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos)
|
|
|
|
{
|
|
|
|
return read_from_oldmem(buf, count, ppos, 0);
|
|
|
|
}
|
|
|
|
|
2013-09-11 21:24:51 +00:00
|
|
|
/*
|
|
|
|
* Architectures may override this function to map oldmem
|
|
|
|
*/
|
|
|
|
int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
|
|
|
|
unsigned long from, unsigned long pfn,
|
|
|
|
unsigned long size, pgprot_t prot)
|
|
|
|
{
|
|
|
|
return remap_pfn_range(vma, from, pfn, size, prot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy to either kernel or user space
|
|
|
|
*/
|
|
|
|
static int copy_to(void *target, void *src, size_t size, int userbuf)
|
|
|
|
{
|
|
|
|
if (userbuf) {
|
|
|
|
if (copy_to_user((char __user *) target, src, size))
|
|
|
|
return -EFAULT;
|
|
|
|
} else {
|
|
|
|
memcpy(target, src, size);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
/* Read from the ELF header and then the crash dump. On error, negative value is
|
|
|
|
* returned otherwise number of bytes read are returned.
|
|
|
|
*/
|
2013-09-11 21:24:51 +00:00
|
|
|
static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
|
|
|
|
int userbuf)
|
2005-06-25 21:58:21 +00:00
|
|
|
{
|
|
|
|
ssize_t acc = 0, tmp;
|
2006-04-11 05:54:10 +00:00
|
|
|
size_t tsz;
|
2013-07-03 22:02:13 +00:00
|
|
|
u64 start;
|
|
|
|
struct vmcore *m = NULL;
|
2005-06-25 21:58:21 +00:00
|
|
|
|
|
|
|
if (buflen == 0 || *fpos >= vmcore_size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* trim buflen to not go beyond EOF */
|
|
|
|
if (buflen > vmcore_size - *fpos)
|
|
|
|
buflen = vmcore_size - *fpos;
|
|
|
|
|
|
|
|
/* Read ELF core header */
|
|
|
|
if (*fpos < elfcorebuf_sz) {
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
tsz = min(elfcorebuf_sz - (size_t)*fpos, buflen);
|
2013-09-11 21:24:51 +00:00
|
|
|
if (copy_to(buffer, elfcorebuf + *fpos, tsz, userbuf))
|
2005-06-25 21:58:21 +00:00
|
|
|
return -EFAULT;
|
|
|
|
buflen -= tsz;
|
|
|
|
*fpos += tsz;
|
|
|
|
buffer += tsz;
|
|
|
|
acc += tsz;
|
|
|
|
|
|
|
|
/* leave now if filled buffer already */
|
|
|
|
if (buflen == 0)
|
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
/* Read Elf note segment */
|
|
|
|
if (*fpos < elfcorebuf_sz + elfnotes_sz) {
|
|
|
|
void *kaddr;
|
|
|
|
|
|
|
|
tsz = min(elfcorebuf_sz + elfnotes_sz - (size_t)*fpos, buflen);
|
|
|
|
kaddr = elfnotes_buf + *fpos - elfcorebuf_sz;
|
2013-09-11 21:24:51 +00:00
|
|
|
if (copy_to(buffer, kaddr, tsz, userbuf))
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
return -EFAULT;
|
|
|
|
buflen -= tsz;
|
|
|
|
*fpos += tsz;
|
|
|
|
buffer += tsz;
|
|
|
|
acc += tsz;
|
|
|
|
|
|
|
|
/* leave now if filled buffer already */
|
|
|
|
if (buflen == 0)
|
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
2013-07-03 22:02:13 +00:00
|
|
|
list_for_each_entry(m, &vmcore_list, list) {
|
|
|
|
if (*fpos < m->offset + m->size) {
|
2016-03-17 21:21:03 +00:00
|
|
|
tsz = (size_t)min_t(unsigned long long,
|
|
|
|
m->offset + m->size - *fpos,
|
|
|
|
buflen);
|
2013-07-03 22:02:13 +00:00
|
|
|
start = m->paddr + *fpos - m->offset;
|
2013-09-11 21:24:51 +00:00
|
|
|
tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
|
2013-07-03 22:02:13 +00:00
|
|
|
if (tmp < 0)
|
|
|
|
return tmp;
|
|
|
|
buflen -= tsz;
|
|
|
|
*fpos += tsz;
|
|
|
|
buffer += tsz;
|
|
|
|
acc += tsz;
|
|
|
|
|
|
|
|
/* leave now if filled buffer already */
|
|
|
|
if (buflen == 0)
|
|
|
|
return acc;
|
2005-06-25 21:58:21 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-03 22:02:13 +00:00
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
2013-09-11 21:24:51 +00:00
|
|
|
static ssize_t read_vmcore(struct file *file, char __user *buffer,
|
|
|
|
size_t buflen, loff_t *fpos)
|
|
|
|
{
|
|
|
|
return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The vmcore fault handler uses the page cache and fills data using the
|
|
|
|
* standard __vmcore_read() function.
|
|
|
|
*
|
|
|
|
* On s390 the fault handler is used for memory regions that can't be mapped
|
|
|
|
* directly with remap_pfn_range().
|
|
|
|
*/
|
|
|
|
static int mmap_vmcore_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_S390
|
|
|
|
struct address_space *mapping = vma->vm_file->f_mapping;
|
|
|
|
pgoff_t index = vmf->pgoff;
|
|
|
|
struct page *page;
|
|
|
|
loff_t offset;
|
|
|
|
char *buf;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
page = find_or_create_page(mapping, index, GFP_KERNEL);
|
|
|
|
if (!page)
|
|
|
|
return VM_FAULT_OOM;
|
|
|
|
if (!PageUptodate(page)) {
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 12:29:47 +00:00
|
|
|
offset = (loff_t) index << PAGE_SHIFT;
|
2013-09-11 21:24:51 +00:00
|
|
|
buf = __va((page_to_pfn(page) << PAGE_SHIFT));
|
|
|
|
rc = __read_vmcore(buf, PAGE_SIZE, &offset, 0);
|
|
|
|
if (rc < 0) {
|
|
|
|
unlock_page(page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 12:29:47 +00:00
|
|
|
put_page(page);
|
2013-09-11 21:24:51 +00:00
|
|
|
return (rc == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
|
|
|
|
}
|
|
|
|
SetPageUptodate(page);
|
|
|
|
}
|
|
|
|
unlock_page(page);
|
|
|
|
vmf->page = page;
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct vm_operations_struct vmcore_mmap_ops = {
|
|
|
|
.fault = mmap_vmcore_fault,
|
|
|
|
};
|
|
|
|
|
2013-07-03 22:02:23 +00:00
|
|
|
/**
|
|
|
|
* alloc_elfnotes_buf - allocate buffer for ELF note segment in
|
|
|
|
* vmalloc memory
|
|
|
|
*
|
|
|
|
* @notes_sz: size of buffer
|
|
|
|
*
|
|
|
|
* If CONFIG_MMU is defined, use vmalloc_user() to allow users to mmap
|
|
|
|
* the buffer to user-space by means of remap_vmalloc_range().
|
|
|
|
*
|
|
|
|
* If CONFIG_MMU is not defined, use vzalloc() since mmap_vmcore() is
|
|
|
|
* disabled and there's no need to allow users to mmap the buffer.
|
|
|
|
*/
|
|
|
|
static inline char *alloc_elfnotes_buf(size_t notes_sz)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_MMU
|
|
|
|
return vmalloc_user(notes_sz);
|
|
|
|
#else
|
|
|
|
return vzalloc(notes_sz);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable mmap_vmcore() if CONFIG_MMU is not defined. MMU is
|
|
|
|
* essential for mmap_vmcore() in order to map physically
|
|
|
|
* non-contiguous objects (ELF header, ELF note segment and memory
|
|
|
|
* regions in the 1st kernel pointed to by PT_LOAD entries) into
|
|
|
|
* virtually contiguous user-space in ELF layout.
|
|
|
|
*/
|
2013-09-11 21:24:53 +00:00
|
|
|
#ifdef CONFIG_MMU
|
2014-08-08 21:22:05 +00:00
|
|
|
/*
|
|
|
|
* remap_oldmem_pfn_checked - do remap_oldmem_pfn_range replacing all pages
|
|
|
|
* reported as not being ram with the zero page.
|
|
|
|
*
|
|
|
|
* @vma: vm_area_struct describing requested mapping
|
|
|
|
* @from: start remapping from
|
|
|
|
* @pfn: page frame number to start remapping to
|
|
|
|
* @size: remapping size
|
|
|
|
* @prot: protection bits
|
|
|
|
*
|
|
|
|
* Returns zero on success, -EAGAIN on failure.
|
|
|
|
*/
|
|
|
|
static int remap_oldmem_pfn_checked(struct vm_area_struct *vma,
|
|
|
|
unsigned long from, unsigned long pfn,
|
|
|
|
unsigned long size, pgprot_t prot)
|
|
|
|
{
|
|
|
|
unsigned long map_size;
|
|
|
|
unsigned long pos_start, pos_end, pos;
|
|
|
|
unsigned long zeropage_pfn = my_zero_pfn(0);
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
pos_start = pfn;
|
|
|
|
pos_end = pfn + (size >> PAGE_SHIFT);
|
|
|
|
|
|
|
|
for (pos = pos_start; pos < pos_end; ++pos) {
|
|
|
|
if (!pfn_is_ram(pos)) {
|
|
|
|
/*
|
|
|
|
* We hit a page which is not ram. Remap the continuous
|
|
|
|
* region between pos_start and pos-1 and replace
|
|
|
|
* the non-ram page at pos with the zero page.
|
|
|
|
*/
|
|
|
|
if (pos > pos_start) {
|
|
|
|
/* Remap continuous region */
|
|
|
|
map_size = (pos - pos_start) << PAGE_SHIFT;
|
|
|
|
if (remap_oldmem_pfn_range(vma, from + len,
|
|
|
|
pos_start, map_size,
|
|
|
|
prot))
|
|
|
|
goto fail;
|
|
|
|
len += map_size;
|
|
|
|
}
|
|
|
|
/* Remap the zero page */
|
|
|
|
if (remap_oldmem_pfn_range(vma, from + len,
|
|
|
|
zeropage_pfn,
|
|
|
|
PAGE_SIZE, prot))
|
|
|
|
goto fail;
|
|
|
|
len += PAGE_SIZE;
|
|
|
|
pos_start = pos + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pos > pos_start) {
|
|
|
|
/* Remap the rest */
|
|
|
|
map_size = (pos - pos_start) << PAGE_SHIFT;
|
|
|
|
if (remap_oldmem_pfn_range(vma, from + len, pos_start,
|
|
|
|
map_size, prot))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
do_munmap(vma->vm_mm, from, len);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vmcore_remap_oldmem_pfn(struct vm_area_struct *vma,
|
|
|
|
unsigned long from, unsigned long pfn,
|
|
|
|
unsigned long size, pgprot_t prot)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Check if oldmem_pfn_is_ram was registered to avoid
|
|
|
|
* looping over all pages without a reason.
|
|
|
|
*/
|
|
|
|
if (oldmem_pfn_is_ram)
|
|
|
|
return remap_oldmem_pfn_checked(vma, from, pfn, size, prot);
|
|
|
|
else
|
|
|
|
return remap_oldmem_pfn_range(vma, from, pfn, size, prot);
|
|
|
|
}
|
|
|
|
|
2013-07-03 22:02:23 +00:00
|
|
|
static int mmap_vmcore(struct file *file, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
size_t size = vma->vm_end - vma->vm_start;
|
|
|
|
u64 start, end, len, tsz;
|
|
|
|
struct vmcore *m;
|
|
|
|
|
|
|
|
start = (u64)vma->vm_pgoff << PAGE_SHIFT;
|
|
|
|
end = start + size;
|
|
|
|
|
|
|
|
if (size > vmcore_size || end > vmcore_size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (vma->vm_flags & (VM_WRITE | VM_EXEC))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
vma->vm_flags &= ~(VM_MAYWRITE | VM_MAYEXEC);
|
|
|
|
vma->vm_flags |= VM_MIXEDMAP;
|
2013-09-11 21:24:51 +00:00
|
|
|
vma->vm_ops = &vmcore_mmap_ops;
|
2013-07-03 22:02:23 +00:00
|
|
|
|
|
|
|
len = 0;
|
|
|
|
|
|
|
|
if (start < elfcorebuf_sz) {
|
|
|
|
u64 pfn;
|
|
|
|
|
|
|
|
tsz = min(elfcorebuf_sz - (size_t)start, size);
|
|
|
|
pfn = __pa(elfcorebuf + start) >> PAGE_SHIFT;
|
|
|
|
if (remap_pfn_range(vma, vma->vm_start, pfn, tsz,
|
|
|
|
vma->vm_page_prot))
|
|
|
|
return -EAGAIN;
|
|
|
|
size -= tsz;
|
|
|
|
start += tsz;
|
|
|
|
len += tsz;
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start < elfcorebuf_sz + elfnotes_sz) {
|
|
|
|
void *kaddr;
|
|
|
|
|
|
|
|
tsz = min(elfcorebuf_sz + elfnotes_sz - (size_t)start, size);
|
|
|
|
kaddr = elfnotes_buf + start - elfcorebuf_sz;
|
|
|
|
if (remap_vmalloc_range_partial(vma, vma->vm_start + len,
|
|
|
|
kaddr, tsz))
|
|
|
|
goto fail;
|
|
|
|
size -= tsz;
|
|
|
|
start += tsz;
|
|
|
|
len += tsz;
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(m, &vmcore_list, list) {
|
|
|
|
if (start < m->offset + m->size) {
|
|
|
|
u64 paddr = 0;
|
|
|
|
|
2016-03-17 21:21:03 +00:00
|
|
|
tsz = (size_t)min_t(unsigned long long,
|
|
|
|
m->offset + m->size - start, size);
|
2013-07-03 22:02:23 +00:00
|
|
|
paddr = m->paddr + start - m->offset;
|
2014-08-08 21:22:05 +00:00
|
|
|
if (vmcore_remap_oldmem_pfn(vma, vma->vm_start + len,
|
|
|
|
paddr >> PAGE_SHIFT, tsz,
|
|
|
|
vma->vm_page_prot))
|
2013-07-03 22:02:23 +00:00
|
|
|
goto fail;
|
|
|
|
size -= tsz;
|
|
|
|
start += tsz;
|
|
|
|
len += tsz;
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
do_munmap(vma->vm_mm, vma->vm_start, len);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int mmap_vmcore(struct file *file, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-06 10:36:31 +00:00
|
|
|
static const struct file_operations proc_vmcore_operations = {
|
2005-06-25 21:58:21 +00:00
|
|
|
.read = read_vmcore,
|
2010-09-22 20:04:54 +00:00
|
|
|
.llseek = default_llseek,
|
2013-07-03 22:02:23 +00:00
|
|
|
.mmap = mmap_vmcore,
|
2005-06-25 21:58:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct vmcore* __init get_new_element(void)
|
|
|
|
{
|
2009-06-17 23:26:00 +00:00
|
|
|
return kzalloc(sizeof(struct vmcore), GFP_KERNEL);
|
2005-06-25 21:58:21 +00:00
|
|
|
}
|
|
|
|
|
2013-07-03 22:02:22 +00:00
|
|
|
static u64 __init get_vmcore_size(size_t elfsz, size_t elfnotesegsz,
|
|
|
|
struct list_head *vc_list)
|
2005-06-25 21:58:21 +00:00
|
|
|
{
|
|
|
|
u64 size;
|
2013-07-03 22:02:22 +00:00
|
|
|
struct vmcore *m;
|
2005-06-25 21:58:22 +00:00
|
|
|
|
2013-07-03 22:02:22 +00:00
|
|
|
size = elfsz + elfnotesegsz;
|
|
|
|
list_for_each_entry(m, vc_list, list) {
|
|
|
|
size += m->size;
|
2005-06-25 21:58:22 +00:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
/**
|
|
|
|
* update_note_header_size_elf64 - update p_memsz member of each PT_NOTE entry
|
|
|
|
*
|
|
|
|
* @ehdr_ptr: ELF header
|
|
|
|
*
|
|
|
|
* This function updates p_memsz member of each PT_NOTE entry in the
|
|
|
|
* program header table pointed to by @ehdr_ptr to real size of ELF
|
|
|
|
* note segment.
|
|
|
|
*/
|
|
|
|
static int __init update_note_header_size_elf64(const Elf64_Ehdr *ehdr_ptr)
|
2005-06-25 21:58:21 +00:00
|
|
|
{
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
int i, rc=0;
|
|
|
|
Elf64_Phdr *phdr_ptr;
|
2005-06-25 21:58:21 +00:00
|
|
|
Elf64_Nhdr *nhdr_ptr;
|
|
|
|
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
phdr_ptr = (Elf64_Phdr *)(ehdr_ptr + 1);
|
2005-06-25 21:58:21 +00:00
|
|
|
for (i = 0; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) {
|
|
|
|
void *notes_section;
|
|
|
|
u64 offset, max_sz, sz, real_sz = 0;
|
|
|
|
if (phdr_ptr->p_type != PT_NOTE)
|
|
|
|
continue;
|
|
|
|
max_sz = phdr_ptr->p_memsz;
|
|
|
|
offset = phdr_ptr->p_offset;
|
|
|
|
notes_section = kmalloc(max_sz, GFP_KERNEL);
|
|
|
|
if (!notes_section)
|
|
|
|
return -ENOMEM;
|
2013-09-11 21:24:49 +00:00
|
|
|
rc = elfcorehdr_read_notes(notes_section, max_sz, &offset);
|
2005-06-25 21:58:21 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
kfree(notes_section);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
nhdr_ptr = notes_section;
|
2014-02-10 22:25:36 +00:00
|
|
|
while (nhdr_ptr->n_namesz != 0) {
|
2005-06-25 21:58:21 +00:00
|
|
|
sz = sizeof(Elf64_Nhdr) +
|
2015-02-17 21:46:01 +00:00
|
|
|
(((u64)nhdr_ptr->n_namesz + 3) & ~3) +
|
|
|
|
(((u64)nhdr_ptr->n_descsz + 3) & ~3);
|
2014-02-10 22:25:36 +00:00
|
|
|
if ((real_sz + sz) > max_sz) {
|
|
|
|
pr_warn("Warning: Exceeded p_memsz, dropping PT_NOTE entry n_namesz=0x%x, n_descsz=0x%x\n",
|
|
|
|
nhdr_ptr->n_namesz, nhdr_ptr->n_descsz);
|
|
|
|
break;
|
|
|
|
}
|
2005-06-25 21:58:21 +00:00
|
|
|
real_sz += sz;
|
|
|
|
nhdr_ptr = (Elf64_Nhdr*)((char*)nhdr_ptr + sz);
|
|
|
|
}
|
|
|
|
kfree(notes_section);
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
phdr_ptr->p_memsz = real_sz;
|
2014-02-10 22:25:36 +00:00
|
|
|
if (real_sz == 0) {
|
|
|
|
pr_warn("Warning: Zero PT_NOTE entries found\n");
|
|
|
|
}
|
2005-06-25 21:58:21 +00:00
|
|
|
}
|
|
|
|
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get_note_number_and_size_elf64 - get the number of PT_NOTE program
|
|
|
|
* headers and sum of real size of their ELF note segment headers and
|
|
|
|
* data.
|
|
|
|
*
|
|
|
|
* @ehdr_ptr: ELF header
|
|
|
|
* @nr_ptnote: buffer for the number of PT_NOTE program headers
|
|
|
|
* @sz_ptnote: buffer for size of unique PT_NOTE program header
|
|
|
|
*
|
|
|
|
* This function is used to merge multiple PT_NOTE program headers
|
|
|
|
* into a unique single one. The resulting unique entry will have
|
|
|
|
* @sz_ptnote in its phdr->p_mem.
|
|
|
|
*
|
|
|
|
* It is assumed that program headers with PT_NOTE type pointed to by
|
|
|
|
* @ehdr_ptr has already been updated by update_note_header_size_elf64
|
|
|
|
* and each of PT_NOTE program headers has actual ELF note segment
|
|
|
|
* size in its p_memsz member.
|
|
|
|
*/
|
|
|
|
static int __init get_note_number_and_size_elf64(const Elf64_Ehdr *ehdr_ptr,
|
|
|
|
int *nr_ptnote, u64 *sz_ptnote)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Elf64_Phdr *phdr_ptr;
|
|
|
|
|
|
|
|
*nr_ptnote = *sz_ptnote = 0;
|
|
|
|
|
|
|
|
phdr_ptr = (Elf64_Phdr *)(ehdr_ptr + 1);
|
|
|
|
for (i = 0; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) {
|
|
|
|
if (phdr_ptr->p_type != PT_NOTE)
|
|
|
|
continue;
|
|
|
|
*nr_ptnote += 1;
|
|
|
|
*sz_ptnote += phdr_ptr->p_memsz;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* copy_notes_elf64 - copy ELF note segments in a given buffer
|
|
|
|
*
|
|
|
|
* @ehdr_ptr: ELF header
|
|
|
|
* @notes_buf: buffer into which ELF note segments are copied
|
|
|
|
*
|
|
|
|
* This function is used to copy ELF note segment in the 1st kernel
|
|
|
|
* into the buffer @notes_buf in the 2nd kernel. It is assumed that
|
|
|
|
* size of the buffer @notes_buf is equal to or larger than sum of the
|
|
|
|
* real ELF note segment headers and data.
|
|
|
|
*
|
|
|
|
* It is assumed that program headers with PT_NOTE type pointed to by
|
|
|
|
* @ehdr_ptr has already been updated by update_note_header_size_elf64
|
|
|
|
* and each of PT_NOTE program headers has actual ELF note segment
|
|
|
|
* size in its p_memsz member.
|
|
|
|
*/
|
|
|
|
static int __init copy_notes_elf64(const Elf64_Ehdr *ehdr_ptr, char *notes_buf)
|
|
|
|
{
|
|
|
|
int i, rc=0;
|
|
|
|
Elf64_Phdr *phdr_ptr;
|
|
|
|
|
|
|
|
phdr_ptr = (Elf64_Phdr*)(ehdr_ptr + 1);
|
|
|
|
|
|
|
|
for (i = 0; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) {
|
|
|
|
u64 offset;
|
|
|
|
if (phdr_ptr->p_type != PT_NOTE)
|
|
|
|
continue;
|
|
|
|
offset = phdr_ptr->p_offset;
|
2013-09-11 21:24:49 +00:00
|
|
|
rc = elfcorehdr_read_notes(notes_buf, phdr_ptr->p_memsz,
|
|
|
|
&offset);
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
notes_buf += phdr_ptr->p_memsz;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Merges all the PT_NOTE headers into one. */
|
|
|
|
static int __init merge_note_headers_elf64(char *elfptr, size_t *elfsz,
|
|
|
|
char **notes_buf, size_t *notes_sz)
|
|
|
|
{
|
|
|
|
int i, nr_ptnote=0, rc=0;
|
|
|
|
char *tmp;
|
|
|
|
Elf64_Ehdr *ehdr_ptr;
|
|
|
|
Elf64_Phdr phdr;
|
|
|
|
u64 phdr_sz = 0, note_off;
|
|
|
|
|
|
|
|
ehdr_ptr = (Elf64_Ehdr *)elfptr;
|
|
|
|
|
|
|
|
rc = update_note_header_size_elf64(ehdr_ptr);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = get_note_number_and_size_elf64(ehdr_ptr, &nr_ptnote, &phdr_sz);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
*notes_sz = roundup(phdr_sz, PAGE_SIZE);
|
2013-07-03 22:02:23 +00:00
|
|
|
*notes_buf = alloc_elfnotes_buf(*notes_sz);
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
if (!*notes_buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rc = copy_notes_elf64(ehdr_ptr, *notes_buf);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
/* Prepare merged PT_NOTE program header. */
|
|
|
|
phdr.p_type = PT_NOTE;
|
|
|
|
phdr.p_flags = 0;
|
|
|
|
note_off = sizeof(Elf64_Ehdr) +
|
|
|
|
(ehdr_ptr->e_phnum - nr_ptnote +1) * sizeof(Elf64_Phdr);
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
phdr.p_offset = roundup(note_off, PAGE_SIZE);
|
2005-06-25 21:58:21 +00:00
|
|
|
phdr.p_vaddr = phdr.p_paddr = 0;
|
|
|
|
phdr.p_filesz = phdr.p_memsz = phdr_sz;
|
|
|
|
phdr.p_align = 0;
|
|
|
|
|
|
|
|
/* Add merged PT_NOTE program header*/
|
|
|
|
tmp = elfptr + sizeof(Elf64_Ehdr);
|
|
|
|
memcpy(tmp, &phdr, sizeof(phdr));
|
|
|
|
tmp += sizeof(phdr);
|
|
|
|
|
|
|
|
/* Remove unwanted PT_NOTE program headers. */
|
|
|
|
i = (nr_ptnote - 1) * sizeof(Elf64_Phdr);
|
|
|
|
*elfsz = *elfsz - i;
|
|
|
|
memmove(tmp, tmp+i, ((*elfsz)-sizeof(Elf64_Ehdr)-sizeof(Elf64_Phdr)));
|
2013-07-03 22:02:14 +00:00
|
|
|
memset(elfptr + *elfsz, 0, i);
|
|
|
|
*elfsz = roundup(*elfsz, PAGE_SIZE);
|
2005-06-25 21:58:21 +00:00
|
|
|
|
|
|
|
/* Modify e_phnum to reflect merged headers. */
|
|
|
|
ehdr_ptr->e_phnum = ehdr_ptr->e_phnum - nr_ptnote + 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
/**
|
|
|
|
* update_note_header_size_elf32 - update p_memsz member of each PT_NOTE entry
|
|
|
|
*
|
|
|
|
* @ehdr_ptr: ELF header
|
|
|
|
*
|
|
|
|
* This function updates p_memsz member of each PT_NOTE entry in the
|
|
|
|
* program header table pointed to by @ehdr_ptr to real size of ELF
|
|
|
|
* note segment.
|
|
|
|
*/
|
|
|
|
static int __init update_note_header_size_elf32(const Elf32_Ehdr *ehdr_ptr)
|
2005-06-25 21:58:22 +00:00
|
|
|
{
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
int i, rc=0;
|
|
|
|
Elf32_Phdr *phdr_ptr;
|
2005-06-25 21:58:22 +00:00
|
|
|
Elf32_Nhdr *nhdr_ptr;
|
|
|
|
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
phdr_ptr = (Elf32_Phdr *)(ehdr_ptr + 1);
|
2005-06-25 21:58:22 +00:00
|
|
|
for (i = 0; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) {
|
|
|
|
void *notes_section;
|
|
|
|
u64 offset, max_sz, sz, real_sz = 0;
|
|
|
|
if (phdr_ptr->p_type != PT_NOTE)
|
|
|
|
continue;
|
|
|
|
max_sz = phdr_ptr->p_memsz;
|
|
|
|
offset = phdr_ptr->p_offset;
|
|
|
|
notes_section = kmalloc(max_sz, GFP_KERNEL);
|
|
|
|
if (!notes_section)
|
|
|
|
return -ENOMEM;
|
2013-09-11 21:24:49 +00:00
|
|
|
rc = elfcorehdr_read_notes(notes_section, max_sz, &offset);
|
2005-06-25 21:58:22 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
kfree(notes_section);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
nhdr_ptr = notes_section;
|
2014-02-10 22:25:36 +00:00
|
|
|
while (nhdr_ptr->n_namesz != 0) {
|
2005-06-25 21:58:22 +00:00
|
|
|
sz = sizeof(Elf32_Nhdr) +
|
2015-02-17 21:46:01 +00:00
|
|
|
(((u64)nhdr_ptr->n_namesz + 3) & ~3) +
|
|
|
|
(((u64)nhdr_ptr->n_descsz + 3) & ~3);
|
2014-02-10 22:25:36 +00:00
|
|
|
if ((real_sz + sz) > max_sz) {
|
|
|
|
pr_warn("Warning: Exceeded p_memsz, dropping PT_NOTE entry n_namesz=0x%x, n_descsz=0x%x\n",
|
|
|
|
nhdr_ptr->n_namesz, nhdr_ptr->n_descsz);
|
|
|
|
break;
|
|
|
|
}
|
2005-06-25 21:58:22 +00:00
|
|
|
real_sz += sz;
|
|
|
|
nhdr_ptr = (Elf32_Nhdr*)((char*)nhdr_ptr + sz);
|
|
|
|
}
|
|
|
|
kfree(notes_section);
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
phdr_ptr->p_memsz = real_sz;
|
2014-02-10 22:25:36 +00:00
|
|
|
if (real_sz == 0) {
|
|
|
|
pr_warn("Warning: Zero PT_NOTE entries found\n");
|
|
|
|
}
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get_note_number_and_size_elf32 - get the number of PT_NOTE program
|
|
|
|
* headers and sum of real size of their ELF note segment headers and
|
|
|
|
* data.
|
|
|
|
*
|
|
|
|
* @ehdr_ptr: ELF header
|
|
|
|
* @nr_ptnote: buffer for the number of PT_NOTE program headers
|
|
|
|
* @sz_ptnote: buffer for size of unique PT_NOTE program header
|
|
|
|
*
|
|
|
|
* This function is used to merge multiple PT_NOTE program headers
|
|
|
|
* into a unique single one. The resulting unique entry will have
|
|
|
|
* @sz_ptnote in its phdr->p_mem.
|
|
|
|
*
|
|
|
|
* It is assumed that program headers with PT_NOTE type pointed to by
|
|
|
|
* @ehdr_ptr has already been updated by update_note_header_size_elf32
|
|
|
|
* and each of PT_NOTE program headers has actual ELF note segment
|
|
|
|
* size in its p_memsz member.
|
|
|
|
*/
|
|
|
|
static int __init get_note_number_and_size_elf32(const Elf32_Ehdr *ehdr_ptr,
|
|
|
|
int *nr_ptnote, u64 *sz_ptnote)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Elf32_Phdr *phdr_ptr;
|
|
|
|
|
|
|
|
*nr_ptnote = *sz_ptnote = 0;
|
|
|
|
|
|
|
|
phdr_ptr = (Elf32_Phdr *)(ehdr_ptr + 1);
|
|
|
|
for (i = 0; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) {
|
|
|
|
if (phdr_ptr->p_type != PT_NOTE)
|
|
|
|
continue;
|
|
|
|
*nr_ptnote += 1;
|
|
|
|
*sz_ptnote += phdr_ptr->p_memsz;
|
2005-06-25 21:58:22 +00:00
|
|
|
}
|
|
|
|
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* copy_notes_elf32 - copy ELF note segments in a given buffer
|
|
|
|
*
|
|
|
|
* @ehdr_ptr: ELF header
|
|
|
|
* @notes_buf: buffer into which ELF note segments are copied
|
|
|
|
*
|
|
|
|
* This function is used to copy ELF note segment in the 1st kernel
|
|
|
|
* into the buffer @notes_buf in the 2nd kernel. It is assumed that
|
|
|
|
* size of the buffer @notes_buf is equal to or larger than sum of the
|
|
|
|
* real ELF note segment headers and data.
|
|
|
|
*
|
|
|
|
* It is assumed that program headers with PT_NOTE type pointed to by
|
|
|
|
* @ehdr_ptr has already been updated by update_note_header_size_elf32
|
|
|
|
* and each of PT_NOTE program headers has actual ELF note segment
|
|
|
|
* size in its p_memsz member.
|
|
|
|
*/
|
|
|
|
static int __init copy_notes_elf32(const Elf32_Ehdr *ehdr_ptr, char *notes_buf)
|
|
|
|
{
|
|
|
|
int i, rc=0;
|
|
|
|
Elf32_Phdr *phdr_ptr;
|
|
|
|
|
|
|
|
phdr_ptr = (Elf32_Phdr*)(ehdr_ptr + 1);
|
|
|
|
|
|
|
|
for (i = 0; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) {
|
|
|
|
u64 offset;
|
|
|
|
if (phdr_ptr->p_type != PT_NOTE)
|
|
|
|
continue;
|
|
|
|
offset = phdr_ptr->p_offset;
|
2013-09-11 21:24:49 +00:00
|
|
|
rc = elfcorehdr_read_notes(notes_buf, phdr_ptr->p_memsz,
|
|
|
|
&offset);
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
notes_buf += phdr_ptr->p_memsz;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Merges all the PT_NOTE headers into one. */
|
|
|
|
static int __init merge_note_headers_elf32(char *elfptr, size_t *elfsz,
|
|
|
|
char **notes_buf, size_t *notes_sz)
|
|
|
|
{
|
|
|
|
int i, nr_ptnote=0, rc=0;
|
|
|
|
char *tmp;
|
|
|
|
Elf32_Ehdr *ehdr_ptr;
|
|
|
|
Elf32_Phdr phdr;
|
|
|
|
u64 phdr_sz = 0, note_off;
|
|
|
|
|
|
|
|
ehdr_ptr = (Elf32_Ehdr *)elfptr;
|
|
|
|
|
|
|
|
rc = update_note_header_size_elf32(ehdr_ptr);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = get_note_number_and_size_elf32(ehdr_ptr, &nr_ptnote, &phdr_sz);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
*notes_sz = roundup(phdr_sz, PAGE_SIZE);
|
2013-07-03 22:02:23 +00:00
|
|
|
*notes_buf = alloc_elfnotes_buf(*notes_sz);
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
if (!*notes_buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rc = copy_notes_elf32(ehdr_ptr, *notes_buf);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
2005-06-25 21:58:22 +00:00
|
|
|
/* Prepare merged PT_NOTE program header. */
|
|
|
|
phdr.p_type = PT_NOTE;
|
|
|
|
phdr.p_flags = 0;
|
|
|
|
note_off = sizeof(Elf32_Ehdr) +
|
|
|
|
(ehdr_ptr->e_phnum - nr_ptnote +1) * sizeof(Elf32_Phdr);
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
phdr.p_offset = roundup(note_off, PAGE_SIZE);
|
2005-06-25 21:58:22 +00:00
|
|
|
phdr.p_vaddr = phdr.p_paddr = 0;
|
|
|
|
phdr.p_filesz = phdr.p_memsz = phdr_sz;
|
|
|
|
phdr.p_align = 0;
|
|
|
|
|
|
|
|
/* Add merged PT_NOTE program header*/
|
|
|
|
tmp = elfptr + sizeof(Elf32_Ehdr);
|
|
|
|
memcpy(tmp, &phdr, sizeof(phdr));
|
|
|
|
tmp += sizeof(phdr);
|
|
|
|
|
|
|
|
/* Remove unwanted PT_NOTE program headers. */
|
|
|
|
i = (nr_ptnote - 1) * sizeof(Elf32_Phdr);
|
|
|
|
*elfsz = *elfsz - i;
|
|
|
|
memmove(tmp, tmp+i, ((*elfsz)-sizeof(Elf32_Ehdr)-sizeof(Elf32_Phdr)));
|
2013-07-03 22:02:14 +00:00
|
|
|
memset(elfptr + *elfsz, 0, i);
|
|
|
|
*elfsz = roundup(*elfsz, PAGE_SIZE);
|
2005-06-25 21:58:22 +00:00
|
|
|
|
|
|
|
/* Modify e_phnum to reflect merged headers. */
|
|
|
|
ehdr_ptr->e_phnum = ehdr_ptr->e_phnum - nr_ptnote + 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
/* Add memory chunks represented by program headers to vmcore list. Also update
|
|
|
|
* the new offset fields of exported program headers. */
|
|
|
|
static int __init process_ptload_program_headers_elf64(char *elfptr,
|
|
|
|
size_t elfsz,
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
size_t elfnotes_sz,
|
2005-06-25 21:58:21 +00:00
|
|
|
struct list_head *vc_list)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Elf64_Ehdr *ehdr_ptr;
|
|
|
|
Elf64_Phdr *phdr_ptr;
|
|
|
|
loff_t vmcore_off;
|
|
|
|
struct vmcore *new;
|
|
|
|
|
|
|
|
ehdr_ptr = (Elf64_Ehdr *)elfptr;
|
|
|
|
phdr_ptr = (Elf64_Phdr*)(elfptr + sizeof(Elf64_Ehdr)); /* PT_NOTE hdr */
|
|
|
|
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
/* Skip Elf header, program headers and Elf note segment. */
|
|
|
|
vmcore_off = elfsz + elfnotes_sz;
|
2005-06-25 21:58:21 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) {
|
vmcore: treat memory chunks referenced by PT_LOAD program header entries in page-size boundary in vmcore_list
Treat memory chunks referenced by PT_LOAD program header entries in
page-size boundary in vmcore_list. Formally, for each range [start,
end], we set up the corresponding vmcore object in vmcore_list to
[rounddown(start, PAGE_SIZE), roundup(end, PAGE_SIZE)].
This change affects layout of /proc/vmcore. The gaps generated by the
rearrangement are newly made visible to applications as holes.
Concretely, they are two ranges [rounddown(start, PAGE_SIZE), start] and
[end, roundup(end, PAGE_SIZE)].
Suppose variable m points at a vmcore object in vmcore_list, and
variable phdr points at the program header of PT_LOAD type the variable
m corresponds to. Then, pictorially:
m->offset +---------------+
| hole |
phdr->p_offset = +---------------+
m->offset + (paddr - start) | |\
| kernel memory | phdr->p_memsz
| |/
+---------------+
| hole |
m->offset + m->size +---------------+
where m->offset and m->offset + m->size are always page-size aligned.
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:15 +00:00
|
|
|
u64 paddr, start, end, size;
|
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
if (phdr_ptr->p_type != PT_LOAD)
|
|
|
|
continue;
|
|
|
|
|
vmcore: treat memory chunks referenced by PT_LOAD program header entries in page-size boundary in vmcore_list
Treat memory chunks referenced by PT_LOAD program header entries in
page-size boundary in vmcore_list. Formally, for each range [start,
end], we set up the corresponding vmcore object in vmcore_list to
[rounddown(start, PAGE_SIZE), roundup(end, PAGE_SIZE)].
This change affects layout of /proc/vmcore. The gaps generated by the
rearrangement are newly made visible to applications as holes.
Concretely, they are two ranges [rounddown(start, PAGE_SIZE), start] and
[end, roundup(end, PAGE_SIZE)].
Suppose variable m points at a vmcore object in vmcore_list, and
variable phdr points at the program header of PT_LOAD type the variable
m corresponds to. Then, pictorially:
m->offset +---------------+
| hole |
phdr->p_offset = +---------------+
m->offset + (paddr - start) | |\
| kernel memory | phdr->p_memsz
| |/
+---------------+
| hole |
m->offset + m->size +---------------+
where m->offset and m->offset + m->size are always page-size aligned.
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:15 +00:00
|
|
|
paddr = phdr_ptr->p_offset;
|
|
|
|
start = rounddown(paddr, PAGE_SIZE);
|
|
|
|
end = roundup(paddr + phdr_ptr->p_memsz, PAGE_SIZE);
|
|
|
|
size = end - start;
|
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
/* Add this contiguous chunk of memory to vmcore list.*/
|
|
|
|
new = get_new_element();
|
|
|
|
if (!new)
|
|
|
|
return -ENOMEM;
|
vmcore: treat memory chunks referenced by PT_LOAD program header entries in page-size boundary in vmcore_list
Treat memory chunks referenced by PT_LOAD program header entries in
page-size boundary in vmcore_list. Formally, for each range [start,
end], we set up the corresponding vmcore object in vmcore_list to
[rounddown(start, PAGE_SIZE), roundup(end, PAGE_SIZE)].
This change affects layout of /proc/vmcore. The gaps generated by the
rearrangement are newly made visible to applications as holes.
Concretely, they are two ranges [rounddown(start, PAGE_SIZE), start] and
[end, roundup(end, PAGE_SIZE)].
Suppose variable m points at a vmcore object in vmcore_list, and
variable phdr points at the program header of PT_LOAD type the variable
m corresponds to. Then, pictorially:
m->offset +---------------+
| hole |
phdr->p_offset = +---------------+
m->offset + (paddr - start) | |\
| kernel memory | phdr->p_memsz
| |/
+---------------+
| hole |
m->offset + m->size +---------------+
where m->offset and m->offset + m->size are always page-size aligned.
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:15 +00:00
|
|
|
new->paddr = start;
|
|
|
|
new->size = size;
|
2005-06-25 21:58:21 +00:00
|
|
|
list_add_tail(&new->list, vc_list);
|
|
|
|
|
|
|
|
/* Update the program header offset. */
|
vmcore: treat memory chunks referenced by PT_LOAD program header entries in page-size boundary in vmcore_list
Treat memory chunks referenced by PT_LOAD program header entries in
page-size boundary in vmcore_list. Formally, for each range [start,
end], we set up the corresponding vmcore object in vmcore_list to
[rounddown(start, PAGE_SIZE), roundup(end, PAGE_SIZE)].
This change affects layout of /proc/vmcore. The gaps generated by the
rearrangement are newly made visible to applications as holes.
Concretely, they are two ranges [rounddown(start, PAGE_SIZE), start] and
[end, roundup(end, PAGE_SIZE)].
Suppose variable m points at a vmcore object in vmcore_list, and
variable phdr points at the program header of PT_LOAD type the variable
m corresponds to. Then, pictorially:
m->offset +---------------+
| hole |
phdr->p_offset = +---------------+
m->offset + (paddr - start) | |\
| kernel memory | phdr->p_memsz
| |/
+---------------+
| hole |
m->offset + m->size +---------------+
where m->offset and m->offset + m->size are always page-size aligned.
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:15 +00:00
|
|
|
phdr_ptr->p_offset = vmcore_off + (paddr - start);
|
|
|
|
vmcore_off = vmcore_off + size;
|
2005-06-25 21:58:21 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-25 21:58:22 +00:00
|
|
|
static int __init process_ptload_program_headers_elf32(char *elfptr,
|
|
|
|
size_t elfsz,
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
size_t elfnotes_sz,
|
2005-06-25 21:58:22 +00:00
|
|
|
struct list_head *vc_list)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Elf32_Ehdr *ehdr_ptr;
|
|
|
|
Elf32_Phdr *phdr_ptr;
|
|
|
|
loff_t vmcore_off;
|
|
|
|
struct vmcore *new;
|
|
|
|
|
|
|
|
ehdr_ptr = (Elf32_Ehdr *)elfptr;
|
|
|
|
phdr_ptr = (Elf32_Phdr*)(elfptr + sizeof(Elf32_Ehdr)); /* PT_NOTE hdr */
|
|
|
|
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
/* Skip Elf header, program headers and Elf note segment. */
|
|
|
|
vmcore_off = elfsz + elfnotes_sz;
|
2005-06-25 21:58:22 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) {
|
vmcore: treat memory chunks referenced by PT_LOAD program header entries in page-size boundary in vmcore_list
Treat memory chunks referenced by PT_LOAD program header entries in
page-size boundary in vmcore_list. Formally, for each range [start,
end], we set up the corresponding vmcore object in vmcore_list to
[rounddown(start, PAGE_SIZE), roundup(end, PAGE_SIZE)].
This change affects layout of /proc/vmcore. The gaps generated by the
rearrangement are newly made visible to applications as holes.
Concretely, they are two ranges [rounddown(start, PAGE_SIZE), start] and
[end, roundup(end, PAGE_SIZE)].
Suppose variable m points at a vmcore object in vmcore_list, and
variable phdr points at the program header of PT_LOAD type the variable
m corresponds to. Then, pictorially:
m->offset +---------------+
| hole |
phdr->p_offset = +---------------+
m->offset + (paddr - start) | |\
| kernel memory | phdr->p_memsz
| |/
+---------------+
| hole |
m->offset + m->size +---------------+
where m->offset and m->offset + m->size are always page-size aligned.
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:15 +00:00
|
|
|
u64 paddr, start, end, size;
|
|
|
|
|
2005-06-25 21:58:22 +00:00
|
|
|
if (phdr_ptr->p_type != PT_LOAD)
|
|
|
|
continue;
|
|
|
|
|
vmcore: treat memory chunks referenced by PT_LOAD program header entries in page-size boundary in vmcore_list
Treat memory chunks referenced by PT_LOAD program header entries in
page-size boundary in vmcore_list. Formally, for each range [start,
end], we set up the corresponding vmcore object in vmcore_list to
[rounddown(start, PAGE_SIZE), roundup(end, PAGE_SIZE)].
This change affects layout of /proc/vmcore. The gaps generated by the
rearrangement are newly made visible to applications as holes.
Concretely, they are two ranges [rounddown(start, PAGE_SIZE), start] and
[end, roundup(end, PAGE_SIZE)].
Suppose variable m points at a vmcore object in vmcore_list, and
variable phdr points at the program header of PT_LOAD type the variable
m corresponds to. Then, pictorially:
m->offset +---------------+
| hole |
phdr->p_offset = +---------------+
m->offset + (paddr - start) | |\
| kernel memory | phdr->p_memsz
| |/
+---------------+
| hole |
m->offset + m->size +---------------+
where m->offset and m->offset + m->size are always page-size aligned.
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:15 +00:00
|
|
|
paddr = phdr_ptr->p_offset;
|
|
|
|
start = rounddown(paddr, PAGE_SIZE);
|
|
|
|
end = roundup(paddr + phdr_ptr->p_memsz, PAGE_SIZE);
|
|
|
|
size = end - start;
|
|
|
|
|
2005-06-25 21:58:22 +00:00
|
|
|
/* Add this contiguous chunk of memory to vmcore list.*/
|
|
|
|
new = get_new_element();
|
|
|
|
if (!new)
|
|
|
|
return -ENOMEM;
|
vmcore: treat memory chunks referenced by PT_LOAD program header entries in page-size boundary in vmcore_list
Treat memory chunks referenced by PT_LOAD program header entries in
page-size boundary in vmcore_list. Formally, for each range [start,
end], we set up the corresponding vmcore object in vmcore_list to
[rounddown(start, PAGE_SIZE), roundup(end, PAGE_SIZE)].
This change affects layout of /proc/vmcore. The gaps generated by the
rearrangement are newly made visible to applications as holes.
Concretely, they are two ranges [rounddown(start, PAGE_SIZE), start] and
[end, roundup(end, PAGE_SIZE)].
Suppose variable m points at a vmcore object in vmcore_list, and
variable phdr points at the program header of PT_LOAD type the variable
m corresponds to. Then, pictorially:
m->offset +---------------+
| hole |
phdr->p_offset = +---------------+
m->offset + (paddr - start) | |\
| kernel memory | phdr->p_memsz
| |/
+---------------+
| hole |
m->offset + m->size +---------------+
where m->offset and m->offset + m->size are always page-size aligned.
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:15 +00:00
|
|
|
new->paddr = start;
|
|
|
|
new->size = size;
|
2005-06-25 21:58:22 +00:00
|
|
|
list_add_tail(&new->list, vc_list);
|
|
|
|
|
|
|
|
/* Update the program header offset */
|
vmcore: treat memory chunks referenced by PT_LOAD program header entries in page-size boundary in vmcore_list
Treat memory chunks referenced by PT_LOAD program header entries in
page-size boundary in vmcore_list. Formally, for each range [start,
end], we set up the corresponding vmcore object in vmcore_list to
[rounddown(start, PAGE_SIZE), roundup(end, PAGE_SIZE)].
This change affects layout of /proc/vmcore. The gaps generated by the
rearrangement are newly made visible to applications as holes.
Concretely, they are two ranges [rounddown(start, PAGE_SIZE), start] and
[end, roundup(end, PAGE_SIZE)].
Suppose variable m points at a vmcore object in vmcore_list, and
variable phdr points at the program header of PT_LOAD type the variable
m corresponds to. Then, pictorially:
m->offset +---------------+
| hole |
phdr->p_offset = +---------------+
m->offset + (paddr - start) | |\
| kernel memory | phdr->p_memsz
| |/
+---------------+
| hole |
m->offset + m->size +---------------+
where m->offset and m->offset + m->size are always page-size aligned.
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:15 +00:00
|
|
|
phdr_ptr->p_offset = vmcore_off + (paddr - start);
|
|
|
|
vmcore_off = vmcore_off + size;
|
2005-06-25 21:58:22 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
/* Sets offset fields of vmcore elements. */
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
static void __init set_vmcore_list_offsets(size_t elfsz, size_t elfnotes_sz,
|
2013-07-03 22:02:14 +00:00
|
|
|
struct list_head *vc_list)
|
2005-06-25 21:58:21 +00:00
|
|
|
{
|
|
|
|
loff_t vmcore_off;
|
|
|
|
struct vmcore *m;
|
|
|
|
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
/* Skip Elf header, program headers and Elf note segment. */
|
|
|
|
vmcore_off = elfsz + elfnotes_sz;
|
2005-06-25 21:58:21 +00:00
|
|
|
|
|
|
|
list_for_each_entry(m, vc_list, list) {
|
|
|
|
m->offset = vmcore_off;
|
|
|
|
vmcore_off += m->size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-03 22:02:14 +00:00
|
|
|
static void free_elfcorebuf(void)
|
2005-06-25 21:58:22 +00:00
|
|
|
{
|
2013-07-03 22:02:14 +00:00
|
|
|
free_pages((unsigned long)elfcorebuf, get_order(elfcorebuf_sz_orig));
|
|
|
|
elfcorebuf = NULL;
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
vfree(elfnotes_buf);
|
|
|
|
elfnotes_buf = NULL;
|
2005-06-25 21:58:22 +00:00
|
|
|
}
|
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
static int __init parse_crash_elf64_headers(void)
|
|
|
|
{
|
|
|
|
int rc=0;
|
|
|
|
Elf64_Ehdr ehdr;
|
|
|
|
u64 addr;
|
|
|
|
|
|
|
|
addr = elfcorehdr_addr;
|
|
|
|
|
|
|
|
/* Read Elf header */
|
2013-09-11 21:24:49 +00:00
|
|
|
rc = elfcorehdr_read((char *)&ehdr, sizeof(Elf64_Ehdr), &addr);
|
2005-06-25 21:58:21 +00:00
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* Do some basic Verification. */
|
|
|
|
if (memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0 ||
|
|
|
|
(ehdr.e_type != ET_CORE) ||
|
2010-11-19 08:29:24 +00:00
|
|
|
!vmcore_elf64_check_arch(&ehdr) ||
|
2005-06-25 21:58:21 +00:00
|
|
|
ehdr.e_ident[EI_CLASS] != ELFCLASS64 ||
|
|
|
|
ehdr.e_ident[EI_VERSION] != EV_CURRENT ||
|
|
|
|
ehdr.e_version != EV_CURRENT ||
|
|
|
|
ehdr.e_ehsize != sizeof(Elf64_Ehdr) ||
|
|
|
|
ehdr.e_phentsize != sizeof(Elf64_Phdr) ||
|
|
|
|
ehdr.e_phnum == 0) {
|
2013-02-28 01:03:16 +00:00
|
|
|
pr_warn("Warning: Core image elf header is not sane\n");
|
2005-06-25 21:58:21 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in all elf headers. */
|
2013-07-03 22:02:14 +00:00
|
|
|
elfcorebuf_sz_orig = sizeof(Elf64_Ehdr) +
|
|
|
|
ehdr.e_phnum * sizeof(Elf64_Phdr);
|
|
|
|
elfcorebuf_sz = elfcorebuf_sz_orig;
|
|
|
|
elfcorebuf = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
|
|
|
|
get_order(elfcorebuf_sz_orig));
|
2005-06-25 21:58:21 +00:00
|
|
|
if (!elfcorebuf)
|
|
|
|
return -ENOMEM;
|
|
|
|
addr = elfcorehdr_addr;
|
2013-09-11 21:24:49 +00:00
|
|
|
rc = elfcorehdr_read(elfcorebuf, elfcorebuf_sz_orig, &addr);
|
2013-07-03 22:02:14 +00:00
|
|
|
if (rc < 0)
|
|
|
|
goto fail;
|
2005-06-25 21:58:21 +00:00
|
|
|
|
|
|
|
/* Merge all PT_NOTE headers into one. */
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
rc = merge_note_headers_elf64(elfcorebuf, &elfcorebuf_sz,
|
|
|
|
&elfnotes_buf, &elfnotes_sz);
|
2013-07-03 22:02:14 +00:00
|
|
|
if (rc)
|
|
|
|
goto fail;
|
2005-06-25 21:58:21 +00:00
|
|
|
rc = process_ptload_program_headers_elf64(elfcorebuf, elfcorebuf_sz,
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
elfnotes_sz, &vmcore_list);
|
2013-07-03 22:02:14 +00:00
|
|
|
if (rc)
|
|
|
|
goto fail;
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
set_vmcore_list_offsets(elfcorebuf_sz, elfnotes_sz, &vmcore_list);
|
2005-06-25 21:58:21 +00:00
|
|
|
return 0;
|
2013-07-03 22:02:14 +00:00
|
|
|
fail:
|
|
|
|
free_elfcorebuf();
|
|
|
|
return rc;
|
2005-06-25 21:58:21 +00:00
|
|
|
}
|
|
|
|
|
2005-06-25 21:58:22 +00:00
|
|
|
static int __init parse_crash_elf32_headers(void)
|
|
|
|
{
|
|
|
|
int rc=0;
|
|
|
|
Elf32_Ehdr ehdr;
|
|
|
|
u64 addr;
|
|
|
|
|
|
|
|
addr = elfcorehdr_addr;
|
|
|
|
|
|
|
|
/* Read Elf header */
|
2013-09-11 21:24:49 +00:00
|
|
|
rc = elfcorehdr_read((char *)&ehdr, sizeof(Elf32_Ehdr), &addr);
|
2005-06-25 21:58:22 +00:00
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* Do some basic Verification. */
|
|
|
|
if (memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0 ||
|
|
|
|
(ehdr.e_type != ET_CORE) ||
|
2016-02-11 12:36:54 +00:00
|
|
|
!vmcore_elf32_check_arch(&ehdr) ||
|
2005-06-25 21:58:22 +00:00
|
|
|
ehdr.e_ident[EI_CLASS] != ELFCLASS32||
|
|
|
|
ehdr.e_ident[EI_VERSION] != EV_CURRENT ||
|
|
|
|
ehdr.e_version != EV_CURRENT ||
|
|
|
|
ehdr.e_ehsize != sizeof(Elf32_Ehdr) ||
|
|
|
|
ehdr.e_phentsize != sizeof(Elf32_Phdr) ||
|
|
|
|
ehdr.e_phnum == 0) {
|
2013-02-28 01:03:16 +00:00
|
|
|
pr_warn("Warning: Core image elf header is not sane\n");
|
2005-06-25 21:58:22 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in all elf headers. */
|
2013-07-03 22:02:14 +00:00
|
|
|
elfcorebuf_sz_orig = sizeof(Elf32_Ehdr) + ehdr.e_phnum * sizeof(Elf32_Phdr);
|
|
|
|
elfcorebuf_sz = elfcorebuf_sz_orig;
|
|
|
|
elfcorebuf = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
|
|
|
|
get_order(elfcorebuf_sz_orig));
|
2005-06-25 21:58:22 +00:00
|
|
|
if (!elfcorebuf)
|
|
|
|
return -ENOMEM;
|
|
|
|
addr = elfcorehdr_addr;
|
2013-09-11 21:24:49 +00:00
|
|
|
rc = elfcorehdr_read(elfcorebuf, elfcorebuf_sz_orig, &addr);
|
2013-07-03 22:02:14 +00:00
|
|
|
if (rc < 0)
|
|
|
|
goto fail;
|
2005-06-25 21:58:22 +00:00
|
|
|
|
|
|
|
/* Merge all PT_NOTE headers into one. */
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
rc = merge_note_headers_elf32(elfcorebuf, &elfcorebuf_sz,
|
|
|
|
&elfnotes_buf, &elfnotes_sz);
|
2013-07-03 22:02:14 +00:00
|
|
|
if (rc)
|
|
|
|
goto fail;
|
2005-06-25 21:58:22 +00:00
|
|
|
rc = process_ptload_program_headers_elf32(elfcorebuf, elfcorebuf_sz,
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
elfnotes_sz, &vmcore_list);
|
2013-07-03 22:02:14 +00:00
|
|
|
if (rc)
|
|
|
|
goto fail;
|
vmcore: allocate ELF note segment in the 2nd kernel vmalloc memory
The reasons why we don't allocate ELF note segment in the 1st kernel
(old memory) on page boundary is to keep backward compatibility for old
kernels, and that if doing so, we waste not a little memory due to
round-up operation to fit the memory to page boundary since most of the
buffers are in per-cpu area.
ELF notes are per-cpu, so total size of ELF note segments depends on
number of CPUs. The current maximum number of CPUs on x86_64 is 5192,
and there's already system with 4192 CPUs in SGI, where total size
amounts to 1MB. This can be larger in the near future or possibly even
now on another architecture that has larger size of note per a single
cpu. Thus, to avoid the case where memory allocation for large block
fails, we allocate vmcore objects on vmalloc memory.
This patch adds elfnotes_buf and elfnotes_sz variables to keep pointer
to the ELF note segment buffer and its size. There's no longer the
vmcore object that corresponds to the ELF note segment in vmcore_list.
Accordingly, read_vmcore() has new case for ELF note segment and
set_vmcore_list_offsets_elf{64,32}() and other helper functions starts
calculating offset from sum of size of ELF headers and size of ELF note
segment.
[akpm@linux-foundation.org: use min(), fix error-path vzalloc() leaks]
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:02:19 +00:00
|
|
|
set_vmcore_list_offsets(elfcorebuf_sz, elfnotes_sz, &vmcore_list);
|
2005-06-25 21:58:22 +00:00
|
|
|
return 0;
|
2013-07-03 22:02:14 +00:00
|
|
|
fail:
|
|
|
|
free_elfcorebuf();
|
|
|
|
return rc;
|
2005-06-25 21:58:22 +00:00
|
|
|
}
|
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
static int __init parse_crash_elf_headers(void)
|
|
|
|
{
|
|
|
|
unsigned char e_ident[EI_NIDENT];
|
|
|
|
u64 addr;
|
|
|
|
int rc=0;
|
|
|
|
|
|
|
|
addr = elfcorehdr_addr;
|
2013-09-11 21:24:49 +00:00
|
|
|
rc = elfcorehdr_read(e_ident, EI_NIDENT, &addr);
|
2005-06-25 21:58:21 +00:00
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
if (memcmp(e_ident, ELFMAG, SELFMAG) != 0) {
|
2013-02-28 01:03:16 +00:00
|
|
|
pr_warn("Warning: Core image elf header not found\n");
|
2005-06-25 21:58:21 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e_ident[EI_CLASS] == ELFCLASS64) {
|
|
|
|
rc = parse_crash_elf64_headers();
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2005-06-25 21:58:22 +00:00
|
|
|
} else if (e_ident[EI_CLASS] == ELFCLASS32) {
|
|
|
|
rc = parse_crash_elf32_headers();
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2005-06-25 21:58:21 +00:00
|
|
|
} else {
|
2013-02-28 01:03:16 +00:00
|
|
|
pr_warn("Warning: Core image elf header is not sane\n");
|
2005-06-25 21:58:21 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-07-03 22:02:22 +00:00
|
|
|
|
|
|
|
/* Determine vmcore size. */
|
|
|
|
vmcore_size = get_vmcore_size(elfcorebuf_sz, elfnotes_sz,
|
|
|
|
&vmcore_list);
|
|
|
|
|
2005-06-25 21:58:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Init function for vmcore module. */
|
|
|
|
static int __init vmcore_init(void)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
2013-09-11 21:24:49 +00:00
|
|
|
/* Allow architectures to allocate ELF header in 2nd kernel */
|
|
|
|
rc = elfcorehdr_alloc(&elfcorehdr_addr, &elfcorehdr_size);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
/*
|
|
|
|
* If elfcorehdr= has been passed in cmdline or created in 2nd kernel,
|
|
|
|
* then capture the dump.
|
|
|
|
*/
|
kdump: add is_vmcore_usable() and vmcore_unusable()
The usage of elfcorehdr_addr has changed recently such that being set to
ELFCORE_ADDR_MAX is used by is_kdump_kernel() to indicate if the code is
executing in a kernel executed as a crash kernel.
However, arch/ia64/kernel/setup.c:reserve_elfcorehdr will rest
elfcorehdr_addr to ELFCORE_ADDR_MAX on error, which means any subsequent
calls to is_kdump_kernel() will return 0, even though they should return
1.
Ok, at this point in time there are no subsequent calls, but I think its
fair to say that there is ample scope for error or at the very least
confusion.
This patch add an extra state, ELFCORE_ADDR_ERR, which indicates that
elfcorehdr_addr was passed on the command line, and thus execution is
taking place in a crashdump kernel, but vmcore can't be used for some
reason. This is tested for using is_vmcore_usable() and set using
vmcore_unusable(). A subsequent patch makes use of this new code.
To summarise, the states that elfcorehdr_addr can now be in are as follows:
ELFCORE_ADDR_MAX: not a crashdump kernel
ELFCORE_ADDR_ERR: crashdump kernel but vmcore is unusable
any other value: crash dump kernel and vmcore is usable
Signed-off-by: Simon Horman <horms@verge.net.au>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-10-19 03:28:29 +00:00
|
|
|
if (!(is_vmcore_usable()))
|
2005-06-25 21:58:21 +00:00
|
|
|
return rc;
|
|
|
|
rc = parse_crash_elf_headers();
|
|
|
|
if (rc) {
|
2013-02-28 01:03:16 +00:00
|
|
|
pr_warn("Kdump: vmcore not initialized\n");
|
2005-06-25 21:58:21 +00:00
|
|
|
return rc;
|
|
|
|
}
|
2013-09-11 21:24:49 +00:00
|
|
|
elfcorehdr_free(elfcorehdr_addr);
|
|
|
|
elfcorehdr_addr = ELFCORE_ADDR_ERR;
|
2005-06-25 21:58:21 +00:00
|
|
|
|
2008-10-06 10:36:31 +00:00
|
|
|
proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
|
2005-06-25 21:58:21 +00:00
|
|
|
if (proc_vmcore)
|
|
|
|
proc_vmcore->size = vmcore_size;
|
|
|
|
return 0;
|
|
|
|
}
|
2014-01-23 23:55:45 +00:00
|
|
|
fs_initcall(vmcore_init);
|
2012-02-16 01:15:00 +00:00
|
|
|
|
|
|
|
/* Cleanup function for vmcore module. */
|
|
|
|
void vmcore_cleanup(void)
|
|
|
|
{
|
|
|
|
struct list_head *pos, *next;
|
|
|
|
|
|
|
|
if (proc_vmcore) {
|
2013-04-12 16:27:28 +00:00
|
|
|
proc_remove(proc_vmcore);
|
2012-02-16 01:15:00 +00:00
|
|
|
proc_vmcore = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear the vmcore list. */
|
|
|
|
list_for_each_safe(pos, next, &vmcore_list) {
|
|
|
|
struct vmcore *m;
|
|
|
|
|
|
|
|
m = list_entry(pos, struct vmcore, list);
|
|
|
|
list_del(&m->list);
|
|
|
|
kfree(m);
|
|
|
|
}
|
2013-07-03 22:02:14 +00:00
|
|
|
free_elfcorebuf();
|
2012-02-16 01:15:00 +00:00
|
|
|
}
|