Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 2 | /* |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 3 | * Memory subsystem support |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 4 | * |
| 5 | * Written by Matt Tolentino <matthew.e.tolentino@intel.com> |
| 6 | * Dave Hansen <haveblue@us.ibm.com> |
| 7 | * |
| 8 | * This file provides the necessary infrastructure to represent |
| 9 | * a SPARSEMEM-memory-model system's physical memory in /sysfs. |
| 10 | * All arch-independent code that assumes MEMORY_HOTPLUG requires |
| 11 | * SPARSEMEM should be contained here, or in mm/memory_hotplug.c. |
| 12 | */ |
| 13 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 16 | #include <linux/topology.h> |
Randy.Dunlap | c59ede7 | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 17 | #include <linux/capability.h> |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 18 | #include <linux/device.h> |
| 19 | #include <linux/memory.h> |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 20 | #include <linux/memory_hotplug.h> |
| 21 | #include <linux/mm.h> |
Shaohua Li | 9f1b16a | 2008-10-18 20:27:12 -0700 | [diff] [blame] | 22 | #include <linux/stat.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Scott Cheloha | 4fb6eab | 2020-06-03 16:03:48 -0700 | [diff] [blame] | 24 | #include <linux/xarray.h> |
Shaohua Li | 9f1b16a | 2008-10-18 20:27:12 -0700 | [diff] [blame] | 25 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 26 | #include <linux/atomic.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 27 | #include <linux/uaccess.h> |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 28 | |
| 29 | #define MEMORY_CLASS_NAME "memory" |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 30 | |
David Hildenbrand | 4dc8207 | 2020-04-06 20:07:24 -0700 | [diff] [blame] | 31 | static const char *const online_type_to_str[] = { |
| 32 | [MMOP_OFFLINE] = "offline", |
| 33 | [MMOP_ONLINE] = "online", |
| 34 | [MMOP_ONLINE_KERNEL] = "online_kernel", |
| 35 | [MMOP_ONLINE_MOVABLE] = "online_movable", |
| 36 | }; |
| 37 | |
David Hildenbrand | 5f47adf | 2020-04-06 20:07:44 -0700 | [diff] [blame] | 38 | int memhp_online_type_from_str(const char *str) |
David Hildenbrand | 4dc8207 | 2020-04-06 20:07:24 -0700 | [diff] [blame] | 39 | { |
| 40 | int i; |
| 41 | |
| 42 | for (i = 0; i < ARRAY_SIZE(online_type_to_str); i++) { |
| 43 | if (sysfs_streq(str, online_type_to_str[i])) |
| 44 | return i; |
| 45 | } |
| 46 | return -EINVAL; |
| 47 | } |
| 48 | |
Gu Zheng | 7315f0c | 2013-08-28 14:38:27 +0800 | [diff] [blame] | 49 | #define to_memory_block(dev) container_of(dev, struct memory_block, dev) |
| 50 | |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 51 | static int sections_per_block; |
| 52 | |
David Hildenbrand | 90ec010f | 2019-07-18 15:57:40 -0700 | [diff] [blame] | 53 | static inline unsigned long base_memory_block_id(unsigned long section_nr) |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 54 | { |
| 55 | return section_nr / sections_per_block; |
| 56 | } |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 57 | |
David Hildenbrand | 90ec010f | 2019-07-18 15:57:40 -0700 | [diff] [blame] | 58 | static inline unsigned long pfn_to_block_id(unsigned long pfn) |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 59 | { |
| 60 | return base_memory_block_id(pfn_to_section_nr(pfn)); |
| 61 | } |
| 62 | |
David Hildenbrand | ea88464 | 2019-07-18 15:57:50 -0700 | [diff] [blame] | 63 | static inline unsigned long phys_to_block_id(unsigned long phys) |
| 64 | { |
| 65 | return pfn_to_block_id(PFN_DOWN(phys)); |
| 66 | } |
| 67 | |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 68 | static int memory_subsys_online(struct device *dev); |
| 69 | static int memory_subsys_offline(struct device *dev); |
| 70 | |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 71 | static struct bus_type memory_subsys = { |
Kay Sievers | af5ca3f4 | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 72 | .name = MEMORY_CLASS_NAME, |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 73 | .dev_name = MEMORY_CLASS_NAME, |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 74 | .online = memory_subsys_online, |
| 75 | .offline = memory_subsys_offline, |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Scott Cheloha | 4fb6eab | 2020-06-03 16:03:48 -0700 | [diff] [blame] | 78 | /* |
| 79 | * Memory blocks are cached in a local radix tree to avoid |
| 80 | * a costly linear search for the corresponding device on |
| 81 | * the subsystem bus. |
| 82 | */ |
| 83 | static DEFINE_XARRAY(memory_blocks); |
| 84 | |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 85 | static BLOCKING_NOTIFIER_HEAD(memory_chain); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 86 | |
Andy Whitcroft | 98a38eb | 2006-01-06 00:10:35 -0800 | [diff] [blame] | 87 | int register_memory_notifier(struct notifier_block *nb) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 88 | { |
Ioana Ciornei | 2aeebca | 2015-03-08 12:48:35 +0200 | [diff] [blame] | 89 | return blocking_notifier_chain_register(&memory_chain, nb); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 90 | } |
Hannes Hering | 3c82c30 | 2008-05-07 14:43:01 +0200 | [diff] [blame] | 91 | EXPORT_SYMBOL(register_memory_notifier); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 92 | |
Andy Whitcroft | 98a38eb | 2006-01-06 00:10:35 -0800 | [diff] [blame] | 93 | void unregister_memory_notifier(struct notifier_block *nb) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 94 | { |
Ioana Ciornei | 2aeebca | 2015-03-08 12:48:35 +0200 | [diff] [blame] | 95 | blocking_notifier_chain_unregister(&memory_chain, nb); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 96 | } |
Hannes Hering | 3c82c30 | 2008-05-07 14:43:01 +0200 | [diff] [blame] | 97 | EXPORT_SYMBOL(unregister_memory_notifier); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 98 | |
Yasuaki Ishimatsu | fa7194e | 2012-12-11 16:00:44 -0800 | [diff] [blame] | 99 | static void memory_block_release(struct device *dev) |
| 100 | { |
Gu Zheng | 7315f0c | 2013-08-28 14:38:27 +0800 | [diff] [blame] | 101 | struct memory_block *mem = to_memory_block(dev); |
Yasuaki Ishimatsu | fa7194e | 2012-12-11 16:00:44 -0800 | [diff] [blame] | 102 | |
| 103 | kfree(mem); |
| 104 | } |
| 105 | |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 106 | unsigned long __weak memory_block_size_bytes(void) |
| 107 | { |
| 108 | return MIN_MEMORY_BLOCK_SIZE; |
| 109 | } |
Dave Hansen | c221c0b | 2019-02-25 10:57:40 -0800 | [diff] [blame] | 110 | EXPORT_SYMBOL_GPL(memory_block_size_bytes); |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 111 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 112 | /* |
David Hildenbrand | f915fb7 | 2019-09-23 15:35:43 -0700 | [diff] [blame] | 113 | * Show the first physical section index (number) of this memory block. |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 114 | */ |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 115 | static ssize_t phys_index_show(struct device *dev, |
| 116 | struct device_attribute *attr, char *buf) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 117 | { |
Gu Zheng | 7315f0c | 2013-08-28 14:38:27 +0800 | [diff] [blame] | 118 | struct memory_block *mem = to_memory_block(dev); |
Nathan Fontenot | d336016 | 2011-01-20 10:44:29 -0600 | [diff] [blame] | 119 | unsigned long phys_index; |
| 120 | |
| 121 | phys_index = mem->start_section_nr / sections_per_block; |
| 122 | return sprintf(buf, "%08lx\n", phys_index); |
| 123 | } |
| 124 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 125 | /* |
David Hildenbrand | 53cdc1c | 2020-03-28 19:17:19 -0700 | [diff] [blame] | 126 | * Legacy interface that we cannot remove. Always indicate "removable" |
| 127 | * with CONFIG_MEMORY_HOTREMOVE - bad heuristic. |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 128 | */ |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 129 | static ssize_t removable_show(struct device *dev, struct device_attribute *attr, |
| 130 | char *buf) |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 131 | { |
David Hildenbrand | 53cdc1c | 2020-03-28 19:17:19 -0700 | [diff] [blame] | 132 | return sprintf(buf, "%d\n", (int)IS_ENABLED(CONFIG_MEMORY_HOTREMOVE)); |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /* |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 136 | * online, offline, going offline, etc. |
| 137 | */ |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 138 | static ssize_t state_show(struct device *dev, struct device_attribute *attr, |
| 139 | char *buf) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 140 | { |
Gu Zheng | 7315f0c | 2013-08-28 14:38:27 +0800 | [diff] [blame] | 141 | struct memory_block *mem = to_memory_block(dev); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 142 | ssize_t len = 0; |
| 143 | |
| 144 | /* |
| 145 | * We can probably put these states in a nice little array |
| 146 | * so that they're not open-coded |
| 147 | */ |
| 148 | switch (mem->state) { |
Ioana Ciornei | 3d3af6a | 2015-03-08 12:29:04 +0200 | [diff] [blame] | 149 | case MEM_ONLINE: |
| 150 | len = sprintf(buf, "online\n"); |
| 151 | break; |
| 152 | case MEM_OFFLINE: |
| 153 | len = sprintf(buf, "offline\n"); |
| 154 | break; |
| 155 | case MEM_GOING_OFFLINE: |
| 156 | len = sprintf(buf, "going-offline\n"); |
| 157 | break; |
| 158 | default: |
| 159 | len = sprintf(buf, "ERROR-UNKNOWN-%ld\n", |
| 160 | mem->state); |
| 161 | WARN_ON(1); |
| 162 | break; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | return len; |
| 166 | } |
| 167 | |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 168 | int memory_notify(unsigned long val, void *v) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 169 | { |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 170 | return blocking_notifier_call_chain(&memory_chain, val, v); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /* |
| 174 | * MEMORY_HOTPLUG depends on SPARSEMEM in mm/Kconfig, so it is |
| 175 | * OK to have direct references to sparsemem variables in here. |
| 176 | */ |
| 177 | static int |
Baoquan He | 063b8a4 | 2019-05-13 17:19:35 -0700 | [diff] [blame] | 178 | memory_block_action(unsigned long start_section_nr, unsigned long action, |
David Hildenbrand | bd5c234 | 2020-01-30 22:14:54 -0800 | [diff] [blame] | 179 | int online_type, int nid) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 180 | { |
Wen Congyang | a16cee1 | 2012-10-08 16:33:58 -0700 | [diff] [blame] | 181 | unsigned long start_pfn; |
Anton Blanchard | 5409d2c | 2011-05-11 17:25:14 +1000 | [diff] [blame] | 182 | unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 183 | int ret; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 184 | |
Baoquan He | 063b8a4 | 2019-05-13 17:19:35 -0700 | [diff] [blame] | 185 | start_pfn = section_nr_to_pfn(start_section_nr); |
Greg Kroah-Hartman | de0ed36 | 2011-10-18 14:00:57 -0700 | [diff] [blame] | 186 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 187 | switch (action) { |
Ioana Ciornei | 3d3af6a | 2015-03-08 12:29:04 +0200 | [diff] [blame] | 188 | case MEM_ONLINE: |
David Hildenbrand | bd5c234 | 2020-01-30 22:14:54 -0800 | [diff] [blame] | 189 | ret = online_pages(start_pfn, nr_pages, online_type, nid); |
Ioana Ciornei | 3d3af6a | 2015-03-08 12:29:04 +0200 | [diff] [blame] | 190 | break; |
| 191 | case MEM_OFFLINE: |
| 192 | ret = offline_pages(start_pfn, nr_pages); |
| 193 | break; |
| 194 | default: |
| 195 | WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " |
Baoquan He | 063b8a4 | 2019-05-13 17:19:35 -0700 | [diff] [blame] | 196 | "%ld\n", __func__, start_section_nr, action, action); |
Ioana Ciornei | 3d3af6a | 2015-03-08 12:29:04 +0200 | [diff] [blame] | 197 | ret = -EINVAL; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 198 | } |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 199 | |
| 200 | return ret; |
| 201 | } |
| 202 | |
Nathan Fontenot | dc18d70 | 2017-02-24 15:00:02 -0800 | [diff] [blame] | 203 | static int memory_block_change_state(struct memory_block *mem, |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 204 | unsigned long to_state, unsigned long from_state_req) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 205 | { |
Greg Kroah-Hartman | de0ed36 | 2011-10-18 14:00:57 -0700 | [diff] [blame] | 206 | int ret = 0; |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 207 | |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 208 | if (mem->state != from_state_req) |
| 209 | return -EINVAL; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 210 | |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 211 | if (to_state == MEM_OFFLINE) |
| 212 | mem->state = MEM_GOING_OFFLINE; |
| 213 | |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 214 | ret = memory_block_action(mem->start_section_nr, to_state, |
David Hildenbrand | bd5c234 | 2020-01-30 22:14:54 -0800 | [diff] [blame] | 215 | mem->online_type, mem->nid); |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 216 | |
Rafael J. Wysocki | b2c064b | 2013-05-23 10:38:55 +0200 | [diff] [blame] | 217 | mem->state = ret ? from_state_req : to_state; |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 218 | |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 219 | return ret; |
| 220 | } |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 221 | |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 222 | /* The device lock serializes operations on memory_subsys_[online|offline] */ |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 223 | static int memory_subsys_online(struct device *dev) |
| 224 | { |
Gu Zheng | 7315f0c | 2013-08-28 14:38:27 +0800 | [diff] [blame] | 225 | struct memory_block *mem = to_memory_block(dev); |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 226 | int ret; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 227 | |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 228 | if (mem->state == MEM_ONLINE) |
| 229 | return 0; |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 230 | |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 231 | /* |
David Hildenbrand | efc978a | 2020-04-06 20:07:20 -0700 | [diff] [blame] | 232 | * When called via device_online() without configuring the online_type, |
| 233 | * we want to default to MMOP_ONLINE. |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 234 | */ |
David Hildenbrand | efc978a | 2020-04-06 20:07:20 -0700 | [diff] [blame] | 235 | if (mem->online_type == MMOP_OFFLINE) |
David Hildenbrand | 956f8b4 | 2020-04-06 20:07:16 -0700 | [diff] [blame] | 236 | mem->online_type = MMOP_ONLINE; |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 237 | |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 238 | ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); |
David Hildenbrand | efc978a | 2020-04-06 20:07:20 -0700 | [diff] [blame] | 239 | mem->online_type = MMOP_OFFLINE; |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 240 | |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 241 | return ret; |
| 242 | } |
| 243 | |
| 244 | static int memory_subsys_offline(struct device *dev) |
| 245 | { |
Gu Zheng | 7315f0c | 2013-08-28 14:38:27 +0800 | [diff] [blame] | 246 | struct memory_block *mem = to_memory_block(dev); |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 247 | |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 248 | if (mem->state == MEM_OFFLINE) |
| 249 | return 0; |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 250 | |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 251 | return memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 252 | } |
| 253 | |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 254 | static ssize_t state_store(struct device *dev, struct device_attribute *attr, |
| 255 | const char *buf, size_t count) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 256 | { |
David Hildenbrand | 4dc8207 | 2020-04-06 20:07:24 -0700 | [diff] [blame] | 257 | const int online_type = memhp_online_type_from_str(buf); |
Gu Zheng | 7315f0c | 2013-08-28 14:38:27 +0800 | [diff] [blame] | 258 | struct memory_block *mem = to_memory_block(dev); |
David Hildenbrand | 4dc8207 | 2020-04-06 20:07:24 -0700 | [diff] [blame] | 259 | int ret; |
| 260 | |
| 261 | if (online_type < 0) |
| 262 | return -EINVAL; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 263 | |
Rafael J. Wysocki | 5e33bc4 | 2013-08-28 21:41:01 +0200 | [diff] [blame] | 264 | ret = lock_device_hotplug_sysfs(); |
| 265 | if (ret) |
| 266 | return ret; |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 267 | |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 268 | switch (online_type) { |
Tang Chen | 4f7c6b4 | 2014-08-06 16:05:13 -0700 | [diff] [blame] | 269 | case MMOP_ONLINE_KERNEL: |
| 270 | case MMOP_ONLINE_MOVABLE: |
David Hildenbrand | 956f8b4 | 2020-04-06 20:07:16 -0700 | [diff] [blame] | 271 | case MMOP_ONLINE: |
David Hildenbrand | 381eab4 | 2018-10-30 15:10:29 -0700 | [diff] [blame] | 272 | /* mem->online_type is protected by device_hotplug_lock */ |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 273 | mem->online_type = online_type; |
| 274 | ret = device_online(&mem->dev); |
| 275 | break; |
Tang Chen | 4f7c6b4 | 2014-08-06 16:05:13 -0700 | [diff] [blame] | 276 | case MMOP_OFFLINE: |
Seth Jennings | fa2be40 | 2013-08-20 16:05:05 -0500 | [diff] [blame] | 277 | ret = device_offline(&mem->dev); |
| 278 | break; |
| 279 | default: |
| 280 | ret = -EINVAL; /* should never happen */ |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 281 | } |
Rafael J. Wysocki | 4960e05 | 2013-05-08 14:18:37 +0200 | [diff] [blame] | 282 | |
| 283 | unlock_device_hotplug(); |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 284 | |
Reza Arbab | d66ba15 | 2016-10-07 17:00:15 -0700 | [diff] [blame] | 285 | if (ret < 0) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 286 | return ret; |
Reza Arbab | d66ba15 | 2016-10-07 17:00:15 -0700 | [diff] [blame] | 287 | if (ret) |
| 288 | return -EINVAL; |
| 289 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 290 | return count; |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * phys_device is a bad name for this. What I really want |
| 295 | * is a way to differentiate between memory ranges that |
| 296 | * are part of physical devices that constitute |
| 297 | * a complete removable unit or fru. |
| 298 | * i.e. do these ranges belong to the same physical device, |
| 299 | * s.t. if I offline all of these sections I can then |
| 300 | * remove the physical device? |
| 301 | */ |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 302 | static ssize_t phys_device_show(struct device *dev, |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 303 | struct device_attribute *attr, char *buf) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 304 | { |
Gu Zheng | 7315f0c | 2013-08-28 14:38:27 +0800 | [diff] [blame] | 305 | struct memory_block *mem = to_memory_block(dev); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 306 | return sprintf(buf, "%d\n", mem->phys_device); |
| 307 | } |
| 308 | |
Zhang Zhen | ed2f240 | 2014-10-09 15:26:31 -0700 | [diff] [blame] | 309 | #ifdef CONFIG_MEMORY_HOTREMOVE |
Michal Hocko | e5e6893 | 2017-09-06 16:19:37 -0700 | [diff] [blame] | 310 | static void print_allowed_zone(char *buf, int nid, unsigned long start_pfn, |
| 311 | unsigned long nr_pages, int online_type, |
| 312 | struct zone *default_zone) |
| 313 | { |
| 314 | struct zone *zone; |
| 315 | |
Michal Hocko | e5e6893 | 2017-09-06 16:19:37 -0700 | [diff] [blame] | 316 | zone = zone_for_pfn_range(online_type, nid, start_pfn, nr_pages); |
| 317 | if (zone != default_zone) { |
| 318 | strcat(buf, " "); |
| 319 | strcat(buf, zone->name); |
| 320 | } |
| 321 | } |
| 322 | |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 323 | static ssize_t valid_zones_show(struct device *dev, |
Zhang Zhen | ed2f240 | 2014-10-09 15:26:31 -0700 | [diff] [blame] | 324 | struct device_attribute *attr, char *buf) |
| 325 | { |
| 326 | struct memory_block *mem = to_memory_block(dev); |
Michal Hocko | f1dd2cd | 2017-07-06 15:38:11 -0700 | [diff] [blame] | 327 | unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr); |
Zhang Zhen | ed2f240 | 2014-10-09 15:26:31 -0700 | [diff] [blame] | 328 | unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; |
Michal Hocko | e5e6893 | 2017-09-06 16:19:37 -0700 | [diff] [blame] | 329 | struct zone *default_zone; |
Michal Hocko | f1dd2cd | 2017-07-06 15:38:11 -0700 | [diff] [blame] | 330 | int nid; |
Zhang Zhen | ed2f240 | 2014-10-09 15:26:31 -0700 | [diff] [blame] | 331 | |
Michal Hocko | f1dd2cd | 2017-07-06 15:38:11 -0700 | [diff] [blame] | 332 | /* |
Michal Hocko | f1dd2cd | 2017-07-06 15:38:11 -0700 | [diff] [blame] | 333 | * Check the existing zone. Make sure that we do that only on the |
| 334 | * online nodes otherwise the page_zone is not reliable |
| 335 | */ |
| 336 | if (mem->state == MEM_ONLINE) { |
Mikhail Zaslonko | 4e8346d | 2018-09-04 15:46:09 -0700 | [diff] [blame] | 337 | /* |
| 338 | * The block contains more than one zone can not be offlined. |
| 339 | * This can happen e.g. for ZONE_DMA and ZONE_DMA32 |
| 340 | */ |
David Hildenbrand | 9291799 | 2020-02-03 17:34:26 -0800 | [diff] [blame] | 341 | default_zone = test_pages_in_a_zone(start_pfn, |
| 342 | start_pfn + nr_pages); |
| 343 | if (!default_zone) |
Mikhail Zaslonko | 4e8346d | 2018-09-04 15:46:09 -0700 | [diff] [blame] | 344 | return sprintf(buf, "none\n"); |
David Hildenbrand | 9291799 | 2020-02-03 17:34:26 -0800 | [diff] [blame] | 345 | strcat(buf, default_zone->name); |
Michal Hocko | f1dd2cd | 2017-07-06 15:38:11 -0700 | [diff] [blame] | 346 | goto out; |
Zhang Zhen | ed2f240 | 2014-10-09 15:26:31 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Mikhail Zaslonko | 4e8346d | 2018-09-04 15:46:09 -0700 | [diff] [blame] | 349 | nid = mem->nid; |
David Hildenbrand | 956f8b4 | 2020-04-06 20:07:16 -0700 | [diff] [blame] | 350 | default_zone = zone_for_pfn_range(MMOP_ONLINE, nid, start_pfn, |
| 351 | nr_pages); |
Michal Hocko | e5e6893 | 2017-09-06 16:19:37 -0700 | [diff] [blame] | 352 | strcat(buf, default_zone->name); |
Zhang Zhen | ed2f240 | 2014-10-09 15:26:31 -0700 | [diff] [blame] | 353 | |
Michal Hocko | e5e6893 | 2017-09-06 16:19:37 -0700 | [diff] [blame] | 354 | print_allowed_zone(buf, nid, start_pfn, nr_pages, MMOP_ONLINE_KERNEL, |
| 355 | default_zone); |
| 356 | print_allowed_zone(buf, nid, start_pfn, nr_pages, MMOP_ONLINE_MOVABLE, |
| 357 | default_zone); |
Michal Hocko | f1dd2cd | 2017-07-06 15:38:11 -0700 | [diff] [blame] | 358 | out: |
Reza Arbab | a371d9f | 2016-07-26 15:22:27 -0700 | [diff] [blame] | 359 | strcat(buf, "\n"); |
| 360 | |
| 361 | return strlen(buf); |
Zhang Zhen | ed2f240 | 2014-10-09 15:26:31 -0700 | [diff] [blame] | 362 | } |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 363 | static DEVICE_ATTR_RO(valid_zones); |
Zhang Zhen | ed2f240 | 2014-10-09 15:26:31 -0700 | [diff] [blame] | 364 | #endif |
| 365 | |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 366 | static DEVICE_ATTR_RO(phys_index); |
| 367 | static DEVICE_ATTR_RW(state); |
| 368 | static DEVICE_ATTR_RO(phys_device); |
| 369 | static DEVICE_ATTR_RO(removable); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 370 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 371 | /* |
David Hildenbrand | f915fb7 | 2019-09-23 15:35:43 -0700 | [diff] [blame] | 372 | * Show the memory block size (shared by all memory blocks). |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 373 | */ |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 374 | static ssize_t block_size_bytes_show(struct device *dev, |
| 375 | struct device_attribute *attr, char *buf) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 376 | { |
David Hildenbrand | 902ce63b | 2019-09-23 15:35:46 -0700 | [diff] [blame] | 377 | return sprintf(buf, "%lx\n", memory_block_size_bytes()); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 378 | } |
| 379 | |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 380 | static DEVICE_ATTR_RO(block_size_bytes); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 381 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 382 | /* |
Vitaly Kuznetsov | 31bc385 | 2016-03-15 14:56:48 -0700 | [diff] [blame] | 383 | * Memory auto online policy. |
| 384 | */ |
| 385 | |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 386 | static ssize_t auto_online_blocks_show(struct device *dev, |
| 387 | struct device_attribute *attr, char *buf) |
Vitaly Kuznetsov | 31bc385 | 2016-03-15 14:56:48 -0700 | [diff] [blame] | 388 | { |
David Hildenbrand | 862919e | 2020-04-06 20:07:40 -0700 | [diff] [blame] | 389 | return sprintf(buf, "%s\n", |
| 390 | online_type_to_str[memhp_default_online_type]); |
Vitaly Kuznetsov | 31bc385 | 2016-03-15 14:56:48 -0700 | [diff] [blame] | 391 | } |
| 392 | |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 393 | static ssize_t auto_online_blocks_store(struct device *dev, |
| 394 | struct device_attribute *attr, |
| 395 | const char *buf, size_t count) |
Vitaly Kuznetsov | 31bc385 | 2016-03-15 14:56:48 -0700 | [diff] [blame] | 396 | { |
David Hildenbrand | 5f47adf | 2020-04-06 20:07:44 -0700 | [diff] [blame] | 397 | const int online_type = memhp_online_type_from_str(buf); |
| 398 | |
| 399 | if (online_type < 0) |
Vitaly Kuznetsov | 31bc385 | 2016-03-15 14:56:48 -0700 | [diff] [blame] | 400 | return -EINVAL; |
| 401 | |
David Hildenbrand | 5f47adf | 2020-04-06 20:07:44 -0700 | [diff] [blame] | 402 | memhp_default_online_type = online_type; |
Vitaly Kuznetsov | 31bc385 | 2016-03-15 14:56:48 -0700 | [diff] [blame] | 403 | return count; |
| 404 | } |
| 405 | |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 406 | static DEVICE_ATTR_RW(auto_online_blocks); |
Vitaly Kuznetsov | 31bc385 | 2016-03-15 14:56:48 -0700 | [diff] [blame] | 407 | |
| 408 | /* |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 409 | * Some architectures will have custom drivers to do this, and |
| 410 | * will not need to do it from userspace. The fake hot-add code |
| 411 | * as well as ppc64 will do all of their discovery in userspace |
| 412 | * and will require this interface. |
| 413 | */ |
| 414 | #ifdef CONFIG_ARCH_MEMORY_PROBE |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 415 | static ssize_t probe_store(struct device *dev, struct device_attribute *attr, |
| 416 | const char *buf, size_t count) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 417 | { |
| 418 | u64 phys_addr; |
John Allen | cb5490a | 2016-01-14 15:22:16 -0800 | [diff] [blame] | 419 | int nid, ret; |
Anton Blanchard | 61b94fe | 2011-09-15 06:26:15 +1000 | [diff] [blame] | 420 | unsigned long pages_per_block = PAGES_PER_SECTION * sections_per_block; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 421 | |
Zhang Zhen | b69deb2 | 2014-08-06 16:06:06 -0700 | [diff] [blame] | 422 | ret = kstrtoull(buf, 0, &phys_addr); |
| 423 | if (ret) |
| 424 | return ret; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 425 | |
Anton Blanchard | 61b94fe | 2011-09-15 06:26:15 +1000 | [diff] [blame] | 426 | if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1)) |
| 427 | return -EINVAL; |
| 428 | |
David Hildenbrand | 8df1d0e | 2018-10-30 15:10:24 -0700 | [diff] [blame] | 429 | ret = lock_device_hotplug_sysfs(); |
| 430 | if (ret) |
zhong jiang | 3780384 | 2019-04-18 17:50:16 -0700 | [diff] [blame] | 431 | return ret; |
David Hildenbrand | 8df1d0e | 2018-10-30 15:10:24 -0700 | [diff] [blame] | 432 | |
John Allen | cb5490a | 2016-01-14 15:22:16 -0800 | [diff] [blame] | 433 | nid = memory_add_physaddr_to_nid(phys_addr); |
David Hildenbrand | 8df1d0e | 2018-10-30 15:10:24 -0700 | [diff] [blame] | 434 | ret = __add_memory(nid, phys_addr, |
| 435 | MIN_MEMORY_BLOCK_SIZE * sections_per_block); |
Nathan Fontenot | 6add7cd | 2011-01-31 10:55:23 -0600 | [diff] [blame] | 436 | |
John Allen | cb5490a | 2016-01-14 15:22:16 -0800 | [diff] [blame] | 437 | if (ret) |
| 438 | goto out; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 439 | |
Nikanth Karthikesan | 9f0af69 | 2011-03-24 11:46:18 +0530 | [diff] [blame] | 440 | ret = count; |
| 441 | out: |
David Hildenbrand | 8df1d0e | 2018-10-30 15:10:24 -0700 | [diff] [blame] | 442 | unlock_device_hotplug(); |
Nikanth Karthikesan | 9f0af69 | 2011-03-24 11:46:18 +0530 | [diff] [blame] | 443 | return ret; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 444 | } |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 445 | |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 446 | static DEVICE_ATTR_WO(probe); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 447 | #endif |
| 448 | |
Andi Kleen | facb601 | 2009-12-16 12:20:00 +0100 | [diff] [blame] | 449 | #ifdef CONFIG_MEMORY_FAILURE |
| 450 | /* |
| 451 | * Support for offlining pages of memory |
| 452 | */ |
| 453 | |
| 454 | /* Soft offline a page */ |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 455 | static ssize_t soft_offline_page_store(struct device *dev, |
| 456 | struct device_attribute *attr, |
| 457 | const char *buf, size_t count) |
Andi Kleen | facb601 | 2009-12-16 12:20:00 +0100 | [diff] [blame] | 458 | { |
| 459 | int ret; |
| 460 | u64 pfn; |
| 461 | if (!capable(CAP_SYS_ADMIN)) |
| 462 | return -EPERM; |
Jingoo Han | 34da5e6 | 2013-07-26 13:10:22 +0900 | [diff] [blame] | 463 | if (kstrtoull(buf, 0, &pfn) < 0) |
Andi Kleen | facb601 | 2009-12-16 12:20:00 +0100 | [diff] [blame] | 464 | return -EINVAL; |
| 465 | pfn >>= PAGE_SHIFT; |
Naoya Horiguchi | feec24a | 2019-11-30 17:53:38 -0800 | [diff] [blame] | 466 | ret = soft_offline_page(pfn, 0); |
Andi Kleen | facb601 | 2009-12-16 12:20:00 +0100 | [diff] [blame] | 467 | return ret == 0 ? count : ret; |
| 468 | } |
| 469 | |
| 470 | /* Forcibly offline a page, including killing processes. */ |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 471 | static ssize_t hard_offline_page_store(struct device *dev, |
| 472 | struct device_attribute *attr, |
| 473 | const char *buf, size_t count) |
Andi Kleen | facb601 | 2009-12-16 12:20:00 +0100 | [diff] [blame] | 474 | { |
| 475 | int ret; |
| 476 | u64 pfn; |
| 477 | if (!capable(CAP_SYS_ADMIN)) |
| 478 | return -EPERM; |
Jingoo Han | 34da5e6 | 2013-07-26 13:10:22 +0900 | [diff] [blame] | 479 | if (kstrtoull(buf, 0, &pfn) < 0) |
Andi Kleen | facb601 | 2009-12-16 12:20:00 +0100 | [diff] [blame] | 480 | return -EINVAL; |
| 481 | pfn >>= PAGE_SHIFT; |
Eric W. Biederman | 83b5753 | 2017-07-09 18:14:01 -0500 | [diff] [blame] | 482 | ret = memory_failure(pfn, 0); |
Andi Kleen | facb601 | 2009-12-16 12:20:00 +0100 | [diff] [blame] | 483 | return ret ? ret : count; |
| 484 | } |
| 485 | |
David Hildenbrand | 3f8e917 | 2018-12-03 12:16:11 +0100 | [diff] [blame] | 486 | static DEVICE_ATTR_WO(soft_offline_page); |
| 487 | static DEVICE_ATTR_WO(hard_offline_page); |
Andi Kleen | facb601 | 2009-12-16 12:20:00 +0100 | [diff] [blame] | 488 | #endif |
| 489 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 490 | /* |
| 491 | * Note that phys_device is optional. It is here to allow for |
| 492 | * differentiation between which *physical* devices each |
| 493 | * section belongs to... |
| 494 | */ |
Heiko Carstens | bc32df0 | 2010-03-15 00:35:03 -0400 | [diff] [blame] | 495 | int __weak arch_get_memory_phys_device(unsigned long start_pfn) |
| 496 | { |
| 497 | return 0; |
| 498 | } |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 499 | |
Scott Cheloha | 4fb6eab | 2020-06-03 16:03:48 -0700 | [diff] [blame] | 500 | /* |
| 501 | * A reference for the returned memory block device is acquired. |
| 502 | * |
| 503 | * Called under device_hotplug_lock. |
| 504 | */ |
David Hildenbrand | dd62528 | 2019-07-18 15:57:53 -0700 | [diff] [blame] | 505 | static struct memory_block *find_memory_block_by_id(unsigned long block_id) |
Robin Holt | 9838303 | 2010-09-29 14:00:55 -0500 | [diff] [blame] | 506 | { |
Scott Cheloha | 4fb6eab | 2020-06-03 16:03:48 -0700 | [diff] [blame] | 507 | struct memory_block *mem; |
Robin Holt | 9838303 | 2010-09-29 14:00:55 -0500 | [diff] [blame] | 508 | |
Scott Cheloha | 4fb6eab | 2020-06-03 16:03:48 -0700 | [diff] [blame] | 509 | mem = xa_load(&memory_blocks, block_id); |
| 510 | if (mem) |
| 511 | get_device(&mem->dev); |
| 512 | return mem; |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 515 | /* |
Scott Cheloha | 4fb6eab | 2020-06-03 16:03:48 -0700 | [diff] [blame] | 516 | * Called under device_hotplug_lock. |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 517 | */ |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 518 | struct memory_block *find_memory_block(struct mem_section *section) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 519 | { |
David Hildenbrand | dd62528 | 2019-07-18 15:57:53 -0700 | [diff] [blame] | 520 | unsigned long block_id = base_memory_block_id(__section_nr(section)); |
| 521 | |
| 522 | return find_memory_block_by_id(block_id); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Nathan Fontenot | 96b2c0f | 2013-06-04 14:42:28 -0500 | [diff] [blame] | 525 | static struct attribute *memory_memblk_attrs[] = { |
| 526 | &dev_attr_phys_index.attr, |
Nathan Fontenot | 96b2c0f | 2013-06-04 14:42:28 -0500 | [diff] [blame] | 527 | &dev_attr_state.attr, |
| 528 | &dev_attr_phys_device.attr, |
| 529 | &dev_attr_removable.attr, |
Zhang Zhen | ed2f240 | 2014-10-09 15:26:31 -0700 | [diff] [blame] | 530 | #ifdef CONFIG_MEMORY_HOTREMOVE |
| 531 | &dev_attr_valid_zones.attr, |
| 532 | #endif |
Nathan Fontenot | 96b2c0f | 2013-06-04 14:42:28 -0500 | [diff] [blame] | 533 | NULL |
| 534 | }; |
| 535 | |
| 536 | static struct attribute_group memory_memblk_attr_group = { |
| 537 | .attrs = memory_memblk_attrs, |
| 538 | }; |
| 539 | |
| 540 | static const struct attribute_group *memory_memblk_attr_groups[] = { |
| 541 | &memory_memblk_attr_group, |
| 542 | NULL, |
| 543 | }; |
| 544 | |
| 545 | /* |
| 546 | * register_memory - Setup a sysfs device for a memory block |
| 547 | */ |
| 548 | static |
| 549 | int register_memory(struct memory_block *memory) |
| 550 | { |
Arvind Yadav | 085aa2d | 2018-04-26 21:12:09 +0530 | [diff] [blame] | 551 | int ret; |
| 552 | |
Nathan Fontenot | 96b2c0f | 2013-06-04 14:42:28 -0500 | [diff] [blame] | 553 | memory->dev.bus = &memory_subsys; |
| 554 | memory->dev.id = memory->start_section_nr / sections_per_block; |
| 555 | memory->dev.release = memory_block_release; |
| 556 | memory->dev.groups = memory_memblk_attr_groups; |
Linus Torvalds | f991fae | 2013-07-03 14:35:40 -0700 | [diff] [blame] | 557 | memory->dev.offline = memory->state == MEM_OFFLINE; |
Nathan Fontenot | 96b2c0f | 2013-06-04 14:42:28 -0500 | [diff] [blame] | 558 | |
Arvind Yadav | 085aa2d | 2018-04-26 21:12:09 +0530 | [diff] [blame] | 559 | ret = device_register(&memory->dev); |
Scott Cheloha | 4fb6eab | 2020-06-03 16:03:48 -0700 | [diff] [blame] | 560 | if (ret) { |
Arvind Yadav | 085aa2d | 2018-04-26 21:12:09 +0530 | [diff] [blame] | 561 | put_device(&memory->dev); |
Scott Cheloha | 4fb6eab | 2020-06-03 16:03:48 -0700 | [diff] [blame] | 562 | return ret; |
| 563 | } |
| 564 | ret = xa_err(xa_store(&memory_blocks, memory->dev.id, memory, |
| 565 | GFP_KERNEL)); |
| 566 | if (ret) { |
| 567 | put_device(&memory->dev); |
| 568 | device_unregister(&memory->dev); |
| 569 | } |
Arvind Yadav | 085aa2d | 2018-04-26 21:12:09 +0530 | [diff] [blame] | 570 | return ret; |
Nathan Fontenot | 96b2c0f | 2013-06-04 14:42:28 -0500 | [diff] [blame] | 571 | } |
| 572 | |
David Hildenbrand | 90ec010f | 2019-07-18 15:57:40 -0700 | [diff] [blame] | 573 | static int init_memory_block(struct memory_block **memory, |
| 574 | unsigned long block_id, unsigned long state) |
Nathan Fontenot | e4619c8 | 2010-10-19 12:44:20 -0500 | [diff] [blame] | 575 | { |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 576 | struct memory_block *mem; |
Nathan Fontenot | e4619c8 | 2010-10-19 12:44:20 -0500 | [diff] [blame] | 577 | unsigned long start_pfn; |
| 578 | int ret = 0; |
| 579 | |
David Hildenbrand | dd62528 | 2019-07-18 15:57:53 -0700 | [diff] [blame] | 580 | mem = find_memory_block_by_id(block_id); |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 581 | if (mem) { |
| 582 | put_device(&mem->dev); |
| 583 | return -EEXIST; |
| 584 | } |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 585 | mem = kzalloc(sizeof(*mem), GFP_KERNEL); |
Nathan Fontenot | e4619c8 | 2010-10-19 12:44:20 -0500 | [diff] [blame] | 586 | if (!mem) |
| 587 | return -ENOMEM; |
| 588 | |
David Hildenbrand | 1811582 | 2019-07-18 15:56:46 -0700 | [diff] [blame] | 589 | mem->start_section_nr = block_id * sections_per_block; |
Nathan Fontenot | e4619c8 | 2010-10-19 12:44:20 -0500 | [diff] [blame] | 590 | mem->state = state; |
Nathan Fontenot | d336016 | 2011-01-20 10:44:29 -0600 | [diff] [blame] | 591 | start_pfn = section_nr_to_pfn(mem->start_section_nr); |
Nathan Fontenot | e4619c8 | 2010-10-19 12:44:20 -0500 | [diff] [blame] | 592 | mem->phys_device = arch_get_memory_phys_device(start_pfn); |
David Hildenbrand | d84f2f5 | 2019-09-23 15:35:40 -0700 | [diff] [blame] | 593 | mem->nid = NUMA_NO_NODE; |
Nathan Fontenot | e4619c8 | 2010-10-19 12:44:20 -0500 | [diff] [blame] | 594 | |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 595 | ret = register_memory(mem); |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 596 | |
| 597 | *memory = mem; |
| 598 | return ret; |
| 599 | } |
| 600 | |
David Hildenbrand | 2491f0a | 2019-07-18 15:57:37 -0700 | [diff] [blame] | 601 | static int add_memory_block(unsigned long base_section_nr) |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 602 | { |
David Hildenbrand | 68c3a6a | 2020-04-06 20:06:40 -0700 | [diff] [blame] | 603 | int section_count = 0; |
Seth Jennings | cb5e39b | 2013-08-20 12:13:03 -0500 | [diff] [blame] | 604 | struct memory_block *mem; |
David Hildenbrand | 2491f0a | 2019-07-18 15:57:37 -0700 | [diff] [blame] | 605 | unsigned long nr; |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 606 | |
David Hildenbrand | 2491f0a | 2019-07-18 15:57:37 -0700 | [diff] [blame] | 607 | for (nr = base_section_nr; nr < base_section_nr + sections_per_block; |
| 608 | nr++) |
| 609 | if (present_section_nr(nr)) |
David Hildenbrand | 1811582 | 2019-07-18 15:56:46 -0700 | [diff] [blame] | 610 | section_count++; |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 611 | |
Seth Jennings | cb5e39b | 2013-08-20 12:13:03 -0500 | [diff] [blame] | 612 | if (section_count == 0) |
| 613 | return 0; |
David Hildenbrand | 68c3a6a | 2020-04-06 20:06:40 -0700 | [diff] [blame] | 614 | return init_memory_block(&mem, base_memory_block_id(base_section_nr), |
| 615 | MEM_ONLINE); |
Nathan Fontenot | e4619c8 | 2010-10-19 12:44:20 -0500 | [diff] [blame] | 616 | } |
| 617 | |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 618 | static void unregister_memory(struct memory_block *memory) |
David Rientjes | 4edd7ce | 2013-04-29 15:08:22 -0700 | [diff] [blame] | 619 | { |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 620 | if (WARN_ON_ONCE(memory->dev.bus != &memory_subsys)) |
| 621 | return; |
David Rientjes | 4edd7ce | 2013-04-29 15:08:22 -0700 | [diff] [blame] | 622 | |
Scott Cheloha | 4fb6eab | 2020-06-03 16:03:48 -0700 | [diff] [blame] | 623 | WARN_ON(xa_erase(&memory_blocks, memory->dev.id) == NULL); |
| 624 | |
David Hildenbrand | cb7b3a3 | 2019-05-13 17:21:37 -0700 | [diff] [blame] | 625 | /* drop the ref. we got via find_memory_block() */ |
Seth Jennings | df2b717 | 2013-08-20 12:12:59 -0500 | [diff] [blame] | 626 | put_device(&memory->dev); |
David Rientjes | 4edd7ce | 2013-04-29 15:08:22 -0700 | [diff] [blame] | 627 | device_unregister(&memory->dev); |
| 628 | } |
| 629 | |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 630 | /* |
| 631 | * Create memory block devices for the given memory area. Start and size |
| 632 | * have to be aligned to memory block granularity. Memory block devices |
| 633 | * will be initialized as offline. |
David Hildenbrand | 848e19a | 2019-11-30 17:54:14 -0800 | [diff] [blame] | 634 | * |
| 635 | * Called under device_hotplug_lock. |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 636 | */ |
| 637 | int create_memory_block_devices(unsigned long start, unsigned long size) |
| 638 | { |
David Hildenbrand | 90ec010f | 2019-07-18 15:57:40 -0700 | [diff] [blame] | 639 | const unsigned long start_block_id = pfn_to_block_id(PFN_DOWN(start)); |
| 640 | unsigned long end_block_id = pfn_to_block_id(PFN_DOWN(start + size)); |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 641 | struct memory_block *mem; |
| 642 | unsigned long block_id; |
| 643 | int ret = 0; |
| 644 | |
| 645 | if (WARN_ON_ONCE(!IS_ALIGNED(start, memory_block_size_bytes()) || |
| 646 | !IS_ALIGNED(size, memory_block_size_bytes()))) |
| 647 | return -EINVAL; |
| 648 | |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 649 | for (block_id = start_block_id; block_id != end_block_id; block_id++) { |
| 650 | ret = init_memory_block(&mem, block_id, MEM_OFFLINE); |
| 651 | if (ret) |
| 652 | break; |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 653 | } |
| 654 | if (ret) { |
| 655 | end_block_id = block_id; |
| 656 | for (block_id = start_block_id; block_id != end_block_id; |
| 657 | block_id++) { |
David Hildenbrand | dd62528 | 2019-07-18 15:57:53 -0700 | [diff] [blame] | 658 | mem = find_memory_block_by_id(block_id); |
David Hildenbrand | 848e19a | 2019-11-30 17:54:14 -0800 | [diff] [blame] | 659 | if (WARN_ON_ONCE(!mem)) |
| 660 | continue; |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 661 | unregister_memory(mem); |
| 662 | } |
| 663 | } |
David Hildenbrand | db051a0 | 2019-07-18 15:56:56 -0700 | [diff] [blame] | 664 | return ret; |
| 665 | } |
| 666 | |
David Hildenbrand | 4c4b7f9 | 2019-07-18 15:57:06 -0700 | [diff] [blame] | 667 | /* |
| 668 | * Remove memory block devices for the given memory area. Start and size |
| 669 | * have to be aligned to memory block granularity. Memory block devices |
| 670 | * have to be offline. |
David Hildenbrand | 848e19a | 2019-11-30 17:54:14 -0800 | [diff] [blame] | 671 | * |
| 672 | * Called under device_hotplug_lock. |
David Hildenbrand | 4c4b7f9 | 2019-07-18 15:57:06 -0700 | [diff] [blame] | 673 | */ |
| 674 | void remove_memory_block_devices(unsigned long start, unsigned long size) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 675 | { |
David Hildenbrand | 90ec010f | 2019-07-18 15:57:40 -0700 | [diff] [blame] | 676 | const unsigned long start_block_id = pfn_to_block_id(PFN_DOWN(start)); |
| 677 | const unsigned long end_block_id = pfn_to_block_id(PFN_DOWN(start + size)); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 678 | struct memory_block *mem; |
David Hildenbrand | 90ec010f | 2019-07-18 15:57:40 -0700 | [diff] [blame] | 679 | unsigned long block_id; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 680 | |
David Hildenbrand | 4c4b7f9 | 2019-07-18 15:57:06 -0700 | [diff] [blame] | 681 | if (WARN_ON_ONCE(!IS_ALIGNED(start, memory_block_size_bytes()) || |
| 682 | !IS_ALIGNED(size, memory_block_size_bytes()))) |
David Hildenbrand | cb7b3a3 | 2019-05-13 17:21:37 -0700 | [diff] [blame] | 683 | return; |
| 684 | |
David Hildenbrand | 4c4b7f9 | 2019-07-18 15:57:06 -0700 | [diff] [blame] | 685 | for (block_id = start_block_id; block_id != end_block_id; block_id++) { |
David Hildenbrand | dd62528 | 2019-07-18 15:57:53 -0700 | [diff] [blame] | 686 | mem = find_memory_block_by_id(block_id); |
David Hildenbrand | 4c4b7f9 | 2019-07-18 15:57:06 -0700 | [diff] [blame] | 687 | if (WARN_ON_ONCE(!mem)) |
| 688 | continue; |
David Hildenbrand | 4c4b7f9 | 2019-07-18 15:57:06 -0700 | [diff] [blame] | 689 | unregister_memory_block_under_nodes(mem); |
Nathan Fontenot | 0c2c99b | 2011-01-20 10:43:34 -0600 | [diff] [blame] | 690 | unregister_memory(mem); |
David Hildenbrand | 4c4b7f9 | 2019-07-18 15:57:06 -0700 | [diff] [blame] | 691 | } |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Yasuaki Ishimatsu | 6677e3e | 2013-02-22 16:32:52 -0800 | [diff] [blame] | 694 | /* return true if the memory block is offlined, otherwise, return false */ |
| 695 | bool is_memblock_offlined(struct memory_block *mem) |
| 696 | { |
| 697 | return mem->state == MEM_OFFLINE; |
| 698 | } |
| 699 | |
Nathan Fontenot | 96b2c0f | 2013-06-04 14:42:28 -0500 | [diff] [blame] | 700 | static struct attribute *memory_root_attrs[] = { |
| 701 | #ifdef CONFIG_ARCH_MEMORY_PROBE |
| 702 | &dev_attr_probe.attr, |
| 703 | #endif |
| 704 | |
| 705 | #ifdef CONFIG_MEMORY_FAILURE |
| 706 | &dev_attr_soft_offline_page.attr, |
| 707 | &dev_attr_hard_offline_page.attr, |
| 708 | #endif |
| 709 | |
| 710 | &dev_attr_block_size_bytes.attr, |
Vitaly Kuznetsov | 31bc385 | 2016-03-15 14:56:48 -0700 | [diff] [blame] | 711 | &dev_attr_auto_online_blocks.attr, |
Nathan Fontenot | 96b2c0f | 2013-06-04 14:42:28 -0500 | [diff] [blame] | 712 | NULL |
| 713 | }; |
| 714 | |
| 715 | static struct attribute_group memory_root_attr_group = { |
| 716 | .attrs = memory_root_attrs, |
| 717 | }; |
| 718 | |
| 719 | static const struct attribute_group *memory_root_attr_groups[] = { |
| 720 | &memory_root_attr_group, |
| 721 | NULL, |
| 722 | }; |
| 723 | |
Wen Congyang | e90bdb7 | 2012-10-08 16:34:01 -0700 | [diff] [blame] | 724 | /* |
David Hildenbrand | 848e19a | 2019-11-30 17:54:14 -0800 | [diff] [blame] | 725 | * Initialize the sysfs support for memory devices. At the time this function |
| 726 | * is called, we cannot have concurrent creation/deletion of memory block |
| 727 | * devices, the device_hotplug_lock is not needed. |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 728 | */ |
David Hildenbrand | 902ce63b | 2019-09-23 15:35:46 -0700 | [diff] [blame] | 729 | void __init memory_dev_init(void) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 730 | { |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 731 | int ret; |
David Hildenbrand | 2491f0a | 2019-07-18 15:57:37 -0700 | [diff] [blame] | 732 | unsigned long block_sz, nr; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 733 | |
David Hildenbrand | 902ce63b | 2019-09-23 15:35:46 -0700 | [diff] [blame] | 734 | /* Validate the configured memory block size */ |
| 735 | block_sz = memory_block_size_bytes(); |
| 736 | if (!is_power_of_2(block_sz) || block_sz < MIN_MEMORY_BLOCK_SIZE) |
| 737 | panic("Memory block size not suitable: 0x%lx\n", block_sz); |
| 738 | sections_per_block = block_sz / MIN_MEMORY_BLOCK_SIZE; |
| 739 | |
Nathan Fontenot | 96b2c0f | 2013-06-04 14:42:28 -0500 | [diff] [blame] | 740 | ret = subsys_system_register(&memory_subsys, memory_root_attr_groups); |
Andrew Morton | 28ec24e | 2006-12-06 20:37:29 -0800 | [diff] [blame] | 741 | if (ret) |
David Hildenbrand | 848e19a | 2019-11-30 17:54:14 -0800 | [diff] [blame] | 742 | panic("%s() failed to register subsystem: %d\n", __func__, ret); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 743 | |
| 744 | /* |
| 745 | * Create entries for memory sections that were found |
| 746 | * during boot and have been initialized |
| 747 | */ |
David Hildenbrand | 2491f0a | 2019-07-18 15:57:37 -0700 | [diff] [blame] | 748 | for (nr = 0; nr <= __highest_present_section_nr; |
| 749 | nr += sections_per_block) { |
David Hildenbrand | 848e19a | 2019-11-30 17:54:14 -0800 | [diff] [blame] | 750 | ret = add_memory_block(nr); |
| 751 | if (ret) |
| 752 | panic("%s() failed to add memory block: %d\n", __func__, |
| 753 | ret); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 754 | } |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 755 | } |
David Hildenbrand | ea88464 | 2019-07-18 15:57:50 -0700 | [diff] [blame] | 756 | |
| 757 | /** |
| 758 | * walk_memory_blocks - walk through all present memory blocks overlapped |
| 759 | * by the range [start, start + size) |
| 760 | * |
| 761 | * @start: start address of the memory range |
| 762 | * @size: size of the memory range |
| 763 | * @arg: argument passed to func |
| 764 | * @func: callback for each memory section walked |
| 765 | * |
| 766 | * This function walks through all present memory blocks overlapped by the |
| 767 | * range [start, start + size), calling func on each memory block. |
| 768 | * |
| 769 | * In case func() returns an error, walking is aborted and the error is |
| 770 | * returned. |
Scott Cheloha | 4fb6eab | 2020-06-03 16:03:48 -0700 | [diff] [blame] | 771 | * |
| 772 | * Called under device_hotplug_lock. |
David Hildenbrand | ea88464 | 2019-07-18 15:57:50 -0700 | [diff] [blame] | 773 | */ |
| 774 | int walk_memory_blocks(unsigned long start, unsigned long size, |
| 775 | void *arg, walk_memory_blocks_func_t func) |
| 776 | { |
| 777 | const unsigned long start_block_id = phys_to_block_id(start); |
| 778 | const unsigned long end_block_id = phys_to_block_id(start + size - 1); |
| 779 | struct memory_block *mem; |
| 780 | unsigned long block_id; |
| 781 | int ret = 0; |
| 782 | |
David Hildenbrand | dd62528 | 2019-07-18 15:57:53 -0700 | [diff] [blame] | 783 | if (!size) |
| 784 | return 0; |
| 785 | |
David Hildenbrand | ea88464 | 2019-07-18 15:57:50 -0700 | [diff] [blame] | 786 | for (block_id = start_block_id; block_id <= end_block_id; block_id++) { |
David Hildenbrand | dd62528 | 2019-07-18 15:57:53 -0700 | [diff] [blame] | 787 | mem = find_memory_block_by_id(block_id); |
David Hildenbrand | ea88464 | 2019-07-18 15:57:50 -0700 | [diff] [blame] | 788 | if (!mem) |
| 789 | continue; |
| 790 | |
| 791 | ret = func(mem, arg); |
| 792 | put_device(&mem->dev); |
| 793 | if (ret) |
| 794 | break; |
| 795 | } |
| 796 | return ret; |
| 797 | } |
David Hildenbrand | 2c91f8f | 2019-11-15 17:34:57 -0800 | [diff] [blame] | 798 | |
| 799 | struct for_each_memory_block_cb_data { |
| 800 | walk_memory_blocks_func_t func; |
| 801 | void *arg; |
| 802 | }; |
| 803 | |
| 804 | static int for_each_memory_block_cb(struct device *dev, void *data) |
| 805 | { |
| 806 | struct memory_block *mem = to_memory_block(dev); |
| 807 | struct for_each_memory_block_cb_data *cb_data = data; |
| 808 | |
| 809 | return cb_data->func(mem, cb_data->arg); |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * for_each_memory_block - walk through all present memory blocks |
| 814 | * |
| 815 | * @arg: argument passed to func |
| 816 | * @func: callback for each memory block walked |
| 817 | * |
| 818 | * This function walks through all present memory blocks, calling func on |
| 819 | * each memory block. |
| 820 | * |
| 821 | * In case func() returns an error, walking is aborted and the error is |
| 822 | * returned. |
| 823 | */ |
| 824 | int for_each_memory_block(void *arg, walk_memory_blocks_func_t func) |
| 825 | { |
| 826 | struct for_each_memory_block_cb_data cb_data = { |
| 827 | .func = func, |
| 828 | .arg = arg, |
| 829 | }; |
| 830 | |
| 831 | return bus_for_each_dev(&memory_subsys, NULL, &cb_data, |
| 832 | for_each_memory_block_cb); |
| 833 | } |