Skip to contentSkip to conversation

s390x: Add Full Boot Order Support

PATCH Superseded [email protected] 2 participants 46 messages Sep 27, 2024 – Sep 30, 2024 Arm/Amlogic Meson SoC support

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover s390x: Add Full Boot Order Support

From: Jared Rossi <[email protected]>

Loosely a v2, this updated patch set is a significant rework to most aspects of the initially proposed multi-device boot order. Of particular note, the original patch set used code jumps to restart the IPL while this version does not. In order to remove the code jumps, two significant prerequisite changes are required for the pc-bios. Firstly, the netboot code is linked into the main s390-ccw.img, which allows for return after a failed netboot, based on the patch set from Thomas Huth <[email protected]>
(https://lists.gnu.org/archive/html/qemu-devel/2024-06/msg03956.html).
Secondly, IPL errors that result in an immediate termination are converted to instead provide a return value back to the main IPL calling function.

The routines for building and loading fallback device IPLBs are largely
unchanged: An IPLB is built for each device with a boot index specified (up to 8 devices). The IPLBs location in memory is passed to the guest using the global QIPL structure, which is stored at a fixed address. If the first device in the boot order successfully IPLs, then the additional IPLBs are never used; however, if the first device fails, subsequent IPLBs are retrieved from memory and the IPL process restarts using the specifications contained in the new IPLB.

This continues until IPL is successful or there are no IPLBs left to try.

The per-device loadparm attribute is still uniformly added to CCW devices although it may only be assigned a value if the device has a boot index. This will need further rework if a more targeted approach is desired.

Two automated test cases are planned for v3: a minimal test where a guest has two boot devices defined and the first fails, and also a limit test where the guest has 8 boot devices defined but only the last one can actually IPL.

Changes v1 -> v2:

- Use the libc from SLOF and replace sclp_print calls with put/printf
- Merge netboot into the main s390-ccw.img
- Rework pc-bios to return on error instead of panic
- Handle non-archetected IPLB types (QEMU SCSI) from DIAG308
- Remove code jumps and instead restart the IPL using a traditional loop

Jared Rossi (18):
hw/s390x/ipl: Provide more memory to the s390-ccw.img firmware pc-bios/s390-ccw: Use the libc from SLOF and remove sclp prints pc-bios/s390-ccw: Link the netboot code into the main s390-ccw.img
binary
hw/s390x: Remove the possibility to load the s390-netboot.img binary pc-bios/s390-ccw: Merge netboot.mak into the main Makefile docs/system/s390x/bootdevices: Update the documentation about network
booting
pc-bios/s390-ccw: Remove panics from ISO IPL path pc-bios/s390-ccw: Remove panics from SCSI IPL path pc-bios/s390-ccw: Remove panics from ECKD IPL path pc-bios/s390-ccw: Remove panics from DASD IPL path pc-bios/s390-ccw: Remove panics from netboot IPL path pc-bios/s390-ccw: Enable failed IPL to return after error include/hw/s390x: Add include files for common IPL structs
s390x: Add individual loadparm assignment to CCW device
s390x: Build an IPLB for each boot device
s390x: Rebuild IPLB for SCSI device directly from DIAG308 pc-bios/s390x: Enable multi-device boot loop
docs/system: Update documentation for s390x IPL

 docs/system/bootindex.rst         |   7 +-
 docs/system/s390x/bootdevices.rst |  29 +-
 pc-bios/s390-ccw/netboot.mak      |  62 -----
 hw/s390x/ccw-device.h             |   2 +
 hw/s390x/ipl.h                    | 123 +--------
 include/hw/s390x/ipl/qipl.h       | 126 +++++++++
 pc-bios/s390-ccw/bootmap.h        |  21 +-
 pc-bios/s390-ccw/cio.h            |   2 +
 pc-bios/s390-ccw/dasd-ipl.h       |   2 +-
 pc-bios/s390-ccw/iplb.h           | 107 ++------
 pc-bios/s390-ccw/libc.h           |  89 -------
 pc-bios/s390-ccw/s390-ccw.h       |  36 +--
 pc-bios/s390-ccw/virtio.h         |   3 +-
 hw/s390x/ccw-device.c             |  46 ++++
 hw/s390x/ipl.c                    | 314 +++++++++++-----------
 hw/s390x/s390-virtio-ccw.c        |  28 +-
 hw/s390x/sclp.c                   |   3 +-
 pc-bios/s390-ccw/bootmap.c        | 428 ++++++++++++++++++++----------
 pc-bios/s390-ccw/cio.c            |  81 +++---
 pc-bios/s390-ccw/dasd-ipl.c       |  71 ++---
 pc-bios/s390-ccw/jump2ipl.c       |  22 +-
 pc-bios/s390-ccw/libc.c           |  88 ------
 pc-bios/s390-ccw/main.c           | 125 ++++-----
 pc-bios/s390-ccw/menu.c           |  51 ++--
 pc-bios/s390-ccw/netmain.c        |  44 ++-
 pc-bios/s390-ccw/sclp.c           |   7 +-
 pc-bios/s390-ccw/virtio-blkdev.c  |  14 +-
 pc-bios/s390-ccw/virtio-net.c     |   7 +-
 pc-bios/s390-ccw/virtio-scsi.c    | 164 ++++++++----
 pc-bios/s390-ccw/virtio.c         |  67 +++--
 target/s390x/diag.c               |   9 +-
 pc-bios/meson.build               |   1 -
 pc-bios/s390-ccw/Makefile         |  69 ++++-
 pc-bios/s390-netboot.img          | Bin 67232 -> 0 bytes
 34 files changed, 1143 insertions(+), 1105 deletions(-)
 delete mode 100644 pc-bios/s390-ccw/netboot.mak
 create mode 100644 include/hw/s390x/ipl/qipl.h
 delete mode 100644 pc-bios/s390-ccw/libc.h
 delete mode 100644 pc-bios/s390-ccw/libc.c
 delete mode 100644 pc-bios/s390-netboot.img
Signature · 1 line
2.45.1
#1 lore raw

PATCH v2 1/18 hw/s390x/ipl: Provide more memory to the s390-ccw.img firmware

From: Jared Rossi <[email protected]>

We are going to link the SLOF libc into the s390-ccw.img, and this libc needs more memory for providing space for malloc() and friends. Thus bump the memory size that we reserve for the bios to 3 MiB instead of only 2 MiB. While we're at it, add a proper check that there is really enough memory assigned to the machine before blindly using it.

Co-authored by: Thomas Huth <[email protected]>

---
 hw/s390x/ipl.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +9 -1
index dd71689642..c33a044d1d 100644
@@ -45,6 +45,7 @@
 #define INITRD_PARM_START               0x010408UL
 #define PARMFILE_START                  0x001000UL
 #define ZIPL_IMAGE_START                0x009000UL
+#define BIOS_MAX_SIZE                   0x300000UL
 #define IPL_PSW_MASK                    (PSW_MASK_32 | PSW_MASK_64)
 
 static bool iplb_extended_needed(void *opaque)
@@ -144,7 +145,14 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
      * even if an external kernel has been defined.
      */
     if (!ipl->kernel || ipl->enforce_bios) {
-        uint64_t fwbase = (MIN(ms->ram_size, 0x80000000U) - 0x200000) & ~0xffffUL;
+        uint64_t fwbase;
+
+        if (ms->ram_size < BIOS_MAX_SIZE) {
+            error_setg(errp, "not enough RAM to load the BIOS file");
+            return;
+        }
+
+        fwbase = (MIN(ms->ram_size, 0x80000000U) - BIOS_MAX_SIZE) & ~0xffffUL;
 
         bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, ipl->firmware);
         if (bios_filename == NULL) {
Signature · 1 line
2.45.1
#2 lore raw

PATCH v2 2/18 pc-bios/s390-ccw: Use the libc from SLOF and remove sclp prints

In reply to [email protected]

From: Jared Rossi <[email protected]>

We are already using the libc from SLOF for the s390-netboot.img, and this libc implementation is way more complete and accurate than the simple implementation that we currently use for the s390-ccw.img binary. Since we are now always assuming that the SLOF submodule is available when building the s390-ccw bios (see commit bf6903f6944f), we can drop the simple implementation and use the SLOF libc for the s390-ccw.img binary, too.

Additionally replace sclp_print calls with puts/printf now that it is avaliable.

Co-authored by: Thomas Huth <[email protected]>

---
 pc-bios/s390-ccw/netboot.mak     |  3 --
 pc-bios/s390-ccw/bootmap.h       |  4 +-
 pc-bios/s390-ccw/libc.h          | 89 --------------------------------
 pc-bios/s390-ccw/s390-ccw.h      | 30 ++++-------
 pc-bios/s390-ccw/bootmap.c       | 47 ++++++++---------
 pc-bios/s390-ccw/cio.c           | 78 +++++++++++++---------------
 pc-bios/s390-ccw/dasd-ipl.c      |  5 +-
 pc-bios/s390-ccw/jump2ipl.c      |  5 +-
 pc-bios/s390-ccw/libc.c          | 88 -------------------------------
 pc-bios/s390-ccw/main.c          | 14 ++---
 pc-bios/s390-ccw/menu.c          | 51 +++++++++---------
 pc-bios/s390-ccw/netmain.c       | 10 ++--
 pc-bios/s390-ccw/sclp.c          |  7 +--
 pc-bios/s390-ccw/virtio-blkdev.c |  6 +--
 pc-bios/s390-ccw/virtio-scsi.c   | 17 +++---
 pc-bios/s390-ccw/virtio.c        |  2 +-
 pc-bios/s390-ccw/Makefile        | 15 ++++--
 17 files changed, 136 insertions(+), 335 deletions(-)
 delete mode 100644 pc-bios/s390-ccw/libc.h
 delete mode 100644 pc-bios/s390-ccw/libc.c
pc-bios/s390-ccw/netboot.mak +0 -3
index 046aa35587..d2b3d8ee74 100644
@@ -1,9 +1,6 @@
 
-SLOF_DIR := $(SRC_PATH)/../../roms/SLOF
-
 NETOBJS := start.o sclp.o cio.o virtio.o virtio-net.o jump2ipl.o netmain.o
 
-LIBC_INC := -nostdinc -I$(SLOF_DIR)/lib/libc/include
 LIBNET_INC := -I$(SLOF_DIR)/lib/libnet
 
 NETLDFLAGS := $(LDFLAGS) -Wl,-Ttext=0x7800000
pc-bios/s390-ccw/bootmap.h +1 -3
index d4690a88c2..bbe2c132aa 100644
@@ -336,9 +336,7 @@ static inline void print_volser(const void *volser)
 
     ebcdic_to_ascii((char *)volser, ascii, 6);
     ascii[6] = '\0';
-    sclp_print("VOLSER=[");
-    sclp_print(ascii);
-    sclp_print("]\n");
+    printf("VOLSER=[%s]", ascii);
 }
 
 static inline bool unused_space(const void *p, size_t size)
pc-bios/s390-ccw/libc.h deleted +0 -89

89 lines not on this page · raw message

pc-bios/s390-ccw/s390-ccw.h +9 -21
index c977a52b50..9b622e616a 100644
@@ -13,6 +13,11 @@
 
 /* #define DEBUG */
 
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+
 typedef unsigned char      u8;
 typedef unsigned short     u16;
 typedef unsigned int       u32;
@@ -26,9 +31,6 @@ typedef unsigned long long u64;
 #define EBUSY   2
 #define ENODEV  3
 
-#ifndef NULL
-#define NULL    0
-#endif
 #ifndef MIN
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
 #endif
@@ -87,7 +89,7 @@ bool menu_is_enabled_enum(void);
 __attribute__ ((__noreturn__))
 static inline void panic(const char *string)
 {
-    sclp_print(string);
+    printf("ERROR: %s\n ", string);
     disabled_wait();
 }
 
@@ -109,20 +111,10 @@ static inline void fill_hex_val(char *out, void *ptr, unsigned size)
     }
 }
 
-static inline void print_int(const char *desc, u64 addr)
-{
-    char out[] = ": 0xffffffffffffffff\n";
-
-    fill_hex_val(&out[4], &addr, sizeof(addr));
-
-    sclp_print(desc);
-    sclp_print(out);
-}
-
 static inline void debug_print_int(const char *desc, u64 addr)
 {
 #ifdef DEBUG
-    print_int(desc, addr);
+    printf("%s 0x%X", desc, addr);
 #endif
 }
 
@@ -147,18 +139,14 @@ static inline void debug_print_addr(const char *desc, void *p)
 static inline void IPL_assert(bool term, const char *message)
 {
     if (!term) {
-        sclp_print("\n! ");
-        sclp_print(message);
-        panic(" !\n"); /* no return */
+        panic(message); /* no return */
     }
 }
 
 static inline void IPL_check(bool term, const char *message)
 {
     if (!term) {
-        sclp_print("\n! WARNING: ");
-        sclp_print(message);
-        sclp_print(" !\n");
+        printf("WARNING: %s\n", message);
     }
 }
 
pc-bios/s390-ccw/bootmap.c +24 -23

160 lines not on this page · raw message

pc-bios/s390-ccw/cio.c +36 -42

152 lines not on this page · raw message

pc-bios/s390-ccw/dasd-ipl.c +3 -2
index 254bb1a15e..99c0b93083 100644
@@ -8,7 +8,8 @@
  * directory.
  */
 
-#include "libc.h"
+#include <string.h>
+#include <stdio.h>
 #include "s390-ccw.h"
 #include "s390-arch.h"
 #include "dasd-ipl.h"
@@ -82,7 +83,7 @@ static int run_dynamic_ccw_program(SubChannelId schid, uint16_t cutype,
     do {
         has_next = dynamic_cp_fixup(cpa, &next_cpa);
 
-        print_int("executing ccw chain at ", cpa);
+        printf("executing ccw chain at 0x%X", cpa);
         enable_prefixing();
         rc = do_cio(schid, cutype, cpa, CCW_FMT0);
         disable_prefixing();
pc-bios/s390-ccw/jump2ipl.c +3 -2
index 78f5f46533..80b7f6a1f3 100644
@@ -6,7 +6,8 @@
  * directory.
  */
 
-#include "libc.h"
+#include <string.h>
+#include <stdio.h>
 #include "s390-ccw.h"
 #include "s390-arch.h"
 
@@ -57,7 +58,7 @@ void jump_to_IPL_code(uint64_t address)
     debug_print_int("set IPL addr to", address ?: *reset_psw & PSW_MASK_SHORT_ADDR);
 
     /* Ensure the guest output starts fresh */
-    sclp_print("\n");
+    printf("\n");
 
     /*
      * HACK ALERT.
pc-bios/s390-ccw/libc.c deleted +0 -88

88 lines not on this page · raw message

pc-bios/s390-ccw/main.c +8 -6
index 5506798098..73093d3f14 100644
@@ -8,7 +8,9 @@
  * directory.
  */
 
-#include "libc.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
 #include "helper.h"
 #include "s390-arch.h"
 #include "s390-ccw.h"
@@ -50,7 +52,7 @@ void write_iplb_location(void)
 
 unsigned int get_loadparm_index(void)
 {
-    return atoui(loadparm_str);
+    return atoi(loadparm_str);
 }
 
 static int is_dev_possibly_bootable(int dev_no, int sch_no)
@@ -176,7 +178,7 @@ static void boot_setup(void)
 
     sclp_get_loadparm_ascii(loadparm_str);
     memcpy(lpmsg + 10, loadparm_str, 8);
-    sclp_print(lpmsg);
+    puts(lpmsg);
 
     /*
      * Clear out any potential S390EP magic (see jump_to_low_kernel()),
@@ -228,7 +230,7 @@ static int virtio_setup(void)
 
     switch (vdev->senseid.cu_model) {
     case VIRTIO_ID_NET:
-        sclp_print("Network boot device detected\n");
+        puts("Network boot device detected");
         vdev->netboot_start_addr = qipl.netboot_start_addr;
         return 0;
     case VIRTIO_ID_BLOCK:
@@ -261,7 +263,7 @@ static void ipl_boot_device(void)
         }
         break;
     default:
-        print_int("Attempting to boot from unexpected device type", cutype);
+        printf("Attempting to boot from unexpected device type 0x%X", cutype);
         panic("\nBoot failed.\n");
     }
 }
@@ -287,7 +289,7 @@ static void probe_boot_device(void)
         }
     }
 
-    sclp_print("Could not find a suitable boot device (none specified)\n");
+    puts("Could not find a suitable boot device (none specified)");
 }
 
 void main(void)
pc-bios/s390-ccw/menu.c +23 -28

134 lines not on this page · raw message

pc-bios/s390-ccw/netmain.c +5 -5
index 5cd619b2d6..509119be15 100644
@@ -293,7 +293,7 @@ static int load_kernel_with_initrd(filename_ip_t *fn_ip,
     printf("Loading pxelinux.cfg entry '%s'\n", entry->label);
 
     if (!entry->kernel) {
-        printf("Kernel entry is missing!\n");
+        puts("Kernel entry is missing!\n");
         return -1;
     }
 
@@ -515,13 +515,13 @@ void main(void)
     int rc, fnlen;
 
     sclp_setup();
-    sclp_print("Network boot starting...\n");
+    puts("Network boot starting...");
 
     virtio_setup();
 
     rc = net_init(&fn_ip);
     if (rc) {
-        panic("Network initialization failed. Halting.\n");
+        panic("Network initialization failed. Halting.");
     }
 
     fnlen = strlen(fn_ip.filename);
@@ -535,9 +535,9 @@ void main(void)
     net_release(&fn_ip);
 
     if (rc > 0) {
-        sclp_print("Network loading done, starting kernel...\n");
+        puts("Network loading done, starting kernel...");
         jump_to_low_kernel();
     }
 
-    panic("Failed to load OS from network\n");
+    panic("Failed to load OS from network.");
 }
pc-bios/s390-ccw/sclp.c +1 -6
index 7251f9af4d..4a07de018d 100644
@@ -8,7 +8,7 @@
  * directory.
  */
 
-#include "libc.h"
+#include <string.h>
 #include "s390-ccw.h"
 #include "sclp.h"
 
@@ -101,11 +101,6 @@ long write(int fd, const void *str, size_t len)
     return len;
 }
 
-void sclp_print(const char *str)
-{
-    write(1, str, strlen(str));
-}
-
 void sclp_get_loadparm_ascii(char *loadparm)
 {
 
pc-bios/s390-ccw/virtio-blkdev.c +3 -3
index a81207b52e..2666326801 100644
@@ -8,7 +8,7 @@
  * directory.
  */
 
-#include "libc.h"
+#include <stdio.h>
 #include "s390-ccw.h"
 #include "virtio.h"
 #include "virtio-scsi.h"
@@ -76,7 +76,7 @@ unsigned long virtio_load_direct(unsigned long rec_list1, unsigned long rec_list
         return -1;
     }
 
-    sclp_print(".");
+    printf(".");
     status = virtio_read_many(sec, (void *)addr, sec_num);
     if (status) {
         panic("I/O Error");
@@ -230,7 +230,7 @@ int virtio_blk_setup_device(SubChannelId schid)
     vdev->schid = schid;
     virtio_setup_ccw(vdev);
 
-    sclp_print("Using virtio-blk.\n");
+    puts("Using virtio-blk.");
 
     return 0;
 }
pc-bios/s390-ccw/virtio-scsi.c +9 -8
index d1a84b937c..0e274d0c38 100644
@@ -9,7 +9,8 @@
  * directory.
  */
 
-#include "libc.h"
+#include <string.h>
+#include <stdio.h>
 #include "s390-ccw.h"
 #include "virtio.h"
 #include "scsi.h"
@@ -30,9 +31,9 @@ static inline void vs_assert(bool term, const char **msgs)
     if (!term) {
         int i = 0;
 
-        sclp_print("\n! ");
+        printf("\n! ");
         while (msgs[i]) {
-            sclp_print(msgs[i++]);
+            printf("%s", msgs[i++]);
         }
         panic(" !\n");
     }
@@ -236,11 +237,11 @@ static int virtio_scsi_locate_device(VDev *vdev)
             if (resp.response == VIRTIO_SCSI_S_BAD_TARGET) {
                 continue;
             }
-            print_int("target", target);
+            printf("target 0x%X", target);
             virtio_scsi_verify_response(&resp, "SCSI cannot report LUNs");
         }
         if (r->lun_list_len == 0) {
-            print_int("no LUNs for target", target);
+            printf("no LUNs for target 0x%X", target);
             continue;
         }
         luns = r->lun_list_len / 8;
@@ -264,7 +265,7 @@ static int virtio_scsi_locate_device(VDev *vdev)
         }
     }
 
-    sclp_print("Warning: Could not locate a usable virtio-scsi device\n");
+    puts("Warning: Could not locate a usable virtio-scsi device");
     return -ENODEV;
 }
 
@@ -379,7 +380,7 @@ static int virtio_scsi_setup(VDev *vdev)
     }
 
     if (virtio_scsi_inquiry_response_is_cdrom(scsi_inquiry_std_response)) {
-        sclp_print("SCSI CD-ROM detected.\n");
+        puts("SCSI CD-ROM detected.");
         vdev->is_cdrom = true;
         vdev->scsi_block_size = VIRTIO_ISO_BLOCK_SIZE;
     }
@@ -443,7 +444,7 @@ int virtio_scsi_setup_device(SubChannelId schid)
     IPL_assert(vdev->config.scsi.cdb_size == VIRTIO_SCSI_CDB_SIZE,
                "Config: CDB size mismatch");
 
-    sclp_print("Using virtio-scsi.\n");
+    puts("Using virtio-scsi.");
 
     return virtio_scsi_setup(vdev);
 }
pc-bios/s390-ccw/virtio.c +1 -1
index 5edd058d88..8c6b0a8a92 100644
@@ -8,7 +8,7 @@
  * directory.
  */
 
-#include "libc.h"
+#include <string.h>
 #include "s390-ccw.h"
 #include "cio.h"
 #include "virtio.h"
pc-bios/s390-ccw/Makefile +10 -5
index 6207911b53..3f4232636e 100644
@@ -33,13 +33,18 @@ QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d
 .PHONY : all clean build-all distclean
 
 OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o \
-	  virtio.o virtio-scsi.o virtio-blkdev.o libc.o cio.o dasd-ipl.o
+	  virtio.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o
+
+SLOF_DIR := $(SRC_PATH)/../../roms/SLOF
+
+LIBC_INC := -nostdinc -I$(SLOF_DIR)/lib/libc/include
 
 EXTRA_CFLAGS += -Wall
 EXTRA_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks -fno-common -fPIE
 EXTRA_CFLAGS += -fwrapv -fno-strict-aliasing -fno-asynchronous-unwind-tables
 EXTRA_CFLAGS += -msoft-float
 EXTRA_CFLAGS += -std=gnu99
+EXTRA_CFLAGS += $(LIBC_INC)
 LDFLAGS += -Wl,-pie -nostdlib -z noexecstack
 
 cc-test = $(CC) -Werror $1 -c -o /dev/null -xc /dev/null >/dev/null 2>/dev/null
@@ -55,18 +60,18 @@ config-cc.mak: Makefile
 	    $(call cc-option,-march=z900,-march=z10)) 3> config-cc.mak
 -include config-cc.mak
 
+include $(SRC_PATH)/netboot.mak
+
 build-all: s390-ccw.img s390-netboot.img
 
-s390-ccw.elf: $(OBJECTS)
-	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $(OBJECTS),Linking)
+s390-ccw.elf: $(OBJECTS) libc.a
+	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^,Linking)
 
 s390-ccw.img: s390-ccw.elf
 	$(call quiet-command,$(STRIP) --strip-unneeded $< -o $@,Stripping $< into)
 
 $(OBJECTS): Makefile
 
-include $(SRC_PATH)/netboot.mak
-
 ALL_OBJS = $(sort $(OBJECTS) $(NETOBJS) $(LIBCOBJS) $(LIBNETOBJS))
 -include $(ALL_OBJS:%.o=%.d)
 
Signature · 1 line
2.45.1
#3 lore raw

PATCH v2 3/18 pc-bios/s390-ccw: Link the netboot code into the main s390-ccw.img binary

In reply to [email protected]

From: Jared Rossi <[email protected]>

We originally built a separate binary for the netboot code since it was considered as experimental and we could not be sure that the necessary SLOF module had been checked out. Time passed, the code proved its usefulness, and the build system nowadays makes sure that the SLOF module is checked out if you have a s390x compiler available for building the s390-ccw bios. So there is no real compelling reason anymore to keep the netboot code in a separate binary. Linking the code together with the main s390-ccw.img will make future enhancements much easier, like supporting more than one boot device.

Co-authored by: Thomas Huth <[email protected]>

---
 pc-bios/s390-ccw/netboot.mak | 14 --------------
 pc-bios/s390-ccw/cio.h       |  2 ++
 pc-bios/s390-ccw/iplb.h      |  4 ++--
 pc-bios/s390-ccw/s390-ccw.h  |  3 +++
 pc-bios/s390-ccw/virtio.h    |  1 -
 pc-bios/s390-ccw/bootmap.c   |  2 +-
 pc-bios/s390-ccw/main.c      | 10 +++++++---
 pc-bios/s390-ccw/netmain.c   | 15 ++-------------
 pc-bios/s390-ccw/Makefile    | 13 +++++++------
 9 files changed, 24 insertions(+), 40 deletions(-)
pc-bios/s390-ccw/netboot.mak +0 -14
index d2b3d8ee74..0a24257ff4 100644
@@ -1,18 +1,4 @@
 
-NETOBJS := start.o sclp.o cio.o virtio.o virtio-net.o jump2ipl.o netmain.o
-
-LIBNET_INC := -I$(SLOF_DIR)/lib/libnet
-
-NETLDFLAGS := $(LDFLAGS) -Wl,-Ttext=0x7800000
-
-$(NETOBJS): EXTRA_CFLAGS += $(LIBC_INC) $(LIBNET_INC)
-
-s390-netboot.elf: $(NETOBJS) libnet.a libc.a
-	$(call quiet-command,$(CC) $(NETLDFLAGS) -o $@ $^,Linking)
-
-s390-netboot.img: s390-netboot.elf
-	$(call quiet-command,$(STRIP) --strip-unneeded $< -o $@,Stripping $< into)
-
 # libc files:
 
 LIBC_CFLAGS = $(EXTRA_CFLAGS) $(CFLAGS) $(LIBC_INC) $(LIBNET_INC) \
pc-bios/s390-ccw/cio.h +2 -0
index 8b18153deb..6a5e86ba01 100644
@@ -361,6 +361,8 @@ typedef struct CcwSearchIdData {
     uint8_t record;
 } __attribute__((packed)) CcwSearchIdData;
 
+extern SubChannelId net_schid;
+
 int enable_mss_facility(void);
 void enable_subchannel(SubChannelId schid);
 uint16_t cu_type(SubChannelId schid);
pc-bios/s390-ccw/iplb.h +2 -2
index cb6ac8a880..3758698468 100644
@@ -87,9 +87,9 @@ extern IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));
 struct QemuIplParameters {
     uint8_t  qipl_flags;
     uint8_t  reserved1[3];
-    uint64_t netboot_start_addr;
+    uint64_t reserved2;
     uint32_t boot_menu_timeout;
-    uint8_t  reserved2[12];
+    uint8_t  reserved3[12];
 } __attribute__ ((packed));
 typedef struct QemuIplParameters QemuIplParameters;
 
pc-bios/s390-ccw/s390-ccw.h +3 -0
index 9b622e616a..0ed7eb8ade 100644
@@ -55,6 +55,9 @@ void write_iplb_location(void);
 unsigned int get_loadparm_index(void);
 void main(void);
 
+/* netmain.c */
+void netmain(void);
+
 /* sclp.c */
 void sclp_print(const char *string);
 void sclp_set_write_mask(uint32_t receive_mask, uint32_t send_mask);
pc-bios/s390-ccw/virtio.h +0 -1
index 85bd9d1695..6f9a558ff5 100644
@@ -253,7 +253,6 @@ struct VDev {
     uint8_t scsi_dev_heads;
     bool scsi_device_selected;
     ScsiDevice selected_scsi_device;
-    uint64_t netboot_start_addr;
     uint32_t max_transfer;
     uint32_t guest_features[2];
 };
pc-bios/s390-ccw/bootmap.c +1 -1
index 3cc79706be..414c3f1b47 100644
@@ -929,7 +929,7 @@ void zipl_load(void)
     }
 
     if (virtio_get_device_type() == VIRTIO_ID_NET) {
-        jump_to_IPL_code(vdev->netboot_start_addr);
+        netmain();
     }
 
     ipl_scsi();
pc-bios/s390-ccw/main.c +7 -3
index 73093d3f14..2345432abb 100644
@@ -38,8 +38,13 @@ LowCore *lowcore; /* Yes, this *is* a pointer to address 0 */
  */
 void write_subsystem_identification(void)
 {
-    lowcore->subchannel_id = blk_schid.sch_id;
-    lowcore->subchannel_nr = blk_schid.sch_no;
+    if (cutype == CU_TYPE_VIRTIO && virtio_get_device_type() == VIRTIO_ID_NET) {
+        lowcore->subchannel_id = net_schid.sch_id;
+        lowcore->subchannel_nr = net_schid.sch_no;
+    } else {
+        lowcore->subchannel_id = blk_schid.sch_id;
+        lowcore->subchannel_nr = blk_schid.sch_no;
+    }
     lowcore->io_int_parm = 0;
 }
 
@@ -231,7 +236,6 @@ static int virtio_setup(void)
     switch (vdev->senseid.cu_model) {
     case VIRTIO_ID_NET:
         puts("Network boot device detected");
-        vdev->netboot_start_addr = qipl.netboot_start_addr;
         return 0;
     case VIRTIO_ID_BLOCK:
         ret = virtio_blk_setup_device(blk_schid);
pc-bios/s390-ccw/netmain.c +2 -13
index 509119be15..bc6ad8695f 100644
@@ -41,7 +41,6 @@
 #define DEFAULT_TFTP_RETRIES 20
 
 extern char _start[];
-void write_iplb_location(void) {}
 
 #define KERNEL_ADDR             ((void *)0L)
 #define KERNEL_MAX_SIZE         ((long)_start)
@@ -50,10 +49,9 @@ void write_iplb_location(void) {}
 /* STSI 3.2.2 offset of first vmdb + offset of uuid inside vmdb */
 #define STSI322_VMDB_UUID_OFFSET ((8 + 12) * 4)
 
-IplParameterBlock iplb __attribute__((aligned(PAGE_SIZE)));
 static char cfgbuf[2048];
 
-static SubChannelId net_schid = { .one = 1 };
+SubChannelId net_schid = { .one = 1 };
 static uint8_t mac[6];
 static uint64_t dest_timer;
 
@@ -438,15 +436,6 @@ static int net_try_direct_tftp_load(filename_ip_t *fn_ip)
     return rc;
 }
 
-void write_subsystem_identification(void)
-{
-    SubChannelId *schid = (SubChannelId *) 184;
-    uint32_t *zeroes = (uint32_t *) 188;
-
-    *schid = net_schid;
-    *zeroes = 0;
-}
-
 static bool find_net_dev(Schib *schib, int dev_no)
 {
     int i, r;
@@ -509,7 +498,7 @@ static void virtio_setup(void)
     IPL_assert(found, "No virtio net device found");
 }
 
-void main(void)
+void netmain(void)
 {
     filename_ip_t fn_ip;
     int rc, fnlen;
pc-bios/s390-ccw/Makefile +7 -6
index 3f4232636e..cf6859823a 100644
@@ -32,19 +32,20 @@ QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d
 
 .PHONY : all clean build-all distclean
 
-OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o \
-	  virtio.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o
+OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o netmain.o \
+	  virtio.o virtio-net.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o
 
 SLOF_DIR := $(SRC_PATH)/../../roms/SLOF
 
 LIBC_INC := -nostdinc -I$(SLOF_DIR)/lib/libc/include
+LIBNET_INC := -I$(SLOF_DIR)/lib/libnet
 
 EXTRA_CFLAGS += -Wall
 EXTRA_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks -fno-common -fPIE
 EXTRA_CFLAGS += -fwrapv -fno-strict-aliasing -fno-asynchronous-unwind-tables
 EXTRA_CFLAGS += -msoft-float
 EXTRA_CFLAGS += -std=gnu99
-EXTRA_CFLAGS += $(LIBC_INC)
+EXTRA_CFLAGS += $(LIBC_INC) $(LIBNET_INC)
 LDFLAGS += -Wl,-pie -nostdlib -z noexecstack
 
 cc-test = $(CC) -Werror $1 -c -o /dev/null -xc /dev/null >/dev/null 2>/dev/null
@@ -62,9 +63,9 @@ config-cc.mak: Makefile
 
 include $(SRC_PATH)/netboot.mak
 
-build-all: s390-ccw.img s390-netboot.img
+build-all: s390-ccw.img
 
-s390-ccw.elf: $(OBJECTS) libc.a
+s390-ccw.elf: $(OBJECTS) libnet.a libc.a
 	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^,Linking)
 
 s390-ccw.img: s390-ccw.elf
@@ -72,7 +73,7 @@ s390-ccw.img: s390-ccw.elf
 
 $(OBJECTS): Makefile
 
-ALL_OBJS = $(sort $(OBJECTS) $(NETOBJS) $(LIBCOBJS) $(LIBNETOBJS))
+ALL_OBJS = $(sort $(OBJECTS) $(LIBCOBJS) $(LIBNETOBJS))
 -include $(ALL_OBJS:%.o=%.d)
 
 clean:
Signature · 1 line
2.45.1
#4 lore raw

PATCH v2 4/18 hw/s390x: Remove the possibility to load the s390-netboot.img binary

In reply to [email protected]

From: Jared Rossi <[email protected]>

Since the netboot code has now been merged into the main s390-ccw.img binary, we don't need the separate s390-netboot.img anymore. Remove it and the code that was responsible for loading it.

Co-authored by: Thomas Huth <[email protected]>

---
 hw/s390x/ipl.h             | 12 +++------
 hw/s390x/ipl.c             | 55 --------------------------------------
 hw/s390x/s390-virtio-ccw.c | 10 ++-----
 pc-bios/meson.build        |  1 -
 4 files changed, 6 insertions(+), 72 deletions(-)
hw/s390x/ipl.h +4 -8
index 57cd125769..b2105b616a 100644
@@ -134,11 +134,8 @@ void s390_ipl_clear_reset_request(void);
 /*
  * The QEMU IPL Parameters will be stored at absolute address
  * 204 (0xcc) which means it is 32-bit word aligned but not
- * double-word aligned.
- * Placement of data fields in this area must account for
- * their alignment needs. E.g., netboot_start_address must
- * have an offset of 4 + n * 8 bytes within the struct in order
- * to keep it double-word aligned.
+ * double-word aligned. Placement of 64-bit data fields in this
+ * area must account for their alignment needs.
  * The total size of the struct must never exceed 28 bytes.
  * This definition must be kept in sync with the definition
  * in pc-bios/s390-ccw/iplb.h.
@@ -146,9 +143,9 @@ void s390_ipl_clear_reset_request(void);
 struct QemuIplParameters {
     uint8_t  qipl_flags;
     uint8_t  reserved1[3];
-    uint64_t netboot_start_addr;
+    uint64_t reserved2;
     uint32_t boot_menu_timeout;
-    uint8_t  reserved2[12];
+    uint8_t  reserved3[12];
 } QEMU_PACKED;
 typedef struct QemuIplParameters QemuIplParameters;
 
@@ -178,7 +175,6 @@ struct S390IPLState {
     char *initrd;
     char *cmdline;
     char *firmware;
-    char *netboot_fw;
     uint8_t cssid;
     uint8_t ssid;
     uint16_t devno;
hw/s390x/ipl.c +0 -55

73 lines not on this page · raw message

hw/s390x/s390-virtio-ccw.c +2 -8
index 18240a0fd8..c89a5475eb 100644
@@ -197,11 +197,10 @@ static void s390_memory_init(MemoryRegion *ram)
 static void s390_init_ipl_dev(const char *kernel_filename,
                               const char *kernel_cmdline,
                               const char *initrd_filename, const char *firmware,
-                              const char *netboot_fw, bool enforce_bios)
+                              bool enforce_bios)
 {
     Object *new = object_new(TYPE_S390_IPL);
     DeviceState *dev = DEVICE(new);
-    char *netboot_fw_prop;
 
     if (kernel_filename) {
         qdev_prop_set_string(dev, "kernel", kernel_filename);
@@ -212,11 +211,6 @@ static void s390_init_ipl_dev(const char *kernel_filename,
     qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
     qdev_prop_set_string(dev, "firmware", firmware);
     qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
-    netboot_fw_prop = object_property_get_str(new, "netboot_fw", &error_abort);
-    if (!strlen(netboot_fw_prop)) {
-        qdev_prop_set_string(dev, "netboot_fw", netboot_fw);
-    }
-    g_free(netboot_fw_prop);
     object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
                               new);
     object_unref(new);
@@ -284,7 +278,7 @@ static void ccw_init(MachineState *machine)
     s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
                       machine->initrd_filename,
                       machine->firmware ?: "s390-ccw.img",
-                      "s390-netboot.img", true);
+                      true);
 
     dev = qdev_new(TYPE_S390_PCI_HOST_BRIDGE);
     object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
pc-bios/meson.build +0 -1
index 090379763e..4823dff189 100644
@@ -68,7 +68,6 @@ blobs = [
   'kvmvapic.bin',
   'pvh.bin',
   's390-ccw.img',
-  's390-netboot.img',
   'slof.bin',
   'skiboot.lid',
   'palcode-clipper',
Signature · 1 line
2.45.1
#5 lore raw

PATCH v2 5/18 pc-bios/s390-ccw: Merge netboot.mak into the main Makefile

In reply to [email protected]

From: Jared Rossi <[email protected]>

Now that the netboot code has been merged into the main s390-ccw.img, it also does not make sense to keep the build rules in a separate file. Thus let's merge netboot.mak into the main Makefile.

Co-authored by: Thomas Huth <[email protected]>

---
 pc-bios/s390-ccw/netboot.mak |  45 ---------------------------------
 pc-bios/s390-ccw/Makefile    |  47 ++++++++++++++++++++++++++++++++++-
 pc-bios/s390-netboot.img     | Bin 67232 -> 0 bytes
 3 files changed, 46 insertions(+), 46 deletions(-)
 delete mode 100644 pc-bios/s390-ccw/netboot.mak
 delete mode 100644 pc-bios/s390-netboot.img
pc-bios/s390-ccw/netboot.mak deleted +0 -45
deleted file mode 100644
index 0a24257ff4..0000000000
@@ -1,45 +0,0 @@
-
-# libc files:
-
-LIBC_CFLAGS = $(EXTRA_CFLAGS) $(CFLAGS) $(LIBC_INC) $(LIBNET_INC) \
-	      -MMD -MP -MT $@ -MF $(@:%.o=%.d)
-
-CTYPE_OBJS = isdigit.o isxdigit.o toupper.o
-%.o : $(SLOF_DIR)/lib/libc/ctype/%.c
-	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,Compiling)
-
-STRING_OBJS = strcat.o strchr.o strrchr.o strcpy.o strlen.o strncpy.o \
-	      strcmp.o strncmp.o strcasecmp.o strncasecmp.o strstr.o \
-	      memset.o memcpy.o memmove.o memcmp.o
-%.o : $(SLOF_DIR)/lib/libc/string/%.c
-	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,Compiling)
-
-STDLIB_OBJS = atoi.o atol.o strtoul.o strtol.o rand.o malloc.o free.o
-%.o : $(SLOF_DIR)/lib/libc/stdlib/%.c
-	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,Compiling)
-
-STDIO_OBJS = sprintf.o snprintf.o vfprintf.o vsnprintf.o vsprintf.o fprintf.o \
-	     printf.o putc.o puts.o putchar.o stdchnls.o fileno.o
-%.o : $(SLOF_DIR)/lib/libc/stdio/%.c
-	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,Compiling)
-
-sbrk.o: $(SLOF_DIR)/slof/sbrk.c
-	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,Compiling)
-
-LIBCOBJS := $(STRING_OBJS) $(CTYPE_OBJS) $(STDLIB_OBJS) $(STDIO_OBJS) sbrk.o
-
-libc.a: $(LIBCOBJS)
-	$(call quiet-command,$(AR) -rc $@ $^,Creating static library)
-
-# libnet files:
-
-LIBNETOBJS := args.o dhcp.o dns.o icmpv6.o ipv6.o tcp.o udp.o bootp.o \
-	      dhcpv6.o ethernet.o ipv4.o ndp.o tftp.o pxelinux.o
-LIBNETCFLAGS = $(EXTRA_CFLAGS) $(CFLAGS) $(LIBC_INC) $(LIBNET_INC) \
-	       -DDHCPARCH=0x1F -MMD -MP -MT $@ -MF $(@:%.o=%.d)
-
-%.o : $(SLOF_DIR)/lib/libnet/%.c
-	$(call quiet-command,$(CC) $(LIBNETCFLAGS) -c -o $@ $<,Compiling)
-
-libnet.a: $(LIBNETOBJS)
-	$(call quiet-command,$(AR) -rc $@ $^,Creating static library)
pc-bios/s390-ccw/Makefile +46 -1

53 lines not on this page · raw message

pc-bios/s390-netboot.img deleted binary +0 -0
deleted file mode 100644
index 6908e49f06801808b826d3a01f88132cf1b2f57c..0000000000000000000000000000000000000000
GIT binary patch
Signature · 1 line
2.45.1
#6 lore raw

PATCH v2 6/18 docs/system/s390x/bootdevices: Update the documentation about network booting

In reply to [email protected]

From: Jared Rossi <[email protected]>

Remove the information about the separate s390-netboot.img from the documentation.

Co-authored by: Thomas Huth <[email protected]>

---
 docs/system/s390x/bootdevices.rst | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)
docs/system/s390x/bootdevices.rst +7 -13
index 1a7a18b43b..c97efb8fc0 100644
@@ -82,23 +82,17 @@ Note that ``0`` can be used to boot the default entry.
 Booting from a network device
 -----------------------------
 
-Beside the normal guest firmware (which is loaded from the file ``s390-ccw.img``
-in the data directory of QEMU, or via the ``-bios`` option), QEMU ships with
-a small TFTP network bootloader firmware for virtio-net-ccw devices, too. This
-firmware is loaded from a file called ``s390-netboot.img`` in the QEMU data
-directory. In case you want to load it from a different filename instead,
-you can specify it via the ``-global s390-ipl.netboot_fw=filename``
-command line option.
-
-The ``bootindex`` property is especially important for booting via the network.
-If you don't specify the ``bootindex`` property here, the network bootloader
-firmware code won't get loaded into the guest memory so that the network boot
-will fail. For a successful network boot, try something like this::
+The firmware that ships with QEMU includes a small TFTP network bootloader
+for virtio-net-ccw devices.  The ``bootindex`` property is especially
+important for booting via the network. If you don't specify the ``bootindex``
+property here, the network bootloader won't be taken into consideration and
+the network boot will fail. For a successful network boot, try something
+like this::
 
  qemu-system-s390x -netdev user,id=n1,tftp=...,bootfile=... \
                    -device virtio-net-ccw,netdev=n1,bootindex=1
 
-The network bootloader firmware also has basic support for pxelinux.cfg-style
+The network bootloader also has basic support for pxelinux.cfg-style
 configuration files. See the `PXELINUX Configuration page
 <https://wiki.syslinux.org/wiki/index.php?title=PXELINUX#Configuration>`__
 for details how to set up the configuration file on your TFTP server.
Signature · 1 line
2.45.1
#7 lore raw

PATCH v2 7/18 pc-bios/s390-ccw: Remove panics from ISO IPL path

In reply to [email protected]

From: Jared Rossi <[email protected]>

Remove panic-on-error from IPL ISO El Torito specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---
 pc-bios/s390-ccw/bootmap.h  | 17 +++++++---
 pc-bios/s390-ccw/s390-ccw.h |  1 +
 pc-bios/s390-ccw/bootmap.c  | 64 ++++++++++++++++++++++++-------------
 3 files changed, 55 insertions(+), 27 deletions(-)
pc-bios/s390-ccw/bootmap.h +12 -5
index bbe2c132aa..cb5346829b 100644
@@ -385,17 +385,24 @@ static inline uint32_t iso_733_to_u32(uint64_t x)
 
 #define ISO_PRIMARY_VD_SECTOR 16
 
-static inline void read_iso_sector(uint32_t block_offset, void *buf,
+static inline int read_iso_sector(uint32_t block_offset, void *buf,
                                    const char *errmsg)
 {
-    IPL_assert(virtio_read_many(block_offset, buf, 1) == 0, errmsg);
+    if (virtio_read(block_offset, buf)) {
+        puts(errmsg);
+        return 1;
+    }
+    return 0;
 }
 
-static inline void read_iso_boot_image(uint32_t block_offset, void *load_addr,
+static inline int read_iso_boot_image(uint32_t block_offset, void *load_addr,
                                        uint32_t blks_to_load)
 {
-    IPL_assert(virtio_read_many(block_offset, load_addr, blks_to_load) == 0,
-               "Failed to read boot image!");
+    if (!virtio_read_many(block_offset, load_addr, blks_to_load)) {
+        puts("Failed to read boot image!");
+        return 1;
+    }
+    return 0;
 }
 
 #define ISO9660_MAX_DIR_DEPTH 8
pc-bios/s390-ccw/s390-ccw.h +1 -0
index 0ed7eb8ade..cbd92f3671 100644
@@ -30,6 +30,7 @@ typedef unsigned long long u64;
 #define EIO     1
 #define EBUSY   2
 #define ENODEV  3
+#define EINVAL  4
 
 #ifndef MIN
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
pc-bios/s390-ccw/bootmap.c +42 -22

134 lines not on this page · raw message

Signature · 1 line
2.45.1
#8 lore raw

Re: [PATCH 07/18] pc-bios/s390-ccw: Remove panics from ISO IPL path

Quoted 32 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Remove panic-on-error from IPL ISO El Torito specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---
  pc-bios/s390-ccw/bootmap.h  | 17 +++++++---
  pc-bios/s390-ccw/s390-ccw.h |  1 +
  pc-bios/s390-ccw/bootmap.c  | 64 ++++++++++++++++++++++++-------------
  3 files changed, 55 insertions(+), 27 deletions(-)
pc-bios/s390-ccw/bootmap.h +5 -2
index bbe2c132aa..cb5346829b 100644
@@ -385,17 +385,24 @@ static inline uint32_t iso_733_to_u32(uint64_t x)
 
  #define ISO_PRIMARY_VD_SECTOR 16
 
-static inline void read_iso_sector(uint32_t block_offset, void *buf,
+static inline int read_iso_sector(uint32_t block_offset, void *buf,
                                     const char *errmsg)
  {
-    IPL_assert(virtio_read_many(block_offset, buf, 1) == 0, errmsg);
+    if (virtio_read(block_offset, buf)) {
+        puts(errmsg);
+        return 1;
+    }

pc-bios/s390-ccw/bootmap.h static inline uint32_t iso_733_to_u32(uint64_t x) · line 401

Quoted 10 lines
pc-bios/s390-ccw/bootmap.h +3 -3
+    return 0;
  }
 
-static inline void read_iso_boot_image(uint32_t block_offset, void *load_addr,
+static inline int read_iso_boot_image(uint32_t block_offset, void *load_addr,
                                         uint32_t blks_to_load)
  {
-    IPL_assert(virtio_read_many(block_offset, load_addr, blks_to_load) == 0,
-               "Failed to read boot image!");
+    if (!virtio_read_many(block_offset, load_addr, blks_to_load)) {

That "!" looks wrong here? Or do I misunderstood the original IPL_assert() condition?

Quoted 46 lines
pc-bios/s390-ccw/bootmap.h +4 -0
+        puts("Failed to read boot image!");
+        return 1;
+    }
+    return 0;
  }
 
  #define ISO9660_MAX_DIR_DEPTH 8
pc-bios/s390-ccw/s390-ccw.h +1 -0
index 0ed7eb8ade..cbd92f3671 100644
@@ -30,6 +30,7 @@ typedef unsigned long long u64;
  #define EIO     1
  #define EBUSY   2
  #define ENODEV  3
+#define EINVAL  4
 
  #ifndef MIN
  #define MIN(a, b) (((a) < (b)) ? (a) : (b))
pc-bios/s390-ccw/bootmap.c +8 -4
index 414c3f1b47..31cf0f6d97 100644
@@ -678,8 +678,10 @@ static bool is_iso_bc_entry_compatible(IsoBcSection *s)
      if (s->unused || !s->sector_count) {
          return false;
      }
-    read_iso_sector(bswap32(s->load_rba), magic_sec,
-                    "Failed to read image sector 0");
+    if (read_iso_sector(bswap32(s->load_rba), magic_sec,
+                    "Failed to read image sector 0")) {
+        return false;
+    }
 
      /* Checking bytes 8 - 32 for S390 Linux magic */
      return !memcmp(magic_sec + 8, linux_s390_magic, 24);
@@ -706,14 +708,18 @@ static inline uint32_t iso_get_file_size(uint32_t load_rba)
      sec_offset[0] = 0;
 
      while (level >= 0) {
-        IPL_assert(sec_offset[level] <= ISO_SECTOR_SIZE,
-                   "Directory tree structure violation");
+        if (sec_offset[level] > ISO_SECTOR_SIZE) {
+            puts("Directory tree structure violation");
+            return -EIO;
+        }

pc-bios/s390-ccw/bootmap.c static inline uint32_t iso_get_file_size(uint32_t load_rba) · line 722

Quoted 10 lines
pc-bios/s390-ccw/bootmap.c +4 -2
 
          cur_record = (IsoDirHdr *)(temp + sec_offset[level]);
 
          if (sec_offset[level] == 0) {
-            read_iso_sector(sec_loc[level], temp,
-                            "Failed to read ISO directory");
+            if (virtio_read(sec_loc[level], temp)) {
+                puts("Failed to read ISO directory");
+                return -EIO;
+            }

Any reasons for switching from read_iso_sector() directly to virtio_read() here?

Apart from that, patch looks fine for me, thanks for doing this clean-up work!

Thomas

#9 lore raw

Re: [PATCH 07/18] pc-bios/s390-ccw: Remove panics from ISO IPL path

Quoted 36 lines · Thomas Huth
Quoted 35 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Remove panic-on-error from IPL ISO El Torito specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---
  pc-bios/s390-ccw/bootmap.h  | 17 +++++++--- pc-bios/s390-ccw/s390-ccw.h |  1 + pc-bios/s390-ccw/bootmap.c  | 64 ++++++++++++++++++++++++-------------

  3 files changed, 55 insertions(+), 27 deletions(-)
pc-bios/s390-ccw/bootmap.h +7 -1
index bbe2c132aa..cb5346829b 100644
@@ -385,17 +385,24 @@ static inline uint32_t iso_733_to_u32(uint64_t x)
     #define ISO_PRIMARY_VD_SECTOR 16
   -static inline void read_iso_sector(uint32_t block_offset, void *buf,
+static inline int read_iso_sector(uint32_t block_offset, void *buf,
                                      const char *errmsg)
   {
-    IPL_assert(virtio_read_many(block_offset, buf, 1) == 0, errmsg);
+    if (virtio_read(block_offset, buf)) {
+        puts(errmsg);
+        return 1;
+    }
+    return 0;
   }
   -static inline void read_iso_boot_image(uint32_t block_offset, void *load_addr,
+static inline int read_iso_boot_image(uint32_t block_offset, void 
 *load_addr,
Quoted 9 lines

pc-bios/s390-ccw/bootmap.h static inline uint32_t iso_733_to_u32(uint64_t x) · line 401

Quoted 6 lines
pc-bios/s390-ccw/bootmap.h +1 -2
                                          uint32_t blks_to_load)
   {
-    IPL_assert(virtio_read_many(block_offset, load_addr, 
 blks_to_load) == 0,
-               "Failed to read boot image!");
+    if (!virtio_read_many(block_offset, load_addr, blks_to_load)) {

That "!" looks wrong here? Or do I misunderstood the original IPL_assert() condition?

Basically all of the IPL_assert() conditions become logically flipped, but it is intended. IPL_assert() panics if success condition is NOT met, but in the new version an error code is returned if an failure condition IS met, so we are branching on the inverse condition.

Quoted 46 lines
Quoted 46 lines
pc-bios/s390-ccw/bootmap.h +4 -0
+        puts("Failed to read boot image!");
+        return 1;
+    }
+    return 0;
   }
     #define ISO9660_MAX_DIR_DEPTH 8
pc-bios/s390-ccw/s390-ccw.h +1 -0
index 0ed7eb8ade..cbd92f3671 100644
@@ -30,6 +30,7 @@ typedef unsigned long long u64;
   #define EIO     1
   #define EBUSY   2
   #define ENODEV  3
+#define EINVAL  4
     #ifndef MIN
   #define MIN(a, b) (((a) < (b)) ? (a) : (b))
pc-bios/s390-ccw/bootmap.c +8 -4
index 414c3f1b47..31cf0f6d97 100644
@@ -678,8 +678,10 @@ static bool 
 is_iso_bc_entry_compatible(IsoBcSection *s)
       if (s->unused || !s->sector_count) {
           return false;
       }
-    read_iso_sector(bswap32(s->load_rba), magic_sec,
-                    "Failed to read image sector 0");
+    if (read_iso_sector(bswap32(s->load_rba), magic_sec,
+                    "Failed to read image sector 0")) {
+        return false;
+    }
         /* Checking bytes 8 - 32 for S390 Linux magic */
       return !memcmp(magic_sec + 8, linux_s390_magic, 24);
@@ -706,14 +708,18 @@ static inline uint32_t 
 iso_get_file_size(uint32_t load_rba)
       sec_offset[0] = 0;
         while (level >= 0) {
-        IPL_assert(sec_offset[level] <= ISO_SECTOR_SIZE,
-                   "Directory tree structure violation");
+        if (sec_offset[level] > ISO_SECTOR_SIZE) {
+            puts("Directory tree structure violation");
+            return -EIO;
+        }
             cur_record = (IsoDirHdr *)(temp + sec_offset[level]);
             if (sec_offset[level] == 0) {
Quoted 8 lines

pc-bios/s390-ccw/bootmap.c static inline uint32_t iso_get_file_size(uint32_t load_rba) · line 722

Quoted 6 lines
pc-bios/s390-ccw/bootmap.c +4 -2
-            read_iso_sector(sec_loc[level], temp,
-                            "Failed to read ISO directory");
+            if (virtio_read(sec_loc[level], temp)) {
+                puts("Failed to read ISO directory");
+                return -EIO;
+            }

Any reasons for switching from read_iso_sector() directly to virtio_read() here?

I think this is just an oversight on my part.  I had thought to remove the read_iso_sector() function entirely since it is just a wrapper for virtio_read() that becomes redundant once the panic is removed, but it looks like I wasn't consistent with where I removed it.  In my opinion we can remove read_iso_sector() and just call virtio_read(), but either way it should be consistent, so I will standardize the calls.  I don't see any compelling reason to keep the read_iso_sector() function since all it is doing is checking the RC of virtio_read(), which we will want to check anyway to determine if we need to abort the IPL here.

Quoted 5 lines

Apart from that, patch looks fine for me, thanks for doing this clean-up work!

 Thomas

#10 lore raw

Re: [PATCH 07/18] pc-bios/s390-ccw: Remove panics from ISO IPL path

Quoted 18 lines · Jared Rossi
Quoted 16 lines · Thomas Huth
Quoted 15 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Remove panic-on-error from IPL ISO El Torito specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---
  pc-bios/s390-ccw/bootmap.h  | 17 +++++++--- pc-bios/s390-ccw/s390-ccw.h |  1 + pc-bios/s390-ccw/bootmap.c  | 64 ++++++++++++++++++++++++-------------

  3 files changed, 55 insertions(+), 27 deletions(-)
Quoted 11 lines
Quoted 11 lines

pc-bios/s390-ccw/bootmap.h static inline uint32_t iso_733_to_u32(uint64_t x) · line 389

Quoted 11 lines
pc-bios/s390-ccw/bootmap.h +1 -1
index bbe2c132aa..cb5346829b 100644
@@ -385,17 +385,24 @@ static inline uint32_t iso_733_to_u32(uint64_t x)
     #define ISO_PRIMARY_VD_SECTOR 16
   -static inline void read_iso_sector(uint32_t block_offset, void *buf,
+static inline int read_iso_sector(uint32_t block_offset, void *buf,
                                      const char *errmsg)
   {
-    IPL_assert(virtio_read_many(block_offset, buf, 1) == 0, errmsg);

This IPL_assert() made sure that virtio_read_many() returned 0 (for success)...

Quoted 1 line
Quoted 1 line

pc-bios/s390-ccw/bootmap.h static inline uint32_t iso_733_to_u32(uint64_t x) · line 391

Quoted 1 line
pc-bios/s390-ccw/bootmap.h +1 -0
+    if (virtio_read(block_offset, buf)) {

... so the new code here checks that virtio_read() (which returns the same error code as virtio_read_many()) does *not* return 0 to signal that there was an error...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
pc-bios/s390-ccw/bootmap.h +4 -0
+        puts(errmsg);
+        return 1;
+    }
+    return 0;
   }
Quoted 8 lines
Quoted 8 lines

pc-bios/s390-ccw/bootmap.h static inline uint32_t iso_733_to_u32(uint64_t x) · line 397

Quoted 8 lines
pc-bios/s390-ccw/bootmap.h +1 -2
   -static inline void read_iso_boot_image(uint32_t block_offset, void *load_addr,
+static inline int read_iso_boot_image(uint32_t block_offset, void 
 *load_addr,
                                          uint32_t blks_to_load)
   {
-    IPL_assert(virtio_read_many(block_offset, load_addr, blks_to_load) 
 == 0,
-               "Failed to read boot image!");

... and this IPL_assert() also checks that virtio_read_many() returns 0 for success...

Quoted 1 line
Quoted 1 line

pc-bios/s390-ccw/bootmap.h static inline uint32_t iso_733_to_u32(uint64_t x) · line 401

Quoted 1 line
pc-bios/s390-ccw/bootmap.h +1 -0
+    if (!virtio_read_many(block_offset, load_addr, blks_to_load)) {

... but this code here checks that virtio_read_many() now returns 0 to signal that there is an error...

Either I need more coffee or one of the two if-conditions is wrong...?

Quoted 7 lines
Quoted 2 lines

That "!" looks wrong here? Or do I misunderstood the original IPL_assert() condition?

Basically all of the IPL_assert() conditions become logically flipped, but it is intended. IPL_assert() panics if success condition is NOT met, but in the new version an error code is returned if an failure condition IS met, so we are branching on the inverse condition.

Why is one of the two if-statements using a "!" and why is one without it?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
pc-bios/s390-ccw/bootmap.h +4 -0
+        puts("Failed to read boot image!");
+        return 1;
+    }
+    return 0;
   }
     #define ISO9660_MAX_DIR_DEPTH 8

...

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
pc-bios/s390-ccw/bootmap.h +4 -2
@@ -706,14 +708,18 @@ static inline uint32_t iso_get_file_size(uint32_t 
 load_rba)
       sec_offset[0] = 0;
         while (level >= 0) {
-        IPL_assert(sec_offset[level] <= ISO_SECTOR_SIZE,
-                   "Directory tree structure violation");
+        if (sec_offset[level] > ISO_SECTOR_SIZE) {
+            puts("Directory tree structure violation");
+            return -EIO;
+        }
             cur_record = (IsoDirHdr *)(temp + sec_offset[level]);
             if (sec_offset[level] == 0) {
Quoted 8 lines

pc-bios/s390-ccw/bootmap.h static inline uint32_t iso_get_file_size(uint32_t · line 720

Quoted 6 lines
pc-bios/s390-ccw/bootmap.h +4 -2
-            read_iso_sector(sec_loc[level], temp,
-                            "Failed to read ISO directory");
+            if (virtio_read(sec_loc[level], temp)) {
+                puts("Failed to read ISO directory");
+                return -EIO;
+            }

Any reasons for switching from read_iso_sector() directly to virtio_read() here?

Quoted 9 lines

I think this is just an oversight on my part.  I had thought to remove the read_iso_sector() function entirely since it is just a wrapper for virtio_read() that becomes redundant once the panic is removed, but it looks like I wasn't consistent with where I removed it.  In my opinion we can remove read_iso_sector() and just call virtio_read(), but either way it should be consistent, so I will standardize the calls.  I don't see any compelling reason to keep the read_iso_sector() function since all it is doing is checking the RC of virtio_read(), which we will want to check anyway to determine if we need to abort the IPL here.

I agree, I also don't see a compelling reason for keeping read_iso_sector() anymore.

Thomas

#11 lore raw

Re: [PATCH 07/18] pc-bios/s390-ccw: Remove panics from ISO IPL path

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+    if (!virtio_read_many(block_offset, load_addr, blks_to_load)) {

... but this code here checks that virtio_read_many() now returns 0 to signal that there is an error...

Either I need more coffee or one of the two if-conditions is wrong...?

Hmm, I think you are sufficiently caffeinated... I agree that something is mixed up here. I suspect I got some wires crossed when I was doing the read_iso_sector() rework/removal.  I will double check all of the IPL_assert() reworks and uniformly remove the read_iso_sector() calls so it is consistent in that regard.

I’ll also take a closer look at my test coverage, because the mismatched error conditions should always cause incorrect IPL behavior here, which seems to indicate this code path was not properly exercised...

Jared Rossi

#12 lore raw

PATCH v2 8/18 pc-bios/s390-ccw: Remove panics from ECKD IPL path

In reply to [email protected]

From: Jared Rossi <[email protected]>

Remove panic-on-error from ECKD block device IPL specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---
 pc-bios/s390-ccw/bootmap.c | 183 +++++++++++++++++++++++++------------
 1 file changed, 125 insertions(+), 58 deletions(-)
pc-bios/s390-ccw/bootmap.c +125 -58
index 0751a225cd..dc7200c264 100644
@@ -145,14 +145,17 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
     bool more_data;
 
     memset(_bprs, FREE_SPACE_FILLER, sizeof(_bprs));
-    read_block(blk, bprs, "BPRS read failed");
+    if (virtio_read(blk, bprs)) {
+        puts("BPRS read failed");
+        return -EIO;
+    }
 
     do {
         more_data = false;
         for (j = 0;; j++) {
             block_nr = gen_eckd_block_num(&bprs[j].xeckd, ldipl);
             if (is_null_block_number(block_nr)) { /* end of chunk */
-                break;
+                return 0; /* use 0 to indicate end of load, not real block 0 */
             }
 
             /* we need the updated blockno for the next indirect entry
@@ -163,15 +166,20 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
             }
 
             /* List directed pointer does not store block size */
-            IPL_assert(ldipl || block_size_ok(bprs[j].xeckd.bptr.size),
-                       "bad chunk block size");
+            if (!ldipl && !block_size_ok(bprs[j].xeckd.bptr.size)) {
+                puts("Bad chunk block size");
+                return -EIO;
+            }
 
             if (!eckd_valid_address(&bprs[j].xeckd, ldipl)) {
                 /*
                  * If an invalid address is found during LD-IPL then break and
-                 * retry as CCW
+                 * retry as CCW-IPL, otherwise abort on error
                  */
-                IPL_assert(ldipl, "bad chunk ECKD addr");
+                if (!ldipl) {
+                    puts("Bad chunk ECKD address");
+                    return -EIO;
+                }
                 break;
             }
 
@@ -189,7 +197,10 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
                  * I.e. the next ptr must point to the unused memory area
                  */
                 memset(_bprs, FREE_SPACE_FILLER, sizeof(_bprs));
-                read_block(block_nr, bprs, "BPRS continuation read failed");
+                if (virtio_read(block_nr, bprs)) {
+                    puts("BPRS continuation read failed");
+                    return -EIO;
+                }
                 more_data = true;
                 break;
             }
@@ -198,7 +209,10 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
              * to memory (address).
              */
             rc = virtio_read_many(block_nr, (void *)(*address), count + 1);
-            IPL_assert(rc == 0, "code chunk read failed");
+            if (rc != 0) {
+                puts("Code chunk read failed");
+                return -EIO;
+            }
 
             *address += (count + 1) * virtio_get_block_size();
         }
@@ -232,7 +246,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
 
     /* Get Stage1b data */
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(s1b_block_nr, s1b, "Cannot read stage1b boot loader");
+    if (virtio_read(s1b_block_nr, s1b)) {
+        puts("Cannot read stage1b boot loader");
+        return -EIO;
+    }
 
     memset(_s2, FREE_SPACE_FILLER, sizeof(_s2));
 
@@ -244,7 +261,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
             break;
         }
 
-        read_block(cur_block_nr, s2_cur_blk, "Cannot read stage2 boot loader");
+        if (virtio_read(cur_block_nr, s2_cur_blk)) {
+            puts("Cannot read stage2 boot loader");
+            return -EIO;
+        }
 
         if (find_zipl_boot_menu_banner(&banner_offset)) {
             /*
@@ -252,8 +272,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
              * possibility of menu data spanning multiple blocks.
              */
             if (prev_block_nr) {
-                read_block(prev_block_nr, s2_prev_blk,
-                           "Cannot read stage2 boot loader");
+                if (virtio_read(prev_block_nr, s2_prev_blk)) {
+                    puts("Cannot read stage2 boot loader");
+                    return -EIO;
+                }
             }
 
             if (i + 1 < STAGE2_BLK_CNT_MAX) {
@@ -261,8 +283,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
             }
 
             if (next_block_nr && !is_null_block_number(next_block_nr)) {
-                read_block(next_block_nr, s2_next_blk,
-                           "Cannot read stage2 boot loader");
+                if (virtio_read(next_block_nr, s2_next_blk)) {
+                    puts("Cannot read stage2 boot loader");
+                    return -EIO;
+                }
             }
 
             return menu_get_zipl_boot_index(s2_cur_blk + banner_offset);
@@ -275,7 +299,7 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
     return 0;
 }
 
-static void run_eckd_boot_script(block_number_t bmt_block_nr,
+static int run_eckd_boot_script(block_number_t bmt_block_nr,
                                  block_number_t s1b_block_nr)
 {
     int i;
@@ -292,17 +316,28 @@ static void run_eckd_boot_script(block_number_t bmt_block_nr,
     }
 
     debug_print_int("loadparm", loadparm);
-    IPL_assert(loadparm < MAX_BOOT_ENTRIES, "loadparm value greater than"
-               " maximum number of boot entries allowed");
+    if (loadparm >= MAX_BOOT_ENTRIES) {
+        puts("loadparm value greater than max number of boot entries allowed");
+        return -EINVAL;
+    }
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(bmt_block_nr, sec, "Cannot read Boot Map Table");
+    if (virtio_read(bmt_block_nr, sec)) {
+        puts("Cannot read Boot Map Table");
+        return -EIO;
+    }
 
     block_nr = gen_eckd_block_num(&bmt->entry[loadparm].xeckd, ldipl);
-    IPL_assert(block_nr != -1, "Cannot find Boot Map Table Entry");
+    if (block_nr == NULL_BLOCK_NR) {
+        puts("Cannot find Boot Map Table Entry");
+        return -EIO;
+    }
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(block_nr, sec, "Cannot read Boot Map Script");
+    if (virtio_read(block_nr, sec)) {
+        puts("Cannot read Boot Map Script");
+        return -EIO;
+    }
 
     for (i = 0; bms->entry[i].type == BOOT_SCRIPT_LOAD ||
                 bms->entry[i].type == BOOT_SCRIPT_SIGNATURE; i++) {
@@ -317,21 +352,28 @@ static void run_eckd_boot_script(block_number_t bmt_block_nr,
 
         do {
             block_nr = load_eckd_segments(block_nr, ldipl, &address);
-        } while (block_nr != -1);
+        } while (block_nr > 0);
+
+        if (block_nr < 0) {
+            return ldipl ? 0 : -EIO;
+        }
     }
 
     if (ldipl && bms->entry[i].type != BOOT_SCRIPT_EXEC) {
         /* Abort LD-IPL and retry as CCW-IPL */
-        return;
+        return 0;
     }
 
-    IPL_assert(bms->entry[i].type == BOOT_SCRIPT_EXEC,
-               "Unknown script entry type");
+    if (bms->entry[i].type != BOOT_SCRIPT_EXEC) {
+        puts("Unknown script entry type");
+        return -EINVAL;
+    }
     write_reset_psw(bms->entry[i].address.load_address); /* no return */
     jump_to_IPL_code(0); /* no return */
+    return 1;
 }
 
-static void ipl_eckd_cdl(void)
+static int ipl_eckd_cdl(void)
 {
     XEckdMbr *mbr;
     EckdCdlIpl2 *ipl2 = (void *)sec;
@@ -342,20 +384,23 @@ static void ipl_eckd_cdl(void)
     puts("CDL");
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(1, ipl2, "Cannot read IPL2 record at block 1");
+    if (virtio_read(1, ipl2)) {
+        puts("Cannot read IPL2 record at block 1");
+        return -EIO;
+    }
 
     mbr = &ipl2->mbr;
     if (!magic_match(mbr, ZIPL_MAGIC)) {
         puts("No zIPL section in IPL2 record.");
-        return;
+        return 0;
     }
     if (!block_size_ok(mbr->blockptr.xeckd.bptr.size)) {
         puts("Bad block size in zIPL section of IPL2 record.");
-        return;
+        return 0;
     }
     if (mbr->dev_type != DEV_TYPE_ECKD) {
         puts("Non-ECKD device type in zIPL section of IPL2 record.");
-        return;
+        return 0;
     }
 
     /* save pointer to Boot Map Table */
@@ -365,19 +410,21 @@ static void ipl_eckd_cdl(void)
     s1b_block_nr = eckd_block_num(&ipl2->stage1.seek[0].chs);
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(2, vlbl, "Cannot read Volume Label at block 2");
+    if (virtio_read(2, vlbl)) {
+        puts("Cannot read Volume Label at block 2");
+        return -EIO;
+    }
     if (!magic_match(vlbl->key, VOL1_MAGIC)) {
         puts("Invalid magic of volume label block.");
-        return;
+        return 0;
     }
     if (!magic_match(vlbl->f.key, VOL1_MAGIC)) {
         puts("Invalid magic of volser block.");
-        return;
+        return 0;
     }
     print_volser(vlbl->f.volser);
 
-    run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
-    /* no return */
+    return run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
 }
 
 static void print_eckd_ldl_msg(ECKD_IPL_mode_t mode)
@@ -403,7 +450,7 @@ static void print_eckd_ldl_msg(ECKD_IPL_mode_t mode)
     print_volser(vlbl->volser);
 }
 
-static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
+static int ipl_eckd_ldl(ECKD_IPL_mode_t mode)
 {
     block_number_t bmt_block_nr, s1b_block_nr;
     EckdLdlIpl1 *ipl1 = (void *)sec;
@@ -415,10 +462,13 @@ static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
     /* DO NOT read BootMap pointer (only one, xECKD) at block #2 */
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(0, sec, "Cannot read block 0 to grab boot info.");
+    if (virtio_read(0, sec)) {
+        puts("Cannot read block 0 to grab boot info.");
+        return -EIO;
+    }
     if (mode == ECKD_LDL_UNLABELED) {
         if (!magic_match(ipl1->bip.magic, ZIPL_MAGIC)) {
-            return; /* not applicable layout */
+            return 0; /* not applicable layout */
         }
         puts("unlabeled LDL.");
     }
@@ -430,8 +480,7 @@ static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
     /* save pointer to Stage1b Data */
     s1b_block_nr = eckd_block_num(&ipl1->stage1.seek[0].chs);
 
-    run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
-    /* no return */
+    return run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
 }
 
 static block_number_t eckd_find_bmt(ExtEckdBlockPtr *ptr)
@@ -441,11 +490,14 @@ static block_number_t eckd_find_bmt(ExtEckdBlockPtr *ptr)
     BootRecord *br;
 
     blockno = gen_eckd_block_num(ptr, 0);
-    read_block(blockno, tmp_sec, "Cannot read boot record");
+    if (virtio_read(blockno, tmp_sec)) {
+        puts("Cannot read boot record");
+        return -EIO;
+    }
     br = (BootRecord *)tmp_sec;
     if (!magic_match(br->magic, ZIPL_MAGIC)) {
         /* If the boot record is invalid, return and try CCW-IPL instead */
-        return NULL_BLOCK_NR;
+        return 0;
     }
 
     return gen_eckd_block_num(&br->pgt.xeckd, 1);
@@ -470,7 +522,7 @@ static void print_eckd_msg(void)
     printf("%s", msg);
 }
 
-static void ipl_eckd(void)
+static int ipl_eckd(void)
 {
     IplVolumeLabel *vlbl = (void *)sec;
     LDL_VTOC *vtoc = (void *)sec;
@@ -480,7 +532,10 @@ static void ipl_eckd(void)
 
     /* Block 2 can contain either the CDL VOL1 label or the LDL VTOC */
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(2, vlbl, "Cannot read block 2");
+    if (virtio_read(2, vlbl)) {
+        puts("Cannot read block 2");
+        return -EIO;
+    }
 
     /*
      * First check for a list-directed-format pointer which would
@@ -490,34 +545,46 @@ static void ipl_eckd(void)
         ldipl_bmt = eckd_find_bmt((ExtEckdBlockPtr *)&vlbl->f.br);
         if (ldipl_bmt) {
             puts("List-Directed");
-            /* LD-IPL does not use the S1B bock, just make it NULL */
-            run_eckd_boot_script(ldipl_bmt, NULL_BLOCK_NR);
-            /* Only return in error, retry as CCW-IPL */
+            /*
+             * LD-IPL does not use the S1B bock, just make it NULL_BLOCK_NR.
+             * In some failure cases retry IPL before aborting.
+             */
+            if (run_eckd_boot_script(ldipl_bmt, NULL_BLOCK_NR)) {
+                return -EIO;
+            }
+            /* Non-fatal error, retry as CCW-IPL */
             printf("Retrying IPL ");
             print_eckd_msg();
         }
         memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-        read_block(2, vtoc, "Cannot read block 2");
+        if (virtio_read(2, vtoc)) {
+            puts("Cannot read block 2");
+            return -EIO;
+        }
     }
 
     /* Not list-directed */
     if (magic_match(vtoc->magic, VOL1_MAGIC)) {
-        ipl_eckd_cdl(); /* may return in error */
+        if (ipl_eckd_cdl()) {
+            return 1;
+        }
     }
 
     if (magic_match(vtoc->magic, CMS1_MAGIC)) {
-        ipl_eckd_ldl(ECKD_CMS); /* no return */
+        return ipl_eckd_ldl(ECKD_CMS);
     }
     if (magic_match(vtoc->magic, LNX1_MAGIC)) {
-        ipl_eckd_ldl(ECKD_LDL); /* no return */
+        return ipl_eckd_ldl(ECKD_LDL);
     }
 
-    ipl_eckd_ldl(ECKD_LDL_UNLABELED); /* it still may return */
+    if (ipl_eckd_ldl(ECKD_LDL_UNLABELED)) {
+        return 1;
+    }
     /*
      * Ok, it is not a LDL by any means.
      * It still might be a CDL with zero record keys for IPL1 and IPL2
      */
-    ipl_eckd_cdl();
+    return ipl_eckd_cdl();
 }
 
 /***********************************************************************
@@ -943,7 +1010,7 @@ static bool has_iso_signature(void)
  * Bus specific IPL sequences
  */
 
-static void zipl_load_vblk(void)
+static int zipl_load_vblk(void)
 {
     int blksize = virtio_get_block_size();
 
@@ -952,7 +1019,7 @@ static void zipl_load_vblk(void)
             virtio_assume_iso9660();
         }
         if (ipl_iso_el_torito()) {
-            return;
+            return 0;
         }
     }
 
@@ -960,21 +1027,21 @@ static void zipl_load_vblk(void)
         puts("Using guessed DASD geometry.");
         virtio_assume_eckd();
     }
-    ipl_eckd();
+    return ipl_eckd();
 }
 
-static void zipl_load_vscsi(void)
+static int zipl_load_vscsi(void)
 {
     if (virtio_get_block_size() == VIRTIO_ISO_BLOCK_SIZE) {
         /* Is it an ISO image in non-CD drive? */
         if (ipl_iso_el_torito()) {
-            return;
+            return 0;
         }
     }
 
     puts("Using guessed DASD geometry.");
     virtio_assume_eckd();
-    ipl_eckd();
+    return ipl_eckd();
 }
 
 /***********************************************************************
Signature · 1 line
2.45.1
#13 lore raw

Re: [PATCH 08/18] pc-bios/s390-ccw: Remove panics from ECKD IPL path

Quoted 24 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Remove panic-on-error from ECKD block device IPL specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---
  pc-bios/s390-ccw/bootmap.c | 183 +++++++++++++++++++++++++------------
  1 file changed, 125 insertions(+), 58 deletions(-)
pc-bios/s390-ccw/bootmap.c +2 -1
index 0751a225cd..dc7200c264 100644
@@ -145,14 +145,17 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
      bool more_data;
 
      memset(_bprs, FREE_SPACE_FILLER, sizeof(_bprs));
-    read_block(blk, bprs, "BPRS read failed");
+    if (virtio_read(blk, bprs)) {
+        puts("BPRS read failed");

pc-bios/s390-ccw/bootmap.c static block_number_t load_eckd_segments(block_number_t blk, bool ldipl, · line 158

Quoted 10 lines
pc-bios/s390-ccw/bootmap.c +3 -1
+        return -EIO;
+    }
 
      do {
          more_data = false;
          for (j = 0;; j++) {
              block_nr = gen_eckd_block_num(&bprs[j].xeckd, ldipl);
              if (is_null_block_number(block_nr)) { /* end of chunk */
-                break;
+                return 0; /* use 0 to indicate end of load, not real block 0 */

Can we be very sure that block 0 is never a valid one, so that returning 0 is OK here? Maybe you could use an error code instead (intruducing e.g. ENOENT ?)

Thomas

#14 lore raw

Re: [PATCH 08/18] pc-bios/s390-ccw: Remove panics from ECKD IPL path

Quoted 29 lines · Thomas Huth
Quoted 28 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Remove panic-on-error from ECKD block device IPL specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---
  pc-bios/s390-ccw/bootmap.c | 183 +++++++++++++++++++++++++------------

  1 file changed, 125 insertions(+), 58 deletions(-)
pc-bios/s390-ccw/bootmap.c +4 -1
index 0751a225cd..dc7200c264 100644
@@ -145,14 +145,17 @@ static block_number_t 
 load_eckd_segments(block_number_t blk, bool ldipl,
       bool more_data;
         memset(_bprs, FREE_SPACE_FILLER, sizeof(_bprs));
-    read_block(blk, bprs, "BPRS read failed");
+    if (virtio_read(blk, bprs)) {
+        puts("BPRS read failed");
+        return -EIO;
+    }
         do {
           more_data = false;
Quoted 8 lines
Quoted 6 lines
pc-bios/s390-ccw/bootmap.c +0 -0
           for (j = 0;; j++) {
               block_nr = gen_eckd_block_num(&bprs[j].xeckd, ldipl);

              if (is_null_block_number(block_nr)) { /* end of chunk */ -                break;
+                return 0; /* use 0 to indicate end of load, not real block 0 */

Can we be very sure that block 0 is never a valid one, so that returning 0 is OK here? Maybe you could use an error code instead (intruducing e.g. ENOENT ?)

Yes, because block 0 is an administrative block and is reserved in both CDL and LDL disk formats.  That being said, it is simple enough to use a specific RC instead, which would be more resilient to format changes in the future (e.g. if CDL and LDL are no longer written for list-directed IPL formatted disks), so it is probably worth while to add a new code as you suggest.

#15 lore raw

PATCH v2 9/18 pc-bios/s390-ccw: Remove panics from SCSI IPL path

In reply to [email protected]

From: Jared Rossi <[email protected]>

Remove panic-on-error from virtio-scsi IPL specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---
 pc-bios/s390-ccw/bootmap.c     |  88 +++++++++++++++-----
 pc-bios/s390-ccw/virtio-scsi.c | 147 ++++++++++++++++++++++-----------
 2 files changed, 165 insertions(+), 70 deletions(-)
pc-bios/s390-ccw/bootmap.c +66 -22
index 31cf0f6d97..0751a225cd 100644
@@ -524,7 +524,7 @@ static void ipl_eckd(void)
  * IPL a SCSI disk
  */
 
-static void zipl_load_segment(ComponentEntry *entry)
+static int zipl_load_segment(ComponentEntry *entry)
 {
     const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));
     ScsiBlockPtr *bprs = (void *)sec;
@@ -544,7 +544,10 @@ static void zipl_load_segment(ComponentEntry *entry)
     do {
         memset(bprs, FREE_SPACE_FILLER, bprs_size);
         fill_hex_val(blk_no, &blockno, sizeof(blockno));
-        read_block(blockno, bprs, err_msg);
+        if (virtio_read(blockno, bprs)) {
+            puts(err_msg);
+            return -EIO;
+        }
 
         for (i = 0;; i++) {
             uint64_t *cur_desc = (void *)&bprs[i];
@@ -572,23 +575,37 @@ static void zipl_load_segment(ComponentEntry *entry)
             }
             address = virtio_load_direct(cur_desc[0], cur_desc[1], 0,
                                          (void *)address);
-            IPL_assert(address != -1, "zIPL load segment failed");
+            if (!address) {
+                puts("zIPL load segment failed");
+                return -EIO;
+            }
         }
     } while (blockno);
+
+    return 0;
 }
 
 /* Run a zipl program */
-static void zipl_run(ScsiBlockPtr *pte)
+static int zipl_run(ScsiBlockPtr *pte)
 {
     ComponentHeader *header;
     ComponentEntry *entry;
     uint8_t tmp_sec[MAX_SECTOR_SIZE];
 
-    read_block(pte->blockno, tmp_sec, "Cannot read header");
+    if (virtio_read(pte->blockno, tmp_sec)) {
+        puts("Cannot read header");
+        return -EIO;
+    }
     header = (ComponentHeader *)tmp_sec;
 
-    IPL_assert(magic_match(tmp_sec, ZIPL_MAGIC), "No zIPL magic in header");
-    IPL_assert(header->type == ZIPL_COMP_HEADER_IPL, "Bad header type");
+    if (!magic_match(tmp_sec, ZIPL_MAGIC)) {
+        puts("No zIPL magic in header");
+        return -EINVAL;
+    }
+    if (header->type != ZIPL_COMP_HEADER_IPL) {
+        puts("Bad header type");
+        return -EINVAL;
+    }
 
     dputs("start loading images\n");
 
@@ -603,22 +620,30 @@ static void zipl_run(ScsiBlockPtr *pte)
             continue;
         }
 
-        zipl_load_segment(entry);
+        if (zipl_load_segment(entry)) {
+            return 1;
+        }
 
         entry++;
 
-        IPL_assert((uint8_t *)(&entry[1]) <= (tmp_sec + MAX_SECTOR_SIZE),
-                   "Wrong entry value");
+        if ((uint8_t *)(&entry[1]) > (tmp_sec + MAX_SECTOR_SIZE)) {
+            puts("Wrong entry value");
+            return -EINVAL;
+        }
     }
 
-    IPL_assert(entry->component_type == ZIPL_COMP_ENTRY_EXEC, "No EXEC entry");
+    if (entry->component_type != ZIPL_COMP_ENTRY_EXEC) {
+        puts("No EXEC entry");
+        return -EINVAL;
+    }
 
     /* should not return */
     write_reset_psw(entry->compdat.load_psw);
     jump_to_IPL_code(0);
+    return 1;
 }
 
-static void ipl_scsi(void)
+static int ipl_scsi(void)
 {
     ScsiMbr *mbr = (void *)sec;
     int program_table_entries = 0;
@@ -629,10 +654,13 @@ static void ipl_scsi(void)
 
     /* Grab the MBR */
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(0, mbr, "Cannot read block 0");
+    if (virtio_read(0, mbr)) {
+        puts("Cannot read block 0");
+        return -EIO;
+    }
 
     if (!magic_match(mbr->magic, ZIPL_MAGIC)) {
-        return;
+        return 0;
     }
 
     puts("Using SCSI scheme.");
@@ -640,11 +668,20 @@ static void ipl_scsi(void)
     IPL_check(mbr->version_id == 1,
               "Unknown MBR layout version, assuming version 1");
     debug_print_int("program table", mbr->pt.blockno);
-    IPL_assert(mbr->pt.blockno, "No Program Table");
+    if (!mbr->pt.blockno) {
+        puts("No Program Table");
+        return -EINVAL;
+    }
 
     /* Parse the program table */
-    read_block(mbr->pt.blockno, sec, "Error reading Program Table");
-    IPL_assert(magic_match(sec, ZIPL_MAGIC), "No zIPL magic in PT");
+    if (virtio_read(mbr->pt.blockno, sec)) {
+        puts("Error reading Program Table");
+        return -EIO;
+    }
+    if (!magic_match(sec, ZIPL_MAGIC)) {
+        puts("No zIPL magic in Program Table");
+        return -EINVAL;
+    }
 
     for (i = 0; i < MAX_BOOT_ENTRIES; i++) {
         if (prog_table->entry[i].scsi.blockno) {
@@ -654,17 +691,22 @@ static void ipl_scsi(void)
     }
 
     debug_print_int("program table entries", program_table_entries);
-    IPL_assert(program_table_entries != 0, "Empty Program Table");
+    if (program_table_entries == 0) {
+        puts("Empty Program Table");
+        return -EINVAL;
+    }
 
     if (menu_is_enabled_enum()) {
         loadparm = menu_get_enum_boot_index(valid_entries);
     }
 
     debug_print_int("loadparm", loadparm);
-    IPL_assert(loadparm < MAX_BOOT_ENTRIES, "loadparm value greater than"
-               " maximum number of boot entries allowed");
+    if (loadparm >= MAX_BOOT_ENTRIES) {
+        puts("loadparm value greater than max number of boot entries allowed");
+        return -EINVAL;
+    }
 
-    zipl_run(&prog_table->entry[loadparm].scsi); /* no return */
+    return zipl_run(&prog_table->entry[loadparm].scsi);
 }
 
 /***********************************************************************
@@ -952,7 +994,9 @@ void zipl_load(void)
         netmain();
     }
 
-    ipl_scsi();
+    if (ipl_scsi()) {
+        panic("\n! Cannot IPL this device !\n");
+    }
 
     switch (virtio_get_device_type()) {
     case VIRTIO_ID_BLOCK:
pc-bios/s390-ccw/virtio-scsi.c +99 -48

305 lines not on this page · raw message

Signature · 1 line
2.45.1
#16 lore raw

Re: [PATCH 09/18] pc-bios/s390-ccw: Remove panics from SCSI IPL path

Quoted 10 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Remove panic-on-error from virtio-scsi IPL specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---

...

pc-bios/s390-ccw/bootmap.c static void zipl_load_segment(ComponentEntry *entry) · line 578

Quoted 6 lines
pc-bios/s390-ccw/bootmap.c +1 -1
@@ -572,23 +575,37 @@ static void zipl_load_segment(ComponentEntry *entry)
              }
              address = virtio_load_direct(cur_desc[0], cur_desc[1], 0,
                                           (void *)address);
-            IPL_assert(address != -1, "zIPL load segment failed");
+            if (!address) {

Shouldn't that be "if (address == -1)" or "if (address < 0)" instead?

Hmm, virtio_load_direct() seems to return an "unsigned long", so maybe that one rather needs to be fixed, too?

Quoted 8 lines
pc-bios/s390-ccw/bootmap.c +5 -0
+                puts("zIPL load segment failed");
+                return -EIO;
+            }
          }
      } while (blockno);
+
+    return 0;
  }

...

pc-bios/s390-ccw/virtio-scsi.c static void prepare_request(VDev *vdev, const void *cdb, int cdb_size, · line 89

Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +2 -3
@@ -78,24 +84,30 @@ static void prepare_request(VDev *vdev, const void *cdb, int cdb_size,
      }
  }
 
-static inline void vs_io_assert(bool term, const char *msg)
+static inline bool vs_io_assert(bool term, const char *msg)
  {
-    if (!term) {
-        virtio_scsi_verify_response(&resp, msg);
+    if (!term && !virtio_scsi_verify_response(&resp, msg)) {

Should that be "||" instead of "&&" ?

Quoted 5 lines
pc-bios/s390-ccw/virtio-scsi.c +3 -0
+        return false;
      }
+
+    return true;
  }

pc-bios/s390-ccw/virtio-scsi.c static void prepare_request(VDev *vdev, const void *cdb, int cdb_size, · line 102

Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +3 -2
 
-static void vs_run(const char *title, VirtioCmd *cmd, VDev *vdev,
+static int vs_run(const char *title, VirtioCmd *cmd, VDev *vdev,
                     const void *cdb, int cdb_size,
                     void *data, uint32_t data_size)
  {
      prepare_request(vdev, cdb, cdb_size, data, data_size);
-    vs_io_assert(virtio_run(vdev, VR_REQUEST, cmd) == 0, title);
+    if (!vs_io_assert(virtio_run(vdev, VR_REQUEST, cmd) == 0, title)) {
+        puts(title);

Shouldn't there be a "return -1;" or something similar here?

pc-bios/s390-ccw/bootmap.c static void zipl_load_segment(ComponentEntry *entry) · line 586

Quoted 4 lines
pc-bios/s390-ccw/bootmap.c +3 -0
+    }
+
+    return 0;
  }

Thomas

#17 lore raw

Re: [PATCH 09/18] pc-bios/s390-ccw: Remove panics from SCSI IPL path

Quoted 21 lines · Thomas Huth
Quoted 10 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Remove panic-on-error from virtio-scsi IPL specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---

...

pc-bios/s390-ccw/bootmap.c static void zipl_load_segment(ComponentEntry *entry) · line 578

Quoted 6 lines
pc-bios/s390-ccw/bootmap.c +1 -1
@@ -572,23 +575,37 @@ static void zipl_load_segment(ComponentEntry *entry)
               }
               address = virtio_load_direct(cur_desc[0], cur_desc[1], 0,
                                            (void *)address);
-            IPL_assert(address != -1, "zIPL load segment failed");
+            if (!address) {

Shouldn't that be "if (address == -1)" or "if (address < 0)" instead?

Quoted 1 line

Hmm, virtio_load_direct() seems to return an "unsigned long", so maybe that one rather needs to be fixed, too?

(see my comments on patch 12)

Quoted 9 lines
Quoted 8 lines
pc-bios/s390-ccw/bootmap.c +5 -0
+                puts("zIPL load segment failed");
+                return -EIO;
+            }
           }
       } while (blockno);
+
+    return 0;
   }

...

Quoted 12 lines

pc-bios/s390-ccw/virtio-scsi.c static void prepare_request(VDev *vdev, const void · line 89

Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +2 -3
@@ -78,24 +84,30 @@ static void prepare_request(VDev *vdev, const void 
 *cdb, int cdb_size,
       }
   }
-static inline void vs_io_assert(bool term, const char *msg)
+static inline bool vs_io_assert(bool term, const char *msg)
   {
-    if (!term) {
-        virtio_scsi_verify_response(&resp, msg);
+    if (!term && !virtio_scsi_verify_response(&resp, msg)) {

Should that be "||" instead of "&&" ?

Ah, never mind, I got it wrong, the "&&" should be fine here.

Thomas

#18 lore raw

PATCH v2 10/18 pc-bios/s390-ccw: Remove panics from DASD IPL path

In reply to [email protected]

From: Jared Rossi <[email protected]>

Remove panic-on-error from DASD IPL specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---
 pc-bios/s390-ccw/dasd-ipl.h |  2 +-
 pc-bios/s390-ccw/dasd-ipl.c | 66 ++++++++++++++++++++-----------------
 2 files changed, 37 insertions(+), 31 deletions(-)
pc-bios/s390-ccw/dasd-ipl.h +1 -1
index c394828906..eb1898c84a 100644
@@ -11,6 +11,6 @@
 #ifndef DASD_IPL_H
 #define DASD_IPL_H
 
-void dasd_ipl(SubChannelId schid, uint16_t cutype);
+int dasd_ipl(SubChannelId schid, uint16_t cutype);
 
 #endif /* DASD_IPL_H */
pc-bios/s390-ccw/dasd-ipl.c +36 -30

126 lines not on this page · raw message

Signature · 1 line
2.45.1
Reviewed-by on v2 10/18
#19 lore raw

Re: [PATCH 10/18] pc-bios/s390-ccw: Remove panics from DASD IPL path

Quoted 8 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Remove panic-on-error from DASD IPL specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

#20 lore raw

PATCH v2 11/18 pc-bios/s390-ccw: Remove panics from Netboot IPL path

In reply to [email protected]

From: Jared Rossi <[email protected]>

Remove panic-on-error from Netboot specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---
 pc-bios/s390-ccw/s390-ccw.h   |  2 +-
 pc-bios/s390-ccw/bootmap.c    |  1 +
 pc-bios/s390-ccw/netmain.c    | 22 +++++++++++++++-------
 pc-bios/s390-ccw/virtio-net.c |  7 +++++--
 4 files changed, 22 insertions(+), 10 deletions(-)
pc-bios/s390-ccw/s390-ccw.h +1 -1
index cbd92f3671..8dac070257 100644
@@ -57,7 +57,7 @@ unsigned int get_loadparm_index(void);
 void main(void);
 
 /* netmain.c */
-void netmain(void);
+int netmain(void);
 
 /* sclp.c */
 void sclp_print(const char *string);
pc-bios/s390-ccw/bootmap.c +1 -0
index dc7200c264..9459e19ffb 100644
@@ -1059,6 +1059,7 @@ void zipl_load(void)
 
     if (virtio_get_device_type() == VIRTIO_ID_NET) {
         netmain();
+        panic("\n! Cannot IPL from this network !\n");
     }
 
     if (ipl_scsi()) {
pc-bios/s390-ccw/netmain.c +15 -7
index bc6ad8695f..013f94d932 100644
@@ -464,7 +464,7 @@ static bool find_net_dev(Schib *schib, int dev_no)
     return false;
 }
 
-static void virtio_setup(void)
+static int virtio_setup(void)
 {
     Schib schib;
     int ssid;
@@ -479,7 +479,10 @@ static void virtio_setup(void)
     enable_mss_facility();
 
     if (store_iplb(&iplb)) {
-        IPL_assert(iplb.pbt == S390_IPL_TYPE_CCW, "IPL_TYPE_CCW expected");
+        if (iplb.pbt != S390_IPL_TYPE_CCW) {
+            puts("IPL_TYPE_CCW expected");
+        }
+
         dev_no = iplb.ccw.devno;
         debug_print_int("device no. ", dev_no);
         net_schid.ssid = iplb.ccw.ssid & 0x3;
@@ -495,10 +498,10 @@ static void virtio_setup(void)
         }
     }
 
-    IPL_assert(found, "No virtio net device found");
+    return found;
 }
 
-void netmain(void)
+int netmain(void)
 {
     filename_ip_t fn_ip;
     int rc, fnlen;
@@ -506,11 +509,15 @@ void netmain(void)
     sclp_setup();
     puts("Network boot starting...");
 
-    virtio_setup();
+    if (!virtio_setup()) {
+        puts("No virtio net device found.");
+        return 1;
+    }
 
     rc = net_init(&fn_ip);
     if (rc) {
-        panic("Network initialization failed. Halting.");
+        puts("Network initialization failed.");
+        return 1;
     }
 
     fnlen = strlen(fn_ip.filename);
@@ -528,5 +535,6 @@ void netmain(void)
         jump_to_low_kernel();
     }
 
-    panic("Failed to load OS from network.");
+    puts("Failed to load OS from network.");
+    return 1;
 }
pc-bios/s390-ccw/virtio-net.c +5 -2
index 2fcb0a58c5..f9854a22c3 100644
@@ -54,8 +54,11 @@ int virtio_net_init(void *mac_addr)
     vdev->guest_features[0] = VIRTIO_NET_F_MAC_BIT;
     virtio_setup_ccw(vdev);
 
-    IPL_assert(vdev->guest_features[0] & VIRTIO_NET_F_MAC_BIT,
-               "virtio-net device does not support the MAC address feature");
+    if (!(vdev->guest_features[0] & VIRTIO_NET_F_MAC_BIT)) {
+        puts("virtio-net device does not support the MAC address feature");
+        return -1;
+    }
+
     memcpy(mac_addr, vdev->config.net.mac, ETH_ALEN);
 
     for (i = 0; i < 64; i++) {
Signature · 1 line
2.45.1
#21 lore raw

Re: [PATCH 11/18] pc-bios/s390-ccw: Remove panics from Netboot IPL path

Quoted 10 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Remove panic-on-error from Netboot specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---

...

Quoted 13 lines

index bc6ad8695f..013f94d932 100644

pc-bios/s390-ccw/netmain.c +1 -1
@@ -464,7 +464,7 @@ static bool find_net_dev(Schib *schib, int dev_no)
      return false;
  }
 
-static void virtio_setup(void)
+static int virtio_setup(void)
  {
      Schib schib;
      int ssid;

pc-bios/s390-ccw/netmain.c static void virtio_setup(void) · line 484

Quoted 7 lines
pc-bios/s390-ccw/netmain.c +3 -1
@@ -479,7 +479,10 @@ static void virtio_setup(void)
      enable_mss_facility();
 
      if (store_iplb(&iplb)) {
-        IPL_assert(iplb.pbt == S390_IPL_TYPE_CCW, "IPL_TYPE_CCW expected");
+        if (iplb.pbt != S390_IPL_TYPE_CCW) {
+            puts("IPL_TYPE_CCW expected");
+        }

I think in this case, the IPL_assert() could maybe even stay: If we end up here without the correct type in iplb.pbt, there was likely a bug elsewhere in the earlier setup code already, or do you see a way we could end up here with another type?

Anyway, if you want to change it, shouldn't there be a "return false" after the puts() statement?

Thomas

#22 lore raw

Re: [PATCH 11/18] pc-bios/s390-ccw: Remove panics from Netboot IPL path

Quoted 25 lines · Thomas Huth
Quoted 10 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Remove panic-on-error from Netboot specific functions so that error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

---

...

Quoted 13 lines

index bc6ad8695f..013f94d932 100644

pc-bios/s390-ccw/netmain.c +1 -0
@@ -464,7 +464,7 @@ static bool find_net_dev(Schib *schib, int dev_no)
       return false;
   }
   -static void virtio_setup(void)
+static int virtio_setup(void)
   {
       Schib schib;
       int ssid;
@@ -479,7 +479,10 @@ static void virtio_setup(void)
       enable_mss_facility();
Quoted 9 lines

pc-bios/s390-ccw/netmain.c static void virtio_setup(void) · line 484

Quoted 6 lines
pc-bios/s390-ccw/netmain.c +3 -1
         if (store_iplb(&iplb)) {
-        IPL_assert(iplb.pbt == S390_IPL_TYPE_CCW, "IPL_TYPE_CCW 
 expected");
+        if (iplb.pbt != S390_IPL_TYPE_CCW) {
+            puts("IPL_TYPE_CCW expected");
+        }

I think in this case, the IPL_assert() could maybe even stay: If we end up here without the correct type in iplb.pbt, there was likely a bug elsewhere in the earlier setup code already, or do you see a way we could end up here with another type?

I agree that the panic can stay in this case. The only way that the PBT could be wrong at this stage is if there were in error earlier when building the IPLB, so it is appropriate to terminate the entire IPL in that case.

Jared Rossi

#23 lore raw

PATCH v2 12/18 pc-bios/s390-ccw: Enable failed IPL to return after error

In reply to [email protected]

From: Jared Rossi <[email protected]>

Remove panic-on-error from IPL functions such that a return code is propagated back to the main IPL calling function (rather than terminating immediately), which facilitates possible error recovery in the future.

A select few panics remain, which indicate fatal non-devices errors that must result in termination.

---
 pc-bios/s390-ccw/s390-ccw.h      |  2 +-
 pc-bios/s390-ccw/virtio.h        |  2 +-
 pc-bios/s390-ccw/bootmap.c       | 53 ++++++++++++++++++--------
 pc-bios/s390-ccw/cio.c           |  3 +-
 pc-bios/s390-ccw/jump2ipl.c      |  5 ++-
 pc-bios/s390-ccw/main.c          | 35 +++++++++--------
 pc-bios/s390-ccw/virtio-blkdev.c |  8 ++--
 pc-bios/s390-ccw/virtio.c        | 65 +++++++++++++++++++++-----------
 8 files changed, 113 insertions(+), 60 deletions(-)
pc-bios/s390-ccw/s390-ccw.h +1 -1
index 8dac070257..7e49da46a5 100644
@@ -78,7 +78,7 @@ void zipl_load(void);
 
 /* jump2ipl.c */
 void write_reset_psw(uint64_t psw);
-void jump_to_IPL_code(uint64_t address);
+int jump_to_IPL_code(uint64_t address);
 void jump_to_low_kernel(void);
 
 /* menu.c */
pc-bios/s390-ccw/virtio.h +1 -1
index 6f9a558ff5..9faf3986b1 100644
@@ -274,7 +274,7 @@ void vring_send_buf(VRing *vr, void *p, int len, int flags);
 int vr_poll(VRing *vr);
 int vring_wait_reply(void);
 int virtio_run(VDev *vdev, int vqid, VirtioCmd *cmd);
-void virtio_setup_ccw(VDev *vdev);
+int virtio_setup_ccw(VDev *vdev);
 
 int virtio_net_init(void *mac_addr);
 
pc-bios/s390-ccw/bootmap.c +38 -15

85 lines not on this page · raw message

pc-bios/s390-ccw/cio.c +2 -1
index 758e74965e..35b08ba7c1 100644
@@ -59,7 +59,8 @@ uint16_t cu_type(SubChannelId schid)
     };
 
     if (do_cio(schid, CU_TYPE_UNKNOWN, ptr2u32(&sense_id_ccw), CCW_FMT1)) {
-        panic("Failed to run SenseID CCw\n");
+        puts("Failed to run SenseID CCW");
+        return CU_TYPE_UNKNOWN;
     }
 
     return sense_data.cu_type;
pc-bios/s390-ccw/jump2ipl.c +3 -2
index 80b7f6a1f3..d45aec6694 100644
@@ -33,7 +33,7 @@ static void jump_to_IPL_addr(void)
     /* should not return */
 }
 
-void jump_to_IPL_code(uint64_t address)
+int jump_to_IPL_code(uint64_t address)
 {
     /* store the subsystem information _after_ the bootmap was loaded */
     write_subsystem_identification();
@@ -68,7 +68,8 @@ void jump_to_IPL_code(uint64_t address)
     asm volatile("lghi %%r1,1\n\t"
                  "diag %%r1,%%r1,0x308\n\t"
                  : : : "1", "memory");
-    panic("\n! IPL returns !\n");
+    puts("IPL code jump failed");
+    return 1;
 }
 
 void jump_to_low_kernel(void)
pc-bios/s390-ccw/main.c +20 -15
index 2345432abb..f818bd7210 100644
@@ -77,6 +77,9 @@ static int is_dev_possibly_bootable(int dev_no, int sch_no)
 
     enable_subchannel(blk_schid);
     cutype = cu_type(blk_schid);
+    if (cutype == CU_TYPE_UNKNOWN) {
+        return -EIO;
+    }
 
     /*
      * Note: we always have to run virtio_is_supported() here to make
@@ -194,10 +197,10 @@ static void boot_setup(void)
     have_iplb = store_iplb(&iplb);
 }
 
-static void find_boot_device(void)
+static bool find_boot_device(void)
 {
     VDev *vdev = virtio_get_device();
-    bool found;
+    bool found = false;
 
     switch (iplb.pbt) {
     case S390_IPL_TYPE_CCW:
@@ -215,10 +218,10 @@ static void find_boot_device(void)
         found = find_subch(iplb.scsi.devno);
         break;
     default:
-        panic("List-directed IPL not supported yet!\n");
+        puts("Invalid IPLB");
     }
 
-    IPL_assert(found, "Boot device not found\n");
+    return found;
 }
 
 static int virtio_setup(void)
@@ -244,11 +247,13 @@ static int virtio_setup(void)
         ret = virtio_scsi_setup_device(blk_schid);
         break;
     default:
-        panic("\n! No IPL device available !\n");
+        puts("\n! No IPL device available !\n");
+        return 1;
     }
 
-    if (!ret) {
-        IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
+    if (!ret && !virtio_ipl_disk_is_valid()) {
+        puts("No valid IPL device detected");
+        return -ENODEV;
     }
 
     return ret;
@@ -259,16 +264,16 @@ static void ipl_boot_device(void)
     switch (cutype) {
     case CU_TYPE_DASD_3990:
     case CU_TYPE_DASD_2107:
-        dasd_ipl(blk_schid, cutype); /* no return */
+        dasd_ipl(blk_schid, cutype);
         break;
     case CU_TYPE_VIRTIO:
-        if (virtio_setup() == 0) {
-            zipl_load();             /* Only returns in case of errors */
+        if (virtio_setup()) {
+            return;    /* Only returns in case of errors */
         }
+        zipl_load();
         break;
     default:
         printf("Attempting to boot from unexpected device type 0x%X", cutype);
-        panic("\nBoot failed.\n");
     }
 }
 
@@ -288,7 +293,8 @@ static void probe_boot_device(void)
                 break;
             }
             if (ret == true) {
-                ipl_boot_device();      /* Only returns if unsuccessful */
+                ipl_boot_device(); /* Only returns if unsuccessful */
+                return;
             }
         }
     }
@@ -301,12 +307,11 @@ void main(void)
     sclp_setup();
     css_setup();
     boot_setup();
-    if (have_iplb) {
-        find_boot_device();
+    if (have_iplb && find_boot_device()) {
         ipl_boot_device();
     } else {
         probe_boot_device();
     }
 
-    panic("Failed to load OS from hard disk\n");
+    panic("Failed to IPL. Halting...");
 }
pc-bios/s390-ccw/virtio-blkdev.c +4 -4
index 2666326801..5ef273bdc0 100644
@@ -59,8 +59,8 @@ int virtio_read_many(unsigned long sector, void *load_addr, int sec_num)
     case VIRTIO_ID_SCSI:
         return virtio_scsi_read_many(vdev, sector, load_addr, sec_num);
     }
-    panic("\n! No readable IPL device !\n");
-    return -1;
+
+    return 1;
 }
 
 unsigned long virtio_load_direct(unsigned long rec_list1, unsigned long rec_list2,
@@ -73,13 +73,13 @@ unsigned long virtio_load_direct(unsigned long rec_list1, unsigned long rec_list
     unsigned long addr = (unsigned long)load_addr;
 
     if (sec_len != virtio_get_block_size()) {
-        return -1;
+        return 0;
     }
 
     printf(".");
     status = virtio_read_many(sec, (void *)addr, sec_num);
     if (status) {
-        panic("I/O Error");
+        return 0;
     }
     addr += sec_num * virtio_get_block_size();
 
pc-bios/s390-ccw/virtio.c +44 -21

114 lines not on this page · raw message

Signature · 1 line
2.45.1
#24 lore raw

Re: [PATCH 12/18] pc-bios/s390-ccw: Enable failed IPL to return after error

Quoted 12 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Remove panic-on-error from IPL functions such that a return code is propagated back to the main IPL calling function (rather than terminating immediately), which facilitates possible error recovery in the future.

A select few panics remain, which indicate fatal non-devices errors that must result in termination.

---

...

Quoted 9 lines
pc-bios/s390-ccw/bootmap.c +2 -1
@@ -1054,16 +1073,19 @@ void zipl_load(void)
 
      if (vdev->is_cdrom) {
          ipl_iso_el_torito();
-        panic("\n! Cannot IPL this ISO image !\n");
+        puts("Failed to IPL this ISO image!");
+        return;
      }
 

pc-bios/s390-ccw/bootmap.c void zipl_load(void) · line 1087

Quoted 10 lines
pc-bios/s390-ccw/bootmap.c +3 -2
      if (virtio_get_device_type() == VIRTIO_ID_NET) {
          netmain();
-        panic("\n! Cannot IPL from this network !\n");
+        puts("Failed to IPL from this network!");
+        return;
      }
 
      if (ipl_scsi()) {
-        panic("\n! Cannot IPL this device !\n");
+        puts("Failed to IPL from this device!");

I'd maybe say "Failed to IPL from this SCSI device" now, just to make sure that it is easier to match the message with one of the boot device types later?

Quoted 2 lines
(quoted diff) +1 -0
+        return;
      }

...

Quoted 29 lines

void jump_to_low_kernel(void)

pc-bios/s390-ccw/main.c +5 -2
index 2345432abb..f818bd7210 100644
@@ -77,6 +77,9 @@ static int is_dev_possibly_bootable(int dev_no, int sch_no)
 
      enable_subchannel(blk_schid);
      cutype = cu_type(blk_schid);
+    if (cutype == CU_TYPE_UNKNOWN) {
+        return -EIO;
+    }
 
      /*
       * Note: we always have to run virtio_is_supported() here to make
@@ -194,10 +197,10 @@ static void boot_setup(void)
      have_iplb = store_iplb(&iplb);
  }
 
-static void find_boot_device(void)
+static bool find_boot_device(void)
  {
      VDev *vdev = virtio_get_device();
-    bool found;
+    bool found = false;
 
      switch (iplb.pbt) {
      case S390_IPL_TYPE_CCW:

pc-bios/s390-ccw/main.c static void find_boot_device(void) · line 221

Quoted 5 lines
pc-bios/s390-ccw/main.c +1 -1
@@ -215,10 +218,10 @@ static void find_boot_device(void)
          found = find_subch(iplb.scsi.devno);
          break;
      default:
-        panic("List-directed IPL not supported yet!\n");
+        puts("Invalid IPLB");

Maybe rather say "Unsupported IPLB" ? At least the original message sounds like it was rather something that has not been implemented yet, and not something that is wrong on the disk...?

Quoted 5 lines
pc-bios/s390-ccw/main.c +1 -1
      }
 
-    IPL_assert(found, "Boot device not found\n");
+    return found;
  }

...

Quoted 6 lines

unsigned long virtio_load_direct(unsigned long rec_list1, unsigned long rec_list2,

pc-bios/s390-ccw/main.c +0 -1
@@ -73,13 +73,13 @@ unsigned long virtio_load_direct(unsigned long rec_list1, unsigned long rec_list
      unsigned long addr = (unsigned long)load_addr;
 
      if (sec_len != virtio_get_block_size()) {
-        return -1;

pc-bios/s390-ccw/main.c unsigned long virtio_load_direct(unsigned long rec_list1, unsigned long rec_list · line 84

Quoted 10 lines
pc-bios/s390-ccw/main.c +2 -1
+        return 0;
      }
 
      printf(".");
      status = virtio_read_many(sec, (void *)addr, sec_num);
      if (status) {
-        panic("I/O Error");
+        return 0;
      }
      addr += sec_num * virtio_get_block_size();

Ah, here's the fix for virtio_load_direct() ... since you changed the call site in patch 09 already, I think you should move this hunk to patch 09, too.

Quoted 12 lines
pc-bios/s390-ccw/virtio.c +1 -2
index 8c6b0a8a92..e3fdb95b3c 100644
@@ -217,16 +217,19 @@ int virtio_run(VDev *vdev, int vqid, VirtioCmd *cmd)
      return 0;
  }
 
-void virtio_setup_ccw(VDev *vdev)
+int virtio_setup_ccw(VDev *vdev)
  {
-    int i, rc, cfg_size = 0;

pc-bios/s390-ccw/virtio.c int virtio_run(VDev *vdev, int vqid, VirtioCmd *cmd) · line 230

Quoted 10 lines
pc-bios/s390-ccw/virtio.c +3 -1
+    int i, cfg_size = 0;
      uint8_t status;
      struct VirtioFeatureDesc {
          uint32_t features;
          uint8_t index;
      } __attribute__((packed)) feats;
 
-    IPL_assert(virtio_is_supported(vdev->schid), "PE");
+    if (!virtio_is_supported(vdev->schid)) {
+        puts("PE");

Do you remember what "PE" means here? ... might be a good opportunity to fix this error message as well...

pc-bios/s390-ccw/virtio.c int virtio_run(VDev *vdev, int vqid, VirtioCmd *cmd) · line 232

Quoted 2 lines
pc-bios/s390-ccw/virtio.c +2 -0
+        return -ENODEV;
+    }

Thomas

#25 lore raw

Re: [PATCH 12/18] pc-bios/s390-ccw: Enable failed IPL to return after error

Quoted 13 lines · Thomas Huth
Quoted 2 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

...

Quoted 9 lines

  unsigned long virtio_load_direct(unsigned long rec_list1, unsigned long rec_list2,

(quoted diff) +0 -0
@@ -73,13 +73,13 @@ unsigned long virtio_load_direct(unsigned long 

rec_list1, unsigned long rec_list
      unsigned long addr = (unsigned long)load_addr; if (sec_len != virtio_get_block_size()) { -        return -1;
+        return 0;
      }
        printf(".");

Quoted 8 lines
Quoted 6 lines

      status = virtio_read_many(sec, (void *)addr, sec_num); if (status) {
-        panic("I/O Error");
+        return 0;
      }
      addr += sec_num * virtio_get_block_size();

Ah, here's the fix for virtio_load_direct() ... since you changed the call site in patch 09 already, I think you should move this hunk to patch 09, too.

Yes, that would be a more appropriate place for it.  Will do.

Quoted 16 lines
Quoted 16 lines
pc-bios/s390-ccw/virtio.c +2 -1
index 8c6b0a8a92..e3fdb95b3c 100644
@@ -217,16 +217,19 @@ int virtio_run(VDev *vdev, int vqid, VirtioCmd 
 *cmd)
       return 0;
   }
   -void virtio_setup_ccw(VDev *vdev)
+int virtio_setup_ccw(VDev *vdev)
   {
-    int i, rc, cfg_size = 0;
+    int i, cfg_size = 0;
       uint8_t status;
       struct VirtioFeatureDesc {
Quoted 8 lines

pc-bios/s390-ccw/virtio.c int virtio_run(VDev *vdev, int vqid, VirtioCmd *cmd) · line 230

Quoted 6 lines
pc-bios/s390-ccw/virtio.c +2 -0
           uint32_t features;
           uint8_t index;
       } __attribute__((packed)) feats;
   -    IPL_assert(virtio_is_supported(vdev->schid), "PE");
+    if (!virtio_is_supported(vdev->schid)) {
+        puts("PE");

Do you remember what "PE" means here? ... might be a good opportunity to fix this error message as well...

Unfortunately I don't know what it means. I guess it would be better to write a new message than continue carrying this mysterious one forward, though.

I'll make those messages you pointed out more useful.

Jared Rossi

#26 lore raw

PATCH v2 13/18 include/hw/s390x: Add include files for common IPL structs

In reply to [email protected]

From: Jared Rossi <[email protected]>

Currently, structures defined in both hw/s390x/ipl.h and pc-bios/s390-ccw/iplb.h must be kept in sync, which is prone to error. Instead, create a new directory at include/hw/s390x/ipl/ to contain the definitions that must be shared.

---
 hw/s390x/ipl.h              | 104 +-----------------------------
 include/hw/s390x/ipl/qipl.h | 123 ++++++++++++++++++++++++++++++++++++
 pc-bios/s390-ccw/iplb.h     |  84 ++----------------------
 pc-bios/s390-ccw/Makefile   |   2 +-
 4 files changed, 130 insertions(+), 183 deletions(-)
 create mode 100644 include/hw/s390x/ipl/qipl.h
hw/s390x/ipl.h +1 -103
index b2105b616a..fa394c339d 100644
@@ -16,95 +16,11 @@
 #include "cpu.h"
 #include "exec/address-spaces.h"
 #include "hw/qdev-core.h"
+#include "hw/s390x/ipl/qipl.h"
 #include "qom/object.h"
 
-struct IPLBlockPVComp {
-    uint64_t tweak_pref;
-    uint64_t addr;
-    uint64_t size;
-} QEMU_PACKED;
-typedef struct IPLBlockPVComp IPLBlockPVComp;
-
-struct IPLBlockPV {
-    uint8_t  reserved18[87];    /* 0x18 */
-    uint8_t  version;           /* 0x6f */
-    uint32_t reserved70;        /* 0x70 */
-    uint32_t num_comp;          /* 0x74 */
-    uint64_t pv_header_addr;    /* 0x78 */
-    uint64_t pv_header_len;     /* 0x80 */
-    struct IPLBlockPVComp components[0];
-} QEMU_PACKED;
-typedef struct IPLBlockPV IPLBlockPV;
-
-struct IplBlockCcw {
-    uint8_t  reserved0[85];
-    uint8_t  ssid;
-    uint16_t devno;
-    uint8_t  vm_flags;
-    uint8_t  reserved3[3];
-    uint32_t vm_parm_len;
-    uint8_t  nss_name[8];
-    uint8_t  vm_parm[64];
-    uint8_t  reserved4[8];
-} QEMU_PACKED;
-typedef struct IplBlockCcw IplBlockCcw;
-
-struct IplBlockFcp {
-    uint8_t  reserved1[305 - 1];
-    uint8_t  opt;
-    uint8_t  reserved2[3];
-    uint16_t reserved3;
-    uint16_t devno;
-    uint8_t  reserved4[4];
-    uint64_t wwpn;
-    uint64_t lun;
-    uint32_t bootprog;
-    uint8_t  reserved5[12];
-    uint64_t br_lba;
-    uint32_t scp_data_len;
-    uint8_t  reserved6[260];
-    uint8_t  scp_data[0];
-} QEMU_PACKED;
-typedef struct IplBlockFcp IplBlockFcp;
-
-struct IplBlockQemuScsi {
-    uint32_t lun;
-    uint16_t target;
-    uint16_t channel;
-    uint8_t  reserved0[77];
-    uint8_t  ssid;
-    uint16_t devno;
-} QEMU_PACKED;
-typedef struct IplBlockQemuScsi IplBlockQemuScsi;
-
 #define DIAG308_FLAGS_LP_VALID 0x80
 
-union IplParameterBlock {
-    struct {
-        uint32_t len;
-        uint8_t  reserved0[3];
-        uint8_t  version;
-        uint32_t blk0_len;
-        uint8_t  pbt;
-        uint8_t  flags;
-        uint16_t reserved01;
-        uint8_t  loadparm[8];
-        union {
-            IplBlockCcw ccw;
-            IplBlockFcp fcp;
-            IPLBlockPV pv;
-            IplBlockQemuScsi scsi;
-        };
-    } QEMU_PACKED;
-    struct {
-        uint8_t  reserved1[110];
-        uint16_t devno;
-        uint8_t  reserved2[88];
-        uint8_t  reserved_ext[4096 - 200];
-    } QEMU_PACKED;
-} QEMU_PACKED;
-typedef union IplParameterBlock IplParameterBlock;
-
 int s390_ipl_set_loadparm(uint8_t *loadparm);
 void s390_ipl_update_diag308(IplParameterBlock *iplb);
 int s390_ipl_prepare_pv_header(Error **errp);
@@ -131,24 +47,6 @@ void s390_ipl_clear_reset_request(void);
 #define QIPL_FLAG_BM_OPTS_CMD   0x80
 #define QIPL_FLAG_BM_OPTS_ZIPL  0x40
 
-/*
- * The QEMU IPL Parameters will be stored at absolute address
- * 204 (0xcc) which means it is 32-bit word aligned but not
- * double-word aligned. Placement of 64-bit data fields in this
- * area must account for their alignment needs.
- * The total size of the struct must never exceed 28 bytes.
- * This definition must be kept in sync with the definition
- * in pc-bios/s390-ccw/iplb.h.
- */
-struct QemuIplParameters {
-    uint8_t  qipl_flags;
-    uint8_t  reserved1[3];
-    uint64_t reserved2;
-    uint32_t boot_menu_timeout;
-    uint8_t  reserved3[12];
-} QEMU_PACKED;
-typedef struct QemuIplParameters QemuIplParameters;
-
 #define TYPE_S390_IPL "s390-ipl"
 OBJECT_DECLARE_SIMPLE_TYPE(S390IPLState, S390_IPL)
 
include/hw/s390x/ipl/qipl.h new file +123 -0

123 lines not on this page · raw message

pc-bios/s390-ccw/iplb.h +5 -79

93 lines not on this page · raw message

pc-bios/s390-ccw/Makefile +1 -1
index 27cbb354af..db9e8f0892 100644
@@ -3,7 +3,7 @@ all: build-all
 	@true
 
 include config-host.mak
-CFLAGS = -O2 -g
+CFLAGS = -O2 -g -I $(SRC_PATH)/../../include/hw/s390x/ipl
 MAKEFLAGS += -rR
 
 GIT_SUBMODULES = roms/SLOF
Signature · 1 line
2.45.1
Reviewed-by on v2 13/18
#27 lore raw

Re: [PATCH 13/18] include/hw/s390x: Add include files for common IPL structs

Quoted 9 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Currently, structures defined in both hw/s390x/ipl.h and pc-bios/s390-ccw/iplb.h must be kept in sync, which is prone to error. Instead, create a new directory at include/hw/s390x/ipl/ to contain the definitions that must be shared.

---

...

Quoted 38 lines
include/hw/s390x/ipl/qipl.h new file +32 -0
new file mode 100644
index 0000000000..d21a8f91e3
@@ -0,0 +1,123 @@
+/*
+ * S/390 boot structures
+ *
+ * Copyright 2024 IBM Corp.
+ * Author(s): Jared Rossi <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#ifndef S390X_QIPL_H
+#define S390X_QIPL_H
+
+/* Boot Menu flags */
+#define QIPL_FLAG_BM_OPTS_CMD   0x80
+#define QIPL_FLAG_BM_OPTS_ZIPL  0x40
+
+#define QIPL_ADDRESS  0xcc
+#define LOADPARM_LEN    8
+
+/*
+ * The QEMU IPL Parameters will be stored at absolute address
+ * 204 (0xcc) which means it is 32-bit word aligned but not
+ * double-word aligned. Placement of 64-bit data fields in this
+ * area must account for their alignment needs.
+ * The total size of the struct must never exceed 28 bytes.
+ */
+struct QemuIplParameters {
+    uint8_t  qipl_flags;
+    uint8_t  reserved1[3];
+    uint64_t reserved2;

include/hw/s390x/ipl/qipl.h line 42

Quoted 10 lines
include/hw/s390x/ipl/qipl.h new file +10 -0
+    uint32_t boot_menu_timeout;
+    uint8_t  reserved3[12];
+} QEMU_PACKED;
+typedef struct QemuIplParameters QemuIplParameters;
+
+struct IPLBlockPVComp {
+    uint64_t tweak_pref;
+    uint64_t addr;
+    uint64_t size;
+}  QEMU_PACKED;

Could you please replace the two spaces in front of QEMU_PACKED with just one place? (also in the other affected spots in this file)

Apart from that cosmetic nit:

#28 lore raw

Re: [PATCH 13/18] include/hw/s390x: Add include files for common IPL structs

Quoted 11 lines · Thomas Huth

On 27/09/2024 02.51, [email protected] wrote:
...

include/hw/s390x/ipl/qipl.h line 42

Quoted 6 lines
include/hw/s390x/ipl/qipl.h new file +6 -0
+
+struct IPLBlockPVComp {
+    uint64_t tweak_pref;
+    uint64_t addr;
+    uint64_t size;
+}  QEMU_PACKED;

Could you please replace the two spaces in front of QEMU_PACKED with just one place? (also in the other affected spots in this file)

Quoted 3 lines

Apart from that cosmetic nit:

Will do.

#29 lore raw

PATCH v2 14/18 s390x: Add individual loadparm assignment to CCW device

In reply to [email protected]

From: Jared Rossi <[email protected]>

Add a loadparm property to the VirtioCcwDevice object so that different loadparms can be defined on a per-device basis for CCW boot devices.

The machine/global loadparm is still supported. If both a global and per-device loadparm are defined, the per-device value will override the global value for that device, but any other devices that do not specify a per-device loadparm will still use the global loadparm.

It is invalid to assign a loadparm to a non-boot device.

---
 hw/s390x/ccw-device.h      |  2 ++
 hw/s390x/ipl.h             |  3 +-
 hw/s390x/ccw-device.c      | 46 ++++++++++++++++++++++++++
 hw/s390x/ipl.c             | 66 +++++++++++++++++++++++---------------
 hw/s390x/s390-virtio-ccw.c | 18 +----------
 hw/s390x/sclp.c            |  3 +-
 pc-bios/s390-ccw/main.c    | 10 ++++--
 7 files changed, 100 insertions(+), 48 deletions(-)
hw/s390x/ccw-device.h +2 -0
index 5feeb0ee7a..1e1737c0f3 100644
@@ -26,6 +26,8 @@ struct CcwDevice {
     CssDevId dev_id;
     /* The actual busid of the virtual subchannel. */
     CssDevId subch_id;
+    /* If set, use this loadparm value when device is boot target */
+    uint8_t loadparm[8];
 };
 typedef struct CcwDevice CcwDevice;
 
hw/s390x/ipl.h +2 -1
index fa394c339d..b670bad551 100644
@@ -21,7 +21,8 @@
 
 #define DIAG308_FLAGS_LP_VALID 0x80
 
-int s390_ipl_set_loadparm(uint8_t *loadparm);
+void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp);
+void s390_ipl_fmt_loadparm(uint8_t *loadparm, char *str, Error **errp);
 void s390_ipl_update_diag308(IplParameterBlock *iplb);
 int s390_ipl_prepare_pv_header(Error **errp);
 int s390_ipl_pv_unpack(void);
hw/s390x/ccw-device.c +46 -0

62 lines not on this page · raw message

hw/s390x/ipl.c +40 -26

104 lines not on this page · raw message

hw/s390x/s390-virtio-ccw.c +1 -17
index c89a5475eb..111e5a8452 100644
@@ -722,28 +722,12 @@ static void machine_set_loadparm(Object *obj, Visitor *v,
 {
     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
     char *val;
-    int i;
 
     if (!visit_type_str(v, name, &val, errp)) {
         return;
     }
 
-    for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
-        uint8_t c = qemu_toupper(val[i]); /* mimic HMC */
-
-        if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
-            (c == ' ')) {
-            ms->loadparm[i] = c;
-        } else {
-            error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
-                       c, c);
-            return;
-        }
-    }
-
-    for (; i < sizeof(ms->loadparm); i++) {
-        ms->loadparm[i] = ' '; /* pad right with spaces */
-    }
+    s390_ipl_fmt_loadparm(ms->loadparm, val, errp);
 }
 
 static void ccw_machine_class_init(ObjectClass *oc, void *data)
hw/s390x/sclp.c +2 -1
index e725dcd5fd..8b2d7a88bd 100644
@@ -175,7 +175,8 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
         memcpy(&read_info->loadparm, &ipib->loadparm,
                sizeof(read_info->loadparm));
     } else {
-        s390_ipl_set_loadparm(read_info->loadparm);
+        s390_ipl_convert_loadparm((char *)S390_CCW_MACHINE(machine)->loadparm,
+                                read_info->loadparm);
     }
 
     sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_READ_COMPLETION);
pc-bios/s390-ccw/main.c +7 -3
index f818bd7210..d7c457e0ed 100644
@@ -183,8 +183,14 @@ static void css_setup(void)
 static void boot_setup(void)
 {
     char lpmsg[] = "LOADPARM=[________]\n";
+    have_iplb = store_iplb(&iplb);
+
+    if (memcmp(iplb.loadparm, "@@@@@@@@", LOADPARM_LEN) != 0) {
+        ebcdic_to_ascii((char *) iplb.loadparm, loadparm_str, LOADPARM_LEN);
+    } else {
+        sclp_get_loadparm_ascii(loadparm_str);
+    }
 
-    sclp_get_loadparm_ascii(loadparm_str);
     memcpy(lpmsg + 10, loadparm_str, 8);
     puts(lpmsg);
 
@@ -193,8 +199,6 @@ static void boot_setup(void)
      * so we don't taint our decision-making process during a reboot.
      */
     memset((char *)S390EP, 0, 6);
-
-    have_iplb = store_iplb(&iplb);
 }
 
 static bool find_boot_device(void)
Signature · 1 line
2.45.1
Reviewed-by on v2 14/18
#30 lore raw

Re: [PATCH 14/18] s390x: Add individual loadparm assignment to CCW device

Quoted 10 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Add a loadparm property to the VirtioCcwDevice object so that different loadparms can be defined on a per-device basis for CCW boot devices.

The machine/global loadparm is still supported. If both a global and per-device loadparm are defined, the per-device value will override the global value for that device, but any other devices that do not specify a per-device loadparm will still use the global loadparm.

Quoted 5 lines

It is invalid to assign a loadparm to a non-boot device.

---

#31 lore raw

PATCH v2 15/18 hw/s390x: Build an IPLB for each boot device

In reply to [email protected]

From: Jared Rossi <[email protected]>

Build an IPLB for any device with a bootindex (up to a maximum of 8 devices).

The IPLB chain is placed immediately before the BIOS in memory. Because this is not a fixed address, the location of the next IPLB and number of remaining boot devices is stored in the QIPL global variable for possible later access by the guest during IPL.

---
 hw/s390x/ipl.h              |   1 +
 include/hw/s390x/ipl/qipl.h |   4 +-
 hw/s390x/ipl.c              | 125 ++++++++++++++++++++++++++++--------
 3 files changed, 101 insertions(+), 29 deletions(-)
hw/s390x/ipl.h +1 -0
index b670bad551..e4af8e3782 100644
@@ -20,6 +20,7 @@
 #include "qom/object.h"
 
 #define DIAG308_FLAGS_LP_VALID 0x80
+#define MAX_IPLB_CHAIN 7 /* Max number of fallback boot devices */
 
 void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp);
 void s390_ipl_fmt_loadparm(uint8_t *loadparm, char *str, Error **errp);
include/hw/s390x/ipl/qipl.h +3 -1
index d21a8f91e3..15342ac5cd 100644
@@ -31,7 +31,9 @@ struct QemuIplParameters {
     uint8_t  reserved1[3];
     uint64_t reserved2;
     uint32_t boot_menu_timeout;
-    uint8_t  reserved3[12];
+    uint8_t  reserved3[2];
+    uint16_t chain_len;
+    uint64_t next_iplb;
 } QEMU_PACKED;
 typedef struct QemuIplParameters QemuIplParameters;
 
hw/s390x/ipl.c +97 -28

191 lines not on this page · raw message

Signature · 1 line
2.45.1
#32 lore raw

Re: [PATCH 15/18] hw/s390x: Build an IPLB for each boot device

Quoted 11 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Build an IPLB for any device with a bootindex (up to a maximum of 8 devices).

The IPLB chain is placed immediately before the BIOS in memory. Because this is not a fixed address, the location of the next IPLB and number of remaining boot devices is stored in the QIPL global variable for possible later access by the guest during IPL.

Note: There's an empty line below your SoB in most of your patch descriptions ... it's just cosmetics, but in case you touch the patch anyway, please remove it.

Quoted 1 line

---

...

Quoted 15 lines
hw/s390x/ipl.c +2 -2
@@ -484,8 +499,8 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)
              lp = S390_CCW_MACHINE(qdev_get_machine())->loadparm;
          }
 
-        s390_ipl_convert_loadparm((char *)lp, ipl->iplb.loadparm);
-        ipl->iplb.flags |= DIAG308_FLAGS_LP_VALID;
+        s390_ipl_convert_loadparm((char *)lp, iplb->loadparm);
+        iplb->flags |= DIAG308_FLAGS_LP_VALID;
 
          return true;
      }
@@ -493,6 +508,58 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)
      return false;
  }
 

hw/s390x/ipl.c static bool s390_gen_initial_iplb(S390IPLState *ipl) · line 520

Quoted 10 lines
hw/s390x/ipl.c +10 -0
+static bool s390_init_all_iplbs(S390IPLState *ipl)
+{
+    int iplb_num = 0;
+    IplParameterBlock iplb_chain[7];
+    DeviceState *dev_st = get_boot_device(0);
+
+    /*
+     * Parse the boot devices.  Generate an IPLB for the first boot device,
+     * which will later be set with DIAG308. Index any fallback boot devices.
+     */

The comment looks like it rather belongs to the whole function, and not to the if-statement below? So maybe move it at the top?

hw/s390x/ipl.c static bool s390_gen_initial_iplb(S390IPLState *ipl) · line 528

Quoted 8 lines
hw/s390x/ipl.c +8 -0
+    if (!dev_st) {
+        ipl->qipl.chain_len = 0;
+        return false;
+    }
+
+    iplb_num = 1;
+    s390_build_iplb(dev_st, &ipl->iplb);
+    ipl->iplb.flags |= DIAG308_FLAGS_LP_VALID;

Isn't DIAG308_FLAGS_LP_VALID set within s390_build_iplb() already?

hw/s390x/ipl.c static bool s390_gen_initial_iplb(S390IPLState *ipl) · line 532

Quoted 3 lines
hw/s390x/ipl.c +3 -0
+    while (get_boot_device(iplb_num)) {
+        iplb_num++;
+    }

I'd maybe move the code block below to this spot here, so you've got to assign ipl->qipl.chain_len only once:

+ if (iplb_num > MAX_IPLB_CHAIN + 1) {
+ warn_report("Excess boot devices defined! %d boot devices found, "
+ "but only the first %d will be considered.",
+ iplb_num, MAX_IPLB_CHAIN + 1);
+
+ iplb_num = MAX_IPLB_CHAIN + 1;
+ }

Quoted 5 lines
hw/s390x/ipl.c +5 -0
+    ipl->qipl.chain_len = iplb_num - 1;
+
+    /*
+     * Build fallback IPLBs for any boot devices above index 0, up to a
+     * maximum amount as defined in ipl.h

hw/s390x/ipl.c static bool s390_gen_initial_iplb(S390IPLState *ipl) · line 548

Quoted 10 lines
hw/s390x/ipl.c +10 -0
+     */
+    if (iplb_num > 1) {
+        if (iplb_num > MAX_IPLB_CHAIN + 1) {
+            warn_report("Excess boot devices defined! %d boot devices found, "
+                        "but only the first %d will be considered.",
+                        iplb_num, MAX_IPLB_CHAIN + 1);
+
+            ipl->qipl.chain_len = MAX_IPLB_CHAIN;
+            iplb_num = MAX_IPLB_CHAIN + 1;
+        }

i.e. move this code block -^
and remove the "ipl->qipl.chain_len = MAX_IPLB_CHAIN;" in there.

hw/s390x/ipl.c static bool s390_gen_initial_iplb(S390IPLState *ipl) · line 554

Quoted 5 lines
hw/s390x/ipl.c +5 -0
+        /* Start at 1 because the IPLB for boot index 0 is not chained */
+        for (int i = 1; i < iplb_num; i++) {
+            dev_st = get_boot_device(i);
+            s390_build_iplb(dev_st, &iplb_chain[i - 1]);
+            iplb_chain[i - 1].flags |= DIAG308_FLAGS_LP_VALID;

Again, setting DIAG308_FLAGS_LP_VALID should not be necessary since it is already done in s390_build_iplb() ?

Quoted 21 lines
hw/s390x/ipl.c +9 -1
+        }
+
+        ipl->qipl.next_iplb = s390_ipl_map_iplb_chain(iplb_chain);
+    }
+
+    return iplb_num;
+}
+
  static bool is_virtio_ccw_device_of_type(IplParameterBlock *iplb,
                                           int virtio_id)
  {
@@ -620,7 +687,7 @@ void s390_ipl_reset_request(CPUState *cs, enum s390_reset reset_type)
               * this is the original boot device's SCSI
               * so restore IPL parameter info from it
               */
-            ipl->iplb_valid = s390_gen_initial_iplb(ipl);
+            ipl->iplb_valid = s390_build_iplb(get_boot_device(0), &ipl->iplb);
          }
      }
      if (reset_type == S390_RESET_MODIFIED_CLEAR ||

hw/s390x/ipl.c void s390_ipl_prepare_cpu(S390CPU *cpu) · line 789

Quoted 10 lines
hw/s390x/ipl.c +3 -1
@@ -714,7 +781,9 @@ void s390_ipl_prepare_cpu(S390CPU *cpu)
      if (!ipl->kernel || ipl->iplb_valid) {
          cpu->env.psw.addr = ipl->bios_start_addr;
          if (!ipl->iplb_valid) {
-            ipl->iplb_valid = s390_gen_initial_iplb(ipl);
+            ipl->iplb_valid = s390_init_all_iplbs(ipl);
+        } else {
+            ipl->qipl.chain_len = 0;
          }
      }
      s390_ipl_set_boot_menu(ipl);

Thomas

#33 lore raw

Re: [PATCH 15/18] hw/s390x: Build an IPLB for each boot device

Quoted 22 lines · Thomas Huth
Quoted 21 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>
...

hw/s390x/ipl.c +7 -1
@@ -484,8 +499,8 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)
               lp = S390_CCW_MACHINE(qdev_get_machine())->loadparm;
           }
   -        s390_ipl_convert_loadparm((char *)lp, ipl->iplb.loadparm);
-        ipl->iplb.flags |= DIAG308_FLAGS_LP_VALID;
+        s390_ipl_convert_loadparm((char *)lp, iplb->loadparm);
+        iplb->flags |= DIAG308_FLAGS_LP_VALID;
             return true;
       }
@@ -493,6 +508,58 @@ static bool s390_gen_initial_iplb(S390IPLState 
 *ipl)
       return false;
   }
   +static bool s390_init_all_iplbs(S390IPLState *ipl)
+{
+    int iplb_num = 0;
+    IplParameterBlock iplb_chain[7];
+    DeviceState *dev_st = get_boot_device(0);
+
Quoted 8 lines
Quoted 6 lines
(quoted diff) +3 -0
+    /*
+     * Parse the boot devices.  Generate an IPLB for the first boot 
 device,
+     * which will later be set with DIAG308. Index any fallback boot 

devices.
+     */

The comment looks like it rather belongs to the whole function, and not to the if-statement below? So maybe move it at the top?

Agreed.

Quoted 47 lines
Quoted 9 lines

+    if (!dev_st) {
+        ipl->qipl.chain_len = 0;
+        return false;
+    }
+
+    iplb_num = 1;
+    s390_build_iplb(dev_st, &ipl->iplb);
+    ipl->iplb.flags |= DIAG308_FLAGS_LP_VALID;

Isn't DIAG308_FLAGS_LP_VALID set within s390_build_iplb() already?

Quoted 3 lines

+    while (get_boot_device(iplb_num)) {
+        iplb_num++;
+    }

I'd maybe move the code block below to this spot here, so you've got to assign ipl->qipl.chain_len only once:

+    if (iplb_num > MAX_IPLB_CHAIN + 1) {
+        warn_report("Excess boot devices defined! %d boot devices found, "
+                    "but only the first %d will be considered.", +                    iplb_num, MAX_IPLB_CHAIN + 1);
+
+        iplb_num = MAX_IPLB_CHAIN + 1;
+    }

Quoted 8 lines

+    ipl->qipl.chain_len = iplb_num - 1;
+
+    /*
+     * Build fallback IPLBs for any boot devices above index 0, up to a +     * maximum amount as defined in ipl.h
+     */
+    if (iplb_num > 1) {
+        if (iplb_num > MAX_IPLB_CHAIN + 1) {

Quoted 8 lines

+            warn_report("Excess boot devices defined! %d boot devices found, "
+                        "but only the first %d will be considered.", +                        iplb_num, MAX_IPLB_CHAIN + 1);
+
+            ipl->qipl.chain_len = MAX_IPLB_CHAIN;
+            iplb_num = MAX_IPLB_CHAIN + 1;
+        }

i.e. move this code block -^
and remove the "ipl->qipl.chain_len = MAX_IPLB_CHAIN;" in there.

Quoted 9 lines
Quoted 6 lines

+        /* Start at 1 because the IPLB for boot index 0 is not chained */
+        for (int i = 1; i < iplb_num; i++) {
+            dev_st = get_boot_device(i);
+            s390_build_iplb(dev_st, &iplb_chain[i - 1]); +            iplb_chain[i - 1].flags |= DIAG308_FLAGS_LP_VALID;

Again, setting DIAG308_FLAGS_LP_VALID should not be necessary since it is already done in s390_build_iplb() ?

I’ll see if I can clean section this up and remove redundant flag assignments.

Jared Rossi

#34 lore raw

PATCH v2 16/18 s390x: Rebuild IPLB for SCSI device directly from DIAG308

In reply to [email protected]

From: Jared Rossi <[email protected]>

Because virtio-scsi type devices use a non-architected IPLB pbt code they cannot be set and stored normally. Instead, the IPLB must be rebuilt during re-ipl.

As s390x does not natively support multiple boot devices, the devno field is used to store the position in the boot order for the device.

Handling the rebuild as part of DIAG308 removes the need to check the devices for invalid IPLBs later in the IPL.

---
 hw/s390x/ipl.h              |  11 ++--
 include/hw/s390x/ipl/qipl.h |   3 +-
 hw/s390x/ipl.c              | 104 ++++++++++--------------------------
 pc-bios/s390-ccw/jump2ipl.c |  11 ++--
 target/s390x/diag.c         |   9 +++-
 5 files changed, 54 insertions(+), 84 deletions(-)
hw/s390x/ipl.h +8 -3
index e4af8e3782..d1ebc384d8 100644
@@ -24,6 +24,7 @@
 
 void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp);
 void s390_ipl_fmt_loadparm(uint8_t *loadparm, char *str, Error **errp);
+void s390_rebuild_iplb(uint16_t index, IplParameterBlock *iplb);
 void s390_ipl_update_diag308(IplParameterBlock *iplb);
 int s390_ipl_prepare_pv_header(Error **errp);
 int s390_ipl_pv_unpack(void);
@@ -65,7 +66,8 @@ struct S390IPLState {
     bool enforce_bios;
     bool iplb_valid;
     bool iplb_valid_pv;
-    bool netboot;
+    bool rebuilt_iplb;
+    uint16_t iplb_index;
     /* reset related properties don't have to be migrated or reset */
     enum s390_reset reset_type;
     int reset_cpu_index;
@@ -172,11 +174,14 @@ static inline bool iplb_valid_pv(IplParameterBlock *iplb)
 
 static inline bool iplb_valid(IplParameterBlock *iplb)
 {
+    uint32_t len = be32_to_cpu(iplb->len);
+
     switch (iplb->pbt) {
     case S390_IPL_TYPE_FCP:
-        return be32_to_cpu(iplb->len) >= S390_IPLB_MIN_FCP_LEN;
+        return len >= S390_IPLB_MIN_FCP_LEN;
     case S390_IPL_TYPE_CCW:
-        return be32_to_cpu(iplb->len) >= S390_IPLB_MIN_CCW_LEN;
+        return (len >= S390_IPLB_MIN_CCW_LEN);
+    case S390_IPL_TYPE_QEMU_SCSI:
     default:
         return false;
     }
include/hw/s390x/ipl/qipl.h +2 -1
index 15342ac5cd..0f518adb62 100644
@@ -28,7 +28,8 @@
  */
 struct QemuIplParameters {
     uint8_t  qipl_flags;
-    uint8_t  reserved1[3];
+    uint8_t  index;
+    uint8_t  reserved1[2];
     uint64_t reserved2;
     uint32_t boot_menu_timeout;
     uint8_t  reserved3[2];
hw/s390x/ipl.c +28 -76

156 lines not on this page · raw message

pc-bios/s390-ccw/jump2ipl.c +8 -3
index d45aec6694..bcf0e12f02 100644
@@ -39,10 +39,15 @@ int jump_to_IPL_code(uint64_t address)
     write_subsystem_identification();
     write_iplb_location();
 
-    /* prevent unknown IPL types in the guest */
+    /*
+     * The IPLB for QEMU SCSI type devices must be rebuilt during re-ipl. The
+     * iplb.devno is set to the boot position of the target SCSI device.
+     */
     if (iplb.pbt == S390_IPL_TYPE_QEMU_SCSI) {
-        iplb.pbt = S390_IPL_TYPE_CCW;
-        set_iplb(&iplb);
+        iplb.devno = qipl.index;
+        if (!set_iplb(&iplb)) {
+            panic("Failed to set IPLB");
+        }
     }
 
     /*
target/s390x/diag.c +8 -1
index 27ffd48576..a1fd54ddac 100644
@@ -133,7 +133,14 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
 
         valid = subcode == DIAG308_PV_SET ? iplb_valid_pv(iplb) : iplb_valid(iplb);
         if (!valid) {
-            env->regs[r1 + 1] = DIAG_308_RC_INVALID;
+            if (subcode == DIAG308_SET && iplb->pbt == S390_IPL_TYPE_QEMU_SCSI) {
+                s390_rebuild_iplb(iplb->devno, iplb);
+                s390_ipl_update_diag308(iplb);
+                env->regs[r1 + 1] = DIAG_308_RC_OK;
+            } else {
+                env->regs[r1 + 1] = DIAG_308_RC_INVALID;
+            }
+
             goto out;
         }
 
Signature · 1 line
2.45.1
#35 lore raw

Re: [PATCH 16/18] s390x: Rebuild IPLB for SCSI device directly from DIAG308

Quoted 14 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Because virtio-scsi type devices use a non-architected IPLB pbt code they cannot be set and stored normally. Instead, the IPLB must be rebuilt during re-ipl.

As s390x does not natively support multiple boot devices, the devno field is used to store the position in the boot order for the device.

Handling the rebuild as part of DIAG308 removes the need to check the devices for invalid IPLBs later in the IPL.

---

...

Quoted 23 lines
hw/s390x/ipl.c +0 -4
index ba66847b9c..86c995b580 100644
@@ -448,7 +448,6 @@ void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp)
 
  static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)
  {
-    S390IPLState *ipl = get_ipl_device();
      CcwDevice *ccw_dev = NULL;
      SCSIDevice *sd;
      int devtype;
@@ -481,9 +480,6 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)
              iplb->ccw.ssid = ccw_dev->sch->ssid & 3;
              break;
          case CCW_DEVTYPE_VIRTIO_NET:
-            /* The S390IPLState netboot is true if ANY IPLB may use netboot */
-            ipl->netboot = true;
-            /* Fall through to CCW_DEVTYPE_VIRTIO case */
          case CCW_DEVTYPE_VIRTIO:
              iplb->len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN);
              iplb->blk0_len =

hw/s390x/ipl.c static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb) · line 508

Quoted 5 lines
hw/s390x/ipl.c +2 -0
@@ -508,6 +504,16 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)
      return false;
  }
 
+
+void s390_rebuild_iplb(uint16_t dev_index, IplParameterBlock *iplb) {

Please put the curly brace on a new line for function declarations.

Quoted 7 lines
hw/s390x/ipl.c +7 -0
+    S390IPLState *ipl = get_ipl_device();
+    uint16_t index;
+    index = ipl->rebuilt_iplb ? ipl->iplb_index : dev_index;
+
+    ipl->rebuilt_iplb = s390_build_iplb(get_boot_device(index), iplb);
+    ipl->iplb_index = index;
+}

...

Quoted 10 lines
hw/s390x/ipl.c +3 -1
@@ -661,35 +629,33 @@ IplParameterBlock *s390_ipl_get_iplb(void)
      return &ipl->iplb;
  }
 
-void s390_ipl_reset_request(CPUState *cs, enum s390_reset reset_type)
+static void s390_ipl_prepare_qipl(S390CPU *cpu)
  {
      S390IPLState *ipl = get_ipl_device();
+    uint8_t *addr;
+    uint64_t len = 4096;

hw/s390x/ipl.c IplParameterBlock *s390_ipl_get_iplb(void) · line 646

Quoted 10 lines
hw/s390x/ipl.c +10 -0
+
+    addr = cpu_physical_memory_map(cpu->env.psa, &len, true);
+    if (!addr || len < QIPL_ADDRESS + sizeof(QemuIplParameters)) {
+        error_report("Cannot set QEMU IPL parameters");
+        return;
+    }
+
+    memcpy(addr + QIPL_ADDRESS, &ipl->qipl, sizeof(QemuIplParameters));
+    cpu_physical_memory_unmap(addr, len, 1, len);
+}

Why did you move the s390_ipl_prepare_qipl() function around? It does not seem to get moved in the new code below, so the movement does not seem to be required?

Quoted 41 lines
hw/s390x/ipl.c +4 -23
+void s390_ipl_reset_request(CPUState *cs, enum s390_reset reset_type)
+{
+    S390IPLState *ipl = get_ipl_device();
      if (reset_type == S390_RESET_EXTERNAL || reset_type == S390_RESET_REIPL) {
          /* use CPU 0 for full resets */
          ipl->reset_cpu_index = 0;
      } else {
          ipl->reset_cpu_index = cs->cpu_index;
      }
-    ipl->reset_type = reset_type;
 
-    if (reset_type == S390_RESET_REIPL &&
-        ipl->iplb_valid &&
-        !ipl->netboot &&
-        ipl->iplb.pbt == S390_IPL_TYPE_CCW &&
-        is_virtio_scsi_device(&ipl->iplb)) {
-        CcwDevice *ccw_dev = s390_get_ccw_device(get_boot_device(0), NULL);
-
-        if (ccw_dev &&
-            cpu_to_be16(ccw_dev->sch->devno) == ipl->iplb.ccw.devno &&
-            (ccw_dev->sch->ssid & 3) == ipl->iplb.ccw.ssid) {
-            /*
-             * this is the original boot device's SCSI
-             * so restore IPL parameter info from it
-             */
-            ipl->iplb_valid = s390_build_iplb(get_boot_device(0), &ipl->iplb);
-        }
-    }
+    ipl->reset_type = reset_type;
      if (reset_type == S390_RESET_MODIFIED_CLEAR ||
          reset_type == S390_RESET_LOAD_NORMAL ||
          reset_type == S390_RESET_PV) {
@@ -725,20 +691,6 @@ void s390_ipl_clear_reset_request(void)
      ipl->reset_cpu_index = 0;
  }
 
-static void s390_ipl_prepare_qipl(S390CPU *cpu)
-{
-    S390IPLState *ipl = get_ipl_device();
-    uint8_t *addr;
-    uint64_t len = 4096;

hw/s390x/ipl.c void s390_ipl_clear_reset_request(void) · line 694

Quoted 10 lines
hw/s390x/ipl.c +0 -9
-
-    addr = cpu_physical_memory_map(cpu->env.psa, &len, true);
-    if (!addr || len < QIPL_ADDRESS + sizeof(QemuIplParameters)) {
-        error_report("Cannot set QEMU IPL parameters");
-        return;
-    }
-    memcpy(addr + QIPL_ADDRESS, &ipl->qipl, sizeof(QemuIplParameters));
-    cpu_physical_memory_unmap(addr, len, 1, len);
-}
 

Thomas

#36 lore raw

Re: [PATCH 16/18] s390x: Rebuild IPLB for SCSI device directly from DIAG308

Quoted 25 lines · Thomas Huth
Quoted 10 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]> ...

hw/s390x/ipl.c +3 -0
@@ -661,35 +629,33 @@ IplParameterBlock *s390_ipl_get_iplb(void)
       return &ipl->iplb;
   }
   -void s390_ipl_reset_request(CPUState *cs, enum s390_reset reset_type)
+static void s390_ipl_prepare_qipl(S390CPU *cpu)
   {
       S390IPLState *ipl = get_ipl_device();
+    uint8_t *addr;
+    uint64_t len = 4096;

hw/s390x/ipl.c IplParameterBlock *s390_ipl_get_iplb(void) · line 646

Quoted 10 lines
hw/s390x/ipl.c +10 -0
+
+    addr = cpu_physical_memory_map(cpu->env.psa, &len, true);
+    if (!addr || len < QIPL_ADDRESS + sizeof(QemuIplParameters)) {
+        error_report("Cannot set QEMU IPL parameters");
+        return;
+    }
+
+    memcpy(addr + QIPL_ADDRESS, &ipl->qipl, sizeof(QemuIplParameters));
+    cpu_physical_memory_unmap(addr, len, 1, len);
+}

Why did you move the s390_ipl_prepare_qipl() function around? It does not seem to get moved in the new code below, so the movement does not seem to be required?

Quoted 2 lines

 Thomas

You are correct, it is not necessary to move it.  I moved it in preparation for a change I ultimately ended up reverting, but I forgot to revert moving the function itself.  I’ll fix it.

Jared Rossi

#37 lore raw

PATCH v2 17/18 pc-bios/s390x: Enable multi-device boot loop

In reply to [email protected]

From: Jared Rossi <[email protected]>

Allow attempts to boot from multiple IPL devices. If the first device fails to IPL, select the pre-built IPLB for the next device in the boot order and attempt to IPL from it. Continue this process until IPL is successful or there are no devices left to try.

---
 pc-bios/s390-ccw/iplb.h     | 23 +++++++++++++
 pc-bios/s390-ccw/jump2ipl.c |  7 ++--
 pc-bios/s390-ccw/main.c     | 68 +++++++++++++++----------------------
 pc-bios/s390-ccw/netmain.c  |  3 +-
 4 files changed, 56 insertions(+), 45 deletions(-)
pc-bios/s390-ccw/iplb.h +23 -0
index 16643f5879..d58fe71974 100644
@@ -17,6 +17,7 @@
 #endif
 
 #include <qipl.h>
+#include <string.h>
 
 extern QemuIplParameters qipl;
 extern IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));
@@ -49,4 +50,26 @@ static inline bool set_iplb(IplParameterBlock *iplb)
     return manage_iplb(iplb, false);
 }
 
+/*
+ * The IPL started on the device, but failed in some way.  If the IPLB chain
+ * still has more devices left to try, use the next device in order.
+ */
+static inline bool load_next_iplb(void)
+{
+    IplParameterBlock *next_iplb;
+
+    if (qipl.chain_len < 1) {
+        return false;
+    }
+
+    qipl.index++;
+    next_iplb = (IplParameterBlock *) qipl.next_iplb;
+    memcpy(&iplb, next_iplb, sizeof(IplParameterBlock));
+
+    qipl.chain_len--;
+    qipl.next_iplb = qipl.next_iplb + sizeof(IplParameterBlock);
+
+    return true;
+}
+
 #endif /* IPLB_H */
pc-bios/s390-ccw/jump2ipl.c +4 -3
index bcf0e12f02..afe1888511 100644
@@ -45,9 +45,10 @@ int jump_to_IPL_code(uint64_t address)
      */
     if (iplb.pbt == S390_IPL_TYPE_QEMU_SCSI) {
         iplb.devno = qipl.index;
-        if (!set_iplb(&iplb)) {
-            panic("Failed to set IPLB");
-        }
+    }
+
+    if (!set_iplb(&iplb)) {
+        panic("Failed to set IPLB");
     }
 
     /*
pc-bios/s390-ccw/main.c +27 -41

121 lines not on this page · raw message

pc-bios/s390-ccw/netmain.c +2 -1
index 013f94d932..734e980c6b 100644
@@ -41,6 +41,7 @@
 #define DEFAULT_TFTP_RETRIES 20
 
 extern char _start[];
+extern bool have_iplb;
 
 #define KERNEL_ADDR             ((void *)0L)
 #define KERNEL_MAX_SIZE         ((long)_start)
@@ -478,7 +479,7 @@ static int virtio_setup(void)
      */
     enable_mss_facility();
 
-    if (store_iplb(&iplb)) {
+    if (have_iplb || store_iplb(&iplb)) {
         if (iplb.pbt != S390_IPL_TYPE_CCW) {
             puts("IPL_TYPE_CCW expected");
         }
Signature · 1 line
2.45.1
#38 lore raw

Re: [PATCH 17/18] pc-bios/s390x: Enable multi-device boot loop

Quoted 10 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Allow attempts to boot from multiple IPL devices. If the first device fails to IPL, select the pre-built IPLB for the next device in the boot order and attempt to IPL from it. Continue this process until IPL is successful or there are no devices left to try.

---

...

Quoted 123 lines
pc-bios/s390-ccw/main.c +20 -40
index d7c457e0ed..e38eedd83a 100644
@@ -23,7 +23,7 @@ static SubChannelId blk_schid = { .one = 1 };
  static char loadparm_str[LOADPARM_LEN + 1];
  QemuIplParameters qipl;
  IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));
-static bool have_iplb;
+bool have_iplb;
  static uint16_t cutype;
  LowCore *lowcore; /* Yes, this *is* a pointer to address 0 */
 
@@ -55,6 +55,12 @@ void write_iplb_location(void)
      }
  }
 
+static void copy_qipl(void)
+{
+    QemuIplParameters *early_qipl = (QemuIplParameters *)QIPL_ADDRESS;
+    memcpy(&qipl, early_qipl, sizeof(QemuIplParameters));
+}
+
  unsigned int get_loadparm_index(void)
  {
      return atoi(loadparm_str);
@@ -152,6 +158,7 @@ static void menu_setup(void)
 
      /* If loadparm was set to any other value, then do not enable menu */
      if (memcmp(loadparm_str, LOADPARM_EMPTY, LOADPARM_LEN) != 0) {
+        menu_set_parms(qipl.qipl_flags && ~BOOT_MENU_FLAG_MASK, 0);
          return;
      }
 
@@ -183,7 +190,10 @@ static void css_setup(void)
  static void boot_setup(void)
  {
      char lpmsg[] = "LOADPARM=[________]\n";
-    have_iplb = store_iplb(&iplb);
+
+    if (!have_iplb) {
+        have_iplb = store_iplb(&iplb);
+    }
 
      if (memcmp(iplb.loadparm, "@@@@@@@@", LOADPARM_LEN) != 0) {
          ebcdic_to_ascii((char *) iplb.loadparm, loadparm_str, LOADPARM_LEN);
@@ -191,6 +201,10 @@ static void boot_setup(void)
          sclp_get_loadparm_ascii(loadparm_str);
      }
 
+    if (have_iplb) {
+        menu_setup();
+    }
+
      memcpy(lpmsg + 10, loadparm_str, 8);
      puts(lpmsg);
 
@@ -208,6 +222,7 @@ static bool find_boot_device(void)
 
      switch (iplb.pbt) {
      case S390_IPL_TYPE_CCW:
+        vdev->scsi_device_selected = false;
          debug_print_int("device no. ", iplb.ccw.devno);
          blk_schid.ssid = iplb.ccw.ssid & 0x3;
          debug_print_int("ssid ", blk_schid.ssid);
@@ -231,15 +246,8 @@ static bool find_boot_device(void)
  static int virtio_setup(void)
  {
      VDev *vdev = virtio_get_device();
-    QemuIplParameters *early_qipl = (QemuIplParameters *)QIPL_ADDRESS;
      int ret;
 
-    memcpy(&qipl, early_qipl, sizeof(QemuIplParameters));
-
-    if (have_iplb) {
-        menu_setup();
-    }
-
      switch (vdev->senseid.cu_model) {
      case VIRTIO_ID_NET:
          puts("Network boot device detected");
@@ -281,41 +289,19 @@ static void ipl_boot_device(void)
      }
  }
 
-/*
- * No boot device has been specified, so we have to scan through the
- * channels to find one.
- */
-static void probe_boot_device(void)
-{
-    int ssid, sch_no, ret;
-
-    for (ssid = 0; ssid < 0x3; ssid++) {
-        blk_schid.ssid = ssid;
-        for (sch_no = 0; sch_no < 0x10000; sch_no++) {
-            ret = is_dev_possibly_bootable(-1, sch_no);
-            if (ret < 0) {
-                break;
-            }
-            if (ret == true) {
-                ipl_boot_device(); /* Only returns if unsuccessful */
-                return;
-            }
-        }
-    }
-
-    puts("Could not find a suitable boot device (none specified)");
-}
-
  void main(void)
  {
+    copy_qipl();
      sclp_setup();
      css_setup();
-    boot_setup();
-    if (have_iplb && find_boot_device()) {
-        ipl_boot_device();
-    } else {
-        probe_boot_device();
-    }
+    do {
+        boot_setup();

pc-bios/s390-ccw/main.c static void ipl_boot_device(void) · line 307

Quoted 10 lines
pc-bios/s390-ccw/main.c +7 -1
+        if (have_iplb && find_boot_device()) {
+            ipl_boot_device();
+        }
+        have_iplb = load_next_iplb();
+    } while (have_iplb);
+
+    panic("No suitable device for IPL. Halting...");
 
-    panic("Failed to IPL. Halting...");
  }

Can we please keep the possibility to boot from any device (i.e. the probe_boot_device() stuff), in case the user did not specify any boot index property at all?

Thanks,
Thomas

#39 lore raw

Re: [PATCH 17/18] pc-bios/s390x: Enable multi-device boot loop

Quoted 31 lines · Thomas Huth
Quoted 28 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

  -/*
- * No boot device has been specified, so we have to scan through the
- * channels to find one.
- */

pc-bios/s390-ccw/main.c +0 -21
-static void probe_boot_device(void)
-{
-    int ssid, sch_no, ret;
-
-    for (ssid = 0; ssid < 0x3; ssid++) {
-        blk_schid.ssid = ssid;
-        for (sch_no = 0; sch_no < 0x10000; sch_no++) {
-            ret = is_dev_possibly_bootable(-1, sch_no);
-            if (ret < 0) {
-                break;
-            }
-            if (ret == true) {
-                ipl_boot_device(); /* Only returns if unsuccessful */
-                return;
-            }
-        }
-    }
-
-    puts("Could not find a suitable boot device (none specified)");
-}
-

...

Quoted 5 lines

Can we please keep the possibility to boot from any device (i.e. the probe_boot_device() stuff), in case the user did not specify any boot index property at all?

 Thanks,
  Thomas

Yes, I’ll restore it.

Jared Rossi

#40 lore raw

Re: [PATCH 17/18] pc-bios/s390x: Enable multi-device boot loop

In reply to [email protected]
Quoted 10 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Allow attempts to boot from multiple IPL devices. If the first device fails to IPL, select the pre-built IPLB for the next device in the boot order and attempt to IPL from it. Continue this process until IPL is successful or there are no devices left to try.

---

...

Quoted 27 lines
pc-bios/s390-ccw/main.c +7 -1
index d7c457e0ed..e38eedd83a 100644
@@ -23,7 +23,7 @@ static SubChannelId blk_schid = { .one = 1 };
  static char loadparm_str[LOADPARM_LEN + 1];
  QemuIplParameters qipl;
  IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));
-static bool have_iplb;
+bool have_iplb;
  static uint16_t cutype;
  LowCore *lowcore; /* Yes, this *is* a pointer to address 0 */
 
@@ -55,6 +55,12 @@ void write_iplb_location(void)
      }
  }
 
+static void copy_qipl(void)
+{
+    QemuIplParameters *early_qipl = (QemuIplParameters *)QIPL_ADDRESS;
+    memcpy(&qipl, early_qipl, sizeof(QemuIplParameters));
+}
+
  unsigned int get_loadparm_index(void)
  {
      return atoi(loadparm_str);

pc-bios/s390-ccw/main.c static void menu_setup(void) · line 161

Quoted 4 lines
pc-bios/s390-ccw/main.c +1 -0
@@ -152,6 +158,7 @@ static void menu_setup(void)
 
      /* If loadparm was set to any other value, then do not enable menu */
      if (memcmp(loadparm_str, LOADPARM_EMPTY, LOADPARM_LEN) != 0) {
+        menu_set_parms(qipl.qipl_flags && ~BOOT_MENU_FLAG_MASK, 0);

That looks supsicious ... did you mean just one "&" instead of "&&" here?

pc-bios/s390-ccw/main.c static void menu_setup(void) · line 163

Quoted 2 lines
pc-bios/s390-ccw/main.c +0 -0
          return;
      }

Thomas

#41 lore raw

Re: [PATCH 17/18] pc-bios/s390x: Enable multi-device boot loop

Quoted 34 lines · Thomas Huth
Quoted 10 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Allow attempts to boot from multiple IPL devices. If the first device fails to IPL, select the pre-built IPLB for the next device in the boot order and attempt to IPL from it. Continue this process until IPL is successful or there are no devices left to try.

---

...

Quoted 22 lines
pc-bios/s390-ccw/main.c +1 -1
index d7c457e0ed..e38eedd83a 100644
@@ -23,7 +23,7 @@ static SubChannelId blk_schid = { .one = 1 };
   static char loadparm_str[LOADPARM_LEN + 1];
   QemuIplParameters qipl;
   IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));
-static bool have_iplb;
+bool have_iplb;
   static uint16_t cutype;

  LowCore *lowcore; /* Yes, this *is* a pointer to address 0 */ @@ -55,6 +55,12 @@ void write_iplb_location(void)
      }
  }
  +static void copy_qipl(void)

pc-bios/s390-ccw/main.c +5 -0
+{
+    QemuIplParameters *early_qipl = (QemuIplParameters *)QIPL_ADDRESS;
+    memcpy(&qipl, early_qipl, sizeof(QemuIplParameters));
+}
+

  unsigned int get_loadparm_index(void)

Quoted 9 lines

pc-bios/s390-ccw/main.c static void menu_setup(void) · line 160

Quoted 6 lines

  {
      return atoi(loadparm_str);

pc-bios/s390-ccw/main.c +1 -0
@@ -152,6 +158,7 @@ static void menu_setup(void)
         /* If loadparm was set to any other value, then do not enable menu */
       if (memcmp(loadparm_str, LOADPARM_EMPTY, LOADPARM_LEN) != 0) {
+        menu_set_parms(qipl.qipl_flags && ~BOOT_MENU_FLAG_MASK, 0);

That looks supsicious ... did you mean just one "&" instead of "&&" here?

Good catch, yes it should be a single “&”.

Jared Rossi

#42 lore raw

PATCH v2 18/18 docs/system: Update documentation for s390x IPL

In reply to [email protected]

From: Jared Rossi <[email protected]>

Update docs to show that s390x PC BIOS can support more than one boot device.

---
 docs/system/bootindex.rst         | 7 ++++---
 docs/system/s390x/bootdevices.rst | 9 ++++++---
 2 files changed, 10 insertions(+), 6 deletions(-)
docs/system/bootindex.rst +4 -3
index 8b057f812f..142ae1a0a2 100644
@@ -49,10 +49,11 @@ Limitations
 -----------
 
 Some firmware has limitations on which devices can be considered for
-booting.  For instance, the PC BIOS boot specification allows only one
-disk to be bootable.  If boot from disk fails for some reason, the BIOS
+booting.  For instance, the x86 PC BIOS boot specification allows only one
+disk to be bootable.  If boot from disk fails for some reason, the x86 BIOS
 won't retry booting from other disk.  It can still try to boot from
-floppy or net, though.
+floppy or net, though. In the case of s390x PC BIOS, the BIOS will try up to
+8 total devices, any number of which may be disks.
 
 Sometimes, firmware cannot map the device path QEMU wants firmware to
 boot from to a boot method.  It doesn't happen for devices the firmware
docs/system/s390x/bootdevices.rst +6 -3
index c97efb8fc0..1a1a764c1c 100644
@@ -6,9 +6,7 @@ Booting with bootindex parameter
 
 For classical mainframe guests (i.e. LPAR or z/VM installations), you always
 have to explicitly specify the disk where you want to boot from (or "IPL" from,
-in s390x-speak -- IPL means "Initial Program Load"). In particular, there can
-also be only one boot device according to the architecture specification, thus
-specifying multiple boot devices is not possible (yet).
+in s390x-speak -- IPL means "Initial Program Load").
 
 So for booting an s390x guest in QEMU, you should always mark the
 device where you want to boot from with the ``bootindex`` property, for
@@ -17,6 +15,11 @@ example::
  qemu-system-s390x -drive if=none,id=dr1,file=guest.qcow2 \
                    -device virtio-blk,drive=dr1,bootindex=1
 
+Multiple devices may have a bootindex. The lowest bootindex is assigned to the
+device to IPL first.  If the IPL fails for the first, the device with the second
+lowest bootindex will be tried and so on until IPL is successful or there are no
+remaining boot devices to try.
+
 For booting from a CD-ROM ISO image (which needs to include El-Torito boot
 information in order to be bootable), it is recommended to specify a ``scsi-cd``
 device, for example like this::
Signature · 1 line
2.45.1
#43 lore raw

Re: [PATCH 18/18] docs/system: Update documentation for s390x IPL

Quoted 17 lines · On 27/09/2024 02.51, [email protected] wrote:

From: Jared Rossi <[email protected]>

Update docs to show that s390x PC BIOS can support more than one boot device.

---
  docs/system/bootindex.rst         | 7 ++++---
  docs/system/s390x/bootdevices.rst | 9 ++++++---
  2 files changed, 10 insertions(+), 6 deletions(-)
docs/system/bootindex.rst +0 -0
index 8b057f812f..142ae1a0a2 100644
@@ -49,10 +49,11 @@ Limitations
  -----------

docs/system/bootindex.rst Limitations · line 56

Quoted 10 lines
docs/system/bootindex.rst +4 -3
 
  Some firmware has limitations on which devices can be considered for
-booting.  For instance, the PC BIOS boot specification allows only one
-disk to be bootable.  If boot from disk fails for some reason, the BIOS
+booting.  For instance, the x86 PC BIOS boot specification allows only one
+disk to be bootable.  If boot from disk fails for some reason, the x86 BIOS
  won't retry booting from other disk.  It can still try to boot from
-floppy or net, though.
+floppy or net, though. In the case of s390x PC BIOS, the BIOS will try up to
+8 total devices, any number of which may be disks.

I'd just say "s390x BIOS" - or "s390x firmware", but using the term "PC" with s390x sounds wrong to me ;-)

Thomas

#44 lore raw
In reply to [email protected]
Quoted 24 lines · On 27/09/2024 02.50, [email protected] wrote:

From: Jared Rossi <[email protected]>

Loosely a v2, this updated patch set is a significant rework to most aspects of the initially proposed multi-device boot order. Of particular note, the original patch set used code jumps to restart the IPL while this version does not. In order to remove the code jumps, two significant prerequisite changes are required for the pc-bios. Firstly, the netboot code is linked into the main s390-ccw.img, which allows for return after a failed netboot, based on the patch set from Thomas Huth <[email protected]>
(https://lists.gnu.org/archive/html/qemu-devel/2024-06/msg03956.html).
Secondly, IPL errors that result in an immediate termination are converted to instead provide a return value back to the main IPL calling function.

The routines for building and loading fallback device IPLBs are largely
unchanged: An IPLB is built for each device with a boot index specified (up to 8 devices). The IPLBs location in memory is passed to the guest using the global QIPL structure, which is stored at a fixed address. If the first device in the boot order successfully IPLs, then the additional IPLBs are never used; however, if the first device fails, subsequent IPLBs are retrieved from memory and the IPL process restarts using the specifications contained in the new IPLB.

This continues until IPL is successful or there are no IPLBs left to try.

Quoted 7 lines

The per-device loadparm attribute is still uniformly added to CCW devices although it may only be assigned a value if the device has a boot index. This will need further rework if a more targeted approach is desired.

Two automated test cases are planned for v3: a minimal test where a guest has two boot devices defined and the first fails, and also a limit test where the guest has 8 boot devices defined but only the last one can actually IPL.

Thanks, this looks already much better than the "jump back to start" stuff in v1 !

One thing I noticed while testing your patches: Booting from ISO images seems to be broken for me now, e.g. something like:

./qemu-system-s390x -nographic -accel kvm -m 1G \
-bios pc-bios/s390-ccw/s390-ccw.img \
-drive
if=none,id=d1,file=Fedora-Server-dvd-s390x-38-1.6.iso,format=raw,media=cdrom \
-device virtio-scsi -device scsi-cd,drive=d1,bootindex=1

used to work fine in the past, but gives me a "Failed to IPL this ISO image!" error now.

Does ISO IPL-ing work for you?

Thomas

#45 lore raw
Quoted 13 lines · Thomas Huth
Quoted 2 lines · On 27/09/2024 02.50, [email protected] wrote:

From: Jared Rossi <[email protected]>
...

Thanks, this looks already much better than the "jump back to start" stuff in v1 !

One thing I noticed while testing your patches: Booting from ISO images seems to be broken for me now, e.g. something like:

./qemu-system-s390x -nographic -accel kvm -m 1G \
 -bios pc-bios/s390-ccw/s390-ccw.img \
 -drive if=none,id=d1,file=Fedora-Server-dvd-s390x-38-1.6.iso,format=raw,media=cdrom \
 -device virtio-scsi -device scsi-cd,drive=d1,bootindex=1

Quoted 7 lines

used to work fine in the past, but gives me a "Failed to IPL this ISO image!" error now.

Does ISO IPL-ing work for you?

 Thomas

Hi Thomas,

Firstly, I just wanted to say thank you for your continued support and guidance on this feature. Converting all of the panics to returns ended up being rather invasive and touched a lot of code I had not initially expected to modify, so I appreciate your patience with the rework.

As for the ISO IPL, after reading your review comments I’m not surprised it fails for you. The problem is certainly caused by the mismatched error condition checks you pointed out in your response to patch 07. I also recognize that means this code path was not sufficiently exercised in my own testing, so I will resolve that and also double check for any other gaps in coverage on my side.

I will make the changes you suggest and also add the automated test cases you previously requested, and try to get v3 posted ASAP.

Thanks again,
Jared Rossi