Improve documentation of read_page()

Describe other fields that are guaranteed to be initialised.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
Allocate page buffer when setting page size

The buffer should be allocated as early as possible to allow reading
pages in arch init code.

I added a helper function (kdump_set_page_size) to ensure consistent
behaviour for all file formats.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
initialize_xen_map(): Do not re-allocate page buffer

The page buffer is set up when initialize_xen_map() is called, so the
allocation and free must go away. Note that there is a trick - the
original buffer is stored as "dir", and a new page buffer is allocated
for subsequent reads to avoid an unnecessary memcpy().

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
elfdump: Merge cleanup() and elf_cleanup()

Keep the cleanup code close together to improve readability.

There is no need to keep a separate cleanup() function, because
elf_cleanup() can always be used instead.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
Document which fields must be initialised for processing ELF notes

ELF notes are read when kdump_ctx is not yet fully initialised.
Clarify which fields must be set before calling kdump_process_note.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
kdump_set_page_size: check that page size is a power of 2

Move this sanity check into kdump_set_page_size() so that it is
applied to all possible sources for the page size.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
Set default page shift in kdump_set_arch()

If page size is still unknown when architecture is being set, the default
for that architecture should be used.

Note that this currently works only for architectures with a fixed page
size. Where multiple page sizes are possible, setting the architecture
fails. I'm not sure if silently using a default value is better...

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
Separate processing of noarch and arch notes

With ELF notes, there is a chicken-and-egg problem: some notes can be
processed only after arch-dependent fields are initialized (e.g. page
size), but those fields are initialised by processing ELF notes.

To solve this, the notes must be processed twice. First, the
arch-independent notes are processed, and then the arch-dependent ones.

This commit adds the function calls to process arch-dependent and
arch-independent notes separately.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
diskdump: fix use of wrong pointer when initialising header_version

Oops. When reading a 64-bit header, the header_version field would
be set incorrectly, causing all kinds of unexpected behaviour.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
diskdump: prevent integer overflow in sane_header_values()

On very large systems, max covered pfn may be higher than 2^32.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
diskdump: Reshuffle code to ensure correct initialisation order

Rework the init code so that page size is always fully initialised
before setting architecture.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
diskdump: Fix error path

Make sure that the cleanup routine is called if something fails in
open_common(). Note that the malloc() was changed to a calloc() to
ensure that all fields are initially zero, and the cleanup does not
check uninitialised variable (ddp->bitmap).

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
elfdump: Move LOAD segment processing to open_common()

This requires that the virtual address is stored in struct load_segment.
Note that the semantics gets fixed, too. Previously, arch_ops->
process_load() was called for all program header types, not only
LOAD segments.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
elfdump: store segment size instead of phys_end

It seems that storing the size is more practical for later use.
While doing that, I have renamed the fields (making them shorter).

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
elfdump: process noarch notes and arch notes separately

Loop over the notes twice, first processing noarch notes and then
arch-dependent notes.

This currently makes no practical difference, but allows to insert
some code between the two loops.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
elfdump: Initialise architecture after processing noarch notes

This allows e.g. to set the page size from VMCOREINFO and then process
the remaining (arch-dependent) notes.

Without this patch, libkdumpfile would fail on ELF dumps from
architectures that have a variable page size, because kdump_set_arch()
requires a known page size.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
Store page shift in kdump_ctx

Since bit shifting is faster than multiply/divide, let's add this
info into kdump_ctx.

I'm also providing a public API to get this value.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
Cleanup: rename kdump_s390_ops to kdump_s390dump_ops

Since there's a plan to add arch_ops for the s390 architecture, this
name would be in conflict.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
s390dump: Proper initialisation order

Set architecture as late as possible. This allows more flexibility in
arch init code.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
Add support for s390x

Add s390x initialisation. The vtop translation is a stub, but a non-NULL
pointer is needed, or KDUMP_KVADDR fails for all addresses.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>