The function copy_table_entry_write() maps/unmaps /proc/vmcore for each
64kB of the file in order to write its content to a dump partition.
This requires a page allocation of order 2 in kernel (crst_table_alloc)
each time a mmap() syscall is performed and which cannot always be
fulfilled due to external memory fragmentation. And this in turn
results in a OOM kernel panic while writing /proc/vmcore content to
a dump partition. To make zfcpdump more robust in the face of such
problems with page allocations of order > 0, we use a simple file
read/write loop to transfer the content of /proc/vmcore to a dump
partition. This solution is less efficient (by not much) than the old
one with mmap() because it requires additional user space copy but
we trade off here efficiency for robustness which is more important
for zfcpdump.
We use a statically allocated buffer to read data into from /proc/vmcore
and write to a dump partition to avoid repeated use of the memory
mapping kernel path which would be required for a buffer allocated
dynamically at each entry of copy_table_entry_write().
Another possible and very convenient solution would be to use sendfile()
which would avoid any user space copies but, unfortunately, sendfile()
doesn't work with large /proc files.
Example of failed mmap() call for /proc/vmcore
==============================================
[ 26.568654] init invoked oom-killer: gfp_mask=0x40cc0(GFP_KERNEL|__GFP_COMP), order=2, oom_score_adj=0
[ 26.568665] CPU: 0 PID: 1 Comm: init Not tainted 6.9.0-20240504.rc6.git0.9986ea583f39.300.fc39.s390x+zfcpdump #1
[ 26.568668] Hardware name: IBM 3931 A01 704 (LPAR)
[ 26.568669] Call Trace:
[ 26.568671] [<000003ffe03277c6>] dump_stack_lvl+0x76/0x98
[ 26.568676] [<000003ffe00f15c8>] dump_header+0x58/0x2d0
[ 26.568680] [<000003ffe00f219a>] out_of_memory+0x252/0x348
[ 26.568683] [<000003ffe0132f3e>] __alloc_pages_slowpath.constprop.0+0x65e/0x7c0
[ 26.568686] [<000003ffe01331a4>] __alloc_pages+0x104/0x128
[ 26.568688] [<000003ffe001ab46>] crst_table_alloc+0x2e/0xa0
[ 26.568693] [<000003ffe01164c4>] __pmd_alloc+0x24/0x160
[ 26.568696] [<000003ffe0116650>] pmd_alloc+0x50/0x68
[ 26.568698] [<000003ffe0117be4>] remap_pfn_range_notrack+0x194/0x310
[ 26.568701] [<000003ffe0117d7c>] remap_pfn_range+0x1c/0x28
[ 26.568703] [<000003ffe0015442>] remap_oldmem_pfn_range+0xb2/0x108
[ 26.568705] [<000003ffe01a0544>] mmap_vmcore+0x414/0x448
[ 26.568707] [<000003ffe01937c4>] proc_reg_mmap+0x84/0xa0
[ 26.568709] [<000003ffe011f264>] mmap_region+0x22c/0x6f8
[ 26.568711] [<000003ffe011fae8>] do_mmap+0x3b8/0x410
[ 26.568713] [<000003ffe01015cc>] vm_mmap_pgoff+0x9c/0xe8
[ 26.568715] [<000003ffe011d006>] ksys_mmap_pgoff+0x8e/0xb8
[ 26.568716] [<000003ffe011d0f4>] __s390x_sys_old_mmap+0x74/0x90
[ 26.568718] [<000003ffe0341a2a>] __do_syscall+0x1aa/0x220
[ 26.568720] [<000003ffe03478b0>] system_call+0x70/0x98
[ 26.568724] Mem-Info:
[ 26.568725] active_anon:1 inactive_anon:12 isolated_anon:0
active_file:83590 inactive_file:93939 isolated_file:0
unevictable:201 dirty:17845 writeback:4
slab_reclaimable:4259 slab_unreclaimable:1482
mapped:174 shmem:0 pagetables:810
sec_pagetables:0 bounce:0
kernel_misc_reclaimable:0
free:2694 free_pcp:105 free_cma:0
[ 26.568729] Node 0 active_anon:4kB inactive_anon:48kB active_file:334360kB inactive_file:375756kB unevictable:804kB isolated(anon):0kB isolated(file):0kB mapped:696kB dirty:71380kB writeback:16kB shmem:0kB writeback_tmp:0kB kernel_stack:544kB pagetables:3240kB sec_pagetables:0kB all_unreclaimable? no
[ 26.568732] DMA free:10776kB boost:0kB min:3496kB low:4368kB high:5240kB reserved_highatomic:0KB active_anon:4kB inactive_anon:48kB active_file:334360kB inactive_file:375756kB unevictable:804kB writepending:71360kB present:786428kB managed:764664kB mlocked:0kB bounce:0kB free_pcp:420kB local_pcp:420kB free_cma:0kB
[ 26.568735] lowmem_reserve[]: 0 0 0
[ 26.568738] DMA: 1069*4kB (UH) 757*8kB (UH) 11*16kB (H) 6*32kB (H) 1*64kB (H) 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 10764kB
[ 26.568747] 177773 total pagecache pages
[ 26.568748] 196607 pages RAM
[ 26.568748] 0 pages HighMem/MovableOnly
[ 26.568749] 5441 pages reserved
[ 26.568749] Tasks state (memory values in pages):
[ 26.568750] [ pid ] uid tgid total_vm rss rss_anon rss_file rss_shmem pgtables_bytes swapents oom_score_adj name
[ 26.568751] Out of memory and no killable processes...
[ 26.568752] Kernel panic - not syncing: System is deadlocked on memory
[ 26.568755] CPU: 0 PID: 1 Comm: init Not tainted 6.9.0-20240504.rc6.git0.9986ea583f39.300.fc39.s390x+zfcpdump #1
[ 26.568758] Hardware name: IBM 3931 A01 704 (LPAR)
[ 26.568759] Call Trace:
[ 26.568760] [<000003ffe03277c6>] dump_stack_lvl+0x76/0x98
[ 26.568763] [<000003ffe001f14e>] panic+0x10e/0x2e8
[ 26.568765] [<000003ffe00f21c8>] out_of_memory+0x280/0x348
[ 26.568768] [<000003ffe0132f3e>] __alloc_pages_slowpath.constprop.0+0x65e/0x7c0
[ 26.568771] [<000003ffe01331a4>] __alloc_pages+0x104/0x128
[ 26.568773] [<000003ffe001ab46>] crst_table_alloc+0x2e/0xa0
[ 26.568776] [<000003ffe01164c4>] __pmd_alloc+0x24/0x160
[ 26.568779] [<000003ffe0116650>] pmd_alloc+0x50/0x68
[ 26.568781] [<000003ffe0117be4>] remap_pfn_range_notrack+0x194/0x310
[ 26.568784] [<000003ffe0117d7c>] remap_pfn_range+0x1c/0x28
[ 26.568787] [<000003ffe0015442>] remap_oldmem_pfn_range+0xb2/0x108
[ 26.568789] [<000003ffe01a0544>] mmap_vmcore+0x414/0x448
[ 26.568791] [<000003ffe01937c4>] proc_reg_mmap+0x84/0xa0
[ 26.568793] [<000003ffe011f264>] mmap_region+0x22c/0x6f8
[ 26.568795] [<000003ffe011fae8>] do_mmap+0x3b8/0x410
[ 26.568797] [<000003ffe01015cc>] vm_mmap_pgoff+0x9c/0xe8
[ 26.568799] [<000003ffe011d006>] ksys_mmap_pgoff+0x8e/0xb8
[ 26.568801] [<000003ffe011d0f4>] __s390x_sys_old_mmap+0x74/0x90
[ 26.568803] [<000003ffe0341a2a>] __do_syscall+0x1aa/0x220
[ 26.568805] [<000003ffe03478b0>] system_call+0x70/0x98
Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Having timestamps in gzip leads to lintian warning
'package-contains-timestamped-gzip' and will harm reproducible builds.
Gzip option '-n' avoids saving original file name and especially timestamps
by default.
Fixes: https://github.com/ibm-s390-linux/s390-tools/pull/169
Signed-off-by: Frank Heimes <frank.heimes@canonical.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
[seiden@linux.ibm.com: Fix commit message]
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Check for vmcore LOAD segment with zero paddr (instead of zero vaddr) to
identify HSA since physical and virtual addresses can be uncoupled on s390.
Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Acked-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
The rust integration into the s390-tools build system consists of the
following steps:
- Add a subdirectory for the rust code.
- Add a Makefile that forwards rust builds to `cargo`.
- Add a `utils` crate for rust code in s390-tools.
- Add rust stuff for dotfiles:
- gitignore
- editorconfig
- codespellrc (while at it, add an ignore file)
With cargo the rust ecosystem has its own build system which also is
responsible to resolve rust dependencies via downloading the dependencies
from (default) crates.io and discover the source files. Therefore, the
Makefile just calls `cargo build` to forward the build to cargo.
If a rust crate does not require external dependencies, users might call
rustc directly.
A simple `make` will build all the rust targets as well (with --release
specified). Also `make install` will work as usual.
A few Makefile configuration variables are introduced for rust/Cargo:
- HAVE_CARGO (default 1) to toggle the build of rust code using cargo
- CARGOFLAGS to add custom cargo flags, e.g. --offline
- CARGO Cargo binary location defaults to
$(where cargo)
A new global make target is defined to get the current s390-tools
version:
$ make version
2.28.0
rust/Makefile also has the `print-rust-targets` target to print all rust
directories/crates that should be shipped/installed.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Commit 62ec87680a61 ("common.mak: improve cross compilation support")
added one extra whitespace during the changes of the toolchain command
definitions. The rest of the commands did not receive that change.
Since then the pretty print output looks like this:
...
CC zipl/boot/eckd1b.o
CXX ziomon/ziorep_collapser.o
SED zdev/src/lszdev_usage.c
CC hyptop/sd_cpu_items.o
MV zfcpdump/zfcpdump-initrd
LINK dasdfmt/dasdfmt
...
Add the additional whitespace to all other tools definitions used during
the build process.
Note: This doesn't fix the misaligned indentation for commands like
$(CC_FOR_BUILD) as those inherit the whitespace from the original
command, here $(CC).
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Introduce `BUILD_ARCH` and `(CC|LINK|...|OBJDUMP)_FOR_BUILD` variables
in order to properly support the build of tools that generate code or
data during the build process. Replace existing variables `HOSTCC` with
`CC_FOR_BUILD` and `HOSTCFLAGS` `CFLAGS_FOR_BUILD`. The Makefile
variables for the `HOST_ARCH` are unchanged.
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Install libasan first, e.g. on Fedora 32:
dnf install -y libasan libasan-static.
To compile with address sanitizer, pass ASAN=1 to make.
AdressSanitizer helps to catch various memory bugs for which C/C++ is
infamous.
Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Philipp Rudo <prudo@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Remove obsolete and unused constants for zcore memory
character devices '/sys/kernel/debug/zcore/mem' and
'/sys/kernel/debug/zcore/memmap'.
Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Philipp Rudo <prudo@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Dump compression was a feature of the file system dumper which was removed
several years ago. This include is a leftover. Remove it.
Signed-off-by: Philipp Rudo <prudo@linux.ibm.com>
Acked-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
When zfcpdump is built you get a compile warning
zfcpdump.c: In function ‘init_sig’:
zfcpdump.c:307:24: warning: cast between incompatible function types from ‘void (* (*)(int, siginfo_t *, void *))(int)’ {aka ‘void (* (*)(int, struct <anonymous> *, void *))(int)’} to ‘void (*)(int)’ [-Wcast-function-type]
g.sigact.sa_handler = (__sighandler_t)dump_sig_handler;
Furthermore the man pages for sigaction says
$man 2 sigaction
[...]
If SA_SIGINFO is specified in sa_flags, then sa_sigaction (instead
of sa_handler) specifies the signal-handling function for signum.
This function receives three arguments, as described below.
[...]
Because SA_SIGINFO is set, using sa_handler at all is wrong in this case.
Fix this by giving dump_sig_handler the correct return type and assign it
to sa_sigaction.
Signed-off-by: Philipp Rudo <prudo@linux.ibm.com>
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
The zfcpdump kernel is built without module support. Furthermore the initrd
doesn't contain modprobe. So trying to load modules using modprobe in
zfcpdump userspace doesn't really make sense.
Signed-off-by: Philipp Rudo <prudo@linux.ibm.com>
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Since version 198 (Feb 2013) systemd contains kernel-install, a script
managing kernel installs. This script allows execution of drop-in scripts
for customization. Add such a drop-in script to s390-tools to handle the
installation of zfcpdump kernels.
It's main purpose is to manage a link to the latest installed zfcpudump
kernel at ZFCPDUMP_IMAGE, where zipl expects to find the image to install
for a SCSI dumper.
The script supports two installation modes. One recommended by the
BootLoaderSpecs [1] to /boot/<machine-id>/<kernel-version> directories and
one directly to /boot. In the second case files are renamed during
installation to <original-name>-<kernel-version> to guarantee unique names.
Because the zfcpdump kernel is so special make the script stand-alone and
prevent any other script from being executed (exit 77) when a zfcpdump is
installed. Especially avoid functionality like creating an initrd (already
provided by s390-tools) or creating a boot entry (the zfcpdump kernel
should not be used for any other purpose than dumping).
The script requires systemd >= 203.
[1] https://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/
Signed-off-by: Philipp Rudo <prudo@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
The file system dumper no longer exists. So there is no need in keeping
'PART' to distinguish between the file system and the partition dumper.
Adjust the macro name to the usage in zipl by removing 'PART'.
While at it also adjust the file names the macros stand for.
Signed-off-by: Philipp Rudo <prudo@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
For systems that do not have glibc-static installed, print the
following error message when building zfcpdump:
s390-tools/zfcpdump # make
REQCHK zfcpdump (stdio.h)
****************************************************************
* Missing build requirement for: zfcpdump *
* Install package..............: glibc-static or libc-dev *
* You can skip build with......: make HAVE_LIBC_STATIC=0 *
****************************************************************
To allow the check add a new compiler/linker option to the "check_dep"
macro and do full compile/link instead of a simple compile.
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
This commit is based on the s390-tools-1.39.0 version.
Changes on top of s390-tools-1.39.0:
- Add MIT license to all source files
- Add LICENSE file
- Transform REAMDE to README.md (markdown)
- Add AUTHORS.md file
- Add CONTRIBUTING.md file
- Move changelog from README to CHANGELOG.md file
Reviewed-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>