Skip to contentSkip to conversation

s390x: network boot

PATCH Superseded Cornelia Huck 6 participants 22 messages Feb 20, 2017 – Feb 24, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover s390x: network boot

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             |  87 +++++++++++++++++++++++++++++++++++++++++++++
 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, 157 insertions(+), 17 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 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
index ee5abd6eb7..9d1af1f6f3 100644
@@ -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
index 25659b93be..a172a6068a 100644
@@ -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
index 0dbd8d6bf3..3df4d73398 100644
@@ -65,7 +65,7 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);
 #define ELF_LOAD_WRONG_ENDIAN -4
 const 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
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] elf-loader: Allow late loading of elf

Quoted 9 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.

Could you maybe also explain here why you need such a delayed ELF loading? Why can't you load the s390-netboot.img at the same time as s390-ccw.img?

Thomas

#3 lore raw

Re: [Qemu-devel] [PATCH 1/5] elf-loader: Allow late loading of elf

(restored cc:s)

Quoted 8 lines · On Mon, 20 Feb 2017 16:33:36 +0100 Thomas Huth <[email protected]> wrote:
Quoted 7 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.

Quoted 10 lines
Quoted 2 lines

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.

Could you maybe also explain here why you need such a delayed ELF loading? Why can't you load the s390-netboot.img at the same time as s390-ccw.img?

Thomas

Why should we load the netboot image in all cases, and not just when we actually need it?

#4 lore raw

Re: [Qemu-devel] [PATCH 1/5] elf-loader: Allow late loading of elf

In reply to Thomas Huth
Quoted 8 lines · Thomas Huth
Quoted 7 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.

Quoted 6 lines
Quoted 2 lines

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.

Could you maybe also explain here why you need such a delayed ELF loading? Why can't you load the s390-netboot.img at the same time as s390-ccw.img?

Please read the cover letter for some details how to build such a netrom. This is a simple variant to implement a standard compliant network boot today but using a kernel+busybox+scripts.
Long term we certainly want to have a look at implementing something in the ccw bios, but this (tcp stack, virtio net, etc) will take some (a lot?) more time. Having a ramdisk+kernel loaded all the time would be extremely wasteful.

This patch (1) has another advantage.
Right now we load the ccw bios all the time, even for -kernel xxx boot, to allow the guest user to use chreipl to reboot from a disk. With this in place we can rework our ccw bios loader to load the ccw bios lazily as well.

Christian

#5 lore raw

Re: [Qemu-devel] [PATCH 1/5] elf-loader: Allow late loading of elf

Quoted 9 lines · Christian Borntraeger
Quoted 8 lines · Thomas Huth
Quoted 7 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.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

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.

Could you maybe also explain here why you need such a delayed ELF loading? Why can't you load the s390-netboot.img at the same time as s390-ccw.img?

Please read the cover letter for some details how to build such a netrom.

Sure, understood, but I still did not see an explanation why this can't be loaded as "ROM", too / why it needs to be loaded "delayed"? Does the image data need to be writable in memory? Or is the information not available yet at that point in time, whether the user wants to do a network boot or not? Don't get me wrong, I'm basically fine with this patch, I'm just missing some explanation *why* you have to do it this way.

Quoted 3 lines

Long term we certainly want to have a look at implementing something in the ccw bios, but this (tcp stack, virtio net, etc) will take some (a lot?) more time.

Just an idea: There's a complete TFTP-boot-over-virtio-net stack in SLOF, written by IBM ... maybe you could use that for s390x, too?

Quoted 5 lines

This patch (1) has another advantage.
Right now we load the ccw bios all the time, even for -kernel xxx boot, to allow the guest user to use chreipl to reboot from a disk. With this in place we can rework our ccw bios loader to load the ccw bios lazily as well.

But this "RAM"-loader here has still the problem that the images are not restored during reboot/reset, right? ... so before you're going to implement that as well, let me ask another question: Did you already have a look at the generic loader device? I think that might already provide what you're trying to implement here, so your problem could maybe be solved with some few lines of creating an instance of that device instead (see
https://lists.gnu.org/archive/html/qemu-devel/2017-01/msg05366.html for an example how to use that device).

Thomas

#6 lore raw

Re: [Qemu-devel] [PATCH 1/5] elf-loader: Allow late loading of elf

Quoted 17 lines · Thomas Huth
Quoted 16 lines · Christian Borntraeger
Quoted 14 lines · Thomas Huth
Quoted 9 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.

Could you maybe also explain here why you need such a delayed ELF loading? Why can't you load the s390-netboot.img at the same time as s390-ccw.img?

Quoted 8 lines
Quoted 1 line

Please read the cover letter for some details how to build such a netrom.

Sure, understood, but I still did not see an explanation why this can't be loaded as "ROM", too / why it needs to be loaded "delayed"? Does the image data need to be writable in memory? Or is the information not available yet at that point in time, whether the user wants to do a network boot or not? Don't get me wrong, I'm basically fine with this patch, I'm just missing some explanation *why* you have to do it this way.

As I already wrote, the rom will be big. kernel + ramdisk will take easily 10-30Mbytes. This is loaded twice (in the rom as data and into the guest) So this will waste lets say 60Mbyte per guest for nothing.

You know yourself that on s390 we do have >100 guests in production environment.

#7 lore raw

Re: [Qemu-devel] [PATCH 1/5] elf-loader: Allow late loading of elf

Quoted 27 lines · Christian Borntraeger
Quoted 17 lines · Thomas Huth
Quoted 16 lines · Christian Borntraeger
Quoted 14 lines · Thomas Huth
Quoted 9 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.

Could you maybe also explain here why you need such a delayed ELF loading? Why can't you load the s390-netboot.img at the same time as s390-ccw.img?

Quoted 8 lines
Quoted 1 line

Please read the cover letter for some details how to build such a netrom.

Sure, understood, but I still did not see an explanation why this can't be loaded as "ROM", too / why it needs to be loaded "delayed"? Does the image data need to be writable in memory? Or is the information not available yet at that point in time, whether the user wants to do a network boot or not? Don't get me wrong, I'm basically fine with this patch, I'm just missing some explanation *why* you have to do it this way.

Quoted 3 lines

As I already wrote, the rom will be big. kernel + ramdisk will take easily 10-30Mbytes. This is loaded twice (in the rom as data and into the guest) So this will waste lets say 60Mbyte per guest for nothing.

OK, now that's a proper explanation, thanks! ... it would maybe be helpful for future reviewers to include such a proper statement in the patch description (or cover letter), too.

Thomas

#8 lore raw

Re: [Qemu-devel] [PATCH 1/5] elf-loader: Allow late loading of elf

In reply to Thomas Huth
Quoted 49 lines · Thomas Huth
Quoted 9 lines · Christian Borntraeger
Quoted 8 lines · Thomas Huth
Quoted 7 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.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

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.

Could you maybe also explain here why you need such a delayed ELF loading? Why can't you load the s390-netboot.img at the same time as s390-ccw.img?

Please read the cover letter for some details how to build such a netrom.

Sure, understood, but I still did not see an explanation why this can't be loaded as "ROM", too / why it needs to be loaded "delayed"? Does the image data need to be writable in memory? Or is the information not available yet at that point in time, whether the user wants to do a network boot or not? Don't get me wrong, I'm basically fine with this patch, I'm just missing some explanation *why* you have to do it this way.

Quoted 3 lines

Long term we certainly want to have a look at implementing something in the ccw bios, but this (tcp stack, virtio net, etc) will take some (a lot?) more time.

Just an idea: There's a complete TFTP-boot-over-virtio-net stack in SLOF, written by IBM ... maybe you could use that for s390x, too?

Quoted 5 lines

This patch (1) has another advantage.
Right now we load the ccw bios all the time, even for -kernel xxx boot, to allow the guest user to use chreipl to reboot from a disk. With this in place we can rework our ccw bios loader to load the ccw bios lazily as well.

But this "RAM"-loader here has still the problem that the images are not restored during reboot/reset, right? ... so before you're going to implement that as well, let me ask another question: Did you already have a look at the generic loader device? I think that might already provide what you're trying to implement here, so your problem could maybe be solved with some few lines of creating an instance of that device instead (see
https://lists.gnu.org/archive/html/qemu-devel/2017-01/msg05366.html for an example how to use that device).

Quoted 2 lines

Thomas

Hi Thomas,

I did think of the generic loader device, but doesn't the generic loader device also load ELF's as ROMs? This would again bring us back to the problem of ROMs cannot be loaded after initializations of the ROM. So if a user wants to switch boot device from disk to network device we still wouldn't be able to load the ROM?

Thanks
Farhan

#9 lore raw

Re: [Qemu-devel] [PATCH 1/5] elf-loader: Allow late loading of elf

Quoted 58 lines · Farhan Ali
Quoted 52 lines · Thomas Huth
Quoted 12 lines · Christian Borntraeger
Quoted 11 lines · Thomas Huth
Quoted 9 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.

Quoted 6 lines
Quoted 3 lines

Could you maybe also explain here why you need such a delayed ELF loading? Why can't you load the s390-netboot.img at the same time as s390-ccw.img?

Please read the cover letter for some details how to build such a netrom.

Sure, understood, but I still did not see an explanation why this can't be loaded as "ROM", too / why it needs to be loaded "delayed"? Does the image data need to be writable in memory? Or is the information not available yet at that point in time, whether the user wants to do a network boot or not? Don't get me wrong, I'm basically fine with this patch, I'm just missing some explanation *why* you have to do it this way.

Quoted 4 lines

Long term we certainly want to have a look at implementing something in the ccw bios, but this (tcp stack, virtio net, etc) will take some (a lot?)
more time.

Just an idea: There's a complete TFTP-boot-over-virtio-net stack in SLOF, written by IBM ... maybe you could use that for s390x, too?

Quoted 5 lines

This patch (1) has another advantage.
Right now we load the ccw bios all the time, even for -kernel xxx boot, to allow the guest user to use chreipl to reboot from a disk. With this in place we can rework our ccw bios loader to load the ccw bios lazily as well.

But this "RAM"-loader here has still the problem that the images are not restored during reboot/reset, right? ... so before you're going to implement that as well, let me ask another question: Did you already have a look at the generic loader device? I think that might already provide what you're trying to implement here, so your problem could maybe be solved with some few lines of creating an instance of that device instead (see
https://lists.gnu.org/archive/html/qemu-devel/2017-01/msg05366.html for an example how to use that device).

Quoted 2 lines

Thomas

Quoted 7 lines

Hi Thomas,

I did think of the generic loader device, but doesn't the generic loader device also load ELF's as ROMs? This would again bring us back to the problem of ROMs cannot be loaded after initializations of the ROM. So if a user wants to switch boot device from disk to network device we still wouldn't be able to load the ROM?

OK, never mind, I just had another look at the generic loader code, and it seems like the ELF loading is also only done there during the realize() function, not during the reset() function. Sorry, I somehow got that wrong when I looked at that code for the first time... :-/

Thomas

#10 lore raw

PATCH 2/5 s390x/ipl: Extend S390IPLState to support network boot

In reply to Cornelia Huck

From: 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
index 2e2664f22e..fd656718a7 100644
@@ -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
index c89109585a..4ad9a7c05e 100644
@@ -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
index 4f0d62b2d8..40914fde6f 100644
@@ -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
index 9cfb09057e..afa4148e6b 100644
@@ -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
index f588b80a6e..f2377a3e0e 100644
@@ -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
#11 lore raw

PATCH 3/5 s390x/ipl: Load network boot image

In reply to 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.

---
 hw/s390x/ipl.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/s390x/ipl.h |  4 ++-
 2 files changed, 89 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +86 -0
index fd656718a7..80e05cc7a5 100644
@@ -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,84 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)
     return false;
 }
 
+static int load_netboot_image(void)
+{
+
+    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_report("Failed to find memory region at address 0");
+        goto out;
+    }
+
+    ram_ptr = memory_region_get_ram_ptr(mr);
+    if (!ram_ptr) {
+        error_report("No RAM found");
+        goto unref_mr;
+    }
+
+    netboot_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, ipl->netboot_fw);
+    if (netboot_filename == NULL) {
+        error_report("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;
+    }
+
+    g_free(netboot_filename);
+
+unref_mr:
+    memory_region_unref(mr);
+out:
+    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)
@@ -298,6 +377,13 @@ void s390_ipl_prepare_cpu(S390CPU *cpu)
             ipl->iplb_valid = s390_gen_initial_iplb(ipl);
         }
     }
+    if (ipl->netboot) {
+        if (load_netboot_image() < 0) {
+            error_report("Failed to load network bootloader");
+            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
index 4ad9a7c05e..46930e4c64 100644
@@ -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
#12 lore raw

Re: [Qemu-devel] [PATCH 3/5] s390x/ipl: Load network boot image

Quoted 45 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.

---
 hw/s390x/ipl.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/s390x/ipl.h |  4 ++-
 2 files changed, 89 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +7 -0
index fd656718a7..80e05cc7a5 100644
@@ -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);
 

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

Quoted 6 lines
hw/s390x/ipl.c +3 -0
@@ -259,12 +266,84 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)
     return false;
 }
 
+static int load_netboot_image(void)
+{
+

Please remove that empty line above.

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

Quoted 11 lines
hw/s390x/ipl.c +11 -0
+    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_report("Failed to find memory region at address 0");
+        goto out;

<bikeshedpainting>I'd prefer a "return -1 here</bikeshedpainting>

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

Quoted 13 lines
hw/s390x/ipl.c +13 -0
+    }
+
+    ram_ptr = memory_region_get_ram_ptr(mr);
+    if (!ram_ptr) {
+        error_report("No RAM found");
+        goto unref_mr;
+    }
+
+    netboot_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, ipl->netboot_fw);
+    if (netboot_filename == NULL) {
+        error_report("Could not find network bootloader");
+        goto unref_mr;
+    }

So you're doing error_report() here already ...

Quoted 54 lines
hw/s390x/ipl.c +44 -0
+    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;
+    }
+
+    g_free(netboot_filename);
+
+unref_mr:
+    memory_region_unref(mr);
+out:
+    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)

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

Quoted 6 lines
hw/s390x/ipl.c +3 -0
@@ -298,6 +377,13 @@ void s390_ipl_prepare_cpu(S390CPU *cpu)
             ipl->iplb_valid = s390_gen_initial_iplb(ipl);
         }
     }
+    if (ipl->netboot) {
+        if (load_netboot_image() < 0) {
+            error_report("Failed to load network bootloader");

... and then you do another error_report here again ... so one error gets reported with two error message. Wouldn't it be nicer to rather do error_setg(...) in load_netboot_image() and then report only one error at this level here?

Quoted 30 lines
hw/s390x/ipl.c +4 -0
+            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
index 4ad9a7c05e..46930e4c64 100644
@@ -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;
#13 lore raw

Re: [Qemu-devel] [PATCH 3/5] s390x/ipl: Load network boot image

Hi Thomas,

Thanks for the review.

Quoted 49 lines · Thomas Huth
Quoted 48 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.

---
 hw/s390x/ipl.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/s390x/ipl.h |  4 ++-
 2 files changed, 89 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +7 -0
index fd656718a7..80e05cc7a5 100644
@@ -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,84 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)
     return false;
 }
 
Quoted 6 lines

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

Quoted 3 lines
hw/s390x/ipl.c +3 -0
+static int load_netboot_image(void)
+{
+

Please remove that empty line above.

Will do.

Quoted 12 lines

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

Quoted 11 lines
hw/s390x/ipl.c +11 -0
+    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_report("Failed to find memory region at address 0");
+        goto out;
Quoted 2 lines

<bikeshedpainting>I'd prefer a "return -1 here</bikeshedpainting>

will make the change.

Quoted 68 lines

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

Quoted 13 lines
hw/s390x/ipl.c +13 -0
+    }
+
+    ram_ptr = memory_region_get_ram_ptr(mr);
+    if (!ram_ptr) {
+        error_report("No RAM found");
+        goto unref_mr;
+    }
+
+    netboot_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, ipl->netboot_fw);
+    if (netboot_filename == NULL) {
+        error_report("Could not find network bootloader");
+        goto unref_mr;
+    }

So you're doing error_report() here already ...

Quoted 52 lines
hw/s390x/ipl.c +44 -0
+    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;
+    }
+
+    g_free(netboot_filename);
+
+unref_mr:
+    memory_region_unref(mr);
+out:
+    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);
 }
 
Quoted 14 lines

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

Quoted 8 lines
hw/s390x/ipl.c +3 -0
 IplParameterBlock *s390_ipl_get_iplb(void)
@@ -298,6 +377,13 @@ void s390_ipl_prepare_cpu(S390CPU *cpu)
             ipl->iplb_valid = s390_gen_initial_iplb(ipl);
         }
     }
+    if (ipl->netboot) {
+        if (load_netboot_image() < 0) {
+            error_report("Failed to load network bootloader");

... and then you do another error_report here again ... so one error gets reported with two error message. Wouldn't it be nicer to rather do error_setg(...) in load_netboot_image() and then report only one error at this level here?

What would be the advantage of doing that?

Thanks
Farhan

Quoted 33 lines
Quoted 30 lines
hw/s390x/ipl.c +4 -0
+            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
index 4ad9a7c05e..46930e4c64 100644
@@ -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;
#14 lore raw

Re: [Qemu-devel] [PATCH 3/5] s390x/ipl: Load network boot image

Quoted 7 lines · Farhan Ali

Hi Thomas,

Thanks for the review.

Quoted 2 lines · Thomas Huth
Quoted 1 line · Cornelia Huck

From: Farhan Ali <[email protected]>

[...]

Quoted 86 lines
Quoted 71 lines
Quoted 10 lines
hw/s390x/ipl.c +9 -0
+    }
+
+    ram_ptr = memory_region_get_ram_ptr(mr);
+    if (!ram_ptr) {
+        error_report("No RAM found");
+        goto unref_mr;
+    }
+
+    netboot_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,

ipl->netboot_fw);

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

Quoted 4 lines
hw/s390x/ipl.c +4 -0
+    if (netboot_filename == NULL) {
+        error_report("Could not find network bootloader");
+        goto unref_mr;
+    }

So you're doing error_report() here already ...

Quoted 54 lines

+ img_size = load_elf_ram(netboot_filename, NULL, NULL,
&ipl->start_addr,

hw/s390x/ipl.c +4 -0
+                            NULL, NULL, 1, EM_S390, 0, 0, NULL, false);
+
+    if (img_size < 0) {
+        img_size = load_image_size(netboot_filename, ram_ptr,

ram_size);

hw/s390x/ipl.c +39 -0
+        ipl->start_addr = KERN_IMAGE_START;
+    }
+
+    g_free(netboot_filename);
+
+unref_mr:
+    memory_region_unref(mr);
+out:
+    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);
 }
Quoted 14 lines

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

Quoted 8 lines

IplParameterBlock *s390_ipl_get_iplb(void)

hw/s390x/ipl.c +3 -0
@@ -298,6 +377,13 @@ void s390_ipl_prepare_cpu(S390CPU *cpu)
             ipl->iplb_valid = s390_gen_initial_iplb(ipl);
         }
     }
+    if (ipl->netboot) {
+        if (load_netboot_image() < 0) {
+            error_report("Failed to load network bootloader");

... and then you do another error_report here again ... so one error gets reported with two error message. Wouldn't it be nicer to rather do error_setg(...) in load_netboot_image() and then report only one error at this level here?

Quoted 1 line

What would be the advantage of doing that?

It's just good coding style to report an error only once, at the outermost calling function. Otherwise the same error gets reported multiple times to the user, with different error messages, and that can easily get confusing. It's likely not a big problem here yet, since the call depths is only 2 functions, but imagine a situation where you've got a call depth or 5 or more and an error is reported at every depths... that's ugly. So this is why we've got error_setg() and friends in QEMU.

Thomas

#15 lore raw

Re: [Qemu-devel] [PATCH 3/5] s390x/ipl: Load network boot image

Quoted 17 lines · Thomas Huth
Quoted 7 lines
Quoted 5 lines

... and then you do another error_report here again ... so one error gets reported with two error message. Wouldn't it be nicer to rather do error_setg(...) in load_netboot_image() and then report only one error at this level here?

What would be the advantage of doing that?

It's just good coding style to report an error only once, at the outermost calling function. Otherwise the same error gets reported multiple times to the user, with different error messages, and that can easily get confusing. It's likely not a big problem here yet, since the call depths is only 2 functions, but imagine a situation where you've got a call depth or 5 or more and an error is reported at every depths... that's ugly. So this is why we've got error_setg() and friends in QEMU.

Quoted 1 line

Thomas

Farhan was already convinced. Can you check v2 of this patch set? Thanks for doing the review :-)

#16 lore raw

Re: [Qemu-devel] [PATCH 3/5] s390x/ipl: Load network boot image

In reply to Thomas Huth
Quoted 106 lines · Thomas Huth
Quoted 7 lines · Farhan Ali

Hi Thomas,

Thanks for the review.

Quoted 2 lines · Thomas Huth
Quoted 1 line · Cornelia Huck

From: Farhan Ali <[email protected]>

[...]

Quoted 86 lines
Quoted 71 lines
Quoted 10 lines
hw/s390x/ipl.c +9 -0
+    }
+
+    ram_ptr = memory_region_get_ram_ptr(mr);
+    if (!ram_ptr) {
+        error_report("No RAM found");
+        goto unref_mr;
+    }
+
+    netboot_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,

ipl->netboot_fw);

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

Quoted 4 lines
hw/s390x/ipl.c +4 -0
+    if (netboot_filename == NULL) {
+        error_report("Could not find network bootloader");
+        goto unref_mr;
+    }

So you're doing error_report() here already ...

Quoted 54 lines

+ img_size = load_elf_ram(netboot_filename, NULL, NULL,
&ipl->start_addr,

hw/s390x/ipl.c +4 -0
+                            NULL, NULL, 1, EM_S390, 0, 0, NULL, false);
+
+    if (img_size < 0) {
+        img_size = load_image_size(netboot_filename, ram_ptr,

ram_size);

hw/s390x/ipl.c +39 -0
+        ipl->start_addr = KERN_IMAGE_START;
+    }
+
+    g_free(netboot_filename);
+
+unref_mr:
+    memory_region_unref(mr);
+out:
+    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);
 }
Quoted 14 lines

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

Quoted 8 lines

IplParameterBlock *s390_ipl_get_iplb(void)

hw/s390x/ipl.c +3 -0
@@ -298,6 +377,13 @@ void s390_ipl_prepare_cpu(S390CPU *cpu)
             ipl->iplb_valid = s390_gen_initial_iplb(ipl);
         }
     }
+    if (ipl->netboot) {
+        if (load_netboot_image() < 0) {
+            error_report("Failed to load network bootloader");

... and then you do another error_report here again ... so one error gets reported with two error message. Wouldn't it be nicer to rather do error_setg(...) in load_netboot_image() and then report only one error at this level here?

Quoted 1 line

What would be the advantage of doing that?

It's just good coding style to report an error only once, at the outermost calling function. Otherwise the same error gets reported multiple times to the user, with different error messages, and that can easily get confusing. It's likely not a big problem here yet, since the call depths is only 2 functions, but imagine a situation where you've got a call depth or 5 or more and an error is reported at every depths... that's ugly. So this is why we've got error_setg() and friends in QEMU.

Quoted 2 lines

Thomas

Yes, I realized it. We update with a version 2. Would appreciate your feedback on it :)

Thanks
Farhan

#17 lore raw

PATCH 4/5 pc-bios/s390-ccw: Use the ccw bios to start the network boot

In reply to Cornelia Huck

From: 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
index 611102e3ef..b21c877b53 100644
@@ -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
index 86abc56a90..890aed9ece 100644
@@ -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
index 345b848752..0946766d86 100644
@@ -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
index b333734955..6ee93d56db 100644
@@ -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
index eb35ea5faf..3388a423e5 100644
@@ -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
#18 lore raw

PATCH 5/5 pc-bios/s390-ccw.img: rebuild image

In reply to Cornelia Huck

Contains 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
index cf05bf0be2299ec6512375ef4b38179f22558ddc..2a4adfa654844040dbc84e90a9c2e0af56fdb9fa 100644
GIT binary patch
Signature · 1 line
2.11.0
#19 lore raw
In reply to Cornelia Huck
Quoted 2 lines · Cornelia Huck

This patchset implements network boot for s390x. You need to build a s390-netboot.img to actually perform the work (not included).

Do you plan to include this into the upstream QEMU repository later, or will this stay an external binary?

Quoted 2 lines

Basically, we add support for virtio-net devices into the ipl code and update the ccw bios to handle this as well.

Just out of curiosity: What's the reason for shipping an additional binary here? Couldn't it be linked into the ccw bios as well (so that it's easier for the user to select a different version with the -bios parameter)?

Thomas

#20 lore raw
Quoted 7 lines · Thomas Huth
Quoted 2 lines · Cornelia Huck

This patchset implements network boot for s390x. You need to build a s390-netboot.img to actually perform the work (not included).

Do you plan to include this into the upstream QEMU repository later, or will this stay an external binary?

Quoted 7 lines
Quoted 2 lines

Basically, we add support for virtio-net devices into the ipl code and update the ccw bios to handle this as well.

Just out of curiosity: What's the reason for shipping an additional binary here? Couldn't it be linked into the ccw bios as well (so that it's easier for the user to select a different version with the -bios parameter)?

The "other binary" (s390-netboot.img) is the equivalent of grub or pxelinux in an x86 network boot environment. That one usually comes from a different entity and different department :).

I haven't looked at the patches in detail, but do they follow the "normal" PXE boot flow? Do they do a DHCP request, send a proper Vendor-Class-Identifier for s390x, fetch the binary described by the "filename" property in the DHCP ack via TFTP from next-server and run that one then?

It would be very good to stick to that flow, so that you don't confuse your network admins :).

Alex

#21 lore raw
Quoted 13 lines · Alexander Graf
Quoted 10 lines · Thomas Huth
Quoted 2 lines · Cornelia Huck

This patchset implements network boot for s390x. You need to build a s390-netboot.img to actually perform the work (not included).

Do you plan to include this into the upstream QEMU repository later, or will this stay an external binary?

Quoted 2 lines

Basically, we add support for virtio-net devices into the ipl code and update the ccw bios to handle this as well.

Quoted 8 lines
Quoted 4 lines

Just out of curiosity: What's the reason for shipping an additional binary here? Couldn't it be linked into the ccw bios as well (so that it's easier for the user to select a different version with the -bios parameter)?

The "other binary" (s390-netboot.img) is the equivalent of grub or pxelinux in an x86 network boot environment. That one usually comes from a different entity and different department :).

I'd rather compare the other binary to an option ROM. At this point in time we there's no netboot ROM, but a set of instructions on how to build a netboot binary from a kernel and a ramdisk, the series coverletter contains a brief version of that.

Quoted 6 lines

I haven't looked at the patches in detail, but do they follow the "normal" PXE boot flow? Do they do a DHCP request, send a proper Vendor-Class-Identifier for s390x, fetch the binary described by the "filename" property in the DHCP ack via TFTP from next-server and run that one then?

It's currently not described with that level of detail, but the idea is to skip the step of loading a syslinux equivalent, and to immediately fetch the PXELINUX config file from the TFT next server aka siaddr and load the kernel and ramdisk specified therein.
I.e. a simulation of the PXELINUX process is done in a similar fashion to petitboot PXE boot.

Quoted 7 lines

It would be very good to stick to that flow, so that you don't confuse your network admins :).

Alex

Signature · 8 lines
Mit freundlichen Grüßen/Kind Regards
   Viktor Mihajlovski

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martina Köderitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294