Skip to content

Commit 7a405db

Browse files
committed
Merge tag 'mm-stable-2025-10-03-16-49' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Pull more MM updates from Andrew Morton: "Only two patch series in this pull request: - "mm/memory_hotplug: fixup crash during uevent handling" from Hannes Reinecke fixes a race that was causing udev to trigger a crash in the memory hotplug code - "mm_slot: following fixup for usage of mm_slot_entry()" from Wei Yang adds some touchups to the just-merged mm_slot changes" * tag 'mm-stable-2025-10-03-16-49' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: mm/khugepaged: use KMEM_CACHE() mm/ksm: cleanup mm_slot_entry() invocation Documentation/mm: drop pxx_mkdevmap() descriptions from page table helpers mm: clean up is_guard_pte_marker() drivers/base: move memory_block_add_nid() into the caller mm/memory_hotplug: activate node before adding new memory blocks drivers/base/memory: add node id parameter to add_memory_block()
2 parents cf0e371 + c14bdcc commit 7a405db

File tree

8 files changed

+63
-79
lines changed

8 files changed

+63
-79
lines changed

Documentation/mm/arch_pgtable_helpers.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ PTE Page Table Helpers
5252
+---------------------------+--------------------------------------------------+
5353
| pte_mkspecial | Creates a special PTE |
5454
+---------------------------+--------------------------------------------------+
55-
| pte_mkdevmap | Creates a ZONE_DEVICE mapped PTE |
56-
+---------------------------+--------------------------------------------------+
5755
| pte_mksoft_dirty | Creates a soft dirty PTE |
5856
+---------------------------+--------------------------------------------------+
5957
| pte_clear_soft_dirty | Clears a soft dirty PTE |
@@ -124,8 +122,6 @@ PMD Page Table Helpers
124122
+---------------------------+--------------------------------------------------+
125123
| pmd_mkspecial | Creates a special PMD |
126124
+---------------------------+--------------------------------------------------+
127-
| pmd_mkdevmap | Creates a ZONE_DEVICE mapped PMD |
128-
+---------------------------+--------------------------------------------------+
129125
| pmd_mksoft_dirty | Creates a soft dirty PMD |
130126
+---------------------------+--------------------------------------------------+
131127
| pmd_clear_soft_dirty | Clears a soft dirty PMD |
@@ -185,8 +181,6 @@ PUD Page Table Helpers
185181
+---------------------------+--------------------------------------------------+
186182
| pud_wrprotect | Creates a write protected PUD |
187183
+---------------------------+--------------------------------------------------+
188-
| pud_mkdevmap | Creates a ZONE_DEVICE mapped PUD |
189-
+---------------------------+--------------------------------------------------+
190184
| pud_mkinvalid | Invalidates a present PUD; do not call for |
191185
| | non-present PUD [1] |
192186
+---------------------------+--------------------------------------------------+

drivers/base/memory.c

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -769,21 +769,22 @@ static struct zone *early_node_zone_for_memory_block(struct memory_block *mem,
769769

770770
#ifdef CONFIG_NUMA
771771
/**
772-
* memory_block_add_nid() - Indicate that system RAM falling into this memory
773-
* block device (partially) belongs to the given node.
772+
* memory_block_add_nid_early() - Indicate that early system RAM falling into
773+
* this memory block device (partially) belongs
774+
* to the given node.
774775
* @mem: The memory block device.
775776
* @nid: The node id.
776-
* @context: The memory initialization context.
777777
*
778-
* Indicate that system RAM falling into this memory block (partially) belongs
779-
* to the given node. If the context indicates ("early") that we are adding the
780-
* node during node device subsystem initialization, this will also properly
781-
* set/adjust mem->zone based on the zone ranges of the given node.
778+
* Indicate that early system RAM falling into this memory block (partially)
779+
* belongs to the given node. This will also properly set/adjust mem->zone based
780+
* on the zone ranges of the given node.
781+
*
782+
* Memory hotplug handles this on memory block creation, where we can only have
783+
* a single nid span a memory block.
782784
*/
783-
void memory_block_add_nid(struct memory_block *mem, int nid,
784-
enum meminit_context context)
785+
void memory_block_add_nid_early(struct memory_block *mem, int nid)
785786
{
786-
if (context == MEMINIT_EARLY && mem->nid != nid) {
787+
if (mem->nid != nid) {
787788
/*
788789
* For early memory we have to determine the zone when setting
789790
* the node id and handle multiple nodes spanning a single
@@ -797,19 +798,18 @@ void memory_block_add_nid(struct memory_block *mem, int nid,
797798
mem->zone = early_node_zone_for_memory_block(mem, nid);
798799
else
799800
mem->zone = NULL;
801+
/*
802+
* If this memory block spans multiple nodes, we only indicate
803+
* the last processed node. If we span multiple nodes (not applicable
804+
* to hotplugged memory), zone == NULL will prohibit memory offlining
805+
* and consequently unplug.
806+
*/
807+
mem->nid = nid;
800808
}
801-
802-
/*
803-
* If this memory block spans multiple nodes, we only indicate
804-
* the last processed node. If we span multiple nodes (not applicable
805-
* to hotplugged memory), zone == NULL will prohibit memory offlining
806-
* and consequently unplug.
807-
*/
808-
mem->nid = nid;
809809
}
810810
#endif
811811

812-
static int add_memory_block(unsigned long block_id, unsigned long state,
812+
static int add_memory_block(unsigned long block_id, int nid, unsigned long state,
813813
struct vmem_altmap *altmap,
814814
struct memory_group *group)
815815
{
@@ -827,7 +827,7 @@ static int add_memory_block(unsigned long block_id, unsigned long state,
827827

828828
mem->start_section_nr = block_id * sections_per_block;
829829
mem->state = state;
830-
mem->nid = NUMA_NO_NODE;
830+
mem->nid = nid;
831831
mem->altmap = altmap;
832832
INIT_LIST_HEAD(&mem->group_next);
833833

@@ -854,13 +854,6 @@ static int add_memory_block(unsigned long block_id, unsigned long state,
854854
return 0;
855855
}
856856

857-
static int add_hotplug_memory_block(unsigned long block_id,
858-
struct vmem_altmap *altmap,
859-
struct memory_group *group)
860-
{
861-
return add_memory_block(block_id, MEM_OFFLINE, altmap, group);
862-
}
863-
864857
static void remove_memory_block(struct memory_block *memory)
865858
{
866859
if (WARN_ON_ONCE(memory->dev.bus != &memory_subsys))
@@ -886,7 +879,7 @@ static void remove_memory_block(struct memory_block *memory)
886879
* Called under device_hotplug_lock.
887880
*/
888881
int create_memory_block_devices(unsigned long start, unsigned long size,
889-
struct vmem_altmap *altmap,
882+
int nid, struct vmem_altmap *altmap,
890883
struct memory_group *group)
891884
{
892885
const unsigned long start_block_id = pfn_to_block_id(PFN_DOWN(start));
@@ -900,7 +893,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size,
900893
return -EINVAL;
901894

902895
for (block_id = start_block_id; block_id != end_block_id; block_id++) {
903-
ret = add_hotplug_memory_block(block_id, altmap, group);
896+
ret = add_memory_block(block_id, nid, MEM_OFFLINE, altmap, group);
904897
if (ret)
905898
break;
906899
}
@@ -1005,7 +998,7 @@ void __init memory_dev_init(void)
1005998
continue;
1006999

10071000
block_id = memory_block_id(nr);
1008-
ret = add_memory_block(block_id, MEM_ONLINE, NULL, NULL);
1001+
ret = add_memory_block(block_id, NUMA_NO_NODE, MEM_ONLINE, NULL, NULL);
10091002
if (ret) {
10101003
panic("%s() failed to add memory block: %d\n",
10111004
__func__, ret);

drivers/base/node.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -819,13 +819,10 @@ int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
819819

820820
#ifdef CONFIG_MEMORY_HOTPLUG
821821
static void do_register_memory_block_under_node(int nid,
822-
struct memory_block *mem_blk,
823-
enum meminit_context context)
822+
struct memory_block *mem_blk)
824823
{
825824
int ret;
826825

827-
memory_block_add_nid(mem_blk, nid, context);
828-
829826
ret = sysfs_create_link_nowarn(&node_devices[nid]->dev.kobj,
830827
&mem_blk->dev.kobj,
831828
kobject_name(&mem_blk->dev.kobj));
@@ -853,7 +850,7 @@ static int register_mem_block_under_node_hotplug(struct memory_block *mem_blk,
853850
{
854851
int nid = *(int *)arg;
855852

856-
do_register_memory_block_under_node(nid, mem_blk, MEMINIT_HOTPLUG);
853+
do_register_memory_block_under_node(nid, mem_blk);
857854
return 0;
858855
}
859856

@@ -893,7 +890,8 @@ static void register_memory_blocks_under_nodes(void)
893890
if (!mem)
894891
continue;
895892

896-
do_register_memory_block_under_node(nid, mem, MEMINIT_EARLY);
893+
memory_block_add_nid_early(mem, nid);
894+
do_register_memory_block_under_node(nid, mem);
897895
put_device(&mem->dev);
898896
}
899897

include/linux/memory.h

Lines changed: 2 additions & 3 deletions
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);
@@ -202,8 +202,7 @@ static inline unsigned long phys_to_block_id(unsigned long phys)
202202
}
203203

204204
#ifdef CONFIG_NUMA
205-
void memory_block_add_nid(struct memory_block *mem, int nid,
206-
enum meminit_context context);
205+
void memory_block_add_nid_early(struct memory_block *mem, int nid);
207206
#endif /* CONFIG_NUMA */
208207
int memory_block_advise_max_size(unsigned long size);
209208
unsigned long memory_block_advised_max_size(void);

mm/khugepaged.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,7 @@ int hugepage_madvise(struct vm_area_struct *vma,
376376

377377
int __init khugepaged_init(void)
378378
{
379-
mm_slot_cache = kmem_cache_create("khugepaged_mm_slot",
380-
sizeof(struct mm_slot),
381-
__alignof__(struct mm_slot),
382-
0, NULL);
379+
mm_slot_cache = KMEM_CACHE(mm_slot, 0);
383380
if (!mm_slot_cache)
384381
return -ENOMEM;
385382

mm/ksm.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,7 @@ int __ksm_enter(struct mm_struct *mm)
29212921

29222922
void __ksm_exit(struct mm_struct *mm)
29232923
{
2924-
struct ksm_mm_slot *mm_slot;
2924+
struct ksm_mm_slot *mm_slot = NULL;
29252925
struct mm_slot *slot;
29262926
int easy_to_free = 0;
29272927

@@ -2936,19 +2936,20 @@ void __ksm_exit(struct mm_struct *mm)
29362936

29372937
spin_lock(&ksm_mmlist_lock);
29382938
slot = mm_slot_lookup(mm_slots_hash, mm);
2939-
if (slot) {
2940-
mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot);
2941-
if (ksm_scan.mm_slot != mm_slot) {
2942-
if (!mm_slot->rmap_list) {
2943-
hash_del(&slot->hash);
2944-
list_del(&slot->mm_node);
2945-
easy_to_free = 1;
2946-
} else {
2947-
list_move(&slot->mm_node,
2948-
&ksm_scan.mm_slot->slot.mm_node);
2949-
}
2950-
}
2939+
if (!slot)
2940+
goto unlock;
2941+
mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot);
2942+
if (ksm_scan.mm_slot == mm_slot)
2943+
goto unlock;
2944+
if (!mm_slot->rmap_list) {
2945+
hash_del(&slot->hash);
2946+
list_del(&slot->mm_node);
2947+
easy_to_free = 1;
2948+
} else {
2949+
list_move(&slot->mm_node,
2950+
&ksm_scan.mm_slot->slot.mm_node);
29512951
}
2952+
unlock:
29522953
spin_unlock(&ksm_mmlist_lock);
29532954

29542955
if (easy_to_free) {

mm/madvise.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,8 @@ static bool is_valid_guard_vma(struct vm_area_struct *vma, bool allow_locked)
10711071

10721072
static bool is_guard_pte_marker(pte_t ptent)
10731073
{
1074-
return is_pte_marker(ptent) &&
1075-
is_guard_swp_entry(pte_to_swp_entry(ptent));
1074+
return is_swap_pte(ptent) &&
1075+
is_guard_swp_entry(pte_to_swp_entry(ptent));
10761076
}
10771077

10781078
static int guard_install_pud_entry(pud_t *pud, unsigned long addr,

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)