s390x: Add Full Boot Order Support
v3 cover s390x: Add Full Boot Order Support
From: Jared Rossi <[email protected]>
Version 3 fixes ISO IPL and restores the ability to probe for boot devices when no primary b0ot device has been specified.
Two automated qtests are added, one that tests a cdrom device as the only fallback device after the primary boot target fails and one that that defines the seven failing devices before one that succeeds.
Note: Although the qtest with multiple invalid IPL devices passes, it may generate a log message about zero sized buffers. This message does not appear to be directly related to the IPLB chaining or loading process, and it also does not appear to cause any unexpected behavior during IPL. The log message seems to be triggered when multiple virtio-scsi devices fail to IPL in succession, but the exact cause is still unclear.
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
Changes v1 -> v2:
- Use the libc from SLOF and replace sclp_print calls with put/printf
- Merge netboot into the main s390-ccw.img
- Rework pc-bios to return on error instead of panic
- Handle non-archetected IPLB types (QEMU SCSI) from DIAG308
- Remove code jumps and instead restart the IPL using a traditional loop
Jared Rossi (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 | 19 +- pc-bios/s390-ccw/cio.h | 2 + pc-bios/s390-ccw/dasd-ipl.h | 2 +- pc-bios/s390-ccw/iplb.h | 107 ++------ pc-bios/s390-ccw/libc.h | 89 ------ pc-bios/s390-ccw/s390-ccw.h | 37 +-- 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 | 442 ++++++++++++++++++++---------- 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 | 100 ++++--- pc-bios/s390-ccw/menu.c | 51 ++-- pc-bios/s390-ccw/netmain.c | 39 ++- 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 | 165 +++++++---- 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, 1150 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
PATCH v3 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
@@ -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
PATCH v3 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
@@ -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
@@ -336,9 +336,7 @@ static inline void print_volser(const void *volser)ebcdic_to_ascii ((char *)volser, ascii,6 ); ascii[6 ] ='\0' ; -sclp_print ("VOLSER=[" ); -sclp_print (ascii); -sclp_print ("]\n" ); +printf ("VOLSER=[%s]" , ascii); }static inline bool unused_space (const void *p,size_t size)
pc-bios/s390-ccw/libc.h deleted +0 -89
89 lines not on this page · raw message
pc-bios/s390-ccw/s390-ccw.h +9 -21
@@ -13,6 +13,11 @@/* #define DEBUG */ +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> +typedef unsigned char u8 ;typedef unsigned short u16 ;typedef unsigned int u32 ;
@@ -26,9 +31,6 @@ typedef unsigned long long u64;#define EBUSY 2#define ENODEV 3 -#ifndef NULL -#define NULL 0 -#endif #ifndef MIN #define MIN (a, b) (((a) < (b)) ? (a) : (b))#endif
@@ -87,7 +89,7 @@ bool menu_is_enabled_enum(void); __attribute__ ((__noreturn__))static inline void panic (const char *string) { -sclp_print (string); +printf ("ERROR: %s\n " , string);disabled_wait (); }
@@ -109,20 +111,10 @@ static inline void fill_hex_val(char *out, void *ptr, unsigned size) } } -static inline void print_int (const char *desc,u64 addr) -{ -char out[] =": 0xffffffffffffffff\n" ; - -fill_hex_val (&out[4 ], &addr,sizeof (addr)); - -sclp_print (desc); -sclp_print (out); -} -static inline void debug_print_int (const char *desc,u64 addr) {#ifdef DEBUG -print_int (desc, addr); +printf ("%s 0x%X" , desc, addr);#endif }
@@ -147,18 +139,14 @@ static inline void debug_print_addr(const char *desc, void *p)static inline void IPL_assert (bool term,const char *message) {if (!term) { -sclp_print ("\n! " ); -sclp_print (message); -panic (" !\n" );/* no return */ +panic (message);/* no return */ } }static inline void IPL_check (bool term,const char *message) {if (!term) { -sclp_print ("\n! WARNING: " ); -sclp_print (message); -sclp_print (" !\n" ); +printf ("WARNING: %s\n" , message); } }
pc-bios/s390-ccw/bootmap.c +24 -23
160 lines not on this page · raw message
pc-bios/s390-ccw/cio.c +36 -42
152 lines not on this page · raw message
pc-bios/s390-ccw/dasd-ipl.c +3 -2
@@ -8,7 +8,8 @@* directory. */ -#include "libc.h" +#include <string.h> +#include <stdio.h> #include "s390-ccw.h" #include "s390-arch.h" #include "dasd-ipl.h"
@@ -82,7 +83,7 @@ static int run_dynamic_ccw_program(SubChannelId schid, uint16_t cutype, do { has_next = dynamic_cp_fixup(cpa, &next_cpa); - print_int("executing ccw chain at ", cpa); + printf("executing ccw chain at 0x%X", cpa); enable_prefixing(); rc = do_cio(schid, cutype, cpa, CCW_FMT0); disable_prefixing();
pc-bios/s390-ccw/jump2ipl.c +3 -2
@@ -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
@@ -8,7 +8,9 @@* directory. */ -#include "libc.h" +#include <stdlib.h> +#include <string.h> +#include <stdio.h> #include "helper.h" #include "s390-arch.h" #include "s390-ccw.h"
@@ -50,7 +52,7 @@ void write_iplb_location(void)unsigned int get_loadparm_index (void ) { -return atoui (loadparm_str); +return atoi (loadparm_str); }static int is_dev_possibly_bootable (int dev_no,int sch_no)
@@ -176,7 +178,7 @@ static void boot_setup(void)sclp_get_loadparm_ascii (loadparm_str);memcpy (lpmsg +10 , loadparm_str,8 ); -sclp_print (lpmsg); +puts (lpmsg);/* * Clear out any potential S390EP magic (see jump_to_low_kernel()),
@@ -228,7 +230,7 @@ static int virtio_setup(void)switch (vdev->senseid.cu_model) {case VIRTIO_ID_NET : -sclp_print ("Network boot device detected\n" ); +puts ("Network boot device detected" ); vdev->netboot_start_addr = qipl.netboot_start_addr;return 0 ;case VIRTIO_ID_BLOCK :
@@ -261,7 +263,7 @@ static void ipl_boot_device(void) }break ;default : -print_int ("Attempting to boot from unexpected device type" , cutype); +printf ("Attempting to boot from unexpected device type 0x%X" , cutype);panic ("\nBoot failed.\n" ); } }
@@ -287,7 +289,7 @@ static void probe_boot_device(void) } } -sclp_print ("Could not find a suitable boot device (none specified)\n" ); +puts ("Could not find a suitable boot device (none specified)" ); }void main (void )
pc-bios/s390-ccw/menu.c +23 -28
134 lines not on this page · raw message
pc-bios/s390-ccw/netmain.c +5 -5
@@ -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
@@ -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
@@ -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_listreturn -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
@@ -9,7 +9,8 @@* directory. */ -#include "libc.h" +#include <string.h> +#include <stdio.h> #include "s390-ccw.h" #include "virtio.h" #include "scsi.h"
@@ -30,9 +31,9 @@ static inline void vs_assert(bool term, const char **msgs)if (!term) {int i =0 ; -sclp_print ("\n! " ); +printf ("\n! " );while (msgs[i]) { -sclp_print (msgs[i++]); +printf ("%s" , msgs[i++]); }panic (" !\n" ); }
@@ -236,11 +237,11 @@ static int virtio_scsi_locate_device(VDev *vdev)if (resp.response ==VIRTIO_SCSI_S_BAD_TARGET ) {continue ; } -print_int ("target" , target); +printf ("target 0x%X" , target);virtio_scsi_verify_response (&resp,"SCSI cannot report LUNs" ); }if (r->lun_list_len ==0 ) { -print_int ("no LUNs for target" , target); +printf ("no LUNs for target 0x%X" , target);continue ; } luns = r->lun_list_len /8 ;
@@ -264,7 +265,7 @@ static int virtio_scsi_locate_device(VDev *vdev) } } -sclp_print ("Warning: Could not locate a usable virtio-scsi device\n" ); +puts ("Warning: Could not locate a usable virtio-scsi device" );return -ENODEV ; }
@@ -379,7 +380,7 @@ static int virtio_scsi_setup(VDev *vdev) }if (virtio_scsi_inquiry_response_is_cdrom (scsi_inquiry_std_response)) { -sclp_print ("SCSI CD-ROM detected.\n" ); +puts ("SCSI CD-ROM detected." ); vdev->is_cdrom = true; vdev->scsi_block_size =VIRTIO_ISO_BLOCK_SIZE ; }
@@ -443,7 +444,7 @@ int virtio_scsi_setup_device(SubChannelId schid)IPL_assert (vdev->config.scsi.cdb_size ==VIRTIO_SCSI_CDB_SIZE ,"Config: CDB size mismatch" ); -sclp_print ("Using virtio-scsi.\n" ); +puts ("Using virtio-scsi." );return virtio_scsi_setup (vdev); }
pc-bios/s390-ccw/virtio.c +1 -1
@@ -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
@@ -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
PATCH v3 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -41,7 +41,6 @@#define DEFAULT_TFTP_RETRIES 20extern 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
@@ -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
PATCH v3 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
@@ -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
@@ -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
@@ -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
PATCH v3 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
@@ -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
Signature · 1 line
2.45.1
PATCH v3 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
@@ -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
PATCH v3 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 | 78 ++++++++++++++++++++++++------------- 3 files changed, 59 insertions(+), 35 deletions(-)
pc-bios/s390-ccw/bootmap.h +6 -9
@@ -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
@@ -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 +52 -26
159 lines not on this page · raw message
Signature · 1 line
2.45.1
Re: [PATCH v3 07/19] pc-bios/s390-ccw: Remove panics from ISO IPL path
Quoted 9 lines · On 08/10/2024 03.15, [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.
Signed-off-by Jared Rossi <[email protected]>---
...
Quoted 18 lines
pc-bios/s390-ccw/bootmap.c +4
-2@@ -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 );
pc-bios/s390-ccw/bootmap.c static inline uint32_t iso_get_file_size(uint32_t load_rba) · line 707
Quoted 9 lines
pc-bios/s390-ccw/bootmap.c +4
-2@@ -699,21 +701,28 @@ static inline uint32_t iso_get_file_size(uint32_t load_rba)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 ; + }
iso_get_file_size() seems to return an uint32_t value, so returning a negative error code won't work here. I think you either have to change the return type to signed "long" and fix the caller site, too, or return 0 for errors here?
Thomas
Re: [PATCH v3 07/19] pc-bios/s390-ccw: Remove panics from ISO IPL path
Quoted 41 lines · Thomas Huth
Quoted 9 lines · On 08/10/2024 03.15, [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.
Signed-off-by Jared Rossi <[email protected]>---
...
Quoted 18 lines
pc-bios/s390-ccw/bootmap.c +4
-2@@ -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);pc-bios/s390-ccw/bootmap.c static inline uint32_t · line 708
Quoted 9 lines
pc-bios/s390-ccw/bootmap.c +4
-1@@ -699,21 +701,28 @@ static inline uint32_t iso_get_file_size(uint32_t load_rba) 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; + }
iso_get_file_size()seems to return anuint32_tvalue, so returning a negative error code won't work here. I think you either have to change the return type to signed "long" and fix the caller site, too, or return 0 for errors here?
Quoted 2 lines
Thomas
Fixed by using "long" as suggested. Also found and fixed an error with real_size < 0 not being handled correctly in a later part of the code that used "if (real_size)"
Jared
PATCH v3 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/s390-ccw.h | 1 + pc-bios/s390-ccw/bootmap.c | 183 ++++++++++++++++++++++++------------ 2 files changed, 126 insertions(+), 58 deletions(-)
pc-bios/s390-ccw/s390-ccw.h +1 -0
@@ -31,6 +31,7 @@ typedef unsigned long long u64;#define EBUSY 2#define ENODEV 3#define EINVAL 4 +#define ENOENT 5#ifndef MIN #define MIN (a, b) (((a) < (b)) ? (a) : (b))
pc-bios/s390-ccw/bootmap.c +125 -58
401 lines not on this page · raw message
Signature · 1 line
2.45.1
Re: [PATCH v3 08/19] pc-bios/s390-ccw: Remove panics from ECKD IPL path
Quoted 30 lines · On 08/10/2024 03.15, [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.
Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/s390-ccw.h | 1 + pc-bios/s390-ccw/bootmap.c | 183 ++++++++++++++++++++++++------------ 2 files changed, 126 insertions(+), 58 deletions(-)pc-bios/s390-ccw/s390-ccw.h +1
-0@@ -31,6 +31,7 @@ typedef unsigned long long u64;#define EBUSY 2#define ENODEV 3#define EINVAL 4 +#define ENOENT 5#ifndef MIN #define MIN (a, b) (((a) < (b)) ? (a) : (b))pc-bios/s390-ccw/bootmap.c +0
-0
pc-bios/s390-ccw/bootmap.c static block_number_t load_eckd_segments(block_number_t blk, bool ldipl, · line 151
Quoted 8 lines
pc-bios/s390-ccw/bootmap.c +4
-1@@ -145,14 +145,17 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,bool more_data;memset (_bprs,FREE_SPACE_FILLER ,sizeof (_bprs)); -read_block (blk, bprs,"BPRS read failed" ); +if (virtio_read (blk, bprs)) { +puts ("BPRS read failed" ); +return -EIO ; + }
load_eckd_segments() returns a value of type block_number_t which is an unsigned type, so returning a negative error value will likely not work as expected...
...
pc-bios/s390-ccw/bootmap.c static void run_eckd_boot_script(block_number_t bmt_block_nr, · line 355
Quoted 6 lines
pc-bios/s390-ccw/bootmap.c +1
-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 >=0 );
... for example here: block_nr is also of type block_number_t, so the while condition is also true for "negative" error codes.
pc-bios/s390-ccw/bootmap.c static void run_eckd_boot_script(block_number_t bmt_block_nr, · line 357
Quoted 1 line
pc-bios/s390-ccw/bootmap.c +1
-0+if (block_nr != -ENOENT && block_nr <0 ) {
"block_nr < 0" likely also always evaluates to "false".
Quoted 20 lines
pc-bios/s390-ccw/bootmap.c +8
-3+return ldipl ?0 : -EIO ; + } }if (ldipl && bms->entry[i].type !=BOOT_SCRIPT_EXEC ) {/* Abort LD-IPL and retry as CCW-IPL */ -return ; +return 0 ; } -IPL_assert (bms->entry[i].type ==BOOT_SCRIPT_EXEC , -"Unknown script entry type" ); +if (bms->entry[i].type !=BOOT_SCRIPT_EXEC ) { +puts ("Unknown script entry type" ); +return -EINVAL ; + }write_reset_psw (bms->entry[i].address.load_address);/* no return */ jump_to_IPL_code (0 );/* no return */ +return 1 ; }
...
pc-bios/s390-ccw/bootmap.c static block_number_t eckd_find_bmt(ExtEckdBlockPtr *ptr) · line 495
Quoted 8 lines
pc-bios/s390-ccw/bootmap.c +3
-1@@ -441,11 +490,14 @@ static block_number_t eckd_find_bmt(ExtEckdBlockPtr *ptr)BootRecord *br; blockno =gen_eckd_block_num (ptr,0 ); -read_block (blockno, tmp_sec,"Cannot read boot record" ); +if (virtio_read (blockno, tmp_sec)) { +puts ("Cannot read boot record" ); +return -EIO ;
Same problem here: Returning a negative error code via unsigned block_number_t ....
...
pc-bios/s390-ccw/bootmap.c static void ipl_eckd(void) · line 546
Quoted 3 lines
pc-bios/s390-ccw/bootmap.c +0
-0@@ -490,34 +545,46 @@ static void ipl_eckd(void) ldipl_bmt =eckd_find_bmt ((ExtEckdBlockPtr *)&vlbl->f.br);if (ldipl_bmt) {
... will cause trouble here.
Quoted 41 lines
pc-bios/s390-ccw/bootmap.c +17
-8puts ("List-Directed" ); -/* LD-IPL does not use the S1B bock, just make it NULL */ -run_eckd_boot_script (ldipl_bmt,NULL_BLOCK_NR ); -/* Only return in error, retry as CCW-IPL */ +/* +* LD-IPL does not use the S1B bock, just make it NULL_BLOCK_NR. +* In some failure cases retry IPL before aborting. +*/ +if (run_eckd_boot_script (ldipl_bmt,NULL_BLOCK_NR )) { +return -EIO ; + } +/* Non-fatal error, retry as CCW-IPL */ printf ("Retrying IPL " );print_eckd_msg (); }memset (sec,FREE_SPACE_FILLER ,sizeof (sec)); -read_block (2 , vtoc,"Cannot read block 2" ); +if (virtio_read (2 , vtoc)) { +puts ("Cannot read block 2" ); +return -EIO ; + } }/* Not list-directed */ if (magic_match (vtoc->magic,VOL1_MAGIC )) { -ipl_eckd_cdl ();/* may return in error */ +if (ipl_eckd_cdl ()) { +return 1 ; + } }if (magic_match (vtoc->magic,CMS1_MAGIC )) { -ipl_eckd_ldl (ECKD_CMS );/* no return */ +return ipl_eckd_ldl (ECKD_CMS ); }if (magic_match (vtoc->magic,LNX1_MAGIC )) { -ipl_eckd_ldl (ECKD_LDL );/* no return */ +return ipl_eckd_ldl (ECKD_LDL ); } -ipl_eckd_ldl (ECKD_LDL_UNLABELED );/* it still may return */
pc-bios/s390-ccw/bootmap.c static void ipl_eckd(void) · line 588
Quoted 10 lines
pc-bios/s390-ccw/bootmap.c +4
-1+if (ipl_eckd_ldl (ECKD_LDL_UNLABELED )) { +return 1 ; + }/* * Ok, it is not a LDL by any means. * It still might be a CDL with zero record keys for IPL1 and IPL2 */ -ipl_eckd_cdl (); +return ipl_eckd_cdl (); }
Thomas
Re: [PATCH v3 08/19] pc-bios/s390-ccw: Remove panics from ECKD IPL path
Quoted 5 lines · Thomas Huth
Quoted 1 line · On 08/10/2024 03.15, [email protected] wrote:
[snip...]
load_eckd_segments()returns a value of typeblock_number_twhich is an unsigned type, so returning a negative error value will likely not work as expected...
Quoted 8 lines
...
Quoted 6 lines
pc-bios/s390-ccw/bootmap.c +1
-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 >= 0);[snip...]
There already exists a special block number defined in bootmap.h, NULL_BLOCK_NR 0xffffffffffffffffULL. Therefore I would propose simply adding another as ERROR_BLOCK_NR 0xfffffffffffffffeULL.
ERROR_BLOCK_NR would replace the negative error codes and NULL_BLOCK_NR would represent expected end of chunk. Does this seem reasonable?
Jared
Re: [PATCH v3 08/19] pc-bios/s390-ccw: Remove panics from ECKD IPL path
Quoted 17 lines · Jared Rossi
Quoted 5 lines · Thomas Huth
Quoted 1 line · On 08/10/2024 03.15, [email protected] wrote:
[snip...]
load_eckd_segments()returns a value of typeblock_number_twhich is an unsigned type, so returning a negative error value will likely not work as expected...Quoted 8 lines
...
Quoted 6 lines
pc-bios/s390-ccw/bootmap.c +1
-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 >= 0);[snip...]
Quoted 3 lines
There already exists a special block number defined in
bootmap.h,NULL_BLOCK_NR0xffffffffffffffffULL. Therefore I would propose simply adding another asERROR_BLOCK_NR0xfffffffffffffffeULL.
ERROR_BLOCK_NRwould replace the negative error codes andNULL_BLOCK_NRwould represent expected end of chunk. Does this seem reasonable?
Sounds like a good idea.
Alternatively, you could do casting to signed long here and there, but that's ugly, too.
Thomas
PATCH v3 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/bootmap.c | 88 +++++++++++++----- pc-bios/s390-ccw/jump2ipl.c | 1 + pc-bios/s390-ccw/virtio-blkdev.c | 4 +- pc-bios/s390-ccw/virtio-scsi.c | 148 +++++++++++++++++++++---------- 4 files changed, 169 insertions(+), 72 deletions(-)
pc-bios/s390-ccw/bootmap.c +66 -22
@@ -591,7 +591,7 @@ static int ipl_eckd(void)* IPL a SCSI disk */ -static void zipl_load_segment (ComponentEntry *entry) +static int zipl_load_segment (ComponentEntry *entry) {const int max_entries = (MAX_SECTOR_SIZE /sizeof (ScsiBlockPtr));ScsiBlockPtr *bprs = (void *)sec;
@@ -611,7 +611,10 @@ static void zipl_load_segment(ComponentEntry *entry) do { memset(bprs, FREE_SPACE_FILLER, bprs_size); fill_hex_val(blk_no, &blockno, sizeof(blockno)); - read_block(blockno, bprs, err_msg); + if (virtio_read(blockno, bprs)) { + puts(err_msg); + return -EIO; + } for (i = 0;; i++) { uint64_t *cur_desc = (void *)&bprs[i];
@@ -639,23 +642,37 @@ static void zipl_load_segment(ComponentEntry *entry) } address =virtio_load_direct (cur_desc[0 ], cur_desc[1 ],0 , (void *)address); -IPL_assert (address !=-1 ,"zIPL load segment failed" ); +if (!address) { +puts ("zIPL load segment failed" ); +return -EIO ; + } } }while (blockno); + +return 0 ; }/* Run a zipl program */ -static void zipl_run (ScsiBlockPtr *pte) +static int zipl_run (ScsiBlockPtr *pte) {ComponentHeader *header;ComponentEntry *entry;uint8_t tmp_sec[MAX_SECTOR_SIZE ]; -read_block (pte->blockno, tmp_sec,"Cannot read header" ); +if (virtio_read (pte->blockno, tmp_sec)) { +puts ("Cannot read header" ); +return -EIO ; + } header = (ComponentHeader *)tmp_sec; -IPL_assert (magic_match (tmp_sec,ZIPL_MAGIC ),"No zIPL magic in header" ); -IPL_assert (header->type ==ZIPL_COMP_HEADER_IPL ,"Bad header type" ); +if (!magic_match (tmp_sec,ZIPL_MAGIC )) { +puts ("No zIPL magic in header" ); +return -EINVAL ; + } +if (header->type !=ZIPL_COMP_HEADER_IPL ) { +puts ("Bad header type" ); +return -EINVAL ; + }dputs ("start loading images\n" );
@@ -670,22 +687,30 @@ static void zipl_run(ScsiBlockPtr *pte)continue ; } -zipl_load_segment (entry); +if (zipl_load_segment (entry)) { +return 1 ; + } entry++; -IPL_assert ((uint8_t *)(&entry[1 ]) <= (tmp_sec +MAX_SECTOR_SIZE ), -"Wrong entry value" ); +if ((uint8_t *)(&entry[1 ]) > (tmp_sec +MAX_SECTOR_SIZE )) { +puts ("Wrong entry value" ); +return -EINVAL ; + } } -IPL_assert (entry->component_type ==ZIPL_COMP_ENTRY_EXEC ,"No EXEC entry" ); +if (entry->component_type !=ZIPL_COMP_ENTRY_EXEC ) { +puts ("No EXEC entry" ); +return -EINVAL ; + }/* should not return */ write_reset_psw (entry->compdat.load_psw);jump_to_IPL_code (0 ); +return 1 ; } -static void ipl_scsi (void ) +static int ipl_scsi (void ) {ScsiMbr *mbr = (void *)sec;int program_table_entries =0 ;
@@ -696,10 +721,13 @@ static void ipl_scsi(void)/* Grab the MBR */ memset (sec,FREE_SPACE_FILLER ,sizeof (sec)); -read_block (0 , mbr,"Cannot read block 0" ); +if (virtio_read (0 , mbr)) { +puts ("Cannot read block 0" ); +return -EIO ; + }if (!magic_match (mbr->magic,ZIPL_MAGIC )) { -return ; +return 0 ; }puts ("Using SCSI scheme." );
@@ -707,11 +735,20 @@ static void ipl_scsi(void)IPL_check (mbr->version_id ==1 ,"Unknown MBR layout version, assuming version 1" );debug_print_int ("program table" , mbr->pt.blockno); -IPL_assert (mbr->pt.blockno,"No Program Table" ); +if (!mbr->pt.blockno) { +puts ("No Program Table" ); +return -EINVAL ; + }/* Parse the program table */ -read_block (mbr->pt.blockno, sec,"Error reading Program Table" ); -IPL_assert (magic_match (sec,ZIPL_MAGIC ),"No zIPL magic in PT" ); +if (virtio_read (mbr->pt.blockno, sec)) { +puts ("Error reading Program Table" ); +return -EIO ; + } +if (!magic_match (sec,ZIPL_MAGIC )) { +puts ("No zIPL magic in Program Table" ); +return -EINVAL ; + }for (i =0 ; i <MAX_BOOT_ENTRIES ; i++) {if (prog_table->entry[i].scsi.blockno) {
@@ -721,17 +758,22 @@ static void ipl_scsi(void) }debug_print_int ("program table entries" , program_table_entries); -IPL_assert (program_table_entries !=0 ,"Empty Program Table" ); +if (program_table_entries ==0 ) { +puts ("Empty Program Table" ); +return -EINVAL ; + }if (menu_is_enabled_enum ()) { loadparm =menu_get_enum_boot_index (valid_entries); }debug_print_int ("loadparm" , loadparm); -IPL_assert (loadparm <MAX_BOOT_ENTRIES ,"loadparm value greater than" -" maximum number of boot entries allowed" ); +if (loadparm >=MAX_BOOT_ENTRIES ) { +puts ("loadparm value greater than max number of boot entries allowed" ); +return -EINVAL ; + } -zipl_run (&prog_table->entry[loadparm].scsi);/* no return */ +return zipl_run (&prog_table->entry[loadparm].scsi); }/***********************************************************************
@@ -1025,7 +1067,9 @@ void zipl_load(void)netmain (); } -ipl_scsi (); +if (ipl_scsi ()) { +panic ("\n! Cannot IPL this SCSI device !\n" ); + }switch (virtio_get_device_type ()) {case VIRTIO_ID_BLOCK :
pc-bios/s390-ccw/jump2ipl.c +1 -0
@@ -16,6 +16,7 @@#define RESET_PSW ((uint64_t)&jump_to_IPL_addr | RESET_PSW_MASK)static uint64_t *reset_psw =0 , save_psw, ipl_continue; +extern bool have_iplb;void write_reset_psw (uint64_t psw) {
pc-bios/s390-ccw/virtio-blkdev.c +2 -2
@@ -73,13 +73,13 @@ unsigned long virtio_load_direct(unsigned long rec_list1, unsigned long rec_listunsigned 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 -48
307 lines not on this page · raw message
Signature · 1 line
2.45.1
Re: [PATCH v3 09/19] pc-bios/s390-ccw: Remove panics from SCSI IPL path
Quoted 9 lines · On 08/10/2024 03.15, [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.
Signed-off-by Jared Rossi <[email protected]>---
...
Quoted 15 lines
pc-bios/s390-ccw/virtio-scsi.c +5
-3@@ -78,24 +84,30 @@ static void prepare_request(VDev *vdev, const void *cdb, int cdb_size, } } -static inline void vs_io_assert (bool term,const char *msg) +static inline bool vs_io_assert (bool term,const char *msg) { -if (!term) { -virtio_scsi_verify_response (&resp, msg); +if (!term && !virtio_scsi_verify_response (&resp, msg)) { +return false; } + +return true; }
pc-bios/s390-ccw/virtio-scsi.c static void prepare_request(VDev *vdev, const void *cdb, int cdb_size, · line 102
Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +3
-2-static void vs_run (const char *title,VirtioCmd *cmd,VDev *vdev, +static int vs_run (const char *title,VirtioCmd *cmd,VDev *vdev,const void *cdb,int cdb_size,void *data,uint32_t data_size) {prepare_request (vdev, cdb, cdb_size, data, data_size); -vs_io_assert (virtio_run (vdev,VR_REQUEST , cmd) ==0 , title); +if (!vs_io_assert (virtio_run (vdev,VR_REQUEST , cmd) ==0 , title)) { +puts (title);
Should there be a "return" with a non-0 value here? ...
Quoted 13 lines
pc-bios/s390-ccw/virtio-scsi.c +4
-1+ } + +return 0 ; }/* SCSI protocol implementation routines */ -static bool scsi_inquiry (VDev *vdev,uint8_t evpd,uint8_t page, +static int scsi_inquiry (VDev *vdev,uint8_t evpd,uint8_t page,void *data,uint32_t data_size) {ScsiCdbInquiry cdb = {
pc-bios/s390-ccw/virtio-scsi.c static bool scsi_inquiry(VDev *vdev, uint8_t evpd, uint8_t page, · line 126
Quoted 6 lines
pc-bios/s390-ccw/virtio-scsi.c +2
-1@@ -110,12 +122,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 cc =vs_run ("inquiry" , inquiry, + vdev, &cdb,sizeof (cdb), data, data_size);
... since the caller site now obviously checks for a non-zero value!
Quoted 3 lines
pc-bios/s390-ccw/virtio-scsi.c +1
-1-return virtio_scsi_response_ok (&resp); +return cc ? cc :virtio_scsi_response_ok (&resp); }
...
Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +1
-1@@ -207,7 +221,7 @@ static int virtio_scsi_locate_device(VDev *vdev)static uint8_t data[16 +8 *63 ];ScsiLunReport *r = (void *) data;ScsiDevice *sdev = vdev->scsi_device; -int i, luns; +int i, cc, luns;/* QEMU has hardcoded channel #0 in many places. * If this hardcoded value is ever changed, we'll need to add code for
pc-bios/s390-ccw/virtio-scsi.c static int virtio_scsi_locate_device(VDev *vdev) · line 253
Quoted 8 lines
pc-bios/s390-ccw/virtio-scsi.c +4
-1@@ -233,13 +247,21 @@ static int virtio_scsi_locate_device(VDev *vdev) sdev->channel = channel; sdev->target = target; sdev->lun =0 ;/* LUN has to be 0 for REPORT LUNS */ -if (!scsi_report_luns (vdev, data,sizeof (data))) { + cc =scsi_report_luns (vdev, data,sizeof (data)); +if (cc <0 ) { +return cc; + }
By the way, calling a variable "cc" reminds me of the CC of the PSW, so I'd expect values from 0 to 3 for this variable. Obviously this was meant to convey negative error codes instead, so I'd like to suggest to rename that variable to "ret" or something similar instead.
pc-bios/s390-ccw/virtio-scsi.c static int virtio_scsi_locate_device(VDev *vdev) · line 263
Quoted 10 lines
pc-bios/s390-ccw/virtio-scsi.c +4
-1+else if (cc ==0 ) {if (resp.response ==VIRTIO_SCSI_S_BAD_TARGET ) {continue ; }printf ("target 0x%X" , target); -virtio_scsi_verify_response (&resp,"SCSI cannot report LUNs" ); +if (!virtio_scsi_verify_response (&resp,"SCSI cannot report LUNs" )) { +return -EIO ; + } }
Thomas
Re: [PATCH v3 09/19] pc-bios/s390-ccw: Remove panics from SCSI IPL path
Quoted 63 lines · Thomas Huth
Quoted 2 lines · On 08/10/2024 03.15, [email protected] wrote:
+ if (!vs_io_assert(virtio_run(vdev,
VR_REQUEST, cmd) == 0, title)) { + puts(title);Should there be a "return" with a non-0 value here? ...
Quoted 11 lines
+ }
+
+ return 0;
}
/* SCSI protocol implementation routines */
-static bool scsi_inquiry(VDev *vdev,uint8_tevpd,uint8_tpage, +static intscsi_inquiry(VDev *vdev, uint8_t evpd, uint8_t page, void *data, uint32_t data_size){
ScsiCdbInquiry cdb = {pc-bios/s390-ccw/virtio-scsi.c static bool scsi_inquiry(VDev *vdev, uint8_t · line 127
Quoted 6 lines
pc-bios/s390-ccw/virtio-scsi.c +2
-0@@ -110,12 +122,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 cc = vs_run("inquiry", inquiry, + vdev, &cdb, sizeof(cdb), data, data_size);... since the caller site now obviously checks for a non-zero value!
Quoted 3 lines
pc-bios/s390-ccw/virtio-scsi.c +1
-1- return virtio_scsi_response_ok(&resp); + return cc ? cc : virtio_scsi_response_ok(&resp); }...
Quoted 11 lines
pc-bios/s390-ccw/virtio-scsi.c +1
-1@@ -207,7 +221,7 @@ static int virtio_scsi_locate_device(VDev *vdev) static uint8_t data[16 + 8 * 63]; ScsiLunReport *r = (void *) data; ScsiDevice *sdev = vdev->scsi_device; - int i, luns; + int i, cc, luns; /* QEMU has hardcoded channel #0 in many places.* If this hardcoded value is ever changed, we'll need to add code for @@ -233,13 +247,21 @@ static int virtio_scsi_locate_device(VDev *vdev) sdev->channel = channel; sdev->target = target;Quoted 6 lines
sdev->lun= 0; /* LUN has to be 0 for REPORT LUNS */ - if (!scsi_report_luns(vdev, data, sizeof(data))) { + cc =scsi_report_luns(vdev, data, sizeof(data));
+ if (cc < 0) {
+ return cc;
+ }By the way, calling a variable "cc" reminds me of the CC of the PSW, so I'd expect values from 0 to 3 for this variable. Obviously this was meant to convey negative error codes instead, so I'd like to suggest to rename that variable to "ret" or something similar instead.
Quoted 4 lines
+ else if (cc == 0) {
if (resp.response ==VIRTIO_SCSI_S_BAD_TARGET) { continue;
}Quoted 8 lines
printf("target 0x%X", target);
-virtio_scsi_verify_response(&resp, "SCSI cannot report LUNs");
+ if (!virtio_scsi_verify_response(&resp, "SCSI cannot report LUNs")) {
+ return-EIO;
+ }
}
Quoted 2 lines
Thomas
Fixed the missing return and also changed the variable to "ret" instead of "cc" as suggested.
Jared
PATCH v3 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
@@ -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
PATCH v3 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
@@ -58,7 +58,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
@@ -1065,6 +1065,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
@@ -464,7 +464,7 @@ static bool find_net_dev(Schib *schib, int dev_no)return false; } -static void virtio_setup (void ) +static int virtio_setup (void ) {Schib schib;int ssid;
@@ -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
@@ -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
Re: [PATCH v3 11/19] pc-bios/s390-ccw: Remove panics from Netboot IPL path
Quoted 9 lines · On 08/10/2024 03.15, [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.
Signed-off-by Jared Rossi <[email protected]>---
...
pc-bios/s390-ccw/netmain.c static bool find_net_dev(Schib *schib, int dev_no) · line 467
Quoted 10 lines
pc-bios/s390-ccw/netmain.c +1
-1@@ -464,7 +464,7 @@ static bool find_net_dev(Schib *schib, int dev_no)return false; } -static void virtio_setup (void ) +static int virtio_setup (void )
Maybe better use "bool" instead of "int" here...
pc-bios/s390-ccw/netmain.c static void virtio_setup(void) · line 498
Quoted 9 lines
pc-bios/s390-ccw/netmain.c +1
-1{Schib schib;int ssid;@@ -495,10 +495,10 @@ static void virtio_setup(void) } } -IPL_assert (found,"No virtio net device found" ); +return found;
... since the function obviously returns a boolean value.
Thomas
Re: [PATCH v3 11/19] pc-bios/s390-ccw: Remove panics from Netboot IPL path
Quoted 34 lines · Thomas Huth
Quoted 9 lines · On 08/10/2024 03.15, [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.
Signed-off-by Jared Rossi <[email protected]>---
...
pc-bios/s390-ccw/netmain.c static bool find_net_dev(Schib *schib, int dev_no) · line 467
Quoted 9 lines
pc-bios/s390-ccw/netmain.c +1
-0@@ -464,7 +464,7 @@ static bool find_net_dev(Schib *schib, int dev_no) return false; } -static void virtio_setup(void) +static int virtio_setup(void)Maybe better use "bool" instead of "int" here...
pc-bios/s390-ccw/netmain.c static void virtio_setup(void) · line 498
Quoted 8 lines
pc-bios/s390-ccw/netmain.c +1
-0{ Schib schib; int ssid;@@ -495,10 +495,10 @@ static void virtio_setup(void) } } - IPL_assert(found, "No virtio net device found"); + return found;... since the function obviously returns a boolean value.
Quoted 2 lines
Thomas
Fixed, changed return type to bool.
Jared
PATCH v3 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 | 35 +++++++++-------- pc-bios/s390-ccw/virtio-blkdev.c | 4 +- pc-bios/s390-ccw/virtio.c | 65 +++++++++++++++++++++----------- 8 files changed, 111 insertions(+), 58 deletions(-)
pc-bios/s390-ccw/s390-ccw.h +1 -1
@@ -79,7 +79,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
@@ -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
@@ -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
@@ -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) asmvolatile ("lghi %%r1,1\n\t" "diag %%r1,%%r1,0x308\n\t" : : :"1" ,"memory" ); -panic ("\n! IPL returns !\n" ); +puts ("IPL code jump failed" ); +return 1 ; }void jump_to_low_kernel (void )
pc-bios/s390-ccw/main.c +20 -15
@@ -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" , cutype); -panic ("\nBoot failed.\n" ); } }
@@ -288,7 +293,8 @@ static void probe_boot_device(void)break ; }if (ret == true) { -ipl_boot_device ();/* Only returns if unsuccessful */ +ipl_boot_device ();/* Only returns if unsuccessful */ +return ; } } }
@@ -301,12 +307,11 @@ void main(void)sclp_setup ();css_setup ();boot_setup (); -if (have_iplb) { -find_boot_device (); +if (have_iplb &&find_boot_device ()) {ipl_boot_device (); }else {probe_boot_device (); } -panic ("Failed to load OS from hard disk\n" ); +panic ("Failed to IPL. Halting..." ); }
pc-bios/s390-ccw/virtio-blkdev.c +2 -2
@@ -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
Re: [PATCH v3 12/19] pc-bios/s390-ccw: Enable failed IPL to return after error
Quoted 6 lines · On 08/10/2024 03.15, [email protected] wrote:
From: Jared Rossi <[email protected]>
Remove panic-on-error from IPL functions such that a return code is propagated back to the main IPL calling function (rather than terminating immediately), which facilitates possible error recovery in the future.
Quoted 6 lines
A select few panics remain, which indicate fatal non-devices errors that must result in termination.
Signed-off-by Jared Rossi <[email protected]>---
PATCH v3 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 | 84 ++---------------------- pc-bios/s390-ccw/Makefile | 2 +- 4 files changed, 130 insertions(+), 183 deletions(-) create mode 100644 include/hw/s390x/ipl/qipl.h
hw/s390x/ipl.h +1 -103
@@ -16,95 +16,11 @@#include "cpu.h" #include "exec/address-spaces.h" #include "hw/qdev-core.h" +#include "hw/s390x/ipl/qipl.h" #include "qom/object.h" -struct IPLBlockPVComp { -uint64_t tweak_pref; -uint64_t addr; -uint64_t size; -}QEMU_PACKED ; -typedef struct IPLBlockPVComp IPLBlockPVComp ; - -struct IPLBlockPV { -uint8_t reserved18[87 ];/* 0x18 */ -uint8_t version;/* 0x6f */ -uint32_t reserved70;/* 0x70 */ -uint32_t num_comp;/* 0x74 */ -uint64_t pv_header_addr;/* 0x78 */ -uint64_t pv_header_len;/* 0x80 */ -struct IPLBlockPVComp components[0 ]; -}QEMU_PACKED ; -typedef struct IPLBlockPV IPLBlockPV ; - -struct IplBlockCcw { -uint8_t reserved0[85 ]; -uint8_t ssid; -uint16_t devno; -uint8_t vm_flags; -uint8_t reserved3[3 ]; -uint32_t vm_parm_len; -uint8_t nss_name[8 ]; -uint8_t vm_parm[64 ]; -uint8_t reserved4[8 ]; -}QEMU_PACKED ; -typedef struct IplBlockCcw IplBlockCcw ; - -struct IplBlockFcp { -uint8_t reserved1[305 -1 ]; -uint8_t opt; -uint8_t reserved2[3 ]; -uint16_t reserved3; -uint16_t devno; -uint8_t reserved4[4 ]; -uint64_t wwpn; -uint64_t lun; -uint32_t bootprog; -uint8_t reserved5[12 ]; -uint64_t br_lba; -uint32_t scp_data_len; -uint8_t reserved6[260 ]; -uint8_t scp_data[0 ]; -}QEMU_PACKED ; -typedef struct IplBlockFcp IplBlockFcp ; - -struct IplBlockQemuScsi { -uint32_t lun; -uint16_t target; -uint16_t channel; -uint8_t reserved0[77 ]; -uint8_t ssid; -uint16_t devno; -}QEMU_PACKED ; -typedef struct IplBlockQemuScsi IplBlockQemuScsi ; -#define DIAG308_FLAGS_LP_VALID 0x80 -union IplParameterBlock { -struct { -uint32_t len; -uint8_t reserved0[3 ]; -uint8_t version; -uint32_t blk0_len; -uint8_t pbt; -uint8_t flags; -uint16_t reserved01; -uint8_t loadparm[8 ]; -union { -IplBlockCcw ccw; -IplBlockFcp fcp; -IPLBlockPV pv; -IplBlockQemuScsi scsi; - }; - } QEMU_PACKED; -struct { -uint8_t reserved1[110 ]; -uint16_t devno; -uint8_t reserved2[88 ]; -uint8_t reserved_ext[4096 -200 ]; - } QEMU_PACKED; -}QEMU_PACKED ; -typedef union IplParameterBlock IplParameterBlock ; -int s390_ipl_set_loadparm (uint8_t *loadparm);void s390_ipl_update_diag308 (IplParameterBlock *iplb);int s390_ipl_prepare_pv_header (Error **errp);
@@ -131,24 +47,6 @@ void s390_ipl_clear_reset_request(void);#define QIPL_FLAG_BM_OPTS_CMD 0x80#define QIPL_FLAG_BM_OPTS_ZIPL 0x40 -/* -* The QEMU IPL Parameters will be stored at absolute address -* 204 (0xcc) which means it is 32-bit word aligned but not -* double-word aligned. Placement of 64-bit data fields in this -* area must account for their alignment needs. -* The total size of the struct must never exceed 28 bytes. -* This definition must be kept in sync with the definition -* in pc-bios/s390-ccw/iplb.h. -*/ -struct QemuIplParameters { -uint8_t qipl_flags; -uint8_t reserved1[3 ]; -uint64_t reserved2; -uint32_t boot_menu_timeout; -uint8_t reserved3[12 ]; -}QEMU_PACKED ; -typedef struct QemuIplParameters QemuIplParameters ; -#define TYPE_S390_IPL "s390-ipl"OBJECT_DECLARE_SIMPLE_TYPE (S390IPLState,S390_IPL )
include/hw/s390x/ipl/qipl.h new file +123 -0
123 lines not on this page · raw message
pc-bios/s390-ccw/iplb.h +5 -79
93 lines not on this page · raw message
pc-bios/s390-ccw/Makefile +1 -1
@@ -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
PATCH v3 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v3 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
@@ -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
@@ -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
Re: [PATCH v3 15/19] hw/s390x: Build an IPLB for each boot device
Quoted 9 lines · On 08/10/2024 03.15, [email protected] wrote:
From: Jared Rossi <[email protected]>
Build an IPLB for any device with a bootindex (up to a maximum of 8 devices).
The IPLB chain is placed immediately before the BIOS in memory. Because this is not a fixed address, the location of the next IPLB and number of remaining boot devices is stored in the QIPL global variable for possible later access by the guest during IPL.
Quoted 6 lines
Signed-off-by Jared Rossi <[email protected]>--- hw/s390x/ipl.h | 1 + include/hw/s390x/ipl/qipl.h | 4 +- hw/s390x/ipl.c | 123 ++++++++++++++++++++++++++++-------- 3 files changed, 99 insertions(+), 29 deletions(-)
PATCH v3 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v3 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 | 47 ++++++++++++++++++++++--------------- pc-bios/s390-ccw/netmain.c | 3 ++- 4 files changed, 57 insertions(+), 23 deletions(-) --- pc-bios/s390-ccw/iplb.h | 23 ++++++++++++++++++ pc-bios/s390-ccw/jump2ipl.c | 7 +++--- pc-bios/s390-ccw/main.c | 47 ++++++++++++++++++++++--------------- pc-bios/s390-ccw/netmain.c | 3 ++- 4 files changed, 57 insertions(+), 23 deletions(-)
pc-bios/s390-ccw/iplb.h +23 -0
@@ -17,6 +17,7 @@#endif #include <qipl.h> +#include <string.h> extern QemuIplParameters qipl; extern IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));
@@ -49,4 +50,26 @@ static inline bool set_iplb(IplParameterBlock *iplb) return manage_iplb(iplb, false); } +/* +* The IPL started on the device, but failed in some way. If the IPLB chain +* still has more devices left to try, use the next device in order. +*/ +static inline bool load_next_iplb (void ) +{ +IplParameterBlock *next_iplb; + +if (qipl.chain_len <1 ) { +return false; + } + + qipl.index++; + next_iplb = (IplParameterBlock *) qipl.next_iplb; +memcpy (&iplb, next_iplb,sizeof (IplParameterBlock)); + + qipl.chain_len--; + qipl.next_iplb = qipl.next_iplb +sizeof (IplParameterBlock); + +return true; +} +#endif /* IPLB_H */
pc-bios/s390-ccw/jump2ipl.c +4 -3
@@ -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 +28 -19
113 lines not on this page · raw message
pc-bios/s390-ccw/netmain.c +2 -1
@@ -41,6 +41,7 @@#define DEFAULT_TFTP_RETRIES 20extern char _start[]; +extern bool have_iplb;#define KERNEL_ADDR ((void *)0L)#define KERNEL_MAX_SIZE ((long)_start)
@@ -478,7 +479,7 @@ static int virtio_setup(void)*/ enable_mss_facility (); -if (store_iplb (&iplb)) { +if (have_iplb ||store_iplb (&iplb)) {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
Re: [PATCH v3 17/19] pc-bios/s390x: Enable multi-device boot loop
Quoted 11 lines · On 10/7/24 9:15 PM, [email protected] wrote:
[snip...]
switch (vdev->senseid.cu_model) { case VIRTIO_ID_NET: puts("Network boot device detected");pc-bios/s390-ccw/main.c +0
-2@@ -271,11 +275,9 @@ static void ipl_boot_device(void)dasd_ipl (blk_schid, cutype);break ;case CU_TYPE_VIRTIO : -if (virtio_setup ()) { -return ;/* Only returns in case of errors */
pc-bios/s390-ccw/main.c static void ipl_boot_device(void)
Quoted 10 lines
pc-bios/s390-ccw/main.c +2
-2+if (virtio_setup () ==0 ) { +zipl_load (); } -zipl_load (); -break ;default :printf ("Attempting to boot from unexpected device type 0x%X" , cutype); }
A small mistake I found after posting is that the break is missing after zipl_load(). This causes the "unexpected device type" message to print after a failed virtio IPL, but it is fixed simply by not removing the break and will be will be corrected in the next version.
PATCH v3 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
@@ -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
@@ -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
Re: [PATCH v3 18/19] docs/system: Update documentation for s390x IPL
Quoted 9 lines · On 08/10/2024 03.15, [email protected] wrote:
From: Jared Rossi <[email protected]>
Update docs to show that s390x PC BIOS can support more than one boot device.
Signed-off-by Jared Rossi <[email protected]>--- docs/system/bootindex.rst | 7 ++++--- docs/system/s390x/bootdevices.rst | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-)
PATCH v3 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
@@ -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 virtio-blk,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
Re: [PATCH v3 19/19] tests/qtest: Add s390x boot order tests to cdrom-test.c
Quoted 41 lines · On 08/10/2024 03.15, [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.
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.
Signed-off-by Jared Rossi <[email protected]>--- tests/qtest/cdrom-test.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)tests/qtest/cdrom-test.c +14
-0@@ -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 "
tests/qtest/cdrom-test.c static void add_s390x_tests(void) · line 239
Quoted 10 lines
tests/qtest/cdrom-test.c +10
-0+"-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 virtio-blk,drive=d8,bootindex=8 " + "-drive if=none,id=d8,media=cdrom,file=", test_cdboot);
Could you please use a scsi-hd for the good device here in the second test, too? ... so we make sure that the good drive detection also works with virtio-scsi devices and not only with virtio-blk devices.
Thanks,
Thomas
Re: [PATCH v3 19/19] tests/qtest: Add s390x boot order tests to cdrom-test.c
Quoted 65 lines · Thomas Huth
Quoted 53 lines · On 08/10/2024 03.15, [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.
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.
Signed-off-by Jared Rossi <[email protected]>---
tests/qtest/cdrom-test.c| 24 ++++++++++++++++++++++++1 file changed, 24 insertions(+)tests/qtest/cdrom-test.c +0
-0@@ -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 "Quoted 8 lines
+ "-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 virtio-blk,drive=d8,bootindex=8 " + "-drive if=none,id=d8,media=cdrom,file=",test_cdboot);Could you please use a scsi-hd for the good device here in the second test, too? ... so we make sure that the good drive detection also works with virtio-scsi devices and not only with virtio-blk devices.
Quoted 3 lines
Thanks,
Thomas
Do you mean use "scsi-cd" instead?
Jared
Re: [PATCH v3 19/19] tests/qtest: Add s390x boot order tests to cdrom-test.c
Quoted 68 lines · Jared Rossi
Quoted 65 lines · Thomas Huth
Quoted 53 lines · On 08/10/2024 03.15, [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.
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.
Signed-off-by Jared Rossi <[email protected]>---
tests/qtest/cdrom-test.c| 24 ++++++++++++++++++++++++1 file changed, 24 insertions(+)tests/qtest/cdrom-test.c +0
-0@@ -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 "Quoted 8 lines
+ "-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 virtio-blk,drive=d8,bootindex=8 " + "-drive if=none,id=d8,media=cdrom,file=",test_cdboot);Could you please use a scsi-hd for the good device here in the second test, too? ... so we make sure that the good drive detection also works with virtio-scsi devices and not only with virtio-blk devices.
Quoted 5 lines
Quoted 3 lines
Thanks,
ThomasDo you mean use "scsi-cd" instead?
Oh, right, sorry for the confusion!
Thomas