igvm: device tree support
cover igvm: device tree support
This series consists of two patches:
The first patch packs the device tree for microvm. This is a soft prerequisite for the next patch that exposes it via IGVM. Currently the unpacked microvm device tree buffer occupies 1 MiB (the default FDT_MAX_SIZE), while the actual content is well below 4096 bytes. Packing removes the unused space.
The second patch exposes the device tree via IGVM.
This will be consumed by Coconut SVSM with the upcoming device tree support [1]. This will allow SVSM to run on a normal CPU (not AMD SEV-SNP) and execute all its tests using upstream QEMU.
Eventually edk2 will also be able to consume DT via IGVM, but the work has not started yet.
[1] https://github.com/coconut-svsm/svsm/pull/1006
To: [email protected]
Cc: Michael S. Tsirkin <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Gerd Hoffmann <[email protected]>
Cc: Stefano Garzarella <[email protected]>
Cc: Ani Sinha <[email protected]>
Cc: Zhao Liu <[email protected]>
Cc: Oliver Steffen <[email protected]>
---
Luigi Leonardi (2):
hw/i386/microvm: pack device tree
igvm: Fill device tree IGVM parameter field on x86_64
backends/igvm.c | 2 ++ hw/i386/microvm-dt.c | 9 +++++++++ include/system/igvm.h | 2 ++ stubs/igvm.c | 6 ++++++ target/i386/igvm.c | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+)
---
base-commit: 29c042c6e9d4a09d4a0ac3fa54aeb7ee08ce0bdc
change-id: 20260608-microvm_device_tree-0263c3b1be86
Best regards,
Signature · 1 line
Luigi Leonardi <[email protected]>
PATCH 1/2 hw/i386/microvm: pack device tree
After the device tree is generated, it can be packed, significantly reducing its size. This is particularly important with the upcoming support for the device tree via IGVM, which can have stricter memory constraints.
--- hw/i386/microvm-dt.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/i386/microvm-dt.c +9 -0
@@ -43,6 +43,8 @@#include "microvm-dt.h" +#include <libfdt.h> +static bool debug; static void dt_add_microvm_irq(MicrovmMachineState *mms,
@@ -326,6 +328,7 @@ void dt_setup_microvm(MicrovmMachineState *mms)X86MachineState *x86ms =X86_MACHINE (mms);MachineState *ms =MACHINE (mms);int size =0 ; +int ret; ms->fdt =create_device_tree (&size);
@@ -337,6 +340,12 @@ void dt_setup_microvm(MicrovmMachineState *mms)qemu_fdt_add_subnode (ms->fdt,"/chosen" );dt_setup_sys_bus (mms); + ret =fdt_pack (ms->fdt); +/* Should only fail if we've built a corrupted tree */ +g_assert (ret ==0 ); + + size =fdt_totalsize (ms->fdt); +/* add to fw_cfg */ if (debug) {fprintf (stderr,"%s: add etc/fdt to fw_cfg\n" , __func__);
Signature · 1 line
2.54.0
PATCH 2/2 igvm: Fill device tree IGVM parameter field on x86_64
In reply to Luigi LeonardiCoconut SVSM, with the upcoming device tree support[1], will use the IGVM device tree parameter to discover virtio-mmio and ISA serial devices instead of relying on the fw_cfg interface, which is QEMU-specific.
The IGVM parameter handler is implemented for the i386 machine target and stubbed for all others.
[1] https://github.com/coconut-svsm/svsm/pull/1006
--- backends/igvm.c | 2 ++ include/system/igvm.h | 2 ++ stubs/igvm.c | 6 ++++++ target/i386/igvm.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+)
backends/igvm.c +2 -0
@@ -130,6 +130,8 @@ static struct QIGVMHandler handlers[] = { qigvm_initialization_guest_policy }, {IGVM_VHT_MADT ,IGVM_HEADER_SECTION_DIRECTIVE , qigvm_directive_madt }, + { IGVM_VHT_DEVICE_TREE, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_device_tree }, };static int qigvm_handler (QIgvm *ctx,uint32_t type,Error **errp)
include/system/igvm.h +2 -0
@@ -32,5 +32,7 @@ int qigvm_x86_set_vp_context(void *data, int index,* IGVM parameter handlers */ int qigvm_directive_madt (QIgvm *ctx,const uint8_t *header_data,Error **errp); +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp);#endif
stubs/igvm.c +6 -0
@@ -29,3 +29,9 @@ int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) {return -1 ; } + +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp) +{ +return -1 ; +}
target/i386/igvm.c +36 -0
@@ -11,6 +11,8 @@#include "qemu/osdep.h" +#include <libfdt.h> +#include "cpu.h" #include "hw/i386/e820_memory_layout.h" #include "hw/i386/acpi-build.h"
@@ -210,3 +212,37 @@ int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp)g_array_free (madt, true);return result; } + +/* +* Process device tree IGVM parameter +*/ +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp) +{ +const IGVM_VHS_PARAMETER *param = (const IGVM_VHS_PARAMETER *)header_data; +QIgvmParameterData *param_entry; +uint32_t fdt_size; + +/* Find the parameter area that should hold the device tree data */ + param_entry =qigvm_find_param_entry (ctx, param->parameter_area_index); +if (param_entry ==NULL ) { +return 0 ; + } + +if (ctx->machine_state->fdt ==NULL ) { +error_setg (errp,"IGVM: device tree not available" ); +return -1 ; + } + + fdt_size =fdt_totalsize (ctx->machine_state->fdt); +if (fdt_size > param_entry->size) { +error_setg (errp, +"IGVM: device tree size exceeds parameter area" +" defined in IGVM file" ); +return -1 ; + } + +memcpy (param_entry->data, ctx->machine_state->fdt, fdt_size); + +return 0 ; +}
Signature · 1 line
2.54.0
Re: [PATCH 2/2] igvm: Fill device tree IGVM parameter field on x86_64
Quoted 7 lines · Luigi Leonardi
Coconut SVSM, with the upcoming device tree support[1], will use the IGVM device tree parameter to discover virtio-mmio and ISA serial devices instead of relying on the
fw_cfginterface, which is QEMU-specific.The IGVM parameter handler is implemented for the i386 machine target and stubbed for all others.
Hmm, why? I can't see anything i386-specific in that code, it should work just fine everywhere. For example on aarch64 (which is not yet supported by qemu but already in the igvm specification).
take care,
Gerd
Re: [PATCH 2/2] igvm: Fill device tree IGVM parameter field on x86_64
Quoted 9 lines · Gerd Hoffmann
Quoted 7 lines · Luigi Leonardi
Coconut SVSM, with the upcoming device tree support[1], will use the IGVM device tree parameter to discover virtio-mmio and ISA serial devices instead of relying on the
fw_cfginterface, which is QEMU-specific.The IGVM parameter handler is implemented for the i386 machine target and stubbed for all others.
Quoted 7 lines
Hmm, why? I can't see anything i386-specific in that code, it should work just fine everywhere. For example on aarch64 (which is not yet supported by qemu but already in the igvm specification).
take care,
Gerd
Right, good point. I think this function can be moved to backends/igvm.c directly, so we'll have aarch64 DT support for free.
Luigi
Re: [PATCH 2/2] igvm: Fill device tree IGVM parameter field on x86_64
In reply to Luigi LeonardiQuoted 48 lines · Luigi Leonardi
Coconut SVSM, with the upcoming device tree support[1], will use the IGVM device tree parameter to discover virtio-mmio and ISA serial devices instead of relying on the
fw_cfginterface, which is QEMU-specific.The IGVM parameter handler is implemented for the i386 machine target and stubbed for all others.
[1] https://github.com/coconut-svsm/svsm/pull/1006
Signed-off-by Luigi Leonardi <[email protected]>---
backends/igvm.c | 2 ++ include/system/igvm.h | 2 ++ stubs/igvm.c | 6 ++++++ target/i386/igvm.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+)backends/igvm.c +2
-0@@ -130,6 +130,8 @@ static struct QIGVMHandler handlers[] = { qigvm_initialization_guest_policy }, {IGVM_VHT_MADT ,IGVM_HEADER_SECTION_DIRECTIVE , qigvm_directive_madt }, + { IGVM_VHT_DEVICE_TREE, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_device_tree }, };static int qigvm_handler (QIgvm *ctx,uint32_t type,Error **errp)include/system/igvm.h +2
-0@@ -32,5 +32,7 @@ int qigvm_x86_set_vp_context(void *data, int index,* IGVM parameter handlers */ int qigvm_directive_madt (QIgvm *ctx,const uint8_t *header_data,Error **errp); +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp);#endif stubs/igvm.c +0
-0
stubs/igvm.c int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) · line 36
Quoted 8 lines
stubs/igvm.c +5
-0@@ -29,3 +29,9 @@ int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) {return -1 ; } + +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp) +{ +return -1 ;
This is pre-existing in the other stubs, so maybe should be fixed in another patch, but IMO we should set errp, like we do in other files in stubs/ (e.g. monitor-internal.c, qmp*.c, etc.)
I mean something like:
error_setg(errp, "IGVM not supported on this platform");
Quoted 20 lines
stubs/igvm.c +1
-0+}target/i386/igvm.c +4
-0@@ -11,6 +11,8 @@#include "qemu/osdep.h" +#include <libfdt.h> +#include "cpu.h" #include "hw/i386/e820_memory_layout.h" #include "hw/i386/acpi-build.h" @@ -210,3 +212,37 @@ int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp)g_array_free (madt, true);return result; } + +/*
target/i386/igvm.c int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) · line 226
Quoted 10 lines
target/i386/igvm.c +10
-0+* Process device tree IGVM parameter +*/ +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp) +{ +const IGVM_VHS_PARAMETER *param = (const IGVM_VHS_PARAMETER *)header_data; +QIgvmParameterData *param_entry; +uint32_t fdt_size; + +/* Find the parameter area that should hold the device tree data */
This comment is a bit pointless; IMHO, we should explain why we return success if we can't find the device tree area.
Here or in the function doc.
Thanks,
Stefano
Quoted 26 lines
target/i386/igvm.c +22
-0+ param_entry =qigvm_find_param_entry (ctx, param->parameter_area_index); +if (param_entry ==NULL ) { +return 0 ; + } + +if (ctx->machine_state->fdt ==NULL ) { +error_setg (errp,"IGVM: device tree not available" ); +return -1 ; + } + + fdt_size =fdt_totalsize (ctx->machine_state->fdt); +if (fdt_size > param_entry->size) { +error_setg (errp, +"IGVM: device tree size exceeds parameter area" +" defined in IGVM file" ); +return -1 ; + } + +memcpy (param_entry->data, ctx->machine_state->fdt, fdt_size); + +return 0 ; +}Signature · 2 lines
-- 2.54.0
Re: [PATCH 2/2] igvm: Fill device tree IGVM parameter field on x86_64
Quoted 60 lines · Stefano Garzarella
Quoted 48 lines · Luigi Leonardi
Coconut SVSM, with the upcoming device tree support[1], will use the IGVM device tree parameter to discover virtio-mmio and ISA serial devices instead of relying on the
fw_cfginterface, which is QEMU-specific.The IGVM parameter handler is implemented for the i386 machine target and stubbed for all others.
[1] https://github.com/coconut-svsm/svsm/pull/1006
Signed-off-by Luigi Leonardi <[email protected]>---
backends/igvm.c | 2 ++ include/system/igvm.h | 2 ++ stubs/igvm.c | 6 ++++++ target/i386/igvm.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+)backends/igvm.c +2
-0@@ -130,6 +130,8 @@ static struct QIGVMHandler handlers[] = { qigvm_initialization_guest_policy }, {IGVM_VHT_MADT ,IGVM_HEADER_SECTION_DIRECTIVE , qigvm_directive_madt }, + { IGVM_VHT_DEVICE_TREE, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_device_tree }, };static int qigvm_handler (QIgvm *ctx,uint32_t type,Error **errp)include/system/igvm.h +2
-0@@ -32,5 +32,7 @@ int qigvm_x86_set_vp_context(void *data, int index,* IGVM parameter handlers */ int qigvm_directive_madt (QIgvm *ctx,const uint8_t *header_data,Error **errp); +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp);#endif stubs/igvm.c +0
-0stubs/igvm.c int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) · line 36
Quoted 8 lines
stubs/igvm.c +5
-0@@ -29,3 +29,9 @@ int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) {return -1 ; } + +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp) +{ +return -1 ;This is pre-existing in the other stubs, so maybe should be fixed in another patch, but IMO we should set errp, like we do in other files in stubs/ (e.g.
monitor-internal.c, qmp*.c, etc.)
Quoted 4 lines
I mean something like:
error_setg(errp, "IGVM not supported on this platform");
Yep, I will send another patch.
Quoted 24 lines
Quoted 24 lines
stubs/igvm.c +1
-0+}target/i386/igvm.c +8
-0@@ -11,6 +11,8 @@#include "qemu/osdep.h" +#include <libfdt.h> +#include "cpu.h" #include "hw/i386/e820_memory_layout.h" #include "hw/i386/acpi-build.h" @@ -210,3 +212,37 @@ int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp)g_array_free (madt, true);return result; } + +/* +* Process device tree IGVM parameter +*/ +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp)
Quoted 8 lines
target/i386/igvm.c int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) · line 226
Quoted 6 lines
target/i386/igvm.c +6
-0+{ +const IGVM_VHS_PARAMETER *param = (const IGVM_VHS_PARAMETER *)header_data; +QIgvmParameterData *param_entry; +uint32_t fdt_size; + +/* Find the parameter area that should hold the device tree data */ This comment is a bit pointless; IMHO, we should explain why we return success if we can't find the device tree area.
Good point: in every place where we used qigvm_find_param_entry we have this behaviour. I don't think it makes too much sense because it's probably due to a malformed igvm-file. WDYT?
Luigi
Re: [PATCH 2/2] igvm: Fill device tree IGVM parameter field on x86_64
Quoted 101 lines · Luigi Leonardi
Quoted 60 lines · Stefano Garzarella
Quoted 48 lines · Luigi Leonardi
Coconut SVSM, with the upcoming device tree support[1], will use the IGVM device tree parameter to discover virtio-mmio and ISA serial devices instead of relying on the
fw_cfginterface, which is QEMU-specific.The IGVM parameter handler is implemented for the i386 machine target and stubbed for all others.
[1] https://github.com/coconut-svsm/svsm/pull/1006
Signed-off-by Luigi Leonardi <[email protected]>---
backends/igvm.c | 2 ++ include/system/igvm.h | 2 ++ stubs/igvm.c | 6 ++++++ target/i386/igvm.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+)backends/igvm.c +2
-0@@ -130,6 +130,8 @@ static struct QIGVMHandler handlers[] = { qigvm_initialization_guest_policy }, { IGVM_VHT_MADT, IGVM_HEADER_SECTION_DIRECTIVE, qigvm_directive_madt }, + { IGVM_VHT_DEVICE_TREE, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_device_tree }, };static int qigvm_handler (QIgvm *ctx,uint32_t type,Error **errp)include/system/igvm.h +2
-0@@ -32,5 +32,7 @@ int qigvm_x86_set_vp_context(void *data, int index,* IGVM parameter handlers */ int qigvm_directive_madt (QIgvm *ctx,const uint8_t *header_data,Error **errp); +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp);#endif stubs/igvm.c +0
-0stubs/igvm.c int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) · line 36
Quoted 8 lines
stubs/igvm.c +5
-0@@ -29,3 +29,9 @@ int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) {return -1 ; } + +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp) +{ +return -1 ;This is pre-existing in the other stubs, so maybe should be fixed in another patch, but IMO we should set errp, like we do in other files in stubs/ (e.g.
monitor-internal.c, qmp*.c, etc.)Quoted 4 lines
I mean something like:
error_setg(errp, "IGVM not supported on this platform");Yep, I will send another patch.
Quoted 24 lines
Quoted 24 lines
stubs/igvm.c +1
-0+}target/i386/igvm.c +8
-0@@ -11,6 +11,8 @@#include "qemu/osdep.h" +#include <libfdt.h> +#include "cpu.h" #include "hw/i386/e820_memory_layout.h" #include "hw/i386/acpi-build.h" @@ -210,3 +212,37 @@ int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp)g_array_free (madt, true);return result; } + +/* +* Process device tree IGVM parameter +*/ +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp)Quoted 8 lines
target/i386/igvm.c int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) · line 226
Quoted 6 lines
target/i386/igvm.c +6
-0+{ +const IGVM_VHS_PARAMETER *param = (const IGVM_VHS_PARAMETER *)header_data; +QIgvmParameterData *param_entry; +uint32_t fdt_size; + +/* Find the parameter area that should hold the device tree data */ This comment is a bit pointless; IMHO, we should explain why we return success if we can't find the device tree area.
Quoted 3 lines
Good point: in every place where we used
qigvm_find_param_entrywe have this behaviour. I don't think it makes too much sense because it's probably due to a malformed igvm-file. WDYT?
ehm, I thought it was more about backward compatibility. For example, QEMU supports the device-tree property, but the IGVM file (which is probably outdated) doesn't have the entry because it's an old version, so we don't return an error (though qigvm_find_param_entry() will still print a warning, as it should). Or am I missing something?
Thanks,
Stefano
Re: [PATCH 2/2] igvm: Fill device tree IGVM parameter field on x86_64
Quoted 102 lines · Stefano Garzarella
Quoted 101 lines · Luigi Leonardi
Quoted 60 lines · Stefano Garzarella
Quoted 48 lines · Luigi Leonardi
Coconut SVSM, with the upcoming device tree support[1], will use the IGVM device tree parameter to discover virtio-mmio and ISA serial devices instead of relying on the
fw_cfginterface, which is QEMU-specific.The IGVM parameter handler is implemented for the i386 machine target and stubbed for all others.
[1] https://github.com/coconut-svsm/svsm/pull/1006
Signed-off-by Luigi Leonardi <[email protected]>---
backends/igvm.c | 2 ++ include/system/igvm.h | 2 ++ stubs/igvm.c | 6 ++++++ target/i386/igvm.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+)backends/igvm.c +2
-0@@ -130,6 +130,8 @@ static struct QIGVMHandler handlers[] = { qigvm_initialization_guest_policy }, { IGVM_VHT_MADT, IGVM_HEADER_SECTION_DIRECTIVE, qigvm_directive_madt }, + { IGVM_VHT_DEVICE_TREE, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_device_tree }, };static int qigvm_handler (QIgvm *ctx,uint32_t type,Error **errp)include/system/igvm.h +2
-0@@ -32,5 +32,7 @@ int qigvm_x86_set_vp_context(void *data, int index,* IGVM parameter handlers */ int qigvm_directive_madt (QIgvm *ctx,const uint8_t *header_data,Error **errp); +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp);#endif stubs/igvm.c +0
-0stubs/igvm.c int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) · line 36
Quoted 8 lines
stubs/igvm.c +5
-0@@ -29,3 +29,9 @@ int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) {return -1 ; } + +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp) +{ +return -1 ;This is pre-existing in the other stubs, so maybe should be fixed in another patch, but IMO we should set errp, like we do in other files in stubs/ (e.g.
monitor-internal.c, qmp*.c, etc.)Quoted 4 lines
I mean something like:
error_setg(errp, "IGVM not supported on this platform");Yep, I will send another patch.
Quoted 32 lines
Quoted 20 lines
stubs/igvm.c +1
-0+}target/i386/igvm.c +4
-0@@ -11,6 +11,8 @@#include "qemu/osdep.h" +#include <libfdt.h> +#include "cpu.h" #include "hw/i386/e820_memory_layout.h" #include "hw/i386/acpi-build.h" @@ -210,3 +212,37 @@ int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp)g_array_free (madt, true);return result; } + +/* target/i386/igvm.c int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp) · line 226
Quoted 10 lines
target/i386/igvm.c +10
-0+* Process device tree IGVM parameter +*/ +int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp) +{ +const IGVM_VHS_PARAMETER *param = (const IGVM_VHS_PARAMETER *)header_data; +QIgvmParameterData *param_entry; +uint32_t fdt_size; + +/* Find the parameter area that should hold the device tree data */ This comment is a bit pointless; IMHO, we should explain why we return success if we can't find the device tree area.
Quoted 6 lines
Quoted 3 lines
Good point: in every place where we used
qigvm_find_param_entrywe have this behaviour. I don't think it makes too much sense because it's probably due to a malformed igvm-file. WDYT?ehm, I thought it was more about backward compatibility. For example, QEMU supports the device-tree property, but the IGVM file (which is probably outdated) doesn't have the entry because it's an old version, so we don't return an error (though
qigvm_find_param_entry()will still print a warning, as it should). Or am I missing something?
In an "old" igvm file, where the device tree directive is not set, qigvm_directive_device_tree will never run. Therefore backward compatibility is guaranteed.
About qigvm_find_param_entry(), maybe Oliver can help us, as he introduced that helper.
Luigi