cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qapi-Cleanup-SGX-related-comments-and-restore-sectio.patch

432cb7
From d0cd7be4d347ebe118eb8f3f2fc2eb3e3eb77e3a Mon Sep 17 00:00:00 2001
432cb7
From: Yang Zhong <yang.zhong@intel.com>
432cb7
Date: Thu, 20 Jan 2022 17:31:04 -0500
432cb7
Subject: [PATCH 5/7] qapi: Cleanup SGX related comments and restore
432cb7
 @section-size
432cb7
MIME-Version: 1.0
432cb7
Content-Type: text/plain; charset=UTF-8
432cb7
Content-Transfer-Encoding: 8bit
432cb7
432cb7
RH-Author: Paul Lai <None>
432cb7
RH-MergeRequest: 111: numa: Enable numa for SGX EPC sections
432cb7
RH-Commit: [5/5] 497dbeaebb7b8f99f5f8a7de58000dcab0d0c22d
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
The SGX NUMA patches were merged into Qemu 7.0 release, we need
432cb7
clarify detailed version history information and also change
432cb7
some related comments, which make SGX related comments clearer.
432cb7
432cb7
The QMP command schema promises backwards compatibility as standard.
432cb7
We temporarily restore "@section-size", which can avoid incompatible
432cb7
API breakage. The "@section-size" will be deprecated in 7.2 version.
432cb7
432cb7
Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
432cb7
Signed-off-by: Yang Zhong <yang.zhong@intel.com>
432cb7
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
432cb7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
432cb7
Message-Id: <20220120223104.437161-1-yang.zhong@intel.com>
432cb7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
432cb7
(cherry picked from commit a66bd91f030827742778a9e0da19fe55716b4a60)
432cb7
Signed-off-by: Paul Lai <plai@redhat.com>
432cb7
---
432cb7
 docs/about/deprecated.rst | 13 +++++++++++++
432cb7
 hw/i386/sgx.c             | 11 +++++++++--
432cb7
 qapi/machine.json         |  4 ++--
432cb7
 qapi/misc-target.json     | 22 +++++++++++++++++-----
432cb7
 4 files changed, 41 insertions(+), 9 deletions(-)
432cb7
432cb7
diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst
432cb7
index ff7488cb63..33925edf45 100644
432cb7
--- a/docs/about/deprecated.rst
432cb7
+++ b/docs/about/deprecated.rst
432cb7
@@ -270,6 +270,19 @@ accepted incorrect commands will return an error. Users should make sure that
432cb7
 all arguments passed to ``device_add`` are consistent with the documented
432cb7
 property types.
432cb7
 
432cb7
+``query-sgx`` return value member ``section-size`` (since 7.0)
432cb7
+''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
432cb7
+
432cb7
+Member ``section-size`` in return value elements with meta-type ``uint64`` is
432cb7
+deprecated.  Use ``sections`` instead.
432cb7
+
432cb7
+
432cb7
+``query-sgx-capabilities`` return value member ``section-size`` (since 7.0)
432cb7
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
432cb7
+
432cb7
+Member ``section-size`` in return value elements with meta-type ``uint64`` is
432cb7
+deprecated.  Use ``sections`` instead.
432cb7
+
432cb7
 System accelerators
432cb7
 -------------------
432cb7
 
432cb7
diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c
432cb7
index 5de5dd0893..a2b318dd93 100644
432cb7
--- a/hw/i386/sgx.c
432cb7
+++ b/hw/i386/sgx.c
432cb7
@@ -83,7 +83,7 @@ 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 SGXEPCSectionList *sgx_calc_host_epc_sections(void)
432cb7
+static SGXEPCSectionList *sgx_calc_host_epc_sections(uint64_t *size)
432cb7
 {
432cb7
     SGXEPCSectionList *head = NULL, **tail = &head;
432cb7
     SGXEPCSection *section;
432cb7
@@ -106,6 +106,7 @@ static SGXEPCSectionList *sgx_calc_host_epc_sections(void)
432cb7
         section = g_new0(SGXEPCSection, 1);
432cb7
         section->node = j++;
432cb7
         section->size = sgx_calc_section_metric(ecx, edx);
432cb7
+        *size += section->size;
432cb7
         QAPI_LIST_APPEND(tail, section);
432cb7
     }
432cb7
 
432cb7
@@ -156,6 +157,7 @@ SGXInfo *qmp_query_sgx_capabilities(Error **errp)
432cb7
 {
432cb7
     SGXInfo *info = NULL;
432cb7
     uint32_t eax, ebx, ecx, edx;
432cb7
+    uint64_t size = 0;
432cb7
 
432cb7
     int fd = qemu_open_old("/dev/sgx_vepc", O_RDWR);
432cb7
     if (fd < 0) {
432cb7
@@ -173,7 +175,8 @@ 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->sections = sgx_calc_host_epc_sections();
432cb7
+    info->sections = sgx_calc_host_epc_sections(&size);
432cb7
+    info->section_size = size;
432cb7
 
432cb7
     close(fd);
432cb7
 
432cb7
@@ -220,12 +223,14 @@ 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
@@ -249,6 +254,8 @@ 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
diff --git a/qapi/machine.json b/qapi/machine.json
432cb7
index 16e771affc..a9f33d0f27 100644
432cb7
--- a/qapi/machine.json
432cb7
+++ b/qapi/machine.json
432cb7
@@ -1207,7 +1207,7 @@
432cb7
 #
432cb7
 # @memdev: memory backend linked with device
432cb7
 #
432cb7
-# @node: the numa node
432cb7
+# @node: the numa node (Since: 7.0)
432cb7
 #
432cb7
 # Since: 6.2
432cb7
 ##
432cb7
@@ -1288,7 +1288,7 @@
432cb7
 #
432cb7
 # @memdev: memory backend linked with device
432cb7
 #
432cb7
-# @node: the numa node
432cb7
+# @node: the numa node (Since: 7.0)
432cb7
 #
432cb7
 # Since: 6.2
432cb7
 ##
432cb7
diff --git a/qapi/misc-target.json b/qapi/misc-target.json
432cb7
index 1022aa0184..4bc45d2474 100644
432cb7
--- a/qapi/misc-target.json
432cb7
+++ b/qapi/misc-target.json
432cb7
@@ -344,9 +344,9 @@
432cb7
 #
432cb7
 # @node: the numa node
432cb7
 #
432cb7
-# @size: the size of epc section
432cb7
+# @size: the size of EPC section
432cb7
 #
432cb7
-# Since: 6.2
432cb7
+# Since: 7.0
432cb7
 ##
432cb7
 { 'struct': 'SGXEPCSection',
432cb7
   'data': { 'node': 'int',
432cb7
@@ -365,7 +365,13 @@
432cb7
 #
432cb7
 # @flc: true if FLC is supported
432cb7
 #
432cb7
-# @sections: The EPC sections info for guest
432cb7
+# @section-size: The EPC section size for guest
432cb7
+#                Redundant with @sections.  Just for backward compatibility.
432cb7
+#
432cb7
+# @sections: The EPC sections info for guest (Since: 7.0)
432cb7
+#
432cb7
+# Features:
432cb7
+# @deprecated: Member @section-size is deprecated.  Use @sections instead.
432cb7
 #
432cb7
 # Since: 6.2
432cb7
 ##
432cb7
@@ -374,6 +380,8 @@
432cb7
             'sgx1': 'bool',
432cb7
             'sgx2': 'bool',
432cb7
             'flc': 'bool',
432cb7
+            'section-size': { 'type': 'uint64',
432cb7
+                    'features': [ 'deprecated' ] },
432cb7
             'sections': ['SGXEPCSection']},
432cb7
    'if': 'TARGET_I386' }
432cb7
 
432cb7
@@ -390,7 +398,9 @@
432cb7
 #
432cb7
 # -> { "execute": "query-sgx" }
432cb7
 # <- { "return": { "sgx": true, "sgx1" : true, "sgx2" : true,
432cb7
-#                  "flc": true, "section-size" : 0 } }
432cb7
+#                  "flc": true,  "section-size" : 96468992,
432cb7
+#                  "sections": [{"node": 0, "size": 67108864},
432cb7
+#                  {"node": 1, "size": 29360128}]} }
432cb7
 #
432cb7
 ##
432cb7
 { 'command': 'query-sgx', 'returns': 'SGXInfo', 'if': 'TARGET_I386' }
432cb7
@@ -408,7 +418,9 @@
432cb7
 #
432cb7
 # -> { "execute": "query-sgx-capabilities" }
432cb7
 # <- { "return": { "sgx": true, "sgx1" : true, "sgx2" : true,
432cb7
-#                  "flc": true, "section-size" : 0 } }
432cb7
+#                  "flc": true, "section-size" : 96468992,
432cb7
+#                  "section" : [{"node": 0, "size": 67108864},
432cb7
+#                  {"node": 1, "size": 29360128}]} }
432cb7
 #
432cb7
 ##
432cb7
 { 'command': 'query-sgx-capabilities', 'returns': 'SGXInfo', 'if': 'TARGET_I386' }
432cb7
-- 
432cb7
2.27.0
432cb7