Skip to content

Commit 9ae49fa

Browse files
rientjestorvalds
authored andcommitted
mm: slab-allocate memory section nodemask for large systems
Nodemasks should not be allocated on the stack for large systems (when it is larger than 256 bytes) since there is a threat of overflow. This patch causes the unregister_mem_sect_under_nodes() nodemask to be allocated on the stack for smaller systems and be allocated by slab for larger systems. GFP_KERNEL is used since remove_memory_block() can block. Cc: Gary Hade <garyhade@us.ibm.com> Cc: Badari Pulavarty <pbadari@us.ibm.com> Cc: Alex Chiang <achiang@hp.com> Signed-off-by: David Rientjes <rientjes@google.com> Cc: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent caed0f4 commit 9ae49fa

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎drivers/base/node.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,16 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
363363
/* unregister memory section under all nodes that it spans */
364364
int unregister_mem_sect_under_nodes(struct memory_block *mem_blk)
365365
{
366-
nodemask_t unlinked_nodes;
366+
NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL);
367367
unsigned long pfn, sect_start_pfn, sect_end_pfn;
368368

369-
if (!mem_blk)
369+
if (!mem_blk) {
370+
NODEMASK_FREE(unlinked_nodes);
370371
return -EFAULT;
371-
nodes_clear(unlinked_nodes);
372+
}
373+
if (!unlinked_nodes)
374+
return -ENOMEM;
375+
nodes_clear(*unlinked_nodes);
372376
sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index);
373377
sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
374378
for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
@@ -379,13 +383,14 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk)
379383
continue;
380384
if (!node_online(nid))
381385
continue;
382-
if (node_test_and_set(nid, unlinked_nodes))
386+
if (node_test_and_set(nid, *unlinked_nodes))
383387
continue;
384388
sysfs_remove_link(&node_devices[nid].sysdev.kobj,
385389
kobject_name(&mem_blk->sysdev.kobj));
386390
sysfs_remove_link(&mem_blk->sysdev.kobj,
387391
kobject_name(&node_devices[nid].sysdev.kobj));
388392
}
393+
NODEMASK_FREE(unlinked_nodes);
389394
return 0;
390395
}
391396

0 commit comments

Comments
 (0)