.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) IBM Corporation, 2014, 2017 |
---|
3 | 4 | * 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. |
---|
9 | 5 | */ |
---|
10 | 6 | |
---|
11 | 7 | #define pr_fmt(fmt) "memtrace: " fmt |
---|
.. | .. |
---|
20 | 16 | #include <linux/slab.h> |
---|
21 | 17 | #include <linux/memory.h> |
---|
22 | 18 | #include <linux/memory_hotplug.h> |
---|
| 19 | +#include <linux/numa.h> |
---|
23 | 20 | #include <asm/machdep.h> |
---|
24 | 21 | #include <asm/debugfs.h> |
---|
25 | 22 | |
---|
.. | .. |
---|
91 | 88 | /* called with device_hotplug_lock held */ |
---|
92 | 89 | static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages) |
---|
93 | 90 | { |
---|
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); |
---|
95 | 93 | |
---|
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)) |
---|
98 | 95 | return false; |
---|
99 | 96 | |
---|
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); |
---|
102 | 99 | |
---|
103 | 100 | 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); |
---|
106 | 103 | return false; |
---|
107 | 104 | } |
---|
108 | 105 | |
---|
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); |
---|
111 | 108 | |
---|
112 | 109 | |
---|
113 | 110 | return true; |
---|
.. | .. |
---|
213 | 210 | |
---|
214 | 211 | snprintf(ent->name, 16, "%08x", ent->nid); |
---|
215 | 212 | 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 | | - } |
---|
221 | 213 | |
---|
222 | 214 | ent->dir = dir; |
---|
223 | 215 | debugfs_create_file("trace", 0400, dir, ent, &memtrace_fops); |
---|
.. | .. |
---|
246 | 238 | ent = &memtrace_array[i]; |
---|
247 | 239 | |
---|
248 | 240 | /* We have onlined this chunk previously */ |
---|
249 | | - if (ent->nid == -1) |
---|
| 241 | + if (ent->nid == NUMA_NO_NODE) |
---|
250 | 242 | continue; |
---|
251 | 243 | |
---|
252 | 244 | /* Remove from io mappings */ |
---|
.. | .. |
---|
255 | 247 | ent->mem = 0; |
---|
256 | 248 | } |
---|
257 | 249 | |
---|
258 | | - if (add_memory(ent->nid, ent->start, ent->size)) { |
---|
| 250 | + if (add_memory(ent->nid, ent->start, ent->size, MHP_NONE)) { |
---|
259 | 251 | pr_err("Failed to add trace memory to node %d\n", |
---|
260 | 252 | ent->nid); |
---|
261 | 253 | ret += 1; |
---|
262 | 254 | continue; |
---|
263 | 255 | } |
---|
264 | 256 | |
---|
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(); |
---|
276 | 261 | |
---|
277 | 262 | /* |
---|
278 | 263 | * Memory was added successfully so clean up references to it |
---|
.. | .. |
---|
280 | 265 | */ |
---|
281 | 266 | debugfs_remove_recursive(ent->dir); |
---|
282 | 267 | 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; |
---|
284 | 269 | } |
---|
285 | 270 | if (ret) |
---|
286 | 271 | return ret; |
---|
.. | .. |
---|
348 | 333 | { |
---|
349 | 334 | memtrace_debugfs_dir = debugfs_create_dir("memtrace", |
---|
350 | 335 | powerpc_debugfs_root); |
---|
351 | | - if (!memtrace_debugfs_dir) |
---|
352 | | - return -1; |
---|
353 | 336 | |
---|
354 | 337 | debugfs_create_file("enable", 0600, memtrace_debugfs_dir, |
---|
355 | 338 | NULL, &memtrace_init_fops); |
---|