From nobody Wed Oct 22 13:04:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151979073501788.62822798129912; Tue, 27 Feb 2018 20:05:35 -0800 (PST) Received: from localhost ([::1]:42095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqszj-0005g3-LK for importer@patchew.org; Tue, 27 Feb 2018 23:05:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54600) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqsxc-0004W9-MO for qemu-devel@nongnu.org; Tue, 27 Feb 2018 23:03:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqsxZ-0002Le-CV for qemu-devel@nongnu.org; Tue, 27 Feb 2018 23:03:20 -0500 Received: from mga05.intel.com ([192.55.52.43]:46587) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eqsxZ-0002Kn-41 for qemu-devel@nongnu.org; Tue, 27 Feb 2018 23:03:17 -0500 Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2018 20:03:15 -0800 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.13.35]) by orsmga006.jf.intel.com with ESMTP; 27 Feb 2018 20:03:13 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,403,1515484800"; d="scan'208";a="21604796" From: Haozhong Zhang To: qemu-devel@nongnu.org Date: Wed, 28 Feb 2018 12:02:58 +0800 Message-Id: <20180228040300.8914-2-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180228040300.8914-1-haozhong.zhang@intel.com> References: <20180228040300.8914-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.43 Subject: [Qemu-devel] [PATCH v2 1/3] hw/acpi-build: build SRAT memory affinity structures for DIMM devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haozhong Zhang , Xiao Guangrong , mst@redhat.com, Eduardo Habkost , Stefan Hajnoczi , Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Dan Williams , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" ACPI 6.2A Table 5-129 "SPA Range Structure" requires the proximity domain of a NVDIMM SPA range must match with corresponding entry in SRAT table. The address ranges of vNVDIMM in QEMU are allocated from the hot-pluggable address space, which is entirely covered by one SRAT memory affinity structure. However, users can set the vNVDIMM proximity domain in NFIT SPA range structure by the 'node' property of '-device nvdimm' to a value different than the one in the above SRAT memory affinity structure. In order to solve such proximity domain mismatch, this patch builds one SRAT memory affinity structure for each static-plugged DIMM device, including both PC-DIMM and NVDIMM, with the proximity domain specified in '-device pc-dimm' or '-device nvdimm'. The remaining hot-pluggable address space is covered by one or multiple SRAT memory affinity structures with the proximity domain of the last node as before. Signed-off-by: Haozhong Zhang --- hw/i386/acpi-build.c | 50 ++++++++++++++++++++++++++++++++++++++++++++= ---- hw/mem/pc-dimm.c | 8 ++++++++ include/hw/mem/pc-dimm.h | 10 ++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index deb440f286..a88de06d8f 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2323,6 +2323,49 @@ build_tpm2(GArray *table_data, BIOSLinker *linker, G= Array *tcpalog) #define HOLE_640K_START (640 * 1024) #define HOLE_640K_END (1024 * 1024) =20 +static void build_srat_hotpluggable_memory(GArray *table_data, uint64_t ba= se, + uint64_t len, int default_node) +{ + GSList *dimms =3D pc_dimm_get_device_list(); + GSList *ent =3D dimms; + PCDIMMDevice *dev; + Object *obj; + uint64_t end =3D base + len, addr, size; + int node; + AcpiSratMemoryAffinity *numamem; + + while (base < end) { + numamem =3D acpi_data_push(table_data, sizeof *numamem); + + if (!ent) { + build_srat_memory(numamem, base, end - base, default_node, + MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENA= BLED); + break; + } + + dev =3D PC_DIMM(ent->data); + obj =3D OBJECT(dev); + addr =3D object_property_get_uint(obj, PC_DIMM_ADDR_PROP, NULL); + size =3D object_property_get_uint(obj, PC_DIMM_SIZE_PROP, NULL); + node =3D object_property_get_uint(obj, PC_DIMM_NODE_PROP, NULL); + + if (base < addr) { + build_srat_memory(numamem, base, addr - base, default_node, + MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENA= BLED); + numamem =3D acpi_data_push(table_data, sizeof *numamem); + } + build_srat_memory(numamem, addr, size, node, + MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED= | + (object_dynamic_cast(obj, TYPE_NVDIMM) ? + MEM_AFFINITY_NON_VOLATILE : 0)); + + base =3D addr + size; + ent =3D g_slist_next(ent); + } + + g_slist_free(dimms); +} + static void build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) { @@ -2434,10 +2477,9 @@ build_srat(GArray *table_data, BIOSLinker *linker, M= achineState *machine) * providing _PXM method if necessary. */ if (hotplugabble_address_space_size) { - numamem =3D acpi_data_push(table_data, sizeof *numamem); - build_srat_memory(numamem, pcms->hotplug_memory.base, - hotplugabble_address_space_size, pcms->numa_node= s - 1, - MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED= ); + build_srat_hotpluggable_memory(table_data, pcms->hotplug_memory.ba= se, + hotplugabble_address_space_size, + pcms->numa_nodes - 1); } =20 build_header(linker, table_data, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 6e74b61cb6..9fd901e87a 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -276,6 +276,14 @@ static int pc_dimm_built_list(Object *obj, void *opaqu= e) return 0; } =20 +GSList *pc_dimm_get_device_list(void) +{ + GSList *list =3D NULL; + + object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &list); + return list; +} + uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, uint64_t address_space_size, uint64_t *hint, uint64_t align, uint64_t si= ze, diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index d83b957829..4cf5cc49e9 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -100,4 +100,14 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotpl= ugState *hpms, MemoryRegion *mr, uint64_t align, Error **errp); void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms, MemoryRegion *mr); + +/* + * Return a list of DeviceState of pc-dimm and nvdimm devices. The + * list is sorted in the ascendant order of the base address of + * devices. + * + * Note: callers are responsible to free the list. + */ +GSList *pc_dimm_get_device_list(void); + #endif --=20 2.14.1