[PATCH v3] Introduce the mdf_pfn_t type.

Replace unsigned long long with mdf_pfn_t where:

  a. the variable denotes a PFN
  b. the variable is a number of pages

The number of pages is converted to a mdf_pfn_t, because it is a result
of subtracting two PFNs or incremented in a loop over a range of PFNs,
so it can get as large as a PFN.

Note: The mdf_ (i.e. makedumpfile) prefix is used to prevent possible
conflicts with other software that defines a pfn_t type.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
[PATCH] Fix bug on is_sparsemem_extreme.

The kernel gets the length of mem_section use this
from: include/linux/mmzone.h:1134

 "#define NR_SECTION_ROOTS  DIV_ROUND_UP(NR_MEM_SECTIONS,
					 SECTIONS_PER_ROOT)"

But when we check the memory model. We forget the
"DIV_ROUND_UP" method.

So when 32-bit ARM linux is in sparsemem_extreme memory:
 with SECTION_SIZE_BIT=28 and 16 byte-size mem_section.
The makedumpfile can not  identify the memory correctly.

This patch introduce the "DIV_ROUND_UP" method in this check.

Signed-off-by: Liu Hua <sdu.liu@huawei.com>
[PATCH v3] Fix free bitmap_buffer_cyclic error.

Description:
In create_dump_bitmap() and write_kdump_pages_and_bitmap_cyclic(),
What should be freed is info->partial_bitmap instead of info->bitmap.

Solution:
Add two functions to free the bitmap_buffer_cyclic. info->partial_bitmap1
is freed by free_bitmap1_buffer_cyclic(). info->partial_bitmap2 is
freed by free_bitmap2_buffer_cyclic(). At the same time, remove
thoes frees that free partial_bitmap1 or partial_bitmap2 at the end
of main() because partial_bitmap1 and partial_bitmap2 has been freed
after dump file has been written out, so there is no need to free it
again at the end of main.

Signed-off-by: Arthur Zou <zzou@redhat.com>
[PATCH] ARM: fix bug on sparse_decode_mem_map.

In sparse_decode_mem_map, makedumpfile checks whether coded_mem_map
is a valid vaddr. But coded_mem_map is not real vaddr. So this patch
checks decoded_mem_map instead.

Signed-off-by: Liu Hua <sdu.liu@huawei.com>
[PATCH] Get MAX_PHYSMEM_BITS and SECTION_SIZE_BITS from vmcore.

Now we define MAX_PHYSMEM_BITS and SECTION_SIZE_BITS as
macros. But for ARM32 platform, different venders may
define different SECTION_SIZE_BITS. for example:

  1 arch/arm/mach-clps711x/include/mach/memory.h
    #define SECTION_SIZE_BITS 24
  2 arch/arm/mach-exynos/include/mach/memory.h
    #define SECTION_SIZE_BITS 28
  3 arch/arm/mach-sa1100/include/mach/memory.h
    #define SECTION_SIZE_BITS 27

And if Large Physical Address extension is enabled,
MAX_PHYSMEM_BITS may also be changed.

"So makedumpfile can't get an appropriate values of the two
macros since the values are variable even if the architecture
and the kernel version are fixed (at least for arm)" --
Atsushi Kumagai

This patch makes makedumpfile get these two values from
vmcore info, which makes the makedumpfile more compatible.

Signed-off-by: Liu Hua <sdu.liu@huawei.com>
[PATCH v4 1/2] Generic handling of multi-page exclusions.

When multiple pages are excluded from the dump, store the extents in
struct cycle and check if anything is still pending on the next invocation
of __exclude_unnecessary_pages. This assumes that:

  1. after __exclude_unnecessary_pages is called for a struct mem_map_data
     that extends beyond the current cycle, it is not called again during
     that cycle,
  2. in the next cycle, __exclude_unnecessary_pages is not called before
     this final struct mem_map_data.

Both assumptions are met if struct mem_map_data segments:

  1. do not overlap,
  2. are sorted by physical address in ascending order.

These two conditions are true for all supported memory models.

Note that the start PFN of the excluded extent is set to the end of the
current cycle (which is equal to the start of the next cycle, see
update_cycle), so only the part of the excluded region which falls beyond
current cycle buffer is valid. If the excluded region is completely
processed in the current cycle, the start PFN is bigger than the end PFN
and no work is done at the beginning of the next cycle.

After processing the leftover from last cycle, pfn_start and mem_map are
adjusted to skip the excluded pages. There is no check whether the
adjusted pfn_start is within the current cycle. Nothing bad happens if
it isn't, because pages outside the current cyclic region are ignored by
the subsequent loop, and the remainder is postponed to the next cycle by
exclude_range().

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
[PATCH v4 2/2] Get rid of overrun adjustments.

Thanks to the previous commit, __exclude_unnecessary_pages does not
require any specific size of the cycle.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
[PATCH] Fix Makefile for eppic_makedumpfile.so build.

When libeppic isn't installed on a standard location, building
eppic_makedumpfile.so with -leppic directly doesn't work.

Add LDFLAGS to build arguments, so that one can pass LDFLAGS="-Ldir
-Idir" to tell where to search for libeppic library and its header
files.

For example, if eppic source is installed on the same directory level
with makedumpfile as the following:

makedumpfile
 |--- arch
 +--- eeppic_scripts
eppic
 |--- applications
 +--- libeppic

After compiling libeppic, one can use the following command to build
eppic_makedumpfile.so:

make LDFLAGS="-I../eppic/libeppic -L../eppic/libeppic" eppic_makedumpfile.so

Signed-off-by: WANG Chao <chaowang@redhat.com>
[PATCH 1/3] Remove the 1st bitmap buffer from the ELF path in cyclic mode.

We can create the 2nd bitmap without creating the 1st bitmap by commit
363d53fc8, so we don't need to create the 1st bitmap in cyclic mode
in the ELF path since it isn't used. Thus, we can use the whole bitmap
buffer only for the 2nd bitmap like the kdump path.

Signed-off-by: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
[PATCH 2/3] Move counting pfn_memhole for cyclic mode.

In cyclic mode, memory holes are checked in initialize_2nd_bitmap_cyclic()
in both the kdump path and the ELF path, so pfn_memhole should be
counted there.

Signed-off-by: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
[PATCH 3/3] Stop maximizing the bitmap buffer to reduce the risk of OOM.

We tried to maximize the bitmap buffer to get the best performance,
but the performance degradation caused by multi-cycle processing
looks very small according to the benchmark on 2TB memory:

  https://lkml.org/lkml/2013/3/26/914

This result means we don't need to make an effort to maximize the
bitmap buffer, it will just increase the risk of OOM.

This patch sets a small fixed value (4MB) as a safety limit,
it may be safer and enough in most cases.

Signed-off-by: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
[PATCH v3 1/2] Initialize for vmalloc address translation support in PPC64 arch.

In this patch, initializing of page table information that is to be
used for virtual to physical address translation  of vmalloc region
is added to the initialization sequence.

Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
[PATCH v3 2/2] vtop address translation support for vmalloc region in PPC64 arch.

This patch adds virtual to physical address translation support
for vmalloc region in PPC64 architecture.

Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
[PATCH v4] Exclude unnecessary hugepages.

There are 2 types of hugepages in the kernel, the both should be
excluded as user pages.

1. Transparent huge pages (THP)
All the pages are anonymous pages (at least for now), so we should
just get how many pages are in the corresponding hugepage.
It can be gotten from the page->lru.prev of the second page in the
hugepage.

2. Hugetlbfs pages
The pages aren't anonymous pages but kind of user pages, we should
exclude also these pages in any way.
Luckily, it's possible to detect these pages by looking the
page->lru.next of the second page in the hugepage. This idea came
from the kernel's PageHuge().
The number of pages can be gotten in the same way as THP.

Changelog:
v4:
  - Cleaned up according to Petr's and Baoquan's comments.
v3:
  - Cleaned up according to Petr's comments.
  - Fix misdetection of hugetlb pages.
v2:
  - Rebased to "Generic multi-page exclusion".

Signed-off-by: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
[PATCH] dump_log_entry: replace magic constant with a variable.

If the buffer space requirements are changed, the magic constant is
hard to spot, and the failure is easily overlooked, because it may
fail only under special conditions.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
[PATCH v2] Fix dmesg format after crash utility.

Add some spaces before a new line as much as the length
of the timestamp like crash utility as:

    $ diff -u  current.dmesg fixed.dmesg
    --- current.dmesg       2014-08-28 17:39:53.000000000 +0900
    +++ fixed.dmesg 2014-08-27 16:46:09.000000000 +0900
    @@ -150,8 +150,8 @@
     [    0.015251] Disabled fast string operations
     [    0.015285] mce: CPU supports 10 MCE banks
     [    0.015402] Last level iTLB entries: 4KB 0, 2MB 0, 4MB 0
    -Last level dTLB entries: 4KB 0, 2MB 0, 4MB 0, 1GB 0
    -tlb_flushall_shift: 6
    +               Last level dTLB entries: 4KB 0, 2MB 0, 4MB 0, 1GB 0
    +               tlb_flushall_shift: 6
     [    0.015535] Freeing SMP alternatives memory: 20K (ffffffff81964000 - ffffffff81969000)
     [    0.018265] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
     [    0.028286] smpboot: CPU0: Intel QEMU Virtual CPU version (cpu64-rhel6) (fam: 06, model: 0d, stepping: 03)
    $

Signed-off-by: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
[PATCH] Fix description about filtering for Xen.

Correct the following points for Xen dump:

  - Add how to filter the pages of domain-0.
  - Fix the difference between man and help.

Reported-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
[PATCH v6 1/8] Initialize pfn_memhole in get_num_dumpable_cyclic.

This is a code bug. In initialize_2nd_bitmap_cyclic pfn_memhole is
calculated, however it's not initialized before that. If an available
pfn_memhole is wanted after get_num_dumpable_cyclic invocation,
initializing pfn_memhole in get_num_dumpable_cyclic is necessary.

Signed-off-by: Baoquan He <bhe@redhat.com>
[PATCH v6 2/8] Functions to get crashkernel memory range.

These functions are used to parse /proc/iomem code and get memory
ranges of specific type. They are implemented in kexec-tools and
borrowed here to get the crashkernel memory range. Since crashkernel
memory range should be excluded from dumpable memory ranges.

Signed-off-by: Baoquan He <bhe@redhat.com>
[PATCH v6 3/8] Preparation functions for parsing vmcoreinfo.

Add 2 preparation functions get_elf_loads and get_page_offset, later
they will be needed for parsing vmcoreinfo.

Meanwhile since get_kernel_version need be called to get page_offset
before initial() in mem_usage code flow, and surely it will be called
inside initial() again. Add a static variable to avoid this duplicate
calling.

Signed-off-by: Baoquan He <bhe@redhat.com>