From patchwork Mon Nov 20 02:54:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CAC02C072A2 for ; Mon, 20 Nov 2023 02:55:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636353.991745 (Exim 4.92) (envelope-from ) id 1r4uR4-0007lJ-N4; Mon, 20 Nov 2023 02:54:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636353.991745; Mon, 20 Nov 2023 02:54:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uR4-0007lC-KF; Mon, 20 Nov 2023 02:54:54 +0000 Received: by outflank-mailman (input) for mailman id 636353; Mon, 20 Nov 2023 02:54:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uR3-0007WE-M1 for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:54:53 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 2d04534a-8750-11ee-9b0e-b553b5be7939; Mon, 20 Nov 2023 03:54:52 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7FDB61042; Sun, 19 Nov 2023 18:55:37 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D254F3F6C4; Sun, 19 Nov 2023 18:54:47 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2d04534a-8750-11ee-9b0e-b553b5be7939 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Henry Wang Subject: [PATCH v6 01/17] xen/arm: use NR_MEM_BANKS to override default NR_NODE_MEMBLKS Date: Mon, 20 Nov 2023 10:54:15 +0800 Message-Id: <20231120025431.14845-2-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen As a memory range described in device tree cannot be split across multiple nodes. And it is very likely than if you have more than 64 nodes, you may need a lot more than 2 regions per node. So the default NR_NODE_MEMBLKS value (MAX_NUMNODES * 2) makes no sense on Arm. So, for Arm, we would just define NR_NODE_MEMBLKS as an alias to NR_MEM_BANKS. And in the future NR_MEM_BANKS will be user-configurable via kconfig, but for now leave NR_MEM_BANKS as 128 on Arm. This avoids having different way to define the value based NUMA vs non-NUMA. Further discussions can be found here[1]. [1] https://lists.xenproject.org/archives/html/xen-devel/2021-09/msg02322.html Signed-off-by: Wei Chen Signed-off-by: Henry Wang Acked-by: Jan Beulich --- v6: - Rebase on top of staging without code changes --- xen/arch/arm/include/asm/numa.h | 19 ++++++++++++++++++- xen/include/xen/numa.h | 9 +++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h index e2bee2bd82..7d6ae36a19 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -3,9 +3,26 @@ #include +#include + typedef u8 nodeid_t; -#ifndef CONFIG_NUMA +#ifdef CONFIG_NUMA + +/* + * It is very likely that if you have more than 64 nodes, you may + * need a lot more than 2 regions per node. So, for Arm, we would + * just define NR_NODE_MEMBLKS as an alias to NR_MEM_BANKS. + * And in the future NR_MEM_BANKS will be bumped for new platforms, + * but for now leave NR_MEM_BANKS as it is on Arm. This avoid to + * have different way to define the value based NUMA vs non-NUMA. + * + * Further discussions can be found here: + * https://lists.xenproject.org/archives/html/xen-devel/2021-09/msg02322.html + */ +#define NR_NODE_MEMBLKS NR_MEM_BANKS + +#else /* Fake one node for now. See also node_online_map. */ #define cpu_to_node(cpu) 0 diff --git a/xen/include/xen/numa.h b/xen/include/xen/numa.h index 287e81ff66..3e215db1ca 100644 --- a/xen/include/xen/numa.h +++ b/xen/include/xen/numa.h @@ -13,7 +13,16 @@ #define MAX_NUMNODES 1 #endif +/* + * Some architectures may have different considerations for + * number of node memory blocks. They can define their + * NR_NODE_MEMBLKS in asm/numa.h to reflect their architectural + * implementation. If the arch does not have specific implementation, + * the following default NR_NODE_MEMBLKS will be used. + */ +#ifndef NR_NODE_MEMBLKS #define NR_NODE_MEMBLKS (MAX_NUMNODES * 2) +#endif #define vcpu_to_node(v) (cpu_to_node((v)->processor)) From patchwork Mon Nov 20 02:54:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460738 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 78602C5ACB3 for ; Mon, 20 Nov 2023 02:55:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636354.991755 (Exim 4.92) (envelope-from ) id 1r4uR8-00081u-00; Mon, 20 Nov 2023 02:54:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636354.991755; Mon, 20 Nov 2023 02:54:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uR7-00081h-Rn; Mon, 20 Nov 2023 02:54:57 +0000 Received: by outflank-mailman (input) for mailman id 636354; Mon, 20 Nov 2023 02:54:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uR7-00081B-40 for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:54:57 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 2f411797-8750-11ee-98df-6d05b1d4d9a1; Mon, 20 Nov 2023 03:54:55 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 344271042; Sun, 19 Nov 2023 18:55:41 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 901FC3F6C4; Sun, 19 Nov 2023 18:54:52 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2f411797-8750-11ee-98df-6d05b1d4d9a1 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 02/17] xen/arm: implement helpers to get and update NUMA status Date: Mon, 20 Nov 2023 10:54:16 +0800 Message-Id: <20231120025431.14845-3-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen NUMA has one global and one implementation specific switches. For ACPI NUMA implementation, Xen has acpi_numa, so we introduce device_tree_numa for device tree NUMA implementation. And use enumerations to indicate init, off and on status. arch_numa_disabled will get device_tree_numa status, but for arch_numa_setup we have not provided boot arguments to setup device_tree_numa. So we just return -EINVAL in this patch. Signed-off-by: Wei Chen Signed-off-by: Henry Wang Acked-by: Julien Grall --- v3 -> v6: - Rebase on top of staging without code changes. v2 -> v3: - Rename the first entry of enum dt_numa_status as DT_NUMA_DEFAULT. - Make enum dt_numa_status device_tree_numa as __ro_after_init and - assign it explicitly to DT_NUMA_DEFAULT. - Update the year in copyright to 2023. - Don't move the x86 numa_disabled() and make Arm's numa_disabled() a static inline function for !CONFIG_NUMA. v1 -> v2: - Use arch_numa_disabled to replace numa_enable_with_firmware. - Introduce enumerations for device tree numa status. - Use common numa_disabled, drop Arm version numa_disabled. - Introduce arch_numa_setup for Arm. - Rename bad_srat to numa_bad. - Add numa_enable_with_firmware helper. - Add numa_disabled helper. - Refine commit message. --- xen/arch/arm/include/asm/numa.h | 17 +++++++++++ xen/arch/arm/numa.c | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 xen/arch/arm/numa.c diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h index 7d6ae36a19..83f60ad05b 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -22,6 +22,8 @@ typedef u8 nodeid_t; */ #define NR_NODE_MEMBLKS NR_MEM_BANKS +extern bool numa_disabled(void); + #else /* Fake one node for now. See also node_online_map. */ @@ -39,6 +41,21 @@ extern mfn_t first_valid_mfn; #define node_start_pfn(nid) (mfn_x(first_valid_mfn)) #define __node_distance(a, b) (20) +static inline bool numa_disabled(void) +{ + return true; +} + +static inline bool arch_numa_unavailable(void) +{ + return true; +} + +static inline bool arch_numa_broken(void) +{ + return true; +} + #endif #define arch_want_default_dmazone() (false) diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c new file mode 100644 index 0000000000..eb5d0632cb --- /dev/null +++ b/xen/arch/arm/numa.c @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Arm Architecture support layer for NUMA. + * + * Copyright (C) 2023 Arm Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#include +#include + +enum dt_numa_status { + DT_NUMA_DEFAULT, + DT_NUMA_ON, + DT_NUMA_OFF, +}; + +static enum dt_numa_status __ro_after_init device_tree_numa = DT_NUMA_DEFAULT; + +void __init numa_fw_bad(void) +{ + printk(KERN_ERR "NUMA: device tree numa info table not used.\n"); + device_tree_numa = DT_NUMA_OFF; +} + +bool __init arch_numa_unavailable(void) +{ + return device_tree_numa != DT_NUMA_ON; +} + +bool arch_numa_disabled(void) +{ + return device_tree_numa == DT_NUMA_OFF; +} + +int __init arch_numa_setup(const char *opt) +{ + return -EINVAL; +} From patchwork Mon Nov 20 02:54:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460740 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0B00EC5ACB3 for ; Mon, 20 Nov 2023 02:55:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636355.991764 (Exim 4.92) (envelope-from ) id 1r4uRD-0008MI-75; Mon, 20 Nov 2023 02:55:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636355.991764; Mon, 20 Nov 2023 02:55:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRD-0008M7-3k; Mon, 20 Nov 2023 02:55:03 +0000 Received: by outflank-mailman (input) for mailman id 636355; Mon, 20 Nov 2023 02:55:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRB-00081B-NQ for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:01 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 3235049b-8750-11ee-98df-6d05b1d4d9a1; Mon, 20 Nov 2023 03:55:00 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 214231042; Sun, 19 Nov 2023 18:55:46 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 336C13F6C4; Sun, 19 Nov 2023 18:54:55 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3235049b-8750-11ee-98df-6d05b1d4d9a1 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Henry Wang Subject: [PATCH v6 03/17] xen/arm: implement node distance helpers for Arm Date: Mon, 20 Nov 2023 10:54:17 +0800 Message-Id: <20231120025431.14845-4-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen We will parse NUMA nodes distances from device tree. So we need a matrix to record the distances between any two nodes we parsed. Accordingly, we provide this node_set_distance API for device tree NUMA to set the distance for any two nodes in this patch. When NUMA initialization failed, __node_distance will return NUMA_REMOTE_DISTANCE, this will help us avoid doing rollback for distance maxtrix when NUMA initialization failed. As both x86 and Arm have implemented __node_distance, so we move its declaration from asm/numa.h to xen/numa.h. At same time, the outdated u8 return value of x86 has been changed to unsigned char. Signed-off-by: Wei Chen Signed-off-by: Henry Wang Acked-by: Jan Beulich # non-Arm parts --- v6: - Rebase on top of staging without code changes. v4 -> v5: - Coding style (extra blank line and printk variable type) and in-code comment fixes and improvements. - Move the from/to range check in numa_set_distance() to caller, - Drop the unnecessary check ensured by caller in numa_set_distance(). - Rework the invalid distance check in numa_set_distance() following Linux, add more in-code comments about these distance checks. v3 -> v4: - s/definition/declaration/ in commit message. - Add Acked-by tag from Jan for non-Arm parts. - Drop unnecessary initializer for node_distance_map. Pre-set the distance map to NUMA_NO_DISTANCE. - Drop NUMA_DISTANCE_UDF_MIN and its usage. - Drop EXPORT_SYMBOL(__node_distance). - Rework __node_distance()'s return value logic. v2 -> v3: - Use __ro_after_init for node_distance_map. - Correct format of if condition identation in numa_set_distance(). - Drop the unnecessary change to the year of copyright. - Use ARRAY_SIZE() to determine node_distance_map's row, column size. v1 -> v2: - Use unsigned int/char instead of uint32_t/u8. - Re-org the commit message. --- xen/arch/arm/Makefile | 1 + xen/arch/arm/include/asm/numa.h | 12 ++++++++ xen/arch/arm/numa.c | 51 +++++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/numa.h | 1 - xen/arch/x86/srat.c | 2 +- xen/include/xen/numa.h | 1 + 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 7bf07e9920..86e0e47e22 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_LIVEPATCH) += livepatch.o obj-y += mem_access.o obj-y += mm.o obj-y += monitor.o +obj-$(CONFIG_NUMA) += numa.o obj-y += p2m.o obj-y += percpu.o obj-y += platform.o diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h index 83f60ad05b..96c856a9f7 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -22,7 +22,19 @@ typedef u8 nodeid_t; */ #define NR_NODE_MEMBLKS NR_MEM_BANKS +/* + * In ACPI spec, 0-9 are the reserved values for node distance, + * 10 indicates local node distance, 20 indicates remote node + * distance. Set node distance map in device tree will follow + * the ACPI's definition. + */ +#define NUMA_DISTANCE_UDF_MAX 9 +#define NUMA_LOCAL_DISTANCE 10 +#define NUMA_REMOTE_DISTANCE 20 + extern bool numa_disabled(void); +extern void numa_set_distance(nodeid_t from, nodeid_t to, + unsigned int distance); #else diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c index eb5d0632cb..31332a6ea7 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -28,6 +28,11 @@ enum dt_numa_status { static enum dt_numa_status __ro_after_init device_tree_numa = DT_NUMA_DEFAULT; +static unsigned char __ro_after_init +node_distance_map[MAX_NUMNODES][MAX_NUMNODES] = { + [0 ... MAX_NUMNODES - 1] = { [0 ... MAX_NUMNODES - 1] = NUMA_NO_DISTANCE } +}; + void __init numa_fw_bad(void) { printk(KERN_ERR "NUMA: device tree numa info table not used.\n"); @@ -48,3 +53,49 @@ int __init arch_numa_setup(const char *opt) { return -EINVAL; } + +void __init numa_set_distance(nodeid_t from, nodeid_t to, + unsigned int distance) +{ + /* + * Since the NUMA device tree binding does not clearly specify the valid + * range of node distance, here we keep consistent with the ACPI, whose + * SLIT table uses 1 byte to describe the node distance. Hence node + * distances that cannot fit in 1 byte are invalid. Also, node distance + * 0-9 are undefined values. + * Reject all above-mentioned invalid distance values. + */ + if ( (uint8_t)distance != distance || distance <= NUMA_DISTANCE_UDF_MAX ) + { + printk(XENLOG_WARNING + "NUMA: invalid distance: from=%"PRIu8" to=%"PRIu8" distance=%u\n", + from, to, distance); + return; + } + + node_distance_map[from][to] = distance; +} + +unsigned char __node_distance(nodeid_t from, nodeid_t to) +{ + if ( from == to ) + return NUMA_LOCAL_DISTANCE; + + /* + * When NUMA is off, any distance will be treated as unreachable, so + * directly return NUMA_NO_DISTANCE from here as an optimization. + */ + if ( numa_disabled() ) + return NUMA_NO_DISTANCE; + + /* + * Check whether the nodes are in the matrix range. + * When any node is out of range, except from and to nodes are the + * same (see above), we treat them as unreachable. + */ + if ( from >= ARRAY_SIZE(node_distance_map) || + to >= ARRAY_SIZE(node_distance_map[0]) ) + return NUMA_NO_DISTANCE; + + return node_distance_map[from][to]; +} diff --git a/xen/arch/x86/include/asm/numa.h b/xen/arch/x86/include/asm/numa.h index 7866afa408..45456ac441 100644 --- a/xen/arch/x86/include/asm/numa.h +++ b/xen/arch/x86/include/asm/numa.h @@ -22,7 +22,6 @@ extern void init_cpu_to_node(void); #define arch_want_default_dmazone() (num_online_nodes() > 1) void srat_parse_regions(paddr_t addr); -extern u8 __node_distance(nodeid_t a, nodeid_t b); unsigned int arch_get_dma_bitsize(void); #endif diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c index 3f70338e6e..e55a749ad5 100644 --- a/xen/arch/x86/srat.c +++ b/xen/arch/x86/srat.c @@ -324,7 +324,7 @@ unsigned int numa_node_to_arch_nid(nodeid_t n) return 0; } -u8 __node_distance(nodeid_t a, nodeid_t b) +unsigned char __node_distance(nodeid_t a, nodeid_t b) { unsigned index; u8 slit_val; diff --git a/xen/include/xen/numa.h b/xen/include/xen/numa.h index 3e215db1ca..bb9a3d2591 100644 --- a/xen/include/xen/numa.h +++ b/xen/include/xen/numa.h @@ -114,6 +114,7 @@ extern bool numa_memblks_available(void); extern bool numa_update_node_memblks(nodeid_t node, unsigned int arch_nid, paddr_t start, paddr_t size, bool hotplug); extern void numa_set_processor_nodes_parsed(nodeid_t node); +extern unsigned char __node_distance(nodeid_t a, nodeid_t b); #else From patchwork Mon Nov 20 02:54:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460742 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D8B18C5ACB3 for ; Mon, 20 Nov 2023 02:55:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636357.991775 (Exim 4.92) (envelope-from ) id 1r4uRH-0000FL-Es; Mon, 20 Nov 2023 02:55:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636357.991775; Mon, 20 Nov 2023 02:55:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRH-0000FC-Bg; Mon, 20 Nov 2023 02:55:07 +0000 Received: by outflank-mailman (input) for mailman id 636357; Mon, 20 Nov 2023 02:55:05 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRF-0007WE-Rj for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:05 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 3450e288-8750-11ee-9b0e-b553b5be7939; Mon, 20 Nov 2023 03:55:04 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BA8631042; Sun, 19 Nov 2023 18:55:49 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 19D183F6C4; Sun, 19 Nov 2023 18:55:00 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3450e288-8750-11ee-9b0e-b553b5be7939 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 04/17] xen/arm: use arch_get_ram_range to get memory ranges from bootinfo Date: Mon, 20 Nov 2023 10:54:18 +0800 Message-Id: <20231120025431.14845-5-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen Implement the same helper "arch_get_ram_range" as x86 for NUMA code to get memory bank from Arm bootinfo. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v2 -> v6: - Rebase on top of staging without code changes. v1 -> v2: - Use arch_get_ram_range instead of arch_get_memory_map. --- xen/arch/arm/numa.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c index 31332a6ea7..e9b2ec93bc 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -99,3 +99,14 @@ unsigned char __node_distance(nodeid_t from, nodeid_t to) return node_distance_map[from][to]; } + +int __init arch_get_ram_range(unsigned int idx, paddr_t *start, paddr_t *end) +{ + if ( idx >= bootinfo.mem.nr_banks ) + return -ENOENT; + + *start = bootinfo.mem.bank[idx].start; + *end = *start + bootinfo.mem.bank[idx].size; + + return 0; +} From patchwork Mon Nov 20 02:54:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2A95C072A2 for ; Mon, 20 Nov 2023 02:55:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636360.991785 (Exim 4.92) (envelope-from ) id 1r4uRJ-0000bL-TW; Mon, 20 Nov 2023 02:55:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636360.991785; Mon, 20 Nov 2023 02:55:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRJ-0000bA-Pd; Mon, 20 Nov 2023 02:55:09 +0000 Received: by outflank-mailman (input) for mailman id 636360; Mon, 20 Nov 2023 02:55:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRI-00081B-Vp for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:08 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 36992474-8750-11ee-98df-6d05b1d4d9a1; Mon, 20 Nov 2023 03:55:08 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6935A1042; Sun, 19 Nov 2023 18:55:53 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C49923F6C4; Sun, 19 Nov 2023 18:55:04 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 36992474-8750-11ee-98df-6d05b1d4d9a1 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 05/17] xen/arm: build NUMA cpu_to_node map in dt_smp_init_cpus Date: Mon, 20 Nov 2023 10:54:19 +0800 Message-Id: <20231120025431.14845-6-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen NUMA implementation has a cpu_to_node array to store CPU to NODE map. Xen is using CPU logical ID in runtime components, so we use CPU logical ID as CPU index in cpu_to_node. In device tree case, cpu_logical_map is created in dt_smp_init_cpus. So, when NUMA is enabled, dt_smp_init_cpus will fetch CPU NUMA id at the same time for cpu_to_node. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v2 -> v6: - Rebase on top of staging without code changes. v1 -> v2: - Use static inline to replace macros to perform function paramerters type check. - Add numa_disabled to gate the numa-node-id check for CONFIG_NUMA on but numa disabled user case. - Use macro instead of static inline function to stub numa_set_node. --- xen/arch/arm/include/asm/numa.h | 4 ++++ xen/arch/arm/smpboot.c | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h index 96c856a9f7..97d4a67dea 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -68,6 +68,10 @@ static inline bool arch_numa_broken(void) return true; } +static inline void numa_set_node(unsigned int cpu, nodeid_t node) +{ +} + #endif #define arch_want_default_dmazone() (false) diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 5533aed455..81574ae0ad 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -119,7 +119,12 @@ static void __init dt_smp_init_cpus(void) { [0 ... NR_CPUS - 1] = MPIDR_INVALID }; + static nodeid_t node_map[NR_CPUS] __initdata = + { + [0 ... NR_CPUS - 1] = NUMA_NO_NODE + }; bool bootcpu_valid = false; + unsigned int nid = 0; int rc; mpidr = system_cpuinfo.mpidr.bits & MPIDR_HWID_MASK; @@ -170,6 +175,28 @@ static void __init dt_smp_init_cpus(void) continue; } + if ( IS_ENABLED(CONFIG_NUMA) ) + { + /* + * When CONFIG_NUMA is set, try to fetch numa infomation + * from CPU dts node, otherwise the nid is always 0. + */ + if ( !dt_property_read_u32(cpu, "numa-node-id", &nid) ) + { + printk(XENLOG_WARNING + "cpu[%d] dts path: %s: doesn't have numa information!\n", + cpuidx, dt_node_full_name(cpu)); + /* + * During the early stage of NUMA initialization, when Xen + * found any CPU dts node doesn't have numa-node-id info, the + * NUMA will be treated as off, all CPU will be set to a FAKE + * node 0. So if we get numa-node-id failed here, we should + * set nid to 0. + */ + nid = 0; + } + } + /* * 8 MSBs must be set to 0 in the DT since the reg property * defines the MPIDR[23:0] @@ -229,9 +256,13 @@ static void __init dt_smp_init_cpus(void) { printk("cpu%d init failed (hwid %"PRIregister"): %d\n", i, hwid, rc); tmp_map[i] = MPIDR_INVALID; + node_map[i] = NUMA_NO_NODE; } else + { tmp_map[i] = hwid; + node_map[i] = nid; + } } if ( !bootcpu_valid ) @@ -247,6 +278,11 @@ static void __init dt_smp_init_cpus(void) continue; cpumask_set_cpu(i, &cpu_possible_map); cpu_logical_map(i) = tmp_map[i]; + + nid = node_map[i]; + if ( nid >= MAX_NUMNODES ) + nid = 0; + numa_set_node(i, nid); } } From patchwork Mon Nov 20 02:54:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0B5E9C5ACB3 for ; Mon, 20 Nov 2023 02:55:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636361.991795 (Exim 4.92) (envelope-from ) id 1r4uRN-000163-8P; Mon, 20 Nov 2023 02:55:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636361.991795; Mon, 20 Nov 2023 02:55:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRN-00015m-4V; Mon, 20 Nov 2023 02:55:13 +0000 Received: by outflank-mailman (input) for mailman id 636361; Mon, 20 Nov 2023 02:55:12 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRM-00081B-0t for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:12 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 38983935-8750-11ee-98df-6d05b1d4d9a1; Mon, 20 Nov 2023 03:55:11 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E69BC1042; Sun, 19 Nov 2023 18:55:56 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4E6503F6C4; Sun, 19 Nov 2023 18:55:08 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 38983935-8750-11ee-98df-6d05b1d4d9a1 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 06/17] xen/arm: Add boot and secondary CPU to NUMA system Date: Mon, 20 Nov 2023 10:54:20 +0800 Message-Id: <20231120025431.14845-7-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen In this patch, we make NUMA node online and add cpu to its NUMA node. This will make NUMA-aware components have NUMA affinity data to support their work. To keep the mostly the same behavior of x86, we use numa_detect_cpu_node to online node. The difference is that, we have prepared cpu_to_node in dt_smp_init_cpus, so we don't need to setup cpu_to_node in numa_detect_cpu_node. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v2 -> v6: - Rebase on top of staging without code changes. v1 -> v2: - Use unsigned int instead of int for cpu id. - Use static inline for stub to do type check. --- xen/arch/arm/include/asm/numa.h | 9 +++++++++ xen/arch/arm/numa.c | 10 ++++++++++ xen/arch/arm/setup.c | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h index 97d4a67dea..b04ace26db 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -35,6 +35,7 @@ typedef u8 nodeid_t; extern bool numa_disabled(void); extern void numa_set_distance(nodeid_t from, nodeid_t to, unsigned int distance); +extern void numa_detect_cpu_node(unsigned int cpu); #else @@ -72,6 +73,14 @@ static inline void numa_set_node(unsigned int cpu, nodeid_t node) { } +static inline void numa_add_cpu(unsigned int cpu) +{ +} + +static inline void numa_detect_cpu_node(unsigned int cpu) +{ +} + #endif #define arch_want_default_dmazone() (false) diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c index e9b2ec93bc..b5a87531f7 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -76,6 +76,16 @@ void __init numa_set_distance(nodeid_t from, nodeid_t to, node_distance_map[from][to] = distance; } +void numa_detect_cpu_node(unsigned int cpu) +{ + nodeid_t node = cpu_to_node[cpu]; + + if ( node == NUMA_NO_NODE ) + node = 0; + + node_set_online(node); +} + unsigned char __node_distance(nodeid_t from, nodeid_t to) { if ( from == to ) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 3f3a45719c..02bc887725 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -1208,6 +1208,11 @@ void __init start_xen(unsigned long boot_phys_offset, for_each_present_cpu ( i ) { + /* Detect and online node based on cpu_to_node[]. */ + numa_detect_cpu_node(i); + /* Set up node_to_cpumask based on cpu_to_node[]. */ + numa_add_cpu(i); + if ( (num_online_cpus() < nr_cpu_ids) && !cpu_online(i) ) { int ret = cpu_up(i); From patchwork Mon Nov 20 02:54:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460744 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE80BC072A2 for ; Mon, 20 Nov 2023 02:55:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636364.991805 (Exim 4.92) (envelope-from ) id 1r4uRS-0001gl-Jg; Mon, 20 Nov 2023 02:55:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636364.991805; Mon, 20 Nov 2023 02:55:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRS-0001ge-GF; Mon, 20 Nov 2023 02:55:18 +0000 Received: by outflank-mailman (input) for mailman id 636364; Mon, 20 Nov 2023 02:55:16 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRQ-0007WE-T3 for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:16 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 3aba77dd-8750-11ee-9b0e-b553b5be7939; Mon, 20 Nov 2023 03:55:15 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7AF451042; Sun, 19 Nov 2023 18:56:00 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D65DF3F6C4; Sun, 19 Nov 2023 18:55:11 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3aba77dd-8750-11ee-9b0e-b553b5be7939 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 07/17] xen/arm: introduce a helper to parse device tree processor node Date: Mon, 20 Nov 2023 10:54:21 +0800 Message-Id: <20231120025431.14845-8-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen Processor NUMA ID information is stored in device tree's processor node as "numa-node-id". We need a new helper to parse this ID from processor node. If we get this ID from processor node, this ID's validity still need to be checked. Once we got a invalid NUMA ID from any processor node, the device tree will be marked as NUMA information invalid. Since new helpers need to know the NUMA status, move the enum dt_numa_status to the Arm NUMA header. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v5 -> v6: - Rebase on top of staging without code changes. v3 -> v5: - Rename "numa_device_tree.c" to "numa-dt.c". v2 -> v3: - Move the enum dt_numa_status to the Arm NUMA header. - Update the year in copyright to 2023. v1 -> v2: - Move numa_disabled from fdt_numa_processor_affinity_init to fdt_parse_numa_cpu_node. - Move invalid NUMA id check to fdt_parse_numa_cpu_node. - Return ENODATA for normal dtb without NUMA info. - Use NUMA status helpers instead of SRAT functions. --- xen/arch/arm/Makefile | 1 + xen/arch/arm/include/asm/numa.h | 8 +++++ xen/arch/arm/numa-dt.c | 64 +++++++++++++++++++++++++++++++++ xen/arch/arm/numa.c | 8 +---- 4 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 xen/arch/arm/numa-dt.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 86e0e47e22..6a4e7814b8 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -39,6 +39,7 @@ obj-y += mem_access.o obj-y += mm.o obj-y += monitor.o obj-$(CONFIG_NUMA) += numa.o +obj-$(CONFIG_DEVICE_TREE_NUMA) += numa-dt.o obj-y += p2m.o obj-y += percpu.o obj-y += platform.o diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h index b04ace26db..2987158d16 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -22,6 +22,14 @@ typedef u8 nodeid_t; */ #define NR_NODE_MEMBLKS NR_MEM_BANKS +enum dt_numa_status { + DT_NUMA_DEFAULT, + DT_NUMA_ON, + DT_NUMA_OFF, +}; + +extern enum dt_numa_status device_tree_numa; + /* * In ACPI spec, 0-9 are the reserved values for node distance, * 10 indicates local node distance, 20 indicates remote node diff --git a/xen/arch/arm/numa-dt.c b/xen/arch/arm/numa-dt.c new file mode 100644 index 0000000000..83601c83e7 --- /dev/null +++ b/xen/arch/arm/numa-dt.c @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Arm Architecture support layer for device tree NUMA. + * + * Copyright (C) 2023 Arm Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#include +#include +#include +#include +#include + +/* Callback for device tree processor affinity */ +static int __init fdt_numa_processor_affinity_init(nodeid_t node) +{ + numa_set_processor_nodes_parsed(node); + device_tree_numa = DT_NUMA_ON; + + printk(KERN_INFO "DT: NUMA node %"PRIu8" processor parsed\n", node); + + return 0; +} + +/* Parse CPU NUMA node info */ +static int __init fdt_parse_numa_cpu_node(const void *fdt, int node) +{ + unsigned int nid; + + if ( numa_disabled() ) + return -EINVAL; + + /* + * device_tree_get_u32 will return NUMA_NO_NODE when this CPU + * DT node doesn't have numa-node-id. This can help us to + * distinguish a bad DTB and a normal DTB without NUMA info. + */ + nid = device_tree_get_u32(fdt, node, "numa-node-id", NUMA_NO_NODE); + if ( nid == NUMA_NO_NODE ) + { + numa_fw_bad(); + return -ENODATA; + } + else if ( nid >= MAX_NUMNODES ) + { + printk(XENLOG_ERR "DT: CPU NUMA node id %u is invalid\n", nid); + numa_fw_bad(); + return -EINVAL; + } + + return fdt_numa_processor_affinity_init(nid); +} diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c index b5a87531f7..08e15ebbb0 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -20,13 +20,7 @@ #include #include -enum dt_numa_status { - DT_NUMA_DEFAULT, - DT_NUMA_ON, - DT_NUMA_OFF, -}; - -static enum dt_numa_status __ro_after_init device_tree_numa = DT_NUMA_DEFAULT; +enum dt_numa_status __ro_after_init device_tree_numa = DT_NUMA_DEFAULT; static unsigned char __ro_after_init node_distance_map[MAX_NUMNODES][MAX_NUMNODES] = { From patchwork Mon Nov 20 02:54:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460745 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 95BE6C5ACB3 for ; Mon, 20 Nov 2023 02:55:34 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636365.991815 (Exim 4.92) (envelope-from ) id 1r4uRU-00023o-S5; Mon, 20 Nov 2023 02:55:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636365.991815; Mon, 20 Nov 2023 02:55:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRU-00023Y-O6; Mon, 20 Nov 2023 02:55:20 +0000 Received: by outflank-mailman (input) for mailman id 636365; Mon, 20 Nov 2023 02:55:19 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRT-00081B-Fv for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:19 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 3ceb8858-8750-11ee-98df-6d05b1d4d9a1; Mon, 20 Nov 2023 03:55:18 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 12C541042; Sun, 19 Nov 2023 18:56:04 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6E0F83F6C4; Sun, 19 Nov 2023 18:55:15 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3ceb8858-8750-11ee-98df-6d05b1d4d9a1 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 08/17] xen/arm: introduce a helper to parse device tree memory node Date: Mon, 20 Nov 2023 10:54:22 +0800 Message-Id: <20231120025431.14845-9-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen Memory blocks' NUMA ID information is stored in device tree's memory nodes as "numa-node-id". We need a new helper to parse and verify this ID from memory nodes. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v5 -> v6: - Rebase on top of staging without code changes. v1 -> v5: - Fix coding style: printk variable type and label indented. - Move numa_disabled check to fdt_parse_numa_memory_node. - Use numa_bad to replace bad_srat. - Replace tabs by spaces. - Align parameters. - return ENODATA for a normal dtb without numa info. - Use node id as dummy PXM for numa_update_node_memblks. --- xen/arch/arm/numa-dt.c | 89 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/xen/arch/arm/numa-dt.c b/xen/arch/arm/numa-dt.c index 83601c83e7..cebc7e4300 100644 --- a/xen/arch/arm/numa-dt.c +++ b/xen/arch/arm/numa-dt.c @@ -34,6 +34,26 @@ static int __init fdt_numa_processor_affinity_init(nodeid_t node) return 0; } +/* Callback for parsing of the memory regions affinity */ +static int __init fdt_numa_memory_affinity_init(nodeid_t node, + paddr_t start, paddr_t size) +{ + if ( !numa_memblks_available() ) + { + dprintk(XENLOG_WARNING, + "Too many NUMA entries, try bigger NR_NODE_MEMBLKS\n"); + return -EINVAL; + } + + numa_fw_nid_name = "numa-node-id"; + if ( !numa_update_node_memblks(node, node, start, size, false) ) + return -EINVAL; + + device_tree_numa = DT_NUMA_ON; + + return 0; +} + /* Parse CPU NUMA node info */ static int __init fdt_parse_numa_cpu_node(const void *fdt, int node) { @@ -62,3 +82,72 @@ static int __init fdt_parse_numa_cpu_node(const void *fdt, int node) return fdt_numa_processor_affinity_init(nid); } + +/* Parse memory node NUMA info */ +static int __init fdt_parse_numa_memory_node(const void *fdt, int node, + const char *name, + unsigned int addr_cells, + unsigned int size_cells) +{ + unsigned int nid; + int ret = 0, len; + paddr_t addr, size; + const struct fdt_property *prop; + unsigned int idx, ranges; + const __be32 *addresses; + + if ( numa_disabled() ) + return -EINVAL; + + /* + * device_tree_get_u32 will return NUMA_NO_NODE when this memory + * DT node doesn't have numa-node-id. This can help us to + * distinguish a bad DTB and a normal DTB without NUMA info. + */ + nid = device_tree_get_u32(fdt, node, "numa-node-id", NUMA_NO_NODE); + if ( node == NUMA_NO_NODE ) + { + numa_fw_bad(); + return -ENODATA; + } + else if ( nid >= MAX_NUMNODES ) + { + printk(XENLOG_WARNING "Node id %u exceeds maximum value\n", nid); + goto invalid_data; + } + + prop = fdt_get_property(fdt, node, "reg", &len); + if ( !prop ) + { + printk(XENLOG_WARNING + "fdt: node `%s': missing `reg' property\n", name); + goto invalid_data; + } + + addresses = (const __be32 *)prop->data; + ranges = len / (sizeof(__be32)* (addr_cells + size_cells)); + for ( idx = 0; idx < ranges; idx++ ) + { + device_tree_get_reg(&addresses, addr_cells, size_cells, &addr, &size); + /* Skip zero size ranges */ + if ( !size ) + continue; + + ret = fdt_numa_memory_affinity_init(nid, addr, size); + if ( ret ) + goto invalid_data; + } + + if ( idx == 0 ) + { + printk(XENLOG_ERR + "bad property in memory node, idx=%u ret=%d\n", idx, ret); + goto invalid_data; + } + + return 0; + + invalid_data: + numa_fw_bad(); + return -EINVAL; +} From patchwork Mon Nov 20 02:54:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460749 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2054AC5AD4C for ; Mon, 20 Nov 2023 02:56:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636376.991835 (Exim 4.92) (envelope-from ) id 1r4uRu-00047T-Gf; Mon, 20 Nov 2023 02:55:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636376.991835; Mon, 20 Nov 2023 02:55:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRu-000479-Bv; Mon, 20 Nov 2023 02:55:46 +0000 Received: by outflank-mailman (input) for mailman id 636376; Mon, 20 Nov 2023 02:55:45 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRX-00081B-1U for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:23 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 3f039905-8750-11ee-98df-6d05b1d4d9a1; Mon, 20 Nov 2023 03:55:22 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9773E1042; Sun, 19 Nov 2023 18:56:07 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F2F0F3F6C4; Sun, 19 Nov 2023 18:55:18 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3f039905-8750-11ee-98df-6d05b1d4d9a1 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map Date: Mon, 20 Nov 2023 10:54:23 +0800 Message-Id: <20231120025431.14845-10-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen A NUMA aware device tree will provide a "distance-map" node to describe distance between any two nodes. This patch introduce a new helper to parse this distance map. Note that, since the NUMA device tree binding does not explicitly specify the range of valid node distance, hence rather than rejecting node distance values >= 0xff, saturate the distance at 0xfe, while keeping 0xff for NUMA_NO_DISTANCE, so overall we can keep things consistent with ACPI. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v5 -> v6: - Rebase on top of staging without code changes. v1 -> v5: - Fix coding style (printk variable type and label indented) and in-code comment. - Check the from/to range to avoid the side-effect of the 8-bit truncation by numa_set_distance(). - The distance map default value is now NUMA_NO_DISTANCE, update the logic accordingly and add in-code comment as a note. - Get rid of useless braces. - Use new NUMA status helper. - Use PRIu32 to replace u in print messages. - Fix opposite = __node_distance(to, from). - disable dtb numa info table when we find an invalid data in dtb. --- xen/arch/arm/numa-dt.c | 116 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/xen/arch/arm/numa-dt.c b/xen/arch/arm/numa-dt.c index cebc7e4300..2fb6663e08 100644 --- a/xen/arch/arm/numa-dt.c +++ b/xen/arch/arm/numa-dt.c @@ -151,3 +151,119 @@ static int __init fdt_parse_numa_memory_node(const void *fdt, int node, numa_fw_bad(); return -EINVAL; } + +/* Parse NUMA distance map v1 */ +static int __init fdt_parse_numa_distance_map_v1(const void *fdt, int node) +{ + const struct fdt_property *prop; + const __be32 *matrix; + unsigned int i, entry_count; + int len; + + printk(XENLOG_INFO "NUMA: parsing numa-distance-map\n"); + + prop = fdt_get_property(fdt, node, "distance-matrix", &len); + if ( !prop ) + { + printk(XENLOG_WARNING + "NUMA: No distance-matrix property in distance-map\n"); + goto invalid_data; + } + + if ( len % sizeof(__be32) != 0 ) + { + printk(XENLOG_WARNING + "distance-matrix in node is not a multiple of u32\n"); + goto invalid_data; + } + + entry_count = len / sizeof(__be32); + if ( entry_count == 0 ) + { + printk(XENLOG_WARNING "NUMA: Invalid distance-matrix\n"); + goto invalid_data; + } + + matrix = (const __be32 *)prop->data; + for ( i = 0; i + 2 < entry_count; i += 3 ) + { + unsigned int from, to, distance, opposite; + + from = dt_next_cell(1, &matrix); + to = dt_next_cell(1, &matrix); + distance = dt_next_cell(1, &matrix); + + if ( from >= MAX_NUMNODES || to >= MAX_NUMNODES ) + { + printk(XENLOG_WARNING "NUMA: invalid nodes: from=%u to=%u MAX=%u\n", + from, to, MAX_NUMNODES); + goto invalid_data; + } + + if ( (from == to && distance != NUMA_LOCAL_DISTANCE) || + (from != to && distance <= NUMA_LOCAL_DISTANCE) ) + { + printk(XENLOG_WARNING + "NUMA: Invalid distance: NODE#%u->NODE#%u:%u\n", + from, to, distance); + goto invalid_data; + } + + printk(XENLOG_INFO "NUMA: distance: NODE#%u->NODE#%u:%u\n", + from, to, distance); + + /* Get opposite way distance */ + opposite = __node_distance(to, from); + /* The default value in node_distance_map is NUMA_NO_DISTANCE */ + if ( opposite == NUMA_NO_DISTANCE ) + { + /* Bi-directions are not set, set both */ + numa_set_distance(from, to, distance); + numa_set_distance(to, from, distance); + } + else + { + /* + * Opposite way distance has been set to a different value. + * It may be a firmware device tree bug? + */ + if ( opposite != distance ) + { + /* + * In device tree NUMA distance-matrix binding: + * https://www.kernel.org/doc/Documentation/devicetree/bindings/numa.txt + * There is a notes mentions: + * "Each entry represents distance from first node to + * second node. The distances are equal in either + * direction." + * + * That means device tree doesn't permit this case. + * But in ACPI spec, it cares to specifically permit this + * case: + * "Except for the relative distance from a System Locality + * to itself, each relative distance is stored twice in the + * matrix. This provides the capability to describe the + * scenario where the relative distances for the two + * directions between System Localities is different." + * + * That means a real machine allows such NUMA configuration. + * So, place a WARNING here to notice system administrators, + * is it the special case that they hijack the device tree + * to support their rare machines? + */ + printk(XENLOG_WARNING + "Un-matched bi-direction! NODE#%u->NODE#%u:%u, NODE#%u->NODE#%u:%u\n", + from, to, distance, to, from, opposite); + } + + /* Opposite way distance was set before, just set this way */ + numa_set_distance(from, to, distance); + } + } + + return 0; + + invalid_data: + numa_fw_bad(); + return -EINVAL; +} From patchwork Mon Nov 20 02:54:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460746 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54B0EC072A2 for ; Mon, 20 Nov 2023 02:55:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636371.991825 (Exim 4.92) (envelope-from ) id 1r4uRc-0002px-4a; Mon, 20 Nov 2023 02:55:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636371.991825; Mon, 20 Nov 2023 02:55:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRc-0002pk-1o; Mon, 20 Nov 2023 02:55:28 +0000 Received: by outflank-mailman (input) for mailman id 636371; Mon, 20 Nov 2023 02:55:27 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRb-0007WE-NI for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:27 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 4150dff3-8750-11ee-9b0e-b553b5be7939; Mon, 20 Nov 2023 03:55:26 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 77CE51042; Sun, 19 Nov 2023 18:56:11 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D3AA53F6C4; Sun, 19 Nov 2023 18:55:22 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4150dff3-8750-11ee-9b0e-b553b5be7939 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 10/17] xen/arm: unified entry to parse all NUMA data from device tree Date: Mon, 20 Nov 2023 10:54:24 +0800 Message-Id: <20231120025431.14845-11-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen In this function, we scan the whole device tree to parse CPU node id, memory node id and distance-map. Though early_scan_node will invoke a handler to process memory nodes. If we want to parse memory node id in that handler, we have to embed NUMA parse code in that handler. But we still need to scan whole device tree to find CPU NUMA id and distance-map. In this case, we include memory NUMA id parse in this function too. Another benefit is that we have a unique entry for device tree NUMA data parse. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v5 -> v6: - Rebase on top of staging without code changes. v1 -> v5: - Fix typos in commit message. - Fix code style and align parameters. - Use strncmp to replace memcmp. --- xen/arch/arm/include/asm/numa.h | 1 + xen/arch/arm/numa-dt.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h index 2987158d16..15308f5a36 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -44,6 +44,7 @@ extern bool numa_disabled(void); extern void numa_set_distance(nodeid_t from, nodeid_t to, unsigned int distance); extern void numa_detect_cpu_node(unsigned int cpu); +extern int numa_device_tree_init(const void *fdt); #else diff --git a/xen/arch/arm/numa-dt.c b/xen/arch/arm/numa-dt.c index 2fb6663e08..8198a0da2e 100644 --- a/xen/arch/arm/numa-dt.c +++ b/xen/arch/arm/numa-dt.c @@ -267,3 +267,33 @@ static int __init fdt_parse_numa_distance_map_v1(const void *fdt, int node) numa_fw_bad(); return -EINVAL; } + +static int __init fdt_scan_numa_nodes(const void *fdt, int node, + const char *uname, int depth, + unsigned int address_cells, + unsigned int size_cells, void *data) +{ + int len, ret = 0; + const void *prop; + + prop = fdt_getprop(fdt, node, "device_type", &len); + if ( prop ) + { + if ( strncmp(prop, "cpu", len) == 0 ) + ret = fdt_parse_numa_cpu_node(fdt, node); + else if ( strncmp(prop, "memory", len) == 0 ) + ret = fdt_parse_numa_memory_node(fdt, node, uname, + address_cells, size_cells); + } + else if ( fdt_node_check_compatible(fdt, node, + "numa-distance-map-v1") == 0 ) + ret = fdt_parse_numa_distance_map_v1(fdt, node); + + return ret; +} + +/* Initialize NUMA from device tree */ +int __init numa_device_tree_init(const void *fdt) +{ + return device_tree_for_each_node(fdt, 0, fdt_scan_numa_nodes, NULL); +} From patchwork Mon Nov 20 02:54:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460750 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ABCF1C072A2 for ; Mon, 20 Nov 2023 02:56:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636386.991885 (Exim 4.92) (envelope-from ) id 1r4uS1-0005kJ-JX; Mon, 20 Nov 2023 02:55:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636386.991885; Mon, 20 Nov 2023 02:55:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uS1-0005k2-Fd; Mon, 20 Nov 2023 02:55:53 +0000 Received: by outflank-mailman (input) for mailman id 636386; Mon, 20 Nov 2023 02:55:51 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRe-00081B-IR for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:30 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 436af30b-8750-11ee-98df-6d05b1d4d9a1; Mon, 20 Nov 2023 03:55:29 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0B83A1042; Sun, 19 Nov 2023 18:56:15 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 66AB63F6C4; Sun, 19 Nov 2023 18:55:26 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 436af30b-8750-11ee-98df-6d05b1d4d9a1 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 11/17] xen/arm: keep guest still be NUMA unware Date: Mon, 20 Nov 2023 10:54:25 +0800 Message-Id: <20231120025431.14845-12-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen The NUMA information provided in the host Device-Tree are only for Xen. For dom0, we want to hide them as they may be different (for now, dom0 is still not aware of NUMA) The CPU and memory nodes are recreated from scratch for the domain. So we already skip the "numa-node-id" property for these two types of nodes. However, some devices like PCIe may have "numa-node-id" property too. We have to skip them as well. Signed-off-by: Wei Chen Signed-off-by: Henry Wang Reviewed-by: Stefano Stabellini --- v5 -> v6: - Rebase on top of staging without code changes. v1 -> v5: - Add Rb --- xen/arch/arm/domain_build.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 2dd2926b41..b738d16a40 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1209,6 +1209,10 @@ static int __init write_properties(struct domain *d, struct kernel_info *kinfo, continue; } + /* Dom0 is currently NUMA unaware */ + if ( dt_property_name_is_equal(prop, "numa-node-id") ) + continue; + res = fdt_property(kinfo->fdt, prop->name, prop_data, prop_len); if ( res ) @@ -2322,6 +2326,8 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo, DT_MATCH_TYPE("memory"), /* The memory mapped timer is not supported by Xen. */ DT_MATCH_COMPATIBLE("arm,armv7-timer-mem"), + /* Numa info doesn't need to be exposed to Domain-0 */ + DT_MATCH_COMPATIBLE("numa-distance-map-v1"), { /* sentinel */ }, }; static const struct dt_device_match timer_matches[] __initconst = From patchwork Mon Nov 20 02:54:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB652C5ACB3 for ; Mon, 20 Nov 2023 02:55:53 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636377.991839 (Exim 4.92) (envelope-from ) id 1r4uRu-0004B5-RL; Mon, 20 Nov 2023 02:55:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636377.991839; Mon, 20 Nov 2023 02:55:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRu-0004AM-Lf; Mon, 20 Nov 2023 02:55:46 +0000 Received: by outflank-mailman (input) for mailman id 636377; Mon, 20 Nov 2023 02:55:45 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRi-0007WE-Tl for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:34 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 457dd832-8750-11ee-9b0e-b553b5be7939; Mon, 20 Nov 2023 03:55:33 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8A6551042; Sun, 19 Nov 2023 18:56:18 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E45863F6C4; Sun, 19 Nov 2023 18:55:29 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 457dd832-8750-11ee-9b0e-b553b5be7939 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 12/17] xen/arm: enable device tree based NUMA in system init Date: Mon, 20 Nov 2023 10:54:26 +0800 Message-Id: <20231120025431.14845-13-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen In this patch, we can start to create NUMA system that is based on device tree. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v5 -> v6: - Rebase on top of staging without code changes. v1 -> v5: - Fix coding style: label indented by 1 space. - replace ~0 by INVALID_PADDR. - only print error messages for invalid dtb data. - remove unnecessary return. - remove the parameter of numa_init. --- xen/arch/arm/include/asm/numa.h | 5 +++ xen/arch/arm/numa.c | 57 +++++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 7 ++++ 3 files changed, 69 insertions(+) diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h index 15308f5a36..55ac4665db 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -45,6 +45,7 @@ extern void numa_set_distance(nodeid_t from, nodeid_t to, unsigned int distance); extern void numa_detect_cpu_node(unsigned int cpu); extern int numa_device_tree_init(const void *fdt); +extern void numa_init(void); #else @@ -90,6 +91,10 @@ static inline void numa_detect_cpu_node(unsigned int cpu) { } +static inline void numa_init(void) +{ +} + #endif #define arch_want_default_dmazone() (false) diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c index 08e15ebbb0..13a167fc4f 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -18,7 +18,11 @@ * */ #include +#include +#include #include +#include +#include enum dt_numa_status __ro_after_init device_tree_numa = DT_NUMA_DEFAULT; @@ -104,6 +108,59 @@ unsigned char __node_distance(nodeid_t from, nodeid_t to) return node_distance_map[from][to]; } +void __init numa_init(void) +{ + unsigned int idx; + paddr_t ram_start = INVALID_PADDR; + paddr_t ram_size = 0; + paddr_t ram_end = 0; + + /* NUMA has been turned off through Xen parameters */ + if ( numa_off ) + goto mem_init; + + /* Initialize NUMA from device tree when system is not ACPI booted */ + if ( acpi_disabled ) + { + int ret = numa_device_tree_init(device_tree_flattened); + if ( ret ) + { + numa_off = true; + if ( ret == -EINVAL ) + printk(XENLOG_WARNING + "Init NUMA from device tree failed, ret=%d\n", ret); + } + } + else + { + /* We don't support NUMA for ACPI boot currently */ + printk(XENLOG_WARNING + "ACPI NUMA has not been supported yet, NUMA off!\n"); + numa_off = true; + } + + mem_init: + /* + * Find the minimal and maximum address of RAM, NUMA will + * build a memory to node mapping table for the whole range. + */ + ram_start = bootinfo.mem.bank[0].start; + ram_size = bootinfo.mem.bank[0].size; + ram_end = ram_start + ram_size; + for ( idx = 1 ; idx < bootinfo.mem.nr_banks; idx++ ) + { + paddr_t bank_start = bootinfo.mem.bank[idx].start; + paddr_t bank_size = bootinfo.mem.bank[idx].size; + paddr_t bank_end = bank_start + bank_size; + + ram_size = ram_size + bank_size; + ram_start = min(ram_start, bank_start); + ram_end = max(ram_end, bank_end); + } + + numa_initmem_init(PFN_UP(ram_start), PFN_DOWN(ram_end)); +} + int __init arch_get_ram_range(unsigned int idx, paddr_t *start, paddr_t *end) { if ( idx >= bootinfo.mem.nr_banks ) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 02bc887725..01affc12d9 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -1124,6 +1124,13 @@ void __init start_xen(unsigned long boot_phys_offset, /* Parse the ACPI tables for possible boot-time configuration */ acpi_boot_table_init(); + /* + * Try to initialize NUMA system, if failed, the system will + * fallback to uniform system which means system has only 1 + * NUMA node. + */ + numa_init(); + end_boot_allocator(); /* From patchwork Mon Nov 20 02:54:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A212EC5AD4C for ; Mon, 20 Nov 2023 02:56:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636378.991846 (Exim 4.92) (envelope-from ) id 1r4uRv-0004Fv-AF; Mon, 20 Nov 2023 02:55:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636378.991846; Mon, 20 Nov 2023 02:55:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRu-0004De-VA; Mon, 20 Nov 2023 02:55:46 +0000 Received: by outflank-mailman (input) for mailman id 636378; Mon, 20 Nov 2023 02:55:46 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRn-0007WE-I7 for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:39 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 47d0901d-8750-11ee-9b0e-b553b5be7939; Mon, 20 Nov 2023 03:55:36 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7B6381042; Sun, 19 Nov 2023 18:56:22 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CE3183F6C4; Sun, 19 Nov 2023 18:55:33 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 47d0901d-8750-11ee-9b0e-b553b5be7939 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 13/17] xen/arm: implement numa_node_to_arch_nid for device tree NUMA Date: Mon, 20 Nov 2023 10:54:27 +0800 Message-Id: <20231120025431.14845-14-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen Device tree based NUMA doesn't have the proximity domain like ACPI. So we can return node id directly as arch nid. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v5 -> v6: - Rebase on top of staging without code changes. v1 -> v5: - Use numa_node_to_arch_nid instead of dummy node_to_pxm. --- xen/arch/arm/include/asm/numa.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h index 55ac4665db..71b95a9a62 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -47,6 +47,15 @@ extern void numa_detect_cpu_node(unsigned int cpu); extern int numa_device_tree_init(const void *fdt); extern void numa_init(void); +/* + * Device tree NUMA doesn't have architecural node id. + * So we can just return node id as arch nid. + */ +static inline unsigned int numa_node_to_arch_nid(nodeid_t n) +{ + return n; +} + #else /* Fake one node for now. See also node_online_map. */ From patchwork Mon Nov 20 02:54:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460748 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CB6A0C5AD4C for ; Mon, 20 Nov 2023 02:55:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636379.991865 (Exim 4.92) (envelope-from ) id 1r4uRw-0004wV-Uq; Mon, 20 Nov 2023 02:55:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636379.991865; Mon, 20 Nov 2023 02:55:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRw-0004vJ-Ou; Mon, 20 Nov 2023 02:55:48 +0000 Received: by outflank-mailman (input) for mailman id 636379; Mon, 20 Nov 2023 02:55:46 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRq-0007WE-6A for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:42 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 49f8400a-8750-11ee-9b0e-b553b5be7939; Mon, 20 Nov 2023 03:55:40 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 16B701042; Sun, 19 Nov 2023 18:56:26 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 697E13F6C4; Sun, 19 Nov 2023 18:55:37 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 49f8400a-8750-11ee-9b0e-b553b5be7939 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 14/17] xen/arm: use CONFIG_NUMA to gate node_online_map in smpboot Date: Mon, 20 Nov 2023 10:54:28 +0800 Message-Id: <20231120025431.14845-15-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen node_online_map in smpboot is still needed for Arm when NUMA is turned off by Kconfig. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v6: - Rebase on top of staging without code changes. --- xen/arch/arm/smpboot.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 81574ae0ad..71f1717985 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -42,8 +42,10 @@ integer_param("maxcpus", max_cpus); /* CPU logical map: map xen cpuid to an MPIDR */ register_t __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = MPIDR_INVALID }; +#ifndef CONFIG_NUMA /* Fake one node for now. See also asm/numa.h */ nodemask_t __read_mostly node_online_map = { { [0] = 1UL } }; +#endif /* Xen stack for bringing up the first CPU. */ static unsigned char __initdata cpu0_boot_stack[STACK_SIZE] From patchwork Mon Nov 20 02:54:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460752 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E0FEBC5ACB3 for ; Mon, 20 Nov 2023 02:56:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636381.991871 (Exim 4.92) (envelope-from ) id 1r4uRx-00051a-Cw; Mon, 20 Nov 2023 02:55:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636381.991871; Mon, 20 Nov 2023 02:55:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRx-0004zs-4S; Mon, 20 Nov 2023 02:55:49 +0000 Received: by outflank-mailman (input) for mailman id 636381; Mon, 20 Nov 2023 02:55:46 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRs-00081B-NW for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:44 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 4bf700e6-8750-11ee-98df-6d05b1d4d9a1; Mon, 20 Nov 2023 03:55:43 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5D3131042; Sun, 19 Nov 2023 18:56:29 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 03E6D3F6C4; Sun, 19 Nov 2023 18:55:40 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4bf700e6-8750-11ee-98df-6d05b1d4d9a1 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Henry Wang , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v6 15/17] xen/arm: Set correct per-cpu cpu_core_mask Date: Mon, 20 Nov 2023 10:54:29 +0800 Message-Id: <20231120025431.14845-16-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 In the common sysctl command XEN_SYSCTL_physinfo, the cores_per_socket is calculated based on the cpu_core_mask of CPU0. Currently on Arm this is a fixed value 1 (can be checked via xl info), which is not correct. This is because during the Arm cpu online process, set_cpu_sibling_map() only sets the per-cpu cpu_core_mask for itself. cores_per_socket refers to the number of cores that belong to the same socket (NUMA node). Therefore, this commit introduces a helper function numa_set_cpu_core_mask(cpu), which sets the per-cpu cpu_core_mask to the cpus in the same NUMA node as cpu. Calling this function at the boot time can ensure the correct cpu_core_mask, leading to the correct cores_per_socket to be returned by XEN_SYSCTL_physinfo. Signed-off-by: Henry Wang --- v6: - Rebase on top of staging without code changes. --- xen/arch/arm/include/asm/numa.h | 7 +++++++ xen/arch/arm/numa.c | 11 +++++++++++ xen/arch/arm/setup.c | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h index 71b95a9a62..d4c89909d0 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -46,6 +46,7 @@ extern void numa_set_distance(nodeid_t from, nodeid_t to, extern void numa_detect_cpu_node(unsigned int cpu); extern int numa_device_tree_init(const void *fdt); extern void numa_init(void); +extern void numa_set_cpu_core_mask(int cpu); /* * Device tree NUMA doesn't have architecural node id. @@ -62,6 +63,12 @@ static inline unsigned int numa_node_to_arch_nid(nodeid_t n) #define cpu_to_node(cpu) 0 #define node_to_cpumask(node) (cpu_online_map) +static inline void numa_set_cpu_core_mask(int cpu) +{ + cpumask_or(per_cpu(cpu_core_mask, cpu), + per_cpu(cpu_core_mask, cpu), &cpu_possible_map); +} + /* * TODO: make first_valid_mfn static when NUMA is supported on Arm, this * is required because the dummy helpers are using it. diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c index 13a167fc4f..1ac2df37fc 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -52,6 +52,17 @@ int __init arch_numa_setup(const char *opt) return -EINVAL; } +void numa_set_cpu_core_mask(int cpu) +{ + nodeid_t node = cpu_to_node[cpu]; + + if ( node == NUMA_NO_NODE ) + node = 0; + + cpumask_or(per_cpu(cpu_core_mask, cpu), + per_cpu(cpu_core_mask, cpu), &node_to_cpumask(node)); +} + void __init numa_set_distance(nodeid_t from, nodeid_t to, unsigned int distance) { diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 01affc12d9..af8631b6e5 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -1229,6 +1229,11 @@ void __init start_xen(unsigned long boot_phys_offset, } printk("Brought up %ld CPUs\n", (long)num_online_cpus()); + + /* Set per-cpu cpu_core_mask to cpus that belongs to the same NUMA node. */ + for_each_online_cpu ( i ) + numa_set_cpu_core_mask(i); + /* TODO: smp_cpus_done(); */ /* This should be done in a vpmu driver but we do not have one yet. */ From patchwork Mon Nov 20 02:54:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460757 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C2370C072A2 for ; Mon, 20 Nov 2023 03:06:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636411.991894 (Exim 4.92) (envelope-from ) id 1r4ubb-0001Gi-GS; Mon, 20 Nov 2023 03:05:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636411.991894; Mon, 20 Nov 2023 03:05:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4ubb-0001Gb-DU; Mon, 20 Nov 2023 03:05:47 +0000 Received: by outflank-mailman (input) for mailman id 636411; Mon, 20 Nov 2023 03:05:46 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRx-0007WE-5g for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:49 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 4e1f4068-8750-11ee-9b0e-b553b5be7939; Mon, 20 Nov 2023 03:55:47 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 02B0B1042; Sun, 19 Nov 2023 18:56:33 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5DB443F6C4; Sun, 19 Nov 2023 18:55:44 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4e1f4068-8750-11ee-9b0e-b553b5be7939 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 16/17] xen/arm: Provide Kconfig options for Arm to enable NUMA Date: Mon, 20 Nov 2023 10:54:30 +0800 Message-Id: <20231120025431.14845-17-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen Arm platforms support both ACPI and device tree. We don't want users to select device tree NUMA or ACPI NUMA manually. We hope users can just enable NUMA for Arm, and device tree NUMA and ACPI NUMA can be selected depends on device tree feature and ACPI feature status automatically. In this case, these two kinds of NUMA support code can be co-exist in one Xen binary. Xen can check feature flags to decide using device tree or ACPI as NUMA based firmware. So in this patch, we introduce a generic option: CONFIG_ARM_NUMA for users to enable NUMA for Arm. And one CONFIG_DEVICE_TREE_NUMA option for ARM_NUMA to select when HAS_DEVICE_TREE option is enabled. Once when ACPI NUMA for Arm is supported, ACPI_NUMA can be selected here too. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v5 -> v6: - Rebase on top of staging without code changes. v1 -> v5: - Remove the condition of selecting DEVICE_TREE_NUMA. --- xen/arch/arm/Kconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 2939db429b..5ce6b20cf2 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -80,6 +80,17 @@ config ARM_EFI UEFI firmware. A UEFI stub is provided to allow Xen to be booted as an EFI application. +config ARM_NUMA + bool "Arm NUMA (Non-Uniform Memory Access) Support (UNSUPPORTED)" if UNSUPPORTED + depends on HAS_DEVICE_TREE + select DEVICE_TREE_NUMA + help + Enable Non-Uniform Memory Access (NUMA) for Arm architecutres + +config DEVICE_TREE_NUMA + bool + select NUMA + config GICV3 bool "GICv3 driver" depends on !NEW_VGIC From patchwork Mon Nov 20 02:54:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13460756 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14072C072A2 for ; Mon, 20 Nov 2023 03:05:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636418.991904 (Exim 4.92) (envelope-from ) id 1r4ubc-0001Vz-OI; Mon, 20 Nov 2023 03:05:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636418.991904; Mon, 20 Nov 2023 03:05:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4ubc-0001Vs-LZ; Mon, 20 Nov 2023 03:05:48 +0000 Received: by outflank-mailman (input) for mailman id 636418; Mon, 20 Nov 2023 03:05:47 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uS0-00081B-Br for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:52 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 50a606d5-8750-11ee-98df-6d05b1d4d9a1; Mon, 20 Nov 2023 03:55:51 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 350C11042; Sun, 19 Nov 2023 18:56:37 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 124773F6C4; Sun, 19 Nov 2023 18:55:47 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 50a606d5-8750-11ee-98df-6d05b1d4d9a1 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Henry Wang , Community Manager , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v6 17/17] docs: update numa command line to support Arm Date: Mon, 20 Nov 2023 10:54:31 +0800 Message-Id: <20231120025431.14845-18-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 From: Wei Chen Current numa command in documentation is x86 only. Remove x86 from numa command's arch limitation in this patch. Also add related entries in the SUPPORT.md and CHANGELOG.md. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v6: - Add the CHANGELOG.md entry, drop Jan's Acked-by tag because of this. --- CHANGELOG.md | 1 + SUPPORT.md | 1 + docs/misc/xen-command-line.pandoc | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c341c9d0bf..0467e2cca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - On x86: - Introduce a new x2APIC driver that uses Cluster Logical addressing mode for IPIs and Physical addressing mode for external interrupts. + - On Arm, NUMA aware scheduling in Xen is supported (Tech Preview). ### Removed diff --git a/SUPPORT.md b/SUPPORT.md index fff4b4c5ba..b4f6fb5eb2 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -425,6 +425,7 @@ on embedded platforms and the x86 PV shim. Enables NUMA aware scheduling in Xen Status, x86: Supported + Status, Arm: Tech Preview ## Scalability diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 8e65f8bd18..2c15bdd9ea 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1944,7 +1944,7 @@ This option is ignored in **pv-shim** mode. ### nr_irqs (x86) > `= ` -### numa (x86) +### numa > `= on | off | fake= | noacpi` > Default: `on`