From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681989976286627.9494855351033; Thu, 20 Apr 2023 04:26:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524032.814578 (Exim 4.92) (envelope-from ) id 1ppSQ2-0006X0-SI; Thu, 20 Apr 2023 11:25:42 +0000 Received: by outflank-mailman (output) from mailman id 524032.814578; Thu, 20 Apr 2023 11:25:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSQ2-0006Wt-O8; Thu, 20 Apr 2023 11:25:42 +0000 Received: by outflank-mailman (input) for mailman id 524032; Thu, 20 Apr 2023 11:25:41 +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 1ppSQ1-0006Vv-6M for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:25:41 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 14432ac5-df6e-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:25:40 +0200 (CEST) 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 339771516; Thu, 20 Apr 2023 04:26:23 -0700 (PDT) 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 D9E013F587; Thu, 20 Apr 2023 04:25:35 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 14432ac5-df6e-11ed-b21f-6b7b168915f2 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Henry Wang Subject: [PATCH v3 01/17] xen/arm: use NR_MEM_BANKS to override default NR_NODE_MEMBLKS Date: Thu, 20 Apr 2023 19:25:05 +0800 Message-Id: <20230420112521.3272732-2-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681989977770100001 Content-Type: text/plain; charset="utf-8" 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 avoid to have 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.h= tml Signed-off-by: Wei Chen Signed-off-by: Henry Wang Acked-by: Jan Beulich --- By checking the discussion in [1] and [2] [1] https://lists.xenproject.org/archives/html/xen-devel/2023-01/msg00595.h= tml [2] https://lists.xenproject.org/archives/html/xen-devel/2021-09/msg02322.h= tml v2 -> v3: 1. No change v1 -> v2: 1. Add code comments to explain using NR_MEM_BANKS for Arm 2. Refine commit messages. --- 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/num= a.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 @@ =20 #include =20 +#include + typedef u8 nodeid_t; =20 -#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.h= tml + */ +#define NR_NODE_MEMBLKS NR_MEM_BANKS + +#else =20 /* 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 29b8c2df89..b86d0851fc 100644 --- a/xen/include/xen/numa.h +++ b/xen/include/xen/numa.h @@ -13,7 +13,16 @@ #define MAX_NUMNODES 1 #endif =20 +/* + * 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 =20 #define vcpu_to_node(v) (cpu_to_node((v)->processor)) =20 --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681989976989419.4838387497339; Thu, 20 Apr 2023 04:26:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524033.814588 (Exim 4.92) (envelope-from ) id 1ppSQ7-0006px-8g; Thu, 20 Apr 2023 11:25:47 +0000 Received: by outflank-mailman (output) from mailman id 524033.814588; Thu, 20 Apr 2023 11:25: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 1ppSQ7-0006pq-5V; Thu, 20 Apr 2023 11:25:47 +0000 Received: by outflank-mailman (input) for mailman id 524033; Thu, 20 Apr 2023 11:25: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 1ppSQ5-0006Vv-M4 for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:25:45 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 17195841-df6e-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:25:44 +0200 (CEST) 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 0CAE21480; Thu, 20 Apr 2023 04:26:28 -0700 (PDT) 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 846CA3F587; Thu, 20 Apr 2023 04:25:41 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 17195841-df6e-11ed-b21f-6b7b168915f2 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Jan Beulich , Henry Wang Subject: [PATCH v3 02/17] xen/arm: implement helpers to get and update NUMA status Date: Thu, 20 Apr 2023 19:25:06 +0800 Message-Id: <20230420112521.3272732-3-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681989978798100005 Content-Type: text/plain; charset="utf-8" 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 --- v2 -> v3: 1. Rename the first entry of enum dt_numa_status as DT_NUMA_DEFAULT. 2. Make enum dt_numa_status device_tree_numa as __ro_after_init and assign it explicitly to DT_NUMA_DEFAULT. 3. Update the year in copyright to 2023. 4. Don't move the x86 numa_disabled() and make Arm's numa_disabled() a static inline function for !CONFIG_NUMA. v1 -> v2: 1. Use arch_numa_disabled to replace numa_enable_with_firmware. 2. Introduce enumerations for device tree numa status. 3. Use common numa_disabled, drop Arm version numa_disabled. 4. Introduce arch_numa_setup for Arm. 5. Rename bad_srat to numa_bad. 6. Add numa_enable_with_firmware helper. 7. Add numa_disabled helper. 8. 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/num= a.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 =20 +extern bool numa_disabled(void); + #else =20 /* 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) =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 =20 #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 =3D DT_NUMA_DE= FAULT; + +void __init numa_fw_bad(void) +{ + printk(KERN_ERR "NUMA: device tree numa info table not used.\n"); + device_tree_numa =3D DT_NUMA_OFF; +} + +bool __init arch_numa_unavailable(void) +{ + return device_tree_numa !=3D DT_NUMA_ON; +} + +bool arch_numa_disabled(void) +{ + return device_tree_numa =3D=3D DT_NUMA_OFF; +} + +int __init arch_numa_setup(const char *opt) +{ + return -EINVAL; +} --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 168198998516026.349146060002113; Thu, 20 Apr 2023 04:26:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524034.814598 (Exim 4.92) (envelope-from ) id 1ppSQC-0007B7-GK; Thu, 20 Apr 2023 11:25:52 +0000 Received: by outflank-mailman (output) from mailman id 524034.814598; Thu, 20 Apr 2023 11:25:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSQC-0007AV-Cb; Thu, 20 Apr 2023 11:25:52 +0000 Received: by outflank-mailman (input) for mailman id 524034; Thu, 20 Apr 2023 11:25: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 1ppSQB-0006Vv-20 for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:25:51 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 1a488df7-df6e-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:25:50 +0200 (CEST) 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 3F8CE1516; Thu, 20 Apr 2023 04:26:33 -0700 (PDT) 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 A49843F587; Thu, 20 Apr 2023 04:25:45 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 1a488df7-df6e-11ed-b21f-6b7b168915f2 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Henry Wang Subject: [PATCH v3 03/17] xen/arm: implement node distance helpers for Arm Date: Thu, 20 Apr 2023 19:25:07 +0800 Message-Id: <20230420112521.3272732-4-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681989985973100003 Content-Type: text/plain; charset="utf-8" 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 definition 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 --- v2 -> v3: 1. Use __ro_after_init for node_distance_map. 2. Correct format of if condition identation in numa_set_distance(). 3. Drop the unnecessary change to the year of copyright. 4. Use ARRAY_SIZE() to determine node_distance_map's row, column size. v1 -> v2: 1. Use unsigned int/char instead of uint32_t/u8. 2. Re-org the commit message. --- xen/arch/arm/Makefile | 1 + xen/arch/arm/include/asm/numa.h | 13 +++++++++ xen/arch/arm/numa.c | 52 +++++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/numa.h | 1 - xen/arch/x86/srat.c | 2 +- xen/include/xen/numa.h | 1 + 6 files changed, 68 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 4d076b278b..9073398d6e 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_LIVEPATCH) +=3D livepatch.o obj-y +=3D mem_access.o obj-y +=3D mm.o obj-y +=3D monitor.o +obj-$(CONFIG_NUMA) +=3D numa.o obj-y +=3D p2m.o obj-y +=3D percpu.o obj-y +=3D platform.o diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/num= a.h index 83f60ad05b..123a1a8dd0 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -22,7 +22,20 @@ typedef u8 nodeid_t; */ #define NR_NODE_MEMBLKS NR_MEM_BANKS =20 +/* + * 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_MIN 0 +#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); =20 #else =20 diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c index eb5d0632cb..c5ef81aad3 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -28,6 +28,11 @@ enum dt_numa_status { =20 static enum dt_numa_status __ro_after_init device_tree_numa =3D DT_NUMA_DE= FAULT; =20 +static unsigned char __ro_after_init +node_distance_map[MAX_NUMNODES][MAX_NUMNODES] =3D { + { 0 } +}; + void __init numa_fw_bad(void) { printk(KERN_ERR "NUMA: device tree numa info table not used.\n"); @@ -48,3 +53,50 @@ int __init arch_numa_setup(const char *opt) { return -EINVAL; } + +void __init numa_set_distance(nodeid_t from, nodeid_t to, + unsigned int distance) +{ + if ( from >=3D ARRAY_SIZE(node_distance_map) || + to >=3D ARRAY_SIZE(node_distance_map[0]) ) + { + printk(KERN_WARNING + "NUMA: invalid nodes: from=3D%"PRIu8" to=3D%"PRIu8" MAX=3D%= "PRIu8"\n", + from, to, MAX_NUMNODES); + return; + } + + /* NUMA defines 0xff as an unreachable node and 0-9 are undefined */ + if ( distance >=3D NUMA_NO_DISTANCE || + (distance >=3D NUMA_DISTANCE_UDF_MIN && + distance <=3D NUMA_DISTANCE_UDF_MAX) || + (from =3D=3D to && distance !=3D NUMA_LOCAL_DISTANCE) ) + { + printk(KERN_WARNING + "NUMA: invalid distance: from=3D%"PRIu8" to=3D%"PRIu8" dist= ance=3D%"PRIu32"\n", + from, to, distance); + return; + } + + node_distance_map[from][to] =3D distance; +} + +unsigned char __node_distance(nodeid_t from, nodeid_t to) +{ + /* When NUMA is off, any distance will be treated as remote. */ + if ( numa_disabled() ) + return NUMA_REMOTE_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, we treat them as unreachable (return 0xFF) + */ + if ( from >=3D ARRAY_SIZE(node_distance_map) || + to >=3D ARRAY_SIZE(node_distance_map[0]) ) + return from =3D=3D to ? NUMA_LOCAL_DISTANCE : NUMA_NO_DISTANCE; + + return node_distance_map[from][to]; +} + +EXPORT_SYMBOL(__node_distance); diff --git a/xen/arch/x86/include/asm/numa.h b/xen/arch/x86/include/asm/num= a.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) =20 void srat_parse_regions(paddr_t addr); -extern u8 __node_distance(nodeid_t a, nodeid_t b); unsigned int arch_get_dma_bitsize(void); =20 #endif diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c index 56749ddca5..50faf5d352 100644 --- a/xen/arch/x86/srat.c +++ b/xen/arch/x86/srat.c @@ -328,7 +328,7 @@ unsigned int numa_node_to_arch_nid(nodeid_t n) return 0; } =20 -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 b86d0851fc..8356e47b61 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 hot= plug); extern void numa_set_processor_nodes_parsed(nodeid_t node); +extern unsigned char __node_distance(nodeid_t a, nodeid_t b); =20 #else =20 --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681989983008895.198358419138; Thu, 20 Apr 2023 04:26:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524035.814608 (Exim 4.92) (envelope-from ) id 1ppSQF-0007dT-PQ; Thu, 20 Apr 2023 11:25:55 +0000 Received: by outflank-mailman (output) from mailman id 524035.814608; Thu, 20 Apr 2023 11:25:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSQF-0007dI-Kf; Thu, 20 Apr 2023 11:25:55 +0000 Received: by outflank-mailman (input) for mailman id 524035; Thu, 20 Apr 2023 11:25:54 +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 1ppSQE-0006Vv-91 for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:25:54 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 1c6c5186-df6e-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:25:53 +0200 (CEST) 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 E60761480; Thu, 20 Apr 2023 04:26:36 -0700 (PDT) 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 A30503F587; Thu, 20 Apr 2023 04:25:50 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 1c6c5186-df6e-11ed-b21f-6b7b168915f2 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 04/17] xen/arm: use arch_get_ram_range to memory ranges from bootinfo Date: Thu, 20 Apr 2023 19:25:08 +0800 Message-Id: <20230420112521.3272732-5-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681989985051100001 Content-Type: text/plain; charset="utf-8" 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 -> v3: 1. No change. v1 -> v2: 1. 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 c5ef81aad3..a0e7b14925 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -100,3 +100,14 @@ unsigned char __node_distance(nodeid_t from, nodeid_t = to) } =20 EXPORT_SYMBOL(__node_distance); + +int __init arch_get_ram_range(unsigned int idx, paddr_t *start, paddr_t *e= nd) +{ + if ( idx >=3D bootinfo.mem.nr_banks ) + return -ENOENT; + + *start =3D bootinfo.mem.bank[idx].start; + *end =3D *start + bootinfo.mem.bank[idx].size; + + return 0; +} --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681989988624673.2037474500453; Thu, 20 Apr 2023 04:26:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524041.814618 (Exim 4.92) (envelope-from ) id 1ppSQK-00083y-1w; Thu, 20 Apr 2023 11:26:00 +0000 Received: by outflank-mailman (output) from mailman id 524041.814618; Thu, 20 Apr 2023 11:26:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSQJ-00083X-Ub; Thu, 20 Apr 2023 11:25:59 +0000 Received: by outflank-mailman (input) for mailman id 524041; Thu, 20 Apr 2023 11:25:58 +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 1ppSQI-0006Vv-5P for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:25:58 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 1e98d4a4-df6e-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:25:57 +0200 (CEST) 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 924971480; Thu, 20 Apr 2023 04:26:40 -0700 (PDT) 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 57DFA3F587; Thu, 20 Apr 2023 04:25:54 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 1e98d4a4-df6e-11ed-b21f-6b7b168915f2 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 05/17] xen/arm: build NUMA cpu_to_node map in dt_smp_init_cpus Date: Thu, 20 Apr 2023 19:25:09 +0800 Message-Id: <20230420112521.3272732-6-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681989988947100001 Content-Type: text/plain; charset="utf-8" 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 -> v3: 1. No change. v1 -> v2: 1. Use static inline to replace macros to perform function paramerters type check. 2. Add numa_disabled to gate the numa-node-id check for CONFIG_NUMA on but numa disabled user case. 3. 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/num= a.h index 123a1a8dd0..e7a7d4e835 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -69,6 +69,10 @@ static inline bool arch_numa_broken(void) return true; } =20 +static inline void numa_set_node(unsigned int cpu, nodeid_t node) +{ +} + #endif =20 #define arch_want_default_dmazone() (false) diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 4a89b3a834..da7f2afd97 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -118,7 +118,12 @@ static void __init dt_smp_init_cpus(void) { [0 ... NR_CPUS - 1] =3D MPIDR_INVALID }; + static nodeid_t node_map[NR_CPUS] __initdata =3D + { + [0 ... NR_CPUS - 1] =3D NUMA_NO_NODE + }; bool bootcpu_valid =3D false; + unsigned int nid =3D 0; int rc; =20 mpidr =3D system_cpuinfo.mpidr.bits & MPIDR_HWID_MASK; @@ -169,6 +174,28 @@ static void __init dt_smp_init_cpus(void) continue; } =20 + 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 informatio= n!\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 F= AKE + * node 0. So if we get numa-node-id failed here, we should + * set nid to 0. + */ + nid =3D 0; + } + } + /* * 8 MSBs must be set to 0 in the DT since the reg property * defines the MPIDR[23:0] @@ -228,9 +255,13 @@ static void __init dt_smp_init_cpus(void) { printk("cpu%d init failed (hwid %"PRIregister"): %d\n", i, hwi= d, rc); tmp_map[i] =3D MPIDR_INVALID; + node_map[i] =3D NUMA_NO_NODE; } else + { tmp_map[i] =3D hwid; + node_map[i] =3D nid; + } } =20 if ( !bootcpu_valid ) @@ -246,6 +277,11 @@ static void __init dt_smp_init_cpus(void) continue; cpumask_set_cpu(i, &cpu_possible_map); cpu_logical_map(i) =3D tmp_map[i]; + + nid =3D node_map[i]; + if ( nid >=3D MAX_NUMNODES ) + nid =3D 0; + numa_set_node(i, nid); } } =20 --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681989993912737.3006309952924; Thu, 20 Apr 2023 04:26:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524047.814628 (Exim 4.92) (envelope-from ) id 1ppSQO-0000A7-BL; Thu, 20 Apr 2023 11:26:04 +0000 Received: by outflank-mailman (output) from mailman id 524047.814628; Thu, 20 Apr 2023 11:26:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSQO-00009s-7J; Thu, 20 Apr 2023 11:26:04 +0000 Received: by outflank-mailman (input) for mailman id 524047; Thu, 20 Apr 2023 11:26:02 +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 1ppSQM-0006GU-OY for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:02 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 20cf2ecc-df6e-11ed-8611-37d641c3527e; Thu, 20 Apr 2023 13:26:01 +0200 (CEST) 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 3FA141480; Thu, 20 Apr 2023 04:26:44 -0700 (PDT) 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 056CD3F587; Thu, 20 Apr 2023 04:25:57 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 20cf2ecc-df6e-11ed-8611-37d641c3527e From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 06/17] xen/arm: Add boot and secondary CPU to NUMA system Date: Thu, 20 Apr 2023 19:25:10 +0800 Message-Id: <20230420112521.3272732-7-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681989994249100001 Content-Type: text/plain; charset="utf-8" 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 -> v3: 1. No change. v1 -> v2: 1. Use unsigned int instead of int for cpu id. 2. 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/num= a.h index e7a7d4e835..2f3d7079d9 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -36,6 +36,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); =20 #else =20 @@ -73,6 +74,14 @@ static inline void numa_set_node(unsigned int cpu, nodei= d_t node) { } =20 +static inline void numa_add_cpu(unsigned int cpu) +{ +} + +static inline void numa_detect_cpu_node(unsigned int cpu) +{ +} + #endif =20 #define arch_want_default_dmazone() (false) diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c index a0e7b14925..05a339b044 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -81,6 +81,16 @@ void __init numa_set_distance(nodeid_t from, nodeid_t to, node_distance_map[from][to] =3D distance; } =20 +void numa_detect_cpu_node(unsigned int cpu) +{ + nodeid_t node =3D cpu_to_node[cpu]; + + if ( node =3D=3D NUMA_NO_NODE ) + node =3D 0; + + node_set_online(node); +} + unsigned char __node_distance(nodeid_t from, nodeid_t to) { /* When NUMA is off, any distance will be treated as remote. */ diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 6f9f4d8c8a..09e18d32df 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -1205,6 +1205,11 @@ void __init start_xen(unsigned long boot_phys_offset, =20 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 =3D cpu_up(i); --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681990171334178.91070994558845; Thu, 20 Apr 2023 04:29:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524087.814724 (Exim 4.92) (envelope-from ) id 1ppSTQ-0005Hw-3t; Thu, 20 Apr 2023 11:29:12 +0000 Received: by outflank-mailman (output) from mailman id 524087.814724; Thu, 20 Apr 2023 11:29:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSTP-0005GY-Ur; Thu, 20 Apr 2023 11:29:11 +0000 Received: by outflank-mailman (input) for mailman id 524087; Thu, 20 Apr 2023 11:29:10 +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 1ppSQP-0006Vv-IF for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:05 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 22ef9f1a-df6e-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:26:04 +0200 (CEST) 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 C0B9B1480; Thu, 20 Apr 2023 04:26:47 -0700 (PDT) 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 867A73F587; Thu, 20 Apr 2023 04:26:01 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 22ef9f1a-df6e-11ed-b21f-6b7b168915f2 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 07/17] xen/arm: introduce a helper to parse device tree processor node Date: Thu, 20 Apr 2023 19:25:11 +0800 Message-Id: <20230420112521.3272732-8-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681990172081100013 Content-Type: text/plain; charset="utf-8" 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 --- v2 -> v3: 1. Move the enum dt_numa_status to the Arm NUMA header. 2. Update the year in copyright to 2023. v1 -> v2: 1. Move numa_disabled from fdt_numa_processor_affinity_init to fdt_parse_numa_cpu_node. 2. Move invalid NUMA id check to fdt_parse_numa_cpu_node. 3. Return ENODATA for normal dtb without NUMA info. 4. 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.c | 8 +---- xen/arch/arm/numa_device_tree.c | 64 +++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 xen/arch/arm/numa_device_tree.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 9073398d6e..bbc68e3735 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -39,6 +39,7 @@ obj-y +=3D mem_access.o obj-y +=3D mm.o obj-y +=3D monitor.o obj-$(CONFIG_NUMA) +=3D numa.o +obj-$(CONFIG_DEVICE_TREE_NUMA) +=3D numa_device_tree.o obj-y +=3D p2m.o obj-y +=3D percpu.o obj-y +=3D platform.o diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/num= a.h index 2f3d7079d9..fe1bf4251f 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 =20 +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.c b/xen/arch/arm/numa.c index 05a339b044..06e067712d 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -20,13 +20,7 @@ #include #include =20 -enum dt_numa_status { - DT_NUMA_DEFAULT, - DT_NUMA_ON, - DT_NUMA_OFF, -}; - -static enum dt_numa_status __ro_after_init device_tree_numa =3D DT_NUMA_DE= FAULT; +enum dt_numa_status __ro_after_init device_tree_numa =3D DT_NUMA_DEFAULT; =20 static unsigned char __ro_after_init node_distance_map[MAX_NUMNODES][MAX_NUMNODES] =3D { diff --git a/xen/arch/arm/numa_device_tree.c b/xen/arch/arm/numa_device_tre= e.c new file mode 100644 index 0000000000..52051e4537 --- /dev/null +++ b/xen/arch/arm/numa_device_tree.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 =3D 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 =3D device_tree_get_u32(fdt, node, "numa-node-id", NUMA_NO_NODE); + if ( nid =3D=3D NUMA_NO_NODE ) + { + numa_fw_bad(); + return -ENODATA; + } + else if ( nid >=3D 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); +} --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681989998560515.6988789643497; Thu, 20 Apr 2023 04:26:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524052.814638 (Exim 4.92) (envelope-from ) id 1ppSQV-0000r6-MR; Thu, 20 Apr 2023 11:26:11 +0000 Received: by outflank-mailman (output) from mailman id 524052.814638; Thu, 20 Apr 2023 11:26:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSQV-0000qy-J0; Thu, 20 Apr 2023 11:26:11 +0000 Received: by outflank-mailman (input) for mailman id 524052; Thu, 20 Apr 2023 11:26:10 +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 1ppSQU-0006GU-BS for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:10 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 2527de5a-df6e-11ed-8611-37d641c3527e; Thu, 20 Apr 2023 13:26:08 +0200 (CEST) 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 7B6B21480; Thu, 20 Apr 2023 04:26:51 -0700 (PDT) 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 412E33F587; Thu, 20 Apr 2023 04:26:04 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 2527de5a-df6e-11ed-8611-37d641c3527e From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 08/17] xen/arm: introduce a helper to parse device tree memory node Date: Thu, 20 Apr 2023 19:25:12 +0800 Message-Id: <20230420112521.3272732-9-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681989999009100001 Content-Type: text/plain; charset="utf-8" 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 --- v2 -> v3: 1. No change. v1 -> v2: 1. Move numa_disabled check to fdt_parse_numa_memory_node. 2. Use numa_bad to replace bad_srat. 3. Replace tabs by spaces. 4. Align parameters. 5. return ENODATA for a normal dtb without numa info. 6. Un-addressed comment: "Why not parse numa-node-id and call fdt_numa_memory_affinity_init from xen/arch/arm/bootfdt.c:device_tree_get_meminfo. Is it because device_tree_get_meminfo is called too early?" I checked the device_tree_get_meminfo code and I think the answer is similar as I reply in RFC. I prefer a unify numa initialization entry. Don't want to make numa parse code in different places. 7. Use node id as dummy PXM for numa_update_node_memblks. --- xen/arch/arm/numa_device_tree.c | 89 +++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/xen/arch/arm/numa_device_tree.c b/xen/arch/arm/numa_device_tre= e.c index 52051e4537..9796490747 100644 --- a/xen/arch/arm/numa_device_tree.c +++ b/xen/arch/arm/numa_device_tree.c @@ -34,6 +34,26 @@ static int __init fdt_numa_processor_affinity_init(nodei= d_t node) return 0; } =20 +/* Callback for parsing of the memory regions affinity */ +static int __init fdt_numa_memory_affinity_init(nodeid_t node, + paddr_t start, paddr_t siz= e) +{ + if ( !numa_memblks_available() ) + { + dprintk(XENLOG_WARNING, + "Too many numa entry, try bigger NR_NODE_MEMBLKS\n"); + return -EINVAL; + } + + numa_fw_nid_name =3D "numa-node-id"; + if ( !numa_update_node_memblks(node, node, start, size, false) ) + return -EINVAL; + + device_tree_numa =3D 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 *fd= t, int node) =20 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 =3D 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 =3D device_tree_get_u32(fdt, node, "numa-node-id", NUMA_NO_NODE); + if ( node =3D=3D NUMA_NO_NODE ) + { + numa_fw_bad(); + return -ENODATA; + } + else if ( nid >=3D MAX_NUMNODES ) + { + printk(XENLOG_WARNING "Node id %u exceeds maximum value\n", nid); + goto invalid_data; + } + + prop =3D fdt_get_property(fdt, node, "reg", &len); + if ( !prop ) + { + printk(XENLOG_WARNING + "fdt: node `%s': missing `reg' property\n", name); + goto invalid_data; + } + + addresses =3D (const __be32 *)prop->data; + ranges =3D len / (sizeof(__be32)* (addr_cells + size_cells)); + for ( idx =3D 0; idx < ranges; idx++ ) + { + device_tree_get_reg(&addresses, addr_cells, size_cells, &addr, &si= ze); + /* Skip zero size ranges */ + if ( !size ) + continue; + + ret =3D fdt_numa_memory_affinity_init(nid, addr, size); + if ( ret ) + goto invalid_data; + } + + if ( idx =3D=3D 0 ) + { + printk(XENLOG_ERR + "bad property in memory node, idx=3D%d ret=3D%d\n", idx, re= t); + goto invalid_data; + } + + return 0; + +invalid_data: + numa_fw_bad(); + return -EINVAL; +} --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681990003347112.09697710326941; Thu, 20 Apr 2023 04:26:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524055.814648 (Exim 4.92) (envelope-from ) id 1ppSQa-0001G8-4X; Thu, 20 Apr 2023 11:26:16 +0000 Received: by outflank-mailman (output) from mailman id 524055.814648; Thu, 20 Apr 2023 11:26:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSQa-0001Fz-0w; Thu, 20 Apr 2023 11:26:16 +0000 Received: by outflank-mailman (input) for mailman id 524055; Thu, 20 Apr 2023 11:26:14 +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 1ppSQY-0006GU-Cz for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:14 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 272e8d04-df6e-11ed-8611-37d641c3527e; Thu, 20 Apr 2023 13:26:11 +0200 (CEST) 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 0F2121480; Thu, 20 Apr 2023 04:26:55 -0700 (PDT) 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 C8EF03F587; Thu, 20 Apr 2023 04:26:08 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 272e8d04-df6e-11ed-8611-37d641c3527e From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map Date: Thu, 20 Apr 2023 19:25:13 +0800 Message-Id: <20230420112521.3272732-10-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681990005324100001 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v2 -> v3: 1. No change. v1 -> v2: 1. Get rid of useless braces. 2. Use new NUMA status helper. 3. Use PRIu32 to replace u in print messages. 4. Fix opposite =3D __node_distance(to, from). 5. disable dtb numa info table when we find an invalid data in dtb. --- xen/arch/arm/numa_device_tree.c | 107 ++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/xen/arch/arm/numa_device_tree.c b/xen/arch/arm/numa_device_tre= e.c index 9796490747..718afca826 100644 --- a/xen/arch/arm/numa_device_tree.c +++ b/xen/arch/arm/numa_device_tree.c @@ -151,3 +151,110 @@ invalid_data: 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 =3D 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) !=3D 0 ) + { + printk(XENLOG_WARNING + "distance-matrix in node is not a multiple of u32\n"); + goto invalid_data; + } + + entry_count =3D len / sizeof(__be32); + if ( entry_count =3D=3D 0 ) + { + printk(XENLOG_WARNING "NUMA: Invalid distance-matrix\n"); + goto invalid_data; + } + + matrix =3D (const __be32 *)prop->data; + for ( i =3D 0; i + 2 < entry_count; i +=3D 3 ) + { + unsigned int from, to, distance, opposite; + + from =3D dt_next_cell(1, &matrix); + to =3D dt_next_cell(1, &matrix); + distance =3D dt_next_cell(1, &matrix); + if ( (from =3D=3D to && distance !=3D NUMA_LOCAL_DISTANCE) || + (from !=3D to && distance <=3D NUMA_LOCAL_DISTANCE) ) + { + printk(XENLOG_WARNING + "NUMA: Invalid distance: NODE#%"PRIu32"->NODE#%"PRIu32"= :%"PRIu32"\n", + from, to, distance); + goto invalid_data; + } + + printk(XENLOG_INFO "NUMA: distance: NODE#%"PRIu32"->NODE#%"PRIu32"= :%"PRIu32"\n", + from, to, distance); + + /* Get opposite way distance */ + opposite =3D __node_distance(to, from); + if ( opposite =3D=3D 0 ) + { + /* 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 !=3D distance ) + { + /* + * In device tree NUMA distance-matrix binding: + * https://www.kernel.org/doc/Documentation/devicetree/bin= dings/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 t= he + * 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 configuratio= n. + * So, place a WARNING here to notice system administrator= s, + * is it the specail case that they hijack the device tree + * to support their rare machines? + */ + printk(XENLOG_WARNING + "Un-matched bi-direction! NODE#%"PRIu32"->NODE#%"PR= Iu32":%"PRIu32", NODE#%"PRIu32"->NODE#%"PRIu32":%"PRIu32"\n", + from, to, distance, to, from, opposite); + } + + /* Opposite way distance has been set, just set this way */ + numa_set_distance(from, to, distance); + } + } + + return 0; + +invalid_data: + numa_fw_bad(); + return -EINVAL; +} --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 168199000815912.457413698978371; Thu, 20 Apr 2023 04:26:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524057.814658 (Exim 4.92) (envelope-from ) id 1ppSQc-0001cj-Ee; Thu, 20 Apr 2023 11:26:18 +0000 Received: by outflank-mailman (output) from mailman id 524057.814658; Thu, 20 Apr 2023 11:26: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 1ppSQc-0001cU-9v; Thu, 20 Apr 2023 11:26:18 +0000 Received: by outflank-mailman (input) for mailman id 524057; Thu, 20 Apr 2023 11:26:17 +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 1ppSQb-0006GU-9N for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:17 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 295bbe74-df6e-11ed-8611-37d641c3527e; Thu, 20 Apr 2023 13:26:15 +0200 (CEST) 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 92C8D1480; Thu, 20 Apr 2023 04:26:58 -0700 (PDT) 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 589843F587; Thu, 20 Apr 2023 04:26:12 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 295bbe74-df6e-11ed-8611-37d641c3527e From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 10/17] xen/arm: unified entry to parse all NUMA data from device tree Date: Thu, 20 Apr 2023 19:25:14 +0800 Message-Id: <20230420112521.3272732-11-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681990008869100001 Content-Type: text/plain; charset="utf-8" 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 --- v2 -> v3: 1. No change. v1 -> v2: 1. Fix typos in commit message. 2. Fix code style and align parameters. 3. Use strncmp to replace memcmp. --- xen/arch/arm/include/asm/numa.h | 1 + xen/arch/arm/numa_device_tree.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/num= a.h index fe1bf4251f..a2b4f6cc10 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -45,6 +45,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); =20 #else =20 diff --git a/xen/arch/arm/numa_device_tree.c b/xen/arch/arm/numa_device_tre= e.c index 718afca826..a7dc58188e 100644 --- a/xen/arch/arm/numa_device_tree.c +++ b/xen/arch/arm/numa_device_tree.c @@ -258,3 +258,33 @@ invalid_data: 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 =3D 0; + const void *prop; + + prop =3D fdt_getprop(fdt, node, "device_type", &len); + if ( prop ) + { + if ( strncmp(prop, "cpu", len) =3D=3D 0 ) + ret =3D fdt_parse_numa_cpu_node(fdt, node); + else if ( strncmp(prop, "memory", len) =3D=3D 0 ) + ret =3D fdt_parse_numa_memory_node(fdt, node, uname, + address_cells, size_cells); + } + else if ( fdt_node_check_compatible(fdt, node, + "numa-distance-map-v1") =3D=3D 0 ) + ret =3D 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); +} --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681990166226424.6883810257808; Thu, 20 Apr 2023 04:29:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524061.814668 (Exim 4.92) (envelope-from ) id 1ppSTD-0003a6-0v; Thu, 20 Apr 2023 11:28:59 +0000 Received: by outflank-mailman (output) from mailman id 524061.814668; Thu, 20 Apr 2023 11:28:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSTC-0003Zz-UE; Thu, 20 Apr 2023 11:28:58 +0000 Received: by outflank-mailman (input) for mailman id 524061; Thu, 20 Apr 2023 11:28: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 1ppSQd-0006Vv-Ha for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:19 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 2b79b97b-df6e-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:26:18 +0200 (CEST) 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 262E91480; Thu, 20 Apr 2023 04:27:02 -0700 (PDT) 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 E01963F587; Thu, 20 Apr 2023 04:26:15 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 2b79b97b-df6e-11ed-b21f-6b7b168915f2 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 11/17] xen/arm: keep guest still be NUMA unware Date: Thu, 20 Apr 2023 19:25:15 +0800 Message-Id: <20230420112521.3272732-12-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681990167525100003 Content-Type: text/plain; charset="utf-8" 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 --- v2 -> v3: 1. No change. v1 -> v2: 1. 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 f80fdd1af2..2bf586fc45 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1185,6 +1185,10 @@ static int __init write_properties(struct domain *d,= struct kernel_info *kinfo, continue; } =20 + /* Dom0 is currently NUMA unaware */ + if ( dt_property_name_is_equal(prop, "numa-node-id") ) + continue; + res =3D fdt_property(kinfo->fdt, prop->name, prop_data, prop_len); =20 if ( res ) @@ -2567,6 +2571,8 @@ static int __init handle_node(struct domain *d, struc= t 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 =3D --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681990168238619.503122231471; Thu, 20 Apr 2023 04:29:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524064.814672 (Exim 4.92) (envelope-from ) id 1ppSTD-0003c5-AS; Thu, 20 Apr 2023 11:28:59 +0000 Received: by outflank-mailman (output) from mailman id 524064.814672; Thu, 20 Apr 2023 11:28:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSTD-0003bI-4y; Thu, 20 Apr 2023 11:28:59 +0000 Received: by outflank-mailman (input) for mailman id 524064; Thu, 20 Apr 2023 11:28: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 1ppSQh-0006Vv-Id for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:23 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 2d8eb75b-df6e-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:26:22 +0200 (CEST) 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 B552E1480; Thu, 20 Apr 2023 04:27:05 -0700 (PDT) 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 7AEBC3F587; Thu, 20 Apr 2023 04:26:19 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 2d8eb75b-df6e-11ed-b21f-6b7b168915f2 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 12/17] xen/arm: enable device tree based NUMA in system init Date: Thu, 20 Apr 2023 19:25:16 +0800 Message-Id: <20230420112521.3272732-13-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681990170069100009 Content-Type: text/plain; charset="utf-8" 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 --- v2 -> v3: 1. No change. v1 -> v2: 1. replace ~0 by INVALID_PADDR. 2. only print error messages for invalid dtb data. 3. remove unnecessary return. 4. 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/num= a.h index a2b4f6cc10..8057db09c4 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, 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); =20 #else =20 @@ -91,6 +92,10 @@ static inline void numa_detect_cpu_node(unsigned int cpu) { } =20 +static inline void numa_init(void) +{ +} + #endif =20 #define arch_want_default_dmazone() (false) diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c index 06e067712d..0a8a67512b 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -18,7 +18,11 @@ * */ #include +#include +#include #include +#include +#include =20 enum dt_numa_status __ro_after_init device_tree_numa =3D DT_NUMA_DEFAULT; =20 @@ -105,6 +109,59 @@ unsigned char __node_distance(nodeid_t from, nodeid_t = to) =20 EXPORT_SYMBOL(__node_distance); =20 +void __init numa_init(void) +{ + unsigned int idx; + paddr_t ram_start =3D INVALID_PADDR; + paddr_t ram_size =3D 0; + paddr_t ram_end =3D 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 =3D numa_device_tree_init(device_tree_flattened); + if ( ret ) + { + numa_off =3D true; + if ( ret =3D=3D -EINVAL ) + printk(XENLOG_WARNING + "Init NUMA from device tree failed, ret=3D%d\n", re= t); + } + } + 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 =3D 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 =3D bootinfo.mem.bank[0].start; + ram_size =3D bootinfo.mem.bank[0].size; + ram_end =3D ram_start + ram_size; + for ( idx =3D 1 ; idx < bootinfo.mem.nr_banks; idx++ ) + { + paddr_t bank_start =3D bootinfo.mem.bank[idx].start; + paddr_t bank_size =3D bootinfo.mem.bank[idx].size; + paddr_t bank_end =3D bank_start + bank_size; + + ram_size =3D ram_size + bank_size; + ram_start =3D min(ram_start, bank_start); + ram_end =3D 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 *e= nd) { if ( idx >=3D bootinfo.mem.nr_banks ) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 09e18d32df..f05e233f3a 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -1121,6 +1121,13 @@ void __init start_xen(unsigned long boot_phys_offset, /* Parse the ACPI tables for possible boot-time configuration */ acpi_boot_table_init(); =20 + /* + * 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(); =20 /* --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681990168017759.5256079074695; Thu, 20 Apr 2023 04:29:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524079.814708 (Exim 4.92) (envelope-from ) id 1ppSTO-0004oj-8J; Thu, 20 Apr 2023 11:29:10 +0000 Received: by outflank-mailman (output) from mailman id 524079.814708; Thu, 20 Apr 2023 11:29:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSTO-0004oV-4P; Thu, 20 Apr 2023 11:29:10 +0000 Received: by outflank-mailman (input) for mailman id 524079; Thu, 20 Apr 2023 11:29:06 +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 1ppSQk-0006Vv-LM for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:26 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 2fb9e0f7-df6e-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:26:26 +0200 (CEST) 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 4ED0E1480; Thu, 20 Apr 2023 04:27:09 -0700 (PDT) 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 0BB0E3F587; Thu, 20 Apr 2023 04:26:22 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 2fb9e0f7-df6e-11ed-b21f-6b7b168915f2 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 13/17] xen/arm: implement numa_node_to_arch_nid for device tree NUMA Date: Thu, 20 Apr 2023 19:25:17 +0800 Message-Id: <20230420112521.3272732-14-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681990169919100007 Content-Type: text/plain; charset="utf-8" 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 --- v2 -> v3: 1. No change. v1 -> v2: 1. 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/num= a.h index 8057db09c4..30b1fa39f1 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -48,6 +48,15 @@ extern void numa_detect_cpu_node(unsigned int cpu); extern int numa_device_tree_init(const void *fdt); extern void numa_init(void); =20 +/* + * 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 =20 /* Fake one node for now. See also node_online_map. */ --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681990171691332.94849074588535; Thu, 20 Apr 2023 04:29:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524080.814713 (Exim 4.92) (envelope-from ) id 1ppSTO-0004s4-PT; Thu, 20 Apr 2023 11:29:10 +0000 Received: by outflank-mailman (output) from mailman id 524080.814713; Thu, 20 Apr 2023 11:29:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSTO-0004qx-E7; Thu, 20 Apr 2023 11:29:10 +0000 Received: by outflank-mailman (input) for mailman id 524080; Thu, 20 Apr 2023 11:29:06 +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 1ppSQp-0006GU-A6 for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:31 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 31d2b099-df6e-11ed-8611-37d641c3527e; Thu, 20 Apr 2023 13:26:29 +0200 (CEST) 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 E14AB1480; Thu, 20 Apr 2023 04:27:12 -0700 (PDT) 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 9DD043F587; Thu, 20 Apr 2023 04:26:26 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 31d2b099-df6e-11ed-8611-37d641c3527e From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 14/17] xen/arm: use CONFIG_NUMA to gate node_online_map in smpboot Date: Thu, 20 Apr 2023 19:25:18 +0800 Message-Id: <20230420112521.3272732-15-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681990171939100011 Content-Type: text/plain; charset="utf-8" From: Wei Chen node_online_map in smpboot still need for Arm when NUMA is turn off by Kconfig. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v2 -> v3: 1. No change. v1 -> v2: 1. No change. --- 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 da7f2afd97..4f71cc974a 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -41,8 +41,10 @@ integer_param("maxcpus", max_cpus); /* CPU logical map: map xen cpuid to an MPIDR */ register_t __cpu_logical_map[NR_CPUS] =3D { [0 ... NR_CPUS-1] =3D MPIDR_IN= VALID }; =20 +#ifndef CONFIG_NUMA /* Fake one node for now. See also asm/numa.h */ nodemask_t __read_mostly node_online_map =3D { { [0] =3D 1UL } }; +#endif =20 /* Xen stack for bringing up the first CPU. */ static unsigned char __initdata cpu0_boot_stack[STACK_SIZE] --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681990181684445.28236067038426; Thu, 20 Apr 2023 04:29:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524096.814738 (Exim 4.92) (envelope-from ) id 1ppSTY-0006JM-Ji; Thu, 20 Apr 2023 11:29:20 +0000 Received: by outflank-mailman (output) from mailman id 524096.814738; Thu, 20 Apr 2023 11:29: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 1ppSTY-0006J7-Dr; Thu, 20 Apr 2023 11:29:20 +0000 Received: by outflank-mailman (input) for mailman id 524096; Thu, 20 Apr 2023 11:29:19 +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 1ppSQs-0006GU-Qw for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:34 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 33c33523-df6e-11ed-8611-37d641c3527e; Thu, 20 Apr 2023 13:26:32 +0200 (CEST) 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 2270F1480; Thu, 20 Apr 2023 04:27:16 -0700 (PDT) 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 2A2183F587; Thu, 20 Apr 2023 04:26:29 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 33c33523-df6e-11ed-8611-37d641c3527e From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Henry Wang , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 15/17] xen/arm: Set correct per-cpu cpu_core_mask Date: Thu, 20 Apr 2023 19:25:19 +0800 Message-Id: <20230420112521.3272732-16-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681990182901100001 Content-Type: text/plain; charset="utf-8" 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 --- v2 -> v3: 1. No change. v1 -> v2: 1. New patch --- 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/num= a.h index 30b1fa39f1..d340b6c147 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -47,6 +47,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); =20 /* * Device tree NUMA doesn't have architecural node id. @@ -63,6 +64,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) =20 +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 0a8a67512b..2251d7177c 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; } =20 +void numa_set_cpu_core_mask(int cpu) +{ + nodeid_t node =3D cpu_to_node[cpu]; + + if ( node =3D=3D NUMA_NO_NODE ) + node =3D 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 f05e233f3a..7cef913b7c 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -1226,6 +1226,11 @@ void __init start_xen(unsigned long boot_phys_offset, } =20 printk("Brought up %ld CPUs\n", (long)num_online_cpus()); + + /* Set per-cpu cpu_core_mask to cpus that belongs to the same NUMA nod= e. */ + for_each_online_cpu ( i ) + numa_set_cpu_core_mask(i); + /* TODO: smp_cpus_done(); */ =20 /* This should be done in a vpmu driver but we do not have one yet. */ --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681990169015638.8558795695604; Thu, 20 Apr 2023 04:29:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524078.814697 (Exim 4.92) (envelope-from ) id 1ppSTK-0004SF-Qh; Thu, 20 Apr 2023 11:29:06 +0000 Received: by outflank-mailman (output) from mailman id 524078.814697; Thu, 20 Apr 2023 11:29:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSTK-0004Rs-Mp; Thu, 20 Apr 2023 11:29:06 +0000 Received: by outflank-mailman (input) for mailman id 524078; Thu, 20 Apr 2023 11:29:06 +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 1ppSQu-0006Vv-V6 for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:36 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 35dbd8a5-df6e-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:26:36 +0200 (CEST) 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 A9C751480; Thu, 20 Apr 2023 04:27:19 -0700 (PDT) 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 6F9433F587; Thu, 20 Apr 2023 04:26:33 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 35dbd8a5-df6e-11ed-b21f-6b7b168915f2 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Henry Wang Subject: [PATCH v3 16/17] xen/arm: Provide Kconfig options for Arm to enable NUMA Date: Thu, 20 Apr 2023 19:25:20 +0800 Message-Id: <20230420112521.3272732-17-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681990169540100005 Content-Type: text/plain; charset="utf-8" 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 --- v2 -> v3: 1. No change. v1 -> v2: 1. 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 239d3aed3c..e751ad50d1 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -39,6 +39,17 @@ config ACPI config ARM_EFI bool =20 +config ARM_NUMA + bool "Arm NUMA (Non-Uniform Memory Access) Support (UNSUPPORTED)" if UNSU= PPORTED + 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 --=20 2.25.1 From nobody Tue May 14 18:05:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681990164902959.8141979209677; Thu, 20 Apr 2023 04:29:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524066.814677 (Exim 4.92) (envelope-from ) id 1ppSTD-0003ej-IB; Thu, 20 Apr 2023 11:28:59 +0000 Received: by outflank-mailman (output) from mailman id 524066.814677; Thu, 20 Apr 2023 11:28:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSTD-0003dK-CI; Thu, 20 Apr 2023 11:28:59 +0000 Received: by outflank-mailman (input) for mailman id 524066; Thu, 20 Apr 2023 11:28:58 +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 1ppSQz-0006Vv-20 for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:26:41 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 384c8b37-df6e-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:26:40 +0200 (CEST) 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 A99C81480; Thu, 20 Apr 2023 04:27:23 -0700 (PDT) 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 DF3963F587; Thu, 20 Apr 2023 04:26:36 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 384c8b37-df6e-11ed-b21f-6b7b168915f2 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Henry Wang Subject: [PATCH v3 17/17] docs: update numa command line to support Arm Date: Thu, 20 Apr 2023 19:25:21 +0800 Message-Id: <20230420112521.3272732-18-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420112521.3272732-1-Henry.Wang@arm.com> References: <20230420112521.3272732-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1681990166011100001 Content-Type: text/plain; charset="utf-8" From: Wei Chen Current numa command in documentation is x86 only. Remove x86 from numa command's arch limitation in this patch. Signed-off-by: Wei Chen Signed-off-by: Henry Wang Acked-by: Jan Beulich --- v2 -> v3: 1. Add the Acked-by tag from Jan. v1 -> v2: 1. Update Arm NUMA status in SUPPORT.md to "Tech Preview". --- SUPPORT.md | 1 + docs/misc/xen-command-line.pandoc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/SUPPORT.md b/SUPPORT.md index aa1940e55f..da4e3b9aa2 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -401,6 +401,7 @@ on embedded platforms and the x86 PV shim. Enables NUMA aware scheduling in Xen =20 Status, x86: Supported + Status, Arm: Tech Preview =20 ## Scalability =20 diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index e0b89b7d33..2fea22dd70 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1890,7 +1890,7 @@ i.e. a limit on the number of guests it is possible t= o start each having assigned a device sharing a common interrupt line. Accepts values between 1 and 255. =20 -### numa (x86) +### numa > `=3D on | off | fake=3D | noacpi` =20 > Default: `on` --=20 2.25.1