SGX NUMA support plus vepc reset
v3 cover SGX NUMA support plus vepc reset
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.
This version also plus the vEPC reset support because the related kernel patches were merged into tip tree master branch, please ref below link:
https://lore.kernel.org/all/[email protected]/
or the tip tree master branch.
Thanks!
Yang
Changes from V2:
- Updated the reset patch(patch 5), reduced to 2 pass.(Paolo)
Changes from V1:
- added documents for new members.(Eric)
- changed the "index" to "node" in struct SGXEPCSection.(Eric, Paolo)
- squashed the previous patch 4 and patch 5 into patch 3.(Paolo)
- added reset patch(patch 5) into this version.
Yang Zhong (5):
numa: Enable numa for SGX EPC sections
monitor: Support 'info numa' command
numa: Support SGX numa in the monitor and Libvirt interfaces
doc: Add the SGX numa description
sgx: Reset the vEPC regions during VM reboot
docs/system/i386/sgx.rst | 31 +++++++-- qapi/machine.json | 10 ++- qapi/misc-target.json | 19 +++++- include/hw/i386/sgx-epc.h | 3 + include/hw/i386/x86.h | 1 + linux-headers/linux/kvm.h | 6 ++ hw/core/numa.c | 6 ++ hw/i386/acpi-build.c | 4 ++ hw/i386/sgx-epc.c | 3 + hw/i386/sgx.c | 137 +++++++++++++++++++++++++++++++++++--- hw/i386/x86.c | 4 ++ monitor/hmp-cmds.c | 1 + qemu-options.hx | 4 +- 13 files changed, 211 insertions(+), 18 deletions(-)
PATCH v3 1/5 numa: Enable numa for SGX EPC sections
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 \
......
--- qapi/machine.json | 10 ++++++++- 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, 66 insertions(+), 3 deletions(-)
qapi/machine.json +9 -1
@@ -1207,12 +1207,15 @@ # # @memdev: memory backend linked with device # +# @node: the numa node +# # Since: 6.2 ## { 'struct': 'SgxEPCDeviceInfo', 'data': { '*id': 'str', 'memaddr': 'size', 'size': 'size', + 'node': 'int', 'memdev': 'str' } }
@@ -1285,10 +1288,15 @@ # # @memdev: memory backend linked with device # +# @node: the numa node +# # 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;bool 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
PATCH v3 2/5 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 v3 3/5 numa: Support SGX numa in the monitor and Libvirt interfaces
In reply to Yang ZhongAdd the SGXEPCSection list into SGXInfo to show the multiple SGX EPC sections detailed info, not the total size like before. This patch can enable numa support for 'info sgx' command and QMP interfaces. The new interfaces show each EPC section info in one numa node. Libvirt can use QMP interface to get the detailed host SGX EPC capabilities to decide how to allocate host EPC sections to guest.
(qemu) info sgx
SGX support: enabled
SGX1 support: enabled
SGX2 support: enabled
FLC support: enabled
NUMA node #0: size=67108864
NUMA node #1: size=29360128
The QMP interface show:
(QEMU) query-sgx
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 67108864}, {"node": 1, "size": 29360128}], "flc": true}}
(QEMU) query-sgx-capabilities
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 17070817280}, {"node": 1, "size": 17079205888}], "flc": true}}
--- qapi/misc-target.json | 19 ++++++++++++++-- hw/i386/sgx.c | 51 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 11 deletions(-)
qapi/misc-target.json +17 -2
@@ -337,6 +337,21 @@ 'if': 'TARGET_ARM' } +## +# @SGXEPCSection: +# +# Information about intel SGX EPC section info +# +# @node: the numa node +# +# @size: the size of epc section +# +# Since: 6.2 +## +{ 'struct': 'SGXEPCSection', + 'data': { 'node': 'int', + 'size': 'uint64'}} + ## # @SGXInfo: #
@@ -350,7 +365,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 ##
@@ -359,7 +374,7 @@ 'sgx1': 'bool', 'sgx2': 'bool', 'flc': 'bool', - 'section-size': 'uint64'}, + 'sections': ['SGXEPCSection']}, 'if': 'TARGET_I386' } ##
hw/i386/sgx.c +42 -9
104 lines not on this page · raw message
Re: [PATCH v3 3/5] numa: Support SGX numa in the monitor and Libvirt interfaces
Quoted 16 lines · Yang Zhong
Add the SGXEPCSection list into SGXInfo to show the multiple SGX EPC sections detailed info, not the total size like before. This patch can enable numa support for 'info sgx' command and QMP interfaces. The new interfaces show each EPC section info in one numa node. Libvirt can use QMP interface to get the detailed host SGX EPC capabilities to decide how to allocate host EPC sections to guest.
(qemu) info sgx
SGX support: enabled
SGX1 support: enabled
SGX2 support: enabled
FLC support: enabled
NUMA node #0: size=67108864
NUMA node #1: size=29360128
Quoted 8 lines
The QMP interface show:
(QEMU) query-sgx
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 67108864}, {"node": 1, "size": 29360128}], "flc": true}}(QEMU) query-sgx-capabilities
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 17070817280}, {"node": 1, "size": 17079205888}], "flc": true}}
Other than the different "size" values, how do these commands differ?
Quoted 15 lines
Signed-off-by Yang Zhong <[email protected]>--- qapi/misc-target.json | 19 ++++++++++++++-- hw/i386/sgx.c | 51 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 11 deletions(-)qapi/misc-target.json +0
-0@@ -337,6 +337,21 @@ 'if': 'TARGET_ARM' }
qapi/misc-target.json line 349
Quoted 10 lines
qapi/misc-target.json +10
-0+## +# @SGXEPCSection: +# +# Information about intel SGX EPC section info +# +# @node: the numa node +# +# @size: the size of epc section +# +# Since: 6.2
Are we still trying to cram this into 6.2, or is now slipping into 7.0?
Quoted 18 lines
qapi/misc-target.json +6
-1+## +{ 'struct': 'SGXEPCSection', + 'data': { 'node': 'int', + 'size': 'uint64'}} + ## # @SGXInfo: #@@ -350,7 +365,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 5 lines
qapi/misc-target.json +1
-1@@ -359,7 +374,7 @@ 'sgx1': 'bool', 'sgx2': 'bool', 'flc': 'bool', - 'section-size': 'uint64'}, + 'sections': ['SGXEPCSection']},
This would be an incompatible change. As long as 6.2 isn't released, we can do that; but once it is, we need to be more careful about changing the QMP spec.
Quoted 13 lines
qapi/misc-target.json +0
-0'if': 'TARGET_I386' } ##hw/i386/sgx.c +1
-1@@ -76,11 +76,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 )
...
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 3/5] numa: Support SGX numa in the monitor and Libvirt interfaces
Quoted 22 lines · Eric Blake
Quoted 21 lines · Yang Zhong
Add the SGXEPCSection list into SGXInfo to show the multiple SGX EPC sections detailed info, not the total size like before. This patch can enable numa support for 'info sgx' command and QMP interfaces. The new interfaces show each EPC section info in one numa node. Libvirt can use QMP interface to get the detailed host SGX EPC capabilities to decide how to allocate host EPC sections to guest.
(qemu) info sgx
SGX support: enabled
SGX1 support: enabled
SGX2 support: enabled
FLC support: enabled
NUMA node #0: size=67108864
NUMA node #1: size=29360128The QMP interface show:
(QEMU) query-sgx
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 67108864}, {"node": 1, "size": 29360128}], "flc": true}}
Quoted 5 lines
Quoted 3 lines
(QEMU) query-sgx-capabilities
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 17070817280}, {"node": 1, "size": 17079205888}], "flc": true}}Other than the different "size" values, how do these commands differ?
As for QMP interfaces,
The 'query-sgx' to get VM sgx detailed info, and 'query-sgx-capabilities' to get the host sgx capabilities and Libvirt can use this info to decide how to allocate virtual EPC sections to VMs.
'info sgx' and 'query-sgx' are same functions, only different interfaces, HMP and QMP.
Yang
Quoted 16 lines
Quoted 16 lines
Signed-off-by Yang Zhong <[email protected]>--- qapi/misc-target.json | 19 ++++++++++++++-- hw/i386/sgx.c | 51 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 11 deletions(-)qapi/misc-target.json +0
-0@@ -337,6 +337,21 @@ 'if': 'TARGET_ARM' }
Quoted 12 lines
qapi/misc-target.json line 349
Quoted 10 lines
qapi/misc-target.json +10
-0+## +# @SGXEPCSection: +# +# Information about intel SGX EPC section info +# +# @node: the numa node +# +# @size: the size of epc section +# +# Since: 6.2Are we still trying to cram this into 6.2, or is now slipping into 7.0?
The numa patches will be merged into Qemu next version, once the new version is ready, i will change this and send V4. thanks!
Yang
Quoted 20 lines
Quoted 20 lines
qapi/misc-target.json +6
-1+## +{ 'struct': 'SGXEPCSection', + 'data': { 'node': 'int', + 'size': 'uint64'}} + ## # @SGXInfo: #@@ -350,7 +365,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 ##@@ -359,7 +374,7 @@ 'sgx1': 'bool',
Quoted 8 lines
qapi/misc-target.json line 377
Quoted 4 lines
qapi/misc-target.json +1
-1'sgx2': 'bool', 'flc': 'bool', - 'section-size': 'uint64'}, + 'sections': ['SGXEPCSection']},This would be an incompatible change. As long as 6.2 isn't released, we can do that; but once it is, we need to be more careful about changing the QMP spec.
Thanks for reminder! I had to use SGXEPCSection lists to show those epc infos because the MAX SGX epc section number is 8, this number in each server maybe different, not one fixed number. Once the new QMP spec release, let me check how to adjust this. thanks!
Regards,
Yang
Quoted 20 lines
Quoted 14 lines
qapi/misc-target.json +0
-0'if': 'TARGET_I386' } ##hw/i386/sgx.c +1
-1@@ -76,11 +76,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 )...
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 3/5] numa: Support SGX numa in the monitor and Libvirt interfaces
Quoted 27 lines · Yang Zhong
Quoted 26 lines · Eric Blake
Quoted 24 lines · Yang Zhong
Add the SGXEPCSection list into SGXInfo to show the multiple SGX EPC sections detailed info, not the total size like before. This patch can enable numa support for 'info sgx' command and QMP interfaces. The new interfaces show each EPC section info in one numa node. Libvirt can use QMP interface to get the detailed host SGX EPC capabilities to decide how to allocate host EPC sections to guest.
(qemu) info sgx
SGX support: enabled
SGX1 support: enabled
SGX2 support: enabled
FLC support: enabled
NUMA node #0: size=67108864
NUMA node #1: size=29360128The QMP interface show:
(QEMU) query-sgx
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 67108864}, {"node": 1, "size": 29360128}], "flc": true}}(QEMU) query-sgx-capabilities
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 17070817280}, {"node": 1, "size": 17079205888}], "flc": true}}
Quoted 7 lines
Quoted 1 line
Other than the different "size" values, how do these commands differ?
As for QMP interfaces,
The 'query-sgx' to get VM sgx detailed info, and 'query-sgx-capabilities' to get the host sgx capabilities and Libvirt can use this info to decide how to allocate virtual EPC sections to VMs.
What about renaming/aliasing as 'query-host-sgx' / 'query-guest-sgx'?
Re: [PATCH v3 3/5] numa: Support SGX numa in the monitor and Libvirt interfaces
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 30 lines · Yang Zhong
Quoted 27 lines · Eric Blake
Quoted 16 lines · Yang Zhong
Add the SGXEPCSection list into SGXInfo to show the multiple SGX EPC sections detailed info, not the total size like before. This patch can enable numa support for 'info sgx' command and QMP interfaces. The new interfaces show each EPC section info in one numa node. Libvirt can use QMP interface to get the detailed host SGX EPC capabilities to decide how to allocate host EPC sections to guest.
(qemu) info sgx
SGX support: enabled
SGX1 support: enabled
SGX2 support: enabled
FLC support: enabled
NUMA node #0: size=67108864
NUMA node #1: size=29360128Quoted 8 lines
The QMP interface show:
(QEMU) query-sgx
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 67108864}, {"node": 1, "size": 29360128}], "flc": true}}(QEMU) query-sgx-capabilities
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 17070817280}, {"node": 1, "size": 17079205888}], "flc": true}}Other than the different "size" values, how do these commands differ?
Quoted 6 lines
Quoted 4 lines
As for QMP interfaces,
The 'query-sgx' to get VM sgx detailed info, and 'query-sgx-capabilities' to get the host sgx capabilities and Libvirt can use this info to decide how to allocate virtual EPC sections to VMs.What about renaming/aliasing as 'query-host-sgx' / 'query-guest-sgx'?
The current Libvirt and Qemu's QMP interface define all interfaces like those naming rule. If we change those names, there are lots of work in the Qemu and Libvirt sides.
Thanks!
Yang
Re: [PATCH v3 3/5] numa: Support SGX numa in the monitor and Libvirt interfaces
In reply to Eric BlakeQuoted 10 lines · Eric Blake
Quoted 8 lines
The QMP interface show:
(QEMU) query-sgx
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 67108864}, {"node": 1, "size": 29360128}], "flc": true}}(QEMU) query-sgx-capabilities
{"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \
[{"node": 0, "size": 17070817280}, {"node": 1, "size": 17079205888}], "flc": true}}Other than the different "size" values, how do these commands differ?
The latter is the host state, the former is the guest state. So for example the guest might have been configured with a different NUMA setup.
Paolo
PATCH v3 4/5 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 ----------
PATCH v3 5/5 sgx: Reset the vEPC regions during VM reboot
In reply to Yang ZhongFor bare-metal SGX on real hardware, the hardware provides guarantees SGX state at reboot. For instance, all pages start out uninitialized. The vepc driver provides a similar guarantee today for freshly-opened vepc instances, but guests such as Windows expect all pages to be in uninitialized state on startup, including after every guest reboot.
Qemu can invoke the ioctl to bring its vEPC pages back to uninitialized state. There is a possibility that some pages fail to be removed if they are SECS pages, and the child and SECS pages could be in separate vEPC regions. Therefore, the ioctl returns the number of EREMOVE failures, telling Qemu to try the ioctl again after it's done with all vEPC regions.
The related kernel patches:
--- include/hw/i386/x86.h | 1 + linux-headers/linux/kvm.h | 6 ++++++ hw/i386/sgx.c | 42 +++++++++++++++++++++++++++++++++++++++ hw/i386/x86.c | 4 ++++ 4 files changed, 53 insertions(+)
include/hw/i386/x86.h +1 -0
@@ -141,5 +141,6 @@ qemu_irq x86_allocate_cpu_irq(void);void gsi_handler (void *opaque,int n,int level);void ioapic_init_gsi (GSIState *gsi_state,const char *parent_name);DeviceState *ioapic_init_secondary (GSIState *gsi_state); +void sgx_epc_reset (void *opaque);#endif
linux-headers/linux/kvm.h +6 -0
@@ -887,6 +887,12 @@ struct kvm_ppc_resize_hpt {#define KVM_GET_EMULATED_CPUID _IOWR(KVMIO, 0x09, struct kvm_cpuid2)#define KVM_GET_MSR_FEATURE_INDEX_LIST _IOWR(KVMIO, 0x0a, struct kvm_msr_list) +/* +* ioctl for /dev/sgx_vepc +*/ +#define SGX_MAGIC 0xA4 +#define SGX_IOC_VEPC_REMOVE_ALL _IO(SGX_MAGIC, 0x04) +/* * Extension capability list. */
hw/i386/sgx.c +42 -0
60 lines not on this page · raw message
hw/i386/x86.c +4 -0
@@ -39,6 +39,7 @@#include "sysemu/replay.h" #include "sysemu/sysemu.h" #include "sysemu/cpu-timers.h" +#include "sysemu/reset.h" #include "trace.h" #include "hw/i386/x86.h"
@@ -1307,6 +1308,9 @@ static void machine_set_sgx_epc(Object *obj, Visitor *v, const char *name,visit_type_SgxEPCList (v, name, &x86ms->sgx_epc_list, errp);qapi_free_SgxEPCList (list); + +/* register the reset callback for sgx reset */ +qemu_register_reset (sgx_epc_reset,NULL ); }static void x86_machine_initfn (Object *obj)
Paolo Bonzini
AppliedQuoted 11 lines · Yang Zhong
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.
This version also plus the vEPC reset support because the related kernel patches were merged into tip tree master branch, please ref below link:
https://lore.kernel.org/all/[email protected]/
or the tip tree master branch.
Hi,
I queued patch 5, and enough of patch 2 to avoid crashing 'info numa'.
For patch 5, note that linux-headers/ is automatically generated from Linux headers (as the name says!) so the ioctl has to be declared in hw/i386/sgx-epc.c.
Thanks,
Paolo
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Yang Zhong
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.
This version also plus the vEPC reset support because the related kernel patches were merged into tip tree master branch, please ref below link:
https://lore.kernel.org/all/[email protected]/
or the tip tree master branch.
Quoted 8 lines
Hi,
I queued patch 5, and enough of patch 2 to avoid crashing 'info numa'.
For patch 5, note that linux-headers/ is automatically generated from Linux headers (as the name says!) so the ioctl has to be declared in
hw/i386/sgx-epc.c.
Paolo, thanks!
No other maintainers to review numa patches, so i will send the numa patches again? thanks!
Yang
Quoted 3 lines
Thanks,
Paolo
Quoted 4 lines · Yang Zhong
Paolo, thanks!
No other maintainers to review numa patches, so i will send the numa patches again? thanks!
The patch look good, but they were sent too close to the 6.2 release freeze. I'll take a look at them again a month.
Paolo
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Yang Zhong
Paolo, thanks!
No other maintainers to review numa patches, so i will send the numa patches again? thanks!
The patch look good, but they were sent too close to the 6.2 release freeze. I'll take a look at them again a month.
Thanks Paolo, once the new Qemu version is ready, i will send V4. thanks!
Regards,
Yang
Quoted 1 line
Paolo