cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-numa-Support-SGX-numa-in-the-monitor-and-Libvirt-int.patch

2bc292
From 0f75501ba348dc9fb3ce0198ceafc8093149457d Mon Sep 17 00:00:00 2001
2bc292
From: Yang Zhong <yang.zhong@intel.com>
2bc292
Date: Mon, 1 Nov 2021 12:20:07 -0400
2bc292
Subject: [PATCH 02/12] numa: Support SGX numa in the monitor and Libvirt
2bc292
 interfaces
2bc292
2bc292
RH-Author: Paul Lai <plai@redhat.com>
2bc292
RH-MergeRequest: 65: Enable SGX and add SGX Numa support
2bc292
RH-Commit: [2/5] 8c19cfb1a139fd4dbac771e695a133f16a68437f
2bc292
RH-Bugzilla: 2033708
2bc292
RH-Acked-by: Paolo Bonzini <None>
2bc292
RH-Acked-by: Bandan Das <None>
2bc292
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
2bc292
2bc292
Add the SGXEPCSection list into SGXInfo to show the multiple
2bc292
SGX EPC sections detailed info, not the total size like before.
2bc292
This patch can enable numa support for 'info sgx' command and
2bc292
QMP interfaces. The new interfaces show each EPC section info
2bc292
in one numa node. Libvirt can use QMP interface to get the
2bc292
detailed host SGX EPC capabilities to decide how to allocate
2bc292
host EPC sections to guest.
2bc292
2bc292
(qemu) info sgx
2bc292
 SGX support: enabled
2bc292
 SGX1 support: enabled
2bc292
 SGX2 support: enabled
2bc292
 FLC support: enabled
2bc292
 NUMA node #0: size=67108864
2bc292
 NUMA node #1: size=29360128
2bc292
2bc292
The QMP interface show:
2bc292
(QEMU) query-sgx
2bc292
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
2bc292
[{"node": 0, "size": 67108864}, {"node": 1, "size": 29360128}], "flc": true}}
2bc292
2bc292
(QEMU) query-sgx-capabilities
2bc292
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
2bc292
[{"node": 0, "size": 17070817280}, {"node": 1, "size": 17079205888}], "flc": true}}
2bc292
2bc292
Signed-off-by: Yang Zhong <yang.zhong@intel.com>
2bc292
Message-Id: <20211101162009.62161-4-yang.zhong@intel.com>
2bc292
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2bc292
(cherry picked from commit 4755927ae12547c2e7cb22c5fa1b39038c6c11b1)
2bc292
Signed-off-by: Paul Lai <plai@redhat.com>
2bc292
---
2bc292
 hw/i386/sgx.c         | 51 +++++++++++++++++++++++++++++++++++--------
2bc292
 qapi/misc-target.json | 19 ++++++++++++++--
2bc292
 2 files changed, 59 insertions(+), 11 deletions(-)
2bc292
2bc292
diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c
2bc292
index d04299904a..5de5dd0893 100644
2bc292
--- a/hw/i386/sgx.c
2bc292
+++ b/hw/i386/sgx.c
2bc292
@@ -83,11 +83,13 @@ static uint64_t sgx_calc_section_metric(uint64_t low, uint64_t high)
2bc292
            ((high & MAKE_64BIT_MASK(0, 20)) << 32);
2bc292
 }
2bc292
 
2bc292
-static uint64_t sgx_calc_host_epc_section_size(void)
2bc292
+static SGXEPCSectionList *sgx_calc_host_epc_sections(void)
2bc292
 {
2bc292
+    SGXEPCSectionList *head = NULL, **tail = &head;
2bc292
+    SGXEPCSection *section;
2bc292
     uint32_t i, type;
2bc292
     uint32_t eax, ebx, ecx, edx;
2bc292
-    uint64_t size = 0;
2bc292
+    uint32_t j = 0;
2bc292
 
2bc292
     for (i = 0; i < SGX_MAX_EPC_SECTIONS; i++) {
2bc292
         host_cpuid(0x12, i + 2, &eax, &ebx, &ecx, &edx;;
2bc292
@@ -101,10 +103,13 @@ static uint64_t sgx_calc_host_epc_section_size(void)
2bc292
             break;
2bc292
         }
2bc292
 
2bc292
-        size += sgx_calc_section_metric(ecx, edx);
2bc292
+        section = g_new0(SGXEPCSection, 1);
2bc292
+        section->node = j++;
2bc292
+        section->size = sgx_calc_section_metric(ecx, edx);
2bc292
+        QAPI_LIST_APPEND(tail, section);
2bc292
     }
2bc292
 
2bc292
-    return size;
2bc292
+    return head;
2bc292
 }
2bc292
 
2bc292
 static void sgx_epc_reset(void *opaque)
2bc292
@@ -168,13 +173,35 @@ SGXInfo *qmp_query_sgx_capabilities(Error **errp)
2bc292
     info->sgx1 = eax & (1U << 0) ? true : false;
2bc292
     info->sgx2 = eax & (1U << 1) ? true : false;
2bc292
 
2bc292
-    info->section_size = sgx_calc_host_epc_section_size();
2bc292
+    info->sections = sgx_calc_host_epc_sections();
2bc292
 
2bc292
     close(fd);
2bc292
 
2bc292
     return info;
2bc292
 }
2bc292
 
2bc292
+static SGXEPCSectionList *sgx_get_epc_sections_list(void)
2bc292
+{
2bc292
+    GSList *device_list = sgx_epc_get_device_list();
2bc292
+    SGXEPCSectionList *head = NULL, **tail = &head;
2bc292
+    SGXEPCSection *section;
2bc292
+
2bc292
+    for (; device_list; device_list = device_list->next) {
2bc292
+        DeviceState *dev = device_list->data;
2bc292
+        Object *obj = OBJECT(dev);
2bc292
+
2bc292
+        section = g_new0(SGXEPCSection, 1);
2bc292
+        section->node = object_property_get_uint(obj, SGX_EPC_NUMA_NODE_PROP,
2bc292
+                                                 &error_abort);
2bc292
+        section->size = object_property_get_uint(obj, SGX_EPC_SIZE_PROP,
2bc292
+                                                 &error_abort);
2bc292
+        QAPI_LIST_APPEND(tail, section);
2bc292
+    }
2bc292
+    g_slist_free(device_list);
2bc292
+
2bc292
+    return head;
2bc292
+}
2bc292
+
2bc292
 SGXInfo *qmp_query_sgx(Error **errp)
2bc292
 {
2bc292
     SGXInfo *info = NULL;
2bc292
@@ -193,14 +220,13 @@ SGXInfo *qmp_query_sgx(Error **errp)
2bc292
         return NULL;
2bc292
     }
2bc292
 
2bc292
-    SGXEPCState *sgx_epc = &pcms->sgx_epc;
2bc292
     info = g_new0(SGXInfo, 1);
2bc292
 
2bc292
     info->sgx = true;
2bc292
     info->sgx1 = true;
2bc292
     info->sgx2 = true;
2bc292
     info->flc = true;
2bc292
-    info->section_size = sgx_epc->size;
2bc292
+    info->sections = sgx_get_epc_sections_list();
2bc292
 
2bc292
     return info;
2bc292
 }
2bc292
@@ -208,6 +234,7 @@ SGXInfo *qmp_query_sgx(Error **errp)
2bc292
 void hmp_info_sgx(Monitor *mon, const QDict *qdict)
2bc292
 {
2bc292
     Error *err = NULL;
2bc292
+    SGXEPCSectionList *section_list, *section;
2bc292
     g_autoptr(SGXInfo) info = qmp_query_sgx(&err;;
2bc292
 
2bc292
     if (err) {
2bc292
@@ -222,8 +249,14 @@ void hmp_info_sgx(Monitor *mon, const QDict *qdict)
2bc292
                    info->sgx2 ? "enabled" : "disabled");
2bc292
     monitor_printf(mon, "FLC support: %s\n",
2bc292
                    info->flc ? "enabled" : "disabled");
2bc292
-    monitor_printf(mon, "size: %" PRIu64 "\n",
2bc292
-                   info->section_size);
2bc292
+
2bc292
+    section_list = info->sections;
2bc292
+    for (section = section_list; section; section = section->next) {
2bc292
+        monitor_printf(mon, "NUMA node #%" PRId64 ": ",
2bc292
+                       section->value->node);
2bc292
+        monitor_printf(mon, "size=%" PRIu64 "\n",
2bc292
+                       section->value->size);
2bc292
+    }
2bc292
 }
2bc292
 
2bc292
 bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size)
2bc292
diff --git a/qapi/misc-target.json b/qapi/misc-target.json
2bc292
index 5aa2b95b7d..1022aa0184 100644
2bc292
--- a/qapi/misc-target.json
2bc292
+++ b/qapi/misc-target.json
2bc292
@@ -337,6 +337,21 @@
2bc292
   'if': 'TARGET_ARM' }
2bc292
 
2bc292
 
2bc292
+##
2bc292
+# @SGXEPCSection:
2bc292
+#
2bc292
+# Information about intel SGX EPC section info
2bc292
+#
2bc292
+# @node: the numa node
2bc292
+#
2bc292
+# @size: the size of epc section
2bc292
+#
2bc292
+# Since: 6.2
2bc292
+##
2bc292
+{ 'struct': 'SGXEPCSection',
2bc292
+  'data': { 'node': 'int',
2bc292
+            'size': 'uint64'}}
2bc292
+
2bc292
 ##
2bc292
 # @SGXInfo:
2bc292
 #
2bc292
@@ -350,7 +365,7 @@
2bc292
 #
2bc292
 # @flc: true if FLC is supported
2bc292
 #
2bc292
-# @section-size: The EPC section size for guest
2bc292
+# @sections: The EPC sections info for guest
2bc292
 #
2bc292
 # Since: 6.2
2bc292
 ##
2bc292
@@ -359,7 +374,7 @@
2bc292
             'sgx1': 'bool',
2bc292
             'sgx2': 'bool',
2bc292
             'flc': 'bool',
2bc292
-            'section-size': 'uint64'},
2bc292
+            'sections': ['SGXEPCSection']},
2bc292
    'if': 'TARGET_I386' }
2bc292
 
2bc292
 ##
2bc292
-- 
2bc292
2.27.0
2bc292