From nobody Wed May 8 00:12:31 2024 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 1505464466569478.3264365950331; Fri, 15 Sep 2017 01:34:26 -0700 (PDT) Received: from localhost ([::1]:51933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsm4v-00040A-JT for importer@patchew.org; Fri, 15 Sep 2017 04:34:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36447) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsm43-0002Z7-PG for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:33:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsm40-0008Cn-LI for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:33:31 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:19664 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsm3z-0008C8-Rx for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:33:28 -0400 Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 15 Sep 2017 16:33:23 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 61FB747CA470; Fri, 15 Sep 2017 16:33:24 +0800 (CST) Received: from localhost.localdomain.localdomain (10.167.226.106) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 15 Sep 2017 16:33:24 +0800 X-IronPort-AV: E=Sophos;i="5.42,396,1500912000"; d="scan'208";a="26552208" From: Dou Liyang To: Date: Fri, 15 Sep 2017 16:33:18 +0800 Message-ID: <1505464398-28897-1-git-send-email-douly.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.5.5 MIME-Version: 1.0 X-Originating-IP: [10.167.226.106] X-yoursite-MailScanner-ID: 61FB747CA470.A1B03 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: douly.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 183.91.158.132 Subject: [Qemu-devel] [RFC PATCH] NUMA: Enable adding NUMA node implicitly 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: Dou Liyang , Thomas Huth , Takao Indoh , Eduardo Habkost , "Michael S. Tsirkin" , Izumi Taku , David Hildenbrand , f4bug@amsat.org, Alistair Francis , Igor Mammedov , Marcel Apfelbaum , Paolo Bonzini , 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 Content-Type: text/plain; charset="utf-8" In QEMU, if we enable NUMA and have nodes, QEMU will build ACPI SRAT table for transfering NUMA configuration to the guest. So, the maximum memory in SRAT can be used to determine whether to use the swiotlb for IOMMU or not. However, if QEmu doesn't enable NUMA explicitly on CLI, The SRAT will never be built. When memory hotplug is enabled, some guest's devices may start failing due to SWIOTLB is disabled. Add numa_implicit_add_node0 in struct MachineClass, Invoke it before QEMU parse NUMA options to enable adding NUMA node implicitly. Reported-by: Thadeu Lima de Souza Cascardo Suggested-by: Igor Mammedov Signed-off-by: Dou Liyang Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Cc: Igor Mammedov Cc: David Hildenbrand Cc: Thomas Huth Cc: Alistair Francis Cc: f4bug@amsat.org Cc: Takao Indoh Cc: Izumi Taku --- hw/i386/pc.c | 6 ++++++ include/hw/boards.h | 4 ++++ vl.c | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2108104..3c40117 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2308,6 +2308,11 @@ static const CPUArchIdList *pc_possible_cpu_arch_ids= (MachineState *ms) return ms->possible_cpus; } =20 +static void numa_implicit_add_node0(void) +{ + qemu_opts_parse_noisily(qemu_find_opts("numa"), "node", true); +} + static void x86_nmi(NMIState *n, int cpu_index, Error **errp) { /* cpu index isn't used */ @@ -2349,6 +2354,7 @@ static void pc_machine_class_init(ObjectClass *oc, vo= id *data) mc->get_hotplug_handler =3D pc_get_hotpug_handler; mc->cpu_index_to_instance_props =3D pc_cpu_index_to_props; mc->possible_cpu_arch_ids =3D pc_possible_cpu_arch_ids; + mc->numa_implicit_add_node0 =3D numa_implicit_add_node0; mc->has_hotpluggable_cpus =3D true; mc->default_boot_order =3D "cad"; mc->hot_add_cpu =3D pc_hot_add_cpu; diff --git a/include/hw/boards.h b/include/hw/boards.h index 7f044d1..898d841 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -141,6 +141,8 @@ typedef struct { * should instead use "unimplemented-device" for all memory ranges where * the guest will attempt to probe for a device that QEMU doesn't * implement and a stub device is required. + * @numa_implicit_add_node0: + * Enable NUMA implicitly by add a NUMA node. */ struct MachineClass { /*< private >*/ @@ -191,6 +193,8 @@ struct MachineClass { CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *mac= hine, unsigned cpu_inde= x); const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine); + + void (*numa_implicit_add_node0)(void); }; =20 /** diff --git a/vl.c b/vl.c index fb1f05b..814a5fa 100644 --- a/vl.c +++ b/vl.c @@ -3030,6 +3030,7 @@ int main(int argc, char **argv, char **envp) Error *main_loop_err =3D NULL; Error *err =3D NULL; bool list_data_dirs =3D false; + bool has_numa_config_in_CLI =3D false; typedef struct BlockdevOptions_queue { BlockdevOptions *bdo; Location loc; @@ -3293,6 +3294,7 @@ int main(int argc, char **argv, char **envp) if (!opts) { exit(1); } + has_numa_config_in_CLI =3D true; break; case QEMU_OPTION_display: display_type =3D select_display(optarg); @@ -4585,6 +4587,18 @@ int main(int argc, char **argv, char **envp) default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS); default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS); =20 + /* + * If memory hotplug is enabled i.e. slots > 0 and user hasn't add + * NUMA nodes explicitly on CLI + * + * Enable NUMA implicitly for guest to know the maximum memory + * from ACPI SRAT table, which is used for SWIOTLB. + */ + if (ram_slots > 0 && !has_numa_config_in_CLI) { + if (machine_class->numa_implicit_add_node0) { + machine_class->numa_implicit_add_node0(); + } + } parse_numa_opts(current_machine); =20 if (qemu_opts_foreach(qemu_find_opts("mon"), --=20 2.5.5