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

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