diff options
| author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-05-07 18:29:49 -0400 |
|---|---|---|
| committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-05-12 08:14:38 -0400 |
| commit | e2ff39400d81233374e780b133496a2296643d7d (patch) | |
| tree | 6f96f82ebc9474652a32e7fff8f8d9eb7184eb56 | |
| parent | ac212b6980d8d5eda705864fc5a8ecddc6d6eacc (diff) | |
ACPI / memhotplug: Bind removable memory blocks to ACPI device nodes
During ACPI memory hotplug configuration bind memory blocks residing
in modules removable through the standard ACPI mechanism to struct
acpi_device objects associated with ACPI namespace objects
representing those modules. Accordingly, unbind those memory blocks
from the struct acpi_device objects when the memory modules in
question are being removed.
When "offline" operation for devices representing memory blocks is
introduced, this will allow the ACPI core's device hot-remove code to
use it to carry out remove_memory() for those memory blocks and check
the results of that before it actually removes the modules holding
them from the system.
Since walk_memory_range() is used for accessing all memory blocks
corresponding to a given ACPI namespace object, it is exported from
memory_hotplug.c so that the code in acpi_memhotplug.c can use it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
Reviewed-by: Toshi Kani <toshi.kani@hp.com>
| -rw-r--r-- | drivers/acpi/acpi_memhotplug.c | 53 | ||||
| -rw-r--r-- | include/linux/memory_hotplug.h | 2 | ||||
| -rw-r--r-- | mm/memory_hotplug.c | 4 |
3 files changed, 55 insertions, 4 deletions
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c index 5e6301e94920..5590db12028e 100644 --- a/drivers/acpi/acpi_memhotplug.c +++ b/drivers/acpi/acpi_memhotplug.c | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | */ | 28 | */ |
| 29 | 29 | ||
| 30 | #include <linux/acpi.h> | 30 | #include <linux/acpi.h> |
| 31 | #include <linux/memory.h> | ||
| 31 | #include <linux/memory_hotplug.h> | 32 | #include <linux/memory_hotplug.h> |
| 32 | 33 | ||
| 33 | #include "internal.h" | 34 | #include "internal.h" |
| @@ -166,13 +167,50 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device) | |||
| 166 | return 0; | 167 | return 0; |
| 167 | } | 168 | } |
| 168 | 169 | ||
| 170 | static unsigned long acpi_meminfo_start_pfn(struct acpi_memory_info *info) | ||
| 171 | { | ||
| 172 | return PFN_DOWN(info->start_addr); | ||
| 173 | } | ||
| 174 | |||
| 175 | static unsigned long acpi_meminfo_end_pfn(struct acpi_memory_info *info) | ||
| 176 | { | ||
| 177 | return PFN_UP(info->start_addr + info->length-1); | ||
| 178 | } | ||
| 179 | |||
| 180 | static int acpi_bind_memblk(struct memory_block *mem, void *arg) | ||
| 181 | { | ||
| 182 | return acpi_bind_one(&mem->dev, (acpi_handle)arg); | ||
| 183 | } | ||
| 184 | |||
| 185 | static int acpi_bind_memory_blocks(struct acpi_memory_info *info, | ||
| 186 | acpi_handle handle) | ||
| 187 | { | ||
| 188 | return walk_memory_range(acpi_meminfo_start_pfn(info), | ||
| 189 | acpi_meminfo_end_pfn(info), (void *)handle, | ||
| 190 | acpi_bind_memblk); | ||
| 191 | } | ||
| 192 | |||
| 193 | static int acpi_unbind_memblk(struct memory_block *mem, void *arg) | ||
| 194 | { | ||
| 195 | acpi_unbind_one(&mem->dev); | ||
| 196 | return 0; | ||
| 197 | } | ||
| 198 | |||
| 199 | static void acpi_unbind_memory_blocks(struct acpi_memory_info *info, | ||
| 200 | acpi_handle handle) | ||
| 201 | { | ||
| 202 | walk_memory_range(acpi_meminfo_start_pfn(info), | ||
| 203 | acpi_meminfo_end_pfn(info), NULL, acpi_unbind_memblk); | ||
| 204 | } | ||
| 205 | |||
| 169 | static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) | 206 | static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) |
| 170 | { | 207 | { |
| 208 | acpi_handle handle = mem_device->device->handle; | ||
| 171 | int result, num_enabled = 0; | 209 | int result, num_enabled = 0; |
| 172 | struct acpi_memory_info *info; | 210 | struct acpi_memory_info *info; |
| 173 | int node; | 211 | int node; |
| 174 | 212 | ||
| 175 | node = acpi_get_node(mem_device->device->handle); | 213 | node = acpi_get_node(handle); |
| 176 | /* | 214 | /* |
| 177 | * Tell the VM there is more memory here... | 215 | * Tell the VM there is more memory here... |
| 178 | * Note: Assume that this function returns zero on success | 216 | * Note: Assume that this function returns zero on success |
| @@ -203,6 +241,12 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) | |||
| 203 | if (result && result != -EEXIST) | 241 | if (result && result != -EEXIST) |
| 204 | continue; | 242 | continue; |
| 205 | 243 | ||
| 244 | result = acpi_bind_memory_blocks(info, handle); | ||
| 245 | if (result) { | ||
| 246 | acpi_unbind_memory_blocks(info, handle); | ||
| 247 | return -ENODEV; | ||
| 248 | } | ||
| 249 | |||
| 206 | info->enabled = 1; | 250 | info->enabled = 1; |
| 207 | 251 | ||
| 208 | /* | 252 | /* |
| @@ -229,10 +273,11 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) | |||
| 229 | 273 | ||
| 230 | static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device) | 274 | static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device) |
| 231 | { | 275 | { |
| 276 | acpi_handle handle = mem_device->device->handle; | ||
| 232 | int result = 0, nid; | 277 | int result = 0, nid; |
| 233 | struct acpi_memory_info *info, *n; | 278 | struct acpi_memory_info *info, *n; |
| 234 | 279 | ||
| 235 | nid = acpi_get_node(mem_device->device->handle); | 280 | nid = acpi_get_node(handle); |
| 236 | 281 | ||
| 237 | list_for_each_entry_safe(info, n, &mem_device->res_list, list) { | 282 | list_for_each_entry_safe(info, n, &mem_device->res_list, list) { |
| 238 | if (!info->enabled) | 283 | if (!info->enabled) |
| @@ -240,6 +285,8 @@ static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device) | |||
| 240 | 285 | ||
| 241 | if (nid < 0) | 286 | if (nid < 0) |
| 242 | nid = memory_add_physaddr_to_nid(info->start_addr); | 287 | nid = memory_add_physaddr_to_nid(info->start_addr); |
| 288 | |||
| 289 | acpi_unbind_memory_blocks(info, handle); | ||
| 243 | result = remove_memory(nid, info->start_addr, info->length); | 290 | result = remove_memory(nid, info->start_addr, info->length); |
| 244 | if (result) | 291 | if (result) |
| 245 | return result; | 292 | return result; |
| @@ -300,7 +347,7 @@ static int acpi_memory_device_add(struct acpi_device *device, | |||
| 300 | if (result) { | 347 | if (result) { |
| 301 | dev_err(&device->dev, "acpi_memory_enable_device() error\n"); | 348 | dev_err(&device->dev, "acpi_memory_enable_device() error\n"); |
| 302 | acpi_memory_device_free(mem_device); | 349 | acpi_memory_device_free(mem_device); |
| 303 | return -ENODEV; | 350 | return result; |
| 304 | } | 351 | } |
| 305 | 352 | ||
| 306 | dev_dbg(&device->dev, "Memory device configured by ACPI\n"); | 353 | dev_dbg(&device->dev, "Memory device configured by ACPI\n"); |
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 3e622c610925..2975b7b2a9d8 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h | |||
| @@ -245,6 +245,8 @@ static inline int is_mem_section_removable(unsigned long pfn, | |||
| 245 | static inline void try_offline_node(int nid) {} | 245 | static inline void try_offline_node(int nid) {} |
| 246 | #endif /* CONFIG_MEMORY_HOTREMOVE */ | 246 | #endif /* CONFIG_MEMORY_HOTREMOVE */ |
| 247 | 247 | ||
| 248 | extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, | ||
| 249 | void *arg, int (*func)(struct memory_block *, void *)); | ||
| 248 | extern int mem_online_node(int nid); | 250 | extern int mem_online_node(int nid); |
| 249 | extern int add_memory(int nid, u64 start, u64 size); | 251 | extern int add_memory(int nid, u64 start, u64 size); |
| 250 | extern int arch_add_memory(int nid, u64 start, u64 size); | 252 | extern int arch_add_memory(int nid, u64 start, u64 size); |
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index a221fac1f47d..5ea1287ee91f 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c | |||
| @@ -1618,6 +1618,7 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages) | |||
| 1618 | { | 1618 | { |
| 1619 | return __offline_pages(start_pfn, start_pfn + nr_pages, 120 * HZ); | 1619 | return __offline_pages(start_pfn, start_pfn + nr_pages, 120 * HZ); |
| 1620 | } | 1620 | } |
| 1621 | #endif /* CONFIG_MEMORY_HOTREMOVE */ | ||
| 1621 | 1622 | ||
| 1622 | /** | 1623 | /** |
| 1623 | * walk_memory_range - walks through all mem sections in [start_pfn, end_pfn) | 1624 | * walk_memory_range - walks through all mem sections in [start_pfn, end_pfn) |
| @@ -1631,7 +1632,7 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages) | |||
| 1631 | * | 1632 | * |
| 1632 | * Returns the return value of func. | 1633 | * Returns the return value of func. |
| 1633 | */ | 1634 | */ |
| 1634 | static int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, | 1635 | int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, |
| 1635 | void *arg, int (*func)(struct memory_block *, void *)) | 1636 | void *arg, int (*func)(struct memory_block *, void *)) |
| 1636 | { | 1637 | { |
| 1637 | struct memory_block *mem = NULL; | 1638 | struct memory_block *mem = NULL; |
| @@ -1668,6 +1669,7 @@ static int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, | |||
| 1668 | return 0; | 1669 | return 0; |
| 1669 | } | 1670 | } |
| 1670 | 1671 | ||
| 1672 | #ifdef CONFIG_MEMORY_HOTREMOVE | ||
| 1671 | /** | 1673 | /** |
| 1672 | * offline_memory_block_cb - callback function for offlining memory block | 1674 | * offline_memory_block_cb - callback function for offlining memory block |
| 1673 | * @mem: the memory block to be offlined | 1675 | * @mem: the memory block to be offlined |
