SGX NUMA support
PATCH 2/6 monitor: Support 'info numa' command
In reply to Yang ZhongAdd the MEMORY_DEVICE_INFO_KIND_SGX_EPC case for SGX numa info with 'info numa' command in the monitor.
--- hw/core/numa.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/core/numa.c +6 -0
@@ -756,6 +756,7 @@ static void numa_stat_memory_devices(NumaNodeMem node_mem[])PCDIMMDeviceInfo *pcdimm_info;VirtioPMEMDeviceInfo *vpi;VirtioMEMDeviceInfo *vmi; +SgxEPCDeviceInfo *se;for (info = info_list; info; info = info->next) {MemoryDeviceInfo *value = info->value;
@@ -781,6 +782,11 @@ static void numa_stat_memory_devices(NumaNodeMem node_mem[]) node_mem[vmi->node].node_mem += vmi->size; node_mem[vmi->node].node_plugged_mem += vmi->size;break ; +case MEMORY_DEVICE_INFO_KIND_SGX_EPC : + se = value->u.sgx_epc.data; + node_mem[se->node].node_mem += se->size; + node_mem[se->node].node_plugged_mem =0 ; +break ;default :g_assert_not_reached (); }
PATCH 1/6 numa: Enable numa for SGX EPC sections
In reply to Yang ZhongThe basic SGX did not enable numa for SGX EPC sections, which result in all EPC sections located in numa node 0. This patch enable SGX numa function in the guest and the EPC section can work with RAM as one numa node.
The Guest kernel related log:
[ 0.009981] ACPI: SRAT: Node 0 PXM 0 [mem 0x180000000-0x183ffffff] [ 0.009982] ACPI: SRAT: Node 1 PXM 1 [mem 0x184000000-0x185bfffff]
The SRAT table can normally show SGX EPC sections menory info in different numa nodes.
The SGX EPC numa related command:
......
-m 4G,maxmem=20G \
-smp sockets=2,cores=2 \
-cpu host,+sgx-provisionkey \
-object memory-backend-ram,size=2G,host-nodes=0,policy=bind,id=node0 \
-object memory-backend-epc,id=mem0,size=64M,prealloc=on,host-nodes=0,policy=bind \
-numa node,nodeid=0,cpus=0-1,memdev=node0 \
-object memory-backend-ram,size=2G,host-nodes=1,policy=bind,id=node1 \
-object memory-backend-epc,id=mem1,size=28M,prealloc=on,host-nodes=1,policy=bind \
-numa node,nodeid=1,cpus=2-3,memdev=node1 \
-M sgx-epc.0.memdev=mem0,sgx-epc.0.node=0,sgx-epc.1.memdev=mem1,sgx-epc.1.node=1 \
......
--- qapi/machine.json | 6 +++++- include/hw/i386/sgx-epc.h | 3 +++ hw/i386/acpi-build.c | 4 ++++ hw/i386/sgx-epc.c | 3 +++ hw/i386/sgx.c | 44 +++++++++++++++++++++++++++++++++++++++ monitor/hmp-cmds.c | 1 + qemu-options.hx | 4 ++-- 7 files changed, 62 insertions(+), 3 deletions(-)
qapi/machine.json +5 -1
@@ -1213,6 +1213,7 @@ 'data': { '*id': 'str', 'memaddr': 'size', 'size': 'size', + 'node': 'int', 'memdev': 'str' } }
@@ -1288,7 +1289,10 @@ # Since: 6.2 ## { 'struct': 'SgxEPC', - 'data': { 'memdev': 'str' } } + 'data': { 'memdev': 'str', + 'node': 'int' + } +} ## # @SgxEPCProperties:
include/hw/i386/sgx-epc.h +3 -0
@@ -25,6 +25,7 @@#define SGX_EPC_ADDR_PROP "addr"#define SGX_EPC_SIZE_PROP "size"#define SGX_EPC_MEMDEV_PROP "memdev" +#define SGX_EPC_NUMA_NODE_PROP "node"/** * SGXEPCDevice:
@@ -38,6 +39,7 @@ typedef struct SGXEPCDevice {/* public */ uint64_t addr; +uint32_t node;HostMemoryBackendEpc *hostmem; } SGXEPCDevice;
@@ -56,6 +58,7 @@ typedef struct SGXEPCState { } SGXEPCState;int sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size); +void sgx_epc_build_srat (GArray *table_data);static inline uint64_t sgx_epc_above_4g_end (SGXEPCState *sgx_epc) {
hw/i386/acpi-build.c +4 -0
@@ -2062,6 +2062,10 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)nvdimm_build_srat (table_data); } +if (pcms->sgx_epc.size !=0 ) { +sgx_epc_build_srat (table_data); + } +/* * TODO: this part is not in ACPI spec and current linux kernel boots fine * without these entries. But I recall there were issues the last time I
hw/i386/sgx-epc.c +3 -0
@@ -21,6 +21,7 @@static Property sgx_epc_properties[] = {DEFINE_PROP_UINT64 (SGX_EPC_ADDR_PROP , SGXEPCDevice, addr,0 ), +DEFINE_PROP_UINT32 (SGX_EPC_NUMA_NODE_PROP , SGXEPCDevice, node,0 ),DEFINE_PROP_LINK (SGX_EPC_MEMDEV_PROP , SGXEPCDevice, hostmem, TYPE_MEMORY_BACKEND_EPC, HostMemoryBackendEpc *),DEFINE_PROP_END_OF_LIST (),
@@ -139,6 +140,8 @@ static void sgx_epc_md_fill_device_info(const MemoryDeviceState *md, se->memaddr = epc->addr; se->size =object_property_get_uint (OBJECT (epc),SGX_EPC_SIZE_PROP ,NULL ); + se->node =object_property_get_uint (OBJECT (epc),SGX_EPC_NUMA_NODE_PROP , +NULL ); se->memdev =object_get_canonical_path (OBJECT (epc->hostmem)); info->u.sgx_epc.data = se;
hw/i386/sgx.c +44 -0
62 lines not on this page · raw message
monitor/hmp-cmds.c +1 -0
@@ -1878,6 +1878,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) se->id ? se->id : "");monitor_printf (mon," memaddr: 0x%" PRIx64"\n" , se->memaddr);monitor_printf (mon," size: %" PRIu64"\n" , se->size); +monitor_printf (mon," node: %" PRId64"\n" , se->node);monitor_printf (mon," memdev: %s\n" , se->memdev);break ;default :
qemu-options.hx +2 -2
@@ -127,11 +127,11 @@ SRST ERST DEF("M", HAS_ARG, QEMU_OPTION_M, - " sgx-epc.0.memdev=memid\n", + " sgx-epc.0.memdev=memid,sgx-epc.0.node=numaid\n", QEMU_ARCH_ALL) SRST -``sgx-epc.0.memdev=@var{memid}`` +``sgx-epc.0.memdev=@var{memid},sgx-epc.0.node=@var{numaid}`` Define an SGX EPC section. ERST
cover SGX NUMA support
The basic SGX patches were merged into Qemu release, the left NUMA function for SGX should be enabled. The patch1 implemented the SGX NUMA ACPI to enable NUMA in the SGX guest. Since Libvirt need detailed host SGX EPC sections info to decide how to allocate EPC sections for SGX NUMA guest, the SGXEPCSection list is introduced to show detailed sections info in the monitor or HMP interface.
Please help review this patchset, the link also can be found:
https://github.com/intel/qemu-sgx upstream
Yang Zhong (6):
numa: Enable numa for SGX EPC sections
monitor: Support 'info numa' command
numa: Add SGXEPCSection list for multiple sections
monitor: numa support for 'info sgx' command
numa: Enable numa for libvirt interface
doc: Add the SGX numa description
docs/system/i386/sgx.rst | 31 +++++++++++++-- qapi/machine.json | 6 ++- qapi/misc-target.json | 19 ++++++++- include/hw/i386/sgx-epc.h | 3 ++ hw/core/numa.c | 6 +++ hw/i386/acpi-build.c | 4 ++ hw/i386/sgx-epc.c | 3 ++ hw/i386/sgx.c | 84 +++++++++++++++++++++++++++++++++++---- monitor/hmp-cmds.c | 1 + target/i386/monitor.c | 11 ++++- qemu-options.hx | 4 +- 11 files changed, 154 insertions(+), 18 deletions(-)
PATCH 5/6 numa: Enable numa for libvirt interface
Libvirt need get the detailed host SGX EPC capabilities to support numa function. Libvirt can decide how to allocate host EPC sections to guest numa from host numa info.
(QEMU) query-sgx-capabilities
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"index": 0, "size": 17070817280}, {"index": 1, "size": 17079205888}], "flc": true}}
--- hw/i386/sgx.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
hw/i386/sgx.c +10 -5
@@ -74,11 +74,13 @@ static uint64_t sgx_calc_section_metric(uint64_t low, uint64_t high) ((high &MAKE_64BIT_MASK (0 ,20 )) <<32 ); } -static uint64_t sgx_calc_host_epc_section_size (void ) +static SGXEPCSectionList *sgx_calc_host_epc_sections (void ) { +SGXEPCSectionList *head =NULL , **tail = &head; +SGXEPCSection *section;uint32_t i, type;uint32_t eax, ebx, ecx, edx; -uint64_t size =0 ; +uint32_t j =0 ;for (i =0 ; i <SGX_MAX_EPC_SECTIONS ; i++) {host_cpuid (0x12 , i +2 , &eax, &ebx, &ecx, &edx);
@@ -92,10 +94,13 @@ static uint64_t sgx_calc_host_epc_section_size(void)break ; } - size +=sgx_calc_section_metric (ecx, edx); + section =g_new0 (SGXEPCSection,1 ); + section->index = j++; + section->size =sgx_calc_section_metric (ecx, edx); +QAPI_LIST_APPEND (tail, section); } -return size; +return head; }SGXInfo *sgx_get_capabilities (Error **errp)
@@ -119,7 +124,7 @@ SGXInfo *sgx_get_capabilities(Error **errp) info->sgx1 = eax & (1U <<0 ) ? true : false; info->sgx2 = eax & (1U <<1 ) ? true : false; - info->section_size =sgx_calc_host_epc_section_size (); + info->sections =sgx_calc_host_epc_sections ();close (fd);
PATCH 3/6 numa: Add SGXEPCSection list for multiple sections
In reply to Yang ZhongThe SGXEPCSection list added into SGXInfo to show the multiple SGX EPC sections detailed info, not the total size like before.
--- qapi/misc-target.json | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
qapi/misc-target.json +17 -2
@@ -334,6 +334,21 @@ 'returns': 'SevAttestationReport', 'if': 'TARGET_I386' } +## +# @SGXEPCSection: +# +# Information about intel SGX EPC section info +# +# @index: the SGX epc section index +# +# @size: the size of epc section +# +# Since: 6.2 +## +{ 'struct': 'SGXEPCSection', + 'data': { 'index': 'uint64', + 'size': 'uint64'}} + ## # @SGXInfo: #
@@ -347,7 +362,7 @@ # # @flc: true if FLC is supported # -# @section-size: The EPC section size for guest +# @sections: The EPC sections info for guest # # Since: 6.2 ##
@@ -356,7 +371,7 @@ 'sgx1': 'bool', 'sgx2': 'bool', 'flc': 'bool', - 'section-size': 'uint64'}, + 'sections': ['SGXEPCSection']}, 'if': 'TARGET_I386' } ##
PATCH 4/6 monitor: numa support for 'info sgx' command
In reply to Yang ZhongThis patch can enable numa support for 'info sgx' command in the monitor, which can show detailed SGX EPC sections info.
(qemu) info sgx
SGX support: enabled
SGX1 support: enabled
SGX2 support: enabled
FLC support: enabled
SECTION #0: size=67108864
SECTION #1: size=29360128
The QMP interface show:
(QEMU) query-sgx
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"index": 0, "size": 67108864}, {"index": 1, "size": 29360128}], "flc": true}}
--- hw/i386/sgx.c | 25 +++++++++++++++++++++++-- target/i386/monitor.c | 11 +++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-)
hw/i386/sgx.c +23 -2
@@ -126,6 +126,28 @@ SGXInfo *sgx_get_capabilities(Error **errp)return info; } +static SGXEPCSectionList *sgx_get_epc_sections_list (void ) +{ +GSList *device_list =sgx_epc_get_device_list (); +SGXEPCSectionList *head =NULL , **tail = &head; +SGXEPCSection *section; +uint64_t i =0 ; + +for (; device_list; device_list = device_list->next) { +DeviceState *dev = device_list->data; +Object *obj =OBJECT (dev); + + section =g_new0 (SGXEPCSection,1 ); + section->index = i++; + section->size =object_property_get_uint (obj,SGX_EPC_SIZE_PROP , + &error_abort); +QAPI_LIST_APPEND (tail, section); + } +g_slist_free (device_list); + +return head; +} +SGXInfo *sgx_get_info (Error **errp) {SGXInfo *info =NULL ;
@@ -144,14 +166,13 @@ SGXInfo *sgx_get_info(Error **errp)return NULL ; } -SGXEPCState *sgx_epc = &pcms->sgx_epc; info =g_new0 (SGXInfo,1 ); info->sgx = true; info->sgx1 = true; info->sgx2 = true; info->flc = true; - info->section_size = sgx_epc->size; + info->sections =sgx_get_epc_sections_list ();return info; }
target/i386/monitor.c +9 -2
@@ -773,6 +773,7 @@ SGXInfo *qmp_query_sgx(Error **errp)void hmp_info_sgx (Monitor *mon,const QDict *qdict) {Error *err =NULL ; +SGXEPCSectionList *section_list, *section;g_autoptr (SGXInfo) info =qmp_query_sgx (&err);if (err) {
@@ -787,8 +788,14 @@ void hmp_info_sgx(Monitor *mon, const QDict *qdict) info->sgx2 ? "enabled" : "disabled");monitor_printf (mon,"FLC support: %s\n" , info->flc ?"enabled" :"disabled" ); -monitor_printf (mon,"size: %" PRIu64"\n" , - info->section_size); + + section_list = info->sections; +for (section = section_list; section; section = section->next) { +monitor_printf (mon,"SECTION #%" PRId64": " , + section->value->index); +monitor_printf (mon,"size=%" PRIu64"\n" , + section->value->size); + } }SGXInfo *qmp_query_sgx_capabilities (Error **errp)
PATCH 6/6 doc: Add the SGX numa description
In reply to Yang ZhongAdd the SGX numa reference command and how to check if SGX numa is support or not with multiple EPC sections.
--- docs/system/i386/sgx.rst | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
docs/system/i386/sgx.rst +27 -4
@@ -141,8 +141,7 @@ To launch a SGX guest: |qemu_system_x86| \\ -cpu host,+sgx-provisionkey \\ -object memory-backend-epc,id=mem1,size=64M,prealloc=on \\ - -object memory-backend-epc,id=mem2,size=28M \\ - -M sgx-epc.0.memdev=mem1,sgx-epc.1.memdev=mem2 + -M sgx-epc.0.memdev=mem1,sgx-epc.0.node=0 Utilizing SGX in the guest requires a kernel/OS with SGX support. The support can be determined in guest by::
@@ -152,8 +151,32 @@ The support can be determined in guest by:: and SGX epc info by:: $ dmesg | grep sgx - [ 1.242142] sgx: EPC section 0x180000000-0x181bfffff - [ 1.242319] sgx: EPC section 0x181c00000-0x1837fffff + [ 0.182807] sgx: EPC section 0x140000000-0x143ffffff + [ 0.183695] sgx: [Firmware Bug]: Unable to map EPC section to online node. Fallback to the NUMA node 0. + +To launch a SGX numa guest: + +.. parsed-literal:: + + |qemu_system_x86| \\ + -cpu host,+sgx-provisionkey \\ + -object memory-backend-ram,size=2G,host-nodes=0,policy=bind,id=node0 \\ + -object memory-backend-epc,id=mem0,size=64M,prealloc=on,host-nodes=0,policy=bind \\ + -numa node,nodeid=0,cpus=0-1,memdev=node0 \\ + -object memory-backend-ram,size=2G,host-nodes=1,policy=bind,id=node1 \\ + -object memory-backend-epc,id=mem1,size=28M,prealloc=on,host-nodes=1,policy=bind \\ + -numa node,nodeid=1,cpus=2-3,memdev=node1 \\ + -M sgx-epc.0.memdev=mem0,sgx-epc.0.node=0,sgx-epc.1.memdev=mem1,sgx-epc.1.node=1 + +and SGX epc numa info by:: + + $ dmesg | grep sgx + [ 0.369937] sgx: EPC section 0x180000000-0x183ffffff + [ 0.370259] sgx: EPC section 0x184000000-0x185bfffff + + $ dmesg | grep SRAT + [ 0.009981] ACPI: SRAT: Node 0 PXM 0 [mem 0x180000000-0x183ffffff] + [ 0.009982] ACPI: SRAT: Node 1 PXM 1 [mem 0x184000000-0x185bfffff] References ----------
Re: [PATCH 1/6] numa: Enable numa for SGX EPC sections
In reply to Yang ZhongQuoted 49 lines · Yang Zhong
The basic SGX did not enable numa for SGX EPC sections, which result in all EPC sections located in numa node 0. This patch enable SGX numa function in the guest and the EPC section can work with RAM as one numa node.
The Guest kernel related log:
[ 0.009981] ACPI: SRAT: Node 0 PXM 0 [mem 0x180000000-0x183ffffff] [ 0.009982] ACPI: SRAT: Node 1 PXM 1 [mem 0x184000000-0x185bfffff]The SRAT table can normally show SGX EPC sections menory info in different numa nodes.
The SGX EPC numa related command:
......
-m 4G,maxmem=20G \
-smp sockets=2,cores=2 \
-cpu host,+sgx-provisionkey \
-object memory-backend-ram,size=2G,host-nodes=0,policy=bind,id=node0 \
-object memory-backend-epc,id=mem0,size=64M,prealloc=on,host-nodes=0,policy=bind \
-numa node,nodeid=0,cpus=0-1,memdev=node0 \
-object memory-backend-ram,size=2G,host-nodes=1,policy=bind,id=node1 \
-object memory-backend-epc,id=mem1,size=28M,prealloc=on,host-nodes=1,policy=bind \
-numa node,nodeid=1,cpus=2-3,memdev=node1 \
-M sgx-epc.0.memdev=mem0,sgx-epc.0.node=0,sgx-epc.1.memdev=mem1,sgx-epc.1.node=1 \
......Signed-off-by Yang Zhong <[email protected]>--- qapi/machine.json | 6 +++++- include/hw/i386/sgx-epc.h | 3 +++ hw/i386/acpi-build.c | 4 ++++ hw/i386/sgx-epc.c | 3 +++ hw/i386/sgx.c | 44 +++++++++++++++++++++++++++++++++++++++ monitor/hmp-cmds.c | 1 + qemu-options.hx | 4 ++-- 7 files changed, 62 insertions(+), 3 deletions(-)qapi/machine.json +1
-0@@ -1213,6 +1213,7 @@ 'data': { '*id': 'str', 'memaddr': 'size', 'size': 'size', + 'node': 'int', 'memdev': 'str' } }
qapi/machine.json line 1295
Quoted 8 lines
qapi/machine.json +4
-1@@ -1288,7 +1289,10 @@ # Since: 6.2 ## { 'struct': 'SgxEPC', - 'data': { 'memdev': 'str' } } + 'data': { 'memdev': 'str', + 'node': 'int' + } +}
Missing documentation of the new member.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH 3/6] numa: Add SGXEPCSection list for multiple sections
In reply to Yang ZhongQuoted 35 lines · Yang Zhong
The SGXEPCSection list added into SGXInfo to show the multiple SGX EPC sections detailed info, not the total size like before.
Signed-off-by Yang Zhong <[email protected]>--- qapi/misc-target.json | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)qapi/misc-target.json +15
-0@@ -334,6 +334,21 @@ 'returns': 'SevAttestationReport', 'if': 'TARGET_I386' } +## +# @SGXEPCSection: +# +# Information about intel SGX EPC section info +# +# @index: the SGX epc section index +# +# @size: the size of epc section +# +# Since: 6.2 +## +{ 'struct': 'SGXEPCSection', + 'data': { 'index': 'uint64', + 'size': 'uint64'}} + ## # @SGXInfo: #
qapi/misc-target.json line 367
Quoted 7 lines
qapi/misc-target.json +1
-1@@ -347,7 +362,7 @@ # # @flc: true if FLC is supported # -# @section-size: The EPC section size for guest +# @sections: The EPC sections info for guest # # Since: 6.2
Given this has not yet been in a stable release, we can make this change...
qapi/misc-target.json line 375
Quoted 8 lines
qapi/misc-target.json +1
-1##@@ -356,7 +371,7 @@ 'sgx1': 'bool', 'sgx2': 'bool', 'flc': 'bool', - 'section-size': 'uint64'}, + 'sections': ['SGXEPCSection']}, 'if': 'TARGET_I386' }
...but are we sure we have the best interface possible if we are still expressing uncertainty about the QAPI used to represent it?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH 5/6] numa: Enable numa for libvirt interface
In reply to Yang ZhongQuoted 51 lines · Yang Zhong
Libvirt need get the detailed host SGX EPC capabilities to support numa function. Libvirt can decide how to allocate host EPC sections to guest numa from host numa info.
(QEMU) query-sgx-capabilities
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"index": 0, "size": 17070817280}, {"index": 1, "size": 17079205888}], "flc": true}}Signed-off-by Yang Zhong <[email protected]>--- hw/i386/sgx.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)hw/i386/sgx.c +9
-4@@ -74,11 +74,13 @@ static uint64_t sgx_calc_section_metric(uint64_t low, uint64_t high) ((high &MAKE_64BIT_MASK (0 ,20 )) <<32 ); } -static uint64_t sgx_calc_host_epc_section_size (void ) +static SGXEPCSectionList *sgx_calc_host_epc_sections (void ) { +SGXEPCSectionList *head =NULL , **tail = &head; +SGXEPCSection *section;uint32_t i, type;uint32_t eax, ebx, ecx, edx; -uint64_t size =0 ; +uint32_t j =0 ;for (i =0 ; i <SGX_MAX_EPC_SECTIONS ; i++) {host_cpuid (0x12 , i +2 , &eax, &ebx, &ecx, &edx);@@ -92,10 +94,13 @@ static uint64_t sgx_calc_host_epc_section_size(void)break ; } - size +=sgx_calc_section_metric (ecx, edx); + section =g_new0 (SGXEPCSection,1 ); + section->index = j++; + section->size =sgx_calc_section_metric (ecx, edx); +QAPI_LIST_APPEND (tail, section); } -return size; +return head; }SGXInfo *sgx_get_capabilities (Error **errp)
hw/i386/sgx.c SGXInfo *sgx_get_capabilities(Error **errp) · line 130
Quoted 8 lines
hw/i386/sgx.c +1
-1@@ -119,7 +124,7 @@ SGXInfo *sgx_get_capabilities(Error **errp) info->sgx1 = eax & (1U <<0 ) ? true : false; info->sgx2 = eax & (1U <<1 ) ? true : false; - info->section_size =sgx_calc_host_epc_section_size (); + info->sections =sgx_calc_host_epc_sections ();close (fd);
This too.
Paolo
Re: [PATCH 4/6] monitor: numa support for 'info sgx' command
In reply to Yang ZhongQuoted 92 lines · Yang Zhong
This patch can enable numa support for 'info sgx' command in the monitor, which can show detailed SGX EPC sections info.
(qemu) info sgx
SGX support: enabled
SGX1 support: enabled
SGX2 support: enabled
FLC support: enabled
SECTION #0: size=67108864
SECTION #1: size=29360128The QMP interface show:
(QEMU) query-sgx
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"index": 0, "size": 67108864}, {"index": 1, "size": 29360128}], "flc": true}}Signed-off-by Yang Zhong <[email protected]>--- hw/i386/sgx.c | 25 +++++++++++++++++++++++-- target/i386/monitor.c | 11 +++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-)hw/i386/sgx.c +23
-2@@ -126,6 +126,28 @@ SGXInfo *sgx_get_capabilities(Error **errp)return info; } +static SGXEPCSectionList *sgx_get_epc_sections_list (void ) +{ +GSList *device_list =sgx_epc_get_device_list (); +SGXEPCSectionList *head =NULL , **tail = &head; +SGXEPCSection *section; +uint64_t i =0 ; + +for (; device_list; device_list = device_list->next) { +DeviceState *dev = device_list->data; +Object *obj =OBJECT (dev); + + section =g_new0 (SGXEPCSection,1 ); + section->index = i++; + section->size =object_property_get_uint (obj,SGX_EPC_SIZE_PROP , + &error_abort); +QAPI_LIST_APPEND (tail, section); + } +g_slist_free (device_list); + +return head; +} +SGXInfo *sgx_get_info (Error **errp) {SGXInfo *info =NULL ;@@ -144,14 +166,13 @@ SGXInfo *sgx_get_info(Error **errp)return NULL ; } -SGXEPCState *sgx_epc = &pcms->sgx_epc; info =g_new0 (SGXInfo,1 ); info->sgx = true; info->sgx1 = true; info->sgx2 = true; info->flc = true; - info->section_size = sgx_epc->size; + info->sections =sgx_get_epc_sections_list ();return info; }target/i386/monitor.c +2
-2@@ -773,6 +773,7 @@ SGXInfo *qmp_query_sgx(Error **errp)void hmp_info_sgx (Monitor *mon,const QDict *qdict) {Error *err =NULL ; +SGXEPCSectionList *section_list, *section;g_autoptr (SGXInfo) info =qmp_query_sgx (&err);if (err) {@@ -787,8 +788,14 @@ void hmp_info_sgx(Monitor *mon, const QDict *qdict) info->sgx2 ? "enabled" : "disabled");monitor_printf (mon,"FLC support: %s\n" , info->flc ?"enabled" :"disabled" ); -monitor_printf (mon,"size: %" PRIu64"\n" , - info->section_size); +
target/i386/monitor.c void hmp_info_sgx(Monitor *mon, const QDict *qdict) · line 801
Quoted 10 lines
target/i386/monitor.c +7
-0+ section_list = info->sections; +for (section = section_list; section; section = section->next) { +monitor_printf (mon,"SECTION #%" PRId64": " , + section->value->index); +monitor_printf (mon,"size=%" PRIu64"\n" , + section->value->size); + } }SGXInfo *qmp_query_sgx_capabilities (Error **errp)
This needs to be squashed in the previous patch.
Paolo
Re: [PATCH 3/6] numa: Add SGXEPCSection list for multiple sections
In reply to Eric BlakeQuoted 5 lines · Eric Blake
Quoted 3 lines
+# @sections: The EPC sections info for guest
#
# Since: 6.2Given this has not yet been in a stable release, we can make this change...
Quoted 10 lines
qapi/misc-target.json line 375
Quoted 8 lines
##
qapi/misc-target.json +1
-1@@ -356,7 +371,7 @@ 'sgx1': 'bool', 'sgx2': 'bool', 'flc': 'bool', - 'section-size': 'uint64'}, + 'sections': ['SGXEPCSection']}, 'if': 'TARGET_I386' }...but are we sure we have the best interface possible if we are still expressing uncertainty about the QAPI used to represent it?
Yes, I think it's better to have a more flexible representation.
Paolo
Re: [PATCH 3/6] numa: Add SGXEPCSection list for multiple sections
In reply to Yang ZhongQuoted 45 lines · Yang Zhong
The SGXEPCSection list added into SGXInfo to show the multiple SGX EPC sections detailed info, not the total size like before.
Signed-off-by Yang Zhong <[email protected]>--- qapi/misc-target.json | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)qapi/misc-target.json +16
-1@@ -334,6 +334,21 @@ 'returns': 'SevAttestationReport', 'if': 'TARGET_I386' } +## +# @SGXEPCSection: +# +# Information about intel SGX EPC section info +# +# @index: the SGX epc section index +# +# @size: the size of epc section +# +# Since: 6.2 +## +{ 'struct': 'SGXEPCSection', + 'data': { 'index': 'uint64', + 'size': 'uint64'}} + ## # @SGXInfo: #@@ -347,7 +362,7 @@ # # @flc: true if FLC is supported # -# @section-size: The EPC section size for guest +# @sections: The EPC sections info for guest # # Since: 6.2 ##
qapi/misc-target.json line 377
Quoted 8 lines
qapi/misc-target.json +1
-1@@ -356,7 +371,7 @@ 'sgx1': 'bool', 'sgx2': 'bool', 'flc': 'bool', - 'section-size': 'uint64'}, + 'sections': ['SGXEPCSection']}, 'if': 'TARGET_I386' } ##
I am not sure the index is particularly useful, but perhaps you should add the node there?
Paolo
Re: [PATCH 1/6] numa: Enable numa for SGX EPC sections
In reply to Eric BlakeQuoted 52 lines · Eric Blake
Quoted 51 lines · Yang Zhong
The basic SGX did not enable numa for SGX EPC sections, which result in all EPC sections located in numa node 0. This patch enable SGX numa function in the guest and the EPC section can work with RAM as one numa node.
The Guest kernel related log:
[ 0.009981] ACPI: SRAT: Node 0 PXM 0 [mem 0x180000000-0x183ffffff] [ 0.009982] ACPI: SRAT: Node 1 PXM 1 [mem 0x184000000-0x185bfffff]The SRAT table can normally show SGX EPC sections menory info in different numa nodes.
The SGX EPC numa related command:
......
-m 4G,maxmem=20G \
-smp sockets=2,cores=2 \
-cpu host,+sgx-provisionkey \
-object memory-backend-ram,size=2G,host-nodes=0,policy=bind,id=node0 \
-object memory-backend-epc,id=mem0,size=64M,prealloc=on,host-nodes=0,policy=bind \
-numa node,nodeid=0,cpus=0-1,memdev=node0 \
-object memory-backend-ram,size=2G,host-nodes=1,policy=bind,id=node1 \
-object memory-backend-epc,id=mem1,size=28M,prealloc=on,host-nodes=1,policy=bind \
-numa node,nodeid=1,cpus=2-3,memdev=node1 \
-M sgx-epc.0.memdev=mem0,sgx-epc.0.node=0,sgx-epc.1.memdev=mem1,sgx-epc.1.node=1 \
......Signed-off-by Yang Zhong <[email protected]>--- qapi/machine.json | 6 +++++- include/hw/i386/sgx-epc.h | 3 +++ hw/i386/acpi-build.c | 4 ++++ hw/i386/sgx-epc.c | 3 +++ hw/i386/sgx.c | 44 +++++++++++++++++++++++++++++++++++++++ monitor/hmp-cmds.c | 1 + qemu-options.hx | 4 ++-- 7 files changed, 62 insertions(+), 3 deletions(-)qapi/machine.json +1
-0@@ -1213,6 +1213,7 @@ 'data': { '*id': 'str', 'memaddr': 'size', 'size': 'size', + 'node': 'int', 'memdev': 'str' } }@@ -1288,7 +1289,10 @@ # Since: 6.2 ##
Quoted 9 lines
qapi/machine.json line 1295
Quoted 6 lines
qapi/machine.json +4
-1{ 'struct': 'SgxEPC', - 'data': { 'memdev': 'str' } } + 'data': { 'memdev': 'str', + 'node': 'int' + } +}Missing documentation of the new member.
Sorry for delay response, i will add this in next version, thanks!
Yang
Quoted 4 lines
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH 4/6] monitor: numa support for 'info sgx' command
In reply to Paolo BonziniQuoted 91 lines · Paolo Bonzini
Quoted 90 lines · Yang Zhong
This patch can enable numa support for 'info sgx' command in the monitor, which can show detailed SGX EPC sections info.
(qemu) info sgx
SGX support: enabled
SGX1 support: enabled
SGX2 support: enabled
FLC support: enabled
SECTION #0: size=67108864
SECTION #1: size=29360128The QMP interface show:
(QEMU) query-sgx
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"index": 0, "size": 67108864}, {"index": 1, "size": 29360128}], "flc": true}}Signed-off-by Yang Zhong <[email protected]>--- hw/i386/sgx.c | 25 +++++++++++++++++++++++-- target/i386/monitor.c | 11 +++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-)hw/i386/sgx.c +23
-2@@ -126,6 +126,28 @@ SGXInfo *sgx_get_capabilities(Error **errp)return info; } +static SGXEPCSectionList *sgx_get_epc_sections_list (void ) +{ +GSList *device_list =sgx_epc_get_device_list (); +SGXEPCSectionList *head =NULL , **tail = &head; +SGXEPCSection *section; +uint64_t i =0 ; + +for (; device_list; device_list = device_list->next) { +DeviceState *dev = device_list->data; +Object *obj =OBJECT (dev); + + section =g_new0 (SGXEPCSection,1 ); + section->index = i++; + section->size =object_property_get_uint (obj,SGX_EPC_SIZE_PROP , + &error_abort); +QAPI_LIST_APPEND (tail, section); + } +g_slist_free (device_list); + +return head; +} +SGXInfo *sgx_get_info (Error **errp) {SGXInfo *info =NULL ;@@ -144,14 +166,13 @@ SGXInfo *sgx_get_info(Error **errp)return NULL ; } -SGXEPCState *sgx_epc = &pcms->sgx_epc; info =g_new0 (SGXInfo,1 ); info->sgx = true; info->sgx1 = true; info->sgx2 = true; info->flc = true; - info->section_size = sgx_epc->size; + info->sections =sgx_get_epc_sections_list ();return info; }target/i386/monitor.c +6
-2@@ -773,6 +773,7 @@ SGXInfo *qmp_query_sgx(Error **errp)void hmp_info_sgx (Monitor *mon,const QDict *qdict) {Error *err =NULL ; +SGXEPCSectionList *section_list, *section;g_autoptr (SGXInfo) info =qmp_query_sgx (&err);if (err) {@@ -787,8 +788,14 @@ void hmp_info_sgx(Monitor *mon, const QDict *qdict) info->sgx2 ? "enabled" : "disabled");monitor_printf (mon,"FLC support: %s\n" , info->flc ?"enabled" :"disabled" ); -monitor_printf (mon,"size: %" PRIu64"\n" , - info->section_size); + + section_list = info->sections; +for (section = section_list; section; section = section->next) { +monitor_printf (mon,"SECTION #%" PRId64": " , + section->value->index);
Quoted 9 lines
target/i386/monitor.c void hmp_info_sgx(Monitor *mon, const QDict *qdict)
Quoted 6 lines
target/i386/monitor.c +3
-0+monitor_printf (mon,"size=%" PRIu64"\n" , + section->value->size); + } }SGXInfo *qmp_query_sgx_capabilities (Error **errp)This needs to be squashed in the previous patch.
Okay, let me do it in next version, thanks!
Yang
Quoted 1 line
Paolo
Re: [PATCH 3/6] numa: Add SGXEPCSection list for multiple sections
In reply to Eric BlakeQuoted 37 lines · Eric Blake
Quoted 36 lines · Yang Zhong
The SGXEPCSection list added into SGXInfo to show the multiple SGX EPC sections detailed info, not the total size like before.
Signed-off-by Yang Zhong <[email protected]>--- qapi/misc-target.json | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)qapi/misc-target.json +15
-0@@ -334,6 +334,21 @@ 'returns': 'SevAttestationReport', 'if': 'TARGET_I386' } +## +# @SGXEPCSection: +# +# Information about intel SGX EPC section info +# +# @index: the SGX epc section index +# +# @size: the size of epc section +# +# Since: 6.2 +## +{ 'struct': 'SGXEPCSection', + 'data': { 'index': 'uint64', + 'size': 'uint64'}} + ## # @SGXInfo: #@@ -347,7 +362,7 @@ #
Quoted 9 lines
qapi/misc-target.json line 367
Quoted 6 lines
qapi/misc-target.json +1
-1# @flc: true if FLC is supported # -# @section-size: The EPC section size for guest +# @sections: The EPC sections info for guest # # Since: 6.2Given this has not yet been in a stable release, we can make this change...
The basic SGX is only suitable for one vepc section to guest. This new patchset need support NUMA function with multiple vepc to guest. So we need detailed epc or vepc section info. Thanks!
Yang
Quoted 12 lines
qapi/misc-target.json line 375
Quoted 8 lines
qapi/misc-target.json +1
-1##@@ -356,7 +371,7 @@ 'sgx1': 'bool', 'sgx2': 'bool', 'flc': 'bool', - 'section-size': 'uint64'}, + 'sections': ['SGXEPCSection']}, 'if': 'TARGET_I386' }...but are we sure we have the best interface possible if we are still expressing uncertainty about the QAPI used to represent it?
Yes, we need more accurate definition to handle this. Paolo suggested to use the numa node to replace this index, which is much better. Let me change this in next version, thanks!
Yang
Quoted 4 lines
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH 3/6] numa: Add SGXEPCSection list for multiple sections
In reply to Paolo BonziniQuoted 47 lines · Paolo Bonzini
Quoted 46 lines · Yang Zhong
The SGXEPCSection list added into SGXInfo to show the multiple SGX EPC sections detailed info, not the total size like before.
Signed-off-by Yang Zhong <[email protected]>--- qapi/misc-target.json | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)qapi/misc-target.json +16
-1@@ -334,6 +334,21 @@ 'returns': 'SevAttestationReport', 'if': 'TARGET_I386' } +## +# @SGXEPCSection: +# +# Information about intel SGX EPC section info +# +# @index: the SGX epc section index +# +# @size: the size of epc section +# +# Since: 6.2 +## +{ 'struct': 'SGXEPCSection', + 'data': { 'index': 'uint64', + 'size': 'uint64'}} + ## # @SGXInfo: #@@ -347,7 +362,7 @@ # # @flc: true if FLC is supported # -# @section-size: The EPC section size for guest +# @sections: The EPC sections info for guest # # Since: 6.2 ##@@ -356,7 +371,7 @@ 'sgx1': 'bool', 'sgx2': 'bool', 'flc': 'bool',
Quoted 9 lines
qapi/misc-target.json
Quoted 5 lines
qapi/misc-target.json +1
-1- 'section-size': 'uint64'}, + 'sections': ['SGXEPCSection']}, 'if': 'TARGET_I386' } ##I am not sure the index is particularly useful, but perhaps you should add the node there?
Good point! The node is much better than index here. thanks!
Yang
Quoted 1 line
Paolo