igvm: device tree support
v2 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]>
---
Changes in v2:
- First patch introduced a shadowed variable, fixed.
- When parameter area is not found return -1.
- Moved qigvm_directive_device_tree to backends/igvm.c
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]
---
Luigi Leonardi (2):
hw/i386/microvm: pack device tree
igvm: add device tree parameter support
backends/igvm.c | 40 ++++++++++++++++++++++++++++++++++++++++ hw/i386/microvm-dt.c | 11 ++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-)
---
base-commit: cc329c491768b2d91eb0b0984f3baa0bf805776d
change-id: 20260608-microvm_device_tree-0263c3b1be86
Best regards,
Signature · 1 line
Luigi Leonardi <[email protected]>
PATCH v2 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 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
hw/i386/microvm-dt.c +10 -1
@@ -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__);
@@ -349,7 +358,7 @@ void dt_setup_microvm(MicrovmMachineState *mms)fprintf (stderr,"%s: writing microvm.fdt failed\n" , __func__);return ; } -int ret =system ("dtc -I dtb -O dts microvm.fdt" ); + ret =system ("dtc -I dtb -O dts microvm.fdt" );if (ret !=0 ) {fprintf (stderr,"%s: oops, dtc not installed?\n" , __func__); }
Signature · 1 line
2.54.0
Re: [PATCH v2 1/2] hw/i386/microvm: pack device tree
Hi,
Quoted 1 line
+ ret =
fdt_pack(ms->fdt);
I'm wondering whenever this is the best place to do it, or whenever the igvm code should make a copy + pack it + place it in the directive, so we do not depend on the machine code to do the packing for us. When doing a quick grep the packing seems to be a rare thing, there isn't a single call in all arm code for example ...
take care,
Gerd
Re: [PATCH v2 1/2] hw/i386/microvm: pack device tree
Hi Gerd,
Quoted 10 lines · Gerd Hoffmann
Hi,
Quoted 1 line
+ ret =
fdt_pack(ms->fdt);I'm wondering whenever this is the best place to do it, or whenever the igvm code should make a copy + pack it + place it in the directive, so we do not depend on the machine code to do the packing for us. When doing a quick grep the packing seems to be a rare thing, there isn't a single call in all arm code for example ...
True, it's rather rare throughout the codebase. If we do this here, when we will support other archs we would have to add fdt_pack to them as well. Is this your concern?
Luigi
Re: [PATCH v2 1/2] hw/i386/microvm: pack device tree
Quoted 14 lines · Luigi Leonardi
Hi Gerd,
Quoted 10 lines · Gerd Hoffmann
Hi,
Quoted 1 line
+ ret =
fdt_pack(ms->fdt);I'm wondering whenever this is the best place to do it, or whenever the igvm code should make a copy + pack it + place it in the directive, so we do not depend on the machine code to do the packing for us. When doing a quick grep the packing seems to be a rare thing, there isn't a single call in all arm code for example ...
Quoted 3 lines
True, it's rather rare throughout the codebase. If we do this here, when we will support other archs we would have to add
fdt_packto them as well. Is this your concern?
Yes. Essentially igvm wants the fdt be packed so it fits into the parameter area, so I think it is better to handle that in igvm instead of depending this being done elsewhere for us. I'm also not sure if there is some specific reason to not pack the fdt (beyond nobody needed that so far), i.e. if packing could break something.
take care,
Gerd
PATCH v2 2/2 igvm: add device tree parameter support
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.
Because this code is architecture-independent, it is implemented in the generic IGVM backend.
[1] https://github.com/coconut-svsm/svsm/pull/1006
---
Error handling on qigvm_find_param_entry will change when [2] will be merged. Here i am already using the new approach.
[2] https://lore.kernel.org/qemu-devel/[email protected]
--- backends/igvm.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
backends/igvm.c +40 -0
@@ -25,6 +25,7 @@#include <igvm/igvm.h> #include <igvm/igvm_defs.h> +#include <libfdt.h> /*
@@ -100,6 +101,8 @@ static int qigvm_directive_snp_id_block(QIgvm *ctx, const uint8_t *header_data,static int qigvm_initialization_guest_policy (QIgvm *ctx,const uint8_t *header_data,Error **errp); +static int qigvm_directive_device_tree (QIgvm *ctx,const uint8_t *header_data, +Error **errp);struct QIGVMHandler {uint32_t type;
@@ -130,6 +133,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)
@@ -752,6 +757,41 @@ static int qigvm_directive_snp_id_block(QIgvm *ctx, const uint8_t *header_data,return 0 ; } +/* +* Process device tree IGVM parameter +*/ +static 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; + + param_entry =qigvm_find_param_entry (ctx, param->parameter_area_index); +if (param_entry ==NULL ) { +error_setg (errp,"IGVM: parameter area index %u not found" , + param->parameter_area_index); +return -1 ; + } + +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 ; +} +static int qigvm_initialization_guest_policy (QIgvm *ctx,const uint8_t *header_data,Error **errp) {
Signature · 1 line
2.54.0