From nobody Thu May 16 15:30:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633951477162709.0903414526089; Mon, 11 Oct 2021 04:24:37 -0700 (PDT) Received: from localhost ([::1]:48480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZtQ3-0004AH-Ps for importer@patchew.org; Mon, 11 Oct 2021 07:24:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNJ-0001Ty-QJ for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:45 -0400 Received: from mga04.intel.com ([192.55.52.120]:28238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNB-00080y-1i for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:45 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2021 04:21:30 -0700 Received: from icx-2s.bj.intel.com ([10.240.193.41]) by orsmga008.jf.intel.com with ESMTP; 11 Oct 2021 04:21:29 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10133"; a="225624843" X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="225624843" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="490432119" From: Yang Zhong To: qemu-devel@nongnu.org Subject: [PATCH 1/6] numa: Enable numa for SGX EPC sections Date: Mon, 11 Oct 2021 19:15:49 +0800 Message-Id: <20211011111554.12403-2-yang.zhong@intel.com> X-Mailer: git-send-email 2.29.2.334.gfaefdd61ec In-Reply-To: <20211011111554.12403-1-yang.zhong@intel.com> References: <20211011111554.12403-1-yang.zhong@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.120; envelope-from=yang.zhong@intel.com; helo=mga04.intel.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, pbonzini@redhat.com, eblake@redhat.com, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633951478854100004 Content-Type: text/plain; charset="utf-8" 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=3D20G \ -smp sockets=3D2,cores=3D2 \ -cpu host,+sgx-provisionkey \ -object memory-backend-ram,size=3D2G,host-nodes=3D0,policy=3Dbind,id=3Dnod= e0 \ -object memory-backend-epc,id=3Dmem0,size=3D64M,prealloc=3Don,host-nodes= =3D0,policy=3Dbind \ -numa node,nodeid=3D0,cpus=3D0-1,memdev=3Dnode0 \ -object memory-backend-ram,size=3D2G,host-nodes=3D1,policy=3Dbind,id=3Dnod= e1 \ -object memory-backend-epc,id=3Dmem1,size=3D28M,prealloc=3Don,host-nodes= =3D1,policy=3Dbind \ -numa node,nodeid=3D1,cpus=3D2-3,memdev=3Dnode1 \ -M sgx-epc.0.memdev=3Dmem0,sgx-epc.0.node=3D0,sgx-epc.1.memdev=3Dmem1,sgx-= epc.1.node=3D1 \ ...... Signed-off-by: Yang Zhong --- 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(-) diff --git a/qapi/machine.json b/qapi/machine.json index 5db54df298..09b6188e6f 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -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' + } +} =20 ## # @SgxEPCProperties: diff --git a/include/hw/i386/sgx-epc.h b/include/hw/i386/sgx-epc.h index 65a68ca753..7a61c52869 100644 --- a/include/hw/i386/sgx-epc.h +++ b/include/hw/i386/sgx-epc.h @@ -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" =20 /** * SGXEPCDevice: @@ -38,6 +39,7 @@ typedef struct SGXEPCDevice { =20 /* public */ uint64_t addr; + uint32_t node; HostMemoryBackendEpc *hostmem; } SGXEPCDevice; =20 @@ -56,6 +58,7 @@ typedef struct SGXEPCState { } SGXEPCState; =20 int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size); +void sgx_epc_build_srat(GArray *table_data); =20 static inline uint64_t sgx_epc_above_4g_end(SGXEPCState *sgx_epc) { diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 81418b7911..563a38992f 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2062,6 +2062,10 @@ build_srat(GArray *table_data, BIOSLinker *linker, M= achineState *machine) nvdimm_build_srat(table_data); } =20 + if (pcms->sgx_epc.size !=3D 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 diff --git a/hw/i386/sgx-epc.c b/hw/i386/sgx-epc.c index 55e2217eae..e5cd2789be 100644 --- a/hw/i386/sgx-epc.c +++ b/hw/i386/sgx-epc.c @@ -21,6 +21,7 @@ =20 static Property sgx_epc_properties[] =3D { 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 MemoryDev= iceState *md, se->memaddr =3D epc->addr; se->size =3D object_property_get_uint(OBJECT(epc), SGX_EPC_SIZE_PROP, NULL); + se->node =3D object_property_get_uint(OBJECT(epc), SGX_EPC_NUMA_NODE_P= ROP, + NULL); se->memdev =3D object_get_canonical_path(OBJECT(epc->hostmem)); =20 info->u.sgx_epc.data =3D se; diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c index e481e9358f..906facb645 100644 --- a/hw/i386/sgx.c +++ b/hw/i386/sgx.c @@ -19,6 +19,7 @@ #include "exec/address-spaces.h" #include "hw/i386/sgx.h" #include "sysemu/hw_accel.h" +#include "hw/acpi/aml-build.h" =20 #define SGX_MAX_EPC_SECTIONS 8 #define SGX_CPUID_EPC_INVALID 0x0 @@ -27,6 +28,46 @@ #define SGX_CPUID_EPC_SECTION 0x1 #define SGX_CPUID_EPC_MASK 0xF =20 +static int sgx_epc_device_list(Object *obj, void *opaque) +{ + GSList **list =3D opaque; + + if (object_dynamic_cast(obj, TYPE_SGX_EPC)) { + *list =3D g_slist_append(*list, DEVICE(obj)); + } + + object_child_foreach(obj, sgx_epc_device_list, opaque); + return 0; +} + +static GSList *sgx_epc_get_device_list(void) +{ + GSList *list =3D NULL; + + object_child_foreach(qdev_get_machine(), sgx_epc_device_list, &list); + return list; +} + +void sgx_epc_build_srat(GArray *table_data) +{ + GSList *device_list =3D sgx_epc_get_device_list(); + + for (; device_list; device_list =3D device_list->next) { + DeviceState *dev =3D device_list->data; + Object *obj =3D OBJECT(dev); + uint64_t addr, size; + int node; + + node =3D object_property_get_uint(obj, SGX_EPC_NUMA_NODE_PROP, + &error_abort); + addr =3D object_property_get_uint(obj, SGX_EPC_ADDR_PROP, &error_a= bort); + size =3D object_property_get_uint(obj, SGX_EPC_SIZE_PROP, &error_a= bort); + + build_srat_memory(table_data, addr, size, node, MEM_AFFINITY_ENABL= ED); + } + g_slist_free(device_list); +} + static uint64_t sgx_calc_section_metric(uint64_t low, uint64_t high) { return (low & MAKE_64BIT_MASK(12, 20)) + @@ -156,6 +197,9 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms) /* set the memdev link with memory backend */ object_property_parse(obj, SGX_EPC_MEMDEV_PROP, list->value->memde= v, &error_fatal); + /* set the numa node property for sgx epc object */ + object_property_set_uint(obj, SGX_EPC_NUMA_NODE_PROP, list->value-= >node, + &error_fatal); object_property_set_bool(obj, "realized", true, &error_fatal); object_unref(obj); } diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index bcaa41350e..8af26e3e20 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1878,6 +1878,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDic= t *qdict) se->id ? se->id : ""); monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", se->mema= ddr); 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: diff --git a/qemu-options.hx b/qemu-options.hx index 5f375bbfa6..aaa5a1926d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -127,11 +127,11 @@ SRST ERST =20 DEF("M", HAS_ARG, QEMU_OPTION_M, - " sgx-epc.0.memdev=3Dmemid\n", + " sgx-epc.0.memdev=3Dmemid,sgx-epc.0.node=3Dnumaid\n", QEMU_ARCH_ALL) =20 SRST -``sgx-epc.0.memdev=3D@var{memid}`` +``sgx-epc.0.memdev=3D@var{memid},sgx-epc.0.node=3D@var{numaid}`` Define an SGX EPC section. ERST =20 From nobody Thu May 16 15:30:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633951477199650.9633681017506; Mon, 11 Oct 2021 04:24:37 -0700 (PDT) Received: from localhost ([::1]:48442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZtQ3-000497-ME for importer@patchew.org; Mon, 11 Oct 2021 07:24:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNE-0001TH-Ln for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:40 -0400 Received: from mga04.intel.com ([192.55.52.120]:28240) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNB-0008Kp-1g for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:39 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2021 04:21:32 -0700 Received: from icx-2s.bj.intel.com ([10.240.193.41]) by orsmga008.jf.intel.com with ESMTP; 11 Oct 2021 04:21:30 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10133"; a="225624851" X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="225624851" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="490432152" From: Yang Zhong To: qemu-devel@nongnu.org Subject: [PATCH 2/6] monitor: Support 'info numa' command Date: Mon, 11 Oct 2021 19:15:50 +0800 Message-Id: <20211011111554.12403-3-yang.zhong@intel.com> X-Mailer: git-send-email 2.29.2.334.gfaefdd61ec In-Reply-To: <20211011111554.12403-1-yang.zhong@intel.com> References: <20211011111554.12403-1-yang.zhong@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.120; envelope-from=yang.zhong@intel.com; helo=mga04.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, pbonzini@redhat.com, eblake@redhat.com, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633951478814100001 Content-Type: text/plain; charset="utf-8" Add the MEMORY_DEVICE_INFO_KIND_SGX_EPC case for SGX numa info with 'info numa' command in the monitor. Signed-off-by: Yang Zhong --- hw/core/numa.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/core/numa.c b/hw/core/numa.c index 510d096a88..1aa05dcf42 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -756,6 +756,7 @@ static void numa_stat_memory_devices(NumaNodeMem node_m= em[]) PCDIMMDeviceInfo *pcdimm_info; VirtioPMEMDeviceInfo *vpi; VirtioMEMDeviceInfo *vmi; + SgxEPCDeviceInfo *se; =20 for (info =3D info_list; info; info =3D info->next) { MemoryDeviceInfo *value =3D info->value; @@ -781,6 +782,11 @@ static void numa_stat_memory_devices(NumaNodeMem node_= mem[]) node_mem[vmi->node].node_mem +=3D vmi->size; node_mem[vmi->node].node_plugged_mem +=3D vmi->size; break; + case MEMORY_DEVICE_INFO_KIND_SGX_EPC: + se =3D value->u.sgx_epc.data; + node_mem[se->node].node_mem +=3D se->size; + node_mem[se->node].node_plugged_mem =3D 0; + break; default: g_assert_not_reached(); } From nobody Thu May 16 15:30:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633951625946537.0759429797184; Mon, 11 Oct 2021 04:27:05 -0700 (PDT) Received: from localhost ([::1]:55168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZtST-0000Hj-0g for importer@patchew.org; Mon, 11 Oct 2021 07:27:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNJ-0001Tw-PN for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:45 -0400 Received: from mga04.intel.com ([192.55.52.120]:28240) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNE-0008Kp-Ij for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:41 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2021 04:21:34 -0700 Received: from icx-2s.bj.intel.com ([10.240.193.41]) by orsmga008.jf.intel.com with ESMTP; 11 Oct 2021 04:21:32 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10133"; a="225624856" X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="225624856" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="490432173" From: Yang Zhong To: qemu-devel@nongnu.org Subject: [PATCH 3/6] numa: Add SGXEPCSection list for multiple sections Date: Mon, 11 Oct 2021 19:15:51 +0800 Message-Id: <20211011111554.12403-4-yang.zhong@intel.com> X-Mailer: git-send-email 2.29.2.334.gfaefdd61ec In-Reply-To: <20211011111554.12403-1-yang.zhong@intel.com> References: <20211011111554.12403-1-yang.zhong@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.120; envelope-from=yang.zhong@intel.com; helo=mga04.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, pbonzini@redhat.com, eblake@redhat.com, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633951626965100001 Content-Type: text/plain; charset="utf-8" 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 --- qapi/misc-target.json | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/qapi/misc-target.json b/qapi/misc-target.json index 594fbd1577..89a5a4250a 100644 --- a/qapi/misc-target.json +++ b/qapi/misc-target.json @@ -334,6 +334,21 @@ 'returns': 'SevAttestationReport', 'if': 'TARGET_I386' } =20 +## +# @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' } =20 ## From nobody Thu May 16 15:30:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633951629422862.0580187567688; Mon, 11 Oct 2021 04:27:09 -0700 (PDT) Received: from localhost ([::1]:55152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZtSW-0000H6-F3 for importer@patchew.org; Mon, 11 Oct 2021 07:27:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNL-0001Wh-DD for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:47 -0400 Received: from mga04.intel.com ([192.55.52.120]:28236) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNJ-0007q1-JO for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:47 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2021 04:21:35 -0700 Received: from icx-2s.bj.intel.com ([10.240.193.41]) by orsmga008.jf.intel.com with ESMTP; 11 Oct 2021 04:21:34 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10133"; a="225624865" X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="225624865" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="490432195" From: Yang Zhong To: qemu-devel@nongnu.org Subject: [PATCH 4/6] monitor: numa support for 'info sgx' command Date: Mon, 11 Oct 2021 19:15:52 +0800 Message-Id: <20211011111554.12403-5-yang.zhong@intel.com> X-Mailer: git-send-email 2.29.2.334.gfaefdd61ec In-Reply-To: <20211011111554.12403-1-yang.zhong@intel.com> References: <20211011111554.12403-1-yang.zhong@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.120; envelope-from=yang.zhong@intel.com; helo=mga04.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, pbonzini@redhat.com, eblake@redhat.com, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633951631247100001 Content-Type: text/plain; charset="utf-8" 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=3D67108864 SECTION #1: size=3D29360128 The QMP interface show: (QEMU) query-sgx {"return": {"sgx": true, "sgx2": true, "sgx1": true, "sections": \ [{"index": 0, "size": 67108864}, {"index": 1, "size": 29360128}], "flc": t= rue}} Signed-off-by: Yang Zhong --- hw/i386/sgx.c | 25 +++++++++++++++++++++++-- target/i386/monitor.c | 11 +++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c index 906facb645..8af45925c6 100644 --- a/hw/i386/sgx.c +++ b/hw/i386/sgx.c @@ -126,6 +126,28 @@ SGXInfo *sgx_get_capabilities(Error **errp) return info; } =20 +static SGXEPCSectionList *sgx_get_epc_sections_list(void) +{ + GSList *device_list =3D sgx_epc_get_device_list(); + SGXEPCSectionList *head =3D NULL, **tail =3D &head; + SGXEPCSection *section; + uint64_t i =3D 0; + + for (; device_list; device_list =3D device_list->next) { + DeviceState *dev =3D device_list->data; + Object *obj =3D OBJECT(dev); + + section =3D g_new0(SGXEPCSection, 1); + section->index =3D i++; + section->size =3D 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 =3D NULL; @@ -144,14 +166,13 @@ SGXInfo *sgx_get_info(Error **errp) return NULL; } =20 - SGXEPCState *sgx_epc =3D &pcms->sgx_epc; info =3D g_new0(SGXInfo, 1); =20 info->sgx =3D true; info->sgx1 =3D true; info->sgx2 =3D true; info->flc =3D true; - info->section_size =3D sgx_epc->size; + info->sections =3D sgx_get_epc_sections_list(); =20 return info; } diff --git a/target/i386/monitor.c b/target/i386/monitor.c index 196c1c9e77..08e7d4a425 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -773,6 +773,7 @@ SGXInfo *qmp_query_sgx(Error **errp) void hmp_info_sgx(Monitor *mon, const QDict *qdict) { Error *err =3D NULL; + SGXEPCSectionList *section_list, *section; g_autoptr(SGXInfo) info =3D qmp_query_sgx(&err); =20 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 =3D info->sections; + for (section =3D section_list; section; section =3D section->next) { + monitor_printf(mon, "SECTION #%" PRId64 ": ", + section->value->index); + monitor_printf(mon, "size=3D%" PRIu64 "\n", + section->value->size); + } } =20 SGXInfo *qmp_query_sgx_capabilities(Error **errp) From nobody Thu May 16 15:30:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633951481516745.3227598864238; Mon, 11 Oct 2021 04:24:41 -0700 (PDT) Received: from localhost ([::1]:48912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZtQ8-0004SI-Ez for importer@patchew.org; Mon, 11 Oct 2021 07:24:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNM-0001bU-Mc for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:48 -0400 Received: from mga04.intel.com ([192.55.52.120]:28240) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNK-0008Kp-54 for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:48 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2021 04:21:37 -0700 Received: from icx-2s.bj.intel.com ([10.240.193.41]) by orsmga008.jf.intel.com with ESMTP; 11 Oct 2021 04:21:36 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10133"; a="225624872" X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="225624872" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="490432226" From: Yang Zhong To: qemu-devel@nongnu.org Subject: [PATCH 5/6] numa: Enable numa for libvirt interface Date: Mon, 11 Oct 2021 19:15:53 +0800 Message-Id: <20211011111554.12403-6-yang.zhong@intel.com> X-Mailer: git-send-email 2.29.2.334.gfaefdd61ec In-Reply-To: <20211011111554.12403-1-yang.zhong@intel.com> References: <20211011111554.12403-1-yang.zhong@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.120; envelope-from=yang.zhong@intel.com; helo=mga04.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, pbonzini@redhat.com, eblake@redhat.com, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633951483272100001 Content-Type: text/plain; charset="utf-8" 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}], "fl= c": true}} Signed-off-by: Yang Zhong --- hw/i386/sgx.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c index 8af45925c6..fe3034060d 100644 --- a/hw/i386/sgx.c +++ b/hw/i386/sgx.c @@ -74,11 +74,13 @@ static uint64_t sgx_calc_section_metric(uint64_t low, u= int64_t high) ((high & MAKE_64BIT_MASK(0, 20)) << 32); } =20 -static uint64_t sgx_calc_host_epc_section_size(void) +static SGXEPCSectionList *sgx_calc_host_epc_sections(void) { + SGXEPCSectionList *head =3D NULL, **tail =3D &head; + SGXEPCSection *section; uint32_t i, type; uint32_t eax, ebx, ecx, edx; - uint64_t size =3D 0; + uint32_t j =3D 0; =20 for (i =3D 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; } =20 - size +=3D sgx_calc_section_metric(ecx, edx); + section =3D g_new0(SGXEPCSection, 1); + section->index =3D j++; + section->size =3D sgx_calc_section_metric(ecx, edx); + QAPI_LIST_APPEND(tail, section); } =20 - return size; + return head; } =20 SGXInfo *sgx_get_capabilities(Error **errp) @@ -119,7 +124,7 @@ SGXInfo *sgx_get_capabilities(Error **errp) info->sgx1 =3D eax & (1U << 0) ? true : false; info->sgx2 =3D eax & (1U << 1) ? true : false; =20 - info->section_size =3D sgx_calc_host_epc_section_size(); + info->sections =3D sgx_calc_host_epc_sections(); =20 close(fd); =20 From nobody Thu May 16 15:30:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633951747198435.96380422254845; Mon, 11 Oct 2021 04:29:07 -0700 (PDT) Received: from localhost ([::1]:60404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZtUQ-0003nh-5B for importer@patchew.org; Mon, 11 Oct 2021 07:29:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNL-0001Ya-Sy for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:47 -0400 Received: from mga04.intel.com ([192.55.52.120]:28238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZtNK-00080y-56 for qemu-devel@nongnu.org; Mon, 11 Oct 2021 07:21:47 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2021 04:21:39 -0700 Received: from icx-2s.bj.intel.com ([10.240.193.41]) by orsmga008.jf.intel.com with ESMTP; 11 Oct 2021 04:21:37 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10133"; a="225624876" X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="225624876" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="490432244" From: Yang Zhong To: qemu-devel@nongnu.org Subject: [PATCH 6/6] doc: Add the SGX numa description Date: Mon, 11 Oct 2021 19:15:54 +0800 Message-Id: <20211011111554.12403-7-yang.zhong@intel.com> X-Mailer: git-send-email 2.29.2.334.gfaefdd61ec In-Reply-To: <20211011111554.12403-1-yang.zhong@intel.com> References: <20211011111554.12403-1-yang.zhong@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.120; envelope-from=yang.zhong@intel.com; helo=mga04.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, pbonzini@redhat.com, eblake@redhat.com, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633951747651100001 Content-Type: text/plain; charset="utf-8" Add the SGX numa reference command and how to check if SGX numa is support or not with multiple EPC sections. Signed-off-by: Yang Zhong --- docs/system/i386/sgx.rst | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/docs/system/i386/sgx.rst b/docs/system/i386/sgx.rst index f103ae2a2f..9e4ada761f 100644 --- a/docs/system/i386/sgx.rst +++ b/docs/system/i386/sgx.rst @@ -141,8 +141,7 @@ To launch a SGX guest: |qemu_system_x86| \\ -cpu host,+sgx-provisionkey \\ -object memory-backend-epc,id=3Dmem1,size=3D64M,prealloc=3Don \\ - -object memory-backend-epc,id=3Dmem2,size=3D28M \\ - -M sgx-epc.0.memdev=3Dmem1,sgx-epc.1.memdev=3Dmem2 + -M sgx-epc.0.memdev=3Dmem1,sgx-epc.0.node=3D0 =20 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:: =20 $ 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=3D2G,host-nodes=3D0,policy=3Dbind,id=3D= node0 \\ + -object memory-backend-epc,id=3Dmem0,size=3D64M,prealloc=3Don,host-node= s=3D0,policy=3Dbind \\ + -numa node,nodeid=3D0,cpus=3D0-1,memdev=3Dnode0 \\ + -object memory-backend-ram,size=3D2G,host-nodes=3D1,policy=3Dbind,id=3D= node1 \\ + -object memory-backend-epc,id=3Dmem1,size=3D28M,prealloc=3Don,host-node= s=3D1,policy=3Dbind \\ + -numa node,nodeid=3D1,cpus=3D2-3,memdev=3Dnode1 \\ + -M sgx-epc.0.memdev=3Dmem0,sgx-epc.0.node=3D0,sgx-epc.1.memdev=3Dmem1,s= gx-epc.1.node=3D1 + +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] =20 References ----------