hc
2024-10-16 50a212ec906f7524620675f0c57357691c26c81f
kernel/arch/arm64/mm/numa.c
....@@ -1,26 +1,14 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * NUMA support, based on the x86 implementation.
34 *
45 * Copyright (C) 2015 Cavium Inc.
56 * Author: Ganapatrao Kulkarni <gkulkarni@cavium.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
187 */
198
209 #define pr_fmt(fmt) "NUMA: " fmt
2110
2211 #include <linux/acpi.h>
23
-#include <linux/bootmem.h>
2412 #include <linux/memblock.h>
2513 #include <linux/module.h>
2614 #include <linux/of.h>
....@@ -41,7 +29,7 @@
4129 {
4230 if (!opt)
4331 return -EINVAL;
44
- if (!strncmp(opt, "off", 3))
32
+ if (str_has_prefix(opt, "off"))
4533 numa_off = true;
4634
4735 return 0;
....@@ -125,11 +113,11 @@
125113 }
126114
127115 /* cpumask_of_node() will now work */
128
- pr_debug("Node to cpumask map for %d nodes\n", nr_node_ids);
116
+ pr_debug("Node to cpumask map for %u nodes\n", nr_node_ids);
129117 }
130118
131119 /*
132
- * Set the cpu to node and mem mapping
120
+ * Set the cpu to node and mem mapping
133121 */
134122 void numa_store_cpu_info(unsigned int cpu)
135123 {
....@@ -172,7 +160,7 @@
172160 {
173161 int nid = early_cpu_to_node(cpu);
174162
175
- return memblock_virt_alloc_try_nid(size, align,
163
+ return memblock_alloc_try_nid(size, align,
176164 __pa(MAX_DMA_ADDRESS), MEMBLOCK_ALLOC_ACCESSIBLE, nid);
177165 }
178166
....@@ -205,7 +193,7 @@
205193 #endif
206194
207195 /**
208
- * numa_add_memblk - Set node id to memblk
196
+ * numa_add_memblk() - Set node id to memblk
209197 * @nid: NUMA node ID of the new memblk
210198 * @start: Start address of the new memblk
211199 * @end: End address of the new memblk
....@@ -228,7 +216,7 @@
228216 return ret;
229217 }
230218
231
-/**
219
+/*
232220 * Initialize NODE_DATA for a node on the local memory
233221 */
234222 static void __init setup_node_data(int nid, u64 start_pfn, u64 end_pfn)
....@@ -241,7 +229,11 @@
241229 if (start_pfn >= end_pfn)
242230 pr_info("Initmem setup node %d [<memory-less node>]\n", nid);
243231
244
- nd_pa = memblock_alloc_try_nid(nd_size, SMP_CACHE_BYTES, nid);
232
+ nd_pa = memblock_phys_alloc_try_nid(nd_size, SMP_CACHE_BYTES, nid);
233
+ if (!nd_pa)
234
+ panic("Cannot allocate %zu bytes for node %d data\n",
235
+ nd_size, nid);
236
+
245237 nd = __va(nd_pa);
246238
247239 /* report and initialize */
....@@ -258,7 +250,7 @@
258250 NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
259251 }
260252
261
-/**
253
+/*
262254 * numa_free_distance
263255 *
264256 * The current table is freed.
....@@ -278,10 +270,8 @@
278270 numa_distance = NULL;
279271 }
280272
281
-/**
282
- *
273
+/*
283274 * Create a new NUMA distance table.
284
- *
285275 */
286276 static int __init numa_alloc_distance(void)
287277 {
....@@ -312,7 +302,7 @@
312302 }
313303
314304 /**
315
- * numa_set_distance - Set inter node NUMA distance from node to node.
305
+ * numa_set_distance() - Set inter node NUMA distance from node to node.
316306 * @from: the 'from' node to set distance
317307 * @to: the 'to' node to set distance
318308 * @distance: NUMA distance
....@@ -322,7 +312,6 @@
322312 *
323313 * If @from or @to is higher than the highest known node or lower than zero
324314 * or @distance doesn't make sense, the call is ignored.
325
- *
326315 */
327316 void __init numa_set_distance(int from, int to, int distance)
328317 {
....@@ -348,7 +337,7 @@
348337 numa_distance[from * numa_distance_cnt + to] = distance;
349338 }
350339
351
-/**
340
+/*
352341 * Return NUMA distance @from to @to
353342 */
354343 int __node_distance(int from, int to)
....@@ -365,13 +354,16 @@
365354 struct memblock_region *mblk;
366355
367356 /* Check that valid nid is set to memblks */
368
- for_each_memblock(memory, mblk)
369
- if (mblk->nid == NUMA_NO_NODE || mblk->nid >= MAX_NUMNODES) {
357
+ for_each_mem_region(mblk) {
358
+ int mblk_nid = memblock_get_region_node(mblk);
359
+
360
+ if (mblk_nid == NUMA_NO_NODE || mblk_nid >= MAX_NUMNODES) {
370361 pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
371
- mblk->nid, mblk->base,
362
+ mblk_nid, mblk->base,
372363 mblk->base + mblk->size - 1);
373364 return -EINVAL;
374365 }
366
+ }
375367
376368 /* Finally register nodes. */
377369 for_each_node_mask(nid, numa_nodes_parsed) {
....@@ -395,7 +387,6 @@
395387 nodes_clear(numa_nodes_parsed);
396388 nodes_clear(node_possible_map);
397389 nodes_clear(node_online_map);
398
- numa_free_distance();
399390
400391 ret = numa_alloc_distance();
401392 if (ret < 0)
....@@ -403,46 +394,49 @@
403394
404395 ret = init_func();
405396 if (ret < 0)
406
- return ret;
397
+ goto out_free_distance;
407398
408399 if (nodes_empty(numa_nodes_parsed)) {
409400 pr_info("No NUMA configuration found\n");
410
- return -EINVAL;
401
+ ret = -EINVAL;
402
+ goto out_free_distance;
411403 }
412404
413405 ret = numa_register_nodes();
414406 if (ret < 0)
415
- return ret;
407
+ goto out_free_distance;
416408
417409 setup_node_to_cpumask_map();
418410
419411 return 0;
412
+out_free_distance:
413
+ numa_free_distance();
414
+ return ret;
420415 }
421416
422417 /**
423
- * dummy_numa_init - Fallback dummy NUMA init
418
+ * dummy_numa_init() - Fallback dummy NUMA init
424419 *
425420 * Used if there's no underlying NUMA architecture, NUMA initialization
426421 * fails, or NUMA is disabled on the command line.
427422 *
428423 * Must online at least one node (node 0) and add memory blocks that cover all
429424 * allowed memory. It is unlikely that this function fails.
425
+ *
426
+ * Return: 0 on success, -errno on failure.
430427 */
431428 static int __init dummy_numa_init(void)
432429 {
430
+ phys_addr_t start = memblock_start_of_DRAM();
431
+ phys_addr_t end = memblock_end_of_DRAM();
433432 int ret;
434
- struct memblock_region *mblk;
435433
436434 if (numa_off)
437435 pr_info("NUMA disabled\n"); /* Forced off on command line. */
438
- pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n",
439
- memblock_start_of_DRAM(), memblock_end_of_DRAM() - 1);
436
+ pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1);
440437
441
- for_each_memblock(memory, mblk) {
442
- ret = numa_add_memblk(0, mblk->base, mblk->base + mblk->size);
443
- if (!ret)
444
- continue;
445
-
438
+ ret = numa_add_memblk(0, start, end);
439
+ if (ret) {
446440 pr_err("NUMA init failed\n");
447441 return ret;
448442 }
....@@ -452,10 +446,10 @@
452446 }
453447
454448 /**
455
- * arm64_numa_init - Initialize NUMA
449
+ * arm64_numa_init() - Initialize NUMA
456450 *
457
- * Try each configured NUMA initialization method until one succeeds. The
458
- * last fallback is dummy single node config encomapssing whole memory.
451
+ * Try each configured NUMA initialization method until one succeeds. The
452
+ * last fallback is dummy single node config encompassing whole memory.
459453 */
460454 void __init arm64_numa_init(void)
461455 {