s390x: network boot
v2 cover s390x: network boot
v1->v2:
- style enhancements for patch 3, as suggested by Thomas
If this looks fine (and I'd still like an ack for patch 1), I'd like to get this into 2.9.
Original cover letter:
This patchset implements network boot for s390x. You need to build a s390-netboot.img to actually perform the work (not included).
Basically, we add support for virtio-net devices into the ipl code and update the ccw bios to handle this as well.
For the first patch (elf loading) I'd like to get an ack.
A s390-netboot.img can be built by bundling some shell scripts, busybox and the kexec binary bundled into an initial ramdisk and append that to a kernel image. An existing s390 system can be used as source.
The init process can be a simple shell script that mounts a few essential filesystems, like /dev, /proc, /sys, ..., starts a DHCP client (busybox udchpc) and then invokes another script to do the actual network boot.
udchpc will invoke the script /usr/share/udhcpc/default.script in response to DHCP server messages to configure interfaces. The sample busybox default.script can be used for that, but needs to also extract the DHCP options like the tftp server address and pass that on to the boot script.
The boot script itself has to retrieve the PXELINUX configuration from the tftp server as in [1], then retrieve the remote kernel and initial ramdisk and finally use kexec to boot the network kernel.
In a nutshell:
1. Create a skeleton initramfs directory structure
2. Create the init script, the PXE boot scripts and the DHCP default script
3. Copy kexec and its dependencies from the source system into the initramfs
4. Copy virtio network and block modules from the source system into the initramfs
5. Copy the busybox binaries into the initramfs
6. Build the ramdisk (in compressed CPIO format)
7. Concatenate the kernel image and the initial ramdisk
8. Update the 8 bytes at location 66568 with the offset value of the ramdisk in the new binary, and the 8 bytes at location 66576 with the size of the ramdisk. Both values need to be updated in binary, big endian format.
[1]
http://www.syslinux.org/wiki/index.php?title=PXELINUX#Configuration_filename
Cornelia Huck (1):
pc-bios/s390-ccw.img: rebuild image
Farhan Ali (4):
elf-loader: Allow late loading of elf
s390x/ipl: Extend S390IPLState to support network boot s390x/ipl: Load network boot image pc-bios/s390-ccw: Use the ccw bios to start the network boot
hw/core/loader.c | 17 ++++++++- hw/s390x/ipl.c | 90 +++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/ipl.h | 5 ++- hw/s390x/s390-virtio-ccw.c | 3 +- hw/s390x/s390-virtio.c | 2 + hw/s390x/s390-virtio.h | 1 + include/hw/elf_ops.h | 13 +++++-- include/hw/loader.h | 13 ++++++- pc-bios/s390-ccw.img | Bin 26392 -> 26456 bytes pc-bios/s390-ccw/bootmap.c | 8 +++- pc-bios/s390-ccw/iplb.h | 3 +- pc-bios/s390-ccw/main.c | 20 +++++++--- pc-bios/s390-ccw/virtio.c | 1 + pc-bios/s390-ccw/virtio.h | 1 + 14 files changed, 160 insertions(+), 17 deletions(-)
Signature · 1 line
2.11.0
PATCH v2 1/5 elf-loader: Allow late loading of elf
From: Farhan Ali <[email protected]>
The current QEMU ROM infrastructure rejects late loading of ROMs. And ELFs are currently loaded as ROM, this prevents delayed loading of ELFs. So when loading ELF, allow the user to specify if ELF should be loaded as ROM or not.
If an ELF is not loaded as ROM, then they are not restored on a guest reboot/reset and so its upto the user to handle the reloading.
--- hw/core/loader.c | 17 +++++++++++++++-- include/hw/elf_ops.h | 13 +++++++++---- include/hw/loader.h | 13 ++++++++++++- 3 files changed, 36 insertions(+), 7 deletions(-)
hw/core/loader.c +15 -2
@@ -435,6 +435,19 @@ int load_elf_as(const char *filename, uint64_t *highaddr, int big_endian, int elf_machine, int clear_lsb, int data_swab, AddressSpace *as) { + return load_elf_ram(filename, translate_fn, translate_opaque, +pentry ,lowaddr ,highaddr ,big_endian ,elf_machine , +clear_lsb ,data_swab ,as ,true ); +} + +/* return < 0 if error, otherwise the number of bytes loaded in memory */ +int load_elf_ram (const char *filename, +uint64_t (*translate_fn)(void *,uint64_t ), +void *translate_opaque,uint64_t *pentry,uint64_t *lowaddr, +uint64_t *highaddr,int big_endian,int elf_machine, +int clear_lsb,int data_swab,AddressSpace *as, +bool load_rom) +{int fd, data_order, target_data_order, must_swab, ret =ELF_LOAD_FAILED ;uint8_t e_ident[EI_NIDENT ];
@@ -473,11 +486,11 @@ int load_elf_as(const char *filename,if (e_ident[EI_CLASS ] ==ELFCLASS64 ) { ret =load_elf64 (filename, fd, translate_fn, translate_opaque, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb, - data_swab, as); + data_swab, as, load_rom); }else { ret =load_elf32 (filename, fd, translate_fn, translate_opaque, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb, - data_swab, as); + data_swab, as, load_rom); } fail:
include/hw/elf_ops.h +9 -4
@@ -264,7 +264,7 @@ static int glue(load_elf, SZ)(const char *name, int fd, int must_swab, uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr, int elf_machine, int clear_lsb, int data_swab, - AddressSpace *as) + AddressSpace *as, bool load_rom) { struct elfhdr ehdr;struct elf_phdr *phdr =NULL , *ph;
@@ -403,10 +403,15 @@ static int glue(load_elf, SZ)(const char *name, int fd, *pentry = ehdr.e_entry - ph->p_vaddr + ph->p_paddr; } -snprintf (label,sizeof (label),"phdr #%d: %s" , i, name); +if (load_rom) { +snprintf (label,sizeof (label),"phdr #%d: %s" , i, name); -/* rom_add_elf_program() seize the ownership of 'data' */ -rom_add_elf_program (label, data, file_size, mem_size, addr, as); +/* rom_add_elf_program() seize the ownership of 'data' */ +rom_add_elf_program (label, data, file_size, mem_size, addr, as); + }else { +cpu_physical_memory_write (addr, data, file_size); +g_free (data); + } total_size += mem_size;if (addr < low)
include/hw/loader.h +12 -1
@@ -65,7 +65,7 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);#define ELF_LOAD_WRONG_ENDIAN -4const char *load_elf_strerror (int error); -/** load_elf_as: +/** load_elf_ram: * @filename: Path of ELF file * @translate_fn: optional function to translate load addresses * @translate_opaque: opaque data passed to @translate_fn
@@ -81,6 +81,7 @@ const char *load_elf_strerror(int error);* words and 3 for within doublewords. * @as: The AddressSpace to load the ELF to. The value of address_space_memory * is used if nothing is supplied here. +* @load_rom : Load ELF binary as ROM * * Load an ELF file's contents to the emulated system's address space. * Clients may optionally specify a callback to perform address
@@ -93,6 +94,16 @@ const char *load_elf_strerror(int error);* If @elf_machine is EM_NONE then the machine type will be read from the * ELF header and no checks will be carried out against the machine type. */ +int load_elf_ram (const char *filename, +uint64_t (*translate_fn)(void *,uint64_t ), +void *translate_opaque,uint64_t *pentry,uint64_t *lowaddr, +uint64_t *highaddr,int big_endian,int elf_machine, +int clear_lsb,int data_swab,AddressSpace *as, +bool load_rom); + +/** load_elf_as: +* Same as load_elf_ram(), but always loads the elf as ROM +*/ int load_elf_as(const char *filename, uint64_t (*translate_fn)(void *, uint64_t), void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v2 1/5] elf-loader: Allow late loading of elf
Quoted 33 lines · Cornelia Huck
From: Farhan Ali <[email protected]>
The current QEMU ROM infrastructure rejects late loading of ROMs. And ELFs are currently loaded as ROM, this prevents delayed loading of ELFs. So when loading ELF, allow the user to specify if ELF should be loaded as ROM or not.
If an ELF is not loaded as ROM, then they are not restored on a guest reboot/reset and so its upto the user to handle the reloading.
Signed-off-by Farhan Ali <[email protected]>Reviewed-by Christian Borntraeger <[email protected]>Cc Peter Maydell <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/core/loader.c | 17 +++++++++++++++-- include/hw/elf_ops.h | 13 +++++++++---- include/hw/loader.h | 13 ++++++++++++- 3 files changed, 36 insertions(+), 7 deletions(-)hw/core/loader.c +5
-0@@ -435,6 +435,19 @@ int load_elf_as(const char *filename, uint64_t *highaddr, int big_endian, int elf_machine, int clear_lsb, int data_swab, AddressSpace *as) { + return load_elf_ram(filename, translate_fn, translate_opaque, +pentry ,lowaddr ,highaddr ,big_endian ,elf_machine , +clear_lsb ,data_swab ,as ,true ); +} +
hw/core/loader.c int load_elf_as(const char *filename, · line 452
Quoted 10 lines
hw/core/loader.c +8
-0+/* return < 0 if error, otherwise the number of bytes loaded in memory */ +int load_elf_ram (const char *filename, +uint64_t (*translate_fn)(void *,uint64_t ), +void *translate_opaque,uint64_t *pentry,uint64_t *lowaddr, +uint64_t *highaddr,int big_endian,int elf_machine, +int clear_lsb,int data_swab,AddressSpace *as, +bool load_rom) +{int fd, data_order, target_data_order, must_swab, ret =ELF_LOAD_FAILED ;uint8_t e_ident[EI_NIDENT ];
<bikeshedpaintingsofeelfreetoignoreme>
The patch looks basically fine to me, but I think it's a little bit confusing to have a function called load_elf_ram() which can also be used to load ROMs with a load_rom=1 parameter. If I read "load_elf_ram()", I'd expect a function that can only read ELFs to RAM. So what about adding the "load_rom" parameter to load_elf_as() instead and then making load_elf_ram() a wrapper function to that one with load_rom=0 ? AFAICS there is only one additional caller to load_elf_as (in the generic-loader), so the additional effort here should be OK, I think.
</bikeshedpaintingsofeelfreetoignoreme>
Thomas
Re: [Qemu-devel] [PATCH v2 1/5] elf-loader: Allow late loading of elf
Quoted 57 lines · On Sat, 25 Feb 2017 07:05:27 +0100 Thomas Huth <[email protected]> wrote:
Quoted 33 lines · Cornelia Huck
From: Farhan Ali <[email protected]>
The current QEMU ROM infrastructure rejects late loading of ROMs. And ELFs are currently loaded as ROM, this prevents delayed loading of ELFs. So when loading ELF, allow the user to specify if ELF should be loaded as ROM or not.
If an ELF is not loaded as ROM, then they are not restored on a guest reboot/reset and so its upto the user to handle the reloading.
Signed-off-by Farhan Ali <[email protected]>Reviewed-by Christian Borntraeger <[email protected]>Cc Peter Maydell <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/core/loader.c | 17 +++++++++++++++-- include/hw/elf_ops.h | 13 +++++++++---- include/hw/loader.h | 13 ++++++++++++- 3 files changed, 36 insertions(+), 7 deletions(-)hw/core/loader.c +5
-0@@ -435,6 +435,19 @@ int load_elf_as(const char *filename, uint64_t *highaddr, int big_endian, int elf_machine, int clear_lsb, int data_swab, AddressSpace *as) { + return load_elf_ram(filename, translate_fn, translate_opaque, +pentry ,lowaddr ,highaddr ,big_endian ,elf_machine , +clear_lsb ,data_swab ,as ,true ); +} +hw/core/loader.c int load_elf_as(const char *filename, · line 452
Quoted 10 lines
hw/core/loader.c +8
-0+/* return < 0 if error, otherwise the number of bytes loaded in memory */ +int load_elf_ram (const char *filename, +uint64_t (*translate_fn)(void *,uint64_t ), +void *translate_opaque,uint64_t *pentry,uint64_t *lowaddr, +uint64_t *highaddr,int big_endian,int elf_machine, +int clear_lsb,int data_swab,AddressSpace *as, +bool load_rom) +{int fd, data_order, target_data_order, must_swab, ret =ELF_LOAD_FAILED ;uint8_t e_ident[EI_NIDENT ];<bikeshedpaintingsofeelfreetoignoreme>
The patch looks basically fine to me, but I think it's a little bit confusing to have a function called
load_elf_ram()which can also be used to load ROMs with a load_rom=1 parameter. If I read "load_elf_ram()", I'd expect a function that can only read ELFs to RAM. So what about adding the "load_rom" parameter toload_elf_as()instead and then makingload_elf_ram()a wrapper function to that one with load_rom=0 ? AFAICS there is only one additional caller toload_elf_as(in the generic-loader), so the additional effort here should be OK, I think.
Quoted 4 lines
</bikeshedpaintingsofeelfreetoignoreme>
Thomas
I think both approaches are fine, but I'd prefer to keep the bikeshed colour to avoid a re-spin :)
Re: [Qemu-devel] [PATCH v2 1/5] elf-loader: Allow late loading of elf
In reply to Cornelia HuckQuoted 14 lines · On Thu, 23 Feb 2017 13:20:21 +0100 Cornelia Huck <[email protected]>…
From: Farhan Ali <[email protected]>
The current QEMU ROM infrastructure rejects late loading of ROMs. And ELFs are currently loaded as ROM, this prevents delayed loading of ELFs. So when loading ELF, allow the user to specify if ELF should be loaded as ROM or not.
If an ELF is not loaded as ROM, then they are not restored on a guest reboot/reset and so its upto the user to handle the reloading.
Signed-off-by Farhan Ali <[email protected]>Reviewed-by Christian Borntraeger <[email protected]>Cc Peter Maydell <[email protected]>Signed-off-by Cornelia Huck <[email protected]>
Quoted 6 lines
--- hw/core/loader.c | 17 +++++++++++++++-- include/hw/elf_ops.h | 13 +++++++++---- include/hw/loader.h | 13 ++++++++++++- 3 files changed, 36 insertions(+), 7 deletions(-)
Any further acks for this?
Or, put differently, any objections to me sending this in a pullreq for 2.9?
Quoted 108 lines
hw/core/loader.c +15
-2@@ -435,6 +435,19 @@ int load_elf_as(const char *filename, uint64_t *highaddr, int big_endian, int elf_machine, int clear_lsb, int data_swab, AddressSpace *as) { + return load_elf_ram(filename, translate_fn, translate_opaque, +pentry ,lowaddr ,highaddr ,big_endian ,elf_machine , +clear_lsb ,data_swab ,as ,true ); +} + +/* return < 0 if error, otherwise the number of bytes loaded in memory */ +int load_elf_ram (const char *filename, +uint64_t (*translate_fn)(void *,uint64_t ), +void *translate_opaque,uint64_t *pentry,uint64_t *lowaddr, +uint64_t *highaddr,int big_endian,int elf_machine, +int clear_lsb,int data_swab,AddressSpace *as, +bool load_rom) +{int fd, data_order, target_data_order, must_swab, ret =ELF_LOAD_FAILED ;uint8_t e_ident[EI_NIDENT ];@@ -473,11 +486,11 @@ int load_elf_as(const char *filename,if (e_ident[EI_CLASS ] ==ELFCLASS64 ) { ret =load_elf64 (filename, fd, translate_fn, translate_opaque, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb, - data_swab, as); + data_swab, as, load_rom); }else { ret =load_elf32 (filename, fd, translate_fn, translate_opaque, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb, - data_swab, as); + data_swab, as, load_rom); } fail:include/hw/elf_ops.h +9
-4@@ -264,7 +264,7 @@ static int glue(load_elf, SZ)(const char *name, int fd, int must_swab, uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr, int elf_machine, int clear_lsb, int data_swab, - AddressSpace *as) + AddressSpace *as, bool load_rom) { struct elfhdr ehdr;struct elf_phdr *phdr =NULL , *ph;@@ -403,10 +403,15 @@ static int glue(load_elf, SZ)(const char *name, int fd, *pentry = ehdr.e_entry - ph->p_vaddr + ph->p_paddr; } -snprintf (label,sizeof (label),"phdr #%d: %s" , i, name); +if (load_rom) { +snprintf (label,sizeof (label),"phdr #%d: %s" , i, name); -/* rom_add_elf_program() seize the ownership of 'data' */ -rom_add_elf_program (label, data, file_size, mem_size, addr, as); +/* rom_add_elf_program() seize the ownership of 'data' */ +rom_add_elf_program (label, data, file_size, mem_size, addr, as); + }else { +cpu_physical_memory_write (addr, data, file_size); +g_free (data); + } total_size += mem_size;if (addr < low)include/hw/loader.h +12
-1@@ -65,7 +65,7 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);#define ELF_LOAD_WRONG_ENDIAN -4const char *load_elf_strerror (int error); -/** load_elf_as: +/** load_elf_ram: * @filename: Path of ELF file * @translate_fn: optional function to translate load addresses * @translate_opaque: opaque data passed to @translate_fn @@ -81,6 +81,7 @@ const char *load_elf_strerror(int error);* words and 3 for within doublewords. * @as: The AddressSpace to load the ELF to. The value of address_space_memory * is used if nothing is supplied here. +* @load_rom : Load ELF binary as ROM * * Load an ELF file's contents to the emulated system's address space. * Clients may optionally specify a callback to perform address @@ -93,6 +94,16 @@ const char *load_elf_strerror(int error);* If @elf_machine is EM_NONE then the machine type will be read from the * ELF header and no checks will be carried out against the machine type. */ +int load_elf_ram (const char *filename, +uint64_t (*translate_fn)(void *,uint64_t ), +void *translate_opaque,uint64_t *pentry,uint64_t *lowaddr, +uint64_t *highaddr,int big_endian,int elf_machine, +int clear_lsb,int data_swab,AddressSpace *as, +bool load_rom); + +/** load_elf_as: +* Same as load_elf_ram(), but always loads the elf as ROM +*/ int load_elf_as(const char *filename, uint64_t (*translate_fn)(void *, uint64_t), void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
PATCH v2 2/5 s390x/ipl: Extend S390IPLState to support network boot
In reply to Cornelia HuckFrom: Farhan Ali <[email protected]>
Add new field to S390IPLState to store the name of the network boot loader.
--- hw/s390x/ipl.c | 1 + hw/s390x/ipl.h | 1 + hw/s390x/s390-virtio-ccw.c | 3 ++- hw/s390x/s390-virtio.c | 2 ++ hw/s390x/s390-virtio.h | 1 + 5 files changed, 7 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +1 -0
@@ -209,6 +209,7 @@ static Property s390_ipl_properties[] = {DEFINE_PROP_STRING ("initrd" , S390IPLState, initrd),DEFINE_PROP_STRING ("cmdline" , S390IPLState, cmdline),DEFINE_PROP_STRING ("firmware" , S390IPLState, firmware), +DEFINE_PROP_STRING ("netboot_fw" , S390IPLState, netboot_fw),DEFINE_PROP_BOOL ("enforce_bios" , S390IPLState, enforce_bios, false),DEFINE_PROP_BOOL ("iplbext_migration" , S390IPLState, iplbext_migration, true),
hw/s390x/ipl.h +1 -0
@@ -106,6 +106,7 @@ struct S390IPLState {char *initrd;char *cmdline;char *firmware; +char *netboot_fw;uint8_t cssid;uint8_t ssid;uint16_t devno;
hw/s390x/s390-virtio-ccw.c +2 -1
@@ -116,7 +116,8 @@ static void ccw_init(MachineState *machine)/* get a BUS */ css_bus =virtual_css_bus_init ();s390_init_ipl_dev (machine->kernel_filename, machine->kernel_cmdline, - machine->initrd_filename,"s390-ccw.img" , true); + machine->initrd_filename,"s390-ccw.img" , +"s390-netboot.img" , true);s390_flic_init (); dev =qdev_create (NULL ,TYPE_S390_PCI_HOST_BRIDGE );
hw/s390x/s390-virtio.c +2 -0
@@ -65,6 +65,7 @@ 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) { Object *new = object_new(TYPE_S390_IPL);
@@ -78,6 +79,7 @@ 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_string (dev,"netboot_fw" , netboot_fw);qdev_prop_set_bit (dev,"enforce_bios" , enforce_bios);object_property_add_child (qdev_get_machine (),TYPE_S390_IPL , new,NULL );
hw/s390x/s390-virtio.h +1 -0
@@ -24,6 +24,7 @@ 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);void s390_create_virtio_net (BusState *bus,const char *name);void s390_nmi (NMIState *n,int cpu_index,Error **errp);
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v2 2/5] s390x/ipl: Extend S390IPLState to support network boot
Quoted 81 lines · Cornelia Huck
From: Farhan Ali <[email protected]>
Add new field to S390IPLState to store the name of the network boot loader.
Signed-off-by Farhan Ali <[email protected]>Reviewed-by Christian Borntraeger <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/ipl.c | 1 + hw/s390x/ipl.h | 1 + hw/s390x/s390-virtio-ccw.c | 3 ++- hw/s390x/s390-virtio.c | 2 ++ hw/s390x/s390-virtio.h | 1 + 5 files changed, 7 insertions(+), 1 deletion(-)hw/s390x/ipl.c +1
-0@@ -209,6 +209,7 @@ static Property s390_ipl_properties[] = {DEFINE_PROP_STRING ("initrd" , S390IPLState, initrd),DEFINE_PROP_STRING ("cmdline" , S390IPLState, cmdline),DEFINE_PROP_STRING ("firmware" , S390IPLState, firmware), +DEFINE_PROP_STRING ("netboot_fw" , S390IPLState, netboot_fw),DEFINE_PROP_BOOL ("enforce_bios" , S390IPLState, enforce_bios, false),DEFINE_PROP_BOOL ("iplbext_migration" , S390IPLState, iplbext_migration, true),hw/s390x/ipl.h +1
-0@@ -106,6 +106,7 @@ struct S390IPLState {char *initrd;char *cmdline;char *firmware; +char *netboot_fw;uint8_t cssid;uint8_t ssid;uint16_t devno;hw/s390x/s390-virtio-ccw.c +2
-1@@ -116,7 +116,8 @@ static void ccw_init(MachineState *machine)/* get a BUS */ css_bus =virtual_css_bus_init ();s390_init_ipl_dev (machine->kernel_filename, machine->kernel_cmdline, - machine->initrd_filename,"s390-ccw.img" , true); + machine->initrd_filename,"s390-ccw.img" , +"s390-netboot.img" , true);s390_flic_init (); dev =qdev_create (NULL ,TYPE_S390_PCI_HOST_BRIDGE );hw/s390x/s390-virtio.c +2
-0@@ -65,6 +65,7 @@ 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) { Object *new = object_new(TYPE_S390_IPL);@@ -78,6 +79,7 @@ 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_string (dev,"netboot_fw" , netboot_fw);qdev_prop_set_bit (dev,"enforce_bios" , enforce_bios);object_property_add_child (qdev_get_machine (),TYPE_S390_IPL , new,NULL );hw/s390x/s390-virtio.h +0
-0
hw/s390x/s390-virtio.h void s390_init_ipl_dev(const char *kernel_filename, · line 30
Quoted 7 lines
hw/s390x/s390-virtio.h +1
-0@@ -24,6 +24,7 @@ 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);void s390_create_virtio_net (BusState *bus,const char *name);void s390_nmi (NMIState *n,int cpu_index,Error **errp);
PATCH v2 3/5 s390x/ipl: Load network boot image
In reply to Cornelia HuckFrom: Farhan Ali <[email protected]>
Load the network boot image into guest RAM when the boot device selected is a network device. Use some of the reserved space in IplBlockCcw to store the start address of the netboot image.
A user could also use 'chreipl'(diag 308/5) to change the boot device. So every time we update the IPLB, we need to verify if the selected boot device is a network device so we can appropriately load the network boot image.
--- hw/s390x/ipl.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/ipl.h | 4 ++- 2 files changed, 92 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +89 -0
@@ -20,6 +20,7 @@#include "hw/s390x/virtio-ccw.h" #include "hw/s390x/css.h" #include "ipl.h" +#include "qemu/error-report.h" #define KERN_IMAGE_START 0x010000UL#define KERN_PARM_AREA 0x010480UL
@@ -227,6 +228,12 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl) TYPE_VIRTIO_CCW_DEVICE);SCSIDevice *sd = (SCSIDevice *)object_dynamic_cast (OBJECT (dev_st),TYPE_SCSI_DEVICE ); +VirtIONet *vn = (VirtIONet *)object_dynamic_cast (OBJECT (dev_st), +TYPE_VIRTIO_NET ); + +if (vn) { + ipl->netboot = true; + }if (virtio_ccw_dev) {CcwDevice *ccw_dev =CCW_DEVICE (virtio_ccw_dev);
@@ -259,12 +266,86 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)return false; } +static int load_netboot_image (Error **errp) +{ +S390IPLState *ipl =get_ipl_device (); +char *netboot_filename; +MemoryRegion *sysmem =get_system_memory (); +MemoryRegion *mr =NULL ; +void *ram_ptr =NULL ; +int img_size =-1 ; + + mr =memory_region_find (sysmem,0 ,1 ).mr; +if (!mr) { +error_setg (errp,"Failed to find memory region at address 0" ); +return -1 ; + } + + ram_ptr =memory_region_get_ram_ptr (mr); +if (!ram_ptr) { +error_setg (errp,"No RAM found" ); + goto unref_mr; + } + + netboot_filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , ipl->netboot_fw); +if (netboot_filename ==NULL ) { +error_setg (errp,"Could not find network bootloader" ); + goto unref_mr; + } + + img_size =load_elf_ram (netboot_filename,NULL ,NULL , &ipl->start_addr, +NULL ,NULL ,1 ,EM_S390 ,0 ,0 ,NULL , false); + +if (img_size <0 ) { + img_size =load_image_size (netboot_filename, ram_ptr, ram_size); + ipl->start_addr =KERN_IMAGE_START ; + } + +if (img_size <0 ) { +error_setg (errp,"Failed to load network bootloader" ); + } + +g_free (netboot_filename); + +unref_mr: +memory_region_unref (mr); +return img_size; +} + +static bool is_virtio_net_device (IplParameterBlock *iplb) +{ +uint8_t cssid; +uint8_t ssid; +uint16_t devno; +uint16_t schid; +SubchDev *sch =NULL ; + +if (iplb->pbt !=S390_IPL_TYPE_CCW ) { +return false; + } + + devno =be16_to_cpu (iplb->ccw.devno); + ssid = iplb->ccw.ssid &3 ; + +for (schid =0 ; schid <MAX_SCHID ; schid++) { +for (cssid =0 ; cssid <MAX_CSSID ; cssid++) { + sch =css_find_subch (1 , cssid, ssid, schid); + +if (sch && sch->devno == devno) { +return sch->id.cu_model ==VIRTIO_ID_NET ; + } + } + } +return false; +} +void s390_ipl_update_diag308 (IplParameterBlock *iplb) {S390IPLState *ipl =get_ipl_device (); ipl->iplb = *iplb; ipl->iplb_valid = true; + ipl->netboot =is_virtio_net_device (iplb); }IplParameterBlock *s390_ipl_get_iplb (void )
@@ -288,6 +369,7 @@ void s390_reipl_request(void)void s390_ipl_prepare_cpu (S390CPU *cpu) {S390IPLState *ipl =get_ipl_device (); +Error *err =NULL ; cpu->env.psw.addr = ipl->start_addr; cpu->env.psw.mask =IPL_PSW_MASK ;
@@ -298,6 +380,13 @@ void s390_ipl_prepare_cpu(S390CPU *cpu) ipl->iplb_valid =s390_gen_initial_iplb (ipl); } } +if (ipl->netboot) { +if (load_netboot_image (&err) <0 ) { +error_report_err (err); +vm_stop (RUN_STATE_INTERNAL_ERROR ); + } + ipl->iplb.ccw.netboot_start_addr = ipl->start_addr; + } }static void s390_ipl_reset (DeviceState *dev)
hw/s390x/ipl.h +3 -1
@@ -16,7 +16,8 @@#include "cpu.h" struct IplBlockCcw { -uint8_t reserved0[85 ]; +uint64_t netboot_start_addr; +uint8_t reserved0[77 ];uint8_t ssid;uint16_t devno;uint8_t vm_flags;
@@ -100,6 +101,7 @@ struct S390IPLState {IplParameterBlock iplb;bool iplb_valid;bool reipl_requested; +bool netboot;/*< public >*/ char *kernel;
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v2 3/5] s390x/ipl: Load network boot image
Quoted 109 lines · Cornelia Huck
From: Farhan Ali <[email protected]>
Load the network boot image into guest RAM when the boot device selected is a network device. Use some of the reserved space in IplBlockCcw to store the start address of the netboot image.
A user could also use 'chreipl'(diag 308/5) to change the boot device. So every time we update the IPLB, we need to verify if the selected boot device is a network device so we can appropriately load the network boot image.
Signed-off-by Farhan Ali <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/ipl.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/ipl.h | 4 ++- 2 files changed, 92 insertions(+), 1 deletion(-)hw/s390x/ipl.c +68
-0@@ -20,6 +20,7 @@#include "hw/s390x/virtio-ccw.h" #include "hw/s390x/css.h" #include "ipl.h" +#include "qemu/error-report.h" #define KERN_IMAGE_START 0x010000UL#define KERN_PARM_AREA 0x010480UL@@ -227,6 +228,12 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl) TYPE_VIRTIO_CCW_DEVICE);SCSIDevice *sd = (SCSIDevice *)object_dynamic_cast (OBJECT (dev_st),TYPE_SCSI_DEVICE ); +VirtIONet *vn = (VirtIONet *)object_dynamic_cast (OBJECT (dev_st), +TYPE_VIRTIO_NET ); + +if (vn) { + ipl->netboot = true; + }if (virtio_ccw_dev) {CcwDevice *ccw_dev =CCW_DEVICE (virtio_ccw_dev);@@ -259,12 +266,86 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)return false; } +static int load_netboot_image (Error **errp) +{ +S390IPLState *ipl =get_ipl_device (); +char *netboot_filename; +MemoryRegion *sysmem =get_system_memory (); +MemoryRegion *mr =NULL ; +void *ram_ptr =NULL ; +int img_size =-1 ; + + mr =memory_region_find (sysmem,0 ,1 ).mr; +if (!mr) { +error_setg (errp,"Failed to find memory region at address 0" ); +return -1 ; + } + + ram_ptr =memory_region_get_ram_ptr (mr); +if (!ram_ptr) { +error_setg (errp,"No RAM found" ); + goto unref_mr; + } + + netboot_filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , ipl->netboot_fw); +if (netboot_filename ==NULL ) { +error_setg (errp,"Could not find network bootloader" ); + goto unref_mr; + } + + img_size =load_elf_ram (netboot_filename,NULL ,NULL , &ipl->start_addr, +NULL ,NULL ,1 ,EM_S390 ,0 ,0 ,NULL , false); + +if (img_size <0 ) { + img_size =load_image_size (netboot_filename, ram_ptr, ram_size); + ipl->start_addr =KERN_IMAGE_START ; + } + +if (img_size <0 ) { +error_setg (errp,"Failed to load network bootloader" ); + } + +g_free (netboot_filename); + +unref_mr: +memory_region_unref (mr); +return img_size; +} + +static bool is_virtio_net_device (IplParameterBlock *iplb) +{ +uint8_t cssid; +uint8_t ssid; +uint16_t devno; +uint16_t schid; +SubchDev *sch =NULL ; + +if (iplb->pbt !=S390_IPL_TYPE_CCW ) { +return false; + } + + devno =be16_to_cpu (iplb->ccw.devno); + ssid = iplb->ccw.ssid &3 ; +
hw/s390x/ipl.c static bool s390_gen_initial_iplb(S390IPLState *ipl) · line 339
Quoted 10 lines
hw/s390x/ipl.c +10
-0+for (schid =0 ; schid <MAX_SCHID ; schid++) { +for (cssid =0 ; cssid <MAX_CSSID ; cssid++) { + sch =css_find_subch (1 , cssid, ssid, schid); + +if (sch && sch->devno == devno) { +return sch->id.cu_model ==VIRTIO_ID_NET ; + } + } + } +return false;
The above line has only 3 instead of 4 spaces. I wonder why checkpatch does not complain here...?
Quoted 21 lines
hw/s390x/ipl.c +4
-0+} +void s390_ipl_update_diag308 (IplParameterBlock *iplb) {S390IPLState *ipl =get_ipl_device (); ipl->iplb = *iplb; ipl->iplb_valid = true; + ipl->netboot =is_virtio_net_device (iplb); }IplParameterBlock *s390_ipl_get_iplb (void )@@ -288,6 +369,7 @@ void s390_reipl_request(void)void s390_ipl_prepare_cpu (S390CPU *cpu) {S390IPLState *ipl =get_ipl_device (); +Error *err =NULL ; cpu->env.psw.addr = ipl->start_addr; cpu->env.psw.mask =IPL_PSW_MASK ;
hw/s390x/ipl.c void s390_ipl_prepare_cpu(S390CPU *cpu) · line 388
Quoted 9 lines
hw/s390x/ipl.c +6
-0@@ -298,6 +380,13 @@ void s390_ipl_prepare_cpu(S390CPU *cpu) ipl->iplb_valid =s390_gen_initial_iplb (ipl); } } +if (ipl->netboot) { +if (load_netboot_image (&err) <0 ) { +error_report_err (err); +vm_stop (RUN_STATE_INTERNAL_ERROR ); + } + ipl->iplb.ccw.netboot_start_addr = ipl->start_addr;
Not sure whether it matters, but in case of early errors during load_netboot_image(), ipl->start_addr could be used uninitialized here. Maybe you should move the "ipl->start_addr = KERN_IMAGE_START;" there at the beginning of the function, to make it also the default value for the other error cases?
Quoted 20 lines
hw/s390x/ipl.c +1
-0+ } }static void s390_ipl_reset (DeviceState *dev)hw/s390x/ipl.h +2
-1@@ -16,7 +16,8 @@#include "cpu.h" struct IplBlockCcw { -uint8_t reserved0[85 ]; +uint64_t netboot_start_addr; +uint8_t reserved0[77 ];uint8_t ssid;uint16_t devno;uint8_t vm_flags;
hw/s390x/ipl.h struct S390IPLState { · line 107
Quoted 7 lines
hw/s390x/ipl.h +1
-0@@ -100,6 +101,7 @@ struct S390IPLState {IplParameterBlock iplb;bool iplb_valid;bool reipl_requested; +bool netboot;/*< public >*/ char *kernel;
Thomas
Re: [Qemu-devel] [PATCH v2 3/5] s390x/ipl: Load network boot image
Quoted 40 lines · On Sat, 25 Feb 2017 07:18:29 +0100 Thomas Huth <[email protected]> wrote:
Quoted 39 lines · Cornelia Huck
From: Farhan Ali <[email protected]>
Load the network boot image into guest RAM when the boot device selected is a network device. Use some of the reserved space in IplBlockCcw to store the start address of the netboot image.
A user could also use 'chreipl'(diag 308/5) to change the boot device. So every time we update the IPLB, we need to verify if the selected boot device is a network device so we can appropriately load the network boot image.
Signed-off-by Farhan Ali <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/ipl.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/ipl.h | 4 ++- 2 files changed, 92 insertions(+), 1 deletion(-)hw/s390x/ipl.c +20
-0+static bool is_virtio_net_device (IplParameterBlock *iplb) +{ +uint8_t cssid; +uint8_t ssid; +uint16_t devno; +uint16_t schid; +SubchDev *sch =NULL ; + +if (iplb->pbt !=S390_IPL_TYPE_CCW ) { +return false; + } + + devno =be16_to_cpu (iplb->ccw.devno); + ssid = iplb->ccw.ssid &3 ; + +for (schid =0 ; schid <MAX_SCHID ; schid++) { +for (cssid =0 ; cssid <MAX_CSSID ; cssid++) { + sch =css_find_subch (1 , cssid, ssid, schid); + +if (sch && sch->devno == devno) {
Quoted 8 lines
hw/s390x/ipl.c static bool s390_gen_initial_iplb(S390IPLState *ipl) · line 339
Quoted 5 lines
hw/s390x/ipl.c +5
-0+return sch->id.cu_model ==VIRTIO_ID_NET ; + } + } + } +return false;The above line has only 3 instead of 4 spaces. I wonder why checkpatch does not complain here...?
Odd. Will fixup.
Quoted 10 lines
hw/s390x/ipl.c void s390_ipl_prepare_cpu(S390CPU *cpu) · line 388
Quoted 9 lines
hw/s390x/ipl.c +7
-0+} +if (ipl->netboot) { +if (load_netboot_image (&err) <0 ) { +error_report_err (err); +vm_stop (RUN_STATE_INTERNAL_ERROR ); + } + ipl->iplb.ccw.netboot_start_addr = ipl->start_addr;
Quoted 5 lines
Not sure whether it matters, but in case of early errors during
load_netboot_image(),ipl->start_addrcould be used uninitialized here. Maybe you should move the "ipl->start_addr=KERN_IMAGE_START;" there at the beginning of the function, to make it also the default value for the other error cases?
ipl->start_addr has already been set to some value in the realize function (either the kernel entry address, or the bios address).
But that should not matter with the vm_stop() on error anyway, no?
Re: [Qemu-devel] [PATCH v2 3/5] s390x/ipl: Load network boot image
Quoted 22 lines · Cornelia Huck
Quoted 19 lines · On Sat, 25 Feb 2017 07:18:29 +0100 Thomas Huth <[email protected]> wrote:
Quoted 18 lines · Cornelia Huck
From: Farhan Ali <[email protected]>
Load the network boot image into guest RAM when the boot device selected is a network device. Use some of the reserved space in IplBlockCcw to store the start address of the netboot image.
A user could also use 'chreipl'(diag 308/5) to change the boot device. So every time we update the IPLB, we need to verify if the selected boot device is a network device so we can appropriately load the network boot image.
Signed-off-by Farhan Ali <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/ipl.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/ipl.h | 4 ++- 2 files changed, 92 insertions(+), 1 deletion(-)
[...]
Quoted 13 lines
Quoted 7 lines
hw/s390x/ipl.c void s390_ipl_prepare_cpu(S390CPU *cpu) · line 388
Quoted 6 lines
hw/s390x/ipl.c +6
-0+if (ipl->netboot) { +if (load_netboot_image (&err) <0 ) { +error_report_err (err); +vm_stop (RUN_STATE_INTERNAL_ERROR ); + } + ipl->iplb.ccw.netboot_start_addr = ipl->start_addr;Quoted 5 lines
Not sure whether it matters, but in case of early errors during
load_netboot_image(),ipl->start_addrcould be used uninitialized here. Maybe you should move the "ipl->start_addr=KERN_IMAGE_START;" there at the beginning of the function, to make it also the default value for the other error cases?
Quoted 4 lines
ipl->start_addrhas already been set to some value in the realize function (either the kernel entry address, or the bios address).But that should not matter with the
vm_stop()on error anyway, no?
Likely not. It's just a little bit strange to see that the program flow continues after the error in this function here ... maybe it would have been clearer to put a "return" right after the "vm_stop()"? Anyway, it likely does not really matter here, so never mind.
Thomas
PATCH v2 4/5 pc-bios/s390-ccw: Use the ccw bios to start the network boot
In reply to Cornelia HuckFrom: Farhan Ali <[email protected]>
We want to use the ccw bios to start final network boot. To do this we use ccw bios to detect if the boot device is a virtio network device and retrieve the start address of the network boot image.
--- pc-bios/s390-ccw/bootmap.c | 8 +++++++- pc-bios/s390-ccw/iplb.h | 3 ++- pc-bios/s390-ccw/main.c | 20 ++++++++++++++------ pc-bios/s390-ccw/virtio.c | 1 + pc-bios/s390-ccw/virtio.h | 1 + 5 files changed, 25 insertions(+), 8 deletions(-)
pc-bios/s390-ccw/bootmap.c +7 -1
@@ -724,11 +724,17 @@ static void zipl_load_vscsi(void)void zipl_load (void ) { -if (virtio_get_device ()->is_cdrom) { +VDev *vdev =virtio_get_device (); + +if (vdev->is_cdrom) {ipl_iso_el_torito ();panic ("\n! Cannot IPL this ISO image !\n" ); } +if (virtio_get_device_type () ==VIRTIO_ID_NET ) { +jump_to_IPL_code (vdev->netboot_start_addr); + } +ipl_scsi ();switch (virtio_get_device_type ()) {
pc-bios/s390-ccw/iplb.h +2 -1
@@ -13,7 +13,8 @@#define IPLB_H struct IplBlockCcw { -uint8_t reserved0[85 ]; +uint64_t netboot_start_addr; +uint8_t reserved0[77 ];uint8_t ssid;uint16_t devno;uint8_t vm_flags;
pc-bios/s390-ccw/main.c +14 -6
@@ -53,6 +53,12 @@ static bool find_dev(Schib *schib, int dev_no)if (!virtio_is_supported (blk_schid)) {continue ; } +/* Skip net devices since no IPLB is created and therefore no +* no network bootloader has been loaded +*/ +if (virtio_get_device_type () ==VIRTIO_ID_NET && dev_no <0 ) { +continue ; + }if ((dev_no <0 ) || (schib->pmcw.dev == dev_no)) {return true; }
@@ -67,6 +73,7 @@ static void virtio_setup(void)int ssid;bool found = false;uint16_t dev_no; +VDev *vdev =virtio_get_device ();/* * We unconditionally enable mss support. In every sane configuration,
@@ -85,9 +92,6 @@ static void virtio_setup(void) found =find_dev (&schib, dev_no);break ;case S390_IPL_TYPE_QEMU_SCSI : - { -VDev *vdev =virtio_get_device (); - vdev->scsi_device_selected = true; vdev->selected_scsi_device.channel = iplb.scsi.channel; vdev->selected_scsi_device.target = iplb.scsi.target;
@@ -95,7 +99,6 @@ static void virtio_setup(void) blk_schid.ssid = iplb.scsi.ssid &0x3 ; found =find_dev (&schib, iplb.scsi.devno);break ; - }default :panic ("List-directed IPL not supported yet!\n" ); }
@@ -111,9 +114,14 @@ static void virtio_setup(void)IPL_assert (found,"No virtio device found" ); -virtio_setup_device (blk_schid); +if (virtio_get_device_type () ==VIRTIO_ID_NET ) { +sclp_print ("Network boot device detected\n" ); + vdev->netboot_start_addr = iplb.ccw.netboot_start_addr; + }else { +virtio_setup_device (blk_schid); -IPL_assert (virtio_ipl_disk_is_valid (),"No valid IPL device detected" ); +IPL_assert (virtio_ipl_disk_is_valid (),"No valid IPL device detected" ); + } }int main (void )
pc-bios/s390-ccw/virtio.c +1 -0
@@ -585,6 +585,7 @@ bool virtio_is_supported(SubChannelId schid)switch (vdev.senseid.cu_model) {case VIRTIO_ID_BLOCK :case VIRTIO_ID_SCSI : +case VIRTIO_ID_NET :return true; } }
pc-bios/s390-ccw/virtio.h +1 -0
@@ -276,6 +276,7 @@ struct VDev {uint8_t scsi_dev_heads;bool scsi_device_selected;ScsiDevice selected_scsi_device; +uint64_t netboot_start_addr; };typedef struct VDev VDev ;
Signature · 1 line
2.11.0
PATCH v2 5/5 pc-bios/s390-ccw.img: rebuild image
In reply to Cornelia HuckContains the following commits:
- pc-bios/s390-ccw: Use the ccw bios to start the network boot
--- pc-bios/s390-ccw.img | Bin 26392 -> 26456 bytes 1 file changed, 0 insertions(+), 0 deletions(-)
pc-bios/s390-ccw.img binary +0 -0
Signature · 1 line
2.11.0