Re: [PULL 13/18] hw/core: implement a guest-loader to support static hypervisor guests
Philippe Mathieu-Daudé writes: > On 3/15/21 5:59 PM, Christian Borntraeger wrote: >> On 15.03.21 17:51, Philippe Mathieu-Daudé wrote: >> >>> diff --git a/hw/core/Kconfig b/hw/core/Kconfig >>> index fdf03514d7d..9397503656d 100644 >>> --- a/hw/core/Kconfig >>> +++ b/hw/core/Kconfig >>> @@ -11,6 +11,11 @@ config GENERIC_LOADER >>> bool >>> default y >>> >>> +config GUEST_LOADER >>> + bool >>> + default y >>> + depends on TCG >>> + >>> config OR_IRQ >>> bool >>> >>> diff --git a/hw/core/meson.build b/hw/core/meson.build >>> index 9cd72edf513..59f1605bb07 100644 >>> --- a/hw/core/meson.build >>> +++ b/hw/core/meson.build >>> @@ -16,6 +16,7 @@ >>> common_ss.add(files('cpu.c')) >>> common_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) >>> common_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: >>> files('generic-loader.c')) >>> +common_ss.add(when: ['CONFIG_GUEST_LOADER', fdt], if_true: >>> files('guest-loader.c')) >>> common_ss.add(when: 'CONFIG_OR_IRQ', if_true: files('or-irq.c')) >>> common_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: >>> files('platform-bus.c')) >>> common_ss.add(when: 'CONFIG_PTIMER', if_true: files('ptimer.c')) >>> @@ -37,8 +38,6 @@ >>> 'clock-vmstate.c', >>> )) >>> >>> -softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('guest-loader.c')) >>> - >>> specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files( >>> 'machine-qmp-cmds.c', >>> 'numa.c', >> >> >> Also >> Tested-by: Christian Borntraeger > > Thanks Christian! Can you send that to me as a proper patch (unless Christian wants to take it through the s390 trees)? -- Alex Bennée
Re: [PULL 13/18] hw/core: implement a guest-loader to support static hypervisor guests
On 3/15/21 5:59 PM, Christian Borntraeger wrote: > On 15.03.21 17:51, Philippe Mathieu-Daudé wrote: > >> diff --git a/hw/core/Kconfig b/hw/core/Kconfig >> index fdf03514d7d..9397503656d 100644 >> --- a/hw/core/Kconfig >> +++ b/hw/core/Kconfig >> @@ -11,6 +11,11 @@ config GENERIC_LOADER >> bool >> default y >> >> +config GUEST_LOADER >> + bool >> + default y >> + depends on TCG >> + >> config OR_IRQ >> bool >> >> diff --git a/hw/core/meson.build b/hw/core/meson.build >> index 9cd72edf513..59f1605bb07 100644 >> --- a/hw/core/meson.build >> +++ b/hw/core/meson.build >> @@ -16,6 +16,7 @@ >> common_ss.add(files('cpu.c')) >> common_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) >> common_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: >> files('generic-loader.c')) >> +common_ss.add(when: ['CONFIG_GUEST_LOADER', fdt], if_true: >> files('guest-loader.c')) >> common_ss.add(when: 'CONFIG_OR_IRQ', if_true: files('or-irq.c')) >> common_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: >> files('platform-bus.c')) >> common_ss.add(when: 'CONFIG_PTIMER', if_true: files('ptimer.c')) >> @@ -37,8 +38,6 @@ >> 'clock-vmstate.c', >> )) >> >> -softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('guest-loader.c')) >> - >> specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files( >> 'machine-qmp-cmds.c', >> 'numa.c', > > > Also > Tested-by: Christian Borntraeger Thanks Christian!
Re: [PULL 13/18] hw/core: implement a guest-loader to support static hypervisor guests
On 15.03.21 17:51, Philippe Mathieu-Daudé wrote: diff --git a/hw/core/Kconfig b/hw/core/Kconfig index fdf03514d7d..9397503656d 100644 --- a/hw/core/Kconfig +++ b/hw/core/Kconfig @@ -11,6 +11,11 @@ config GENERIC_LOADER bool default y +config GUEST_LOADER +bool +default y +depends on TCG + config OR_IRQ bool diff --git a/hw/core/meson.build b/hw/core/meson.build index 9cd72edf513..59f1605bb07 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -16,6 +16,7 @@ common_ss.add(files('cpu.c')) common_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) common_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: files('generic-loader.c')) +common_ss.add(when: ['CONFIG_GUEST_LOADER', fdt], if_true: files('guest-loader.c')) common_ss.add(when: 'CONFIG_OR_IRQ', if_true: files('or-irq.c')) common_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('platform-bus.c')) common_ss.add(when: 'CONFIG_PTIMER', if_true: files('ptimer.c')) @@ -37,8 +38,6 @@ 'clock-vmstate.c', )) -softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('guest-loader.c')) - specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files( 'machine-qmp-cmds.c', 'numa.c', Also Tested-by: Christian Borntraeger
Re: [PULL 13/18] hw/core: implement a guest-loader to support static hypervisor guests
On 15.03.21 17:44, Philippe Mathieu-Daudé wrote: On 3/15/21 5:16 PM, Christian Borntraeger wrote: On 08.03.21 14:50, Alex Bennée wrote: Hypervisors, especially type-1 ones, need the firmware/bootcode to put their initial guest somewhere in memory and pass the information to it via platform data. The guest-loader is modelled after the generic loader for exactly this sort of purpose: $QEMU $ARGS -kernel ~/xen.git/xen/xen \ -append "dom0_mem=1G,max:1G loglvl=all guest_loglvl=all" \ -device guest-loader,addr=0x4200,kernel=Image,bootargs="root=/dev/sda2 ro console=hvc0 earlyprintk=xen" \ -device guest-loader,addr=0x4700,initrd=rootfs.cpio Signed-off-by: Alex Bennée Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20210303173642.3805-5-alex.ben...@linaro.org> This now results in /usr/bin/ld: libcommon.fa.p/hw_core_guest-loader.c.o: in function `loader_insert_platform_data': build/../hw/core/guest-loader.c:56: undefined reference to `qemu_fdt_add_subnode' /usr/bin/ld: build/../hw/core/guest-loader.c:57: undefined reference to `qemu_fdt_setprop' /usr/bin/ld: build/../hw/core/guest-loader.c:61: undefined reference to `qemu_fdt_setprop_string_array' /usr/bin/ld: build/../hw/core/guest-loader.c:68: undefined reference to `qemu_fdt_setprop_string' /usr/bin/ld: build/../hw/core/guest-loader.c:74: undefined reference to `qemu_fdt_setprop_string_array' collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. when building s390-softmmu on s390 with --disable-fdt, which was in my build script. Oops. Quick fix: -- >8 -- diff --git a/hw/core/meson.build b/hw/core/meson.build index 9cd72edf513..5827996206e 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -37,7 +37,7 @@ 'clock-vmstate.c', )) -softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('guest-loader.c')) +softmmu_ss.add(when: ['CONFIG_TCG', fdt], if_true: files('guest-loader.c')) specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files( 'machine-qmp-cmds.c', At least this one is Tested-by: Christian Borntraeger
Re: [PULL 13/18] hw/core: implement a guest-loader to support static hypervisor guests
On 3/15/21 5:44 PM, Philippe Mathieu-Daudé wrote: > On 3/15/21 5:16 PM, Christian Borntraeger wrote: >> >> >> On 08.03.21 14:50, Alex Bennée wrote: >>> Hypervisors, especially type-1 ones, need the firmware/bootcode to put >>> their initial guest somewhere in memory and pass the information to it >>> via platform data. The guest-loader is modelled after the generic >>> loader for exactly this sort of purpose: >>> >>> $QEMU $ARGS -kernel ~/xen.git/xen/xen \ >>> -append "dom0_mem=1G,max:1G loglvl=all guest_loglvl=all" \ >>> -device >>> guest-loader,addr=0x4200,kernel=Image,bootargs="root=/dev/sda2 ro >>> console=hvc0 earlyprintk=xen" \ >>> -device guest-loader,addr=0x4700,initrd=rootfs.cpio >>> >>> Signed-off-by: Alex Bennée >>> Reviewed-by: Alistair Francis >>> Reviewed-by: Philippe Mathieu-Daudé >>> Message-Id: <20210303173642.3805-5-alex.ben...@linaro.org> >>> >> >> This now results in >> >> /usr/bin/ld: libcommon.fa.p/hw_core_guest-loader.c.o: in function >> `loader_insert_platform_data': >> build/../hw/core/guest-loader.c:56: undefined reference to >> `qemu_fdt_add_subnode' >> /usr/bin/ld: build/../hw/core/guest-loader.c:57: undefined reference >> to `qemu_fdt_setprop' >> /usr/bin/ld: build/../hw/core/guest-loader.c:61: undefined reference >> to `qemu_fdt_setprop_string_array' >> /usr/bin/ld: build/../hw/core/guest-loader.c:68: undefined reference >> to `qemu_fdt_setprop_string' >> /usr/bin/ld: build/../hw/core/guest-loader.c:74: undefined reference >> to `qemu_fdt_setprop_string_array' >> collect2: error: ld returned 1 exit status >> ninja: build stopped: subcommand failed. >> >> when building s390-softmmu on s390 with --disable-fdt, which was in my >> build script. >> > > Oops. Quick fix: > > -- >8 -- > diff --git a/hw/core/meson.build b/hw/core/meson.build > index 9cd72edf513..5827996206e 100644 > --- a/hw/core/meson.build > +++ b/hw/core/meson.build > @@ -37,7 +37,7 @@ >'clock-vmstate.c', > )) > > -softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('guest-loader.c')) > +softmmu_ss.add(when: ['CONFIG_TCG', fdt], if_true: files('guest-loader.c')) > > specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files( >'machine-qmp-cmds.c', > > --- > > But better is a Kconfig entry to be able to deselect this > device. -- >8 -- diff --git a/hw/core/Kconfig b/hw/core/Kconfig index fdf03514d7d..9397503656d 100644 --- a/hw/core/Kconfig +++ b/hw/core/Kconfig @@ -11,6 +11,11 @@ config GENERIC_LOADER bool default y +config GUEST_LOADER +bool +default y +depends on TCG + config OR_IRQ bool diff --git a/hw/core/meson.build b/hw/core/meson.build index 9cd72edf513..59f1605bb07 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -16,6 +16,7 @@ common_ss.add(files('cpu.c')) common_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) common_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: files('generic-loader.c')) +common_ss.add(when: ['CONFIG_GUEST_LOADER', fdt], if_true: files('guest-loader.c')) common_ss.add(when: 'CONFIG_OR_IRQ', if_true: files('or-irq.c')) common_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('platform-bus.c')) common_ss.add(when: 'CONFIG_PTIMER', if_true: files('ptimer.c')) @@ -37,8 +38,6 @@ 'clock-vmstate.c', )) -softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('guest-loader.c')) - specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files( 'machine-qmp-cmds.c', 'numa.c', ---
Re: [PULL 13/18] hw/core: implement a guest-loader to support static hypervisor guests
On 3/15/21 5:16 PM, Christian Borntraeger wrote: > > > On 08.03.21 14:50, Alex Bennée wrote: >> Hypervisors, especially type-1 ones, need the firmware/bootcode to put >> their initial guest somewhere in memory and pass the information to it >> via platform data. The guest-loader is modelled after the generic >> loader for exactly this sort of purpose: >> >> $QEMU $ARGS -kernel ~/xen.git/xen/xen \ >> -append "dom0_mem=1G,max:1G loglvl=all guest_loglvl=all" \ >> -device >> guest-loader,addr=0x4200,kernel=Image,bootargs="root=/dev/sda2 ro >> console=hvc0 earlyprintk=xen" \ >> -device guest-loader,addr=0x4700,initrd=rootfs.cpio >> >> Signed-off-by: Alex Bennée >> Reviewed-by: Alistair Francis >> Reviewed-by: Philippe Mathieu-Daudé >> Message-Id: <20210303173642.3805-5-alex.ben...@linaro.org> >> > > This now results in > > /usr/bin/ld: libcommon.fa.p/hw_core_guest-loader.c.o: in function > `loader_insert_platform_data': > build/../hw/core/guest-loader.c:56: undefined reference to > `qemu_fdt_add_subnode' > /usr/bin/ld: build/../hw/core/guest-loader.c:57: undefined reference > to `qemu_fdt_setprop' > /usr/bin/ld: build/../hw/core/guest-loader.c:61: undefined reference > to `qemu_fdt_setprop_string_array' > /usr/bin/ld: build/../hw/core/guest-loader.c:68: undefined reference > to `qemu_fdt_setprop_string' > /usr/bin/ld: build/../hw/core/guest-loader.c:74: undefined reference > to `qemu_fdt_setprop_string_array' > collect2: error: ld returned 1 exit status > ninja: build stopped: subcommand failed. > > when building s390-softmmu on s390 with --disable-fdt, which was in my > build script. > Oops. Quick fix: -- >8 -- diff --git a/hw/core/meson.build b/hw/core/meson.build index 9cd72edf513..5827996206e 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -37,7 +37,7 @@ 'clock-vmstate.c', )) -softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('guest-loader.c')) +softmmu_ss.add(when: ['CONFIG_TCG', fdt], if_true: files('guest-loader.c')) specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files( 'machine-qmp-cmds.c', --- But better is a Kconfig entry to be able to deselect this device.
Re: [PULL 13/18] hw/core: implement a guest-loader to support static hypervisor guests
On 08.03.21 14:50, Alex Bennée wrote: Hypervisors, especially type-1 ones, need the firmware/bootcode to put their initial guest somewhere in memory and pass the information to it via platform data. The guest-loader is modelled after the generic loader for exactly this sort of purpose: $QEMU $ARGS -kernel ~/xen.git/xen/xen \ -append "dom0_mem=1G,max:1G loglvl=all guest_loglvl=all" \ -device guest-loader,addr=0x4200,kernel=Image,bootargs="root=/dev/sda2 ro console=hvc0 earlyprintk=xen" \ -device guest-loader,addr=0x4700,initrd=rootfs.cpio Signed-off-by: Alex Bennée Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20210303173642.3805-5-alex.ben...@linaro.org> This now results in /usr/bin/ld: libcommon.fa.p/hw_core_guest-loader.c.o: in function `loader_insert_platform_data': build/../hw/core/guest-loader.c:56: undefined reference to `qemu_fdt_add_subnode' /usr/bin/ld: build/../hw/core/guest-loader.c:57: undefined reference to `qemu_fdt_setprop' /usr/bin/ld: build/../hw/core/guest-loader.c:61: undefined reference to `qemu_fdt_setprop_string_array' /usr/bin/ld: build/../hw/core/guest-loader.c:68: undefined reference to `qemu_fdt_setprop_string' /usr/bin/ld: build/../hw/core/guest-loader.c:74: undefined reference to `qemu_fdt_setprop_string_array' collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. when building s390-softmmu on s390 with --disable-fdt, which was in my build script.
[PULL 13/18] hw/core: implement a guest-loader to support static hypervisor guests
Hypervisors, especially type-1 ones, need the firmware/bootcode to put their initial guest somewhere in memory and pass the information to it via platform data. The guest-loader is modelled after the generic loader for exactly this sort of purpose: $QEMU $ARGS -kernel ~/xen.git/xen/xen \ -append "dom0_mem=1G,max:1G loglvl=all guest_loglvl=all" \ -device guest-loader,addr=0x4200,kernel=Image,bootargs="root=/dev/sda2 ro console=hvc0 earlyprintk=xen" \ -device guest-loader,addr=0x4700,initrd=rootfs.cpio Signed-off-by: Alex Bennée Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20210303173642.3805-5-alex.ben...@linaro.org> diff --git a/hw/core/guest-loader.h b/hw/core/guest-loader.h new file mode 100644 index 00..07f4b4884b --- /dev/null +++ b/hw/core/guest-loader.h @@ -0,0 +1,34 @@ +/* + * Guest Loader + * + * Copyright (C) 2020 Linaro + * Written by Alex Bennée + * (based on the generic-loader by Li Guang ) + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef GUEST_LOADER_H +#define GUEST_LOADER_H + +#include "hw/qdev-core.h" +#include "qom/object.h" + +struct GuestLoaderState { +/* */ +DeviceState parent_obj; + +/* */ +uint64_t addr; +char *kernel; +char *args; +char *initrd; +}; + +#define TYPE_GUEST_LOADER "guest-loader" +OBJECT_DECLARE_SIMPLE_TYPE(GuestLoaderState, GUEST_LOADER) + +#endif diff --git a/hw/core/guest-loader.c b/hw/core/guest-loader.c new file mode 100644 index 00..bde44e27b4 --- /dev/null +++ b/hw/core/guest-loader.c @@ -0,0 +1,145 @@ +/* + * Guest Loader + * + * Copyright (C) 2020 Linaro + * Written by Alex Bennée + * (based on the generic-loader by Li Guang ) + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +/* + * Much like the generic-loader this is treated as a special device + * inside QEMU. However unlike the generic-loader this device is used + * to load guest images for hypervisors. As part of that process the + * hypervisor needs to have platform information passed to it by the + * lower levels of the stack (e.g. firmware/bootloader). If you boot + * the hypervisor directly you use the guest-loader to load the Dom0 + * or equivalent guest images in the right place in the same way a + * boot loader would. + * + * This is only relevant for full system emulation. + */ + +#include "qemu/osdep.h" +#include "hw/core/cpu.h" +#include "hw/sysbus.h" +#include "sysemu/dma.h" +#include "hw/loader.h" +#include "hw/qdev-properties.h" +#include "qapi/error.h" +#include "qemu/module.h" +#include "guest-loader.h" +#include "sysemu/device_tree.h" +#include "hw/boards.h" + +/* + * Insert some FDT nodes for the loaded blob. + */ +static void loader_insert_platform_data(GuestLoaderState *s, int size, +Error **errp) +{ +MachineState *machine = MACHINE(qdev_get_machine()); +void *fdt = machine->fdt; +g_autofree char *node = g_strdup_printf("/chosen/module@0x%08" PRIx64, +s->addr); +uint64_t reg_attr[2] = {cpu_to_be64(s->addr), cpu_to_be64(size)}; + +if (!fdt) { +error_setg(errp, "Cannot modify FDT fields if the machine has none"); +return; +} + +qemu_fdt_add_subnode(fdt, node); +qemu_fdt_setprop(fdt, node, "reg", _attr, sizeof(reg_attr)); + +if (s->kernel) { +const char *compat[2] = { "multiboot,module", "multiboot,kernel" }; +if (qemu_fdt_setprop_string_array(fdt, node, "compatible", + (char **) , + ARRAY_SIZE(compat)) < 0) { +error_setg(errp, "couldn't set %s/compatible", node); +return; +} +if (s->args) { +if (qemu_fdt_setprop_string(fdt, node, "bootargs", s->args) < 0) { +error_setg(errp, "couldn't set %s/bootargs", node); +} +} +} else if (s->initrd) { +const char *compat[2] = { "multiboot,module", "multiboot,ramdisk" }; +if (qemu_fdt_setprop_string_array(fdt, node, "compatible", + (char **) , + ARRAY_SIZE(compat)) < 0) { +error_setg(errp, "couldn't set %s/compatible", node); +return; +} +} +} + +static void guest_loader_realize(DeviceState *dev, Error **errp) +{ +GuestLoaderState *s = GUEST_LOADER(dev); +char *file = s->kernel ? s->kernel : s->initrd; +int size = 0; + +/* Perform some error checking on the user's options */ +if (s->kernel && s->initrd) { +error_setg(errp, "Cannot specify a kernel and initrd in same