Skip to contentSkip to conversation

Device tree based NUMA support for Arm - Part#3

PATCH Superseded Henry Wang 3 participants 44 messages Apr 25, 2023 – May 23, 2023

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Henry Wang

author
#0 lore raw

v4 cover Device tree based NUMA support for Arm - Part#3

(Henry: Following the offline discussion with Wei, I will be the one to follow-up the upstream comments for this series.)

The preparation work to support NUMA on Arm has been merged and can be found at [1] and [2]. The initial discussions of the Arm NUMA support can be found at [3].

- Background of this series:

Xen memory allocation and scheduler modules are NUMA aware. But actually, on x86 has implemented the architecture APIs to support NUMA. Arm was providing a set of fake architecture APIs to make it compatible with NUMA awared memory allocation and scheduler.

Arm system was working well as a single node NUMA system with these fake APIs, because we didn't have multiple nodes NUMA system on Arm. But in recent years, more and more Arm devices support multiple nodes NUMA system.

So now we have a new problem. When Xen is running on these Arm devices, Xen still treat them as single node SMP systems. The NUMA affinity capability of Xen memory allocation and scheduler becomes meaningless. Because they rely on input data that does not reflect real NUMA layout.

Xen still think the access time for all of the memory is the same for all CPUs. However, Xen may allocate memory to a VM from different NUMA nodes with different access speeds. This difference can be amplified in workloads inside VM, causing performance instability and timeouts.

So in this patch series, we implement a set of NUMA API to use device tree to describe the NUMA layout. We reuse most of the code of x86 NUMA to create and maintain the mapping between memory and CPU, create the matrix between any two NUMA nodes. Except ACPI and some x86 specified code, we have moved other code to common. In next stage, when we implement ACPI based NUMA for Arm64, we may move the ACPI NUMA code to common too, but in current stage, we keep it as x86 only.

This patch serires has been tested and booted well on FVP in Arm64 mode with NUMA configs in device tree and one HPE x86 NUMA machine.

[1] https://lists.xenproject.org/archives/html/xen-devel/2022-06/msg00499.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2022-11/msg01043.html
[3] https://lists.xenproject.org/archives/html/xen-devel/2021-09/msg01903.html

v3 -> v4:
1. s/definition/declaration/ in commit message.
2. Add Acked-by tag from Jan for non-Arm parts.
3. Drop unnecessary initializer for node_distance_map. Pre-set the distance map to NUMA_NO_DISTANCE.
4. Drop NUMA_DISTANCE_UDF_MIN and its usage.
5. Drop EXPORT_SYMBOL(__node_distance).
6. Rework __node_distance()'s return value logic.
7. The distance map default value is now NUMA_NO_DISTANCE, update the logic accordingly and add in-code comment as a note.
8. Add Acked-by tag from Jan for related patches.

Henry Wang (1):
xen/arm: Set correct per-cpu cpu_core_mask

Wei Chen (16):
xen/arm: use NR_MEM_BANKS to override default NR_NODE_MEMBLKS xen/arm: implement helpers to get and update NUMA status xen/arm: implement node distance helpers for Arm xen/arm: use arch_get_ram_range to get memory ranges from bootinfo xen/arm: build NUMA cpu_to_node map in dt_smp_init_cpus xen/arm: Add boot and secondary CPU to NUMA system xen/arm: introduce a helper to parse device tree processor node xen/arm: introduce a helper to parse device tree memory node xen/arm: introduce a helper to parse device tree NUMA distance map xen/arm: unified entry to parse all NUMA data from device tree xen/arm: keep guest still be NUMA unware
xen/arm: enable device tree based NUMA in system init xen/arm: implement numa_node_to_arch_nid for device tree NUMA xen/arm: use CONFIG_NUMA to gate node_online_map in smpboot xen/arm: Provide Kconfig options for Arm to enable NUMA
docs: update numa command line to support Arm

 SUPPORT.md                        |   1 +
 docs/misc/xen-command-line.pandoc |   2 +-
 xen/arch/arm/Kconfig              |  11 ++
 xen/arch/arm/Makefile             |   2 +
 xen/arch/arm/domain_build.c       |   6 +
 xen/arch/arm/include/asm/numa.h   |  91 +++++++++-
 xen/arch/arm/numa.c               | 188 +++++++++++++++++++
 xen/arch/arm/numa_device_tree.c   | 291 ++++++++++++++++++++++++++++++
 xen/arch/arm/setup.c              |  17 ++
 xen/arch/arm/smpboot.c            |  38 ++++
 xen/arch/x86/include/asm/numa.h   |   1 -
 xen/arch/x86/srat.c               |   2 +-
 xen/include/xen/numa.h            |  10 +
 13 files changed, 656 insertions(+), 4 deletions(-)
 create mode 100644 xen/arch/arm/numa.c
 create mode 100644 xen/arch/arm/numa_device_tree.c
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v4 1/17 xen/arm: use NR_MEM_BANKS to override default NR_NODE_MEMBLKS

From: Wei Chen <[email protected]>

As a memory range described in device tree cannot be split across multiple nodes. And it is very likely than if you have more than 64 nodes, you may need a lot more than 2 regions per node. So the default NR_NODE_MEMBLKS value (MAX_NUMNODES * 2) makes no sense on Arm.

So, for Arm, we would just define NR_NODE_MEMBLKS as an alias to NR_MEM_BANKS. And in the future NR_MEM_BANKS will be user-configurable via kconfig, but for now leave NR_MEM_BANKS as 128 on Arm. This avoids having different way to define the value based NUMA vs non-NUMA.

Further discussions can be found here[1].

[1] https://lists.xenproject.org/archives/html/xen-devel/2021-09/msg02322.html

---
v3 -> v4:
1. Add Acked-by tag from Jan.
v2 -> v3:
By checking the discussion in [1] and [2]
[1] https://lists.xenproject.org/archives/html/xen-devel/2023-01/msg00595.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2021-09/msg02322.html
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(-)
xen/arch/arm/include/asm/numa.h +18 -1
index e2bee2bd82..7d6ae36a19 100644
@@ -3,9 +3,26 @@
 
 #include <xen/mm.h>
 
+#include <asm/setup.h>
+
 typedef u8 nodeid_t;
 
-#ifndef CONFIG_NUMA
+#ifdef CONFIG_NUMA
+
+/*
+ * It is very likely that if you have more than 64 nodes, you may
+ * need a lot more than 2 regions per node. So, for Arm, we would
+ * just define NR_NODE_MEMBLKS as an alias to NR_MEM_BANKS.
+ * And in the future NR_MEM_BANKS will be bumped for new platforms,
+ * but for now leave NR_MEM_BANKS as it is on Arm. This avoid to
+ * have different way to define the value based NUMA vs non-NUMA.
+ *
+ * Further discussions can be found here:
+ * https://lists.xenproject.org/archives/html/xen-devel/2021-09/msg02322.html
+ */
+#define NR_NODE_MEMBLKS NR_MEM_BANKS
+
+#else
 
 /* Fake one node for now. See also node_online_map. */
 #define cpu_to_node(cpu) 0
xen/include/xen/numa.h +9 -0
index 29b8c2df89..b86d0851fc 100644
@@ -13,7 +13,16 @@
 #define MAX_NUMNODES 1
 #endif
 
+/*
+ * Some architectures may have different considerations for
+ * number of node memory blocks. They can define their
+ * NR_NODE_MEMBLKS in asm/numa.h to reflect their architectural
+ * implementation. If the arch does not have specific implementation,
+ * the following default NR_NODE_MEMBLKS will be used.
+ */
+#ifndef NR_NODE_MEMBLKS
 #define NR_NODE_MEMBLKS (MAX_NUMNODES * 2)
+#endif
 
 #define vcpu_to_node(v) (cpu_to_node((v)->processor))
 
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v4 2/17 xen/arm: implement helpers to get and update NUMA status

In reply to Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
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
xen/arch/arm/include/asm/numa.h +17 -0
index 7d6ae36a19..83f60ad05b 100644
@@ -22,6 +22,8 @@ typedef u8 nodeid_t;
  */
 #define NR_NODE_MEMBLKS NR_MEM_BANKS
 
+extern bool numa_disabled(void);
+
 #else
 
 /* Fake one node for now. See also node_online_map. */
@@ -39,6 +41,21 @@ extern mfn_t first_valid_mfn;
 #define node_start_pfn(nid) (mfn_x(first_valid_mfn))
 #define __node_distance(a, b) (20)
 
+static inline bool numa_disabled(void)
+{
+    return true;
+}
+
+static inline bool arch_numa_unavailable(void)
+{
+    return true;
+}
+
+static inline bool arch_numa_broken(void)
+{
+    return true;
+}
+
 #endif
 
 #define arch_want_default_dmazone() (false)
xen/arch/arm/numa.c new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v4 3/17 xen/arm: implement node distance helpers for Arm

In reply to Henry Wang

From: Wei Chen <[email protected]>

We will parse NUMA nodes distances from device tree. So we need a matrix to record the distances between any two nodes we parsed. Accordingly, we provide this node_set_distance API for device tree NUMA to set the distance for any two nodes in this patch. When NUMA initialization failed, __node_distance will return NUMA_REMOTE_DISTANCE, this will help us avoid doing rollback for distance maxtrix when NUMA initialization failed.

As both x86 and Arm have implemented __node_distance, so we move its declaration from asm/numa.h to xen/numa.h. At same time, the outdated u8 return value of x86 has been changed to unsigned char.

---
v3 -> v4:
1. s/definition/declaration/ in commit message.
2. Add Acked-by tag from Jan for non-Arm parts.
3. Drop unnecessary initializer for node_distance_map. Pre-set the distance map to NUMA_NO_DISTANCE.
4. Drop NUMA_DISTANCE_UDF_MIN and its usage.
5. Drop EXPORT_SYMBOL(__node_distance).
6. Rework __node_distance()'s return value logic.
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 | 12 +++++++
 xen/arch/arm/numa.c             | 55 +++++++++++++++++++++++++++++++++
 xen/arch/x86/include/asm/numa.h |  1 -
 xen/arch/x86/srat.c             |  2 +-
 xen/include/xen/numa.h          |  1 +
 6 files changed, 70 insertions(+), 2 deletions(-)
xen/arch/arm/Makefile +1 -0
index 4d076b278b..9073398d6e 100644
@@ -38,6 +38,7 @@ obj-$(CONFIG_LIVEPATCH) += livepatch.o
 obj-y += mem_access.o
 obj-y += mm.o
 obj-y += monitor.o
+obj-$(CONFIG_NUMA) += numa.o
 obj-y += p2m.o
 obj-y += percpu.o
 obj-y += platform.o
xen/arch/arm/include/asm/numa.h +12 -0
index 83f60ad05b..96c856a9f7 100644
@@ -22,7 +22,19 @@ typedef u8 nodeid_t;
  */
 #define NR_NODE_MEMBLKS NR_MEM_BANKS
 
+/*
+ * In ACPI spec, 0-9 are the reserved values for node distance,
+ * 10 indicates local node distance, 20 indicates remote node
+ * distance. Set node distance map in device tree will follow
+ * the ACPI's definition.
+ */
+#define NUMA_DISTANCE_UDF_MAX   9
+#define NUMA_LOCAL_DISTANCE     10
+#define NUMA_REMOTE_DISTANCE    20
+
 extern bool numa_disabled(void);
+extern void numa_set_distance(nodeid_t from, nodeid_t to,
+                              unsigned int distance);
 
 #else
 
xen/arch/arm/numa.c +55 -0

64 lines not on this page · raw message

xen/arch/x86/include/asm/numa.h +0 -1
index 7866afa408..45456ac441 100644
@@ -22,7 +22,6 @@ extern void init_cpu_to_node(void);
 #define arch_want_default_dmazone() (num_online_nodes() > 1)
 
 void srat_parse_regions(paddr_t addr);
-extern u8 __node_distance(nodeid_t a, nodeid_t b);
 unsigned int arch_get_dma_bitsize(void);
 
 #endif
xen/arch/x86/srat.c +1 -1
index 56749ddca5..50faf5d352 100644
@@ -328,7 +328,7 @@ unsigned int numa_node_to_arch_nid(nodeid_t n)
 	return 0;
 }
 
-u8 __node_distance(nodeid_t a, nodeid_t b)
+unsigned char __node_distance(nodeid_t a, nodeid_t b)
 {
 	unsigned index;
 	u8 slit_val;
xen/include/xen/numa.h +1 -0
index b86d0851fc..8356e47b61 100644
@@ -114,6 +114,7 @@ extern bool numa_memblks_available(void);
 extern bool numa_update_node_memblks(nodeid_t node, unsigned int arch_nid,
                                      paddr_t start, paddr_t size, bool hotplug);
 extern void numa_set_processor_nodes_parsed(nodeid_t node);
+extern unsigned char __node_distance(nodeid_t a, nodeid_t b);
 
 #else
 
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v4 03/17] xen/arm: implement node distance helpers for Arm

xen/arch/arm/numa.c enum dt_numa_status { · line 36

Quoted 12 lines · Henry Wang
xen/arch/arm/numa.c +6 -0
@@ -28,6 +28,12 @@ enum dt_numa_status {
 
 static enum dt_numa_status __ro_after_init device_tree_numa = DT_NUMA_DEFAULT;
 
+static unsigned char __ro_after_init
+node_distance_map[MAX_NUMNODES][MAX_NUMNODES] = {
+    [0 ... MAX_NUMNODES - 1] = { [0 ... MAX_NUMNODES - 1] = NUMA_NO_DISTANCE }
+};
+
+

Nit: A stray 2nd blank line has appeared here.

Quoted 16 lines
xen/arch/arm/numa.c +12 -0
@@ -48,3 +54,52 @@ 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 >= ARRAY_SIZE(node_distance_map) ||
+         to >= ARRAY_SIZE(node_distance_map[0]) )
+    {
+        printk(KERN_WARNING
+               "NUMA: invalid nodes: from=%"PRIu8" to=%"PRIu8" MAX=%"PRIu8"\n",
+               from, to, MAX_NUMNODES);
+        return;
+    }

xen/arch/arm/numa.c int __init arch_numa_setup(const char *opt) · line 78

Quoted 10 lines
xen/arch/arm/numa.c +10 -0
+
+    /* NUMA defines NUMA_NO_DISTANCE as unreachable and 0-9 are undefined */
+    if ( distance >= NUMA_NO_DISTANCE || distance <= NUMA_DISTANCE_UDF_MAX ||
+         (from == to && distance != NUMA_LOCAL_DISTANCE) )
+    {
+        printk(KERN_WARNING
+               "NUMA: invalid distance: from=%"PRIu8" to=%"PRIu8" distance=%"PRIu32"\n",
+               from, to, distance);
+        return;
+    }

I appreciate the checking that node-local references are NUMA_LOCAL_DISTANCE, but if they're wrongly passed into here, shouldn't the resulting array still have NUMA_LOCAL_DISTANCE on its diagonal, at least as far as present nodes go?

Quoted 9 lines
xen/arch/arm/numa.c +9 -0
+    node_distance_map[from][to] = distance;
+}
+
+unsigned char __node_distance(nodeid_t from, nodeid_t to)
+{
+    if ( from == to )
+        return NUMA_LOCAL_DISTANCE;
+
+    /*

xen/arch/arm/numa.c int __init arch_numa_setup(const char *opt) · line 98

Quoted 10 lines
xen/arch/arm/numa.c +10 -0
+     * When NUMA is off, any distance will be treated as unreachable, so
+     * directly return NUMA_NO_DISTANCE from here as an optimization.
+     */
+    if ( numa_disabled() )
+        return NUMA_NO_DISTANCE;
+
+    /*
+     * Check whether the nodes are in the matrix range.
+     * When any node is out of range, except from and to nodes are the
+     * same, we treat them as unreachable.

I think this "except ..." part is slightly confusing, as it doesn't comment the subsequent code, but instead refers to the first check in the function. If you want to keep it, may I suggest to add something like "(see above)" before the comma?

Jan

author
#5 lore raw

RE: [PATCH v4 03/17] xen/arm: implement node distance helpers for Arm

Hi Jan,

Quoted 17 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: Re: [PATCH v4 03/17] xen/arm: implement node distance helpers for Arm

xen/arch/arm/numa.c enum dt_numa_status { · line 29

Quoted 5 lines · Henry Wang
xen/arch/arm/numa.c +0 -0
@@ -28,6 +28,12 @@ enum dt_numa_status {
 
 static enum dt_numa_status __ro_after_init device_tree_numa =

DT_NUMA_DEFAULT;

xen/arch/arm/numa.c enum dt_numa_status {

Quoted 4 lines
xen/arch/arm/numa.c +3 -0
+static unsigned char __ro_after_init
+node_distance_map[MAX_NUMNODES][MAX_NUMNODES] = {
+    [0 ... MAX_NUMNODES - 1] = { [0 ... MAX_NUMNODES - 1] =

NUMA_NO_DISTANCE }

Quoted 5 lines

xen/arch/arm/numa.c enum dt_numa_status { · line 36

Quoted 3 lines
xen/arch/arm/numa.c +3 -0
+};
+
+

Nit: A stray 2nd blank line has appeared here.

Will fix this in v5.

Quoted 14 lines

xen/arch/arm/numa.c enum dt_numa_status { · line 36

Quoted 2 lines
xen/arch/arm/numa.c +1 -0
+    /* NUMA defines NUMA_NO_DISTANCE as unreachable and 0-9 are

undefined */

xen/arch/arm/numa.c enum dt_numa_status { · line 37

Quoted 1 line
xen/arch/arm/numa.c +1 -0
+    if ( distance >= NUMA_NO_DISTANCE || distance <=

NUMA_DISTANCE_UDF_MAX ||

xen/arch/arm/numa.c int __init arch_numa_setup(const char *opt)

Quoted 4 lines
xen/arch/arm/numa.c +4 -0
+         (from == to && distance != NUMA_LOCAL_DISTANCE) )
+    {
+        printk(KERN_WARNING
+               "NUMA: invalid distance: from=%"PRIu8" to=%"PRIu8"

distance=%"PRIu32"\n",

xen/arch/arm/numa.c int __init arch_numa_setup(const char *opt) · line 78

Quoted 3 lines
xen/arch/arm/numa.c +3 -0
+               from, to, distance);
+        return;
+    }
Quoted 5 lines

I appreciate the checking that node-local references are NUMA_LOCAL_DISTANCE,
but if they're wrongly passed into here, shouldn't the resulting array still have NUMA_LOCAL_DISTANCE on its diagonal, at least as far as present nodes go?

Apologies in advance to ask more specific details from you as I am not sure if I can correctly understand the "if they're wrongly passed into here" case. Do you mean we are always guaranteed that if from == to, the distance will always be NUMA_LOCAL_DISTANCE so the (from == to && distance != NUMA_LOCAL_DISTANCE) check is redundant and can be removed? Thanks.

Quoted 3 lines
Quoted 3 lines
xen/arch/arm/numa.c +2 -0
+    node_distance_map[from][to] = distance;
+}

[...]

Quoted 9 lines

xen/arch/arm/numa.c int __init arch_numa_setup(const char *opt) · line 98

Quoted 4 lines
xen/arch/arm/numa.c +4 -0
+    /*
+     * 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.

I think this "except ..." part is slightly confusing, as it doesn't comment the subsequent code, but instead refers to the first check in the function. If you want to keep it, may I suggest to add something like "(see above)" before the comma?

Sure, I will add "(see above)" in v5.

Kind regards,
Henry

Quoted 2 lines

Jan

#6 lore raw

Re: [PATCH v4 03/17] xen/arm: implement node distance helpers for Arm

Quoted 23 lines · Henry Wang
Quoted 17 lines

-----Original Message-----
From: Jan Beulich <[email protected]>

Quoted 1 line · Henry Wang

+ /* NUMA defines NUMA_NO_DISTANCE as unreachable and 0-9 are

undefined */

Quoted 1 line

+ if ( distance >= NUMA_NO_DISTANCE || distance <=

NUMA_DISTANCE_UDF_MAX ||

xen/arch/arm/numa.c int __init arch_numa_setup(const char *opt)

Quoted 4 lines
xen/arch/arm/numa.c +4 -0
+         (from == to && distance != NUMA_LOCAL_DISTANCE) )
+    {
+        printk(KERN_WARNING
+               "NUMA: invalid distance: from=%"PRIu8" to=%"PRIu8"

distance=%"PRIu32"\n",

xen/arch/arm/numa.c int __init arch_numa_setup(const char *opt) · line 78

Quoted 3 lines
xen/arch/arm/numa.c +3 -0
+               from, to, distance);
+        return;
+    }
Quoted 5 lines

I appreciate the checking that node-local references are NUMA_LOCAL_DISTANCE,
but if they're wrongly passed into here, shouldn't the resulting array still have NUMA_LOCAL_DISTANCE on its diagonal, at least as far as present nodes go?

Quoted 5 lines

Apologies in advance to ask more specific details from you as I am not sure if I can correctly understand the "if they're wrongly passed into here" case. Do you mean we are always guaranteed that if from == to, the distance will always be NUMA_LOCAL_DISTANCE so the (from == to && distance != NUMA_LOCAL_DISTANCE) check is redundant and can be removed? Thanks.

It's a little odd that you ask me: It is your code which insists on NUMA_LOCAL_DISTANCE when from == to. If you insist on your caller to pass only this one value, then I think it is only logical to also set the respective table entries to that value (rather than leaving them at NUMA_NO_DISTANCE).

Jan

author
#7 lore raw

RE: [PATCH v4 03/17] xen/arm: implement node distance helpers for Arm

Hi Jan,

Quoted 36 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: Re: [PATCH v4 03/17] xen/arm: implement node distance helpers for Arm

Quoted 13 lines · Henry Wang
Quoted 13 lines

-----Original Message-----
From: Jan Beulich <[email protected]>

Quoted 1 line · Henry Wang

+ /* NUMA defines NUMA_NO_DISTANCE as unreachable and 0-9 are

undefined */

Quoted 1 line

+ if ( distance >= NUMA_NO_DISTANCE || distance <=

NUMA_DISTANCE_UDF_MAX ||

xen/arch/arm/numa.c int __init arch_numa_setup(const char *opt)

Quoted 4 lines
xen/arch/arm/numa.c +4 -0
+         (from == to && distance != NUMA_LOCAL_DISTANCE) )
+    {
+        printk(KERN_WARNING
+               "NUMA: invalid distance: from=%"PRIu8" to=%"PRIu8"

distance=%"PRIu32"\n",

Quoted 8 lines
Quoted 8 lines

xen/arch/arm/numa.c int __init arch_numa_setup(const char *opt) · line 78

Quoted 3 lines
xen/arch/arm/numa.c +3 -0
+               from, to, distance);
+        return;
+    }

I appreciate the checking that node-local references are NUMA_LOCAL_DISTANCE,
but if they're wrongly passed into here, shouldn't the resulting array still have NUMA_LOCAL_DISTANCE on its diagonal, at least as far as present

nodes

Quoted 4 lines
Quoted 1 line

go?

Apologies in advance to ask more specific details from you as I am not sure if I can correctly understand the "if they're wrongly passed into here" case.

Do you

Quoted 1 line

mean we are always guaranteed that if from == to, the distance will always

be

Quoted 1 line

NUMA_LOCAL_DISTANCE so the (from == to && distance !=

Quoted 8 lines

NUMA_LOCAL_DISTANCE)

Quoted 1 line

check is redundant and can be removed? Thanks.

It's a little odd that you ask me: It is your code which insists on NUMA_LOCAL_DISTANCE when from == to. If you insist on your caller to pass only this one value, then I think it is only logical to also set the respective table entries to that value (rather than leaving them at NUMA_NO_DISTANCE).

I think I understand what do you mean now. I was only checking this specific patch so didn't make the connection with the latter patches.

Kind regards,
Henry

Quoted 2 lines

Jan

author
#8 lore raw

PATCH v4 4/17 xen/arm: use arch_get_ram_range to get memory ranges from bootinfo

In reply to Henry Wang

From: Wei Chen <[email protected]>

Implement the same helper "arch_get_ram_range" as x86 for NUMA code to get memory bank from Arm bootinfo.

---
v3 -> v4:
1. No change.
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(+)
xen/arch/arm/numa.c +11 -0
index e4f75f314b..3fee3789c7 100644
@@ -103,3 +103,14 @@ unsigned char __node_distance(nodeid_t from, nodeid_t to)
 
     return node_distance_map[from][to];
 }
+
+int __init arch_get_ram_range(unsigned int idx, paddr_t *start, paddr_t *end)
+{
+    if ( idx >= bootinfo.mem.nr_banks )
+        return -ENOENT;
+
+    *start = bootinfo.mem.bank[idx].start;
+    *end = *start + bootinfo.mem.bank[idx].size;
+
+    return 0;
+}
Signature · 1 line
2.25.1
author
#9 lore raw

PATCH v4 5/17 xen/arm: build NUMA cpu_to_node map in dt_smp_init_cpus

In reply to Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
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(+)
xen/arch/arm/include/asm/numa.h +4 -0
index 96c856a9f7..97d4a67dea 100644
@@ -68,6 +68,10 @@ static inline bool arch_numa_broken(void)
     return true;
 }
 
+static inline void numa_set_node(unsigned int cpu, nodeid_t node)
+{
+}
+
 #endif
 
 #define arch_want_default_dmazone() (false)
xen/arch/arm/smpboot.c +36 -0
index 4a89b3a834..da7f2afd97 100644
@@ -118,7 +118,12 @@ static void __init dt_smp_init_cpus(void)
     {
         [0 ... NR_CPUS - 1] = MPIDR_INVALID
     };
+    static nodeid_t node_map[NR_CPUS] __initdata =
+    {
+        [0 ... NR_CPUS - 1] = NUMA_NO_NODE
+    };
     bool bootcpu_valid = false;
+    unsigned int nid = 0;
     int rc;
 
     mpidr = system_cpuinfo.mpidr.bits & MPIDR_HWID_MASK;
@@ -169,6 +174,28 @@ static void __init dt_smp_init_cpus(void)
             continue;
         }
 
+        if ( IS_ENABLED(CONFIG_NUMA) )
+        {
+            /*
+             * When CONFIG_NUMA is set, try to fetch numa infomation
+             * from CPU dts node, otherwise the nid is always 0.
+             */
+            if ( !dt_property_read_u32(cpu, "numa-node-id", &nid) )
+            {
+                printk(XENLOG_WARNING
+                       "cpu[%d] dts path: %s: doesn't have numa information!\n",
+                       cpuidx, dt_node_full_name(cpu));
+                /*
+                 * During the early stage of NUMA initialization, when Xen
+                 * found any CPU dts node doesn't have numa-node-id info, the
+                 * NUMA will be treated as off, all CPU will be set to a FAKE
+                 * node 0. So if we get numa-node-id failed here, we should
+                 * set nid to 0.
+                 */
+                nid = 0;
+            }
+        }
+
         /*
          * 8 MSBs must be set to 0 in the DT since the reg property
          * defines the MPIDR[23:0]
@@ -228,9 +255,13 @@ static void __init dt_smp_init_cpus(void)
         {
             printk("cpu%d init failed (hwid %"PRIregister"): %d\n", i, hwid, rc);
             tmp_map[i] = MPIDR_INVALID;
+            node_map[i] = NUMA_NO_NODE;
         }
         else
+        {
             tmp_map[i] = hwid;
+            node_map[i] = nid;
+        }
     }
 
     if ( !bootcpu_valid )
@@ -246,6 +277,11 @@ static void __init dt_smp_init_cpus(void)
             continue;
         cpumask_set_cpu(i, &cpu_possible_map);
         cpu_logical_map(i) = tmp_map[i];
+
+        nid = node_map[i];
+        if ( nid >= MAX_NUMNODES )
+            nid = 0;
+        numa_set_node(i, nid);
     }
 }
 
Signature · 1 line
2.25.1
author
#10 lore raw

PATCH v4 6/17 xen/arm: Add boot and secondary CPU to NUMA system

In reply to Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
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(+)
xen/arch/arm/include/asm/numa.h +9 -0
index 97d4a67dea..b04ace26db 100644
@@ -35,6 +35,7 @@ typedef u8 nodeid_t;
 extern bool numa_disabled(void);
 extern void numa_set_distance(nodeid_t from, nodeid_t to,
                               unsigned int distance);
+extern void numa_detect_cpu_node(unsigned int cpu);
 
 #else
 
@@ -72,6 +73,14 @@ static inline void numa_set_node(unsigned int cpu, nodeid_t node)
 {
 }
 
+static inline void numa_add_cpu(unsigned int cpu)
+{
+}
+
+static inline void numa_detect_cpu_node(unsigned int cpu)
+{
+}
+
 #endif
 
 #define arch_want_default_dmazone() (false)
xen/arch/arm/numa.c +10 -0
index 3fee3789c7..7ae9ace15d 100644
@@ -80,6 +80,16 @@ void __init numa_set_distance(nodeid_t from, nodeid_t to,
     node_distance_map[from][to] = distance;
 }
 
+void numa_detect_cpu_node(unsigned int cpu)
+{
+    nodeid_t node = cpu_to_node[cpu];
+
+    if ( node == NUMA_NO_NODE )
+        node = 0;
+
+    node_set_online(node);
+}
+
 unsigned char __node_distance(nodeid_t from, nodeid_t to)
 {
     if ( from == to )
xen/arch/arm/setup.c +5 -0
index 6f9f4d8c8a..09e18d32df 100644
@@ -1205,6 +1205,11 @@ void __init start_xen(unsigned long boot_phys_offset,
 
     for_each_present_cpu ( i )
     {
+        /* Detect and online node based on cpu_to_node[]. */
+        numa_detect_cpu_node(i);
+        /* Set up node_to_cpumask based on cpu_to_node[]. */
+        numa_add_cpu(i);
+
         if ( (num_online_cpus() < nr_cpu_ids) && !cpu_online(i) )
         {
             int ret = cpu_up(i);
Signature · 1 line
2.25.1
author
#11 lore raw

PATCH v4 7/17 xen/arm: introduce a helper to parse device tree processor node

In reply to Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
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
xen/arch/arm/Makefile +1 -0
index 9073398d6e..bbc68e3735 100644
@@ -39,6 +39,7 @@ obj-y += mem_access.o
 obj-y += mm.o
 obj-y += monitor.o
 obj-$(CONFIG_NUMA) += numa.o
+obj-$(CONFIG_DEVICE_TREE_NUMA) += numa_device_tree.o
 obj-y += p2m.o
 obj-y += percpu.o
 obj-y += platform.o
xen/arch/arm/include/asm/numa.h +8 -0
index b04ace26db..2987158d16 100644
@@ -22,6 +22,14 @@ typedef u8 nodeid_t;
  */
 #define NR_NODE_MEMBLKS NR_MEM_BANKS
 
+enum dt_numa_status {
+    DT_NUMA_DEFAULT,
+    DT_NUMA_ON,
+    DT_NUMA_OFF,
+};
+
+extern enum dt_numa_status device_tree_numa;
+
 /*
  * In ACPI spec, 0-9 are the reserved values for node distance,
  * 10 indicates local node distance, 20 indicates remote node
xen/arch/arm/numa.c +1 -7
index 7ae9ace15d..b953c2574a 100644
@@ -20,13 +20,7 @@
 #include <xen/init.h>
 #include <xen/numa.h>
 
-enum dt_numa_status {
-    DT_NUMA_DEFAULT,
-    DT_NUMA_ON,
-    DT_NUMA_OFF,
-};
-
-static enum dt_numa_status __ro_after_init device_tree_numa = DT_NUMA_DEFAULT;
+enum dt_numa_status __ro_after_init device_tree_numa = DT_NUMA_DEFAULT;
 
 static unsigned char __ro_after_init
 node_distance_map[MAX_NUMNODES][MAX_NUMNODES] = {
xen/arch/arm/numa_device_tree.c new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
2.25.1
#12 lore raw

Re: [PATCH v4 07/17] xen/arm: introduce a helper to parse device tree processor node

Quoted 26 lines · Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
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.

Quoted 7 lines
---
 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

As asked for in various other contexts, may I please ask that new files prefer dashes over underscores in their names? Additionally short but still descriptive names are imo to be generally preferred; in the case here how about numa-dt.c?

Jan

author
#13 lore raw

RE: [PATCH v4 07/17] xen/arm: introduce a helper to parse device tree processor node

Hi Jan,

Quoted 6 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: Re: [PATCH v4 07/17] xen/arm: introduce a helper to parse device tree processor node

Quoted 1 line
 xen/arch/arm/numa_device_tree.c | 64
Quoted 8 lines

+++++++++++++++++++++++++++++++++

Quoted 2 lines
 4 files changed, 74 insertions(+), 7 deletions(-)
 create mode 100644 xen/arch/arm/numa_device_tree.c

As asked for in various other contexts, may I please ask that new files prefer dashes over underscores in their names? Additionally short but still descriptive names are imo to be generally preferred; in the case here how about numa-dt.c?

Sounds good to me. I will follow your suggestion if there will be no explicit objection from other maintainers. Thanks for the suggestion as always :)

Kind regards,
Henry

Quoted 2 lines

Jan

#14 lore raw

Re: [PATCH v4 07/17] xen/arm: introduce a helper to parse device tree processor node

In reply to Jan Beulich

Hi Jan,

Quoted 37 lines · Jan Beulich
Quoted 26 lines · Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
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.

Quoted 7 lines
---
 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
Quoted 4 lines

As asked for in various other contexts, may I please ask that new files prefer dashes over underscores in their names? Additionally short but still descriptive names are imo to be generally preferred; in the case here how about numa-dt.c?

Seeing that you made this request multiple times within the last months, maybe it would be better to write it down in CODING_STYLE or CONTRIBUTING? Otherwise, you will keep making these requests indefinitely without people being able to know things like that before pushing new files (+ this always requires respin).

~Michal

#15 lore raw

Re: [PATCH v4 07/17] xen/arm: introduce a helper to parse device tree processor node

Quoted 45 lines · Michal Orzel

Hi Jan,

Quoted 37 lines · Jan Beulich
Quoted 26 lines · Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
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.

Quoted 7 lines
---
 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
Quoted 4 lines

As asked for in various other contexts, may I please ask that new files prefer dashes over underscores in their names? Additionally short but still descriptive names are imo to be generally preferred; in the case here how about numa-dt.c?

Quoted 4 lines

Seeing that you made this request multiple times within the last months, maybe it would be better to write it down in CODING_STYLE or CONTRIBUTING? Otherwise, you will keep making these requests indefinitely without people being able to know things like that before pushing new files (+ this always requires respin).

Well. I could make a try, but getting ./CODING_STYLE changed has proven to be difficult in the past, and I would prefer to not again sit on such a patch for months or years. IOW I've become quite hesitant to submit such patches, even more so for things which - imo - should go without saying.

Jan

#16 lore raw

Re: [PATCH v4 07/17] xen/arm: introduce a helper to parse device tree processor node

Quoted 53 lines · Jan Beulich
Quoted 45 lines · Michal Orzel

Hi Jan,

Quoted 37 lines · Jan Beulich
Quoted 26 lines · Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
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.

Quoted 7 lines
---
 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
Quoted 4 lines

As asked for in various other contexts, may I please ask that new files prefer dashes over underscores in their names? Additionally short but still descriptive names are imo to be generally preferred; in the case here how about numa-dt.c?

Quoted 4 lines

Seeing that you made this request multiple times within the last months, maybe it would be better to write it down in CODING_STYLE or CONTRIBUTING? Otherwise, you will keep making these requests indefinitely without people being able to know things like that before pushing new files (+ this always requires respin).

Quoted 5 lines

Well. I could make a try, but getting ./CODING_STYLE changed has proven to be difficult in the past, and I would prefer to not again sit on such a patch for months or years. IOW I've become quite hesitant to submit such patches, even more so for things which - imo - should go without saying.

I understand your point. It might be worth asking e.g. on a community call to see what others think (for now I did not see any objections). It might be that everyone is ok with it under good justification.

~Michal

author
#17 lore raw

PATCH v4 8/17 xen/arm: introduce a helper to parse device tree memory node

In reply to Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
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(+)
xen/arch/arm/numa_device_tree.c +89 -0
index 83601c83e7..38f5e93d1d 100644
@@ -34,6 +34,26 @@ static int __init fdt_numa_processor_affinity_init(nodeid_t node)
     return 0;
 }
 
+/* Callback for parsing of the memory regions affinity */
+static int __init fdt_numa_memory_affinity_init(nodeid_t node,
+                                                paddr_t start, paddr_t size)
+{
+    if ( !numa_memblks_available() )
+    {
+        dprintk(XENLOG_WARNING,
+                "Too many NUMA entries, try bigger NR_NODE_MEMBLKS\n");
+        return -EINVAL;
+    }
+
+    numa_fw_nid_name = "numa-node-id";
+    if ( !numa_update_node_memblks(node, node, start, size, false) )
+        return -EINVAL;
+
+    device_tree_numa = DT_NUMA_ON;
+
+    return 0;
+}
+
 /* Parse CPU NUMA node info */
 static int __init fdt_parse_numa_cpu_node(const void *fdt, int node)
 {
@@ -62,3 +82,72 @@ static int __init fdt_parse_numa_cpu_node(const void *fdt, int node)
 
     return fdt_numa_processor_affinity_init(nid);
 }
+
+/* Parse memory node NUMA info */
+static int __init fdt_parse_numa_memory_node(const void *fdt, int node,
+                                             const char *name,
+                                             unsigned int addr_cells,
+                                             unsigned int size_cells)
+{
+    unsigned int nid;
+    int ret = 0, len;
+    paddr_t addr, size;
+    const struct fdt_property *prop;
+    unsigned int idx, ranges;
+    const __be32 *addresses;
+
+    if ( numa_disabled() )
+        return -EINVAL;
+
+    /*
+     * device_tree_get_u32 will return NUMA_NO_NODE when this memory
+     * DT node doesn't have numa-node-id. This can help us to
+     * distinguish a bad DTB and a normal DTB without NUMA info.
+     */
+    nid = device_tree_get_u32(fdt, node, "numa-node-id", NUMA_NO_NODE);
+    if ( node == NUMA_NO_NODE )
+    {
+        numa_fw_bad();
+        return -ENODATA;
+    }
+    else if ( nid >= MAX_NUMNODES )
+    {
+        printk(XENLOG_WARNING "Node id %u exceeds maximum value\n", nid);
+        goto invalid_data;
+    }
+
+    prop = fdt_get_property(fdt, node, "reg", &len);
+    if ( !prop )
+    {
+        printk(XENLOG_WARNING
+               "fdt: node `%s': missing `reg' property\n", name);
+        goto invalid_data;
+    }
+
+    addresses = (const __be32 *)prop->data;
+    ranges = len / (sizeof(__be32)* (addr_cells + size_cells));
+    for ( idx = 0; idx < ranges; idx++ )
+    {
+        device_tree_get_reg(&addresses, addr_cells, size_cells, &addr, &size);
+        /* Skip zero size ranges */
+        if ( !size )
+            continue;
+
+        ret = fdt_numa_memory_affinity_init(nid, addr, size);
+        if ( ret )
+            goto invalid_data;
+    }
+
+    if ( idx == 0 )
+    {
+        printk(XENLOG_ERR
+               "bad property in memory node, idx=%d ret=%d\n", idx, ret);
+        goto invalid_data;
+    }
+
+    return 0;
+
+invalid_data:
+    numa_fw_bad();
+    return -EINVAL;
+}
Signature · 1 line
2.25.1
author
#18 lore raw

PATCH v4 9/17 xen/arm: introduce a helper to parse device tree NUMA distance map

In reply to Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. The distance map default value is now NUMA_NO_DISTANCE, update the logic accordingly and add in-code comment as a note.
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 = __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 | 108 ++++++++++++++++++++++++++++++++
 1 file changed, 108 insertions(+)
xen/arch/arm/numa_device_tree.c +108 -0
index 38f5e93d1d..9d9d09273e 100644
@@ -151,3 +151,111 @@ 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 = fdt_get_property(fdt, node, "distance-matrix", &len);
+    if ( !prop )
+    {
+        printk(XENLOG_WARNING
+               "NUMA: No distance-matrix property in distance-map\n");
+        goto invalid_data;
+    }
+
+    if ( len % sizeof(__be32) != 0 )
+    {
+        printk(XENLOG_WARNING
+               "distance-matrix in node is not a multiple of u32\n");
+        goto invalid_data;
+    }
+
+    entry_count = len / sizeof(__be32);
+    if ( entry_count == 0 )
+    {
+        printk(XENLOG_WARNING "NUMA: Invalid distance-matrix\n");
+        goto invalid_data;
+    }
+
+    matrix = (const __be32 *)prop->data;
+    for ( i = 0; i + 2 < entry_count; i += 3 )
+    {
+        unsigned int from, to, distance, opposite;
+
+        from = dt_next_cell(1, &matrix);
+        to = dt_next_cell(1, &matrix);
+        distance = dt_next_cell(1, &matrix);
+        if ( (from == to && distance != NUMA_LOCAL_DISTANCE) ||
+             (from != to && distance <= 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 = __node_distance(to, from);
+        /* The default value in node_distance_map is NUMA_NO_DISTANCE */
+        if ( opposite == NUMA_NO_DISTANCE )
+        {
+            /* Bi-directions are not set, set both */
+            numa_set_distance(from, to, distance);
+            numa_set_distance(to, from, distance);
+        }
+        else
+        {
+            /*
+             * Opposite way distance has been set to a different value.
+             * It may be a firmware device tree bug?
+             */
+            if ( opposite != distance )
+            {
+                /*
+                 * In device tree NUMA distance-matrix binding:
+                 * https://www.kernel.org/doc/Documentation/devicetree/bindings/numa.txt
+                 * There is a notes mentions:
+                 * "Each entry represents distance from first node to
+                 *  second node. The distances are equal in either
+                 *  direction."
+                 *
+                 * That means device tree doesn't permit this case.
+                 * But in ACPI spec, it cares to specifically permit this
+                 * case:
+                 * "Except for the relative distance from a System Locality
+                 *  to itself, each relative distance is stored twice in the
+                 *  matrix. This provides the capability to describe the
+                 *  scenario where the relative distances for the two
+                 *  directions between System Localities is different."
+                 *
+                 * That means a real machine allows such NUMA configuration.
+                 * So, place a WARNING here to notice system administrators,
+                 * is it the specail case that they hijack the device tree
+                 * to support their rare machines?
+                 */
+                printk(XENLOG_WARNING
+                       "Un-matched bi-direction! NODE#%"PRIu32"->NODE#%"PRIu32":%"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;
+}
Signature · 1 line
2.25.1
#19 lore raw

Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 8 lines · Henry Wang

From: Wei Chen <[email protected]>

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.

While trying to hunt down the caller(s) of numa_set_distance() in the context to replying to patch 3, I came across this one:

Quoted 33 lines
xen/arch/arm/numa_device_tree.c +27 -0
@@ -151,3 +151,111 @@ 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 = fdt_get_property(fdt, node, "distance-matrix", &len);
+    if ( !prop )
+    {
+        printk(XENLOG_WARNING
+               "NUMA: No distance-matrix property in distance-map\n");
+        goto invalid_data;
+    }
+
+    if ( len % sizeof(__be32) != 0 )
+    {
+        printk(XENLOG_WARNING
+               "distance-matrix in node is not a multiple of u32\n");
+        goto invalid_data;
+    }
+
+    entry_count = len / sizeof(__be32);

xen/arch/arm/numa_device_tree.c invalid_data: · line 190

Quoted 10 lines
xen/arch/arm/numa_device_tree.c +10 -0
+    if ( entry_count == 0 )
+    {
+        printk(XENLOG_WARNING "NUMA: Invalid distance-matrix\n");
+        goto invalid_data;
+    }
+
+    matrix = (const __be32 *)prop->data;
+    for ( i = 0; i + 2 < entry_count; i += 3 )
+    {
+        unsigned int from, to, distance, opposite;

With these ...

xen/arch/arm/numa_device_tree.c invalid_data: · line 199

Quoted 8 lines
xen/arch/arm/numa_device_tree.c +8 -0
+        from = dt_next_cell(1, &matrix);
+        to = dt_next_cell(1, &matrix);
+        distance = dt_next_cell(1, &matrix);
+        if ( (from == to && distance != NUMA_LOCAL_DISTANCE) ||
+             (from != to && distance <= NUMA_LOCAL_DISTANCE) )
+        {
+            printk(XENLOG_WARNING
+                   "NUMA: Invalid distance: NODE#%"PRIu32"->NODE#%"PRIu32":%"PRIu32"\n",

... you don't mean PRIu32 here and ...

xen/arch/arm/numa_device_tree.c invalid_data: · line 204

Quoted 5 lines
xen/arch/arm/numa_device_tree.c +5 -0
+                   from, to, distance);
+            goto invalid_data;
+        }
+
+        printk(XENLOG_INFO "NUMA: distance: NODE#%"PRIu32"->NODE#%"PRIu32":%"PRIu32"\n",

... here and yet further down anymore. That'll at the same time shorten all these lines quite a bit.

xen/arch/arm/numa_device_tree.c invalid_data: · line 210

Quoted 6 lines
xen/arch/arm/numa_device_tree.c +6 -0
+               from, to, distance);
+
+        /* Get opposite way distance */
+        opposite = __node_distance(to, from);
+        /* The default value in node_distance_map is NUMA_NO_DISTANCE */
+        if ( opposite == NUMA_NO_DISTANCE )

And the matrix you're reading from can't hold NUMA_NO_DISTANCE entries? I ask because you don't check this above; you only check against NUMA_LOCAL_DISTANCE.

Quoted 32 lines
xen/arch/arm/numa_device_tree.c +32 -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 != distance )
+            {
+                /*
+                 * In device tree NUMA distance-matrix binding:
+                 * https://www.kernel.org/doc/Documentation/devicetree/bindings/numa.txt
+                 * There is a notes mentions:
+                 * "Each entry represents distance from first node to
+                 *  second node. The distances are equal in either
+                 *  direction."
+                 *
+                 * That means device tree doesn't permit this case.
+                 * But in ACPI spec, it cares to specifically permit this
+                 * case:
+                 * "Except for the relative distance from a System Locality
+                 *  to itself, each relative distance is stored twice in the
+                 *  matrix. This provides the capability to describe the
+                 *  scenario where the relative distances for the two
+                 *  directions between System Localities is different."
+                 *
+                 * That means a real machine allows such NUMA configuration.
+                 * So, place a WARNING here to notice system administrators,

xen/arch/arm/numa_device_tree.c invalid_data: · line 252

Quoted 10 lines
xen/arch/arm/numa_device_tree.c +10 -0
+                 * 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#%"PRIu32":%"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);

It took me a while to understand what the comment is to tell me, because in this iteration the opposite entry wasn't set. May I suggest to make more explicit that you refer to an earlier iteration, e.g. by "... was set before, ..."?

xen/arch/arm/numa_device_tree.c invalid_data: · line 258

Quoted 6 lines
xen/arch/arm/numa_device_tree.c +6 -0
+        }
+    }
+
+    return 0;
+
+invalid_data:

Nit: Style (labels to be indented by [at least] one blank).

Jan

author
#20 lore raw

RE: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Hi Jan,

Quoted 28 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 1 line

+ unsigned int from, to, distance, opposite;

With these ...

Quoted 9 lines
xen/arch/arm/numa_device_tree.c +8 -0
+        from = dt_next_cell(1, &matrix);
+        to = dt_next_cell(1, &matrix);
+        distance = dt_next_cell(1, &matrix);
+        if ( (from == to && distance != NUMA_LOCAL_DISTANCE) ||
+             (from != to && distance <= NUMA_LOCAL_DISTANCE) )
+        {
+            printk(XENLOG_WARNING
+                   "NUMA: Invalid distance: NODE#%"PRIu32"-

NODE#%"PRIu32":%"PRIu32"\n",

... you don't mean PRIu32 here and ...

Quoted 6 lines
xen/arch/arm/numa_device_tree.c +5 -0
+                   from, to, distance);
+            goto invalid_data;
+        }
+
+        printk(XENLOG_INFO "NUMA: distance: NODE#%"PRIu32"-

NODE#%"PRIu32":%"PRIu32"\n",

Quoted 2 lines

... here and yet further down anymore. That'll at the same time shorten all these lines quite a bit.

I did a little bit archeology to check the discussion back to 2 years ago when Wei originally sent the v1 to the mailing list. Changing %u to %"PRIu32" was one of the comment at that time [1] when these variables were defined as uint32_t. But now with these variables being unsigned int I think now %u is a more proper way here. I will do the according changes in v5.

Quoted 6 lines

xen/arch/arm/numa_device_tree.c invalid_data:

Quoted 6 lines
xen/arch/arm/numa_device_tree.c +5 -0
+               from, to, distance);
+
+        /* Get opposite way distance */
+        opposite = __node_distance(to, from);
+        /* The default value in node_distance_map is NUMA_NO_DISTANCE
Quoted 6 lines

*/

Quoted 1 line

+ if ( opposite == NUMA_NO_DISTANCE )

And the matrix you're reading from can't hold NUMA_NO_DISTANCE entries? I ask because you don't check this above; you only check against NUMA_LOCAL_DISTANCE.

My understanding for the purpose of this part of code is to check if the opposite way distance has already been set, so we need to compare the opposite way distance with the default value NUMA_NO_DISTANCE here.

Back to your question, I can see your point of the question. However I don't think NUMA_NO_DISTANCE is a valid value to describe the node distance in the device tree. This is because I hunted down the previous discussions and found [2] about we should try to keep consistent between the value used in device tree and ACPI tables. From the ACPI spec, 0xFF, i.e. NUMA_NO_DISTANCE means unreachable. I think this is also the reason why NUMA_NO_DISTANCE can be used as the default value of the distance map, otherwise we won't have any value to use.

Quoted 47 lines
Quoted 7 lines
xen/arch/arm/numa_device_tree.c +6 -0
+        {
+            /* Bi-directions are not set, set both */
+            numa_set_distance(from, to, distance);
+            numa_set_distance(to, from, distance);
+        }
+        else

xen/arch/arm/numa_device_tree.c invalid_data: · line 231

Quoted 10 lines
xen/arch/arm/numa_device_tree.c +10 -0
+        {
+            /*
+             * Opposite way distance has been set to a different value.
+             * It may be a firmware device tree bug?
+             */
+            if ( opposite != distance )
+            {
+                /*
+                 * In device tree NUMA distance-matrix binding:
+                 *

https://www.kernel.org/doc/Documentation/devicetree/bindings/numa.txt

Quoted 23 lines
xen/arch/arm/numa_device_tree.c +21 -0
+                 * There is a notes mentions:
+                 * "Each entry represents distance from first node to
+                 *  second node. The distances are equal in either
+                 *  direction."
+                 *
+                 * That means device tree doesn't permit this case.
+                 * But in ACPI spec, it cares to specifically permit this
+                 * case:
+                 * "Except for the relative distance from a System Locality
+                 *  to itself, each relative distance is stored twice in the
+                 *  matrix. This provides the capability to describe the
+                 *  scenario where the relative distances for the two
+                 *  directions between System Localities is different."
+                 *
+                 * That means a real machine allows such NUMA configuration.
+                 * So, place a WARNING here to notice system administrators,
+                 * is it the specail case that they hijack the device tree
+                 * to support their rare machines?
+                 */
+                printk(XENLOG_WARNING
+                       "Un-matched bi-direction! NODE#%"PRIu32"-

NODE#%"PRIu32":%"PRIu32", NODE#%"PRIu32"-
NODE#%"PRIu32":%"PRIu32"\n",

xen/arch/arm/numa_device_tree.c invalid_data: · line 252

Quoted 5 lines
xen/arch/arm/numa_device_tree.c +5 -0
+                       from, to, distance, to, from, opposite);
+            }
+
+            /* Opposite way distance has been set, just set this way */
+            numa_set_distance(from, to, distance);
Quoted 4 lines

It took me a while to understand what the comment is to tell me, because in this iteration the opposite entry wasn't set. May I suggest to make more explicit that you refer to an earlier iteration, e.g. by "... was set before, ..."?

Yes, thanks for pointing this out. I will make the comment more explicit as you suggested.

Quoted 9 lines

xen/arch/arm/numa_device_tree.c invalid_data: · line 258

Quoted 7 lines
xen/arch/arm/numa_device_tree.c +6 -0
+        }
+    }
+
+    return 0;
+
+invalid_data:

Nit: Style (labels to be indented by [at least] one blank).

Sure. Will add a space before.

[1] https://lists.xenproject.org/archives/html/xen-devel/2021-09/msg02066.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2023-01/msg00690.html

Kind regards,
Henry

Quoted 2 lines

Jan

#21 lore raw

Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 17 lines · Henry Wang
Quoted 6 lines

-----Original Message-----
From: Jan Beulich <[email protected]>

xen/arch/arm/numa_device_tree.c invalid_data:

Quoted 3 lines
xen/arch/arm/numa_device_tree.c +3 -0
+        /* Get opposite way distance */
+        opposite = __node_distance(to, from);
+        /* The default value in node_distance_map is NUMA_NO_DISTANCE
Quoted 6 lines

*/

Quoted 1 line

+ if ( opposite == NUMA_NO_DISTANCE )

And the matrix you're reading from can't hold NUMA_NO_DISTANCE entries? I ask because you don't check this above; you only check against NUMA_LOCAL_DISTANCE.

My understanding for the purpose of this part of code is to check if the opposite way distance has already been set, so we need to compare the opposite way distance with the default value NUMA_NO_DISTANCE here.

Quoted 7 lines

Back to your question, I can see your point of the question. However I don't think NUMA_NO_DISTANCE is a valid value to describe the node distance in the device tree. This is because I hunted down the previous discussions and found [2] about we should try to keep consistent between the value used in device tree and ACPI tables. From the ACPI spec, 0xFF, i.e. NUMA_NO_DISTANCE means unreachable. I think this is also the reason why NUMA_NO_DISTANCE can be used as the default value of the distance map, otherwise we won't have any value to use.

The [2] link you provided discusses NUMA_LOCAL_DISTANCE. Looking at Linux'es Documentation/devicetree/numa.txt, there's no mention of an upper bound on the distance values. It only says that on the diagonal entries should be 10 (i.e. matching ACPI, without really saying so).

Jan

author
#22 lore raw

RE: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Hi Jan,

Quoted 34 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 6 lines · Henry Wang
Quoted 6 lines

-----Original Message-----
From: Jan Beulich <[email protected]>

Quoted 3 lines
xen/arch/arm/numa_device_tree.c +3 -0
+        /* Get opposite way distance */
+        opposite = __node_distance(to, from);
+        /* The default value in node_distance_map is

NUMA_NO_DISTANCE

Quoted 4 lines
Quoted 4 lines

*/

Quoted 1 line

+ if ( opposite == NUMA_NO_DISTANCE )

And the matrix you're reading from can't hold NUMA_NO_DISTANCE

entries?

Quoted 4 lines
Quoted 2 lines

I ask because you don't check this above; you only check against NUMA_LOCAL_DISTANCE.

My understanding for the purpose of this part of code is to check if the

opposite

Quoted 1 line

way distance has already been set, so we need to compare the opposite

way

Quoted 3 lines

distance with the default value NUMA_NO_DISTANCE here.

Back to your question, I can see your point of the question. However I don't

think

Quoted 1 line

NUMA_NO_DISTANCE is a valid value to describe the node distance in the

device

Quoted 1 line

tree. This is because I hunted down the previous discussions and found [2]

about

Quoted 1 line

we should try to keep consistent between the value used in device tree and

Quoted 8 lines

ACPI

Quoted 1 line

tables. From the ACPI spec, 0xFF, i.e. NUMA_NO_DISTANCE means

unreachable.

Quoted 1 line

I think this is also the reason why NUMA_NO_DISTANCE can be used as the

default

Quoted 1 line

value of the distance map, otherwise we won't have any value to use.

The [2] link you provided discusses NUMA_LOCAL_DISTANCE.

I inferred the discussion as "we should try to keep consistent between the value used in device tree and ACPI tables". Maybe my inference is wrong.

Quoted 4 lines

Looking at
Linux'es Documentation/devicetree/numa.txt, there's no mention of an upper bound on the distance values. It only says that on the diagonal entries should be 10 (i.e. matching ACPI, without really saying so).

I agree that the NUMA device tree binding is a little bit vague. So I cannot say the case that you provided is not valid. I would like to ask Arm maintainers (putting them into To:) opinion on this as I think I am not the one to decide the expected behavior on Arm.

Bertrand/Julien/Stefano: Would you please kindly share your opinion on which value should be used as the default value of the node distance map? Do you think reusing the "unreachable" distance, i.e. 0xFF, as the default node distance is acceptable here? Thanks!

Kind regards,
Henry

Quoted 2 lines

Jan

#23 lore raw

Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 58 lines · Henry Wang

Hi Jan,

Quoted 34 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 6 lines · Henry Wang
Quoted 6 lines

-----Original Message-----
From: Jan Beulich <[email protected]>

Quoted 3 lines
xen/arch/arm/numa_device_tree.c +3 -0
+        /* Get opposite way distance */
+        opposite = __node_distance(to, from);
+        /* The default value in node_distance_map is

NUMA_NO_DISTANCE

Quoted 4 lines
Quoted 4 lines

*/

Quoted 1 line

+ if ( opposite == NUMA_NO_DISTANCE )

And the matrix you're reading from can't hold NUMA_NO_DISTANCE

entries?

Quoted 4 lines
Quoted 2 lines

I ask because you don't check this above; you only check against NUMA_LOCAL_DISTANCE.

My understanding for the purpose of this part of code is to check if the

opposite

Quoted 1 line

way distance has already been set, so we need to compare the opposite

way

Quoted 3 lines

distance with the default value NUMA_NO_DISTANCE here.

Back to your question, I can see your point of the question. However I don't

think

Quoted 1 line

NUMA_NO_DISTANCE is a valid value to describe the node distance in the

device

Quoted 1 line

tree. This is because I hunted down the previous discussions and found [2]

about

Quoted 1 line

we should try to keep consistent between the value used in device tree and

Quoted 8 lines

ACPI

Quoted 1 line

tables. From the ACPI spec, 0xFF, i.e. NUMA_NO_DISTANCE means

unreachable.

Quoted 1 line

I think this is also the reason why NUMA_NO_DISTANCE can be used as the

default

Quoted 1 line

value of the distance map, otherwise we won't have any value to use.

The [2] link you provided discusses NUMA_LOCAL_DISTANCE.

I inferred the discussion as "we should try to keep consistent between the value used in device tree and ACPI tables". Maybe my inference is wrong.

Quoted 4 lines

Looking at
Linux'es Documentation/devicetree/numa.txt, there's no mention of an upper bound on the distance values. It only says that on the diagonal entries should be 10 (i.e. matching ACPI, without really saying so).

I agree that the NUMA device tree binding is a little bit vague. So I cannot say the case that you provided is not valid. I would like to ask Arm maintainers (putting them into To:) opinion on this as I think I am not the one to decide the expected behavior on Arm.

Quoted 4 lines

Bertrand/Julien/Stefano: Would you please kindly share your opinion on which value should be used as the default value of the node distance map? Do you think reusing the "unreachable" distance, i.e. 0xFF, as the default node distance is acceptable here? Thanks!

My suggestion would be to, rather than rejecting values >= 0xff, to saturate at 0xfe, while keeping 0xff for NUMA_NO_DISTANCE (and overall keeping things consistent with ACPI).

Jan

author
#24 lore raw

RE: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Hi Jan,

Quoted 60 lines

-----Original Message-----
Subject: Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ /* The default value in node_distance_map is

NUMA_NO_DISTANCE

Quoted 4 lines
Quoted 4 lines

*/

Quoted 1 line

+ if ( opposite == NUMA_NO_DISTANCE )

And the matrix you're reading from can't hold NUMA_NO_DISTANCE

entries?

Quoted 3 lines
Quoted 2 lines

I ask because you don't check this above; you only check against NUMA_LOCAL_DISTANCE.

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

My understanding for the purpose of this part of code is to check if the

opposite

Quoted 1 line

way distance has already been set, so we need to compare the opposite

way

Quoted 3 lines

distance with the default value NUMA_NO_DISTANCE here.

Back to your question, I can see your point of the question. However I

don't

Quoted 4 lines
Quoted 4 lines

think

Quoted 1 line

NUMA_NO_DISTANCE is a valid value to describe the node distance in the

device

Quoted 1 line

tree. This is because I hunted down the previous discussions and found

[2]

Quoted 2 lines
Quoted 2 lines

about

Quoted 1 line

we should try to keep consistent between the value used in device tree

and

Quoted 4 lines
Quoted 4 lines

ACPI

Quoted 1 line

tables. From the ACPI spec, 0xFF, i.e. NUMA_NO_DISTANCE means

unreachable.

Quoted 1 line

I think this is also the reason why NUMA_NO_DISTANCE can be used as

the

Quoted 6 lines
Quoted 4 lines

default

Quoted 1 line

value of the distance map, otherwise we won't have any value to use.

The [2] link you provided discusses NUMA_LOCAL_DISTANCE.

I inferred the discussion as "we should try to keep consistent between the

value

Quoted 9 lines

used in device tree and ACPI tables". Maybe my inference is wrong.

Quoted 4 lines

Looking at
Linux'es Documentation/devicetree/numa.txt, there's no mention of an upper bound on the distance values. It only says that on the diagonal entries should be 10 (i.e. matching ACPI, without really saying so).

I agree that the NUMA device tree binding is a little bit vague. So I cannot say the case that you provided is not valid. I would like to ask Arm

maintainers

Quoted 1 line

(putting them into To:) opinion on this as I think I am not the one to decide

the

Quoted 3 lines

expected behavior on Arm.

Bertrand/Julien/Stefano: Would you please kindly share your opinion on

which

Quoted 1 line

value should be used as the default value of the node distance map? Do

you

Quoted 8 lines
Quoted 1 line

think reusing the "unreachable" distance, i.e. 0xFF, as the default node

distance

Quoted 1 line

is acceptable here? Thanks!

My suggestion would be to, rather than rejecting values >= 0xff, to saturate at 0xfe, while keeping 0xff for NUMA_NO_DISTANCE (and overall keeping things
consistent with ACPI).

Since it has been a while and there were no feedback from Arm maintainers, I would like to follow your suggestions for v5. However while I was writing the code for the "saturation", i.e., adding below snippet in numa_set_distance():

```
if ( distance > NUMA_NO_DISTANCE )
        distance = NUMA_MAX_DISTANCE;
```

I noticed an issue which needs your clarification:
Currently, the default value of the distance map is NUMA_NO_DISTANCE, which indicates the nodes are not reachable. IMHO, if in device tree, we do saturations like above for ACPI invalid distances (distances >= 0xff), by saturating the distance to 0xfe, we are making the unreachable nodes to reachable. I am not sure if this will lead to problems. Do you have any more thoughts? Thanks!

Kind regards,
Henry

Quoted 2 lines

Jan

#25 lore raw

Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 76 lines · Henry Wang
Quoted 60 lines

-----Original Message-----
Subject: Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ /* The default value in node_distance_map is

NUMA_NO_DISTANCE

Quoted 4 lines
Quoted 4 lines

*/

Quoted 1 line

+ if ( opposite == NUMA_NO_DISTANCE )

And the matrix you're reading from can't hold NUMA_NO_DISTANCE

entries?

Quoted 3 lines
Quoted 2 lines

I ask because you don't check this above; you only check against NUMA_LOCAL_DISTANCE.

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

My understanding for the purpose of this part of code is to check if the

opposite

Quoted 1 line

way distance has already been set, so we need to compare the opposite

way

Quoted 3 lines

distance with the default value NUMA_NO_DISTANCE here.

Back to your question, I can see your point of the question. However I

don't

Quoted 4 lines
Quoted 4 lines

think

Quoted 1 line

NUMA_NO_DISTANCE is a valid value to describe the node distance in the

device

Quoted 1 line

tree. This is because I hunted down the previous discussions and found

[2]

Quoted 2 lines
Quoted 2 lines

about

Quoted 1 line

we should try to keep consistent between the value used in device tree

and

Quoted 4 lines
Quoted 4 lines

ACPI

Quoted 1 line

tables. From the ACPI spec, 0xFF, i.e. NUMA_NO_DISTANCE means

unreachable.

Quoted 1 line

I think this is also the reason why NUMA_NO_DISTANCE can be used as

the

Quoted 6 lines
Quoted 4 lines

default

Quoted 1 line

value of the distance map, otherwise we won't have any value to use.

The [2] link you provided discusses NUMA_LOCAL_DISTANCE.

I inferred the discussion as "we should try to keep consistent between the

value

Quoted 9 lines

used in device tree and ACPI tables". Maybe my inference is wrong.

Quoted 4 lines

Looking at
Linux'es Documentation/devicetree/numa.txt, there's no mention of an upper bound on the distance values. It only says that on the diagonal entries should be 10 (i.e. matching ACPI, without really saying so).

I agree that the NUMA device tree binding is a little bit vague. So I cannot say the case that you provided is not valid. I would like to ask Arm

maintainers

Quoted 1 line

(putting them into To:) opinion on this as I think I am not the one to decide

the

Quoted 3 lines

expected behavior on Arm.

Bertrand/Julien/Stefano: Would you please kindly share your opinion on

which

Quoted 1 line

value should be used as the default value of the node distance map? Do

you

Quoted 8 lines
Quoted 1 line

think reusing the "unreachable" distance, i.e. 0xFF, as the default node

distance

Quoted 1 line

is acceptable here? Thanks!

My suggestion would be to, rather than rejecting values >= 0xff, to saturate at 0xfe, while keeping 0xff for NUMA_NO_DISTANCE (and overall keeping things
consistent with ACPI).

Since it has been a while and there were no feedback from Arm maintainers, I would like to follow your suggestions for v5. However while I was writing the code for the "saturation", i.e., adding below snippet in numa_set_distance():

```
if ( distance > NUMA_NO_DISTANCE )
        distance = NUMA_MAX_DISTANCE;
```
Quoted 6 lines

I noticed an issue which needs your clarification:
Currently, the default value of the distance map is NUMA_NO_DISTANCE, which indicates the nodes are not reachable. IMHO, if in device tree, we do saturations like above for ACPI invalid distances (distances >= 0xff), by saturating the distance to 0xfe, we are making the unreachable nodes to reachable. I am not sure if this will lead to problems. Do you have any more thoughts? Thanks!

I can only answer this with a question back: How is "unreachable" represented in DT? Or is "unreachable" simply expressed by the absence of any data?

Jan

author
#26 lore raw

RE: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Hi Jan,

Quoted 51 lines

-----Original Message-----
Subject: Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 1 line

The [2] link you provided discusses NUMA_LOCAL_DISTANCE.

I inferred the discussion as "we should try to keep consistent between the

value

Quoted 7 lines

used in device tree and ACPI tables". Maybe my inference is wrong.

Quoted 4 lines

Looking at
Linux'es Documentation/devicetree/numa.txt, there's no mention of an upper bound on the distance values. It only says that on the diagonal entries should be 10 (i.e. matching ACPI, without really saying so).

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

I agree that the NUMA device tree binding is a little bit vague. So I cannot say the case that you provided is not valid. I would like to ask Arm

maintainers

Quoted 1 line

(putting them into To:) opinion on this as I think I am not the one to

decide

Quoted 9 lines
Quoted 9 lines

the

Quoted 3 lines

expected behavior on Arm.

Bertrand/Julien/Stefano: Would you please kindly share your opinion on

which

Quoted 1 line

value should be used as the default value of the node distance map? Do

you

Quoted 1 line

think reusing the "unreachable" distance, i.e. 0xFF, as the default node

distance

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

is acceptable here? Thanks!

My suggestion would be to, rather than rejecting values >= 0xff, to saturate at 0xfe, while keeping 0xff for NUMA_NO_DISTANCE (and overall keeping things
consistent with ACPI).

Since it has been a while and there were no feedback from Arm

maintainers,

Quoted 1 line

I would like to follow your suggestions for v5. However while I was writing

the

Quoted 1 line

code for the "saturation", i.e., adding below snippet in

numa_set_distance():

Quoted 8 lines
```
if ( distance > NUMA_NO_DISTANCE )
        distance = NUMA_MAX_DISTANCE;
```

I noticed an issue which needs your clarification:
Currently, the default value of the distance map is NUMA_NO_DISTANCE, which indicates the nodes are not reachable. IMHO, if in device tree, we do saturations like above for ACPI invalid distances (distances >= 0xff), by

saturating

Quoted 8 lines
Quoted 1 line

the distance to 0xfe, we are making the unreachable nodes to reachable. I

am

Quoted 1 line

not sure if this will lead to problems. Do you have any more thoughts?

Thanks!

I can only answer this with a question back: How is "unreachable" represented
in DT?

Exactly, that is also what we I am trying to find but failed. My understanding is that, the spec of NUMA is defined in the ACPI, and the DT NUMA binding only specifies how users can use DT to represent the same set of ACPI data, instead of define another standard.

By looking into the existing implementation of NUMA for DT,
in Linux, from drivers/base/arch_numa.c: numa_set_distance(), there is a "if ((u8)distance != distance)" then return. So I think at least in Linux the distance value is consistent with the ACPI spec.

Quoted 1 line

Or is "unreachable" simply expressed by the absence of any data?

Maybe I am wrong but I don't think so, as in the Linux implementation, drivers/of/of_numa.c: of_numa_parse_distance_map_v1(), the for loop "for (i = 0; i + 2 < entry_count; i += 3)" basically implies no fields should be omitted in the distance map entry.

Kind regards,
Henry

Quoted 2 lines

Jan

#27 lore raw

Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 65 lines · Henry Wang
Quoted 51 lines

-----Original Message-----
Subject: Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 1 line

The [2] link you provided discusses NUMA_LOCAL_DISTANCE.

I inferred the discussion as "we should try to keep consistent between the

value

Quoted 7 lines

used in device tree and ACPI tables". Maybe my inference is wrong.

Quoted 4 lines

Looking at
Linux'es Documentation/devicetree/numa.txt, there's no mention of an upper bound on the distance values. It only says that on the diagonal entries should be 10 (i.e. matching ACPI, without really saying so).

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

I agree that the NUMA device tree binding is a little bit vague. So I cannot say the case that you provided is not valid. I would like to ask Arm

maintainers

Quoted 1 line

(putting them into To:) opinion on this as I think I am not the one to

decide

Quoted 9 lines
Quoted 9 lines

the

Quoted 3 lines

expected behavior on Arm.

Bertrand/Julien/Stefano: Would you please kindly share your opinion on

which

Quoted 1 line

value should be used as the default value of the node distance map? Do

you

Quoted 1 line

think reusing the "unreachable" distance, i.e. 0xFF, as the default node

distance

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

is acceptable here? Thanks!

My suggestion would be to, rather than rejecting values >= 0xff, to saturate at 0xfe, while keeping 0xff for NUMA_NO_DISTANCE (and overall keeping things
consistent with ACPI).

Since it has been a while and there were no feedback from Arm

maintainers,

Quoted 1 line

I would like to follow your suggestions for v5. However while I was writing

the

Quoted 1 line

code for the "saturation", i.e., adding below snippet in

numa_set_distance():

Quoted 8 lines
```
if ( distance > NUMA_NO_DISTANCE )
        distance = NUMA_MAX_DISTANCE;
```

I noticed an issue which needs your clarification:
Currently, the default value of the distance map is NUMA_NO_DISTANCE, which indicates the nodes are not reachable. IMHO, if in device tree, we do saturations like above for ACPI invalid distances (distances >= 0xff), by

saturating

Quoted 8 lines
Quoted 1 line

the distance to 0xfe, we are making the unreachable nodes to reachable. I

am

Quoted 1 line

not sure if this will lead to problems. Do you have any more thoughts?

Thanks!

I can only answer this with a question back: How is "unreachable" represented
in DT?

Exactly, that is also what we I am trying to find but failed. My understanding is that, the spec of NUMA is defined in the ACPI, and the DT NUMA binding only specifies how users can use DT to represent the same set of ACPI data, instead of define another standard.

Quoted 4 lines

By looking into the existing implementation of NUMA for DT,
in Linux, from drivers/base/arch_numa.c: numa_set_distance(), there is a "if ((u8)distance != distance)" then return. So I think at least in Linux the distance value is consistent with the ACPI spec.

Can we simply gain a similar check (suitably commented), eliminating the need for saturation?

Jan

Quoted 9 lines
Quoted 1 line

Or is "unreachable" simply expressed by the absence of any data?

Maybe I am wrong but I don't think so, as in the Linux implementation, drivers/of/of_numa.c: of_numa_parse_distance_map_v1(), the for loop "for (i = 0; i + 2 < entry_count; i += 3)" basically implies no fields should be omitted in the distance map entry.

Kind regards,
Henry

author
#28 lore raw

RE: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Hi Jan,

Quoted 9 lines

-----Original Message-----

Quoted 4 lines · Henry Wang

By looking into the existing implementation of NUMA for DT,
in Linux, from drivers/base/arch_numa.c: numa_set_distance(), there is a "if ((u8)distance != distance)" then return. So I think at least in Linux the distance value is consistent with the ACPI spec.

Can we simply gain a similar check (suitably commented), eliminating the need for saturation?

Yes, I will use the similar check and add the related comments in v5. Thanks for your confirmation!

Kind regards,
Henry

Quoted 2 lines

Jan

#29 lore raw

Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

In reply to Henry Wang
Quoted 37 lines · Henry Wang
xen/arch/arm/numa_device_tree.c +31 -0
@@ -151,3 +151,111 @@ 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 = fdt_get_property(fdt, node, "distance-matrix", &len);
+    if ( !prop )
+    {
+        printk(XENLOG_WARNING
+               "NUMA: No distance-matrix property in distance-map\n");
+        goto invalid_data;
+    }
+
+    if ( len % sizeof(__be32) != 0 )
+    {
+        printk(XENLOG_WARNING
+               "distance-matrix in node is not a multiple of u32\n");
+        goto invalid_data;
+    }
+
+    entry_count = len / sizeof(__be32);
+    if ( entry_count == 0 )
+    {
+        printk(XENLOG_WARNING "NUMA: Invalid distance-matrix\n");
+        goto invalid_data;

xen/arch/arm/numa_device_tree.c invalid_data: · line 194

Quoted 10 lines
xen/arch/arm/numa_device_tree.c +10 -0
+    }
+
+    matrix = (const __be32 *)prop->data;
+    for ( i = 0; i + 2 < entry_count; i += 3 )
+    {
+        unsigned int from, to, distance, opposite;
+
+        from = dt_next_cell(1, &matrix);
+        to = dt_next_cell(1, &matrix);
+        distance = dt_next_cell(1, &matrix);

Upon second thought I checked what dt_next_cell() returns: You're silently truncating here and then ...

Quoted 10 lines
xen/arch/arm/numa_device_tree.c +10 -0
+        if ( (from == to && distance != NUMA_LOCAL_DISTANCE) ||
+             (from != to && distance <= 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",

xen/arch/arm/numa_device_tree.c invalid_data: · line 214

Quoted 10 lines
xen/arch/arm/numa_device_tree.c +10 -0
+               from, to, distance);
+
+        /* Get opposite way distance */
+        opposite = __node_distance(to, from);
+        /* The default value in node_distance_map is NUMA_NO_DISTANCE */
+        if ( opposite == NUMA_NO_DISTANCE )
+        {
+            /* Bi-directions are not set, set both */
+            numa_set_distance(from, to, distance);
+            numa_set_distance(to, from, distance);

... here again. Is that really the intention?

Jan

author
#30 lore raw

RE: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Hi Jan,

Quoted 7 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 1 line

+ distance = dt_next_cell(1, &matrix);

Quoted 8 lines

Upon second thought I checked what dt_next_cell() returns: You're silently truncating here and then ...

xen/arch/arm/numa_device_tree.c invalid_data: · line 214

Quoted 3 lines
xen/arch/arm/numa_device_tree.c +3 -0
+            /* Bi-directions are not set, set both */
+            numa_set_distance(from, to, distance);
+            numa_set_distance(to, from, distance);

... here again. Is that really the intention?

By hunting down the historical discussions I found that using dt_next_cell() is what Julien suggested 2 years ago in the RFC series [1]. Given the truncation here is for node id (from/to) and distance which I am pretty sure will not exceed 32-bit range, I think the silent truncation is safe.

However I understand your point here, the silent truncation is not ideal, so I wonder if you have any suggestions to improve, do you think I should change these variables to u64 or maybe I need to do the explicit type cast or any better suggestions from you? Thanks!

[1] https://lists.xenproject.org/archives/html/xen-devel/2021-08/msg01175.html

Kind regards,
Henry

Quoted 2 lines

Jan

#31 lore raw

Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 12 lines · Henry Wang
Quoted 12 lines

-----Original Message-----
From: Jan Beulich <[email protected]>

Quoted 1 line

+ distance = dt_next_cell(1, &matrix);

Upon second thought I checked what dt_next_cell() returns: You're silently truncating here and then ...

Quoted 3 lines
xen/arch/arm/numa_device_tree.c +3 -0
+            /* Bi-directions are not set, set both */
+            numa_set_distance(from, to, distance);
+            numa_set_distance(to, from, distance);
Quoted 6 lines
Quoted 1 line

... here again. Is that really the intention?

By hunting down the historical discussions I found that using dt_next_cell() is what Julien suggested 2 years ago in the RFC series [1]. Given the truncation here is for node id (from/to) and distance which I am pretty sure will not exceed 32-bit range, I think the silent truncation is safe.

That discussion is orthogonal; the previously used dt_read_number() is no different in the regard I'm referring to.

Quoted 4 lines

However I understand your point here, the silent truncation is not ideal, so I wonder if you have any suggestions to improve, do you think I should change these variables to u64 or maybe I need to do the explicit type cast or any better suggestions from you? Thanks!

So one thing I overlooked is that by passing 1 as the first argument, you only request a 32-bit value. Hence there's no (silent) truncation then on the dt_next_cell() uses. But the numa_set_distance() calls still truncate to 8 bits. Adding explicit type casts won't help at all - truncation will remain as silent as it was before. However, numa_set_distance()'s first two arguments could easily become "unsigned int", resulting in its node related bounds checking to take care of all truncation issues. The "distance" parameter already is unsigned int, and is already being bounds checked against NUMA_NO_DISTANCE.

Jan

Quoted 4 lines

[1] https://lists.xenproject.org/archives/html/xen-devel/2021-08/msg01175.html

Kind regards,
Henry

author
#32 lore raw

RE: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Hi Jan,

Quoted 35 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 8 lines · Henry Wang
Quoted 8 lines

-----Original Message-----
From: Jan Beulich <[email protected]>

Quoted 1 line

+ distance = dt_next_cell(1, &matrix);

Upon second thought I checked what dt_next_cell() returns: You're silently truncating here and then ...

Quoted 7 lines
Quoted 5 lines

xen/arch/arm/numa_device_tree.c invalid_data: · line 214

Quoted 3 lines
xen/arch/arm/numa_device_tree.c +3 -0
+            /* Bi-directions are not set, set both */
+            numa_set_distance(from, to, distance);
+            numa_set_distance(to, from, distance);

... here again. Is that really the intention?

By hunting down the historical discussions I found that using dt_next_cell()

is

Quoted 3 lines

what Julien suggested 2 years ago in the RFC series [1]. Given the truncation here is for node id (from/to) and distance which I am pretty sure will not exceed 32-bit range, I think the silent truncation is safe.

That discussion is orthogonal; the previously used dt_read_number() is no different in the regard I'm referring to.

Quoted 2 lines

However I understand your point here, the silent truncation is not ideal, so I wonder if you have any suggestions to improve, do you think I should

change

Quoted 2 lines

these variables to u64 or maybe I need to do the explicit type cast or any better suggestions from you? Thanks!

Quoted 9 lines

So one thing I overlooked is that by passing 1 as the first argument, you only request a 32-bit value. Hence there's no (silent) truncation then on the dt_next_cell() uses. But the numa_set_distance() calls still truncate to 8 bits. Adding explicit type casts won't help at all - truncation will remain as silent as it was before. However, numa_set_distance()'s first two arguments could easily become "unsigned int", resulting in its node related bounds checking to take care of all truncation issues. The "distance" parameter already is unsigned int, and is already being bounds checked against NUMA_NO_DISTANCE.

Great points! Thanks for pointing the 8-bit truncation out. You are correct. Somehow my impression of numa_set_distance()'s first two arguments are already "unsigned int" so I missed this part...Sorry.

In that case, I think I will add a check between "from, to" and MAX_NUMNODES as soon as the values of "from" and "to" are populated by dt_next_cell(). Hopefully this will address your concern.

Kind regards,
Henry

Quoted 8 lines

Jan

Quoted 1 line

[1] https://lists.xenproject.org/archives/html/xen-devel/2021-

08/msg01175.html

Quoted 3 lines

Kind regards,
Henry

#33 lore raw

Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 43 lines · Henry Wang
Quoted 33 lines

-----Original Message-----
From: Jan Beulich <[email protected]>

Quoted 8 lines · Henry Wang
Quoted 8 lines

-----Original Message-----
From: Jan Beulich <[email protected]>

Quoted 1 line

+ distance = dt_next_cell(1, &matrix);

Upon second thought I checked what dt_next_cell() returns: You're silently truncating here and then ...

Quoted 7 lines
Quoted 5 lines

xen/arch/arm/numa_device_tree.c invalid_data: · line 214

Quoted 3 lines
xen/arch/arm/numa_device_tree.c +3 -0
+            /* Bi-directions are not set, set both */
+            numa_set_distance(from, to, distance);
+            numa_set_distance(to, from, distance);

... here again. Is that really the intention?

By hunting down the historical discussions I found that using dt_next_cell()

is

Quoted 3 lines

what Julien suggested 2 years ago in the RFC series [1]. Given the truncation here is for node id (from/to) and distance which I am pretty sure will not exceed 32-bit range, I think the silent truncation is safe.

That discussion is orthogonal; the previously used dt_read_number() is no different in the regard I'm referring to.

Quoted 2 lines

However I understand your point here, the silent truncation is not ideal, so I wonder if you have any suggestions to improve, do you think I should

change

Quoted 2 lines

these variables to u64 or maybe I need to do the explicit type cast or any better suggestions from you? Thanks!

Quoted 9 lines

So one thing I overlooked is that by passing 1 as the first argument, you only request a 32-bit value. Hence there's no (silent) truncation then on the dt_next_cell() uses. But the numa_set_distance() calls still truncate to 8 bits. Adding explicit type casts won't help at all - truncation will remain as silent as it was before. However, numa_set_distance()'s first two arguments could easily become "unsigned int", resulting in its node related bounds checking to take care of all truncation issues. The "distance" parameter already is unsigned int, and is already being bounds checked against NUMA_NO_DISTANCE.

Quoted 7 lines

Great points! Thanks for pointing the 8-bit truncation out. You are correct. Somehow my impression of numa_set_distance()'s first two arguments are already "unsigned int" so I missed this part...Sorry.

In that case, I think I will add a check between "from, to" and MAX_NUMNODES as soon as the values of "from" and "to" are populated by dt_next_cell(). Hopefully this will address your concern.

While this would address by concern, I don't see why you want to repeat the checking that numa_set_distance() already does.

Jan

author
#34 lore raw

RE: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Hi Jan,

Quoted 9 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 4 lines

Great points! Thanks for pointing the 8-bit truncation out. You are correct. Somehow my impression of numa_set_distance()'s first two arguments are already "unsigned int" so I missed this part...Sorry.

Quoted 7 lines
Quoted 1 line

In that case, I think I will add a check between "from, to" and

MAX_NUMNODES

Quoted 2 lines

as soon as the values of "from" and "to" are populated by dt_next_cell(). Hopefully this will address your concern.

While this would address by concern, I don't see why you want to repeat the checking that numa_set_distance() already does.

Correct, I think I would better to move the check in numa_set_distance() to the caller fdt_parse_numa_distance_map_v1() as I believe if the truncation really happens it is too late to check in numa_set_distance().

Kind regards,
Henry

Quoted 2 lines

Jan

author
#35 lore raw

RE: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Hi Jan

Quoted 22 lines

-----Original Message-----
From: Henry Wang
Subject: RE: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Hi Jan,

Quoted 7 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: Re: [PATCH v4 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map

Quoted 2 lines

Great points! Thanks for pointing the 8-bit truncation out. You are correct. Somehow my impression of numa_set_distance()'s first two arguments

are

Quoted 7 lines
Quoted 3 lines

already "unsigned int" so I missed this part...Sorry.

In that case, I think I will add a check between "from, to" and

MAX_NUMNODES

Quoted 2 lines

as soon as the values of "from" and "to" are populated by dt_next_cell(). Hopefully this will address your concern.

Quoted 6 lines
Quoted 2 lines

While this would address by concern, I don't see why you want to repeat the checking that numa_set_distance() already does.

Correct, I think I would better to move the check in numa_set_distance() to the caller fdt_parse_numa_distance_map_v1() as I believe if the truncation really happens it is too late to check in numa_set_distance().

On second thought, maybe even remove the same check in __node_distance() if we do the check in the caller, as I believe they will suffer the same problem...

Kind regards,
Henry

Quoted 6 lines

Kind regards,
Henry

Quoted 2 lines

Jan

author
#36 lore raw

PATCH v4 10/17 xen/arm: unified entry to parse all NUMA data from device tree

In reply to Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
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(+)
xen/arch/arm/include/asm/numa.h +1 -0
index 2987158d16..15308f5a36 100644
@@ -44,6 +44,7 @@ extern bool numa_disabled(void);
 extern void numa_set_distance(nodeid_t from, nodeid_t to,
                               unsigned int distance);
 extern void numa_detect_cpu_node(unsigned int cpu);
+extern int numa_device_tree_init(const void *fdt);
 
 #else
 
xen/arch/arm/numa_device_tree.c +30 -0
index 9d9d09273e..bf5f112b92 100644
@@ -259,3 +259,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 = 0;
+    const void *prop;
+
+    prop = fdt_getprop(fdt, node, "device_type", &len);
+    if ( prop )
+    {
+        if ( strncmp(prop, "cpu", len) == 0 )
+            ret = fdt_parse_numa_cpu_node(fdt, node);
+        else if ( strncmp(prop, "memory", len) == 0 )
+            ret = fdt_parse_numa_memory_node(fdt, node, uname,
+                                address_cells, size_cells);
+    }
+    else if ( fdt_node_check_compatible(fdt, node,
+                                        "numa-distance-map-v1") == 0 )
+        ret = fdt_parse_numa_distance_map_v1(fdt, node);
+
+    return ret;
+}
+
+/* Initialize NUMA from device tree */
+int __init numa_device_tree_init(const void *fdt)
+{
+    return device_tree_for_each_node(fdt, 0, fdt_scan_numa_nodes, NULL);
+}
Signature · 1 line
2.25.1
author
#37 lore raw

PATCH v4 11/17 xen/arm: keep guest still be NUMA unware

In reply to Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
v2 -> v3:
1. No change.
v1 -> v2:
1. Add Rb

---
 xen/arch/arm/domain_build.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/arm/domain_build.c +6 -0
index f80fdd1af2..2bf586fc45 100644
@@ -1185,6 +1185,10 @@ static int __init write_properties(struct domain *d, struct kernel_info *kinfo,
                 continue;
         }
 
+        /* Dom0 is currently NUMA unaware */
+        if ( dt_property_name_is_equal(prop, "numa-node-id") )
+            continue;
+
         res = fdt_property(kinfo->fdt, prop->name, prop_data, prop_len);
 
         if ( res )
@@ -2567,6 +2571,8 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
         DT_MATCH_TYPE("memory"),
         /* The memory mapped timer is not supported by Xen. */
         DT_MATCH_COMPATIBLE("arm,armv7-timer-mem"),
+        /* Numa info doesn't need to be exposed to Domain-0 */
+        DT_MATCH_COMPATIBLE("numa-distance-map-v1"),
         { /* sentinel */ },
     };
     static const struct dt_device_match timer_matches[] __initconst =
Signature · 1 line
2.25.1
author
#38 lore raw

PATCH v4 12/17 xen/arm: enable device tree based NUMA in system init

In reply to Henry Wang

From: Wei Chen <[email protected]>

In this patch, we can start to create NUMA system that is based on device tree.

---
v3 -> v4:
1. No change.
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(+)
xen/arch/arm/include/asm/numa.h +5 -0
index 15308f5a36..55ac4665db 100644
@@ -45,6 +45,7 @@ extern void numa_set_distance(nodeid_t from, nodeid_t to,
                               unsigned int distance);
 extern void numa_detect_cpu_node(unsigned int cpu);
 extern int numa_device_tree_init(const void *fdt);
+extern void numa_init(void);
 
 #else
 
@@ -90,6 +91,10 @@ static inline void numa_detect_cpu_node(unsigned int cpu)
 {
 }
 
+static inline void numa_init(void)
+{
+}
+
 #endif
 
 #define arch_want_default_dmazone() (false)
xen/arch/arm/numa.c +57 -0

70 lines not on this page · raw message

xen/arch/arm/setup.c +7 -0
index 09e18d32df..f05e233f3a 100644
@@ -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();
 
+    /*
+     * 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();
 
     /*
Signature · 1 line
2.25.1
author
#39 lore raw

PATCH v4 13/17 xen/arm: implement numa_node_to_arch_nid for device tree NUMA

In reply to Henry Wang

From: Wei Chen <[email protected]>

Device tree based NUMA doesn't have the proximity domain like ACPI. So we can return node id directly as arch nid.

---
v3 -> v4:
1. No change.
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(+)
xen/arch/arm/include/asm/numa.h +9 -0
index 55ac4665db..71b95a9a62 100644
@@ -47,6 +47,15 @@ extern void numa_detect_cpu_node(unsigned int cpu);
 extern int numa_device_tree_init(const void *fdt);
 extern void numa_init(void);
 
+/*
+ * Device tree NUMA doesn't have architecural node id.
+ * So we can just return node id as arch nid.
+ */
+static inline unsigned int numa_node_to_arch_nid(nodeid_t n)
+{
+    return n;
+}
+
 #else
 
 /* Fake one node for now. See also node_online_map. */
Signature · 1 line
2.25.1
author
#40 lore raw

PATCH v4 14/17 xen/arm: use CONFIG_NUMA to gate node_online_map in smpboot

In reply to Henry Wang

From: Wei Chen <[email protected]>

node_online_map in smpboot is still needed for Arm when NUMA is turned off by Kconfig.

---
v3 -> v4:
1. No change.
v2 -> v3:
1. No change.
v1 -> v2:
1. No change.

---
 xen/arch/arm/smpboot.c | 2 ++
 1 file changed, 2 insertions(+)
xen/arch/arm/smpboot.c +2 -0
index da7f2afd97..4f71cc974a 100644
@@ -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] = { [0 ... NR_CPUS-1] = MPIDR_INVALID };
 
+#ifndef CONFIG_NUMA
 /* Fake one node for now. See also asm/numa.h */
 nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };
+#endif
 
 /* Xen stack for bringing up the first CPU. */
 static unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
Signature · 1 line
2.25.1
author
#41 lore raw

PATCH v4 15/17 xen/arm: Set correct per-cpu cpu_core_mask

In reply to Henry Wang

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.

---
v3 -> v4:
1. No change.
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(+)
xen/arch/arm/include/asm/numa.h +7 -0
index 71b95a9a62..d4c89909d0 100644
@@ -46,6 +46,7 @@ extern void numa_set_distance(nodeid_t from, nodeid_t to,
 extern void numa_detect_cpu_node(unsigned int cpu);
 extern int numa_device_tree_init(const void *fdt);
 extern void numa_init(void);
+extern void numa_set_cpu_core_mask(int cpu);
 
 /*
  * Device tree NUMA doesn't have architecural node id.
@@ -62,6 +63,12 @@ static inline unsigned int numa_node_to_arch_nid(nodeid_t n)
 #define cpu_to_node(cpu) 0
 #define node_to_cpumask(node)   (cpu_online_map)
 
+static inline void numa_set_cpu_core_mask(int cpu)
+{
+    cpumask_or(per_cpu(cpu_core_mask, cpu),
+               per_cpu(cpu_core_mask, cpu), &cpu_possible_map);
+}
+
 /*
  * TODO: make first_valid_mfn static when NUMA is supported on Arm, this
  * is required because the dummy helpers are using it.
xen/arch/arm/numa.c +11 -0
index f4635e0277..74e4dc2c67 100644
@@ -53,6 +53,17 @@ int __init arch_numa_setup(const char *opt)
     return -EINVAL;
 }
 
+void numa_set_cpu_core_mask(int cpu)
+{
+    nodeid_t node = cpu_to_node[cpu];
+
+    if ( node == NUMA_NO_NODE )
+        node = 0;
+
+    cpumask_or(per_cpu(cpu_core_mask, cpu),
+               per_cpu(cpu_core_mask, cpu), &node_to_cpumask(node));
+}
+
 void __init numa_set_distance(nodeid_t from, nodeid_t to,
                               unsigned int distance)
 {
xen/arch/arm/setup.c +5 -0
index f05e233f3a..7cef913b7c 100644
@@ -1226,6 +1226,11 @@ void __init start_xen(unsigned long boot_phys_offset,
     }
 
     printk("Brought up %ld CPUs\n", (long)num_online_cpus());
+
+    /* Set per-cpu cpu_core_mask to cpus that belongs to the same NUMA node. */
+    for_each_online_cpu ( i )
+        numa_set_cpu_core_mask(i);
+
     /* TODO: smp_cpus_done(); */
 
     /* This should be done in a vpmu driver but we do not have one yet. */
Signature · 1 line
2.25.1
author
#42 lore raw

PATCH v4 16/17 xen/arm: Provide Kconfig options for Arm to enable NUMA

In reply to Henry Wang

From: Wei Chen <[email protected]>

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.

---
v3 -> v4:
1. No change.
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(+)
xen/arch/arm/Kconfig +11 -0
index 239d3aed3c..e751ad50d1 100644
@@ -39,6 +39,17 @@ config ACPI
 config ARM_EFI
 	bool
 
+config ARM_NUMA
+	bool "Arm NUMA (Non-Uniform Memory Access) Support (UNSUPPORTED)" if UNSUPPORTED
+	depends on HAS_DEVICE_TREE
+	select DEVICE_TREE_NUMA
+	help
+	  Enable Non-Uniform Memory Access (NUMA) for Arm architecutres
+
+config DEVICE_TREE_NUMA
+	bool
+	select NUMA
+
 config GICV3
 	bool "GICv3 driver"
 	depends on !NEW_VGIC
Signature · 1 line
2.25.1
author
#43 lore raw

PATCH v4 17/17 docs: update numa command line to support Arm

In reply to Henry Wang

From: Wei Chen <[email protected]>

Current numa command in documentation is x86 only. Remove x86 from numa command's arch limitation in this patch.

---
v3 -> v4:
1. No change.
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(-)
SUPPORT.md +1 -0
index aa1940e55f..da4e3b9aa2 100644
@@ -401,6 +401,7 @@ on embedded platforms and the x86 PV shim.
 Enables NUMA aware scheduling in Xen
 
     Status, x86: Supported
+    Status, Arm: Tech Preview
 
 ## Scalability
 
docs/misc/xen-command-line.pandoc +1 -1
index e0b89b7d33..2fea22dd70 100644
@@ -1890,7 +1890,7 @@ i.e. a limit on the number of guests it is possible to start each having
 assigned a device sharing a common interrupt line.  Accepts values between
 1 and 255.
 
-### numa (x86)
+### numa
 > `= on | off | fake=<integer> | noacpi`
 
 > Default: `on`
Signature · 1 line
2.25.1