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()

+63 -79
-6
Documentation/mm/arch_pgtable_helpers.rst
··· 52 52 +---------------------------+--------------------------------------------------+ 53 53 | pte_mkspecial | Creates a special PTE | 54 54 +---------------------------+--------------------------------------------------+ 55 - | pte_mkdevmap | Creates a ZONE_DEVICE mapped PTE | 56 - +---------------------------+--------------------------------------------------+ 57 55 | pte_mksoft_dirty | Creates a soft dirty PTE | 58 56 +---------------------------+--------------------------------------------------+ 59 57 | pte_clear_soft_dirty | Clears a soft dirty PTE | ··· 122 124 +---------------------------+--------------------------------------------------+ 123 125 | pmd_mkspecial | Creates a special PMD | 124 126 +---------------------------+--------------------------------------------------+ 125 - | pmd_mkdevmap | Creates a ZONE_DEVICE mapped PMD | 126 - +---------------------------+--------------------------------------------------+ 127 127 | pmd_mksoft_dirty | Creates a soft dirty PMD | 128 128 +---------------------------+--------------------------------------------------+ 129 129 | pmd_clear_soft_dirty | Clears a soft dirty PMD | ··· 180 184 | pud_mkwrite | Creates a writable PUD | 181 185 +---------------------------+--------------------------------------------------+ 182 186 | pud_wrprotect | Creates a write protected PUD | 183 - +---------------------------+--------------------------------------------------+ 184 - | pud_mkdevmap | Creates a ZONE_DEVICE mapped PUD | 185 187 +---------------------------+--------------------------------------------------+ 186 188 | pud_mkinvalid | Invalidates a present PUD; do not call for | 187 189 | | non-present PUD [1] |
+23 -30
drivers/base/memory.c
··· 769 769 770 770 #ifdef CONFIG_NUMA 771 771 /** 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. 774 775 * @mem: The memory block device. 775 776 * @nid: The node id. 776 - * @context: The memory initialization context. 777 777 * 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. 782 784 */ 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) 785 786 { 786 - if (context == MEMINIT_EARLY && mem->nid != nid) { 787 + if (mem->nid != nid) { 787 788 /* 788 789 * For early memory we have to determine the zone when setting 789 790 * the node id and handle multiple nodes spanning a single ··· 798 797 mem->zone = early_node_zone_for_memory_block(mem, nid); 799 798 else 800 799 mem->zone = NULL; 800 + /* 801 + * If this memory block spans multiple nodes, we only indicate 802 + * the last processed node. If we span multiple nodes (not applicable 803 + * to hotplugged memory), zone == NULL will prohibit memory offlining 804 + * and consequently unplug. 805 + */ 806 + mem->nid = nid; 801 807 } 802 - 803 - /* 804 - * If this memory block spans multiple nodes, we only indicate 805 - * the last processed node. If we span multiple nodes (not applicable 806 - * to hotplugged memory), zone == NULL will prohibit memory offlining 807 - * and consequently unplug. 808 - */ 809 - mem->nid = nid; 810 808 } 811 809 #endif 812 810 813 - static int add_memory_block(unsigned long block_id, unsigned long state, 811 + static int add_memory_block(unsigned long block_id, int nid, unsigned long state, 814 812 struct vmem_altmap *altmap, 815 813 struct memory_group *group) 816 814 { ··· 827 827 828 828 mem->start_section_nr = block_id * sections_per_block; 829 829 mem->state = state; 830 - mem->nid = NUMA_NO_NODE; 830 + mem->nid = nid; 831 831 mem->altmap = altmap; 832 832 INIT_LIST_HEAD(&mem->group_next); 833 833 ··· 852 852 } 853 853 854 854 return 0; 855 - } 856 - 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 855 } 863 856 864 857 static void remove_memory_block(struct memory_block *memory) ··· 879 886 * Called under device_hotplug_lock. 880 887 */ 881 888 int create_memory_block_devices(unsigned long start, unsigned long size, 882 - struct vmem_altmap *altmap, 889 + int nid, struct vmem_altmap *altmap, 883 890 struct memory_group *group) 884 891 { 885 892 const unsigned long start_block_id = pfn_to_block_id(PFN_DOWN(start)); ··· 893 900 return -EINVAL; 894 901 895 902 for (block_id = start_block_id; block_id != end_block_id; block_id++) { 896 - ret = add_hotplug_memory_block(block_id, altmap, group); 903 + ret = add_memory_block(block_id, nid, MEM_OFFLINE, altmap, group); 897 904 if (ret) 898 905 break; 899 906 } ··· 998 1005 continue; 999 1006 1000 1007 block_id = memory_block_id(nr); 1001 - ret = add_memory_block(block_id, MEM_ONLINE, NULL, NULL); 1008 + ret = add_memory_block(block_id, NUMA_NO_NODE, MEM_ONLINE, NULL, NULL); 1002 1009 if (ret) { 1003 1010 panic("%s() failed to add memory block: %d\n", 1004 1011 __func__, ret);
+4 -6
drivers/base/node.c
··· 819 819 820 820 #ifdef CONFIG_MEMORY_HOTPLUG 821 821 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) 824 823 { 825 824 int ret; 826 - 827 - memory_block_add_nid(mem_blk, nid, context); 828 825 829 826 ret = sysfs_create_link_nowarn(&node_devices[nid]->dev.kobj, 830 827 &mem_blk->dev.kobj, ··· 850 853 { 851 854 int nid = *(int *)arg; 852 855 853 - do_register_memory_block_under_node(nid, mem_blk, MEMINIT_HOTPLUG); 856 + do_register_memory_block_under_node(nid, mem_blk); 854 857 return 0; 855 858 } 856 859 ··· 890 893 if (!mem) 891 894 continue; 892 895 893 - do_register_memory_block_under_node(nid, mem, MEMINIT_EARLY); 896 + memory_block_add_nid_early(mem, nid); 897 + do_register_memory_block_under_node(nid, mem); 894 898 put_device(&mem->dev); 895 899 } 896 900
+2 -3
include/linux/memory.h
··· 159 159 extern int register_memory_notifier(struct notifier_block *nb); 160 160 extern void unregister_memory_notifier(struct notifier_block *nb); 161 161 int create_memory_block_devices(unsigned long start, unsigned long size, 162 - struct vmem_altmap *altmap, 162 + int nid, struct vmem_altmap *altmap, 163 163 struct memory_group *group); 164 164 void remove_memory_block_devices(unsigned long start, unsigned long size); 165 165 extern void memory_dev_init(void); ··· 202 202 } 203 203 204 204 #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); 207 206 #endif /* CONFIG_NUMA */ 208 207 int memory_block_advise_max_size(unsigned long size); 209 208 unsigned long memory_block_advised_max_size(void);
+1 -4
mm/khugepaged.c
··· 376 376 377 377 int __init khugepaged_init(void) 378 378 { 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); 383 380 if (!mm_slot_cache) 384 381 return -ENOMEM; 385 382
+14 -13
mm/ksm.c
··· 2921 2921 2922 2922 void __ksm_exit(struct mm_struct *mm) 2923 2923 { 2924 - struct ksm_mm_slot *mm_slot; 2924 + struct ksm_mm_slot *mm_slot = NULL; 2925 2925 struct mm_slot *slot; 2926 2926 int easy_to_free = 0; 2927 2927 ··· 2936 2936 2937 2937 spin_lock(&ksm_mmlist_lock); 2938 2938 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); 2951 2951 } 2952 + unlock: 2952 2953 spin_unlock(&ksm_mmlist_lock); 2953 2954 2954 2955 if (easy_to_free) {
+2 -2
mm/madvise.c
··· 1071 1071 1072 1072 static bool is_guard_pte_marker(pte_t ptent) 1073 1073 { 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)); 1076 1076 } 1077 1077 1078 1078 static int guard_install_pud_entry(pud_t *pud, unsigned long addr,
+17 -15
mm/memory_hotplug.c
··· 1477 1477 } 1478 1478 1479 1479 /* 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, 1481 1481 params.altmap, group); 1482 1482 if (ret) { 1483 1483 arch_remove_memory(cur_start, memblock_size, NULL); ··· 1539 1539 1540 1540 ret = __try_online_node(nid, false); 1541 1541 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 + } 1544 1552 1545 1553 /* 1546 1554 * Self hosted memmap array ··· 1564 1556 goto error; 1565 1557 1566 1558 /* create memory block devices after memory was added */ 1567 - ret = create_memory_block_devices(start, size, NULL, group); 1559 + ret = create_memory_block_devices(start, size, nid, NULL, group); 1568 1560 if (ret) { 1569 1561 arch_remove_memory(start, size, params.altmap); 1570 1562 goto error; 1571 1563 } 1572 - } 1573 - 1574 - if (new_node) { 1575 - /* If sysfs file of new node can't be created, cpu on the node 1576 - * can't be hot-added. There is no rollback way now. 1577 - * So, check by BUG_ON() to catch it reluctantly.. 1578 - * We online node here. We can't roll back from here. 1579 - */ 1580 - node_set_online(nid); 1581 - ret = register_one_node(nid); 1582 - BUG_ON(ret); 1583 1564 } 1584 1565 1585 1566 register_memory_blocks_under_node_hotplug(nid, PFN_DOWN(start), ··· 1594 1597 1595 1598 return ret; 1596 1599 error: 1600 + if (new_node) { 1601 + node_set_offline(nid); 1602 + unregister_one_node(nid); 1603 + } 1604 + error_memblock_remove: 1597 1605 if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK)) 1598 1606 memblock_remove(start, size); 1599 1607 error_mem_hotplug_end: