Skip to contentSkip to conversation

arm64, numa: Add numa support for arm64 platforms

PATCH Superseded David Daney 6 participants 22 messages Feb 20, 2016 – Mar 1, 2016

Subsystems (4)

v11 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#0 lore raw

v11 cover arm64, numa: Add numa support for arm64 platforms

From: David Daney <[email protected]>

v11:
- Dropped cleanup patches for other architectures, they will be submitted as a separate set after more testing.

- Added patch set from Ard Biesheuvel that are needed to make the whole thing actually work. Previously this was a separate set.

- Kconfig and other fixes and simplifications as suggested by Rob Herring.

- Rearranged, refactored and reordered so that we don't patch new files multiple times.

- Summary:

o 6 patches from Ard Biesheuvel to allow use of "memory" nodes with efi stub.

o 2 patches to document and add of_numa.c

o 1 patch to add arm64 NUMA support.

o 1 patch to add NUMA balancing support for arm64.

v10:
- Incorporated review comments from Rob Herring.
- Moved numa binding and implementation to devicetree core.
- Added cleanup patch to remove redundant NODE_DATA macro from asm header files
- Include numa balancing support for arm64 patch in this series.
- Fix tile build issue reported by the kbuild robot(patch 7)

v9: - Added cleanup patch to reuse and avoid redefinition of cpumask_of_pcibus
as suggested from Will Deacon and Bjorn Helgaas.
- Including patch to Make pci-host-generic driver numa aware.
- Incorporated comment from Shannon Zhao.

v8:
- Incorporated review comments of Mark Rutland and Will Deacon.
- Added pci helper function and macro for numa.

v7:
- managing numa memory mapping using memblock.
- Incorporated review comments of Mark Rutland.

v6:
- defined and implemented the numa dt binding using node property proximity and device node distance-map.
- renamed dt_numa to of_numa

v5:
- created base verion of numa.c which creates dummy numa without using dt on single socket platforms. Then added patches for dt support.
- Incorporated review comments from Hanjun Guo.

v4:
done changes as per Arnd review comments.

v3:
Added changes to support numa on arm64 based platforms. Tested these patches on cavium's multinode(2 node topology) platform. In this patchset, defined and implemented dt bindings for numa mapping for core and memory using device node property arm,associativity.

v2:
Defined and implemented numa map for memory, cores to node and proximity distance matrix of nodes.

v1:
Initial patchset to support numa on arm64 platforms.

Note: 1. This patchset is tested for NUMA and without NUMA with dt
(both with and without NUMA bindings) on thunderx single socket and dual socket boards.

Ard Biesheuvel (6):
of/fdt: make generic early_init_dt_add_memory_arch() a weak alias
arm64: override generic version of early_init_dt_add_memory_arch()
efi: move FDT handling to separate object file
arm64/efi: move EFI /chosen node parsing before early FDT processing arm64/efi: ignore DT memory nodes instead of removing them arm64/efi: ignore DT memreserve entries instead of removing them

Ganapatrao Kulkarni (4):
Documentation, dt, numa: dt bindings for NUMA. dt, numa: Add NUMA dt binding implementation. arm64, numa: Add NUMA support for arm64 platforms. arm64, mm, numa: Add NUMA balancing support for arm64.

 Documentation/devicetree/bindings/numa.txt | 272 +++++++++++++++++++
 arch/arm64/Kconfig                         |  27 ++
 arch/arm64/include/asm/efi.h               |   2 +
 arch/arm64/include/asm/mmzone.h            |  12 +
 arch/arm64/include/asm/numa.h              |  45 ++++
 arch/arm64/include/asm/pgtable.h           |  15 ++
 arch/arm64/include/asm/topology.h          |  10 +
 arch/arm64/kernel/pci.c                    |  10 +
 arch/arm64/kernel/setup.c                  |   7 +
 arch/arm64/kernel/smp.c                    |   4 +
 arch/arm64/mm/Makefile                     |   1 +
 arch/arm64/mm/init.c                       |  46 +++-
 arch/arm64/mm/mmu.c                        |   1 +
 arch/arm64/mm/numa.c                       | 403 +++++++++++++++++++++++++++++
 drivers/firmware/efi/Makefile              |   1 +
 drivers/firmware/efi/arm-init.c            |  36 ++-
 drivers/firmware/efi/efi-fdt.c             |  73 ++++++
 drivers/firmware/efi/efi.c                 |  84 ------
 drivers/firmware/efi/libstub/fdt.c         |  33 +--
 drivers/of/Kconfig                         |   3 +
 drivers/of/Makefile                        |   1 +
 drivers/of/fdt.c                           |   7 +-
 drivers/of/of_numa.c                       | 211 +++++++++++++++
 include/linux/efi.h                        |   2 +-
 include/linux/of.h                         |   9 +
 include/linux/of_fdt.h                     |   1 +
 26 files changed, 1178 insertions(+), 138 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/numa.txt
 create mode 100644 arch/arm64/include/asm/mmzone.h
 create mode 100644 arch/arm64/include/asm/numa.h
 create mode 100644 arch/arm64/mm/numa.c
 create mode 100644 drivers/firmware/efi/efi-fdt.c
 create mode 100644 drivers/of/of_numa.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v11 1/10 of/fdt: make generic early_init_dt_add_memory_arch() a weak alias

From: Ard Biesheuvel <[email protected]>

The function early_init_dt_add_memory_arch() is defined as __weak so that archs can override it. However, in this override implementation, it may still be useful to invoke the generic implementation, so instead, rename the generic version to early_init_dt_add_memory() and turn the original definition into a weak alias. This way, the generic version can still be called even in the presence of an arch specific override.

---
 drivers/of/fdt.c       | 7 +++++--
 include/linux/of_fdt.h | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/of/fdt.c +5 -2
index 655f79d..cba8281 100644
@@ -980,7 +980,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
 #define MAX_MEMBLOCK_ADDR	((phys_addr_t)~0)
 #endif
 
-void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
+void __init early_init_dt_add_memory(u64 base, u64 size)
 {
 	const u64 phys_offset = __pa(PAGE_OFFSET);
 
@@ -1038,7 +1038,7 @@ void * __init __weak early_init_dt_alloc_memory_arch(u64 size, u64 align)
 	return __va(memblock_alloc(size, align));
 }
 #else
-void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
+void __init early_init_dt_add_memory(u64 base, u64 size)
 {
 	WARN_ON(1);
 }
@@ -1058,6 +1058,9 @@ void * __init __weak early_init_dt_alloc_memory_arch(u64 size, u64 align)
 }
 #endif
 
+__weak __alias(early_init_dt_add_memory)
+void early_init_dt_add_memory_arch(u64 base, u64 size);
+
 bool __init early_init_dt_verify(void *params)
 {
 	if (!params)
include/linux/of_fdt.h +1 -0
index df9ef38..463a06b 100644
@@ -65,6 +65,7 @@ extern int early_init_dt_scan_memory(unsigned long node, const char *uname,
 				     int depth, void *data);
 extern void early_init_fdt_scan_reserved_mem(void);
 extern void early_init_fdt_reserve_self(void);
+extern void early_init_dt_add_memory(u64 base, u64 size);
 extern void early_init_dt_add_memory_arch(u64 base, u64 size);
 extern int early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size,
 					     bool no_map);
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v11 2/10 arm64: override generic version of early_init_dt_add_memory_arch()

In reply to David Daney

From: Ard Biesheuvel <[email protected]>

Override the __weak early_init_dt_add_memory_arch() with our own version. We need this in a subsequent patch to make the handling of the memory nodes conditional on whether we are booting via UEFI or not. Note that for now, all that our version does is invoke the generic implementation.

---
 arch/arm64/mm/init.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm64/mm/init.c +5 -0
index f3b061e..208c1d3 100644
@@ -380,3 +380,8 @@ static int __init keepinitrd_setup(char *__unused)
 
 __setup("keepinitrd", keepinitrd_setup);
 #endif
+
+void __init early_init_dt_add_memory_arch(u64 base, u64 size)
+{
+	early_init_dt_add_memory(base, size);
+}
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v11 3/10 efi: move FDT handling to separate object file

In reply to David Daney

From: Ard Biesheuvel <[email protected]>

The EFI specific FDT handling is compiled conditionally, and is logically independent of the rest of efi.o. So move it to a separate file before making changes to it in subsequent patches.

---
 drivers/firmware/efi/Makefile  |  1 +
 drivers/firmware/efi/efi-fdt.c | 91 ++++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/efi/efi.c     | 84 --------------------------------------
 3 files changed, 92 insertions(+), 84 deletions(-)
 create mode 100644 drivers/firmware/efi/efi-fdt.c
drivers/firmware/efi/Makefile +1 -0
index 62e654f..bb7ec2f 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_EFI_RUNTIME_MAP)		+= runtime-map.o
 obj-$(CONFIG_EFI_RUNTIME_WRAPPERS)	+= runtime-wrappers.o
 obj-$(CONFIG_EFI_STUB)			+= libstub/
 obj-$(CONFIG_EFI_FAKE_MEMMAP)		+= fake_mem.o
+obj-$(CONFIG_EFI_PARAMS_FROM_FDT)	+= efi-fdt.o
 
 arm-obj-$(CONFIG_EFI)			:= arm-init.o arm-runtime.o
 obj-$(CONFIG_ARM)			+= $(arm-obj-y)
drivers/firmware/efi/efi-fdt.c new file +91 -0

91 lines not on this page · raw message

drivers/firmware/efi/efi.c +0 -84

96 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v11 4/10 arm64/efi: move EFI /chosen node parsing before early FDT processing

In reply to David Daney

From: Ard Biesheuvel <[email protected]>

The early FDT processing is responsible for enumerating the DT memory nodes and installing them as memblocks. This should only be done if we are not booting via EFI, but at this point, we don't know yet if that is the case or not.

So move part of the EFI init to before the early FDT processing. This involves making some changes to the way EFI discovers the locations of the EFI system table and the memory map, since those values are retrieved from the FDT as well. Instead the of_scan infrastructure, it now uses libfdt directly to access the /chosen node.

[ rric: Ported to v4.5-rc1 ]
---
 arch/arm64/include/asm/efi.h    |  2 ++
 arch/arm64/kernel/setup.c       |  3 ++
 drivers/firmware/efi/arm-init.c | 34 ++++++++++++-------
 drivers/firmware/efi/efi-fdt.c  | 72 ++++++++++++++++-------------------------
 include/linux/efi.h             |  2 +-
 5 files changed, 55 insertions(+), 58 deletions(-)
arch/arm64/include/asm/efi.h +2 -0
index 8e88a69..acc7f65 100644
@@ -8,8 +8,10 @@
 
 #ifdef CONFIG_EFI
 extern void efi_init(void);
+extern void efi_parse_fdt(void *fdt);
 #else
 #define efi_init()
+#define efi_parse_fdt(x)
 #endif
 
 int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
arch/arm64/kernel/setup.c +3 -0
index 8119479..3f57233 100644
@@ -181,6 +181,9 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
 {
 	void *dt_virt = fixmap_remap_fdt(dt_phys);
 
+	if (dt_virt)
+		efi_parse_fdt(dt_virt);
+
 	if (!dt_virt || !early_init_dt_scan(dt_virt)) {
 		pr_crit("\n"
 			"Error: invalid device tree blob at physical address %pa (virtual address 0x%p)\n"
drivers/firmware/efi/arm-init.c +22 -12
index 9e15d57..9fe0464 100644
@@ -170,22 +170,35 @@ static __init void reserve_regions(void)
 		if (efi_enabled(EFI_DBG))
 			pr_cont("\n");
 	}
-
-	set_bit(EFI_MEMMAP, &efi.flags);
 }
 
-void __init efi_init(void)
+void __init efi_parse_fdt(void *fdt)
 {
 	struct efi_fdt_params params;
 
 	/* Grab UEFI information placed in FDT by stub */
-	if (!efi_get_fdt_params(&params))
+	if (!efi_get_fdt_params(fdt, &params))
 		return;
 
 	efi_system_table = params.system_table;
 
 	memmap.phys_map = params.mmap;
-	memmap.map = early_memremap(params.mmap, params.mmap_size);
+	memmap.desc_size = params.desc_size;
+	memmap.desc_version = params.desc_ver;
+	memmap.nr_map = params.mmap_size / params.desc_size;
+
+	set_bit(EFI_MEMMAP, &efi.flags);
+}
+
+void __init efi_init(void)
+{
+	int mmap_size = memmap.nr_map * memmap.desc_size;
+	u64 phys_map  = memmap.phys_map;
+
+	if (!efi_enabled(EFI_MEMMAP))
+		return;
+
+	memmap.map = early_memremap(phys_map, mmap_size);
 	if (memmap.map == NULL) {
 		/*
 		* If we are booting via UEFI, the UEFI memory map is the only
@@ -194,16 +207,13 @@ void __init efi_init(void)
 		*/
 		panic("Unable to map EFI memory map.\n");
 	}
-	memmap.map_end = memmap.map + params.mmap_size;
-	memmap.desc_size = params.desc_size;
-	memmap.desc_version = params.desc_ver;
+	memmap.map_end = memmap.map + mmap_size;
 
 	if (uefi_init() < 0)
 		return;
 
 	reserve_regions();
-	early_memunmap(memmap.map, params.mmap_size);
-	memblock_mark_nomap(params.mmap & PAGE_MASK,
-			    PAGE_ALIGN(params.mmap_size +
-				       (params.mmap & ~PAGE_MASK)));
+	early_memunmap(memmap.map, mmap_size);
+	memblock_mark_nomap(phys_map & PAGE_MASK,
+			    PAGE_ALIGN(mmap_size + (phys_map & ~PAGE_MASK)));
 }
drivers/firmware/efi/efi-fdt.c +27 -45

95 lines not on this page · raw message

include/linux/efi.h +1 -1
index 569b5a8..ede2c21 100644
@@ -915,7 +915,7 @@ extern void efi_initialize_iomem_resources(struct resource *code_resource,
 		struct resource *data_resource, struct resource *bss_resource);
 extern void efi_get_time(struct timespec *now);
 extern void efi_reserve_boot_services(void);
-extern int efi_get_fdt_params(struct efi_fdt_params *params);
+extern int efi_get_fdt_params(void *fdt, struct efi_fdt_params *params);
 extern struct efi_memory_map memmap;
 extern struct kobject *efi_kobj;
 
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v11 5/10 arm64/efi: ignore DT memory nodes instead of removing them

In reply to David Daney

From: Ard Biesheuvel <[email protected]>

There are two problems with the UEFI stub DT memory node removal routine:
- it deletes nodes as it traverses the tree, which happens to work but is not supported, as deletion invalidates the node iterator;
- deleting memory nodes entirely may discard annotations in the form of additional properties on the nodes.

Now that the UEFI initialization has moved to an earlier stage, we can actually just ignore any memblocks that are installed after we have processed the UEFI memory map. This way, it is no longer necessary to remove the nodes, so we can remove that logic from the stub as well.

---
 arch/arm64/mm/init.c               |  6 +++++-
 drivers/firmware/efi/arm-init.c    |  2 +-
 drivers/firmware/efi/libstub/fdt.c | 24 +-----------------------
 3 files changed, 7 insertions(+), 25 deletions(-)
arch/arm64/mm/init.c +5 -1
index 208c1d3..eda226e 100644
@@ -383,5 +383,9 @@ __setup("keepinitrd", keepinitrd_setup);
 
 void __init early_init_dt_add_memory_arch(u64 base, u64 size)
 {
-	early_init_dt_add_memory(base, size);
+	/*
+	 * Ignore DT memory nodes if we are booting via UEFI.
+	 */
+	if (!efi_enabled(EFI_MEMMAP))
+		early_init_dt_add_memory(base, size);
 }
drivers/firmware/efi/arm-init.c +1 -1
index 9fe0464..ded8957 100644
@@ -159,7 +159,7 @@ static __init void reserve_regions(void)
 		size = npages << PAGE_SHIFT;
 
 		if (is_normal_ram(md))
-			early_init_dt_add_memory_arch(paddr, size);
+			early_init_dt_add_memory(paddr, size);
 
 		if (is_reserve_region(md)) {
 			memblock_mark_nomap(paddr, size);
drivers/firmware/efi/libstub/fdt.c +1 -23
index cf7b7d4..9df1560 100644
@@ -24,7 +24,7 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
 			unsigned long map_size, unsigned long desc_size,
 			u32 desc_ver)
 {
-	int node, prev, num_rsv;
+	int node, num_rsv;
 	int status;
 	u32 fdt_val32;
 	u64 fdt_val64;
@@ -54,28 +54,6 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
 		goto fdt_set_fail;
 
 	/*
-	 * Delete any memory nodes present. We must delete nodes which
-	 * early_init_dt_scan_memory may try to use.
-	 */
-	prev = 0;
-	for (;;) {
-		const char *type;
-		int len;
-
-		node = fdt_next_node(fdt, prev, NULL);
-		if (node < 0)
-			break;
-
-		type = fdt_getprop(fdt, node, "device_type", &len);
-		if (type && strncmp(type, "memory", len) == 0) {
-			fdt_del_node(fdt, node);
-			continue;
-		}
-
-		prev = node;
-	}
-
-	/*
 	 * Delete all memory reserve map entries. When booting via UEFI,
 	 * kernel will use the UEFI memory map to find reserved regions.
 	 */
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v11 6/10 arm64/efi: ignore DT memreserve entries instead of removing them

In reply to David Daney

From: Ard Biesheuvel <[email protected]>

Now that the reservation of the FDT image itself is split off from the processing of memory reservations described by the device tree, we can make the DT scanning of memreserves conditional on whether we booted via UEFI and have its memory map available. This allows us to drop deletion of these memreserves in the stub. It also fixes the issue where the /reserved-memory node (which offers another way of reserving memory ranges) was not being ignored under UEFI.

Note that this reverts commit 0ceac9e094b0 ("efi/arm64: Fix fdt-related memory reservation").

---
 arch/arm64/mm/init.c               |  3 ++-
 drivers/firmware/efi/libstub/fdt.c | 11 +----------
 2 files changed, 3 insertions(+), 11 deletions(-)
arch/arm64/mm/init.c +2 -1
index eda226e..ee06165 100644
@@ -171,7 +171,8 @@ void __init arm64_memblock_init(void)
 		memblock_reserve(__virt_to_phys(initrd_start), initrd_end - initrd_start);
 #endif
 
-	early_init_fdt_scan_reserved_mem();
+	if (!efi_enabled(EFI_MEMMAP))
+		early_init_fdt_scan_reserved_mem();
 
 	/* 4GB maximum for 32-bit only capable devices */
 	if (IS_ENABLED(CONFIG_ZONE_DMA))
drivers/firmware/efi/libstub/fdt.c +1 -10
index 9df1560..12cb2a3 100644
@@ -24,8 +24,7 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
 			unsigned long map_size, unsigned long desc_size,
 			u32 desc_ver)
 {
-	int node, num_rsv;
-	int status;
+	int node, status;
 	u32 fdt_val32;
 	u64 fdt_val64;
 
@@ -53,14 +52,6 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
 	if (status != 0)
 		goto fdt_set_fail;
 
-	/*
-	 * Delete all memory reserve map entries. When booting via UEFI,
-	 * kernel will use the UEFI memory map to find reserved regions.
-	 */
-	num_rsv = fdt_num_mem_rsv(fdt);
-	while (num_rsv-- > 0)
-		fdt_del_mem_rsv(fdt, num_rsv);
-
 	node = fdt_subnode_offset(fdt, 0, "chosen");
 	if (node < 0) {
 		node = fdt_add_subnode(fdt, 0, "chosen");
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v11 7/10 Documentation, dt, numa: dt bindings for NUMA.

In reply to David Daney

From: Ganapatrao Kulkarni <[email protected]>

Add DT bindings for numa mapping of memory, CPUs and IOs.

---
 Documentation/devicetree/bindings/numa.txt | 272 +++++++++++++++++++++++++++++
 1 file changed, 272 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/numa.txt
Documentation/devicetree/bindings/numa.txt new file +272 -0
new file mode 100644
index 0000000..ec5ed7c
@@ -0,0 +1,272 @@
+==============================================================================
+NUMA binding description.
+==============================================================================
+
+==============================================================================
+1 - Introduction
+==============================================================================
+
+Systems employing a Non Uniform Memory Access (NUMA) architecture contain
+collections of hardware resources including processors, memory, and I/O buses,
+that comprise what is commonly known as a NUMA node.
+Processor accesses to memory within the local NUMA node is generally faster
+than processor accesses to memory outside of the local NUMA node.
+DT defines interfaces that allow the platform to convey NUMA node
+topology information to OS.
+
+==============================================================================
+2 - numa-node-id
+==============================================================================
+
+For the purpose of identification, each NUMA node is associated with a unique
+token known as a node id. For the purpose of this binding
+a node id is a 32-bit integer.
+
+A device node is associated with a NUMA node by the presence of a
+numa-node-id property which contains the node id of the device.
+
+Example:
+	/* numa node 0 */
+	numa-node-id = <0>;
+
+	/* numa node 1 */
+	numa-node-id = <1>;
+
+==============================================================================
+3 - distance-map
+==============================================================================
+
+The device tree node distance-map describes the relative
+distance (memory latency) between all numa nodes.
+
+- compatible : Should at least contain "numa-distance-map-v1".
+
+- distance-matrix
+  This property defines a matrix to describe the relative distances
+  between all numa nodes.
+  It is represented as a list of node pairs and their relative distance.
+
+  Note:
+	1. Each entry represents distance from first node to second node.
+	The distances are equal in either direction.
+	2. The distance from a node to self (local distance) is represented
+	with value 10 and all internode distance should be represented with
+	a value greater than 10.
+	3. distance-matrix should have entries in lexicographical ascending
+	order of nodes.
+	4. There must be only one device node distance-map which must reside in the root node.
+
+Example:
+	4 nodes connected in mesh/ring topology as below,
+
+		0_______20______1
+		|               |
+		|               |
+		20             20
+		|               |
+		|               |
+		|_______________|
+		3       20      2
+
+	if relative distance for each hop is 20,
+	then internode distance would be,
+	      0 -> 1 = 20
+	      1 -> 2 = 20
+	      2 -> 3 = 20
+	      3 -> 0 = 20
+	      0 -> 2 = 40
+	      1 -> 3 = 40
+
+     and dt presentation for this distance matrix is,
+
+		distance-map {
+			 compatible = "numa-distance-map-v1";
+			 distance-matrix = <0 0  10>,
+					   <0 1  20>,
+					   <0 2  40>,
+					   <0 3  20>,
+					   <1 0  20>,
+					   <1 1  10>,
+					   <1 2  20>,
+					   <1 3  40>,
+					   <2 0  40>,
+					   <2 1  20>,
+					   <2 2  10>,
+					   <2 3  20>,
+					   <3 0  20>,
+					   <3 1  40>,
+					   <3 2  20>,
+					   <3 3  10>;
+		};
+
+==============================================================================
+4 - Example dts
+==============================================================================
+
+Dual socket system consists of 2 boards connected through ccn bus and
+each board having one socket/soc of 8 cpus, memory and pci bus.
+
+	memory at c00000 {
+		device_type = "memory";
+		reg = <0x0 0xc00000 0x0 0x80000000>;
+		/* node 0 */
+		numa-node-id = <0>;
+	};
+
+	memory at 10000000000 {
+		device_type = "memory";
+		reg = <0x100 0x0 0x0 0x80000000>;
+		/* node 1 */
+		numa-node-id = <1>;
+	};
+
+	cpus {
+		#address-cells = <2>;
+		#size-cells = <0>;
+
+		cpu at 0 {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0x0>;
+			enable-method = "psci";
+			/* node 0 */
+			numa-node-id = <0>;
+		};
+		cpu at 1 {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0x1>;
+			enable-method = "psci";
+			numa-node-id = <0>;
+		};
+		cpu at 2 {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0x2>;
+			enable-method = "psci";
+			numa-node-id = <0>;
+		};
+		cpu at 3 {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0x3>;
+			enable-method = "psci";
+			numa-node-id = <0>;
+		};
+		cpu at 4 {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0x4>;
+			enable-method = "psci";
+			numa-node-id = <0>;
+		};
+		cpu at 5 {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0x5>;
+			enable-method = "psci";
+			numa-node-id = <0>;
+		};
+		cpu at 6 {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0x6>;
+			enable-method = "psci";
+			numa-node-id = <0>;
+		};
+		cpu at 7 {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0x7>;
+			enable-method = "psci";
+			numa-node-id = <0>;
+		};
+		cpu at 8 {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0x8>;
+			enable-method = "psci";
+			/* node 1 */
+			numa-node-id = <1>;
+		};
+		cpu at 9 {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0x9>;
+			enable-method = "psci";
+			numa-node-id = <1>;
+		};
+		cpu at a {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0xa>;
+			enable-method = "psci";
+			numa-node-id = <1>;
+		};
+		cpu at b {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0xb>;
+			enable-method = "psci";
+			numa-node-id = <1>;
+		};
+		cpu at c {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0xc>;
+			enable-method = "psci";
+			numa-node-id = <1>;
+		};
+		cpu at d {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0xd>;
+			enable-method = "psci";
+			numa-node-id = <1>;
+		};
+		cpu at e {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0xe>;
+			enable-method = "psci";
+			numa-node-id = <1>;
+		};
+		cpu at f {
+			device_type = "cpu";
+			compatible =  "arm,armv8";
+			reg = <0x0 0xf>;
+			enable-method = "psci";
+			numa-node-id = <1>;
+		};
+	};
+
+	pcie0: pcie0 at 848000000000 {
+		compatible = "arm,armv8";
+		device_type = "pci";
+		bus-range = <0 255>;
+		#size-cells = <2>;
+		#address-cells = <3>;
+		reg = <0x8480 0x00000000 0 0x10000000>;  /* Configuration space */
+		ranges = <0x03000000 0x8010 0x00000000 0x8010 0x00000000 0x70 0x00000000>;
+		/* node 0 */
+		numa-node-id = <0>;
+        };
+
+	pcie1: pcie1 at 948000000000 {
+		compatible = "arm,armv8";
+		device_type = "pci";
+		bus-range = <0 255>;
+		#size-cells = <2>;
+		#address-cells = <3>;
+		reg = <0x9480 0x00000000 0 0x10000000>;  /* Configuration space */
+		ranges = <0x03000000 0x9010 0x00000000 0x9010 0x00000000 0x70 0x00000000>;
+		/* node 1 */
+		numa-node-id = <1>;
+        };
+
+	distance-map {
+		compatible = "numa-distance-map-v1";
+		distance-matrix = <0 0 10>,
+				  <0 1 20>,
+				  <1 1 10>;
+	};
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH v11 8/10 dt, numa: Add NUMA dt binding implementation.

In reply to David Daney

From: Ganapatrao Kulkarni <[email protected]>

ADD device tree node parsing for NUMA topology using device "numa-node-id" property distance-map.

---
 drivers/of/Kconfig   |   3 +
 drivers/of/Makefile  |   1 +
 drivers/of/of_numa.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h   |   9 +++
 4 files changed, 224 insertions(+)
 create mode 100644 drivers/of/of_numa.c
drivers/of/Kconfig +3 -0
index e2a4841..b3bec3a 100644
@@ -112,4 +112,7 @@ config OF_OVERLAY
 	  While this option is selected automatically when needed, you can
 	  enable it manually to improve device tree unit test coverage.
 
+config OF_NUMA
+	bool
+
 endif # OF
drivers/of/Makefile +1 -0
index 156c072..bee3fa9 100644
@@ -14,5 +14,6 @@ obj-$(CONFIG_OF_MTD)	+= of_mtd.o
 obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o
 obj-$(CONFIG_OF_RESOLVE)  += resolver.o
 obj-$(CONFIG_OF_OVERLAY) += overlay.o
+obj-$(CONFIG_OF_NUMA) += of_numa.o
 
 obj-$(CONFIG_OF_UNITTEST) += unittest-data/
drivers/of/of_numa.c new file +211 -0

211 lines not on this page · raw message

include/linux/of.h +9 -0
index dc6e396..fe67a4c 100644
@@ -685,6 +685,15 @@ static inline int of_node_to_nid(struct device_node *device)
 }
 #endif
 
+#ifdef CONFIG_OF_NUMA
+extern int of_numa_init(void);
+#else
+static inline int of_numa_init(void)
+{
+	return -ENOSYS;
+}
+#endif
+
 static inline struct device_node *of_find_matching_node(
 	struct device_node *from,
 	const struct of_device_id *matches)
Signature · 1 line
1.8.3.1
maintainer
#9 lore raw

Re: [PATCH v11 08/10] dt, numa: Add NUMA dt binding implementation.

Quoted 4 lines · David Daney

From: Ganapatrao Kulkarni <[email protected]>

ADD device tree node parsing for NUMA topology using device "numa-node-id" property distance-map.

I still want an adequate explanation why NUMA setup cannot be done with an unflattened tree. PowerPC manages to do that and should have a similar init flow being memblock based, so I would expect arm64 can too.

Rob

#10 lore raw

Re: [PATCH v11 08/10] dt, numa: Add NUMA dt binding implementation.

Quoted 9 lines · Rob Herring
Quoted 4 lines · David Daney

From: Ganapatrao Kulkarni <[email protected]>

ADD device tree node parsing for NUMA topology using device "numa-node-id" property distance-map.

I still want an adequate explanation why NUMA setup cannot be done with an unflattened tree. PowerPC manages to do that and should have a similar init flow being memblock based, so I would expect arm64 can too.

Many things could be done. Really, we want to know what *should* be done.

In the context of the current arm64 memory initialization we (more or less) do:

1) early_init_fdt_scan_reserved_mem();
2) memory_present()
3) sparse_init()
4) other things
5) unflatten_device_tree()

We are already reading information out of the FDT at #1.

This patch set adds a step between 1 and 2 where we read NUMA information out of the FDT.

Hypothetically, it might be possible to rewrite the arm64 setup code so that the ordering was different, and the NUMA setup was done on the unflattened tree, but that would certainly be a much more invasive patch.

If the arm64 maintainers would like a rewrite of:

arch/arm64/kernel/setup.c
arch/arm64/mm/init.c
arch/arm64/mm/mm/mmu.c
.
.
.

we can discuss doing NUMA setup with the unflattened tree. With the current memory initialization code, I think it makes more sense to parse the NUMA information out of the flattened form.

David Daney

#11 lore raw

Re: [PATCH v11 08/10] dt, numa: Add NUMA dt binding implementation.

Quoted 22 lines · David Daney
Quoted 9 lines · Rob Herring
Quoted 4 lines · David Daney

From: Ganapatrao Kulkarni <[email protected]>

ADD device tree node parsing for NUMA topology using device "numa-node-id" property distance-map.

I still want an adequate explanation why NUMA setup cannot be done with an unflattened tree. PowerPC manages to do that and should have a similar init flow being memblock based, so I would expect arm64 can too.

Many things could be done. Really, we want to know what *should* be done.

In the context of the current arm64 memory initialization we (more or less) do:

1) early_init_fdt_scan_reserved_mem();
2) memory_present()
3) sparse_init()
4) other things
5) unflatten_device_tree()

Quoted 8 lines

We are already reading information out of the FDT at #1.

This patch set adds a step between 1 and 2 where we read NUMA information out of the FDT.

Hypothetically, it might be possible to rewrite the arm64 setup code so that the ordering was different, and the NUMA setup was done on the unflattened tree, but that would certainly be a much more invasive patch.

I just looked at what PPC get up to, and there's really not an obvious way we could do that on arm64. They run whole swathes of the kernel with the MMU off directly from head.S to parse the flattened tree and get memblock up really early. On arm64, the head.S environment is considerably more hostile, and I don't think we'd want to do that (not to mention the interaction with EFI stub).

So I'm perfectly happy for this to operate on the flattened tree.

Will

maintainer
#12 lore raw

Re: [PATCH v11 08/10] dt, numa: Add NUMA dt binding implementation.

Quoted 32 lines · Will Deacon
Quoted 22 lines · David Daney
Quoted 9 lines · Rob Herring
Quoted 4 lines · David Daney

From: Ganapatrao Kulkarni <[email protected]>

ADD device tree node parsing for NUMA topology using device "numa-node-id" property distance-map.

I still want an adequate explanation why NUMA setup cannot be done with an unflattened tree. PowerPC manages to do that and should have a similar init flow being memblock based, so I would expect arm64 can too.

Many things could be done. Really, we want to know what *should* be done.

In the context of the current arm64 memory initialization we (more or less) do:

1) early_init_fdt_scan_reserved_mem();
2) memory_present()
3) sparse_init()
4) other things
5) unflatten_device_tree()

Quoted 8 lines

We are already reading information out of the FDT at #1.

This patch set adds a step between 1 and 2 where we read NUMA information out of the FDT.

Hypothetically, it might be possible to rewrite the arm64 setup code so that the ordering was different, and the NUMA setup was done on the unflattened tree, but that would certainly be a much more invasive patch.

Quoted 8 lines

I just looked at what PPC get up to, and there's really not an obvious way we could do that on arm64. They run whole swathes of the kernel with the MMU off directly from head.S to parse the flattened tree and get memblock up really early. On arm64, the head.S environment is considerably more hostile, and I don't think we'd want to do that (not to mention the interaction with EFI stub).

So I'm perfectly happy for this to operate on the flattened tree.

Of course you are. The code is not in your tree. I'm all for keeping things out of /arch, but just want to understand what are the dependencies which aren't clearly spelled out here.

Rob

maintainer
#13 lore raw

Re: [PATCH v11 08/10] dt, numa: Add NUMA dt binding implementation.

In reply to David Daney
Quoted 26 lines · David Daney
Quoted 5 lines · Rob Herring
Quoted 3 lines · David Daney

From: Ganapatrao Kulkarni <[email protected]>

Quoted 7 lines
Quoted 2 lines

ADD device tree node parsing for NUMA topology using device "numa-node-id" property distance-map.

I still want an adequate explanation why NUMA setup cannot be done with an unflattened tree. PowerPC manages to do that and should have a similar init flow being memblock based, so I would expect arm64 can too.

Many things could be done. Really, we want to know what *should* be done.

In the context of the current arm64 memory initialization we (more or less) do:

1) early_init_fdt_scan_reserved_mem();
2) memory_present()
3) sparse_init()
4) other things
5) unflatten_device_tree()

Quoted 4 lines

We are already reading information out of the FDT at #1.

This patch set adds a step between 1 and 2 where we read NUMA information out of the FDT.

The dependency on unflattening is that memblock is up and we can allocate a chunk from it. Isn't that dependency met by step 1 or is there a dependency on sparsemem (or something else)?

Rob

#14 lore raw

Re: [PATCH v11 08/10] dt, numa: Add NUMA dt binding implementation.

Quoted 27 lines · Rob Herring
Quoted 26 lines · David Daney
Quoted 5 lines · Rob Herring
Quoted 3 lines · David Daney

From: Ganapatrao Kulkarni <[email protected]>

Quoted 7 lines
Quoted 2 lines

ADD device tree node parsing for NUMA topology using device "numa-node-id" property distance-map.

I still want an adequate explanation why NUMA setup cannot be done with an unflattened tree. PowerPC manages to do that and should have a similar init flow being memblock based, so I would expect arm64 can too.

Many things could be done. Really, we want to know what *should* be done.

In the context of the current arm64 memory initialization we (more or less) do:

1) early_init_fdt_scan_reserved_mem();
2) memory_present()
3) sparse_init()
4) other things
5) unflatten_device_tree()

Quoted 7 lines
Quoted 4 lines

We are already reading information out of the FDT at #1.

This patch set adds a step between 1 and 2 where we read NUMA information out of the FDT.

The dependency on unflattening is that memblock is up and we can allocate a chunk from it. Isn't that dependency met by step 1

No.

Quoted 2 lines

or is
there a dependency on sparsemem (or something else)?

Will Deacon talked about this over here:

https://lkml.org/lkml/2016/2/26/782

I am happy to modify the patch set, but I don't want to get stuck as an intermediary between two opposing blocs.

David Daney

maintainer
#15 lore raw

Re: [PATCH v11 08/10] dt, numa: Add NUMA dt binding implementation.

Quoted 43 lines · David Daney
Quoted 42 lines · Rob Herring
Quoted 37 lines · David Daney
Quoted 7 lines · Rob Herring
Quoted 4 lines · David Daney

From: Ganapatrao Kulkarni <[email protected]>

Quoted 8 lines
Quoted 2 lines

ADD device tree node parsing for NUMA topology using device "numa-node-id" property distance-map.

I still want an adequate explanation why NUMA setup cannot be done with an unflattened tree. PowerPC manages to do that and should have a similar init flow being memblock based, so I would expect arm64 can too.

Many things could be done. Really, we want to know what *should* be done.

In the context of the current arm64 memory initialization we (more or less)
do:

1) early_init_fdt_scan_reserved_mem();
2) memory_present()
3) sparse_init()
4) other things
5) unflatten_device_tree()

We are already reading information out of the FDT at #1.

This patch set adds a step between 1 and 2 where we read NUMA information out of the FDT.

Quoted 5 lines
Quoted 2 lines

The dependency on unflattening is that memblock is up and we can allocate a chunk from it. Isn't that dependency met by step 1

No.

Really, because it seems that numa_alloc_distance is essentially doing a memblock alloc and that happens before memory_present.

Quoted 8 lines
Quoted 3 lines

or is
there a dependency on sparsemem (or something else)?

Will Deacon talked about this over here:

https://lkml.org/lkml/2016/2/26/782

I'm not saying to move memblock setup earlier nor before the MMU is on, so I don't see how Will's reply is relevant other than PPC doesn't serve as an example. Maybe PPC should be ignored because I think maybe NUMA is only used on non-FDT systems.

In any case, no one has clearly explained what the dependencies are or what happens if you moved the unflattening up sooner. You told me what the current order is which doesn't equate to dependencies. For example, step 4 may or may not be a dependency of step 5. These are the dependencies I'm aware of:

memblock dependent on DT memory and reserved-memory parsing unflattening dependent on memblock_alloc() sparsemem dependent on NUMA parsing and memblock

What am I missing from here?

Rob

#16 lore raw

Re: [PATCH v11 08/10] dt, numa: Add NUMA dt binding implementation.

Quoted 73 lines · Rob Herring
Quoted 43 lines · David Daney
Quoted 42 lines · Rob Herring
Quoted 37 lines · David Daney
Quoted 7 lines · Rob Herring
Quoted 4 lines · David Daney

From: Ganapatrao Kulkarni <[email protected]>

Quoted 8 lines
Quoted 2 lines

ADD device tree node parsing for NUMA topology using device "numa-node-id" property distance-map.

I still want an adequate explanation why NUMA setup cannot be done with an unflattened tree. PowerPC manages to do that and should have a similar init flow being memblock based, so I would expect arm64 can too.

Many things could be done. Really, we want to know what *should* be done.

In the context of the current arm64 memory initialization we (more or less)
do:

1) early_init_fdt_scan_reserved_mem();
2) memory_present()
3) sparse_init()
4) other things
5) unflatten_device_tree()

We are already reading information out of the FDT at #1.

This patch set adds a step between 1 and 2 where we read NUMA information out of the FDT.

Quoted 5 lines
Quoted 2 lines

The dependency on unflattening is that memblock is up and we can allocate a chunk from it. Isn't that dependency met by step 1

No.

Really, because it seems that numa_alloc_distance is essentially doing a memblock alloc and that happens before memory_present.

Quoted 8 lines
Quoted 3 lines

or is
there a dependency on sparsemem (or something else)?

Will Deacon talked about this over here:

https://lkml.org/lkml/2016/2/26/782

I'm not saying to move memblock setup earlier nor before the MMU is on, so I don't see how Will's reply is relevant other than PPC doesn't serve as an example. Maybe PPC should be ignored because I think maybe NUMA is only used on non-FDT systems.

In any case, no one has clearly explained what the dependencies are or what happens if you moved the unflattening up sooner. You told me what the current order is which doesn't equate to dependencies. For example, step 4 may or may not be a dependency of step 5. These are the dependencies I'm aware of:

Quoted 4 lines

memblock dependent on DT memory and reserved-memory parsing unflattening dependent on memblock_alloc() sparsemem dependent on NUMA parsing and memblock

I understand what you are saying.

Let me go back over the code looking to separate the issues of the inertia of the initial implementation, the need to cleanly support both EFI and non-EFI firmware, and your desire to unflatten the device tree much earlier than we currently do.

At this point, arm64 is the only user of the of_numa.c file. So, if you think it is not general purpose enough to live in drivers/of we could discuss the possibility of moving it under arch/arm64

David.

#17 lore raw

PATCH v11 9/10 arm64, numa: Add NUMA support for arm64 platforms.

In reply to David Daney

From: Ganapatrao Kulkarni <[email protected]>

Attempt to get the memory and CPU NUMA node via of_numa. If that fails, default the dummy NUMA node and map all memory and CPUs to node 0.

---
 arch/arm64/Kconfig                |  26 +++
 arch/arm64/include/asm/mmzone.h   |  12 ++
 arch/arm64/include/asm/numa.h     |  45 +++++
 arch/arm64/include/asm/topology.h |  10 +
 arch/arm64/kernel/pci.c           |  10 +
 arch/arm64/kernel/setup.c         |   4 +
 arch/arm64/kernel/smp.c           |   4 +
 arch/arm64/mm/Makefile            |   1 +
 arch/arm64/mm/init.c              |  34 +++-
 arch/arm64/mm/mmu.c               |   1 +
 arch/arm64/mm/numa.c              | 403 ++++++++++++++++++++++++++++++++++++++
 11 files changed, 545 insertions(+), 5 deletions(-)
 create mode 100644 arch/arm64/include/asm/mmzone.h
 create mode 100644 arch/arm64/include/asm/numa.h
 create mode 100644 arch/arm64/mm/numa.c
arch/arm64/Kconfig +26 -0
index a969970..9f0972a 100644
@@ -74,6 +74,7 @@ config ARM64
 	select HAVE_HW_BREAKPOINT if PERF_EVENTS
 	select HAVE_IRQ_TIME_ACCOUNTING
 	select HAVE_MEMBLOCK
+	select HAVE_MEMBLOCK_NODE_MAP if NUMA
 	select HAVE_PATA_PLATFORM
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_REGS
@@ -96,6 +97,7 @@ config ARM64
 	select SYSCTL_EXCEPTION_TRACE
 	select HAVE_CONTEXT_TRACKING
 	select HAVE_ARM_SMCCC
+	select OF_NUMA if NUMA && OF
 	help
 	  ARM 64-bit (AArch64) Linux support.
 
@@ -545,6 +547,30 @@ config HOTPLUG_CPU
 	  Say Y here to experiment with turning CPUs off and on.  CPUs
 	  can be controlled through /sys/devices/system/cpu.
 
+# Common NUMA Features
+config NUMA
+	bool "Numa Memory Allocation and Scheduler Support"
+	depends on SMP
+	help
+	  Enable NUMA (Non Uniform Memory Access) support.
+
+	  The kernel will try to allocate memory used by a CPU on the
+	  local memory of the CPU and add some more
+	  NUMA awareness to the kernel.
+
+config NODES_SHIFT
+	int "Maximum NUMA Nodes (as a power of 2)"
+	range 1 10
+	default "2"
+	depends on NEED_MULTIPLE_NODES
+	help
+	  Specify the maximum number of NUMA Nodes available on the target
+	  system.  Increases memory reserved to accommodate various tables.
+
+config USE_PERCPU_NUMA_NODE_ID
+	def_bool y
+	depends on NUMA
+
 source kernel/Kconfig.preempt
 source kernel/Kconfig.hz
 
arch/arm64/include/asm/mmzone.h new file +12 -0
new file mode 100644
index 0000000..a0de9e6
@@ -0,0 +1,12 @@
+#ifndef __ASM_MMZONE_H
+#define __ASM_MMZONE_H
+
+#ifdef CONFIG_NUMA
+
+#include <asm/numa.h>
+
+extern struct pglist_data *node_data[];
+#define NODE_DATA(nid)		(node_data[(nid)])
+
+#endif /* CONFIG_NUMA */
+#endif /* __ASM_MMZONE_H */
arch/arm64/include/asm/numa.h new file +45 -0

45 lines not on this page · raw message

arch/arm64/include/asm/topology.h +10 -0
index a3e9d6f..8b57339 100644
@@ -22,6 +22,16 @@ void init_cpu_topology(void);
 void store_cpu_topology(unsigned int cpuid);
 const struct cpumask *cpu_coregroup_mask(int cpu);
 
+#ifdef CONFIG_NUMA
+
+struct pci_bus;
+int pcibus_to_node(struct pci_bus *bus);
+#define cpumask_of_pcibus(bus)	(pcibus_to_node(bus) == -1 ?		\
+				 cpu_all_mask :				\
+				 cpumask_of_node(pcibus_to_node(bus)))
+
+#endif /* CONFIG_NUMA */
+
 #include <asm-generic/topology.h>
 
 #endif /* _ASM_ARM_TOPOLOGY_H */
arch/arm64/kernel/pci.c +10 -0
index b3d098b..65e6b7d 100644
@@ -76,6 +76,16 @@ int raw_pci_write(unsigned int domain, unsigned int bus,
 	return -ENXIO;
 }
 
+#ifdef CONFIG_NUMA
+
+int pcibus_to_node(struct pci_bus *bus)
+{
+	return dev_to_node(&bus->dev);
+}
+EXPORT_SYMBOL(pcibus_to_node);
+
+#endif
+
 #ifdef CONFIG_ACPI
 /* Root bridge scanning */
 struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
arch/arm64/kernel/setup.c +4 -0
index 3f57233..a347a55 100644
@@ -53,6 +53,7 @@
 #include <asm/cpufeature.h>
 #include <asm/cpu_ops.h>
 #include <asm/kasan.h>
+#include <asm/numa.h>
 #include <asm/sections.h>
 #include <asm/setup.h>
 #include <asm/smp_plat.h>
@@ -375,6 +376,9 @@ static int __init topology_init(void)
 {
 	int i;
 
+	for_each_online_node(i)
+		register_one_node(i);
+
 	for_each_possible_cpu(i) {
 		struct cpu *cpu = &per_cpu(cpu_data.cpu, i);
 		cpu->hotpluggable = 1;
arch/arm64/kernel/smp.c +4 -0
index b1adc51..46c45c8 100644
@@ -45,6 +45,7 @@
 #include <asm/cputype.h>
 #include <asm/cpu_ops.h>
 #include <asm/mmu_context.h>
+#include <asm/numa.h>
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
 #include <asm/processor.h>
@@ -125,6 +126,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)
 static void smp_store_cpu_info(unsigned int cpuid)
 {
 	store_cpu_topology(cpuid);
+	numa_store_cpu_info(cpuid);
 }
 
 /*
@@ -518,6 +520,8 @@ static void __init of_parse_and_init_cpus(void)
 
 		pr_debug("cpu logical map 0x%llx\n", hwid);
 		cpu_logical_map(cpu_count) = hwid;
+
+		early_map_cpu_to_node(cpu_count, of_node_to_nid(dn));
 next:
 		cpu_count++;
 	}
arch/arm64/mm/Makefile +1 -0
index 57f57fd..54bb209 100644
@@ -4,6 +4,7 @@ obj-y				:= dma-mapping.o extable.o fault.o init.o \
 				   context.o proc.o pageattr.o
 obj-$(CONFIG_HUGETLB_PAGE)	+= hugetlbpage.o
 obj-$(CONFIG_ARM64_PTDUMP)	+= dump.o
+obj-$(CONFIG_NUMA)		+= numa.o
 
 obj-$(CONFIG_KASAN)		+= kasan_init.o
 KASAN_SANITIZE_kasan_init.o	:= n
arch/arm64/mm/init.c +29 -5
index ee06165..5680c84 100644
@@ -37,6 +37,7 @@
 
 #include <asm/fixmap.h>
 #include <asm/memory.h>
+#include <asm/numa.h>
 #include <asm/sections.h>
 #include <asm/setup.h>
 #include <asm/sizes.h>
@@ -77,6 +78,21 @@ static phys_addr_t __init max_zone_dma_phys(void)
 	return min(offset + (1ULL << 32), memblock_end_of_DRAM());
 }
 
+#ifdef CONFIG_NUMA
+
+static void __init zone_sizes_init(unsigned long min, unsigned long max)
+{
+	unsigned long max_zone_pfns[MAX_NR_ZONES]  = {0};
+
+	if (IS_ENABLED(CONFIG_ZONE_DMA))
+		max_zone_pfns[ZONE_DMA] = PFN_DOWN(max_zone_dma_phys());
+	max_zone_pfns[ZONE_NORMAL] = max;
+
+	free_area_init_nodes(max_zone_pfns);
+}
+
+#else
+
 static void __init zone_sizes_init(unsigned long min, unsigned long max)
 {
 	struct memblock_region *reg;
@@ -117,6 +133,8 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)
 	free_area_init_node(0, zone_size, min, zhole_size);
 }
 
+#endif /* CONFIG_NUMA */
+
 #ifdef CONFIG_HAVE_ARCH_PFN_VALID
 int pfn_valid(unsigned long pfn)
 {
@@ -133,10 +151,15 @@ static void __init arm64_memory_present(void)
 static void __init arm64_memory_present(void)
 {
 	struct memblock_region *reg;
+	int nid = 0;
 
-	for_each_memblock(memory, reg)
-		memory_present(0, memblock_region_memory_base_pfn(reg),
-			       memblock_region_memory_end_pfn(reg));
+	for_each_memblock(memory, reg) {
+#ifdef CONFIG_NUMA
+		nid = reg->nid;
+#endif
+		memory_present(nid, memblock_region_memory_base_pfn(reg),
+				memblock_region_memory_end_pfn(reg));
+	}
 }
 #endif
 
@@ -182,7 +205,6 @@ void __init arm64_memblock_init(void)
 	dma_contiguous_reserve(arm64_dma_phys_limit);
 
 	memblock_allow_resize();
-	memblock_dump_all();
 }
 
 void __init bootmem_init(void)
@@ -194,6 +216,9 @@ void __init bootmem_init(void)
 
 	early_memtest(min << PAGE_SHIFT, max << PAGE_SHIFT);
 
+	max_pfn = max_low_pfn = max;
+
+	arm64_numa_init();
 	/*
 	 * Sparsemem tries to allocate bootmem in memory_present(), so must be
 	 * done after the fixed reservations.
@@ -204,7 +229,6 @@ void __init bootmem_init(void)
 	zone_sizes_init(min, max);
 
 	high_memory = __va((max << PAGE_SHIFT) - 1) + 1;
-	max_pfn = max_low_pfn = max;
 }
 
 #ifndef CONFIG_SPARSEMEM_VMEMMAP
arch/arm64/mm/mmu.c +1 -0
index 58faeaa..44e3854 100644
@@ -463,6 +463,7 @@ void __init paging_init(void)
 	zero_page = early_alloc(PAGE_SIZE);
 
 	bootmem_init();
+	memblock_dump_all();
 
 	empty_zero_page = virt_to_page(zero_page);
 
arch/arm64/mm/numa.c new file +403 -0

403 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#18 lore raw

PATCH v11 10/10 arm64, mm, numa: Add NUMA balancing support for arm64.

In reply to David Daney

From: Ganapatrao Kulkarni <[email protected]>

Enable NUMA balancing for arm64 platforms.
Add pte, pmd protnone helpers for use by automatic NUMA balancing.

---
 arch/arm64/Kconfig               |  1 +
 arch/arm64/include/asm/pgtable.h | 15 +++++++++++++++
 2 files changed, 16 insertions(+)
arch/arm64/Kconfig +1 -0
index 9f0972a..6e22503 100644
@@ -11,6 +11,7 @@ config ARM64
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
 	select ARCH_USE_CMPXCHG_LOCKREF
 	select ARCH_SUPPORTS_ATOMIC_RMW
+	select ARCH_SUPPORTS_NUMA_BALANCING
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
 	select ARCH_WANT_FRAME_POINTERS
arch/arm64/include/asm/pgtable.h +15 -0
index bf464de..5af9db2 100644
@@ -346,6 +346,21 @@ static inline pgprot_t mk_sect_prot(pgprot_t prot)
 	return __pgprot(pgprot_val(prot) & ~PTE_TABLE_BIT);
 }
 
+#ifdef CONFIG_NUMA_BALANCING
+/*
+ * See the comment in include/asm-generic/pgtable.h
+ */
+static inline int pte_protnone(pte_t pte)
+{
+	return (pte_val(pte) & (PTE_VALID | PTE_PROT_NONE)) == PTE_PROT_NONE;
+}
+
+static inline int pmd_protnone(pmd_t pmd)
+{
+	return pte_protnone(pmd_pte(pmd));
+}
+#endif
+
 /*
  * THP definitions.
  */
Signature · 1 line
1.8.3.1
#19 lore raw
In reply to David Daney

Hello David,

Quoted 10 lines · David Daney

From: David Daney <[email protected]>

v11:
- Dropped cleanup patches for other architectures, they will be submitted as a separate set after more testing.

- Added patch set from Ard Biesheuvel that are needed to make the whole thing actually work. Previously this was a separate set.

This series is out of date, unfortunately. The EFI init code is now (as of v4.5-rc1) shared between ARM and arm64, which means that any changes you make must be made on both sides. This applies to the split between parsing the EFI dt nodes and performing the actual EFI init, but also to the early_init_dt_add_memory_arch() changes. I am happy to have a go at this, but first I need a clear statement from whoever maintains that area that keeping memory nodes *just* for the annotations (and otherwise ignore them) is the way forward (Rob? Grant?)

Also, please drop the 6th patch. As i replied to Robert when he reposted these patches, we need to honor the /reserved-memory node rather than remove it. I will follow up with an updated /reserved-memory node validation patch for the EFI stub once these changes are in.

Quoted 118 lines

- Kconfig and other fixes and simplifications as suggested by Rob Herring.

- Rearranged, refactored and reordered so that we don't patch new files multiple times.

- Summary:

o 6 patches from Ard Biesheuvel to allow use of "memory" nodes with efi stub.

o 2 patches to document and add of_numa.c

o 1 patch to add arm64 NUMA support.

o 1 patch to add NUMA balancing support for arm64.

v10:
- Incorporated review comments from Rob Herring.
- Moved numa binding and implementation to devicetree core.
- Added cleanup patch to remove redundant NODE_DATA macro from asm header files
- Include numa balancing support for arm64 patch in this series.
- Fix tile build issue reported by the kbuild robot(patch 7)

v9: - Added cleanup patch to reuse and avoid redefinition of cpumask_of_pcibus
as suggested from Will Deacon and Bjorn Helgaas.
- Including patch to Make pci-host-generic driver numa aware.
- Incorporated comment from Shannon Zhao.

v8:
- Incorporated review comments of Mark Rutland and Will Deacon.
- Added pci helper function and macro for numa.

v7:
- managing numa memory mapping using memblock.
- Incorporated review comments of Mark Rutland.

v6:
- defined and implemented the numa dt binding using node property proximity and device node distance-map.
- renamed dt_numa to of_numa

v5:
- created base verion of numa.c which creates dummy numa without using dt on single socket platforms. Then added patches for dt support.
- Incorporated review comments from Hanjun Guo.

v4:
done changes as per Arnd review comments.

v3:
Added changes to support numa on arm64 based platforms. Tested these patches on cavium's multinode(2 node topology) platform. In this patchset, defined and implemented dt bindings for numa mapping for core and memory using device node property arm,associativity.

v2:
Defined and implemented numa map for memory, cores to node and proximity distance matrix of nodes.

v1:
Initial patchset to support numa on arm64 platforms.

Note: 1. This patchset is tested for NUMA and without NUMA with dt
(both with and without NUMA bindings) on thunderx single socket and dual socket boards.

Ard Biesheuvel (6):
of/fdt: make generic early_init_dt_add_memory_arch() a weak alias
arm64: override generic version of early_init_dt_add_memory_arch()
efi: move FDT handling to separate object file
arm64/efi: move EFI /chosen node parsing before early FDT processing arm64/efi: ignore DT memory nodes instead of removing them arm64/efi: ignore DT memreserve entries instead of removing them

Ganapatrao Kulkarni (4):
Documentation, dt, numa: dt bindings for NUMA. dt, numa: Add NUMA dt binding implementation. arm64, numa: Add NUMA support for arm64 platforms. arm64, mm, numa: Add NUMA balancing support for arm64.

 Documentation/devicetree/bindings/numa.txt | 272 +++++++++++++++++++
 arch/arm64/Kconfig                         |  27 ++
 arch/arm64/include/asm/efi.h               |   2 +
 arch/arm64/include/asm/mmzone.h            |  12 +
 arch/arm64/include/asm/numa.h              |  45 ++++
 arch/arm64/include/asm/pgtable.h           |  15 ++
 arch/arm64/include/asm/topology.h          |  10 +
 arch/arm64/kernel/pci.c                    |  10 +
 arch/arm64/kernel/setup.c                  |   7 +
 arch/arm64/kernel/smp.c                    |   4 +
 arch/arm64/mm/Makefile                     |   1 +
 arch/arm64/mm/init.c                       |  46 +++-
 arch/arm64/mm/mmu.c                        |   1 +
 arch/arm64/mm/numa.c                       | 403 +++++++++++++++++++++++++++++
 drivers/firmware/efi/Makefile              |   1 +
 drivers/firmware/efi/arm-init.c            |  36 ++-
 drivers/firmware/efi/efi-fdt.c             |  73 ++++++
 drivers/firmware/efi/efi.c                 |  84 ------
 drivers/firmware/efi/libstub/fdt.c         |  33 +--
 drivers/of/Kconfig                         |   3 +
 drivers/of/Makefile                        |   1 +
 drivers/of/fdt.c                           |   7 +-
 drivers/of/of_numa.c                       | 211 +++++++++++++++
 include/linux/efi.h                        |   2 +-
 include/linux/of.h                         |   9 +
 include/linux/of_fdt.h                     |   1 +
 26 files changed, 1178 insertions(+), 138 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/numa.txt
 create mode 100644 arch/arm64/include/asm/mmzone.h
 create mode 100644 arch/arm64/include/asm/numa.h
 create mode 100644 arch/arm64/mm/numa.c
 create mode 100644 drivers/firmware/efi/efi-fdt.c
 create mode 100644 drivers/of/of_numa.c

--
1.8.3.1

#20 lore raw
Quoted 12 lines · Ard Biesheuvel
Quoted 10 lines · David Daney

From: David Daney <[email protected]>

v11:
- Dropped cleanup patches for other architectures, they will be submitted as a separate set after more testing.

- Added patch set from Ard Biesheuvel that are needed to make the whole thing actually work. Previously this was a separate set.

Quoted 9 lines

This series is out of date, unfortunately. The EFI init code is now (as of v4.5-rc1) shared between ARM and arm64, which means that any changes you make must be made on both sides. This applies to the split between parsing the EFI dt nodes and performing the actual EFI init, but also to the early_init_dt_add_memory_arch() changes. I am happy to have a go at this, but first I need a clear statement from whoever maintains that area that keeping memory nodes *just* for the annotations (and otherwise ignore them) is the way forward (Rob? Grant?)

Wasn't there the approach to check for consistency between efi tables and devicetree? Thus, DT is actually not ignored but rather checked if it is in sync with efi tables.

-Robert

#21 lore raw
Quoted 23 lines · Robert Richter
Quoted 12 lines · Ard Biesheuvel
Quoted 10 lines · David Daney

From: David Daney <[email protected]>

v11:
- Dropped cleanup patches for other architectures, they will be submitted as a separate set after more testing.

- Added patch set from Ard Biesheuvel that are needed to make the whole thing actually work. Previously this was a separate set.

Quoted 9 lines

This series is out of date, unfortunately. The EFI init code is now (as of v4.5-rc1) shared between ARM and arm64, which means that any changes you make must be made on both sides. This applies to the split between parsing the EFI dt nodes and performing the actual EFI init, but also to the early_init_dt_add_memory_arch() changes. I am happy to have a go at this, but first I need a clear statement from whoever maintains that area that keeping memory nodes *just* for the annotations (and otherwise ignore them) is the way forward (Rob? Grant?)

Quoted 4 lines

Wasn't there the approach to check for consistency between efi tables and devicetree? Thus, DT is actually not ignored but rather checked if it is in sync with efi tables.

I proposed such an approach for the /reserved-memory node, but not for the memory nodes themselves.

But thinking about this a bit more, I think we can replace the whole 6 piece series with the following patch
(apologies for the mangled whitespace). The reason is that, if we decide to keep the memory nodes, we might just as well parse them as usual (and use generic code to spot any problems etc), and just discard the regions it describes. This completely solves the ARM vs arm64 problem.

---------8<--------------
Subject: [PATCH] efi: ARM/arm64: ignore DT memory nodes instead of removing
them

There are two problems with the UEFI stub DT memory node removal routine:
- it deletes nodes as it traverses the tree, which happens to work but is not supported, as deletion invalidates the node iterator;
- deleting memory nodes entirely may discard annotations in the form of additional properties on the nodes.

Since the discovery of DT memory nodes occurs strictly before the UEFI init sequence, we can simply clear the memblock memory table before parsing the UEFI memory map. This way, it is no longer necessary to remove the nodes, so we can remove that logic from the stub as well.

---
 drivers/firmware/efi/arm-init.c    |  8 +++++++
 drivers/firmware/efi/libstub/fdt.c | 24 +-------------------
 2 files changed, 9 insertions(+), 23 deletions(-)
drivers/firmware/efi/arm-init.c +8 -0
index 9e15d571b53c..40c9d8596d69 100644
@@ -143,6 +143,14 @@ static __init void reserve_regions(void)
  if (efi_enabled(EFI_DBG))
  pr_info("Processing EFI memory map:\n");
 
+ /*
+ * Discard memblocks discovered so far: if there are any at this
+ * point, they originate from memory nodes in the DT, and UEFI
+ * uses its own memory map instead.
+ */
+ memblock_dump_all();
+ memblock_remove(0, ULLONG_MAX);
+
  for_each_efi_memory_desc(&memmap, md) {
  paddr = md->phys_addr;
  npages = md->num_pages;
(quoted diff) +0 -0

b/drivers/firmware/efi/libstub/fdt.c
index 6dba78aef337..e58abfa953cc 100644

drivers/firmware/efi/libstub/fdt.c +0 -0
@@ -24,7 +24,7 @@ efi_status_t update_fdt(efi_system_table_t

*sys_table, void *orig_fdt,
unsigned long map_size, unsigned long desc_size, u32 desc_ver)
{
- int node, prev, num_rsv;
+ int node, num_rsv;
int status;
u32 fdt_val32;
u64 fdt_val64;
@@ -54,28 +54,6 @@
goto fdt_set_fail;

/*
- * Delete any memory nodes present. We must delete nodes which
- * early_init_dt_scan_memory may try to use.
- */
- prev = 0;
- for (;;) {
- const char *type;
- int len;
-
- node = fdt_next_node(fdt, prev, NULL);
- if (node < 0)
- break;
-
- type = fdt_getprop(fdt, node, "device_type", &len);
- if (type && strncmp(type, "memory", len) == 0) {
- fdt_del_node(fdt, node);
- continue;
- }
-
- prev = node;
- }
-
- /*
* Delete all memory reserve map entries. When booting via UEFI,
* kernel will use the UEFI memory map to find reserved regions. */

Signature · 1 line
1.9.1