Skip to contentSkip to conversation

hw/i386: Move SGX under KVM and use QDev API

PATCH In review Philippe Mathieu-Daudé 1 participant 5 messages Feb 15, 2024 – Feb 21, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover hw/i386: Move SGX under KVM and use QDev API

- Update MAINTAINERS
- Move SGX files with KVM ones
- Use QDev API

Supersedes: <[email protected]>

Philippe Mathieu-Daudé (3):
MAINTAINERS: Cover hw/i386/kvm/ in 'X86 KVM CPUs' section hw/i386: Move SGX files within the kvm/ directory hw/i386/sgx: Use QDev API

 MAINTAINERS                  |  1 +
 hw/i386/{ => kvm}/sgx-epc.c  |  0
 hw/i386/{ => kvm}/sgx-stub.c |  0
 hw/i386/{ => kvm}/sgx.c      | 14 ++++++--------
 hw/i386/kvm/meson.build      |  3 +++
 hw/i386/meson.build          |  2 --
 6 files changed, 10 insertions(+), 10 deletions(-)
 rename hw/i386/{ => kvm}/sgx-epc.c (100%)
 rename hw/i386/{ => kvm}/sgx-stub.c (100%)
 rename hw/i386/{ => kvm}/sgx.c (95%)
Signature · 1 line
2.41.0
#1 lore raw

PATCH v2 1/3 MAINTAINERS: Cover hw/i386/kvm/ in 'X86 KVM CPUs' section

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index a24c2b51b6..b526a08015 100644
@@ -490,6 +490,7 @@ L: [email protected]
 S: Supported
 F: docs/system/i386/amd-memory-encryption.rst
 F: docs/system/i386/sgx.rst
+F: hw/i386/kvm/
 F: target/i386/kvm/
 F: target/i386/sev*
 F: scripts/kvm/vmxcap
Signature · 1 line
2.41.0
#2 lore raw

PATCH v2 2/3 hw/i386: Move SGX files within the kvm/ directory

In reply to Philippe Mathieu-Daudé

Per hw/i386/Kconfig:

config SGX
bool
depends on KVM

So move SGX related files under kvm/ for clarity.

---
 hw/i386/{ => kvm}/sgx-epc.c  | 0
 hw/i386/{ => kvm}/sgx-stub.c | 0
 hw/i386/{ => kvm}/sgx.c      | 0
 hw/i386/kvm/meson.build      | 3 +++
 hw/i386/meson.build          | 2 --
 5 files changed, 3 insertions(+), 2 deletions(-)
 rename hw/i386/{ => kvm}/sgx-epc.c (100%)
 rename hw/i386/{ => kvm}/sgx-stub.c (100%)
 rename hw/i386/{ => kvm}/sgx.c (100%)
hw/i386/kvm/sgx-epc.c renamed from hw/i386/sgx-epc.c +0 -0
similarity index 100%
rename from hw/i386/sgx-epc.c
rename to hw/i386/kvm/sgx-epc.c
hw/i386/kvm/sgx-stub.c renamed from hw/i386/sgx-stub.c +0 -0
similarity index 100%
rename from hw/i386/sgx-stub.c
rename to hw/i386/kvm/sgx-stub.c
hw/i386/kvm/sgx.c renamed from hw/i386/sgx.c +0 -0
similarity index 100%
rename from hw/i386/sgx.c
rename to hw/i386/kvm/sgx.c
hw/i386/kvm/meson.build +3 -0
index a4a2e23c06..c9c7adea77 100644
@@ -13,6 +13,9 @@ i386_kvm_ss.add(when: 'CONFIG_XEN_EMU', if_true: files(
   'xenstore_impl.c',
   ))
 
+i386_ss.add(when: 'CONFIG_SGX', if_true: files('sgx-epc.c','sgx.c'),
+                                if_false: files('sgx-stub.c'))
+
 i386_ss.add_all(when: 'CONFIG_KVM', if_true: i386_kvm_ss)
 
 xen_stubs_ss = ss.source_set()
hw/i386/meson.build +0 -2
index b9c1ca39cb..d7318b83e4 100644
@@ -17,8 +17,6 @@ i386_ss.add(when: 'CONFIG_Q35', if_true: files('pc_q35.c'))
 i386_ss.add(when: 'CONFIG_VMMOUSE', if_true: files('vmmouse.c'))
 i386_ss.add(when: 'CONFIG_VMPORT', if_true: files('vmport.c'))
 i386_ss.add(when: 'CONFIG_VTD', if_true: files('intel_iommu.c'))
-i386_ss.add(when: 'CONFIG_SGX', if_true: files('sgx-epc.c','sgx.c'),
-                                if_false: files('sgx-stub.c'))
 
 i386_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-common.c'))
 i386_ss.add(when: 'CONFIG_PC', if_true: files(
Signature · 1 line
2.41.0
#3 lore raw

PATCH v2 3/3 hw/i386/sgx: Use QDev API

In reply to Philippe Mathieu-Daudé

Prefer the QDev API over the low level QOM one.
No logical change intended.

---
Only build-tested.

---
 hw/i386/kvm/sgx.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
hw/i386/kvm/sgx.c +6 -8
index 70305547d4..de76397bcf 100644
@@ -286,7 +286,6 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms)
     SGXEPCState *sgx_epc = &pcms->sgx_epc;
     X86MachineState *x86ms = X86_MACHINE(pcms);
     SgxEPCList *list = NULL;
-    Object *obj;
 
     memset(sgx_epc, 0, sizeof(SGXEPCState));
     if (!x86ms->sgx_epc_list) {
@@ -300,16 +299,15 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms)
                                 &sgx_epc->mr);
 
     for (list = x86ms->sgx_epc_list; list; list = list->next) {
-        obj = object_new("sgx-epc");
+        DeviceState *dev = qdev_new(TYPE_SGX_EPC);
 
         /* set the memdev link with memory backend */
-        object_property_parse(obj, SGX_EPC_MEMDEV_PROP, list->value->memdev,
-                              &error_fatal);
+        object_property_parse(OBJECT(dev), SGX_EPC_MEMDEV_PROP,
+                              list->value->memdev, &error_fatal);
         /* set the numa node property for sgx epc object */
-        object_property_set_uint(obj, SGX_EPC_NUMA_NODE_PROP, list->value->node,
-                             &error_fatal);
-        object_property_set_bool(obj, "realized", true, &error_fatal);
-        object_unref(obj);
+        object_property_set_uint(OBJECT(dev), SGX_EPC_NUMA_NODE_PROP,
+                                 list->value->node, &error_fatal);
+        qdev_realize_and_unref(dev, NULL, &error_fatal);
     }
 
     if ((sgx_epc->base + sgx_epc->size) < sgx_epc->base) {
Signature · 1 line
2.41.0