Compare commits

...

237 Commits

Author SHA1 Message Date
Steffen Eiden
7770b7a2c0 New release s390-tools-2.28.0
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 13:15:19 +02:00
Steffen Eiden
2ef6f64b1d Makefile: fix build for non-390 architectures
The last commit accidentally deleted the TOOLS_DIR for non-s390x
architectures.

Fixes: de013d2f ("Makefile: add genprotimg to non-s390x architectures target list")
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 11:32:26 +02:00
Marc Hartmayer
de013d2f04 Makefile: add genprotimg to non-s390x architectures target list
`genprotimg` can be useful on non-s390x architectures such as x86 or
arm. Therefore add `genprotimg` to the non-s390x target list.

How to build genprotimg on a non-s390x system (s390x cross-compiler
required)

$ # Build and install /usr/bin/genprotimg
$ make -C genprotimg
$ make install -C genprotimg
$ # Build and install the genprotimg bootloaders
$ make -C genprotimg/boot HOST_ARCH=s390x CROSS_COMPILE=s390x-linux-gnu-
$ make install -C genprotimg/boot HOST_ARCH=s390x CROSS_COMPILE=s390x-linux-gnu-

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 08:24:52 +02:00
Marc Hartmayer
ed94cf9839 genprotimg/boot: compile the bootloaders only if HOST_ARCH is s390x
The genprotimg bootloaders are s390x specific, so only build them if the
`HOST_ARCH' is set to s390x.

On x86 one can cross-compile and install the bootloaders as follows:

$ make -C genprotimg/boot HOST_ARCH=s390x CROSS_COMPILE=s390x-linux-gnu-
$ make -C genprotimg/boot install HOST_ARCH=s390x CROSS_COMPILE=s390x-linux-gnu-

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 08:22:04 +02:00
Marc Hartmayer
2fec7688b0 genprotimg: move bootloader installation responsibility to boot/Makefile
It's cleaner if the bootloader installation code is located in the
boot/Makefile, rather than the top Makefile.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 08:22:04 +02:00
Matthew Rosato
3c1834f0fc ap_tools/ap-check: handle missing 'matrix' and 'control_domains' attrs
Under typical circumstances these sysfs attributes should be available
however if the device happens to be in the process of being removed
without the protection of the ap config file lock, this scenario can
be encountered.  In this case, ignore the device and assume it is in
the process of being removed.

Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 08:22:04 +02:00
Matthew Rosato
f6e78d3ecd ap_tools/ap-check: hold ap config file lock over get attributes
Since this callout reads sysfs values for the specified mdev, the
ap config file lock should be held to prevent other tools from
making changes to the ap configuration at the same time.

Reviewed-by: Jason J. Herne <jjherne@linux.ibm.com>
Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 08:22:04 +02:00
Steffen Eiden
dad7fce7a1 zipl/boot: move load_wait_psw() location
`load_wait_psw` is defined in include/boot/s390.h but is implemented in
zipl/boot/libc.c. This results in a dangling definition for s390.h users
other than zipl, due to the missing implementation. Since the function
is only relevant for zipl, move the definition to the corresponding
header file zipl/boot/libc.h

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 08:21:58 +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
Marc Hartmayer
bb8e0e1047 common.mak: test_linker_flag: use LINK and not CC variable
The check is for linker flags, and the $(LINK) variable is used for
linking, not $(CC).

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 08:21:48 +02:00
Marc Hartmayer
5dcac6d2e3 common.mak: use a minimal assembly snippet to check for linker flags
Use a minimal assembly snippet to check for linker flags. This has the
advantage that it will work even if only the cross-toolchain is
installed, but not, for example, stdlib.

Using the C snippet, the check runs in a similar error like this:

  /usr/bin/s390x-linux-gnu-ld: cannot find crt1.o: No such file or directory
  /usr/bin/s390x-linux-gnu-ld: cannot find crti.o: No such file or directory
  /usr/bin/s390x-linux-gnu-ld: cannot find -lc: No such file or directory
  /usr/bin/s390x-linux-gnu-ld: cannot find crtn.o: No such file or directory

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 08:21:48 +02:00
Peter Oberparleiter
552772d2a9 zdev: fix unexpected warning due to non-existent interface
Using option --by-interface with a non-existent network interface name
results in an unexpected duplicate warning message:

  $ lszdev --by-interface xx
  Could not open directory /sys/class/net/xx: No such file or directory
  Could not open directory /sys/class/net/xx: No such file or directory
  lszdev: Could not determine device that provides xx (xx)

Fix this by checking for the existence of the associated /sys/class/net
directory before initiating the associated directory traversal.

Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:04 +02:00
Peter Oberparleiter
42611a787d zdev: use consistent exit code for nonexistent device nodes
zdev's --by-node option returns exit code 15 (EXIT_RUNTIME_ERROR) when
the specified device node cannot be found. This is inconsistent with
other selection options --by-path and --by-interface which both return
the more appropriate exit code 3 (EXIT_DEVICE_NOT_FOUND).

Fix this by changing --by-node to also return exit code 3 in case the
specified device node does not exist.

Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:03 +02:00
Sven Schnelle
743788d02f zipl/dump: fix ngdump dracut helper script
While changing the helper script to create the ngdump filesystem,
some lines were left in the script which now cause the zipl
installation to fail:

Run /lib/s390-tools/zipl_helper.prepare-ngdump /dev/disk/by-path/ccw-0.0.6a56-part1 0
Couldn't find disk by PARTUUID.
Error: Script could not determine dump parameters

Remove the superfluous lines to fix this.

Fixes: 41108c98aa ("zipl: move mkfs to ngdump prepare script")
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Acked-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:03 +02:00
Marc Hartmayer
6028300366 cpacfstatsd: don't fail if no crypto counters are supported
Do not fail to start the daemon if no crypto counters are supported, as
there is still a use case for the daemon to run, as the user can then
use the 'cpacfstats' tool to evaluate that no counter stats are
available. Previously, the user had to check the syslogs for the reason
why the daemon was not running and the cpacfstats command failed.

Before this change:

$ cpacfstats
cpacfstats: Can't access domain socket file '/run/cpacfstatsd_socket', errno=2 [No such file or directory]
cpacfstats: Maybe cpacfstatsd daemon is not running ???
cpacfstats: Can't connect to daemon

After this change:

$ cpacfstats
 des counter: unsupported
 aes counter: unsupported
 sha counter: unsupported
 rng counter: unsupported
 ecc counter: unsupported
 pai_user   : unsupported
 pai_kernel : unsupported

Also, it's no good practice to let systemd services fail, because
otherwise the system state will be shown as 'degraded':

$ systemctl status
* a46lp59
    State: degraded
     Jobs: 0 queued
   Failed: 1 units

$ systemctl list-units --failed
  UNIT                LOAD   ACTIVE SUB    DESCRIPTION
* cpacfstatsd.service loaded failed failed CPACF statistics collection daemon process for Linux on System z

Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:03 +02:00
Marc Hartmayer
70cb25766b cpacfstatsd: manpage: CPU hotplug is recognized by the daemon
Since commit 72b5e8b313 ("cpacfstats: Handle CPU hotplug") CPU
hotplugs are recognized by the daemon.

Fixes: 72b5e8b313 ("cpacfstats: Handle CPU hotplug")
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:03 +02:00
Marc Hartmayer
36eede8f31 cpacfstats: whitespace cleanups and typo fix
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:03 +02:00
Eduard Shishkin
ec0dcdb685 zipl/job.c: Print additional information on error paths
Print the name of the section which specifes non-existing image
and/or ramdisk files.

It allows to quickly identify problems after using non-atomic tools
manipulating with bootloader settings.

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:03 +02:00
Vineeth Vijayan
2a1a821bb3 zdev: add missing label in the udev-rules
The udev-rules generated with the current version of chzdev command
is missing the configuration label, incase of auto configuration,
resulting in an ineffective configuration logic.
Add the missing configuration start label for autoconfig.

Fixes: 2e89722ef0 ("zdev: make site specific udev-rule for ccw")
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:02 +02:00
Vineeth Vijayan
09c01e580a zdev: use rename-file to avoid any symlinks created
During the boot, the ZDEV_SITE_ID is derived with the help
of loadparm and will be saved in ZDEV_SITE_ID_FILE, which
will be the used by the udev-rules.

ZDEV_SITE_ID_FILE creation can have a surface of symlink attack
as we are directly using the fopen and fprintf on it. To avoid
this, make sure that we are writing the ZDEV_SITE_ID to a temporary
file, which will then be renamed to ZDEV_SITE_ID_FILE, which will
remove all the existing symlinks associated with the target file.

Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:02 +02:00
Vineeth Vijayan
27902c9106 zdev: add proper value input for the ZDEV_SITE_ID key
udev does not allow an empty value for keys when importing output
from an external program. Providing an empty value for any key
invokes a warning during the parsing. Currently, ZDEV_SITE_ID for
fallback sites are not assigned any value. Add an empty double
quotes as the value in case of failover sites.

This modification is tested on udevadm version 253 on fedora38.

Also verify that the ZDEV_SITE_ID is properly written, if not log
the error.

Fixes: c8ad5f57d0 ("zdev: modify zdev_id to read the site_id from loadparm")
Reported-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:02 +02:00
Thomas Richter
a8d328bba2 cpumf/lshwc: replace memory alloction functions by library counterparts
Replace memory allocation functions malloc() and calloc()
by counterparts provided in libutil.a library. Also remove error
handling when no memory could be allocated as those functions do
not return.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:02 +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
Marc Hartmayer
94e0b644a7 cpacfstatsd: use a PIPE to notify the parent that the initialization is done
Use a PIPE to notify the parent that the initialization is complete and
all external communication channels are established. See
https://www.freedesktop.org/software/systemd/man/daemon.html for
details.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:02 +02:00
Marc Hartmayer
10f8565e32 cpacfstatsd: replace goto cleanups
There are only two users of the `cleanup` label, so let's replace the
goto statements with the label code. This makes the code easier to read.
Especially since another label will be introduced in the next commit.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:01 +02:00
Marc Hartmayer
22bce41dd7 cpacfstatsd: white-space cleanup and typo fixes
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:41:01 +02:00
Harald Freudenberger
e35e73d2a3 chzcrypt: Support for SE bind, unbind and associate
This patch adds support for Secure Execution with AP pass-through
support for chzcrypt.

chzcrypt details:
* new command: --se-associate <secret-id> <queue device>
* new command: --se-bind <queue device>
* new command: --se-unbind <queue device>

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:40:56 +02:00
Harald Freudenberger
f821f31a51 lszcrypt: Support for SE AP pass-through support
This patch adds support for Secure Execution with AP pass-through
support for lszcrypt.

lszcrypt details:
* extension to -b: list AP bus features
* extension to -c: now also valid for queue devices, shows
		   bind and assoicate state in SE environment;
		   shows MK states (only for current MKs).
* extension to -V: new column SESTAT within an SE guest, shows text
		   for the BS bits within an SE environment:
		   "usable", "bond", "avail", "unuse".

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-04 15:40:47 +02:00
Stefan Haberland
493af760ed zdev: add support for autoquiesce related sysfs attributes
Autoquiesce is a mechanism that tells Linux to stop issuing I/Os to a
specific DASD after certain events.

Add support for configuring related DASD device attributes
that govern the following aspects of autoquiesce:

aq_mask - Configure which events lead to autoquiesce.
aq_requeue - Configure if autoquiesce will requeue all I/O to blocklayer.
aq_timeouts - Configure the number of timeouts before autoquiesce.

Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-30 16:55:55 +02:00
Steffen Eiden
3287bb9613 Prepare for next release
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-30 14:42:12 +02:00
Steffen Eiden
76606802d0 New release s390-tools-2.27.0
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-30 14:42:12 +02:00
Marc Hartmayer
e99b32cacb common.mak: make *clean targets mutually exclusive
The 'clean' build targets can be specified alongside other targets,
which causes an immediate removal of build artifacts. Make 'clean'
targets mutually exclusive to avoid this issue and display an error if
'clean' is used in combination with other targets.

Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
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>
2023-05-30 13:31:53 +02:00
Jan Höppner
87a6154de9 Makefile: limit build targets for non-s390x architecture
A subset of s390 tools can be useful on non-s390x architectures such as
x86 or arm. Limit the build targets for these architectures with
'pvattest' and 'libpv' as the first candidates.

A cross compilation on x86 for s390x will still build the entire package
provided that the HOST_ARCH variable is set properly:

$ make HOST_ARCH=s390x CROSS_COMPILE=s390x-linux-gnu-

Cross compilation on s390x for x86 will limit the build targets as
described:

$ make HOST_ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu-

Co-developed-by: Jan Höppner <hoeppner@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-30 13:31:53 +02:00
Marc Hartmayer
ed4c68e867 common.mak: improve cross compilation support
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>
2023-05-30 13:31:53 +02:00
Marc Hartmayer
e2b68b4d9b common.mak: make sure all command variables are getting exported
Export the Makefile variables HOSTCC, LINKXX, PANDOC, and PKG_CONFIG so
they can be used in sub-make calls, too.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
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>
2023-05-30 13:31:53 +02:00
Marc Hartmayer
686fca1863 Move HOST_ARCH declaration to common.mak
In addition, add the ability that a Makefile that includes `common.mak`
can specify the `HOST_ARCH`. Usage example:

$S390_TOOLS/mytool/Makefile:
``` Makefile
HOST_ARCH := s390x
include ../common.mak
```

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
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>
2023-05-30 13:31:53 +02:00
Marc Hartmayer
0c1a5069d9 Rename ARCH to HOST_ARCH
Use a common naming convention for the variable [1][2][3]. In an
upcoming patch the Makefile variable `BUILD_ARCH` will be introduced.

[1] https://www.gnu.org/software/automake/manual/html_node/Cross_002dCompilation.html
[2] https://docs.yoctoproject.org/ref-manual/variables.html#term-HOST_ARCH
[3] https://mesonbuild.com/Cross-compilation.html#cross-compilation

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
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>
2023-05-30 13:31:53 +02:00
Marc Hartmayer
de88b1c71b common.mak: introduce PKG_CONFIG
Introduce `PKG_CONFIG` Makefile variable. This helps for
cross-compilation.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-30 13:31:51 +02:00
Marc Hartmayer
4bba1058c6 Declare pkg-config as required
`pkg-config` is a well established tool and all of our required
libraries do provide .pc files. Therefore let's declare `pkg-config` as
required and use it. In addition, remove now useless code.

Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
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>
2023-05-30 13:31:20 +02:00
Jan Höppner
49937f40a1 zipl: Disable array-bounds warning
Since GCC12 several warnings like the following are produced in
zipl/boot compile targets:

CC      zipl/boot/stage2.o
stage2.c: In function ‘start’:
stage2.c:99:24: warning: array subscript 0 is outside array bounds of ‘struct stage2_descr[0]’ [-Warray-bounds]
   99 |         stage2_descr = *(struct stage2_descr*)STAGE2_DESC;

This is the same issue as reported for the Kernel [1][2]. There is
currently no sane fix available, therefore simply disable the warning
for the zipl/boot/ targets.

[1] https://lore.kernel.org/lkml/yt9dzgkelelc.fsf@linux.ibm.com/
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-30 13:29:57 +02:00
Jan Höppner
d55818a797 dasdfmt: Fall back to full format if space release fails
In certain storage setups the Release Allocated Space (RAS) command to
free up space on the storage server previously allocated for an ESE DASD
might not work. At the moment dasdfmt will error out if RAS is failing.
This however is not ideal for the default case when a user is expecting
dasdfmt to simply format the disk.

One workaround would be to specify --no-discard to disable RAS
completely. However, a sane default handling that tries to work every
time is more reasonable.

Change the default handling as follows: If an ESE is detected default to
QUICK mode and try RAS. If RAS fails, fall back to the FULL format mode
and display a warning accordingly.

If -M (--mode) QUICK is specified explicitly dasdfmt will still error
out on a failing RAS. A combination with --no-discard will still allow
for a QUICK format on an ESE DASD in that case, if desired.

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-30 13:29:57 +02:00
Steffen Eiden
96897ee32e pvattest/tools: fix endianness in tools
`od` in contrast to `xxd` uses the system endianness for displying the
hexdump by default which leads to invalid results on little endian
systems.
Use the `--endian=big` option to fix the endianness problem.

Fixes: 3cc0b4cd ("pvattest/tools: remove xxd dependency from scripts")
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:04 +02:00
Marc Hartmayer
5522aaedf4 iucvterm/bin/chiucvallow: explicitly use bash
The script uses bashisms (e.g. `local` keyword) therefore make sure that
bash is used by setting the shebang line to `#!/bin/bash`.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:04 +02:00
Joern Siglen
f3b7f4b14b dbginfo.sh: fix icastats for all users
icastats is accounted by user and does cover root only today
adding the --all will collect stats for all users

Reported-by: Ingo Franzki <ifranzki@de.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:04 +02:00
Sven Schnelle
01f74c75f5 zipl/dump: add dasd device to ngdump parmline
For dasd devices, we need to enable the device before we can use it.
Add the required dasd device to the kernel commandline when installing
ngdump to a dasd device.

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:04 +02:00
Sven Schnelle
24bcc3141d zipl: add support for ldipl dump from ECKD DASD
Add the required code to install ngdump on DASDs.

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:04 +02:00
Sven Schnelle
41108c98aa zipl: move mkfs to ngdump prepare script
The current code first assembles the ngdump init ramdisk, and creates
the filesystem on the dump disk afterwards. ngdump uses uuids to mount
the dump device. Because the filesystem uuid is changing with the final
mkfs, ngdump has to use the partuuid of the device. This does work for
nvme, but not for dasds. Another problem is that dryrun likely wouldn't
work if there's no partition table on the dump device. To fix these
issues, move the mkfs to the ngdump helper script so we can use the
filesystem uuid. When --dryrun is specified the script passes /dev/null
as ngdump device to make mkinitramfs happy. As the initramdisk is never
used in this case, this shouldn't be a problem.

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:04 +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
Sven Schnelle
7095da9f9d dumpconf: add options for ldipl ECKD devices
Add the following options to dumpconf so that LDIPL ECKD devices
can be configured for dumping:

br_chr: (optional) location of boot record
device: ccw device
bootprog: boot program selector

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
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
7ecad86938 zipl: split up install_bootloader()
To make the code easier to maintain and prepare for ECKD LD-IPL,
split up install_bootloader() into two functions: One which is used
for IPL, and one for dump partitions.

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
Jan Höppner
908067bdf9 common.mak: Fix slow build
The relative subdirectory path of a build target is determined via a
separate shell command that issues 'cd' and 'pwd'. Spawning a separate
shell is very costly and can lead to extremely slow builds in some
circumstances.

Replace the shell command with the make built-in command 'realpath' to
accomplish the same result more efficiently.

Tested-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:21:03 +02:00
Marc Hartmayer
2c7e61a6c7 zipl: check_common_ipl_data: fix memory leak of @buffer
Related Valgrind output:
  ==1073934== 241,722,000 bytes in 30 blocks are definitely lost in loss record 2 of 2
  ==1073934==    at 0x484417C: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-s390x-linux.so)
  ==1073934==    by 0x1006B8D: misc_malloc (misc.c:33)
  ==1073934==    by 0x1006B8D: misc_read_file (misc.c:150)
  ==1073934==    by 0x100DACD: check_common_ipl_data (job.c:774)
  ==1073934==    by 0x100FE2F: check_job_ipl_data (job.c:827)
  ==1073934==    by 0x100FE2F: check_job_menu_data (job.c:999)
  ==1073934==    by 0x100FE2F: check_job_data (job.c:1139)
  ==1073934==    by 0x100FE2F: job_get (job.c:2011)
  ==1073934==    by 0x1006335: main (zipl.c:141)

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
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>
2023-05-26 12:18:08 +02:00
Joern Siglen
ae824745a0 dbginfo.sh: add nstat command in network section
include the statistics about the network and SNMP

Reported-by: Nils Hoppmann <NIHO@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:18:08 +02:00
Mete Durlu
2b2c111af4 hyptop: Show thread util by default
Since SMT is being used by default on z systems, hyptop should show
thread utilization by default on both system and system list window.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Mete Durlu <meted@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:18:08 +02:00
Marc Hartmayer
1bfa78896f libpv|pvattest: do not link against openssl
Neither libpv nor pvattest uses libssl functionality directly, so let's
remove it from the pkg-config calls.

$ pkg-config --libs openssl
-lssl -lcrypto

$ pkg-config --libs libcrypto
-lcrypto

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:18:04 +02:00
Marc Hartmayer
e928c6f83c .gitignore: ignore clangd cache
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:13:35 +02:00
Marc Hartmayer
0e86da9d66 zipl: extract_signature: fix memory leak of @signature
Fix memory leak @signature in case of an unsupported signature type.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:13:35 +02:00
Marc Hartmayer
21dbbcfa56 zipl: scan_upldate_bls_path: fix memory leak of @img_value
Valgrind finding:
  ==1083976== 19 bytes in 1 blocks are definitely lost in loss record 1 of 1
  ==1083976==    at 0x484417C: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-s390x-linux.so)
  ==1083976==    by 0x48F3C97: __vasprintf_internal (vasprintf.c:71)
  ==1083976==    by 0x1006861: vasprintf (stdio2.h:218)
  ==1083976==    by 0x1006861: misc_asprintf (misc.c:49)
  ==1083976==    by 0x100C7E1: scan_update_bls_path (scan.c:1874)
  ==1083976==    by 0x100FF4B: get_job_from_config_file (job.c:1901)
  ==1083976==    by 0x100FF4B: job_get (job.c:1997)
  ==1083976==    by 0x1006335: main (zipl.c:141)

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:13:35 +02:00
Marc Hartmayer
0a512bf904 common.mak: use single quotes in order to avoid globbing
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-05-26 12:13:35 +02:00
Marc Hartmayer
e6be1c1b79 zipl/boot: constify data in section stage2_head
Declare `magic`, `tape_head`, and `stage2_head` as const.

Acked-by: Eduard Shishkin <edward6@linux.ibm.com>
Acked-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-31 18:23:46 +02:00
Marc Hartmayer
a4eb03dfe1 zipl: set kernel parmline only if it was specified
Before commit 5fb6434548 ("zipl: add get_common_components() and
finalize_common_address_data()") the default kernel parmline was only
overwritten if a parmline was specified. After the commit it was always
overwritten, even if no parmline was specified. Let's change this
behavior back by adding a NULL-pointer check. For dump types this change
changes the behavior before commit 5fb6434548 ("zipl: add
get_common_components() and finalize_common_address_data()").

Fixes: 5fb6434548 ("zipl: add get_common_components() and finalize_common_address_data()")
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-31 18:23:46 +02:00
Marc Hartmayer
fc1167fd34 common.mak: avoid a lot of warnings if make --warn is used
Fix the following warnings by using proper default values:

../common.mak:1: warning: undefined variable 'COMMON_INCLUDED'
../common.mak:87: warning: undefined variable 'V'
../common.mak:95: warning: undefined variable 'W'
../common.mak:98: warning: undefined variable 'D'
../common.mak:107: warning: undefined variable 'ASAN'
../common.mak:249: warning: undefined variable 'OPT_FLAGS'
../common.mak:262: warning: undefined variable 'G'
../common.mak:280: warning: undefined variable 'C'
../common.mak:349: warning: undefined variable 'MAKECMDGOALS'
../common.mak:105: warning: undefined variable 'ENABLE_WERROR'

This has two main advantages:
1. Explicit default values
2. `make --warn` shows less false positives

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-17 10:56:11 +01:00
Marc Hartmayer
561559277d zkey: Makefiles: add newline at end of file
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-17 10:56:11 +01:00
Thomas Richter
68a3ccd45e cpumf/lshwc: Update man page and remove concurrency statement
Linux kernel commits
a029a4eab39 ("s390/cpumf: Allow concurrent access for CPU Measurement Counter Facility")
453380318ed ("s390/cpumf: Allow multiple processes to access /dev/hwc")
removed this restriction. Both commits are included in linux 5.16.

Therefore remove the restriction in the man page.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-17 10:56:11 +01:00
Ingo Franzki
fcfd4a6158 libseckey: Fix error checking when building ECDSA signatures
OpenSSL function i2d_ECDSA_SIG() returns a negative value in case of
an error, so check the returned length for <= zero to detect an error.

Reported-by: Holger Dengler <dengler@linux.ibm.com>
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-17 10:56:11 +01:00
Ingo Franzki
e621d2dfa2 libseckey: Use OSSL_FUNC_keymgmt_im/export_types_ex functions
The provider functions OSSL_FUNC_keymgmt_import_types() and
OSSL_FUNC_keymgmt_export_types() do not get the provider context passed.
However, the implementation of these functions in the secure key provider
need the provider context to pass the call to the default provider
and append some of its own types to the result.

Up to now, the provider context was obtained using a global variable
holding the secure key provider handle. This may not be save if multiple
instances of the provider exist.

Just recently OpenSSL added support for an extended form of these
functions, namely OSSL_FUNC_keymgmt_import_types_ex() and
OSSL_FUNC_keymgmt_export_types_ex(), that get the provider context passed
as argument. Make use of these new functions, if compiled against an
OpenSSL version that supports them. For older OpenSSL versions still use
the global variable as before.

See OpenSSL commit 5e3b84505e

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-17 10:56:11 +01:00
Fedor Loshakov
a92ee5ba8d ziomon/ziorep_config: fix for SCSI devices of type disk without block dev
If system configuration contains zfcp-attached SCSI devices of Peripheral
Device Type disk, but without block device, e.g. because the storage reports
Peripheral Qualifier 1 in INQUIRY, ziorep_config tool issue the
following type of errors during generation of .config file from .cfg
file:

$ ziorep_config -I -i test.cfg
Unpacking configuration ...Done.
Use of uninitialized value in subroutine entry at /usr/sbin/ziorep_config line 36.
Use of uninitialized value in subroutine entry at /usr/sbin/ziorep_config line 36.
Use of uninitialized value in subroutine entry at /usr/sbin/ziorep_config line 54.
Use of uninitialized value in subroutine entry at /usr/sbin/ziorep_config line 135.
...

Such errors can also be seen during printing of adapter, device and map
reports:

$ ziorep_config -ADM -i test.cfg
Unpacking configuration ...Done.
Use of uninitialized value in subroutine entry at /usr/sbin/ziorep_config line 36.
Use of uninitialized value in subroutine entry at /usr/sbin/ziorep_config line 36.
Use of uninitialized value in subroutine entry at /usr/sbin/ziorep_config line 54.
Use of uninitialized value in subroutine entry at /usr/sbin/ziorep_config line 135.
...

This is because ziorep_config reads block device parameters from
non-existent block device subdirectory. And therefore ziorep_config
leaves block device major:minor number column empty in .config file
instead of filling it with 0:0 preset value afterwards.

As a consequence, ziorep_traffic tool, which is using .config file to
get information about devices, reports the following error:

$ ziorep_traffic test
Extracting config data...done
ziorep_traffic: Could not parse line 1 - configuration file broken?

To fix this, skip reading the block device parameters for such
devices, and use the preset values that have been set before
instead.

Signed-off-by: Fedor Loshakov <loshakov@linux.ibm.com>
Suggested-by: Steffen Maier <maier@linux.ibm.com>
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-17 10:56:11 +01:00
Fedor Loshakov
46c291835f ziomon/ziorep_config: fix missing SG major:minor for disk block devices
The value of "generic/dev" exists and can be retrieved directly under
the SCSI device directory, not under the disk block device subdirectory,
where the global variable $c_src points to after
$c_src = $devices{$hctl}{dev}; command.

So move the sg_mm retrieval before the block device parameters
retrieval.

Signed-off-by: Fedor Loshakov <loshakov@linux.ibm.com>
Suggested-by: Steffen Maier <maier@linux.ibm.com>
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-17 10:56:11 +01:00
Benjamin Block
4941fc15c0 zfcpdbf: test-compile the script during the build using perl -c
For a slightly easier development loop add a pseudo compilation of the
zfcpdbf Perl script. This will run the Perl interpreter in syntax-check
mode:

  -c   causes Perl to check the syntax of the program and then exit
       without executing it.  Actually, it will execute any "BEGIN",
       "UNITCHECK", or "CHECK" blocks and any "use" statements: these are
       considered as occurring outside the execution of your program.
       "INIT" and "END" blocks, however, will be skipped.

Additionally add the `-w` switch when the Make variable `W` is `1`. This
will print additional warnings about dubious constructs (according to
Perl).

So this pseudo compilation only happens whenever the script is changed
during development create a file `.zfcpdbf.ct` as a result so we can
describe the relationship and dependency in Make. This file can be ignored
otherwise.

Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-17 10:56:11 +01:00
Joern Siglen
48d7c6e6d1 dbginfo.sh: rework opencryptoki data collection
changes in opencryptoki setup do require some modifications:
- "pkcsconf -mlist" does no longer work in a combined format
- config files have changed
- ep11info was not yet collected

Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-03 09:58:40 +01:00
Steffen Maier
73c46a3056 zdev/dracut: fix kdump by only activating required devices
This prevents out-of-memory (OOM) situations in the kdump crashkernel
environment.

Please note that the new dracut module 95zdev-kdump and the new library
zdev-lib.sh need to be packaged into the same (core) (sub)package as
95zdev.

This patch introduces a new dracut module "zdev-kdump", which is used
instead of module "zdev" when building a kdump initrd:

1. Ignore all persistently configured block devices and disable zfcp auto
LUN scanning => minimize the number of SCSI devices enabled during kdump.

2. Do not rely on chzdev's persistent configuration => work with systems
that do not use chzdev for persistent device configuration.

The detection of kdump is based on strict hostonly mode and on $IN_KDUMP.
See also
https://src.fedoraproject.org/rpms/kexec-tools commit
4eedcae5e154 ("dracut-module-setup.sh: don't include multipath-hostonly")
and https://github.com/dracutdevs/dracut commits
35e86ac117ac ("Merge 90-multipath-hostonly and 90-multipath")
a695250ec7db ("Introduce tri-state hostonly mode")
and
https://src.fedoraproject.org/rpms/kexec-tools/blob/rawhide/f/mkdumprd#_17
https://src.fedoraproject.org/rpms/kexec-tools/blob/rawhide/f/dracut-module-setup.sh#_23.
The detection of kdump is also based on kdump_needed() in
https://github.com/openSUSE/kdump/blob/master/dracut/module-setup.sh.

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-03 09:58:40 +01:00
Steffen Maier
f2c82bf2b5 zdev/dracut: fix hardcoded '/' as required mount or device
With the introduction of zdev for device configuration in v1.33.0,
it used a hardcoded "/" to refer to the root-fs.

Dracut has its own mechanism to find the root file system and to walk its
device dependencies.
Mkdumprd also has its own mechanism to interpret the kdump target
and invokes dracut so that dracut only considers arguments from mkdumprd
without any root-fs dracut would default to [--no-hostonly-default-device].

Use the dracut mechanism to walk device dependencies and individually
have chzdev treat each leaf-node in the dependency tree.
See also https://github.com/dracutdevs/dracut commit
83e0dc7a3dca ("Add for_each_host_dev_and_slaves for device only checking").
This enables the use of dracut options such as --add-device or
--mount used in turn by mkdumprd.

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-03 09:58:20 +01:00
Steffen Eiden
d3a3b26d16 Make -Werror optional
Enforcing `-Werror` can cause problems when compiling with newer
compilers that have additional warnings on by default.

By default `-Werror` is turned off and can be turned on via
`ENABLE_WERROR=1`.

Fixes: https://github.com/ibm-s390-linux/s390-tools/issues/148
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-03 09:53:46 +01:00
Holger Dengler
c142bb0625 lszcrypt: use separate index for inner sub-device loop
The function show_devices_argv() iterates over all remaining
arguments. Each argument may specify a single device or a list of
sub-devices. Use a separate index for the inner sub-device loop. This
fixes a bug, that not all or wrong arguments are processed.

Also terminate the outer arguments loop based on the number of
remaining arguments.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-03 09:50:53 +01:00
Holger Dengler
ec04a1846e lszcrypt: use type-filter option also for sub-devices
The tools lszcrypt provides filter options for card types. Use these
options not only for devices (cards), but also for sub-devices
(domains).

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-03-03 09:50:53 +01:00
Jan Höppner
0324fac616 Prepare for next release
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-14 14:05:17 +01:00
Jan Höppner
4014087876 New release s390-tools-2.26.0
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-14 14:05:17 +01:00
Harald Freudenberger
8a878a0d61 lszcrypt: display hardware filtering support capability
The CEX8 card has in CCA mode a new capability 'stateless
hardware filtering support' which is now displayed as
'H' bit in the FUNCTIONS column and with the -c option.

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-14 13:03:06 +01:00
Sven Schnelle
2b511aa2b9 zipl/dump: move dump parmline processing and verification
The current code has different paths to construct the kernel parameters
depending on whether it's a dump kernel or a normal kernel. This would
require adding special handling to get_common_component(), because for
normal kernels the parmline is already set, contrary to dump kernels,
where the command line is constructed later.

To make the code simpler and fix a bug where the default command line no
longer works, move the dump command line processing to an earlier stage.
Also rename the old function to make the function name match what it is
actually doing.

Fixes: 5fb6434548 ("zipl: add get_common_components() and finalize_common_address_data()")
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-14 13:03:06 +01:00
Steffen Maier
6d8243d1b1 zdev: add default queue_depth value for zfcp-lun scsi_device
This avoids exporting explicit settings if it's the default anyway.
I.e. avoid the last line in the example below:

$ chzdev --export - --active --type --all
[active zfcp-lun 0.0.1941:0x500507630904d...:0x4055408f00000000]
scsi_dev/queue_depth=32

Suggested-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Steffen Maier
7ecaeb1a3d zdev: add zfcp ber_stop parameter handling
Complements Linux kernel v5.4 commit 2190168aaea4 ("scsi: zfcp: fix
reaction on bit error threshold notification").

Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
9ada8332d8 zipl: Embed loader data directly into boot object
Currently, each generated loader binary is linked into one data.o object
file which is then linked against boot.o. The data.o file is also used
to generate the data.h header file using nm, which will contain all
symbols required by zipl.

The linking process is somewhat depended on the directory, as the symbol
names are derived from the file names of the input files, which is the
default behavior of the linker. The file name in this case being the
entire path.

Examples for the current situation (starting from root dir in each case):
  $ cd zipl/boot && make eckd0_cdl.bin
  $ cc -no-pie -static -nostdlib -Wl,--relocatable -Wl,--format,binary -o data.o eckd0_cdl.bin
  $ nm data.o
  0000000000000018 D _binary_eckd0_cdl_bin_end
  0000000000000018 A _binary_eckd0_cdl_bin_size
  0000000000000000 D _binary_eckd0_cdl_bin_start

  $ make -C zipl/boot eckd0_cdl.bin
  $ cc -no-pie -static -nostdlib -Wl,--relocatable -Wl,--format,binary -o data.o zipl/boot/eckd0_cdl.bin
  $ nm data.o
  000000000000018 D _binary_zipl_boot_eckd0_cdl_bin_end
  000000000000018 A _binary_zipl_boot_eckd0_cdl_bin_size
  000000000000000 D _binary_zipl_boot_eckd0_cdl_bin_start

The example above shows that the entire path would end up in the symbol
name if specified that way.

To make this more robust, future proof, and get more control of the
resulting symbol names, use '.incbin' and some macros for embedding the
loader binary files. This also reduces the linker step and the
generation of the data.h header file.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Co-developed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
ca25f71a6e genprotimg/boot: stage3b_reloc.bin: add linker script
Use a linker script instead of a linker flags for the layout. While at
it, use common naming `_start` for entry. This change allows us to
simplify the Makefile by using the linker option `-T` for all
bootloaders.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
67790d3787 genprotimg/boot: stage3b: add size check to the linker script
The stage3b loader memory layout must not be larger than 0x10000 bytes.
Let's check this in the linker script.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
d301668811 genprotimg/boot: improve linker scripts
+ the input section names `.text.init` and `.text.start` aren't
   ambiguous, therefore there is no reason so specify a file name
 + discard `.interp` section since no loader is used

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
6097ee3f9d genprotimg/boot: Makefile: simplify objcopy command
Instead of maintaining an include list, use an exclude list (if
neccessary). This simplifies the `objcopy` calls a lot, and it's
possible because `objcopy -O binary` only includes the memory dump of
the contents of the input object file. [1] This means that sections like
for debug information that do not occupy memory during the process
execution are discarded by design. [2]

In addition, if we do not want a particular ELF section, we can list it
in the discard section of the linker script.

[1] https://man7.org/linux/man-pages/man1/objcopy.1.html
[2] https://man7.org/linux/man-pages/man5/elf.5.html

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
43967feb2c genprotimg/boot: disable build-id
Disable the build-id since it was never used. Adapt the linker scripts
accordingly.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
8f4535f5eb genprotimg/boot: use --no-warn-rwx-segments linker flag
This disables the following warning `ld: warning: stag3a.elf has a LOAD
segment with RWX permissions` for newer linker. This changes nothing in
functionality for the bootloaders, since only the binaries and not the
ELF files are actually used.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
dfe8a4f803 genprotimg/boot: declare that no executable stack is required
Normally, `gcc` takes care of adding the `GNU_STACK` marking except for
assembly code. Therefore, let's add the marking manually. Discard the
`.note.GNU-stack` section in the linker script since it's just a
"message" from the compiler to the linker. This fixes the linker
warning:

ld: warning: entry.o: missing .note.GNU-stack section implies executable stack

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
fe0d42e295 zipl/boot: use linker scripts for all bootloaders
Use linker script for all bootloaders instead of having the load
addresses of the bootloaders hard-coded in the Makefile. This allows us
to simplify the Makefile and it fixes the dependency tracking for the
bootloaders *0.bin, *1.bin, and *1b.bin.

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
baf7e9aa2e zipl: move STAGE2_MAX_SIZE and STAGE1B_LOAD_ADDR to loaders_layout.h
This allows the reuse of the macro in the next patch. In order to match
the naming scheme rename `STAGE1B_LOAD_ADDR` to `STAGE1B_LOAD_ADDRESS`.

Acked-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
60d03262d8 zipl/boot: simplify objcopy commands
Instead of maintaining an include list, use an exclude list (if
neccessary). This simplifies the `objcopy` calls a lot, and it's
possible because `objcopy -O binary` only includes the memory dump of
the contents of the input object file. [1] This means that sections like
for debug information that do not occupy memory during the process
execution are discarded by design. [2]

In addition, if we do not want a particular ELF section, we can list it
in the discard section of the linker script.

[1] https://man7.org/linux/man-pages/man1/objcopy.1.html
[2] https://man7.org/linux/man-pages/man5/elf.5.html

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
4bed503aa7 zipl/boot: disable build-id
Disable the build-id since it was never used. Adapt the linker scripts
accordingly.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
4518bf7d73 zipl/boot: use --no-warn-rwx-segments linker flag
This disables the following warning `ld: warning: stage3.exec has a LOAD
segment with RWX permissions` for newer linker. This changes nothing in
functionality for the zipl bootloaders, since only the binaries and not
the ELF files are actually used.

Acked-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
3d168fac14 zipl/boot: declare that no executable stack is required
Normally, `gcc` takes care of adding the `GNU_STACK` marking except for
assembly code. Therefore, let's add the marking manually. Discard the
`.note.GNU-stack` section in the linker script since it's just a
"message" from the compiler to the linker. This fixes the linker
warning:

ld: warning: entry.o: missing .note.GNU-stack section implies executable stack

Acked-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
746a703079 zipl/boot: discard .eh_frame and .interp input sections
The ELF section `.eh_frame` is used for frame unwinding during, for
example, exception handling and the section `.interp` is used by the
program interpreter. [1] Since no frame unwinding nor a program
interpreter is used for the bootloaders we can discard these input
section.

The content of the (exec|bin) files don't change after this change.

[1] https://refspecs.linuxfoundation.org/LSB_1.2.0/gLSB/specialsections.html

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Marc Hartmayer
4aa5534f1d common.mak: fix typo and remove blank line at the EOF
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-13 22:18:49 +01:00
Sven Schnelle
7c24855ba1 ipl_tools: add support for list-directed IPL from ECKD DASD
Add support to chreipl/lsreipl to show and reconfigure ipl parameters
for list-directed IPL from ECKD DASD.

Parameters accepted:

device   - ccw device id
bootprog - Boot Prog Selector
loadparm - Load parameters
brchr    - location of bootrecord in cylinder/head/record format.
clear    - clear memory before loading

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-02-03 14:48:37 +01:00
Ingo Franzki
6222c38495 zkey: Support EP11 host library version 4
Try to load libep11.so.4 if available, but fallback to older
library versions if not.

Reviewed-by: Jörg Schmidbauer <jschmidb@de.ibm.com>
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-01-27 14:12:38 +01:00
Ingo Franzki
8709a47f6f libseckey: RSA cipher: Tolerate "implicit rejection" option
With parameter OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION one can enable or
disable the implicit rejection mechanism for RSA PKCS#1 v1.5 decryption.
For the default provider, this is enabled by default.

We do not support implicit rejection so far, so disable it for the
default provider operation context when the key contains an RSA secure key,
and reject to set it to anything else then 0 (disabled).

See OpenSSL commit 5ab3ec1bb1

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-01-27 14:12:38 +01:00
Ingo Franzki
1fb05038cd libseckey: RSA signature: Support OSSL_PKEY_RSA_PSS_SALT_LEN_AUTO_DIGEST_MAX
Since OpenSSL 3.1 a new RSA-PSS salt length constant exists to select
the maximum possible salt length based on the RSA-PSS parameters and the
digest used: OSSL_PKEY_RSA_PSS_SALT_LEN_AUTO_DIGEST_MAX
This is the default salt length when no other salt length is set by
the caller.

In contrast to OSSL_PKEY_RSA_PSS_SALT_LEN_MAX, OSSL_PKEY_RSA_PSS_SALT_LEN_AUTO_DIGEST_MAX
also ensures that the resulting salt length is not larger than the used
digest size. The salt length calculated with OSSL_PKEY_RSA_PSS_SALT_LEN_MAX
may be larger than the digest size, dependent on the RSA-PSS parameters.

FIPS 186-4 section 5 "The RSA Digital Signature Algorithm", subsection
5.5 "PKCS #1" says: "For RSASSA-PSS […] the length (in bytes) of the
salt (sLen) shall satisfy 0 <= sLen <= hLen, where hLen is the length of
the hash function output block (in bytes)."

See OpenSSL commit 6c73ca4a2f

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-01-27 14:12:38 +01:00
Ingo Franzki
4f5d33988d libseckey: EC signature: Reject deterministic signatures
With parameter OSSL_SIGNATURE_PARAM_NONCE_TYPE one can choose to generate
a deterministic signature, i.e. using a deterministic nonce K.

We do not support that so far, so reject to set the nonce type to
anything other than 0 (random nonce K).

See OpenSSL commit f3090fc710

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-01-27 14:12:38 +01: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
Thomas Richter
b8fff9b750 libvmdump: Remove libvmdump and vmconvert
The library libvmdump is written in C++ and uses exception handling
and class inheritance. The tools vmur and vmconnect are compiled using
the C++ compiler for linking with the libvmdump library.

With integration of vmdump file support into the zgetdump tool and
the removal of vmur vmdump file conversion support there is no need
anymore the vmconvert tool.
With removal of the tool vmconvert, the libvmdump library written in C++
has no more user and can be deleted.

Remove the vmconvert command from the zgetdump man page.

Remove the directories libvmdump and vmconvert and adjust the Makefile.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Suggested-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-01-27 14:12:38 +01:00
Thomas Richter
d5f853c460 vmur: Remove option -c for dump file conversion
Remove option -c for implicit dump file conversion from vmdump format
to lkcd format. If option -c is specified, an error message
is printed and the program terminates. A hint to the new conversion
tool zgetdump is shown.  Option -c is not listed in the help text.
The man page is also updated to reflect this change.
With zgetdump tool now supporting vmdump file format there is no need to
convert a vmdump file while extracting it from the reader device.

Use commands
1. vmur rec <spool-id> VMDUMP_FILE
2. zgetdump VMDUMP_FILE ELF_FILE
to extract a vmdump file from the reader and convert it to elf format.

Note to Maintainer:
The rename of file vmur.cpp to vmur.c triggers the pre-commit
checking of git-format-clang. This checking fails. This is intended.
The patch shows the changes for this line item.
The pre-commit checking fails on many, many changes not touched
for changed by this patch.
The pre-commit failure should be fixed with a follow-on patch.

Suggested-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-01-27 14:12:38 +01:00
Thomas Richter
067dd5c7ef zdump: Add vmdump dfi for vmdump format to elf format
Add support for vmdump 64big format to the zgetdump utility.
The result is an elf file suitable for tool crash.
This patch adds file dfi_vmdump.c to handle conversion from
z/VM vmdump format to the internal memory representation of this tool.
Therefore both output formats elf and s390 are supported as target
of the conversion.

The vmdump file formats 32bit and 64bit are not supported anymore.
They have been obsolete since CP version 5.1 (end of service since
30-Sep-2009).

Vector register set is not part of a vmdump file and can not be
displayed.

Output before:
 # zgetdump ~/vmdump-0383
 zgetdump: No valid dump found on "/root/vmdump-0383"
 #

Output after:
 # ./zgetdump ~/vmdump-0383 ~/vmdump-0383.elf
 Format Info:
  Source: vmdump
  Target: elf

 Copying dump:
  00000000 / 00000379 MB
  00000379 / 00000379 MB

 Success: Dump has been copied
 # file ~/vmdump-0383.elf
 /root/vmdump-0383.elf: ELF 64-bit MSB core file, IBM S/390, version 1 \
	 .... (SYSV), SVR4-style, from 'vmlinux'
 #

 # ./zgetdump -i ~/vmdump-0383
 General dump info:
  Dump format........: vmdump
  Version............: 2
  UTS node name......: s8360046.lnxne.boe
  UTS kernel release.: 6.1.0-rc2-d-perf+
  UTS kernel version.: #1 SMP Fri Oct 28 09:42:13 CEST 2022
  System arch........: s390x (64 bit)
  CPU count (online).: 2
  CPU count (real)...: 2
  Dump memory range..: 2048 MB

 Memory map:
  0000000000000000 - 000000007fffffff (2048 MB)
 #

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-01-27 14:12:38 +01:00
Joern Siglen
af1d05c4a4 dbginfo.sh: correct location of qemu guest agent command
qemu-ga command was accidently moved to z/VM commands

Reviewed-by: Michael Storzer <mstorzer@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-01-27 14:12:38 +01:00
Joern Siglen
c5ec01420f dbginfo.sh: add zVM command q syscontrol
determine the current values of the algorithm settings controlled
by the SET SYSCONTROL

Reported-by: Eberhard Pasch <epasch@de.ibm.com>
Reviewed-by: Michael Storzer <mstorzer@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-01-27 14:12:38 +01:00
Joern Siglen
f25984e716 dbginfo.sh: update copyright date
update copyright date

Reviewed-by: Michael Storzer <mstorzer@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-01-27 14:12:38 +01:00
Marc Hartmayer
7babd82e6f zgetdump/Makefile: don't use .check_dep_zgetdump as linker input
The `.check_dep_zgetdump` file is used to cache the result of the
dependency checks and should not be used as input for linking or
anything else. Let's add it as dependency for the objects file. This
shouldn't cause any problems since the Makefile rule for object files is
defined in `common.mak` as follows:

%.o: %.c
	$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c $< -o $@

Fixes: https://github.com/ibm-s390-linux/s390-tools/issues/147
Fixes: 8d8d5e9746 ("zdump: Fix Makefile dependencies")
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Hoeppner <hoeppner@linux.ibm.com>
2022-12-20 08:17:20 +01:00
Steffen Eiden
d030874050 libpv: disallow glib features from after 2.56
Enforce that the first glib.h include is done via glib-helper.h for libpv
so that glib version checks are in place.

Change zdump and pvattest such that they never include glibstuff before
libpv/glib-helper.h

Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2022-12-15 11:33:46 +01:00
Steffen Eiden
394a6dd5ea zdump: replace atomic refcount with atomic int
(Atomic) refcounting was introduced in glib2.58.
We want to support v2.56 as well, so replace it with int and the atomic
operations introduced in glib 2.4.

Fixes: https://github.com/ibm-s390-linux/s390-tools/issues/146
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2022-12-15 11:26:11 +01:00
Nikolay Gueorguiev
db6eb7d554 s390-tools: Fix Makefile install step chown warnings
Since coreutils v9.1 commit 8f31074cb ("chown: warn about USER.GROUP")
chown utility now warns about using of wrong separator for USER and
GROUP options.

Closes: https://github.com/ibm-s390-linux/s390-tools/pull/145
Signed-off-by: Nikolay Gueorguiev <nikolay.gueorguiev@suse.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2022-12-15 11:23:37 +01:00
Jan Höppner
032304d503 Prepare for next release
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-12-08 13:40:15 +01:00
Jan Höppner
f75c923627 New release s390-tools-2.25.0
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-12-08 13:40:15 +01:00
Fedor Loshakov
bca8fa3f9c ziomon: fix Makefile install step chown warnings
Since coreutils v9.1 commit 8f31074cb ("chown: warn about USER.GROUP")
chown utility now warns about using of wrong separator for USER and
GROUP options. This leads to warnings during intall step in ziomon:

$ make install
  INSTALL ziomon
  SED     ziomon/install
chown: warning: '.' should be ':': ‘root.root’
  SED     ziomon/install
chown: warning: '.' should be ':': ‘root.root’
  SED     ziomon/install
chown: warning: '.' should be ':': ‘root.root’

To fix those warnings use ':' as separator instead of '.'. With this
patch applied those warnings are no longer present.

Signed-off-by: Fedor Loshakov <loshakov@linux.ibm.com>
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2022-12-07 16:54:09 +01:00
Joern Siglen
d713ea6389 dbginfo.sh: log the work dir state in dbginfo.log
As on space problems the packing may fail, incomplete tgz are send.
Today no evidence for this is in dbginfo.log, packed upfront into the tgz.
This update helps to identify space related corruption of tgz files.

Reviewed-by: Mario Held <mario.held@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2022-12-07 16:54:09 +01:00
Niklas Schnelle
f9fbe79e4f ipl_tools: Fix chreipl node for NVMes with CONFIG_NVME_MULTIPATH
When the kernel is build with CONFIG_NVME_MULTIPATH enabled and an NVMe
where the driver exposes its controller separately is used, chreipl node
on a mount point of the NVMe fails. The failure occurs because chreipl
tries to get the function_id from the NVMe's nvmeXnY block device via
the path '/sys/block/nvmeXnY/device/device/function_id' which does not
exist.

The underlying problem is that with NVMe multipath support the PCI
function is not associated directly with a particular NVMe namespace but
instead with the entire NVMe device which may host multiple NVMe
namespaces. The correct way to get from the block device to the
underlying PCI device and its function ID is then to extract the device
name i.e. the 'nvmeX' part from 'nvmeXnY' and use that to get the
function ID via '/sys/class/nvme/nvme<X>/device/function_id'.

Fixes: 0472b5ea5c ("ipl-tools: Add nvme device support to lsreipl/chreipl")
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2022-12-07 16:54:09 +01:00
Steffen Eiden
3cc0b4cdea pvattest/tools: remove xxd dependency from scripts
xxd has vim-common as a dependency. We can avoid that by using od
instead which is from coreutils.

While at it, add the require_command function from the
pvattest-info script to the pvextract-hdr script and use it.

Suggested-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2022-12-07 16:53:37 +01:00
Steffen Eiden
eef9f622c0 pvattest/man: fix wording
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2022-12-07 16:50:16 +01:00
Daniel S. Haischt
889293e557 zdev: implement --shell command line switch
Fix issue in the lszdev command where column names if using the --pairs
command line switch can contain characters that are not allowed to be
used as variable names in a shell environment.

Replace bad characters in column names by an underscore if the --shell
command line switch is specified along with the --pairs switch.

The additional --shell switch mimics what is already available in the
lsblk command and thus it shall be used along with the --pairs switch.

Signed-off-by: Daniel S. Haischt <modean@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2022-12-07 16:50:16 +01:00
Jan Höppner
0c5b9f5d11 mon_tools: Silence address-of-packed-member compile warning
The proc_sum_t struct is defined with the packed attribute and
produces the following compile warning:

mon_procd.c: In function ‘read_cpu’:
mon_procd.c:351:27: warning: taking address of packed member of ‘struct proc_sum_t’ may result in an unaligned pointer value [-Waddress-of-packed-member]
  351 |         cal_cpu(&cpudata, &proc_sum.cpu);
      |                           ^~~~~~~~~~~~~

Silence the warning with -Wno-address-of-packed-member compile flag
since the struct is required to be as is.

Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2022-12-07 16:50:09 +01:00
Jan Höppner
02af069d48 boot_defs.h: Fix compile warning in zfcpdump
The struct scsi_dump_sb is defined with the __packed attribute and
produces the following compile warning in zfcpdump:

zfcpdump_part.c: In function ‘csum_update’:
zfcpdump_part.c:125:41: warning: taking address of packed member of ‘struct scsi_dump_sb’ may result in an unaligned pointer value [-Waddress-of-packed-member]
  125 |                      dump_sb.csum_size, &dump_sb.csum)) {
      |                                         ^~~~~~~~~~~~~

However, all members are of the same size and the __packed attribute is
unnecessary. Remove the attribute to get rid of the warning.
Add assertion to ensure correct size of the struct during compile time.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2022-12-07 16:49:04 +01:00
Steffen Eiden
5e0056db8d util_lockfile: fix includes
The 'unistd.h' header was missing. Under some circumstances the
-D_GNU_SOURCE gcc flag does not trigger including that file.
Therefore, explicitly include this file here.

Fixes: e1aec24e84 ("libutil: introduce util_lockfile")
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-30 15:51:15 +01:00
Matthew Rosato
4b5937f142 ap_tools/ap-check: use new mdevctl install location
mdevctl has been updated to use /usr/lib/mdevctl/scripts.d/callouts/
instead of /etc/mdevctl.d/scripts.d/callouts/.  The /etc location
is considered deprecated, meaning mdevctl will also look at that
location for now but might eventually stop looking in /etc for
callout scripts.
Based on that, update the installation location for the ap-check
callout.  However, because older versions of mdevctl will still
only look in /etc, let's also put a wrapper script in /etc for now
to provide backward compatibility, and plan to remove it at a
later time.

Link: df6bb57429
Fixes: https://github.com/ibm-s390-linux/s390-tools/issues/139
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-30 15:50:33 +01:00
Marc Hartmayer
8d8d5e9746 zdump: Fix Makefile dependencies
The Makefile target `check_dep_fuse` was declared as .PHONY and
therefore it was always rebuilt. This caused zgetdump to always be
relinked. While at it, remove the non-existent Makefile target
`check_dep_zlib` and add the cache files to `.gitignore`.

Closes: https://github.com/ibm-s390-linux/s390-tools/issues/144
Fixes: e537ab902e ("zdump: Makefile: add basic libpv support")
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-29 17:03:57 +01:00
Jan Höppner
5bdabe3e06 common.mak: Fix pretty print for linking
Commit ae7217806b ("common.mak: remove `LINK` and `LINKXX`") changed
the LINK and LINKXX definition to ensure that the same compiler is used
for compilation and linking when specified with CC= (or CXX=
respectively) on the commandline.

However, the commit also removed the pretty print for both commands. Add
the pretty print back in and use the already defined $(CC) and $(CXX)
variables to preserve the original change.

Fixes: ae7217806b ("common.mak: remove `LINK` and `LINKXX`")
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-29 17:03:57 +01:00
Marc Hartmayer
8a1db94d37 zdump: add missing newlines for log messages
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-29 17:03:57 +01:00
Marc Hartmayer
1911cba130 zdump: check provided sizes for reasonableness
Check the dump provided sizes for reasonableness. This avoids that a
corrupted dump leads to allocation of large buffers on the heap.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-29 17:03:57 +01:00
Marc Hartmayer
f4ed0b0ec6 zdump: check size before mmap'ing
Verify that the size is large enough before doing the mmap. Otherwise
this can result in a SIGBUS signal if there is an attempt to access a
page that lies beyond the end of the mapped file (see `man 2 mmap`).

Fixes: 8fa1b5a00b ("zdump: dfi: add support to read Protected Virtualization dumps")
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-29 17:03:57 +01:00
Marc Hartmayer
6e42c527d7 zdump: pv_process_pglist: convert assertions into errors
Corrupted dumps might have invalid page states. Therefore, let's convert
the assertions into errors.

Fixes: 8fa1b5a00b ("zdump: dfi: add support to read Protected Virtualization dumps")
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-29 17:03:57 +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
Eduard Shishkin
cf5f373142 zipl: Rename component_type enum
Rename component_type enum from COMPONENT_* to COMPONENT_TYPE_*

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-29 17:03:57 +01:00
Eduard Shishkin
e09c675b70 libvtoc: Introduce is_vol1() check
Introduce is_vol1() in vtoc.h and update the user in libzds.c

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-29 17:03:57 +01:00
Eduard Shishkin
6bd93f475c Clean up of libdasd
Remove standalone IOCTLs definitions and use sys/mount.h instead

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-29 17:03:57 +01:00
Stefan Haberland
3f12bdf4c7 tunedasd: add copy_pair swap capability
Add an option to tunedasd to trigger a copy pair swap using the appropriate
ioctl for DASD devices.

      -s, --copy-pair-swap COPY_PAIR

This command requires a comma separated pair of primary,secondary to be
specified. In case of success the old secondary will become the new primary
device and the old primary will become a secondary device.

Example:

tunedasd /dev/dasda -s 0.0.9700,0.0.9740

This will set the old secondary device 0.0.9740 as the new primary.
The old primary device 0.0.9700 will automatically become a secondary
device.

Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-15 10:24:42 +01:00
Stefan Haberland
3aa7f6e298 libdasd: fix ioctl macro to return also positive return codes
In case of an error the ioctl macro only returns errno to the calling
function.
This misses positive returncodes from ioctls.
Change the macro to also return positive return codes.

Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-15 10:24:42 +01:00
Stefan Haberland
4e28047eb4 tunedasd: move tunedasd ioctls to libdasd
Move all DASD IOCTLs to libdasd and adapt all affected
users accordingly.

Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-15 10:24:42 +01:00
Stefan Haberland
f654b971d0 zdev: add copy_pair attribute for DASD devices
The DASD device driver has a new attribute copy_pair to make storage
server copy pairs known to the driver.
Add this attribute to zdev.

Usage example:

Add two copy pairs 1000,2000 and 1000,3000 to a DASD device 1000
$ chzdev dasd 1000 copy_pairs=1000,2000 copy_pairs=1000,3000

or

$ chzdev dasd 1000 copy_pairs="1000,2000 1000,3000"

To add a third copy pair later on:
$ chzdev dasd 1000 copy_pairs=1000,4000

To remove all copy pairs from the device 1000:
$ chzdev dasd 1000 -r copy_pairs

Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-15 10:24:42 +01:00
Stefan Haberland
e742d1c9ae zdev: correctly handle multiple values for CCW devices
Correctly create multiple lines in the udev rule for CCW device attributes
with multi bit set that contain multiple values.

Suggested-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-15 10:24:42 +01:00
Stefan Haberland
803b87e324 zconf/lsdasd: add Copy Pair output option
Add an option -P|--copy-pairs to show all DASD devices with copy
relations set up in the system and their roles.

The output looks like:

    # ./s390-tools/zconf/lsdasd -h
    [...]
            -P|--copy-pairs
	             Print information about copy pairs.

     # ./s390-tools/zconf/lsdasd -P
     Bus-ID    Role       Name      Paired devices
     ================================================================================
     0.0.9700  primary    dasdd     0.0.9740,0.0.9743,0.0.9744,0.0.9745
     0.0.9740  secondary            0.0.9700
     0.0.9701  primary    dasdf     0.0.9741
     0.0.9741  secondary            0.0.9701
     0.0.9702  primary    dasdh     0.0.9742
     0.0.9742  secondary            0.0.9702

Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-15 10:24:42 +01:00
Stefan Haberland
5107a7be16 zconf/lsdasd: fix Copy Pair related output
Fix the default output for copy pair secondary devices to not show
a faulty blockdevice entry and major:minor combination.

The new output looks like:

    # lsdasd
    Bus-ID    Status    Name      Device  Type         BlkSz  Size      Blocks
    ================================================================================
    0.0.9740  secondary                   ECKD
    0.0.9741  secondary                   ECKD
    0.0.9742  secondary                   ECKD
    0.0.e964  active    dasda     94:0    ECKD         4096   21129MB   5409180
    0.0.e967  active    dasdb     94:4    ECKD         4096   21129MB   5409180
    0.0.9330  active    dasdc     94:8    ECKD         4096   782MB     200340
    0.0.9700  active    dasdd     94:12   ECKD         4096   782MB     200340
    0.0.9701  active    dasdf     94:20   ECKD         4096   782MB     200340
    0.0.9702  active    dasdh     94:28   ECKD         4096   782MB     200340

Also add copy_pairs to extended output:

     # lsdasd -l 9700
     0.0.9700/dasdd/94:12
       status:                               active
       type:                                 ECKD
       blksz:                                4096
       size:                                 782MB
       blocks:                               200340
       extent_size:                          1113
       logical_capacity:                     1113
       space_allocated:                      1113
       use_diag:                             0
       readonly:                             0
       eer_enabled:                          0
       erplog:                               0
       hpf:                                  1
       uid:                                  IBM.750000000ABT31.9700.00
       fc_security:                          Unsupported
       paths_installed:                      38 39 3a 3b
       paths_in_use:                         38 39 3a 3b
       paths_non_preferred:
       paths_invalid_cabling:
       paths_cuir_quiesced:
       paths_invalid_hpf_characteristics:
       paths_error_threshold_exceeded:
       copy_pairs:                           0.0.9700,0.0.9740 0.0.9700,0.0.9743 0.0.9700,0.0.9744 0.0.9700,0.0.9745

Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-15 10:24:42 +01:00
Jan Höppner
1178291686 Prepare for next release
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-09 17:11:48 +01:00
Jan Höppner
c8d1aa55b4 New release s390-tools-2.24.0
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-09 17:11:48 +01:00
Matthew Rosato
25a70ac5a8 libap: use util_lockfile and remove liblockfile dependency
Now that we have a utility library for file locking, remove all
calls to liblockfile functions from libap and remove all links to
the library from the current users of the libap liblockfile
implementation (ap_tools/ap-check and zdev).

Fixes: https://github.com/ibm-s390-linux/s390-tools/issues/142
Suggested-by: Luca BRUNO <luca.bruno@coreos.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-09 16:09:19 +01:00
Matthew Rosato
6235a51d7c libutil: add example for util_lockfile
Adds util_lockfile_example.c, which can be used to sample
util_lockfile support.

To acquire a lock using a parent PID (e.g. your shell instance):
util_lockfile_exmample -f <path> -l <retries>

To release the lock using the parent PID:
util_lockfile_example -f <path> -r

To acquire the lock, sleep briefly, and then release the lock
using the PID of the util_lockfile_example process:
util_lockfile_example -f <path> -L <retries>

In each example, the <path> is the location of the desired lockfile
and <retries> is the number of times to retry acquiring the lock
if it fails.

GitHub-ID: https://github.com/ibm-s390-linux/s390-tools/issues/142
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-09 16:09:19 +01:00
Matthew Rosato
e1aec24e84 libutil: introduce util_lockfile
Implement simple file-locking routines that use process PIDs for stale
lock detection.  The implementation is meant to be a simplified subset of
what liblockfile was previously being used for by libap, allowing the
external dependency to be removed.

This initial implementation provides a series of functions that allow for
creating/release file locks using either the current process PID or the
PID of the current process parent.  When creating a file lock, first a
temporary file is created and the appropriate PID (either this process
PID or the parent process PID) is placed in the file to specify the owner
of the lock.  Then an attempt is made to link that file to the desired
file location; if this succeeds, the lock is now held on behalf of the
specified PID.  If it fails, this implies the file already exists
(meaning the lock is already held).  In this case, stale lock detection
is performed by reading the PID from the file and ensuring that the
associated process still exists -- if it does not, then the lock is
presumed stale and destroyed.  If the process still exists, then either
the lock request fails or the caller will sleep and retry, depending on
an optional retry setting.

A lock remains valid until either 1) it is released via the corresponding
util_lockfile function, which will delete the corresponding file 2) the
associated PID no longer exists, which leaves the file in-place but will
cause it to be destroyed the next time a different process attempts to
lock that file or 3) the file is directly removed (e.g. rm).

A typical usecase for such support would be to provide a means for
multiple invocations of the same (or different) tools to ensure that they
do not access the same shared resource simultaneously.  For example,
ap-check, chzdev and lszdev all have a need to view and/or modify the AP
and vfio-ap configuration files; util_lockfile can be used to ensure that
only one instance of any of these utilities do that at a time by ensuring
they all use the same lockfile.
Additionally, providing the ability to specify the parent PID rather than
the current PID allows for a general purpose tool (like mdevctl) to
invoke a sub-program (ap-check) to acquire and release a lockfile as
necssary while allowing stale lock detection to be controlled by that
parent PID, allowing the lock to remain held over multiple sub-program
invocations.

Note that this implementation is sufficient for our current usage (e.g.
lockfiles placed in tmpfs) but does not take into consideration things
like NFS, which a more complete lockfile solution like liblockfile does.

GitHub-ID: https://github.com/ibm-s390-linux/s390-tools/issues/142
Suggested-by: Luca BRUNO <luca.bruno@coreos.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-09 16:09:19 +01:00
Eduard Shishkin
d9a6fb3ccf zipl/src: fix secure boot status check
Set up the secure_boot_supported global variable at the
function bootmap_create() instead of bootmap_create_device()
to make sure that the secure boot status is checked for all
relevant jobs.

Fixes: 7b369318dd ("zipl: check for secure boot once")
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-09 16:09:19 +01:00
Steffen Eiden
a47dd4570a README: update zgetdump information
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:45:38 +01:00
Marc Hartmayer
8fa1b5a00b zdump: dfi: add support to read Protected Virtualization dumps
Sometimes dumping a virtual machine from the outside is the only way to
get the data that is needed. This can be the case if a dumping mechanism
like kdump hasn't been configured or data needs to be fetched at a
specific point. Dumping a protected guest from the outside without help
from FW/HW doesn't yield sufficient data to be useful. Hence we have
introduced Protected Virtualization (PV) dump support - also named
confidential dump support.

The confidential dump support works by integrating the firmware into the
dump process. New Ultravisor calls (UVC) are used to initiate the dump
process, dump CPU data, dump memory state and lastly complete the dump
process. The guest's data is fully encrypted and can only be decrypted
by the entity that owns the customer communication key (CCK) for the
dumped guest. The output format is very similar the normal s390 vmcore
ELF format, it's only enriched by new sections where the returned data
from the UVC "Complete Configuration Dump" and the UVC "Dump
Configuration Storage State" is stored. The encrypted CPU data is stored
in a new note type `NT_S390_PV_CPU_DATA`. The old note types do still
exists but without any confidential data stored. The memory data is
stored in the LOAD segment as usual but for PV dumps it's fully AES-XTS
encrypted.

This commit adds support for reading/decrypting PV guest dumps to
zgetdump by introducing a new DFI input module (`dfi_pv_elf.c`). For
specifying the customer communication key a new command line option
`--key` is added.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:45:38 +01:00
Marc Hartmayer
e537ab902e zdump: Makefile: add basic libpv support
The functionalities of libpv are used in the next patch. Libpv itself
requires glib2 and libcrypto.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:45:38 +01:00
Marc Hartmayer
f0fb4a180a zdump: refactor usage print
The function will be reused in a later patch.

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-11-03 17:45:38 +01:00
Marc Hartmayer
f957d895cd zdump: consolidate error reporting
Consolidate error reporting to make sure that error messages are used
consistently. In addition, don't call `zg_exit()` directly, but instead
return the value 1 in `main()`.

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-11-03 17:45:38 +01:00
Marc Hartmayer
73c3a9e684 libpv: fix memory leak in pv_get_openssl_error
While at it, improve documentation and adapt libpv code.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:45:38 +01:00
Marc Hartmayer
2ee1387f34 libpv/genprotimg/pvattest: use glib/gi18n.h
Replace `<glib/gi18n-lib.h>` with `<glib/gi18n.h>` since `<glib/gi18n-lib.h>` should only be used
for libraries (see https://docs.gtk.org/glib/i18n.html).

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:45:38 +01:00
Eduard Shishkin
10cefb3337 zipl/src/zipl_helper.device-mapper: Fix bug in error path
Prevent double free/close that happens in get_multipath_status()
when the output of "dmsetup status XXX" is empty

Fixes: 599b141 ("zipl: Rewrite helper script in C")
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:45:09 +01:00
Dan Horák
7b369318dd zipl: check for secure boot once
Check for secure boot status only once when starting to create the
bootmap.

Closes: https://github.com/ibm-s390-linux/s390-tools/pull/133
Signed-off-by: Dan Horák <dan@danny.cz>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Dan Horák
cf2fb296f0 zipl: be verbose about secure boot support
Report the details about the state of secure boot on the system when running
zipl in verbose mode.

GitHub-ID: https://github.com/ibm-s390-linux/s390-tools/pull/133
Signed-off-by: Dan Horák <dan@danny.cz>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Marc Hartmayer
6cbd81f997 zdump: zg.h: consolidate PAGE_SIZE macros
Reuse `PAGE_SIZE` defined in `boot/s390.h`.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Marc Hartmayer
2025cf751f zdump: man: fix long form of abbreviation
ELF stands for "Executable and Linkable Format" (see
https://refspecs.linuxfoundation.org/elf/TIS1.1.pdf).

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Marc Hartmayer
5a052103ae zdump: fix signatures of the wrappers zg_alloc, zg_realloc and zg_ioctl
Adapt the wrappers `zg_alloc`, `zg_realloc` and `zg_ioctl` to match the
signatures used by `calloc`, `realloc` and `ioctl`.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Thomas Richter
2ced5853b4 cpumf/lshwc: fix incremented counter output
lshwc displays counter values extracted from the /dev/hwctr device.
The counter values are retrieved using a loop and incremented instead
of just displayed on output.
This leads to the situation where a counter is incremented in large
numbers while the counter triggering program is active. When this
program terminates, the counter should not increase but remain steady.

This is not the case as this example shows:

 # lshwc -i 2 -l90 -a :a | fgrep Total  | \
	awk -F ',' '{print $2 "," $152 "," $157}'
 Report time and values of DFLT_ACCESS and DFLT_CC counters
 sleep 10
 # DFLTCC=1 python3 -c "import zlib; zlib.compress(b'A'*6000000000);
 Increment counter DFLT_ACCESS and DFLT_CC, runs about 45 seconds

Output before:
15:24:20,0,0
15:24:22,0,0
15:24:24,0,0
15:24:26,0,0
15:24:28,0,0
15:24:30,0,0
15:24:32,2067027,592996481      <--- python3 program start
15:24:34,6953101,2039012580
15:24:36,14494585,4264340060
15:24:38,24759568,7346128396
....
15:24:56,232929262,70526362509
15:24:58,269037963,81464038124
15:25:00,307757248,93171809261
15:25:02,348900718,105620730492
15:25:04,392646075,118841031269  <--- python3 program stop
15:25:06,438956016,132853968029  <-- Value column two increased by 49148217
15:25:08,488104233,147709011658  <-- Similar high increase

The reason is that lshwc takes the last read counter value and keeps
adding it to the total count, even if there zero delta to the previous
read value. Fix this by clearing the total count value between ioctl()
read operations.

Output after:
15:39:26,0,0
15:39:28,0,0
15:39:30,0,0
15:39:32,0,0
15:39:34,0,0
15:39:36,1367250,380721127      <--- python3 program start
15:39:38,4104791,1108181711
15:39:40,6740994,1858843730
15:39:42,9277545,2646351211
15:39:44,11895180,3444375804
....
15:40:16,54060774,16315924126
15:40:18,57830349,17513712210
15:40:20,61628170,18690791102
15:40:22,65410470,19864086006
15:40:24,69070765,21028646754   <--- python3 program stop
15:40:26,70429758,21472772340   <-- No increase of value in column two
15:40:28,70429758,21472772340
15:40:30,70429758,21472772340
15:40:32,70429758,21472772340
15:40:34,70429758,21472772340
15:40:36,70429758,21472772340
15:40:38,70429758,21472772340

Fixes: 27a562da0a ("cpumf/lshwc: Program to extract complete counter sets")
Reported-by: Axel Busch <Axel.Busch@ibm.com>
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Thomas Richter
13edbb7d5e cpumf/pai: fix core dump when summary flag set
pai dumps core when invoked with summary flag -S and
certain painnpa.XXXXX data files:

   # ~/s390-tools/cpumf/pai -r -S
   Segmentation fault (core dumped)
   #

Fix this and check the existence of event raw data before
reading it. This avoid accessing NULL pointer trying to read raw
data when no counter values have been appended as raw data by the
kernel.

Fixes: dc73c77d73 ("cpumf/pai: Omit detailed event information when summary flag selected")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Vineeth Vijayan
1643af4578 zdev: dracut: modifiy the module-setup.sh
Export and import the configurations with zdev:early on the
site-specific configurations as well. Filter the site-specific
configurations by attribute "zdev:early" and import the output
to the corresponding sites.

Note that --site parameter does not work with the device type.

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Vineeth Vijayan
c7ac1e63bd zdev: add export/import support for site
Add export and import support for site-specific settings. For each
site-specific configuration, a new site-block will be generated as
below. The same format can be interpreted by the import function and use
the values on the device's site-specific configuration.

Typical example of a site-block in the export file:

[site3 dasd-fba 0.0.f001]
online=1
cmb_enable=0

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Vineeth Vijayan
fa3dd0ec20 zdev: add --deconfigure-all function for chzdev
Introduce --deconfigure-all feature, which will remove all available
settings from the mentioned device. A typical device can have 10
different site-specific settings, active settings, persistent
settings and sometimes auto-configured settings configured in it.
--deconfigure-all can be used to remove all of them with a single
command.

usage: 	chzdev -D <device-id>
	chzdev --deconfigure-all <device-id>

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Vineeth Vijayan
34146c3f92 zdev: modify man-pages to update the site information
Add the new site parameter help information in the man-pages of both
chzdev and lszdev.

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Vineeth Vijayan
298ede17f5 zdev: provide site-specific information in lszdev
lszdev must be modified to share the site-specific configuration
information from the persistent settings. The persistent configuration
array will be read and tabularized based on the site-id input from the
user.

This patch also accommodates the site specific information in the
lszdev --info command. New information about the site-ids are integrated
with the command. For example,

DEVICE dasd-eckd 0.0.f001
  Names              : -
  Modules            : dasd_eckd_mod dasd_mod
  Online             : no
  Exists             : yes
  Persistent         : yes
  Sites              : 1,2

  ATTRIBUTE                     ACTIVE    PERSISTENT  SITE1  SITE2
  cmb_enable                    "0"       "0"         "1"    -
  eer_enabled                   "0"       -           -      -
  erplog                        "0"       -           -      -
  failfast                      "0"       -           -      -
  last_known_reservation_state  "none"    -           -      -
  online                        "0"       "1"         "1"    "1"
  raw_track_access              "0"       -           -      -
  readonly                      "0"       -           -      -
  reservation_policy            "ignore"  -           -      -
  use_diag                      "0"       -           -      -

Each available site specific configuration will be shown as column. The
"Sites" parameter in the above output indicates the available site
configurations and the SITE1 and SITE2 colums indicates the detailed
configuration for the respective sites.

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Vineeth Vijayan
d66ace8121 zdev: add functionality to read site-specific settings
Modify the dev_get_setting_list function to get the site-specific
attributes of the device. The new site_id parameter for this function
must be less than SITE_FALLBACK to read the site-specific attributes.
As SITE_FALLBACK setting is same as persistent setting, we do not need
a separate read function for it.

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Vineeth Vijayan
2e89722ef0 zdev: make site specific udev-rule for ccw
The udev-rules must be modified to make it site-specific. The site
specific part of the rule should be executed only on the sites where the
devices belong. Change the generic udev rule to support the site-specific
udev-rule.

During boot, the current site-id is read from the LOADPARM which is
located at /sys/firmware/ipl. The zdev_id command reads this LOADPARM
and prints the SITE_ID based on the value. This SITE_ID is the
current site where the udev-rule is executing. Based on this assumption,
the rule is divided in to multiple blocks where each site block is executed
only for the corresponding sites.

The rule executes based on the value read from the LOADPARM.
1. When the LOADPARM specifies a site-id and if the current device has
   an associated configuration settings, it will be used.
2. When the LOADPARM specifies a site, and the current device does not
   have any associated configuration set, the udev rule uses the
   fallback configuration settings.
3. If the device does not have a fallback-configuration settings or any
   site-specific settings, no configurations will be used.

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Vineeth Vijayan
c8ad5f57d0 zdev: modify zdev_id to read the site_id from loadparm
The currently active site can be found from the loadparm attribute which
is located at /sys/firmware/ipl/loadparm. Read the value of loadparm and
extract the site_id.

The loadparm is an 8 byte alphanumerical IPL parameter. The content of
loadparm can be of different forms to indicate different boot menu
options, which are used by Linux for selecting the respective boot menu
entries. To indicate the site-id, loadparm adds a 'S' character. Where,
the following character after 'S' indicates either the site-id or
indivcation to derive the site-id from SSID.
For example,
If the loadparm value is Sn,'n' is the integer which could be one of the
valid site_ids from 0 to 9; i.e when booted on site-1, loadparm value will
be S1.
If loadparm value is "SS", zdev_id extracts the site_id from the SSID of
the current ipl device. For ccw and zfcp devices, the current ipl device-id
can be found at /sys/firmware/ipl/device.

In any case, if the loadparm contains invalid value, or empty, the
site_id will be default to the common-site.

After the first invocation of the zdev_id from udev-rule, the site-id
information is stored in /run/zdev_id.env file. This will reduce the
number of further invocation of zdev_id from within udev-rules.

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Vineeth Vijayan
d2317943c0 zdev: add site specific states for devices
Currently zdev supports the configuration and maintenance of one single
persistent device state. With the introduction of sites, zdev should be
able to store, configure and maintaine NUM_SITES number of states in
the persistent configuration. This patch modifies the struct device and
adds a new site_specific device_state array, which stores the
persistent configuration for all the available sites.

Total number of available sites are configured with NUM_SITES. Where,
10 site-specific configurations and 1 common configuration.

1. during read, all site data is always read and update the
   site_specific[] array.
2. dev->persistent is a copy of dev->site_specific[global_site_id]
3. modifications are only done on dev->persistent, and during write
   dev->persistent overlays dev->site_specific[global_site_id]

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Vineeth Vijayan
198c9fc052 zdev: onboard --site option on zdev commands
In some high-availability setups, root and boot disks of a Linux
installation are copied to remote sites that can take over execution
of a Linux workload in case of an outage of the original site.
A site in this context is an execution environment such as an LPAR
or z/VM guest.

Each site may provide a different set of devices, or require different
parameters to be applied per device. chzdev supports site-specific
device configuration for up to 10 sites. Each site is identified by
a number in the range 0 to 9. You can provide a separate set of persistent
device configuration for each site. The IPL Load parameter value specified
during boot determines the currently active site. Only the device
configuration of the active site is applied during boot and when new
devices become available. A common configuration can be provided that is
applied when no site-specific configuration is available for a device in
the active site.

User can use the --site parameter to configure devices for a specific
site only. Configuration actions without a site parameter apply to the
common configuration.

During the boot, the active site configuration is chosed based on the
IPL LOADPARM variable. If the LOADPARM contains no valid site-id (0 to 9),
the fallback-site id will be used. The fallback-site-id can also be
configured with the zdev tools by not specifying the --site parameter.

Some of the new chzdev/lszdev commands with site-parameter can be as
follows

1. chzdev -ep f001 --site 3

This command is used to configure the device f001 for the site 3. During
boot, if the LOADPARM value is S3, this device configuration will be
used.

2. lszdev --site 3

This command lists all the devices which are configured for site 3.

3. chzdev -ep f001

Above command does not have a --site parameter. This device settings
will be used for the following conditions

1. When the loadparm specifies a site, (e.g S3), and the device does not
   have an associated config-set, zdev uses fallback config set.
2. When the loadparm does not specify any site information, then the
   fallback config set will be used.

When the loadparm specifies a site, and the device does not have an
associated config set, nor a fallback site, nothing is configured for this
device.

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Marc Hartmayer
b3551f50a8 Provide codespell configuration
While at it, add a list with words to ignore. This suppresses the following codespell finding:

$ codespell libcpumf/libcpumf_cpuset.c
libcpumf/libcpumf_cpuset.c:15: parm ==> param, pram, parma
libcpumf/libcpumf_cpuset.c:17: parm ==> param, pram, parma

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Marc Hartmayer
4ff360e621 Provide CheckPatch configuration
Provie a CheckPatch configuration file and mention it in the coding style
guidelines (this feature was introduced with CheckPatch version 0.32 ~11 years
ago).

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Marc Hartmayer
87e8fa18cf CODINGSTYLE.md: mention EditorConfig configuration
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Marc Hartmayer
4bd135c3c7 Add project-wide .clang-format
Add a .clang-format configuration and mention it in the coding guidelines.

Usage example:

 $ clang-format -i **/*.[ch]

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-11-03 17:38:53 +01:00
Matthew Rosato
f69350e8bd ap_tools/ap-check: reject start for control domains without usage
When configuring a vfio-ap device, specifying only control domains
without any usage domains results in a useless configuration in that
both adapters and usage domains are required to make cryptographic
resources available to the guest.  Without that, the control domains
are useless.  While the kernel allows this, let's reject this
combination with a message.

Suggested-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:22 +02:00
Peter Oberparleiter
5768d55a08 zipl/boot: add secure boot trailer
This patch enhances the zipl stage3 loader image adding a trailer as
required for secure boot by future firmware versions.

Note: with the change in this patch the padding via objcopy command line
options is replaced by padding via linker script directives with the
same effect.

Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Holger Dengler
538264a8cd lszcrypt: fix parameter handling for device list
lszcrypt allows the explicit definition of a list of devices. Continue
the parameter processing if multiple devices are specified.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Reviewed-By: Harald Freudenberger <freude@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
7f09f0e4ad zdump: refactor pt_load_add
In an upcoming patch the refactored function `pt_load_add` is reused. While at
it, add a wrap-around check to `pt_load_add`, replace `g.opts.device` access
with `fh->path` (this makes this function easier testable) and improve the
documentation.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
e36084d7f2 libpv/pvattest: consolidate __PV_BIT and BIT macros
Consolidate `__PV_BIT` and `BIT` macros.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
bd18166a21 zdump: opts: declare print_usage_exit in header file
Remove `static` attribute from `print_usage_exit` and declare it in the header
file `opts.h`. The function will be reused in a later patch.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
a6f2c38891 zdump: constify dfi_vmcoreinfo_get
Caller of `dfi_vmcoreinfo_get` must not modify the returned value, therefore
return a `const char *` value for `dfi_vmcoreinfo_get`.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
029a3f8f52 zdump: add guarded storage support for ELF input and output format
Add guarded storage registers support for the ELF input and the ELF output
format. See `man 2 s390_guarded_storage` for details about guarded storage.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
dc87aef335 zdump: dfo_elf: replace HDR_PER_CPU_SIZE with get_max_note_size_per_cpu
The maximum size of all supported ELF note entries for a CPU can be 0x4a4 bytes
and not 0x4a0. Use a function for the calculation so it's easier to maintain.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-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
Marc Hartmayer
d712806b39 lib/zt_common.h: add macro for determining field size
The macro `sizeof_field` is used in the next patch.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
2734724432 zdump: df_elf: add multiple ELF section helper
Preparation for upcoming patches.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
6176509076 zdump: df_elf: refactor check_elf_hdr
The function will be reused by upcoming patches.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
1780efae07 zdump: df_elf: ehdr_is_elf_object: add ELF version check
Currently, only the ELF version `1` is defined by the ELF specification. See
`man 5 elf` for details. Therefore of course, we do only support this version.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
922e8cbb2f zdump: since we create ELF version 1 files use this value explicitly
The value of `EV_CURRENT` might change. The ELF specification says: "The value
of EV_CURRENT, though given as 1 above, will change as necessary to reflect the
current version number." [1]

[1] https://refspecs.linuxfoundation.org/elf/elf.pdf

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
eef0dd4fa4 zdump: df_elf: add missing endianness check
A s390x ELF file must use big-endian encoding.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
f93f437f8b zdump: df_elf: read_elf_hdr: return Elf64_Ehdr struct
This makes the API of `read_elf_hdr` consistent with `read_elf_phdrs`.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
4e6d43e2ac zdump: dfi_elf: refactor nt_* functions
The functions are refactored so the `struct zg_fh` value is now passed as
argument to the `nt_*` functions instead of accessing the global variable `g.fh`
from within of the functions. This makes the functions reusable and easier to
test. While at it, improve the documentation of `nt_read`.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
922d29ee49 zdump: dfi_elf_init: introduce temporary variable
Introduce variable `phdrs` and shrink the scope of `phdr`. This removes
duplicated code `&phdr[i]` and makes the code easier to read. While at it,
constify the parameter of `pt_notes_add`.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
25475bdf42 zdump: read_elf_phdrs: fix -Wconversion issue
`ehdr->e_phoff` has the type `Elf64_Off` and this maps to `uint64_t`, but `off_t` is signed. Let's
add a check for this.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
09c413b1be zdump: read_elf_phdrs: handle no program header case
Handle the case where no program headers are defined (see `man 5 elf`).

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
8944c2f60d zdump: dfi_elf: refactor read_elf_(ehdr|phdrs)
Make the function unit testable and easier to reuse - no functional change.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-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
Marc Hartmayer
ff3fe4bf43 zdump: constify struct zg_fh *fh parameter in the zg file APIs
Constify the `struct zg_fh *fh` parameter in the file APIS, e.g. `zg_path()`.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Joern Siglen
5fe2e19277 dbginfo.sh: fix man page
add missing option in man page

Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Joern Siglen
b8cf861aea dbginfo.sh: add kuberentes (OCP) data collection
generalize the collection step name from "docker" to "container host"

initial version of adding data collection for OCP.

all log file content might be too much for most installations

Reviewed-by: Alexander Klein <alkl@de.ibm.com>
Reviewed-by: Mario Held <mario.held@de.ibm.com>
Reviewed-by: Mike Storzer <mstorzer@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Joern Siglen
6ca3576dbf dbginfo.sh: fix typo
typo in KVM section

Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
7ea425db5e pvattest/exchange_format.c: use proper endianess conversion macro for hdr->version
GUINT32_TO_BE and GUINT32_FROM_BE do exactly the same in case of glib2, just the
naming differs. However, at this point the conversion is from be to system
endianness therefore `GUINT32_FROM_BE` is the proper macro.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
330ddb7adb libpv: add copied parameter to pv_gbytes_memcpy and adapt pvattest
It's often useful to know how much data was actually copied, therefore let's
introduce an nullable parameter `@copied` to `pv_gbytes_memcpy`.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
d69b9fab4a pvattest: build_attestation_v1_ioctl: make the code more robust
...by adding a compile time assertion about the buffer size. While at it, report
the actual user data size in case of an error.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
4e02dc8751 pvattest: uvio.c: remove endianness handling
The endianness handling was only partially implemented for uvio.c. Let's remove
it since doesn't make much sense here, because the IOCTL must be build on the
same system where they're actually executed.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Joern Siglen
0c8be405ce dbginfo.sh: fix vmcp buffer resizing
the buffer sizing did not work any longer
add explaining comments and rework the variable names for claritiy

refering commit f7cc14753cc9d930af804e2ac3ce108a12145db6

Reported-by: Mike Storzer <MSTORZER@de.ibm.com>
Reviewed-by: Mario Held <mario.held@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Steffen Eiden
24677dc561 libpv: remove wrong parameter attribute
`error` is actually used therefore let's remove the `G_GNUC_UNUSED` attribute.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Steffen Eiden
7e7c38755d libpv: improve error reporting
Use `PV_CERT_ERROR` error domain whenever useful. Currently, it's only used
internally in libpv and therefore there is no problem in changing it.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
229cd6d194 zdump: don't modify passed program header in pt_load_add()
There should be no problem with this change since the changed value was never
used. Therefore, let's remove the assignment and declare the parameter as const
to prevent such a behavior in the future.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-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
Marc Hartmayer
776e5d41d7 zdump: dfi_elf: factor out some ELF functionalities
This makes them reuseable and testable.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-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
Marc Hartmayer
8d7e8a87b5 zdump: df_elf: move function documentation to function declarations
It's more common to have the function documentation next to the function
declarations.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Acked-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-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
Marc Hartmayer
e24d8c936c zdump: move NOTE_NAME_* definitions to df_elf.h
This allows the reuse in other source files.

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
Marc Hartmayer
39b6c4a273 zdump: introduce ELF_NOTE_ROUNDUP macro
Introduce and use `ELF_NOTE_ROUNDUP` macro.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-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
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
7d855acd07 util_arch: Fix max HSA size for Z16 machine
The machine types are not strictly increasing anymore since Z16, therefore,
we cannot use numerical comparison to find out the correct HSA size
of a machine.

Fixes: 2515832469 ("util_arch: Add IBM z16 as known machine")
Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:26:34 +02:00
Marc Hartmayer
f961a2bf90 common.mak: fix compiler command line for afl-clang
`afl-clang` requires a white space between a option name and the option value.
Therefore let's fix this for `-xc` by adding a white space.

How to reproduce:

$ make -C zdump CC=afl-clang-fast LINK=afl-clang-fast

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:26:34 +02:00
Joern Siglen
9f93af614f dbginfo.sh: ensure compatibility with /bin/dash
some versions of /bin/dash do interpreted our commands different, which
causes a variable failure and termination of the script.

e.g. a new line char "\n" will split the cmd_type to a multiple line variable
not working with the followup commands. adding the head command does avoid
multiline variables now.

Problem found in Ubuntu 20.4 and some older Ubuntu versions

Reviewed-by: Mario Held <mario.held@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:26:34 +02:00
Joern Siglen
d529ba07d3 dbginfo.sh: update message on not beeing root
add a hint that dbginfo.sh -c can check some basic stuff even as non-root

Reviewed-by: Mario Held <mario.held@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:26:34 +02:00
Joern Siglen
0fffb05d01 dbginfo.sh: add tool check for testing
move tool checking to the top of the script and add the output to
the check function (-c) for easy verifivation and testing

Reviewed-by: Mario Held <mario.held@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:26:34 +02:00
Joern Siglen
92b8409207 dbginfo.sh: ensure type commands compatible with dash
All debian distors use the dash shell as default, where type is not supprting "-t" parameter

Remove of "-t" where not important and change type check not using -t

Reviewed-by: Mario Held <mario.held@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:26:34 +02:00
Steffen Maier
bc3134ba5a dbginfo.sh: collect config and logs of Dandified YUM (DNF)
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:26:31 +02:00
Steffen Maier
c7f55a182f dbginfo.sh: collect YaST log files of successful installation
Cf. /usr/sbin/save_y2logs of yast2-logs.rpm.

Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:26:28 +02:00
Steffen Maier
5078be45b8 dbginfo.sh: collect generated unattended installation kickstart files
anaconda-7.2.91-1
c4249bbe06 (diff-86b9da41b3aa75b36055aa04a2effff06c0decadc7b80f6efd8a513fe265746eR49)
("merge dispatch to HEAD")

anaconda-24.7-1
1c4af3b432
("Include original kickstart in /root/original-ks.cfg (#1227939)")
https://github.com/rhinstaller/anaconda/pull/447
https://bugzilla.redhat.com/show_bug.cgi?id=1227939

Cf. https://anaconda-installer.readthedocs.io/en/latest/boot-options.html#inst-nosave
from anaconda-25.2-1
b7d699a547
("Make it possible to skip saving of kickstarts and logs (#1285519)")

Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:26:24 +02:00
Steffen Maier
2418ea93fc dbginfo.sh: collect anaconda log files of successful installation
Since anaconda-15.2-1
7e2754473e (diff-3b740ff14364c6d399b86ef7a6ca044e17b334ab351988600058d9af0e7fa0bc)

See also /usr/libexec/anaconda/log-capture of anaconda-core.rpm.

Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:26:21 +02:00
Steffen Maier
13cac5de44 dbginfo.sh: also collect "local" multipath-tools config
Easier to read for a first glimpse than the (still required) full config.

$ man multipathd
       list|show config local
              Show the currently used configuration like show config, but lim‐
              iting  the  devices  section  to those devices that are actually
              present in the system.

Works as of multipath-tools 0.7.8 commit
c23924dc74ee ("multipathd: implement "show config local"")

Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:17:31 +02:00
Joern Siglen
b6687925cc dbginfo.sh: cleanup outdated comment and formating
remove spaces and outdated comment line

Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:17:31 +02:00
Marc Hartmayer
7ee51182bf zdump: fix memory leak of path
==660622== 385 bytes in 7 blocks are definitely lost in loss record 30 of 37
==660622==    at 0x484417C: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-s390x-linux.so)
==660622==    by 0x4E93BD7: strdup (strdup.c:42)
==660622==    by 0x11249F: zg_strdup (zg.c:115)
==660622==    by 0x11249F: zg_open (zg.c:164)
==660622==    by 0x114FBF: dfi_dump_open (dfi.c:750)
==660622==    by 0x114FBF: dfi_init (dfi.c:772)
==660622==    by 0x111465: do_copy (zgetdump.c:192)
==660622==    by 0x111465: main (zgetdump.c:216)

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:17:31 +02:00
Siglen
ec3e5b4a75 dbginfo.sh: save dbginfo.sh version to dbginfo.log
we do miss a simple way to see the dbginfo.sh version used by the
customer for the debug generation. saving the version now to dbginfo.log

Reported-by: Mike Storzer <MSTORZER@de.ibm.com>
Reviewed-by: Mario Held <mario.held@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:17:31 +02:00
Jan Höppner
0b5aac3d79 Prepare for next release
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-08-18 15:33:16 +02:00
245 changed files with 10063 additions and 4506 deletions

12
.checkpatch.conf Normal file
View File

@@ -0,0 +1,12 @@
--max-line-length=100
--strict
# Not Linux therefore don't expect a Linux tree
--no-tree
# Ignore the following
--ignore PREFER_KERNEL_TYPES
--ignore EXECUTE_PERMISSIONS
--ignore FILE_PATH_CHANGES
--ignore NEW_TYPEDEFS
--ignore SPDX_LICENSE_TAG

134
.clang-format Normal file
View File

@@ -0,0 +1,134 @@
# Must be compatible with clang-format 14
---
AccessModifierOffset: "-4"
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: AcrossComments
AlignConsecutiveMacros: AcrossComments
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BitFieldColonSpacing: Both
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: BeforeComma
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: false
ColumnLimit: "100"
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: "8"
ContinuationIndentWidth: "8"
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
# git grep -h '^#define [^[:space:]]*\(for_each\|iterate\)[^[:space:]]*(' \
# | sed "s,^#define \([^[:space:]]*\(for_each\|iterate\)[^[:space:]]*\)(.*$, - '\1'," \
# | LC_ALL=C sort -u
ForEachMacros:
- "dfi_cpu_iterate"
- "dfi_mem_chunk_iterate"
- "dfo_chunk_iterate"
- "for_each_rb_entry"
- "ns_range_for_each"
- "sd_cpu_item_enable_iterate"
- "sd_cpu_item_iterate"
- "sd_cpu_iterate"
- "sd_cpu_type_iterate"
- "sd_sys_item_enable_iterate"
- "sd_sys_item_iterate"
- "sd_sys_iterate"
- "table_col_iterate"
- "table_iterate_mark_keys"
- "util_list_iterate"
- "util_list_iterate_safe"
- "util_opt_iterate"
- "util_rec_iterate"
IncludeBlocks: Preserve
# Leave imports as is
IncludeCategories:
- Regex: .*
Priority: 1
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: "8"
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: "1"
NamespaceIndentation: Inner
PackConstructorInitializers: CurrentLine
PenaltyBreakAssignment: "10"
PenaltyBreakBeforeFirstCallParameter: "30"
PenaltyBreakComment: "10"
PenaltyBreakFirstLessLess: "0"
PenaltyBreakString: "10"
PenaltyExcessCharacter: "100"
PenaltyReturnTypeOnItsOwnLine: "60"
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: "1"
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros:
- "STATIC_ASSERT"
TabWidth: "8"
TypenameMacros:
- "STACK_OF"
UseTab: Always
WhitespaceSensitiveMacros:
- "STRINGIFY"

5
.codespellrc Normal file
View File

@@ -0,0 +1,5 @@
[codespell]
ignore-words-list = parm,parms
skip = ''
count = ''
quiet-level = 3

8
.gitignore vendored
View File

@@ -9,6 +9,9 @@
tags
TAGS
# clangd cache (https://clangd.llvm.org/design/indexing#backgroundindex)
.cache/
# Ignore coverage data
*.gcda
*.gcno
@@ -78,7 +81,6 @@ systemd/ttyrun-getty@.service
tape390/tape390_crypt
tape390/tape390_display
tunedasd/src/tunedasd
vmconvert/vmconvert
vmcp/vmcp
vmur/vmur
zconf/chp/chchp
@@ -95,6 +97,9 @@ zdev/src/chzdev_usage.c
zdev/src/lszdev
zdev/src/lszdev_usage.c
zdsfs/zdsfs
zdump/.check_dep_fuse
zdump/.check_dep_zgetdump
zdump/.detect_openssl.dep.c
zdump/zgetdump
zfcpdump/10-zfcpdump.install
zfcpdump/cpioinit
@@ -107,6 +112,7 @@ ziomon/ziorep_traffic
ziomon/ziorep_utilization
zipl/boot/*.bin
zipl/boot/*.exec
zipl/boot/.loaders
zipl/boot/data.h
zipl/src/chreipl_helper.device-mapper
zdev/src/zdev_id

View File

@@ -21,6 +21,7 @@ List of all individuals having contributed content to s390-tools
- Colin Walters
- Dan Horak
- Dan Horák
- Daniel S. Haischt
- Despina Papadopoulou
- Dimitri John Ledkov
- Eberhard Pasch
@@ -89,6 +90,7 @@ List of all individuals having contributed content to s390-tools
- Mikhail Zaslonko
- Nikita Dubrovskii
- Niklas Schnelle
- Nikolay Gueorguiev
- Peter Oberparleiter
- Peter Tiedemann
- Philipp Kern

View File

@@ -1,6 +1,112 @@
Release history for s390-tools (MIT version)
--------------------------------------------
* __v2.28.0 (2023-07-11)__
For Linux kernel version: 6.4
Changes of existing tools:
- chzcrypt: Support for SE AP pass-through support
- genprotimg: Add support for non-s390x architectures
- lszcrypt: Support for SE AP pass-through support
- zdev: Add support for autoquiesce related sysfs attributes
Bug Fixes:
- ap_tools/ap-check: Handle missing 'matrix' and 'control_domains' attrs
- ap_tools/ap-check: Hold ap config file lock over get attributes
- s390-tools: Fix build for ppc64le
- zdev: Add missing label in the udev-rules
- zdev: Add proper value input for the ZDEV_SITE_ID key
- zdev: Use rename-file to avoid any symlinks created
- zipl/dump: fix ngdump dracut helper script
* __v2.27.0 (2023-05-30)__
For Linux kernel version: 6.3
Changes of existing tools:
- s390-tools cross-compile and non-s390x support:
- `pkg-config` is now mandatory for the build process
- Add `PKG_CONFIG` Makefile variable to select pkg-config program;
default `pkg-config` or `$(CROSS_COMPILE)pkg-config` if
`CROSS_COMPILE` is set
- Rename Makefile variable `ARCH` to `HOST_ARCH`. `HOST_ARCH` is the
architecture that will run the produced (executable) objects
- Add the Makefile variable `BUILD_ARCH`. `BUILD_ARCH` is the
architecture of the build system. For each Makefile variable like
`CC`, `LINK`, `CPP`, ... there is a suffixed version of it - e.g.
`CC_FOR_BUILD`. This is useful for cross compiling, and this naming
convention is very similar to the Meson convention (see
https://mesonbuild.com/Reference-tables.html#environment-variables-per-machine).
- Limit build targets for non-s390x architectures (pvattest)
- dasdfmt: Fall back to full format if space release fails
- dbginfo.sh: Add nstat for network and SNMP stats
- dbginfo.sh: Rework crypto data collection
- hyptop: Show thread util by default
- zipl: Add support for list-directed IPL dump from ECKD DASD
Bug Fixes:
- lszcrypt: Fix argument parsing
- zdev/dracut: Fix out-of-memory (OOM) situations in the kdump crashkernel environment
- ziomon/ziorep_config: Fix for SCSI devices of type disk without block dev
- pvextract-hdr: Fix parsing issues on little-endian systems
* __v2.26.0 (2023-02-14)__
For Linux kernel version: 6.2
Remove tools / libraries:
- Remove vmconvert and libvmdump in favor of vmdump file support in zdump
Changes of existing tools:
- ipl_tools: Add support for list-directed IPL from ECKD DASD
- lszcrypt: Display hardware filtering support capability
- vmur: Remove option -c for dump file conversion (See zdump changes)
- zdev: Add zfcp ber_stop parameter handling
- zdump: Add vmdump dfi for vmdump format to elf format
- zkey: Support EP11 host library version
Bug Fixes:
- zipl: Move dump parmline processing and verification
- zipl/genprotimg: Various build improvements
* __v2.25.0 (2022-12-08)__
For Linux kernel version: 6.1
Changes of existing tools:
- ap_tools: Use new mdevctl installation location
- lsdasd/tunedasd/zdev: Add support to handle copy pair relations presented by the DASD driver
- zdev: Add --shell command line switch to generate output suitable for shell environments
- zipl: Add List-Directed IPL from ECKD DASD to support secure boot
Bug Fixes:
- ipl_tools: Fix chreipl node for NVMes with CONFIG_NVME_MULTIPATH
- libdasd: Fix bug that prevented positive ioctl return codes
* __v2.24.0 (2022-11-09)__
For Linux kernel version: 6.0
Add new tools / libraries:
- Provide config files for checkpatch, codespell, and clang-format
Changes of existing tools:
- dbginfo.sh: Collect log from various distro tools (YaST, DNF, Anaconda)
- dbginfo.sh: add Kubernetes data collection
- libutil: Introduce util_lockfile
- zdev: Add site-aware device configuration
- zdump: Add support to read Protected Virtualization dumps
- zipl/boot: Add secure boot trailer
Bug Fixes:
- ap_tools/ap-check: Reject start for control domains without usage
- cpumf/lshwc: Fix incremented counter output
- cpumf/pai: Fix core dump when summary flag set
- dbginfo.sh: Ensure compatibility with /bin/dash shell
- dbginfo.sh: Save dbginfo.sh version to dbginfo.log
- zipl/src/zipl_helper.device-mapper: Fix bug in error path
* __v2.23.0 (2022-08-18)__
For Linux kernel version: 5.19
@@ -24,7 +130,6 @@ Release history for s390-tools (MIT version)
- pvattest: Fix dependency checking
- zipl: Fix segmentation fault when no parmline is provided
* __v2.22.0 (2022-06-20)__
For Linux kernel version: 5.18

View File

@@ -4,8 +4,10 @@ Coding guidelines for s390-tools
For s390-tools the preferred language is C. We provide libraries, e.g.
[`libutil`](libutil) that should be used by all tools if possible.
The coding style is based on the Linux [kernel guidelines]. Therefore, use
the [checkpatch] tool for verification before you submit a patch.
The coding style is based on the Linux [kernel guidelines]. Therefore, use the
[checkpatch] tool for verification before you submit a patch. s390-tools
provides a CheckPatch configuration for this - see
[`.checkpatch.conf`](.checkpatch.conf).
[kernel guidelines]: https://www.kernel.org/doc/html/latest/process/coding-style.html
[checkpatch]: https://github.com/torvalds/linux/blob/master/scripts/checkpatch.pl
@@ -17,6 +19,39 @@ This package started in 2001 and has a long "tradition" - therefore, older tools
might not follow all recommendations. Note that when changing existing code,
consistency could have priority over applying rules.
Automatic Code Formatting
-------------------------
> **NOTE:** clang-format is a helpful tool but please don't use it blindly!
s390-tools provides a ClangFormat (https://clang.llvm.org/docs/ClangFormat.html)
configuration file - see [`.clang-format`](.clang-format). It can be used to
format your C/C++ code automatically.
Clang-format can format a single file or multiple files at once. For example, to
format `main.c` in place, run the following command in a terminal:
```bash
clang-format -i main.c
```
In order to format only your current staged changes use the clang-format git
plugin:
```bash
git clang-format --staged
```
See also `git clang-format -h`.
Automatic Editor Configuration
------------------------------
s390-tools provides a EditorConfig (https://editorconfig.org/) configuration
file - see [`.editorconfig`](.editorconfig). EditorConfig defines coding style
rules (such as indentation size, use of tabs, etc.) and is supported by most
common editors natively or via plugins.
Standard abbreviations
----------------------

View File

@@ -1,5 +1,3 @@
ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
# Include common definitions
include common.mak
@@ -8,15 +6,21 @@ include common.mak
# LIBS: Libraries that can have a dependency to base libraries
# TOOLS: Tools that can have a dependency to base libraries or libraries
#
ifeq ($(HOST_ARCH),s390x)
BASELIB_DIRS = libutil libseckey
LIB_DIRS = libvtoc libzds libdasd libvmdump libccw libvmcp libekmfweb \
LIB_DIRS = libvtoc libzds libdasd libccw libvmcp libekmfweb \
libkmipclient libcpumf libap libpv
TOOL_DIRS = zipl zdump fdasd dasdfmt dasdview tunedasd \
tape390 osasnmpd qetharp ip_watcher qethconf scripts zconf \
vmconvert vmcp man mon_tools dasdinfo vmur cpuplugd ipl_tools \
vmcp man mon_tools dasdinfo vmur cpuplugd ipl_tools \
ziomon iucvterm hyptop cmsfs-fuse qethqoat zfcpdump zdsfs cpumf \
systemd hmcdrvfs cpacfstats zdev dump2tar zkey netboot etc zpcictl \
genprotimg lsstp hsci hsavmcore chreipl-fcp-mpath ap_tools pvattest
else
BASELIB_DIRS =
LIB_DIRS = libpv
TOOL_DIRS = genprotimg pvattest
endif
SUB_DIRS = $(BASELIB_DIRS) $(LIB_DIRS) $(TOOL_DIRS)
@@ -49,15 +53,15 @@ endif
$(TOOL_DIRS): $(LIB_DIRS)
$(foreach goal,$(MAKECMDGOALS), \
$(MAKE) -C $@ TOPDIR=$(TOPDIR) ARCH=$(ARCH) $(goal) ;)
$(MAKE) -C $@ TOPDIR=$(TOPDIR) HOST_ARCH=$(HOST_ARCH) $(goal) ;)
.PHONY: $(TOOL_DIRS)
$(LIB_DIRS): $(BASELIB_DIRS)
$(foreach goal,$(MAKECMDGOALS), \
$(MAKE) -C $@ TOPDIR=$(TOPDIR) ARCH=$(ARCH) $(goal) ;)
$(MAKE) -C $@ TOPDIR=$(TOPDIR) HOST_ARCH=$(HOST_ARCH) $(goal) ;)
.PHONY: $(LIB_DIRS)
$(BASELIB_DIRS):
$(foreach goal,$(MAKECMDGOALS), \
$(MAKE) -C $@ TOPDIR=$(TOPDIR) ARCH=$(ARCH) $(goal) ;)
$(MAKE) -C $@ TOPDIR=$(TOPDIR) HOST_ARCH=$(HOST_ARCH) $(goal) ;)
.PHONY: $(BASELIB_DIRS)

View File

@@ -60,6 +60,7 @@ Package contents
* zgetdump:
Retrieve system dumps from either tapes, DASDs, SCSIs or NVMes.
Decrypt Protected Virtualization (PV) dumps from IBM Secure Execution guests.
* qetharp:
Read and flush the ARP cache on OSA Express network cards.
@@ -97,11 +98,6 @@ Package contents
* tunedasd:
Adjust tunable parameters on DASD devices.
* vmconvert:
Convert system dumps created by the z/VM VMDUMP command into dumps with
LKCD format. These LKCD dumps can then be analyzed with the dump analysis
tool lcrash.
* vmcp:
Send commands from Linux as a z/VM guest to the z/VM control program (CP).
Call vmcp with the CP command as an argument. The response of z/VM is
@@ -309,16 +305,15 @@ build options:
| net-snmp | `HAVE_SNMP` | osasnmpd |
| glibc-static | `HAVE_LIBC_STATIC` | zfcpdump |
| openssl | `HAVE_OPENSSL` | genprotimg, zkey, libekmfweb, |
| | | libkmipclient, pvattest |
| | | libkmipclient, pvattest, zgetdump |
| cryptsetup | `HAVE_CRYPTSETUP2` | zkey-cryptsetup |
| json-c | `HAVE_JSONC` | zkey-cryptsetup, libekmfweb, |
| | | libkmipclient |
| glib2 | `HAVE_GLIB2` | genprotimg, pvattest |
| glib2 | `HAVE_GLIB2` | genprotimg, pvattest, zgetdump |
| libcurl | `HAVE_LIBCURL` | genprotimg, libekmfweb, libkmipclient,|
| | | pvattest |
| libxml2 | `HAVE_LIBXML2` | libkmipclient |
| systemd | `HAVE_SYSTEMD` | hsavmcore |
| liblockfile | `HAVE_LOCKFILE` | ap-check |
| libudev | `HAVE_LIBUDEV` | cpacfstatsd |
This table lists additional build or install options:
@@ -330,8 +325,8 @@ This table lists additional build or install options:
| initramfs-tools | `HAVE_INITRAMFS` | zdev, zipl |
| | `ZDEV_ALWAYS_UPDATE_INITRD` | zdev |
The s390-tools build process uses "pkg-config" if available and hard-coded
compiler and linker options otherwise.
The s390-tools build process uses "pkg-config" and therefore it must be
available.
Build and runtime requirements for specific tools
-------------------------------------------------
@@ -376,6 +371,13 @@ the different tools are provided:
- Packages: blktrace, multipath-tools, sg3-utils
- Tools: rsync, tar, lsscsi
* zgetdump
For building zgetdump you need OpenSSL version 1.1.0 or newer
installed (openssl-devel.rpm). Also required is glib2
(glib2-devel.rpm) and zlib (zlib-devel.rpm).
Tip: you may skip the zgetdump build by adding
`HAVE_OPENSSL=0`, `HAVE_GLIB2=0`, or `HAVE_ZLIB=0`.
* cmsfs-fuse/zdsfs/hmcdrvfs/zgetdump:
The tools cmsfs-fuse, zdsfs, hmcdrvfs, and zgetdump depend on FUSE.
FUSE is provided by installing the fuse3 and libfuse3 packages and by a
@@ -505,8 +507,7 @@ the different tools are provided:
GNU awk for the build process.
* ap-check:
For building the ap-check mdevctl callout utility you need liblockfile
version 1.14 or newer installed (liblockfile-devel.rpm). Also required is
json-c version 0.13 or newer (json-c-devel.rpm).
Tip: you may skip ap-check build by adding `HAVE_LOCKFILE=0` or `HAVE_JSONC=0`
to the make invocation.
For building the ap-check mdevctl callout utility you need json-c version
0.13 or newer (json-c-devel.rpm).
Tip: you may skip ap-check build by adding `HAVE_JSONC=0` to the make
invocation.

View File

@@ -1,27 +1,23 @@
include ../common.mak
MDEVCTL_DIR = /etc/mdevctl.d/
MDEVCTL_SCRIPTS = /etc/mdevctl.d/scripts.d/
MDEVCTL_CALLOUTS = /etc/mdevctl.d/scripts.d/callouts/
MDEVCTL_DIR = /usr/lib/mdevctl/
MDEVCTL_SCRIPTS = /usr/lib/mdevctl/scripts.d/
MDEVCTL_CALLOUTS = /usr/lib/mdevctl/scripts.d/callouts/
MDEVCTL_DEP_DIR = /etc/mdevctl.d/
MDEVCTL_DEP_SCRIPTS = /etc/mdevctl.d/scripts.d/
MDEVCTL_DEP_CALLOUTS = /etc/mdevctl.d/scripts.d/callouts/
libs = $(rootdir)/libap/libap.a \
$(rootdir)/libutil/libutil.a
ifeq (${HAVE_LOCKFILE},0)
all:
$(SKIP) HAVE_LOCKFILE=0
install:
$(SKIP) HAVE_LOCKFILE=0
else ifeq (${HAVE_JSONC},0)
ifeq (${HAVE_JSONC},0)
all:
$(SKIP) HAVE_JSONC=0
install:
$(SKIP) HAVE_JSONC=0
else
LDLIBS += -llockfile -ljson-c
LDLIBS += -ljson-c
all: ap-check
@@ -30,15 +26,26 @@ ap-check: ap-check.o $(libs)
install: all
@if [ ! -d $(DESTDIR)$(MDEVCTL_CALLOUTS) ]; then \
mkdir -p $(DESTDIR)$(MDEVCTL_CALLOUTS); \
chown $(OWNER).$(GROUP) $(DESTDIR)$(MDEVCTL_DIR); \
chown $(OWNER).$(GROUP) $(DESTDIR)$(MDEVCTL_SCRIPTS); \
chown $(OWNER).$(GROUP) $(DESTDIR)$(MDEVCTL_CALLOUTS); \
chown $(OWNER):$(GROUP) $(DESTDIR)$(MDEVCTL_DIR); \
chown $(OWNER):$(GROUP) $(DESTDIR)$(MDEVCTL_SCRIPTS); \
chown $(OWNER):$(GROUP) $(DESTDIR)$(MDEVCTL_CALLOUTS); \
chmod 755 $(DESTDIR)$(MDEVCTL_DIR); \
chmod 755 $(DESTDIR)$(MDEVCTL_SCRIPTS); \
chmod 755 $(DESTDIR)$(MDEVCTL_CALLOUTS); \
fi; \
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 755 ap-check \
$(DESTDIR)$(MDEVCTL_CALLOUTS)
@if [ ! -d $(DESTDIR)$(MDEVCTL_DEP_CALLOUTS) ]; then \
mkdir -p $(DESTDIR)$(MDEVCTL_DEP_CALLOUTS); \
chown $(OWNER):$(GROUP) $(DESTDIR)$(MDEVCTL_DEP_DIR); \
chown $(OWNER):$(GROUP) $(DESTDIR)$(MDEVCTL_DEP_SCRIPTS); \
chown $(OWNER):$(GROUP) $(DESTDIR)$(MDEVCTL_DEP_CALLOUTS); \
chmod 755 $(DESTDIR)$(MDEVCTL_DEP_DIR); \
chmod 755 $(DESTDIR)$(MDEVCTL_DEP_SCRIPTS); \
chmod 755 $(DESTDIR)$(MDEVCTL_DEP_CALLOUTS); \
fi; \
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 755 ap-check.sh \
$(DESTDIR)$(MDEVCTL_DEP_CALLOUTS)
endif
clean:

View File

@@ -133,7 +133,7 @@ static void ap_check_cleanup(struct ap_check_anchor *anc)
if (anc->dev)
vfio_ap_device_free(anc->dev);
if (anc->cleanup_lock)
ap_release_lock();
ap_release_lock_callout();
}
/*
@@ -434,14 +434,23 @@ static int check_other_mdev_sysfs_cb(const char *path, const char *filename,
strcasecmp(filename, cbdata->uuid) == 0)
return 0;
dev2 = vfio_ap_device_new();
/*
* Read the 'matrix' attribute to get the list of queues for the active
* device. If the sysfs attribute is unreadable, assume the device is
* being destroyed and skip it.
*/
matrix_path = path_get_vfio_ap_attr(filename, "matrix");
f = fopen(matrix_path, "r");
free(matrix_path);
if (!f)
return 0;
dev2 = vfio_ap_device_new();
while (fgets(buf, sizeof(buf), f))
vfio_ap_parse_matrix(dev2, buf);
vfio_ap_sort_matrix_results(dev2);
fclose(f);
free(matrix_path);
/* Look for conflicts between target device and this device */
rc = find_apqn_conflicts(filename, dev->adapters, dev->domains,
@@ -685,6 +694,14 @@ static int ap_check_handle_start(struct ap_check_anchor *anc)
goto out;
}
/* Ensure device with control domains also has usage domains */
if (util_list_is_empty(anc->dev->domains) &&
!util_list_is_empty(anc->dev->controls)) {
fprintf(stderr, "At least one usage domain must be specified\n");
rc = -1;
goto out;
}
/* Check against all other active vfio-ap devices */
rc = check_other_mdevs_sysfs(anc);
/* Check against the system sysfs values for apmask/aqmask */
@@ -767,7 +784,7 @@ out:
*/
static int ap_check_handle_post(void)
{
return ap_release_lock();
return ap_release_lock_callout();
}
/* For the specified device, print the attributes to stdout in JSON format */
@@ -779,21 +796,39 @@ static int ap_check_handle_get_attributes(struct ap_check_anchor *anc)
char buf[80];
char *path;
FILE *f;
int rc;
rc = ap_get_lock_callout();
if (rc) {
fprintf(stderr, "Failed to acquire configuration lock %d\n", rc);
return -1;
}
anc->cleanup_lock = true;
/*
* Read the 'matrix' and 'control_domains' attributes to get the
* current attributes of the active device. If either of these sysfs
* attributes is unreadable, assume the device is being destroyed
* and return nothing.
*/
path = path_get_vfio_ap_attr(anc->uuid, "matrix");
f = fopen(path, "r");
free(path);
if (!f)
return 0;
while (fgets(buf, sizeof(buf), f))
vfio_ap_parse_matrix(dev, buf);
vfio_ap_sort_matrix_results(dev);
fclose(f);
free(path);
path = path_get_vfio_ap_attr(anc->uuid, "control_domains");
f = fopen(path, "r");
free(path);
if (!f)
return 0;
while (fgets(buf, sizeof(buf), f))
vfio_ap_parse_control(dev, buf);
fclose(f);
free(path);
printf("[{");

15
ap_tools/ap-check.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/bin/sh
#
# ap-check.sh - Wrapper script for 'ap-check' binary
#
# mdevctl has deprecated the /etc/mdevctl.d/scripts.d/callouts/ location in
# newer releases. This wrapper ensures that mdevctl 1.2.0 and older can
# still access 'ap-check' for now, and will be removed at a later time.
#
# Copyright 2022 IBM Corp.
#
# s390-tools is free software; you can redistribute it and/or modify
# it under the terms of the MIT license. See LICENSE for details.
#
[ -e /usr/lib/mdevctl/scripts.d/callouts/ap-check ] && /usr/lib/mdevctl/scripts.d/callouts/ap-check "$@"

View File

@@ -74,7 +74,7 @@ ALL_PANDOCFLAGS = --preserve-tabs --tab-stop=8 --strip-comments \
-M date="$(shell date +'%Y-%m-%d')" \
$(PANDOCFLAGS)
$(eval $(call cmd_define, PANDOC," PANDOC ",pandoc))
$(eval $(call cmd_define_and_export, PANDOC," PANDOC ",pandoc))
%.html : ALL_PANDOCFLAGS += -t html
%.html : %.md

View File

@@ -22,13 +22,8 @@ check_dep:
all: check_dep cmsfs-fuse
ifneq ($(shell sh -c 'command -v pkg-config'),)
FUSE_CFLAGS = $(shell pkg-config --silence-errors --cflags fuse3)
FUSE_LDLIBS = $(shell pkg-config --silence-errors --libs fuse3)
else
FUSE_CFLAGS = -D_FILE_OFFSET_BITS=64 -I/usr/include/fuse3
FUSE_LDLIBS = -lfuse3
endif
FUSE_CFLAGS = $(shell $(PKG_CONFIG) --silence-errors --cflags fuse3)
FUSE_LDLIBS = $(shell $(PKG_CONFIG) --silence-errors --libs fuse3)
ALL_CFLAGS += -DHAVE_SETXATTR $(FUSE_CFLAGS)
LDLIBS += $(FUSE_LDLIBS) -lm

View File

@@ -1,25 +1,47 @@
ifndef $(COMMON_INCLUDED)
COMMON_INCLUDED = true
COMMON_INCLUDED ?= false
V ?= 0
W ?= 0
G ?= 0
C ?= 0
D ?= 0
ASAN ?= 0
ENABLE_WERROR ?= 0
OPT_FLAGS ?=
MAKECMDGOALS ?=
ifeq ($(COMMON_INCLUDED),false)
COMMON_INCLUDED := true
# 'BUILD_ARCH' is the architecture of the machine where the build takes place
BUILD_ARCH := $(shell uname -m | sed -e 's/i.86/i386/' -e 's/sun4u/sparc64/' -e 's/arm.*/arm/' -e 's/sa110/arm/')
# 'HOST_ARCH' is the architecture of the machine that will run the compiled output
HOST_ARCH ?= $(BUILD_ARCH)
# The `*clean` targets are mutually exclusive to all other targets
ifneq ($(filter %clean,$(MAKECMDGOALS)),)
ifneq ($(MAKECMDGOALS),$(filter %clean,$(MAKECMDGOALS)))
$(error The *clean targets are mutually exclusive to all other targets)
endif
endif
# Global definitions
# The variable "DISTRELEASE" should be overwritten in rpm spec files with:
# "make DISTRELEASE=%{release}" and "make install DISTRELEASE=%{release}"
VERSION = 2
RELEASE = 23
RELEASE = 28
PATCHLEVEL = 0
DISTRELEASE = build-$(shell date +%Y%m%d)
S390_TOOLS_RELEASE = $(VERSION).$(RELEASE).$(PATCHLEVEL)-$(DISTRELEASE)
export S390_TOOLS_RELEASE
reldir = $(subst $(shell cd -P $(dir $(filter %common.mak,$(MAKEFILE_LIST))); \
pwd)/,,$(CURDIR))
reldir = $(subst $(realpath $(dir $(filter %common.mak,$(MAKEFILE_LIST))))/,,$(CURDIR))
rootdir= $(dir $(filter %common.mak,$(MAKEFILE_LIST)))
export S390_TEST_LIB_PATH=$(rootdir)/s390-tools-testsuite/lib
#
# For cross compiles specify CROSS_COMPILE= on the commandline:
# For cross compiles specify HOST_ARCH= and CROSS_COMPILE= on the commandline:
#
# $ make CROSS_COMPILE="s390x-5.1.0-"
# $ make HOST_ARCH=s390x CROSS_COMPILE="s390x-linux-gnu-"
#
CROSS_COMPILE =
@@ -29,8 +51,10 @@ CROSS_COMPILE =
#
# $ make CC=gcc-4.8
#
# The "cmd_define" macro wraps the command definition so that the commands
# can be user supplied and are still pretty-printed for the build process.
# The "cmd_define_and_export" macro wraps the command definition so that
# the commands can be user supplied and are still pretty-printed for the
# build process. In addition, the command variable gets exported so it
# can be used by sub-makes.
#
# The macro is called with the following parameters:
#
@@ -40,13 +64,14 @@ CROSS_COMPILE =
#
# The Example below...
#
# $(eval $(call cmd_define, CC," CC ",$(CROSS_COMPILE)gcc))
# $(eval $(call cmd_define_and_export, CC," CC ",$(CROSS_COMPILE)gcc))
#
# ... produces the following code:
#
# CC = $(CROSS_COMPILE)gcc
# CC_SILENT := $(CC)
# override CC = $(call echocmd," CC ",/$@)$(CC_SILENT)
# export CC
#
# The "strip" make function is used for the first parameter to allow blanks,
# which improves readability.
@@ -58,21 +83,47 @@ define cmd_define
override $(strip $(1)) = $$(call echocmd,$(2),/$$@)$$($(strip $(1))_SILENT)
endef
$(eval $(call cmd_define, AS," AS ",$(CROSS_COMPILE)as))
$(eval $(call cmd_define, CC," CC ",$(CROSS_COMPILE)gcc))
$(eval $(call cmd_define, HOSTCC," HOSTCC ",gcc))
$(eval $(call cmd_define, CXX," CXX ",$(CROSS_COMPILE)g++))
$(eval $(call cmd_define, CPP," CPP ",$(CROSS_COMPILE)gcc -E))
$(eval $(call cmd_define, AR," AR ",$(CROSS_COMPILE)ar))
$(eval $(call cmd_define, NM," NM ",$(CROSS_COMPILE)nm))
$(eval $(call cmd_define, STRIP," STRIP ",$(CROSS_COMPILE)strip))
$(eval $(call cmd_define,OBJCOPY," OBJCOPY ",$(CROSS_COMPILE)objcopy))
$(eval $(call cmd_define,OBJDUMP," OBJDUMP ",$(CROSS_COMPILE)objdump))
define cmd_define_and_export
$(call cmd_define,$(1),$(2),$(3))
export $(strip $(1))
endef
define define_toolchain_variables
$(eval $(call cmd_define_and_export, AS$(1)," AS$(1) ",$(2)as))
$(eval $(call cmd_define_and_export, CC$(1)," CC$(1) ",$(2)gcc))
$(eval $(call cmd_define_and_export, LINK$(1)," LINK$(1) ",$$(CC$(1))))
$(eval $(call cmd_define_and_export, CXX$(1)," CXX$(1) ",$(2)g++))
$(eval $(call cmd_define_and_export, LINKXX$(1)," LINKXX$(1) ",$$(CXX$(1))))
$(eval $(call cmd_define_and_export, CPP$(1)," CPP$(1) ",$(2)gcc -E))
$(eval $(call cmd_define_and_export, AR$(1)," AR$(1) ",$(2)ar))
$(eval $(call cmd_define_and_export, NM$(1)," NM$(1) ",$(2)nm))
$(eval $(call cmd_define_and_export, STRIP$(1)," STRIP$(1) ",$(2)strip))
$(eval $(call cmd_define_and_export,OBJCOPY$(1)," OBJCOPY$(1) ",$(2)objcopy))
$(eval $(call cmd_define_and_export,OBJDUMP$(1)," OBJDUMP$(1) ",$(2)objdump))
$(eval PKG_CONFIG$(1) = pkg-config)
$(eval export PKG_CONFIG$(1))
endef
# If the host architecture is not the same as the build architecture
# 'CROSS_COMPILE=...' is always required (except for the '*clean' targets).
ifneq ($(HOST_ARCH),$(BUILD_ARCH))
ifeq ($(CROSS_COMPILE),)
# `make clean` and similar must always work!
ifeq ($(filter %clean,$(MAKECMDGOALS)),)
$(error Please specify CROSS_COMPILE=... and try it again!)
endif
endif
endif
$(call define_toolchain_variables,_FOR_BUILD,)
$(call define_toolchain_variables,,$(CROSS_COMPILE))
$(eval $(call cmd_define,RUNTEST," RUNTEST ",$(S390_TEST_LIB_PATH)/s390_runtest))
$(eval $(call cmd_define, CAT," CAT ",cat))
$(eval $(call cmd_define, SED," SED ",sed))
$(eval $(call cmd_define, GZIP," GZIP ",gzip))
$(eval $(call cmd_define, MV," MV ",mv))
$(eval $(call cmd_define, PERLC," PERLC ",perl -c))
CHECK = sparse
CHECK_SILENT := $(CHECK)
@@ -81,8 +132,6 @@ CHECKTOOL = $(call echocmd," CHECK ",/$@)$(CHECK_SILENT)
SKIP = echo " SKIP $(call reldir) due to"
INSTALL = install
LINK = $(CC)
LINKXX = $(CXX)
CP = cp
ifneq ("${V}","1")
MAKEFLAGS += --quiet
@@ -101,6 +150,10 @@ else
DEFAULT_CFLAGS += -O3
endif
ifeq ("${ENABLE_WERROR}", "1")
DEFAULT_CFLAGS += -Werror
endif
DEFAULT_CPPFLAGS = -D_GNU_SOURCE
DEFAULT_LDFLAGS = -rdynamic
@@ -109,6 +162,11 @@ ifeq ("${ASAN}","1")
DEFAULT_LDFLAGS += -fsanitize=address
endif
DEFAULT_PERLCFLAGS =
ifeq ("${W}","1")
DEFAULT_PERLCFLAGS += -w
endif
#
# Check for header prerequisite
#
@@ -120,7 +178,7 @@ endif
define check_header_prereq
$(shell printf "#include <%s>\n int main(void) {return 0;}\n" $1 | \
( $(CC) $(filter-out --coverage, $(ALL_CFLAGS)) $(ALL_CPPFLAGS) \
$2 -o /dev/null -xc - ) >/dev/null 2>&1 && echo -n yes)
$2 -o /dev/null -x c - ) >/dev/null 2>&1 && echo -n yes)
endef
#
@@ -133,7 +191,7 @@ endef
# $5: Additional compiler & linker options (optional)
#
check_dep=\
printf "\#include <%s>\n int main(void) {return 0;}\n" $2 | ( $(CC) $(filter-out --coverage, $(ALL_CFLAGS)) $(ALL_CPPFLAGS) $5 -o /dev/null -xc - ) > /dev/null 2>&1; \
printf "\#include <%s>\n int main(void) {return 0;}\n" $2 | ( $(CC) $(filter-out --coverage, $(ALL_CFLAGS)) $(ALL_CPPFLAGS) $5 -o /dev/null -x c - ) > /dev/null 2>&1; \
if [ $$? != 0 ]; \
then \
printf " REQCHK %s (%s)\n" $1 $2; \
@@ -145,6 +203,20 @@ then \
exit 1; \
fi
#
# Test for linker option
#
# $1: Linker option
#
# Returns the linker option if available and nothing otherwise
#
define test_linker_flag
$(shell printf ".globl _start\n_start:\nnop\n" | \
( $(LINK) "-Wl,$1" -o /dev/null -nostdlib -x assembler -) >/dev/null 2>&1 && printf -- '-Wl,%s' "$1")
endef
NO_WARN_RWX_SEGMENTS_LDFLAGS := $(call test_linker_flag,"--no-warn-rwx-segments")
#
# Support alternate install root
#
@@ -221,10 +293,10 @@ ZFCPDUMP_INITRD = zfcpdump-initrd
ZFCPDUMP_FLAVOR = zfcpdump
export ZFCPDUMP_DIR ZFCPDUMP_IMAGE ZFCPDUMP_INITRD ZFCPDUMP_FLAVOR
CFLAGS ?= $(DEFAULT_CFLAGS) $(OPT_FLAGS)
HOSTCFLAGS ?= $(DEFAULT_CFLAGS) $(OPT_FLAGS)
CPPFLAGS ?= $(DEFAULT_CPPFLAGS)
LDFLAGS ?= $(DEFAULT_LDFLAGS)
CFLAGS ?= $(DEFAULT_CFLAGS) $(OPT_FLAGS)
CFLAGS_FOR_BUILD ?= $(DEFAULT_CFLAGS) $(OPT_FLAGS)
CPPFLAGS ?= $(DEFAULT_CPPFLAGS)
LDFLAGS ?= $(DEFAULT_LDFLAGS)
ALL_CFLAGS = -DS390_TOOLS_RELEASE=$(S390_TOOLS_RELEASE) \
-DS390_TOOLS_LIBDIR=$(TOOLS_LIBDIR) \
@@ -242,6 +314,8 @@ ALL_CXXFLAGS = -DS390_TOOLS_RELEASE=$(S390_TOOLS_RELEASE) \
ALL_CPPFLAGS = -I $(rootdir)include $(CPPFLAGS)
ALL_LDFLAGS = $(LDFLAGS)
ALL_PERLCFLAGS = $(DEFAULT_PERLCFLAGS)
# make G=1
# Compile tools so that gcov can be used to collect code coverage data.
# See the gcov man page for details.
@@ -250,7 +324,7 @@ ALL_CFLAGS := $(filter-out -O%,$(ALL_CFLAGS)) --coverage
ALL_CXXFLAGS := $(filter-out -O%,$(ALL_CXXFLAGS)) --coverage
ALL_LDFLAGS += --coverage
endif
export AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP INSTALL CFLAGS CXXFLAGS \
export INSTALL CFLAGS CXXFLAGS \
LDFLAGS CPPFLAGS ALL_CFLAGS ALL_CXXFLAGS ALL_LDFLAGS ALL_CPPFLAGS
ifneq ($(shell $(CC_SILENT) -dumpspecs 2>/dev/null | grep -e '[^f]no-pie'),)
@@ -261,7 +335,7 @@ else
NO_PIE_LDFLAGS :=
endif
# Overwrite implicite makefile rules for having nice compile output
# Overwrite implicit makefile rules for having nice compile output
%.o: %.c
ifeq ("${C}","1")
$(CHECKTOOL) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c $< -o $@
@@ -288,12 +362,13 @@ help:
@echo ' clean Delete all generated files'
@echo ''
@echo 'OPTIONS'
@echo ' D=1 Build with debugging option "-Og"'
@echo ' C=1 Build with check tool defined with "CHECK=" (default=sparse)'
@echo ' G=1 Build with gcov to collect code coverage data'
@echo ' V=1 Generate verbose build output'
@echo ' W=1 Build with higher warning level'
@echo ' ASAN=1 Build with address sanitizer'
@echo ' D=1 Build with debugging option "-Og"'
@echo ' C=1 Build with check tool defined with "CHECK=" (default=sparse)'
@echo ' G=1 Build with gcov to collect code coverage data'
@echo ' V=1 Generate verbose build output'
@echo ' W=1 Build with higher warning level'
@echo ' ASAN=1 Build with address sanitizer'
@echo ' ENABLE_WERROR=1 Build with -Werror'
@echo ''
@echo 'EXAMPLES'
@echo ' # make clean all D=1 W=1 -j'
@@ -364,10 +439,6 @@ $(rootdir)/libzds/libzds.a: $(rootdir)/libzds
$(MAKE) -C $(rootdir)/libzds/ libzds.a
.PHONY: $(rootdir)/libzds
$(rootdir)/libvmdump/libvmdump.a: $(rootdir)/libvmdump
$(MAKE) -C $(rootdir)/libvmdump/ libvmdump.a
.PHONY: $(rootdir)/libvmdump
$(rootdir)/libvmcp/libvmcp.a: $(rootdir)/libvmcp
$(MAKE) -C $(rootdir)/libvmcp/ libvmcp.a
.PHONY: $(rootdir)/libvmcp
@@ -396,8 +467,8 @@ $(rootdir)/libpv/libpv.a: $(rootdir)/libpv
$(MAKE) -C $(rootdir)/libpv libpv.a
.PHONY: $(rootdir)/libpv
$(rootdir)/zipl/boot/data.o:
$(MAKE) -C $(rootdir)/zipl/boot/ data.o
$(rootdir)/zipl/boot/.loaders:
$(MAKE) -C $(rootdir)/zipl/boot/ .loaders
install_dirs:
for dir in $(INSTDIRS); do \
@@ -422,4 +493,3 @@ clean_dep:
clean: clean_echo clean_gcov clean_dep
endif

View File

@@ -323,7 +323,7 @@ static void json_print_virtual_counter_answer(int s, int ctr,
pai_str[paictr], space, paictr + 1);
if (paistate < 0) {
printf("\"error\":%d}", paistate);
/* Protocol does not send furter counters. */
/* Protocol does not send further counters. */
return;
}
printf("\"value\":%"PRIu64"}", paivalue);
@@ -420,7 +420,7 @@ static void json_print_answer(int s, int ctr, int state, uint64_t value)
printf("\"value\":%"PRIu64"}", value);
}
}
int eprint(const char *format, ...)
{

View File

@@ -45,9 +45,8 @@ counter set authorization control" checkbox.
- The daemon requires root privileges to interact with the performance
ioctls of the kernel.
CPU hotplug is not recognized by the daemon. When adding or removing a CPU,
restart the daemon to ensure correct summing of the per-CPU performance
counters.
CPU hotplug is recognized by the daemon. When adding or removing a CPU,
the daemon ensures correct summing of the per-CPU performance counters.
The starting daemon first checks for any stale pid file
\%/run/cpacfstatsd.pid. If this file exists, and the process ID in the

View File

@@ -97,7 +97,7 @@ static int do_send_pai(int s, int user)
{
int ctr, state, i, maxctr, rc = 0;
uint64_t value;
if (user) {
ctr = PAI_USER;
maxctr = NUM_PAI_USER;
@@ -252,20 +252,26 @@ static int do_print(int s, enum ctr_e ctr)
}
static int become_daemon(void)
static int become_daemon(int *startup_pipe)
{
int child_initialized = 0, fd;
int pipefds[2];
FILE *f;
int fd;
/* syslog */
openlog("cpacfstatsd", 0, LOG_DAEMON);
if (pipe(pipefds) != 0) {
eprint("pipe() failed, errno=%d [%s]\n", errno, strerror(errno));
return -1;
}
/*
* fork and terminate parent
* Reasons:
* - opens new command line prompt
* - the child process is guaranteed not to be the process group leader
* nessecarry for setsid.
* necessary for setsid.
*/
switch (fork()) {
@@ -276,9 +282,23 @@ static int become_daemon(void)
case 0: /* child */
break;
default: /* parent */
(void)close(pipefds[1]);
if (read(pipefds[0], &child_initialized, sizeof(child_initialized)) !=
sizeof(child_initialized)) {
eprint("Couldn't read from PIPE, errno=%d [%s]\n", errno, strerror(errno));
(void)close(pipefds[0]);
_exit(EXIT_FAILURE);
}
(void)close(pipefds[0]);
if (!child_initialized)
_exit(EXIT_FAILURE);
_exit(0);
}
/* Executed within the child context only */
(void)close(pipefds[0]);
*startup_pipe = pipefds[1];
if (chdir("/") != 0) {
eprint("Chdir('/') failed, errno=%d [%s]\n",
errno, strerror(errno));
@@ -418,7 +438,7 @@ int eprint(const char *format, ...)
int main(int argc, char *argv[])
{
int rc, sfd, foreground = 0;
int rc, sfd, foreground = 0, startup_pipe = -1, initialized = 0;
struct sigaction act;
if (argc > 1) {
@@ -454,27 +474,27 @@ int main(int argc, char *argv[])
}
if (check_pidfile() != 0) {
eprint("Stalled pid file or daemon allready running, terminating\n");
eprint("Stalled pid file or daemon already running, terminating\n");
return EXIT_FAILURE;
}
if (!foreground) {
if (become_daemon() != 0) {
if (become_daemon(&startup_pipe) != 0) {
eprint("Couldn't daemonize\n");
return EXIT_FAILURE;
goto error;
}
}
if (perf_init() != 0) {
eprint("Couldn't initialize perf lib\n");
return EXIT_FAILURE;
goto error;
}
atexit(perf_close);
sfd = open_socket(SERVER);
if (sfd < 0) {
eprint("Couldn't initialize server socket\n");
return EXIT_FAILURE;
goto error;
}
atexit(remove_sock);
@@ -484,17 +504,27 @@ int main(int argc, char *argv[])
if (sigaction(SIGINT, &act, 0) != 0) {
eprint("Couldn't establish signal handler for SIGINT, errno=%d [%s]\n",
errno, strerror(errno));
return EXIT_FAILURE;
goto error;
}
if (sigaction(SIGTERM, &act, 0) != 0) {
eprint("Couldn't establish signal handler for SIGTERM, errno=%d [%s]\n",
errno, strerror(errno));
return EXIT_FAILURE;
goto error;
}
/* Ignore SIGPIPE such that we see EPIPE as return from write. */
signal(SIGPIPE, SIG_IGN);
eprint("Running\n");
initialized = 1;
/* `startup_pipe` has been initialized, so we know we are
* running in daemon mode. Let's write to the pipe so that the
* parent knows that the initialization is complete.
*/
if (startup_pipe != -1 &&
write(startup_pipe, &initialized, sizeof(initialized)) != sizeof(initialized))
goto error;
(void)close(startup_pipe);
startup_pipe = -1;
while (!stopsig) {
enum ctr_e ctr;
@@ -507,13 +537,14 @@ int main(int argc, char *argv[])
continue;
eprint("Accept() failure, errno=%d [%s]\n",
errno, strerror(errno));
return EXIT_FAILURE;
goto error;
}
rc = recv_query(s, &ctr, &cmd);
if (rc != 0) {
eprint("Recv_query() failed, ignoring\n");
goto cleanup;
close(s);
continue;
}
if (cmd == ENABLE)
@@ -527,11 +558,9 @@ int main(int argc, char *argv[])
else {
eprint("Received unknown command %d, ignoring\n",
(int) cmd);
goto cleanup;
close(s);
continue;
}
cleanup:
close(s);
}
if (stopsig == SIGTERM)
@@ -543,4 +572,14 @@ cleanup:
remove_pidfile();
return 0;
error:
if (startup_pipe != -1) {
/* Notify the parent process that there was an error */
if (write(startup_pipe, &initialized, sizeof(initialized)) != sizeof(initialized))
eprint("Couldn't write to PIPE, errno=%d [%s]\n", errno, strerror(errno));
(void)close(startup_pipe);
}
return EXIT_FAILURE;
}

View File

@@ -371,7 +371,7 @@ static int addallcpus(void)
errno, strerror(errno));
return -1;
}
while (!feof(fp)) {
/* scan all intervals of online cpus */
scanned = fscanf(fp, "%u-%u", &start, &end);
@@ -414,7 +414,7 @@ static void *hotplughandler(void *UNUSED(unused))
struct udev *hotplug;
struct udev_monitor *monitor;
struct pollfd item;
hotplug = udev_new();
if (!hotplug) {
eprint("Failed to create hotplug device\n");
@@ -496,10 +496,8 @@ int perf_init(void)
num -= 2;
}
if (num == 0) {
if (num == 0)
eprint("No crypto counters supported!\n");
return -1;
}
if (perf_load_counter_data())
return -1;

View File

@@ -276,9 +276,7 @@ static bool check_setpossible(void)
if (!get_cpus(CPUS_KERNELMAX, cpubuf, sizeof(cpubuf)))
return false;
max_possible_cpus = getnumber(cpubuf, '\0') + 1;
check = calloc(max_possible_cpus, sizeof(*check));
if (!check)
err(EXIT_FAILURE, "Maximum CPUs %u", max_possible_cpus);
check = util_zalloc(max_possible_cpus * sizeof(*check));
if (!get_cpus(CPUS_POSSIBLE, cpubuf, sizeof(cpubuf))) {
free(check);
return false;
@@ -356,6 +354,8 @@ static void line(char *header)
putchar(',');
printf("%ld", ctrname[i].total);
comma = true;
ctrname[i].total = 0;
ctrname[i].hitcnt = false;
}
putchar('\n');
}
@@ -446,7 +446,7 @@ static bool add_countervalue(size_t idx, unsigned int cpu, unsigned long value)
ctrname[idx].ccv = calloc(max_possible_cpus,
sizeof(unsigned long));
if (ctrname[idx].ccv)
ctrname[idx].ccv[cpu] += value;
ctrname[idx].ccv[cpu] = value;
ctrname[idx].total += value;
ctrname[idx].hitcnt = true;
return true;
@@ -458,10 +458,8 @@ static int test_read(struct s390_hwctr_read *read)
size_t offset = 0;
/* Clear previous hit counters */
for (unsigned int i = 0; i < max_possible_cpus; ++i) {
check[i].sets_hit = 0;
for (unsigned int i = 0; i < max_possible_cpus; ++i)
check[i].cpu_hit = false;
}
/* Iterate over all CPUs */
for (unsigned int i = 0; i < read->no_cpus; ++i) {
@@ -533,13 +531,8 @@ static int do_read(int ioctlfd)
struct s390_hwctr_read *read;
int rc;
if (!ioctlbuffer) {
ioctlbuffer = malloc(ioctlbuffer_len);
if (!ioctlbuffer) {
warn("ioctl S390_HWCTR_START");
return -ENOMEM;
}
}
if (!ioctlbuffer)
ioctlbuffer = util_malloc(ioctlbuffer_len);
read = (struct s390_hwctr_read *)ioctlbuffer;
rc = ioctl(ioctlfd, S390_HWCTR_READ, read);
if (!rc)

View File

@@ -88,12 +88,6 @@ Include the MT_Diagnostic counter set.
Include the problem counter set.
.IP a
Include all known counter sets (default).
.SH "Concurrency with perf tool"
The \*c tool and the linux
.B perf
tool use the same hardware and cannot be used concurrently.
Both tools print an error message and abort when they
detect this situation.
.SH "EXAMPLES"
The first example enables the basic and problem counter sets on CPU 0 and 1.
Two read operations are performed and a summary line is printed for each

View File

@@ -426,7 +426,7 @@ static const char *evt_selector(struct perf_event_attr *pa)
static void evt_show(__u64 evtnum, const char *evtsel, struct pai_event_out *ev)
{
if (summary) {
if (ev->type == PERF_RECORD_SAMPLE)
if (ev->type == PERF_RECORD_SAMPLE && ev->raw)
evtraw_show(evtnum, ev->raw);
return;
}

View File

@@ -118,12 +118,17 @@ Specify the \fImode\fR to be used to format the device. Valid modes are:
.IP full
Format the entire disk with the specified blocksize. (default)
.IP quick
Format the first two tracks and write label and partition information. Only use
this option if you are sure that the target DASD already contains a regular
Format the first two tracks and write label and partition information. Use this
option only if you are sure that the target DASD already contains a regular
format with the specified blocksize. A blocksize can optionally be specified
using \fB-b\fR (\fB--blocksize\fR).
.br
For thin-provisioned DASD ESE volumes this is the default mode.
For thin-provisioned DASD ESE volumes, quick is the default mode. A full space
release then precedes the formatting step. If this space release fails, dasdfmt
falls back to a full-format mode. Formatting stops if the space release fails
and quick mode was specified explicitly using \fB-M\fR. Specify the
\fB--no-discard\fR option to omit the space release.
.IP expand
Format all unformatted tracks at the end of the target DASD. This mode assumes
that tracks at the beginning of the DASD volume have already been correctly

View File

@@ -1230,7 +1230,7 @@ static void dasdfmt_find_start(unsigned int cylinders, unsigned int heads,
format_params->start_unit = first;
}
static void dasdfmt_release_space(void)
static int dasdfmt_release_space(void)
{
format_data_t r = {
.start_unit = 0,
@@ -1240,12 +1240,21 @@ static void dasdfmt_release_space(void)
int err = 0;
if (!g.ese || g.no_discard)
return;
return 0;
printf("Releasing space for the entire device...\n");
err = dasd_release_space(g.dev_node, &r);
if (err)
/*
* Warn or Error on failing RAS depending on QUICK mode set explicitly or automatically
*/
if (err && !g.mode_specified) {
warnx("Could not release space. Falling back to full format.");
return 1;
} else if (err && g.mode_specified) {
error("Could not release space: %s", strerror(err));
}
return 0;
}
static void dasdfmt_prepare_and_format(unsigned int cylinders, unsigned int heads,
@@ -1445,8 +1454,12 @@ static void do_format_dasd(volume_label_t *vlabel, format_data_t *p,
dasdfmt_prepare_and_format(cylinders, heads, p);
break;
case QUICK:
dasdfmt_release_space();
dasdfmt_quick_format(cylinders, heads, p);
if (dasdfmt_release_space()) {
p->stop_unit = (cylinders * heads) - 1;
dasdfmt_prepare_and_format(cylinders, heads, p);
} else {
dasdfmt_quick_format(cylinders, heads, p);
}
break;
case EXPAND:
dasdfmt_expand_format(cylinders, heads, p);

View File

@@ -16,13 +16,8 @@ check_dep:
BUILDTARGET = check_dep
ifneq ($(shell sh -c 'command -v pkg-config'),)
CURL_CFLAGS = $(shell pkg-config --silence-errors --cflags libcurl)
CURL_LDLIBS = $(shell pkg-config --silence-errors --libs libcurl)
else
CURL_CFLAGS = -I/usr/include/s390x-linux-gnu/curl
CURL_LDLIBS = -lcurl
endif # shell
CURL_CFLAGS = $(shell $(PKG_CONFIG) --silence-errors --cflags libcurl)
CURL_LDLIBS = $(shell $(PKG_CONFIG) --silence-errors --libs libcurl)
endif # HAVE_CURL

View File

@@ -12,8 +12,6 @@ all: all-recursive
install: all install-recursive
$(INSTALL) -d -m 755 "$(PKGDATADIR)"
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 644 boot/stage3a.bin "$(PKGDATADIR)"
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 644 boot/stage3b_reloc.bin "$(PKGDATADIR)"
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 755 samples/check_hostkeydoc "$(PKGDATADIR)"
clean: clean-recursive

View File

@@ -1,8 +1,12 @@
# Common definitions
include ../../common.mak
FILES := stage3a.bin stage3b.bin stage3b_reloc.bin
ifeq ($(HOST_ARCH),s390x)
ZIPL_DIR := $(rootdir)/zipl
ZIPL_BOOT_DIR := $(ZIPL_DIR)/boot
PKGDATADIR := $(DESTDIR)$(TOOLS_DATADIR)/genprotimg
INCLUDE_PATHS := $(ZIPL_BOOT_DIR) $(ZIPL_DIR)/include $(rootdir)/include
INCLUDE_PARMS := $(addprefix -I,$(INCLUDE_PATHS))
@@ -15,11 +19,9 @@ ALL_CFLAGS := $(NO_PIE_CFLAGS) -Os -g \
-fno-delete-null-pointer-checks -fno-stack-protector \
-fexec-charset=IBM1047 -m64 -mpacked-stack \
-mstack-size=4096 -mstack-guard=128 -msoft-float \
-Wall -Wformat-security -Wextra -Werror \
-Wall -Wformat-security -Wextra \
-Wno-array-bounds
FILES := stage3a.bin stage3b.bin stage3b_reloc.bin
ZIPL_SRCS_C := libc.c ebcdic.c ebcdic_conv.c sclp.c
ZIPL_SRCS_ASM := entry.S
@@ -27,9 +29,6 @@ ZIPL_OBJS_C := $(ZIPL_SRCS_C:%.c=%.o)
ZIPL_OBJS_ASM := $(ZIPL_SRCS_ASM:%.S=%.o)
ZIPL_OBJS := $(ZIPL_OBJS_C) $(ZIPL_OBJS_ASM)
all: $(FILES)
# Prevent make from using some default rules...
%: %.S
@@ -69,29 +68,37 @@ endif
stage3b_reloc.o: stage3b.bin
stage3a.elf: head.o stage3a_init.o stage3a.o stage3a.lds $(ZIPL_OBJS)
stage3b.elf: head.o stage3b.o stage3b.lds $(ZIPL_OBJS)
stage3b_reloc.elf:
stage3a.elf: head.o stage3a_init.o $(ZIPL_OBJS)
stage3b.elf: head.o $(ZIPL_OBJS)
%.elf: %.o
case $* in \
stage3a) SFLAGS="-Wl,-T,stage3a.lds";; \
stage3b) SFLAGS="-Wl,-T,stage3b.lds";; \
stage3b_reloc) SFLAGS="-Wl,-estage3b_reloc_start,-Ttext,0";; \
esac; \
$(LINK) $$SFLAGS $(NO_PIE_LDFLAGS) -m64 -static -nostdlib $(filter %.o, $^) -o $@
%.elf: %.lds %.o
$(LINK) $(NO_PIE_LDFLAGS) $(NO_WARN_RWX_SEGMENTS_LDFLAGS) -Wl,-T,$< -Wl,--build-id=none -m64 -static -nostdlib $(filter %.o, $^) -o $@
@chmod a-x $@
%.bin: %.elf
$(OBJCOPY) -O binary \
--only-section=.text* \
--only-section=.ex_table* \
--only-section=.fixup* \
--only-section=.data* \
--only-section=.rodata* \
$< $@
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
@chmod a-x $@
install: stage3a.bin stage3b_reloc.bin
$(INSTALL) -d -m 755 "$(PKGDATADIR)"
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 644 stage3a.bin "$(PKGDATADIR)"
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 644 stage3b_reloc.bin "$(PKGDATADIR)"
else
# Don't generate the dependency files (see `common.mak` for the
# `-include $(dependencies_c)` statement).
.PHONY: $(dependencies_c)
$(FILES):
echo " SKIP $@ due to HOST_ARCH != s390x"
install:
echo " SKIP Bootloader installation due to HOST_ARCH != s390x"
endif
.DEFAULT_GOAL := all
all: $(FILES)
clean:
rm -f *.o *.elf *.bin *.map .*.d *.lds

View File

@@ -29,3 +29,8 @@ _start:
brasl %r14, initialize
.Lstack: .long STACK_ADDRESS + STACK_SIZE - STACK_FRAME_OVERHEAD
.previous
/* The code doesn't require an executable stack */
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif

View File

@@ -11,7 +11,6 @@
#include "stage3a.h"
#include "lib/zt_common.h"
#include "boot/s390.h"
#include "boot/ipl.h"
#include "sclp.h"
#include "error.h"

View File

@@ -23,8 +23,6 @@ ENTRY(_init)
SECTIONS
{
. = 0x0;
. = HEAP_ADDRESS;
__heap_start = .;
.heap : {
@@ -46,7 +44,7 @@ SECTIONS
. = STAGE3A_INIT_ENTRY;
__text_init_start = .;
.text : {
stage3a_init.o(.text.init)
*(.text.init)
__text_init_stop = ABSOLUTE(.);
/* Text size of text_init must be smaller than 'PARMAREA - IMAGE_ENTRY',
* otherwise the text data could be overwritten by the original zipl stage3
@@ -56,8 +54,8 @@ SECTIONS
. = 0x1000;
ASSERT(ABSOLUTE(.) == STAGE3A_ENTRY,
"Text section doesn't conform to the described memory layout");
head.o(.text.start)
*(.text)
*(.text.start)
*(.text .text.*)
}
.ex_table ALIGN(16) : {
@@ -74,7 +72,7 @@ SECTIONS
.rodata ALIGN(16) : {
*(.rodata)
*(.rodata.*)
*(.rodata*)
}
.data ALIGN(16) : {
@@ -90,14 +88,10 @@ SECTIONS
ASSERT(ABSOLUTE(.) < 0x13000, "Data section doesn't conform to the described memory layout");
}
/* List this explicitly as otherwise .note.gnu.build-id will be
* put at 0x0 */
.notes : {
*(.note.*)
}
/* Sections to be discarded */
/DISCARD/ : {
*(.eh_frame)
*(.interp)
*(.note.GNU-stack)
}
}

View File

@@ -26,3 +26,8 @@ _init:
br %r1
.Lstage3a_entry: .long STAGE3A_ENTRY
.previous
/* The code doesn't require an executable stack */
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif

View File

@@ -11,7 +11,7 @@
#include "stage3b.h"
#include "lib/zt_common.h"
#include "boot/s390.h"
#include "boot/psw.h"
#include "boot/linux_layout.h"
#include "boot/loaders_layout.h"
#include "sclp.h"

View File

@@ -21,7 +21,7 @@
#include <stdint.h>
#include "boot/s390.h"
#include "boot/psw.h"
/* Must not have any padding included */
struct memblob {

View File

@@ -21,8 +21,6 @@ ENTRY(_start)
SECTIONS
{
. = 0x0;
. = HEAP_ADDRESS;
__heap_start = .;
.heap : {
@@ -34,8 +32,8 @@ SECTIONS
. = STAGE3B_ENTRY;
.text : {
head.o(.text.start)
*(.text)
*(.text.start)
*(.text .text.*)
}
.ex_table ALIGN(16) : {
@@ -52,7 +50,7 @@ SECTIONS
.rodata ALIGN(16) : {
*(.rodata)
*(.rodata.*)
*(.rodata*)
}
.data ALIGN(16) : {
@@ -74,14 +72,12 @@ SECTIONS
}
__stack_end = .;
/* List this explicitly as otherwise .note.gnu.build-id will be
* put at 0x0 */
.notes : {
*(.note.*)
}
ASSERT(. <= IMAGE_ENTRY, "stage3b size must be smaller than 0x10000 bytes")
/* Sections to be discarded */
/DISCARD/ : {
*(.eh_frame)
*(.interp)
*(.note.GNU-stack)
}
}

View File

@@ -22,8 +22,8 @@
.org 0x0
.section .text.start
.globl stage3b_reloc_start
stage3b_reloc_start:
.globl _start
_start:
/* Might be called after a diag308 so better set
* architecture and addressing mode
*/
@@ -53,3 +53,8 @@ stage3b_start:
.incbin "stage3b.bin"
stage3b_end:
.previous
/* The code doesn't require an executable stack */
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif

View File

@@ -0,0 +1,19 @@
OUTPUT_FORMAT("elf64-s390", "elf64-s390", "elf64-s390")
OUTPUT_ARCH(s390:64-bit)
ENTRY(_start)
SECTIONS
{
.text : {
*(.text.start)
*(.text .text.*)
}
/* Sections to be discarded */
/DISCARD/ : {
*(.eh_frame)
*(.interp)
*(.note.GNU-stack)
}
}

View File

@@ -17,7 +17,7 @@ WARNINGS := -Wall -Wextra -Wshadow \
-Wcast-align -Wwrite-strings -Wmissing-prototypes \
-Wmissing-declarations -Wredundant-decls -Wnested-externs \
-Wno-long-long -Wuninitialized -Wconversion -Wstrict-prototypes \
-Wpointer-arith -Werror -Wno-error=inline \
-Wpointer-arith -Wno-error=inline \
$(NULL)
$(bin_PROGRAM)_SRCS := $(bin_PROGRAM).c pv/pv_stage3.c pv/pv_image.c \
@@ -36,21 +36,12 @@ ALL_CPPFLAGS += $(INCLUDE_PARMS)
LDLIBS += $(GLIB2_LIBS) $(LIBCRYPTO_LIBS) $(LIBCURL_LIBS)
ifneq ($(shell sh -c 'command -v pkg-config'),)
GLIB2_CFLAGS := $(shell pkg-config --silence-errors --cflags glib-2.0)
GLIB2_LIBS := $(shell pkg-config --silence-errors --libs glib-2.0)
LIBCRYPTO_CFLAGS := $(shell pkg-config --silence-errors --cflags libcrypto)
LIBCRYPTO_LIBS := $(shell pkg-config --silence-errors --libs libcrypto)
LIBCURL_CFLAGS := $(shell pkg-config --silence-errors --cflags libcurl)
LIBCURL_LIBS := $(shell pkg-config --silence-errors --libs libcurl)
else
GLIB2_CFLAGS := -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
GLIB2_LIBS := -lglib-2.0
LIBCRYPTO_CFLAGS :=
LIBCRYPTO_LIBS := -lcrypto
LIBCURL_CFLAGS :=
LIBCURL_LIBS := -lcurl
endif
GLIB2_CFLAGS := $(shell $(PKG_CONFIG) --silence-errors --cflags glib-2.0)
GLIB2_LIBS := $(shell $(PKG_CONFIG) --silence-errors --libs glib-2.0)
LIBCRYPTO_CFLAGS := $(shell $(PKG_CONFIG) --silence-errors --cflags libcrypto)
LIBCRYPTO_LIBS := $(shell $(PKG_CONFIG) --silence-errors --libs libcrypto)
LIBCURL_CFLAGS := $(shell $(PKG_CONFIG) --silence-errors --cflags libcurl)
LIBCURL_LIBS := $(shell $(PKG_CONFIG) --silence-errors --libs libcurl)
BUILD_TARGETS := skip-$(bin_PROGRAM)
INSTALL_TARGETS := skip-$(bin_PROGRAM)

View File

@@ -10,10 +10,9 @@
#define GETTEXT_PACKAGE "genprotimg"
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <glib/gi18n.h>
#include "boot/linux_layout.h"
#include "boot/s390.h"
#include "lib/zt_common.h"
static const gchar tool_name[] = "genprotimg";

View File

@@ -12,7 +12,7 @@
#include <openssl/sha.h>
#include "boot/s390.h"
#include "boot/psw.h"
#include "lib/zt_common.h"
#include "utils/crypto.h"

View File

@@ -15,7 +15,6 @@
#include <stdio.h>
#include <string.h>
#include "boot/s390.h"
#include "common.h"
#include "utils/align.h"
#include "utils/buffer.h"

View File

@@ -12,7 +12,7 @@
#include <openssl/evp.h>
#include <stdint.h>
#include "boot/s390.h"
#include "boot/psw.h"
#include "boot/stage3b.h"
#include "common.h"
#include "utils/align.h"

View File

@@ -14,7 +14,7 @@
#include <openssl/evp.h>
#include <stdint.h>
#include "boot/s390.h"
#include "boot/psw.h"
#include "boot/stage3b.h"
#include "utils/buffer.h"

View File

@@ -14,7 +14,7 @@
#include <stdint.h>
#include <string.h>
#include "boot/s390.h"
#include "boot/psw.h"
#include "include/pv_crypto_def.h"
#include "utils/buffer.h"
#include "utils/crypto.h"

View File

@@ -13,7 +13,6 @@
#include <glib.h>
#include <stdint.h>
#include "boot/s390.h"
#include "include/pv_hdr_def.h"
#include "utils/crypto.h"
#include "utils/buffer.h"

View File

@@ -15,7 +15,7 @@
#include <stdlib.h>
#include <string.h>
#include "boot/s390.h"
#include "boot/psw.h"
#include "boot/stage3a.h"
#include "common.h"
#include "include/pv_crypto_def.h"

View File

@@ -15,7 +15,7 @@
#include <openssl/evp.h>
#include <stdint.h>
#include "boot/s390.h"
#include "boot/psw.h"
#include "utils/buffer.h"
#include "pv_args.h"

View File

@@ -13,7 +13,6 @@
#include <stdio.h>
#include "boot/ipl.h"
#include "boot/s390.h"
#include "common.h"
#include "include/pv_hdr_def.h"
#include "lib/zt_common.h"

View File

@@ -15,7 +15,6 @@
#include <stdint.h>
#include "boot/ipl.h"
#include "boot/s390.h"
#include "boot/stage3b.h"
#include "utils/buffer.h"

View File

@@ -10,8 +10,8 @@
#ifndef PV_UTILS_ALIGN_H
#define PV_UTILS_ALIGN_H
#include "boot/s390.h"
#include "lib/zt_common.h"
#include "boot/page.h"
#define IS_ALIGNED(addr, size) (!(addr & (size - 1)))

View File

@@ -24,7 +24,7 @@
#include <stdint.h>
#include <string.h>
#include "boot/s390.h"
#include "boot/page.h"
#include "common.h"
#include "include/pv_crypto_def.h"
#include "pv/pv_error.h"

View File

@@ -19,13 +19,8 @@ check_dep:
"fuse3-devel or libfuse3-dev", \
"HAVE_FUSE=0")
ifneq ($(shell sh -c 'command -v pkg-config'),)
FUSE_CFLAGS = $(shell pkg-config --silence-errors --cflags fuse3)
FUSE_LDLIBS = $(shell pkg-config --silence-errors --libs fuse3)
else
FUSE_CFLAGS = -D_FILE_OFFSET_BITS=64 -I/usr/include/fuse3
FUSE_LDLIBS = -lfuse3
endif
FUSE_CFLAGS = $(shell $(PKG_CONFIG) --silence-errors --cflags fuse3)
FUSE_LDLIBS = $(shell $(PKG_CONFIG) --silence-errors --libs fuse3)
ALL_CFLAGS += -DFUSE_USE_VERSION=30 -D_LARGEFILE_SOURCE $(FUSE_CFLAGS)
LDLIBS += $(FUSE_LDLIBS) -lpthread -lrt -ldl -lm
@@ -52,7 +47,7 @@ install-scripts: lshmc
cat $$i | \
sed -e 's/%S390_TOOLS_VERSION%/$(S390_TOOLS_RELEASE)/' \
>$(DESTDIR)$(USRSBINDIR)/$$i; \
chown $(OWNER).$(GROUP) $(DESTDIR)$(USRSBINDIR)/$$i; \
chown $(OWNER):$(GROUP) $(DESTDIR)$(USRSBINDIR)/$$i; \
chmod 755 $(DESTDIR)$(USRSBINDIR)/$$i; \
done

View File

@@ -22,26 +22,16 @@ else # HAVE_FUSE
#
# FUSE
#
ifneq ($(shell sh -c 'command -v pkg-config'),)
FUSE_CFLAGS = $(shell pkg-config --silence-errors --cflags fuse3)
FUSE_LDLIBS = $(shell pkg-config --silence-errors --libs fuse3)
else
FUSE_CFLAGS = -I/usr/include/fuse3
FUSE_LDLIBS = -lfuse3
endif
FUSE_CFLAGS = $(shell $(PKG_CONFIG) --silence-errors --cflags fuse3)
FUSE_LDLIBS = $(shell $(PKG_CONFIG) --silence-errors --libs fuse3)
#
# systemd
#
ifneq (${HAVE_SYSTEMD},0)
ifeq ($(call check_header_prereq,"systemd/sd-daemon.h"),yes)
ifneq ($(shell sh -c 'command -v pkg-config'),)
SYSTEMD_CFLAGS = $(shell pkg-config --silence-errors --cflags libsystemd)
SYSTEMD_LDLIBS = $(shell pkg-config --silence-errors --libs libsystemd)
else
SYSTEMD_CFLAGS =
SYSTEMD_LDLIBS = -lsystemd
endif
SYSTEMD_CFLAGS = $(shell $(PKG_CONFIG) --silence-errors --cflags libsystemd)
SYSTEMD_LDLIBS = $(shell $(PKG_CONFIG) --silence-errors --libs libsystemd)
ALL_CPPFLAGS += -DHAVE_SYSTEMD
else
$(warning "systemd support disabled")

View File

@@ -5,7 +5,7 @@ all:
install: hsci
$(SED) -e 's/%S390_TOOLS_VERSION%/$(S390_TOOLS_RELEASE)/' \
< hsci >$(DESTDIR)$(BINDIR)/hsci; \
chown $(OWNER).$(GROUP) $(DESTDIR)$(BINDIR)/hsci; \
chown $(OWNER):$(GROUP) $(DESTDIR)$(BINDIR)/hsci; \
chmod 755 $(DESTDIR)$(BINDIR)/hsci; \
$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man8
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 644 hsci.8 \

View File

@@ -311,6 +311,7 @@ static struct sd_sys_item *l_sys_item_vec[] = {
static struct sd_sys_item *l_sys_item_enable_vec[] = {
&sd_sys_item_core_cnt,
&sd_sys_item_core_diff,
&sd_sys_item_thread_diff,
&sd_sys_item_mgm_diff,
&sd_sys_item_core,
&sd_sys_item_mgm,
@@ -339,6 +340,7 @@ static struct sd_cpu_item *l_cpu_item_vec[] = {
static struct sd_cpu_item *l_cpu_item_enable_vec[] = {
&sd_cpu_item_type,
&sd_cpu_item_core_diff,
&sd_cpu_item_thread_diff,
&sd_cpu_item_mgm_diff,
NULL,
};

View File

@@ -57,11 +57,42 @@ struct linear_blockptr {
uint8_t reserved[4];
} __packed;
/*
* Format of a boot record on ECKD DASD for List-Directed IPL
*/
struct eckd_boot_record {
uint8_t magic[4];
uint32_t version_id;
uint8_t unused[8];
uint8_t program_table_pointer[16];
uint8_t reserved[478];
uint16_t os_id;
} __packed;
/*
* Layout of block pointer for cylinder/head/sector devices
* e.g. ECKD
*/
struct eckd_blockptr {
enum blkptr_format_id {
/*
* this is the old format which serves only CCW-type IPL,
* and doesn't fit List-Directed IPL. Still supported for
* compatibility reasons.
*/
LEGACY_BLKPTR_FORMAT_ID,
/*
* this is the "new" format which serves only List-Directed IPL,
* but is also suitable for CCW-type IPL.
*/
BLKPTR_FORMAT_ID,
NR_BLKPTR_FORMATS
};
/*
* Block pointers format identified as LEGACY_BLKPTR_FORMAT_ID.
*/
struct eckd_blockptr_legacy {
uint16_t cyl;
uint16_t head;
uint8_t sec;
@@ -70,10 +101,22 @@ struct eckd_blockptr {
uint8_t reserved[8];
} __packed;
/*
* Block pointers format identified as BLKPTR_FORMAT_ID.
*/
struct eckd_blockptr {
uint32_t cyl;
uint8_t head;
uint8_t sec;
uint8_t reserved1[4];
uint16_t blockct;
uint8_t reserved2[4];
} __packed;
typedef enum {
COMPONENT_EXECUTE = 0x01,
COMPONENT_LOAD = 0x02,
COMPONENT_SIGNATURE = 0x03
COMPONENT_TYPE_EXECUTE = 0x01,
COMPONENT_TYPE_LOAD = 0x02,
COMPONENT_TYPE_SIGNATURE = 0x03
} component_type;
typedef enum {
@@ -117,7 +160,8 @@ struct scsi_dump_sb {
uint64_t csum_offset;
uint64_t csum_size;
uint64_t csum;
} __packed;
};
STATIC_ASSERT(sizeof(struct scsi_dump_sb) == 72);
#define SCSI_DUMP_SB_MAGIC 0x5a46435044554d50ULL /* ZFCPDUMP */
/* To avoid a csum entry of 0 a seed is used */
@@ -151,14 +195,25 @@ struct boot_info_bp_dump {
uint8_t unused[16];
} __packed;
/* This represents on-disk pointer to a block on disk */
union disk_blockptr {
struct eckd_blockptr_legacy eckd_legacy;
struct eckd_blockptr eckd;
struct linear_blockptr linear;
};
struct boot_info_bp_ipl {
union {
struct eckd_blockptr eckd;
struct linear_blockptr lin;
} bm_ptr;
union disk_blockptr bm_ptr;
uint8_t unused[16];
} __packed;
struct disk_program_table {
uint32_t magic;
uint32_t version;
uint64_t unused;
union disk_blockptr component_table[0];
} __packed;
struct boot_info {
char magic[4];
uint8_t version;

View File

@@ -11,7 +11,7 @@
#define IPL_H
#include "lib/zt_common.h"
#include "s390.h"
#include "page.h"
#define IPL_FLAG_SECURE 0x40

View File

@@ -14,12 +14,18 @@
#include "lib/zt_common.h"
#include "linux_layout.h"
#define STAGE0_LOAD_ADDRESS _AC(0x0, UL)
#define STAGE1_LOAD_ADDRESS _AC(0x18, UL)
#define STAGE1B_LOAD_ADDRESS _AC(0xe000, UL)
#define STAGE2_DESC _AC(0x78, UL)
#define STAGE2_ENTRY _AC(0x2018, UL)
#define STAGE2_HEAP_ADDRESS _AC(0x6000, UL)
#define STAGE2_HEAP_SIZE _AC(0x3000, UL)
#define STAGE2_STACK_ADDRESS _AC(0xe400, UL)
#define STAGE2_STACK_SIZE _AC(0x1c00, UL)
#define STAGE2_MAX_SIZE _AC(0x3000, UL)
#define STAGE3_ENTRY _AC(0xa000, UL)

15
include/boot/page.h Normal file
View File

@@ -0,0 +1,15 @@
/*
* Page related definitions and functions.
*
* Copyright IBM Corp. 2023
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef BOOT_PAGE_H
#define BOOT_PAGE_H
#include "lib/zt_common.h"
#define PAGE_SIZE _AC(4096, UL)
#endif

31
include/boot/psw.h Normal file
View File

@@ -0,0 +1,31 @@
/*
* Program Status Word related definitions and functions.
*
* Copyright IBM Corp. 2023
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef BOOT_PSW_H
#define BOOT_PSW_H
#include "lib/zt_common.h"
#define PSW32_ADDR_MASK _AC(0x000000007fffffff, UL)
#define PSW_MASK_BA _AC(0x0000000080000000, UL)
#define PSW_MASK_EA _AC(0x0000000100000000, UL)
#define PSW_MASK_BIT_12 _AC(0x0008000000000000, UL)
#define PSW_LOAD _AC(0x0008000080000000, UL)
#define PSW_DISABLED_WAIT _AC(0x000a000000000000, UL)
#ifndef __ASSEMBLER__
#include <stdint.h>
struct psw_t {
uint64_t mask;
uint64_t addr;
} __aligned(8);
#endif
#endif

View File

@@ -1,7 +1,8 @@
/*
* s390 related definitions and functions.
* Should only be used for code targeting s390 (bootloader code)
*
* Copyright IBM Corp. 2013, 2020
* Copyright IBM Corp. 2013, 2023
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@@ -12,29 +13,22 @@
#include "lib/zt_common.h"
#include "boot/sigp.h"
#include "boot/psw.h"
#include "boot/page.h"
#define __LC_IPLDEV 0x0c6c
#define __LC_OS_INFO 0x0e18
#define LOWCORE_SIZE _AC(0x2000, UL)
#define PAGE_SIZE _AC(4096, UL)
/* Minimum size of a stack frame in bytes */
#define STACK_FRAME_OVERHEAD _AC(160, U)
/* Facilities */
#define UNPACK_FACILITY _AC(161, U)
#define PSW32_ADDR_MASK _AC(0x000000007fffffff, UL)
#define PSW_MASK_BA _AC(0x0000000080000000, UL)
#define PSW_MASK_EA _AC(0x0000000100000000, UL)
#define PSW_MASK_BIT_12 _AC(0x0008000000000000, UL)
#define PSW_LOAD _AC(0x0008000080000000, UL)
#define PSW_DISABLED_WAIT _AC(0x000a000000000000, UL)
#ifndef __ASSEMBLER__
#include <stdint.h>
/*
* Helper macro for exception table entries
@@ -46,18 +40,6 @@
".long (" #_target ")\n" \
".previous\n"
struct psw_t {
uint64_t mask;
uint64_t addr;
} __aligned(8);
struct psw32_t {
uint32_t mask;
uint32_t addr;
} __aligned(8);
void load_wait_psw(uint64_t, struct psw_t *);
struct subchannel_id {
uint32_t cssid:8;
uint32_t:4;

View File

@@ -90,5 +90,6 @@ void ap_list_remove_all(struct util_list *list);
int ap_get_lock(void);
int ap_get_lock_callout(void);
int ap_release_lock(void);
int ap_release_lock_callout(void);
#endif /* LIB_AP_H */

View File

@@ -20,8 +20,8 @@
#include <stdio.h>
#include <sys/ioctl.h>
/* A bus id of a DASD is 8 characters long. E.g. 0.0.4711 */
#define DASD_BUS_ID_SIZE 9
/* the definition of a BUSID in the DASD driver is 20 */
#define DASD_BUS_ID_SIZE 20
typedef struct dasd_information2_t {
unsigned int devno; /* S/390 devno */
@@ -187,6 +187,68 @@ typedef struct format_check_t {
#define DASD_FMT_ERR_RECORD_ID 4
#define DASD_FMT_ERR_KEY_LENGTH 5
/*
* struct profile_info_t
* holds the profiling information
*/
typedef struct dasd_profile_info_t {
unsigned int dasd_io_reqs; /* # of requests processed at all */
unsigned int dasd_io_sects; /* # of sectors processed at all */
unsigned int dasd_io_secs[32]; /* request's sizes */
unsigned int dasd_io_times[32]; /* requests's times */
unsigned int dasd_io_timps[32]; /* requests's times per sector */
unsigned int dasd_io_time1[32]; /* time from build to start */
unsigned int dasd_io_time2[32]; /* time from start to irq */
unsigned int dasd_io_time2ps[32]; /* time from start to irq */
unsigned int dasd_io_time3[32]; /* time from irq to end */
unsigned int dasd_io_nr_req[32]; /* # of requests in chanq */
} dasd_profile_info_t;
/*
* struct attrib_data_t
* represents the operation (cache) bits for the device.
* Used in DE to influence caching of the DASD.
*/
typedef struct attrib_data_t {
unsigned char operation : 3; /* cache operation mode */
unsigned char reserved : 5;
unsigned short nr_cyl; /* no of cyliners for read ahaed */
unsigned char reserved2[29]; /* for future use */
} __attribute__((packed)) attrib_data_t;
/* definition of operation (cache) bits within attributes of DE */
#define DASD_NORMAL_CACHE 0x0
#define DASD_BYPASS_CACHE 0x1
#define DASD_INHIBIT_LOAD 0x2
#define DASD_SEQ_ACCESS 0x3
#define DASD_SEQ_PRESTAGE 0x4
#define DASD_REC_ACCESS 0x5
/*
* Data returned by Sense Path Group ID (SNID)
*/
struct dasd_snid_data {
struct {
__u8 group : 2;
__u8 reserve : 2;
__u8 mode : 1;
__u8 res : 3;
} __attribute__((packed)) path_state;
__u8 pgid[11];
} __attribute__((packed));
struct dasd_snid_ioctl_data {
struct dasd_snid_data data;
__u8 path_mask;
} __attribute__((packed));
struct dasd_copypair_swap_data {
char primary[DASD_BUS_ID_SIZE]; /* BUSID of primary */
char secondary[DASD_BUS_ID_SIZE]; /* BUSID of secondary */
/* Reserved for future updates. */
char reserved[64];
};
#ifndef __linux__
/* definition from hdreg.h */
struct hd_geometry {
@@ -207,27 +269,29 @@ struct hd_geometry {
#define BIODASDRSRV _IO(DASD_IOCTL_LETTER, 2)
/* Release the device for the current LPAR */
#define BIODASDRLSE _IO(DASD_IOCTL_LETTER, 3)
/* Unconditional reserve the device for the current LPAR */
#define BIODASDSLCK _IO(DASD_IOCTL_LETTER, 4)
/* reset profiling information of a device */
#define BIODASDPRRST _IO(DASD_IOCTL_LETTER, 5)
/* retrieve profiling information of a device */
#define BIODASDPRRD _IOR(DASD_IOCTL_LETTER, 2, dasd_profile_info_t)
/* Get information on a dasd device (enhanced) */
#define BIODASDINFO2 _IOR(DASD_IOCTL_LETTER, 3, dasd_information2_t)
/* Get Attributes (cache operations) */
#define BIODASDGATTR _IOR(DASD_IOCTL_LETTER, 5, attrib_data_t)
/* #define BIODASDFORMAT _IOW(IOCTL_LETTER,0,format_data_t) , deprecated */
#define BIODASDFMT _IOW(DASD_IOCTL_LETTER, 1, format_data_t)
/* Set Attributes (cache operations) */
#define BIODASDSATTR _IOW(DASD_IOCTL_LETTER, 2, attrib_data_t)
/* Release Allocated Space */
#define BIODASDRAS _IOW(DASD_IOCTL_LETTER, 3, format_data_t)
/* Swap copy pair */
#define BIODASDPPRCSWAP _IOW(DASD_IOCTL_LETTER, 4, struct dasd_copypair_swap_data)
/* Get Sense Path Group ID (SNID) data */
#define BIODASDSNID _IOWR(DASD_IOCTL_LETTER, 1, struct dasd_snid_ioctl_data)
/* Check device format according to format_data_t */
#define BIODASDCHECKFMT _IOWR(DASD_IOCTL_LETTER, 2, format_check_t)
/********************************************************************************
* SECTION: Further IOCTL Definitions (see fs.h and hdreq.h)
*******************************************************************************/
/* get read-only status (0 = read_write) */
#define BLKROGET _IO(0x12, 94)
/* re-read partition table */
#define BLKRRPART _IO(0x12, 95)
/* get block device sector size */
#define BLKSSZGET _IO(0x12, 104)
/* return device size in bytes (u64 *arg) */
#define BLKGETSIZE64 _IOR(0x12, 114, size_t)
#ifndef __linux__ /* from <linux/hdreg.h> */
#define HDIO_GETGEO 0x0301
#endif
@@ -245,5 +309,12 @@ int dasd_is_ro(const char *device, bool *ro);
int dasd_reread_partition_table(const char *device, int ntries);
int dasd_disk_reserve(const char *device);
int dasd_disk_release(const char *device);
int dasd_slock(const char *device);
int dasd_get_cache(const char *device, attrib_data_t *attrib_data);
int dasd_set_cache(const char *device, attrib_data_t *attrib_data);
int dasd_query_reserve(const char *device);
int dasd_profile(const char *device, dasd_profile_info_t *dasd_profile_info);
int dasd_reset_profile(const char *device);
int dasd_copy_swap(const char *device, struct dasd_copypair_swap_data *data);
#endif /* LIB_DASD_BASE_H */

View File

@@ -0,0 +1,26 @@
/**
* @defgroup util_lockfile_h util_lockfile: File locking utility
* @{
* @brief Create file-based locks
*
* Copyright IBM Corp. 2022
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_LOCKFILE_H
#define LIB_UTIL_LOCKFILE_H
#define UTIL_LOCKFILE_OK 0 /* Lock acquired/released successfully */
#define UTIL_LOCKFILE_LOCK_FAIL 1 /* Lock already held, ran out of retries */
#define UTIL_LOCKFILE_RELEASE_NONE 2 /* Lock not held */
#define UTIL_LOCKFILE_RELEASE_FAIL 3 /* Lock not held by specified pid */
#define UTIL_LOCKFILE_ERR 4 /* Other, unexpected error conditions */
int util_lockfile_lock(char *lockfile, int retries);
int util_lockfile_parent_lock(char *lockfile, int retries);
int util_lockfile_release(char *lockfile);
int util_lockfile_parent_release(char *lockfile);
#endif /** LIB_UTIL_LOCKFILE_H @} */

View File

@@ -97,6 +97,24 @@ typedef struct volume_label
unsigned long long formatted_blocks; /* valid when ldl_version >= f2 */
} __attribute__ ((packed)) volume_label_t;
/**
* This represents a volume label specific for OS/390 compatible disk layout
*/
struct vol_label_cdl {
char volkey[4];
char vollbl[4];
char opaq[70];
cchhb_t br; /* boot record address */
char stdv[1]; /* standard version ID */
} __attribute__ ((packed));
static inline int is_vol1(char *this)
{
char vol1[] = {0xe5, 0xd6, 0xd3, 0xf1, 0x00} /* "VOL1" in EBCDIC */;
return !strncmp(this, vol1, 4);
}
typedef struct extent
{
u_int8_t typeind; /* extent type indicator */

View File

@@ -32,6 +32,10 @@
#ifndef __ASSEMBLER__
#ifndef sizeof_field
#define sizeof_field(type, field) (sizeof((type *)0)->field)
#endif
#ifdef UNUSED
#elif defined(__GNUC__)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
@@ -50,6 +54,10 @@
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#ifndef ROUNDUP
# define ROUNDUP(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
#endif
#define RELEASE_STRING STRINGIFY (S390_TOOLS_RELEASE)
#define TOOLS_LIBDIR STRINGIFY (S390_TOOLS_LIBDIR)
#define TOOLS_SYSCONFDIR STRINGIFY (S390_TOOLS_SYSCONFDIR)
@@ -62,6 +70,7 @@
#define __may_alias __attribute__((may_alias))
#define __section(x) __attribute__((__section__(#x)))
#define __noinline __attribute__((__noinline__))
#define __big_endian
/* The Linux kernel (in stddef.h) and glibc (sys/cdefs.h) define
* __always_inline. Therefore undefine it first to allow the headers
* to be included first.

View File

@@ -68,6 +68,7 @@ typedef enum {
PV_CERT_ERROR_MALFORMED_ROOT_CA,
PV_CERT_ERROR_NO_CRL,
PV_CERT_ERROR_NO_CRLDP,
PV_CERT_ERROR_NO_IBM_Z_SIGNING_KEY,
PV_CERT_ERROR_NO_ISSUER_IBM_Z_FOUND,
PV_CERT_ERROR_NO_PUBLIC_KEY,
PV_CERT_ERROR_READ_CERTIFICATE,

View File

@@ -15,7 +15,7 @@
*/
#include "libpv/glib-helper.h"
#include <glib/gi18n-lib.h>
#include <glib/gi18n.h>
#include "libpv/openssl-compat.h"
#include "libpv/macros.h"

View File

@@ -42,11 +42,14 @@ enum PvCryptoMode {
PV_DECRYPT,
};
/** pv_get_openssl_error:
/** pv_get_openssl_errors:
*
* Returns: (transfer full): String representing the error.
* Returns the last OpenSSL error messages.
* Caller is responsible to free the returned value.
*
* Returns: String representing the error.
*/
const char *pv_get_openssl_error(void);
char *pv_get_openssl_errors(void);
/**
* pv_BIO_reset:
@@ -181,7 +184,6 @@ typedef enum {
PV_CRYPTO_ERROR_KEYGENERATION,
PV_CRYPTO_ERROR_RANDOMIZATION,
PV_CRYPTO_ERROR_READ_FILE,
PV_CRYPTO_ERROR_NO_IBM_Z_SIGNING_KEY,
PV_CRYPTO_ERROR_NO_MATCH_TAG,
} PvCryptoErrors;

View File

@@ -18,6 +18,12 @@
#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_56
#endif
#define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_56
#ifdef __G_LIB_H__
#error "glib.h must be included via libpv/glib-helper.h"
#endif
#include <glib.h>
#include <gmodule.h>
#include <stdio.h>
@@ -102,9 +108,12 @@ FILE *pv_file_open(const char *filename, const char *mode, GError **error);
/** pv_gbytes_memcpy:
*
* memcpy with size check.
* memcpy with size check. In case @dst_size is smaller than the size of @src
* the error value %NULL is returned and @copied and @dst are left unchanged.
*
* If @dst and @src data overlap, the behavior is undefined.
*/
void *pv_gbytes_memcpy(void *dst, size_t dst_size, GBytes *src);
void *pv_gbytes_memcpy(void *dst, size_t dst_size, GBytes *src, size_t *copied);
#define PV_GLIB_HELPER_ERROR g_quark_from_static_string("pv-glib-helper_error-quark")
typedef enum {

View File

@@ -10,7 +10,12 @@
#ifndef LIBPV_MACROS_H
#define LIBPV_MACROS_H
#include <stdint.h>
#define PV_NONNULL(...)
#define DO_PRAGMA(x) _Pragma(#x)
/* Most significant bit */
#define PV_MSB(idx) ((uint64_t)1 << (63 - (idx)))
#endif /* LIBPV_MACROS_H */

View File

@@ -13,8 +13,9 @@
#include <openssl/sha.h>
#include "boot/s390.h"
#include "boot/psw.h"
#include "libpv/crypto.h"
#include "libpv/macros.h"
/* Magic number which is used to identify the file containing the PV
* header
@@ -22,20 +23,17 @@
#define PV_MAGIC_NUMBER 0x49424d5365634578ULL
#define PV_VERSION_1 0x00000100U
/* Internal helper macro */
#define __PV_BIT(nr) (1ULL << (63 - (nr)))
/* Plaintext control flags */
/* dumping of the configuration is allowed */
#define PV_PCF_ALLOW_DUMPING __PV_BIT(34)
#define PV_PCF_ALLOW_DUMPING PV_MSB(34)
/* prevent Ultravisor decryption during unpack operation */
#define PV_PCF_NO_DECRYPTION __PV_BIT(35)
#define PV_PCF_NO_DECRYPTION PV_MSB(35)
/* PCKMO encrypt-DEA/TDEA-key functions allowed */
#define PV_PCF_PCKMO_DEA_TDEA __PV_BIT(56)
#define PV_PCF_PCKMO_DEA_TDEA PV_MSB(56)
/* PCKMO encrypt-AES-key functions allowed */
#define PV_PCF_PCKMO_AES __PV_BIT(57)
#define PV_PCF_PCKMO_AES PV_MSB(57)
/* PCKMO encrypt-ECC-key functions allowed */
#define PV_PCF_PCKM_ECC __PV_BIT(58)
#define PV_PCF_PCKM_ECC PV_MSB(58)
/* maxima for the PV version 1 */
#define PV_V1_IPIB_MAX_SIZE PAGE_SIZE

View File

@@ -12,7 +12,7 @@ clean:
install: ip_watcher.pl xcec-bridge start_hsnc.sh
$(SED) -e 's/%S390_TOOLS_VERSION%/$(S390_TOOLS_RELEASE)/' \
< start_hsnc.sh >$(DESTDIR)$(USRSBINDIR)/start_hsnc.sh; \
chown $(OWNER).$(GROUP) $(DESTDIR)$(USRSBINDIR)/start_hsnc.sh; \
chown $(OWNER):$(GROUP) $(DESTDIR)$(USRSBINDIR)/start_hsnc.sh; \
chmod 755 $(DESTDIR)$(USRSBINDIR)/start_hsnc.sh; \
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 755 ip_watcher.pl \
$(DESTDIR)$(USRSBINDIR)

View File

@@ -23,12 +23,15 @@
#define BOOTPARMS_CCW_MAX 64
#define BOOTPARMS_FCP_MAX 3452
#define OPT_BRCHR 0x80
enum target_type {
TT_CCW,
TT_FCP,
TT_NSS,
TT_NODE,
TT_NVME,
TT_ECKD,
};
enum reipl_type {
@@ -36,12 +39,14 @@ enum reipl_type {
REIPL_CCW,
REIPL_NSS,
REIPL_NVME,
REIPL_ECKD,
};
static const char *const usage_chreipl =
"Usage: %s [TARGET] [ARGS] [OPTIONS]\n"
"\n"
" chreipl [ccw] [-d] <DEVICE> [OPTIONS]\n"
" chreipl [eckd] [-d] <DEVICE> [OPTIONS]\n"
" chreipl [fcp] [-d] <DEVICE> [-w] <WWPN> [-l] <LUN> [OPTIONS]\n"
" chreipl nvme [-i] <FID> [-s] <NSID> [OPTIONS]\n"
" chreipl [node] <NODE|DIR> [OPTIONS]\n"
@@ -50,6 +55,7 @@ static const char *const usage_chreipl =
"\n"
"The following re-IPL targets are supported:\n"
" ccw IPL from CCW device\n"
" eckd IPL from ECKD device\n"
" fcp IPL from FCP device\n"
" nvme IPL from NVME device\n"
" nss IPL from NSS\n"
@@ -66,6 +72,13 @@ static const char *const usage_chreipl =
" -L, --loadparm <PARM> Loadparm specification\n"
" -c, --clear 0|1 Control if memory is cleared on re-IPL\n"
"\n"
"Options for eckd target:\n"
" -d, --device <DEVICE> Device number of the ECKD IPL device\n"
" -b, --bootprog <BPROG> Bootprog specification\n"
" --brchr <C,H,R> Boot record location in Cylinder,Head,Record format\n"
" -L, --loadparm <PARM> Loadparm specification\n"
" -c, --clear 0|1 Control if memory is cleared on re-IPL\n"
"\n"
"Options for fcp target:\n"
" -d, --device <DEVICE> Device number of the adapter of the FCP IPL device\n"
" -l --lun <LUN> Logical unit number of the FCP IPL device\n"
@@ -114,6 +127,8 @@ static struct locals {
int target_type_auto_mode;
enum reipl_type reipl_type; /* CCW, FCP, NVME, NSS */
int reipl_clear;
char *brchr;
int brchr_set;
} l;
static void __noreturn print_usage_chreipl_exit(void)
@@ -329,6 +344,19 @@ static void parse_ccw_args(char *nargv[], int nargc)
set_device(nargv[0]);
}
static void parse_eckd_args(char *nargv[], int nargc)
{
/*
* we might be called like this:
* chreipl eckd 4711
*/
if (l.busid_set)
ERR_EXIT("Use either options or positional parameters");
if (nargc > 1)
ERR_EXIT("Too many arguments specified for \"eckd\" re-IPL type");
set_device(nargv[0]);
}
static void parse_nss_args(char *nargv[], int nargc)
{
/*
@@ -369,6 +397,8 @@ static int set_reipl_type(const char *dev_name)
l.reipl_type = REIPL_FCP;
else if (strncmp(dev_name, "nvme", strlen("nvme")) == 0)
l.reipl_type = REIPL_NVME;
else if (strncmp(dev_name, "eckd", strlen("eckd")) == 0)
l.reipl_type = REIPL_ECKD;
else
return -1;
@@ -493,12 +523,15 @@ static void parse_pos_args(char *nargv[], int nargc)
case TT_NODE:
parse_node_args(nargv, nargc);
break;
case TT_ECKD:
parse_eckd_args(nargv, nargc);
break;
}
}
static void check_fcp_opts(void)
{
if (l.nss_name_set)
if (l.nss_name_set || l.brchr_set)
ERR_EXIT("Invalid option for \"fcp\" target specified");
if (!(l.busid_set && l.wwpn_set && l.lun_set))
ERR_EXIT("The \"fcp\" target requires device, WWPN, "
@@ -507,7 +540,8 @@ static void check_fcp_opts(void)
static void check_nvme_opts(void)
{
if (l.nss_name_set || l.wwpn_set || l.lun_set || l.busid_set)
if (l.nss_name_set || l.wwpn_set || l.lun_set || l.busid_set ||
l.brchr_set)
ERR_EXIT("Invalid option for \"nvme\" target specified");
if (!(l.fid_set && l.nsid_set))
ERR_EXIT("The \"nvme\" target requires FID, and optional NSID");
@@ -515,16 +549,25 @@ static void check_nvme_opts(void)
static void check_ccw_opts(void)
{
if (l.bootprog_set || l.lun_set || l.wwpn_set || l.nss_name_set)
if (l.bootprog_set || l.lun_set || l.wwpn_set || l.nss_name_set ||
l.brchr_set)
ERR_EXIT("Invalid option for \"ccw\" target specified");
if (!l.busid_set)
ERR_EXIT("The \"ccw\" target requires device");
}
static void check_eckd_opts(void)
{
if (l.nss_name_set || l.wwpn_set || l.lun_set || l.fid_set)
ERR_EXIT("Invalid option for \"eckd\" target specified");
if (!(l.busid_set))
ERR_EXIT("The \"eckd\" target requires device");
}
static void check_nss_opts(void)
{
if (l.bootprog_set || l.loadparm_set || l.busid_set || l.wwpn_set ||
l.lun_set)
l.lun_set || l.brchr_set)
ERR_EXIT("Invalid option for \"nss\" target specified");
if (!l.nss_name_set)
ERR_EXIT("The \"nss\" target requires NSS name");
@@ -563,6 +606,12 @@ static void set_reipl_clear(const char *arg)
ERR_EXIT("re-IPL clear argument must be either 1 or 0");
}
static void set_brchr(const char *arg)
{
l.brchr = strdup(arg);
l.brchr_set = 1;
}
static void parse_chreipl_options(int argc, char *argv[])
{
int opt, idx;
@@ -580,6 +629,7 @@ static void parse_chreipl_options(int argc, char *argv[])
{ "force", no_argument, NULL, 'f' },
{ "version", no_argument, NULL, 'v' },
{ "clear", required_argument, NULL, 'c' },
{ "brchr", required_argument, NULL, OPT_BRCHR },
{ NULL, 0, NULL, 0 }
};
static const char optstr[] = "hd:vw:l:fL:b:n:p:c:i:s:";
@@ -592,6 +642,8 @@ static void parse_chreipl_options(int argc, char *argv[])
set_target_type(TT_FCP, 0);
else if (strcmp(argv[1], "ccw") == 0)
set_target_type(TT_CCW, 0);
else if (strcmp(argv[1], "eckd") == 0)
set_target_type(TT_ECKD, 0);
else if (strcmp(argv[1], "nss") == 0)
set_target_type(TT_NSS, 0);
else if (strcmp(argv[1], "nvme") == 0)
@@ -640,6 +692,9 @@ static void parse_chreipl_options(int argc, char *argv[])
case 'c':
set_reipl_clear(optarg);
break;
case OPT_BRCHR:
set_brchr(optarg);
break;
case 'v':
print_version_exit();
default:
@@ -737,6 +792,34 @@ static void chreipl_ccw(void)
print_ccw(0);
}
static void chreipl_eckd(void)
{
check_eckd_opts();
if (!ccw_is_device(l.busid) && !l.force_set) {
if (is_ignored(l.busid))
ERR_EXIT("Device is on cio_ignore list, try \"cio_ignore -r %s\"?",
l.busid);
ERR_EXIT("Could not find DASD ECKD device \"%s\"", l.busid);
}
if (l.reipl_clear >= 0) {
check_exists("reipl/eckd/clear", "ECKD re-IPL clear attribute");
write_str(l.reipl_clear ? "1" : "0", "reipl/eckd/clear");
}
if (!l.brchr_set)
l.brchr = "auto";
write_str(l.brchr, "reipl/eckd/br_chr");
if (!l.bootprog_set)
sprintf(l.bootprog, "0");
write_str(l.bootprog, "reipl/eckd/bootprog");
write_str(l.busid, "reipl/eckd/device");
write_str_optional(l.loadparm, "reipl/eckd/loadparm", l.loadparm_set, "loadparm");
write_str("eckd", "reipl/reipl_type");
print_eckd(0, "eckd");
}
static void chreipl_fcp(void)
{
check_fcp_opts();
@@ -850,6 +933,11 @@ static void chreipl_node(void)
l.busid_set = 1;
chreipl_ccw();
break;
case REIPL_ECKD:
ccw_busid_get(l.dev, l.busid);
l.busid_set = 1;
chreipl_eckd();
break;
case REIPL_FCP:
fcp_wwpn_get(l.dev, l.wwpn);
l.wwpn_set = 1;
@@ -878,6 +966,9 @@ void cmd_chreipl(int argc, char *argv[])
case TT_CCW:
chreipl_ccw();
break;
case TT_ECKD:
chreipl_eckd();
break;
case TT_FCP:
chreipl_fcp();
break;

View File

@@ -141,6 +141,30 @@ void print_ccw(int show_ipl)
print_fw_str("clear: %s\n", dir, "clear");
}
void print_eckd(int show_ipl, const char *name)
{
char *path_loadparm = show_ipl ? "/sys/firmware/ipl/loadparm" :
"/sys/firmware/reipl/eckd/loadparm";
char *dir = show_ipl ? "ipl" : "reipl/eckd";
char loadparm[9], loadparm_path[PATH_MAX];
printf("%-12s %s\n", get_ipl_banner(show_ipl), name);
print_fw_str("Device: %s\n", dir, "device");
print_fw_str("bootprog: %s\n", dir, "bootprog");
print_fw_str("br_chr: %s\n", dir, "br_chr");
print_fw_str("Bootparm: \"%s\"\n", dir, "scp_data");
if (access(path_loadparm, R_OK) == 0) {
sprintf(loadparm_path, "%s/%s", dir, "loadparm");
read_fw_str(loadparm, loadparm_path, sizeof(loadparm));
if (strcmp(loadparm, " ") == 0)
loadparm[0] = 0;
printf("Loadparm: \"%s\"\n", loadparm);
}
if (!show_ipl)
print_fw_str("clear: %s\n", dir, "clear");
}
static void parse_lsreipl_options(int argc, char *argv[])
{
int opt, idx;
@@ -193,6 +217,9 @@ void cmd_lsreipl(int argc, char *argv[])
print_nvme(l.ipl_set, 1);
else if (strcmp(reipl_type_str, "ccw") == 0)
print_ccw(l.ipl_set);
else if (strcmp(reipl_type_str, "eckd") == 0 ||
strcmp(reipl_type_str, "eckd_dump") == 0)
print_eckd(l.ipl_set, reipl_type_str);
else if (strcmp(reipl_type_str, "nss") == 0)
print_nss(l.ipl_set);
else

View File

@@ -45,6 +45,7 @@ extern void print_ccw(int show_ipl);
extern void print_fcp(int show_ipl, int dump);
extern void print_nvme(int show_ipl, int dump);
extern void print_nss(int show_ipl);
extern void print_eckd(int show_ipl, const char *name);
/*
* Helper
@@ -75,6 +76,7 @@ extern void fcp_busid_get(const char *device, char *devno);
* NVME
*/
#define FID_MAX_LEN 11 /* 8 characters + 0x + null */
#define NVME_DEV_MAX_LEN 15 /* "nvme" + u32 in decimal + null */
#define NVME_PATH_MAX (PATH_MAX + NAME_MAX + 1)
extern void nvme_fid_get(const char *device, char *fid);

View File

@@ -36,6 +36,9 @@ The first argument specifies the re-IPL target:
.RB "- " ccw :
Specify a DASD CCW device for reboot
.TP
.RB "- " eckd :
Specify a DASD ECKD device for reboot
.TP
.RB "- " fcp :
Specify a FCP device for reboot
.TP
@@ -175,6 +178,63 @@ in the installed zIPL environment block for evaluation of zIPL environment
variables in the kernel command line:
\fB# chreipl ccw -d 0.0.7e78 -L 1S2\fP
.SH eckd
Use the eckd re-IPL target for DASD devices that are accessed by the hardware
using channel command word (CCW) channels. In contrast to the ccw re-IPL target,
the eckd target uses a list-directed bootloader that supports secure boot.
.TP
.BR "\-d" " or " "\-\-device"
Specifies the device bus-ID of the DASD. If the bus-ID starts with "0.0." this
prefix can be omitted and the four digit short notation can be used (e.g. 5000 is
the same as 0.0.5000).
.TP
.BR "\-b" " or " "\-\-bootprog"
Specifies an entry in the ECKD boot configuration by defining the IPL boot
program selector. If omitted, '0' is used.
.TP
.BR "\-\-brchr"
Specifies the block on the DASD where the boot record is located. If omitted,
0 is used. The specification comprises comma-separated values for cylinder, head,
and record: "--brchr C,H,R". Alternatively, specifying "0" or "auto" makes the
bootloader determine the boot record location from the volume label.
.TP
.BR "\-L" " or " "\-\-loadparm"
The loadparm for the eckd re-IPL target is not used to control the ECKD boot
configuration that is defined by the
.BR zipl (8)
boot menu. Instead it can be used to control higher level boot loaders
like GRUB. For more details refer to distribution specific documentation.
.TP
.BR "\-c" " or " "\-\-clear"
Controls whether memory is cleared on re-IPL. Possible values are 0 to
disable and 1 to enable memory clearing on re-IPL.
Memory clearing is supported if the "clear" attribute is present in
/sys/firmware/reipl/eckd/.
.PP
\fBExamples:\fP
.br
1. Next time reboot from the ECKD device with the bus-ID 0.0.7e78 and boot
program selector 0:
\fB# chreipl eckd 0.0.7e78\fP
2. Next time reboot from the ECKD device with the bus-ID 0.0.7e78 and boot
program selector 2:
\fB# chreipl eckd -d 0.0.7e78 -b 2\fP
3. Next time reboot from the ECKD device with the bus-ID 0.0.7e78 and tell
the bootloader that the bootrecord is located in Cylinder 3, Head 0, Record 1:
\fB# chreipl eckd -d 0.0.7e78 --brchr 3,0,1\fP
.SH fcp
Use the fcp re-IPL target for SCSI disks that are accessed by the hardware
using Fibre Channel Protocol (FCP) channels.

View File

@@ -18,15 +18,31 @@
#include "lib/util_file.h"
#include "ipl_tools.h"
static void nvme_dev_from_bdev(char *dev_name)
{
char *delim = strrchr(dev_name, 'n');
if (delim)
*delim = 0;
}
/*
* Return the fid of a device
*/
void nvme_fid_get(const char *device, char *fid)
{
char path[PATH_MAX], buf[FID_MAX_LEN];
char nvme_dev[NVME_DEV_MAX_LEN];
snprintf(path, PATH_MAX, "/sys/block/%s/device/device/function_id",
device);
/*
* An NVMe may present multiple namespaces and thus block devices, even
* before partitioning, so we need the nvme<NUM> part of the block
* device name to get to the PCI function ID.
*/
util_strlcpy(nvme_dev, device, sizeof(nvme_dev));
nvme_dev_from_bdev(nvme_dev);
snprintf(path, PATH_MAX, "/sys/class/nvme/%s/device/function_id", nvme_dev);
if (util_file_read_line(buf, FID_MAX_LEN, path))
ERR_EXIT_ERRNO("Could not read from \"%s\"", path);

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# z/VM IUCV HVC device driver -- Edit z/VM user ID filter
#

View File

@@ -2,17 +2,6 @@ include ../common.mak
lib = libap.a
check-dep-lock:
touch check-dep-lock
ifneq (${HAVE_LOCKFILE},0)
$(call check_dep, \
"libap", \
"lockfile.h", \
"liblockfile-devel", \
"HAVE_LOCKFILE=0")
ALL_CPPFLAGS += -DHAVE_LOCKFILE
endif
check-dep-json:
touch check-dep-json
ifneq (${HAVE_JSONC},0)
@@ -29,7 +18,7 @@ objects = ap.o
$(lib): $(objects)
$(objects): check-dep-lock check-dep-json
$(objects): check-dep-json
install: all

View File

@@ -22,13 +22,10 @@
#include <json-c/json.h>
#endif /* HAVE_JSONC */
#ifdef HAVE_LOCKFILE
#include <lockfile.h>
#endif /* HAVE_LOCKFILE */
#include "lib/ap.h"
#include "lib/util_file.h"
#include "lib/util_libc.h"
#include "lib/util_lockfile.h"
#include "lib/util_panic.h"
#include "lib/util_path.h"
#include "lib/util_udev.h"
@@ -701,33 +698,28 @@ void ap_list_remove_all(struct util_list *list)
}
}
#ifdef HAVE_LOCKFILE
static int ap_lockfile_create(int flags)
{
return lockfile_create(AP_LOCKFILE, AP_LOCK_RETRIES, flags);
}
/**
* Acquire the ap config lock using this process PID (L_PID)
* Acquire the ap config lock using this Process ID
*
* @retval 0 Lock acquired on behalf of this process
*
* @retval 0 Lock successfully acquired on behalf of L_PID
* @retval != 0 Error, lock was not obtained
*/
int ap_get_lock(void)
{
return ap_lockfile_create(L_PID);
return util_lockfile_lock(AP_LOCKFILE, AP_LOCK_RETRIES);
}
/**
* Acquire the ap config lock using the parent process PID (L_PPID) -- intended
* for use by the mdevctl callout ap-check utility
* Acquire the ap config lock using the Parent Process ID -- intended for use
* by the mdevctl callout ap-check utility
*
* @retval 0 Lock successfully acquired on behalf of L_PPID
* @retval 0 Lock acquired on behalf of parent process
* @retval != 0 Error, lock was not obtained
*/
int ap_get_lock_callout(void)
{
return ap_lockfile_create(L_PPID);
return util_lockfile_parent_lock(AP_LOCKFILE, AP_LOCK_RETRIES);
}
/**
@@ -738,23 +730,10 @@ int ap_get_lock_callout(void)
*/
int ap_release_lock(void)
{
return lockfile_remove(AP_LOCKFILE);
}
#else
/* If no liblockfile, actions are performed without acquiring the file lock */
int ap_get_lock(void)
{
return 0;
return util_lockfile_release(AP_LOCKFILE);
}
int ap_get_lock_callout(void)
int ap_release_lock_callout(void)
{
return 0;
return util_lockfile_parent_release(AP_LOCKFILE);
}
int ap_release_lock(void)
{
return 0;
}
#endif /* HAVE_LOCKFILE */

View File

@@ -15,7 +15,9 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <unistd.h>
#include <string.h>
#include "lib/dasd_base.h"
@@ -27,11 +29,13 @@
#define RUN_IOCTL(fd, req, argp) \
do { \
if (ioctl(fd, req, argp) != 0) { \
int err = errno; \
if (err != EBADF) \
int rc = ioctl(fd, req, argp); \
if (rc != 0) { \
if (rc == -1) \
rc = errno; \
if (rc != EBADF) \
dasd_close_device(fd); \
return err; \
return rc; \
} \
} while (0)
@@ -321,3 +325,159 @@ int dasd_disk_release(const char *device)
return 0;
}
/*
* Unconditionally reserve DASD disk
*
* An existing reserve lock is lifted (steal lock) and the device
* is reserved.
*
* @param[in] device node device node's name
*
* @retval 0 in case of success
* @retval errno in case of failure
*/
int dasd_slock(const char *device)
{
int fd;
fd = dasd_open_device(device, O_RDONLY);
RUN_IOCTL(fd, BIODASDSLCK, NULL);
dasd_close_device(fd);
return 0;
}
/*
* Get the caching algorithm used for the channel programs of this device.
*
* @param[in] device node device node's name
* @param[out] attrib_data pointer to dasd attrib data with:
* 'cache' is the caching mode
* 'no_cyl' the number of cylinders to be cached.
*
* @retval 0 in case of success
* @retval errno in case of failure
*/
int dasd_get_cache(const char *device, attrib_data_t *attrib_data)
{
int fd;
fd = dasd_open_device(device, O_RDONLY);
RUN_IOCTL(fd, BIODASDGATTR, attrib_data);
dasd_close_device(fd);
return 0;
}
/*
* Set the caching algorithm used for the channel programs of this device.
*
* @param[in] device node device node's name
* @param[in] attrib_data pointer to dasd attrib data with:
* 'cache' is the caching mode
* 'no_cyl' the number of cylinders to be cached.
*
* @retval 0 in case of success
* @retval errno in case of failure
*/
int dasd_set_cache(const char *device, attrib_data_t *attrib_data)
{
int fd;
fd = dasd_open_device(device, O_RDONLY);
RUN_IOCTL(fd, BIODASDSATTR, attrib_data);
dasd_close_device(fd);
return 0;
}
/*
* Get reserve status of device.
*
* @param[in] device node device node's name
*
* @retval errno in case of failure
* @retval 0 unreserved
* @retval 1 implicit reserved
* @retval 2 other reservation
* @retval 3 reserved
*/
int dasd_query_reserve(const char *device)
{
struct dasd_snid_ioctl_data snid = { 0 };
int fd;
fd = dasd_open_device(device, O_RDONLY);
RUN_IOCTL(fd, BIODASDSNID, &snid);
dasd_close_device(fd);
return snid.data.path_state.reserve;
}
/*
* Get and print the profiling info of the device.
*
* @param[in] device node device node's name
* @param[in] dasd_profile_info pointer to dasd profile info
*
* @retval 0 in case of success
* @retval errno in case of failure
*/
int dasd_profile(const char *device, dasd_profile_info_t *dasd_profile_info)
{
int fd;
fd = dasd_open_device(device, O_RDONLY);
RUN_IOCTL(fd, BIODASDPRRD, dasd_profile_info);
dasd_close_device(fd);
return 0;
}
/*
* Reset the profiling counters of the device.
*
* @param[in] device node device node's name
*
* @retval 0 in case of success
* @retval errno in case of failure
*/
int dasd_reset_profile(const char *device)
{
int fd;
fd = dasd_open_device(device, O_RDONLY);
RUN_IOCTL(fd, BIODASDPRRST, NULL);
dasd_close_device(fd);
return 0;
}
/*
* Initiate the swap of a copy pairs primary,secondary relation.
* The old secondary will become the new primary and vice versa.
*
* @param[in] device node device node's name
* @param[in] copy_pair data pointer to dasd copypair data with:
* 'primary' old primary, becoming secondary
* 'secondary' old secondary, becoming primary.
*
* @retval errno in case of failure
* @retval 0 in case of success
* @retval 1 swap data invalid
* @retval 2 no active device found
* @retval 3 wrong primary specified
* @retval 4 secondary device not found
* @retval 5 swap already running
*/
int dasd_copy_swap(const char *device, struct dasd_copypair_swap_data *data)
{
int fd;
fd = dasd_open_device(device, O_RDONLY);
RUN_IOCTL(fd, BIODASDPPRCSWAP, data);
dasd_close_device(fd);
return 0;
}

View File

@@ -5,21 +5,12 @@ include ../common.mak
LIB := libpv.a
ifneq ($(shell sh -c 'command -v pkg-config'),)
GLIB2_CFLAGS := $(shell pkg-config --silence-errors --cflags glib-2.0)
GLIB2_LIBS := $(shell pkg-config --silence-errors --libs glib-2.0)
LIBCRYPTO_CFLAGS := $(shell pkg-config --silence-errors --cflags libcrypto openssl)
LIBCRYPTO_LIBS := $(shell pkg-config --silence-errors --libs libcrypto openssl)
LIBCURL_CFLAGS := $(shell pkg-config --silence-errors --cflags libcurl)
LIBCURL_LIBS := $(shell pkg-config --silence-errors --libs libcurl)
else
GLIB2_CFLAGS := -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
GLIB2_LIBS := -lglib-2.0
LIBCRYPTO_CFLAGS :=
LIBCRYPTO_LIBS := -lcrypto -lssl
LIBCURL_CFLAGS := -I/usr/include/s390x-linux-gnu
LIBCURL_LIBS := -lcurl
endif
GLIB2_CFLAGS := $(shell $(PKG_CONFIG) --silence-errors --cflags glib-2.0)
GLIB2_LIBS := $(shell $(PKG_CONFIG) --silence-errors --libs glib-2.0)
LIBCRYPTO_CFLAGS := $(shell $(PKG_CONFIG) --silence-errors --cflags libcrypto)
LIBCRYPTO_LIBS := $(shell $(PKG_CONFIG) --silence-errors --libs libcrypto)
LIBCURL_CFLAGS := $(shell $(PKG_CONFIG) --silence-errors --cflags libcurl)
LIBCURL_LIBS := $(shell $(PKG_CONFIG) --silence-errors --libs libcurl)
LDLIBS += $(GLIB2_LIBS) $(LIBCRYPTO_LIBS) $(LIBCURL_LIBS)
WARNINGS := -Wall -Wextra -Wshadow \
@@ -28,7 +19,6 @@ WARNINGS := -Wall -Wextra -Wshadow \
-Wno-long-long -Wuninitialized -Wconversion -Wstrict-prototypes \
-Wpointer-arith -Wno-error=inline \
-Wno-unused-function -Wno-unused-parameter -Wno-unused-variable \
-Werror \
$(NULL)
ALL_CFLAGS += -std=gnu11 \

View File

@@ -290,7 +290,9 @@ static char *pv_X509_NAME_oneline(const X509_NAME *name)
long len;
if (X509_NAME_print_ex(key_bio, name, 0, XN_FLAG_RFC2253) == -1) {
g_warning(_("Cannot receive X509-NAME from CRL: %s"), pv_get_openssl_error());
g_autofree char *openssl_err_msg = pv_get_openssl_errors();
g_warning(_("Cannot receive X509-NAME from CRL: %s"), openssl_err_msg);
return NULL;
}
@@ -790,7 +792,7 @@ int pv_store_set_verify_param(X509_STORE *store, GError **error)
return 0;
error:
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
g_set_error(error, PV_CERT_ERROR, PV_CERT_ERROR_INTERNAL,
_("X509 store initialization failed"));
return -1;
}
@@ -1375,14 +1377,14 @@ int pv_check_chain_parameters(const STACK_OF_X509 *chain, GError **error)
ca_x509_subject = X509_get_subject_name(ca);
if (!ca_x509_subject) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
g_set_error(error, PV_CERT_ERROR, PV_CERT_ERROR_INTERNAL,
_("subject of the root CA cannot be retrieved"));
return -1;
}
ca_subject = pv_X509_NAME_oneline(ca_x509_subject);
if (!ca_subject) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
g_set_error(error, PV_CERT_ERROR, PV_CERT_ERROR_INTERNAL,
_("subject name of the root CA cannot be retrieved"));
return -1;
}
@@ -1476,11 +1478,11 @@ static STACK_OF_X509 *get_ibm_signing_certs(STACK_OF_X509 *certs, GError **error
ibm_signing_certs = pv_remove_ibm_signing_certs(certs);
ibm_signing_certs_count = sk_X509_num(ibm_signing_certs);
if (ibm_signing_certs_count < 1) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_NO_IBM_Z_SIGNING_KEY,
g_set_error(error, PV_CERT_ERROR, PV_CERT_ERROR_NO_IBM_Z_SIGNING_KEY,
_("Specify at least one IBM Z signing key"));
return NULL;
} else if (ibm_signing_certs_count > 1) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_NO_IBM_Z_SIGNING_KEY,
g_set_error(error, PV_CERT_ERROR, PV_CERT_ERROR_NO_IBM_Z_SIGNING_KEY,
_("Specify only one IBM Z signing key"));
return NULL;
}
@@ -1511,7 +1513,7 @@ static gboolean download_crls(X509_STORE *trusted, PvCertWithPathList *host_key_
X509_CRL *crl = sk_X509_CRL_value(downloaded_ibm_signing_crls, i);
if (X509_STORE_add_crl(trusted, crl) != 1) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
g_set_error(error, PV_CERT_ERROR, PV_CERT_ERROR_INTERNAL,
_("failed to load CRL"));
return FALSE;
}

View File

@@ -19,18 +19,18 @@
#include "libpv/glib-helper.h"
#include "libpv/hash.h"
const char *pv_get_openssl_error(void)
char *pv_get_openssl_errors(void)
{
const char *ret;
BIO *bio;
char *ret;
char *buf;
BIO *bio;
long len;
bio = BIO_new(BIO_s_mem());
ERR_print_errors(bio);
len = BIO_get_mem_data(bio, &buf);
if (len < 0)
ret = "Cannot receive OpenSSL error message.";
if (len <= 0 || !buf)
ret = g_strdup("Cannot receive OpenSSL error message.");
else
ret = g_strndup(buf, (size_t)len);
BIO_free(bio);
@@ -276,7 +276,7 @@ int64_t pv_gcm_decrypt(GBytes *cipher, GBytes *aad, GBytes *tag, const PvCipherP
}
GBytes *pv_hkdf_extract_and_expand(size_t derived_key_len, GBytes *key, GBytes *salt, GBytes *info,
const EVP_MD *md, G_GNUC_UNUSED GError **error)
const EVP_MD *md, GError **error)
{
const unsigned char *salt_data, *key_data, *info_data;
g_autoptr(EVP_PKEY_CTX) ctx = NULL;
@@ -354,7 +354,6 @@ GBytes *pv_hkdf_extract_and_expand(size_t derived_key_len, GBytes *key, GBytes *
if (EVP_PKEY_derive(ctx, derived_key, &derived_key_len) != 1) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_HKDF_FAIL,
"FAILED to derive key via HKDF");
printf("%s\n", pv_get_openssl_error());
return NULL;
}

View File

@@ -168,12 +168,14 @@ GBytes *pv_file_get_content_as_secure_bytes(const char *filename)
return pv_sec_gbytes_new_take(g_steal_pointer(&data), data_size);
}
void *pv_gbytes_memcpy(void *dst, size_t dst_size, GBytes *src)
void *pv_gbytes_memcpy(void *dst, size_t dst_size, GBytes *src, size_t *copied)
{
size_t src_size;
const void *src_data = g_bytes_get_data(src, &src_size);
if (dst_size < src_size)
return NULL;
if (copied)
*copied = src_size;
return memcpy(dst, src_data, src_size);
}

View File

@@ -97,8 +97,10 @@ HMAC_CTX *pv_hmac_ctx_new(GBytes *key, const EVP_MD *md, GError **error)
key_data = g_bytes_get_data(key, &key_size);
if (HMAC_Init_ex(ctx, key_data, (int)key_size, md, NULL) != 1) {
g_autofree char *openssl_err_msg = pv_get_openssl_errors();
g_set_error(error, PV_HASH_ERROR, PV_HASH_ERROR_INTERNAL,
"unable to create HMAC context: %s", pv_get_openssl_error());
"unable to create HMAC context: %s", openssl_err_msg);
return NULL;
}
return g_steal_pointer(&ctx);
@@ -110,8 +112,10 @@ int pv_hmac_ctx_update_raw(HMAC_CTX *ctx, const void *buf, size_t size, GError *
return 0;
if (HMAC_Update(ctx, buf, size) != 1) {
g_autofree char *openssl_err_msg = pv_get_openssl_errors();
g_set_error(error, PV_HASH_ERROR, PV_HASH_ERROR_INTERNAL,
"unable to add data to HMAC context: %s", pv_get_openssl_error());
"unable to add data to HMAC context: %s", openssl_err_msg);
return -1;
}
return 0;
@@ -139,8 +143,10 @@ GBytes *pv_hamc_ctx_finalize(HMAC_CTX *ctx, GError **error)
hmac = g_malloc0((unsigned int)md_size);
if (HMAC_Final(ctx, hmac, &hmac_size) != 1) {
g_autofree char *openssl_err_msg = pv_get_openssl_errors();
g_set_error(error, PV_HASH_ERROR, PV_HASH_ERROR_INTERNAL,
"unable to calculate HMAC: %s", pv_get_openssl_error());
"unable to calculate HMAC: %s", openssl_err_msg);
return NULL;
}
return g_bytes_new_take(g_steal_pointer(&hmac), hmac_size);

View File

@@ -174,6 +174,20 @@ static OSSL_FUNC_keymgmt_settable_params_fn
sk_prov_keymgmt_rsa_pss_settable_params;
static OSSL_FUNC_keymgmt_settable_params_fn
sk_prov_keymgmt_ec_settable_params;
#ifdef OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX
static OSSL_FUNC_keymgmt_export_types_ex_fn
sk_prov_keymgmt_rsa_export_types_ex;
static OSSL_FUNC_keymgmt_export_types_ex_fn
sk_prov_keymgmt_rsa_pss_export_types_ex;
static OSSL_FUNC_keymgmt_export_types_ex_fn
sk_prov_keymgmt_ec_export_types_ex;
static OSSL_FUNC_keymgmt_import_types_ex_fn
sk_prov_keymgmt_rsa_import_types_ex;
static OSSL_FUNC_keymgmt_import_types_ex_fn
sk_prov_keymgmt_rsa_pss_import_types_ex;
static OSSL_FUNC_keymgmt_import_types_ex_fn
sk_prov_keymgmt_ec_import_types_ex;
#else
static OSSL_FUNC_keymgmt_export_types_fn
sk_prov_keymgmt_rsa_export_types;
static OSSL_FUNC_keymgmt_export_types_fn
@@ -185,6 +199,7 @@ static OSSL_FUNC_keymgmt_import_types_fn
static OSSL_FUNC_keymgmt_import_types_fn
sk_prov_keymgmt_rsa_pss_import_types;
static OSSL_FUNC_keymgmt_import_types_fn sk_prov_keymgmt_ec_import_types;
#endif
static OSSL_FUNC_keyexch_newctx_fn sk_prov_keyexch_ec_newctx;
static OSSL_FUNC_keyexch_dupctx_fn sk_prov_keyexch_ec_dupctx;
@@ -552,6 +567,33 @@ static const OSSL_PARAM *sk_prov_cached_params_build(
return provctx->cached_parms[index];
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
static bool sk_prov_check_uint_param(const OSSL_PARAM params[],
const char *param_name,
const struct sk_prov_key *key,
int key_type,
unsigned int expected_value)
{
const OSSL_PARAM *p;
unsigned int value;
if (key == NULL)
return true;
if (key->type != key_type)
return true;
p = OSSL_PARAM_locate_const(params, param_name);
if (p == NULL)
return true;
if (OSSL_PARAM_get_uint(p, &value) != 1)
return true;
return value == expected_value;
}
#pragma GCC diagnostic pop
static struct sk_prov_op_ctx *sk_prov_op_newctx(struct sk_prov_ctx *provctx,
const char *propq,
int type)
@@ -850,6 +892,20 @@ static int sk_prov_asym_op_set_ctx_params(void *vctx, const OSSL_PARAM params[])
for (p = params; p != NULL && p->key != NULL; p++)
sk_debug_op_ctx(ctx, "param: %s", p->key);
#ifdef OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION
/* OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION is for RSA decrypt only */
if (!sk_prov_check_uint_param(params,
OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION,
ctx->key, EVP_PKEY_RSA, 0) ||
!sk_prov_check_uint_param(params,
OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION,
ctx->key, EVP_PKEY_RSA_PSS, 0)) {
put_error_op_ctx(ctx, SK_PROV_ERR_INVALID_PARAM,
"Implicit rejection is not supported");
return 0;
}
#endif
default_set_params_fn = (OSSL_FUNC_asym_cipher_set_ctx_params_fn *)
sk_prov_get_default_asym_func(ctx->provctx,
ctx->type,
@@ -1125,6 +1181,14 @@ static int sk_prov_asym_op_decrypt_init(void *vctx, void *vkey,
struct sk_prov_op_ctx *ctx = vctx;
struct sk_prov_key *key = vkey;
const OSSL_PARAM *p;
#ifdef OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION
unsigned int implicit_rejection = 0;
OSSL_PARAM set_params[] = {
OSSL_PARAM_uint(OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION,
&implicit_rejection),
OSSL_PARAM_END
};
#endif
if (ctx == NULL || key == NULL)
return 0;
@@ -1133,6 +1197,20 @@ static int sk_prov_asym_op_decrypt_init(void *vctx, void *vkey,
for (p = params; p != NULL && p->key != NULL; p++)
sk_debug_op_ctx(ctx, "param: %s", p->key);
#ifdef OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION
/* OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION is for RSA decrypt only */
if (!sk_prov_check_uint_param(params,
OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION,
key, EVP_PKEY_RSA, 0) ||
!sk_prov_check_uint_param(params,
OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION,
key, EVP_PKEY_RSA_PSS, 0)) {
put_error_op_ctx(ctx, SK_PROV_ERR_INVALID_PARAM,
"Implicit rejection is not supported");
return 0;
}
#endif
default_decrypt_init_fn = (OSSL_FUNC_asym_cipher_decrypt_init_fn *)
sk_prov_get_default_asym_func(ctx->provctx,
ctx->type,
@@ -1155,6 +1233,26 @@ static int sk_prov_asym_op_decrypt_init(void *vctx, void *vkey,
return 0;
}
#ifdef OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION
if ((key->type == EVP_PKEY_RSA || key->type == EVP_PKEY_RSA_PSS) &&
key->secure_key != NULL) {
/*
* By default, implicit rejection is enabled for the default
* provider. We currently do not support implicit rejection with
* secure keys, so disable implicit rejection in the default
* provider operation context to report its status correctly
* with get-params.
*/
implicit_rejection = 0;
if (!sk_prov_asym_op_set_ctx_params(ctx, set_params)) {
sk_debug_op_ctx(ctx,
"ERROR: sk_prov_asym_op_set_ctx_params "
"failed");
return 0;
}
}
#endif
return 1;
}
@@ -1361,6 +1459,16 @@ static int sk_prov_sign_op_set_ctx_params(void *vctx, const OSSL_PARAM params[])
for (p = params; p != NULL && p->key != NULL; p++)
sk_debug_op_ctx(ctx, "param: %s", p->key);
#ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
/* OSSL_SIGNATURE_PARAM_NONCE_TYPE is used for EC sign ops only */
if (!sk_prov_check_uint_param(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE,
ctx->key, EVP_PKEY_EC, 0)) {
put_error_op_ctx(ctx, SK_PROV_ERR_INVALID_PARAM,
"Deterministic signature is not supported");
return 0;
}
#endif
default_set_params_fn = (OSSL_FUNC_signature_set_ctx_params_fn *)
sk_prov_get_default_sign_func(ctx->provctx,
ctx->type, OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS);
@@ -1701,6 +1809,11 @@ static int sk_prov_sign_op_get_pss_saltlen(struct sk_prov_op_ctx *ctx,
salt_len = max_saltlen;
else if (strcmp(saltlen, OSSL_PKEY_RSA_PSS_SALT_LEN_AUTO) == 0)
salt_len = max_saltlen;
#ifdef OSSL_PKEY_RSA_PSS_SALT_LEN_AUTO_DIGEST_MAX
else if (strcmp(saltlen,
OSSL_PKEY_RSA_PSS_SALT_LEN_AUTO_DIGEST_MAX) == 0)
salt_len = MIN(max_saltlen, EVP_MD_size(mgf_md));
#endif
else
salt_len = atoi(saltlen);
@@ -1729,6 +1842,16 @@ static int sk_prov_sign_op_sign_init(void *vctx, void *vkey,
for (p = params; p != NULL && p->key != NULL; p++)
sk_debug_op_ctx(ctx, "param: %s", p->key);
#ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
/* OSSL_SIGNATURE_PARAM_NONCE_TYPE is used for EC sign ops only */
if (!sk_prov_check_uint_param(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE,
key, EVP_PKEY_EC, 0)) {
put_error_op_ctx(ctx, SK_PROV_ERR_INVALID_PARAM,
"Deterministic signature is not supported");
return 0;
}
#endif
default_sign_init_fn = (OSSL_FUNC_signature_sign_init_fn *)
sk_prov_get_default_sign_func(ctx->provctx,
ctx->type,
@@ -1955,6 +2078,16 @@ static int sk_prov_sign_op_digest_sign_init(struct sk_prov_op_ctx *ctx,
for (p = params; p != NULL && p->key != NULL; p++)
sk_debug_op_ctx(ctx, "param: %s", p->key);
#ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
/* OSSL_SIGNATURE_PARAM_NONCE_TYPE is used for EC sign ops only */
if (!sk_prov_check_uint_param(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE,
key, EVP_PKEY_EC, 0)) {
put_error_op_ctx(ctx, SK_PROV_ERR_INVALID_PARAM,
"Deterministic signature is not supported");
return 0;
}
#endif
default_digest_sign_init_fn =
(OSSL_FUNC_signature_digest_sign_init_fn *)
sk_prov_get_default_sign_func(ctx->provctx,
@@ -2829,14 +2962,14 @@ static const OSSL_PARAM sk_prov_imexport_types[] = {
OSSL_PARAM_END
};
static const OSSL_PARAM *sk_prov_keymgmt_export_types(int selection,
int pkey_type)
static const OSSL_PARAM *sk_prov_keymgmt_export_types(
struct sk_prov_ctx *provctx,
int selection,
int pkey_type)
{
OSSL_FUNC_keymgmt_export_types_fn *default_export_types_fn;
const OSSL_PARAM *default_parms = NULL, *params;
struct sk_prov_ctx *provctx;
provctx = OSSL_PROVIDER_get0_provider_ctx(sk_prov_securekey_provider);
if (provctx == NULL)
return NULL;
@@ -2864,14 +2997,14 @@ static const OSSL_PARAM *sk_prov_keymgmt_export_types(int selection,
sk_prov_imexport_types);
}
static const OSSL_PARAM *sk_prov_keymgmt_import_types(int selection,
int pkey_type)
static const OSSL_PARAM *sk_prov_keymgmt_import_types(
struct sk_prov_ctx *provctx,
int selection,
int pkey_type)
{
OSSL_FUNC_keymgmt_import_types_fn *default_import_types_fn;
const OSSL_PARAM *default_parms = NULL, *params;
struct sk_prov_ctx *provctx;
provctx = OSSL_PROVIDER_get0_provider_ctx(sk_prov_securekey_provider);
if (provctx == NULL)
return NULL;
@@ -3219,15 +3352,39 @@ static const OSSL_PARAM *sk_prov_keymgmt_rsa_settable_params(void *vprovctx)
return sk_prov_keymgmt_settable_params(provctx, EVP_PKEY_RSA);
}
#ifdef OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX
static const OSSL_PARAM *sk_prov_keymgmt_rsa_export_types_ex(void *vprovctx,
int selection)
{
struct sk_prov_ctx *provctx = vprovctx;
return sk_prov_keymgmt_export_types(provctx, selection, EVP_PKEY_RSA);
}
static const OSSL_PARAM *sk_prov_keymgmt_rsa_import_types_ex(void *vprovctx,
int selection)
{
struct sk_prov_ctx *provctx = vprovctx;
return sk_prov_keymgmt_import_types(provctx, selection, EVP_PKEY_RSA);
}
#else
static const OSSL_PARAM *sk_prov_keymgmt_rsa_export_types(int selection)
{
return sk_prov_keymgmt_export_types(selection, EVP_PKEY_RSA);
struct sk_prov_ctx *provctx =
OSSL_PROVIDER_get0_provider_ctx(sk_prov_securekey_provider);
return sk_prov_keymgmt_export_types(provctx, selection, EVP_PKEY_RSA);
}
static const OSSL_PARAM *sk_prov_keymgmt_rsa_import_types(int selection)
{
return sk_prov_keymgmt_import_types(selection, EVP_PKEY_RSA);
struct sk_prov_ctx *provctx =
OSSL_PROVIDER_get0_provider_ctx(sk_prov_securekey_provider);
return sk_prov_keymgmt_import_types(provctx, selection, EVP_PKEY_RSA);
}
#endif
static void *sk_prov_keymgmt_rsa_gen_init(void *vprovctx, int selection,
const OSSL_PARAM params[])
@@ -3289,15 +3446,43 @@ static const OSSL_PARAM *sk_prov_keymgmt_rsa_pss_settable_params(void *vprovctx)
return sk_prov_keymgmt_settable_params(provctx, EVP_PKEY_RSA_PSS);
}
#ifdef OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX
static const OSSL_PARAM *sk_prov_keymgmt_rsa_pss_export_types_ex(void *vprovctx,
int selection)
{
struct sk_prov_ctx *provctx = vprovctx;
return sk_prov_keymgmt_export_types(provctx, selection,
EVP_PKEY_RSA_PSS);
}
static const OSSL_PARAM *sk_prov_keymgmt_rsa_pss_import_types_ex(void *vprovctx,
int selection)
{
struct sk_prov_ctx *provctx = vprovctx;
return sk_prov_keymgmt_import_types(provctx, selection,
EVP_PKEY_RSA_PSS);
}
#else
static const OSSL_PARAM *sk_prov_keymgmt_rsa_pss_export_types(int selection)
{
return sk_prov_keymgmt_export_types(selection, EVP_PKEY_RSA_PSS);
struct sk_prov_ctx *provctx =
OSSL_PROVIDER_get0_provider_ctx(sk_prov_securekey_provider);
return sk_prov_keymgmt_export_types(provctx, selection,
EVP_PKEY_RSA_PSS);
}
static const OSSL_PARAM *sk_prov_keymgmt_rsa_pss_import_types(int selection)
{
return sk_prov_keymgmt_import_types(selection, EVP_PKEY_RSA_PSS);
struct sk_prov_ctx *provctx =
OSSL_PROVIDER_get0_provider_ctx(sk_prov_securekey_provider);
return sk_prov_keymgmt_import_types(provctx, selection,
EVP_PKEY_RSA_PSS);
}
#endif
static void *sk_prov_keymgmt_rsa_pss_gen_init(void *vprovctx, int selection,
const OSSL_PARAM params[])
@@ -3372,15 +3557,39 @@ static const OSSL_PARAM *sk_prov_keymgmt_ec_settable_params(void *vprovctx)
return sk_prov_keymgmt_settable_params(provctx, EVP_PKEY_EC);
}
#ifdef OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX
static const OSSL_PARAM *sk_prov_keymgmt_ec_export_types_ex(void *vprovctx,
int selection)
{
struct sk_prov_ctx *provctx = vprovctx;
return sk_prov_keymgmt_export_types(provctx, selection, EVP_PKEY_EC);
}
static const OSSL_PARAM *sk_prov_keymgmt_ec_import_types_ex(void *vprovctx,
int selection)
{
struct sk_prov_ctx *provctx = vprovctx;
return sk_prov_keymgmt_import_types(provctx, selection, EVP_PKEY_EC);
}
#else
static const OSSL_PARAM *sk_prov_keymgmt_ec_export_types(int selection)
{
return sk_prov_keymgmt_export_types(selection, EVP_PKEY_EC);
struct sk_prov_ctx *provctx =
OSSL_PROVIDER_get0_provider_ctx(sk_prov_securekey_provider);
return sk_prov_keymgmt_export_types(provctx, selection, EVP_PKEY_EC);
}
static const OSSL_PARAM *sk_prov_keymgmt_ec_import_types(int selection)
{
return sk_prov_keymgmt_import_types(selection, EVP_PKEY_EC);
struct sk_prov_ctx *provctx =
OSSL_PROVIDER_get0_provider_ctx(sk_prov_securekey_provider);
return sk_prov_keymgmt_import_types(provctx, selection, EVP_PKEY_EC);
}
#endif
static void *sk_prov_keymgmt_ec_gen_init(void *vprovctx, int selection,
const OSSL_PARAM params[])
@@ -4530,11 +4739,21 @@ static const OSSL_DISPATCH sk_prov_rsa_keymgmt_functions[] = {
/* Import and export routines */
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))sk_prov_keymgmt_export },
#ifdef OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX,
(void (*)(void))sk_prov_keymgmt_rsa_export_types_ex },
#else
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES,
(void (*)(void))sk_prov_keymgmt_rsa_export_types },
#endif
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))sk_prov_keymgmt_import },
#ifdef OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES_EX,
(void (*)(void))sk_prov_keymgmt_rsa_import_types_ex },
#else
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES,
(void (*)(void))sk_prov_keymgmt_rsa_import_types },
#endif
/* No copy function, OpenSSL will use export/import to copy instead */
{ 0, NULL }
@@ -4579,11 +4798,21 @@ static const OSSL_DISPATCH sk_prov_rsapss_keymgmt_functions[] = {
/* Import and export routines */
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))sk_prov_keymgmt_export },
#ifdef OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX,
(void (*)(void))sk_prov_keymgmt_rsa_pss_export_types_ex },
#else
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES,
(void (*)(void))sk_prov_keymgmt_rsa_pss_export_types },
#endif
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))sk_prov_keymgmt_import },
#ifdef OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES_EX,
(void (*)(void))sk_prov_keymgmt_rsa_pss_import_types_ex },
#else
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES,
(void (*)(void))sk_prov_keymgmt_rsa_pss_import_types },
#endif
/* No copy function, OpenSSL will use export/import to copy instead */
{ 0, NULL }
@@ -4628,11 +4857,21 @@ static const OSSL_DISPATCH sk_prov_ec_keymgmt_functions[] = {
/* Import and export routines */
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))sk_prov_keymgmt_export },
#ifdef OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX,
(void (*)(void))sk_prov_keymgmt_ec_export_types_ex },
#else
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES,
(void (*)(void))sk_prov_keymgmt_ec_export_types },
#endif
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))sk_prov_keymgmt_import },
#ifdef OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES_EX,
(void (*)(void))sk_prov_keymgmt_ec_import_types_ex },
#else
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES,
(void (*)(void))sk_prov_keymgmt_ec_import_types },
#endif
/* No copy function, OpenSSL will use export/import to copy instead */
{ 0, NULL }

View File

@@ -776,6 +776,10 @@ int SK_UTIL_build_ecdsa_signature(const unsigned char *raw_sig,
bn_s = NULL;
der_len = i2d_ECDSA_SIG(ec_sig, NULL);
if (der_len <= 0) {
rc = -EIO;
goto out;
}
if (sig == NULL) {
*sig_len = der_len;
@@ -788,13 +792,14 @@ int SK_UTIL_build_ecdsa_signature(const unsigned char *raw_sig,
memset(sig, 0, *sig_len);
der = sig;
*sig_len = i2d_ECDSA_SIG(ec_sig, &der);
if (*sig_len == 0) {
der_len = i2d_ECDSA_SIG(ec_sig, &der);
if (der_len <= 0) {
rc = -EIO;
goto out;
}
*sig_len = der_len;
out:
if (ec_sig != NULL)
ECDSA_SIG_free(ec_sig);

View File

@@ -107,13 +107,12 @@ const char *util_arch_machine_type_to_str(int type)
*/
unsigned long util_arch_hsa_maxsize(void)
{
unsigned long size = HSA_SIZE_32M;
int type;
type = util_arch_machine_type();
if (type != UTIL_ARCH_MACHINE_TYPE_UNKNOWN &&
type >= UTIL_ARCH_MACHINE_TYPE_Z15)
size = HSA_SIZE_512M;
return size;
switch (util_arch_machine_type()) {
case UTIL_ARCH_MACHINE_TYPE_Z15:
case UTIL_ARCH_MACHINE_TYPE_Z15_T02:
case UTIL_ARCH_MACHINE_TYPE_Z16:
return HSA_SIZE_512M;
default:
return HSA_SIZE_32M;
}
}

301
libutil/util_lockfile.c Normal file
View File

@@ -0,0 +1,301 @@
/*
* util - Utility function library
*
* Created file-based locks
*
* Copyright IBM Corp. 2022
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include "lib/util_libc.h"
#include "lib/util_lockfile.h"
#include "lib/util_panic.h"
#define WAITPID 120 /* Time to wait for pid to be written */
#define WAITINC 5 /* Additional time to wait each retry */
#define MAXWAIT 60 /* Maximum wait between retries */
#define BUFSIZE 40 /* Buffer must be large enough to fit pid string */
/**
* Check if there is a process that exists with the specified identifier.
*
* @param[in] pid Process Identifier to check
*
* @retval true Process exists or we lack privelege to check
* @retval false Process does not exist
*/
static bool pid_exists(int pid)
{
int rc;
/* Use sig 0 to determine if the owner is still alive */
rc = kill(pid, 0);
if (rc != 0) {
switch (errno) {
case EPERM:
/* Privilege issue, just assume PID exists */
break;
case ESRCH:
/* PID does not exist, this lock is stale */
return false;
default:
util_assert(false, "Unexpected return from kill: %d\n", rc);
break;
}
}
return true;
}
/**
* Check for an existing lock that is deemed stale (either the associated PID
* is gone or no PID has been written to the file in a reasonable timeframe).
* In the case a stale lock is found, remove it.
*
* @param[in] lockfile Path to the lock file
*
* @retval 0 Either no lock or stale lock was found and removed
* @retval 1 Lock is held by another PID and is not stale
*/
static int handle_stale_lock(char *lockfile)
{
int fd, rc, pid, len;
struct stat info;
char buf[BUFSIZE];
time_t curr;
fd = open(lockfile, O_RDONLY);
if (fd >= 0) {
/* Lock exists, see who owns it */
len = read(fd, buf, sizeof(buf));
if (len > 0) {
buf[len] = 0; /* Ensure null terminated string */
pid = atoi(buf);
if (!pid_exists(pid)) {
/* Stale lock detected unlink and retry now */
close(fd);
unlink(lockfile);
return 0;
} else if (pid != 0) {
/* Lock is held by an active pid, delay */
close(fd);
return 1;
}
/*
* If we reach this point, the PID was 0 which is
* unexpected. Proceed under the assumption that the
* proper PID hasn't been written yet.
*/
}
/*
* PID hasn't been written yet? Either a bad lock or a very
* new one.
*/
time(&curr);
rc = fstat(fd, &info);
close(fd);
if (rc != 0) {
/* Can't read file anymore, retry now */
return 0;
}
if (curr > info.st_mtime + WAITPID) {
/*
* PID should be in the file within 2 minutes,
* something went wrong. Treat as stale.
*/
unlink(lockfile);
return 0;
}
/* Otherwise, assume file was newly created and delay */
return 1;
}
/* Couldn't open, try again immediately */
return 0;
}
/**
* Attempt to create a lockfile at the specified path.
*
* @param[in] lockfile Path to the lock file
* @param[in] retries Number of times to retry if lock fails initially
* @param[in] pid PID to use for lock ownership
*
* @retval 0 Lock created with PID as owner
* @retval !=0 Lock was not created
*/
static int do_lockfile_lock(char *lockfile, unsigned int retries, int pid)
{
int fd, plen, len, rc = 0, snooze = 0;
unsigned int tries = retries + 1;
char buf[BUFSIZE];
char *tpath;
if (!lockfile)
return UTIL_LOCKFILE_ERR;
plen = snprintf(buf, sizeof(buf), "%d\n", pid);
if (plen < 0 || (plen > ((int)sizeof(buf) - 1)))
return UTIL_LOCKFILE_ERR;
/* Allocate temporary lock file with a sufficiently unique path */
len = util_asprintf(&tpath, "%s%05d%02x", lockfile, getpid(),
(unsigned int)time(NULL) & 255);
if (len < 0)
return UTIL_LOCKFILE_ERR;
/* Open the temporary lockfile, write the specified pid */
fd = open(tpath, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644);
if (fd < 0) {
rc = UTIL_LOCKFILE_ERR;
goto out;
}
len = write(fd, buf, plen);
if (close(fd) != 0) {
rc = UTIL_LOCKFILE_ERR;
goto cleanup;
}
if (len != plen) {
/* Failed to write the temp lockfile, bail out */
rc = UTIL_LOCKFILE_ERR;
goto cleanup;
}
/* Link the temprorary file to the real path */
do {
rc = link(tpath, lockfile);
if (rc == 0) {
/* Lock successfully acquired */
rc = UTIL_LOCKFILE_OK;
goto cleanup;
}
/* Lock already held - check for stale lock */
rc = handle_stale_lock(lockfile);
/* Only wait if the lock was not stale */
if (rc != 0) {
tries--;
if (tries > 0) {
snooze += WAITINC;
snooze = (snooze > MAXWAIT) ? MAXWAIT : snooze;
sleep(snooze);
}
}
} while (tries > 0);
/* Exhausted specified number of retries, exit on failure */
rc = UTIL_LOCKFILE_LOCK_FAIL;
cleanup:
unlink(tpath);
free(tpath);
out:
return rc;
}
/**
* Attempt to release a lockfile at the specified path.
*
* @param[in] lockfile Path to the lock file
* @param[in] pid PID that should own the lock
*
* @retval 0 Lock released
* @retval !=0 Lock was not released or did not exist
*/
static int do_lockfile_release(char *lockfile, int pid)
{
int fd, len, lpid;
char buf[BUFSIZE];
if (!lockfile)
return UTIL_LOCKFILE_ERR;
/* Open lockfile, read the owning pid if it exists */
fd = open(lockfile, O_RDONLY);
if (fd < 0)
return UTIL_LOCKFILE_RELEASE_NONE;
len = read(fd, buf, sizeof(buf));
close(fd);
if (len <= 0)
return UTIL_LOCKFILE_RELEASE_FAIL;
buf[len] = 0;
lpid = atoi(buf);
/* Only release the lock if its held by the right pid */
if (pid != lpid)
return UTIL_LOCKFILE_RELEASE_FAIL;
unlink(lockfile);
return 0;
}
/**
* Attempt to create a lockfile owned by this process at the specified path.
*
* @param[in] lockfile Path to the lock file
* @param[in] retries Number of times to retry if lock fails initially
*
* @retval 0 Lock created
* @retval !=0 Lock was not created
*/
int util_lockfile_lock(char *lockfile, int retries)
{
return do_lockfile_lock(lockfile, retries, getpid());
}
/**
* Attempt to create a lockfile owned by the parent of this process at the
* specified path.
*
* @param[in] lockfile Path to the lock file
* @param[in] retries Number of times to retry if lock fails initially
*
* @retval 0 Lock created
* @retval !=0 Lock was not created
*/
int util_lockfile_parent_lock(char *lockfile, int retries)
{
return do_lockfile_lock(lockfile, retries, getppid());
}
/**
* Attempt to release a lockfile owned by this process at the specified path.
*
* @param[in] lockfile Path to the lock file
*
* @retval 0 Lock released
* @retval !=0 Lock was not released or did not exist
*/
int util_lockfile_release(char *lockfile)
{
return do_lockfile_release(lockfile, getpid());
}
/**
* Attempt to release a lockfile owned by the parent of this process at the
* specified path.
*
* @param[in] lockfile Path to the lock file
*
* @retval 0 Lock released
* @retval !=0 Lock was not released or did not exist
*/
int util_lockfile_parent_release(char *lockfile)
{
return do_lockfile_release(lockfile, getppid());
}

View File

@@ -0,0 +1,232 @@
/**
* util_lockfile_example - Example program for util_lockfile
*
* Copyright IBM Corp. 2022
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
//! [code]
#include <stdio.h>
#include <stdlib.h>
#include "lib/util_opt.h"
#include "lib/util_prg.h"
#include "lib/util_lockfile.h"
static const struct util_prg prg = {
.desc = "Example for util_lockfile.",
.copyright_vec = { {
.owner = "IBM Corp.",
.pub_first = 2022,
.pub_last = 2022,
},
UTIL_PRG_COPYRIGHT_END }
};
static struct util_opt opt_vec[] = {
UTIL_OPT_SECTION("OPTIONS"),
{
.option = { "file", required_argument, NULL, 'f' },
.argument = "PATH",
.desc = "Use the specified path for a lockfile.",
},
{
.option = { "lock", required_argument, NULL, 'l' },
.argument = "RETRIES",
.desc = "Acquire the specified file lock using the parent "
"process id of this process. If not immediately "
"successful, retry for the specified number of times",
},
{
.option = { "release", 0, NULL, 'r' },
.desc = "Release the specified lock file using the parent "
"process id",
},
{
.option = { "lock-and-release", required_argument, NULL, 'L' },
.argument = "RETRIES",
.desc = "Acquire the specified file lock using this process "
"id, then release it. If not immediately successful, "
"retry for the specified number of times.",
},
UTIL_OPT_HELP,
UTIL_OPT_VERSION,
UTIL_OPT_END
};
enum prg_action {
ACTION_NONE = 0,
ACTION_LOCK,
ACTION_RELEASE,
ACTION_LOCK_AND_RELEASE,
};
static void print_single_action_error(void)
{
warnx("Only a single action (--lock, --lock-parent, --release, "
"--release-parent) is allowed");
}
int main(int argc, char *argv[])
{
enum prg_action action_id = ACTION_NONE;
int opt, rc, retries = 0;
char *endp, *path = NULL;
util_prg_init(&prg);
util_opt_init(opt_vec, NULL);
while (1) {
opt = util_opt_getopt_long(argc, argv);
if (opt == -1)
break;
switch (opt) {
case 'f':
path = optarg;
break;
case 'L':
if (action_id != ACTION_NONE) {
print_single_action_error();
return EXIT_FAILURE;
}
retries = strtol(optarg, &endp, 0);
if (*optarg == '\0' || *endp != '\0' || retries < 0) {
warnx("Invalid retry value for "
"--lock-and-release: '%s'",
optarg);
util_prg_print_parse_error();
return EXIT_FAILURE;
}
action_id = ACTION_LOCK_AND_RELEASE;
break;
case 'l':
if (action_id != ACTION_NONE) {
print_single_action_error();
return EXIT_FAILURE;
}
retries = strtol(optarg, &endp, 0);
if (*optarg == '\0' || *endp != '\0' || retries < 0) {
warnx("Invalid retry value for "
"--parent-lock: '%s'",
optarg);
util_prg_print_parse_error();
return EXIT_FAILURE;
}
action_id = ACTION_LOCK;
break;
case 'r':
if (action_id != ACTION_NONE) {
print_single_action_error();
return EXIT_FAILURE;
}
action_id = ACTION_RELEASE;
break;
case 'h':
util_prg_print_help();
util_opt_print_help();
exit(EXIT_SUCCESS);
case 'v':
util_prg_print_version();
exit(EXIT_SUCCESS);
default:
util_opt_print_parse_error(opt, argv);
return EXIT_FAILURE;
}
}
if (!path) {
warnx("--file is required, see --help for more information");
return EXIT_FAILURE;
}
if (action_id == ACTION_NONE) {
warnx("One of the following actions must be specified: "
"--lock, --release, --lock-and-release");
return EXIT_FAILURE;
}
/* Determine which util_lockfile function to call */
switch (action_id) {
case ACTION_LOCK:
rc = util_lockfile_parent_lock(path, retries);
switch (rc) {
case UTIL_LOCKFILE_OK:
printf("lock acquired successfully\n");
break;
case UTIL_LOCKFILE_LOCK_FAIL:
warnx("lock was not acquired; already held");
return EXIT_FAILURE;
case UTIL_LOCKFILE_ERR:
warnx("lock was not acquired; file error");
return EXIT_FAILURE;
default:
warnx("Unknown util_lockfile rc %d", rc);
return EXIT_FAILURE;
}
break;
case ACTION_RELEASE:
rc = util_lockfile_parent_release(path);
switch (rc) {
case UTIL_LOCKFILE_OK:
printf("lock released successfully\n");
break;
case UTIL_LOCKFILE_RELEASE_NONE:
warnx("lock file did not exist");
return EXIT_FAILURE;
case UTIL_LOCKFILE_RELEASE_FAIL:
warnx("lock was not held by the specified pid");
return EXIT_FAILURE;
case UTIL_LOCKFILE_ERR:
warnx("lock was not released; file error");
return EXIT_FAILURE;
default:
warnx("Unknown util_lockfile rc %d", rc);
return EXIT_FAILURE;
}
break;
case ACTION_LOCK_AND_RELEASE:
rc = util_lockfile_lock(path, retries);
switch (rc) {
case UTIL_LOCKFILE_OK:
printf("lock acquired successfully, holding for 2 seconds\n");
break;
case UTIL_LOCKFILE_LOCK_FAIL:
warnx("lock was not acquired; already held");
return EXIT_FAILURE;
case UTIL_LOCKFILE_ERR:
warnx("lock was not acquired; file error");
return EXIT_FAILURE;
default:
warnx("Unknown util_lockfile rc %d", rc);
return EXIT_FAILURE;
}
/* Briefly sleep while holding the lock */
sleep(2);
rc = util_lockfile_release(path);
switch (rc) {
case UTIL_LOCKFILE_OK:
printf("lock released successfully\n");
break;
case UTIL_LOCKFILE_RELEASE_NONE:
warnx("lock file did not exist");
return EXIT_FAILURE;
case UTIL_LOCKFILE_RELEASE_FAIL:
warnx("lock was not held by the specified pid");
return EXIT_FAILURE;
case UTIL_LOCKFILE_ERR:
warnx("lock was not released; file error");
return EXIT_FAILURE;
default:
warnx("Unknown util_lockfile rc %d", rc);
return EXIT_FAILURE;
}
break;
default:
warnx("Unknown util_lockfile action");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
//! [code]

View File

@@ -1,15 +0,0 @@
include ../common.mak
lib = libvmdump.a
all: $(lib)
objects = register_content.o dump.o lkcd_dump.o register_content.o \
vmdump_convert.o vm_dump.o
$(lib): $(objects)
install: all
clean:
rm -f *.o $(lib)

View File

@@ -1,65 +0,0 @@
/*
* vmdump - z/VM dump conversion library
*
* Dump base class
*
* Copyright IBM Corp. 2004, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#include "dump.h"
int debug = 0;
void s390TodToTimeval(uint64_t todval, struct timeval *xtime)
{
/* adjust todclock to 1970 */
todval -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
todval >>= 12;
xtime->tv_sec = todval / 1000000;
xtime->tv_usec = todval % 1000000;
}
Dump::Dump(const char *filename, const char *mode)
{
fh = fopen(filename, mode);
if(!fh){
throw(DumpErrnoException("Open dump file failed!"));
}
}
Dump::~Dump(void)
{
if(fh){
fclose(fh);
}
}
void ProgressBar::initProgress(void)
{
progressPercentage = -1;
}
void ProgressBar::displayProgress(uint64_t value, uint64_t maxValue)
{
char progress_bar[51];
int j;
if (progressPercentage == (int) (value * 100 / maxValue))
fprintf(stderr, "%6lld of %6lld |\r",
(long long) value, (long long) maxValue);
else { /* percent value has changed */
progressPercentage = (value * 100 / maxValue);
for (j = 0; j < progressPercentage / 2; j++)
progress_bar[j] = '#';
for (j = progressPercentage / 2; j < 50; j++)
progress_bar[j] = '-';
progress_bar[50] = 0;
fprintf(stderr, "%6lld of %6lld |%s| %3d%% \r",
(long long) value, (long long) maxValue,
progress_bar, progressPercentage);
}
}

View File

@@ -1,95 +0,0 @@
/*
* vmdump - z/VM dump conversion library
*
* Dump base class
*
* Copyright IBM Corp. 2004, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef DUMP_H
#define DUMP_H
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
extern int debug;
class DumpException
{
public:
DumpException(void) {
msg[0] = 0;
errorCode = 0;
}
DumpException(const char *m) {
sprintf(msg, "%s", m);
errorCode = 0;
}
const char *what(void) const { return msg; }
int code(void) const { return errorCode; }
protected:
char msg[2048];
int errorCode;
};
class DumpErrnoException : public DumpException
{
public:
DumpErrnoException(const char *m) {
sprintf(msg, "%s (%s)", m, strerror(errno));
errorCode = errno;
}
};
class Dump
{
public:
Dump(const char *filename, const char *mode);
Dump(void) : fh(0) {}
virtual ~Dump(void);
typedef enum {DT_VM32, DT_VM64, DT_VM64_BIG, DT_LKCD32, DT_LKCD64,
DT_UNKNOWN} DumpType;
virtual void readMem(char *buf, int size) = 0;
virtual int seekMem(uint64_t offset) = 0;
virtual uint64_t getMemSize(void) const = 0;
virtual struct timeval getDumpTime(void) const = 0;
protected:
FILE *fh;
};
class ProgressBar
{
public:
ProgressBar(void) { progressPercentage = -1; }
void initProgress(void);
void displayProgress(uint64_t value, uint64_t maxValue);
private:
int progressPercentage;
};
void s390TodToTimeval(uint64_t todval, struct timeval *xtime);
int vm_convert(const char *inputFileName, const char *outputFileName,
const char *progName);
static inline void dump_read(void *ptr, size_t size, size_t nmemb,
FILE *stream)
{
if (fread(ptr, size, nmemb, stream) != nmemb)
throw(DumpErrnoException("fread failed"));
}
static inline void dump_seek(FILE *stream, long offset, int whence)
{
if (fseek(stream, offset, whence) == -1)
throw(DumpErrnoException("fseek failed"));
}
#endif /* DUMP_H */

View File

@@ -1,261 +0,0 @@
/*
* vmdump - z/VM dump conversion library
*
* LKCD dump classes: LKCDDump, LKCDDump32, LKCDDump64
*
* Copyright IBM Corp. 2004, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <zlib.h>
#include "lkcd_dump.h"
LKCDDump::LKCDDump(Dump* dump, const char* arch) {
referenceDump = dump;
dumpHeader.magic_number = DUMP_MAGIC_NUMBER;
dumpHeader.version = DUMP_VERSION_NUMBER;
dumpHeader.header_size = sizeof(struct _lkcd_dump_header);
dumpHeader.time.tv_sec = dump->getDumpTime().tv_sec;
dumpHeader.time.tv_usec = dump->getDumpTime().tv_usec;
strcpy(dumpHeader.utsname_machine, arch);
dumpHeader.memory_size = dump->getMemSize();
dumpHeader.memory_start = 0;
dumpHeader.memory_end = dump->getMemSize();
dumpHeader.num_dump_pages = dump->getMemSize()/0x1000;
dumpHeader.page_size = 0x1000;
dumpHeader.dump_compress = DUMP_COMPRESS_GZIP;
dumpHeader.dump_level = DUMP_LEVEL_ALL;
dumpHeaderAsm.magic_number = DUMP_ASM_MAGIC_NUMBER;
dumpHeaderAsm.version = 1;
dumpHeaderAsm.header_size = sizeof(dumpHeaderAsm);
}
int LKCDDump::compressGZIP(const char *old, uint32_t old_size, char *n,
uint32_t new_size)
{
unsigned long len = old_size;
int rc;
rc = compress((Bytef*)n, &len, (const Bytef*)old, new_size);
switch(rc) {
case Z_OK:
rc = len;
break;
case Z_BUF_ERROR:
/* In this case the compressed output is bigger than */
/* the uncompressed */
rc = GZIP_NOT_COMPRESSED;
break;
case Z_MEM_ERROR:
throw(DumpException("gzip call failed: out of memory"));
case Z_DATA_ERROR:
throw(DumpException("gzip call failed: input data " \
"corrupted!"));
default:
throw(DumpException("gzip call failed: unknown error"));
}
return rc;
}
void LKCDDump::writeDump(const char* fileName)
{
char dump_header_buf[DUMP_HEADER_SIZE] = {};
char dump_page_buf[DUMP_BUFFER_SIZE];
char dpcpage[DUMP_PAGE_SIZE];
uint32_t dp_size,dp_flags;
ProgressBar progressBar;
char buf[DUMP_PAGE_SIZE];
struct _dump_page dp;
uint64_t mem_loc = 0;
ssize_t buf_loc = 0;
int size, fd;
if (fileName == NULL) {
fd = STDOUT_FILENO;
} else {
fd = open(fileName, O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR);
if (fd == -1) {
char msg[1024];
sprintf(msg, "Open of dump '%s' failed.", fileName);
throw(DumpErrnoException(msg));
}
}
/* write dump header */
memcpy(dump_header_buf, &dumpHeader, sizeof(dumpHeader));
memcpy(&dump_header_buf[sizeof(dumpHeader)], &dumpHeaderAsm,
sizeof(dumpHeaderAsm));
if (write(fd, dump_header_buf, sizeof(dump_header_buf)) !=
sizeof(dump_header_buf)) {
throw(DumpErrnoException("write failed"));
}
/* write memory */
referenceDump->seekMem(0);
while (mem_loc < dumpHeader.memory_size) {
referenceDump->readMem(buf, DUMP_PAGE_SIZE);
copyRegsToPage(mem_loc,buf);
memset(dpcpage, 0, DUMP_PAGE_SIZE);
/*
* Get the new compressed page size
*/
size = compressGZIP((char *)buf, DUMP_PAGE_SIZE,
(char *)dpcpage, DUMP_PAGE_SIZE);
/*
* If compression failed or compressed was ineffective,
* we write an uncompressed page
*/
if (size == GZIP_NOT_COMPRESSED) {
dp_flags = DUMP_DH_RAW;
dp_size = DUMP_PAGE_SIZE;
} else {
dp_flags = DUMP_DH_COMPRESSED;
dp_size = size;
}
dp.address = mem_loc;
dp.size = dp_size;
dp.flags = dp_flags;
memcpy((void *)(dump_page_buf + buf_loc),
(const void *)&dp, sizeof(dp));
buf_loc += sizeof(dp);
/*
* Copy the page of memory
*/
if (dp_flags & DUMP_DH_COMPRESSED) {
/* Copy the compressed page */
memcpy((void *)(dump_page_buf + buf_loc),
(const void *)dpcpage, dp_size);
} else {
/* Copy directly from memory */
memcpy((void *)(dump_page_buf + buf_loc),
(const void *)buf, dp_size);
}
buf_loc += dp_size;
if(write(fd, dump_page_buf, buf_loc) != buf_loc){
throw(DumpErrnoException("write failed"));
}
buf_loc = 0;
mem_loc += DUMP_PAGE_SIZE;
progressBar.displayProgress(mem_loc/(1024*1024),
dumpHeader.memory_size/(1024*1024));
}
/*
* Write end marker
*/
dp.address = 0x0;
dp.size = 0x0;
dp.flags = DUMP_DH_END;
if(write(fd, &dp, sizeof(dp)) != sizeof(dp)){
throw(DumpErrnoException("write failed"));
}
fprintf(stderr, "\n");
if (fd != STDOUT_FILENO)
close(fd);
}
struct timeval LKCDDump::getDumpTime(void) const
{
struct timeval rc;
rc.tv_sec = dumpHeader.time.tv_sec;
rc.tv_usec = dumpHeader.time.tv_usec;
return rc;
}
LKCDDump32::LKCDDump32(Dump* dump, const RegisterContent32& r)
: LKCDDump(dump,"s390")
{
unsigned int i;
dumpHeaderAsm.real_cpu_cnt = (uint32_t) r.getNumCpus();
for (i = 0; i < dumpHeaderAsm.real_cpu_cnt; i++) {
if (!r.regSets[i].prefix)
continue;
dumpHeaderAsm.lc_vec[i] = r.regSets[i].prefix;
dumpHeaderAsm.cpu_cnt++;
}
registerContent = r;
}
void LKCDDump32::copyRegsToPage(uint64_t offset, char *buf)
{
int cpu;
for(cpu = 0; cpu < registerContent.getNumCpus(); cpu++){
if(offset == registerContent.regSets[cpu].prefix){
memcpy(buf+0xd8,&registerContent.regSets[cpu].cpuTimer,
sizeof(registerContent.regSets[cpu].cpuTimer));
memcpy(buf+0xe0,&registerContent.regSets[cpu].clkCmp,
sizeof(registerContent.regSets[cpu].clkCmp));
memcpy(buf+0x100,&registerContent.regSets[cpu].psw,
sizeof(registerContent.regSets[cpu].psw));
memcpy(buf+0x108,&registerContent.regSets[cpu].prefix,
sizeof(registerContent.regSets[cpu].prefix));
memcpy(buf+0x120,&registerContent.regSets[cpu].acrs,
sizeof(registerContent.regSets[cpu].acrs));
memcpy(buf+0x160,&registerContent.regSets[cpu].fprs,
sizeof(registerContent.regSets[cpu].fprs));
memcpy(buf+0x180,&registerContent.regSets[cpu].gprs,
sizeof(registerContent.regSets[cpu].gprs));
memcpy(buf+0x1c0,&registerContent.regSets[cpu].crs,
sizeof(registerContent.regSets[cpu].crs));
}
}
}
LKCDDump64::LKCDDump64(Dump* dump, const RegisterContent64& r)
: LKCDDump(dump,"s390x")
{
unsigned int i;
dumpHeaderAsm.real_cpu_cnt = (uint32_t) r.getNumCpus();
for (i = 0; i < dumpHeaderAsm.real_cpu_cnt; i++) {
if (!r.regSets[i].prefix)
continue;
dumpHeaderAsm.lc_vec[i] = r.regSets[i].prefix;
dumpHeaderAsm.cpu_cnt++;
}
registerContent = r;
}
void LKCDDump64::copyRegsToPage(uint64_t offset, char *buf)
{
int cpu;
for(cpu = 0; cpu < registerContent.getNumCpus(); cpu++){
if(offset == (registerContent.regSets[cpu].prefix + 0x1000)){
memcpy(buf+0x328,&registerContent.regSets[cpu].cpuTimer,
sizeof(registerContent.regSets[cpu].cpuTimer));
memcpy(buf+0x330,&registerContent.regSets[cpu].clkCmp,
sizeof(registerContent.regSets[cpu].clkCmp));
memcpy(buf+0x300,&registerContent.regSets[cpu].psw,
sizeof(registerContent.regSets[cpu].psw));
memcpy(buf+0x318,&registerContent.regSets[cpu].prefix,
sizeof(registerContent.regSets[cpu].prefix));
memcpy(buf+0x340,&registerContent.regSets[cpu].acrs,
sizeof(registerContent.regSets[cpu].acrs));
memcpy(buf+0x200,&registerContent.regSets[cpu].fprs,
sizeof(registerContent.regSets[cpu].fprs));
memcpy(buf+0x280,&registerContent.regSets[cpu].gprs,
sizeof(registerContent.regSets[cpu].gprs));
memcpy(buf+0x380,&registerContent.regSets[cpu].crs,
sizeof(registerContent.regSets[cpu].crs));
memcpy(buf+0x31c,&registerContent.regSets[cpu].fpCr,
sizeof(registerContent.regSets[cpu].fpCr));
}
}
}

View File

@@ -1,149 +0,0 @@
/*
* vmdump - z/VM dump conversion library
*
* LKCD dump classes: LKCDDump, LKCDDump32, LKCDDump64
*
* Copyright IBM Corp. 2004, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LKCD_DUMP_H
#define LKCD_DUMP_H
#include "lib/zt_common.h"
#include "dump.h"
#include "register_content.h"
#define UTS_LEN 65
#define DUMP_BUFFER_SIZE 0x2000 /* Size of dump buffer */
/* Standard header definitions */
#define DUMP_HEADER_SIZE 0x10000
#define DUMP_MAGIC_NUMBER 0xa8190173618f23edULL /* Dump magic number */
#define DUMP_ASM_MAGIC_NUMBER 0x733339302d64756dULL /* asm magic number */
#define DUMP_VERSION_NUMBER 0x8 /* Dump version number */
#define DUMP_PANIC_LEN 0x100 /* Dump panic string length */
/* Dump levels - type specific stuff added later */
#define DUMP_LEVEL_ALL 0x10 /* Dump all memory RAM and firmware */
/* Dump compression options */
#define DUMP_COMPRESS_GZIP 0x2 /* Use GZIP compression */
/* Dump header flags */
#define DUMP_DH_RAW 0x1 /* Raw page (no compression) */
#define DUMP_DH_COMPRESSED 0x2 /* Page is compressed */
#define DUMP_DH_END 0x4 /* End marker on a full dump */
/* Dump page defines */
#define DUMP_PAGE_SHIFT 12ULL
#define DUMP_PAGE_SIZE (1ULL << DUMP_PAGE_SHIFT)
#define GZIP_NOT_COMPRESSED -1
class LKCDDump : public Dump
{
public:
LKCDDump(Dump*, const char *);
virtual ~LKCDDump(void) {}
inline virtual void readMem(char *UNUSED(buf), int UNUSED(size))
{
throw(DumpException("LKCDDump::readMem() not implemented!"));
}
inline int seekMem(uint64_t UNUSED(offset))
{
throw(DumpException("LKCDDump::seekMem() not implemented!"));
}
inline virtual uint64_t getMemSize() const
{
return dumpHeader.memory_size;
}
virtual struct timeval getDumpTime(void) const;
virtual void writeDump(const char *fileName);
virtual void copyRegsToPage(uint64_t offset, char *buf) = 0;
protected:
struct _lkcd_dump_header {
uint64_t magic_number; /* dump magic number,unique to verify */
/* dump */
uint32_t version; /* version number of this dump */
uint32_t header_size; /* size of this header */
uint32_t dump_level; /* level of this dump */
uint32_t page_size; /* page size (e.g. 4K, 8K, 16K, etc.) */
uint64_t memory_size; /* size of entire physical memory */
uint64_t memory_start; /* start of physical memory */
uint64_t memory_end; /* end of physical memory */
/* the number of dump pages in this dump specifically */
uint32_t num_dump_pages;
char panic_string[DUMP_PANIC_LEN];
/* timeval depends on machine, two long values */
struct {uint64_t tv_sec;
uint64_t tv_usec;
} time; /* the time of the system crash */
/* the NEW utsname (uname) information -- in character form */
/* we do this so we don't have to include utsname.h */
/* plus it helps us be more architecture independent */
char utsname_sysname[UTS_LEN];
char utsname_nodename[UTS_LEN];
char utsname_release[UTS_LEN];
char utsname_version[UTS_LEN];
char utsname_machine[UTS_LEN];
char utsname_domainname[UTS_LEN];
uint64_t current_task;
uint32_t dump_compress; /* compression type used in this dump */
uint32_t dump_flags; /* any additional flags */
uint32_t dump_device; /* any additional flags */
uint64_t s390_asm_magic;
uint16_t cpu_cnt;
uint32_t lowcore_ptr[512];
} __packed;
struct _lkcd_dump_header_asm {
uint64_t magic_number;
uint32_t version;
uint32_t header_size;
uint16_t cpu_cnt;
uint16_t real_cpu_cnt;
uint32_t lc_vec[512];
} __packed;
struct _dump_page {
uint64_t address; /* the address of this dump page */
uint32_t size; /* the size of this dump page */
uint32_t flags; /* flags (DUMP_COMPRESSED, DUMP_RAW */
/* or DUMP_END) */
} __packed;
struct _lkcd_dump_header dumpHeader;
struct _lkcd_dump_header_asm dumpHeaderAsm;
private:
int compressGZIP(const char *old, uint32_t old_size, char *n,
uint32_t new_size);
Dump *referenceDump;
};
class LKCDDump32 : public LKCDDump
{
public:
LKCDDump32(Dump *dump, const RegisterContent32 &rc);
virtual void copyRegsToPage(uint64_t offset, char *buf);
private:
RegisterContent32 registerContent;
};
class LKCDDump64 : public LKCDDump
{
public:
LKCDDump64(Dump *dump, const RegisterContent64 &rc);
virtual void copyRegsToPage(uint64_t offset, char *buf);
private:
RegisterContent64 registerContent;
};
#endif /* LKCD_DUMP_H */

View File

@@ -1,76 +0,0 @@
/*
* vmdump - z/VM dump conversion library
*
* Register content classes
*
* Copyright IBM Corp. 2004, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#include <string.h>
#include "register_content.h"
#include "dump.h"
RegisterContent32::RegisterContent32(void)
: regSets(), nrCpus(0)
{
}
RegisterContent32::RegisterContent32(const RegisterContent32& r)
{
nrCpus = r.nrCpus;
memcpy(&regSets,&r.regSets,sizeof(regSets));
}
void RegisterContent32::addRegisterSet(const RegisterSet32& rs)
{
if(nrCpus < MAX_CPUS){
regSets[nrCpus++] = rs;
} else {
throw(DumpException("RegisterContent32::addRegisterSet - " \
"No more register sets available"));
}
}
RegisterSet32 RegisterContent32::getRegisterSet(int cpu){
if(cpu <= nrCpus){
return regSets[cpu];
} else {
throw(DumpException("RegisterContent32::getRegisterSet - " \
"No register set for cpu"));
}
}
RegisterContent64::RegisterContent64(void)
: regSets(), nrCpus(0)
{
}
RegisterContent64::RegisterContent64(const RegisterContent64& r)
{
nrCpus = r.nrCpus;
memcpy(&regSets,&r.regSets,sizeof(regSets));
}
void RegisterContent64::addRegisterSet(const RegisterSet64& rs)
{
if(nrCpus < MAX_CPUS){
regSets[nrCpus++] = rs;
} else {
throw(DumpException("RegisterContent64::addRegisterSet - " \
"No more register sets available"));
}
}
RegisterSet64 RegisterContent64::getRegisterSet(int cpu)
{
if(cpu <= nrCpus){
return regSets[cpu];
} else {
throw(DumpException("RegisterContent64::getRegisterSet - " \
"No register set for cpu"));
}
}

View File

@@ -1,75 +0,0 @@
/*
* vmdump - z/VM dump conversion library
*
* Register content classes
*
* Copyright IBM Corp. 2004, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef REGISTER_CONTENT_H
#define REGISTER_CONTENT_H
#include <stdint.h>
#define MAX_CPUS 512
class RegisterSet64
{
public:
uint64_t gprs[16];
uint64_t crs[16];
uint32_t acrs[16];
uint64_t fprs[16];
uint32_t fpCr;
uint64_t psw[2];
uint32_t prefix;
uint64_t cpuTimer;
uint64_t clkCmp;
};
class RegisterSet32
{
public:
uint32_t gprs[16];
uint32_t crs[16];
uint32_t acrs[16];
uint64_t fprs[4];
uint32_t psw[2];
uint32_t prefix;
uint64_t cpuTimer;
uint64_t clkCmp;
};
class RegisterContent64{
public:
RegisterContent64(void);
RegisterContent64(const RegisterContent64&);
RegisterSet64 getRegisterSet(int cpu);
void addRegisterSet(const RegisterSet64&);
inline int getNumCpus(void) const { return nrCpus; }
RegisterContent64& operator=(const RegisterContent64&) = default;
RegisterSet64 regSets[MAX_CPUS];
private:
int nrCpus;
};
class RegisterContent32{
public:
RegisterContent32(void);
RegisterContent32(const RegisterContent32&);
RegisterSet32 getRegisterSet(int cpu);
void addRegisterSet(const RegisterSet32&);
inline int getNumCpus(void) const { return nrCpus; }
RegisterContent32& operator=(const RegisterContent32&) = default;
RegisterSet32 regSets[MAX_CPUS];
private:
int nrCpus;
};
#endif /* REGISTER_CONTENT_H */

View File

@@ -1,624 +0,0 @@
/*
* vmdump - z/VM dump conversion library
*
* Register content classes:
* VMDump, VMDumpClassic, VMDump64, VMDump64Big, VMDump32
*
* Copyright IBM Corp. 2004, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#include <ctype.h>
#include <stdint.h>
#include <time.h>
#include "vm_dump.h"
Dump::DumpType VMDump::getDumpType(const char* inputFileName)
{
uint8_t fmbk_id[8] = {0xc8, 0xc3, 0xd7, 0xc4, 0xc6, 0xd4, 0xc2, 0xd2};
struct _fir_basic fir;
struct _fmbk fmbk;
struct _adsr adsr;
char msg[200];
FILE* fh;
fh = fopen(inputFileName,"r");
if (!fh) {
sprintf(msg,"Could not open '%s'",inputFileName);
throw DumpErrnoException(msg);
}
/* Record 1: adsr */
dump_read(&adsr, sizeof(adsr), 1, fh);
/* Record 2: fmbk */
dump_seek(fh, 0x1000, SEEK_SET);
if (fread(&fmbk, sizeof(fmbk), 1, fh) != 1) {
if(ferror(fh)) {
sprintf(msg,"Could not read header of vmdump '%s'",
inputFileName);
fclose(fh);
throw DumpErrnoException(msg);
} else{
sprintf(msg,"Input file '%s' is not a vmdump",
inputFileName);
fclose(fh);
throw DumpException(msg);
}
}
/* Check if this is a vmdump */
if (memcmp(fmbk.id, fmbk_id, 8) != 0 ||
adsr.dump_type != 0xe5d4c4e4d4d74040ULL) {
fclose(fh);
sprintf(msg, "Input file '%s' is not a vmdump", inputFileName);
throw DumpException(msg);
}
/* Record 3-7: fir */
dump_seek(fh, (fmbk.rec_nr_fir - 1) * 0x1000, SEEK_SET);
if(fread(&fir, sizeof(fir), 1, fh) != 1) {
if (ferror(fh)) {
sprintf(msg,"Could not read header of vmdump '%s'",
inputFileName);
fclose(fh);
throw DumpErrnoException(msg);
}
else{
sprintf(msg, "Could not read header of vmdump '%s'",
inputFileName);
fclose(fh);
throw DumpException(msg);
}
}
fclose(fh);
if (fir.fir_format == 0) {
return DT_VM32;
} else if (fir.fir_format == 0x02) {/*XXX && (fir.dump_format == 0x1))*/
return DT_VM64_BIG;
} else if (fir.fir_format == 0x82) {
return DT_VM64;
} else {
return DT_UNKNOWN;
}
}
VMDump::VMDump(const char *fileName) : Dump(fileName, "rb")
{
uint8_t fmbk_id[8] = {0xc8, 0xc3, 0xd7, 0xc4, 0xc6, 0xd4, 0xc2, 0xd2};
ebcdicAsciiConv = iconv_open("ISO-8859-1", "EBCDIC-US");
/* Record 1: adsrRecord */
dump_seek(fh,0,SEEK_SET);
dump_read(&adsrRecord,sizeof(adsrRecord),1,fh);
if(debug) {
char buf_asc[1024];
char buf[1024];
int i;
fprintf(stderr, "off=%d\n", adsrRecord.sec5_offset);
dump_seek(fh, adsrRecord.sec5_offset, SEEK_SET);
dump_read(buf, adsrRecord.sec5_len, 1, fh);
ebcAsc(buf, buf_asc, adsrRecord.sec5_len);
for (i=0; i < adsrRecord.sec5_len; i++) {
if ((buf_asc[i]==0) || iscntrl(buf_asc[i]))
buf_asc[i]=' ';
}
buf_asc[adsrRecord.sec5_len] = 0;
printf("symptom string1: %s\n",buf_asc);
}
/* Record 2: fmbk */
dump_seek(fh,0x1000,SEEK_SET);
dump_read(&fmbkRecord,sizeof(fmbkRecord),1,fh);
/* Check if this is a vmdump */
if(memcmp(fmbkRecord.id, fmbk_id, 8) != 0) {
throw DumpException("Input file is not a vmdump");
}
/* Record 3-7: fir records read by subclasses */
/* Record 8: albk */
dump_seek(fh,(fmbkRecord.rec_nr_access-1)*0x1000 ,SEEK_SET);
dump_read(&albkRecord,sizeof(albkRecord),1,fh);
}
struct timeval VMDump::getDumpTime(void) const
{
struct timeval rc;
s390TodToTimeval(adsrRecord.tod,&rc);
return rc;
}
void VMDump::printDebug(void)
{
struct timeval time;
char fmbk_id[8];
char albk_id[8];
s390TodToTimeval(adsrRecord.tod, &time);
/* adsr */
printf("time : %s\n", ctime(&time.tv_sec));
printf("stat1 : %x\n", adsrRecord.record_status_flag1);
printf("stat2 : %x\n", adsrRecord.record_status_flag2);
printf("sec 2 len: %i\n", adsrRecord.sec2_len);
printf("sec 2.1 len: %i/%i\n", adsrRecord.sec2_1_len,
adsrRecord.sec2_1_offset);
printf("sec 3 len: %i/%i\n", adsrRecord.sec3_len,
adsrRecord.sec3_offset);
printf("sec 4 len: %i/%i\n", adsrRecord.sec4_len,
adsrRecord.sec4_offset);
printf("sec 5 len: %i/%i\n", adsrRecord.sec5_len,
adsrRecord.sec5_offset);
printf("sec 6 len: %i/%i\n", adsrRecord.sec6_len,
adsrRecord.sec6_offset);
/* fmbk */
ebcAsc(fmbkRecord.id, fmbk_id, sizeof(fmbkRecord.id));
fmbk_id[7] = 0;
printf("id : %s\n", fmbk_id);
printf("fir rec nr: %i\n", fmbkRecord.rec_nr_fir);
printf("vec rec nr: %i\n", fmbkRecord.rec_nr_vector);
printf("access rec nr: %i\n", fmbkRecord.rec_nr_access);
/* albk */
ebcAsc(albkRecord.id, albk_id, sizeof(albkRecord.id));
albk_id[7]=0;
printf("ALBK id : %s\n",albk_id);
}
void VMDump::printInfo(void)
{
struct timeval time;
s390TodToTimeval(adsrRecord.tod,&time);
fprintf(stderr, " date........: %s",ctime(&time.tv_sec));
}
int VMDump::seekMem(uint64_t offset)
{
if (offset != 0) {
return -1;
}
pageOffset = 0;
return 0;
}
void VMDump::readMem(char* buf, int size)
{
int i;
if (pageOffset == 0)
dump_seek(fh, memoryStartRecord, SEEK_SET);
if (size % 0x1000 != 0) {
throw(DumpException("internal error: VMDump::readMem() " \
"can only handle sizes which are multiples of page size"));
}
for(i = 0; i < size; i += 0x1000) {
if(testPage(pageOffset)) {
dump_read(buf + i, 0x1000, 1, fh);
} else {
memset(buf + i, 0, 0x1000);
}
pageOffset += 1;
}
}
VMDump::~VMDump(void)
{
}
/*****************************************************************************/
/* VMDumpClassic: traditional 32/64 bit vmdump (before z/VM 5.2) */
/*****************************************************************************/
VMDumpClassic::VMDumpClassic(const char *fileName) : VMDump(fileName)
{
int storageKeyPages,bitMapPages;
pageOffset = 0;
/* Record 9: asibk */
dump_seek(fh,fmbkRecord.rec_nr_access * 0x1000,SEEK_SET);
dump_read(&asibkRecord,sizeof(asibkRecord),1,fh);
/* Record 10: bitmaps */
dump_seek(fh,(fmbkRecord.rec_nr_access + 1)* 0x1000 ,SEEK_SET);
bitmap = new char[asibkRecord.storage_size_2GB / (0x1000 * 8)];
dump_read(bitmap,asibkRecord.storage_size_2GB / (0x1000*8),1,fh);
bitMapPages=asibkRecord.storage_size_2GB / (0x1000 * 8);
if (bitMapPages % 0x1000 != 0)
bitMapPages = bitMapPages/0x1000 + 1;
else
bitMapPages = bitMapPages/0x1000;
storageKeyPages=asibkRecord.storage_size_2GB / 0x1000;
if(storageKeyPages % 0x1000 != 0) {
storageKeyPages = storageKeyPages/0x1000 + 1;
} else {
storageKeyPages = storageKeyPages/0x1000;
}
/* Skip storage keys */
memoryStartRecord = (fmbkRecord.rec_nr_access + 1) *0x1000 /* 0x9000 */
+ (bitMapPages + storageKeyPages)*0x1000;
if(debug) {
printf("Mem Offset: %llx\n", (long long) memoryStartRecord);
}
}
void VMDumpClassic::printInfo(void)
{
VMDump::printInfo();
fprintf(stderr, " storage.....: %i MB\n",
asibkRecord.storage_size_2GB/(1024*1024));
}
VMDumpClassic::~VMDumpClassic(void)
{
delete bitmap;
}
/*****************************************************************************/
/* VMDump32: 32 bit vmdump */
/*****************************************************************************/
VMDump32::VMDump32(const char* filename) : VMDumpClassic(filename)
{
int i;
if(!fh) {
return;
}
dump_seek(fh,(fmbkRecord.rec_nr_fir-1)* 0x1000 ,SEEK_SET);
dump_read(&fir32Record,sizeof(fir32Record),1,fh);
fir32OtherRecords = new _fir_other_32[fir32Record.online_cpus];
for(i=0; i < fir32Record.online_cpus; i++) {
/* fir other */
dump_read(&fir32OtherRecords[i],sizeof(fir32OtherRecords[i]),1,
fh);
}
if(debug)
printDebug();
}
RegisterContent32 VMDump32::getRegisterContent(void)
{
RegisterContent32 rc;
RegisterSet32 rs;
int cpu;
/* First CPU */
memcpy(&rs.gprs, &fir32Record.gprs, sizeof(rs.gprs));
memcpy(&rs.crs, &fir32Record.crs, sizeof(rs.crs));
memcpy(&rs.acrs, &fir32Record.acrs, sizeof(rs.acrs));
memcpy(&rs.psw, &fir32Record.psw, sizeof(rs.psw));
memcpy(&rs.prefix, &fir32Record.prefix, sizeof(rs.prefix));
memcpy(&rs.fprs, &fir32Record.fprs, sizeof(rs.fprs));
memcpy(&rs.cpuTimer, &fir32Record.cpu_timer, sizeof(rs.cpuTimer));
memcpy(&rs.clkCmp, &fir32Record.clock_cmp, sizeof(rs.clkCmp));
rc.addRegisterSet(rs);
/* Other online cpus */
for(cpu = 0; cpu < fir32Record.online_cpus; cpu++) {
memcpy(&rs.gprs, &fir32OtherRecords[cpu].gprs, sizeof(rs.gprs));
memcpy(&rs.crs, &fir32OtherRecords[cpu].crs, sizeof(rs.crs));
memcpy(&rs.acrs, &fir32OtherRecords[cpu].acrs, sizeof(rs.acrs));
/* No psw for ESA vmdumps */
rs.psw[0] = 0xdeadbeef;
rs.psw[1] = 0xdeadbeef;
memcpy(&rs.prefix, &fir32OtherRecords[cpu].prefix,
sizeof(rs.prefix));
memcpy(&rs.fprs, &fir32OtherRecords[cpu].fprs, sizeof(rs.fprs));
memcpy(&rs.cpuTimer, &fir32OtherRecords[cpu].cpu_timer,
sizeof(rs.cpuTimer));
memcpy(&rs.clkCmp, &fir32OtherRecords[cpu].clock_cmp,
sizeof(rs.clkCmp));
rc.addRegisterSet(rs);
}
return rc;
}
void VMDump32::printDebug(void)
{
int i;
VMDump::printDebug();
printf("prefix: %x\n", fir32Record.prefix);
printf("cpus: %x\n", fir32Record.online_cpus);
printf("psw: %08x %08x\n", fir32Record.psw[0], fir32Record.psw[1]);
for (i=0; i < fir32Record.online_cpus; i++) {
/* fir other */
printf("prefix (%i): %x\n", i, fir32OtherRecords[i].prefix);
}
}
void
VMDump32::printInfo(void)
{
fprintf(stderr, "vmdump information:\n");
fprintf(stderr, " architecture: 32 bit\n");
VMDumpClassic::printInfo();
fprintf(stderr, " cpus........: %x\n", fir32Record.online_cpus + 1);
}
VMDump32::~VMDump32(void)
{
delete fir32OtherRecords;
}
/*****************************************************************************/
/* VMDump64: 64 bit vmdump for old vmdump format (z/VM < 5.2) */
/*****************************************************************************/
VMDump64::VMDump64(const char* filename) : VMDumpClassic(filename)
{
int i;
if(!fh) {
return;
}
dump_seek(fh,(fmbkRecord.rec_nr_fir-1)* 0x1000 ,SEEK_SET);
dump_read(&fir64Record,sizeof(fir64Record),1,fh);
fir64OtherRecords = new _fir_other_64[fir64Record.online_cpus];
for (i=0; i < fir64Record.online_cpus; i++) {
/* fir other */
dump_read(&fir64OtherRecords[i], sizeof(fir64OtherRecords[i]),
1, fh);
}
if(debug)
printDebug();
}
void VMDump64::printDebug(void)
{
int i;
VMDump::printDebug();
printf("prefix: %x\n", fir64Record.prefix);
printf("cpus: %x\n", fir64Record.online_cpus);
printf("psw: %016llx %016llx\n", (long long)fir64Record.psw[0],
(long long)fir64Record.psw[1]);
for (i=0; i < fir64Record.online_cpus; i++) {
/* fir other */
printf("prefix (%i): %x\n", i, fir64OtherRecords[i].prefix);
}
}
void VMDump64::printInfo(void)
{
fprintf(stderr, "vmdump information:\n");
fprintf(stderr, " architecture: 64 bit\n");
VMDumpClassic::printInfo();
fprintf(stderr, " cpus........: %x\n",fir64Record.online_cpus + 1);
}
RegisterContent64 VMDump64::getRegisterContent(void)
{
RegisterContent64 rc;
RegisterSet64 rs;
int cpu;
/* First CPU */
memcpy(&rs.gprs, &fir64Record.gprs, sizeof(rs.gprs));
memcpy(&rs.crs, &fir64Record.crs, sizeof(rs.crs));
memcpy(&rs.acrs, &fir64Record.acrs, sizeof(rs.acrs));
memcpy(&rs.psw, &fir64Record.psw, sizeof(rs.psw));
memcpy(&rs.prefix, &fir64Record.prefix, sizeof(rs.prefix));
memcpy(&rs.fprs, &fir64Record.fprs, sizeof(rs.fprs));
memcpy(&rs.cpuTimer, &fir64Record.cpu_timer, sizeof(rs.cpuTimer));
memcpy(&rs.clkCmp, &fir64Record.clock_cmp, sizeof(rs.clkCmp));
memcpy(&rs.fpCr, &fir64Record.fp_cntrl_reg, sizeof(rs.fpCr));
rc.addRegisterSet(rs);
/* other online cpus */
for (cpu = 0; cpu < fir64Record.online_cpus; cpu++) {
memcpy(&rs.gprs, &fir64OtherRecords[cpu].gprs, sizeof(rs.gprs));
memcpy(&rs.crs, &fir64OtherRecords[cpu].crs, sizeof(rs.crs));
memcpy(&rs.acrs, &fir64OtherRecords[cpu].acrs, sizeof(rs.acrs));
memcpy(&rs.psw, &fir64OtherRecords[cpu].psw, sizeof(rs.psw));
memcpy(&rs.prefix, &fir64OtherRecords[cpu].prefix,
sizeof(rs.prefix));
memcpy(&rs.fprs, &fir64OtherRecords[cpu].fprs, sizeof(rs.fprs));
memcpy(&rs.cpuTimer, &fir64OtherRecords[cpu].cpu_timer,
sizeof(rs.cpuTimer));
memcpy(&rs.clkCmp, &fir64OtherRecords[cpu].clock_cmp,
sizeof(rs.clkCmp));
memcpy(&rs.fpCr, &fir64OtherRecords[cpu].fp_cntrl_reg,
sizeof(rs.fpCr));
rc.addRegisterSet(rs);
}
return rc;
}
VMDump64::~VMDump64(void)
{
delete fir64OtherRecords;
}
/*****************************************************************************/
/* VMDump64Big: 64 bit vmdump with new big storage dump format */
/*****************************************************************************/
VMDump64Big::VMDump64Big(const char* filename) : VMDump(filename)
{
uint64_t pageNum, nrDumpedPages;
int i, j;
if(!fh) {
return;
}
/* Record 9: asibk */
dump_seek(fh, fmbkRecord.rec_nr_access * 0x1000,SEEK_SET);
dump_read(&asibkRecordNew, sizeof(asibkRecordNew), 1, fh);
/* Record 10: bitmaps: */
/* Read all bitmap pages and setup bitmap array */
pageNum = 0;
nrDumpedPages = asibkRecordNew.storage_size_def_store / 0x1000;
memoryStartRecord = (fmbkRecord.rec_nr_access + 1) * 0x1000;
bitmap = new char[asibkRecordNew.storage_size_def_store/(0x1000 * 8)];
if(!bitmap) {
throw(DumpErrnoException("out of memory"));
}
memset(bitmap,0,asibkRecordNew.storage_size_def_store/(0x1000 * 8));
dump_seek(fh,(fmbkRecord.rec_nr_access + 1)* 0x1000 ,SEEK_SET);
do {
char bmIndexPage[0x1000];
dump_read(bmIndexPage, sizeof(bmIndexPage), 1, fh);
memoryStartRecord += 0x1000;
for (i=0; i < 0x1000; i++) {
if(testBitmapPage(bmIndexPage, i)) {
char bmPage[0x1000];
dump_read(bmPage,sizeof(bmPage),1,fh);
memoryStartRecord += 0x1000;
for(j = 0; j < 0x1000; j++) {
if(testBitmapKeyPage(bmPage, j)) {
setPageBit(pageNum);
}
pageNum++;
if(pageNum == nrDumpedPages) {
goto all_bitmaps_read;
}
}
} else {
pageNum += 0x1000; /* Empty pages */
}
}
} while (pageNum < nrDumpedPages);
all_bitmaps_read:
if(debug)
printf("Mem Offset: %llx\n", (long long)memoryStartRecord);
dump_seek(fh, (fmbkRecord.rec_nr_fir-1)* 0x1000, SEEK_SET);
dump_read(&fir64Record, sizeof(fir64Record), 1, fh);
fir64OtherRecords = new _fir_other_64[fir64Record.online_cpus];
for (i=0; i < fir64Record.online_cpus; i++) {
/* fir other */
dump_read(&fir64OtherRecords[i], sizeof(fir64OtherRecords[i]),
1, fh);
}
if(debug)
printDebug();
}
void VMDump64Big::printDebug(void)
{
int i;
VMDump::printDebug();
printf("prefix: %x\n", fir64Record.prefix);
printf("cpus: %x\n", fir64Record.online_cpus);
printf("psw: %016llx %016llx\n", (long long)fir64Record.psw[0],
(long long)fir64Record.psw[1]);
for (i=0; i < fir64Record.online_cpus; i++) {
/* fir other */
printf("prefix (%i): %x\n", i, fir64OtherRecords[i].prefix);
}
}
void VMDump64Big::printInfo(void)
{
fprintf(stderr, "vmdump information:\n");
fprintf(stderr, " architecture: 64 bit (big)\n");
fprintf(stderr, " storage.....: %lli MB\n",
(long long)asibkRecordNew.storage_size_def_store / (1024*1024));
VMDump::printInfo();
fprintf(stderr, " cpus........: %x\n", fir64Record.online_cpus + 1);
}
RegisterContent64 VMDump64Big::getRegisterContent(void)
{
RegisterContent64 rc;
RegisterSet64 rs;
int cpu;
/* First CPU */
memcpy(&rs.gprs, &fir64Record.gprs, sizeof(rs.gprs));
memcpy(&rs.crs, &fir64Record.crs, sizeof(rs.crs));
memcpy(&rs.acrs, &fir64Record.acrs, sizeof(rs.acrs));
memcpy(&rs.psw, &fir64Record.psw, sizeof(rs.psw));
memcpy(&rs.prefix, &fir64Record.prefix, sizeof(rs.prefix));
memcpy(&rs.fprs, &fir64Record.fprs, sizeof(rs.fprs));
memcpy(&rs.cpuTimer, &fir64Record.cpu_timer, sizeof(rs.cpuTimer));
memcpy(&rs.clkCmp, &fir64Record.clock_cmp, sizeof(rs.clkCmp));
memcpy(&rs.fpCr, &fir64Record.fp_cntrl_reg, sizeof(rs.fpCr));
rc.addRegisterSet(rs);
/* other online cpus */
for(cpu = 0; cpu < fir64Record.online_cpus; cpu++) {
memcpy(&rs.gprs, &fir64OtherRecords[cpu].gprs, sizeof(rs.gprs));
memcpy(&rs.crs, &fir64OtherRecords[cpu].crs, sizeof(rs.crs));
memcpy(&rs.acrs, &fir64OtherRecords[cpu].acrs, sizeof(rs.acrs));
memcpy(&rs.psw, &fir64OtherRecords[cpu].psw, sizeof(rs.psw));
memcpy(&rs.prefix, &fir64OtherRecords[cpu].prefix,
sizeof(rs.prefix));
memcpy(&rs.fprs, &fir64OtherRecords[cpu].fprs, sizeof(rs.fprs));
memcpy(&rs.cpuTimer, &fir64OtherRecords[cpu].cpu_timer,
sizeof(rs.cpuTimer));
memcpy(&rs.clkCmp, &fir64OtherRecords[cpu].clock_cmp,
sizeof(rs.clkCmp));
memcpy(&rs.fpCr, &fir64OtherRecords[cpu].fp_cntrl_reg,
sizeof(rs.fpCr));
rc.addRegisterSet(rs);
}
return rc;
}
VMDump64Big::~VMDump64Big(void)
{
delete bitmap;
delete fir64OtherRecords;
}

View File

@@ -1,484 +0,0 @@
/*
* vmdump - z/VM dump conversion library
*
* Register content classes:
* VMDump, VMDumpClassic, VMDump64, VMDump64Big, VMDump32
*
* Copyright IBM Corp. 2004, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
/*===========================*
* The format of an vmdump: *
*===========================*
*---------------------------*
* Symptom Record *
* (ADSR COPY) Record 1 *
*---------------------------*
* Dump File Map Record *
* (HCPDFMBK COPY) Record 2 *
*---------------------------*
* Dump File Info Record *
* (HCPDFIR COPY) Records 3-7*
*---------------------------*
* Vector Registers *
* (optional) *
*---------------------------*
* Access Lists (HCPDALBK) *
*---------------------------*
* Address Space A *
* Information and Map *
* Record (HCPASIBK) *
*---------------------------*
* Address Space A *
* Bit Maps *
*---------------------------*
* Address Space A *
* Key Maps *
*---------------------------*
* Address Space A *
* Guest Storage *
*---------------------------*
* Additional Address Spaces *
* ASIBK *
* Bit Maps *
* Key Maps *
* Guest Storage *
* *NOTE* These probably *
* aren't in a Linux guest. *
*---------------------------*
*/
#ifndef VMDUMP_H
#define VMDUMP_H
#include <iconv.h>
#include <string.h>
#include "lib/zt_common.h"
#include "dump.h"
#include "register_content.h"
class VMDump : public Dump
{
public:
VMDump(const char *filename);
virtual ~VMDump(void);
virtual void readMem(char *buf, int size);
virtual int seekMem(uint64_t offset);
virtual struct timeval getDumpTime(void) const;
void printDebug(void);
void printInfo(void);
static DumpType getDumpType(const char *);
inline int testPage(uint64_t bit) const
{
return (bitmap[bit/8] & (1 << (7-(bit % 8))));
}
inline void setPageBit(uint64_t bit) const
{
bitmap[bit/8] |= (1 << (7-(bit % 8)));
}
protected:
/* Types */
struct _adsr {
/* Section 1*/
uint16_t sr;
uint32_t cpu_model;
char cpu_serial[6];
uint32_t time_zone_conversion_factor;
uint64_t tod;
char time_stamp_str[4];
char date_str[6];
char node_name[8];
char product_id[4];
char feature_level[8];
uint8_t record_status_flag1;
uint8_t record_status_flag2;
uint64_t dump_type;
/* Section 2*/
char arch_level[2];
uint16_t sec2_len;
uint16_t sec2_1_len;
uint16_t sec2_1_offset;
uint16_t sec3_len;
uint16_t sec3_offset;
uint16_t sec4_len;
uint16_t sec4_offset;
uint16_t sec5_len;
uint16_t sec5_offset;
uint16_t sec6_len;
uint16_t sec6_offset;
} __packed;
struct _fmbk {
char id[8];
uint32_t rec_nr_fir;
uint32_t rec_nr_vector;
uint32_t rec_nr_access;
uint32_t num_acc_recs;
uint32_t num_addr_spaces;
uint32_t rec_nr_asibk;
} __packed;
struct _fir_basic {
char filler1[15];
uint8_t dump_format;/* 0x1 for big storage dump, 0x2 for cp */
/* hard abend, 0x3 for cp soft abend */
char filler2[171];
uint8_t fir_format; /* 0x2 for big esame, 0x82 for esame, */
/* 0x00 for esa */
} __packed;
struct _albk {
char id[8];
} __packed;
/* Methods */
inline void ebcAsc(char *in, char *out, size_t size) const
{
size_t size_out = size;
size_t size_in = size;
size_t rc;
rc = iconv(ebcdicAsciiConv, &in, &size_in, &out, &size_out);
if (rc == (size_t) -1)
throw(DumpException("Code page translation EBCDIC-ASCII failed"));
}
/* Members */
struct _adsr adsrRecord;
struct _fmbk fmbkRecord;
struct _albk albkRecord;
uint64_t memoryStartRecord;
char *bitmap;
uint64_t pageOffset;
private:
iconv_t ebcdicAsciiConv;
};
class VMDumpClassic : public VMDump
{
public:
VMDumpClassic(const char *filename);
virtual ~VMDumpClassic(void);
void printInfo(void);
inline virtual uint64_t getMemSize(void) const
{
return (uint64_t)asibkRecord.storage_size_2GB;
}
protected:
/* Types */
struct _asibk {
char id[8];
char as_token[8];
char spaceid[33];
char reserved1[3];
uint32_t storage_size_2GB;
uint32_t dcss_bitmap_first_rec;
uint32_t byte_past_highest_defined_byte;
uint64_t format_of_as;
char dump_id[100];
uint32_t nr_of_recs_of_first_bit_map;
} __packed;
/* Members */
struct _asibk asibkRecord;
};
#define MAX_BKEY_PAGES 2
class VMDump64Big : public VMDump
{
public:
VMDump64Big(const char *filename);
virtual ~VMDump64Big(void);
RegisterContent64 getRegisterContent(void);
void printDebug(void);
void printInfo(void);
inline virtual uint64_t getMemSize(void) const
{
return (uint64_t)asibkRecordNew.storage_size_def_store;
}
private:
inline int testBitmapPage(char *page, uint64_t bit) const
{
return (page[bit/8] & (1 << (7-(bit % 8))));
}
inline int testBitmapKeyPage(char *page, uint64_t bit) const
{
return (page[bit] & 0x01);
}
/* types */
struct _asibk_64_new {
char id[8];
char as_token[8];
char spaceid[33];
char reserved1[2];
uint8_t asibk_format;
char filler1[12];
uint64_t storage_size_with_dcss;
uint64_t storage_size_def_store;
char filler2[136];
uint64_t online_storage_table[8]; /* for "def store config" */
uint64_t fence1;
uint64_t requested_range_table[8];
uint64_t fence2;
uint32_t record_number_of_first_bit_map; /* XXX */
} __packed;
struct _fir_64 {
char id[8];
uint64_t reserved1;
uint64_t gprs[16];
uint32_t prefix;
char reserved2[5];
uint64_t tod;
char reserved3[8];
uint64_t cpu_timer;
char reserved4[7];
uint8_t flag;
uint8_t type;
uint8_t complete;
uint8_t fir_format; /* 0x82 for esame - 0x00 for esa */
uint8_t cont_flags;
uint8_t crypto_domain_index_reg;
uint8_t virt_cpu_info;
uint8_t arch_mode_id;
uint64_t psw[2];
uint64_t crs[16];
uint64_t fprs[16];
uint8_t reserved5;
uint64_t clock_cmp;
char reserved6[3];
uint32_t tod_programmable_reg;
uint32_t reserved_for_dvf[20];
uint32_t acrs[16];
uint32_t storage_size_2GB;
uint32_t reserved7;
uint32_t hcpsys_addr;
uint32_t reserved8;
uint64_t storage_size;
uint32_t snap_area_map_blk;
uint32_t reserved9;
char loc_mem[256];
uint16_t online_cpus;
uint16_t cpu_addr;
uint16_t section_size_vector;
uint16_t reserved10;
char asit_primary[8];
char space_id_primary[33];
char reserved12[3];
uint16_t crypto_domain_index_mask;
uint16_t reserved11;
uint32_t fp_cntrl_reg;
uint32_t reserved13;
uint64_t reserved14[16];
} __packed;
struct _fir_other_64 {
uint16_t cpu_addr;
uint16_t vector_sec_size;
uint8_t crypto_index_reg;
uint8_t virt_cpu_info;
uint16_t crypto_index_mask;
uint32_t reserved1[2];
uint64_t fprs[16];
uint64_t gprs[16];
uint64_t psw[2];
uint32_t reserved2[2];
uint32_t prefix;
uint32_t fp_cntrl_reg;
uint32_t reserved3;
uint32_t tod;
uint64_t cpu_timer;
uint64_t clock_cmp;
uint32_t reserved4[2];
uint32_t acrs[16];
uint64_t crs[16];
uint64_t mc_interrupt_code;
uint32_t reserved5;
uint32_t external_damage_code;
uint64_t mc_failing_storage_addr;
} __packed;
/* Members */
struct _asibk_64_new asibkRecordNew;
struct _fir_64 fir64Record;
struct _fir_other_64 *fir64OtherRecords;
};
class VMDump64 : public VMDumpClassic
{
public:
VMDump64(const char *filename);
virtual ~VMDump64(void);
RegisterContent64 getRegisterContent(void);
void printDebug(void);
void printInfo(void);
private:
/* Types */
struct _fir_64 {
char id[8];
uint64_t reserved1;
uint64_t gprs[16];
uint32_t prefix;
char reserved2[5];
uint64_t tod;
char reserved3[8];
uint64_t cpu_timer;
char reserved4[7];
uint8_t flag;
uint8_t type;
uint8_t complete;
uint8_t fir_format; /* 0x82 for esame - 0x00 for esa */
uint8_t cont_flags;
uint8_t crypto_domain_index_reg;
uint8_t virt_cpu_info;
uint8_t arch_mode_id;
uint64_t psw[2];
uint64_t crs[16];
uint64_t fprs[16];
uint8_t reserved5;
uint64_t clock_cmp;
char reserved6[3];
uint32_t tod_programmable_reg;
uint32_t reserved_for_dvf[20];
uint32_t acrs[16];
uint32_t storage_size_2GB;
uint32_t reserved7;
uint32_t hcpsys_addr;
uint32_t reserved8;
uint64_t storage_size;
uint32_t snap_area_map_blk;
uint32_t reserved9;
char loc_mem[256];
uint16_t online_cpus;
uint16_t cpu_addr;
uint16_t section_size_vector;
uint16_t reserved10;
char asit_primary[8];
char space_id_primary[33];
char reserved12[3];
uint16_t crypto_domain_index_mask;
uint16_t reserved11;
uint32_t fp_cntrl_reg;
uint32_t reserved13;
uint64_t reserved14[16];
} __packed;
struct _fir_other_64 {
uint16_t cpu_addr;
uint16_t vector_sec_size;
uint8_t crypto_index_reg;
uint8_t virt_cpu_info;
uint16_t crypto_index_mask;
uint32_t reserved1[2];
uint64_t fprs[16];
uint64_t gprs[16];
uint64_t psw[2];
uint32_t reserved2[2];
uint32_t prefix;
uint32_t fp_cntrl_reg;
uint32_t reserved3;
uint32_t tod;
uint64_t cpu_timer;
uint64_t clock_cmp;
uint32_t reserved4[2];
uint32_t acrs[16];
uint64_t crs[16];
uint64_t mc_interrupt_code;
uint32_t reserved5;
uint32_t external_damage_code;
uint64_t mc_failing_storage_addr;
} __packed;
/* Members */
struct _fir_64 fir64Record;
struct _fir_other_64 *fir64OtherRecords;
};
class VMDump32 : public VMDumpClassic
{
public:
VMDump32(const char *filename);
virtual ~VMDump32(void);
RegisterContent32 getRegisterContent(void);
void printDebug(void);
void printInfo(void);
private:
/* Types */
struct _fir_32 {
uint32_t gprs[16];
uint32_t crs[16];
uint64_t fprs[4];
uint64_t tod;
uint64_t cpu_timer;
uint64_t clock_cmp;
uint8_t flag;
uint8_t type;
uint8_t complete;
uint8_t fir_format;
uint32_t storage_size_2GB;
char loc_mem[256];
uint32_t prefix;
uint16_t online_cpus;
uint8_t cont_flags;
uint8_t crypto_domain_index_reg;
uint8_t virt_cpu_info;
uint8_t arch_mode_id;
uint16_t crypto_domain_index_mask;
uint32_t reserved1;
uint32_t snap_area_map_blk;
uint64_t reserved2;
uint32_t hcpsys_addr;
uint32_t reserved3[20];
uint32_t psw[2];
uint16_t cpu_addr;
uint16_t section_size_vector;
uint32_t acrs[16];
char asit_primary[8];
char space_id_primary[33];
char reserved4[131];
} __packed;
struct _fir_other_32 {
uint16_t cpu_addr;
uint16_t vector_sec_size;
uint32_t prefix;
uint8_t crypto_index_reg;
uint8_t virt_cpu_info;
uint16_t crypto_index_mask;
uint32_t reserved1;
uint64_t cpu_timer;
uint64_t clock_cmp;
uint64_t mc_interrupt_code;
uint64_t reserved2;
uint32_t mc_failing_storage_addr;
uint32_t machine_dependent_region_code;
uint32_t lixed_logout_area[4];
char reserved3[16];
uint32_t acrs[16];
uint64_t fprs[4];
uint32_t gprs[16];
uint32_t crs[16];
} __packed;
/* Members */
struct _fir_32 fir32Record;
struct _fir_other_32 *fir32OtherRecords;
};
#endif /* VMDUMP_H */

Some files were not shown because too many files have changed in this diff Show More