From nobody Mon Apr 29 11:10:08 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 150284801483173.06105018145092; Tue, 15 Aug 2017 18:46:54 -0700 (PDT) Received: from localhost ([::1]:34396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhnQ4-0006NW-30 for importer@patchew.org; Tue, 15 Aug 2017 21:46:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhnP4-0005rl-V6 for qemu-devel@nongnu.org; Tue, 15 Aug 2017 21:45:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhnP0-0001Ez-1Y for qemu-devel@nongnu.org; Tue, 15 Aug 2017 21:45:50 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:40233 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhnOy-0001Dm-NZ for qemu-devel@nongnu.org; Tue, 15 Aug 2017 21:45:45 -0400 Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 Aug 2017 09:45:42 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 24C464724392; Wed, 16 Aug 2017 09:45:40 +0800 (CST) Received: from localhost.localdomain.localdomain (10.167.226.106) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 16 Aug 2017 09:45:39 +0800 X-IronPort-AV: E=Sophos;i="5.41,380,1498492800"; d="scan'208";a="23663762" From: Dou Liyang To: Date: Wed, 16 Aug 2017 09:45:35 +0800 Message-ID: <1502847935-20483-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: 24C464724392.AE8CD 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] [PATCH v3] hw/acpi-build: Fix SRAT memory building when there is no memory in node0 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 , ehabkost@redhat.com, mst@redhat.com, imammedo@redhat.com, pbonzini@redhat.com, rth@twiddle.net 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" Currently, Using the fisrt node without memory on the machine makes QEMU unhappy. With this example command line: ... \ -m 1024M,slots=3D4,maxmem=3D32G \ -numa node,nodeid=3D0 \ -numa node,mem=3D1024M,nodeid=3D1 \ -numa node,nodeid=3D2 \ -numa node,nodeid=3D3 \ Guest reports "No NUMA configuration found" and the NUMA topology is wrong. This is because when QEMU builds ACPI SRAT, it regards node0 as the default node to deal with the memory hole(640K-1M). this means the node0 must have some memory(>1M), but, actually it can have no memory. Fix this problem by replace the node0 with the first node which has memory on it. Add a new function for each node. Also do some cleanup. Signed-off-by: Dou Liyang --- V3 --> V2 -Modify the title V2 --> V1: -Fix a coding style problem Replace for (node =3D 0; node < pcms->numa_nodes && pcms->node_mem[node] =3D=3D 0; node++); with for (node =3D 0; node < pcms->numa_nodes; node++) { if (pcms->node_mem[node] !=3D 0) { break; } hw/i386/acpi-build.c | 78 +++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 98dd424..f93d712 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2318,15 +2318,43 @@ build_tpm2(GArray *table_data, BIOSLinker *linker) (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NUL= L); } =20 +static uint64_t +build_srat_node_entry(GArray *table_data, PCMachineState *pcms, + int i, uint64_t mem_base, uint64_t mem_len) +{ + AcpiSratMemoryAffinity *numamem; + uint64_t next_base; + + next_base =3D mem_base + mem_len; + + /* Cut out the ACPI_PCI hole */ + if (mem_base <=3D pcms->below_4g_mem_size && + next_base > pcms->below_4g_mem_size) { + mem_len -=3D next_base - pcms->below_4g_mem_size; + if (mem_len > 0) { + numamem =3D acpi_data_push(table_data, sizeof *numamem); + build_srat_memory(numamem, mem_base, mem_len, i, + MEM_AFFINITY_ENABLED); + } + mem_base =3D 1ULL << 32; + mem_len =3D next_base - pcms->below_4g_mem_size; + next_base +=3D (1ULL << 32) - pcms->below_4g_mem_size; + } + numamem =3D acpi_data_push(table_data, sizeof *numamem); + build_srat_memory(numamem, mem_base, mem_len, i, + MEM_AFFINITY_ENABLED); + return next_base; +} + static void build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) { AcpiSystemResourceAffinityTable *srat; AcpiSratMemoryAffinity *numamem; =20 - int i; + int i, node; int srat_start, numa_start, slots; - uint64_t mem_len, mem_base, next_base; + uint64_t mem_len, mem_base; MachineClass *mc =3D MACHINE_GET_CLASS(machine); const CPUArchIdList *apic_ids =3D mc->possible_cpu_arch_ids(machine); PCMachineState *pcms =3D PC_MACHINE(machine); @@ -2370,36 +2398,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, = MachineState *machine) /* the memory map is a bit tricky, it contains at least one hole * from 640k-1M and possibly another one from 3.5G-4G. */ - next_base =3D 0; + numa_start =3D table_data->len; =20 - numamem =3D acpi_data_push(table_data, sizeof *numamem); - build_srat_memory(numamem, 0, 640 * 1024, 0, MEM_AFFINITY_ENABLED); - next_base =3D 1024 * 1024; - for (i =3D 1; i < pcms->numa_nodes + 1; ++i) { - mem_base =3D next_base; - mem_len =3D pcms->node_mem[i - 1]; - if (i =3D=3D 1) { - mem_len -=3D 1024 * 1024; + /* get the first node which has memory and map the hole from 640K-1M */ + for (node =3D 0; node < pcms->numa_nodes; node++) { + if (pcms->node_mem[node] !=3D 0) { + break; } - next_base =3D mem_base + mem_len; - - /* Cut out the ACPI_PCI hole */ - if (mem_base <=3D pcms->below_4g_mem_size && - next_base > pcms->below_4g_mem_size) { - mem_len -=3D next_base - pcms->below_4g_mem_size; - if (mem_len > 0) { - numamem =3D acpi_data_push(table_data, sizeof *numamem); - build_srat_memory(numamem, mem_base, mem_len, i - 1, - MEM_AFFINITY_ENABLED); - } - mem_base =3D 1ULL << 32; - mem_len =3D next_base - pcms->below_4g_mem_size; - next_base +=3D (1ULL << 32) - pcms->below_4g_mem_size; + } + numamem =3D acpi_data_push(table_data, sizeof *numamem); + build_srat_memory(numamem, 0, 640 * 1024, node, MEM_AFFINITY_ENABLED); + + /* map the rest of memory from 1M */ + mem_base =3D 1024 * 1024; + mem_len =3D pcms->node_mem[node] - mem_base; + mem_base =3D build_srat_node_entry(table_data, pcms, node, + mem_base, mem_len); + + for (i =3D 0; i < pcms->numa_nodes; i++) { + if (i =3D=3D node) { + continue; } - numamem =3D acpi_data_push(table_data, sizeof *numamem); - build_srat_memory(numamem, mem_base, mem_len, i - 1, - MEM_AFFINITY_ENABLED); + mem_base =3D build_srat_node_entry(table_data, pcms, i, + mem_base, pcms->node_mem[i]); } slots =3D (table_data->len - numa_start) / sizeof *numamem; for (; slots < pcms->numa_nodes + 2; slots++) { --=20 2.5.5