backends/igvm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
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_cfg interface, which is
QEMU-specific.
The device tree is packed before copying into the IGVM parameter area
to reduce its size, since IGVM files can define tighter memory
constraints for parameter areas. Packing is done in the generic IGVM
backend rather than in per-architecture device tree setup code, so
that each architecture does not need to handle it individually.
[1] https://github.com/coconut-svsm/svsm/pull/1006
Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
---
This device tree 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: qemu-devel@nongnu.org
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Stefano Garzarella <sgarzare@redhat.com>
Cc: Ani Sinha <anisinha@redhat.com>
Cc: Zhao Liu <zhao1.liu@intel.com>
Cc: Oliver Steffen <osteffen@redhat.com>
---
Changes in v3:
- Device tree is packed in igvm core code. [Gerd]
- Dropped microvm patch.
- Link to v2: https://lore.kernel.org/qemu-devel/20260610-microvm_device_tree-v2-0-4fb44730c49f@redhat.com
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/20260608-microvm_device_tree-v1-0-730874ad0008@redhat.com
---
Error handling on qigvm_find_param_entry will change once [2] is
merged. I am already using the new approach here.
[2] https://lore.kernel.org/qemu-devel/20260610-igvm_error-v1-1-59d133a69f2f@redhat.com
---
backends/igvm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/backends/igvm.c b/backends/igvm.c
index c347d0c17e..452715b105 100644
--- a/backends/igvm.c
+++ b/backends/igvm.c
@@ -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,48 @@ static int qigvm_directive_snp_id_block(QIgvm *ctx, const uint8_t *header_data,
return 0;
}
+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;
+ g_autofree void *fdt_packed = NULL;
+ 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);
+ fdt_packed = g_malloc(fdt_size);
+ memcpy(fdt_packed, ctx->machine_state->fdt, fdt_size);
+
+ if (fdt_pack(fdt_packed)) {
+ error_setg(errp, "IGVM: failed to pack device tree");
+ return -1;
+ }
+
+ fdt_size = fdt_totalsize(fdt_packed);
+ 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, fdt_packed, fdt_size);
+
+ return 0;
+}
+
static int qigvm_initialization_guest_policy(QIgvm *ctx,
const uint8_t *header_data, Error **errp)
{
---
base-commit: cc329c491768b2d91eb0b0984f3baa0bf805776d
change-id: 20260608-microvm_device_tree-0263c3b1be86
Best regards,
--
Luigi Leonardi <leonardi@redhat.com>
On Thu, Jun 11, 2026 at 01:14:47PM +0200, Luigi Leonardi wrote:
>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_cfg interface, which is
>QEMU-specific.
>
>The device tree is packed before copying into the IGVM parameter area
>to reduce its size, since IGVM files can define tighter memory
>constraints for parameter areas. Packing is done in the generic IGVM
>backend rather than in per-architecture device tree setup code, so
>that each architecture does not need to handle it individually.
>
>[1] https://github.com/coconut-svsm/svsm/pull/1006
>
>Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
>---
>This device tree 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: qemu-devel@nongnu.org
>Cc: Michael S. Tsirkin <mst@redhat.com>
>Cc: Paolo Bonzini <pbonzini@redhat.com>
>Cc: Richard Henderson <richard.henderson@linaro.org>
>Cc: Gerd Hoffmann <kraxel@redhat.com>
>Cc: Stefano Garzarella <sgarzare@redhat.com>
>Cc: Ani Sinha <anisinha@redhat.com>
>Cc: Zhao Liu <zhao1.liu@intel.com>
>Cc: Oliver Steffen <osteffen@redhat.com>
>---
>Changes in v3:
>- Device tree is packed in igvm core code. [Gerd]
>- Dropped microvm patch.
>- Link to v2: https://lore.kernel.org/qemu-devel/20260610-microvm_device_tree-v2-0-4fb44730c49f@redhat.com
>
>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/20260608-microvm_device_tree-v1-0-730874ad0008@redhat.com
>---
>
>Error handling on qigvm_find_param_entry will change once [2] is
>merged. I am already using the new approach here.
>
>[2] https://lore.kernel.org/qemu-devel/20260610-igvm_error-v1-1-59d133a69f2f@redhat.com
>---
> backends/igvm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 47 insertions(+)
>
>diff --git a/backends/igvm.c b/backends/igvm.c
>index c347d0c17e..452715b105 100644
>--- a/backends/igvm.c
>+++ b/backends/igvm.c
>@@ -25,6 +25,7 @@
>
> #include <igvm/igvm.h>
> #include <igvm/igvm_defs.h>
>+#include <libfdt.h>
So now we depend on libfdt. Should we add this dependency to the build
system? Or should we disable IGVM_VHT_DEVICE_TREE support here if libfdt
is not available?
I just tried:
$ ./configure ... --disable-fdt --enable-igvm
$ make
[110/110] Linking target qemu-system-x86_64
FAILED: [code=1] qemu-system-x86_64
cc -m64 @qemu-system-x86_64.rsp
/usr/bin/ld.bfd: libsystem.a.p/backends_igvm.c.o: in function `qigvm_directive_device_tree':
/home/stefano/repos/qemu-review/build/../backends/igvm.c:784:(.text+0x109b): undefined reference to `fdt_pack'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
>
>
> /*
>@@ -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,48 @@ static int qigvm_directive_snp_id_block(QIgvm *ctx, const uint8_t *header_data,
> return 0;
> }
>
>+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;
>+ g_autofree void *fdt_packed = NULL;
>+ 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);
>+ fdt_packed = g_malloc(fdt_size);
>+ memcpy(fdt_packed, ctx->machine_state->fdt, fdt_size);
What about using g_memdup2() ?
Stefano
>+
>+ if (fdt_pack(fdt_packed)) {
>+ error_setg(errp, "IGVM: failed to pack device tree");
>+ return -1;
>+ }
>+
>+ fdt_size = fdt_totalsize(fdt_packed);
>+ 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, fdt_packed, fdt_size);
>+
>+ return 0;
>+}
>+
> static int qigvm_initialization_guest_policy(QIgvm *ctx,
> const uint8_t *header_data, Error **errp)
> {
>
>---
>base-commit: cc329c491768b2d91eb0b0984f3baa0bf805776d
>change-id: 20260608-microvm_device_tree-0263c3b1be86
>
>Best regards,
>--
>Luigi Leonardi <leonardi@redhat.com>
>
On Thu, Jun 11, 2026 at 02:45:04PM +0200, Stefano Garzarella wrote:
>On Thu, Jun 11, 2026 at 01:14:47PM +0200, Luigi Leonardi wrote:
>>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_cfg interface, which is
>>QEMU-specific.
>>
>>The device tree is packed before copying into the IGVM parameter area
>>to reduce its size, since IGVM files can define tighter memory
>>constraints for parameter areas. Packing is done in the generic IGVM
>>backend rather than in per-architecture device tree setup code, so
>>that each architecture does not need to handle it individually.
>>
>>[1] https://github.com/coconut-svsm/svsm/pull/1006
>>
>>Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
>>---
>>This device tree 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: qemu-devel@nongnu.org
>>Cc: Michael S. Tsirkin <mst@redhat.com>
>>Cc: Paolo Bonzini <pbonzini@redhat.com>
>>Cc: Richard Henderson <richard.henderson@linaro.org>
>>Cc: Gerd Hoffmann <kraxel@redhat.com>
>>Cc: Stefano Garzarella <sgarzare@redhat.com>
>>Cc: Ani Sinha <anisinha@redhat.com>
>>Cc: Zhao Liu <zhao1.liu@intel.com>
>>Cc: Oliver Steffen <osteffen@redhat.com>
>>---
>>Changes in v3:
>>- Device tree is packed in igvm core code. [Gerd]
>>- Dropped microvm patch.
>>- Link to v2: https://lore.kernel.org/qemu-devel/20260610-microvm_device_tree-v2-0-4fb44730c49f@redhat.com
>>
>>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/20260608-microvm_device_tree-v1-0-730874ad0008@redhat.com
>>---
>>
>>Error handling on qigvm_find_param_entry will change once [2] is
>>merged. I am already using the new approach here.
>>
>>[2] https://lore.kernel.org/qemu-devel/20260610-igvm_error-v1-1-59d133a69f2f@redhat.com
>>---
>>backends/igvm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>>1 file changed, 47 insertions(+)
>>
>>diff --git a/backends/igvm.c b/backends/igvm.c
>>index c347d0c17e..452715b105 100644
>>--- a/backends/igvm.c
>>+++ b/backends/igvm.c
>>@@ -25,6 +25,7 @@
>>
>>#include <igvm/igvm.h>
>>#include <igvm/igvm_defs.h>
>>+#include <libfdt.h>
>
>So now we depend on libfdt. Should we add this dependency to the build
>system? Or should we disable IGVM_VHT_DEVICE_TREE support here if
>libfdt is not available?
Good question: IIUC, running `--disable-fdt` disables all the things
that depend on on it, like microvm.
So, disabling FDT doesn't make too much sense to provide `IGVM_VHT_DEVICE_TREE `
when fdt is disabled. WDYT?
>
>I just tried:
>
>$ ./configure ... --disable-fdt --enable-igvm
>$ make
>[110/110] Linking target qemu-system-x86_64
>FAILED: [code=1] qemu-system-x86_64
>cc -m64 @qemu-system-x86_64.rsp
>/usr/bin/ld.bfd: libsystem.a.p/backends_igvm.c.o: in function `qigvm_directive_device_tree':
>/home/stefano/repos/qemu-review/build/../backends/igvm.c:784:(.text+0x109b): undefined reference to `fdt_pack'
>collect2: error: ld returned 1 exit status
>ninja: build stopped: subcommand failed.
>
>>
>>
>>/*
>>@@ -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,48 @@ static int qigvm_directive_snp_id_block(QIgvm *ctx, const uint8_t *header_data,
>> return 0;
>>}
>>
>>+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;
>>+ g_autofree void *fdt_packed = NULL;
>>+ 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);
>>+ fdt_packed = g_malloc(fdt_size);
>>+ memcpy(fdt_packed, ctx->machine_state->fdt, fdt_size);
>
>What about using g_memdup2() ?
Yep, good idea.
Thanks,
Luigi
On Thu, Jun 11, 2026 at 03:36:29PM +0200, Luigi Leonardi wrote:
>On Thu, Jun 11, 2026 at 02:45:04PM +0200, Stefano Garzarella wrote:
>>On Thu, Jun 11, 2026 at 01:14:47PM +0200, Luigi Leonardi wrote:
>>>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_cfg interface, which is
>>>QEMU-specific.
>>>
>>>The device tree is packed before copying into the IGVM parameter area
>>>to reduce its size, since IGVM files can define tighter memory
>>>constraints for parameter areas. Packing is done in the generic IGVM
>>>backend rather than in per-architecture device tree setup code, so
>>>that each architecture does not need to handle it individually.
>>>
>>>[1] https://github.com/coconut-svsm/svsm/pull/1006
>>>
>>>Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
>>>---
>>>This device tree 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: qemu-devel@nongnu.org
>>>Cc: Michael S. Tsirkin <mst@redhat.com>
>>>Cc: Paolo Bonzini <pbonzini@redhat.com>
>>>Cc: Richard Henderson <richard.henderson@linaro.org>
>>>Cc: Gerd Hoffmann <kraxel@redhat.com>
>>>Cc: Stefano Garzarella <sgarzare@redhat.com>
>>>Cc: Ani Sinha <anisinha@redhat.com>
>>>Cc: Zhao Liu <zhao1.liu@intel.com>
>>>Cc: Oliver Steffen <osteffen@redhat.com>
>>>---
>>>Changes in v3:
>>>- Device tree is packed in igvm core code. [Gerd]
>>>- Dropped microvm patch.
>>>- Link to v2: https://lore.kernel.org/qemu-devel/20260610-microvm_device_tree-v2-0-4fb44730c49f@redhat.com
>>>
>>>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/20260608-microvm_device_tree-v1-0-730874ad0008@redhat.com
>>>---
>>>
>>>Error handling on qigvm_find_param_entry will change once [2] is
>>>merged. I am already using the new approach here.
>>>
>>>[2] https://lore.kernel.org/qemu-devel/20260610-igvm_error-v1-1-59d133a69f2f@redhat.com
>>>---
>>>backends/igvm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>>>1 file changed, 47 insertions(+)
>>>
>>>diff --git a/backends/igvm.c b/backends/igvm.c
>>>index c347d0c17e..452715b105 100644
>>>--- a/backends/igvm.c
>>>+++ b/backends/igvm.c
>>>@@ -25,6 +25,7 @@
>>>
>>>#include <igvm/igvm.h>
>>>#include <igvm/igvm_defs.h>
>>>+#include <libfdt.h>
>>
>>So now we depend on libfdt. Should we add this dependency to the
>>build system? Or should we disable IGVM_VHT_DEVICE_TREE support here
>>if libfdt is not available?
>
>Good question: IIUC, running `--disable-fdt` disables all the things
>that depend on on it, like microvm.
That was just a test; I just wanted to point out that if libfdt isn't
there, there's a problem here.
>
>So, disabling FDT doesn't make too much sense to provide `IGVM_VHT_DEVICE_TREE `
>when fdt is disabled. WDYT?
Yes, I agree. I would avoid direct dependency, so we can enable IGVM
even if libfdt isn't present (as was the case before this patch) and, of
course, support the device tree only when it is present.
Thanks,
Stefano
>
>>
>>I just tried:
>>
>>$ ./configure ... --disable-fdt --enable-igvm
>>$ make
>>[110/110] Linking target qemu-system-x86_64
>>FAILED: [code=1] qemu-system-x86_64
>>cc -m64 @qemu-system-x86_64.rsp
>>/usr/bin/ld.bfd: libsystem.a.p/backends_igvm.c.o: in function `qigvm_directive_device_tree':
>>/home/stefano/repos/qemu-review/build/../backends/igvm.c:784:(.text+0x109b): undefined reference to `fdt_pack'
>>collect2: error: ld returned 1 exit status
>>ninja: build stopped: subcommand failed.
>>
>>>
>>>
>>>/*
>>>@@ -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,48 @@ static int qigvm_directive_snp_id_block(QIgvm *ctx, const uint8_t *header_data,
>>> return 0;
>>>}
>>>
>>>+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;
>>>+ g_autofree void *fdt_packed = NULL;
>>>+ 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);
>>>+ fdt_packed = g_malloc(fdt_size);
>>>+ memcpy(fdt_packed, ctx->machine_state->fdt, fdt_size);
>>
>>What about using g_memdup2() ?
>
>Yep, good idea.
>
>Thanks,
>Luigi
>
© 2016 - 2026 Red Hat, Inc.