Compare commits

..

310 Commits

Author SHA1 Message Date
Jan Höppner
686262fdcd New release s390-tools-2.33.1
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-05-28 08:26:36 +02:00
Jan Höppner
2379fd8a58 s390-tools: Fix release string
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-05-28 08:26:36 +02:00
Jan Höppner
3552a27ae6 s390-tools: Fix README.md
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-05-28 08:26:36 +02:00
Steffen Eiden
39106ba760 Prepare for next release
Signed-off by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 17:54:42 +02:00
Steffen Eiden
f270ac99f0 New release s390-tools-2.33.0
Signed-off by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 17:53:57 +02:00
Marc Hartmayer
f83af8e076 rust: Generate shell (e.g. bash) completion scripts via build.rs for all tools
It might be handy to have shell completion support for the Rust PV
tools.

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>
2024-05-27 16:54:25 +02:00
Marc Hartmayer
4d2c92f6d5 rust/pvapconfig: Fix expected out doc comment
error[E0753]: expected outer doc comment

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:54:21 +02:00
Steffen Eiden
503e241db1 rust: Improve code formatting
Do some formatting that are in experimental stage but improve the code
readability.

Use rustfmt with a nightly toolchain and enable:

format_code_in_doc_comments = true
reorder_impl_items = true
comment_width = 100
wrap_comments = true
normalize_comments = true

(see .rustfmt.toml)

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:54:17 +02:00
Steffen Eiden
dea5f80215 libpv: Remove unused code
Remove all the code just pvattest-C used from libpv.
z(get)dump is the only user as of now.

Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:54:14 +02:00
Steffen Eiden
c261db259b zdump: Use constant for CCK size
This will reduce code dependency to otherwise unused code in libpv.
This code will be removed with the next patch.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:54:10 +02:00
Steffen Eiden
c382e7ef44 Remove pvattest-C and switch to pvattest-Rust implementation
Removes the C implementation of pvattest.
Use the Rust implementation instead.

Closes: https://github.com/ibm-s390-linux/s390-tools/issues/164
Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:54:06 +02:00
Steffen Eiden
16610a211f rust: pvattest-Rust
Add a CLI compatible Rust implementation of pvattest-C.
 - All (non-experimental) options are supported and work exactly as in
   the C implementation. For some options/parameters new variants are
   available.
 - `perform` now also accepts positional arguments, while keep accepting
   -i and -o  that was mandatory in the C implementation.
 - `version` may also be a command instead of an option now.
 - -V is deprecated
 - -v increases verbosity instead of showing the version
 - all experimental options are dropped

Acked-by: Qi Feng Huo <huoqif@cn.ibm.com>
Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:54:01 +02:00
Steffen Eiden
4d57ff046d rust: Prepare Cargo.toml for crates.io
Renames pv crate to s390_pv and pv_core to s390_pv_core. pv was already
taken on crates.io.

Bump the versions of all crates to 0.10.0. From now on we follow Semver
compatibility rules when it comes to updates. patch-level updates will
not introduce any backwards incompatible changes. For now all crates in
this directory will have the same version number. A version update may,
therefore, not add any new things.

Library users in this repository still use the non prefixed names and
rename the crate in the Cargo.toml. Doc-tests have to use the new name
however.

Add some Cargo metadata to the Cargo.toml.

Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:57 +02:00
Marc Hartmayer
4a76efe6d5 rust: Use AsRef<Path> and PathBuf in libraries
Use `AsRef<Path>` instead of `&Path`, &str, .... to be more versatile
and accept more input types. In addition, use `PathBuf` and `Path` for
paths instead of `String` and `str`.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:47 +02:00
Steffen Eiden
87d43c7a32 rust/pv_*: Add more deny lints to pv and pv_core
Denies compiling if one of the following lints find something in pv or
pv_core:
    missing_docs,
    missing_debug_implementations,
    trivial_numeric_casts,
    unstable_features,
    unused_import_braces,
    unused_qualifications

Those lint force developers to avoid unnecessary code and providing
debuggability & documentation for each public symbol.

Fix the compile time error introduced with those lints.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:43 +02:00
Steffen Eiden
f383278a5a rust/pv: Fix styling issues
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:39 +02:00
Steffen Eiden
a9d4b1e1b9 rust/pv: Inline openssl_extensions sub-crate
crates.io does not like sub-crates in a crate. Unpack the
openssl-extensions sub-crate into a (private) module.

While at it, fix some styling issues.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:35 +02:00
Steffen Eiden
61c5d7d431 rust/pv: Attestation generation and verification support
Add functionality to generate Attestation Measurement requests.
Add functionality to verify Attestation Measurement responses.

Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:32 +02:00
Steffen Eiden
b7765993e2 rust/pv_core: Attestation support
Add functionality for:

* sending attestation requests to the uvdevice and retrieve the
  response
* create/read the attestation exchange format file format

Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:27 +02:00
Steffen Eiden
e152b554f5 rust/pv: Add decrypt and HMAC function
Add a function to decrypt a block with aes_gcm.
Add functionality to perform HMAC operations.

Acked-by: Qi Feng Huo <huoqif@cn.ibm.com>
Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:21 +02:00
Steffen Eiden
c46a066827 rust/utils: Add Hexslice
Add a thin wrapper around [u8] to be able to represent an u8-slice as a
hex-string for Display and Serialize.

Acked-by: Qi Feng Huo <huoqif@cn.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:12 +02:00
Steffen Eiden
cf003379ac rust/pv_core: Remove !#[allow(unused)]
Remove !#[allow(unused)] in pv_core and fix all unused warnings from the
Rust compiler.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:07 +02:00
Steffen Eiden
7b94783cb7 rust/pv: More documentation
Improve the API documentation of the pv crate.

Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:03 +02:00
Steffen Eiden
38600bb4e2 rust/pv: Add conversion implementations
Add AsRef<[u8]> and TryFrom<Vec<u8>> implementations so that the tag
data can be converted into base64.
See: https://docs.rs/serde_with/latest/serde_with/base64/struct.Base64.html

While at it, fix some typos and simplify the tag extraction.

Suggested-by:  Qi Feng Huo <huoqif@cn.ibm.com>
Acked-by: Qi Feng Huo <huoqif@cn.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:56 +02:00
Marc Hartmayer
16875f7c6d rust/pv: Fix clippy finding
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:51 +02:00
Steffen Eiden
381fecfc44 rust: Refactoring and reduce API surface
Prepare pv & pv_core crates to be released on crates.io:
* Remove any unused API to stay flexible
* Remove utils dependency
* Move cli, tmpfile and version utilities to local utils crate
* Use the new utilities in the pv tools
* Rename Secret into Confidential to avoid confusion of Secret (now
  Confidential) and AddSecret requests.
* Move the uvsecret module out of the request module and change the name
  to secret.
* Cleanup dependencies
* Precise and correct minimal dependency versions
* Inline `Aes256Key::from_digest`

The cleanup ensures that the code also compiles with the dependencies
resolved to their minimal versions using:

$ cargo +nightly -Z minimal-versions update
$ cargo build

For more information refer to this blog post:
https://users.rust-lang.org/t/psa-please-specify-precise-dependency-versions-in-cargo-toml/71277/8

Signed-off-by: Marc Hartmayer <mhartmay@de.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:42 +02:00
Marc Hartmayer
5648b924d6 rust/pvsecret: verify.rs: fix clippy finding
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:38 +02:00
Steffen Eiden
636d2d571b rust/pvsecret: Update man files and help
Add subcommands in the man description. Add description for the help option.
Fix some minor wording issues.
Add the curve type  in the --user-data option of create.

Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:35 +02:00
Marc Hartmayer
d016ec129d pre-commit-config: exclude .key and .bin files
Modifying binaries or key material using pre-commit makes no sense.

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>
2024-05-27 16:52:31 +02:00
Peter Oberparleiter
cb77faeae7 chpstat: add tool to display channel-path statistics
Add a new tool named chpstat that can be used to view channel-path
statistics such as utilization and I/O throughput, and to query and
control the status of the channel-path statistics function.

Note: Channel-path statistics are only available on systems running in
      an LPAR or DPM partition.

When run without further options, data for all channel-paths is
displayed repeatedly with a 5 second delay in table format.

Example output:

      CHANNEL-PATH       UTILIZATION(%)   READ(B/s)  WRITE(B/s)
  ID TYP CMG SHR SPEED  PART TOTAL  BUS  PART TOTAL  PART TOTAL
  1d  25   2   1     -  7.16  7.50 7.50  129M  129M  0.00  161K
  21  1b   2   1   32G  0.00  0.00 0.00  0.00  0.00  0.00  0.00
  34  1b   2   1   32G  0.00  0.00 0.00  0.00  0.00  0.00  0.00
  61  25   2   1     -  0.00  0.01 0.00  0.00 2.00K  0.00  307K
  63  25   2   1     -  0.00  0.01 0.00  0.00  0.00  0.00  381K
  bd  11   2   1   10G     -     -    - 529.8 532.1 616.3 616.3

Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:27 +02:00
Peter Oberparleiter
38ea8fc3ee libutil: add output format helpers
Add helper functions for converting structured key-value data into
different formats such as JSON, text pairs, and CSV.

Using these functions the resulting output format can be dynamically
configured at run-time without the need to duplicate output-generating
code for each format type. Also format-specific requirements such as
quoting, indentation, and comma-placement are automatically taken care
of.

Basic API calling sequence:

 util_fmt_init()      => Select output format
 util_fmt_obj_start() => Start a new object or list
 util_fmt_pair()      => Emit a key-value pair
 util_fmt_obj_end()   => End the most recent object or list
 util_fmt_exit()      => Cleanup

Notes:
 - Supported data elements are objects, lists and key-value pairs
   (mappings)
 - Scalars are only supported as part of a mapping

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:23 +02:00
Peter Oberparleiter
d8e5bc07aa libutil: add function to concatenate a format string in place
Add function util_concatf() that appends the result of a format string
expansion to the end of an existing string while taking care of the
required memory allocations.

Usage example:

  char *str = NULL;

  util_concatf(&str, "list:");
  for (int i = 1; i <= 3; i++)
    util_concatf(&str, "%spart%d", (i > 1 ? "," : ""), i);
  printf("%s\n", str); /* list:part1,part2,part3 */

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:20 +02:00
Peter Oberparleiter
3b26f79143 libutil: add dynamic array helpers
Add helper macros to easily create, enlarge and append new elements to
dynamic arrays of arbitrary types.

Note: The use of dynamic arrays over lists may be preferable in some
cases to reduce complexity, and they may be required in cases where
elements need to be addressed directly by index.

Usage example:

  struct {
    int a;
    int b;
  } *array = NULL, element = { 1, 2 };
  unsigned int num = 0;

  util_add_array(&array, &num, element);
  printf("array[0].a=%d\n", array[0].a); /* array[0].a=1 */
  printf("array[0].b=%d\n", array[0].b); /* array[0].b=2 */

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:16 +02:00
Peter Oberparleiter
c366429e57 libutil: fix hexdump indentation
The current implementation of util_hexdump_grp() enforces a minimum
indentation of 1 space which may not be suitable for all users.

Fix this by allowing a true zero indentation level.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:13 +02:00
Peter Oberparleiter
8ed478ce46 libutil: enable record output without separator
The separator line emitted by util_rec functions may not be suitable for
all users. Fix this by making the hdr_sep parameter optional.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:09 +02:00
Peter Oberparleiter
a97a8f1cba libutil: fix util_file_write_* return code
By default, files opened via fopen are block-buffered. As a result,
I/O errors that occur during file write operations via util_file_write_*
are silently ignored because fputs() only buffers data while actual I/O
occurs during the flush operation that is part of the final fclose()
library call.

Fix this by indicating errors that occur during fclose() via the
util_file_write_* function return code.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:07 +02:00
Eduard Shishkin
fb0b6263d1 zipl/src: Fix problems when target parameters are specified by user
Steps to reproduce: Prepare some target disk for IPL, specifying
its parameters via zipl "target options", and an image IMAGE_NAME
located on another disk. Don't specify "-a" option.

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

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

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

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

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

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

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

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

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

Actual result: "Run /lib/s390-tools//zipl_helper.device-mapper /mnt
Error: Could not retrieve device-mapper information for device
'dasda1'"
Expected result: "Run /lib/s390-tools//zipl_helper.device-mapper 253:4
Error: Could not add image file 'IMAGE_NAME': File is not on target
device"

The problem is in incorrect calculation by disk_get_info()
parameters for @device associated with the image file. Specifically,
@target->bootmap_dir is passed to the script, which is wrong.

Fixup: Get rid of bogus branching in disk_get_info() in case when
target parameters are evaluated in "source_script" mode. Always pass
major and minor of the @device (whose parameters to be calculated)
to the helper script.

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:51:52 +02:00
Jan Höppner
7da5a6b9ed tunedasd: Fix missing hyphen escapes in the man page
Hyphens are converted by groff to a different unicode character leading
to failing command execution of copy-pasted options or examples.

Ensure that all hyphens are properly escaped.

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>
2024-05-27 16:51:48 +02:00
Jan Höppner
7ed87bed8c tunedasd: Fix trailing whitespace
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>
2024-05-27 16:51:45 +02:00
Jan Höppner
46ec94d0ce zdsfs: Fix missing hyphen escapes in the man page
Hyphens are converted by groff to a different unicode character leading
to failing command execution of copy-pasted options or examples.

Ensure that all hyphens are properly escaped.

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>
2024-05-27 16:51:42 +02:00
Jan Höppner
6bc0b023aa dasdstat: Fix missing hyphen escapes in the man page
Hyphens are converted by groff to a different unicode character leading
to failing command execution of copy-pasted options or examples.

Ensure that all hyphens are properly escaped.

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>
2024-05-27 16:51:38 +02:00
Jan Höppner
13d673e0f7 dasdstat: Fix man page title
The man page title was incorrectly set to "LSDASD". Set the correct name
"DASDSTAT".

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>
2024-05-27 16:51:35 +02:00
Jan Höppner
c40c159173 lsdasd: Fix missing hyphen escapes in the man page
Hyphens are converted by groff to a different unicode character leading
to failing command execution of copy-pasted options or examples.

Ensure that all hyphens are properly escaped.

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>
2024-05-27 16:51:32 +02:00
Jan Höppner
202ded5d11 tape390: Fix missing hyphen escapes in the man pages
Hyphens are converted by groff to a different unicode character leading
to failing command execution of copy-pasted options or examples.

Ensure that all hyphens are properly escaped.

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>
2024-05-27 16:51:28 +02:00
Jan Höppner
e3a698c382 tape390: Fix trailing whitespace in man pages
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>
2024-05-27 16:51:22 +02:00
Jan Höppner
3a60b4caa8 fdasd: Fix missing hyphen escapes in the man page
Hyphens are converted by groff to a different unicode character leading
to failing command execution of copy-pasted options or examples.

Ensure that all hyphens are properly escaped.

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>
2024-05-27 16:51:19 +02:00
Jan Höppner
f57858b3a8 dasdview: Fix missing hyphen escapes in the man page
Hyphens are converted by groff to a different unicode character leading
to failing command execution of copy-pasted options or examples.

Ensure that all hyphens are properly escaped. Fix whitespace damage
along the way.

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>
2024-05-27 16:51:15 +02:00
Jan Höppner
9e430b9010 dasdinfo: Fix missing hyphen escapes in the man page
Hyphens are converted by groff to a different unicode character leading
to failing command execution of copy-pasted options or examples.

Ensure that all hyphens are properly escaped.

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>
2024-05-27 16:51:10 +02:00
Jan Höppner
ad2a42ce9e dasdfmt: Fix missing hyphen escapes in the man page
Hyphens are converted by groff to a different unicode character leading
to failing command execution of copy-pasted options or examples.

Ensure that all hyphens are properly escaped.

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>
2024-05-27 16:51:05 +02:00
Nikita Dubrovskii
1c32635b3a chreipl: Impove disk type detection when running under QEMU
Under QEMU user can attach disk with smth like:
```
  -device virtio-scsi-ccw,... -device scsi-hd,...
```
So virtio block device appears as '/dev/sda' instead of '/dev/vda'.
chreipl assumes all '/dev/sd*' disks as FCP disks, which is not a
case in such setup.

Closes: https://github.com/ibm-s390-linux/s390-tools/pull/154
Signed-off-by: Nikita Dubrovskii <nikita@linux.ibm.com>
Acked-by: Marc Hartmayer mhartmay@linux.ibm.com
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:51:00 +02:00
Nikita Dubrovskii
558594fddf ipl_tools/ccw: Introduce device_sysfs_path()
Add helper function to get device's real path under SYSFS_ROOT devices
hierarchy.

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/154
Signed-off-by: Nikita Dubrovskii <nikita@linux.ibm.com>
[hoeppner@linux.ibm.com: Adapt commit message]
Acked-by: Marc Hartmayer mhartmay@linux.ibm.com
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:50:42 +02:00
Harald Freudenberger
c8879322b0 pvapconfig: Escape hyphens in man page correctly
Insert backslash(es) to escape the hyphens used
in the pvapconfig man page correctly.

Suggested-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:50:27 +02:00
Harald Freudenberger
d716c553c4 chzcrypt: Escape hyphens in man page correctly
Insert backslash(es) to escape the hyphens used
in the chzcrypt man page correctly.

Suggested-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:50:21 +02:00
Harald Freudenberger
ab35922161 lszcrypt: Escape hyphens in man page correctly
Insert backslash(es) to escape the hyphens used
in the lszcrypt man page correctly.

Suggested-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:50:18 +02:00
Matthew Rosato
474c6adf8f libap: use custom wait time for file locks
If many invocations of mdevctl occur simultaneously (as can happen with
libvirt) then waiting for 5-60 seconds per lock retry is simply too long.
Anticipating this possibility, retry more frequently but also attempt
significantly more retries than before.

Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Marc Hartmayer <marc@linux.ibm.com>
Tested-by: Marc Hartmayer <marc@linux.ibm.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:50:15 +02:00
Matthew Rosato
f5f806af06 libutil/util_lockfile: allow for custom lock wait/retry time
The default values for repeated attempts at acquiring a file lock created
by util_lockfile are on the order of seconds.  Let's leave this the
default, but allow for a caller to specify smaller values by adding
cw (custom_wait) functions and by switching from using sleep to usleep.

Reviewed-by: Anthony 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>
2024-05-27 16:50:12 +02:00
Ingo Franzki
0a01719477 zcryptstats: Fix missing hyphen escapes in man pages
Ensure that all hyphens in command options and examples are escaped properly.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:50:08 +02:00
Ingo Franzki
07cd9143da zkey: Fix missing hyphen escapes in man pages
Ensure that all hyphens in command options and examples are escaped properly.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:50:04 +02:00
Mikhail Zaslonko
d064cb522f include/boot: Sync os_info.h with kernel version.
Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:50:00 +02:00
Alexander Egorenkov
802c7db50e zfcpdump: fix hsa release for V!=R kernel
Since V!=R kernel introduction, HSA memory can be
contained in/spread over more than one ELF LOAD segment of
/proc/vmcore simultaneously. Therefore, the old HSA release logic is no
longer valid because it assumes that HSA memory is fully contained in
exactly one ELF LOAD segment of /proc/vmcore. This resulted in zfcpdump
releasing HSA memory too soon and by that making parts of /proc/vmcore
which cover HSA memory unreadable by user space. To correct this
problem on V!=R kernel, we need first to find all ELF LOAD segments
containing HSA memory, write those /proc/vmcore parts first and only then
release HSA memory. The new HSA release logic must be able to handle
both V!=R and V==R kernels to be backwards compatible.

====================
Tests of V!=R kernel
====================

Output of test run (KASLR on)
=============================

Writing dump:

TRACE: Read: /sys/kernel/debug/zcore/hsa:
TRACE: '2ffff000'

TRACE: ELF LOAD segment: p_offset=0x0000000000009000 p_filesz=0x0000000001cb0000 p_paddr=0x00000002f1e30000 p_vaddr=0x000002c609044000
TRACE: ELF LOAD segment: p_offset=0x0000000001cb9000 p_filesz=0x0000000040000000 p_paddr=0x0000000000000000 p_vaddr=0x000001bd00000000
TRACE: ELF LOAD segment: p_offset=0x0000000041cb9000 p_filesz=0x0000000300000000 p_paddr=0x0000000100000000 p_vaddr=0x000001be00000000

TRACE: Write copy table entry 0: off=0x0000000001cb9000 size=0x000000002ffff000 hsa=1
TRACE: Write copy table entry 1: off=0x0000000000001000 size=0x0000000001cb8000 hsa=0
TRACE: Release HSA memory
TRACE: Write copy table entry 2: off=0x0000000031cb8000 size=0x0000000310001000 hsa=0
TRACE: Write copy table entry 3: off=0x0000000000000000 size=0x0000000000001000 hsa=0

Dump successful

Output of test run (KASLR off)
==============================

Writing dump:

TRACE: Read: /sys/kernel/debug/zcore/hsa:
TRACE: '2ffff000'

TRACE: ELF LOAD segment: p_offset=0x0000000000009000 p_filesz=0x0000000001cb0000 p_paddr=0x0000000000c21000 p_vaddr=0x000003ffe0000000
TRACE: ELF LOAD segment: p_offset=0x0000000001cb9000 p_filesz=0x0000000040000000 p_paddr=0x0000000000000000 p_vaddr=0x000002f200000000
TRACE: ELF LOAD segment: p_offset=0x0000000041cb9000 p_filesz=0x0000000300000000 p_paddr=0x0000000100000000 p_vaddr=0x000002f300000000

TRACE: Write copy table entry 0: off=0x0000000000009000 size=0x0000000001cb0000 hsa=1
TRACE: Write copy table entry 1: off=0x0000000001cb9000 size=0x000000002ffff000 hsa=1
TRACE: Write copy table entry 2: off=0x0000000000001000 size=0x0000000000008000 hsa=0
TRACE: Release HSA memory
TRACE: Write copy table entry 3: off=0x0000000031cb8000 size=0x0000000310001000 hsa=0
TRACE: Write copy table entry 4: off=0x0000000000000000 size=0x0000000000001000 hsa=0

Dump successful

====================
Tests of V==R kernel
====================

Output of test run (KASLR on)
=============================

Writing dump:

TRACE: Read: /sys/kernel/debug/zcore/hsa:
TRACE: '2ffff000'

TRACE: ELF LOAD segment: p_offset=0x0000000000009000 p_filesz=0x0000000000000000 p_paddr=0x0000000000000000 p_vaddr=0x0000000000000000
TRACE: ELF LOAD segment: p_offset=0x0000000000009000 p_filesz=0x0000000040000000 p_paddr=0x0000000000000000 p_vaddr=0x0000000000000000
TRACE: ELF LOAD segment: p_offset=0x0000000040009000 p_filesz=0x0000000300000000 p_paddr=0x0000000100000000 p_vaddr=0x0000000100000000

TRACE: Write copy table entry 0: off=0x0000000000009000 size=0x000000002ffff000 hsa=1
TRACE: Write copy table entry 1: off=0x0000000000001000 size=0x0000000000008000 hsa=0
TRACE: Release HSA memory
TRACE: Write copy table entry 2: off=0x0000000030008000 size=0x0000000310001000 hsa=0
TRACE: Write copy table entry 3: off=0x0000000000000000 size=0x0000000000001000 hsa=0

Dump successful

Output of test run (KASLR off)
==============================

Writing dump:

TRACE: Read: /sys/kernel/debug/zcore/hsa:
TRACE: '2ffff000'

TRACE: ELF LOAD segment: p_offset=0x0000000000009000 p_filesz=0x0000000000000000 p_paddr=0x0000000000000000 p_vaddr=0x0000000000000000
TRACE: ELF LOAD segment: p_offset=0x0000000000009000 p_filesz=0x0000000040000000 p_paddr=0x0000000000000000 p_vaddr=0x0000000000000000
TRACE: ELF LOAD segment: p_offset=0x0000000040009000 p_filesz=0x0000000300000000 p_paddr=0x0000000100000000 p_vaddr=0x0000000100000000

TRACE: Write copy table entry 0: off=0x0000000000009000 size=0x000000002ffff000 hsa=1
TRACE: Write copy table entry 1: off=0x0000000000001000 size=0x0000000000008000 hsa=0
TRACE: Release HSA memory
TRACE: Write copy table entry 2: off=0x0000000030008000 size=0x0000000310001000 hsa=0
TRACE: Write copy table entry 3: off=0x0000000000000000 size=0x0000000000001000 hsa=0

Dump successful

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:49:54 +02:00
Marc Hartmayer
0f87acc2b3 common.mak: Improve overall Makefile performance
Improve overall Makefile performance by dramatically reducing the number
of fork and exec system calls through the use of simply expanded
variables [1]. Before this change, a simple `make -C libutil` invocation
used over 4000 execs, after this change it was reduced to just over 300
execs.

[1] https://www.gnu.org/software/make/manual/html_node/Setting.html

Reported-by: Ingo Franzki <ifranzki@linux.ibm.com>
Tested-by: Ingo Franzki <ifranzki@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@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>
2024-05-27 16:49:05 +02:00
Eduard Shishkin
998b61e5f3 dasdfmt: Change mode default
When formatting an ESE (thin-provisioned) ECKD DASD, dasdfmt(8)
defaults to the quick-format mode instead of full-format for normal
DASDs. This results in a significant performance impact during first
sequential write to each track, which may be unexpected for users.

To address this, change the default for dasdfmt to always use
full-format mode. Customers that require thin provisioning(*) still
override the default by specifying quick format explicitly using the
"-M" option.

Get rid of the related fallbacks; In case of unsuccessful space
release always fail. The customers that still require quick format can
proceed by specifying "--no-discard" option.

(*) Thin provisioning: while providing a large amount of logical
    space, zero amount of actual space is provisioned and then
    allocated on an on-demand basis.

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>
2024-04-26 15:07:19 +02:00
Joern Siglen
c47071815b dbginfo.sh: use POSIX uname options
uname -i is not defined POSIX and will fail on some linux distributions

Reviewed-by: Michael Storzer <mstorzer@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Mikhail Zaslonko
0ed6c1ccde zfcpdump: Search for zero paddr vmcore load to identify HSA
Check for vmcore LOAD segment with zero paddr (instead of zero vaddr) to
identify HSA since physical and virtual addresses can be uncoupled on s390.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Acked-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Vineeth Vijayan
d888a27f07 zconf/chp: add reference to zos document
The 'lschp' command's output contains a 'type' identifier column. For
information about each value of this identifier, provide the
reference to the z/OS public documentation in the manpage.

Suggested-by: Mike Storzer <MSTORZER@de.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>
2024-04-26 15:07:19 +02:00
Steffen Eiden
7c2ae3d2e8 rust/pvsecret: Streamline arch dependend code
Get rid of all arch barriers in main.rs. cmd.rs handles the arch
barriers for the individual commands. Simplifies main.rs & cmd.rs and
makes it easier to read and understand the code.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Steffen Eiden
c88a8b6130 rust/pvapconfig: Fix Cargo clippy findings
Fix findings from `cargo clippy --all-targets`. `warning: calls to
`push` immediately after creation` The findings were in test code only.

Also, replace a while loop with a function from Vec.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Steffen Eiden
32a0434bc3 rust/pv_core: Always report rc and rrc for an UV error
The (non-archiected) rrc helps to debug issues. Therefore report them
also in release builds.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Steffen Eiden
a2e556858a rust/pv_core: Remove unnecessary mirrored constants
They add no value and code outside the crate does not need those constants.
Reduces unnecessary constant duplication. Introduce an error for to
large Add-Secret requests and check for this to render those contsnts
fully unnecessary for the API.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Steffen Eiden
9eab43994b rust/pv: Remove internal BinGuestSecret struct
The BinGuestSecret type provides no benefits. The public GuestSecret
struct can handle everything. Therefore, move the two functions from bin
to the non-bin variant. While at it, use a struct to define the binary
structure instead of copy numbers to some positions in a Vec. This
simplifies the addition of further secret types.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Steffen Eiden
c53dfa9754 rust/pv: Use a SecretId struct instead of an array
This streamlines and unifies the use and (de)serialization of structs
using a secret id. As a bonus, the hidden `for_pv` module is not longer
needed.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Steffen Eiden
81a1e13f3b rust/pv: Provide default for UvCmd::cmd
Provides a default for the cmd function for an UvCmd. This is enabled by
requiring an associated constant for the IOCTL nr of the command.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Steffen Eiden
8f89234f1a rust/pv: Remove dangling file
The content of `pv/src/uvsecret/uvc.rs` was moved with
9b51b8b882 ("rust/pv: Refactor pv crate") to pv_core.
The content was unused, but the file was not deleted.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Steffen Eiden
d757dbfbff rust/pv: Introduce AesGcmResult type
Fix clippy waring `warning: very complex type used.` by introducing a
new struct containing the tuple, that was returned before.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Steffen Eiden
0d9a6e45fb rust/pv_core: Refractor secret list to own file
This makes the secret.rs file more readable.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Steffen Eiden
4d4666cff7 rust/README.md: Add pvapconfig to the tools section
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Steffen Eiden
46092add29 rust/pv_core: Fix lazy-static dev-dependency
During the remove of mockito, lazy_static dependency was accidentally
removed as well.
Fix this by adding lazy-static as dev dependency again.

Fixes: aba8900074 ("rust/pv_core: Remove mockito dependency")
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 15:07:19 +02:00
Finn Callies
1655c39ded cpacfstats: add counter numbers to output
This adds the counter numbers to the corresponding counter names to the
cpacfstats output. This aims to ease using this tool with other related
tools which may use other names for the counters.

Signed-off-by: Finn Callies <fcallies@linux.ibm.com>
Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 14:37:52 +02:00
Vineeth Vijayan
a95dc09c6e zdev: add common header for chzdev generated tempfile too
All files created by chzdev feature a common header; however, this
header is absent in temporary files. It is necessary to incorporate
the consistent "Generated by chzdev" header into temporary files
generated by chzdev as well, so as to properly identify these files
via option --is-owner.

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>
2024-04-26 14:37:52 +02:00
Vineeth Vijayan
f1f80a8a20 zdev: implement option to identify files created by zdev
Enhance the 'chzdev' tool by introducing a new option to discern
files created by 'zdev-tools.' The command usage is as follows:

$ chzdev --is-owner <file-name>

When executed, the command will return an exit code of 0 for all
files generated by zdev-tools. In the case of an unknown file, the
tool will return the exit code 'EXIT_UNKNOWN_FILE i.e 33.'

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>
2024-04-26 14:37:52 +02:00
Vineeth Vijayan
4c2bfb1d47 zdev: rename site.h to zdev.h
Add zdev-specific definitions into a lightweight header file. Rather
than creating a new one, transform the existing "site.h" into "zdev.h"
to house all generic zdev-specific definitions that needs to be shared
between chzdev, lszdev and zdev_id going forward.

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>
2024-04-26 14:37:51 +02:00
Finn Callies
c0fc21efb3 cpacfstats: dynamically load PAI and CPUMF counter
Up until now cpacfstats assumes that on the running hardware either all
PAI and CPUMF are available or non at all.  Which counters are supported
may be hardware dependent and can vary in the future. With
this commit cpacfstats dynamically loads the counters from sysfs entries
in (/sys/devices/pai_crypto/events/) and (/sys/devices/cpum_cf/events/)
respectively.

Additionally cpacfstats has a new way of determining which PAI counters
are meant for kernel usage.

Signed-off-by: Finn Callies <fcallies@linux.ibm.com>
Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-04-26 14:37:51 +02:00
Steffen Eiden
93d3c44a1a Prepare for next release
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-04-03 16:18:09 +02:00
Steffen Eiden
9eea78b3ad New release s390-tools-2.32.0
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-04-03 16:18:09 +02:00
Steffen Eiden
0a3a556879 rust/Cargo.lock: Update curl-sys crate
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-04-03 16:18:09 +02:00
Steffen Eiden
aba8900074 rust/pv_core: Remove mockito dependency
With f6c6f0cc71 ("rust/pv/test: Code + Certificate refactoring")
no code uses mockito anymore, but it's dependency was not removed.

Remove the mockito dependency from the rust workspace.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-04-03 16:18:09 +02:00
Dan Horák
f5744b95db genprotimg: Fix build with OpenSSL 1.1
OpenSSL 1.1 seems to use a non-const parameter to X509_name_dup(), but
x509_armonk_locality_fixup() is passing a const there. The compile then
fails on "discards 'const' qualifier", when -Werror is used. Thus
resolve with a type-cast like in c2b_name().

Fixes: https://github.com/ibm-s390-linux/s390-tools/pull/167
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Dan Horák <dan@danny.cz>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-04-02 17:37:53 +02:00
Dan Horák
13d721afd3 libpv: Fix build with OpenSSL 1.1
OpenSSL 1.1 seems to use a non-const parameter to X509_name_dup(), but
x509_armonk_locality_fixup() is passing a const there. The compile then
fails on "discards 'const' qualifier", when -Werror is used. Thus
resolve with a type-cast like in pv_c2b_name().

GitHub-ID: https://github.com/ibm-s390-linux/s390-tools/pull/167
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Dan Horák <dan@danny.cz>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-04-02 17:37:53 +02:00
Eduard Shishkin
90a2e6d70e zipl/src: Fix leak of files
Fix leak of temporary files: if prepare_build_program_table_file()
is called in no dry-run mode and there was an error then the file
@filename will not be deleted in free_bootloader()).

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

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

                    Original logic:

prepare_bootloader_ipl():
prepare_bootloader_ngdump():

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

prepare_bootloader_device():

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

                    New logic:

prepare_bootloader_ipl():
prepare_bootloader_ngdump():

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

prepare_bootloader_device():

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

Fixes: https://github.com/ibm-s390-tools/s390-tools/issues/165
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Acked-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-04-02 17:37:53 +02:00
Marc Hartmayer
bc9f8a8100 genprotimg: Fix out-of-disk space handling
Convert the assertion to a GError since an out-of-disk-space situation
is a valid situation that should be handled.

ERROR:utils/crypto.c:1843:__encrypt_decrypt_bio: assertion failed: (num_bytes_written == out_len)
Bail out! ERROR:utils/crypto.c:1843:__encrypt_decrypt_bio: assertion failed: (num_bytes_written == out_len)

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>
2024-04-02 17:37:53 +02:00
Steffen Eiden
2b5e7b0491 pvattest: Fix root-ca parsing
The parser setup falsely set the argument type as filename array, but
code expected a single filename. Fixed by setting up the parser
correctly to expect a single file name.

Fixes: 3ab06d77fb ("pvattest: Create, perform, and verify attestation measurements")
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-22 12:07:29 +01:00
Steffen Eiden
d7c95265cd libpv: Support Armonk in IBM signing key subject
New IBM signing keys will have Armonk as locality in the subject.
Ensure that CRLs with Poughkeepsie as issuer locality are still
discovered if they are signed with the signing keys private key.
Also, drop the check for issuer/subject comparison and only rely on
validity period and cryptographic signatures.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-22 12:07:29 +01:00
Marc Hartmayer
8751cfc409 genprotimg/samples/check_hostkeydoc: code formatting
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-22 12:07:29 +01:00
Marc Hartmayer
01f96d30f6 genprotimg/samples/check_hostkeydoc: fix ShellCheck findings
Fix ShellCheck findings and two typos. White spaces in filenames are now
supported properly.

Reviewed-by: Christoph Schlameuss <schlameuss@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>
2024-03-22 12:07:29 +01:00
Marc Hartmayer
fffbd93f12 genprotimg/samples/check_hostkeydoc: improve argument parsing
+ use `getopts` POSIX builtin instead of external program
+ improve error reporting
+ support white spaces in the script name

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-22 12:07:29 +01:00
Marc Hartmayer
ddcfbdc8d2 genprotimg/samples/check_hostkeydoc: support Armonk in IBM signing key subject
Newer IBM signing keys use `Armonk` in their subject therefore add
support for it.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-22 12:07:29 +01:00
Marc Hartmayer
173fd7cdca genprotimg/samples/check_hostkeydoc: set LC_ALL=C for the sort command
Set `LC_ALL=C` for the `sort` command to get a stable sort order. See
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html for
details on the effect of LC_* on `sort`. Adapt the default issuer
accordingly.

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>
2024-03-22 12:07:29 +01:00
Marc Hartmayer
d14e7593cc genprotimg: support Armonk in IBM signing key subject
New IBM signing certificates will have 'Armonk' as locality in the
subject. Make sure that certificate revocations lists (CRL) with
'Poughkeepsie' as issuer locality are still considered as valid as long
as they are signed with the IBM signing keys private key. In addition,
drop the check for 'issuer(HKD) == subject(HKSK)' as it doesn't improve
security. While at it, remove now unused functions and fix a memory leak
of @akid in `check_crl_issuer`.

Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-22 12:07:29 +01:00
Steffen Eiden
1a3d0b74f7 rust/pv: Support Armonk in IBM signing key subject
New IBM signing keys will have Armonk as locality in the subject.
Ensure that CRLs with Poughkeepsie as issuer locality are still
discovered if they are signed with the signing keys private key.
Also, drop the check for issuer/subject comparison and only rely on
validity period and cryptographic signatures.

Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-22 12:07:29 +01:00
Marc Hartmayer
f6c6f0cc71 rust/pv/test: Code + Certificate refactoring
* Get rid of Mockito
* create certs with AKID
* simplify things in the `create_certs.py` script

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-22 12:07:29 +01:00
Thomas Richter
966e67a252 cpumf/lscpumf: add support for machine type 3932
Add support for machine type 3932 and list the
CPU Measurement facility counter sets.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-22 12:07:29 +01:00
Joern Siglen
1c128c0d11 dbginfo.sh: dash compatible copy sequence
rewrite the copy of dbginfo.sh for dash compatibility

Reviewed-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: Steffen Eiden <seiden@linux.ibm.com>
2024-03-22 12:07:29 +01:00
VasiliyS
a3199d58db rust/pv_core: Fix UvDeviceInfo::get() method.
`ATTESTATION_NR` flag was not set properly in case the device
didn't support `Info` IOCTL call.

Closes: https://github.com/ibm-s390-linux/s390-tools/pull/163
Signed-off-by: Vasiliy Suvorov <vsuvorov@gmail.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-22 12:07:29 +01:00
Vineeth Vijayan
659483031e zdev: Rearrange the options alphabetically in man page
re-arrange options in zdev manpages in the alphabetical order.

Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:43 +01:00
Ingo Franzki
7dc2513205 zkey: Detect FIPS mode and generate PBKDF for luksFormat according to it
For LUKS2 volumes, zkey generates 'cryptsetup luksFormat' commands with
options '--pbkdf argon2i --pbkdf-memory 32 --pbkdf-force-iterations 4'
for low memory and time requirements. Using the default Argon2i options
might cause out-of-memory errors when multiple encrypted volumes are
unlocked automatically at boot through /etc/crypttab.

When the system runs in FIPS mode, which is indicated by file
/proc/sys/crypto/fips_enabled containing '1', the Argon2i password based
key derivation function might be disabled by a policy, and such
'cryptsetup luksFormat' commands might fail.

Generate '--pbkdf pbkdf2' instead if the system runs in FIPS mode.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:43 +01:00
Marc Hartmayer
0748d365a6 genprotimg/**/Makefile: Fix staged installs
Fix the support for staged installs. The Makefile variable `PKGDATADIR`
uses `DESTDIR` for all Makefile target, but actually it should only be
used for the `install*` and `uninstall*` targets. [1] Fix this by using
`DESTDIR` only for `install*` targets - uninstall* targets are not
supported by s390-tools.

Before this change, if `DESTDIR` was set for staged installs,
`genprotimg` has tried to find the bootloader binaries at the temporary
installation path `$DESTDIR$(TOOLS_DATADIR)/genprotimg/` instead of
`$(TOOLS_DATADIR)/genprotimg`.

[1] https://www.gnu.org/prep/standards/html_node/DESTDIR.html

Fixes: 65b9fc442c ("genprotimg: introduce new tool for the creation of PV images")
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>
2024-03-15 15:11:38 +01:00
Marc Hartmayer
94a404ed10 pvattest: Makefile: Remove unused variable and CFLAGS
Remove unused variables and unused compiler flags.

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>
2024-03-15 15:11:34 +01:00
Thomas Richter
ef1799f31f s390-tools/libutil: Add machine type 3932
Add support for machine type 3932.
Print identical product name for machine types 8561 and 8562.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Suggested-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:34 +01:00
Mikhail Zaslonko
47b0960cc7 zdump: Make ngdump_get_part_path() public
Make ngdump_get_part_path() public in order for unit-tests to access it.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:34 +01:00
Mikhail Zaslonko
2288331a6f zipl: Clear CCW-type DASD dumper upon ldipl-dump tool installation
Clear CCW-type DASD standalone dumper (if installed on the DASD) upon
successful installation of the List-Directed ECKD dump tool on the same
device. This helps to avoid 'zgetdump -d' confusion and have only one
'active' dump tool per disk.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Acked-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:34 +01:00
Mikhail Zaslonko
23e9156f43 s390_dump.h: Add DF_S390_DUMPER_MAGIC_SIZE constant
Add DF_S390_DUMPER_MAGIC_SIZE constant to s390_dump.h.
Use it instead of hardcoded length when processing dumper magics
in zgetdump code.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Acked-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:34 +01:00
Mikhail Zaslonko
8f99e7c4ea zdump: Move DUMPER_MAGIC constants to include/dump/s390_dump.h
Move DUMPER_MAGIC constants from df_s390.h to the global header
include/dump/s390_dump.h in order to reuse it in zipl code.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:34 +01:00
Mikhail Zaslonko
f3bcd94524 zdump: Add zgetdump -d support for ECKD ldipl-dump
Make 'zgetdump -d' to identify ldipl-dump tool (ngdump) installed on DASD
volume just like it does for NVMe ngdump.

Output sample:
-------------
Dump device info:
  Dump tool.........: Next Generation (NGDump) dump tool
  Version...........: 1
  Architecture......: s390x (64 bit)

Partition info:
  Partition number..: 2

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:34 +01:00
Mikhail Zaslonko
a2f8b19c2a dumpconf: Update the man page and etc/sysconfig/dumpconf template
Update dumpconf man page with list-directed ECKD dump information (new
attributes and configuration example for ECKD LDIPL dump).
Update etc/sysconfig/dumpconf with list-directed ECKD dump configuration
example.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:34 +01:00
Mikhail Zaslonko
588d720517 dumpconf: Process br_chr and bootprog eckd attributes
- Write the following sysfs attributes for list-directed ECKD devices
  introducing setup_eckd_device() function.
    br_chr: location of boot record
    bootprog: boot program selector
- Remove redundant parameters from setup_ccw_device() and setup_fcp_device()
  functioins.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:34 +01:00
Ingo Franzki
cd822cb770 zkey: Fix convert command to accept only keys of type CCA-AESDATA
Reject conversion of other key types with a proper error message.
Also fix a typo in another error message of the convert command.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:34 +01:00
Ingo Franzki
b27b8e3cd3 zkey: Fix typos in error message
Use a colon instead of a semicolon in the message.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:34 +01:00
Steffen Maier
7a2c5dc980 zdev/dracut: Fix file mode of non-executable shell library zdev-lib.sh
Use similar `install` mode option in Makefile as in commit
9b2fb1d4d2 ("zdev: add helper to convert from dasd_mod.dasd to zdev
config").

Fixes: 73c46a3056 ("zdev/dracut: fix kdump by only activating required devices")
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-03-15 15:11:28 +01:00
Jan Höppner
d9e3763d1c Prepare for next release
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-02-02 17:49:44 +01:00
Jan Höppner
6f15ed3264 New release s390-tools-2.31.0
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-02-02 17:49:44 +01:00
Joern Siglen
0d2b5af007 dbginfo.sh: check for DPM mode
check if the LPAR is running in DPM mode and reflect this in the summary.

Suggested-by: Mike Storzer <MSTORZER@de.ibm.com>
Acked-by: Eberhard Pasch <epasch@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>
2024-02-02 16:11:22 +01:00
Jan Höppner
9e7a8f48e8 common.mak: Set default C/C++ standard to gnu11/gnu++11
s390-tools doesn't define a common C/C++ standard at the moment.
Set the standard to gnu11/gnu++11, which is also used by the Kernel, and
establish a common baseline for all tools.

The -std flag is added to ALL_CFLAGS and ALL_CXXFLAGS to avoid losing it
in case CFLAGS are set by an outside entity.
It is also added to CLAGS_FOR_BUILD for this one special cross build
case.

The -std flag is removed from all tools that set it manually until now.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-02-02 16:11:22 +01:00
Steffen Eiden
98f7a0569c rust/pvsecret: User defined signatures and verifications
Introduces the ability to `pvsecret` to add a signature (ecdsa or rsa)
to the program-reserved space (user-data) of an add-secret request
during the request creation. Additionally, some arbitrary data may be
inserted.

The new command `verify` checks if add-secret requests are sane (e.g.
start with the correct magic value). If the request contains a
user-signature `verify` will also verify this signature.

Acked-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>
2024-02-02 16:11:22 +01:00
Steffen Eiden
551f66282e rust/pvsecret: Streamline man and README
Makes the source for the manfiles&README more readable. Fixes some nits
like double spaces, unnessecary indentations, line breaks, ...
Removes pvsecret-version.1 as this command maps to the --version
option.

Acked-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>
2024-02-02 16:11:22 +01:00
Steffen Eiden
3d2ba5aaed rust/pvsecret: Sync man and help
The output of --help and man pages got out of sync.
Apply changes to the help output to fix this.

Acked-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>
2024-02-02 16:11:22 +01:00
Steffen Eiden
94942a48ab rust/pv: Add function to read a private key
Add a function to read a private key in PEM or DER format.

While at it, fix some documentation issues in read_{certs, crls}.

Reviewed-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>
2024-02-02 16:11:22 +01:00
Steffen Eiden
ab8984a7a3 rust/pv: Remove unused functions
Reviewed-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>
2024-02-02 16:11:22 +01:00
Marc Hartmayer
4990f643c1 rust/pv: Add-Secret: Add user-data and user-defined signing keys
User-data can be added to add-secret requests. User-data can be unsigned
or containing a signature of the request using a custom private key.

The user-data is placed at offset 0x218 and 0x200 bytes long.

Reviewed-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>
2024-02-02 16:11:22 +01:00
Steffen Eiden
34bef977e8 rust/pv: User-data signing and verifying
Add the ability to generate signed user-data and to verify the
signature.

Reviewed-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>
2024-02-02 16:11:22 +01:00
Steffen Eiden
f36c34038b rust/pv: Add-Secret: Add user-data types
Add four new user-data types an add-secret request could have:
Unsigned, Signed(EcSECP521R1, Rsa(2048, 3072))

As the user-data enum was not marked as non-exaustive this might be a
breaking change for users. (Not for any crate in this repo though).

The addition of such user-data is provided by following patches.

Reviewed-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>
2024-02-02 16:11:22 +01:00
Steffen Eiden
bfd0e12d22 rust/pv: Signing messages
Adds the ability to sign and verify messages using ECDH or RSA keys.

Reviewed-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>
2024-02-02 16:11:21 +01:00
Steffen Eiden
1450f85ada rust/pv: Fix documentation issue
Add the missing plaintext flags to the request description.

Reviewed-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>
2024-02-02 16:11:21 +01:00
Marc Hartmayer
2a0f1e6977 pvsecret: improve warning if host key document contains multiple certificates
Improve the warning for the case where a host key document contains
multiple certificates (only possible for a PEM file). In case there are
multiple host key document only the first certificate 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>
2024-02-02 16:11:21 +01:00
Marc Hartmayer
0f433b1142 pvsecret: fix panic if empty file is used as host key document
Fix a panic in `pvsecret` when a empty file is used as a host key
document.

$ touch hkd
$ pvsecret create --no-verify -k hkd --output req.bin --hdr sehdr
...
The host key document in 'bla' contains more than one certificate!
thread 'main' panicked at pvsecret/src/cmd/create.rs:192:31:

Fixes: dd82c26f87 ("rust: Add tool to manage UV-secrets")
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>
2024-02-02 16:11:21 +01:00
Marc Hartmayer
ab6bcad263 pv/error.rs: fix typo
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>
2024-02-02 16:11:21 +01:00
Marc Hartmayer
e40a3e0621 pvapconfig/tests: use a temporary directory for tests
Use the `TemporaryDirectory` type to create a temporary directory. This
type has the advantage that the directory is automatically removed once
it goes out of scope. The old implementation in test_sysfs_write_i32
leaks a directory if a previous subtest failed. Also, using a temporary
directory for the LockFile test fixes the following error:

  $ RUST_BACKTRACE=1 cargo test -- helper::tests::test_lockfile
  ...
  running 1 test
  test helper::tests::test_lockfile ... FAILED

  failures:

  ---- helper::tests::test_lockfile stdout ----
  thread 'helper::tests::test_lockfile' panicked at pvapconfig/src/helper.rs:265:9:
  assertion failed: r1.is_ok()
  stack backtrace:
     0: rust_begin_unwind
	       at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:597:5
     1: core::panicking::panic_fmt
	       at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:72:14
     2: core::panicking::panic
	       at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:127:5
     3: pvapconfig::helper::tests::test_lockfile
	       at ./src/helper.rs:265:9
     4: pvapconfig::helper::tests::test_lockfile::{{closure}}
	       at ./src/helper.rs:263:24
     5: core::ops::function::FnOnce::call_once
	       at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/ops/function.rs:250:5
     6: core::ops::function::FnOnce::call_once
	       at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/ops/function.rs:250:5
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-By: Harald Freudenberger <freude@de.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-02-02 16:11:21 +01:00
Marc Hartmayer
e56acf4f14 pv_core: add TemporaryDirectory
Add the type `TemporaryDirectory` that creates a temporary directory
that is automatically removed when it goes out of scope.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-By: Harald Freudenberger <freude@de.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-02-02 16:11:21 +01:00
Finn Callies
17977eda30 cpacfstats: Fix typo PCMKO to PCKMO
This commit fixes a typo in the cpacfstats.c client application and its
respective manpage cpacfstats.1.

Signed-off-by: Finn Callies <fcallies@linux.ibm.com>
Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-02-02 16:11:21 +01:00
Steffen Eiden
459a257568 rust/pvapconfig: Fix typos and clippy findings
Reviewed-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>
2024-02-02 16:11:21 +01:00
Steffen Eiden
fb65b53b9b rust/pvapconfig: use pv_base instead of pv crate
Replace the pv crate with the pv_core crate.

Reviewed-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>
2024-02-02 16:11:21 +01:00
Steffen Eiden
c8d4062f73 rust/pv: bump up crate version to 1.0.0
Recent changes makes it reasonable to update the version string of pv
and pv_base to 1.0.0. Recent changes introduced some non-backwards
compatible changes, like move some Error definition from pv to the new
pv_core crate. Also, the pv crates seem to be in a good shape to be
considered released.

Therefore, move up the Semver to 1.0.0.
See also:
https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html

NOTE: As these crates are not published to `crates.io` as of now, the
version number is meaningless, as cargo will not pull them from
anywhere and just use the files provided by this repository.

Reviewed-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>
2024-02-02 16:11:21 +01:00
Steffen Eiden
c8e0992814 rust/Cargo.lock: Update zerocopy crate
Update the zerocopy dependency from v0.6.* to the non forward compatible
v0.7.*. Incompatible changes are the requirment of the FromZeroes trait
for FromBytes trait and the non-default derive feature which this
patches handles as well.

Reviewed-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>
2024-02-02 16:11:21 +01:00
Steffen Eiden
c0a12b29d0 rust/pv: Reorganize some tests
Use a static Mockito server instead of creating multiple on-the-fly
during testing. Add the `mockito_server_available` test to quickly
verify that the mockito server could be constructed.  Relocate the
verifier API test to the test folder as it tests the public API. Also,
make the Debug impl for CertVerifier public. The test relocation
requires this. Before, there could be a test local implementation of the
Debug impl as it was in the same crate.

While at it, get rid of the lazy_static crate in favor of the once_cell
crate. As the new std lib implementation is very near to the one from
once cell. The project will switch to the std impl when v1.70 is
available in all supported distros. See:
https://doc.rust-lang.org/std/sync/struct.OnceLock.html

Reviewed-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>
2024-02-02 16:11:21 +01:00
Steffen Eiden
02dded11a5 rust/pv: Replace libc wherever possible
Replace all libc references to rust-std references if available.
This eliminates the need to include libc in the pv crate.
However, pv_base still refers to libc::ioctl and libc::ENOTTY.

Reviewed-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>
2024-02-02 16:11:21 +01:00
Steffen Eiden
b71279cda5 rust/pv: Remove memeq function
The rust std lib already provides functionality to compare two slies.
Replace all `memeq` invocations with == and remove the `memeq` function.
As a side effect this eliminates some unsafe code in this crate.

Reviewed-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>
2024-02-02 16:11:21 +01:00
Steffen Eiden
c70477f8c6 rust/pv: Fix 'elided_lifetimes_in_associated_constant' warning
Fixes "warning: `&` without an explicit lifetime name cannot be used
here". This warning will become a hard error in "the future". For more
information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>

Closes: https://github.com/ibm-s390-linux/s390-tools/issues/162
Reviewed-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>
2024-02-02 16:11:21 +01:00
Steffen Eiden
9b51b8b882 rust/pv: Refactor pv crate
Big refactoring patch of the pv crate. The main reason behind this
refactoring is to simplify testing and maintaining the pv crate while
keeping OpenSSL/libcurl dependencies optional. Using crate features
increases the number of targets that have to be tested. This refactoring
eliminates the use of features by splitting the functionality of pv into
a use OpenSSL and no-use-OpenSSL crate.

Split off some code from the pv crate into a pv_core crate. pv requires
pv_core and reexports all symbols. pv_base contains all code from former
pv that does not use OpenSSL or libcurl functionalities. The refactored
pv crate contains functionalities to generate requests and validate host
key documents. All features from pv are dropped as they are not needed
anymore and to streamline the codebase for easier use and testing. While
at it fix some documentation issues.

Users (pvsecret & pvapconfig) have next to no code change, besides the
different import of the crate.

Acked-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>
2024-02-02 16:11:21 +01:00
Steffen Eiden
48539596ef rust/pv: Use constants for invalid secret types
Add local constants for the reserved, and Null secret type and use
them.

Reviewed-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>
2024-02-02 16:11:21 +01:00
Steffen Eiden
cafa99774c rust/pv: Replace file-macros with functions
A function does the job as well. This improves code readability and
useability. While at it remove the implicit Buffer wrapper. Users are
currently not use the benefits of a buffered write. Also, streamline the
write_out helper function.

Reviewed-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>
2024-02-02 16:11:21 +01:00
Tobias Huschle
b5f7ac95d8 cpuplugd: adjust to CPU 0 being no longer hotpluggable
With kernel commit 496bb034f4ff ("s390/smp: disallow CPU hotplug
of CPU 0") it is no longer possible to hotplug CPU 0.

As a side effect, the sysfs handle /sys/devices/system/cpu/cpu0/online
does no longer exist. Since cpuplugd relies on checking all online
handles of all CPUs, this change causes cpuplugd to fail as it
interprets a non existing online file as an indicator that no other CPUs
with higher IDs exist as well. This leads to cpuplugd assuming that
there are no CPUs available.

Instead of checking for the online file, it is preferable to check for
the existence of the parent folder to verify the existence of a CPU.
As a consequence, all other checks for non-existing online files must
now imply that the CPU is online, but not hotpluggable.

Signed-off-by: Tobias Huschle <huschle@linux.ibm.com>
Tested-by: Mete Durlu <meted@linux.ibm.com>
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-02-02 16:11:21 +01:00
Thomas Richter
e984b97db0 s390-tools/cpumf: set exit code on pai data collection error
When pai records data it may fail in select() system call.
This error is not reported and the pai program exits with success.
Change this and exit with proper exit code.

Fixes: d7b1cbad8b ("cpumf/pai: Add Processor Activity Instrumentation tool")
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>
2024-02-02 16:11:21 +01:00
Thomas Richter
64d4e02b4f cpumf/pai: Handle perf records type PERF_RECORD_SWITCH
Running command pai -r <file> might encounter entries of type
PERF_RECORD_SWITCH. Entries of that type are currently not handled
and cause an error message:

 # pai -r ~/paicrypto.000
 unknown header-type 14 unknown header-type 14 \
 unknown header-type 14 ...

The error message is not terminated by a newline.

Handle entries of this type PERF_RECORD_SWITCH. These records
do not carry any payload at all, just a bit is set in the
header::misc member. This bit set determines context switch out.

Output after:
 # ./pai -r ~/paicrypto.000
 0x4b814018f4f3 6 cs-out
 0x4b817bc3c936 6 cs-in
 0x4b817bc5246c 6 cs-out
 0x4b817bd90e9a 6 cs-in
 ....
 #

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>
2024-02-02 16:11:21 +01:00
Marc Hartmayer
90ddef5a41 pre-commit: Provide pre-commit configuration
Add pre-commit (https://pre-commit.com/) configuration to allow
developers to run certain checks on their commits automatically.

Currently enabled checks and hooks are:
- Generic checks (e.g. merge-conflicts, trailing whitespace, etc.)
- git clang-format
- Codespell
- Shellcheck (https://www.shellcheck.net/)

Note: For some hooks Rust is excluded as a lot of false positives are
produced at the moment.

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: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-02-02 16:11:21 +01:00
Joern Siglen
58ef99f76b dbginfo.sh: handle relative and absolute calling path
include the dbginfo.sh script used - enabled for relative paths

Reviewed-by: Michael Storzer <mstorzer@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-01-12 14:10:52 +01:00
Joern Siglen
43c34956fb dbginfo.sh: adding new step to man page
step "initrd config files" was added as 19th step to our data collection
updating for newer date and distro version in the sample output

Reviewed-by: Michael Storzer <mstorzer@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-01-12 14:10:52 +01:00
Joern Siglen
d7dee1b9d3 dbginfo.sh: change copyright for 2024
prepare for the next updates

Reviewed-by: Michael Storzer <mstorzer@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-01-12 14:10:52 +01:00
Harald Freudenberger
94a38ebc3a rust/pvapconfig: Introduce new tool pvapconfig
pvapconfig is a new tool for automatically configuring the APQNs
within an Secure Execution KVM guest with AP pass-through support.
Based on a given AP configuration it tries to find a matching
APQN and bind and associate it with the correct secret.

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-01-12 14:10:52 +01:00
Steffen Eiden
0764460eaf rust/pv: Provide access for SecretList members
Adds getter for SecretList and SecretEntry.
Adds enum to represent secret types.
Add Iterator functionality for SecretList.

While at it, make the datatype of the capacity of the list transparent
for users.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-01-12 14:10:52 +01:00
Steffen Eiden
6fd02279da rust/Makefile: Fix CC/AR variables for TEST_TARGETS
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2024-01-12 14:10:52 +01:00
Yaakov Selkowitz
6274294bc5 libkmipclient: Fix build with libxml2-2.12.0
https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.12.0

"Several cyclic dependencies in public header files were fixed. As a
result, certain headers won't include other headers as before."

Closes: https://github.com/ibm-s390-linux/s390-tools/pull/160
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-12-20 18:32:34 +01:00
Steffen Maier
27708026d4 zdev/dracut: state requirement for sed during kdump initrd build
v2.27.0 commit 73c46a3056 ("zdev/dracut: fix kdump by only activating
required devices") started using `sed` during kdump initrd build time.
It works, but explicitly add the tool as a requirement.

Fixes: 73c46a3056 ("zdev/dracut: fix kdump by only activating required devices")
Closes: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
849aa5b105 zdev/dracut: put temporary files under the subdir ${DRACUT_TMPDIR}
This way, dracut cleans up everything just in case the "rm" here fails.

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
0be83bfbba dbginfo.sh: collect migration backups & logs from old persistent config
Complements commits
("zdev/dracut: add rd.zfcp cmdline option handling")
("zdev/dracut: add rd.dasd cmdline option handling")
and s390utils commits
("zfcp: migrate to consolidated persistent device config with
zdev (#1937046,#1937048)")
("dasd: migrate to consolidated persistent device config with
zdev (#1937046,#1937048)")
.

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Fedor Loshakov <loshakov@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
f8592be43d dbginfo.sh: collect file list and config files from initrd-s
For each initrd, collect verbose content listing as well as
the content of files matching the file glob patterns in $CONFIGFILES.
For dracut-squash such as RHEL kdump, this includes squashfs content.

Code is intentionally compatible with dash, so no bashisms.

Ubuntu initramfs has zdev persistent device configuration udev rules under
/lib/udev/rules.d/ (as opposed to /etc/udev/rules.d/).
Ubuntu initramfs stores configuration under /conf/.
Ubuntu kdump-tools have initrds under /var/lib/kdump/.

SLES auxiliary boot stage with grub2-s390x-emu has initrds under /boot/zipl/.

Dracut initramfs stores configuration under /etc/cmdline.d/ and /etc/conf.d/.
Dracut kdump have initrds under /boot/.

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Fedor Loshakov <loshakov@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
647ad51423 dbginfo.sh: collect other config data from zdev in initrd
Complements commit ("zdev/dracut: retain early persistent config over
switch root").

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Fedor Loshakov <loshakov@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
73f51e45a8 zdev: add helper to convert from zdev config to rd.znet
Converts zdev configuration into the syntax of the dracut cmdline option
rd.znet. Only znet options with non-default values are emitted. The result
string occurs on stdout. It represents one device-specification for the
given network interface name.

Example:
/lib/s390-tools/zdev-to-rd.znet persistent encbdf0
qeth,0.0.bdf0,0.0.bdf1,0.0.bdf2,layer2=1

User:
https://github.com/rhinstaller/anaconda/pull/5250
to generate dracut cmdline entries such as
rd.znet=qeth,0.0.bdf0,0.0.bdf1,0.0.bdf2,layer2=1

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
bc4f455151 zdev/dracut: retain early persistent config over switch root
Useful for debugging (what happened during early boot).

Also useful for distro installers, which can import the early config into
their own environment early after starting:
chzdev --import /run/zdev.initrd.config --persistent --yes \
       --no-root-update --force --verbose

After that, distro installers can modify/add the device config based
on interactive or unattended installation choices using
chzdev --enable --active --persistent ...

Finally, distro installers can likewise transfer the entire device config
to the installed system mounted under $SYSROOT:
chzdev --export /tmp/zdev.config --all --type --persistent --verbose

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
b4b5e0b6aa zdev/dracut: produce helpful user information on parsing rd.zfcp
It builds on the previously added helper function in parse-dasd.sh, which
gets sourced first by dracut so the function is also available to the later
parsing hook parse-zfcp.sh.

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
9927023680 zdev/dracut: add rd.dasd cmdline option handling
Add parsing of dracut cmdline option "rd.dasd=..." at initrd runtime.
It delegates configuration to chzdev.

Implement `dracut --print-cmdline` and `dracut --hostonly-cmdline` for
initrd build time. Emit an rd.dasd option for each DASD disk in dracut's
device dependency graph (to mount the root-fs, or to access the kdump
target).

This allows a distribution independent device configuration.
Configuration is consistent by using chzdev as backend.
It also prevents duplicate activations of the same device.

Copy the udev rule for unique DASD device nodes under /dev/disk/
[59-dasd.rules] into initrd for the same functionality like 95dasd or
95dasd_rules.

Along with the existing functionality of zdev/dracut, it makes the
following dracut modules superfluous:
https://github.com/dracutdevs/dracut/tree/master/modules.d/95dasd
https://github.com/dracutdevs/dracut/tree/master/modules.d/95dasd_mod
https://github.com/dracutdevs/dracut/tree/master/modules.d/95dasd_rules

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
9b2fb1d4d2 zdev: add helper to convert from dasd_mod.dasd to zdev config
Shell library, which can be sourced by other POSIX compatible shell
scripts. Provide helper function parsing its stdin based on the syntax of
kernel device driver parameter dasd_mod.dasd= and invoking chzdev to
produce corresponding persistent device configurations. The helper function
takes one argument, which is either "globals" or "ranges". For a complete
configuration, call the function twice, first with "globals" and then with
"ranges".

The new script library file should be packaged in a core (sub)package of
s390-tools so the script is available for initrd environments.

Users with examples:

Subsequent commit ("zdev/dracut: add rd.dasd parsing") introduces
zdev/dracut/95zdev/parse-dasd.sh performing:
zdev_parse_rd_dasd | zdev_parse_dasd_list globals 2>&1 | zdev_vinfo
zdev_parse_rd_dasd | zdev_parse_dasd_list ranges 2>&1 | zdev_vinfo

https://github.com/dracutdevs/dracut/pull/2534 updates
modules.d/80cms/cmssetup.sh performing:
echo "$DASD" | zdev_parse_dasd_list globals 2>&1 | vinfo
echo "$DASD" | zdev_parse_dasd_list ranges 2>&1 | vinfo

The parsing code for rd.dasd using the same syntax as dasd_mod.dasd=
is inspired by the own implementation that used to be in linuxrc.s390
of https://github.com/rhinstaller/anaconda.
https://web.archive.org/web/20190721154444/https://www.redhat.com/archives/anaconda-devel-list/2009-February/msg00392.html
https://www.spinics.net/linux/fedora/anaconda-devel/msg08316.html
("Re: Improved linuxrc.s390 (third try)")
=> 9249e40f42ff ("IBM improvements to linuxrc.s390 (#475350)")
https://web.archive.org/web/20190721150254/https://www.redhat.com/archives/anaconda-devel-list/2009-July/msg00310.html
=> 5f0fcf6688d0 ("Update linuxrc.s390 and friends to reflect review comments.")
https://web.archive.org/web/20190721125255/https://www.redhat.com/archives/anaconda-devel-list/2009-August/msg00158.html
=> 523095c86876 ("Handle activation of DASDs in linuxrc.s390 since loader no longer works")

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
689b894506 zdev: add helper to convert from zdev config to dasd_mod.dasd
Converts zdev configuration into the syntax of the kernel module parameter
dasd_mod.dasd. Only DASD options with non-default values are emitted. The
result string occurs on stdout. It represents one device-specification for
the given DASD device bus-ID.

Example:
/lib/s390-tools/zdev-to-dasd_mod.dasd persistent 0.0.da5d
0.0.da5d(erplog)

User:
https://github.com/storaged-project/blivet/pull/1162
to generate dracut cmdline entries such as rd.dasd=0.0.da5d(erplog)

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
06a30ae529 zdev/dracut: add rd.zfcp cmdline option handling
Add parsing of dracut cmdline option "rd.zfcp=..." at initrd runtime.
It delegates configuration to chzdev.

Implement `dracut --print-cmdline` and `dracut --hostonly-cmdline` for
initrd build time. Emit an rd.zfcp option for each zfcp-attached SCSI disk
in dracut's device dependency graph (to mount the root-fs, or to access the
kdump target).

This allows a distribution independent device configuration.
Configuration is consistent by using chzdev as backend.
It also prevents duplicate activations of the same device.

Along with the existing functionality of zdev/dracut, it makes the
following dracut modules superfluous:
https://github.com/dracutdevs/dracut/tree/master/modules.d/95zfcp
[rd.zfcp.conf is no longer needed and thus ignored here; the preceding
 ("zdev/dracut: fix marking hostonly files so delete option works")
 makes rd.hostonly=0 work as a generic replacement]
https://github.com/dracutdevs/dracut/tree/master/modules.d/95zfcp_rules

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
ed106d7f28 zdev/dracut: add site support for early devices to the kdump case
The existing code can already determine the required devices for the
actively running system, but this does not work for execution environments
in different (disaster recovery) sites.

Kdump likely does not notice when running in a different site and does not
re-generate the kdump initrd (because the kdump config itself does not
change).

The new code allows users to explicitly specify devices required for early
boot in initrd on different sites. Assuming this is a small number of
devices and could even overlap between the root-fs and the kdump case, do
not further distinguish those two sets of devices, but simply use the same
marker attribute "zdev:early=1" for both cases. With all this site
information available at the (initial) kdump initrd generation, the
resulting kdump initrd can work on any site without having to re-generate.

Complements commit 3c7adcc3c81d ("zdev: dracut: modifiy the
module-setup.sh").

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
9d08fd8c7e zdev/dracut: import persistent config of early devices into kdump initrd
The existing code can already determine the required devices for the
actively running system. In case users would have a need to configure
additional devices for early boot in kdump initrd, import those devices
marked with "zdev:early=1" for completeness. Assuming this is a small
number of devices and could even overlap between the root-fs and the kdump
case, do not further distinguish those two sets of devices.

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
7e8126704b zdev/dracut: fix to not depend on existing chzdev persistent config
Dracut knows exactly what dependencies it needs. Do not break it by
accidentally missing parts in the chzdev persistent configuration
(/etc/udev/rules.d/41-*.rules). Depicted as mathematical sets:

+-------------------------------+
| active                        |
|            +---------------------------------+
|            |                  |   persistent |
|   +------------------------------------+     |
|   |      root / kdump dependencies     |     |
|   | was    |                  |        |     |
|   | missing|   zdev so far    |   DR   |     |
|   +------------------------------------+     |
|            |                  |              |
+-------------------------------+              |
             |                                 |
             +---------------------------------+

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
d96767ee45 zdev/dracut: fix marking hostonly files so delete option works
Chzdev import generates persistent device configuration which are hostonly
files. Dracut cmdline rd.hostonly=0 should be able to delete those.

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
63f31bf73e zdev/dracut: add field debugging capabilities with logging
Additional debugging output can be generated with e.g. dracut option
"--stdlog 5" (or short -L5). It shows the chzdev export result, the output
of chzdev imports, and an overview of the resulting persistent config
within the initrd.
On systems, which default to using dracut option "--quiet", you might need
an additional "--verbose" to counter "--quiet" so -L5 has effect.
Typically combined with "--debug" to get a shell trace from building an
initrd (Note: --debug does not increase the log levels).

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
7ecfe2353f zdev/dracut: respect hostonly mode choice
Otherwise it risks adding arbitrary persistent configuration of the build
host into generic dracut initrds such as those for distro installers.

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
7bec672c7e zdev/dracut: fix kernel module install even for hostonly mode
Otherwise, dracut skips modules that are "not hostonly", i.e. not used /
loaded on the system when running dracut to build an initrd.
Without the fix, zdev device auto configuration only works for device
types for which a device driver happened to be loaded when building an
initrd. Likewise for specifying rd.* boot options.

Hostonly mode is often the default in Linux distributions.
Make zdev device auto configuration work nonetheless without users
having to know about and tweak dracut modes for initrd generation.

On the typical sloppy hostonly mode, the code disables hostonly for
installing kernel modules. This covers building regular initrds, where zdev
device auto configuration should even work for device types, for which
device drivers were not loaded when an initrd was generated. This can
happen when new devices of new types are configured for a DPM logical
partition. Also, users could want to start using dracut cmdline options
rd.{dasd,zfcp,znet} for a device type that was not used when the initrd was
built.

The special strict hostonly mode is used by some kdump implementations. In
that case, hostonly remains in effect intentionally because only support
for the really required devices as determined by dracut module 95zdev-kdump
should be included in a kdump initrd due to the memory-constrained kdump
environment. Cf. commit 73c46a3056 ("zdev/dracut: fix kdump by only
activating required devices"), which also provides more references on
strict hostonly mode. Even for non-kdump cases, let strict hostonly mode be
effective here in 95zdev in case some future use case appears for this
special mode beyond kdump.

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
5aac5deb75 zdev/dracut/module-setup.sh: add comments for dracut called functions
Add a short explaining comment to those functions, which are just callbacks
invoked by the dracut core infrastructure. So nobody wonders how these
functions get called, especially if there are no local callers here in the
code.

Cf. dracut commit
https://github.com/dracutdevs/dracut/commit/8bcfd683bd0c
("*/module-setup.sh: add comments for dracut called functions")

For more information about the dracut module callback functions:
https://github.com/dracutdevs/dracut/blob/master/man/dracut.modules.7.asc#writing-a-module
https://github.com/dracutdevs/dracut/blob/master/docs/HACKING.md#writing-modules

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
54e016ae71 zdev/dracut: use namespace prefix in functions of zdev-lib.sh
Use namespace prefix in functions of zdev-lib.sh to avoid collisions with
different modules being sourced in the shell.

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
6b53378839 zdev/dracut/95zdev: non-functional changes and annotations for shellcheck
Clears all shellcheck reports in old existing code so newly added code can
use shellcheck to find newly introduced suboptimal shell code.

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
1266f86444 zdev/dracut: add shellcheck annotations for recently added code
The annotations and the one non-functional code change in
zdev/dracut/95zdev-kdump/module-setup.sh check() clear all shellcheck
reports.

complements
73c46a3056 ("zdev/dracut: fix kdump by only activating required devices")

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Steffen Maier
231c02cdeb zdev: fix typo for example in chzdev man page
Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Acked-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-12-14 15:25:22 +01:00
Marc Hartmayer
454a8d9d7b systemd/cpi.service: add missing Requires=sysinit.target
`After=sysinit.target` configures only the order but not that the
systemd unit is required and must be activated. Therefore add the
missing `Requires=sysinit.target`. It probably does not fix anything
because sysinit.target should always be activated anyway but it's
cleaner to have it. See
https://www.freedesktop.org/software/systemd/man/systemd.unit.html for
details.

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-12-14 15:25:22 +01:00
Marc Hartmayer
bbe92b9cd3 systemd/cpi.service: fix race condition between stopping unit and shutdown
There is a race condition between stopping the cpi systemd service and
systemd getting a request to exit the main loop, so it may proceed with
shutdown before all pending stop jobs have been processed. Therefore,
add `Before=shutdown.target` as it would have been added by
the (deactivated) default dependencies. [1]

While at it, sort the directives.

[1] https://www.freedesktop.org/software/systemd/man/systemd.service.html#Default%20Dependencies

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-12-14 15:25:22 +01:00
Jan Höppner
7bb41732fb Prepare for next release
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-12-01 15:03:39 +01:00
Jan Höppner
c217f6be6a New release s390-tools-2.30.0
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-12-01 15:03:39 +01:00
Steffen Eiden
21662d38e6 rust/pv: Update mockito to version 1
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-12-01 10:24:48 +01:00
Niklas Schnelle
19f3842292 libutil: fix util_file_read_*() using wrong format specifiers
The sscanf() format specifiers for signed and unsigned int mistakenly
used "%d"/"%u" prefix analogous to "%l" for long but those do not exist.

Fixes: 37348ef662 ("libutil: add util_file_read_i()/util_file_read_ui()")
Acked-by: Sven Schnelle <svens@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-12-01 10:24:48 +01:00
Steffen Eiden
ae0cbf00b1 rust: Use default panic behaviour
Reviewed-by: Marc Hartmayer <marc@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-12-01 10:24:48 +01:00
Steffen Eiden
9019c6864a rust: Sanitize minimal dependencies
The crate dependencies were a bit to slack. Due to the rust dependency
resolver's strategy of always selecting the latest version this never
lead to any issues.

This has no impact on the workspaces Cargo.lock

Reviewed-by: Marc Hartmayer <marc@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-12-01 10:24:48 +01:00
Steffen Eiden
d1b61c37fa rust: Update dependency files
With the last patch introducing the rust workspace the location of
Cargo.lock has changed. Therefore, remove all crate level lock-files and
add rust/Cargo.lock as the only lock-file.

Steps to reproduce:
```
cd rust
mv pvsecret/Cargo.lock .
cargo build
cargo update -p openssl
cargo update -p curl-sys
cargo update -p rustix

```

While at it update some dependencies to get fixes for security issues.

Reviewed-by: Marc Hartmayer <marc@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-12-01 10:24:48 +01:00
Steffen Eiden
32b68a5fad rust: Create workspace
A workspaces simplifies the build and packaging process significantly.
All build artifacts and binaries are now built in a single location
(e.g., rust/target/release/*), and a unified dependency resolution is
used. Hence one Cargo.lock for all crates at rust/Cargo.lock.

Closes: https://github.com/ibm-s390-linux/s390-tools/issues/156
Reviewed-by: Marc Hartmayer <marc@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-12-01 10:24:48 +01:00
Matthew Rosato
55fdb17b18 ap_tools/ap-check: handle get-attributes between pre and post event
Since mdevctl commit acf78c1ff6c9 it is now possible for the
get-attributes event to occur between a pre-define and post-define.
This is done in order to obtain the active attributes for the device
before writing them to the config file, and implies that the
get-attributes cannot re-obtain the file lock.  For other cases
where mdevctl calls get-attributes, the file lock is not already
held and must be obtained by ap-check before reading attributes from
active devices.
To solve this, let's use the knowledge that mdevctl is a single-threaded
tool and add a test to detect this scenario.  If the file lock is
already held by the parent during a get-attributes, don't attempt to
re-acquire it.

Reported-by: Boris Fiuczynski <fiuczy@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-12-01 10:24:48 +01:00
Matthew Rosato
af730c79a6 libutil/util_lockfile: add routine to return owning pid of file lock
Provide a mechanism via which a caller can query the pid of the process
currently holding the file lock.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Acked-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-12-01 10:24:48 +01:00
Marc Hartmayer
041e6131d1 genprotimg/boot: stage3b: check cmdline for null-termination
Add a check to the stage3b that the kernel cmdline is always
null-terminated. While at it, ensure the coding style is consistent.

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-12-01 10:24:48 +01:00
Marc Hartmayer
5a7d7e05b8 genprotimg: make sure the kernel command line is always null-terminated
Make sure that the kernel command line used for the Secure Execution
boot image is always null-terminated. Before this change, users had to
ensure that the provided kernel cmdline was null-terminated, which was
error-prone. But since the default s390x Linux kernel command line is
set to `root=/dev/ram0 ro` the remaining reserved memory for the kernel
command line is zeroed out. Therefore, the problem only shows up if the
used kernel command line is shorter than the default kernel command
line.

Fixes: 65b9fc442c ("genprotimg: introduce new tool for the creation of PV images")
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-12-01 10:24:48 +01:00
Steffen Eiden
71b93d55ef rust/pv: fix Invalid write of size 1
Fix a valgrind finding. Fix an invalid read/write of one byte after the
actual struct to clear. Not fixing this may result in a illegal write or
memory corruption of the program. Fortunately, for the actual only user,
pvsecret this is not the case.

Fixes: c6f621d0 ("rust: Add library for pv tools")
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-12-01 10:24:40 +01:00
Thomas Richter
d2b5e1e2d6 cpumf/pai: Add command line option for realtime scheduling
Pai collects data from per CPU ring buffers and stores them in the
memory mapped output file. When data is collected from many CPUs at
the same time, writing data to output file can be slow.
Improve this and allow the pai recording to run with higher
real time priority. This is the same approach as done by the perf tool.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-12-01 09:58:47 +01:00
Mikhail Zaslonko
a3cb877c54 README: Add info about bundled zlib
Update Dependencies section for zipl with the information of zlib
compression support for CCW-type standalone dump.

Fixes: https://github.com/ibm-s390-linux/s390-tools/issues/157
Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-11-07 14:13:38 +01:00
Joern Siglen
6895a71cc4 dbginfo.sh: remove brakets on lsqeth device list
in customer situation we found lsqeth listing devices like:
Device name                      : (unnamed net_device)
Device name                      : enc2000
Device name                      : enc3000

- the braket around the "unnamed" device is braking the function call and
leads to stop the dbginfo.sh script.
- this patch removes brakets > the functions call works and call of osaoat
will report an unknown device instead of braking the dbginfo.sh script

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>
2023-11-07 14:13:38 +01:00
Joern Siglen
d9034b01f1 dbginfo.sh: enhance ethtool collection for ROCE
collect module-info for new ROCE cards via ethtool

Suggested-by: Niklas Schnelle <schnelle@linux.ibm.com>
Reviewed-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-11-07 14:13:38 +01:00
Joern Siglen
488ac8c3f2 dbginfo.sh: fix shellcheck errors in double quoting
change use of double quote to fit the rules

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>
2023-11-07 14:13:38 +01:00
Jan Höppner
ecf36d53c8 dasdfmt: Update -k/--keep_volser description
Make the description of the --keep_volser option more generic and avoid
mentioning specific tooling.

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-11-07 14:13:38 +01:00
Jan Höppner
893ad920c5 dasdfmt: Fix trailing whitespace in man page
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-11-07 14:13:38 +01:00
Jan Höppner
0695c79f4e fdasd: Improve -k/--keep_volser description slightly
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-11-07 14:13:38 +01:00
Jan Höppner
8837ea24cb fdasd: Fix trailing whitespace in man page
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-11-07 14:13:38 +01:00
Marc Hartmayer
65222d03b9 zipl/boot: compile the bootloaders only if HOST_ARCH is s390x
The zipl bootloaders are s390x specific, so only build them if the
`HOST_ARCH' is set to s390x.

While at it, rename `INC_FILES` to `EMBEDDED_BOOTLOADERS`. Also
introduce `EXTERNAL_BOOTLOADERS` variable and use it in the `install`
Makefile target.

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-11-07 14:13:38 +01:00
Ingo Franzki
54937495e2 zkey: Also check for deconfigured and check-stopped cards
When checking if a card or an APQN is online, not only check the 'online'
sysfs attribute, but also check the 'config' and 'chkstop' attribute.
Cards and APQNs in check-stopped or deconfigured state can still be reported
as online via the sysfs attribute, although they are not available to be
used for zkey.

In case the 2 additional sysfs attributes are not available in sysfs, then
don't fail, but rely on the 'online' attribute only.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-11-07 14:13:38 +01:00
Marc Hartmayer
8a783b81a4 Provide a ShellCheck configuration
This patch adds a ShellCheck configuration for s390-tools. See
https://www.shellcheck.net/wiki/Directive for details.

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-11-07 14:13:38 +01:00
Marc Hartmayer
093da2a5a7 zipl: move responsibility for the stage3.bin installation to boot/Makefile
Move the code responsible for installing stage3.bin to the
boot/Makefile. In addition, remove the stage3.bin from the Makefile
`all` target prerequisites in src/Makefile, as zipl can be built without
it. While at it, use $(INSTALL) instead of $(CP) for the bootloader
installation.

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-11-07 14:13:38 +01:00
Ingo Franzki
b68ea5fc7d zkey: Fix typos in man page
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-11-07 14:13:38 +01:00
Eric Farman
90c587408f cpictl: Limit kernel sublevel to one byte
Linux stable kernels can reach greater than 256 sublevels [1],
which can cause the cpi tooling to generate an invalid string
that gets passed to the firmware and causes unusual responses:

  $ uname -r
  5.4.255
  $ cat /sys/firmware/cpi/system_level
  0x04260000000504ff

  --reboot--

  $ uname -r
  5.4.256
  $ cat /sys/firmware/cpi/system_level
  0x4260000000504100

The first sublevel field is defined as one byte, so ensure that
a value larger than that isn't included.

[1] https://lore.kernel.org/lkml/1612534196241236@kroah.com/

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-11-07 14:13:38 +01:00
Thorsten Winkler
90475fbaa5 common.mak: use eval only once for defining variables
Using eval only once at the top most function "define_toolchain_variables",
makes the other subsequent eval calls redundant.

“The result of the eval function is always the empty string; thus, it
can be placed virtually anywhere in a makefile without causing syntax
errors.” [1]

So this patch also prevents potential syntax errors using GNU Make <v4.2.
Since version 4.2 GNU Make introduced a less errorness function calling and
variable expanding with commit
e971597 ("[SV 46995] Strip leading/trailing space from variable names")

Reference: https://git.savannah.gnu.org/cgit/make.git/commit/?h=4.2&id=e97159745d3359285cef535af780cd8e2b6b0791

[1] https://www.gnu.org/software/make/manual/html_node/Eval-Function.html

Signed-off-by: Thorsten Winkler <twinkler@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-11-07 14:13:38 +01:00
Vineeth Vijayan
07ff9e1da0 zdev: limit the derivation of ZDEV_SITE_ID
Currently ZDEV_SITE_ID is derived with the help of an additional
udev-rule, 40-zdev-id.rules. The sole purpose of this rule is to
determine the ZDEV_SITE_ID environment value with the help of zdev_id
binary. This solution is minimal, but this has some unwanted side-
effects. The zdev_id logic get executed for all the events, even
those completely unrelated to zdev/or site, and imports the unneeded
envionment values to the udev-db.

Instead of having an additional rule file, add this logic as part of
the udev-rule of those devices which are configured with site-support.
The logic will then be available on all those rules with the
site-supported devices only.

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-11-07 14:13:38 +01:00
Vineeth Vijayan
5637799c92 zdev: introduce dev_site_configured macro
Introduce dev_site_configured macro,which can be used to find the
availability of site configurations for the device during udev rule
creation.

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-11-07 14:13:38 +01:00
Vineeth Vijayan
73c82441e7 zdev: move all site-related definitions to one file
Previously SITE_FALLBACK and other site-specific configuration support
macros were defined in device.h. Instead, move them to a relatively
smaller header file which is exclusive for site-related definitions.
This way, light-weight zdev_id also can use the same header file.

Reported-by: Steffen Maier<maier@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-11-07 14:13:38 +01:00
Alexandra Winter
6d06921276 zdev:qeth: adapt performance_stats attribute semantics
Behaviour of the qeth performance_stats sysfs attribute has changed
with kernel commit
b0abc4f5df76 ("s390/qeth: overhaul ethtool statistics")
that went into kernel v5.1.

Before the kernel commit
- collection of statistics was turned on and off by writing 1 or 0
- default after device activation was 0
- statistics were reset by writing 0

After the kernel commit:
- collection is always on
- attribute always reads 1
- statistics is reset by writing 1; writing 0 is a no-op

Problems of chzdev on new kernels:
chzdev cannot reset statistics ('performance_stats=1' does nothing).
'chzdev --export' always lists performance_stats.
'chzdev qeth --help-attribute performance_stats' reflects old behaviour.

This patch will do the following:
'chzdev qeth --help-attribute performance_stats' reflects new behaviour.
'chzdev --export' does not list performance_stats on new kernels.
'chzdev performance_stats=1' resets statistics on new kernels.
'chzdev performance_stats=0' still resets statistics on old kernels,
    does nothing on new kernels.

Suggested-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Alexandra Winter <wintera@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-11-07 14:13:38 +01:00
Steffen Maier
2996b34ddf dbginfo.sh: collect debug data for zdev site support
Complements v2.24.0 commit c8ad5f57d0 ("zdev: modify zdev_id to read the
site_id from loadparm") and commit 2e89722ef0 ("zdev: make site specific
udev-rule for ccw").

Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:07 +02:00
Steffen Maier
e5821301f6 dbginfo.sh: exclude (empty) cpu subdirs under zfcp sdev block mq sysfs
With many CPUs, such as triple digit counts, the by default many empty
sysfs directories are prohibitive to collect, especially if the number
of SCSI disk devices is also large, such as 4-digit counts.

Excluding them from being collected from sysfs saves hundreds times
thousands of archive entries and inodes on expansion.

Since the number device-mapper devices (multipath and other target types
such as LVM) is smaller and can include devices not backed by zfcp, keep
collecting
/sys/devices/virtual/block/dm-[0-9]*/mq/0/cpu[0-9]*/

Definitely keep collecting
/sys/kernel/debug/block/{sd,dm-}*/hctx0/cpu[0-9]*/
as it contains actual statistics files:
completed  default_rq_list  dispatched  merged  poll_rq_list  read_rq_list

Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:07 +02:00
Steffen Maier
f4d1874ac5 dbginfo.sh: collect text export of udev data base
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:07 +02:00
Steffen Maier
f3428929a2 dbginfo.sh: collect potential kdump config under subdir /etc/kdump
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:07 +02:00
Mikhail Zaslonko
263d6950a1 zipl/boot/zlib: Replace static_assert() in zlib code
Replace static_assert() with STATIC_ASSERT macro from zt_common.h in order
to get rid of glibc dependencies in zipl/boot and comply with older
C standards.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Suggested-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:07 +02:00
Marc Hartmayer
8024f8e31a editorconfig: add settings for EDIT_DESCRIPTION
Set the maximum line length for branch description messages (`git branch
--edit-description`) to 72 characters.

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-09-27 18:29:07 +02:00
Marc Hartmayer
3849b29594 rust/**/*.rs: fix cargo clippy findings
Automatically fixed by the command `cargo clippy --fix` and `cargo fmt`.

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-09-27 18:29:07 +02:00
Mikhail Zaslonko
0e4d4da0e5 zdump: Update zgetdump man page
Update zgetdump man page with the information of compressed DASD dumps
support as well as new verbose 'zgetdump -i' output entries.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:07 +02:00
Mikhail Zaslonko
ca3cd51f91 zdump/dt_s390: Support new dumper version by 'zgetdump -d'
Add new dumper version support to 'zgetdump -d' command.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
fda1e0d33d zdump: Move and rename DF_S390_DUMPER_SIZE constants
Move DF_S390_DUMPER_SIZE_* constants from zdump/df_s390.h to
boot/loaders_layout.h since ccw dumper size depends on the zipl boot
loader layout (to keep it all in one place).

Rename DF_S390_DUMPER_SIZE_* constants to STAGE2_DUMPER_SIZE_*

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
1a850392bc zdump/df_s390: Update 'zgetdump -i' output with zlib info
Update verbose 'zgetdump -i' output with zlib info (internal zlib version
and zlib compression unit size).

The following new entriees are to be dispalyed:
	Zlib version.......: 1
	Zlib compression unit: 1 MB

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
14a79eb142 zdump: Increase output buffer from 8 pages to 1 Mb
Increase the auxiliary buffer size from 8 pages to 1 megabyte in order to
significantly increase compressed dump processing speed.
For uncompressed dumps, the effect is minor.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
271b809495 zdump/dfi_s390: Support reading compressed s390_ext dumps
Update dfi_s390.c to support reading of compressed dump segments.
For this, introduce a callback function for reading memory chunks
associated with compressed dump segments. Apart from the segment location
on disk this function requires the entry_offset array from the dump segment
header in order to process each compressed entry separately, thus allowing
fast seek processing for zgetdump (no need to decompress a big dump segment
to extract a single piece of data).

In addition, split mem_chunks_add_ext() in several functions.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
2363269c1c zipl/boot: Set the new version in the dumper and in the dump header
Since we are using the existing s390 extended dump format for compressed
dumps as well, set the version of the s390_ext dumper with compression
support and also dump header of the compressed dump to '2' (in order for
zgetdump to distinguish).

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Acked-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
f1db473d11 zipl/boot: Fix progress_print to correctly display 'Dump file size'
- Adjust progress_print() calls to pass updated address after the set of
  blocks has been written to disk.
- Currently total_dump_size value is updated only after the entire dump
  segment is written to disk what leads to ambiguos Dump file size values
  displayed by progress_print(). Change write_addr_range() to re-calculate
  total_dump_size after each set of blocks has been written to disk thus
  printing the correct value at the end of each log entry.
- Avoid final log entry duplication.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Acked-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
e35d05a5e3 zipl/boot: Add print_progress parameter to write_addr_range()
With current implementation, printing progress while writing a compressed
data chunk might be very inaccurate. Thus, for compressed dump segments
skip progress_print() in write_addr_range() and call it after each
compressed memory chunk is written to disk. For that change
write_addr_range() to call progress_print() conditionally based on the new
print_progress parameter.

For non-compressed dump segments, call progress_print() from
write_addr_range() just as before.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Acked-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
c61783546b zipl: Add --no-compress option to zipl command
Add --no-compress option to explicitly omit compression for single-volume
DASD dumper. Used primarily for test purposes.

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

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

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

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

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
4905975f81 zipl/boot: Adjust Makefile, loaders layout and a linker script
Use a separate linker script eckd2dump_sv.lds for single volume dumper with
compression support.

The new dump tool with zlib compression support now has a size of 8 pages.
Since DASD stand alone dump requires a block size of 4K, we are not
affected by the stage 2 size limitations and can load the dumper to
stage 2 as before. We just need to move the HEAP section for ECKD dumper
in the layout definitions up to 0xb000 address. Also expand the stack by
unused 0x400 bytes.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
d53bfb9201 zipl/boot: Integrate zlib compression to single volume DASD dumper
Integrate zlib DFLTCC deflate compression to single volume dasd dumper
using the existing s390 extended dump format. Compression takes place
only if DFLTCC facility is available, otherwise dump is written
uncompressed as before.

First megabyte of memory is always written uncompressed and afterwards
this area is used for zlib workspace and for the compression output buffer.
The compression takes place in chunks of data of equal size (currently 1MB)
and the offset of each compressed chunk is stored in the dump segment
header. Since existing dump segment headers of 1 page size are used, we
need to limit the maximum size of compressed dump segments.
Chunk is written uncompressed in case of compression error or if
deflate compression only makes it bigger.

Thus every chunk of data is compressed separately and can be decompressed
independently. The main reason for that is to enable zgetdump to make fast
read seeks. Otherwise, zgetdump would need to decompress a big dump segment
in the worst case to extract a single piece of data.

Put compression related functions and structures to eckd2dump_zlib.c
and eckd2dump_zlib.h

Update zipl man page with the general information of zlib compression
support.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
0dac47cb62 zipl/boot: Introduce write_addr_range() helper function
Move code from write_dump_segment() to write_addr_range() function to use
it later for writing compressed dump segments as well.

Verify that passed address range is a multiple of dasd block size.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
7b68552359 zdump: Use global header s390_dump.h
Instead of using its own DF_S390_ constants and df_s390_ structs
in df_s390.h, include those from "dump/s390_dump.h" in order to minimize
duplicates. Adjust the code, where required, to use <stdint> types
instead of those defined in zt_common.h (e.g. use uint64_t instead of u64).

Adjust zdump include statements.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Mikhail Zaslonko
775495c7e7 include/dump: Create a global header s390_dump.h
Move common dump related structures and constants to the global header
"dump/s390_dump.h" in order to get rid of many duplicates in zgetdump code.

Adjust zipl include statements and update Copyright statements.

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

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

Adjust include statements leaving other code as is.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Harald Freudenberger
8235e025d4 zcrypt/lszcrypt: Improve lszcrypt output on SE guests
The AP queue states within a SE guest may have a so called asynchronous
error pending. When that's the case, the sysfs read of some AP queue
attributes fails with EIO. lszcrypt was not really prepared for this
and instead showed some incorrect output.

This patch fixes this oddity and now lszcrypt -c shows "error" in case
of ap_bound or ap_associate read errors and lszcrypt -V shows also
"error" if the BS bits could not get fetched.

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Marc Hartmayer
b301381f90 (genprotimg|zipl)/boot: remove executable bit
The bootloader binaries cannot be executed via `exec()` therefore remove
the executable bit.

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-09-27 18:29:06 +02:00
Jakub Čajka
c62f930634 osasnmpd: Fix missing semicolon
5.9.4 net-snmp started to require semicolon on the config_require there
are no docs covering this change.

Link: https://bugzilla.redhat.com/show_bug.cgi?id=2235734
Closes: https://github.com/ibm-s390-linux/s390-tools/pull/155
Signed-off-by: Jakub Čajka <jcajka@redhat.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-09-27 18:29:06 +02:00
Marc Hartmayer
85eb44ac95 lib(ekmfweb|kmipclient): use pkg-config instead of (curl|xml2)-config
`pkg-config` is mandatory for compiling s390-tools anyway therefore
let's replace `curl-config` and `xml2-config` calls whenever possible.
In addition, `pkg-config` has the advantage that cross-compilation is
supported. While at it, use `pkg-config` for libcrypto, json-c, and
libssl as well.

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-09-27 18:29:06 +02:00
Steffen Eiden
d5f8063900 rust/README.md: Fix some typos
Reviewed-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>
2023-09-27 18:29:06 +02:00
Steffen Eiden
ee66929465 rust/Makefile: Fix use of Cargoflags for 'make clean'
Reviewed-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>
2023-09-27 18:29:06 +02:00
Ingo Franzki
1b044b8a40 zkey: Support EP11 AES keys with prepended header to retain EP11 session
The pkey kernel module supports two key blob formats for EP11 AES keys.
The first one (PKEY_TYPE_EP11) contains a 16 bytes header that overlays
the first 32 bytes of the key blob which usually contain the ID of the
EP11 session to which the key is bound. For zkey/dm-crypt that session
ID used to be all zeros. The second blob format (PKEY_TYPE_EP11_AES)
prepends the 16 bytes header to the blob, an thus does not overlay the
blob. This format can be used for key blobs that are session-bound, i.e.
have a non-zero session ID in the first 32 bytes.

Change zkey to generate EP11 keys using the new format (i.e. pkey type
PKEY_TYPE_EP11_AES), but existing key blobs using the old format can
still be used.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Reviewed-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-08-21 17:09:26 +02:00
Jan Höppner
f46f6d34d3 gitignore: Add cpumf/lspai
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-08-21 17:09:26 +02:00
Thomas Richter
3a96e8826f cpumf: Add lspai program and man page to display PAI counter sets
Add lspai program and man page to display Processor Activity
Information (PAI) facility counter sets in the same way as
lscpumf for the CPU Measurement Facility counter sets.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-08-21 17:09:23 +02:00
Mete Durlu
84738668ca hyptop/helper: fix smt utilization calculation
When calculating smt utiliziation field, subresults are capped to a
minimum value of zero to prevent wrap around while converting values
from signed to unsigned integers. The capping of subresults cause slight
inaccuracies therefore capping has been moved from intermediate steps
and done at the end.

Fixes: 0209c11bc1 ("hyptop: Add real SMT utilization field")

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-08-21 17:07:44 +02:00
Jan Höppner
dbea311aa8 Prepare for next release
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-08-04 14:51:41 +02:00
Jan Höppner
d9ce54dee3 New release s390-tools-2.29.0
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-08-04 14:51:41 +02:00
Marc Hartmayer
7b056735ed rust/pv: some cargo clippy fixes
Found and fixed by the command `cargo clippy --fix -- -Dwarnings`.

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-08-04 14:18:49 +02:00
Marc Hartmayer
33fde99138 rust: pv/pvsecret: some typo fixes
It reads 'add-secret requests' and not 'add secret requests'.

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-08-04 14:18:49 +02:00
Steffen Maier
4b486e87cc zdev/dracut: fix kdump build to integrate with site support
This complements v2.27.0 commit 73c46a3056 ("zdev/dracut: fix kdump by
only activating required devices"). On older distributions, the absence of
zdev_id can cause the following harmless error messages for each udev
event:

(spawn)[387]: failed to execute '/lib/s390-tools/zdev_id' \
'/lib/s390-tools/zdev_id': No such file or directory

Kdump is still functional nonetheless.

As of v2.24.0 commit 2e89722ef0 ("zdev: make site specific udev-rule for
ccw"), the invocations of chzdev within
zdev/dracut/95zdev-kdump/module-setup.sh generate
/etc/udev/rules.d/40-zdev-id.rules. And so even though zdev-kdump
intentionally does not install zdev_id and its previous singular user
zdev/udev/81-dpm.rules into the kdump initrd, because DPM device auto
configuration is not desired in the kdump environment, zdev_id meanwhile
has an additional functionality for site-support and the generated
40-zdev-id.rules calls /lib/s390-tools/zdev_id. By installing zdev_id into
the kdump initrd, 40-zdev-id.rules can work without error.

Fixes: 73c46a3056 ("zdev/dracut: fix kdump by only activating required devices")
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-08-04 13:10:00 +02:00
Marc Hartmayer
a07d1bca74 pvattest: Add --output option to verify subcommand
Other tools may need to process the configuration-unique id. Provide a
machine readable format by writing to a YAML file containing a `cuid`
entry and optionally an `add` entry. New CLI options `--format` and
`--output` are introduced for this. Currently, only the output format
`yaml` is supported.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-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-08-04 13:10:00 +02:00
Marc Hartmayer
5e1ef90962 pvattest: refactor fprint_verify_result
Refactor the code responsible for printing the verification result into
a new function named `fprint_verify_result`. This function will be
reused in the future and a new output format will be added. While at it,
increase the dump data width for the addition data. In addition, add a
prefix `0x` to the values in order to indicate that these are
hexadecimal values.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-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-08-04 13:10:00 +02:00
Marc Hartmayer
8fe214d915 pvattest: pvattest_hexdump: add error checks
`fprintf` can fail, therefore check the return code of it.

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-08-04 13:10:00 +02:00
Marc Hartmayer
bec9d1dfcd pvattest: pvattest_hexdump: add beautify parameter
Add `beautify` parameter to `pvattest_hexdump`. If the parameter is set
to true, a offset and whitespaces will be added for better readability.

With beautify set to FALSE:

14141414141414141414141414141414

With beautify set to TRUE:

0x0000  1414 1414 1414 1414 1414 1414 1414 1414

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>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-08-04 13:10:00 +02:00
Marc Hartmayer
694d5d4638 pvattest: pvattest_log_bytes: use GBytes and handle @width == 0
The only user of `pvattest_hexdump` uses GBytes anyway, therefore let's
use GBytes as parameter type for `pvattest_hexdump`.

While at it, change the order of the parameters, constify `@width` and
handle the `@width == 0` case, which results in an hex-string without
any line breaks.

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-08-04 13:10:00 +02:00
Marc Hartmayer
a6ac7cd876 common.mak: set SHELL to /bin/bash
This fixes the following error (using GNU Make 4.3.0):

  make[2]: command: Command not found

The reason for this is that `command` is a bash builtin. `command` is
used in `common.mak` for the `combdb` Makefile target.

While at it, remove the now useless `SHELL := /bin/bash` definitions in
the sub-Makefiles.

Fixes: 3d098416c6 ("common.mak: add `compdb` Makefile target")
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-08-04 11:41:25 +02:00
Joern Siglen
28751a097a dbginfo.sh: global original Input Field Separator (IFS)
Replace local ifs_orig variables in different functions by a single
global IFS_ORI variable. This will reduce the risk of missing a local
saving and restore of the original IFS.

Reviewed-by: Michael Storzer <MSTORZER@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-08-04 11:41:25 +02:00
Steffen Eiden
19c795be0d rust: Add README
Add a README.md to the rust subdirectory as a guideline for writing
s390-tools tools in Rust. This includes build integration, dependency
handling, and a few coding style hints. Rust related information
is also added to the main README.md.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
[hoeppner@linux.ibm.com: Adapt details in README.md]
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-08-04 11:41:21 +02:00
Steffen Eiden
dd82c26f87 rust: Add tool to manage UV-secrets
Add `pvsecret` a tool to create, add, list, and delete Ultravisor
secrets. `pvsecret` uses the functionality from the pv-crate
to provide an command line tool to manage the secrets.

Add a new target group PV_TARGETS in rust/Makefile that additionally
requires openssl and libcurl as pv with the feature "request" uses
openssl and libcurl fearures.

Acked-by: Jan Höppner <hoeppner@linux.ibm.com>
Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
[hoeppner@linux.ibm.com: Adapt man pages and help output]
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-08-04 11:41:09 +02:00
Steffen Eiden
c6f621d0dc rust: Add library for pv tools
Add a `pv` crate that bundles useful functions and structs for creating
requests like `Attestation`, `Add Secret`, or even `Boot` a.k.a.
Secure Execution Image.
Note pv includes a subcrate `openssl_extensions` that (temporarily)
bundles some needed `openssl-rust` functionalities that are not
upstream yet. The plan is to remove these, when they become
upstream.

The pv crate has multiple features:
 * request - code to generate requests
 * uvsecret - code to access the UV-secret api
		with request enabled also generating requests is
		possible

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Acked-by: Jan Höppner <hoeppner@linux.ibm.com>
Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-08-04 11:40:54 +02:00
Steffen Eiden
e6add997eb Integrate rust into s390-tools build system
The rust integration into the s390-tools build system consists of the
following steps:

- Add a subdirectory for the rust code.
- Add a Makefile that forwards rust builds to `cargo`.
- Add a `utils` crate for rust code in s390-tools.
- Add rust stuff for dotfiles:
  - gitignore
  - editorconfig
  - codespellrc (while at it, add an ignore file)

With cargo the rust ecosystem has its own build system which also is
responsible to resolve rust dependencies via downloading the dependencies
from (default) crates.io and discover the source files. Therefore, the
Makefile just calls `cargo build` to forward the build to cargo.

If a rust crate does not require external dependencies, users might call
rustc directly.

A simple `make` will build all the rust targets as well (with --release
specified). Also `make install` will work as usual.

A few Makefile configuration variables are introduced for rust/Cargo:
  - HAVE_CARGO (default 1) to toggle the build of rust code using cargo
  - CARGOFLAGS             to add custom cargo flags, e.g. --offline
  - CARGO		   Cargo binary location defaults to
                           $(where cargo)

A new global make target is defined to get the current s390-tools
version:
$ make version
  2.28.0

rust/Makefile also has the `print-rust-targets`  target to print all rust
directories/crates that should be shipped/installed.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-08-04 11:40:46 +02:00
Marc Hartmayer
a2baeb2fe2 zdev/dracut/zdev-lib.sh: add ShellCheck shell directive
Add a ShellCheck [1] directive before the first command in the file to tell
ShellCheck and the reader which shell to use. See
https://www.shellcheck.net/wiki/SC2148 for details.

[1] https://www.shellcheck.net/

Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-08-02 14:48:12 +02:00
Thomas Richter
a500946e50 vmur: fix wrong command flag exclusion
Command vmur issues a warning and aborts receiving a file from
the reader when either option -t or option -b is specified.
Example:
 ./vmur re -t 0x25,0x40 22 -H /tmp/xxx.txt
 vmur: Conflicting options: -b and -t are mutually exclusive.
This is wrong as there is only one option specified.
The command should be aborted only when both flags are specified.

Fix this wrong behavior.

Fixes: d5f853c460 ("vmur: Remove option -c for dump file conversion")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reported-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-08-02 14:48:12 +02:00
Marc Hartmayer
b7c9c2679e genprotimg: add support for add-secret requests
IBM Secure Execution guests may want to share additional secrets with
the Ultravisor in a secure manner. For this the concept of secret
requests and three new Ultravisor-calls were introduced.

Add support to genprotimg to prepare an Secure Execution image with the
requirement that add-secret requests must provide an extension secret
that matches the customer communication key (CCK) derived extension
secret.

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-08-02 14:48:12 +02:00
Marc Hartmayer
bc8a14895a genprotimg: improve the --comm-key description
In the future, this key will be used for additional things than the
guest dump encryption.

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-08-02 14:48:12 +02:00
Marc Hartmayer
4ae68d0430 genprotimg: add NAME macro parameter
In preparation for the next patch, add the parameter `NAME` to the
`MUT_EXCL_BOOL_FLAG` macro. This is useful for the case when the command
line flag has a different naming than the struct field.

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-08-02 14:48:12 +02:00
Marc Hartmayer
aabf97f885 genprotimg: refactor arguments related to the control flags into own struct
Refactor arguments related to the SE header control flags into own
struct with the name `PvControlFlagsArgs`. This change makes it easier
to extend the control flags arguments further, without touching the
signature of `pv_img_set_control_flags`. While at it, rename the struct
members `allow_...` to `enable_...`. This matches with the command line
option names.

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-08-02 14:48:12 +02:00
Marc Hartmayer
a9b546cb0f genprotimg: pv_img_set_control_flags: refactor code
Introduce a function for setting the control flags. This makes it easier
to add more control flags in the future.

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-08-02 14:48:12 +02:00
Marc Hartmayer
5566c31458 genprotimg: help|manpage: remove superfluous optional
A default is always optional, therefore let's remove the superfluous
"optional" statements.

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-08-02 14:48:12 +02:00
Marc Hartmayer
ff96d6158e genprotimg/boot: avoid the deletion of .lds files by using .SECONDARY
Avoid the deletion of the intermediate
`(stage3a|stage3b|stage3b_reloc).lds` files by adding them to the
special built-in target `.SECONDARY` as prerequisites. This way they're
declared as intermediate files that should never be deleted
automatically. [1]

[1] https://www.gnu.org/software/make/manual/html_node/Special-Targets.html#index-preserving-with-_002eSECONDARY

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-08-02 14:48:12 +02:00
Marc Hartmayer
2aa9071aed genprotimg: help: add missing period
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-08-02 14:48:12 +02:00
Marc Hartmayer
adf2a030e6 genprotimg: fix error message
The option name is `--enable-dump` and not `--allow-dump`.

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-08-02 14:48:12 +02:00
Marc Hartmayer
0783aa99d7 zipl/boot: simplify clean target
Simplify the clean target since there are several redundant
things (*.bin) and files that aren't built at all (.xxx and .yyy).

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-08-02 14:48:12 +02:00
Marc Hartmayer
5a848c98bb zipl/src: remove no-pie and noexecstack compiler and linker flags
Only the bootloaders cannot be built as PIE and for that there are
already the -no-pie linker and compiler flags set by the boot/Makefile.
In addition, remove the `noexecstack` linker flag as it has no use
anymore (see commit 518bf7d7357 ("zipl/boot: use
`--no-warn-rwx-segments` linker flag")). It was originally introduced to
declare the ELF segment of the bootloader stack as non-executable. But
this ELF attribute had no effect for multiple reasons:

1. ALL_LDFLAGS is not used for the bootloaders
2. no ELF loader is used for the bootloaders that would take this ELF
   attribute into account

This fixes the problem of overriding  `-fPIE` set by the distributor.

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-08-02 14:48:12 +02:00
Marc Hartmayer
e98f9b9c4a .editorconfig: provide more editor settings
Set the maximum line length for commit messages to 72 characters, and
the indentation style for Makefiles to TAB.

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-08-02 14:48:12 +02:00
Marc Hartmayer
faac2520c9 genprotimg|zipl: build debuginfo files
Currently, the debug information of the bootloader is discarded during
the raw binary creation. Change this by creating separate
<loader>.bin.debug files containing the debug information. The packager
will then be able to package these files as desired and the developer
can use them to debug the code.

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-08-02 14:48:12 +02:00
Marc Hartmayer
3d098416c6 common.mak: add compdb Makefile target
Add a new Makefile target 'compdb' to create the compilation database
'compile_commands.json' [1]. This file can then be used by the language
server 'clangd' [2], which is a possible backend for the so called
'Language Server Protocol' (LSP) [3] used by many IDEs and editors.

In addition, add this file to `.gitignore`.

[1] https://clang.llvm.org/docs/JSONCompilationDatabase.html
[2] https://clangd.llvm.org/
[3] https://microsoft.github.io/language-server-protocol/

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-08-02 14:48:12 +02:00
Peter Oberparleiter
7e53611e3a dump2tar: fix truncated paths
When creating a tar archive, dump2tar incorrectly truncates the last
character of file paths that are exactly 100 characters long.

Paths up to 100 characters can be represented in the 100-byte name field
of a tar header entry, while longer paths are handled via an additional
tar data block. For 100-character paths, dump2tar determines that a
single header is sufficient, but then uses util_strlcpy() to store the
path into the name field. Since util_strlcpy() ensures nul-terminated
strings, the final character of the path is overwritten.

Fix this by using strncpy() instead of util_strlcpy(). Also mark the
affected name fields as "nonstring" to prevent associated compiler
warnings.

Reported-by: Steffen Maier <maier@linux.ibm.com>
Fixes: d85cf20981 ("dump2tar: Change SET_STR_FIELD to copy strings correctly")
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Jan Höppner
d8496160cb Makefile: Fix pretty print indentation
Commit 62ec87680a61 ("common.mak: improve cross compilation support")
added one extra whitespace during the changes of the toolchain command
definitions. The rest of the commands did not receive that change.

Since then the pretty print output looks like this:
...
CC       zipl/boot/eckd1b.o
CXX      ziomon/ziorep_collapser.o
SED     zdev/src/lszdev_usage.c
CC       hyptop/sd_cpu_items.o
MV      zfcpdump/zfcpdump-initrd
LINK     dasdfmt/dasdfmt
...

Add the additional whitespace to all other tools definitions used during
the build process.

Note: This doesn't fix the misaligned indentation for commands like
$(CC_FOR_BUILD) as those inherit the whitespace from the original
command, here $(CC).

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Ingo Franzki
c7f10bc76d zkey: man: Fix groff/troff warnings
Fix the following warnings:

troff: zkey-ekmfweb.1:455: warning: macro 'APP=LINUX'' not defined
troff: zkey-ekmfweb.1:457: warning: macro 'encvol'.' not defined

A single quote (') at the beginning of ta line is interpreted as macro.
Fix this by starting the line with a dummy character (\&).

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Joern Siglen
f8910caa59 dbginfo.sh: include the dbginfo.sh used
include the version of dbginfo.sh just used for data collection into our
tar file - so we have the used version in case of data collection problems.

Reviewed-by: Michael Storzer <MSTORZER@de.ibm.com>
Signed-off-by: Joern Siglen <siglen@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Jan Höppner
b1d948daef gitignore: Sort list of generated executables
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Marc Hartmayer
4d4ddbd887 Recursive Makefiles: avoid race condition in the install target
The `install` Makefile target of the top Makefile has `all` and
`install-recursive` as prerequisites. This leads to the two recursive
Makefile calls `make -C <SUBDIR> all` and `make -C <SUBDIR> install`.

The problem is these two targets try to build the same object files and
this leads to a race condition between these two targets in case of a
parallel build.

Fix this problem by removing the `all` prerequisite from the `install`
target, as it is not needed since all the `install` targets in the
sub-Makefiles already have proper prerequisites.

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-07-20 21:45:27 +02:00
Mikhail Zaslonko
d205b47c08 zipl/boot: Conditionally clear memory upon reipl at ccw dump end
- Instead of always clearing the memory on reipl after the ccw dump has
  been taken, check for the special OS_INFO_FLAG_REIPL_CLEAR flag in
  os_info flags entry (indicates if sysfs 'clear' attribute has been set
  on the panicked system) and trigger diag308 with a proper subcode.
- Get rid of superfluous ipib_info structure in stage2dump.c.
- Collect ipl_pbt constants in boot/ipl.h header.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Mikhail Zaslonko
2b7df1fcac include/boot: Rename DIAG308 constants
Add DIAG308_LOAD_NORMAL diag308 subcode (used by FCP/NVMe normal ipl).
Rename other diag308_subcode and diag308_rc constants to be in sync with
kernel naming.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Mikhail Zaslonko
53eccc0a3d zipl/boot: Update struct os_info with new OS_INFO_FLAGS_ENTRY
Introduce new os_info flags entry pointing to the field with bit flags.
The flag OS_INFO_FLAG_REIPL_CLEAR indicates that 'clear' sysfs attribute
has been set on a panicked system.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Mikhail Zaslonko
951cf9d7b0 zipl/boot: Reuse os_info_valid() in kdump_os_info_check()
Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Mikhail Zaslonko
87136bb0d0 zipl/boot: Introduce os_info validation API
- Add os_info_check() function to verify os_info address, magic and
  checksum.
- Add os_info_entry_is_valid() function to check whether requested entry
  is present and valid.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Mikhail Zaslonko
eb06ebe245 include/boot: Move zipl/boot/error.h to include/boot
- Move zipl/boot/error.h to include/boot
- Adjust include statements in zipb/boot and genprotimg/boot
- Remove error.h from tunedasd/src/tunedasd.c as not needed
- Fix tunedasd/src/Makefile

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Mikhail Zaslonko
b06ca88cd4 zipl/boot: Make kdump_os_info_check() argument a const.
Make 'struct os_info *os_info' a const to ensure/indicate that no changes
are made to the given structure.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Mikhail Zaslonko
5af2e30d9a zipl/boot: Move struct os_info to the separate header
- Move struct os_info from kdump.h to the new header os_info.h.
- Place os_info.h to include/boot in order to use it in zgetdump
  code as well.
- Replace hardcoded value of OS_INFO_CSUM_SIZE with a properly
  calculated one.
- Rename os_info_check() of kdump.h to kdump_os_info_check().

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:27 +02:00
Mete Durlu
ea3529e624 hyptop: allow users to set speedup factor
While calculating real CPU SMT utilization, the SMT speedup factor needs
to be taken into account. Speedup factor depends on machine generations
and variations on workload the machine has. The users should be able to
determine the value according to their needs.

Signed-off-by: Mete Durlu <meted@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:22 +02:00
Mete Durlu
0209c11bc1 hyptop: Add real SMT utilization field
By using core utilization, thread utilization, and management
utilization, it is possible to determine how much capacity is left or
how much the real CPU SMT utilization is on lpars. Extending hyptop
with this new field provides useful information.

For more info about real CPU SMT utilization:
https://linux.mainframe.blog/smt_utilization/

Briefly:
ur = real SMT util
uc = core util
ut = thread util
um = *management util
s  = **speedup factor

	ur = ((uc * per_core_thr_count) - ut) / s + (ut - uc) + um

* management utilization:
logical core time spent on hypervisor instead of logical partition.
** speedup factor:
metric used to calculate the SMT utilization on that logical core. This
value varies depending on the workload and the machine generation due
to hardware optimization level.

Signed-off-by: Mete Durlu <meted@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-20 21:45:16 +02:00
Dan Horák
6a24660472 libekmfweb: fix permissions for /usr/include/ekmfweb
Closes: https://github.com/ibm-s390-linux/s390-tools/pull/153
Signed-off-by: Dan Horák <dan@danny.cz>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-13 11:04:13 +02:00
Dan Horák
a3bc87d87d libkmipclient: fix permissions for /usr/include/kmipclient
GitHub-ID: https://github.com/ibm-s390-linux/s390-tools/pull/153
Signed-off-by: Dan Horák <dan@danny.cz>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-13 11:04:13 +02:00
Dan Horák
85493a2581 zdev: silence "maybe uninitialized" warning in lszdev.c
The compiler doesn't fully understand the code block that precedes the
usage of `site` in the condition and thus it thinks it could be
uninitialized. Silence the warning with an explicit initialization.

In function 'get_site_from_pers',
    inlined from 'dev_table_get_value' at lszdev.c:1079:10:
lszdev.c:258:20: warning: 'site' may be used uninitialized [-Wmaybe-uninitialized]
  258 |                 if (site == SITE_FALLBACK)
      |                    ^
lszdev.c: In function 'dev_table_get_value':
lszdev.c:234:13: note: 'site' was declared here
  234 |         int site, i, num = 0;
      |             ^~~~

Closes: https://github.com/ibm-s390-linux/s390-tools/pull/152
Signed-off-by: Dan Horák <dan@danny.cz>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-13 11:04:13 +02:00
Dan Horák
ad544565fe zipl: silence "maybe uninitialized" warning in scan.c
The compiler doesn't fully understand the code block that precedes the
usage of title_off in the condition and thus it thinks it could be
uninitialized. Silence the warning with an explicit initialization.

  CC       zipl/src/scan.o
In function ‘sort_bls_fields’,
    inlined from ‘scan_bls’ at scan.c:1502:8:
scan.c:874:12: warning: ‘title_off’ may be used uninitialized [-Wmaybe-uninitialized]
  874 |         if (title_off == 0)
      |            ^
scan.c: In function ‘scan_bls’:
scan.c:842:16: note: ‘title_off’ was declared here
  842 |         size_t title_off;
      |                ^~~~~~~~~

GitHub-ID: https://github.com/ibm-s390-linux/s390-tools/pull/152
Signed-off-by: Dan Horák <dan@danny.cz>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2023-07-13 11:04:13 +02:00
Steffen Eiden
5e135a9daf Prepare for next release
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2023-07-11 13:15:19 +02:00
467 changed files with 35864 additions and 9450 deletions

3
.codespell.ignore Normal file
View File

@@ -0,0 +1,3 @@
parm
parms
crate

View File

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

View File

@@ -8,6 +8,12 @@ insert_final_newline = true
charset = utf-8
indent_style = tab
tab_width = 8
trim_trailing_whitespace = true
[*.rs]
indent_style = space
indent_size = 4
tab_width = 4
[*.sh]
shell_variant = bash # used by `shfmt`
@@ -19,3 +25,9 @@ indent_size = 2
[*.py]
indent_style = space
indent_size = 4
[{Makefile,*.mak}]
indent_style = tab
[{COMMIT_EDITMSG,EDIT_DESCRIPTION}]
max_line_length = 72

13
.gitignore vendored
View File

@@ -9,6 +9,10 @@
tags
TAGS
# compile_commands.json
# (https://clang.llvm.org/docs/JSONCompilationDatabase.html)
compile_commands.json
# clangd cache (https://clangd.llvm.org/design/indexing#backgroundindex)
.cache/
@@ -19,6 +23,8 @@ TAGS
#
# Ignore generated executables and other generated files
#
**/.detect-openssl.dep.c
*.debug
ap_tools/ap-check
cmsfs-fuse/cmsfs-fuse
cpacfstats/cpacfstats
@@ -26,6 +32,7 @@ cpacfstats/cpacfstatsd
cpumf/chcpumf
cpumf/lscpumf
cpumf/lshwc
cpumf/lspai
cpumf/pai
cpuplugd/cpuplugd
dasdfmt/dasdfmt
@@ -50,8 +57,8 @@ iucvterm/src/iucvconn
iucvterm/src/iucvtty
iucvterm/src/ttyrun
iucvterm/test/test_afiucv
libap/check-dep-lock
libap/check-dep-json
libap/check-dep-lock
libekmfweb/check-dep-libekmfweb
libekmfweb/detect-openssl-version.dep
libekmfweb/libekmfweb.so
@@ -85,6 +92,7 @@ vmcp/vmcp
vmur/vmur
zconf/chp/chchp
zconf/chp/lschp
zconf/chp/chpstat/chpstat
zconf/css/lscss
zconf/qeth/lsqeth
zconf/scm/lsscm
@@ -96,6 +104,7 @@ zdev/src/chzdev
zdev/src/chzdev_usage.c
zdev/src/lszdev
zdev/src/lszdev_usage.c
zdev/src/zdev_id
zdsfs/zdsfs
zdump/.check_dep_fuse
zdump/.check_dep_zgetdump
@@ -115,7 +124,6 @@ zipl/boot/*.exec
zipl/boot/.loaders
zipl/boot/data.h
zipl/src/chreipl_helper.device-mapper
zdev/src/zdev_id
zipl/src/zipl
zipl/src/zipl-editenv
zipl/src/zipl_helper.device-mapper
@@ -129,4 +137,3 @@ zkey/kmip/zkey-kmip.so
zkey/zkey
zkey/zkey-cryptsetup
zpcictl/zpcictl
**/.detect-openssl.dep.c

35
.pre-commit-config.yaml Normal file
View File

@@ -0,0 +1,35 @@
---
exclude: \.(bin|crl|crt|key)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
exclude_types: ['rust']
- repo: local
hooks:
- id: git-clang-format
name: git-clang-format
description: Run git-clang-format
entry: git
args: [clang-format, --staged, --]
pass_filenames: true
language: system
require_serial: true
minimum_pre_commit_version: "2.9.0"
types_or: [c++, c]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.1
hooks:
- id: codespell
exclude_types: ['rust']
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: shellcheck
args: ["--external-sources"]

12
.rustfmt.toml Normal file
View File

@@ -0,0 +1,12 @@
edition = "2021"
newline_style = "Unix"
# Unstable options that help catching some mistakes in formatting and that we may want to enable
# when they become stable.
#
# They are kept here since they are useful to run from time to time.
#format_code_in_doc_comments = true
#reorder_impl_items = true
#comment_width = 100
#wrap_comments = true
#normalize_comments = true

5
.shellcheckrc Normal file
View File

@@ -0,0 +1,5 @@
# Search in the current script's directory by default (since 0.7.0)
source-path=SCRIPTDIR
# Allow external-sources (since 0.8.0)
external-sources=true

View File

@@ -27,6 +27,7 @@ List of all individuals having contributed content to s390-tools
- Eberhard Pasch
- Eduard Shishkin
- Einar Lueck
- Eric Farman
- Eric Sandeen
- Erwin Vicari
- Eugene Crosser
@@ -35,6 +36,7 @@ List of all individuals having contributed content to s390-tools
- Farhan Ali
- Fedor Loshakov
- Felix Beck
- Finn Callies
- Frank Blaschka
- Frank Heimes
- Frank Munzert
@@ -56,6 +58,7 @@ List of all individuals having contributed content to s390-tools
- Horst Hummel
- Ingo Franzki
- Ingo Tuchscherer
- Jakub Čajka
- Jan Glauber
- Jan Höppner
- Jan Willeke
@@ -124,6 +127,8 @@ List of all individuals having contributed content to s390-tools
- Thomas Richter
- Thomas Spatzier
- Thomas Weber
- Thorsten Winkler
- Tobias Huschle
- Tuan Hoang
- Ursula Braun
- Utz Bacher
@@ -134,3 +139,4 @@ List of all individuals having contributed content to s390-tools
- Volker Sameske
- Wenjia Zhang
- Wolfgang Taphorn
- Yaakov Selkowitz

View File

@@ -1,6 +1,132 @@
Release history for s390-tools (MIT version)
--------------------------------------------
* __v2.33.1 (2024-05-28)__
For Linux kernel version: 6.9
Bug Fixes:
- s390-tools: Fix formatting and typos in README.md
- s390-tools: Fix release string
* __v2.33.0 (2024-05-27)__
For Linux kernel version: 6.9
Add new tools / libraries:
- chpstat: New tool for displaying channel path statistics
- libutil: Add output format helpers(util_fmt: JSON, JSON-SEQ, CSV, text pairs)
Changes of existing tools / libraries:
- chzdev: Add --is-owner to identify files created by zdev
- dasdfmt: Change default mode to always use full-format (Note: affects ESE DASD)
- libap: Significantly reduce delay time between file lock retries
- pvattest: Rewrite from C to Rust
- pvattest: Support additional data & user-data
- rust/pv: Support for Attestation
Bug Fixes:
- chreipl: Improve disk type detection when running under QEMU
- dbginfo.sh: Use POSIX option with uname
- s390-tools: Fix missing hyphen escapes in the man page for many tools
- zipl/src: Fix bugs in disk_get_info() reproducible in corner cases
* __v2.32.0 (2024-04-03)__
For Linux kernel version: 6.8
Changes of existing tools:
- cpumf/lscpumf: add support for machine type 3932
- genprotimg, pvattest, and pvsecret accept IBM signing key with Armonk as
subject locality
- zdump/zipl: Support for List-Directed dump from ECKD DASD
- zkey: Detect FIPS mode and generate PBKDF for luksFormat according to it
Bug Fixes:
- dbginfo.sh: dash compatible copy sequence
- rust/pv_core: Fix UvDeviceInfo::get() method
- zipl/src: Fix leak of files if run with a broken configuration
- zkey: Fix convert command to accept only keys of type CCA-AESDATA
* __v2.31.0 (2024-02-02)__
For Linux kernel version: 6.7
General:
- common.mak: Set default C/C++ standard to gnu11/gnu++11
Add new tools / libraries:
- pvapconfig: Tool to automatically configure APQNs in SE KVM guests
- s390-tools: Provide pre-commit configuration
Changes of existing tools:
- cpuplugd: Adjust to CPU 0 being no longer hotpluggable
- dbginfo.sh: Check for Dynamic Partition Mode
- dbginfo.sh: Update man page and copyright
- rust/pv: Add user-data signing and verifying
- rust/pvsecret: Add user defined signatures and verifications
- zdev/dracut: Consolidate device configuration
Bug Fixes:
- dbginfo.sh: Fix relative path on script copy
- libkmipclient: Fix build with libxml2-2.12.0
- pvsecret: Fix panic if empty file is used as host key document
- rust/pv: Fix 'elided_lifetimes_in_associated_constant' warning
* __v2.30.0 (2023-12-01)__
For Linux kernel version: 6.6
Add new tools / libraries:
- lspai: Tool to display PAI counter sets
- s390-tools: Provide a ShellCheck configuration
Changes of existing tools / libraries:
- cpumf/pai: Add command line option for realtime scheduling
- dbginfo.sh: enhance ethtool collection for ROCE
- libutil/util_lockfile: add routine to return owning pid of file lock
- lszcrypt: Improve lszcrypt output on SE guests
- rust: Use a single workspace for all rust tools
- zdev: limit the derivation of ZDEV_SITE_ID
- zdump/df_s390: Update 'zgetdump -i' output with zlib info
- zdump/dfi_s390: Support reading compressed s390_ext dumps
- zipl/boot: Integrate zlib compression to single volume DASD dumper
- zipl/boot: compile the bootloaders only if HOST_ARCH is s390x
- zipl: Add --no-compress option to zipl command
- zkey: Also check for deconfigured and check-stopped cards
- dbginfo.sh: fix relative path on script copy
Bug Fixes:
- ap_tools/ap-check: handle get-attributes between pre and post event
- libutil: fix util_file_read_*() using wrong format specifiers
- rust/pv: fix Invalid write of size 1
* __v2.29.0 (2023-08-04)__
For Linux kernel version: 6.5
General:
- s390-tools now supports tools written in Rust.
- Add `compdb` Makefile target to create 'compile_commands.json' to LSP
backends in IDEs and editors
Add new tools / libraries:
- rust/pv: Library for pv tools written in rust
- rust/pvsecret: Tool to manage UV-secrets
Changes of existing tools:
- dbginfo.sh: Global IFS variable
- genprotimg: Add support for add-secret requests
- genprotimg: Build debuginfo files for bootloader
- hyptop: Add real SMT utilization field
- hyptop: Allow users to set speedup factor
- pvattest: Add yaml-output for verify command
- zipl: Build debuginfo files for bootloader
Bug Fixes:
- dump2tar: Fix truncated paths
- zdev/dracut: fix kdump build to integrate with site support
* __v2.28.0 (2023-07-11)__
For Linux kernel version: 6.4

View File

@@ -15,11 +15,12 @@ TOOL_DIRS = zipl zdump fdasd dasdfmt dasdview tunedasd \
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
genprotimg lsstp hsci hsavmcore chreipl-fcp-mpath ap_tools rust
else
BASELIB_DIRS =
LIB_DIRS = libpv
TOOL_DIRS = genprotimg pvattest
TOOL_DIRS = genprotimg rust
endif
SUB_DIRS = $(BASELIB_DIRS) $(LIB_DIRS) $(TOOL_DIRS)

View File

@@ -15,6 +15,17 @@ The package also contains the following files:
Package contents
----------------
* rust:
all s390-tools that are written in rust and require external crates.
Disable the compilation of all tools in `rust/` using HAVE_CARGO=0
See the `rust/README.md` for Details
- pvattest:
Create, perform, and verify IBM Secure Execution attestation measurements.
- pvapconfig:
Automatic configure APQNs within an SE KVM guest
- pvsecret:
Manage secrets for IBM Secure Execution guests
* dasdfmt:
Low-level format ECKD DASDs with the classical Linux disk layout or the new
z/OS compatible disk layout.
@@ -33,9 +44,6 @@ Package contents
* genprotimg:
Create a protected virtualization image.
* pvattest:
Create, perform, and verify protected virtualization attestation measurements.
* udev rules:
- 59-dasd.rules: rules for unique DASD device nodes created in /dev/disk/.
- 57-osasnmpd.rules: udev rules for osasnmpd.
@@ -305,13 +313,14 @@ build options:
| net-snmp | `HAVE_SNMP` | osasnmpd |
| glibc-static | `HAVE_LIBC_STATIC` | zfcpdump |
| openssl | `HAVE_OPENSSL` | genprotimg, zkey, libekmfweb, |
| | | libkmipclient, pvattest, zgetdump |
| | | libkmipclient, pvattest, zgetdump, |
| | | rust/pvsecret, |
| cryptsetup | `HAVE_CRYPTSETUP2` | zkey-cryptsetup |
| json-c | `HAVE_JSONC` | zkey-cryptsetup, libekmfweb, |
| | | libkmipclient |
| glib2 | `HAVE_GLIB2` | genprotimg, pvattest, zgetdump |
| libcurl | `HAVE_LIBCURL` | genprotimg, libekmfweb, libkmipclient,|
| | | pvattest |
| | | pvattest, rust/pvsecret, |
| libxml2 | `HAVE_LIBXML2` | libkmipclient |
| systemd | `HAVE_SYSTEMD` | hsavmcore |
| libudev | `HAVE_LIBUDEV` | cpacfstatsd |
@@ -324,6 +333,7 @@ This table lists additional build or install options:
| | | zipl |
| initramfs-tools | `HAVE_INITRAMFS` | zdev, zipl |
| | `ZDEV_ALWAYS_UPDATE_INITRD` | zdev |
| rust | `HAVE_CARGO` | rust/* |
The s390-tools build process uses "pkg-config" and therefore it must be
available.
@@ -334,6 +344,14 @@ Build and runtime requirements for specific tools
In the following more details on the build an runtime requirements of
the different tools are provided:
* rust/pvsecret:
For building pvsecret you need OpenSSL version 1.1.1 or newer
installed (openssl-devel.rpm). Also required is cargo and libcurl.
Tip: you may skip the pvsecret build by adding
`HAVE_OPENSSL=0`, `HAVE_LIBCURL=0`, or `HAVE_CARGO=0`.
The runtime requirements are: openssl-libs (>= 1.1.1).
* dbginfo.sh:
The tar package is required to archive collected data.
@@ -345,12 +363,11 @@ the different tools are provided:
The runtime requirements are: openssl-libs (>= 1.1.0) and glib2.
* pvattest:
* rust/pvattest:
For building pvattest you need OpenSSL version 1.1.1 or newer
installed (openssl-devel.rpm). Also required is glib2.56 or newer
(glib2-devel.rpm) and libcurl.
installed (openssl-devel.rpm). Also required is cargo and libcurl.
Tip: you may skip the pvattest build by adding
`HAVE_OPENSSL=0`, `HAVE_LIBCURL=0`, or `HAVE_GLIB2=0`.
`HAVE_OPENSSL=0`, `HAVE_LIBCURL=0`, or `HAVE_CARGO=0`.
The runtime requirements are: openssl-libs (>= 1.1.1) and
glib2.56 or newer.
@@ -371,6 +388,24 @@ the different tools are provided:
- Packages: blktrace, multipath-tools, sg3-utils
- Tools: rsync, tar, lsscsi
* zipl
For CCW-type DASD dump, zlib compression can be used to compress the dump
data before writing it to the DASD partition. It can benefit from
s390 on-chip compression accelerator (DFLTCC) and provide a faster dumping
process, hence lower system downtime.
The zlib version integrated with zipl (zipl/boot/zlib) is based on the Linux
kernel zlib (kernel version 6.3) which represents zlib version 1.1.3 with a
limited number of functions and a number of updates on top including s390
hardware compression (DFLTCC) support. Also, all memory allocations are
performed in advance, which aligns with zipl requirements.
The CCW-type standalone dumper is built as a single binary and must be
loaded to stage2 during boot. Hence, all required zlib functions must be
integrated into it, and its size is restricted. To limit the size, only
deflate-related parts are integrated (no decompression is required during
dumping).
Removing the inflate modules and function prototypes are the only major
modifications made to the kernel version of zlib.
* zgetdump
For building zgetdump you need OpenSSL version 1.1.0 or newer
installed (openssl-devel.rpm). Also required is glib2

View File

@@ -798,12 +798,34 @@ static int ap_check_handle_get_attributes(struct ap_check_anchor *anc)
FILE *f;
int rc;
rc = ap_get_lock_callout();
if (rc) {
fprintf(stderr, "Failed to acquire configuration lock %d\n", rc);
return -1;
/*
* For the get-attributes callout, we are typically called without the
* callout lock held. However, there is a particular scenario (define
* of an active mdev) where we may or may not be called with the lock
* already held on behalf of mdevctl, depending on the mdevctl version.
* Let's test for lock ownership first and, if already owned by the
* parent (mdevctl) proceed rather than waiting on the file lock.
*/
rc = ap_try_lock_callout();
switch (rc) {
case 0:
/* Lock acquired */
anc->cleanup_lock = true;
break;
case 1:
/* Lock held by parent -- trust the lock will remain held */
break;
default:
/* Lock not acquired or held by parent -- do a normal obtain */
rc = ap_get_lock_callout();
if (rc) {
fprintf(stderr,
"Failed to acquire configuration lock %d\n",
rc);
return -1;
}
anc->cleanup_lock = true;
}
anc->cleanup_lock = true;
/*
* Read the 'matrix' and 'control_domains' attributes to get the

View File

@@ -17,7 +17,6 @@
# GNU awk:
# - gawk
override SHELL := /bin/bash
override .SHELLFLAGS := -O globstar -O nullglob -O extglob -c
# Include common s390-tools definitions

View File

@@ -8,10 +8,14 @@ ASAN ?= 0
ENABLE_WERROR ?= 0
OPT_FLAGS ?=
MAKECMDGOALS ?=
CARGO ?= cargo
CARGOFLAGS ?=
ifeq ($(COMMON_INCLUDED),false)
COMMON_INCLUDED := true
override SHELL := /bin/bash
# '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
@@ -27,11 +31,11 @@ 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 = 28
PATCHLEVEL = 0
DISTRELEASE = build-$(shell date +%Y%m%d)
S390_TOOLS_RELEASE = $(VERSION).$(RELEASE).$(PATCHLEVEL)-$(DISTRELEASE)
VERSION := 2
RELEASE := 33
PATCHLEVEL := 1
DISTRELEASE := build-$(shell date +%Y%m%d)
S390_TOOLS_RELEASE := $(VERSION).$(RELEASE).$(PATCHLEVEL)-$(DISTRELEASE)
export S390_TOOLS_RELEASE
reldir = $(subst $(realpath $(dir $(filter %common.mak,$(MAKEFILE_LIST))))/,,$(CURDIR))
@@ -89,19 +93,19 @@ define cmd_define_and_export
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))
$(call cmd_define_and_export, AS$(1)," AS$(1) ",$(2)as)
$(call cmd_define_and_export, CC$(1)," CC$(1) ",$(2)gcc)
$(call cmd_define_and_export, LINK$(1)," LINK$(1) ",$$(CC$(1)))
$(call cmd_define_and_export, CXX$(1)," CXX$(1) ",$(2)g++)
$(call cmd_define_and_export, LINKXX$(1)," LINKXX$(1) ",$$(CXX$(1)))
$(call cmd_define_and_export, CPP$(1)," CPP$(1) ",$(2)gcc -E)
$(call cmd_define_and_export, AR$(1)," AR$(1) ",$(2)ar)
$(call cmd_define_and_export, NM$(1)," NM$(1) ",$(2)nm)
$(call cmd_define_and_export, STRIP$(1)," STRIP$(1) ",$(2)strip)
$(call cmd_define_and_export,OBJCOPY$(1)," OBJCOPY$(1) ",$(2)objcopy)
$(call cmd_define_and_export,OBJDUMP$(1)," OBJDUMP$(1) ",$(2)objdump)
PKG_CONFIG$(1) = pkg-config
export PKG_CONFIG$(1)
endef
# If the host architecture is not the same as the build architecture
@@ -115,15 +119,19 @@ ifneq ($(HOST_ARCH),$(BUILD_ARCH))
endif
endif
$(call define_toolchain_variables,_FOR_BUILD,)
$(call define_toolchain_variables,,$(CROSS_COMPILE))
$(eval $(call define_toolchain_variables,_FOR_BUILD,))
$(eval $(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))
$(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))
$(eval $(call cmd_define,CARGO_BUILD," CARGO BUILD ",$(CARGO) build))
$(eval $(call cmd_define,CARGO_TEST, " CARGO TEST ",$(CARGO) test))
$(eval $(call cmd_define,CARGO_CLEAN," CARGO CLEAN ",$(CARGO) clean))
CHECK = sparse
CHECK_SILENT := $(CHECK)
@@ -133,8 +141,10 @@ SKIP = echo " SKIP $(call reldir) due to"
INSTALL = install
CP = cp
ALL_CARGOFLAGS := $(CARGOFLAGS)
ifneq ("${V}","1")
MAKEFLAGS += --quiet
ALL_CARGOFLAGS += --quiet
echocmd=echo $1$(call reldir)$2;
RUNTEST += > /dev/null 2>&1
else
@@ -283,8 +293,8 @@ INSTDIRS = $(USRSBINDIR) $(USRBINDIR) $(BINDIR) $(LIBDIR) $(MANDIR) \
$(ZFCPDUMP_DIR) $(SYSTEMDSYSTEMUNITDIR) \
$(USRLIB64DIR) $(USRINCLUDEDIR) $(ZKEYKMSPLUGINDIR) \
$(SOINSTALLDIR) $(USRLIBDIR)
OWNER = $(shell id -un)
GROUP = $(shell id -gn)
OWNER := $(shell id -un)
GROUP := $(shell id -gn)
export INSTALLDIR BINDIR LIBDIR USRLIBDIR USRLIB64DIR MANDIR OWNER GROUP
# Special defines for zfcpdump
@@ -294,7 +304,7 @@ ZFCPDUMP_FLAVOR = zfcpdump
export ZFCPDUMP_DIR ZFCPDUMP_IMAGE ZFCPDUMP_INITRD ZFCPDUMP_FLAVOR
CFLAGS ?= $(DEFAULT_CFLAGS) $(OPT_FLAGS)
CFLAGS_FOR_BUILD ?= $(DEFAULT_CFLAGS) $(OPT_FLAGS)
CFLAGS_FOR_BUILD ?= -std=gnu11 $(DEFAULT_CFLAGS) $(OPT_FLAGS)
CPPFLAGS ?= $(DEFAULT_CPPFLAGS)
LDFLAGS ?= $(DEFAULT_LDFLAGS)
@@ -303,14 +313,14 @@ ALL_CFLAGS = -DS390_TOOLS_RELEASE=$(S390_TOOLS_RELEASE) \
-DS390_TOOLS_DATADIR=$(TOOLS_DATADIR) \
-DS390_TOOLS_SYSCONFDIR=$(SYSCONFDIR) \
-DS390_TOOLS_BINDIR=$(BINDIR) \
$(CFLAGS)
-std=gnu11 $(CFLAGS)
CXXFLAGS ?= $(DEFAULT_CFLAGS) $(OPT_FLAGS)
ALL_CXXFLAGS = -DS390_TOOLS_RELEASE=$(S390_TOOLS_RELEASE) \
-DS390_TOOLS_LIBDIR=$(TOOLS_LIBDIR) \
-DS390_TOOLS_DATADIR=$(TOOLS_DATADIR) \
-DS390_TOOLS_SYSCONFDIR=$(SYSCONFDIR) \
-DS390_TOOLS_BINDIR=$(BINDIR) \
$(CXXFLAGS)
-std=gnu++11 $(CXXFLAGS)
ALL_CPPFLAGS = -I $(rootdir)include $(CPPFLAGS)
ALL_LDFLAGS = $(LDFLAGS)
@@ -360,6 +370,7 @@ help:
@echo ' all Build all tools (default target)'
@echo ' install Install tools'
@echo ' clean Delete all generated files'
@echo ' compdb Generate compile_commands.json for clangd'
@echo ''
@echo 'OPTIONS'
@echo ' D=1 Build with debugging option "-Og"'
@@ -375,6 +386,32 @@ help:
@echo ' # make C=1 CHECK=smatch'
.PHONY: help
# 'compile_commands.json' generation
#
# Create the compilation database 'compile_commands.json'. See
# https://clang.llvm.org/docs/JSONCompilationDatabase.html for details.
#
.PHONY: compdb
compdb:
$(MAKE) clean
ifneq ($(shell command -v compiledb),)
compiledb $(MAKE)
else ifneq ($(shell command -v bear),)
ifeq ($(shell bear --help|grep -- '-- ...'),)
bear $(MAKE)
else
bear -- $(MAKE)
endif
else
$(error Please install either 'compiledb' or 'bear')
endif
# Prints the s390-tools release string
version:
$(info $(S390_TOOLS_RELEASE))
.PHONY: version
# Automatic dependency generation
#
# Create ".o.d" dependency files with the -MM compile option for all ".c" and
@@ -485,7 +522,7 @@ install_echo:
install: install_echo install_dirs
clean_echo:
$(call echocmd," CLEAN ")
$(call echocmd," CLEAN ")
clean_gcov:
rm -f -- *.gcda *.gcno *.gcov
clean_dep:

View File

@@ -21,10 +21,11 @@ ALL_CPPFLAGS += -DVERSION=$(VERSION)
all: check_dep cpacfstats cpacfstatsd
cpacfstatsd: cpacfstatsd.o stats_sock.o perf_crypto.o
cpacfstatsd: cpacfstatsd.o stats_sock.o perf_crypto.o cpacfstats_common.o \
$(rootdir)/libutil/libutil.a
$(LINK) $(ALL_LDFLAGS) $^ $(LDLIBS) -ludev -lpthread -o $@
cpacfstats: cpacfstats.o stats_sock.o
cpacfstats: cpacfstats.o stats_sock.o cpacfstats_common.o
$(LINK) $(ALL_LDFLAGS) $^ $(LDLIBS) -o $@
install: all

View File

@@ -355,13 +355,13 @@ PCKMO DES,
.IP \(bu
PCKMO 2key TDES,
.IP \(bu
PCMKO TDES,
PCKMO TDES,
.IP \(bu
PCKMO AES 128bit,
.IP \(bu
PCKMO AES 192bit,
.IP \(bu
PCMKO AES 256bit,
PCKMO AES 256bit,
.IP \(bu
PCKMO ECC P256,
.IP \(bu

View File

@@ -55,168 +55,6 @@ static const char *const counter_str[] = {
[PAI_KERNEL] = "pai_kernel"
};
/* Strings for the pai counter details. Note that this is 0-based
* while PoP is 1-based.
*/
static const char *const pai_str[] = {
[ 0] = "KM DES",
[ 1] = "KM 2key TDES",
[ 2] = "KM TDES",
[ 3] = "KM DES protected key",
[ 4] = "KM 2key TDES protected key",
[ 5] = "KM TDES protected key",
[ 6] = "KM AES 128bit",
[ 7] = "KM AES 192bit",
[ 8] = "KM AES 256bit",
[ 9] = "KM AES 128bit protected key",
[ 10] = "KM AES 192bit protected key",
[ 11] = "KM AES 256bit protected key",
[ 12] = "KM AES-XTS 128bit",
[ 13] = "KM AES-XTS 256bit",
[ 14] = "KM AES-XTS 128bit protected key",
[ 15] = "KM AES-XTS 256bit protected key",
[ 16] = "KMC DES",
[ 17] = "KMC 2key TDES",
[ 18] = "KMC TDES",
[ 19] = "KMC DES protected key",
[ 20] = "KMC 2key TDES protected key",
[ 21] = "KMC TDES protected key",
[ 22] = "KMC AES 128bit",
[ 23] = "KMC AES 192bit",
[ 24] = "KMC AES 256bit",
[ 25] = "KMC AES 128bit protected key",
[ 26] = "KMC AES 192bit protected key",
[ 27] = "KMC AES 256bit protected key",
[ 28] = "KMC PRNG",
[ 29] = "KMA AES 128bit",
[ 30] = "KMA AES 192bit",
[ 31] = "KMA AES 256bit",
[ 32] = "KMA AES 128bit protected key",
[ 33] = "KMA AES 192bit protected key",
[ 34] = "KMA AES 256bit protected key",
[ 35] = "KMF DES",
[ 36] = "KMF 2key TDES",
[ 37] = "KMF TDES",
[ 38] = "KMF DES protected key",
[ 39] = "KMF 2key TDES protected key",
[ 40] = "KMF TDES protected key",
[ 41] = "KMF AES 128bit",
[ 42] = "KMF AES 192bit",
[ 43] = "KMF AES 256bit",
[ 44] = "KMF AES 128bit protected key",
[ 45] = "KMF AES 192bit protected key",
[ 46] = "KMF AES 256bit protected key",
[ 47] = "KMCTR DES",
[ 48] = "KMCTR 2key TDES",
[ 49] = "KMCTR TDES",
[ 50] = "KMCTR DES protected key",
[ 51] = "KMCTR 2key TDES protected key",
[ 52] = "KMCTR TDES protected key",
[ 53] = "KMCTR AES 128bit",
[ 54] = "KMCTR AES 192bit",
[ 55] = "KMCTR AES 256bit",
[ 56] = "KMCTR AES 128bit protected key",
[ 57] = "KMCTR AES 192bit protected key",
[ 58] = "KMCTR AES 256bit protected key",
[ 59] = "KMO DES",
[ 60] = "KMO 2key TDES",
[ 61] = "KMO TDES",
[ 62] = "KMO DES protected key",
[ 63] = "KMO 2key TDES protected key",
[ 64] = "KMO TDES protected key",
[ 65] = "KMO AES 128bit",
[ 66] = "KMO AES 192bit",
[ 67] = "KMO AES 256bit",
[ 68] = "KMO AES 128bit protected key",
[ 69] = "KMO AES 192bit protected key",
[ 70] = "KMO AES 256bit protected key",
[ 71] = "KIMD SHA1",
[ 72] = "KIMD SHA256",
[ 73] = "KIMD SHA512",
[ 74] = "KIMD SHA3-224",
[ 75] = "KIMD SHA3-256",
[ 76] = "KIMD SHA3-384",
[ 77] = "KIMD SHA3-512",
[ 78] = "KIMD SHAKE 128",
[ 79] = "KIMD SHAKE 256",
[ 80] = "KIMD GHASH",
[ 81] = "KLMD SHA1",
[ 82] = "KLMD SHA256",
[ 83] = "KLMD SHA512",
[ 84] = "KLMD SHA3-224",
[ 85] = "KLMD SHA3-256",
[ 86] = "KLMD SHA3-384",
[ 87] = "KLMD SHA3-512",
[ 88] = "KLMD SHAKE 128",
[ 89] = "KLMD SHAKE 256",
[ 90] = "KMAC DES",
[ 91] = "KMAC 2key TDES",
[ 92] = "KMAC TDES",
[ 93] = "KMAC DES protected key",
[ 94] = "KMAC 2key TDES protected key",
[ 95] = "KMAC TDES protected key",
[ 96] = "KMAC AES 128bit",
[ 97] = "KMAC AES 192bit",
[ 98] = "KMAC AES 256bit",
[ 99] = "KMAC AES 128bit protected key",
[100] = "KMAC AES 192bit protected key",
[101] = "KMAC AES 256bit protected key",
[102] = "PCC Last Block CMAC DES",
[103] = "PCC Last Block CMAC 2key TDES",
[104] = "PCC Last Block CMAC TDES",
[105] = "PCC Last Block CMAC DES protected key",
[106] = "PCC Last Block CMAC 2key TDES protected key",
[107] = "PCC Last Block CMAC TDES protected key",
[108] = "PCC Last Block CMAC AES 128bit",
[109] = "PCC Last Block CMAC AES 192bit",
[110] = "PCC Last Block CMAC AES 256bit",
[111] = "PCC Last Block CMAC AES 128bit protected key",
[112] = "PCC Last Block CMAC AES 192bit protected key",
[113] = "PCC Last Block CMAC AES 256bit protected key",
[114] = "PCC XTS Parameter AES 128bit",
[115] = "PCC XTS Parameter AES 256bit",
[116] = "PCC XTS Parameter AES 128bit protected key",
[117] = "PCC XTS Parameter AES 256bit protected key",
[118] = "PCC Scalar Mult P256",
[119] = "PCC Scalar Mult P384",
[120] = "PCC Scalar Mult P521",
[121] = "PCC Scalar Mult Ed25519",
[122] = "PCC Scalar Mult Ed448",
[123] = "PCC Scalar Mult X25519",
[124] = "PCC Scalar Mult X448",
[125] = "PRNO SHA512 DRNG",
[126] = "PRNO TRNG Query Ratio",
[127] = "PRNO TRNG",
[128] = "KDSA ECDSA Verify P256",
[129] = "KDSA ECDSA Verify P384",
[130] = "KDSA ECDSA Verify P521",
[131] = "KDSA ECDSA Sign P256",
[132] = "KDSA ECDSA Sign P384",
[133] = "KDSA ECDSA Sign P521",
[134] = "KDSA ECDSA Sign P256 protected key",
[135] = "KDSA ECDSA Sign P384 protected key",
[136] = "KDSA ECDSA Sign P521 protected key",
[137] = "KDSA EdDSA Verify Ed25519",
[138] = "KDSA EdDSA Verify Ed448",
[139] = "KDSA EdDSA Sign Ed25519",
[140] = "KDSA EdDSA Sign Ed448",
[141] = "KDSA EdDSA Sign Ed25519 protected key",
[142] = "KDSA EdDSA Sign Ed448 protected key",
[143] = "PCKMO DES",
[144] = "PCKMO 2key TDES",
[145] = "PCMKO TDES",
[146] = "PCKMO AES 128bit",
[147] = "PCKMO AES 192bit",
[148] = "PCMKO AES 256bit",
[149] = "PCKMO ECC P256",
[150] = "PCKMO ECC P384",
[151] = "PCKMO ECC P521",
[152] = "PCKMO ECC Ed25519",
[153] = "PCKMO ECC Ed448",
[154] = "Reserved 1",
[155] = "Reserved 2"
};
static int paiprintnonzero;
@@ -275,7 +113,8 @@ static void json_print_virtual_counter_answer(int s, int ctr,
int state, uint64_t value)
{
int paictr = 0, paistate = 0, ec;
uint64_t i, paivalue = 0, maxnum;
uint64_t i, paivalue = 0;
unsigned int maxnum;
const char *space;
switch (ctr) {
@@ -288,11 +127,11 @@ static void json_print_virtual_counter_answer(int s, int ctr,
printf("\"value\":%d}", !!value);
return;
case PAI_USER:
maxnum = NUM_PAI_USER;
maxnum = get_num_user_space_ctrs();
space = "user";
break;
case PAI_KERNEL:
maxnum = NUM_PAI_KERNEL;
maxnum = MAX_NUM_PAI;
space = "kernel";
break;
default:
@@ -304,7 +143,7 @@ static void json_print_virtual_counter_answer(int s, int ctr,
return;
if (value > maxnum) {
eprint("Incompatible versions detected!\n");
eprint("Expected %"PRIu64" counter space for %s, but got %"PRIu64"\n",
eprint("Expected %lu counter space for %s, but got %lu\n",
maxnum, space, value);
exit(EXIT_FAILURE);
}
@@ -315,18 +154,18 @@ static void json_print_virtual_counter_answer(int s, int ctr,
/* No more data for this virtual event after error. */
return;
}
if (paictr > NUM_PAI_KERNEL) {
if (paictr > MAX_NUM_PAI) {
eprint("Pai counter number too big: %d\n", paictr);
} else {
printjsonsep();
printf("{\"counter\":\"%s\",\"space\":\"%s\",\"counterid\":%d,",
pai_str[paictr], space, paictr + 1);
get_ctr_name(paictr), space, paictr + 1);
if (paistate < 0) {
printf("\"error\":%d}", paistate);
/* Protocol does not send further counters. */
return;
}
printf("\"value\":%"PRIu64"}", paivalue);
printf("\"value\":%lu}", paivalue);
}
}
}
@@ -341,7 +180,8 @@ static void print_virtual_counter_answer(int s,
[UNSUPPORTED] = "unsupported"
};
int paictr = 0, paistate = 0, ec;
uint64_t i, paivalue = 0, maxnum;
uint64_t i, paivalue = 0;
unsigned int maxnum;
const char *ctrstr;
switch (ctr) {
@@ -350,11 +190,11 @@ static void print_virtual_counter_answer(int s,
printf(" hotplug detected\n");
return;
case PAI_USER:
maxnum = NUM_PAI_USER;
maxnum = get_num_user_space_ctrs();
ctrstr = "pai_user";
break;
case PAI_KERNEL:
maxnum = NUM_PAI_KERNEL;
maxnum = MAX_NUM_PAI;
ctrstr = "pai_kernel";
break;
default:
@@ -372,7 +212,7 @@ static void print_virtual_counter_answer(int s,
return;
if (value > maxnum) {
eprint("Incompatible versions detected!\n");
eprint("Expected %"PRIu64" counters for %s, but got %"PRIu64"\n",
eprint("Expected %lu counters for %s, but got %lu\n",
maxnum, ctrstr, value);
exit(EXIT_FAILURE);
}
@@ -383,10 +223,11 @@ static void print_virtual_counter_answer(int s,
/* No more data for this virtual event after error. */
return;
}
if (paictr > NUM_PAI_KERNEL)
if (paictr > MAX_NUM_PAI)
eprint("Pai counter number too big: %d\n", paictr);
else if (!paiprintnonzero || paivalue > 0)
printf(" %-45s: %"PRIu64"\n", pai_str[paictr], paivalue);
printf(" (%3d) %-45s: %lu\n", paictr + 1,
get_ctr_name(paictr), paivalue);
}
}
@@ -402,7 +243,7 @@ static void print_answer(int s, int ctr, int state, uint64_t value)
else if (state == UNSUPPORTED)
printf(" %s counter: unsupported\n", counter_str[ctr]);
else
printf(" %s counter: %"PRIu64"\n", counter_str[ctr], value);
printf(" %s counter: %lu\n", counter_str[ctr], value);
}
@@ -417,7 +258,7 @@ static void json_print_answer(int s, int ctr, int state, uint64_t value)
} else if (state == ENABLED) {
printjsonsep();
printf("{\"counter\":\"%s\",", counter_str[ctr]);
printf("\"value\":%"PRIu64"}", value);
printf("\"value\":%lu}", value);
}
}

View File

@@ -20,12 +20,22 @@
#define DEFAULT_RECV_TIMEOUT (30 * 1000)
/*
* Number of PAI counters for user space. This excludes PCKMO since
* this instruction is privileged.
* Number of PAI counters. Contains all counters regardless of kernel or user
* space
*/
#define NUM_PAI_USER 143
/* Number of PAI counters for kernel space. Contains all counters. */
#define NUM_PAI_KERNEL 156
#define MAX_NUM_PAI 156
/*
* This is the sysfs directory from which cpacfstatsd daemon application loads
* the available PAI counters
*/
#define SYSFS_PAI_COUNTER "/sys/bus/event_source/devices/pai_crypto/events/"
/*
* Note that this is the first kernel only counter in the 1-based list of the
* architecture and NOT from the 0-based list in the cpacfstats code!
*/
#define FIRST_KERNEL_ONLY_COUNTER 144
int eprint(const char *format, ...);
@@ -67,6 +77,12 @@ enum state_e {
UNSUPPORTED
};
enum counter_type {
SUPPRESS_COUNTER = 0,
KERNEL_AND_USER_COUNTER,
KERNEL_ONLY_COUNTER,
};
/*
* query send from client to daemon
* Consist of:
@@ -122,15 +138,23 @@ int recv_msg(int sfd, struct msg *m, int timeout);
/* perf_crypto.c */
int perf_init(void);
int perf_init(unsigned int *supported_counters);
void perf_stop(void);
void perf_close(void);
int perf_enable_ctr(enum ctr_e ctr);
int perf_disable_ctr(enum ctr_e ctr);
int perf_reset_ctr(enum ctr_e ctr, uint64_t *value);
int perf_read_ctr(enum ctr_e ctr, uint64_t *value);
int perf_enable_ctr(enum ctr_e ctr, unsigned int *supported_counters);
int perf_disable_ctr(enum ctr_e ctr, unsigned int *supported_counters);
int perf_reset_ctr(enum ctr_e ctr, uint64_t *value, unsigned int
*supported_counters);
int perf_read_ctr(enum ctr_e ctr, uint64_t *value, unsigned int
*supported_counters);
int perf_ecc_supported(void);
int perf_ctr_state(enum ctr_e ctr);
int perf_read_pai_ctr(unsigned int ctrnum, int user, uint64_t *value);
/* cpacfstats_common.c */
enum counter_type is_user_space(unsigned int ctr);
const char *get_ctr_name(unsigned int ctr);
unsigned int get_num_user_space_ctrs(void);
#endif

View File

@@ -0,0 +1,233 @@
/* SPDX-License-Identifier: MIT */
/*
* cpacfstats_common.c - shared code by daemon and client
*
* Copyright IBM Corp. 2024
*/
#include <stdint.h>
#include <stdlib.h>
#include "cpacfstats.h"
struct pai_counter {
const char *str;
const unsigned int counter_type;
};
/*
* Strings for the pai counter details.
* Integer indicating if kernel space is needed (0 for user, KERNEL_ONLY_COUNTER for kernel)
* Note that this is 0-based while PoP is 1-based.
*
* When adding new items to this list add the counter number in the pai_idx
* list in cpacfstatsd.c and increase the number of total counters in
* cpacfstats.h.
*/
const struct pai_counter pai[] = {
[ 0] = {"KM DES", KERNEL_AND_USER_COUNTER},
[ 1] = {"KM 2key TDES", KERNEL_AND_USER_COUNTER},
[ 2] = {"KM TDES", KERNEL_AND_USER_COUNTER},
[ 3] = {"KM DES protected key", KERNEL_AND_USER_COUNTER},
[ 4] = {"KM 2key TDES protected key", KERNEL_AND_USER_COUNTER},
[ 5] = {"KM TDES protected key", KERNEL_AND_USER_COUNTER},
[ 6] = {"KM AES 128bit", KERNEL_AND_USER_COUNTER},
[ 7] = {"KM AES 192bit", KERNEL_AND_USER_COUNTER},
[ 8] = {"KM AES 256bit", KERNEL_AND_USER_COUNTER},
[ 9] = {"KM AES 128bit protected key", KERNEL_AND_USER_COUNTER},
[ 10] = {"KM AES 192bit protected key", KERNEL_AND_USER_COUNTER},
[ 11] = {"KM AES 256bit protected key", KERNEL_AND_USER_COUNTER},
[ 12] = {"KM AES-XTS 128bit", KERNEL_AND_USER_COUNTER},
[ 13] = {"KM AES-XTS 256bit", KERNEL_AND_USER_COUNTER},
[ 14] = {"KM AES-XTS 128bit protected key", KERNEL_AND_USER_COUNTER},
[ 15] = {"KM AES-XTS 256bit protected key", KERNEL_AND_USER_COUNTER},
[ 16] = {"KMC DES", KERNEL_AND_USER_COUNTER},
[ 17] = {"KMC 2key TDES", KERNEL_AND_USER_COUNTER},
[ 18] = {"KMC TDES", KERNEL_AND_USER_COUNTER},
[ 19] = {"KMC DES protected key", KERNEL_AND_USER_COUNTER},
[ 20] = {"KMC 2key TDES protected key", KERNEL_AND_USER_COUNTER},
[ 21] = {"KMC TDES protected key", KERNEL_AND_USER_COUNTER},
[ 22] = {"KMC AES 128bit", KERNEL_AND_USER_COUNTER},
[ 23] = {"KMC AES 192bit", KERNEL_AND_USER_COUNTER},
[ 24] = {"KMC AES 256bit", KERNEL_AND_USER_COUNTER},
[ 25] = {"KMC AES 128bit protected key", KERNEL_AND_USER_COUNTER},
[ 26] = {"KMC AES 192bit protected key", KERNEL_AND_USER_COUNTER},
[ 27] = {"KMC AES 256bit protected key", KERNEL_AND_USER_COUNTER},
[ 28] = {"KMC PRNG", KERNEL_AND_USER_COUNTER},
[ 29] = {"KMA AES 128bit", KERNEL_AND_USER_COUNTER},
[ 30] = {"KMA AES 192bit", KERNEL_AND_USER_COUNTER},
[ 31] = {"KMA AES 256bit", KERNEL_AND_USER_COUNTER},
[ 32] = {"KMA AES 128bit protected key", KERNEL_AND_USER_COUNTER},
[ 33] = {"KMA AES 192bit protected key", KERNEL_AND_USER_COUNTER},
[ 34] = {"KMA AES 256bit protected key", KERNEL_AND_USER_COUNTER},
[ 35] = {"KMF DES", KERNEL_AND_USER_COUNTER},
[ 36] = {"KMF 2key TDES", KERNEL_AND_USER_COUNTER},
[ 37] = {"KMF TDES", KERNEL_AND_USER_COUNTER},
[ 38] = {"KMF DES protected key", KERNEL_AND_USER_COUNTER},
[ 39] = {"KMF 2key TDES protected key", KERNEL_AND_USER_COUNTER},
[ 40] = {"KMF TDES protected key", KERNEL_AND_USER_COUNTER},
[ 41] = {"KMF AES 128bit", KERNEL_AND_USER_COUNTER},
[ 42] = {"KMF AES 192bit", KERNEL_AND_USER_COUNTER},
[ 43] = {"KMF AES 256bit", KERNEL_AND_USER_COUNTER},
[ 44] = {"KMF AES 128bit protected key", KERNEL_AND_USER_COUNTER},
[ 45] = {"KMF AES 192bit protected key", KERNEL_AND_USER_COUNTER},
[ 46] = {"KMF AES 256bit protected key", KERNEL_AND_USER_COUNTER},
[ 47] = {"KMCTR DES", KERNEL_AND_USER_COUNTER},
[ 48] = {"KMCTR 2key TDES", KERNEL_AND_USER_COUNTER},
[ 49] = {"KMCTR TDES", KERNEL_AND_USER_COUNTER},
[ 50] = {"KMCTR DES protected key", KERNEL_AND_USER_COUNTER},
[ 51] = {"KMCTR 2key TDES protected key", KERNEL_AND_USER_COUNTER},
[ 52] = {"KMCTR TDES protected key", KERNEL_AND_USER_COUNTER},
[ 53] = {"KMCTR AES 128bit", KERNEL_AND_USER_COUNTER},
[ 54] = {"KMCTR AES 192bit", KERNEL_AND_USER_COUNTER},
[ 55] = {"KMCTR AES 256bit", KERNEL_AND_USER_COUNTER},
[ 56] = {"KMCTR AES 128bit protected key", KERNEL_AND_USER_COUNTER},
[ 57] = {"KMCTR AES 192bit protected key", KERNEL_AND_USER_COUNTER},
[ 58] = {"KMCTR AES 256bit protected key", KERNEL_AND_USER_COUNTER},
[ 59] = {"KMO DES", KERNEL_AND_USER_COUNTER},
[ 60] = {"KMO 2key TDES", KERNEL_AND_USER_COUNTER},
[ 61] = {"KMO TDES", KERNEL_AND_USER_COUNTER},
[ 62] = {"KMO DES protected key", KERNEL_AND_USER_COUNTER},
[ 63] = {"KMO 2key TDES protected key", KERNEL_AND_USER_COUNTER},
[ 64] = {"KMO TDES protected key", KERNEL_AND_USER_COUNTER},
[ 65] = {"KMO AES 128bit", KERNEL_AND_USER_COUNTER},
[ 66] = {"KMO AES 192bit", KERNEL_AND_USER_COUNTER},
[ 67] = {"KMO AES 256bit", KERNEL_AND_USER_COUNTER},
[ 68] = {"KMO AES 128bit protected key", KERNEL_AND_USER_COUNTER},
[ 69] = {"KMO AES 192bit protected key", KERNEL_AND_USER_COUNTER},
[ 70] = {"KMO AES 256bit protected key", KERNEL_AND_USER_COUNTER},
[ 71] = {"KIMD SHA1", KERNEL_AND_USER_COUNTER},
[ 72] = {"KIMD SHA256", KERNEL_AND_USER_COUNTER},
[ 73] = {"KIMD SHA512", KERNEL_AND_USER_COUNTER},
[ 74] = {"KIMD SHA3-224", KERNEL_AND_USER_COUNTER},
[ 75] = {"KIMD SHA3-256", KERNEL_AND_USER_COUNTER},
[ 76] = {"KIMD SHA3-384", KERNEL_AND_USER_COUNTER},
[ 77] = {"KIMD SHA3-512", KERNEL_AND_USER_COUNTER},
[ 78] = {"KIMD SHAKE 128", KERNEL_AND_USER_COUNTER},
[ 79] = {"KIMD SHAKE 256", KERNEL_AND_USER_COUNTER},
[ 80] = {"KIMD GHASH", KERNEL_AND_USER_COUNTER},
[ 81] = {"KLMD SHA1", KERNEL_AND_USER_COUNTER},
[ 82] = {"KLMD SHA256", KERNEL_AND_USER_COUNTER},
[ 83] = {"KLMD SHA512", KERNEL_AND_USER_COUNTER},
[ 84] = {"KLMD SHA3-224", KERNEL_AND_USER_COUNTER},
[ 85] = {"KLMD SHA3-256", KERNEL_AND_USER_COUNTER},
[ 86] = {"KLMD SHA3-384", KERNEL_AND_USER_COUNTER},
[ 87] = {"KLMD SHA3-512", KERNEL_AND_USER_COUNTER},
[ 88] = {"KLMD SHAKE 128", KERNEL_AND_USER_COUNTER},
[ 89] = {"KLMD SHAKE 256", KERNEL_AND_USER_COUNTER},
[ 90] = {"KMAC DES", KERNEL_AND_USER_COUNTER},
[ 91] = {"KMAC 2key TDES", KERNEL_AND_USER_COUNTER},
[ 92] = {"KMAC TDES", KERNEL_AND_USER_COUNTER},
[ 93] = {"KMAC DES protected key", KERNEL_AND_USER_COUNTER},
[ 94] = {"KMAC 2key TDES protected key", KERNEL_AND_USER_COUNTER},
[ 95] = {"KMAC TDES protected key", KERNEL_AND_USER_COUNTER},
[ 96] = {"KMAC AES 128bit", KERNEL_AND_USER_COUNTER},
[ 97] = {"KMAC AES 192bit", KERNEL_AND_USER_COUNTER},
[ 98] = {"KMAC AES 256bit", KERNEL_AND_USER_COUNTER},
[ 99] = {"KMAC AES 128bit protected key", KERNEL_AND_USER_COUNTER},
[100] = {"KMAC AES 192bit protected key", KERNEL_AND_USER_COUNTER},
[101] = {"KMAC AES 256bit protected key", KERNEL_AND_USER_COUNTER},
[102] = {"PCC Last Block CMAC DES", KERNEL_AND_USER_COUNTER},
[103] = {"PCC Last Block CMAC 2key TDES", KERNEL_AND_USER_COUNTER},
[104] = {"PCC Last Block CMAC TDES", KERNEL_AND_USER_COUNTER},
[105] = {"PCC Last Block CMAC DES protected key",
KERNEL_AND_USER_COUNTER},
[106] = {"PCC Last Block CMAC 2key TDES protected key",
KERNEL_AND_USER_COUNTER},
[107] = {"PCC Last Block CMAC TDES protected key",
KERNEL_AND_USER_COUNTER},
[108] = {"PCC Last Block CMAC AES 128bit", KERNEL_AND_USER_COUNTER},
[109] = {"PCC Last Block CMAC AES 192bit", KERNEL_AND_USER_COUNTER},
[110] = {"PCC Last Block CMAC AES 256bit", KERNEL_AND_USER_COUNTER},
[111] = {"PCC Last Block CMAC AES 128bit protected key",
KERNEL_AND_USER_COUNTER},
[112] = {"PCC Last Block CMAC AES 192bit protected key",
KERNEL_AND_USER_COUNTER},
[113] = {"PCC Last Block CMAC AES 256bit protected key",
KERNEL_AND_USER_COUNTER},
[114] = {"PCC XTS Parameter AES 128bit", KERNEL_AND_USER_COUNTER},
[115] = {"PCC XTS Parameter AES 256bit", KERNEL_AND_USER_COUNTER},
[116] = {"PCC XTS Parameter AES 128bit protected key",
KERNEL_AND_USER_COUNTER},
[117] = {"PCC XTS Parameter AES 256bit protected key",
KERNEL_AND_USER_COUNTER},
[118] = {"PCC Scalar Mult P256", KERNEL_AND_USER_COUNTER},
[119] = {"PCC Scalar Mult P384", KERNEL_AND_USER_COUNTER},
[120] = {"PCC Scalar Mult P521", KERNEL_AND_USER_COUNTER},
[121] = {"PCC Scalar Mult Ed25519", KERNEL_AND_USER_COUNTER},
[122] = {"PCC Scalar Mult Ed448", KERNEL_AND_USER_COUNTER},
[123] = {"PCC Scalar Mult X25519", KERNEL_AND_USER_COUNTER},
[124] = {"PCC Scalar Mult X448", KERNEL_AND_USER_COUNTER},
[125] = {"PRNO SHA512 DRNG", KERNEL_AND_USER_COUNTER},
[126] = {"PRNO TRNG Query Ratio", KERNEL_AND_USER_COUNTER},
[127] = {"PRNO TRNG", KERNEL_AND_USER_COUNTER},
[128] = {"KDSA ECDSA Verify P256", KERNEL_AND_USER_COUNTER},
[129] = {"KDSA ECDSA Verify P384", KERNEL_AND_USER_COUNTER},
[130] = {"KDSA ECDSA Verify P521", KERNEL_AND_USER_COUNTER},
[131] = {"KDSA ECDSA Sign P256", KERNEL_AND_USER_COUNTER},
[132] = {"KDSA ECDSA Sign P384", KERNEL_AND_USER_COUNTER},
[133] = {"KDSA ECDSA Sign P521", KERNEL_AND_USER_COUNTER},
[134] = {"KDSA ECDSA Sign P256 protected key",
KERNEL_AND_USER_COUNTER},
[135] = {"KDSA ECDSA Sign P384 protected key",
KERNEL_AND_USER_COUNTER},
[136] = {"KDSA ECDSA Sign P521 protected key",
KERNEL_AND_USER_COUNTER},
[137] = {"KDSA EdDSA Verify Ed25519", KERNEL_AND_USER_COUNTER},
[138] = {"KDSA EdDSA Verify Ed448", KERNEL_AND_USER_COUNTER},
[139] = {"KDSA EdDSA Sign Ed25519", KERNEL_AND_USER_COUNTER},
[140] = {"KDSA EdDSA Sign Ed448", KERNEL_AND_USER_COUNTER},
[141] = {"KDSA EdDSA Sign Ed25519 protected key",
KERNEL_AND_USER_COUNTER},
[142] = {"KDSA EdDSA Sign Ed448 protected key",
KERNEL_AND_USER_COUNTER},
[143] = {"PCKMO DES", KERNEL_ONLY_COUNTER},
[144] = {"PCKMO 2key TDES", KERNEL_ONLY_COUNTER},
[145] = {"PCKMO TDES", KERNEL_ONLY_COUNTER},
[146] = {"PCKMO AES 128bit", KERNEL_ONLY_COUNTER},
[147] = {"PCKMO AES 192bit", KERNEL_ONLY_COUNTER},
[148] = {"PCKMO AES 256bit", KERNEL_ONLY_COUNTER},
[149] = {"PCKMO ECC P256", KERNEL_ONLY_COUNTER},
[150] = {"PCKMO ECC P384", KERNEL_ONLY_COUNTER},
[151] = {"PCKMO ECC P521", KERNEL_ONLY_COUNTER},
[152] = {"PCKMO ECC Ed25519", KERNEL_ONLY_COUNTER},
[153] = {"PCKMO ECC Ed448", KERNEL_ONLY_COUNTER},
[154] = {"Reserved 1", KERNEL_ONLY_COUNTER},
[155] = {"Reserved 2", KERNEL_ONLY_COUNTER}
};
/*
* Returns counter_type of pai_counter struct
*
* SUPPRESS_COUNTER
* KERNEL_AND_USER_COUNTER
* KERNEL_ONLY_COUNTER
*/
enum counter_type is_user_space(unsigned int ctr)
{
if (ctr >= MAX_NUM_PAI)
return SUPPRESS_COUNTER;
return pai[ctr].counter_type;
}
const char *get_ctr_name(unsigned int ctr)
{
if (ctr >= MAX_NUM_PAI)
return NULL;
return pai[ctr].str;
}
/*
* Returns number of PAI counters for which no kernel space is needed
*/
unsigned int get_num_user_space_ctrs(void)
{
unsigned int counter = 0;
unsigned int i;
for (i = 0; i < MAX_NUM_PAI; i++) {
if (is_user_space(i) == KERNEL_AND_USER_COUNTER)
counter++;
}
return counter;
}

View File

@@ -24,12 +24,52 @@
#include <sys/stat.h>
#include <syslog.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <limits.h>
#include "lib/zt_common.h"
#include "lib/util_file.h"
#include "cpacfstats.h"
static volatile int stopsig;
/*
* This list contains the counter numbers sorted by instruction
*/
static const unsigned int pai_idx[] = {
// KM
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
// KMC
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
// KMA
29, 30, 31, 32, 33, 34,
// KMF
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
// KMCTR
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
// KMO
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
// KIMD
71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
// KLMD
81, 82, 83, 84, 85, 86, 87, 88, 89,
// KMAC
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
// PCC
102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
// PRNO
125, 126, 127,
// KDSA
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142,
// PCKMO
143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
// Reserved
154, 155
};
static const char *const name = "cpacfstatsd";
static const char *const usage =
@@ -93,34 +133,35 @@ static int send_answer(int s, int ctr, int state, uint64_t value)
* Note that the PAI counters are 0-based, not 1 based as in PoP!
* Sending ends with the first error.
*/
static int do_send_pai(int s, int user)
static int do_send_pai(int s, int user, unsigned int *counter)
{
int ctr, state, i, maxctr, rc = 0;
int ctr, state, i, rc = 0;
unsigned int current_ctr;
uint64_t value;
if (user) {
ctr = PAI_USER;
maxctr = NUM_PAI_USER;
} else {
ctr = PAI_KERNEL;
maxctr = NUM_PAI_KERNEL;
}
ctr = user ? PAI_USER : PAI_KERNEL;
state = perf_ctr_state(ctr);
if (state != ENABLED)
return rc;
for (i = 0; i < maxctr; ++i) {
rc = perf_read_pai_ctr(i, user, &value);
for (i = 0; i < MAX_NUM_PAI; ++i) {
current_ctr = pai_idx[i];
if ((user && is_user_space(current_ctr) != KERNEL_AND_USER_COUNTER) ||
(!user && is_user_space(current_ctr) == SUPPRESS_COUNTER) ||
counter[current_ctr] != 1)
continue;
rc = perf_read_pai_ctr(current_ctr, user, &value);
if (rc != 0) {
send_answer(s, i, rc, 0);
send_answer(s, current_ctr, rc, 0);
break;
}
send_answer(s, i, state, value);
send_answer(s, current_ctr, state, value);
}
return rc;
}
static int do_enable(int s, enum ctr_e ctr)
static int do_enable(int s, enum ctr_e ctr, unsigned int *supported_counters)
{
uint64_t value = 0;
int i, rc = 0;
@@ -132,7 +173,7 @@ static int do_enable(int s, enum ctr_e ctr)
if (i == (int) ctr || ctr == ALL_COUNTER) {
state = perf_ctr_state(i);
if (state == DISABLED) {
rc = perf_enable_ctr(i);
rc = perf_enable_ctr(i, supported_counters);
if (rc != 0) {
send_answer(s, i, rc, 0);
break;
@@ -140,7 +181,7 @@ static int do_enable(int s, enum ctr_e ctr)
state = ENABLED;
}
if (state != UNSUPPORTED) {
rc = perf_read_ctr(i, &value);
rc = perf_read_ctr(i, &value, supported_counters);
if (rc != 0) {
send_answer(s, i, rc, 0);
break;
@@ -148,20 +189,20 @@ static int do_enable(int s, enum ctr_e ctr)
}
send_answer(s, i, state, value);
if (i == PAI_USER)
rc = do_send_pai(s, 1);
rc = do_send_pai(s, 1, supported_counters);
if (i == PAI_KERNEL)
rc = do_send_pai(s, 0);
rc = do_send_pai(s, 0, supported_counters);
}
}
if (rc == 0) {
rc = perf_read_ctr(HOTPLUG_DETECTED, &value);
rc = perf_read_ctr(HOTPLUG_DETECTED, &value, NULL);
send_answer(s, HOTPLUG_DETECTED, rc, value);
}
return rc;
}
static int do_disable(int s, enum ctr_e ctr)
static int do_disable(int s, enum ctr_e ctr, unsigned int *supported_counters)
{
int i, rc = 0;
uint64_t value;
@@ -171,7 +212,7 @@ static int do_disable(int s, enum ctr_e ctr)
continue;
if (i == (int) ctr || ctr == ALL_COUNTER) {
if (perf_ctr_state(i) == ENABLED) {
rc = perf_disable_ctr(i);
rc = perf_disable_ctr(i, supported_counters);
if (rc != 0) {
send_answer(s, i, rc, 0);
break;
@@ -181,14 +222,14 @@ static int do_disable(int s, enum ctr_e ctr)
}
}
if (rc == 0) {
rc = perf_read_ctr(HOTPLUG_DETECTED, &value);
rc = perf_read_ctr(HOTPLUG_DETECTED, &value, NULL);
send_answer(s, HOTPLUG_DETECTED, rc, value);
}
return rc;
}
static int do_reset(int s, enum ctr_e ctr)
static int do_reset(int s, enum ctr_e ctr, unsigned int *supported_counters)
{
int i, rc = 0, state;
uint64_t value;
@@ -199,7 +240,7 @@ static int do_reset(int s, enum ctr_e ctr)
if (i == (int) ctr || ctr == ALL_COUNTER) {
state = perf_ctr_state(i);
if (state == ENABLED) {
rc = perf_reset_ctr(i, &value);
rc = perf_reset_ctr(i, &value, supported_counters);
if (rc != 0) {
send_answer(s, i, rc, 0);
break;
@@ -207,20 +248,20 @@ static int do_reset(int s, enum ctr_e ctr)
}
send_answer(s, i, state, value);
if (i == PAI_USER)
rc = do_send_pai(s, 1);
rc = do_send_pai(s, 1, supported_counters);
if (i == PAI_KERNEL)
rc = do_send_pai(s, 0);
rc = do_send_pai(s, 0, supported_counters);
}
}
if (rc == 0) {
rc = perf_read_ctr(HOTPLUG_DETECTED, &value);
rc = perf_read_ctr(HOTPLUG_DETECTED, &value, NULL);
send_answer(s, HOTPLUG_DETECTED, rc, value);
}
return rc;
}
static int do_print(int s, enum ctr_e ctr)
static int do_print(int s, enum ctr_e ctr, unsigned int *supported_counters)
{
int i, rc = 0, state;
uint64_t value = 0;
@@ -231,7 +272,7 @@ static int do_print(int s, enum ctr_e ctr)
if (i == (int) ctr || ctr == ALL_COUNTER) {
state = perf_ctr_state(i);
if (state == ENABLED) {
rc = perf_read_ctr(i, &value);
rc = perf_read_ctr(i, &value, supported_counters);
if (rc != 0) {
send_answer(s, i, rc, 0);
break;
@@ -239,13 +280,13 @@ static int do_print(int s, enum ctr_e ctr)
}
send_answer(s, i, state, value);
if (i == PAI_USER)
rc = do_send_pai(s, 1);
rc = do_send_pai(s, 1, supported_counters);
if (i == PAI_KERNEL)
rc = do_send_pai(s, 0);
rc = do_send_pai(s, 0, supported_counters);
}
}
if (rc == 0) {
rc = perf_read_ctr(HOTPLUG_DETECTED, &value);
rc = perf_read_ctr(HOTPLUG_DETECTED, &value, NULL);
send_answer(s, HOTPLUG_DETECTED, rc, value);
}
return rc;
@@ -436,9 +477,44 @@ int eprint(const char *format, ...)
}
/*
* returns -1 on error
* returns X where X is the found counters in dir
*
* the supplied array supported_counters[] is filled in this function with the
* available PAI counters found in SYSFS_PAI_COUNTER
*/
static void supported_functions(unsigned int supported_counters[])
{
const char *dir = SYSFS_PAI_COUNTER;
struct dirent *dp = NULL;
char filepath[PATH_MAX];
unsigned int num;
DIR *dfd = NULL;
dfd = opendir(dir);
if (dfd == NULL)
return;
while ((dp = readdir(dfd)) != NULL) {
if ((strcmp(dp->d_name, ".") != 0) &&
(strcmp(dp->d_name, "..") != 0)) {
snprintf(filepath, sizeof(filepath), "%s%s", dir, dp->d_name);
if (util_file_read_va(filepath, "event=0x10%x", &num) != 1)
continue;
if (num > 0 && num <= MAX_NUM_PAI)
supported_counters[num - 1] = 1;
}
}
closedir(dfd);
return;
}
int main(int argc, char *argv[])
{
int rc, sfd, foreground = 0, startup_pipe = -1, initialized = 0;
unsigned int supported_counters[MAX_NUM_PAI] = { 0 };
struct sigaction act;
if (argc > 1) {
@@ -485,7 +561,9 @@ int main(int argc, char *argv[])
}
}
if (perf_init() != 0) {
supported_functions(supported_counters);
if (perf_init(supported_counters) != 0) {
eprint("Couldn't initialize perf lib\n");
goto error;
}
@@ -548,13 +626,13 @@ int main(int argc, char *argv[])
}
if (cmd == ENABLE)
rc = do_enable(s, ctr);
rc = do_enable(s, ctr, supported_counters);
else if (cmd == DISABLE)
rc = do_disable(s, ctr);
rc = do_disable(s, ctr, supported_counters);
else if (cmd == RESET)
rc = do_reset(s, ctr);
rc = do_reset(s, ctr, supported_counters);
else if (cmd == PRINT)
rc = do_print(s, ctr);
rc = do_print(s, ctr, supported_counters);
else {
eprint("Received unknown command %d, ignoring\n",
(int) cmd);

View File

@@ -52,8 +52,8 @@ static struct pmf_data {
struct percpucounter {
int ctr_fds[ALL_COUNTER];
int pai_user[NUM_PAI_USER];
int pai_kernel[NUM_PAI_KERNEL];
int pai_user[MAX_NUM_PAI];
int pai_kernel[MAX_NUM_PAI];
unsigned int cpunum;
struct percpucounter *next;
};
@@ -84,10 +84,10 @@ static struct percpucounter *allocpercpucounter(unsigned int cpunum)
for (i = 0; i < ALL_COUNTER; ++i)
ppc->ctr_fds[i] = -1;
for (i = 0; i < NUM_PAI_USER; ++i)
for (i = 0; i < MAX_NUM_PAI; ++i) {
ppc->pai_user[i] = -1;
for (i = 0; i < NUM_PAI_KERNEL; ++i)
ppc->pai_kernel[i] = -1;
}
ppc->cpunum = cpunum;
ppc->next = NULL;
}
@@ -100,10 +100,10 @@ static void freepercpucounter(struct percpucounter *pcpu)
for (i = 0; i < ALL_COUNTER; ++i)
(void)close(pcpu->ctr_fds[i]);
for (i = 0; i < NUM_PAI_USER; ++i)
for (i = 0; i < MAX_NUM_PAI; ++i) {
(void)close(pcpu->pai_user[i]);
for (i = 0; i < NUM_PAI_KERNEL; ++i)
(void)close(pcpu->pai_kernel[i]);
}
free(pcpu);
}
@@ -225,7 +225,7 @@ static int perf_event_encode(int *pmutype, int *eventid,
return 0;
}
static int activatecpu(unsigned int cpu)
static int activatecpu(unsigned int cpu, unsigned int *supported_counters)
{
struct perf_event_attr pfm_event;
struct percpucounter *ppc;
@@ -273,7 +273,10 @@ static int activatecpu(unsigned int cpu)
(ctr_state[PAI_USER] == UNSUPPORTED) ==
(ctr_state[PAI_KERNEL] == UNSUPPORTED) */
if (ctr_state[PAI_USER] != UNSUPPORTED) {
for (i = 1; i <= NUM_PAI_USER; ++i) {
for (i = 1; i <= MAX_NUM_PAI; ++i) {
if (is_user_space(i - 1) != KERNEL_AND_USER_COUNTER ||
supported_counters[i - 1] != 1)
continue;
memset(&pfm_event, 0, sizeof(pfm_event));
pfm_event.size = sizeof(pfm_event);
pfm_event.type = paipmutype;
@@ -307,7 +310,14 @@ static int activatecpu(unsigned int cpu)
ppc->pai_kernel[i - 1] = fd;
}
}
for (; i <= NUM_PAI_KERNEL; ++i) {
/*
* i can start at the index of the first PAI counter
* for which kernel space is needed
*/
for (i = FIRST_KERNEL_ONLY_COUNTER; i <= MAX_NUM_PAI; ++i) {
if (is_user_space(i - 1) == SUPPRESS_COUNTER ||
supported_counters[i - 1] != 1)
continue;
memset(&pfm_event, 0, sizeof(pfm_event));
pfm_event.size = sizeof(pfm_event);
pfm_event.type = paipmutype;
@@ -348,10 +358,10 @@ static void deactivatecpu(unsigned int cpunum)
if (pcpu != NULL) {
for (i = 0; i < ALL_COUNTER; ++i)
(void)close(pcpu->ctr_fds[i]);
for (i = 0; i < NUM_PAI_USER; ++i)
for (i = 0; i < MAX_NUM_PAI; ++i) {
(void)close(pcpu->pai_user[i]);
for (i = 0; i < NUM_PAI_KERNEL; ++i)
(void)close(pcpu->pai_kernel[i]);
}
free(pcpu);
if (enabledcounter)
hotplugdetected = 1;
@@ -359,7 +369,7 @@ static void deactivatecpu(unsigned int cpunum)
pthread_mutex_unlock(&rootmux);
}
static int addallcpus(void)
static int addallcpus(unsigned int *supported_counters)
{
unsigned int start, end;
int scanned, rc = 0;
@@ -379,7 +389,7 @@ static int addallcpus(void)
if (scanned == 1)
end = start;
for (; start <= end; ++start) {
if (activatecpu(start)) {
if (activatecpu(start, supported_counters)) {
rc = -1;
goto out;
}
@@ -409,7 +419,7 @@ static int perf_load_counter_data(void)
return res;
}
static void *hotplughandler(void *UNUSED(unused))
static void *hotplughandler(void *supported_counters)
{
struct udev *hotplug;
struct udev_monitor *monitor;
@@ -452,7 +462,7 @@ static void *hotplughandler(void *UNUSED(unused))
path = udev_device_get_devpath(dev);
if (sscanf(path, "/devices/system/cpu/cpu%u", &cpunum) != 1)
continue;
if (on && activatecpu(cpunum))
if (on && activatecpu(cpunum, (unsigned int *) supported_counters))
eprint("Failed to attach to hotplugged CPU %u\n", cpunum);
if (off)
deactivatecpu(cpunum);
@@ -462,11 +472,18 @@ static void *hotplughandler(void *UNUSED(unused))
return NULL;
}
int perf_init(void)
int perf_init(unsigned int *supported_counters)
{
int ecc_supported, i, num;
static const char *cpum_cf[] = {
"DEA_FUNCTIONS",
"AES_FUNCTIONS",
"SHA_FUNCTIONS",
"PRNG_FUNCTIONS",
"ECC_FUNCTION_COUNT"
};
unsigned long maxfd;
struct rlimit rlim;
int i, num;
FILE *f;
/* initialize performance monitoring library */
@@ -478,16 +495,18 @@ int perf_init(void)
/* We currently support all cpumf counters plus two virtual
* counters for PAI. */
num = ALL_COUNTER + 2;
/* Check if ECC is supported on current hardware */
ecc_supported = perf_counter_supported("cpum_cf", "ECC_FUNCTION_COUNT");
if (!cpumf_authorized()) {
for (i = 0; i < ALL_COUNTER; ++i)
ctr_state[i] = UNSUPPORTED;
num -= ALL_COUNTER;
} else if (!ecc_supported) {
ctr_state[ECC_FUNCTIONS] = UNSUPPORTED;
--num;
} else {
for (i = 0; i < ALL_COUNTER; i++) {
if (!perf_counter_supported("cpum_cf", cpum_cf[i])) {
ctr_state[i] = UNSUPPORTED;
num--;
}
}
}
if (!perf_counter_supported("pai_crypto", "CRYPTO_ALL")) {
@@ -523,11 +542,12 @@ int perf_init(void)
return -1;
}
if (pthread_create(&hotplugthread, NULL, hotplughandler, NULL)) {
if (pthread_create(&hotplugthread, NULL, hotplughandler,
supported_counters)) {
eprint("Failed to start hotplug handler thread\n");
return -1;
}
return addallcpus();
return addallcpus(supported_counters);
}
@@ -552,11 +572,14 @@ void perf_close(void)
}
static int enable_array(int *arr, int size)
static int enable_array(int *arr, int user, unsigned int *supported_counters)
{
int i, ec, rc = 0;
for (i = 0; i < size; ++i) {
for (i = 0; i < MAX_NUM_PAI; ++i) {
if ((user && is_user_space(i) != KERNEL_AND_USER_COUNTER) ||
supported_counters[i] != 1 || is_user_space(i) == SUPPRESS_COUNTER)
continue;
ec = ioctl(arr[i], PERF_EVENT_IOC_ENABLE, 0);
if (ec < 0) {
eprint("Ioctl(PERF_EVENT_IOC_ENABLE) failed with errno=%d [%s]\n",
@@ -568,14 +591,14 @@ static int enable_array(int *arr, int size)
}
int perf_enable_ctr(enum ctr_e ctr)
int perf_enable_ctr(enum ctr_e ctr, unsigned int *supported_counters)
{
struct percpucounter *pcpu;
int ec, rc = 0;
if (ctr == ALL_COUNTER) {
for (ctr = 0; ctr < ALL_COUNTER; ctr++) {
rc = perf_enable_ctr(ctr);
rc = perf_enable_ctr(ctr, supported_counters);
if (rc != 0)
return rc;
}
@@ -593,7 +616,7 @@ int perf_enable_ctr(enum ctr_e ctr)
endforeachcpu();
} else if (ctr == PAI_USER) {
foreachcpu(pcpu) {
ec = enable_array(pcpu->pai_user, NUM_PAI_USER);
ec = enable_array(pcpu->pai_user, 1, supported_counters);
if (ec < 0)
rc = -1;
}
@@ -602,7 +625,7 @@ int perf_enable_ctr(enum ctr_e ctr)
endforeachcpu();
} else if (ctr == PAI_KERNEL) {
foreachcpu(pcpu) {
ec = enable_array(pcpu->pai_kernel, NUM_PAI_KERNEL);
ec = enable_array(pcpu->pai_kernel, 0, supported_counters);
if (ec < 0)
rc = -1;
}
@@ -617,11 +640,14 @@ int perf_enable_ctr(enum ctr_e ctr)
}
static int disable_array(int *arr, int size)
static int disable_array(int *arr, int user, unsigned int *supported_counters)
{
int i, ec, rc = 0;
for (i = 0; i < size; ++i) {
for (i = 0; i < MAX_NUM_PAI; ++i) {
if ((user && is_user_space(i) != KERNEL_AND_USER_COUNTER) ||
supported_counters[i] != 1 || is_user_space(i) == SUPPRESS_COUNTER)
continue;
ec = ioctl(arr[i], PERF_EVENT_IOC_DISABLE, 0);
if (ec < 0) {
eprint("Ioctl(PERF_EVENT_IOC_DISABLE) failed with errno=%d [%s]\n",
@@ -633,14 +659,14 @@ static int disable_array(int *arr, int size)
}
int perf_disable_ctr(enum ctr_e ctr)
int perf_disable_ctr(enum ctr_e ctr, unsigned int *supported_counters)
{
struct percpucounter *pcpu;
int ec, rc = 0;
if (ctr == ALL_COUNTER) {
for (ctr = 0; ctr < ALL_COUNTER; ctr++) {
rc = perf_disable_ctr(ctr);
rc = perf_disable_ctr(ctr, supported_counters);
if (rc != 0)
return rc;
}
@@ -660,7 +686,7 @@ int perf_disable_ctr(enum ctr_e ctr)
endforeachcpu();
} else if (ctr == PAI_USER) {
foreachcpu(pcpu) {
ec = disable_array(pcpu->pai_user, NUM_PAI_USER);
ec = disable_array(pcpu->pai_user, 1, supported_counters);
if (ec < 0)
rc = -1;
}
@@ -671,7 +697,7 @@ int perf_disable_ctr(enum ctr_e ctr)
endforeachcpu();
} else if (ctr == PAI_KERNEL) {
foreachcpu(pcpu) {
ec = disable_array(pcpu->pai_kernel, NUM_PAI_KERNEL);
ec = disable_array(pcpu->pai_kernel, 0, supported_counters);
if (ec < 0)
rc = -1;
}
@@ -688,11 +714,14 @@ int perf_disable_ctr(enum ctr_e ctr)
}
static int reset_array(int *arr, int size)
static int reset_array(int *arr, int user, unsigned int *supported_counters)
{
int ec, rc = 0, i;
for (i = 0; i < size; ++i) {
for (i = 0; i < MAX_NUM_PAI; ++i) {
if ((user && is_user_space(i) != KERNEL_AND_USER_COUNTER) ||
supported_counters[i] != 1 || is_user_space(i) == SUPPRESS_COUNTER)
continue;
ec = ioctl(arr[i], PERF_EVENT_IOC_RESET, 0);
if (ec < 0) {
eprint("Ioctl(PERF_EVENT_IOC_RESET) failed with errno=%d [%s]\n",
@@ -704,14 +733,15 @@ static int reset_array(int *arr, int size)
}
int perf_reset_ctr(enum ctr_e ctr, uint64_t *value)
int perf_reset_ctr(enum ctr_e ctr, uint64_t *value, unsigned int
*supported_counters)
{
struct percpucounter *pcpu;
int ec, rc = 0;
if (ctr == ALL_COUNTER) {
for (ctr = 0; ctr < ALL_COUNTER; ctr++) {
rc = perf_reset_ctr(ctr, value);
rc = perf_reset_ctr(ctr, value, supported_counters);
if (rc != 0)
return rc;
}
@@ -727,14 +757,14 @@ int perf_reset_ctr(enum ctr_e ctr, uint64_t *value)
endforeachcpu();
} else if (ctr == PAI_USER) {
foreachcpu(pcpu) {
ec = reset_array(pcpu->pai_user, NUM_PAI_USER);
ec = reset_array(pcpu->pai_user, 1, supported_counters);
if (ec < 0)
rc = -1;
}
endforeachcpu();
} else if (ctr == PAI_KERNEL) {
foreachcpu(pcpu) {
ec = reset_array(pcpu->pai_kernel, NUM_PAI_KERNEL);
ec = reset_array(pcpu->pai_kernel, 0, supported_counters);
if (ec < 0)
rc = -1;
}
@@ -743,12 +773,13 @@ int perf_reset_ctr(enum ctr_e ctr, uint64_t *value)
rc = -1;
}
if (rc == 0)
rc = perf_read_ctr(ctr, value);
rc = perf_read_ctr(ctr, value, supported_counters);
return rc;
}
int perf_read_ctr(enum ctr_e ctr, uint64_t *value)
int perf_read_ctr(enum ctr_e ctr, uint64_t *value, unsigned int
*supported_counters)
{
struct percpucounter *pcpu;
int ec, rc = 0;
@@ -761,11 +792,26 @@ int perf_read_ctr(enum ctr_e ctr, uint64_t *value)
return 0;
}
if (ctr == PAI_USER) {
*value = NUM_PAI_USER;
int c = 0;
for (int i = 0; i < MAX_NUM_PAI; i++) {
if (is_user_space(i) == KERNEL_AND_USER_COUNTER &&
supported_counters[i] == 1)
c++;
}
*value = c;
return 0;
}
if (ctr == PAI_KERNEL) {
*value = NUM_PAI_KERNEL;
int c = 0;
for (int i = 0; i < MAX_NUM_PAI; i++) {
if (supported_counters[i] == 1)
c++;
}
*value = c;
return 0;
}
if (ctr >= ALL_COUNTER)
@@ -802,14 +848,15 @@ int perf_ctr_state(enum ctr_e ctr) {
int perf_read_pai_ctr(unsigned int ctrnum, int user, uint64_t *value)
{
struct percpucounter *pcpu;
unsigned int maxctr;
int *arr, ec, rc = 0;
uint64_t val;
*value = 0;
maxctr = user ? NUM_PAI_USER : NUM_PAI_KERNEL;
if (ctrnum >= maxctr)
if (is_user_space(ctrnum) == SUPPRESS_COUNTER ||
(user && is_user_space(ctrnum) == KERNEL_ONLY_COUNTER))
return -1;
foreachcpu(pcpu) {
arr = user ? pcpu->pai_user : pcpu->pai_kernel;
ec = read(arr[ctrnum], &val, sizeof(val));

View File

@@ -1,7 +1,7 @@
include ../common.mak
BIN_FILES = lscpumf chcpumf lshwc pai
MAN_FILES = lscpumf.8 chcpumf.8 lshwc.8 pai.8
BIN_FILES = lscpumf chcpumf lshwc pai lspai
MAN_FILES = lscpumf.8 chcpumf.8 lshwc.8 pai.8 lspai.8
all: $(BIN_FILES)
@@ -11,6 +11,7 @@ lscpumf: lscpumf.o $(libs)
chcpumf: chcpumf.o $(libs)
lshwc: lshwc.o $(libs)
pai: pai.o $(libs)
lspai: lspai.o $(libs)
install: all install-man
$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man8

View File

@@ -3473,6 +3473,7 @@ static struct counters *get_counter(int ctrset, size_t *len)
read_ccerror(cp, *len);
break;
case UTIL_ARCH_MACHINE_TYPE_Z16:
case UTIL_ARCH_MACHINE_TYPE_Z16_A02:
cp = cpumcf_z16_counters;
*len = ARRAY_SIZE(cpumcf_z16_counters);
}

352
cpumf/lspai.c Normal file
View File

@@ -0,0 +1,352 @@
/* 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.
*/
/* List available Processor Assist Instrumentation (PAI) counters. */
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "lib/util_opt.h"
#include "lib/util_prg.h"
#include "lib/util_base.h"
#include "lib/util_path.h"
#include "lib/util_scandir.h"
#include "lib/util_libc.h"
#include "lib/util_file.h"
#include "lib/util_list.h"
#include "lib/libcpumf.h"
static struct util_opt opt_vec[] = {
UTIL_OPT_SECTION("OPTIONS"),
{
.option = { "numeric", no_argument, NULL, 'n' },
.desc = "Sort PAI counters by counter number"
},
{
.option = { "type", required_argument, NULL, 't' },
.argument = "TYPE",
.desc = "Type of PAI counters to show: crypto, nnpa"
},
UTIL_OPT_HELP,
UTIL_OPT_VERSION,
UTIL_OPT_END
};
static const struct util_prg prg = {
.desc = "List Processor Assist Information counter sets",
.copyright_vec = {
{
.owner = "IBM Corp.",
.pub_first = 2023,
.pub_last = 2023,
},
UTIL_PRG_COPYRIGHT_END
}
};
static bool numsort; /* If true sort counter numerically */
#define PAI_PATH "/bus/event_source/devices/%s"
enum pai_types { /* Bit mask for supported PAI counters */
pai_type_crypto = 0, /* PAI Crypto Counters */
pai_type_nnpa = 1, /* PAI NNPA Counters */
pai_type_max = 2, /* PAI maximum value, must be last */
};
static int pai_types_show;
struct pai_ctrname { /* List of defined counters */
char *name; /* Counter name */
unsigned long nr; /* Counter number */
};
struct pai_node { /* Head for PAI counter sets */
struct util_list_node node; /* Successor in PAI counter set list */
enum pai_types type; /* PAI type */
int pmu; /* Assigned PMU type number */
const char *name; /* Counter set name */
char *name_uc; /* Counter set name upper case */
const char *sysfs_name; /* Counter set name in /sysfs tree */
const char *filter_name; /* Counter set name for scandir filter */
struct pai_ctrname *ctrlist; /* List of counter names & numbers */
size_t ctrsize; /* Total size in bytes of ctrlist */
int ctridx; /* Index of last entry used in ctrlist */
unsigned long base; /* Base number for counter set */
};
static struct util_list pai_list;
/* Return base of counter set, this is the first counter of this set. */
static unsigned long pai_type_base(enum pai_types t)
{
switch (t) {
case pai_type_crypto:
return 0x1000;
case pai_type_nnpa:
return 0x1800;
case pai_type_max:
break;
}
return 0;
}
/* Test PAI counter name from command line option. */
static const char *pai_type_name(enum pai_types t)
{
switch (t) {
case pai_type_crypto:
return "crypto";
case pai_type_nnpa:
return "nnpa";
case pai_type_max:
break;
}
return "unknown";
}
/* Convert PAI counter type to sysfs directory name. Only validated
* input at this time.
*/
static const char *pai_type_sysfs(enum pai_types t)
{
if (t == pai_type_crypto)
return "pai_crypto";
return "pai_ext";
}
/* Convert PAI counter type to sysfs directory name filter for scandir(). */
static const char *pai_type_filter(enum pai_types t)
{
if (t == pai_type_nnpa)
return "^NNPA";
return "[^.]"; /* Matches anything but . and .. in sysfs */
}
/* Sort PAI counter names by assigned counter number. */
static int pai_ctrcmp(const void *p1, const void *p2)
{
struct pai_ctrname *l = (struct pai_ctrname *)p1;
struct pai_ctrname *r = (struct pai_ctrname *)p2;
return l->nr > r->nr ? 1 : -1;
}
/* Convert string to upper case. */
static char *str2uc(const char *s)
{
char *uc = util_strdup(s), *old_uc = uc;
for (; *uc; ++uc)
*uc = toupper(*uc);
return old_uc;
}
/* Read counter names and assigned event number from sysfs file tree.
* Exit when sysfs directory can not be scanned.
*/
static void read_counternames(struct pai_node *node)
{
int i, more = 0, ctr = 0, count = 0;
struct dirent **namelist = NULL;
char *path, *ctrpath;
/* Read counter names and assigned event number. */
path = util_path_sysfs(PAI_PATH "/events", node->sysfs_name);
count = util_scandir(&namelist, alphasort, path, node->filter_name);
if (count <= 0)
errx(EXIT_FAILURE, "Cannot open %s", path);
node->ctrsize = count * sizeof(*node->ctrlist);
node->ctrlist = util_malloc(node->ctrsize);
for (i = 0; i < count && ctr >= 0; i++) {
util_asprintf(&ctrpath, "%s/%s", path, namelist[i]->d_name);
if (util_file_read_va(ctrpath, "event=%x", &ctr) == 1) {
node->ctrlist[node->ctridx].name = util_strdup(namelist[i]->d_name);
node->ctrlist[node->ctridx++].nr = ctr;
more++;
} else {
warnx("Cannot parse %s", ctrpath);
}
free(ctrpath);
}
util_scandir_free(namelist, count);
free(path);
if (numsort && more > 1)
qsort(node->ctrlist, more, sizeof(*node->ctrlist), pai_ctrcmp);
}
static void show_painode(void)
{
struct pai_node *node;
int indent = 0;
int offset = 0;
util_list_iterate(&pai_list, node) {
for (int i = 0; i < node->ctridx; ++i)
indent = MAX((size_t)indent, strlen(node->ctrlist[i].name));
}
printf("RAW %*s NAME %*s DESCRIPTION\n", 3, "", indent - 5, "");
util_list_iterate(&pai_list, node) {
for (int i = 0; i < node->ctridx; ++i) {
printf("%d:%ld %s", node->pmu,
node->ctrlist[i].nr, node->ctrlist[i].name);
offset = indent - strlen(node->ctrlist[i].name) + 1;
printf("%*s", offset, "");
printf("Counter %ld / PAI %s counter set\n",
node->ctrlist[i].nr - node->base, node->name_uc);
}
}
}
/* Release all memory allocated at make_painode(). */
static void free_painode(void)
{
struct pai_node *next, *node;
util_list_iterate_safe(&pai_list, node, next) {
free(node->name_uc);
for (int i = 0; i < node->ctridx; ++i)
free(node->ctrlist[i].name);
free(node->ctrlist);
free(node);
}
}
static void make_painode(enum pai_types t)
{
struct pai_node *node = util_zalloc(sizeof(*node));
char *path;
node->type = t;
node->sysfs_name = pai_type_sysfs(t);
node->name = pai_type_name(t);
node->name_uc = str2uc(node->name);
node->filter_name = pai_type_filter(t);
node->base = pai_type_base(t);
/* Read PMU type number. */
path = util_path_sysfs(PAI_PATH, node->sysfs_name);
node->pmu = libcpumf_pmutype(path);
if (node->pmu < 0)
errx(EXIT_FAILURE, "Cannot open %s", path);
free(path);
read_counternames(node);
util_list_add_tail(&pai_list, node);
}
static int painode_cmp(void *a, void *b, void *UNUSED(data))
{
struct pai_node *n1 = (struct pai_node *)a;
struct pai_node *n2 = (struct pai_node *)b;
return n1->pmu < n2->pmu ? -1 : 1;
}
static void sort_painode(void)
{
util_list_sort(&pai_list, painode_cmp, NULL);
}
/* Check for hardware support and return false if not available. */
static bool have_support(enum pai_types t)
{
const char *sysfn = pai_type_sysfs(t);
char *path = util_path_sysfs(PAI_PATH, sysfn);
bool rc = true;
if (!util_path_is_dir(path)) {
warnx("No support for PAI %s facility", pai_type_name(t));
rc = false;
}
free(path);
return rc;
}
/*
* Check the argument for option -t. It must be a valid PAI counter set.
* Exit when an invalid PAI counter set name has been specified.
*/
static void check_type_name(const char *type)
{
bool no_match = true;
enum pai_types i;
const char *fn;
for (i = pai_type_crypto; i < pai_type_max; ++i) {
fn = pai_type_name(i);
if (!strcasecmp(fn, type)) {
pai_types_show |= (1 << i);
no_match = false;
}
}
if (no_match)
errx(EXIT_FAILURE, "Invalid argument for -t %s", type);
}
int main(int argc, char **argv)
{
int ch;
util_list_init(&pai_list, struct pai_node, node);
util_prg_init(&prg);
util_opt_init(opt_vec, NULL);
while ((ch = util_opt_getopt_long(argc, argv)) != -1) {
switch (ch) {
default:
util_opt_print_parse_error(ch, argv);
return EXIT_FAILURE;
case 'h':
util_prg_print_help();
util_opt_print_help();
return EXIT_SUCCESS;
case 'v':
util_prg_print_version();
return EXIT_SUCCESS;
case 'n':
numsort = true;
break;
case 't':
check_type_name(optarg);
break;
}
}
/* Nothing specified, show all PAI counters */
if (!pai_types_show)
pai_types_show = (1 << pai_type_crypto) | (1 << pai_type_nnpa);
/* Check for hardware support */
for (enum pai_types i = pai_type_crypto; i < pai_type_max; ++i) {
if ((pai_types_show & (1 << i))) {
if (!have_support(i))
pai_types_show &= ~(1 << i);
else
make_painode(i);
}
}
sort_painode();
show_painode();
free_painode();
return ch;
}

80
cpumf/man/lspai.8 Normal file
View File

@@ -0,0 +1,80 @@
.\" lspai.8
.\"
.\"
.\" Copyright IBM Corp. 2021
.\" s390-tools is free software; you can redistribute it and/or modify
.\" it under the terms of the MIT license. See LICENSE for details.
.\" ----------------------------------------------------------------------
.ds c \fBlspai\fP
.
.TH \*c "8" "August 2023" "s390-tools" "CPU-MF management programs"
.
.SH NAME
\*c \- list Processor Activity Instrumentation (PAI) counters
.
.SH SYNOPSIS
\*c
.RB [ \-n ]
.RB [ \-t
.IR "\ TYPE" ]
.br
\*c
.BR \-h | \-\-help
.br
\*c
.BR \-v | \-\-version
.
.
.SH DESCRIPTION
\*c displays the Processor Activity Instrumentation (PAI) counters
for Linux on IBM Z.
The output is a human-readable list of available PAI counter
names and numbers.
.SH OPTIONS
.TP
.BR \-h ", " \-\-help
Displays help information, then exits.
.
.TP
.BR \-v ", " \-\-version
Displays version information, then exits.
.
.TP
.BR \-t ", " \-\-type "\ TYPE"
Specifies the PAI counter set to list.
Valid counter set values are
.I crypto
and
.IR nnpa .
By default, the command lists all available PAI counter sets.
NNPA refers to the Neural Network Processing Assist facility counter set.
Crypto refers to the Cryptografic Processing Assist facility counter set.
.
.TP
.BR \-n ", " \-\-numeric
Shows the PAI counter sets sorted by counter number.
Default sort order is PAI counter name.
.
.SH "EXAMPLE"
The \*c invocation lists all PAI Neural Network Processing Assist Facility
(NNPA) counters in numeric order:
.nf
# lspai -t nnpa -n
RAW NAME DESCRIPTION
13:6144 NNPA_ALL Counter 0 / PAI NNPA counter set
13:6145 NNPA_ADD Counter 1 / PAI NNPA counter set
13:6146 NNPA_SUB Counter 2 / PAI NNPA counter set
13:6147 NNPA_MUL Counter 3 / PAI NNPA counter set
\&...
.fi
The first column shows the raw event number suitable for
.IR perf "(8)"
raw event specification.
The second column shows the PAI NNPA counter name,
suitable for
.IR perf "(8)"
event specification by name.
The third gives a short explanation, if available.
.SH "SEE ALSO"
.BR pai (8)
.BR lscpumf (8)

View File

@@ -18,6 +18,8 @@
.IR size ]
.RB [ \-i | \-\-interval
.IR ms ]
.RB [ \-R | \-\-realtime
.IR prio ]
.BR \-c | \-\-crypto [ \fIcpulist ][: \fIdata\fR "] [" \fIloops\fP ]
.br
\*c
@@ -25,6 +27,8 @@
.IR size ]
.RB [ \-i | \-\-interval
.IR ms ]
.RB [ \-R | \-\-realtime
.IR prio ]
.BR \-n | \-\-nnpa [ \fIcpulist ][: \fIdata\fR "] [" \fIloops\fP ]
.br
\*c
@@ -191,6 +195,14 @@ The ring buffer is created with the
.IR mmap (2)
system call.
.
.TP
.BR \-R ", " \-\-realtime "\ prio"
Collect data using the RT SCHED_FIFO priority specified by
.BR prio .
Valid values are integers in the range 1 (low) to 99 (high).
Use this option when gathering data from multiple CPUs
to prevent data loss.
.
.SH ARGUMENT
The command line options determine how command line
arguments are interpreted.

View File

@@ -320,7 +320,7 @@ static void readmap(int fd)
* ring buffer per event, sleep some short time and always read all
* ring buffer for new contents.
*/
static void collect(unsigned long cnt)
static int collect(unsigned long cnt)
{
fd_set r_fds, e_fds, a_fds;
struct pai_event *p;
@@ -328,6 +328,7 @@ static void collect(unsigned long cnt)
int rc, max_fd;
do {
rc = -1;
max_fd = -1;
tv.tv_sec = read_interval / 1000;
tv.tv_usec = (1000 * read_interval) % 1000000;
@@ -357,6 +358,7 @@ static void collect(unsigned long cnt)
}
}
} while (rc != -1 && --cnt > 0);
return rc;
}
static void lookup_event(__u64 evtnum, __u16 ctr, __u64 value)
@@ -449,6 +451,11 @@ static void evt_show(__u64 evtnum, const char *evtsel, struct pai_event_out *ev)
ev->u.s_comm.tid);
break;
case PERF_RECORD_SWITCH:
printf("cs-%s",
(ev->misc & PERF_RECORD_MISC_SWITCH_OUT) ? "out" : "in");
break;
case PERF_RECORD_SWITCH_CPU_WIDE:
if (ev->misc & PERF_RECORD_MISC_SWITCH_OUT) {
short p = PERF_RECORD_MISC_SWITCH_OUT_PREEMPT;
@@ -549,6 +556,9 @@ static int evt_scan(char *fn, unsigned char *buf, size_t len,
offset -= sizeof(__u64);
break;
case PERF_RECORD_SWITCH:
break;
case PERF_RECORD_SWITCH_CPU_WIDE:
memcpy(&ev.u, buf + offset, sizeof(ev.u.s_cs));
offset += sizeof(ev.u.s_cs);
@@ -583,7 +593,7 @@ static int evt_scan(char *fn, unsigned char *buf, size_t len,
break;
default:
printf("unknown header-type %d ", hdr->type);
printf("unknown header-type %d\n", hdr->type);
offset += hdr->size - sizeof(*hdr);
goto bypass;
}
@@ -944,6 +954,11 @@ static struct util_opt opt_vec[] = {
.option = { "report", no_argument, NULL, 'r' },
.desc = "Report file contents"
},
{
.option = { "realtime", required_argument, NULL, 'R' },
.argument = "PRIO",
.desc = "Collect data with this RT SCHED_FIFO priority"
},
{
.option = { "interval", required_argument, NULL, 'i' },
.argument = "NUMBER",
@@ -1007,6 +1022,19 @@ static unsigned long check_mapsize(unsigned long n)
return cnt == 1 ? n : 0;
}
static void setprio(const char *prio)
{
struct sched_param param;
char *endstr;
memset(&param, 0, sizeof(param));
param.sched_priority = strtoul(prio, &endstr, 0);
if (*endstr)
errno = EINVAL;
if (*endstr || sched_setscheduler(0, SCHED_FIFO, &param))
err(EXIT_FAILURE, "Could not set realtime priority");
}
int main(int argc, char **argv)
{
bool crypto_record = false, report = false;
@@ -1061,6 +1089,9 @@ int main(int argc, char **argv)
record_cpus_nnpa(optarg);
nnpa_record = true;
break;
case 'R':
setprio(optarg);
break;
case 'r':
report = true;
break;
@@ -1094,12 +1125,12 @@ int main(int argc, char **argv)
ev_install(group);
ev_enable();
collect(loop_count);
ch = collect(loop_count);
ev_disable();
ev_deinstall();
ev_dealloc();
return EXIT_SUCCESS;
return ch < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
/* Must be reporting */

View File

@@ -25,7 +25,7 @@ int get_numcpus()
for (i = 0; ; i++) {
/* check whether file exists and is readable */
sprintf(path, "/sys/devices/system/cpu/cpu%d/online", i);
sprintf(path, "/sys/devices/system/cpu/cpu%d", i);
if (access(path, R_OK) == 0)
number++;
else
@@ -45,11 +45,13 @@ int get_num_online_cpus()
int status = 0;
int value_of_onlinefile, rc;
for (i = 0; i <= get_numcpus(); i++) {
for (i = 0; i < get_numcpus(); i++) {
/* check wether file exists and is readable */
sprintf(path, "/sys/devices/system/cpu/cpu%d/online", i);
if (access(path, R_OK) != 0)
if (access(path, R_OK) != 0) {
status++;
continue;
}
filp = fopen(path, "r");
if (!filp)
cpuplugd_exit("Cannot open cpu online file: "
@@ -101,10 +103,8 @@ int hotplug(int cpuid)
cpuid);
return -1;
}
} else {
cpuplugd_error("hotplugging cpu with id %d failed\n", cpuid);
return -1;
}
cpuplugd_debug("cpu with id %d cannot be hotplugged\n", cpuid);
return -1;
}
@@ -135,9 +135,8 @@ int hotunplug(int cpuid)
fclose(filp);
if (state == 0)
return 1;
} else {
cpuplugd_error("unplugging cpu with id %d failed\n", cpuid);
}
cpuplugd_debug("cpu with id %d cannot be hotunplugged\n", cpuid);
return retval;
}
@@ -163,6 +162,8 @@ int is_online(int cpuid)
retval = 0;
}
fclose(filp);
} else {
retval = 1;
}
return retval;
}

View File

@@ -7,45 +7,45 @@
dasdfmt \- formatting of DASD (ECKD) disk drives.
.SH SYNOPSIS
\fBdasdfmt\fR [-h] [-t] [-v] [-y] [-p] [-P] [-m \fIstep\fR]
\fBdasdfmt\fR [\-h] [\-t] [\-v] [\-y] [\-p] [\-P] [\-m \fIstep\fR]
.br
[-r \fIcylinder\fR] [-b \fIblksize\fR] [-l \fIvolser\fR] [-d \fIlayout\fR]
[\-r \fIcylinder\fR] [\-b \fIblksize\fR] [\-l \fIvolser\fR] [\-d \fIlayout\fR]
.br
[-L] [-V] [-F] [-k] [-C] [-M \fImode\fR] \fIdevice\fR
[\-L] [\-V] [\-F] [\-k] [\-C] [\-M \fImode\fR] \fIdevice\fR
.SH DESCRIPTION
\fBdasdfmt\fR formats a DASD (ECKD) disk drive to prepare it
for usage with Linux for S/390.
for usage with Linux for S/390.
The \fIdevice\fR is the node of the device (e.g. '/dev/dasda').
Any device node created by udev for kernel 2.6 can be used
Any device node created by udev for kernel 2.6 can be used
(e.g. '/dev/dasd/0.0.b100/disc').
.br
\fBWARNING\fR: Careless usage of \fBdasdfmt\fR can result in
\fBWARNING\fR: Careless usage of \fBdasdfmt\fR can result in
\fBLOSS OF DATA\fR.
.SH OPTIONS
.TP
\fB-h\fR or \fB--help\fR
\fB\-h\fR or \fB\-\-help\fR
Print usage and exit.
.TP
\fB-t\fR or \fB--test\fR
Disables any modification of the disk drive.
\fB\-t\fR or \fB\-\-test\fR
Disables any modification of the disk drive.
.br
\fBdasdfmt\fR just prints
out, what it \fBwould\fR do.
.TP
\fB-v\fR
\fB\-v\fR
Increases verbosity.
.TP
\fB-y\fR
\fB\-y\fR
Start formatting without further user-confirmation.
.TP
\fB--norecordzero\fR
\fB\-\-norecordzero\fR
Remove permission for subsystem to format write record zero.
.br
This is an expert option: Per default in recent dasd drivers, subsystems are
@@ -54,80 +54,80 @@ to remove this permission.
.br
.TP
\fB-L\fR or \fB--no_label\fR
\fB\-L\fR or \fB\-\-no_label\fR
Omit the writing of a disk label after formatting.
.br
This makes only sense for the 'ldl' disk layout.
.br
The '-L' option has to be specified after the '-d ldl' option.
The '\-L' option has to be specified after the '\-d ldl' option.
.br
e.g. dasdfmt -d ldl -L /dev/...
e.g. dasdfmt \-d ldl \-L /dev/...
.TP
\fB-V\fR or \fB--version\fR
\fB\-V\fR or \fB\-\-version\fR
Print version number and exit.
.TP
\fB-F\fR or \fB--force\fR
\fB\-F\fR or \fB\-\-force\fR
Formats the device without performing sanity checking.
.TP
\fB-C\fR or \fB--check_host_count\fR
\fB\-C\fR or \fB\-\-check_host_count\fR
Force dasdfmt to check the host access open count to ensure the device
is not online on another operating system instance
.TP
\fB-d\fR \fIlayout\fR or \fB--disk_layout\fR=\fIlayout\fR
\fB\-d\fR \fIlayout\fR or \fB\-\-disk_layout\fR=\fIlayout\fR
Formats the device with compatible disk layout or linux disk layout.
\fIlayout\fR is either \fIcdl\fR for the compatible disk layout
(default) or \fIldl\fR for the linux disk layout.
.br
Compatible disk layout means a special handling of the
first two tracks of the volume. This enables other S/390 or zSeries
Compatible disk layout means a special handling of the
first two tracks of the volume. This enables other S/390 or zSeries
operating systems to access this device (e.g. for backup purposes).
.TP
\fB-p\fR or \fB--progressbar\fR
Print a progress bar while formatting.
Print a progress bar while formatting.
Do not use this option if you are using a 3270 console,
running in background or redirecting the output to a file.
.TP
\fB-P\fR or \fB--percentage\fR
\fB\-P\fR or \fB\-\-percentage\fR
Print one line for each formatted cylinder showing the number of the
cylinder and percentage of formatting process.
Intended to be used by higher level interfaces.
.TP
\fB-m\fR \fIstep\fR or \fB--hashmarks\fR=\fIstep\fR
\fB\-m\fR \fIstep\fR or \fB\-\-hashmarks\fR=\fIstep\fR
Print a hashmark every \fIstep\fR cylinders. The value \fIstep\fR has to be within range [1,1000], otherwise it will be set to the default, which is 10.
.br
You can use this option to see the progress of formatting in case you
are not able to use the progress bar option -p, e.g. with a 3270
are not able to use the progress bar option \-p, e.g. with a 3270
terminal.
.br
The value will be at least as big as the -r or --requestsize value.
The value will be at least as big as the \-r or \-\-requestsize value.
.br
.TP
\fB-M\fR \fImode\fR or \fB--mode\fR=\fImode\fR
\fB\-M\fR \fImode\fR or \fB\-\-mode\fR=\fImode\fR
Specify the \fImode\fR to be used to format the device. Valid modes are:
.RS
.IP full
Format the entire disk with the specified blocksize. (default)
.IP quick
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).
Format the first two tracks and write label and partition information.
.br
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.
Use this option for DASD ESE volumes to take the benefits of thin provisioning.
In this case, a full space release precedes the formatting step. If this space
release fails, then the formatting also fails. Specify the \fB\-\-no\-discard\fR
option to omit the space release.
.br
For non-ESE volumes 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).
.IP expand
Format all unformatted tracks at the end of the target DASD. This mode assumes
@@ -135,20 +135,20 @@ that tracks at the beginning of the DASD volume have already been correctly
formatted, while a consecutive set of tracks at the end are unformatted. You can
use this mode to make added space available for Linux use after dynamically
increasing the size of a DASD volume. A blocksize can optionally be specified
using \fB-b\fR (\fB--blocksize\fR).
using \fB\-b\fR (\fB\-\-blocksize\fR).
.RE
.TP
\fB--check\fR
\fB\-\-check\fR
Perform a complete format check on a DASD volume. A blocksize can be specified
with \fB-b\fR (\fB--blocksize\fR).
with \fB\-b\fR (\fB\-\-blocksize\fR).
.TP
\fB--no-discard\fR
\fB\-\-no\-discard\fR
Omit a full space release when formatting a thin-provisioned DASD ESE volume.
.TP
\fB-r\fR \fIcylindercount\fR or \fB--requestsize\fR=\fIcylindercount\fR
\fB\-r\fR \fIcylindercount\fR or \fB\-\-requestsize\fR=\fIcylindercount\fR
Number of cylinders to be processed in one formatting step.
The value must be an integer in the range 1 - 255.
.br
@@ -158,48 +158,47 @@ devices, counting the base device and all alias devices.
.br
.TP
\fB-b\fR \fIblksize\fR or \fB--blocksize\fR=\fIblksize\fR
\fB\-b\fR \fIblksize\fR or \fB\-\-blocksize\fR=\fIblksize\fR
Specify blocksize to be used. \fIblksize\fR must be a positive integer
and always be a power of two. The recommended blocksize is 4096 bytes.
.TP
\fB-l\fR \fIvolser\fR or \fB--label\fR=\fIvolser\fR
Specify the volume serial number or volume identifier to be written
to disk after formatting. If no label is specified, a sensible default
is used. \fIvolser\fR is interpreted as ASCII string and is automatically
\fB\-l\fR \fIvolser\fR or \fB\-\-label\fR=\fIvolser\fR
Specify the volume serial number or volume identifier to be written
to disk after formatting. If no label is specified, a sensible default
is used. \fIvolser\fR is interpreted as ASCII string and is automatically
converted to uppercase and then to EBCDIC.
.br
e.g. -l LNX001 or --label=DASD01
e.g. \-l LNX001 or \-\-label=DASD01
.br
The \fIvolser\fR identifies by serial number the volume. A volume serial
The \fIvolser\fR identifies by serial number the volume. A volume serial
number is 1 through 6 alphanumeric or one of the following special
characters: $, #, @, %. Enclose a serial number that contains special
characters in apostrophes. If the number is shorter than six
characters: $, #, @, %. Enclose a serial number that contains special
characters in apostrophes. If the number is shorter than six
characters, it is padded with trailing blanks.
.br
.br
Do not code a volume serial number as SCRTCH, PRIVAT, or Lnnnnn (L with
five numbers); these are used in OS/390 messages to ask the operator to
mount a volume. Do not code a volume serial number as MIGRAT, which is
used by the OS/390 Hierarchical Storage Manager DFSMShsm for migrated
Do not code a volume serial number as SCRTCH, PRIVAT, or Lnnnnn (L with
five numbers); these are used in OS/390 messages to ask the operator to
mount a volume. Do not code a volume serial number as MIGRAT, which is
used by the OS/390 Hierarchical Storage Manager DFSMShsm for migrated
data sets.
.br
NOTE: Try to avoid using special characters in the volume serial. This may cause problems accessing a disk by volser.
NOTE: Try to avoid using special characters in the volume serial. This may cause problems accessing a disk by volser.
.br
In case you really have to use special characters, make sure you are using quotes. In addition there is a special handling for the '$' sign. Please specify it using '\\$' if necessary.
.br
e.g. -l 'a@b\\$c#' to get A@B$C#
e.g. \-l 'a@b\\$c#' to get A@B$C#
.br
.TP
\fB-k\fR or \fB--keep_volser\fR
Keeps the Volume Serial Number, when writing the Volume Label. This is
useful, if the Serial Number has been written with a VM Tool and should not
be overwritten.
\fB\-k\fR or \fB\-\-keep_volser\fR
Keeps the Volume Serial Number when writing the Volume Label. This is useful if
the volume already has a Serial Number that should not be overwritten.
.br
.SH SEE ALSO

View File

@@ -1230,7 +1230,7 @@ static void dasdfmt_find_start(unsigned int cylinders, unsigned int heads,
format_params->start_unit = first;
}
static int dasdfmt_release_space(void)
static void dasdfmt_release_space(void)
{
format_data_t r = {
.start_unit = 0,
@@ -1240,21 +1240,12 @@ static int dasdfmt_release_space(void)
int err = 0;
if (!g.ese || g.no_discard)
return 0;
return;
printf("Releasing space for the entire device...\n");
err = dasd_release_space(g.dev_node, &r);
/*
* 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) {
if (err)
error("Could not release space: %s", strerror(err));
}
return 0;
}
static void dasdfmt_prepare_and_format(unsigned int cylinders, unsigned int heads,
@@ -1454,12 +1445,8 @@ static void do_format_dasd(volume_label_t *vlabel, format_data_t *p,
dasdfmt_prepare_and_format(cylinders, heads, p);
break;
case QUICK:
if (dasdfmt_release_space()) {
p->stop_unit = (cylinders * heads) - 1;
dasdfmt_prepare_and_format(cylinders, heads, p);
} else {
dasdfmt_quick_format(cylinders, heads, p);
}
dasdfmt_release_space();
dasdfmt_quick_format(cylinders, heads, p);
break;
case EXPAND:
dasdfmt_expand_format(cylinders, heads, p);
@@ -1491,7 +1478,7 @@ static void eval_format_mode(void)
}
if (!g.mode_specified)
mode = g.ese ? QUICK : FULL;
mode = FULL;
}
/*

View File

@@ -7,28 +7,28 @@
.B "dasdinfo "
\- tool to read unique id from s390 DASD device
.SH SYNOPSIS
.BI "dasdinfo [-a] [-l] [-u] [-x] [-e] {-i " <busid>
.BI "| -b " <blockdev>
.BI " | -d " <devnode>
.BI "dasdinfo [\-a] [\-l] [\-u] [\-x] [\-e] {\-i " <busid>
.BI "| \-b " <blockdev>
.BI " | \-d " <devnode>
.BI "}"
.sp
.BI "dasdinfo [-h] [-v]"
.BI "dasdinfo [\-h] [\-v]"
.SH DESCRIPTION
.B dasdinfo
.B dasdinfo
displays specific information about a specified DASD device.
It is normally called from a udev rule, to provide udev with a unique id string and
additional information (type, serial) for an S390 DASD drive. Udev can use this
information to create symlinks in /dev/disk/by-id and /dev/disk/by-label
information to create symlinks in /dev/disk/by\-id and /dev/disk/by\-label
to the real device node.
.SH OPTIONS
.TP
.BI "-a|--all"
.BI "\-a|\-\-all"
Same as -u -x -l
.TP
.BI "-x|--extended-uid"
.BI "\-x|\-\-extended\-uid"
Print DASD uid
This option prints the full uid of the DASD. When z/VM provides two
@@ -42,13 +42,13 @@ For z/VM: VM support for the hypervisor injected Special Node Element
Qualifier (SNEQ) (or hypervisor injected self-description data) is
available by applying the PTFs for VM APAR VM64273 on z/VM 5.2.0 and higher.
.TP
.BI "-u|--uid"
.BI "\-u|\-\-uid"
Print DASD uid without z/VM minidisk token
z/VM may provide an additional token that can be used to distinguish
between different minidisks (see --extended-uid option). To remain
between different minidisks (see \-\-extended\-uid option). To remain
compatible with systems that were installed on older Linux or z/VM
levels, the -u option will print the uid excluding any z/VM-provided
levels, the \-u option will print the uid excluding any z/VM-provided
minidisk token.
For example, if the extended uid is
@@ -57,35 +57,35 @@ uid is IBM.75000000092461.e900.10. If the extended uid contains no
minidisk token, e.g. in an LPAR environment, then both uids are the
same.
.TP
.BI "-l|--label"
.BI "\-l|\-\-label"
Print DASD volume label (volser).
.TP
.BI "-i|--busid " <busid>
.BI "\-i|\-\-busid " <busid>
Use the bus ID as input parameter, e.g. 0.0.e910.
.TP
.BI "-b|--block " <blockdev>
.BI "\-b|\-\-block " <blockdev>
Use the block device name as input parameter, e.g. dasdb.
.TP
.BI "-d|--devnode " <devnode>
.BI "\-d|\-\-devnode " <devnode>
Use a device node as input parameter, e.g. /dev/dasdb.
.TP
.BI "-e|--export"
.BI "\-e|\-\-export"
Print all values (ID_BUS, ID_TYPE, ID_SERIAL).
.TP
.BI "-h|--help"
.BI "\-h|\-\-help"
Print usage text.
.TP
.BI "-v|--version"
.BI "\-v|\-\-version"
Print version number.
.SH EXAMPLES
dasdinfo -u -i 0.0.e910
dasdinfo \-u \-i 0.0.e910
dasdinfo -u -b dasdb
dasdinfo \-u \-b dasdb
dasdinfo -u -d /dev/dasdb
dasdinfo \-u \-d /dev/dasdb
All three examples should return the same unique ID for
All three examples should return the same unique ID for
the same DASD device, e.g. IBM.75000000092461.e900.10.
In case this uid is not available, dasdinfo will return

View File

@@ -7,21 +7,21 @@
dasdview \- Display DASD and VTOC information and dump the content of a DASD
to the console.
.SH SYNOPSIS
\fBdasdview\fR [-h] [-v]
\fBdasdview\fR [\-h] [\-v]
.br
[-b \fIbegin\fR] [-s \fIsize\fR] [-1|-2]
[\-b \fIbegin\fR] [\-s \fIsize\fR] [\-1|\-2]
.br
[-i] [-x] [-j] [-c]
[\-i] [\-x] [\-j] [\-c]
.br
[-l] [-t {\fIinfo\fR|\fIf1\fR|\fIf3\fR|\fIf4\fR|\fIf5\fR|\fIf7\fR|\fIf8\fR|\fIf9\fR}]
[\-l] [\-t {\fIinfo\fR|\fIf1\fR|\fIf3\fR|\fIf4\fR|\fIf5\fR|\fIf7\fR|\fIf8\fR|\fIf9\fR}]
.br
\fIdevice\fR
.SH DESCRIPTION
\fBdasdview\fR prints you some useful information of your disks to the console.
You can display a disk dump by specifying start point and offset and you can
You can display a disk dump by specifying start point and offset and you can
print the volume label and VTOC entries.
The \fIdevice\fR is the node of the device (e.g. '/dev/dasda').
Any device node created by udev for kernel 2.6 can be used
Any device node created by udev for kernel 2.6 can be used
(e.g. '/dev/dasd/0.0.b100/disc').
DASD devices in raw_track_access mode are supported and detected
@@ -29,30 +29,30 @@ automatically. When in raw_track_access mode, the same basic
functions are available as in the regular mode, but the output may
have a slightly different layout:
.IP \(bu 2
The disk dump functions (\fB-b\fR and \fB-s\fR) print the count,
The disk dump functions (\fB\-b\fR and \fB\-s\fR) print the count,
key and data information for the whole track, and not just the
contents of the data areas.
.IP \(bu 2
The VTOC listing (\fB-t\fR) print all specified DSCBs in the same
The VTOC listing (\fB\-t\fR) print all specified DSCBs in the same
format as in the regular mode, but in the sequence as they appear in
the VTOC. The \fB-t info\fR overview contains more details for each
the VTOC. The \fB\-t info\fR overview contains more details for each
data set than in the regular mode, to support the larger variety of
data set layouts.
.SH OPTIONS
.TP
\fB-h\fR or \fB--help\fR
\fB\-h\fR or \fB\-\-help\fR
Print usage and exit.
.TP
\fB-v\fR or \fB--version\fR
\fB\-v\fR or \fB\-\-version\fR
Print version number and exit.
.TP
\fB-b\fR \fIbegin\fR or \fB--begin=\fR\fIbegin\fR
Print a disk dump to the console, starting with \fIbegin\fR. The content of
the disk will be displayed in hexadecimal numbers, ASCII text and EBCDIC text.
If no size is specified dasdview will take the default size. The variable
\fB\-b\fR \fIbegin\fR or \fB\-\-begin=\fR\fIbegin\fR
Print a disk dump to the console, starting with \fIbegin\fR. The content of
the disk will be displayed in hexadecimal numbers, ASCII text and EBCDIC text.
If no size is specified dasdview will take the default size. The variable
\fIbegin\fR can be specified in one of the following ways:
.br
@@ -63,10 +63,10 @@ The default for \fIbegin\fR is \fI0\fR.
.br
\fBNote 1:\fR dasdview will show you the content of your disk using the DASD
driver. If this driver decides to hide or add some parts of the disk, you have
to live with it. This happens for example with the first two tracks of a
cdl-formatted disk. In this case the DASD driver fills up shorter blocks with
zeros to have a constant blocksize. And all applications, including dasdview,
driver. If this driver decides to hide or add some parts of the disk, you have
to live with it. This happens for example with the first two tracks of a
cdl-formatted disk. In this case the DASD driver fills up shorter blocks with
zeros to have a constant blocksize. And all applications, including dasdview,
believe it.
.br
\fBNote 2:\fR In raw_track_access mode \fIbegin\fR must be aligned to
@@ -76,24 +76,24 @@ cylinder as starting point.
examples:
.br
-b 32 --> start printing at Byte 32
\-b 32 --> start printing at Byte 32
.br
-b 32k --> start printing at kByte 32
\-b 32k --> start printing at kByte 32
.br
-b 32m --> start printing at MByte 32
\-b 32m --> start printing at MByte 32
.br
-b 32b --> start printing at block 32
\-b 32b --> start printing at block 32
.br
-b 32t --> start printing at track 32
\-b 32t --> start printing at track 32
.br
-b 32c --> start printing at cylinder 32
\-b 32c --> start printing at cylinder 32
.TP
\fB-s\fR \fIsize\fR or \fB--size=\fR\fIsize\fR
Print a disk dump to the console, starting with \fIbegin\fR, specified with
the \fB-b\fR option and size \fIsize\fR. The content of the disk will be
displayed in hexadecimal numbers, ASCII text and EBCDIC text. If no start
value is specified dasdview will take the default start value. The variable
\fB\-s\fR \fIsize\fR or \fB\-\-size=\fR\fIsize\fR
Print a disk dump to the console, starting with \fIbegin\fR, specified with
the \fB\-b\fR option and size \fIsize\fR. The content of the disk will be
displayed in hexadecimal numbers, ASCII text and EBCDIC text. If no start
value is specified dasdview will take the default start value. The variable
\fIsize\fR can be specified in one of the following ways:
.br
@@ -111,76 +111,76 @@ in raw_track_access mode.
examples:
.br
-s 16 --> use a 16 Byte size
\-s 16 --> use a 16 Byte size
.br
-s 16k --> use a 16 kByte size
\-s 16k --> use a 16 kByte size
.br
-s 16m --> use a 16 MByte size
\-s 16m --> use a 16 MByte size
.br
-s 16b --> use a 16 block size
\-s 16b --> use a 16 block size
.br
-s 16t --> use a 16 track size
\-s 16t --> use a 16 track size
.br
-s 16c --> use a 16 cylinder size
\-s 16c --> use a 16 cylinder size
.TP
\fB-1\fR
This option tells dasdview to print the disk dump using format 1. This means
you will get 16 Bytes per line in hex, ascii and ebcdic. There is no line
\fB\-1\fR
This option tells dasdview to print the disk dump using format 1. This means
you will get 16 Bytes per line in hex, ascii and ebcdic. There is no line
number.
.br
The \fB-1\fR option makes only sense with the \fB-b\fR and/or the \fB-s\fR
options.
The \fB\-1\fR option makes only sense with the \fB\-b\fR and/or the \fB\-s\fR
options.
.br
This is the default.
.TP
\fB-2\fR
This option tells dasdview to print the disk dump using format 2. This means
you will get 8 Bytes per line in hex, ascii and ebcdic. And in addition a line
\fB\-2\fR
This option tells dasdview to print the disk dump using format 2. This means
you will get 8 Bytes per line in hex, ascii and ebcdic. And in addition a line
number and a decimal and hexadecimal byte count will be printed.
.br
The \fB-2\fR option makes only sense with the \fB-b\fR and/or the \fB-s\fR
The \fB\-2\fR option makes only sense with the \fB\-b\fR and/or the \fB\-s\fR
options. In raw_track_access mode this format is not supported and the
option will be ignored.
.TP
\fB-i\fR or \fB--info\fR
\fB\-i\fR or \fB\-\-info\fR
Print some useful information (e.g. device node/number/type or geometry data).
When running dasdview on a kernel 2.6 based distribution the busid
When running dasdview on a kernel 2.6 based distribution the busid
is printed instead of the device number.
.TP
\fB-x\fR or \fB--extended\fR
\fB\-x\fR or \fB\-\-extended\fR
Print some more DASD information (e.g. open count, subchannel identifier).
.TP
\fB-j\fR or \fB--volser\fR
\fB\-j\fR or \fB\-\-volser\fR
Print volume serial number (volume identifier).
.TP
\fB-l\fR or \fB--label\fR
\fB\-l\fR or \fB\-\-label\fR
Print the volume label.
.TP
\fB-c\fR or \fB--characteristic\fR
\fB\-c\fR or \fB\-\-characteristic\fR
Print some information about the device e.g. if it is encrypted.
.TP
\fB-t\fR \fIspec\fR or \fB--vtoc=\fR\fIspec\fR
\fB\-t\fR \fIspec\fR or \fB\-\-vtoc=\fR\fIspec\fR
Print the VTOC (table of content) or single VTOC entries to the console.
\fIspec\fR can be one of the following strings:
.br
\fIinfo\fR:
\fIinfo\fR:
.br
Gives you a VTOC overview. You will see what other S/390 or zSeries operating
Gives you a VTOC overview. You will see what other S/390 or zSeries operating
systems would see (e.g. data set names and sizes).
.br
\fIf1\fR:
.br
Print the content of all format 1 DSCBs.
Print the content of all format 1 DSCBs.
.br
\fIf3\fR:
@@ -188,17 +188,17 @@ Print the content of all format 1 DSCBs.
Print the content of all format 3 DSCBs.
.br
\fIf4\fR:
\fIf4\fR:
.br
Print the content of the format 4 DSCB.
.br
\fIf5\fR:
\fIf5\fR:
.br
Print the content of the format 5 DSCB.
.br
\fIf7\fR:
\fIf7\fR:
.br
Print the content of the format 7 DSCB.
.br
@@ -213,6 +213,6 @@ Print the content of all format 8 DSCBs.
Print the content of all format 9 DSCBs.
.br
\fIall\fR:
\fIall\fR:
.br
Print the content of all DSCBs.
Print the content of all DSCBs.

View File

@@ -1,7 +1,7 @@
# Common definitions
include ../../common.mak
ALL_CPPFLAGS += -I../include -std=gnu99 -Wno-unused-parameter
ALL_CPPFLAGS += -I../include -Wno-unused-parameter
LDLIBS += -lpthread -lrt
ifneq ($(HAVE_ZLIB),0)
ALL_CPPFLAGS += -DHAVE_ZLIB

View File

@@ -23,9 +23,16 @@
#define BLOCKSIZE 512
#if __has_attribute(nonstring)
# define __nonstring __attribute__ ((nonstring))
#else
# define __nonstring
#endif
/* Basic TAR header */
struct tar_header {
char name[100];
char name[100] __nonstring;
char mode[8];
char uid[8];
char gid[8];
@@ -33,7 +40,7 @@ struct tar_header {
char mtime[12];
char chksum[8];
char typeflag;
char linkname[100];
char linkname[100] __nonstring;
char magic[6];
char version[2];
char uname[32];
@@ -78,7 +85,7 @@ static void set_time(char *dest, size_t len, time_t value)
#define SET_TIME_FIELD(obj, name, value) \
set_time((obj)->name, sizeof((obj)->name), (time_t) (value))
#define SET_STR_FIELD(obj, name, value) \
util_strlcpy((obj)->name, (value), sizeof((obj)->name))
strncpy((obj)->name, (value), sizeof((obj)->name))
/* Initialize the tar file @header with the provided data */
static void init_header(struct tar_header *header, const char *filename,

View File

@@ -28,6 +28,15 @@
# DEVICE=0.0.4e13
# DELAY_MINUTES=5
#
# Dump on ECKD device (DASD)
#
#ON_PANIC=dump
#DUMP_TYPE=eckd
#DEVICE=0.0.1004
#BOOTPROG=0
#BR_CHR=auto
#
# Dump on fcp device (SCSI Disk)
#

View File

@@ -8,21 +8,21 @@ fdasd \- partitioning tool.
.SH SYNOPSIS
interactive mode:
.br
\fBfdasd\fR [-s] [-r] [-C] \fIdevice\fR
\fBfdasd\fR [\-s] [\-r] [\-C] \fIdevice\fR
.br
command line mode:
.br
\fBfdasd\fR [-s] [-r] [-C] {-a[-k|-l \fIvolser\fR]|-i|-p|-c \fIconf_file\fR}
\fBfdasd\fR [\-s] [\-r] [\-C] {\-a[\-k|\-l \fIvolser\fR]|\-i|\-p|\-c \fIconf_file\fR}
[-f \fI[type,blocksize]\fR] \fIdevice\fR
.br
help:
.br
\fBfdasd\fR {-h|-v}
\fBfdasd\fR {\-h|\-v}
.SH DESCRIPTION
\fBfdasd\fR writes a partition table to a cdl (compatible disk layout)
\fBfdasd\fR writes a partition table to a cdl (compatible disk layout)
formatted DASD, in the form of
a VTOC (volume table of contents) for usage with Linux for S/390
or zSeries. If fdasd detects a valid \fBVOL1\fR volume label, it
or zSeries. If fdasd detects a valid \fBVOL1\fR volume label, it
will use it, otherwise it asks to write a new one.
.br
@@ -30,66 +30,66 @@ will use it, otherwise it asks to write a new one.
\fBfdasd\fR can result in loss of data.
.SH OPTIONS
.TP
\fB-h\fR or \fB--help\fR
\fB\-h\fR or \fB\-\-help\fR
Print usage information, then exit.
.TP
\fB-v\fR or \fB--version\fR
\fB\-v\fR or \fB\-\-version\fR
Print version information, then exit.
.TP
\fB-s\fR or \fB--silent\fR
\fB\-s\fR or \fB\-\-silent\fR
Suppress messages in non-interactive mode.
.TP
\fB-r\fR or \fB--verbose\fR
\fB\-r\fR or \fB\-\-verbose\fR
Provide more verbose output.
.TP
\fB-a\fR or \fB--auto\fR
Automatically create a partition using the entire disk in non-interactive
\fB\-a\fR or \fB\-\-auto\fR
Automatically create a partition using the entire disk in non-interactive
mode.
.TP
\fB-k\fR or \fB--keep_volser\fR
Keeps the volume serial when writing the volume label.
\fB\-k\fR or \fB\-\-keep_volser\fR
Keeps the Volume Serial Number when writing the Volume Label.
.br
This is useful, if the volume serial has been written before and should not
be overwritten. This option is only applicable in non-interactive mode.
This is useful if the volume already has a Serial Number that should not be
overwritten. This option is only applicable in non-interactive mode.
.TP
\fB-l\fR \fIvolser\fR or \fB--label\fR \fIvolser\fR
\fB\-l\fR \fIvolser\fR or \fB\-\-label\fR \fIvolser\fR
Specify the volume serial.
.br
\fIvolser\fR is interpreted as ASCII string and is automatically converted to
\fIvolser\fR is interpreted as ASCII string and is automatically converted to
uppercase, padded with blanks and finally converted to EBCDIC to be written
to disk. This option is only applicable in non-interactive mode.
.br
Do not use the following reserved volume serial: SCRTCH, PRIVAT, MIGRAT,
or Lnnnnn (L with five digit number); These are used as keywords by
Do not use the following reserved volume serial: SCRTCH, PRIVAT, MIGRAT,
or Lnnnnn (L with five digit number); These are used as keywords by
other operating systems (OS/390).
.br
A volume serial is 1 through 6 alphanumeric characters or one of the
following special characters: $, #, @, %. All other characters are simply
ignored.
A volume serial is 1 through 6 alphanumeric characters or one of the
following special characters: $, #, @, %. All other characters are simply
ignored.
.br
Try to avoid using special characters in the volume serial.
This may cause problems accessing a disk by volser.
In case you really have to use special characters, make sure you are using
quotes. In addition there is a special handling for the '$' sign.
Try to avoid using special characters in the volume serial.
This may cause problems accessing a disk by volser.
In case you really have to use special characters, make sure you are using
quotes. In addition there is a special handling for the '$' sign.
Please specify it using '\\$' if necessary.
.br
e.g. -l 'a@b\\$c#' to get A@B$C#
e.g. \-l 'a@b\\$c#' to get A@B$C#
.br
Omitting this parameter causes fdasd to ask for it in case it is needed.
.br
.TP
\fB-c\fR \fIconf_file\fR or \fB--config\fR \fIconf_file\fR
\fB\-c\fR \fIconf_file\fR or \fB\-\-config\fR \fIconf_file\fR
Use this option to create multiple partitions according to
specifications in a configuration file, \fIconf_file\fR.
.br
@@ -124,37 +124,37 @@ partitions that use the entire disk:
.br
.TP
\fB-i\fR or \fB--volser\fR
\fB\-i\fR or \fB\-\-volser\fR
Print the volume serial, then exit.
.TP
\fB-p\fR or \fB--table\fR
Print partition table, then exit.
\fB\-p\fR or \fB\-\-table\fR
Print partition table, then exit.
.br
In combination with the -s option fdasd will display a short version of the
In combination with the \-s option fdasd will display a short version of the
partition table.
.TP
\fB-C\fR or \fB--check_host_count\fR
\fB\-C\fR or \fB\-\-check_host_count\fR
Force fdasd to check the host access open count to ensure the device
is not online on another operating system instance
.TP
\fB-f\fR \fI[type,blocksize]\fR or \fB--force\fR \fI[type,blocksize]\fR
\fB\-f\fR \fI[type,blocksize]\fR or \fB\-\-force\fR \fI[type,blocksize]\fR
Force fdasd to work on non DASD devices.
.br
If fdasd is to be used on a block device that is neither a native DASD
nor exposes the proper disk geometry of a DASD of type 3390,
then the --force option can be used to assume the geometry of a
then the \-\-force option can be used to assume the geometry of a
given device type. The default device type is 3390 and the default
block size is 4096. An optional argument of <device type>,<blocksize>
can be used to specify type and blocksize explicitly. For example:
-f
\-f
has the same effect as
-f3390,4096 or --force=3390,4096
\-f3390,4096 or \-\-force=3390,4096
Valid device types are: 3390, 3380, 9345
.br
@@ -179,7 +179,7 @@ In case your are not using the device file system, please specify:
.br
where \fIx\fR is one or more lowercase letter(s) or any other device
node specification configured by udev for kernel 2.6 or higher.
node specification configured by udev for kernel 2.6 or higher.
.SH SEE ALSO
.BR dasdfmt (8)

View File

@@ -3,16 +3,16 @@ include ../common.mak
.DEFAULT_GOAL := all
PKGDATADIR := "$(DESTDIR)$(TOOLS_DATADIR)/genprotimg"
PKGDATADIR := "$(TOOLS_DATADIR)/genprotimg"
TESTS :=
SUBDIRS := boot src man
RECURSIVE_TARGETS := all-recursive install-recursive clean-recursive
all: all-recursive
install: all install-recursive
$(INSTALL) -d -m 755 "$(PKGDATADIR)"
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 755 samples/check_hostkeydoc "$(PKGDATADIR)"
install: install-recursive
$(INSTALL) -d -m 755 "$(DESTDIR)$(PKGDATADIR)"
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 755 samples/check_hostkeydoc "$(DESTDIR)$(PKGDATADIR)"
clean: clean-recursive

View File

@@ -2,11 +2,12 @@
include ../../common.mak
FILES := stage3a.bin stage3b.bin stage3b_reloc.bin
DEBUG_FILES := $(addsuffix .debug,$(FILES))
ifeq ($(HOST_ARCH),s390x)
ZIPL_DIR := $(rootdir)/zipl
ZIPL_BOOT_DIR := $(ZIPL_DIR)/boot
PKGDATADIR := $(DESTDIR)$(TOOLS_DATADIR)/genprotimg
PKGDATADIR := $(TOOLS_DATADIR)/genprotimg
INCLUDE_PATHS := $(ZIPL_BOOT_DIR) $(ZIPL_DIR)/include $(rootdir)/include
INCLUDE_PARMS := $(addprefix -I,$(INCLUDE_PATHS))
@@ -71,25 +72,30 @@ stage3b_reloc.o: stage3b.bin
stage3a.elf: head.o stage3a_init.o $(ZIPL_OBJS)
stage3b.elf: head.o $(ZIPL_OBJS)
.SECONDARY: $(FILES:.bin=.lds)
%.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.debug: %.elf
$(OBJCOPY) --only-keep-debug $< $@
@chmod a-x $@
%.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)"
$(INSTALL) -d -m 755 "$(DESTDIR)$(PKGDATADIR)"
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 644 stage3a.bin "$(DESTDIR)$(PKGDATADIR)"
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 644 stage3b_reloc.bin "$(DESTDIR)$(PKGDATADIR)"
else
# Don't generate the dependency files (see `common.mak` for the
# `-include $(dependencies_c)` statement).
.PHONY: $(dependencies_c)
$(FILES):
$(FILES) $(DEBUG_FILES):
echo " SKIP $@ due to HOST_ARCH != s390x"
install:
@@ -97,9 +103,9 @@ install:
endif
.DEFAULT_GOAL := all
all: $(FILES)
all: $(FILES) $(DEBUG_FILES)
clean:
rm -f *.o *.elf *.bin *.map .*.d *.lds
rm -f -- *.o *.elf *.bin *.map .*.d *.lds *.debug
.PHONY: all clean

View File

@@ -11,9 +11,10 @@
#include "stage3a.h"
#include "lib/zt_common.h"
#include "boot/error.h"
#include "boot/s390.h"
#include "boot/ipl.h"
#include "sclp.h"
#include "error.h"
static volatile struct stage3a_args __section(".loader_parms") loader_parms;

View File

@@ -12,10 +12,11 @@
#include "lib/zt_common.h"
#include "boot/psw.h"
#include "boot/error.h"
#include "boot/s390.h"
#include "boot/linux_layout.h"
#include "boot/loaders_layout.h"
#include "sclp.h"
#include "error.h"
static volatile struct stage3b_args __section(".loader_parms") loader_parms;
@@ -60,13 +61,17 @@ void __noreturn start(void)
if (cmdline->size > get_kernel_cmdline_size())
panic(EINTERNAL, "Command line is too large\n");
/* move the kernel cmdline */
memmove((void *)COMMAND_LINE,
(void *)cmdline->src,
cmdline->size);
if (cmdline->size > 0) {
/* make sure the cmdline is a null-terminated string */
if (((char *)cmdline->src)[cmdline->size - 1] != '\0')
panic(EINTERNAL, "Command line needs to be null-terminated\n");
/* move the kernel cmdline */
memmove((void *)COMMAND_LINE, (void *)cmdline->src, cmdline->size);
}
/* the initrd does not need to be moved */
if (initrd->size != 0) {
if (initrd->size > 0) {
/* copy initrd start address and size into new kernel space */
*(unsigned long long *)INITRD_START = initrd->src;
*(unsigned long long *)INITRD_SIZE = initrd->size;

View File

@@ -97,18 +97,29 @@ Do not use for a production image unless you verified
the host-key document before. Optional.
.TP
\fB\-\-comm\-key\fR=\fI\,FILE\/\fR
Specifies the encryption key you want to use for the PV guest dump. Use a
secure, random, plaintext AES-256 GCM key. Optional.
Specifies the customer communication key (CCK). This key is used for the
PV guest dump encryption and to derive the CCK-derived extension secret
used for add-secret requests. Use a secure, random, plaintext AES-256
GCM key. Optional.
.TP
\fB\-\-enable\-dump\fR
Enable PV guest dumps. Requires the \fB\-\-comm-key\fR option. Optional.
Enable PV guest dumps. Requires the \fB\-\-comm\-key\fR option. Optional.
.TP
\fB\-\-disable\-dump\fR
Disable PV guest dumps. This is the default. Optional.
Disable PV guest dumps. This is the default.
.TP
\fB\-\-enable\-cck\-extension\-secret\fR
Add-secret requests must provide an extension secret that matches the
CCK-derived extension secret. Requires the \fB\-\-comm\-key\fR option.
Optional.
.TP
\fB\-\-disable\-cck\-extension\-secret\fR
Add-secret requests don't have to provide an extension secret. This is
the default.
.TP
\fB\-\-enable\-pckmo\fR
Enable the support for the DEA, TDEA, AES, and ECC PCKMO key encryption
functions. This is the default. Optional.
functions. This is the default.
.TP
\fB\-\-disable\-pckmo\fR
Disable the support for the DEA, TDEA, AES, and ECC PCKMO key encryption

View File

@@ -4,7 +4,7 @@
#
# Sample script to verify that a host key document is genuine by
# verifying the issuer, the validity date and the signature.
# Optionally verify the full trust chain using a CA certficate.
# Optionally verify the full trust chain using a CA certificate.
#
# Sample invocation:
#
@@ -15,31 +15,33 @@
# s390-tools is free software; you can redistribute it and/or modify
# it under the terms of the MIT license. See LICENSE for details.
# Allocate temporary files
ISSUER_PUBKEY_FILE=$(mktemp)
SIGNATURE_FILE=$(mktemp)
BODY_FILE=$(mktemp)
ISSUER_DN_FILE=$(mktemp)
SUBJECT_DN_FILE=$(mktemp)
DEF_ISSUER_DN_FILE=$(mktemp)
DEF_ISSUER_ARMONK_DN_FILE=$(mktemp)
DEF_ISSUER_POUGHKEEPSIE_DN_FILE=$(mktemp)
CANONICAL_ISSUER_DN_FILE=$(mktemp)
CRL_SERIAL_FILE=$(mktemp)
# Cleanup on exit
cleanup()
{
rm -f $ISSUER_PUBKEY_FILE $SIGNATURE_FILE $BODY_FILE \
$ISSUER_DN_FILE $SUBJECT_DN_FILE $DEF_ISSUER_DN_FILE \
$CANONICAL_ISSUER_DN_FILE $CRL_SERIAL_FILE
rm -f "$ISSUER_PUBKEY_FILE" "$SIGNATURE_FILE" "$BODY_FILE" \
"$ISSUER_DN_FILE" "$SUBJECT_DN_FILE" "$DEF_ISSUER_ARMONK_DN_FILE" "$DEF_ISSUER_POUGHKEEPSIE_DN_FILE" \
"$CANONICAL_ISSUER_DN_FILE" "$CRL_SERIAL_FILE"
}
trap cleanup EXIT
# Enhanced error checking for bash
if [ -n "${BASH}" ]
then
if [ -n "${BASH}" ]; then
# shellcheck disable=SC3040
set -o posix
# shellcheck disable=SC3040
set -o pipefail
# shellcheck disable=SC3040
set -o nounset
fi
set -e
@@ -47,8 +49,8 @@ set -e
# Usage
usage()
{
cat <<-EOF
Usage: `basename $1` [-d] [-c CA-cert] [-r CRL] host-key-doc signing-key-cert
cat <<-EOF
Usage: $(basename "$1") [-d] [-c CA-cert] [-r CRL] host-key-doc signing-key-cert
Verify an IBM Secure Execution host key document against
a signing key.
@@ -71,8 +73,7 @@ check_verify_chain()
{
# Verify certificate chain in case a CA certificate file/bundle
# was specified on the command line.
if [ $# = 1 ]
then
if [ -z "$2" ]; then
cat >&2 <<-EOF
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
No CA certificate specified! Skipping trust chain verification.
@@ -80,37 +81,37 @@ Make sure that '$1' is a valid certificate.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
EOF
else
openssl verify -crl_download -crl_check $2 &&
openssl verify -crl_download -crl_check -untrusted $2 $1 ||
exit 1
openssl verify -crl_download -crl_check "$2" &&
openssl verify -crl_download -crl_check -untrusted "$2" "$1" ||
exit 1
fi
}
extract_pubkey()
{
openssl x509 -in $1 -pubkey -noout > $2
openssl x509 -in "$1" -pubkey -noout >"$2"
}
extract_signature()
{
# Assuming that the last field is the signature
SIGOFFSET=$(openssl asn1parse -in $1 | tail -1 | cut -d : -f 1)
SIGOFFSET=$(openssl asn1parse -in "$1" | tail -1 | cut -d : -f 1)
openssl asn1parse -in $1 -out $2 -strparse $SIGOFFSET -noout
openssl asn1parse -in "$1" -out "$2" -strparse "$SIGOFFSET" -noout
}
extract_body()
{
# Assuming that the first field is the full cert body
SIGOFFSET=$(openssl asn1parse -in $1 | head -2 | tail -1 | cut -d : -f 1)
SIGOFFSET=$(openssl asn1parse -in "$1" | head -2 | tail -1 | cut -d : -f 1)
openssl asn1parse -in $1 -out $2 -strparse $SIGOFFSET -noout
openssl asn1parse -in "$1" -out "$2" -strparse "$SIGOFFSET" -noout
}
verify_signature()
{
# Assuming that the signature algorithm is SHA512 with RSA
openssl sha512 -verify $1 -signature $2 $3
openssl sha512 -verify "$1" -signature "$2" "$3"
}
canonical_dn()
@@ -120,18 +121,30 @@ canonical_dn()
DNTYPE=$3
OUTPUT=$4
openssl $OBJTYPE -in $OBJ -$DNTYPE -noout -nameopt multiline \
| sort | grep -v $DNTYPE= > $OUTPUT
openssl "$OBJTYPE" -in "$OBJ" -"$DNTYPE" -noout -nameopt multiline |
LC_ALL=C sort | grep -v "$DNTYPE"= >"$OUTPUT"
}
default_issuer()
default_issuer_armonk()
{
cat <<-EOF
commonName = International Business Machines Corporation
countryName = US
localityName = Armonk
organizationName = International Business Machines Corporation
organizationalUnitName = Key Signing Service
stateOrProvinceName = New York
EOF
}
default_issuer_pougkeepsie()
{
cat <<-EOF
commonName = International Business Machines Corporation
countryName = US
localityName = Poughkeepsie
organizationalUnitName = Key Signing Service
organizationName = International Business Machines Corporation
organizationalUnitName = Key Signing Service
stateOrProvinceName = New York
EOF
}
@@ -141,42 +154,37 @@ EOF
# stripping off the prefix
verify_default_issuer()
{
default_issuer > $DEF_ISSUER_DN_FILE
default_issuer_pougkeepsie >"$DEF_ISSUER_POUGHKEEPSIE_DN_FILE"
default_issuer_armonk >"$DEF_ISSUER_ARMONK_DN_FILE"
sed "s/\(^[ ]*organizationalUnitName[ ]*=[ ]*\).*\(Key Signing Service$\)/\1\2/" \
$ISSUER_DN_FILE > $CANONICAL_ISSUER_DN_FILE
"$ISSUER_DN_FILE" >"$CANONICAL_ISSUER_DN_FILE"
if ! diff $CANONICAL_ISSUER_DN_FILE $DEF_ISSUER_DN_FILE
then
if ! {
diff "$CANONICAL_ISSUER_DN_FILE" "$DEF_ISSUER_POUGHKEEPSIE_DN_FILE" ||
diff "$CANONICAL_ISSUER_DN_FILE" "$DEF_ISSUER_ARMONK_DN_FILE"
} >/dev/null 2>&1; then
echo Incorrect default issuer >&2 && exit 1
fi
}
verify_issuer_files()
{
if [ $1 -eq 1 ]
then
verify_default_issuer
fi
if diff $ISSUER_DN_FILE $SUBJECT_DN_FILE
then
echo Issuer verification OK
else
echo Issuer verification failed >&2 && exit 1
if [ "$1" -eq 1 ]; then
verify_default_issuer
fi
}
cert_time()
{
DATE=$(openssl x509 -in $1 -$2 -noout | sed "s/^.*=//")
DATE=$(openssl x509 -in "$1" -"$2" -noout | sed "s/^.*=//")
date -d "$DATE" +%s
}
crl_time()
{
DATE=$(openssl crl -in $1 -$2 -noout | sed "s/^.*=//")
DATE=$(openssl crl -in "$1" -"$2" -noout | sed "s/^.*=//")
date -d "$DATE" +%s
}
@@ -188,8 +196,7 @@ verify_dates()
MSG="${3:-Certificate}"
NOW=$(date +%s)
if [ $START -le $NOW -a $NOW -le $END ]
then
if [ "$START" -le "$NOW" ] && [ "$NOW" -le "$END" ]; then
echo "${MSG} dates are OK"
else
echo "${MSG} date verification failed" >&2 && exit 1
@@ -198,22 +205,21 @@ verify_dates()
crl_serials()
{
openssl crl -in $1 -text -noout | \
grep "Serial Number" > $CRL_SERIAL_FILE
openssl crl -in "$1" -text -noout |
grep "Serial Number" >"$CRL_SERIAL_FILE"
}
check_serial()
{
CERT_SERIAL=$(openssl x509 -in $1 -noout -serial | cut -d = -f 2)
CERT_SERIAL=$(openssl x509 -in "$1" -noout -serial | cut -d = -f 2)
grep -q $CERT_SERIAL $CRL_SERIAL_FILE
grep -q "$CERT_SERIAL" "$CRL_SERIAL_FILE"
}
check_file()
{
[ $# = 0 ] ||
[ -e "$1" ] ||
(echo "File '$1' not found" >&2 && exit 1)
(echo "File '$1' not found" >&2 && exit 1)
}
# check args
@@ -221,28 +227,25 @@ CRL_FILE=
CA_FILE=
CHECK_DEFAULT_ISSUER=1
args=$(getopt -qu "dr:c:h" $*)
if [ $? = 0 ]
then
set -- $args
while [ $1 != "" ]
do
case $1 in
-d) CHECK_DEFAULT_ISSUER=0; shift;;
-r) CRL_FILE=$2; shift 2;;
-c) CA_FILE=$2; shift 2;;
-h) usage $0; exit 0;;
--) shift; break;;
esac
done
else
usage $0 >&2
exit 1
fi
while getopts 'dr:c:h' opt; do
case $opt in
d) CHECK_DEFAULT_ISSUER=0 ;;
r) CRL_FILE=$OPTARG ;;
c) CA_FILE=$OPTARG ;;
h)
usage "$0"
exit 0
;;
?)
usage "$0"
exit 1
;;
esac
done
shift "$((OPTIND - 1))"
if [ $# -ne 2 ]
then
usage $0 >&2
if [ $# -ne 2 ]; then
usage "$0" >&2
exit 1
fi
@@ -250,51 +253,51 @@ HKD_FILE=$1
HKSK_FILE=$2
# Check whether all specified files exist
check_file $HKD_FILE
check_file $HKSK_FILE
check_file $CA_FILE
check_file $CRL_FILE
check_file "$HKD_FILE"
check_file "$HKSK_FILE"
# CA and CRL are optional arguments
[ -n "$CA_FILE" ] && check_file "$CA_FILE"
[ -n "$CRL_FILE" ] && check_file "$CRL_FILE"
# Check trust chain
check_verify_chain $HKSK_FILE $CA_FILE
check_verify_chain "$HKSK_FILE" "$CA_FILE"
# Verify host key document signature
echo -n "Checking host key document signature: "
extract_pubkey $HKSK_FILE $ISSUER_PUBKEY_FILE &&
extract_signature $HKD_FILE $SIGNATURE_FILE &&
extract_body $HKD_FILE $BODY_FILE &&
verify_signature $ISSUER_PUBKEY_FILE $SIGNATURE_FILE $BODY_FILE ||
exit 1
printf "Checking host key document signature: "
extract_pubkey "$HKSK_FILE" "$ISSUER_PUBKEY_FILE" &&
extract_signature "$HKD_FILE" "$SIGNATURE_FILE" &&
extract_body "$HKD_FILE" "$BODY_FILE" &&
verify_signature "$ISSUER_PUBKEY_FILE" "$SIGNATURE_FILE" "$BODY_FILE" ||
exit 1
# Verify the issuer
canonical_dn x509 $HKD_FILE issuer $ISSUER_DN_FILE
canonical_dn x509 $HKSK_FILE subject $SUBJECT_DN_FILE
canonical_dn x509 "$HKD_FILE" issuer "$ISSUER_DN_FILE"
canonical_dn x509 "$HKSK_FILE" subject "$SUBJECT_DN_FILE"
verify_issuer_files $CHECK_DEFAULT_ISSUER
# Verify dates
verify_dates $(cert_time $HKD_FILE startdate) $(cert_time $HKD_FILE enddate)
verify_dates "$(cert_time "$HKD_FILE" startdate)" "$(cert_time "$HKD_FILE" enddate)"
# Check CRL if specified
if [ -n "$CRL_FILE" ]
then
echo -n "Checking CRL signature: "
extract_signature $CRL_FILE $SIGNATURE_FILE &&
extract_body $CRL_FILE $BODY_FILE &&
verify_signature $ISSUER_PUBKEY_FILE $SIGNATURE_FILE $BODY_FILE ||
exit 1
if [ -n "$CRL_FILE" ]; then
printf "Checking CRL signature: "
extract_signature "$CRL_FILE" "$SIGNATURE_FILE" &&
extract_body "$CRL_FILE" "$BODY_FILE" &&
verify_signature "$ISSUER_PUBKEY_FILE" "$SIGNATURE_FILE" "$BODY_FILE" ||
exit 1
echo -n "CRL "
canonical_dn crl $CRL_FILE issuer $ISSUER_DN_FILE
canonical_dn x509 $HKSK_FILE subject $SUBJECT_DN_FILE
printf "CRL "
canonical_dn crl "$CRL_FILE" issuer "$ISSUER_DN_FILE"
canonical_dn x509 "$HKSK_FILE" subject "$SUBJECT_DN_FILE"
verify_issuer_files $CHECK_DEFAULT_ISSUER
verify_dates $(crl_time $CRL_FILE lastupdate) $(crl_time $CRL_FILE nextupdate) 'CRL'
verify_dates "$(crl_time "$CRL_FILE" lastupdate)" "$(crl_time "$CRL_FILE" nextupdate)" 'CRL'
crl_serials $CRL_FILE
check_serial $HKD_FILE &&
echo "Certificate is revoked, do not use it anymore!" >&2 &&
exit 1
crl_serials "$CRL_FILE"
check_serial "$HKD_FILE" &&
echo "Certificate is revoked, do not use it anymore!" >&2 &&
exit 1
fi
# We made it
echo All checks reqested for \'$HKD_FILE\' were successful
echo All checks requested for \'"$HKD_FILE"\' were successful

View File

@@ -3,7 +3,7 @@ include ../../common.mak
bin_PROGRAM = genprotimg
PKGDATADIR ?= "$(DESTDIR)$(TOOLS_DATADIR)/genprotimg"
PKGDATADIR ?= "$(TOOLS_DATADIR)/genprotimg"
SRC_DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
TOP_SRCDIR := $(SRC_DIR)/../
ROOT_DIR = $(TOP_SRC_DIR)/../../
@@ -27,7 +27,7 @@ $(bin_PROGRAM)_SRCS := $(bin_PROGRAM).c pv/pv_stage3.c pv/pv_image.c \
$(NULL)
$(bin_PROGRAM)_OBJS := $($(bin_PROGRAM)_SRCS:.c=.o)
ALL_CFLAGS += -std=gnu11 -DPKGDATADIR=$(PKGDATADIR) \
ALL_CFLAGS += -DPKGDATADIR=$(PKGDATADIR) \
$(GLIB2_CFLAGS) $(LIBCRYPTO_CFLAGS) $(LIBCURL_CFLAGS) \
-DOPENSSL_API_COMPAT=0x10100000L \
$(WARNINGS) \

View File

@@ -17,7 +17,8 @@
/* IBM signing key subject */
#define PV_IBM_Z_SUBJECT_COMMON_NAME "International Business Machines Corporation"
#define PV_IBM_Z_SUBJECT_COUNTRY_NAME "US"
#define PV_IBM_Z_SUBJECT_LOCALITY_NAME "Poughkeepsie"
#define PV_IBM_Z_SUBJECT_LOCALITY_NAME_POUGHKEEPSIE "Poughkeepsie"
#define PV_IBM_Z_SUBJECT_LOCALITY_NAME_ARMONK "Armonk"
#define PV_IBM_Z_SUBJECT_ORGANIZATIONONAL_UNIT_NAME_SUFFIX "Key Signing Service"
#define PV_IBM_Z_SUBJECT_ORGANIZATION_NAME "International Business Machines Corporation"
#define PV_IBM_Z_SUBJECT_STATE "New York"

View File

@@ -34,6 +34,10 @@
#define PV_PCF_PCKMO_AES __PV_BIT(57) /* PCKMO encrypt-AES-key functions allowed */
#define PV_PCF_PCKM_ECC __PV_BIT(58) /* PCKMO encrypt-ECC-key functions allowed */
/* Secret control flags */
#define PV_SCF_CCK_EXTENSION_SECRET_ENFORCMENT \
__PV_BIT(1) /* All add-secret requests must provide an extension secret */
/* maxima for the PV version 1 */
#define PV_V1_IPIB_MAX_SIZE PAGE_SIZE
#define PV_V1_PV_HDR_MAX_SIZE (2 * PAGE_SIZE)

View File

@@ -62,11 +62,12 @@ static gint pv_args_set_defaults(PvArgs *args, GError **err G_GNUC_UNUSED)
static gint pv_args_validate_options(PvArgs *args, GError **err)
{
const PvControlFlagsArgs *cf_args = &args->cf_args;
PvComponentType KERNEL = PV_COMP_TYPE_KERNEL;
/* Check for mutually exclusive arguments */
if (args->pcf && !(args->allow_pckmo == PV_NOT_SET &&
args->allow_dump == PV_NOT_SET)) {
if (cf_args->pcf &&
!(cf_args->enable_pckmo == PV_NOT_SET && cf_args->enable_dump == PV_NOT_SET)) {
g_set_error(
err, PV_PARSE_ERROR, PV_PARSE_ERROR_SYNTAX,
_("The '--x-pcf' option cannot be used with the '--(enable|disable)-pckmo' or"
@@ -74,6 +75,13 @@ static gint pv_args_validate_options(PvArgs *args, GError **err)
return -1;
}
if (cf_args->scf && !(cf_args->enable_cck_extension_secret_enforcement == PV_NOT_SET)) {
g_set_error(
err, PV_PARSE_ERROR, PV_PARSE_ERROR_SYNTAX,
_("The '--x-scf' option cannot be used with the '--(enable|disable)-extension-secret-required' flags.\nUse 'genprotimg --help' for more information"));
return -1;
}
/* Check for unused arguments */
if (args->unused_values->len > 0) {
g_autofree gchar *unused = NULL;
@@ -93,12 +101,20 @@ static gint pv_args_validate_options(PvArgs *args, GError **err)
}
/* Check for mandatory arguments */
if (args->allow_dump == PV_TRUE && !args->cust_comm_key_path) {
if (cf_args->enable_dump == PV_TRUE && !args->cust_comm_key_path) {
g_set_error(err, PV_PARSE_ERROR, PR_PARSE_ERROR_MISSING_ARGUMENT,
_("Option '--allow-dump' requires the '--comm-key' option.\nUse 'genprotimg "
_("Option '--enable-dump' requires the '--comm-key' option.\nUse 'genprotimg "
"--help' for more information"));
return -1;
}
if (cf_args->enable_cck_extension_secret_enforcement == PV_TRUE &&
!args->cust_comm_key_path) {
g_set_error(
err, PV_PARSE_ERROR, PR_PARSE_ERROR_MISSING_ARGUMENT,
_("Option '--enable-cck-extension-secret' requires the '--comm-key' option.\nUse 'genprotimg "
"--help' for more information"));
return -1;
}
if (!args->output_path) {
g_set_error(err, PV_PARSE_ERROR, PR_PARSE_ERROR_MISSING_ARGUMENT,
@@ -178,11 +194,11 @@ static gboolean cb_set_string_option(const gchar *option, const gchar *value,
if (g_str_equal(option, "--x-header-key"))
args_option = &args->cust_root_key_path;
if (g_str_equal(option, "--x-pcf"))
args_option = &args->pcf;
args_option = &args->cf_args.pcf;
if (g_str_equal(option, "--x-psw"))
args_option = &args->psw_addr;
if (g_str_equal(option, "--x-scf"))
args_option = &args->scf;
args_option = &args->cf_args.scf;
if (!args_option) {
g_set_error(err, PV_PARSE_ERROR, PV_PARSE_ERROR_SYNTAX,
@@ -217,49 +233,48 @@ static gboolean cb_remaining_values(const gchar *option G_GNUC_UNUSED,
}
#define MUT_EXCL_BOOL_FLAG_CB_NAME(FLAG, VALUE) (cb_##FLAG##_##VALUE)
#define DEFINE_MUT_EXCL_BOOL_FLAG_CB(FLAG, VALUE) \
static gboolean MUT_EXCL_BOOL_FLAG_CB_NAME(FLAG, VALUE)( \
const gchar *option G_GNUC_UNUSED, const gchar *value G_GNUC_UNUSED, \
PvArgs *args, GError **err) \
{ \
if (!(args->allow_##FLAG == PV_NOT_SET || \
args->allow_##FLAG == VALUE)) { \
g_set_error(err, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, \
"'--enable-" #FLAG "' and '--disable-" #FLAG \
"' are mutually exclusive"); \
return FALSE; \
} \
args->allow_##FLAG = VALUE; \
return TRUE; \
#define DEFINE_MUT_EXCL_BOOL_FLAG_CB(FLAG, VALUE) \
static gboolean MUT_EXCL_BOOL_FLAG_CB_NAME(FLAG, VALUE)(const gchar *option G_GNUC_UNUSED, \
const gchar *value G_GNUC_UNUSED, \
PvArgs *args, GError **err) \
{ \
if (!(args->cf_args.enable_##FLAG == PV_NOT_SET || \
args->cf_args.enable_##FLAG == VALUE)) { \
g_set_error(err, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, \
"'--enable-" #FLAG "' and '--disable-" #FLAG \
"' are mutually exclusive"); \
return FALSE; \
} \
args->cf_args.enable_##FLAG = VALUE; \
return TRUE; \
}
#define DEFINE_MUT_EXCL_BOOL_FLAG_CBS(FLAG) \
DEFINE_MUT_EXCL_BOOL_FLAG_CB(FLAG, PV_TRUE) \
DEFINE_MUT_EXCL_BOOL_FLAG_CB(FLAG, PV_FALSE)
#define MUT_EXCL_BOOL_FLAG(FLAG, ENABLE_DESC, DISABLE_DESC) \
{ \
.long_name = "enable-" #FLAG, \
.short_name = 0, \
.flags = G_OPTION_FLAG_NO_ARG, \
.arg = G_OPTION_ARG_CALLBACK, \
.arg_data = MUT_EXCL_BOOL_FLAG_CB_NAME(FLAG, PV_TRUE), \
.description = ENABLE_DESC, \
}, \
{ \
.long_name = "disable-" #FLAG, \
.short_name = 0, \
.flags = G_OPTION_FLAG_NO_ARG, \
.arg = G_OPTION_ARG_CALLBACK, \
.arg_data = MUT_EXCL_BOOL_FLAG_CB_NAME(FLAG, PV_FALSE), \
.description = DISABLE_DESC, \
#define MUT_EXCL_BOOL_FLAG(NAME, FLAG, ENABLE_DESC, DISABLE_DESC) \
{ \
.long_name = "enable-" #NAME, \
.short_name = 0, \
.flags = G_OPTION_FLAG_NO_ARG, \
.arg = G_OPTION_ARG_CALLBACK, \
.arg_data = MUT_EXCL_BOOL_FLAG_CB_NAME(FLAG, PV_TRUE), \
.description = ENABLE_DESC, \
}, \
{ \
.long_name = "disable-" #NAME, .short_name = 0, .flags = G_OPTION_FLAG_NO_ARG, \
.arg = G_OPTION_ARG_CALLBACK, \
.arg_data = MUT_EXCL_BOOL_FLAG_CB_NAME(FLAG, PV_FALSE), \
.description = DISABLE_DESC, \
}
#define INDENT " "
#define INDENT " "
/* Define the callbacks for mutually exclusive command line flags */
DEFINE_MUT_EXCL_BOOL_FLAG_CBS(dump)
DEFINE_MUT_EXCL_BOOL_FLAG_CBS(pckmo)
DEFINE_MUT_EXCL_BOOL_FLAG_CBS(dump);
DEFINE_MUT_EXCL_BOOL_FLAG_CBS(pckmo);
DEFINE_MUT_EXCL_BOOL_FLAG_CBS(cck_extension_secret_enforcement);
gint pv_args_parse_options(PvArgs *args, gint *argc, gchar **argv[],
GError **err)
@@ -280,7 +295,7 @@ gint pv_args_parse_options(PvArgs *args, gint *argc, gchar **argv[],
.arg_data = &args->host_keys,
.description =
_("FILE specifies a host-key document. At least\n" INDENT
"one is required Specify this option multiple times\n" INDENT
"one is required. Specify this option multiple times\n" INDENT
"to enable the image to run on more than one host."),
.arg_description = _("FILE") },
{ .long_name = "cert",
@@ -325,27 +340,31 @@ gint pv_args_parse_options(PvArgs *args, gint *argc, gchar **argv[],
.description = _("Use the kernel parameters stored in PARMFILE\n" INDENT
"(optional)."),
.arg_description = _("PARMFILE") },
MUT_EXCL_BOOL_FLAG(dump, dump,
_("Enable PV guest dumps (optional). This option\n" INDENT
"requires the '--comm-key' option."),
_("Disable PV guest dumps (default).")),
MUT_EXCL_BOOL_FLAG(
dump,
_("Enable PV guest dumps (optional). This option\n" INDENT
"requires the '--comm-key' option."),
_("Disable PV guest dumps (default) (optional).")),
MUT_EXCL_BOOL_FLAG(
pckmo,
_("Enable the support for the DEA, TDEA, AES, and\n" INDENT
"ECC PCKMO key encryption functions (default)\n" INDENT
"(optional)."),
_("Disable the support for the DEA, TDEA, AES, and\n" INDENT
"ECC PCKMO key encryption functions (optional).")),
cck-extension-secret, cck_extension_secret_enforcement,
_("Add-secret requests must provide an extension\n" INDENT
"secret that matches the CCK-derived extension\n" INDENT
"secret (optional). This option requires the\n" INDENT
"'--comm-key' option."),
_("Add-secret requests don't have to provide\n" INDENT
"the CCK-derived extension secret (default).")),
MUT_EXCL_BOOL_FLAG(pckmo, pckmo,
_("Enable the support for the DEA, TDEA, AES, and\n" INDENT
"ECC PCKMO key encryption functions (default)."),
_("Disable the support for the DEA, TDEA, AES, and\n" INDENT
"ECC PCKMO key encryption functions (optional).")),
{ .long_name = "comm-key",
.short_name = 0,
.flags = G_OPTION_FLAG_FILENAME,
.arg = G_OPTION_ARG_CALLBACK,
.arg_data = cb_set_string_option,
.description = _(
"FILE contains the key with which you encrypt\n" INDENT
"the PV guest dump (optional). Required by\n" INDENT
"the '--enable-dump' option."),
"FILE contains the customer communication key\n" INDENT
"(CCK) (optional)."),
.arg_description = _("FILE") },
{ .long_name = "crl",
.short_name = 0,
@@ -450,6 +469,8 @@ gint pv_args_parse_options(PvArgs *args, gint *argc, gchar **argv[],
.arg_data = cb_set_string_option,
.description = _("Specify the secret control flags\n" INDENT
"as a hexadecimal value.\n" INDENT
"Optional; mutually exclusive with\n" INDENT
"'--(enable|disable)-cck-extension-secret';\n" INDENT
"Optional; default: '0x0'."),
.arg_description = _("VALUE") },
{ 0 },
@@ -487,8 +508,10 @@ PvArgs *pv_args_new(void)
g_autoptr(PvArgs) args = g_new0(PvArgs, 1);
args->unused_values = g_ptr_array_new_with_free_func(g_free);
args->allow_dump = PV_NOT_SET;
args->allow_pckmo = PV_NOT_SET;
/* `args->cf_args` is implicitly initialized with zeros since
* `g_new0` is used. So there is no reason to explicitly
* initialize the values as PV_NOT_SET == 0.
*/
return g_steal_pointer(&args);
}
@@ -497,8 +520,8 @@ void pv_args_free(PvArgs *args)
if (!args)
return;
g_free(args->pcf);
g_free(args->scf);
g_free(args->cf_args.pcf);
g_free(args->cf_args.scf);
g_free(args->psw_addr);
g_free(args->cust_root_key_path);
g_free(args->cust_comm_key_path);

View File

@@ -23,19 +23,27 @@ PvArg *pv_arg_new(PvComponentType type, const gchar *path);
void pv_arg_free(PvArg *arg);
typedef enum pv_tristate {
PV_NOT_SET = 0,
PV_TRUE,
PV_FALSE,
PV_NOT_SET = 0,
PV_TRUE,
PV_FALSE,
} PvTristate;
/* The value of PV_NOT_SET is not allowed to be changed */
STATIC_ASSERT(PV_NOT_SET == 0)
typedef struct {
gchar *pcf;
gchar *scf;
/* Add-secret requests do require CCK-extension secrets */
PvTristate enable_cck_extension_secret_enforcement;
PvTristate enable_dump;
PvTristate enable_pckmo;
} PvControlFlagsArgs;
typedef struct {
gint log_level;
gint no_verify;
gboolean offline;
gchar *pcf;
gchar *scf;
PvTristate allow_dump;
PvTristate allow_pckmo;
PvControlFlagsArgs cf_args;
gchar *psw_addr; /* PSW address which will be used for the start of
* the actual component (e.g. Linux kernel)
*/

View File

@@ -228,37 +228,40 @@ static gint pv_img_set_psw_addr(PvImage *img, const gchar *psw_addr_s,
return 0;
}
static gint pv_img_set_control_flags(PvImage *img, const gchar *pcf_s,
const gchar *scf_s,
PvTristate allow_dump,
PvTristate allow_pckmo, GError **err)
static void pv_img_set_control_flag(uint64_t *flags, const PvTristate option, const uint64_t flag)
{
if (option == PV_TRUE)
*flags |= flag;
else if (option == PV_FALSE)
*flags &= ~flag;
}
static gint pv_img_set_control_flags(PvImage *img, const PvControlFlagsArgs *cf_args, GError **err)
{
uint64_t flags;
if (pcf_s) {
if (hex_str_toull(pcf_s, &flags, err) < 0)
/* Set plain control flags */
if (cf_args->pcf) {
if (hex_str_toull(cf_args->pcf, &flags, err) < 0)
return -1;
img->pcf = flags;
}
if (scf_s) {
if (hex_str_toull(scf_s, &flags, err) < 0)
pv_img_set_control_flag(&img->pcf, cf_args->enable_dump, PV_PCF_ALLOW_DUMPING);
pv_img_set_control_flag(&img->pcf, cf_args->enable_pckmo,
PV_PCF_PCKM_ECC | PV_PCF_PCKMO_AES | PV_PCF_PCKMO_DEA_TDEA);
/* Set secret control flags */
if (cf_args->scf) {
if (hex_str_toull(cf_args->scf, &flags, err) < 0)
return -1;
img->scf = flags;
}
if (allow_dump == PV_TRUE)
img->pcf |= PV_PCF_ALLOW_DUMPING;
else if (allow_dump == PV_FALSE)
img->pcf &= ~PV_PCF_ALLOW_DUMPING;
if (allow_pckmo == PV_TRUE)
img->pcf |= PV_PCF_PCKM_ECC | PV_PCF_PCKMO_AES | PV_PCF_PCKMO_DEA_TDEA;
else if (allow_pckmo == PV_FALSE)
img->pcf &= ~(PV_PCF_PCKM_ECC | PV_PCF_PCKMO_AES | PV_PCF_PCKMO_DEA_TDEA);
pv_img_set_control_flag(&img->scf, cf_args->enable_cck_extension_secret_enforcement,
PV_SCF_CCK_EXTENSION_SECRET_ENFORCMENT);
return 0;
}
@@ -610,9 +613,7 @@ PvImage *pv_img_new(PvArgs *args, const gchar *stage3a_path, GError **err)
return NULL;
/* set the control flags: PCF and SCF */
if (pv_img_set_control_flags(ret, args->pcf, args->scf,
args->allow_dump, args->allow_pckmo,
err) < 0)
if (pv_img_set_control_flags(ret, &args->cf_args, err) < 0)
return NULL;
/* read in the keys */
@@ -683,7 +684,26 @@ gint pv_img_add_component(PvImage *img, const PvArg *arg, GError **err)
{
g_autoptr(PvComponent) comp = NULL;
comp = pv_component_new_file(arg->type, arg->path, err);
switch (arg->type) {
case PV_COMP_TYPE_INITRD:
case PV_COMP_TYPE_KERNEL:
case PV_COMP_TYPE_STAGE3B:
comp = pv_component_new_file(arg->type, arg->path, err);
break;
case PV_COMP_TYPE_CMDLINE: {
g_autoptr(PvBuffer) buf = NULL;
g_autofree char *data = NULL;
gsize length;
if (!g_file_get_contents(arg->path, &data, &length, err))
return -1;
/* Add one for the null terminator */
buf = pv_buffer_take(g_steal_pointer(&data), length + 1);
comp = pv_component_new_buf(arg->type, buf, err);
} break;
}
if (!comp)
return -1;

View File

@@ -59,7 +59,7 @@ static gint pv_ipib_init(IplParameterBlock *ipib, GSList *comps,
ipib_size = MAX(ipl_pl_hdr_size + blk0_len, (uint32_t)PAGE_SIZE);
g_assert(pv_ipib_get_size(comps_length) == ipib_size);
pv->pbt = IPL_TYPE_PV;
pv->pbt = IPL_PBT_PV;
pv->len = GUINT32_TO_BE(blk0_len);
pv->num_comp = GUINT32_TO_BE(comps_length);
/* both values will be overwritten during the IPL process by

View File

@@ -26,6 +26,15 @@ PvBuffer *pv_buffer_alloc(gsize size)
return ret;
}
PvBuffer *pv_buffer_take(char *data, gsize size)
{
PvBuffer *ret = g_new0(PvBuffer, 1);
ret->data = data;
ret->size = size;
return ret;
}
PvBuffer *pv_buffer_dup(const PvBuffer *buf, gboolean page_aligned)
{
PvBuffer *ret;

View File

@@ -21,6 +21,10 @@ typedef struct PvBuffer {
} PvBuffer;
PvBuffer *pv_buffer_alloc(gsize size);
/* After this call @data belongs to the PvBuffer and must no longer be modified
* by the caller.
*/
PvBuffer *pv_buffer_take(char *data, gsize size);
void pv_buffer_free(PvBuffer *buf);
void pv_buffer_clear(PvBuffer **buf);
gint pv_buffer_write(const PvBuffer *buf, FILE *file, GError **err);

View File

@@ -664,62 +664,9 @@ static gboolean x509_name_data_by_nid_equal(X509_NAME *name, gint nid,
return memcmp(data, y, data_len) == 0;
}
static gboolean own_X509_NAME_ENTRY_equal(const X509_NAME_ENTRY *x,
const X509_NAME_ENTRY *y)
{
const ASN1_OBJECT *x_obj = X509_NAME_ENTRY_get_object(x);
const ASN1_STRING *x_data = X509_NAME_ENTRY_get_data(x);
const ASN1_OBJECT *y_obj = X509_NAME_ENTRY_get_object(y);
const ASN1_STRING *y_data = X509_NAME_ENTRY_get_data(y);
gint x_len = ASN1_STRING_length(x_data);
gint y_len = ASN1_STRING_length(y_data);
if (x_len < 0 || x_len != y_len)
return FALSE;
/* ASN1_STRING_cmp(x_data, y_data) == 0 doesn't work because it also
* compares the type, which is sometimes different.
*/
return OBJ_cmp(x_obj, y_obj) == 0 &&
memcmp(ASN1_STRING_get0_data(x_data),
ASN1_STRING_get0_data(y_data),
(unsigned long)x_len) == 0;
}
static gboolean own_X509_NAME_equal(const X509_NAME *x, const X509_NAME *y)
{
gint x_count = X509_NAME_entry_count(x);
gint y_count = X509_NAME_entry_count(y);
if (x != y && (!x || !y))
return FALSE;
if (x_count != y_count)
return FALSE;
for (gint i = 0; i < x_count; i++) {
const X509_NAME_ENTRY *entry_i = X509_NAME_get_entry(x, i);
gboolean entry_found = FALSE;
for (gint j = 0; j < y_count; j++) {
const X509_NAME_ENTRY *entry_j =
X509_NAME_get_entry(y, j);
if (own_X509_NAME_ENTRY_equal(entry_i, entry_j)) {
entry_found = TRUE;
break;
}
}
if (!entry_found)
return FALSE;
}
return TRUE;
}
/* Checks whether the subject of @cert is a IBM signing key subject. For this we
* must check that the subject is equal to: 'C = US, ST = New York, L =
* Poughkeepsie, O = International Business Machines Corporation, CN =
* Poughkeepsie or Armonk, O = International Business Machines Corporation, CN =
* International Business Machines Corporation' and the organization unit (OUT)
* must end with the suffix ' Key Signing Service'.
*/
@@ -743,8 +690,10 @@ static gboolean has_ibm_signing_subject(X509 *cert)
PV_IBM_Z_SUBJECT_STATE))
return FALSE;
if (!x509_name_data_by_nid_equal(subject, NID_localityName,
PV_IBM_Z_SUBJECT_LOCALITY_NAME))
if (!(x509_name_data_by_nid_equal(subject, NID_localityName,
PV_IBM_Z_SUBJECT_LOCALITY_NAME_POUGHKEEPSIE) ||
x509_name_data_by_nid_equal(subject, NID_localityName,
PV_IBM_Z_SUBJECT_LOCALITY_NAME_ARMONK)))
return FALSE;
if (!x509_name_data_by_nid_equal(subject, NID_organizationName,
@@ -806,6 +755,39 @@ static X509_NAME *x509_name_reorder_attributes(const X509_NAME *name, const gint
return g_steal_pointer(&ret);
}
/** Replace locality 'Armonk' with 'Pougkeepsie'. If Armonk was not set return
* `NULL`.
*/
static X509_NAME *x509_armonk_locality_fixup(const X509_NAME *name)
{
g_autoptr(X509_NAME) ret = NULL;
int pos;
/* Check if ``L=Armonk`` */
if (!x509_name_data_by_nid_equal((X509_NAME *)name, NID_localityName,
PV_IBM_Z_SUBJECT_LOCALITY_NAME_ARMONK))
return NULL;
ret = X509_NAME_dup((X509_NAME *)name);
if (!ret)
g_abort();
pos = X509_NAME_get_index_by_NID(ret, NID_localityName, -1);
if (pos == -1)
return NULL;
X509_NAME_ENTRY_free(X509_NAME_delete_entry(ret, pos));
/* Create a new name entry at the same position as before */
if (X509_NAME_add_entry_by_NID(
ret, NID_localityName, MBSTRING_UTF8,
(const unsigned char *)&PV_IBM_Z_SUBJECT_LOCALITY_NAME_POUGHKEEPSIE,
sizeof(PV_IBM_Z_SUBJECT_LOCALITY_NAME_POUGHKEEPSIE) - 1, pos, 0) != 1)
return NULL;
return g_steal_pointer(&ret);
}
/* In RFC 5280 the attributes of a (subject/issuer) name is not mandatory
* ordered. The problem is that our certificates are not consistent in the order
* (see https://tools.ietf.org/html/rfc5280#section-4.1.2.4 for details).
@@ -828,24 +810,10 @@ X509_NAME *c2b_name(const X509_NAME *name)
return X509_NAME_dup((X509_NAME *)name);
}
/* Verify that: subject(issuer) == issuer(crl) and SKID(issuer) == AKID(crl) */
/* Verify that SKID(issuer) == AKID(crl) if available */
static gint check_crl_issuer(X509_CRL *crl, X509 *issuer, GError **err)
{
const X509_NAME *crl_issuer = X509_CRL_get_issuer(crl);
const X509_NAME *issuer_subject = X509_get_subject_name(issuer);
AUTHORITY_KEYID *akid = NULL;
if (!own_X509_NAME_equal(issuer_subject, crl_issuer)) {
g_autofree char *issuer_subject_str = X509_NAME_oneline(issuer_subject,
NULL, 0);
g_autofree char *crl_issuer_str = X509_NAME_oneline(crl_issuer, NULL, 0);
g_set_error(err, PV_CRYPTO_ERROR,
PV_CRYPTO_ERROR_CRL_SUBJECT_ISSUER_MISMATCH,
_("issuer mismatch:\n%s\n%s"),
issuer_subject_str, crl_issuer_str);
return -1;
}
g_autoptr(AUTHORITY_KEYID) akid = NULL;
/* If AKID(@crl) is specified it must match with SKID(@issuer) */
akid = X509_CRL_get_ext_d2i(crl, NID_authority_key_identifier, NULL, NULL);
@@ -881,7 +849,6 @@ gint check_crl_valid_for_cert(X509_CRL *crl, X509 *cert,
return -1;
}
/* check that the @crl issuer matches with the subject name of @cert*/
if (check_crl_issuer(crl, cert, err) < 0)
return -1;
@@ -910,6 +877,60 @@ gint check_crl_valid_for_cert(X509_CRL *crl, X509 *cert,
return 0;
}
/* This function contains work-arounds for some known subject(CRT)<->issuer(CRL)
* issues.
*/
static STACK_OF_X509_CRL *quirk_X509_STORE_ctx_get1_crls(X509_STORE_CTX *ctx,
const X509_NAME *subject, GError **err)
{
g_autoptr(X509_NAME) fixed_subject = NULL;
g_autoptr(STACK_OF_X509_CRL) ret = NULL;
ret = Pv_X509_STORE_CTX_get1_crls(ctx, subject);
if (ret && sk_X509_CRL_num(ret) > 0)
return g_steal_pointer(&ret);
/* Workaround to fix the mismatch between issuer name of the * IBM
* signing CRLs and the IBM signing key subject name. Locality name has
* changed from Poughkeepsie to Armonk.
*/
fixed_subject = x509_armonk_locality_fixup(subject);
/* Was the locality replaced? */
if (fixed_subject) {
X509_NAME *tmp;
sk_X509_CRL_free(ret);
ret = Pv_X509_STORE_CTX_get1_crls(ctx, fixed_subject);
if (ret && sk_X509_CRL_num(ret) > 0)
return g_steal_pointer(&ret);
/* Workaround to fix the ordering mismatch between issuer name
* of the IBM signing CRLs and the IBM signing key subject name.
*/
tmp = fixed_subject;
fixed_subject = c2b_name(fixed_subject);
X509_NAME_free(tmp);
sk_X509_CRL_free(ret);
ret = Pv_X509_STORE_CTX_get1_crls(ctx, fixed_subject);
if (ret && sk_X509_CRL_num(ret) > 0)
return g_steal_pointer(&ret);
X509_NAME_free(fixed_subject);
fixed_subject = NULL;
}
/* Workaround to fix the ordering mismatch between issuer name of the
* IBM signing CRLs and the IBM signing key subject name.
*/
fixed_subject = c2b_name(subject);
sk_X509_CRL_free(ret);
ret = Pv_X509_STORE_CTX_get1_crls(ctx, fixed_subject);
if (ret && sk_X509_CRL_num(ret) > 0)
return g_steal_pointer(&ret);
g_set_error(err, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_NO_CRL, _("no CRL found"));
return NULL;
}
/* Given a certificate @cert try to find valid revocation lists in @ctx. If no
* valid CRL was found NULL is returned.
*/
@@ -927,20 +948,9 @@ STACK_OF_X509_CRL *store_ctx_find_valid_crls(X509_STORE_CTX *ctx, X509 *cert,
return NULL;
}
ret = X509_STORE_CTX_get1_crls(ctx, subject);
if (!ret) {
/* Workaround to fix the mismatch between issuer name of the
* IBM Z signing CRLs and the IBM Z signing key subject name.
*/
g_autoptr(X509_NAME) broken_subject = c2b_name(subject);
ret = X509_STORE_CTX_get1_crls(ctx, broken_subject);
if (!ret) {
g_set_error(err, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_NO_CRL,
_("no CRL found"));
return NULL;
}
}
ret = quirk_X509_STORE_ctx_get1_crls(ctx, subject, err);
if (!ret)
return NULL;
/* Filter out non-valid CRLs for @cert */
for (gint i = 0; i < sk_X509_CRL_num(ret); i++) {
@@ -1328,32 +1338,14 @@ gint check_chain_parameters(const STACK_OF_X509 *chain,
/* It's almost the same as X509_check_issed from OpenSSL does except that we
* don't check the key usage of the potential issuer. This means we check:
* 1. issuer_name(cert) == subject_name(issuer)
* 2. Check whether the akid(cert) (if available) matches the issuer skid
* 3. Check that the cert algrithm matches the subject algorithm
* 4. Verify the signature of certificate @cert is using the public key of
* 1. Check whether the akid(cert) (if available) matches the issuer skid
* 2. Check that the cert algrithm matches the subject algorithm
* 3. Verify the signature of certificate @cert is using the public key of
* @issuer.
*/
static gint check_host_key_issued(X509 *cert, X509 *issuer, GError **err)
{
const X509_NAME *issuer_subject = X509_get_subject_name(issuer);
const X509_NAME *cert_issuer = X509_get_issuer_name(cert);
AUTHORITY_KEYID *akid = NULL;
/* We cannot use X509_NAME_cmp() because it considers the order of the
* X509_NAME_Entries.
*/
if (!own_X509_NAME_equal(issuer_subject, cert_issuer)) {
g_autofree char *issuer_subject_str =
X509_NAME_oneline(issuer_subject, NULL, 0);
g_autofree char *cert_issuer_str =
X509_NAME_oneline(cert_issuer, NULL, 0);
g_set_error(err, PV_CRYPTO_ERROR,
PV_CRYPTO_ERROR_CERT_SUBJECT_ISSUER_MISMATCH,
_("Subject issuer mismatch:\n'%s'\n'%s'"),
issuer_subject_str, cert_issuer_str);
return -1;
}
g_autoptr(AUTHORITY_KEYID) akid = NULL;
akid = X509_get_ext_d2i(cert, NID_authority_key_identifier, NULL, NULL);
if (akid && X509_check_akid(issuer, akid) != X509_V_OK) {
@@ -1834,14 +1826,12 @@ static gint __encrypt_decrypt_bio(const struct cipher_parms *parms, BIO *b_in,
g_assert(out_len >= 0);
num_bytes_written = BIO_write(b_out, out_buf, out_len);
if (num_bytes_written < 0) {
if (num_bytes_written != out_len) {
g_set_error(err, PV_CRYPTO_ERROR,
PV_CRYPTO_ERROR_INTERNAL,
_("Failed to write"));
return -1;
}
g_assert(num_bytes_written == out_len);
tmp_size_out += (guint)num_bytes_written;
/* Set new tweak value. Please keep in mind that the

View File

@@ -75,6 +75,7 @@ void x509_pair_free(x509_pair *pair);
/* Register auto cleanup functions */
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(ASN1_INTEGER, ASN1_INTEGER_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(ASN1_OCTET_STRING, ASN1_OCTET_STRING_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(AUTHORITY_KEYID, AUTHORITY_KEYID_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(BIGNUM, BN_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(BIO, BIO_free_all)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(BN_CTX, BN_CTX_free)

View File

@@ -116,6 +116,7 @@ static void l_sd_cpu_fill(struct sd_cpu *cpu, struct l_x_cpu_info *cpu_info,
int threads)
{
sd_cpu_cpu_time_us_set(cpu, cpu_info->lp_time);
sd_cpu_threads_per_core_set(cpu, threads);
if (threads > 1)
sd_cpu_thread_time_us_set(cpu,
cpu_info->lp_time * threads - cpu_info->mt_idle_time);
@@ -297,6 +298,7 @@ static struct sd_sys_item *l_sys_item_vec[] = {
&sd_sys_item_thread_cnt,
&sd_sys_item_core_diff,
&sd_sys_item_thread_diff,
&sd_sys_item_smt_diff,
&sd_sys_item_mgm_diff,
&sd_sys_item_core,
&sd_sys_item_thread,
@@ -326,6 +328,7 @@ static struct sd_cpu_item *l_cpu_item_vec[] = {
&sd_cpu_item_type,
&sd_cpu_item_core_diff,
&sd_cpu_item_thread_diff,
&sd_cpu_item_smt_diff,
&sd_cpu_item_mgm_diff,
&sd_cpu_item_core,
&sd_cpu_item_thread,

View File

@@ -391,3 +391,24 @@ void hyptop_helper_init(void)
if (l_iconv_ebcdic_ascii == (iconv_t) -1)
ERR_EXIT("Could not initialize iconv\n");
}
/*
* Calculate real SMT utilization
* @core_us: core utilization in us
* @thr_us: thread utilization in us
* @mgm_us: management utilization in us
* @thread_per_core: SMT thread count per core
*/
s64 ht_calculate_smt_util(u64 core_us, u64 thr_us, u64 mgm_us, int thread_per_core)
{
s64 component1, component2, smt_us;
double smt_factor = g.o.smt_factor;
component1 = thread_per_core * core_us - thr_us;
if (thread_per_core > 1)
component1 /= smt_factor;
component2 = thr_us - core_us;
smt_us = G0(component1 + component2 + mgm_us);
return smt_us;
}

View File

@@ -34,6 +34,7 @@ extern void ht_ebcdic_to_ascii(char *in, char *out, size_t len);
extern char *ht_mount_point_get(const char *fs_type);
extern u64 ht_ext_tod_2_us(void *tod_ext);
extern void ht_print_time(void);
extern s64 ht_calculate_smt_util(u64 core_us, u64 thr_us, u64 mgm_us, int thread_per_core);
/*
* Memory alloc functions

View File

@@ -74,6 +74,18 @@ In this mode no user input is accepted.
.BR "\-d <SECONDS>" " or " "\-\-delay=<SECONDS>"
Specifies the delay between screen updates.
.TP
.BR "\-m <FACTOR>" " or " "\-\-smt_factor=<FACTOR>"
Specifies a workload dependent SMT speedup factor.
For IBM z15 servers, the default value is 1.3. If the workload benefits
from SMT, you can specify a higher value. If the workload does not benefit
from SMT, specifying lower values results in more accurate reports of
real CPU SMT utilization field for LPARs. There is no hard boundary except
that it must be a positive value. Example ranges to select a sensible value
from:
For IBM z13: [0.8, 1.3]
For IBM z15: [1.1, 1.5]
.TP
.BR "\-n <ITERATIONS>" " or " "\-\-iterations=<ITERATIONS>"
Specifies the maximum number of iterations before ending.
@@ -119,6 +131,7 @@ The following fields are available under LPAR:
In "sys_list" and "sys" window:
'c' - Core dispatch time per second
'e' - Thread time per second
'S' - Real CPU SMT utilization
'm' - Management time per second
'C' - Total core dispatch time
'E' - Total thread time

View File

@@ -22,6 +22,7 @@
#include "table.h"
#define HYPTOP_OPT_DEFAULT_DELAY 2
#define HYPTOP_OPT_DEFAULT_SMT_SCALE 1.3
#define HYPTOP_MAX_WIN_DEPTH 4
#define HYPTOP_MAX_LINE 512
#define PROG_NAME "hyptop"
@@ -60,6 +61,8 @@ struct hyptop_opts {
int delay_s;
int delay_us;
double smt_factor;
};
/*

View File

@@ -39,6 +39,7 @@ static char HELP_TEXT[] =
"-t, --cpu_types TYPE[,..] CPU types used for time calculations\n"
"-b, --batch_mode Use batch mode (no curses)\n"
"-d, --delay SECONDS Delay time between screen updates\n"
"-m, --smt_factor FACTOR Machine generation dependent SMT speedup factor.\n"
"-n, --iterations NUMBER Number of iterations before ending\n";
/*
@@ -48,6 +49,7 @@ static void l_init_defaults(void)
{
g.prog_name = PROG_NAME;
g.o.delay_s = HYPTOP_OPT_DEFAULT_DELAY;
g.o.smt_factor = HYPTOP_OPT_DEFAULT_SMT_SCALE;
g.w.cur = &win_sys_list;
g.o.cur_win = &win_sys_list;
}
@@ -108,6 +110,20 @@ static void l_delay_set(char *delay_string)
g.o.delay_us = 0;
}
/*
* Set SMT factor option
*/
static void l_factor_set(char *value_string)
{
double factor;
if (sscanf(value_string, "%lf", &factor) != 1)
ERR_EXIT("The SMT factor \"%s\" is invalid\n", value_string);
if (factor <= 0)
ERR_EXIT("The SMT factor \"%s\" is <= 0\n", value_string);
g.o.smt_factor = factor;
}
/*
* Get number of occurrences of character 'c' in "str"
*/
@@ -299,6 +315,7 @@ void opts_parse(int argc, char *argv[])
{ "help", no_argument, NULL, 'h'},
{ "batch_mode", no_argument, NULL, 'b'},
{ "delay", required_argument, NULL, 'd'},
{ "smt_factor", required_argument, NULL, 'm'},
{ "window", required_argument, NULL, 'w'},
{ "sys", required_argument, NULL, 's'},
{ "iterations", required_argument, NULL, 'n'},
@@ -307,7 +324,7 @@ void opts_parse(int argc, char *argv[])
{ "cpu_types", required_argument, NULL, 't'},
{ NULL, 0, NULL, 0 }
};
static const char option_string[] = "vhbd:w:s:n:f:t:S:";
static const char option_string[] = "vhbd:m:w:s:n:f:t:S:";
l_init_defaults();
while (1) {
@@ -328,6 +345,9 @@ void opts_parse(int argc, char *argv[])
case 'd':
l_delay_set(optarg);
break;
case 'm':
l_factor_set(optarg);
break;
case 'w':
l_window_set(optarg);
break;

View File

@@ -200,6 +200,7 @@ struct sd_cpu {
struct sd_cpu_info *d_cur;
struct sd_cpu_info *d_prev;
u16 cnt;
int threads_per_core;
enum sd_cpu_state state;
};
@@ -232,6 +233,11 @@ static inline void sd_cpu_cpu_time_us_set(struct sd_cpu *cpu, u64 value)
cpu->d_cur->cpu_time_us = value;
}
static inline void sd_cpu_threads_per_core_set(struct sd_cpu *cpu, int value)
{
cpu->threads_per_core = value;
}
static inline void sd_cpu_thread_time_us_set(struct sd_cpu *cpu, u64 value)
{
cpu->d_cur->thread_time_us = value;
@@ -335,6 +341,7 @@ extern struct sd_cpu_item sd_cpu_item_state;
extern struct sd_cpu_item sd_cpu_item_cpu_diff;
extern struct sd_cpu_item sd_cpu_item_core_diff;
extern struct sd_cpu_item sd_cpu_item_thread_diff;
extern struct sd_cpu_item sd_cpu_item_smt_diff;
extern struct sd_cpu_item sd_cpu_item_mgm_diff;
extern struct sd_cpu_item sd_cpu_item_wait_diff;
extern struct sd_cpu_item sd_cpu_item_steal_diff;
@@ -398,6 +405,7 @@ static inline char *sd_sys_item_str(struct sd_sys *sys,
extern struct sd_sys_item sd_sys_item_cpu_cnt;
extern struct sd_sys_item sd_sys_item_core_cnt;
extern struct sd_sys_item sd_sys_item_thread_cnt;
extern struct sd_sys_item sd_sys_item_smt_diff;
extern struct sd_sys_item sd_sys_item_cpu_oper_cnt;
extern struct sd_sys_item sd_sys_item_cpu_deconf_cnt;
extern struct sd_sys_item sd_sys_item_cpu_stop_cnt;

View File

@@ -98,6 +98,18 @@ static u64 l_cpu_item_64(struct sd_cpu_item *item, struct sd_cpu *cpu)
return l_cpu_info_u64(cpu->d_cur, item->offset) / cpu->cnt;
}
static u64 l_cpu_smt_util(struct sd_cpu_item *item, struct sd_cpu *cpu)
{
u64 core_us, thr_us, mgm_us;
(void)item;
core_us = sd_cpu_item_u64(&sd_cpu_item_core_diff, cpu);
thr_us = sd_cpu_item_u64(&sd_cpu_item_thread_diff, cpu);
mgm_us = sd_cpu_item_u64(&sd_cpu_item_mgm_diff, cpu);
return ht_calculate_smt_util(core_us, thr_us, mgm_us, cpu->threads_per_core);
}
/*
* CPU item definitions
*/
@@ -139,6 +151,13 @@ struct sd_cpu_item sd_cpu_item_thread_diff = {
.fn_u64 = l_cpu_diff_u64,
};
struct sd_cpu_item sd_cpu_item_smt_diff = {
.table_col = TABLE_COL_TIME_DIFF_SUM(table_col_unit_perc, 'S', "smt"),
.type = SD_TYPE_U64,
.desc = "Real CPU SMT utilization",
.fn_u64 = l_cpu_smt_util,
};
struct sd_cpu_item sd_cpu_item_mgm_diff = {
.table_col = TABLE_COL_TIME_DIFF_SUM(table_col_unit_perc, 'm', "mgm"),
.type = SD_TYPE_U64,

View File

@@ -208,6 +208,18 @@ static s64 l_sys_cpu_info_diff_s64(struct sd_sys_item *item, struct sd_sys *sys)
return rc;
}
static u64 l_sys_smt_util(struct sd_sys_item *item, struct sd_sys *sys)
{
u64 core_us, thr_us, mgm_us;
(void)item;
core_us = sd_sys_item_u64(sys, &sd_sys_item_core_diff);
thr_us = sd_sys_item_u64(sys, &sd_sys_item_thread_diff);
mgm_us = sd_sys_item_u64(sys, &sd_sys_item_mgm_diff);
return ht_calculate_smt_util(core_us, thr_us, mgm_us, sys->threads_per_core);
}
/*
* System item definitions
*/
@@ -277,6 +289,13 @@ struct sd_sys_item sd_sys_item_thread_diff = {
.fn_u64 = l_sys_cpu_info_diff_u64,
};
struct sd_sys_item sd_sys_item_smt_diff = {
.table_col = TABLE_COL_TIME_DIFF_SUM(table_col_unit_perc, 'S', "smt"),
.type = SD_TYPE_U64,
.desc = "Real CPU SMT utilization",
.fn_u64 = l_sys_smt_util,
};
struct sd_sys_item sd_sys_item_mgm_diff = {
.table_col = TABLE_COL_TIME_DIFF_SUM(table_col_unit_perc, 'm', "mgm"),
.offset = SD_CPU_INFO_OFFSET(mgm_time_us),

View File

@@ -34,10 +34,10 @@
/* Secure IPL error */
#define ESECUREBOOT 0x00004512
/* kdump: No operating system information was found */
/* os_info error: No operating system information was found */
#define EOS_INFO_MISSING 0x00004520
/* kdump: The checksum of the operating system information is incorrect */
/* os_info error: The checksum of the operating system information is incorrect */
#define EOS_INFO_CSUM_FAILED 0x00004521
/* kdump: The major version of the operating system information is too high */

View File

@@ -21,10 +21,6 @@
#define IPL_MAX_SUPPORTED_VERSION 0
#define IPL_PARM_BLOCK_VERSION 0x1
/* IPL Types */
#define IPL_TYPE_PV 0x5
#ifndef __ASSEMBLER__
#include <stdint.h>
@@ -43,6 +39,16 @@ struct ipl_pb_hdr {
uint8_t pbt;
} __packed;
/* IPL Parameter Block types */
enum ipl_pbt {
IPL_PBT_FCP = 0,
IPL_PBT_SCP_DATA = 1,
IPL_PBT_CCW = 2,
IPL_PBT_ECKD = 3,
IPL_PBT_NVME = 4,
IPL_PBT_PV = 5,
};
/* IPL Parameter Block 0 with common fields */
struct ipl_pb0_common {
uint32_t len;

View File

@@ -22,11 +22,19 @@
#define STAGE2_DESC _AC(0x78, UL)
#define STAGE2_ENTRY _AC(0x2018, UL)
#define STAGE2_HEAP_ADDRESS _AC(0x6000, UL)
#define ECKD2DUMP_SV_HEAP_ADDRESS _AC(0xb000, UL)
#define STAGE2_HEAP_SIZE _AC(0x3000, UL)
#define STAGE2_STACK_ADDRESS _AC(0xe400, UL)
#define STAGE2_STACK_SIZE _AC(0x1c00, UL)
#define ECKD2DUMP_SV_STACK_ADDRESS _AC(0xe000, UL)
#define ECKD2DUMP_SV_STACK_SIZE _AC(0x2000, UL)
#define STAGE2_MAX_SIZE _AC(0x3000, UL)
#define STAGE2_DUMPER_SIZE_V1 _AC(0x1000, UL)
#define STAGE2_DUMPER_SIZE_V2 _AC(0x2000, UL)
#define STAGE2_DUMPER_SIZE_V3 _AC(0x3000, UL)
#define STAGE2_DUMPER_SIZE_ZLIB _AC(0x8000, UL)
#define STAGE3_ENTRY _AC(0xa000, UL)
#define STAGE2_LOAD_ADDRESS _AC(0x2000, UL)

92
include/boot/os_info.h Normal file
View File

@@ -0,0 +1,92 @@
/*
* zipl - zSeries Initial Program Loader tool
*
* os-info definitions
*
* 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.
*/
#ifndef OS_INFO_H
#define OS_INFO_H
#include "lib/zt_common.h"
#include "boot/error.h"
#include "boot/s390.h"
#include <stdint.h>
#define OS_INFO_MAGIC 0x4f53494e464f535aULL /* OSINFOSZ */
#define OS_INFO_CSUM_SIZE (sizeof(struct os_info) - offsetof(struct os_info, version_major))
#define OS_INFO_FLAGS_ENTRY_SIZE (sizeof(unsigned long))
#define OS_INFO_VMCOREINFO 0
#define OS_INFO_REIPL_BLOCK 1
#define OS_INFO_FLAGS_ENTRY 2
#define OS_INFO_RESERVED 3
#define OS_INFO_IDENTITY_BASE 4
#define OS_INFO_KASLR_OFFSET 5
#define OS_INFO_KASLR_OFF_PHYS 6
#define OS_INFO_VMEMMAP 7
#define OS_INFO_AMODE31_START 8
#define OS_INFO_AMODE31_END 9
#define OS_INFO_IMAGE_START 10
#define OS_INFO_IMAGE_END 11
#define OS_INFO_IMAGE_PHYS 12
#define OS_INFO_MAX 13
#define OS_INFO_FLAG_REIPL_CLEAR (1UL << 0)
struct os_info_entry {
union {
uint64_t addr;
uint64_t val;
};
uint64_t size;
uint32_t csum;
} __packed;
struct os_info {
uint64_t magic;
uint32_t csum;
uint16_t version_major;
uint16_t version_minor;
uint64_t crashkernel_addr;
uint64_t crashkernel_size;
struct os_info_entry entry[OS_INFO_MAX];
uint8_t reserved[3804];
} __packed;
/*
* Return 0 in case of valid os_info
* Return -EOS_INFO_MISSING if os_info address is not page aligned or page is
* not accessible or os_info magic value is missing.
* Return -EOS_INFO_CSUM_FAILED if os_info checksum is invalid.
*/
static inline int os_info_check(const struct os_info *os_info)
{
if (!os_info ||
(unsigned long)os_info % PAGE_SIZE ||
!page_is_valid((unsigned long)os_info) ||
os_info->magic != OS_INFO_MAGIC)
return -EOS_INFO_MISSING;
if (os_info->csum != csum_partial(&os_info->version_major, OS_INFO_CSUM_SIZE, 0))
return -EOS_INFO_CSUM_FAILED;
return 0;
}
/*
* Return 1 in case of valid os_info_entry, otherwise 0
* Make sure that the entire os_info structure is checked first with os_info_check().
*/
static inline int os_info_entry_is_valid(const struct os_info_entry *entry)
{
return (entry &&
entry->addr &&
entry->size &&
page_is_valid(entry->addr) &&
entry->csum == csum_partial((void *)entry->addr, entry->size, 0));
}
#endif /* OS_INFO_H */

View File

@@ -25,6 +25,7 @@
#define STACK_FRAME_OVERHEAD _AC(160, U)
/* Facilities */
#define DFLTCC_FACILITY _AC(151, U)
#define UNPACK_FACILITY _AC(161, U)
#ifndef __ASSEMBLER__
@@ -285,18 +286,21 @@ static __always_inline void __ctl_set_bit(unsigned int cr, unsigned int bit)
* DIAG 308 support
*/
enum diag308_subcode {
DIAG308_REL_HSA = 2,
DIAG308_IPL = 3,
DIAG308_DUMP = 4,
DIAG308_SET = 5,
DIAG308_STORE = 6,
DIAG308_CLEAR_RESET = 0,
DIAG308_LOAD_NORMAL_RESET = 1,
DIAG308_REL_HSA = 2,
DIAG308_LOAD_CLEAR = 3,
DIAG308_LOAD_NORMAL_DUMP = 4,
DIAG308_SET = 5,
DIAG308_STORE = 6,
DIAG308_LOAD_NORMAL = 7,
DIAG308_SET_PV = 8,
DIAG308_UNPACK_PV = 10,
};
enum diag308_rc {
DIAG308_RC_OK = 0x0001,
DIAG308_RC_NO_CONF = 0x0102,
DIAG308_RC_NOCONFIG = 0x0102,
};
static __always_inline unsigned long diag308(unsigned long subcode, void *addr)

145
include/dump/s390_dump.h Normal file
View File

@@ -0,0 +1,145 @@
/*
* s390 related definitions and functions.
*
* 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.
*/
#ifndef S390_DUMP_H
#define S390_DUMP_H
#include <stdint.h>
#include "boot/page.h"
#include "lib/zt_common.h"
/*
* S390 dump format defines
*/
#define DF_S390_MAGIC 0xa8190173618f23fdULL
#define DF_S390_MAGIC_EXT 0xa8190173618f23feULL
#define DF_S390_HDR_SIZE 0x1000
#define DF_S390_EM_SIZE 16
#define DF_S390_EM_MAGIC 0x44554d505f454e44ULL
#define DF_S390_EM_STR "DUMP_END"
#define DF_S390_CPU_MAX 512
#define DF_S390_MAGIC_BLK_ECKD 3
#define DF_S390_DUMPER_MAGIC_SIZE 7
#define DF_S390_DUMPER_MAGIC32 "ZECKD31"
#define DF_S390_DUMPER_MAGIC64 "ZECKD64"
#define DF_S390_DUMPER_MAGIC_EXT "XECKD64"
#define DF_S390_DUMPER_MAGIC32_FBA "ZDFBA31"
#define DF_S390_DUMPER_MAGIC64_FBA "ZDFBA64"
#define DF_S390_DUMPER_MAGIC_FBA_EXT "XDFBA64"
#define DF_S390_DUMPER_MAGIC_MV "ZMULT64"
#define DF_S390_DUMPER_MAGIC_MV_EXT "XMULT64"
#define OLD_DUMPER_HEX_INSTR1 "\x0d\x10\x47\xf0" /* BASR + 1st halfword of BC */
#define OLD_DUMPER_HEX_INSTR2 "\x0d\xd0" /* BASR 13,0 */
/*
* Architecture of dumped system
*/
enum df_s390_arch {
DF_S390_ARCH_32 = 1,
DF_S390_ARCH_64 = 2,
};
/*
* zipl parameters passed at tail of dump tools
*/
struct stage2dump_parm_tail {
char reserved[6];
uint8_t no_compress;
uint8_t mvdump_force;
uint64_t mem_upper_limit;
} __packed;
/*
* s390 dump header format
*/
struct df_s390_hdr {
uint64_t magic; /* 0x000 */
uint32_t version; /* 0x008 */
uint32_t hdr_size; /* 0x00c */
uint32_t dump_level; /* 0x010 */
uint32_t page_size; /* 0x014 */
uint64_t mem_size; /* 0x018 */
uint64_t mem_start; /* 0x020 */
uint64_t mem_end; /* 0x028 */
uint32_t num_pages; /* 0x030 */
uint32_t pad; /* 0x034 */
uint64_t tod; /* 0x038 */
uint64_t cpu_id; /* 0x040 */
uint32_t arch; /* 0x048 */
uint32_t volnr; /* 0x04c */
uint32_t build_arch; /* 0x050 */
uint64_t mem_size_real; /* 0x054 */
uint8_t mvdump; /* 0x05c */
uint16_t cpu_cnt; /* 0x05d */
uint16_t real_cpu_cnt; /* 0x05f */
uint8_t zlib_version_s390; /* 0x061 */
uint32_t zlib_entry_size; /* 0x062 */
uint8_t end_pad1[0x200 - 0x066]; /* 0x066 */
uint64_t mvdump_sign; /* 0x200 */
uint64_t mvdump_zipl_time; /* 0x208 */
uint8_t end_pad2[0x800 - 0x210]; /* 0x210 */
uint32_t lc_vec[DF_S390_CPU_MAX]; /* 0x800 */
} __packed __aligned(16);
/*
* End marker: Should be at the end of every valid s390 crash dump
*/
struct df_s390_em {
union {
uint64_t magic;
char str[8];
};
uint64_t tod;
} __packed __aligned(16);
/*
* Dump segment header
*/
struct df_s390_dump_segm_hdr {
union {
struct {
uint64_t start; /* 0x000 */
uint64_t len; /* 0x008 */
uint64_t stop_marker; /* 0x010 */
/* Size in blocks of compressed dump segment written to disk */
uint32_t size_on_disk; /* 0x018 */
uint8_t reserved_pad[0x30 - 0x1c]; /* 0x01c */
/*
* Number of compressed entries in this dump segment (up to
* 1011 entries)
*/
uint32_t entry_count; /* 0x030 */
/*
* Offsets in blocks to compressed entries written to disk
* from the start of the dump segment.
* High-order bit is set if the entry has been written
* uncompressed.
*/
uint32_t entry_offset[]; /* 0x034 */
} __packed;
uint8_t padding[PAGE_SIZE];
};
};
/* Data compression granularity (size of input data chunk for zlib deflate) */
#define DUMP_SEGM_ZLIB_ENTSIZE (1 * MIB)
/* Maximum number of compressed entries in one dump segment */
#define DUMP_SEGM_ZLIB_MAXENTS ((sizeof(struct df_s390_dump_segm_hdr) \
- offsetof(struct df_s390_dump_segm_hdr, entry_offset)) \
/ sizeof(uint32_t))
/*
* Maximum length of compressed dump segment considering the size of
* a single input chunk
*/
#define DUMP_SEGM_ZLIB_MAXLEN (DUMP_SEGM_ZLIB_MAXENTS * DUMP_SEGM_ZLIB_ENTSIZE)
/* Bitmask to mark uncompressed chunks */
#define DUMP_SEGM_ENTRY_UNCOMPRESSED 0x80000000
#endif /* S390_DUMP_H */

View File

@@ -21,7 +21,9 @@
#define AP_UDEV_FILE "/etc/udev/rules.d/41-ap.rules"
#define AP_LOCKFILE "/run/lock/s390apconfig.lock"
#define AP_LOCK_RETRIES 15
#define AP_LOCK_RETRIES 3000
#define AP_LOCK_DELAY_US 30000 /* wait at least 30ms between lock retries */
#define AP_LOCK_VARIANCE_US 3000 /* or as much as 33ms */
/* apmask and aqmask are each represented as 67 character strings with:
* '0x' leading characters
@@ -89,6 +91,7 @@ void ap_list_remove_all(struct util_list *list);
/* Lock Functions */
int ap_get_lock(void);
int ap_get_lock_callout(void);
int ap_try_lock_callout(void);
int ap_release_lock(void);
int ap_release_lock_callout(void);

View File

@@ -27,6 +27,7 @@ enum util_arch_machine_type {
UTIL_ARCH_MACHINE_TYPE_Z15 = 8561,
UTIL_ARCH_MACHINE_TYPE_Z15_T02 = 8562,
UTIL_ARCH_MACHINE_TYPE_Z16 = 3931,
UTIL_ARCH_MACHINE_TYPE_Z16_A02 = 3932,
};
int util_arch_machine_type(void);

View File

@@ -14,7 +14,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "zt_common.h"
#include "lib/util_libc.h"
void util_hexdump(FILE *fh, const char *tag, const void *data, int cnt);
void util_hexdump_grp(FILE *fh, const char *tag, const void *data, int group,
@@ -37,4 +40,30 @@ static inline void util_ptr_vec_free(void **ptr_vec, int count)
free(ptr_vec);
}
/*
* Expand size of dynamic array (element_t *) by one element
*
* @param[in,out] array Pointer to array (element_t **)
* @param[in,out] num Pointer to integer containing number of elements
*/
#define util_expand_array(array, num) \
do { \
unsigned int __size = sizeof(*(*(array))); \
*(array) = util_realloc(*(array), ++(*(num)) * __size); \
memset(&((*(array))[*(num) - 1]), 0, __size); \
} while (0)
/*
* Append one element to dynamic array (element_t *)
*
* @param[in,out] array Pointer to array (element_t **)
* @param[in,out] num Pointer to integer containing number of elements
* @param[in] element Element to add (element_t)
*/
#define util_add_array(array, num, element) \
do { \
util_expand_array(array, num); \
(*(array))[*(num) - 1] = (element) ; \
} while (0)
#endif /* LIB_UTIL_BASE_H */

235
include/lib/util_fmt.h Normal file
View File

@@ -0,0 +1,235 @@
/*
* util_fmt - Format structured key-value data as JSON, text pairs, or CSV
*
* Copyright IBM Corp. 2024
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*
* This module provides helper functions for converting structured key-value
* data into different output formats.
*
* Benefits:
* - Output format can be dynamically configured at run-time
* - Callers do not need to add extra code for each output format
* - Some format-specific requirements such as quoting, indentation, and
* comma-placement are automated
*
* Basic API calling sequence:
*
* util_fmt_init() => Select output format
* util_fmt_obj_start() => Start a new object or list
* util_fmt_pair() => Emit a key-value pair
* util_fmt_obj_end() => End the latest object or list
* util_fmt_exit() => Cleanup
*
* Note:
* - Supported data elements are objects, lists and key-value pairs (mappings)
* - Scalars are only supported as part of a mapping
* - For CSV output and key filtering, mapping keys must be unique - this can
* be achieved either by choosing unique key names or by including object
* names via the FMT_PREFIX flag
* - For CSV output, at least one object or list with the FMT_ROW flag must be
* emitted
* - Common tool-specific meta-information such as API-level, tool version,
* etc. is automatically added to the output
*/
#ifndef LIB_UTIL_FMT_H
#define LIB_UTIL_FMT_H
#include <stdbool.h>
#include <stdio.h>
/* Flag value for default behavior (all flag types). */
#define FMT_DEFAULT 0
/* Names of supported output format types. */
#define FMT_TYPE_NAMES "json json-seq pairs csv"
/**
* enum util_fmt_t - Output format types.
* @FMT_JSON: JavaScript Object Notation output data structure
* @FMT_JSONSEQ: Sequence of JSON data structures according to RFC7464
* @FMT_PAIRS: Textual key=value pairs
* @FMT_CSV: Comma-separated-values output
*
* Use these types with util_fmt_init() to control the output format.
*/
enum util_fmt_t {
FMT_JSON,
FMT_JSONSEQ,
FMT_PAIRS,
FMT_CSV,
};
/**
* enum util_fmt_flags_t - Format control flags.
* @FMT_NOPREFIX: (pairs) Remove object hierarchy prefix from keys
* @FMT_KEEPINVAL: (all) Print mappings even if value is marked as invalid
* Values will be replaced with null (JSON) or an empty
* string
* @FMT_QUOTEALL: (all) Add quotes to all mapping values
* @FMT_FILTER: (all) Ignore keys not announced via util_fmt_add_key()
* @FMT_HANDLEINT: (json) Ensure correct JSON closure when interrupted
* @FMT_NOMETA: (all) Do not emit tool meta-data
* @FMT_WARN: (all) Warn about incorrect API usage
*
* Use these flags with util_fmt_init() to control generic aspects.
*/
enum util_fmt_flags_t {
FMT_NOPREFIX = (1 << 0),
FMT_KEEPINVAL = (1 << 1),
FMT_QUOTEALL = (1 << 2),
FMT_FILTER = (1 << 3),
FMT_HANDLEINT = (1 << 4),
FMT_NOMETA = (1 << 5),
FMT_WARN = (1 << 6),
};
/**
* enum util_fmt_oflags_t - Object flags.
* @FMT_LIST: (all) Object is a list
* @FMT_ROW: (csv) Start a new CSV row with this object
* @FMT_PREFIX: (all) Include object name in key prefix for CSV headings
* and filter keys
*
* Use these flags with util_fmt_obj_start() to control object related
* aspects.
*/
enum util_fmt_oflags_t {
FMT_LIST = (1 << 0),
FMT_ROW = (1 << 1),
FMT_PREFIX = (1 << 2),
};
/**
* enum util_fmt_mflags_t - Mapping flags.
* @FMT_QUOTE: (all) Quote value
* @FMT_INVAL: (all) Mark value as invalid
* @FMT_PERSIST: (csv) Keep value across CSV rows until overwritten
*
* Use these flags with util_fmt_pair() to control mapping related aspects.
*/
enum util_fmt_mflags_t {
FMT_QUOTE = (1 << 0),
FMT_INVAL = (1 << 1),
FMT_PERSIST = (1 << 2),
};
/**
* util_fmt_init() - Initialize output formatter.
* @fd : Output file descriptor
* @type : Output format type
* @flags: Formatting parameters
* @api_level: Output format level indicator
*
* Prepare for writing formatted output with the given @type to @fd. Additional
* @flags can be specified to control certain output aspects (see &enum
* util_fmt_flags_t).
*
* @api_level represents an application-specific output format version number:
* this number starts at 1 and must be increased whenever an incompatible format
* change is introduced, e.g. when a non-optional object or mapping is removed
* or used for different data.
*/
void util_fmt_init(FILE *fd, enum util_fmt_t type, unsigned int flags,
int api_level);
/**
* util_fmt_exit() - Release resources used by output formatter.
*
* Release all resources currently in use by the output formatter.
*/
void util_fmt_exit(void);
/**
* util_fmt_name_to_type() - Convert format name to type identifier.
* @name: Format name
* @type: Pointer to resulting format type identifier
*
* Search supported output format types for a type with associated @name. If
* found, store resulting type identifier in @type.
*
* Return: %true if type is found, %false otherwise.
*/
bool util_fmt_name_to_type(const char *name, enum util_fmt_t *type);
/**
* util_fmt_set_indent() - Set indentation parameters.
* @base : Base indentation level to apply to all output lines (default 0)
* @width : Number of indentation characters per intendation level (default 2)
* @ind_char: Indentation characters to use (default space).
*/
void util_fmt_set_indent(unsigned int base, unsigned int width, char ind_char);
/**
* util_fmt_add_key() - Register expected mapping keys.
* @fmt: Format string to generate key
*
* Register a mapping key before the associated key-value pair is emitted.
*
* Use this function together with format control flag @FMT_FILTER to ignore all
* key-value pairs for which the key has not been registered. This can be
* useful to allow for dynamically configured filtering of output based on
* a static list of emitted mappings.
*
* When creating CSV output, use this function to register all column keys
* in advance to enable a stable column list in case of rows that do not
* provide data for all columns.
*/
void util_fmt_add_key(const char *fmt, ...);
/**
* util_fmt_obj_start() - Start a new data object.
* @oflags: Flags controlling aspects of this object.
* @fmt : Format string for generating an object name or %NULL.
*
* Use this function to start a new object in output data. Depending on
* @oflags, the new object represents either a normal object or a list. @oflags
* can also be used to indicated that an object corresponds to a new row of
* CSV data. If @fmt is non-%NULL, the resulting name is used in a format
* type specified way:
*
* Pairs:
* - Object names are reflected as dot-separated component in the mapping
* prefix, e.g. 'a.b.key=value'
* - An index is generated for mappings and objects that are part of list,
* e.g. 'a.b[1].key=value'
* JSON:
* - Object names are reflected as key-object mappings, e.g.
* <name>: { }
* - Required commas between objects and mappings are automatically generated
* CSV:
* - Object names and the list type flag have no effect
* - When flag @FMT_ROW is specified, a CSV row will be emitted when
* util_fmt_obj_end() is called for the associated object
*/
void util_fmt_obj_start(unsigned int oflags, const char *fmt, ...);
/**
* util_fmt_obj_end() - Announce the end of the latest data object started.
*
* Each object started with util_fmt_obj_start() must be ended with an
* associated util_fmt_obj_end() call.
*/
void util_fmt_obj_end(void);
/**
* util_fmt_pair() - Emit a key-value pair.
* @mflags: Flags controlling this pair.
* @key : Key for this pair, excluding prefix.
* @fmt : Format string used to generated the pair value.
*
* Emit a key-value pair with the specified @key and the value that results
* from format string @fmt.
*
* Notes:
* - For JSON, a mapping can only occur after util_fmt_obj_start()
* - For CSV, each @key must be unique, either by choosing unique key names
* or by including object names as prefix via the use of FMT_PREFIX in
* parent objects
*/
void util_fmt_pair(unsigned int mflags, const char *key, const char *fmt, ...);
#endif /* LIB_UTIL_FMT_H */

View File

@@ -127,6 +127,7 @@ do { \
int __util_vsprintf(const char *func, const char *file, int line,
char *str, const char *fmt, va_list ap);
char *util_strcat_realloc(char *str1, const char *str2);
void util_concatf(char **str1, const char *fmt, ...);
void util_str_toupper(char *str);
char *util_strstrip(char *s);

View File

@@ -18,9 +18,15 @@
#define UTIL_LOCKFILE_ERR 4 /* Other, unexpected error conditions */
int util_lockfile_lock(char *lockfile, int retries);
int util_lockfile_lock_cw(char *lockfile, int retries, unsigned int waitinc,
unsigned int maxwait);
int util_lockfile_parent_lock(char *lockfile, int retries);
int util_lockfile_parent_lock_cw(char *lockfile, int retries,
unsigned int waitinc, unsigned int maxwait);
int util_lockfile_release(char *lockfile);
int util_lockfile_parent_release(char *lockfile);
int util_lockfile_peek_owner(char *lockfile, int *pid);
#endif /** LIB_UTIL_LOCKFILE_H @} */

View File

@@ -40,6 +40,7 @@
#define LV_COMPAT_CYL 0xFFFE
#define VTOC_ERROR "VTOC error:"
#define MAX_VTOC_ENTRIES 9 /* max number of VTOC labels for cdl formatted DASD */
typedef struct ttr
{

View File

@@ -1,439 +0,0 @@
/*
* Certificate functions and definitions.
*
* 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 LIBPV_CERT_H
#define LIBPV_CERT_H
#include <openssl/x509v3.h>
#include <openssl/err.h>
#include "libpv/common.h"
#define PV_IBM_Z_SUBJECT_COMMON_NAME "International Business Machines Corporation"
#define PV_IBM_Z_SUBJECT_COUNTRY_NAME "US"
#define PV_IBM_Z_SUBJECT_LOCALITY_NAME "Poughkeepsie"
#define PV_IBM_Z_SUBJECT_ORGANIZATIONAL_UNIT_NAME_SUFFIX "Key Signing Service"
#define PV_IBM_Z_SUBJECT_ORGANIZATION_NAME "International Business Machines Corporation"
#define PV_IBM_Z_SUBJECT_STATE "New York"
#define PV_IMB_Z_SUBJECT_ENTRY_COUNT 6
/* Minimum security level for the keys/certificates used to establish a chain of
* trust (see https://www.openssl.org/docs/man1.1.1/man3/X509_VERIFY_PARAM_set_auth_level.html
* for details).
*/
#define PV_CERTS_SECURITY_LEVEL 2
/** pv_cert_init:
*
* Should not be called by user.
* Use pv_init() instead which
* calls this function during creation.
*
* Sets up data structures for caching CRLs.
*/
void pv_cert_init(void);
/** pv_cert_cleanup:
*
* Should not be called by user.
* Use pv_cleanup() instead which
* calls this function during creation.
*
* Cleans up data structures for caching CRLs.
*/
void pv_cert_cleanup(void);
#define PV_CERT_ERROR g_quark_from_static_string("pv-cert-error-quark")
typedef enum {
PV_CERT_ERROR_CERT_REVOKED,
PV_CERT_ERROR_CERT_SIGNATURE_INVALID,
PV_CERT_ERROR_CERT_SUBJECT_ISSUER_MISMATCH,
PV_CERT_ERROR_CRL_DOWNLOAD_FAILED,
PV_CERT_ERROR_CRL_SIGNATURE_INVALID,
PV_CERT_ERROR_CRL_SUBJECT_ISSUER_MISMATCH,
PV_CERT_ERROR_FAILED_DOWNLOAD_CRL,
PV_CERT_ERROR_INTERNAL,
PV_CERT_ERROR_INVALID_PARM,
PV_CERT_ERROR_INVALID_SIGNATURE_ALGORITHM,
PV_CERT_ERROR_INVALID_VALIDITY_PERIOD,
PV_CERT_ERROR_LOAD_CRL,
PV_CERT_ERROR_LOAD_DEFAULT_CA,
PV_CERT_ERROR_LOAD_ROOT_CA,
PV_CERT_ERROR_MALFORMED_CERTIFICATE,
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,
PV_CERT_ERROR_READ_CRL,
PV_CERT_ERROR_SIGNATURE_ALGORITHM_MISMATCH,
PV_CERT_ERROR_SKID_AKID_MISMATCH,
PV_CERT_ERROR_VERIFICATION_FAILED,
PV_CERT_ERROR_WRONG_CA_USED,
} PvCertErrors;
/** PvX509WithPath - X509 certificate associated with a path
*/
typedef struct {
X509 *cert;
char *path;
} PvX509WithPath;
/** pv_x509_with_path_new:
*
* @cert: X509 certificate
* @path: Path of that X509 certificate
*
* Returns: (nullable) (transfer full): new X509 with path
*/
PvX509WithPath *pv_x509_with_path_new(X509 *cert, const char *path);
/** pv_x509_with_path_free:
*
* Frees the path and the PvX509WithPath; Decreases the refcount of the X509
*/
void pv_x509_with_path_free(PvX509WithPath *cert);
typedef STACK_OF(DIST_POINT) STACK_OF_DIST_POINT;
typedef STACK_OF(X509) STACK_OF_X509;
typedef STACK_OF(X509_CRL) STACK_OF_X509_CRL;
typedef GSList PvCertWithPathList;
typedef struct {
X509 *cert;
STACK_OF_X509_CRL *crls;
} PvX509Pair;
/** pv_x509_pair_new_take:
* @cert: ptr to X509
* @crls: ptr to CRLs
*
* Takes a X509 and the associated CRLs and builds a pair.
* Both, *cert and *crls will be NULL afterwards, and owned by the pair.
*
* Returns: (nullable) (transfer full): New PvX509Pair
*/
PvX509Pair *pv_x509_pair_new_take(X509 **cert, STACK_OF_X509_CRL **crls);
/** pv_x509_pair_free:
*
* Decreases the refcount of the X509 and crls.
* Frees the PvX509Pair.
*/
void pv_x509_pair_free(PvX509Pair *pair);
void STACK_OF_DIST_POINT_free(STACK_OF_DIST_POINT *stack);
void STACK_OF_X509_free(STACK_OF_X509 *stack);
void STACK_OF_X509_CRL_free(STACK_OF_X509_CRL *stack);
/** pv_x509_from_pem_der_data:
*
* @data: GBytes containing the cert in PEM format
* @error: return location for a #GError
*
* Returns: (nullable) (transfer full): X509 cert
*/
X509 *pv_x509_from_pem_der_data(GBytes *data, GError **error);
/** pv_x509_get_ec_pubkey:
*
* @cert: X509 to extract elliptic curve pubkey from
* @nid: numerical identifier of the expected curve
* @error: return location for a #GError
*
* Returns: (nullable) (transfer full): corresponding pupkey for the given certificate
*/
EVP_PKEY *pv_x509_get_ec_pubkey(X509 *cert, int nid, GError **error);
/** pv_get_ec_pubkeys:
*
* @certs_with_path: List of PvX509WithPath
* @nid: numerical identifier of the expected curve
* @error: return location for a #GError
*
* Returns: (nullable) (transfer full): List of corresponding public keys for the given certificate
*/
GSList *pv_get_ec_pubkeys(PvCertWithPathList *certs_with_path, int nid, GError **error);
/* pv_load_certificates:
*
* @cert_paths: list of cert paths.
* @error: return location for a #GError
*
* @cert_paths must contain at least one element, otherwise an error is
* reported.
*
* Returns: (nullable) (transfer full): List of PvX509WithPath corresponding to the given paths
*/
PvCertWithPathList *pv_load_certificates(char **cert_paths, GError **error);
/* pv_load_first_cert_from_file:
*
* @path: location of the x509
* @error: return location for a #GError
*
* This function reads in only the first certificate and ignores all other. This
* is only relevant for the PEM file format. For the host-key document and the
* root CA this behavior is expected.
*
* Returns: (nullable) (transfer full): PvX509WithPath corresponding to the given path
*/
X509 *pv_load_first_cert_from_file(const char *path, GError **error);
/* pv_load_first_crl_from_file:
*
* @path: location of the x509 CRL
* @error: return location for a #GError
*
* This function reads in only the first CRL and ignores all other. This
* is only relevant for the PEM file format.
*
* Returns: (nullable) (transfer full): X509_CRL corresponding to the given path
*/
X509_CRL *pv_load_first_crl_from_file(const char *path, GError **error);
/** pv_store_setup_crl_download:
*
* @st: X509_STORE
*/
void pv_store_setup_crl_download(X509_STORE *st);
/** pv_load_first_crl_by_cert:
* @cert: X509 to specify the download location.
* @error: return location for a #GError
*
* This function returns the first X509_CRL found from the CRL distribution
* points specified in @cert.
*
* Returns: (nullable) (transfer full): x509 CRL corresponding to the given X509
*/
X509_CRL *pv_load_first_crl_by_cert(X509 *cert, GError **error);
/** pv_try_load_crls_by_certs:
*
* @certs_with_path: List of PvX509WithPath
*
* Returns: (nullable) (transfer full): Stack of CRLs corresponding to the given X509
*/
STACK_OF_X509_CRL *pv_try_load_crls_by_certs(PvCertWithPathList *certs_with_path);
/** pv_store_setup:
*
* @root_ca_path: Location of the rootCA or NULL if SystemRoot CA shall be used
* @crl_paths: List of CRL paths or NULL
* @cert_with_crl_paths: List of (untrusted) X509 paths
* @error: return location for a #GError
*
* The untrusted certs need to be verified before actually verifying a Host Key Document.
*
* Returns: (nullable) (transfer full): X509_store with given input data.
*
*/
X509_STORE *pv_store_setup(char *root_ca_path, char **crl_paths, char **cert_with_crl_paths,
GError **error);
/** pv_get_x509_stack:
*
* x509_with_path_list: list of PvX509WithPath
*
* Returns: (nullable) (transfer full): Stack of X509 corresponding to the given x509 with path
*/
STACK_OF_X509 *pv_get_x509_stack(const GSList *x509_with_path_list);
/** pv_init_store_ctx:
*
* @ctx: a uninitialized Store CTX
* @trusted: X509_STORE with a trusted rootCA
* @chain: untrusted X509s
* @error: return location for a #GError
*
* Can be called multiple times on the same context if X509_STORE_CTX_cleanup(ctx)
* was called before.
*
* Returns:
* 0 on success
* -1 in failure
*/
int pv_init_store_ctx(X509_STORE_CTX *ctx, X509_STORE *trusted, STACK_OF_X509 *chain,
GError **error) PV_NONNULL(1, 2, 3);
/** pv_init_store_ctx:
*
* @trusted: X509_STORE with a trusted rootCA
* @chain: untrusted X509s
* @error: return location for a #GError
*
* Returns: (nullable) (transfer full): X509_STORE_CTX setup with the input data
*/
X509_STORE_CTX *pv_create_store_ctx(X509_STORE *trusted, STACK_OF_X509 *chain, GError **error)
PV_NONNULL(1, 2);
/** pv_remove_ibm_signing_certs:
*
* @certs: Stack of X509s
*
* Returns: (transfer full):
* List of all IBM Z signing key certificates in @certs and remove them
* from the chain.
* Empty stack if no IBM Z signing key is found.
*/
STACK_OF_X509 *pv_remove_ibm_signing_certs(STACK_OF_X509 *certs);
/** pv_c2b_name:
*
* Workaround to fix the mismatch between issuer name of the
* IBM Z signing CRLs and the IBM Z signing key subject name.
*
* In RFC 5280 the attributes of a (subject/issuer) name is not mandatory
* ordered. The problem is that our certificates are not consistent in the order
* (see https://tools.ietf.org/html/rfc5280#section-4.1.2.4 for details).
*
* This function tries to reorder the name attributes such that
* further OpenSSL calls can work with it. The caller is
* responsible to free the returned value.
*/
X509_NAME *pv_c2b_name(const X509_NAME *name);
/** pv_verify_host_key:
*
* @host_key: X509 to be verified
* @issuer_pairs: IBM signing key X509+CRLs Pairs used for verification
* @level: Security level. see PV_CERTS_SECURITY_LEVEL
* @error: return location for a #GError
*
* Returns:
* 0 if Host key could be verified with one of the IBM signing keys
* -1 if no IBM signing key could verify the authenticity of the given host key
*
*/
int pv_verify_host_key(X509 *host_key, GSList *issuer_pairs, int verify_flags, int level,
GError **error);
/** pv_verify_cert:
*
* @ctx: trusted store ctx used for verification
* @cert: X509 to be verified
* @error: return location for a #GError
*
* Cannot be used to verify host keys with IBM signing keys, as IBM signing
* keys are no intermediate CAs. Use pv_verify_host_key() instead.
*
* Returns:
* 0 if @cert could be verified
* -1 if @cert could not be verified
*/
int pv_verify_cert(X509_STORE_CTX *ctx, X509 *cert, GError **error) PV_NONNULL(1, 2);
/** pv_check_crl_valid_for_cert:
*
* @crl: CRL to be verified
* @cert: Cert that probably issued the given CRL
* @verify_flags: X509 Verification flags (X509_V_FLAG_<TYPE>)
* @error: return location for a #GError
*
* Verify whether a revocation list @crl is valid and is issued by @cert. For
* this multiple steps must be done:
*
* 1. verify issuer of the CRL matches with the suject name of @cert
* 2. verify the validity period of the CRL
* 3. verify the signature of the CRL
*
* Important: This function does not verify whether @cert is allowed to issue a
* CRL.
*
* Returns:
* 0 if @crl is valid and issued by @cert
* -1 otherwise
*/
int pv_verify_crl(X509_CRL *crl, X509 *cert, int verify_flags, GError **error);
/** pv_check_chain_parameters:
*
* @chain: chain of trust to be validated
* @error: return location for a #GError
*
* Verifies that chain has at least a RootCA ans intermediate CA
* and logs the used ROD CA subject
*
* Returns:
* 0 @chain is valid
* -1 otherwise
*/
int pv_check_chain_parameters(const STACK_OF_X509 *chain, GError **error);
/** pv_store_set_verify_param:
*
* @store: X509_STORE to set parameters
* @error: return location for a #GError
*
* Returns:
* 0 on success
* -1 on failure
*/
int pv_store_set_verify_param(X509_STORE *store, GError **error);
/** pv_store_ctx_find_valid_crls:
*
* @ctx: STORE_CTX for searching CRLs
* @cert: X509 to match CRLs aggainst
* @error: return location for a #GError
*
* Returns: (nullable) (transfer full): STACK of CRLs related to given @crl fin @ctx
*/
STACK_OF_X509_CRL *pv_store_ctx_find_valid_crls(X509_STORE_CTX *ctx, X509 *cert, GError **error)
PV_NONNULL(1, 2);
/** pv_verify_host_key_doc:
*
* @host_key_certs_with_path: X509s to be verified
* @trusted. X509_STORE with a rusted RootCA
* @untrusted_certs: STACK OF untrusted X509s
* @online: true if CRLs shall be downloaded
* @error: return location for a #GError
*
* Returns:
* 0 if all given HKDs could be verified using the chain of trust.
* -1 otherwise
*/
int pv_verify_host_key_doc(PvCertWithPathList *host_key_certs_with_path, X509_STORE *trusted,
STACK_OF_X509 *untrusted_certs, gboolean online, GError **error)
PV_NONNULL(1, 2, 3);
/** pv_verify_host_key_docs_by_path:
*
* @host_key_paths: locations of X509 to be verified
* @optional_root_ca_path: rootCA location or NULL if Default shall be used
* @optional_crl_paths: locations of CRLs or NULL
* @untrusted_cert_paths: locations of IntermediateCAs including the IBM signing key
* @online: true if CRLs shall be downloaded
* @error: return location for a #GError
*
* Returns:
* 0 if all given HKDs could be verfied using the chain of trust.
* -1 otherwise
*/
int pv_verify_host_key_docs_by_path(char **host_key_paths, char *optional_root_ca_path,
char **optional_crl_paths, char **untrusted_cert_paths,
gboolean online, GError **error) PV_NONNULL(1, 4);
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(AUTHORITY_KEYID, AUTHORITY_KEYID_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(PvX509WithPath, pv_x509_with_path_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(STACK_OF_DIST_POINT, STACK_OF_DIST_POINT_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(STACK_OF_X509, STACK_OF_X509_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(STACK_OF_X509_CRL, STACK_OF_X509_CRL_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(X509, X509_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(X509_CRL, X509_CRL_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(X509_LOOKUP, X509_LOOKUP_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(X509_NAME, X509_NAME_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(X509_VERIFY_PARAM, X509_VERIFY_PARAM_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(PvX509Pair, pv_x509_pair_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(X509_STORE, X509_STORE_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(X509_STORE_CTX, X509_STORE_CTX_free)
#endif /* LIBPV_CERT_H */

View File

@@ -14,22 +14,6 @@
* the glib version is supported
*/
#include "libpv/glib-helper.h"
#include <glib/gi18n.h>
#include "libpv/openssl-compat.h"
#include "libpv/macros.h"
/** pv_init:
*
* Must be called before any libpv call.
*/
int pv_init(void);
/** pv_cleanup:
*
* Must be called when done with using libpv.
*/
void pv_cleanup(void);
#endif /* LIBPV_COMMON_H */

View File

@@ -15,6 +15,7 @@
#include <openssl/evp.h>
#include "libpv/common.h"
#define PV_NONNULL(...)
typedef struct pv_cipher_parms {
const EVP_CIPHER *cipher;
@@ -26,17 +27,6 @@ typedef struct pv_cipher_parms {
};
} PvCipherParms;
typedef union {
struct {
uint8_t x[80];
uint8_t y[80];
};
uint8_t data[160];
} PvEcdhPubKey;
G_STATIC_ASSERT(sizeof(PvEcdhPubKey) == 160);
typedef GSList PvEvpKeyList;
enum PvCryptoMode {
PV_ENCRYPT,
PV_DECRYPT,
@@ -61,42 +51,6 @@ char *pv_get_openssl_errors(void);
*/
int pv_BIO_reset(BIO *b);
/**
* pv_generate_rand_data:
* @size: number of generated random bytes using a crypographically secure pseudo random generator
* @error: return location for a #GError
*
* Creates a new #GBytes with @size random bytes using a cryptographically
* secure pseudo random generator.
*
* Returns: (nullable) (transfer full): a new #GBytes, or %NULL in case of an error
*/
GBytes *pv_generate_rand_data(size_t size, GError **error);
/**
* pv_generate_key:
* @cipher: specifies the OpenSSL cipher for which a cryptographically secure key should be generated
* @error: return location for a #GError
*
* Creates a random key for @cipher using a cryptographically secure pseudo
* random generator.
*
* Returns: (nullable) (transfer full): a new #GBytes, or %NULL in case of an error
*/
GBytes *pv_generate_key(const EVP_CIPHER *cipher, GError **error) PV_NONNULL(1);
/**
* pv_generate_iv:
* @cipher: specifies the OpenSSL cipher for which a cryptographically secure IV should be generated
* @error: return location for a #GError
*
* Creates a random IV for @cipher using a cryptographically secure pseudo
* random generator.
*
* Returns: (nullable) (transfer full): a new #GBytes, or %NULL in case of an error
*/
GBytes *pv_generate_iv(const EVP_CIPHER *cipher, GError **error) PV_NONNULL(1);
/* Symmetric en/decryption functions */
/**
@@ -135,7 +89,7 @@ int64_t pv_gcm_decrypt(GBytes *cipher, GBytes *aad, GBytes *tag, const PvCipherP
* @derived_key_len: size of the output key
* @key: input key
* @salt: salt for the extraction
* @info: infor for the expansion
* @info: info for the expansion
* @md: EVP mode of operation
* @error: return location for a #GError
*
@@ -147,54 +101,15 @@ 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, GError **error) PV_NONNULL(2, 3, 4, 5);
/** pv_generate_ec_key:
*
* @nid: Numerical identifier of the curve
* @error: return location for a #GError
*
* Returns: (nullable) (transfer full): new random key based on the given curve
*/
EVP_PKEY *pv_generate_ec_key(int nid, GError **error);
/** pv_evp_pkey_to_ecdh_pub_key:
*
* @key: input key in EVP_PKEY format
* @error: return location for a #GError
*
* Returns: the public part of the input @key in ECDH format.
*/
PvEcdhPubKey *pv_evp_pkey_to_ecdh_pub_key(EVP_PKEY *key, GError **error) PV_NONNULL(1);
/** pv_derive_exchange_key:
* @cust: Customer Key
* @host: Host key
* @error: return location for a #GError
*
* Returns: (nullable) (transfer full): Shared Secret of @cust and @host
*/
GBytes *pv_derive_exchange_key(EVP_PKEY *cust, EVP_PKEY *host, GError **error) PV_NONNULL(1, 2);
GQuark pv_crypto_error_quark(void);
#define PV_CRYPTO_ERROR pv_crypto_error_quark()
typedef enum {
PV_CRYPTO_ERROR_DERIVE,
PV_CRYPTO_ERROR_HKDF_FAIL,
PV_CRYPTO_ERROR_INTERNAL,
PV_CRYPTO_ERROR_INVALID_KEY_SIZE,
PV_CRYPTO_ERROR_KEYGENERATION,
PV_CRYPTO_ERROR_RANDOMIZATION,
PV_CRYPTO_ERROR_READ_FILE,
PV_CRYPTO_ERROR_NO_MATCH_TAG,
} PvCryptoErrors;
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(ASN1_INTEGER, ASN1_INTEGER_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(ASN1_OCTET_STRING, ASN1_OCTET_STRING_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(BIO, BIO_free_all)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(BIGNUM, BN_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(BN_CTX, BN_CTX_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(EC_GROUP, EC_GROUP_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(EC_KEY, EC_KEY_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(EC_POINT, EC_POINT_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(EVP_CIPHER_CTX, EVP_CIPHER_CTX_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(EVP_PKEY, EVP_PKEY_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(EVP_PKEY_CTX, EVP_PKEY_CTX_free)

View File

@@ -1,53 +0,0 @@
/*
* Libcurl utils
*
* 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 LIBPV_CURL_H
#define LIBPV_CURL_H
#include <curl/curl.h>
#include "libpv/common.h"
#define CRL_DOWNLOAD_TIMEOUT_MS 3000
#define CRL_DOWNLOAD_MAX_SIZE 0x100000
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(CURL, curl_easy_cleanup)
/** curl_download:
* @url: URL to specify location of data
* @timeout_ms: time to wait until fail
* @max_size: Maximum size of the downloaded data
* @error: return location for a GError
*
* Returns: (nullable) (transfer full): Downloaded data as #GByteArray
*/
GByteArray *curl_download(const char *url, long timeout_ms, uint max_size, GError **err);
/** pv_curl_init:
*
* Should not be called by user.
* Use pv_init() instead which
* calls this function during creation.
*/
int pv_curl_init(void);
/** pv_curl_cleanup:
*
* Should not be called by user.
* Use pv_cleanup() instead which
* calls this function during creation.
*/
void pv_curl_cleanup(void);
#define PV_CURL_ERROR g_quark_from_static_string("pv-curl-error-quark")
typedef enum {
PV_CURL_ERROR_CURL_INIT_FAILED,
PV_CURL_ERROR_DOWNLOAD_FAILED,
} PvCurlErrors;
#endif /* LIBPV_CURL_H */

View File

@@ -28,8 +28,6 @@
#include <gmodule.h>
#include <stdio.h>
#include "libpv/macros.h"
#ifdef __clang__
#define WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(...) \
DO_PRAGMA(clang diagnostic push) \
@@ -40,6 +38,8 @@
#define WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(...) G_DEFINE_AUTOPTR_CLEANUP_FUNC(__VA_ARGS__)
#endif
#define DO_PRAGMA(x) _Pragma(#x)
#define pv_wrapped_g_assert(__expr) g_assert(__expr)
/** pv_sec_gbytes_new_take:

View File

@@ -1,119 +0,0 @@
/*
* Hashing definitions.
*
* 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 LIBPV_HASH_H
#define LIBPV_HASH_H
#include <openssl/hmac.h>
#include "libpv/common.h"
/** pv_digest_ctx_new:
* @md: mode of digest, e.g. #EVP_sha256()
* @error: return location for a #GError
*
* Returns: (nullable) (transfer full): a new #EVP_MD_CTX, or %NULL in case of an error
*/
EVP_MD_CTX *pv_digest_ctx_new(const EVP_MD *md, GError **error);
/** pv_digest_ctx_update:
* @ctx: EVP_MD_CTX to add data
* @data: #GBytes to add to the context
* @error: return location for a #GError
*
* Adds @data to the digest context. Can be called multiple times.
*
* Returns: 0 in case of success, -1 otherwise.
*/
int pv_digest_ctx_update(EVP_MD_CTX *ctx, GBytes *data, GError **error);
/** pv_digest_ctx_update_raw:
* @ctx: #EVP_MD_CTX to add data
* @buf: data to add to the context
* @size: size of @buf
* @error: return location for a #GError
*
* Adds @buf to the digest context. Can be called multiple times.
*
* Returns: 0 in case of success, -1 otherwise.
*/
int pv_digest_ctx_update_raw(EVP_MD_CTX *ctx, const uint8_t *buf, size_t size, GError **error);
/** pv_digest_ctx_finalize:
* @ctx: #EVP_MD_CTX with data to digest
* @error: return location for a #GError
*
* Calculates the digest of all previously added data. Do not use @ctx afterwards.
*
* Returns: (nullable) (transfer full): Digest of all data added before as #GBytes, or NULL in case of error.
*/
GBytes *pv_digest_ctx_finalize(EVP_MD_CTX *ctx, GError **error);
/** pv_sha256_hash:
* @buf: data for which a sha256 hash sould be calculated
* @size: size of @buf
* @error: return location for a #GError
*
* Shorthand for initializing a sha256-digest ctx, updating, and finalizing.
*
* Returns: (nullable) (transfer full): SHA256 of @buf as #GBytes, or NULL in case of error.
*/
GBytes *pv_sha256_hash(uint8_t *buf, size_t size, GError **error);
/** pv_hmac_ctx_new:
* @key: key used for the HMAC
* @md: mode of digest, e.g. #EVP_sha512()
* @error: return location for a #GError
*
* Returns: (nullable) (transfer full): New #HMAC_CTX or NULL in case of error
*/
HMAC_CTX *pv_hmac_ctx_new(GBytes *key, const EVP_MD *md, GError **error);
/** pv_hmac_ctx_update_raw:
* @ctx: #HMAC_CTX to add data
* @buf: data to add to the context
* @size: size of @buf
* @error: return location for a #GError
*
* Adds @buf to the HMAC context. Can be called multiple times.
*
* Returns: 0 in case of success, -1 otherwise.
*/
int pv_hmac_ctx_update_raw(HMAC_CTX *ctx, const void *data, size_t size, GError **error);
/** pv_hmac_ctx_update:
* @ctx: #HMAC_CTX to add data
* @data: #GBytes to add to the context
* @error: return location for a #GError
*
* Adds @data to the HMAC context. Can be called multiple times.
*
* Returns: 0 in case of success, -1 otherwise.
*/
int pv_hmac_ctx_update(HMAC_CTX *ctx, GBytes *data, GError **error);
/** pv_hmac_ctx_finalize:
* @ctx: #HMAC_CTX with data to digest
* @error: return location for a #GError
*
* Calculates the HMAC of all previously added data. Do not use @ctx afterwards.
*
* Returns: (nullable) (transfer full): HMAC of all data added before as #GBytes, or NULL in case of error.
*/
GBytes *pv_hamc_ctx_finalize(HMAC_CTX *ctx, GError **error);
#define PV_HASH_ERROR g_quark_from_static_string("pv-crypro-error-quark")
typedef enum {
PV_HASH_ERROR_INTERNAL,
} PvHashErrors;
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(EVP_MD_CTX, EVP_MD_CTX_free)
WRAPPED_G_DEFINE_AUTOPTR_CLEANUP_FUNC(HMAC_CTX, HMAC_CTX_free)
#endif /* LIBPV_HASH_H */

View File

@@ -1,21 +0,0 @@
/*
* Libpv common macro definitions.
*
* 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 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

@@ -1,29 +0,0 @@
/*
* OpenSSL compatibility utils
*
* Copyright IBM Corp. 2021
*
* 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 LIBPV_OPENSSL_COMPAT_H
#define LIBPV_OPENSSL_COMPAT_H
#include <openssl/opensslv.h>
#include <openssl/x509.h>
#include <openssl/x509_vfy.h>
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
#define pv_X509_STORE_CTX_get_current_cert(ctx) X509_STORE_CTX_get_current_cert(ctx)
#define pv_X509_STORE_CTX_get1_crls(ctx, nm) X509_STORE_CTX_get1_crls((ctx), (nm))
#define pv_X509_STORE_set_lookup_crls(st, cb) X509_STORE_set_lookup_crls(st, cb)
#elif OPENSSL_VERSION_NUMBER >= 0x10100000L
#define pv_X509_STORE_CTX_get_current_cert(ctx) \
X509_STORE_CTX_get_current_cert((X509_STORE_CTX *)(ctx))
#define pv_X509_STORE_CTX_get1_crls(ctx, nm) \
X509_STORE_CTX_get1_crls((X509_STORE_CTX *)(ctx), (X509_NAME *)(nm))
#define pv_X509_STORE_set_lookup_crls(st, cb) \
X509_STORE_set_lookup_crls(st, (X509_STORE_CTX_lookup_crls_fn)(cb))
#endif
#endif /* LIBPV_OPENSSL_COMPAT_H */

View File

@@ -1,96 +0,0 @@
/*
* PV/SE header definitions
*
* Copyright IBM Corp. 2020
*
* 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 LIBPV_SE_HDR_H
#define LIBPV_SE_HDR_H
#include "libpv/common.h"
#include <openssl/sha.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
*/
#define PV_MAGIC_NUMBER 0x49424d5365634578ULL
#define PV_VERSION_1 0x00000100U
/* Plaintext control flags */
/* dumping of the configuration is allowed */
#define PV_PCF_ALLOW_DUMPING PV_MSB(34)
/* prevent Ultravisor decryption during unpack operation */
#define PV_PCF_NO_DECRYPTION PV_MSB(35)
/* PCKMO encrypt-DEA/TDEA-key functions allowed */
#define PV_PCF_PCKMO_DEA_TDEA PV_MSB(56)
/* PCKMO encrypt-AES-key functions allowed */
#define PV_PCF_PCKMO_AES PV_MSB(57)
/* PCKMO encrypt-ECC-key functions allowed */
#define PV_PCF_PCKM_ECC PV_MSB(58)
/* maxima for the PV version 1 */
#define PV_V1_IPIB_MAX_SIZE PAGE_SIZE
#define PV_V1_PV_HDR_MIN_SIZE \
(sizeof(struct pv_hdr_head) + sizeof(struct pv_hdr_encrypted) + \
sizeof(((struct pv_hdr *)0)->tag) + 1 * sizeof(struct pv_hdr_key_slot))
#define PV_V1_PV_HDR_MAX_SIZE (2 * PAGE_SIZE)
#define PV_IMAGE_ENCR_KEY_SIZE 64
typedef struct pv_hdr_key_slot {
uint8_t digest_key[SHA256_DIGEST_LENGTH];
uint8_t wrapped_key[32];
uint8_t tag[16];
} __packed PvHdrKeySlot;
typedef struct pv_hdr_opt_item {
uint32_t otype;
uint8_t ibk[32];
uint8_t data[];
} __packed PvHdrOptItem;
/* integrity protected data (by GCM tag), but non-encrypted */
struct pv_hdr_head {
uint64_t magic;
uint32_t version;
uint32_t phs;
uint8_t iv[12];
uint32_t res1;
uint64_t nks;
uint64_t sea;
uint64_t nep;
uint64_t pcf;
PvEcdhPubKey cust_pub_key;
uint8_t pld[SHA512_DIGEST_LENGTH];
uint8_t ald[SHA512_DIGEST_LENGTH];
uint8_t tld[SHA512_DIGEST_LENGTH];
} __packed;
/* Must not have any padding */
struct pv_hdr_encrypted {
uint8_t cust_comm_key[32];
uint8_t img_enc_key_1[PV_IMAGE_ENCR_KEY_SIZE / 2];
uint8_t img_enc_key_2[PV_IMAGE_ENCR_KEY_SIZE / 2];
struct psw_t psw;
uint64_t scf;
uint32_t noi;
uint32_t res2;
};
G_STATIC_ASSERT(sizeof(struct pv_hdr_encrypted) == 32 + 32 + 32 + sizeof(struct psw_t) + 8 + 4 + 4);
typedef struct pv_hdr {
struct pv_hdr_head head;
struct pv_hdr_key_slot *slots;
struct pv_hdr_encrypted *encrypted;
struct pv_hdr_opt_item **optional_items;
uint8_t tag[16];
} PvHdr;
#endif /* LIBPV_SE_HDR_H */

View File

@@ -15,8 +15,31 @@
#include <string.h>
#include <unistd.h>
#include "lib/util_path.h"
#include "lib/util_panic.h"
#include "ipl_tools.h"
/*
* Look up for the device in /sys/devices/ hierarchy.
*
* path must be PATH_MAX large and the value will be replaced in place
*/
static int device_sysfs_path(const char *device, char *path, const size_t path_size)
{
util_assert(device != NULL, "Internal error: device is NULL");
util_assert(path != NULL, "Internal error: path is NULL");
util_assert(path_size == PATH_MAX, "Internal error: path_size is '%zu', but must be '%zu'",
path_size, PATH_MAX);
char *buf = util_path_sysfs("block/%s/device", device);
if (!realpath(buf, path)) {
free(buf);
return -1;
}
free(buf);
return 0;
}
/*
* Check if the specified device number is a valid device number
* which can be found in the /sys/bus/ccw/drivers/dasd-eckd/
@@ -42,6 +65,26 @@ int ccw_is_device(const char *busid)
return 0;
}
/*
* Check if the specified device is a valid virtio subchannel device
*/
int ccw_is_virtio_device(const char *device)
{
char path[PATH_MAX] = { '\0' };
unsigned virtio = 0;
if (device_sysfs_path(device, path, sizeof(path)) != 0)
return -1;
/*
* The output has the following format:
* /sys/devices/css0/0.0.0000/0.0.0000/virtio0/block/vda
*/
if (sscanf(path, "/sys/devices/css0/%*[0-9a-f.]/%*[0-9a-f.]/virtio%u", &virtio) != 1)
return -1;
return 0;
}
/*
* Return CCW Bus ID (old sysfs)
*/
@@ -77,11 +120,9 @@ out_fclose:
*/
static int ccw_busid_get_sysfs_new(const char *device, char *busid)
{
char path[PATH_MAX], buf[4096];
char path[PATH_MAX] = { '\0' };
memset(buf, 0, sizeof(buf));
snprintf(path, sizeof(path), "/sys/block/%s/device", device);
if (realpath(path, buf) == NULL)
if (device_sysfs_path(device, path, sizeof(path)) != 0)
return -1;
/*
@@ -89,7 +130,7 @@ static int ccw_busid_get_sysfs_new(const char *device, char *busid)
* /sys/devices/css0/0.0.0119/0.0.3f19/block/dasda
* /sys/devices/css0/0.0.0000/0.0.0000/virtio0/block/vda
*/
if (sscanf(buf, "/sys/devices/css0/%*[0-9a-f.]/%[0-9a-f.]", busid) != 1)
if (sscanf(path, "/sys/devices/css0/%*[0-9a-f.]/%[0-9a-f.]", busid) != 1)
return -1;
return 0;
}

View File

@@ -391,7 +391,8 @@ static void dev_from_part_nvme(char *dev_name)
static int set_reipl_type(const char *dev_name)
{
if (strncmp(dev_name, "dasd", strlen("dasd")) == 0 ||
strncmp(dev_name, "vd", strlen("vd")) == 0)
strncmp(dev_name, "vd", strlen("vd")) == 0 ||
ccw_is_virtio_device(dev_name) == 0)
l.reipl_type = REIPL_CCW;
else if (strncmp(dev_name, "sd", strlen("sd")) == 0)
l.reipl_type = REIPL_FCP;

View File

@@ -87,6 +87,7 @@ int nvme_is_device(char *fid_str, char *nsid_str);
* CCW
*/
extern int ccw_is_device(const char *devno);
extern int ccw_is_virtio_device(const char *device);
extern void ccw_busid_get(const char *device, char *devno);
/*

View File

@@ -13,8 +13,7 @@ RECURSIVE_TARGETS = all-recursive install-recursive clean-recursive \
all: all-recursive
check: check-recursive
install: all install-recursive
install: install-recursive
clean: clean-recursive

View File

@@ -11,12 +11,15 @@
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#ifdef HAVE_JSONC
#include <json-c/json.h>
@@ -698,6 +701,20 @@ void ap_list_remove_all(struct util_list *list)
}
}
static unsigned int random_delay(void)
{
static bool libap_seed = true;
struct timeval t;
if (libap_seed) {
gettimeofday(&t, NULL);
srand((unsigned int)((t.tv_sec + t.tv_usec) % UINT_MAX));
libap_seed = false;
}
return AP_LOCK_DELAY_US + (rand() % AP_LOCK_VARIANCE_US);
}
/**
* Acquire the ap config lock using this Process ID
*
@@ -707,7 +724,9 @@ void ap_list_remove_all(struct util_list *list)
*/
int ap_get_lock(void)
{
return util_lockfile_lock(AP_LOCKFILE, AP_LOCK_RETRIES);
unsigned int delay = random_delay();
return util_lockfile_lock_cw(AP_LOCKFILE, AP_LOCK_RETRIES, delay, delay);
}
/**
@@ -719,7 +738,38 @@ int ap_get_lock(void)
*/
int ap_get_lock_callout(void)
{
return util_lockfile_parent_lock(AP_LOCKFILE, AP_LOCK_RETRIES);
unsigned int delay = random_delay();
return util_lockfile_parent_lock_cw(AP_LOCKFILE, AP_LOCK_RETRIES, delay,
delay);
}
/**
* Attempt to acquire the ap config lock using the Parent Process ID without
* waiting/retries. Detect if the attempt was rejected because the lock is
* already held by the Parent Process ID.
*
* @retval 0 Lock acquired on behalf of parent process
* @retval 1 Lock not obtained, already held by parent
* @retval != 0 Lock was not obtained, other error
*/
int ap_try_lock_callout(void)
{
int pid, ppid, rc;
if (util_lockfile_parent_lock(AP_LOCKFILE, 0)) {
/* Lock is already held, let's peek at the owner */
ppid = getppid();
rc = util_lockfile_peek_owner(AP_LOCKFILE, &pid);
if (rc || pid != ppid) {
/* We didn't get the lock, unknown or other owner */
return 2;
}
/* Signify that the lock is already held by the caller */
return 1;
}
return 0;
}
/**

View File

@@ -55,7 +55,7 @@ check-dep-libekmfweb: detect-openssl-version.dep
"detect-openssl-version.dep", \
"openssl-devel version >= 1.1.1", \
"HAVE_OPENSSL=0", \
-I. -lcrypto -DOPENSSL_SUPPRESS_DEPRECATED)
-I. `$(PKG_CONFIG) --cflags --libs libcrypto` -DOPENSSL_SUPPRESS_DEPRECATED)
$(call check_dep, \
"libekmfweb", \
"json-c/json.h", \
@@ -66,7 +66,7 @@ check-dep-libekmfweb: detect-openssl-version.dep
"curl/curl.h", \
"libcurl-devel", \
"HAVE_LIBCURL=0" \
`$(CURL_CONFIG) --cflags` `$(CURL_CONFIG) --libs`)
`$(PKG_CONFIG) --cflags --libs libcurl`)
$(CURL_CONFIG) --ssl-backends | grep OpenSSL >/dev/null 2>&1 || { echo "Error: libcurl is not built with the OpenSSL backend"; exit 1; }
touch check-dep-libekmfweb
@@ -85,8 +85,8 @@ ekmfweb.o: check-dep-libekmfweb ekmfweb.c utilities.h cca.h $(rootdir)include/ek
utilities.o: check-dep-libekmfweb utilities.c utilities.h $(rootdir)include/ekmfweb/ekmfweb.h
cca.o: check-dep-libekmfweb cca.c cca.h utilities.h $(rootdir)include/ekmfweb/ekmfweb.h
libekmfweb.so.$(VERSION): ALL_CFLAGS += -fPIC `$(CURL_CONFIG) --cflags`
libekmfweb.so.$(VERSION): LDLIBS = -ljson-c -lcrypto -lssl `$(CURL_CONFIG) --libs` -ldl
libekmfweb.so.$(VERSION): ALL_CFLAGS += -fPIC `$(PKG_CONFIG) --cflags json-c libcurl libcrypto libssl`
libekmfweb.so.$(VERSION): LDLIBS = `$(PKG_CONFIG) --libs json-c libcurl libcrypto libssl` -ldl
libekmfweb.so.$(VERSION): ALL_LDFLAGS += -shared -Wl,--version-script=libekmfweb.map \
-Wl,-z,defs,-Bsymbolic -Wl,-soname,libekmfweb.so.$(VERM)
libekmfweb.so.$(VERSION): ekmfweb.o utilities.o cca.o $(libs)
@@ -98,7 +98,7 @@ install-libekmfweb.so.$(VERSION): libekmfweb.so.$(VERSION)
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 755 -T libekmfweb.so.$(VERSION) $(DESTDIR)$(SOINSTALLDIR)/libekmfweb.so.$(VERSION)
ln -srf $(DESTDIR)$(SOINSTALLDIR)/libekmfweb.so.$(VERSION) $(DESTDIR)$(SOINSTALLDIR)/libekmfweb.so.$(VERM)
ln -srf $(DESTDIR)$(SOINSTALLDIR)/libekmfweb.so.$(VERSION) $(DESTDIR)$(SOINSTALLDIR)/libekmfweb.so
$(INSTALL) -d -m 770 $(DESTDIR)$(USRINCLUDEDIR)/ekmfweb
$(INSTALL) -d -m 755 $(DESTDIR)$(USRINCLUDEDIR)/ekmfweb
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 644 $(rootdir)include/ekmfweb/ekmfweb.h $(DESTDIR)$(USRINCLUDEDIR)/ekmfweb
install: all $(INSTALL_TARGETS)

View File

@@ -51,7 +51,6 @@ detect-openssl-version.dep:
mv $(TMPFILE) $@
CURL_CONFIG ?= curl-config
XML2_CONFIG ?= xml2-config
check-dep-libkmipclient: detect-openssl-version.dep
$(call check_dep, \
@@ -59,7 +58,7 @@ check-dep-libkmipclient: detect-openssl-version.dep
"detect-openssl-version.dep", \
"openssl-devel version >= 1.1.1", \
"HAVE_OPENSSL=0", \
-I. -lcrypto -DOPENSSL_SUPPRESS_DEPRECATED)
-I. `$(PKG_CONFIG) --cflags --libs libcrypto` -DOPENSSL_SUPPRESS_DEPRECATED)
$(call check_dep, \
"libkmipclient", \
"json-c/json.h", \
@@ -70,13 +69,13 @@ check-dep-libkmipclient: detect-openssl-version.dep
"libxml/tree.h", \
"libxml2-devel", \
"HAVE_LIBXML2=0", \
`$(XML2_CONFIG) --cflags` `$(XML2_CONFIG) --libs`)
`$(PKG_CONFIG) --cflags --libs libxml-2.0`)
$(call check_dep, \
"libkmipclient", \
"curl/curl.h", \
"libcurl-devel", \
"HAVE_LIBCURL=0" \
`$(CURL_CONFIG) --cflags` `$(CURL_CONFIG) --libs`)
`$(PKG_CONFIG) --cflags --libs libcurl`)
$(CURL_CONFIG) --ssl-backends | grep OpenSSL >/dev/null 2>&1 || { echo "Error: libcurl is not built with the OpenSSL backend"; exit 1; }
touch check-dep-libkmipclient
@@ -107,8 +106,8 @@ tls.o: check-dep-libkmipclient tls.c kmip.h utils.h $(rootdir)include/kmipclient
names.o: check-dep-libkmipclient names.c names.h utils.h $(rootdir)include/kmipclient/kmipclient.h
utils.o: check-dep-libkmipclient utils.c names.h utils.h $(rootdir)include/kmipclient/kmipclient.h
libkmipclient.so.$(VERSION): ALL_CFLAGS += -fPIC `$(XML2_CONFIG) --cflags` `$(CURL_CONFIG) --cflags`
libkmipclient.so.$(VERSION): LDLIBS = -ljson-c -lcrypto -lssl `$(XML2_CONFIG) --libs` `$(CURL_CONFIG) --libs`
libkmipclient.so.$(VERSION): ALL_CFLAGS += -fPIC `$(PKG_CONFIG) --cflags json-c libcrypto libssl libxml-2.0 libcurl`
libkmipclient.so.$(VERSION): LDLIBS = `$(PKG_CONFIG) --libs json-c libcrypto libssl libxml-2.0 libcurl`
libkmipclient.so.$(VERSION): ALL_LDFLAGS += -shared -Wl,--version-script=libkmipclient.map \
-Wl,-z,defs,-Bsymbolic -Wl,-soname,libkmipclient.so.$(VERM)
libkmipclient.so.$(VERSION): kmip.o request.o response.o attribute.o key.o ttlv.o json.o \
@@ -121,7 +120,7 @@ install-libkmipclient.so.$(VERSION): libkmipclient.so.$(VERSION)
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 755 -T libkmipclient.so.$(VERSION) $(DESTDIR)$(SOINSTALLDIR)/libkmipclient.so.$(VERSION)
ln -srf $(DESTDIR)$(SOINSTALLDIR)/libkmipclient.so.$(VERSION) $(DESTDIR)$(SOINSTALLDIR)/libkmipclient.so.$(VERM)
ln -srf $(DESTDIR)$(SOINSTALLDIR)/libkmipclient.so.$(VERSION) $(DESTDIR)$(SOINSTALLDIR)/libkmipclient.so
$(INSTALL) -d -m 770 $(DESTDIR)$(USRINCLUDEDIR)/kmipclient
$(INSTALL) -d -m 755 $(DESTDIR)$(USRINCLUDEDIR)/kmipclient
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 644 $(rootdir)include/kmipclient/kmipclient.h $(DESTDIR)$(USRINCLUDEDIR)/kmipclient
install: all $(INSTALL_TARGETS)

View File

@@ -16,6 +16,7 @@
#include <openssl/ssl.h>
#include <json-c/json.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <curl/curl.h>

View File

@@ -9,10 +9,7 @@ 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)
LDLIBS += $(GLIB2_LIBS) $(LIBCRYPTO_LIBS)
WARNINGS := -Wall -Wextra -Wshadow \
-Wcast-align -Wwrite-strings -Wmissing-prototypes \
-Wmissing-declarations -Wredundant-decls -Wnested-externs \
@@ -21,22 +18,18 @@ WARNINGS := -Wall -Wextra -Wshadow \
-Wno-unused-function -Wno-unused-parameter -Wno-unused-variable \
$(NULL)
ALL_CFLAGS += -std=gnu11 \
-DOPENSSL_API_COMPAT=0x10101000L \
ALL_CFLAGS += -DOPENSSL_API_COMPAT=0x10101000L \
$(GLIB2_CFLAGS) \
$(LIBCRYPTO_CFLAGS) \
$(LIBCURL_CFLAGS) \
$(WARNINGS) \
$(NULL)
BUILD_TARGETS := skip-$(LIB)
ifneq (${HAVE_OPENSSL},0)
ifneq (${HAVE_GLIB2},0)
ifneq (${HAVE_LIBCURL},0)
BUILD_TARGETS := $(LIB)
endif
endif
endif
sources := $(wildcard *.c)
objects := $(patsubst %.c,%.o,$(sources))
@@ -83,9 +76,4 @@ skip-$(LIB):
"openssl-devel / libssl-dev version >= 1.1.1", \
"HAVE_OPENSSL=0", \
"-I.")
$(call check_dep, \
"$(LIB)", \
"curl/curl.h", \
"libcurl-devel", \
"HAVE_LIBCURL=0")
touch $@

File diff suppressed because it is too large Load Diff

View File

@@ -1,45 +0,0 @@
/*
* Libpv common functions.
*
* 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.
*
*/
/* Must be included before any other header */
#include "config.h"
#include "libpv/common.h"
#include "libpv/cert.h"
#include "libpv/curl.h"
/* setup and tear down */
int pv_init(void)
{
static size_t openssl_initalized;
if (g_once_init_enter(&openssl_initalized)) {
if (OPENSSL_VERSION_NUMBER < 0x1000100fL)
g_assert_not_reached();
#if OPENSSL_VERSION_NUMBER < 0x10100000L
SSL_library_init();
SSL_load_error_strings();
#else
OPENSSL_init_crypto(0, NULL);
#endif
if (pv_curl_init() != 0)
return -1;
pv_cert_init();
g_once_init_leave(&openssl_initalized, 1);
}
return 0;
}
void pv_cleanup(void)
{
pv_cert_cleanup();
pv_curl_cleanup();
}

View File

@@ -17,7 +17,6 @@
#include "lib/zt_common.h"
#include "libpv/crypto.h"
#include "libpv/glib-helper.h"
#include "libpv/hash.h"
char *pv_get_openssl_errors(void)
{
@@ -46,59 +45,6 @@ int pv_BIO_reset(BIO *b)
return 1;
}
GBytes *pv_generate_rand_data(size_t size, GError **error)
{
g_autofree uint8_t *data = NULL;
if (size > INT_MAX) {
g_set_error_literal(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_RANDOMIZATION,
"Too many random data requested. Split it up");
OPENSSL_clear_free(data, size);
return NULL;
}
data = g_malloc(size);
if (RAND_bytes(data, (int)size) != 1) {
g_set_error_literal(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_RANDOMIZATION,
"The required amount of random data is not available");
return NULL;
}
return pv_sec_gbytes_new_take(g_steal_pointer(&data), size);
}
GBytes *pv_generate_key(const EVP_CIPHER *cipher, GError **error)
{
int size;
pv_wrapped_g_assert(cipher);
size = EVP_CIPHER_key_length(cipher);
if (size <= 0) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_KEYGENERATION,
"Unknown cipher");
return NULL;
}
return pv_generate_rand_data((guint)size, error);
}
GBytes *pv_generate_iv(const EVP_CIPHER *cipher, GError **error)
{
int size;
pv_wrapped_g_assert(cipher);
size = EVP_CIPHER_iv_length(cipher);
if (size <= 0) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_KEYGENERATION,
"Unknown cipher");
return NULL;
}
return pv_generate_rand_data((guint)size, error);
}
static int64_t pv_gcm_encrypt_decrypt(GBytes *input, GBytes *aad, const PvCipherParms *parms,
GBytes **output, GBytes **tagp, enum PvCryptoMode mode,
GError **error)
@@ -360,168 +306,6 @@ GBytes *pv_hkdf_extract_and_expand(size_t derived_key_len, GBytes *key, GBytes *
return pv_sec_gbytes_new_take(g_steal_pointer(&derived_key), derived_key_len);
}
EVP_PKEY *pv_generate_ec_key(int nid, GError **error)
{
g_autoptr(EVP_PKEY_CTX) ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
g_autoptr(EVP_PKEY) ret = NULL;
g_assert(ctx);
if (EVP_PKEY_keygen_init(ctx) != 1) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_KEYGENERATION,
_("EC key could not be auto-generated"));
return NULL;
}
if (EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) != 1) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_KEYGENERATION,
_("EC key could not be auto-generated"));
return NULL;
}
if (EVP_PKEY_keygen(ctx, &ret) != 1) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_KEYGENERATION,
_("EC key could not be auto-generated"));
return NULL;
}
return g_steal_pointer(&ret);
}
/* Convert a EVP_PKEY to the key format used in the PV header */
PvEcdhPubKey *pv_evp_pkey_to_ecdh_pub_key(EVP_PKEY *key, GError **error)
{
g_autofree PvEcdhPubKey *ret = g_new0(PvEcdhPubKey, 1);
g_autoptr(BIGNUM) pub_x_big = NULL, pub_y_big = NULL;
g_autoptr(EC_KEY) ec_key = NULL;
const EC_POINT *pub_key;
const EC_GROUP *grp;
pv_wrapped_g_assert(key);
ec_key = EVP_PKEY_get1_EC_KEY(key);
if (!ec_key) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
_("Key has the wrong type"));
return NULL;
}
pub_key = EC_KEY_get0_public_key(ec_key);
if (!pub_key) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
_("Failed to get public key"));
return NULL;
}
grp = EC_KEY_get0_group(ec_key);
if (!grp) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
_("Failed to get EC group"));
return NULL;
}
pub_x_big = BN_new();
if (!pub_x_big)
g_abort();
pub_y_big = BN_new();
if (!pub_y_big)
g_abort();
if (EC_POINT_get_affine_coordinates_GFp(grp, pub_key, pub_x_big, pub_y_big, NULL) != 1) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
_("Cannot convert key to internal format"));
return NULL;
}
if (BN_bn2binpad(pub_x_big, ret->x, sizeof(ret->x)) < 0) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
_("Cannot convert key to internal format"));
return NULL;
}
if (BN_bn2binpad(pub_y_big, ret->y, sizeof(ret->y)) < 0) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
_("Cannot convert key to internal format"));
return NULL;
}
return g_steal_pointer(&ret);
}
static GBytes *derive_key(EVP_PKEY *key1, EVP_PKEY *key2, GError **error)
{
g_autoptr(EVP_PKEY_CTX) ctx = NULL;
uint8_t *data = NULL;
size_t data_size, key_size;
ctx = EVP_PKEY_CTX_new(key1, NULL);
if (!ctx)
g_abort();
if (EVP_PKEY_derive_init(ctx) != 1) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
_("Key derivation failed"));
return NULL;
}
if (EVP_PKEY_derive_set_peer(ctx, key2) != 1) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_INTERNAL,
_("Key derivation failed"));
return NULL;
}
/* Determine buffer length */
if (EVP_PKEY_derive(ctx, NULL, &key_size) != 1) {
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_DERIVE,
_("Key derivation failed"));
return NULL;
}
data_size = key_size;
data = OPENSSL_malloc(data_size);
if (!data)
g_abort();
if (EVP_PKEY_derive(ctx, data, &data_size) != 1) {
OPENSSL_clear_free(data, data_size);
g_set_error(error, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_DERIVE,
_("Key derivation failed"));
return NULL;
}
g_assert(data_size == key_size);
return pv_sec_gbytes_new_take(g_steal_pointer(&data), data_size);
}
GBytes *pv_derive_exchange_key(EVP_PKEY *cust, EVP_PKEY *host, GError **error)
{
const guint8 append[] = { 0x00, 0x00, 0x00, 0x01 };
g_autoptr(GBytes) derived_key = NULL, ret = NULL;
g_autoptr(GByteArray) der_key_ga = NULL;
g_autofree uint8_t *raw = NULL;
size_t raw_len;
pv_wrapped_g_assert(cust);
pv_wrapped_g_assert(host);
derived_key = derive_key(cust, host, error);
if (!derived_key)
return NULL;
der_key_ga = g_bytes_unref_to_array(g_steal_pointer(&derived_key));
/* ANSI X.9.63-2011: 66 bytes x with leading 7 bits and
* concatenate 32 bit int '1'
*/
der_key_ga = g_byte_array_append(der_key_ga, append, sizeof(append));
/* free GBytesArray and get underlying data */
raw_len = der_key_ga->len;
raw = g_byte_array_free(g_steal_pointer(&der_key_ga), FALSE);
ret = pv_sha256_hash(raw, raw_len, error);
OPENSSL_cleanse(raw, raw_len);
return g_steal_pointer(&ret);
}
GQuark pv_crypto_error_quark(void)
{
return g_quark_from_static_string("pv-crypto-error-quark");

View File

@@ -1,116 +0,0 @@
/*
* Libcurl utils
*
* Copyright IBM Corp. 2020
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
/* Must be included before any other header */
#include "config.h"
#include <curl/curl.h>
#include <stdio.h>
#include "lib/zt_common.h"
#include "libpv/curl.h"
struct UserData {
GByteArray *buffer;
uint max_size;
};
static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
{
g_assert(userdata);
struct UserData *data = (struct UserData *)userdata;
GByteArray *buffer = data->buffer;
uint64_t actual_size;
size_t err;
g_assert(buffer);
if (!g_uint64_checked_mul(&actual_size, size, nmemb))
g_abort();
/* Signal an error condition by returning a amount that differs
* from the amount passed to the callback. This results in a
* CURLE_WRITE_ERROR.
*/
err = actual_size + 1;
if (actual_size > G_MAXUINT)
return err;
data->buffer = g_byte_array_append(buffer, (uint8_t *)ptr, (uint)actual_size);
if (data->buffer->len > data->max_size)
return err;
return actual_size;
}
int pv_curl_init(void)
{
if (curl_global_init(CURL_GLOBAL_ALL) != 0)
return -1;
return 0;
}
void pv_curl_cleanup(void)
{
curl_global_cleanup();
}
GByteArray *curl_download(const char *url, long timeout_ms, uint max_size, GError **err)
{
g_autoptr(GByteArray) ret = NULL;
g_autoptr(CURL) handle = NULL;
g_autofree char *agent = NULL;
struct UserData userdata;
CURLcode rc;
/* set up curl session */
handle = curl_easy_init();
if (!handle)
g_abort();
/* follow redirection */
rc = curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
if (rc != CURLE_OK)
goto curl_err;
rc = curl_easy_setopt(handle, CURLOPT_TIMEOUT_MS, timeout_ms);
if (rc != CURLE_OK)
goto curl_err;
rc = curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1L);
if (rc != CURLE_OK)
goto curl_err;
agent = g_strdup_printf("%s/%s", GETTEXT_PACKAGE, RELEASE_STRING);
rc = curl_easy_setopt(handle, CURLOPT_USERAGENT, agent);
if (rc != CURLE_OK)
goto curl_err;
rc = curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_callback);
if (rc != CURLE_OK)
goto curl_err;
ret = g_byte_array_new();
userdata.buffer = ret;
userdata.max_size = max_size;
rc = curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void *)&userdata);
if (rc != CURLE_OK)
goto curl_err;
rc = curl_easy_setopt(handle, CURLOPT_URL, url);
if (rc != CURLE_OK)
goto curl_err;
rc = curl_easy_perform(handle);
if (rc != CURLE_OK) {
g_set_error(err, PV_CURL_ERROR, PV_CURL_ERROR_DOWNLOAD_FAILED,
_("download failed: %s"), curl_easy_strerror(rc));
return NULL;
}
return g_steal_pointer(&ret);
curl_err:
g_set_error(err, PV_CURL_ERROR, PV_CURL_ERROR_CURL_INIT_FAILED,
_("cURL initialization failed: %s"), curl_easy_strerror(rc));
return NULL;
}

View File

@@ -1,153 +0,0 @@
/*
* Hashing functions.
* 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.
*/
/* Must be included before any other header */
#include "config.h"
#include "libpv/crypto.h"
#include "libpv/hash.h"
GBytes *pv_sha256_hash(uint8_t *buf, size_t size, GError **error)
{
g_autoptr(EVP_MD_CTX) ctx = NULL;
ctx = pv_digest_ctx_new(EVP_sha256(), error);
if (!ctx)
return NULL;
if (pv_digest_ctx_update_raw(ctx, buf, size, error) != 0)
return NULL;
return pv_digest_ctx_finalize(ctx, error);
}
EVP_MD_CTX *pv_digest_ctx_new(const EVP_MD *md, GError **error)
{
g_autoptr(EVP_MD_CTX) ctx = EVP_MD_CTX_new();
if (!ctx) {
g_set_error(error, PV_HASH_ERROR, PV_HASH_ERROR_INTERNAL,
_("Hash context generation failed"));
return NULL;
}
if (EVP_DigestInit_ex(ctx, md, NULL) != 1) {
g_set_error(error, PV_HASH_ERROR, PV_HASH_ERROR_INTERNAL,
_("EVP_DigestInit_ex failed"));
return NULL;
}
return g_steal_pointer(&ctx);
}
int pv_digest_ctx_update_raw(EVP_MD_CTX *ctx, const uint8_t *buf, size_t size, GError **error)
{
if (!buf || size == 0)
return 0;
if (EVP_DigestUpdate(ctx, buf, size) != 1) {
g_set_error(error, PV_HASH_ERROR, PV_HASH_ERROR_INTERNAL,
_("EVP_DigestUpdate failed"));
return -1;
}
return 0;
}
int pv_digest_ctx_update(EVP_MD_CTX *ctx, GBytes *data, GError **error)
{
const uint8_t *buf;
size_t buf_size;
if (!data)
return 0;
buf = g_bytes_get_data((GBytes *)data, &buf_size);
return pv_digest_ctx_update_raw(ctx, buf, buf_size, error);
}
GBytes *pv_digest_ctx_finalize(EVP_MD_CTX *ctx, GError **error)
{
int md_size = EVP_MD_size(EVP_MD_CTX_md(ctx));
g_autofree uint8_t *digest = NULL;
unsigned int digest_size;
g_assert(md_size > 0);
digest = g_malloc0((uint)md_size);
if (EVP_DigestFinal_ex(ctx, digest, &digest_size) != 1) {
g_set_error(error, PV_HASH_ERROR, PV_HASH_ERROR_INTERNAL,
_("EVP_DigestFinal_ex failed"));
return NULL;
}
g_assert(digest_size == (uint)md_size);
return g_bytes_new_take(g_steal_pointer(&digest), digest_size);
}
HMAC_CTX *pv_hmac_ctx_new(GBytes *key, const EVP_MD *md, GError **error)
{
g_autoptr(HMAC_CTX) ctx = HMAC_CTX_new();
const uint8_t *key_data;
size_t key_size;
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", openssl_err_msg);
return NULL;
}
return g_steal_pointer(&ctx);
}
int pv_hmac_ctx_update_raw(HMAC_CTX *ctx, const void *buf, size_t size, GError **error)
{
if (!buf || size == 0)
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", openssl_err_msg);
return -1;
}
return 0;
}
int pv_hmac_ctx_update(HMAC_CTX *ctx, GBytes *data, GError **error)
{
const uint8_t *buf;
size_t buf_size;
if (!data)
return 0;
buf = g_bytes_get_data((GBytes *)data, &buf_size);
return pv_hmac_ctx_update_raw(ctx, buf, buf_size, error);
}
GBytes *pv_hamc_ctx_finalize(HMAC_CTX *ctx, GError **error)
{
int md_size = EVP_MD_size(HMAC_CTX_get_md(ctx));
g_autofree uint8_t *hmac = NULL;
unsigned int hmac_size = 0;
g_assert(md_size > 0);
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", openssl_err_msg);
return NULL;
}
return g_bytes_new_take(g_steal_pointer(&hmac), hmac_size);
}

View File

@@ -90,10 +90,10 @@ const char *util_arch_machine_type_to_str(int type)
case UTIL_ARCH_MACHINE_TYPE_Z14_ZR1:
return "IBM z14 ZR1";
case UTIL_ARCH_MACHINE_TYPE_Z15:
return "IBM z15";
case UTIL_ARCH_MACHINE_TYPE_Z15_T02:
return "IBM z15 Model T02";
return "IBM z15";
case UTIL_ARCH_MACHINE_TYPE_Z16:
case UTIL_ARCH_MACHINE_TYPE_Z16_A02:
return "IBM z16";
default:
return "Unknown machine type";
@@ -111,6 +111,7 @@ unsigned long util_arch_hsa_maxsize(void)
case UTIL_ARCH_MACHINE_TYPE_Z15:
case UTIL_ARCH_MACHINE_TYPE_Z15_T02:
case UTIL_ARCH_MACHINE_TYPE_Z16:
case UTIL_ARCH_MACHINE_TYPE_Z16_A02:
return HSA_SIZE_512M;
default:
return HSA_SIZE_32M;

View File

@@ -27,7 +27,7 @@ void util_hexdump_grp(FILE *fh, const char *tag, const void *data, int grp,
for (i = 0; i < count; i++) {
if (first) {
fprintf(fh, "%*s", indent, " ");
fprintf(fh, "%*s", indent, "");
if (tag)
fprintf(fh, "%s: ", tag);
fprintf(fh, "%08x: ", i);

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