Skip to content

Commit e2ff394

Browse files
committed
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>
1 parent ac212b6 commit e2ff394

3 files changed

Lines changed: 55 additions & 4 deletions

File tree

‎drivers/acpi/acpi_memhotplug.c‎

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929

3030
#include <linux/acpi.h>
31+
#include <linux/memory.h>
3132
#include <linux/memory_hotplug.h>
3233

3334
#include "internal.h"
@@ -166,13 +167,50 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
166167
return 0;
167168
}
168169

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+
169206
static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
170207
{
208+
acpi_handle handle = mem_device->device->handle;
171209
int result, num_enabled = 0;
172210
struct acpi_memory_info *info;
173211
int node;
174212

175-
node = acpi_get_node(mem_device->device->handle);
213+
node = acpi_get_node(handle);
176214
/*
177215
* Tell the VM there is more memory here...
178216
* 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)
203241
if (result && result != -EEXIST)
204242
continue;
205243

244+
result = acpi_bind_memory_blocks(info, handle);
245+
if (result) {
246+
acpi_unbind_memory_blocks(info, handle);
247+
return -ENODEV;
248+
}
249+
206250
info->enabled = 1;
207251

208252
/*
@@ -229,17 +273,20 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
229273

230274
static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
231275
{
276+
acpi_handle handle = mem_device->device->handle;
232277
int result = 0, nid;
233278
struct acpi_memory_info *info, *n;
234279

235-
nid = acpi_get_node(mem_device->device->handle);
280+
nid = acpi_get_node(handle);
236281

237282
list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
238283
if (!info->enabled)
239284
continue;
240285

241286
if (nid < 0)
242287
nid = memory_add_physaddr_to_nid(info->start_addr);
288+
289+
acpi_unbind_memory_blocks(info, handle);
243290
result = remove_memory(nid, info->start_addr, info->length);
244291
if (result)
245292
return result;
@@ -300,7 +347,7 @@ static int acpi_memory_device_add(struct acpi_device *device,
300347
if (result) {
301348
dev_err(&device->dev, "acpi_memory_enable_device() error\n");
302349
acpi_memory_device_free(mem_device);
303-
return -ENODEV;
350+
return result;
304351
}
305352

306353
dev_dbg(&device->dev, "Memory device configured by ACPI\n");

‎include/linux/memory_hotplug.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ static inline int is_mem_section_removable(unsigned long pfn,
245245
static inline void try_offline_node(int nid) {}
246246
#endif /* CONFIG_MEMORY_HOTREMOVE */
247247

248+
extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn,
249+
void *arg, int (*func)(struct memory_block *, void *));
248250
extern int mem_online_node(int nid);
249251
extern int add_memory(int nid, u64 start, u64 size);
250252
extern int arch_add_memory(int nid, u64 start, u64 size);

‎mm/memory_hotplug.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,7 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages)
16181618
{
16191619
return __offline_pages(start_pfn, start_pfn + nr_pages, 120 * HZ);
16201620
}
1621+
#endif /* CONFIG_MEMORY_HOTREMOVE */
16211622

16221623
/**
16231624
* 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)
16311632
*
16321633
* Returns the return value of func.
16331634
*/
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,
16351636
void *arg, int (*func)(struct memory_block *, void *))
16361637
{
16371638
struct memory_block *mem = NULL;
@@ -1668,6 +1669,7 @@ static int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn,
16681669
return 0;
16691670
}
16701671

1672+
#ifdef CONFIG_MEMORY_HOTREMOVE
16711673
/**
16721674
* offline_memory_block_cb - callback function for offlining memory block
16731675
* @mem: the memory block to be offlined

0 commit comments

Comments
 (0)