Skip to contentSkip to conversation

s390x: Add Full Boot Order Support

PATCH Superseded [email protected] 2 participants 27 messages Oct 17, 2024 Arm/Amlogic Meson SoC support

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover s390x: Add Full Boot Order Support

From: Jared Rossi <[email protected]>

changes v3 -> v4:
- Ensure signed-ness of return values is appropriate
- Add missing newline character in replacements of sclp_print_int()
- Add a missing return in a SCSI error path
- Restore break that was incorrectly removed for Virtio CU devices
- Remove an extra/early return that caused probing to end early
- Convert "good" device to scsi-cd in a cdrom-test for better coverage
- Minor stylistic clean-ups and variable name clarifications

changes v2 -> v3:

- Fix return code mismatch in ISO IPL path
- Introduce a new RC for loading ECKD segments rather than rely on block 0
- Fix bug causing false negative in some SCSI device error cases
- Terminate entire IPL on bad PBT instead of trying next device
- Simplify routine for building IPLB chain
- Restore device probing
- Add qtests
- Minor stylistic clean-ups and comment clarifications

Jared Rossi (19):
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 ECKD IPL path pc-bios/s390-ccw: Remove panics from SCSI 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 hw/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 tests/qtest: Add s390x boot order tests to cdrom-test.c

 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        |  20 +-
 pc-bios/s390-ccw/cio.h            |   2 +
 pc-bios/s390-ccw/dasd-ipl.h       |   2 +-
 pc-bios/s390-ccw/iplb.h           | 108 ++-----
 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                    | 279 +++++++++---------
 hw/s390x/s390-virtio-ccw.c        |  28 +-
 hw/s390x/sclp.c                   |   3 +-
 pc-bios/s390-ccw/bootmap.c        | 456 ++++++++++++++++++++----------
 pc-bios/s390-ccw/cio.c            |  81 +++---
 pc-bios/s390-ccw/dasd-ipl.c       |  71 ++---
 pc-bios/s390-ccw/jump2ipl.c       |  23 +-
 pc-bios/s390-ccw/libc.c           |  88 ------
 pc-bios/s390-ccw/main.c           |  97 ++++---
 pc-bios/s390-ccw/menu.c           |  51 ++--
 pc-bios/s390-ccw/netmain.c        |  38 ++-
 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 +-
 tests/qtest/cdrom-test.c          |  24 ++
 pc-bios/meson.build               |   1 -
 pc-bios/s390-ccw/Makefile         |  69 ++++-
 pc-bios/s390-netboot.img          | Bin 67232 -> 0 bytes
 35 files changed, 1160 insertions(+), 1072 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 v4 1/19 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 5ab7433908..5f60977ceb 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 v4 2/19 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..4a7d8a91f1 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]\n", 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..6f6d95d170 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\n", 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..ae751adec1 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\n", 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..203df20965 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\n", 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..6b4a1caf8a 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\n", 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\n", 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 v4 3/19 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 6f6d95d170..6abb34e563 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 203df20965..fc44da3161 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 v4 4/19 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 5aa8d207a3..529e53f308 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 v4 5/19 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 v4 6/19 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 v4 7/19 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  | 15 +++----
 pc-bios/s390-ccw/s390-ccw.h |  1 +
 pc-bios/s390-ccw/bootmap.c  | 82 ++++++++++++++++++++++++-------------
 3 files changed, 61 insertions(+), 37 deletions(-)
pc-bios/s390-ccw/bootmap.h +6 -9
index 4a7d8a91f1..09f4e6fb40 100644
@@ -385,17 +385,14 @@ 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,
-                                   const char *errmsg)
-{
-    IPL_assert(virtio_read_many(block_offset, buf, 1) == 0, errmsg);
-}
-
-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 6abb34e563..3e844abd71 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 +54 -28

175 lines not on this page · raw message

Signature · 1 line
2.45.1
#8 lore raw

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

Quoted 9 lines · On 17/10/2024 03.47, [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.

---

...

Quoted 74 lines
pc-bios/s390-ccw/bootmap.c +22 -11
index 414c3f1b47..5477cfe228 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 (virtio_read(bswap32(s->load_rba), magic_sec)) {
+        puts("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);
@@ -692,28 +694,35 @@ static uint32_t sec_offset[ISO9660_MAX_DIR_DEPTH];
  /* Remained directory space in bytes */
  static uint32_t dir_rem[ISO9660_MAX_DIR_DEPTH];
 
-static inline uint32_t iso_get_file_size(uint32_t load_rba)
+static inline long iso_get_file_size(uint32_t load_rba)
  {
      IsoVolDesc *vd = (IsoVolDesc *)sec;
      IsoDirHdr *cur_record = &vd->vd.primary.rootdir;
      uint8_t *temp = sec + ISO_SECTOR_SIZE;
      int level = 0;
 
-    read_iso_sector(ISO_PRIMARY_VD_SECTOR, sec,
-                    "Failed to read ISO primary descriptor");
+    if (virtio_read(ISO_PRIMARY_VD_SECTOR, sec)) {
+        puts("Failed to read ISO primary descriptor");
+        return -EIO;
+    }
+
      sec_loc[0] = iso_733_to_u32(cur_record->ext_loc);
      dir_rem[0] = 0;
      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) {
-            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;
+            }
              if (dir_rem[level] == 0) {
                  /* Skip self and parent records */
                  dir_rem[level] = iso_733_to_u32(cur_record->data_len) -
@@ -758,8 +767,10 @@ static inline uint32_t iso_get_file_size(uint32_t load_rba)
          if (dir_rem[level] == 0) {
              /* Nothing remaining */
              level--;
-            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;
+            }
          }
      }
 

pc-bios/s390-ccw/bootmap.c static void load_iso_bc_entry(IsoBcSection *load) · line 791

Quoted 8 lines
pc-bios/s390-ccw/bootmap.c +1 -1
@@ -774,7 +785,7 @@ static void load_iso_bc_entry(IsoBcSection *load)
       * is padded and ISO_SECTOR_SIZE bytes aligned
       */
      uint32_t blks_to_load = bswap16(s.sector_count) >> ET_SECTOR_SHIFT;
-    uint32_t real_size = iso_get_file_size(bswap32(s.load_rba));
+    long real_size = iso_get_file_size(bswap32(s.load_rba));
 
      if (real_size) {
          /* Round up blocks to load */

I think this check should now be changed to "real_size > 0" ? And in the "else" path, the function should return immediately?

Thomas

#9 lore raw

PATCH v4 8/19 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.h |   1 +
 pc-bios/s390-ccw/bootmap.c | 193 +++++++++++++++++++++++++------------
 2 files changed, 135 insertions(+), 59 deletions(-)
pc-bios/s390-ccw/bootmap.h +1 -0
index 09f4e6fb40..271dbabbc3 100644
@@ -16,6 +16,7 @@
 
 typedef uint64_t block_number_t;
 #define NULL_BLOCK_NR 0xffffffffffffffffULL
+#define ERROR_BLOCK_NR 0xfffffffffffffffeULL
 
 #define FREE_SPACE_FILLER '\xAA'
 
pc-bios/s390-ccw/bootmap.c +134 -59

420 lines not on this page · raw message

Signature · 1 line
2.45.1
#10 lore raw

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

Quoted 50 lines · On 17/10/2024 03.47, [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.h |   1 +
  pc-bios/s390-ccw/bootmap.c | 193 +++++++++++++++++++++++++------------
  2 files changed, 135 insertions(+), 59 deletions(-)
pc-bios/s390-ccw/bootmap.h +1 -0
index 09f4e6fb40..271dbabbc3 100644
@@ -16,6 +16,7 @@
 
  typedef uint64_t block_number_t;
  #define NULL_BLOCK_NR 0xffffffffffffffffULL
+#define ERROR_BLOCK_NR 0xfffffffffffffffeULL
 
  #define FREE_SPACE_FILLER '\xAA'
 
pc-bios/s390-ccw/bootmap.c +5 -2
index 5477cfe228..dd04bb3384 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 ERROR_BLOCK_NR;
+    }
 
      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 NULL_BLOCK_NR;
              }
 
              /* we need the updated blockno for the next indirect entry

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

Quoted 8 lines
pc-bios/s390-ccw/bootmap.c +3 -2
@@ -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 NULL_BLOCK_NR;

Shouldn't that be a "return ERROR_BLOCK_NR" instead?

Quoted 134 lines
pc-bios/s390-ccw/bootmap.c +47 -16
+            }
 
              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 ERROR_BLOCK_NR;
+                }
                  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 ERROR_BLOCK_NR;
+                }
                  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 ERROR_BLOCK_NR;
+            }
 
              *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++) {

pc-bios/s390-ccw/bootmap.c static void run_eckd_boot_script(block_number_t bmt_block_nr, · line 359

Quoted 9 lines
pc-bios/s390-ccw/bootmap.c +5 -1
@@ -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 != ERROR_BLOCK_NR && block_nr != NULL_BLOCK_NR);
+
+        if (block_nr == ERROR_BLOCK_NR) {
+            return ldipl ? 0 : -EIO;
+        }

Mostly a matter of style, but if you move the if-statement into the while loop, you don't have to check for ERROR_BLOCK_NR in the while condition again.

Quoted 18 lines
pc-bios/s390-ccw/bootmap.c +6 -3
      }
 
      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;
  }

...

Quoted 5 lines
pc-bios/s390-ccw/bootmap.c +0 -1
@@ -787,12 +859,15 @@ static void load_iso_bc_entry(IsoBcSection *load)
      uint32_t blks_to_load = bswap16(s.sector_count) >> ET_SECTOR_SHIFT;
      long real_size = iso_get_file_size(bswap32(s.load_rba));
 
-    if (real_size) {

pc-bios/s390-ccw/bootmap.c static void load_iso_bc_entry(IsoBcSection *load) · line 871

Quoted 10 lines
pc-bios/s390-ccw/bootmap.c +4 -0
+    if (real_size > 0) {
          /* Round up blocks to load */
          blks_to_load = (real_size + ISO_SECTOR_SIZE - 1) / ISO_SECTOR_SIZE;
          puts("ISO boot image size verified");
      } else {
          puts("ISO boot image size could not be verified");
+        if (real_size < 0) {
+            return;
+        }
      }

Ah, here's the fix for the problem that I complained about in the previous patch :-) ... looks like you've squashed it into the wrong patch.

Thomas

#11 lore raw

PATCH v4 9/19 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/iplb.h          |   2 +
 pc-bios/s390-ccw/bootmap.c       |  88 +++++++++++++-----
 pc-bios/s390-ccw/jump2ipl.c      |   1 +
 pc-bios/s390-ccw/main.c          |   2 +-
 pc-bios/s390-ccw/virtio-blkdev.c |   4 +-
 pc-bios/s390-ccw/virtio-scsi.c   | 147 +++++++++++++++++++++----------
 6 files changed, 172 insertions(+), 72 deletions(-)
pc-bios/s390-ccw/iplb.h +2 -0
index 3758698468..639fa34919 100644
@@ -94,6 +94,8 @@ struct QemuIplParameters {
 typedef struct QemuIplParameters QemuIplParameters;
 
 extern QemuIplParameters qipl;
+extern IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));
+extern bool have_iplb;
 
 #define S390_IPL_TYPE_FCP 0x00
 #define S390_IPL_TYPE_CCW 0x02
pc-bios/s390-ccw/bootmap.c +66 -22

170 lines not on this page · raw message

pc-bios/s390-ccw/jump2ipl.c +1 -0
index 80b7f6a1f3..0826c16787 100644
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include "s390-ccw.h"
 #include "s390-arch.h"
+#include "iplb.h"
 
 #define KERN_IMAGE_START 0x010000UL
 #define RESET_PSW_MASK (PSW_MASK_SHORTPSW | PSW_MASK_64)
pc-bios/s390-ccw/main.c +1 -1
index fc44da3161..ed72f87962 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 */
 
pc-bios/s390-ccw/virtio-blkdev.c +2 -2
index 2666326801..1c585f034b 100644
@@ -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-scsi.c +100 -47

300 lines not on this page · raw message

Signature · 1 line
2.45.1
#12 lore raw

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

Quoted 22 lines · On 17/10/2024 03.47, [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/iplb.h          |   2 +
  pc-bios/s390-ccw/bootmap.c       |  88 +++++++++++++-----
  pc-bios/s390-ccw/jump2ipl.c      |   1 +
  pc-bios/s390-ccw/main.c          |   2 +-
  pc-bios/s390-ccw/virtio-blkdev.c |   4 +-
  pc-bios/s390-ccw/virtio-scsi.c   | 147 +++++++++++++++++++++----------
  6 files changed, 172 insertions(+), 72 deletions(-)
pc-bios/s390-ccw/iplb.h +0 -0
index 3758698468..639fa34919 100644

pc-bios/s390-ccw/iplb.h struct QemuIplParameters { · line 98

Quoted 5 lines
pc-bios/s390-ccw/iplb.h +2 -0
@@ -94,6 +94,8 @@ struct QemuIplParameters {
  typedef struct QemuIplParameters QemuIplParameters;
 
  extern QemuIplParameters qipl;
+extern IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));
+extern bool have_iplb;

Why do you move these to the header file now here? You don't seem to be using these in this patch? Should it be done in a later patch?

Also the "extern IplParameterBlock iplb" is already available in this header file, no need to add it again.

...

Quoted 31 lines
pc-bios/s390-ccw/virtio-scsi.c +5 -3
index 6b4a1caf8a..32fa81a247 100644
@@ -26,7 +26,7 @@ static uint8_t scsi_inquiry_std_response[256];
  static ScsiInquiryEvpdPages scsi_inquiry_evpd_pages_response;
  static ScsiInquiryEvpdBl scsi_inquiry_evpd_bl_response;
 
-static inline void vs_assert(bool term, const char **msgs)
+static inline bool vs_assert(bool term, const char **msgs)
  {
      if (!term) {
          int i = 0;
@@ -35,11 +35,13 @@ static inline void vs_assert(bool term, const char **msgs)
          while (msgs[i]) {
              printf("%s", msgs[i++]);
          }
-        panic(" !\n");
+        puts(" !");
      }
+
+    return term;
  }
 
-static void virtio_scsi_verify_response(VirtioScsiCmdResp *resp,
+static bool virtio_scsi_verify_response(VirtioScsiCmdResp *resp,
                                          const char *title)
  {
      const char *mr[] = {
@@ -56,8 +58,12 @@ static void virtio_scsi_verify_response(VirtioScsiCmdResp *resp,
          0

pc-bios/s390-ccw/virtio-scsi.c static void virtio_scsi_verify_response(VirtioScsiCmdResp *resp, · line 66

Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +6 -2
      };
 
-    vs_assert(resp->response == VIRTIO_SCSI_S_OK, mr);
-    vs_assert(resp->status == CDB_STATUS_GOOD, ms);
+    if (!vs_assert(resp->response == VIRTIO_SCSI_S_OK, mr) ||
+                !vs_assert(resp->status == CDB_STATUS_GOOD, ms)) {
+        return false;
+    }
+
+    return true;

Could be simplified to:

    return vs_assert(resp->response == VIRTIO_SCSI_S_OK, mr) &&
           vs_assert(resp->status == CDB_STATUS_GOOD, ms);
Quoted 2 lines
pc-bios/s390-ccw/virtio-scsi.c +0 -0
  }
 

...

pc-bios/s390-ccw/virtio-scsi.c static bool scsi_inquiry(VDev *vdev, uint8_t evpd, uint8_t page, · line 127

Quoted 7 lines
pc-bios/s390-ccw/virtio-scsi.c +2 -1
@@ -110,12 +123,13 @@ static bool scsi_inquiry(VDev *vdev, uint8_t evpd, uint8_t page,
          { data, data_size, VRING_DESC_F_WRITE },
      };
 
-    vs_run("inquiry", inquiry, vdev, &cdb, sizeof(cdb), data, data_size);
+    int ret = vs_run("inquiry", inquiry,
+            vdev, &cdb, sizeof(cdb), data, data_size);

Please indent the second line with the "(" in the previous line.

Quoted 3 lines
pc-bios/s390-ccw/virtio-scsi.c +1 -1
-    return virtio_scsi_response_ok(&resp);
+    return ret ? ret : virtio_scsi_response_ok(&resp);
  }

...

Quoted 36 lines
          if (r->lun_list_len == 0) {
              printf("no LUNs for target 0x%X\n", target);
              continue;
pc-bios/s390-ccw/virtio-scsi.c +12 -5
@@ -283,7 +306,9 @@ int virtio_scsi_read_many(VDev *vdev,
          data_size = sector_count * virtio_get_block_size() * f;
          if (!scsi_read_10(vdev, sector * f, sector_count * f, load_addr,
                            data_size)) {
-            virtio_scsi_verify_response(&resp, "virtio-scsi:read_many");
+            if (!virtio_scsi_verify_response(&resp, "virtio-scsi:read_many")) {
+                return 1;
+            }
          }
          load_addr += data_size;
          sector += sector_count;
@@ -352,11 +377,16 @@ static int virtio_scsi_setup(VDev *vdev)
              uint8_t code = resp.sense[0] & SCSI_SENSE_CODE_MASK;
              uint8_t sense_key = resp.sense[2] & SCSI_SENSE_KEY_MASK;
 
-            IPL_assert(resp.sense_len != 0, "virtio-scsi:setup: no SENSE data");
+            if (resp.sense_len == 0) {
+                puts("virtio-scsi: setup: no SENSE data");
+                return -EINVAL;
+            }
 
-            IPL_assert(retry_test_unit_ready && code == 0x70 &&
-                       sense_key == SCSI_SENSE_KEY_UNIT_ATTENTION,
-                       "virtio-scsi:setup: cannot retry");
+            if (!retry_test_unit_ready || code != 0x70 ||
+                       sense_key != SCSI_SENSE_KEY_UNIT_ATTENTION) {
+                puts("virtio-scsi:setup: cannot retry");
+                return -EIO;
+            }
 
              /* retry on CHECK_CONDITION/UNIT_ATTENTION as it
               * may not designate a real error, but it may be

pc-bios/s390-ccw/virtio-scsi.c static int virtio_scsi_setup(VDev *vdev) · line 401

Quoted 6 lines
pc-bios/s390-ccw/virtio-scsi.c +2 -1
@@ -367,16 +397,22 @@ static int virtio_scsi_setup(VDev *vdev)
              continue;
          }
 
-        virtio_scsi_verify_response(&resp, "virtio-scsi:setup");
+        if (!virtio_scsi_verify_response(&resp, "virtio-scsi:setup")) {
+            return 1;

Phew, there a bunch of places now that return "1" for e.g. response OK, but this one here is now using "1" for error? ... that's quite confusing. Could we maybe standardize on using negative values for error codes? (and 1/0 or true/false only for functions that return OK/not OK ?), i.e. use a negative error code here (returning -1 is also fine for me)?

Quoted 6 lines
pc-bios/s390-ccw/virtio-scsi.c +2 -1
+        }
      }
 
      /* read and cache SCSI INQUIRY response */
-    if (!scsi_inquiry(vdev,
+    ret = scsi_inquiry(vdev,

pc-bios/s390-ccw/virtio-scsi.c static int virtio_scsi_setup(VDev *vdev) · line 414

Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +5 -2
                        SCSI_INQUIRY_STANDARD,
                        SCSI_INQUIRY_STANDARD_NONE,
                        scsi_inquiry_std_response,
-                      sizeof(scsi_inquiry_std_response))) {
-        virtio_scsi_verify_response(&resp, "virtio-scsi:setup:inquiry");
+                      sizeof(scsi_inquiry_std_response));
+    if (ret < 1) {
+        if (ret != 0 || !virtio_scsi_verify_response(&resp,
+                "virtio-scsi:setup:inquiry")) {
+            return 1;

dito, use a negative error code here?

Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +2 -1
+        }
      }
 
      if (virtio_scsi_inquiry_response_is_cdrom(scsi_inquiry_std_response)) {
@@ -385,12 +421,16 @@ static int virtio_scsi_setup(VDev *vdev)
          vdev->scsi_block_size = VIRTIO_ISO_BLOCK_SIZE;
      }
 
-    if (!scsi_inquiry(vdev,
+    ret = scsi_inquiry(vdev,

pc-bios/s390-ccw/virtio-scsi.c static int virtio_scsi_setup(VDev *vdev) · line 432

Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +5 -2
                        SCSI_INQUIRY_EVPD,
                        SCSI_INQUIRY_EVPD_SUPPORTED_PAGES,
                        evpd,
-                      sizeof(*evpd))) {
-        virtio_scsi_verify_response(&resp, "virtio-scsi:setup:supported_pages");
+                      sizeof(*evpd));
+    if (ret < 1) {
+        if (ret != 0 || !virtio_scsi_verify_response(&resp,
+                "virtio-scsi:setup:supported_pages")) {
+            return 1;

dito

Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +2 -1
+        }
      }
 
      debug_print_int("EVPD length", evpd->page_length);
@@ -402,12 +442,16 @@ static int virtio_scsi_setup(VDev *vdev)
              continue;
          }
 
-        if (!scsi_inquiry(vdev,
+        ret = scsi_inquiry(vdev,

pc-bios/s390-ccw/virtio-scsi.c static int virtio_scsi_setup(VDev *vdev) · line 453

Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +5 -2
                            SCSI_INQUIRY_EVPD,
                            SCSI_INQUIRY_EVPD_BLOCK_LIMITS,
                            evpd_bl,
-                          sizeof(*evpd_bl))) {
-            virtio_scsi_verify_response(&resp, "virtio-scsi:setup:blocklimits");
+                          sizeof(*evpd_bl));
+        if (ret < 1) {
+            if (ret != 0 || !virtio_scsi_verify_response(&resp,
+                    "virtio-scsi:setup:blocklimits")) {
+                return 1;

dito

Quoted 5 lines
pc-bios/s390-ccw/virtio-scsi.c +1 -0
+            }
          }
 
          debug_print_int("max transfer", evpd_bl->max_transfer);

pc-bios/s390-ccw/virtio-scsi.c static int virtio_scsi_setup(VDev *vdev) · line 474

Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +5 -2
@@ -423,8 +467,12 @@ static int virtio_scsi_setup(VDev *vdev)
      vdev->max_transfer = MIN_NON_ZERO(VIRTIO_SCSI_MAX_SECTORS,
                                        vdev->max_transfer);
 
-    if (!scsi_read_capacity(vdev, data, data_size)) {
-        virtio_scsi_verify_response(&resp, "virtio-scsi:setup:read_capacity");
+    ret = scsi_read_capacity(vdev, data, data_size);
+    if (ret < 1) {
+        if (ret != 0 || !virtio_scsi_verify_response(&resp,
+                "virtio-scsi:setup:read_capacity")) {
+            return 1;

dito

Quoted 14 lines
pc-bios/s390-ccw/virtio-scsi.c +3 -4
+        }
      }
      scsi_parse_capacity_report(data, &vdev->scsi_last_block,
                                 (uint32_t *) &vdev->scsi_block_size);
@@ -439,10 +487,15 @@ int virtio_scsi_setup_device(SubChannelId schid)
      vdev->schid = schid;
      virtio_setup_ccw(vdev);
 
-    IPL_assert(vdev->config.scsi.sense_size == VIRTIO_SCSI_SENSE_SIZE,
-               "Config: sense size mismatch");
-    IPL_assert(vdev->config.scsi.cdb_size == VIRTIO_SCSI_CDB_SIZE,
-               "Config: CDB size mismatch");
+    if (vdev->config.scsi.sense_size != VIRTIO_SCSI_SENSE_SIZE) {
+        puts("Config: sense size mismatch");

pc-bios/s390-ccw/virtio-scsi.c int virtio_scsi_setup_device(SubChannelId schid) · line 501

Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +7 -0
+        return -EINVAL;
+    }
+
+    if (vdev->config.scsi.cdb_size != VIRTIO_SCSI_CDB_SIZE) {
+        puts("Config: CDB size mismatch");
+        return -EINVAL;
+    }
 
      puts("Using virtio-scsi.");
 

Thomas

#13 lore raw

PATCH v4 10/19 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
#14 lore raw

PATCH v4 11/19 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    | 17 +++++++++++------
 pc-bios/s390-ccw/virtio-net.c |  7 +++++--
 4 files changed, 18 insertions(+), 9 deletions(-)
pc-bios/s390-ccw/s390-ccw.h +1 -1
index 3e844abd71..344ad15655 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 a277fc3431..f1cfb7aaa8 100644
@@ -1073,6 +1073,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 +11 -6
index bc6ad8695f..0bb359e09f 100644
@@ -464,7 +464,7 @@ static bool find_net_dev(Schib *schib, int dev_no)
     return false;
 }
 
-static void virtio_setup(void)
+static bool virtio_setup(void)
 {
     Schib schib;
     int ssid;
@@ -495,10 +495,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 +506,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 +532,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
Reviewed-by on v4 11/19
#15 lore raw

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

Quoted 85 lines · On 17/10/2024 03.47, [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.

---
  pc-bios/s390-ccw/s390-ccw.h   |  2 +-
  pc-bios/s390-ccw/bootmap.c    |  1 +
  pc-bios/s390-ccw/netmain.c    | 17 +++++++++++------
  pc-bios/s390-ccw/virtio-net.c |  7 +++++--
  4 files changed, 18 insertions(+), 9 deletions(-)
pc-bios/s390-ccw/s390-ccw.h +1 -1
index 3e844abd71..344ad15655 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 a277fc3431..f1cfb7aaa8 100644
@@ -1073,6 +1073,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 +9 -5
index bc6ad8695f..0bb359e09f 100644
@@ -464,7 +464,7 @@ static bool find_net_dev(Schib *schib, int dev_no)
      return false;
  }
 
-static void virtio_setup(void)
+static bool virtio_setup(void)
  {
      Schib schib;
      int ssid;
@@ -495,10 +495,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 +506,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);

pc-bios/s390-ccw/netmain.c void netmain(void) · line 537

Quoted 7 lines
pc-bios/s390-ccw/netmain.c +2 -1
@@ -528,5 +532,6 @@ void netmain(void)
          jump_to_low_kernel();
      }
 
-    panic("Failed to load OS from network.");
+    puts("Failed to load OS from network.");
+    return 1;
  }

I'd maybe also change the netmain() function to return -1 in case of errors.

Anyway:

#16 lore raw

PATCH v4 12/19 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          | 32 +++++++++-------
 pc-bios/s390-ccw/virtio-blkdev.c |  4 +-
 pc-bios/s390-ccw/virtio.c        | 65 +++++++++++++++++++++-----------
 8 files changed, 109 insertions(+), 57 deletions(-)
pc-bios/s390-ccw/s390-ccw.h +1 -1
index 344ad15655..6cdce3e5e5 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 7b09a38c96..5d543da73f 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 0826c16787..68fae4447f 100644
@@ -34,7 +34,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();
@@ -69,7 +69,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 +18 -14
index ed72f87962..6674a2a2b3 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("Unsupported 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\n", cutype);
-        panic("\nBoot failed.\n");
     }
 }
 
@@ -301,12 +306,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 +2 -2
index 1c585f034b..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,
pc-bios/s390-ccw/virtio.c +44 -21

114 lines not on this page · raw message

Signature · 1 line
2.45.1
#17 lore raw

PATCH v4 13/19 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     |  83 ++----------------------
 pc-bios/s390-ccw/Makefile   |   2 +-
 4 files changed, 129 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 +4 -79

90 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
#18 lore raw

PATCH v4 14/19 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 529e53f308..fe03f716f3 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 6674a2a2b3..9770290958 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
#19 lore raw

PATCH v4 15/19 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              | 123 ++++++++++++++++++++++++++++--------
 3 files changed, 99 insertions(+), 29 deletions(-)
hw/s390x/ipl.h +1 -0
index b670bad551..54eb48fd6e 100644
@@ -20,6 +20,7 @@
 #include "qom/object.h"
 
 #define DIAG308_FLAGS_LP_VALID 0x80
+#define MAX_BOOT_DEVS 8 /* Max number of devices that may have a bootindex */
 
 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 0ef04af027..e56b181298 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 +95 -28

189 lines not on this page · raw message

Signature · 1 line
2.45.1
#20 lore raw

PATCH v4 16/19 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              | 75 +++++++------------------------------
 pc-bios/s390-ccw/jump2ipl.c | 11 ++++--
 target/s390x/diag.c         |  9 ++++-
 5 files changed, 39 insertions(+), 70 deletions(-)
hw/s390x/ipl.h +8 -3
index 54eb48fd6e..aead1d6ae5 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 e56b181298..451f3b1684 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 +13 -62

118 lines not on this page · raw message

pc-bios/s390-ccw/jump2ipl.c +8 -3
index 68fae4447f..4bc9ba4f04 100644
@@ -40,10 +40,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
Acked-by on v4 16/19
#21 lore raw

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

Quoted 45 lines · On 17/10/2024 03.47, [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.

---
  hw/s390x/ipl.h              | 11 ++++--
  include/hw/s390x/ipl/qipl.h |  3 +-
  hw/s390x/ipl.c              | 75 +++++++------------------------------
  pc-bios/s390-ccw/jump2ipl.c | 11 ++++--
  target/s390x/diag.c         |  9 ++++-
  5 files changed, 39 insertions(+), 70 deletions(-)
hw/s390x/ipl.h +3 -1
index 54eb48fd6e..aead1d6ae5 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)

hw/s390x/ipl.h static inline bool iplb_valid_pv(IplParameterBlock *iplb) · line 183

Quoted 10 lines
hw/s390x/ipl.h +4 -2
  {
+    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);

Style inconsistency: In the FCP case, you did the return statement without parentheses, so I'd suggest to remove them here, too.

Quoted 41 lines
hw/s390x/ipl.h +1 -0
+    case S390_IPL_TYPE_QEMU_SCSI:
      default:
          return false;
      }
include/hw/s390x/ipl/qipl.h +2 -1
index e56b181298..451f3b1684 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 +0 -4
index aec79f41a8..50fde05b67 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 507

Quoted 4 lines
hw/s390x/ipl.c +1 -0
@@ -508,6 +504,17 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)
      return false;
  }
 
+

Remove the additonal empty line, please.

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

Quoted 9 lines
hw/s390x/ipl.c +9 -0
+void s390_rebuild_iplb(uint16_t dev_index, IplParameterBlock *iplb)
+{
+    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;
+}

With the nits fixed:

Thomas

#22 lore raw

PATCH v4 17/19 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     | 43 +++++++++++++++++++++++--------------
 pc-bios/s390-ccw/netmain.c  |  2 +-
 4 files changed, 55 insertions(+), 20 deletions(-)
pc-bios/s390-ccw/iplb.h +23 -0
index 81ff9d4497..08f259ff31 100644
@@ -17,6 +17,7 @@
 #endif
 
 #include <qipl.h>
+#include <string.h>
 
 extern QemuIplParameters qipl;
 extern IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));
@@ -50,4 +51,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 4bc9ba4f04..6aa44ccd05 100644
@@ -46,9 +46,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 (have_iplb && !set_iplb(&iplb)) {
+        panic("Failed to set IPLB");
     }
 
     /*
pc-bios/s390-ccw/main.c +27 -16

97 lines not on this page · raw message

pc-bios/s390-ccw/netmain.c +1 -1
index 0bb359e09f..d8cf3a0ef3 100644
@@ -478,7 +478,7 @@ static bool virtio_setup(void)
      */
     enable_mss_facility();
 
-    if (store_iplb(&iplb)) {
+    if (have_iplb || store_iplb(&iplb)) {
         IPL_assert(iplb.pbt == S390_IPL_TYPE_CCW, "IPL_TYPE_CCW expected");
         dev_no = iplb.ccw.devno;
         debug_print_int("device no. ", dev_no);
Signature · 1 line
2.45.1
#23 lore raw

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

Quoted 9 lines · On 17/10/2024 03.47, [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 18 lines
pc-bios/s390-ccw/main.c +6 -0
index 9770290958..da3394de7c 100644
@@ -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 fishy ... should it be a single "&" ?

Thomas

#24 lore raw

PATCH v4 18/19 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..988f7b3beb 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 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
#25 lore raw

PATCH v4 19/19 tests/qtest: Add s390x boot order tests to cdrom-test.c

In reply to [email protected]

From: Jared Rossi <[email protected]>

Add two new qtests to verify that a valid IPL device can successfully boot after failed IPL attempts from one or more invalid devices.

cdrom-test/as-fallback-device: Defines the primary boot target as a device that is invalid for IPL and a second boot target that is valid for IPL. Ensures that the valid device will be selected after the initial failed IPL.

cdrom-test/as-last-option: Defines the maximum number of boot devices (8) where only the final entry in the boot order is valid. Ensures that a valid device will be selected even after multiple failed IPL attempts from both virtio-blk and virtio-scsi device types.

---
 tests/qtest/cdrom-test.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
tests/qtest/cdrom-test.c +24 -0
index 9d72b24e4b..c86725a511 100644
@@ -213,6 +213,30 @@ static void add_s390x_tests(void)
                         "-drive driver=null-co,read-zeroes=on,if=none,id=d1 "
                         "-device virtio-blk,drive=d2,bootindex=1 "
                         "-drive if=none,id=d2,media=cdrom,file=", test_cdboot);
+    qtest_add_data_func("cdrom/boot/as-fallback-device",
+                        "-device virtio-serial -device virtio-scsi "
+                        "-device virtio-blk,drive=d1,bootindex=1 "
+                        "-drive driver=null-co,read-zeroes=on,if=none,id=d1 "
+                        "-device virtio-blk,drive=d2,bootindex=2 "
+                        "-drive if=none,id=d2,media=cdrom,file=", test_cdboot);
+    qtest_add_data_func("cdrom/boot/as-last-option",
+                        "-device virtio-serial -device virtio-scsi "
+                        "-device virtio-blk,drive=d1,bootindex=1 "
+                        "-drive driver=null-co,read-zeroes=on,if=none,id=d1 "
+                        "-device virtio-blk,drive=d2,bootindex=2 "
+                        "-drive driver=null-co,read-zeroes=on,if=none,id=d2 "
+                        "-device virtio-blk,drive=d3,bootindex=3 "
+                        "-drive driver=null-co,read-zeroes=on,if=none,id=d3 "
+                        "-device scsi-hd,drive=d4,bootindex=4 "
+                        "-drive driver=null-co,read-zeroes=on,if=none,id=d4 "
+                        "-device scsi-hd,drive=d5,bootindex=5 "
+                        "-drive driver=null-co,read-zeroes=on,if=none,id=d5 "
+                        "-device virtio-blk,drive=d6,bootindex=6 "
+                        "-drive driver=null-co,read-zeroes=on,if=none,id=d6 "
+                        "-device scsi-hd,drive=d7,bootindex=7 "
+                        "-drive driver=null-co,read-zeroes=on,if=none,id=d7 "
+                        "-device scsi-cd,drive=d8,bootindex=8 "
+                        "-drive if=none,id=d8,media=cdrom,file=", test_cdboot);
     if (qtest_has_device("x-terminal3270")) {
         qtest_add_data_func("cdrom/boot/without-bootindex",
                             "-device virtio-scsi -device virtio-serial "
Signature · 1 line
2.45.1
Reviewed-by on v4 19/19
#26 lore raw

Re: [PATCH v4 19/19] tests/qtest: Add s390x boot order tests to cdrom-test.c

Quoted 9 lines · On 17/10/2024 03.47, [email protected] wrote:

From: Jared Rossi <[email protected]>

Add two new qtests to verify that a valid IPL device can successfully boot after failed IPL attempts from one or more invalid devices.

cdrom-test/as-fallback-device: Defines the primary boot target as a device that is invalid for IPL and a second boot target that is valid for IPL. Ensures that the valid device will be selected after the initial failed IPL.

Quoted 7 lines

cdrom-test/as-last-option: Defines the maximum number of boot devices (8) where only the final entry in the boot order is valid. Ensures that a valid device will be selected even after multiple failed IPL attempts from both virtio-blk and virtio-scsi device types.

---