Commit Graph

91 Commits

Author SHA1 Message Date
Eduard Shishkin
ee8897f9db zipl/src: Add ->set_location() private method of program component
Add/use ->set_location() private method of struct component_footer
instead of checking component types every time when operating with
program components.

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2026-07-03 12:05:06 +02:00
Eduard Shishkin
f2902a1990 zipl/src: Fix alignment of componets location in bootmap file
Calculate the alignment value as maximum of physical block sizes of
disks participating in the mirrored setup. Earlier the alignment was
calculated as a physical block size of the first disk of a mirrored
setup.

Without this change, the assertion in disk_get_blocklist_from_file()
'assert(reg->offset % info->phy_block_size == 0)' is triggered in case
when blocksize of base disk #J > blocksize of base disk #I && (J>I).
To reproduce the problem, build a mixed mirrored setup with first SCSI
disk, second DASD disk and prepare it for IPL.

Fixes: 731f00202c ("zipl/src: Enable heterogeneous mirrors support")
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2026-07-03 12:05:06 +02:00
Eduard Shishkin
9882aabe44 zipl/src: Update format of zipl helpers output
Change the format of zipl helpers output to support hybrid mirrors
(i.e. composed of disks of different types and geometry).
The new format imposes an additional requirement that any key-value
pair "targetbase=X:Y" titles a new section with a set of target
parmeters for the base disk identified by that pair.

Without this change, zipl reports "Inconsistent script output".
To reproduce the problem, build a mixed mirrored setup with first
SCSI disk and second DASD disk, and prepare it for IPL.

Fixes: 731f00202c ("zipl/src: Enable heterogeneous mirrors support")
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2026-07-03 12:05:06 +02:00
Eduard Shishkin
a902fd9afe zipl/src: Introduce verbosity levels of zipl session
Introduce verbosity levels of zipl session and verbosity classes of
messages. This is used by the next patches in the series to suppress
information not corresponding the default output of zipl tool that
could be confusing for user.

Add a new option "--debug" of zipl tool to set up verbosity level 2
(and higher) of zipl session.

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2026-06-25 14:14:43 +02:00
Eduard Shishkin
d1ab6be082 zipl/src: Don't modify job->data.dump and job->data.mvdump sequentially
Set job->data.dump.no_compress (job->data.mvdump.force) only after
making sure that the job is 'dump' ('mvdump') respectively. Othrewise,
the second assignment can potentially corrupt the value that was set by
the first assignment.

Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2026-05-21 13:20:06 +02:00
Eduard Shishkin
5c2e6fd730 zipl/src: Fix dump job on tape devices
Fix incorrect handling of tape devices leading to inability of
creating dumps on them.
Make the check for tape device go first, to not miss it on irrelevant
errors

Reported-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2026-02-12 13:08:47 +01:00
Eduard Shishkin
179bc57cdf zipl/src: Use a matrix of component ranges instead of an array
Fix a design mistake leading to IPL programs corruption.
Use a matrix of component ranges to locate the added components in the
body of bootmap file instead of an array.
Earlier an array of NR_PROGRAM_COMPONENTS was used, which is incorrect
Now a matrix of (NR_PROGRAM_COMPONENTS X BOOT_MENU_ENTRIES) is used.

Don't duplicate environment block for each menu entry. Instead, reuse
the one that was added when processing the first menu entry.

Tested-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reported-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2025-09-15 11:47:32 +02:00
Eduard Shishkin
1ca5f63dee zipl/src: Use generic infrastructure when adding environment block
Apply previously introduced generic infrastructure to add an
environment block as a "buffer component".


Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2025-09-15 11:12:16 +02:00
Eduard Shishkin
431e4542ca zipl/src: Reuse data of file components in bootmap
If the option '--add-files' is specified, don't duplicate data of
components added via add_component_file() and friends to bootmap
file for each mirror. Instead, reuse the data that were added when
preparing a program table for the first mirror to create metadata
(block lists, program tables, etc) specific for other mirrors.


Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2025-09-15 11:12:16 +02:00
Eduard Shishkin
731f00202c zipl/src: Enable heterogeneous mirrors support
Drop limitations on identical target parameters of base disks per
logical device;

Fix verbose zipl output to include geometry of each mirror and
component load addresses that would be used when booting from each
mirror.


Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2025-09-15 11:12:16 +02:00
Eduard Shishkin
2945593991 zipl/src: Support (create/boot-with) different program tables per target
Replace struct install_set with a new type containing multiple
program tables and program components. Refactor the code accordingly.

When retrieving device INFO, for each mirror complete a respective
structure disk_info in the INFO.BASE array.

When building a bootmap, for each mirror create a separate program
table (or a pair of tables in case of DASD - for CCW-TYPE IPL and
for LD-IPL), using respective components in the arrays INFO.BASE and
BIS.MIRRORS

Make data of program components added via get_component_buffer() and
get_component_file() be duplicated per each mirror.

Make boot record on each mirror point out to a respective program
table in the bootmap (when booting from different mirrors, different
program tables in the bootmap are used).

This patch doesn't make functional changes. However, test cases
comparing boot meta-data dumps of different mirrors may fail (since
boot records on different mirrors now refer different copies of boot
data). This will be fixed by the next patches in the series which
allow boot data to be reused.


Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2025-09-15 11:12:15 +02:00
Eduard Shishkin
f375327085 zipl/src: Support multiple disk_info structures per logical device
Replace struct disk_info with new 2 types.

Old type:

struct disk_info {
  A; /* logical device info */
  B; /* basedisk info */
};

New types:

struct disk_info {
  B; /* basedisk info */
};

and

struct device_info {
  A; /* logical device info */
  struct disk_info C [MAX_TARGETS]; /* array of base disks */
};

Here A (logical device info) is the following:

dev_t device;     /* logical device for bootmap creation */
char *name;       /* name of logical device as reetrieved from
                     "/proc/partitions" */
char *drv_name;   /* name of the driver managing the logical
                     device  as retrieved from "/proc/devices",
                     or evaluated */
int fs_block_size;

Refactor the code respectively, to use only the first element of
the array C, so that this patch represents an equivalent transform.


Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2025-09-15 11:12:15 +02:00
Eduard Shishkin
95e4b3413a zipl/src: Prepare for global sync(2) removal
zipl tool calls sync(2) before exit, which may hang on attempts to
flush not relevant problematic mounts (e.g. nfs) [1].

Complete any modification performed by zipl(8) tool with calling
fsync(2), or syncfs(2). This allows to get rid of the mentioned
sync(2) call.

[1] https://github.com/openshift/os/issues/1720
Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/186
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2025-07-08 10:23:08 +02:00
Eduard Shishkin
34a5e47508 zipl_helper.device-mapper: Fix imprecise is_device_mapper() predicate
Fix is_device_mapper() predicate to not base on checking a hardcoded
major number (253), which not always correct, since on some systems
dm-devices have different majors".

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2025-05-05 17:20:35 +02:00
Eduard Shishkin
c39722aff2 zipl/src: Implement '--dry-run' option for ngdumps
Use the directory specified by the shell environment variable TMPDIR
for temporary objects creation and ngdump job simulation. If TMPDIR is
not set, then use "/tmp" for the mentioned purposes;

While running ngdump job in 'dry-run' mode:
. Don't format/mount the target dump device. Instead, create the
  bootmap file and the meta-file at the temporary mount point without
  mounting anything to it. Thus, the mentioned files to be acrually
  created in the "proxy" file system owning the temporary mount point;
. Retrieve base disk info from the read-only dump device and
  complete that info with the block size of the proxy file system;

Separate the steps on retrieving/setting file system block size
into a dedicated procedure;

Use definitions instead of hardcoded file names;

Fix a bug in an error path (accessing freed memory);

Make misc_open_simulate() and misc_open_exclusive() static;

Update man pages with the requirements on the system environment
(resources) for ngdump job being executed in dry-run mode;

Provide hints for user (in stderr) in case when ngdump job in dry-run
mode failed due to inappropriate system environment.

Tested-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2025-04-07 17:42:18 +02:00
Eduard Shishkin
72218c5bc3 zipl/src: Introduce misc_open_simulate() and misc_open_device()
Introduce misc_open_simulate() to mark individual files as "opened
for write simulation".
Introduce misc_open_device() to open a file either in "usual", or
in "simulation" mode, depending on the passed argument

Tested-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2025-04-07 17:42:18 +02:00
Eduard Shishkin
b94566048b zipl/src: Introduce 'write simulation' mode for individual files
Introduce a write simulation operation, which doesn't write actual
data and just updates the current position in the file.
This allows to emulate block lists for files located on raw devices
(not formatted with a file system). This is used by the next patches
in the series to implement '--dry-run' zipl option for dumps of all
types (not only ngdumps).

Introduce a 'misc file descriptor', which allows to mark individual
files as "opened in a simulation mode".

Whenever bulding a bootmap file, use either real write, or write
simulation depending on the mode set in the 'misc file descriptor'.

Tested-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2025-04-07 17:42:18 +02:00
Eduard Shishkin
85a232a711 zipl/src: Add missed removal of temporary ramdisk
Remove temporary ramdisk created by zipl_helper.prepare-ngdump in
dump job session

Tested-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2025-04-07 17:42:18 +02:00
Eduard Shishkin
41da0f0809 zipl/src: make disk type detecton fail
When detecting disk type, the function disk_get_info() is called.
It can fail for various reasons (e.g. when the logial target is not
eligible for boot record installation).

Once disk_get_info() fails, don't proceed with type detection.
Return error instead. When applicable, mark the dump job with
"is_ngdump" flag to avoid extra type detection calls.

Acked-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-09-13 19:15:01 +02:00
Eduard Shishkin
d6b702d579 zipl/src: add basic support for multiple target base disks
. Modify disk_get_info() to process multiple sets of target parameters
  provided by the helper script and store it in the array of "targets"
  of the structure job_target_data;
. Besides the logical device, maintain an array of physical base disks
  in the disk_info structure;
. Use the logical target device only to create bootmap (it is
  automatically mirrored by the respective linux driver (dm, or md)
  managing the mirrored target). In contrast, install bootstrap blocks
  to each physical base disk individually, bypassing that driver;
. Report in verbose mode on which base disks the bootstrap
  installation was performed;
. Use the following logic of setting @info->device (which is printed
  as "Device...:" in verbose mode):
  . source_auto   - the target base disk is set;
  . source_script - the target (logical) device is set;
  . source_user   - the device specified by user (via --targetbase
                    option), or config file is set.

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-08-26 10:40:21 +02:00
Eduard Shishkin
c0f02d2f68 zipl/src: Fix problems when target parameters are specified by user
Steps to reproduce: Prepare some disk for IPL, specifying its
parameters via zipl "target options", and an image IMAGE_NAME
located on another disk. Don't specify "-a" option.

Actual result: Installation succeeded (resulting in unbootable setup)
Expected result: "Error: Could not add image file 'IMAGE_NAME': File
is not on target device"

The problem is in incorrect evaluation of device number (dev_t)
of the base disk where the image is located by the function
add_component_file_range() in case when target parameters are
specified by user.

Fixup: Retrieve info of the underlying disk without any user hints,
passing zeroed structure job_target_data

This is an improved version of fb0b6263d that was reverted by
63ff07ba3 afterwards. The shortcoming of the original ( fb0b6263d )
fix: it fails to prepare for IPL mounted qcow2 images.
The difference from the original fix: when making sure that boot
files are located on the target disk: in case of failed auto-detection
of disk parameters skip the check with warnings instead of aborting
the whole installation session.

Acked-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-08-22 10:32:36 +02:00
Marc Hartmayer
63ff07ba38 Revert "zipl/src: Fix problems when target parameters are specified by user"
The commit fb0b6263d1 ("zipl/src: Fix problems when target parameters
are specified by user") breaks the case where the user has to provide
all target attributes via the zipl command line, because the target
device cannot be used to retrieve those attributes.

$ zipl -V --blsdir /tmp/tmp.xHmFUdgBCi/boot//loader/entries/ --config /tmp/tmp.dSv9MJ3svs
Looking for components in '/lib/s390-tools'
Using config file '/tmp/tmp.dSv9MJ3svs' (from command line)
Using BLS config file '/tmp/tmp.xHmFUdgBCi/boot//loader/entries//50_normal.conf'
Using BLS config file '/tmp/tmp.xHmFUdgBCi/boot//loader/entries//45_normal_swiotlb.conf'
Using BLS config file '/tmp/tmp.xHmFUdgBCi/boot//loader/entries//40_pv.conf'
Using BLS config file '/tmp/tmp.xHmFUdgBCi/boot//loader/entries//30_pv_reboot.conf'
Secure boot support: yes
Target device information
  Device..........................: 2b:00
  Device name.....................: nbd0 *)
  Device driver name..............: nbd
  Type............................: disk device
  Disk layout.....................: SCSI disk layout *)
  Geometry - start................: 2048 *)
  File system block size..........: 4096
  Physical block size.............: 512 *)
  Device size in physical blocks..: 2095071
  *) Data provided by user.
Building bootmap in '/tmp/tmp.xHmFUdgBCi/boot/'
Building menu 'zipl-automatic-menu'
Adding #1: IPL section 'Normal Guest' (default)
  initial ramdisk...: /tmp/tmp.xHmFUdgBCi/boot//ramdisk-s390x
  kernel image......: /tmp/tmp.xHmFUdgBCi/boot//vmlinux-s390x
zIPL environment block content:
Error: Could not add image file '/tmp/tmp.xHmFUdgBCi/boot//vmlinux-s390x': Could not get disk geometry

This reverts commit fb0b6263d1.

Acked-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-06-24 16:23:24 +02:00
Eduard Shishkin
fb0b6263d1 zipl/src: Fix problems when target parameters are specified by user
Steps to reproduce: Prepare some target disk for IPL, specifying
its parameters via zipl "target options", and an image IMAGE_NAME
located on another disk. Don't specify "-a" option.

Actual result: Installation succeeded (resulting in unbootable setup)
Expected result: "Error: Could not add image file 'IMAGE_NAME': File
is not on target device"

The problem is in incorrect evaluation of device number(dev_t) where
the image is located by the function add_component_file_range() in
case when target parameters are specified by user.

Fixup: Retrieve info of the underlying disk without any user hints,
passing zeroed structure job_target_data

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:03 +02:00
Eduard Shishkin
76aaf3d4a8 zipl/src: Fix problems when image is not on target SCSI
This patch fixes a bug in disk_get_info()
Steps to reproduce: Prepare a SCSI disk for IPL, specifying an image
("-i IMAGE_NAME") located on DASD and a target directory ("-t /mnt")
located on SCSI (dm). Don't specify "-a" option.

Actual result: Installation succeeded (resulting in unbootable setup!)
Expected result: "Error: Could not add image file 'IMAGE_NAME':
File is not on target device".

The problem is in incorrect evaluation of device number (dev_t) of
the device, where the image file is located, by the function
add_component_file_range(). To evaluate it, disk_get_info() is called
with the structure job_target_data (passed as the second argument)
previously completed by disk_get_info() called earlier to evaluate
parameters of the specified target device (SCSI dm) by the function
prepare_build_program_table_file(). Since the targetbase is already
set in the passed job_target_data (by the first call), in the second
call the source type is evaluated as "source_user", so the number of
the device where the image is located is calculated by the base SCSI
disk, which is incorrect.

Fixup: Rework disk_get_info(): introduce a dedicated function to
evaluate source type not depending on the job_target_data content.
Implement the core procedure as a switch by the evaluated source
type.

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:51:59 +02:00
Eduard Shishkin
08232d29b9 zipl/src: Drop "bootmap_dir" field of struct install_info
Use "bootmap_dir" field of struct job_target_data instead,
thus avoid allocation/releasing additional resources.

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:51:56 +02:00
Eduard Shishkin
90a2e6d70e zipl/src: Fix leak of files
Fix leak of temporary files: if prepare_build_program_table_file()
is called in no dry-run mode and there was an error then the file
@filename will not be deleted in free_bootloader()).

Fix leak of renamed files as well as corruption of previously
created bootmap files with the same name in case of unsuccessful
IPL installation.

Add a special flag to keep a track of file's "temporary" state;
Base the cleanup decision on this flag instead of checking dry-run;
Release resources captured by prepare_bootloader() in the error path;
Move the final rename to be called only after successful installation.

                    Original logic:

prepare_bootloader_ipl():
prepare_bootloader_ngdump():

  always create temporary @filename
  if (!dry-run) rename @filename;
  install;
  cleanup: if (dry_run) drop @filename (*** LEAK ***)

prepare_bootloader_device():

  if (dry_run) create temporary @filename
  install, don't rename;
  cleanup: if (dry_run) drop @filename

                    New logic:

prepare_bootloader_ipl():
prepare_bootloader_ngdump():

  always create temporary @filename and set @tmp_filename_created;
  install;
  if (!dry_run) rename @filename and clear @tmp_filename_created;
  cleanup: if (@tmp_filename_created is set), drop @filename

prepare_bootloader_device():

  if (dry_run) create @filename and set @tmp_filename_created;
  install, don't rename;
  cleanup: if (@tmp_filename_created is set) drop @filename.

Fixes: https://github.com/ibm-s390-tools/s390-tools/issues/165
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Acked-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-04-02 17:37:53 +02:00
Mikhail Zaslonko
c61783546b zipl: Add --no-compress option to zipl command
Add --no-compress option to explicitly omit compression for single-volume
DASD dumper. Used primarily for test purposes.

Since only the lowest byte of mvdump_force field (struct
stage2dump_parm_tail) has been used, split it in two byte fields and use
one for the new no_compress attribute.

Update zipl help and zipl man page with the new parameter info.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
c08794bdfb zipl/src: Pass stage2dump_parm_tail struct to install_dump_ functions
Move struct stage2dump_parm_tail from stage2dump.h in to
include/dump/s390_dump.h

Pass the entire stage2dump_parm_tail structure to install_dump_* functions
instead of individual parameters.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
1057f13cdc zipl/zlib: Adjust zlib parts for zipl needs
Mainly zlib code remains unchanged for the sake of further maintenance.
Only minor adjustments of zlib deflate parts for build purposes:
- Make is_dfltcc_enabled() always return true
- Define CONFIG_ZLIB_DFLTCC in zlib.h to build zlib code with DFLTCC support
- Remove inflate related prototypes from zlib.h
- Adjust oesc_msg() to use snprintf from libc.h
- Remove BUG_ON from zlib_deflate_workspacesize()
- Replace bitrev32() with bi_reverse() from defutil.h
- Include <assert.h> to dfltcc.h header because of static_assert() calls
- Fix other include statements
- Adjust the text in zipl.h following Zlib License requirements

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
ce59a299cb zipl/zlib: Copy required zlib_deflate parts
Add required zlib_deflate parts based on kernel zlib code in preparation
to DASD dumper DFLTCC deflate exploitation. Omit inflate modules in
order to minimize the dumper size (no decompression is required for the
dumping).

Adjust include statements leaving other code as is.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Steffen Eiden
8058921f58 Reorganize boot-loader header files
include/boot/s390.h relies on s390 specific kernel headers. However,
some tools used this header for non-s390 code (outside of boot-loaders).
To solve this the PSW and PAGE_SIZE definitions are now in separate
header files. All includes for s390.h which are not in boot-loader code
are replaced with one of psw.h or page.h.

This fixes the compilation failure on ppc64le due to conflicting types
for `__vector128`.

Fixes: https://github.com/ibm-s390-linux/s390-tools/issues/151
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 08:21:48 +02:00
Eduard Shishkin
917d611883 zipl: add/move some definitions to header files
Make the listed changes which are needed to re-use some definitions
by the new zipl-debug(8) tool introduced by the next patch in the
series:

. Add definitions to boot_defs.h:
   . a named union disk_bloclkptr (instead of the anonymous one);
   . a named structure disk_program_table;
. Remove a 'typedef union disk_blockptr_t' from boot/stage2.h
  (cleanup), use the named union in boot_defs.h instead;
. Move the definition of scsi_layout types and the function
  get_scsi_layout() from install.c to install.h;
. Move definition of PROGRAM_TABLE_BLOCK_SIZE from bootmap.c to
  bootmap.h

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:02 +02:00
Sven Schnelle
f5aa1d4406 zipl: add ldipl-dump option
CCW and LD-IPL records cannot be used at the same time for dumps because
CCW dump uses the standalone dumper, while LD-IPL uses ngdump. The first
one writes data to the raw disk without any filesystem, while the second
one uses an ext filesystem. Therefore we need a way to tell zipl which
kind of dumper it should install, as both cannot be installed at the
same time. The device given is the same for both types, so we cannot use
this to decide which type to install. Therefore add a '--ldipl-dump' option
so the user can decide which type of dump to use.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Acked-by: Eduard Shishkin <edward6@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:04 +02:00
Sven Schnelle
ee4f503ec0 zipl: pass job to is_ngdump_enabled()
No functional change, only preparation for the next patches.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Acked-by: Eduard Shishkin <edward6@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:04 +02:00
Eduard Shishkin
7c656faa36 zipl: remove last table / number of tables logic
In order to allow installing only a list-directed ipl entry, remove
the last-table/number-of-tables logic which always required a legacy
program table. With the new code there's no longer a loop in
prepare_bootloader() which requires a certain start index or order
of tables.

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:03 +02:00
Sven Schnelle
10515380e8 zipl: add print_details flag to struct install_set
Instead of depending on array index, add an explicit print_details
flag to struct install_set.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Acked-by: Eduard Shishkin <edward6@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:03 +02:00
Sven Schnelle
7301883e69 zipl: add skip_prepare flag to struct install_set
Instead of depending on array index to decide whether we
did already the preparation work for installing the bootloader,
add an explicit skip_prepare flag to struct install_set.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Acked-by: Eduard Shishkin <edward6@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:03 +02:00
Sven Schnelle
555f3782d4 zipl: rename PROGRAM_TABLE_* to {LEGACY}_BLKPTR_FORMAT_ID
In preparation of decoupling the program table position from
the block pointer format, rename:

PROGRAM_TABLE_0 to LEGACY_BLKPTR_FORMAT_ID
PRAGRAM_TABLE_1 to BLKPTR_FORMAT_ID

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:03 +02:00
Sven Schnelle
e496e9862c zipl: show whether we're installed LD ipl or dump
Let the user know whether we're going to install a
list-directed IPL or dump.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Acked-by: Eduard Shishkin <edward6@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:03 +02:00
Sven Schnelle
c8e989840f zipl: add disk_is_eckd_ldl()
Add a small helper to check whether a given disk is ECKD
containing a Linux disk label.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Acked-by: Eduard Shishkin <edward6@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:03 +02:00
Eduard Shishkin
75513ee975 zipl/src: Fix the improper order of resource releasing
Fix the improper order of resource releasing resulted in failed umount
Do umount after closing (not before)

Fixes: f7d2339 (zipl: List-Directed IPL from ECKD DASD)
Reported-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Tested-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-01-27 14:12:38 +01:00
Eduard Shishkin
f7d2339c6a zipl: List-Directed IPL from ECKD DASD
Make zipl tool prepare ECKD DASD for booting by different IPL
programs (with the same boot record installed).

Besides standard CCW-type IPL, user gets an ability to trigger
(with the same boot record installed!) List-Directed IPL. This
allows to use the feature of secure boot from ECKD DASD (which
is not available for CCW-type IPL).

When using the old boot interfaces, the usual CCW-type IPL is
triggered for DASD. Also for compatibility reasons zipl(8) tool
is modified to create and install one, or two "similar" program
tables per boot partition, depending on job and disk type. The
"similar" program tables differ only in block pointers format.
The old IPL programs (CCW-type IPL) use program table based on the
old format.

All program tables are packed to the same bootmap file. Their
order and logical offsets in the file are not significant (not
used by anyone).

The picture below shows which program table is used for IPL of
specified type from disk of specified type. Here "0" and "1" are
identifiers of program tables based on the old and new block
pointers format respectively. E.g. program table "0" is used for
CCW-type IPL from ECKD DASD. LD-IPL from DASD FBA is unsupported
(respectively, only one program table "0" is used), etc.

                            CCW-IPL   LD-IPL

 SCSI                          X        0
 DASD FBA                      0        X
 ECKD DASD LDL                 0        X
 ECKD DASD CDL                 0        1

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-29 17:03:57 +01:00
Marc Hartmayer
da9b96fb12 lib/zt_common.h: consolidate ROUNDUP macro
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Acked-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Alexander Egorenkov
2b015183aa zipl: Implement NGDump
This commit finalizes the implementation of the new stand-alone dump -
Next Gen Dump (NGDump).

NGDump stand-alone dump is a universal stand-alone dump which works for both
SCSI and NVMe disks. But currently can be used only with NVMe disks
and SCSI stand-alone dump remains the default for SCSI disks.

Currently, this stand-alone dump can be used only on IBM z15 or newer
machine generations because it requires larger amount of HSA memory offered
by firmware only on IBM z15 machines. Whereas SCSI stand-alone dump is able
to work with HSA memory of 32M, the new stand-alone dump requires 512M HSA
memory at the moment.

NGDump stand-alone dump installation is initiated by passing a path to
a NVMe disk partition to zipl via the command-line -d, similar to SCSI
stand-alone dump. zipl will then:
- build a dumper initramfs with either dracut (Fedora/RHEL/SLES) or
  initramfs-tools (Ubuntu/Debian)
- format the given NVMe partition with ext4 file system
- create a bootmap file on the newly created file system using the built
  initramfs and the currently active kernel image
- install a boot loader on the disk the given dump partition belongs to

The operations described above are destructive for the given NVMe dump
partition and the boot record(s) of its disk.

After the installation step, users can configure the dumpconf to IPL
the dumper automatically on panic or trigger a dump manually via HMC
interface.

When activated, the dumper will create a dump ELF file named "dump.elf"
on the given NVMe dump partition by using the makedumpfile tool. The kdump
compressed file format is not supported yet due to zgetdump not being able
to read such a file format. Therefore, the dumper is restricted to write
the dump only in ELF format but only kernel pages which are in use.
This will usually make the dump smaller than the original size of
/proc/vmcore and the whole dump process faster as well.

Example configuration for dumpconf:

ON_PANIC=dump   # or dump_reipl
DUMP_TYPE=nvme
FID=0x00000001
NSID=0x00000001
BOOTPROG=0
BR_LBA=0

$ systemctl enable --now dumpconf

To install the dracut support on Fedora/RHEL/SUSE:

$ make -C zipl/dracut HAVE_DRACUT=1 install

To install the initramfs-tools support on Ubuntu/Debian:

$ make -C zipl/initramfs-tools HAVE_INITRAMFS=1 install

Example of NGDump console output on SLES during dump
----------------------------------------------------

         Starting NGDump...
[    8.932343] ngdump.sh[327]: NGDump started
[    8.934739] ngdump.sh[336]: Checking for memory holes                         : [  0.0 %] /
[    8.967536] ngdump.sh[336]: Checking for memory holes                         : [100.0 %] |
[    9.076976] ngdump.sh[336]: Excluding unnecessary pages                       : [100.0 %] \
[   11.721157] ngdump.sh[336]: Copying data                                      : [  0.0 %] -
[   12.317319] ngdump.sh[336]: Copying data                                      : [ 22.5 %] /           eta: 2s
[   13.273000] ngdump.sh[336]: Copying data                                      : [100.0 %] |           eta: 0s
[   13.273244] ngdump.sh[336]: The kernel version is not supported.
[   13.273263] ngdump.sh[336]: The makedumpfile operation may be incomplete.
[   13.273281] ngdump.sh[336]: The dumpfile is saved to /ngdump/dump.elf.
[   13.273299] ngdump.sh[336]: makedumpfile Completed.

Example of NGDump console output on Ubuntu during dump
-------------------------------------------------------

[    3.240078] zdump: The dump process started for a 64-bit operating system
Loading, please wait...
Starting version 245.4-4ubuntu3.17
Begin: Starting firmware auto-configuration ... done.
Begin: Loading essential drivers ... done.
Begin: Running /scripts/init-premount ...
Begin: NGDump ...
Checking for memory holes                         : [  0.0 %] /
Checking for memory holes                         : [100.0 %] |
Excluding unnecessary pages                       : [100.0 %] \
Copying data                                      : [  0.0 %] -
Copying data                                      : [ 40.7 %] /           eta: 1s
Copying data                                      : [100.0 %] |           eta: 0s
The kernel version is not supported.
The makedumpfile operation may be incomplete.
The dumpfile is saved to /ngdump/dump.elf.
makedumpfile Completed.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Tested-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
b4142a9966 zipl: Implement zipl helper script for NGDump
The purpose of the new zipl helper script is to build a dumper initramfs
for NGDump stand-alone dump. zipl executes the helper script when
preparing a NVMe dump partition for stand-alone dump.

The zipl helper script expects a single parameter - a path to the dump
partition to store a dump on. The helper script terminates with 0 on
success and a positive value otherwise.

The zipl helper script performs the following steps:
- It builds an initramfs image suitable for dumping. To perform this step,
  the script employs the dracut tool on Fedora/RHEL/SLES and
  the initramfs-tools on Ubuntu/Debian.
- It outputs the path to the newly built initramfs image and the currently
  active kernel bzImage on the standard output.
- It prints the kernel command-line to be used by the dumper on
  the standard output.

On success, zipl expects the helper script to return at least three lines
containing:
- initrd=<path to an initramfs image>
- kernel=<path to a kernel bzImage>
- cmdline=<kernel command-line parameters>

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
5094354c39 zipl: Implement helper function disk_is_nvme()
The new function disk_is_nvme() is a convenience function that indicates
whether the given path to a device file represents a NVMe disk.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
844058bf4d zipl: Extend disk_get_info() to recognize NVMe disks
Until now, NVMe disks were handled by zipl as SCSI disks. To support
NVMe stand-alone dump, it became necessary to further differentiate between
both types of disks.

There are two cases that must be handled:
1. A non-device-mapper device is a NVMe disk if it is assigned to the blkext
   device driver.
2. A device-mapper disk is a NVMe disk if the ioctl NVME_IOCTL_ID succeeds.
   This case is necessary to properly recognize NVMe disks which are
   DM devices and, therefore, not directly handled by the blkext device
   driver.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:04 +02:00
Alexander Egorenkov
647e8b5c37 zipl/boot: move zipl magic string definitions to boot_defs.h for reuse
To reduce duplication of definitions and facilitate reuse between zipl
and zgetdump.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:04 +02:00
Alexander Egorenkov
953af2cc67 zipl/boot: move SCSI MBR struct definition to boot_defs.h for reuse
To reduce duplication of definitions and facilitate reuse between zipl
and zgetdump.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:04 +02:00
Alexander Egorenkov
ba7bf2f6d3 zipl/boot: move boot info struct definitions to boot_defs.h for reuse
To reduce duplication of definitions and facilitate reuse between zipl
and zgetdump.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:04 +02:00