forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/arch/powerpc/platforms/powernv/memtrace.c
....@@ -1,11 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) IBM Corporation, 2014, 2017
34 * Anton Blanchard, Rashmica Gupta.
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation; either version 2 of the License, or
8
- * (at your option) any later version.
95 */
106
117 #define pr_fmt(fmt) "memtrace: " fmt
....@@ -20,6 +16,7 @@
2016 #include <linux/slab.h>
2117 #include <linux/memory.h>
2218 #include <linux/memory_hotplug.h>
19
+#include <linux/numa.h>
2320 #include <asm/machdep.h>
2421 #include <asm/debugfs.h>
2522
....@@ -91,23 +88,23 @@
9188 /* called with device_hotplug_lock held */
9289 static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages)
9390 {
94
- u64 end_pfn = start_pfn + nr_pages - 1;
91
+ const unsigned long start = PFN_PHYS(start_pfn);
92
+ const unsigned long size = PFN_PHYS(nr_pages);
9593
96
- if (walk_memory_range(start_pfn, end_pfn, NULL,
97
- check_memblock_online))
94
+ if (walk_memory_blocks(start, size, NULL, check_memblock_online))
9895 return false;
9996
100
- walk_memory_range(start_pfn, end_pfn, (void *)MEM_GOING_OFFLINE,
101
- change_memblock_state);
97
+ walk_memory_blocks(start, size, (void *)MEM_GOING_OFFLINE,
98
+ change_memblock_state);
10299
103100 if (offline_pages(start_pfn, nr_pages)) {
104
- walk_memory_range(start_pfn, end_pfn, (void *)MEM_ONLINE,
105
- change_memblock_state);
101
+ walk_memory_blocks(start, size, (void *)MEM_ONLINE,
102
+ change_memblock_state);
106103 return false;
107104 }
108105
109
- walk_memory_range(start_pfn, end_pfn, (void *)MEM_OFFLINE,
110
- change_memblock_state);
106
+ walk_memory_blocks(start, size, (void *)MEM_OFFLINE,
107
+ change_memblock_state);
111108
112109
113110 return true;
....@@ -213,11 +210,6 @@
213210
214211 snprintf(ent->name, 16, "%08x", ent->nid);
215212 dir = debugfs_create_dir(ent->name, memtrace_debugfs_dir);
216
- if (!dir) {
217
- pr_err("Failed to create debugfs directory for node %d\n",
218
- ent->nid);
219
- return -1;
220
- }
221213
222214 ent->dir = dir;
223215 debugfs_create_file("trace", 0400, dir, ent, &memtrace_fops);
....@@ -246,7 +238,7 @@
246238 ent = &memtrace_array[i];
247239
248240 /* We have onlined this chunk previously */
249
- if (ent->nid == -1)
241
+ if (ent->nid == NUMA_NO_NODE)
250242 continue;
251243
252244 /* Remove from io mappings */
....@@ -255,24 +247,17 @@
255247 ent->mem = 0;
256248 }
257249
258
- if (add_memory(ent->nid, ent->start, ent->size)) {
250
+ if (add_memory(ent->nid, ent->start, ent->size, MHP_NONE)) {
259251 pr_err("Failed to add trace memory to node %d\n",
260252 ent->nid);
261253 ret += 1;
262254 continue;
263255 }
264256
265
- /*
266
- * If kernel isn't compiled with the auto online option
267
- * we need to online the memory ourselves.
268
- */
269
- if (!memhp_auto_online) {
270
- lock_device_hotplug();
271
- walk_memory_range(PFN_DOWN(ent->start),
272
- PFN_UP(ent->start + ent->size - 1),
273
- NULL, online_mem_block);
274
- unlock_device_hotplug();
275
- }
257
+ lock_device_hotplug();
258
+ walk_memory_blocks(ent->start, ent->size, NULL,
259
+ online_mem_block);
260
+ unlock_device_hotplug();
276261
277262 /*
278263 * Memory was added successfully so clean up references to it
....@@ -280,7 +265,7 @@
280265 */
281266 debugfs_remove_recursive(ent->dir);
282267 pr_info("Added trace memory back to node %d\n", ent->nid);
283
- ent->size = ent->start = ent->nid = -1;
268
+ ent->size = ent->start = ent->nid = NUMA_NO_NODE;
284269 }
285270 if (ret)
286271 return ret;
....@@ -348,8 +333,6 @@
348333 {
349334 memtrace_debugfs_dir = debugfs_create_dir("memtrace",
350335 powerpc_debugfs_root);
351
- if (!memtrace_debugfs_dir)
352
- return -1;
353336
354337 debugfs_create_file("enable", 0600, memtrace_debugfs_dir,
355338 NULL, &memtrace_init_fops);