Skip to content

Commit 90c7eae

Browse files
ldu4torvalds
authored andcommitted
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>
1 parent cb8e3c8 commit 90c7eae

3 files changed

Lines changed: 30 additions & 24 deletions

File tree

‎drivers/base/node.c‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,8 @@ static int __ref get_nid_for_pfn(unsigned long pfn)
772772
return pfn_to_nid(pfn);
773773
}
774774

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)
777777
{
778778
int ret;
779779

@@ -786,12 +786,19 @@ static int do_register_memory_block_under_node(int nid,
786786
ret = sysfs_create_link_nowarn(&node_devices[nid]->dev.kobj,
787787
&mem_blk->dev.kobj,
788788
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);
791793

792-
return sysfs_create_link_nowarn(&mem_blk->dev.kobj,
794+
ret = sysfs_create_link_nowarn(&mem_blk->dev.kobj,
793795
&node_devices[nid]->dev.kobj,
794796
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);
795802
}
796803

797804
/* register memory section under specified node if it spans that node */
@@ -827,7 +834,8 @@ static int register_mem_block_under_node_early(struct memory_block *mem_blk,
827834
if (page_nid != nid)
828835
continue;
829836

830-
return do_register_memory_block_under_node(nid, mem_blk);
837+
do_register_memory_block_under_node(nid, mem_blk);
838+
return 0;
831839
}
832840
/* mem section does not span the specified node */
833841
return 0;
@@ -842,7 +850,8 @@ static int register_mem_block_under_node_hotplug(struct memory_block *mem_blk,
842850
{
843851
int nid = *(int *)arg;
844852

845-
return do_register_memory_block_under_node(nid, mem_blk);
853+
do_register_memory_block_under_node(nid, mem_blk);
854+
return 0;
846855
}
847856

848857
/*
@@ -860,8 +869,8 @@ void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
860869
kobject_name(&node_devices[mem_blk->nid]->dev.kobj));
861870
}
862871

863-
int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn,
864-
enum meminit_context context)
872+
void link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn,
873+
enum meminit_context context)
865874
{
866875
walk_memory_blocks_func_t func;
867876

@@ -870,9 +879,9 @@ int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn,
870879
else
871880
func = register_mem_block_under_node_early;
872881

873-
return walk_memory_blocks(PFN_PHYS(start_pfn),
874-
PFN_PHYS(end_pfn - start_pfn), (void *)&nid,
875-
func);
882+
walk_memory_blocks(PFN_PHYS(start_pfn), PFN_PHYS(end_pfn - start_pfn),
883+
(void *)&nid, func);
884+
return;
876885
}
877886

878887
#ifdef CONFIG_HUGETLBFS

‎include/linux/node.h‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,14 @@ extern struct node *node_devices[];
9999
typedef void (*node_registration_func_t)(struct node *);
100100

101101
#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);
105105
#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)
109109
{
110-
return 0;
111110
}
112111
#endif
113112

@@ -130,8 +129,7 @@ static inline int register_one_node(int nid)
130129
if (error)
131130
return error;
132131
/* link memory sections under this node */
133-
error = link_mem_sections(nid, start_pfn, end_pfn,
134-
MEMINIT_EARLY);
132+
link_mem_sections(nid, start_pfn, end_pfn, MEMINIT_EARLY);
135133
}
136134

137135
return error;

‎mm/memory_hotplug.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,9 +1092,8 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
10921092
}
10931093

10941094
/* 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);
10981097

10991098
/* create new memmap entry */
11001099
if (!strcmp(res->name, "System RAM"))

0 commit comments

Comments
 (0)