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

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