Skip to content

Commit b8179af

Browse files
Hannes Reineckeakpm00
authored andcommitted
mm/memory_hotplug: activate node before adding new memory blocks
The sysfs attributes for memory blocks require the node ID to be set and initialized, so move the node activation before adding new memory blocks. This also has the nice side effect that the BUG_ON() can be converted into a WARN_ON() as we now can handle registration errors. Link: https://lkml.kernel.org/r/[email protected] Fixes: b9ff036 ("mm/memory_hotplug.c: make add_memory_resource use __try_online_node") Signed-off-by: Hannes Reinecke <[email protected]> Acked-by: David Hildenbrand <[email protected]> Acked-by: Oscar Salvador <[email protected]> Reviewed-by: Donet Tom <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c6a8093 commit b8179af

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

drivers/base/memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ static void remove_memory_block(struct memory_block *memory)
879879
* Called under device_hotplug_lock.
880880
*/
881881
int create_memory_block_devices(unsigned long start, unsigned long size,
882-
struct vmem_altmap *altmap,
882+
int nid, struct vmem_altmap *altmap,
883883
struct memory_group *group)
884884
{
885885
const unsigned long start_block_id = pfn_to_block_id(PFN_DOWN(start));
@@ -893,7 +893,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size,
893893
return -EINVAL;
894894

895895
for (block_id = start_block_id; block_id != end_block_id; block_id++) {
896-
ret = add_memory_block(block_id, NUMA_NO_NODE, MEM_OFFLINE, altmap, group);
896+
ret = add_memory_block(block_id, nid, MEM_OFFLINE, altmap, group);
897897
if (ret)
898898
break;
899899
}

include/linux/memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static inline unsigned long memory_block_advised_max_size(void)
159159
extern int register_memory_notifier(struct notifier_block *nb);
160160
extern void unregister_memory_notifier(struct notifier_block *nb);
161161
int create_memory_block_devices(unsigned long start, unsigned long size,
162-
struct vmem_altmap *altmap,
162+
int nid, struct vmem_altmap *altmap,
163163
struct memory_group *group);
164164
void remove_memory_block_devices(unsigned long start, unsigned long size);
165165
extern void memory_dev_init(void);

mm/memory_hotplug.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group,
14771477
}
14781478

14791479
/* create memory block devices after memory was added */
1480-
ret = create_memory_block_devices(cur_start, memblock_size,
1480+
ret = create_memory_block_devices(cur_start, memblock_size, nid,
14811481
params.altmap, group);
14821482
if (ret) {
14831483
arch_remove_memory(cur_start, memblock_size, NULL);
@@ -1539,8 +1539,16 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
15391539

15401540
ret = __try_online_node(nid, false);
15411541
if (ret < 0)
1542-
goto error;
1543-
new_node = ret;
1542+
goto error_memblock_remove;
1543+
if (ret) {
1544+
node_set_online(nid);
1545+
ret = register_one_node(nid);
1546+
if (WARN_ON(ret)) {
1547+
node_set_offline(nid);
1548+
goto error_memblock_remove;
1549+
}
1550+
new_node = true;
1551+
}
15441552

15451553
/*
15461554
* Self hosted memmap array
@@ -1556,24 +1564,13 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
15561564
goto error;
15571565

15581566
/* create memory block devices after memory was added */
1559-
ret = create_memory_block_devices(start, size, NULL, group);
1567+
ret = create_memory_block_devices(start, size, nid, NULL, group);
15601568
if (ret) {
15611569
arch_remove_memory(start, size, params.altmap);
15621570
goto error;
15631571
}
15641572
}
15651573

1566-
if (new_node) {
1567-
/* If sysfs file of new node can't be created, cpu on the node
1568-
* can't be hot-added. There is no rollback way now.
1569-
* So, check by BUG_ON() to catch it reluctantly..
1570-
* We online node here. We can't roll back from here.
1571-
*/
1572-
node_set_online(nid);
1573-
ret = register_one_node(nid);
1574-
BUG_ON(ret);
1575-
}
1576-
15771574
register_memory_blocks_under_node_hotplug(nid, PFN_DOWN(start),
15781575
PFN_UP(start + size - 1));
15791576

@@ -1597,6 +1594,11 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
15971594

15981595
return ret;
15991596
error:
1597+
if (new_node) {
1598+
node_set_offline(nid);
1599+
unregister_one_node(nid);
1600+
}
1601+
error_memblock_remove:
16001602
if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK))
16011603
memblock_remove(start, size);
16021604
error_mem_hotplug_end:

0 commit comments

Comments
 (0)