Skip to contentSkip to conversation

igvm: device tree support

PATCH Superseded Luigi Leonardi 1 participant 4 messages Jun 25 – Jun 26 Arm/Amlogic Meson SoC support

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover igvm: device tree support

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.

In this v5, I'm adding a patch that simplifies meson logic. Adding it here to avoid conflicts with patch 2, that needs to modify the same line.

[1] https://github.com/coconut-svsm/svsm/pull/1006

---
Changes in v5:
- Added a patch, suggested by Paolo, to simplify current igvm meson config
- Added missing fdt dependency for igvm in meson.
- Link to v4: https://lore.kernel.org/qemu-devel/[email protected]

Changes in v4:
- Using g_memdup2 [Stefano]
- madt directive is now protected by CONFIG_FDT [Stefano]
- Link to v3: https://lore.kernel.org/qemu-devel/[email protected]

Changes in v3:
- Device tree is packed in igvm core code. [Gerd]
- Dropped microvm patch.
- Link to v2: https://lore.kernel.org/qemu-devel/[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):
igvm: use idiomatic meson conditional for IGVM build files
igvm: add device tree parameter support

 backends/igvm.c      | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 backends/meson.build |  7 ++-----
 2 files changed, 57 insertions(+), 5 deletions(-)

---
base-commit: b83371668192a705b878e909c5ae9c1233cbd5fb
change-id: 20260608-microvm_device_tree-0263c3b1be86

Best regards,

Signature · 1 line
Luigi Leonardi <[email protected]>
#1 lore raw

PATCH v5 1/2 igvm: use idiomatic meson conditional for IGVM build files

Replace the explicit igvm.found() check with system_ss.add(when:, if_true:), matching the pattern used by all other optional backends.

---
 backends/meson.build | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
backends/meson.build +2 -5
index 60021f45d1..aabfaea5fd 100644
@@ -34,11 +34,8 @@ if have_vhost_user_crypto
 endif
 system_ss.add(when: gio, if_true: files('dbus-vmstate.c'))
 system_ss.add(when: 'CONFIG_SGX', if_true: files('hostmem-epc.c'))
-if igvm.found()
-  system_ss.add(igvm)
-  system_ss.add(files('igvm-cfg.c'), igvm)
-  system_ss.add(files('igvm.c'), igvm)
-endif
+
+system_ss.add(when: igvm, if_true: [files('igvm-cfg.c', 'igvm.c')])
 
 system_ss.add(when: 'CONFIG_SPDM_SOCKET', if_true: files('spdm-socket.c'))
 
Signature · 1 line
2.54.0
#2 lore raw

PATCH v5 2/2 igvm: add device tree parameter support

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

---

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/[email protected]/

---
 backends/igvm.c      | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 backends/meson.build |  2 +-
 2 files changed, 56 insertions(+), 1 deletion(-)
backends/igvm.c +55 -0
index 3f4b97a5d4..53e96fae25 100644
@@ -26,6 +26,10 @@
 #include <igvm/igvm.h>
 #include <igvm/igvm_defs.h>
 
+#ifdef CONFIG_FDT
+#include <libfdt.h>
+#endif
+
 #ifndef IGVM_VHT_OPTIONAL_BIT
 #define IGVM_VHT_OPTIONAL_BIT (1U << 31)
 #endif
@@ -119,6 +123,10 @@ 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);
+#ifdef CONFIG_FDT
+static int qigvm_directive_device_tree(QIgvm *ctx, const uint8_t *header_data,
+                                       Error **errp);
+#endif
 
 struct QIGVMHandler {
     IgvmVariableHeaderType type;
@@ -149,6 +157,10 @@ static struct QIGVMHandler handlers[] = {
       qigvm_initialization_guest_policy },
     { IGVM_VHT_MADT, IGVM_HEADER_SECTION_DIRECTIVE,
       qigvm_directive_madt },
+#ifdef CONFIG_FDT
+    { IGVM_VHT_DEVICE_TREE, IGVM_HEADER_SECTION_DIRECTIVE,
+      qigvm_directive_device_tree },
+#endif
 };
 
 static int qigvm_handler(QIgvm *ctx, IgvmVariableHeaderType raw_type,
@@ -780,6 +792,49 @@ static int qigvm_directive_snp_id_block(QIgvm *ctx, const uint8_t *header_data,
     return 0;
 }
 
+#ifdef CONFIG_FDT
+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_memdup2(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;
+}
+#endif
+
 static int qigvm_initialization_guest_policy(QIgvm *ctx,
                                        const uint8_t *header_data, Error **errp)
 {
backends/meson.build +1 -1
index aabfaea5fd..8792c58c36 100644
@@ -35,7 +35,7 @@ endif
 system_ss.add(when: gio, if_true: files('dbus-vmstate.c'))
 system_ss.add(when: 'CONFIG_SGX', if_true: files('hostmem-epc.c'))
 
-system_ss.add(when: igvm, if_true: [files('igvm-cfg.c', 'igvm.c')])
+system_ss.add(when: igvm, if_true: [files('igvm-cfg.c', 'igvm.c'), fdt])
 
 system_ss.add(when: 'CONFIG_SPDM_SOCKET', if_true: files('spdm-socket.c'))
 
Signature · 1 line
2.54.0
#3 lore raw
In reply to Luigi Leonardi
Quoted 7 lines · Luigi Leonardi

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.

Quoted 8 lines

In this v5, I'm adding a patch that simplifies meson logic. Adding it here to avoid conflicts with patch 2, that needs to modify the same line.

[1] https://github.com/coconut-svsm/svsm/pull/1006

---

Please ignore this patch, this will conflict with [1]. Today I will send a new version that picks up that patch as well, fixing the conflict.

Sorry for the noise.
Luigi

[1] https://lore.kernel.org/qemu-devel/[email protected]/