Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: don't panic when links can't be created in sysfs

At boot time, or when doing memory hot-add operations, if the links in
sysfs can't be created, the system is still able to run, so just report
the error in the kernel log rather than BUG_ON and potentially make system
unusable because the callpath can be called with locks held.

Since the number of memory blocks managed could be high, the messages are
rate limited.

As a consequence, link_mem_sections() has no status to report anymore.

Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Nathan Lynch <nathanl@linux.ibm.com>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>
Cc: Scott Cheloha <cheloha@linux.ibm.com>
Cc: Tony Luck <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/20200915094143.79181-4-ldufour@linux.ibm.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Laurent Dufour and committed by
Linus Torvalds
90c7eaeb cb8e3c8b

+30 -24
+21 -12
drivers/base/node.c
··· 772 772 return pfn_to_nid(pfn); 773 773 } 774 774 775 - static int do_register_memory_block_under_node(int nid, 776 - struct memory_block *mem_blk) 775 + static void do_register_memory_block_under_node(int nid, 776 + struct memory_block *mem_blk) 777 777 { 778 778 int ret; 779 779 ··· 786 786 ret = sysfs_create_link_nowarn(&node_devices[nid]->dev.kobj, 787 787 &mem_blk->dev.kobj, 788 788 kobject_name(&mem_blk->dev.kobj)); 789 - if (ret) 790 - return ret; 789 + if (ret && ret != -EEXIST) 790 + dev_err_ratelimited(&node_devices[nid]->dev, 791 + "can't create link to %s in sysfs (%d)\n", 792 + kobject_name(&mem_blk->dev.kobj), ret); 791 793 792 - return sysfs_create_link_nowarn(&mem_blk->dev.kobj, 794 + ret = sysfs_create_link_nowarn(&mem_blk->dev.kobj, 793 795 &node_devices[nid]->dev.kobj, 794 796 kobject_name(&node_devices[nid]->dev.kobj)); 797 + if (ret && ret != -EEXIST) 798 + dev_err_ratelimited(&mem_blk->dev, 799 + "can't create link to %s in sysfs (%d)\n", 800 + kobject_name(&node_devices[nid]->dev.kobj), 801 + ret); 795 802 } 796 803 797 804 /* register memory section under specified node if it spans that node */ ··· 834 827 if (page_nid != nid) 835 828 continue; 836 829 837 - return do_register_memory_block_under_node(nid, mem_blk); 830 + do_register_memory_block_under_node(nid, mem_blk); 831 + return 0; 838 832 } 839 833 /* mem section does not span the specified node */ 840 834 return 0; ··· 850 842 { 851 843 int nid = *(int *)arg; 852 844 853 - return do_register_memory_block_under_node(nid, mem_blk); 845 + do_register_memory_block_under_node(nid, mem_blk); 846 + return 0; 854 847 } 855 848 856 849 /* ··· 869 860 kobject_name(&node_devices[mem_blk->nid]->dev.kobj)); 870 861 } 871 862 872 - int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn, 873 - enum meminit_context context) 863 + void link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn, 864 + enum meminit_context context) 874 865 { 875 866 walk_memory_blocks_func_t func; 876 867 ··· 879 870 else 880 871 func = register_mem_block_under_node_early; 881 872 882 - return walk_memory_blocks(PFN_PHYS(start_pfn), 883 - PFN_PHYS(end_pfn - start_pfn), (void *)&nid, 884 - func); 873 + walk_memory_blocks(PFN_PHYS(start_pfn), PFN_PHYS(end_pfn - start_pfn), 874 + (void *)&nid, func); 875 + return; 885 876 } 886 877 887 878 #ifdef CONFIG_HUGETLBFS
+7 -9
include/linux/node.h
··· 99 99 typedef void (*node_registration_func_t)(struct node *); 100 100 101 101 #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA) 102 - int link_mem_sections(int nid, unsigned long start_pfn, 103 - unsigned long end_pfn, 104 - enum meminit_context context); 102 + void link_mem_sections(int nid, unsigned long start_pfn, 103 + unsigned long end_pfn, 104 + enum meminit_context context); 105 105 #else 106 - static inline int link_mem_sections(int nid, unsigned long start_pfn, 107 - unsigned long end_pfn, 108 - enum meminit_context context) 106 + static inline void link_mem_sections(int nid, unsigned long start_pfn, 107 + unsigned long end_pfn, 108 + enum meminit_context context) 109 109 { 110 - return 0; 111 110 } 112 111 #endif 113 112 ··· 129 130 if (error) 130 131 return error; 131 132 /* link memory sections under this node */ 132 - error = link_mem_sections(nid, start_pfn, end_pfn, 133 - MEMINIT_EARLY); 133 + link_mem_sections(nid, start_pfn, end_pfn, MEMINIT_EARLY); 134 134 } 135 135 136 136 return error;
+2 -3
mm/memory_hotplug.c
··· 1092 1092 } 1093 1093 1094 1094 /* link memory sections under this node.*/ 1095 - ret = link_mem_sections(nid, PFN_DOWN(start), PFN_UP(start + size - 1), 1096 - MEMINIT_HOTPLUG); 1097 - BUG_ON(ret); 1095 + link_mem_sections(nid, PFN_DOWN(start), PFN_UP(start + size - 1), 1096 + MEMINIT_HOTPLUG); 1098 1097 1099 1098 /* create new memmap entry */ 1100 1099 if (!strcmp(res->name, "System RAM"))