]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drivers/base/node: consolidate node device subsystem initialization in node_dev_init()
authorDavid Hildenbrand <david@redhat.com>
Tue, 22 Mar 2022 21:47:13 +0000 (14:47 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 22 Mar 2022 22:57:10 +0000 (15:57 -0700)
...  and call node_dev_init() after memory_dev_init() from driver_init(),
so before any of the existing arch/subsys calls.  All online nodes should
be known at that point: early during boot, arch code determines node and
zone ranges and sets the relevant nodes online; usually this happens in
setup_arch().

This is in line with memory_dev_init(), which initializes the memory
device subsystem and creates all memory block devices.

Similar to memory_dev_init(), panic() if anything goes wrong, we don't
want to continue with such basic initialization errors.

The important part is that node_dev_init() gets called after
memory_dev_init() and after cpu_dev_init(), but before any of the relevant
archs call register_cpu() to register the new cpu device under the node
device.  The latter should be the case for the current users of
topology_init().

Link: https://lkml.kernel.org/r/20220203105212.30385-1-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Tested-by: Anatoly Pugachev <matorola@gmail.com> (sparc64)
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
12 files changed:
arch/arm64/kernel/setup.c
arch/ia64/kernel/topology.c
arch/mips/kernel/topology.c
arch/powerpc/kernel/sysfs.c
arch/riscv/kernel/setup.c
arch/s390/kernel/numa.c
arch/sh/kernel/topology.c
arch/sparc/kernel/sysfs.c
arch/x86/kernel/topology.c
drivers/base/init.c
drivers/base/node.c
include/linux/node.h

index f70573928f1bff0eb507d4c8630bc622293b20f3..3505789cf4bd92aaa4ac011cedc202cb866bbf27 100644 (file)
@@ -406,9 +406,6 @@ static int __init topology_init(void)
 {
        int i;
 
-       for_each_online_node(i)
-               register_one_node(i);
-
        for_each_possible_cpu(i) {
                struct cpu *cpu = &per_cpu(cpu_data.cpu, i);
                cpu->hotpluggable = cpu_can_disable(i);
index e4992917a24b772e48a4769faea57c68e178576a..94a848b06f15a964c0a07575533d6ace844b7b0b 100644 (file)
@@ -70,16 +70,6 @@ static int __init topology_init(void)
 {
        int i, err = 0;
 
-#ifdef CONFIG_NUMA
-       /*
-        * MCD - Do we want to register all ONLINE nodes, or all POSSIBLE nodes?
-        */
-       for_each_online_node(i) {
-               if ((err = register_one_node(i)))
-                       goto out;
-       }
-#endif
-
        sysfs_cpus = kcalloc(NR_CPUS, sizeof(struct ia64_cpu), GFP_KERNEL);
        if (!sysfs_cpus)
                panic("kzalloc in topology_init failed - NR_CPUS too big?");
index 08ad6371fbe087b2c174613c1a8f0eb19824dff7..9429d85a4703c0f514f7d385c83e7bd480bf3da5 100644 (file)
@@ -12,11 +12,6 @@ static int __init topology_init(void)
 {
        int i, ret;
 
-#ifdef CONFIG_NUMA
-       for_each_online_node(i)
-               register_one_node(i);
-#endif /* CONFIG_NUMA */
-
        for_each_present_cpu(i) {
                struct cpu *c = &per_cpu(cpu_devices, i);
 
index d45a415d5374bbd46285369d868b10826d8e0910..2069bbb90a9a39fc41654a2daeb0b241eb930d6a 100644 (file)
@@ -1110,14 +1110,6 @@ EXPORT_SYMBOL_GPL(cpu_remove_dev_attr_group);
 /* NUMA stuff */
 
 #ifdef CONFIG_NUMA
-static void __init register_nodes(void)
-{
-       int i;
-
-       for (i = 0; i < MAX_NUMNODES; i++)
-               register_one_node(i);
-}
-
 int sysfs_add_device_to_node(struct device *dev, int nid)
 {
        struct node *node = node_devices[nid];
@@ -1132,13 +1124,6 @@ void sysfs_remove_device_from_node(struct device *dev, int nid)
        sysfs_remove_link(&node->dev.kobj, kobject_name(&dev->kobj));
 }
 EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node);
-
-#else
-static void __init register_nodes(void)
-{
-       return;
-}
-
 #endif
 
 /* Only valid if CPU is present. */
@@ -1155,8 +1140,6 @@ static int __init topology_init(void)
 {
        int cpu, r;
 
-       register_nodes();
-
        for_each_possible_cpu(cpu) {
                struct cpu *c = &per_cpu(cpu_devices, cpu);
 
index b42bfdc674823cec93ab3342235f12c5b867b611..834eb652a7b9d6046c0c054b9c58815e03e464c6 100644 (file)
@@ -301,9 +301,6 @@ static int __init topology_init(void)
 {
        int i, ret;
 
-       for_each_online_node(i)
-               register_one_node(i);
-
        for_each_possible_cpu(i) {
                struct cpu *cpu = &per_cpu(cpu_devices, i);
 
index 51c5a9f6e525735790393164f4cd68b10b1878b3..23ab9f02f2787301ecfd6c4e93c674570f279873 100644 (file)
@@ -33,10 +33,3 @@ void __init numa_setup(void)
        NODE_DATA(0)->node_spanned_pages = memblock_end_of_DRAM() >> PAGE_SHIFT;
        NODE_DATA(0)->node_id = 0;
 }
-
-static int __init numa_init_late(void)
-{
-       register_one_node(0);
-       return 0;
-}
-arch_initcall(numa_init_late);
index 76af6db9daa237c9976be0814f751f0c9ae23679..2d2a7509b565ac8835087518fc92221a315daeb2 100644 (file)
@@ -46,11 +46,6 @@ static int __init topology_init(void)
 {
        int i, ret;
 
-#ifdef CONFIG_NUMA
-       for_each_online_node(i)
-               register_one_node(i);
-#endif
-
        for_each_present_cpu(i) {
                struct cpu *c = &per_cpu(cpu_devices, i);
 
index 6d60d416f0dd70f8f0c96d95fa6311599d6e2c30..f19487e4cc71eb714e5d5c4e08d231ba8597828f 100644 (file)
@@ -244,22 +244,10 @@ static void __init check_mmu_stats(void)
                mmu_stats_supported = 1;
 }
 
-static void register_nodes(void)
-{
-#ifdef CONFIG_NUMA
-       int i;
-
-       for (i = 0; i < MAX_NUMNODES; i++)
-               register_one_node(i);
-#endif
-}
-
 static int __init topology_init(void)
 {
        int cpu, ret;
 
-       register_nodes();
-
        check_mmu_stats();
 
        for_each_possible_cpu(cpu) {
index bd83748e2bde3a7f1b95b94a90db5c0577f99b66..8617d1ed9d31bc47580bcf231808f7dd1cb99eb9 100644 (file)
@@ -154,11 +154,6 @@ static int __init topology_init(void)
 {
        int i;
 
-#ifdef CONFIG_NUMA
-       for_each_online_node(i)
-               register_one_node(i);
-#endif
-
        for_each_present_cpu(i)
                arch_register_cpu(i);
 
index a9f57c22fb9e2f128e9d8708483ca1f631a8fa7e..d8d0fe687111a0e0cec44c388a470df8708bdf44 100644 (file)
@@ -35,5 +35,6 @@ void __init driver_init(void)
        auxiliary_bus_init();
        cpu_dev_init();
        memory_dev_init();
+       node_dev_init();
        container_dev_init();
 }
index 87acc47e89515b82df059e25bd8d76d2eb8211ec..a133981a12fc642d5ceb4cac1509e322eff09885 100644 (file)
@@ -1065,26 +1065,30 @@ static const struct attribute_group *cpu_root_attr_groups[] = {
 };
 
 #define NODE_CALLBACK_PRI      2       /* lower than SLAB */
-static int __init register_node_type(void)
+void __init node_dev_init(void)
 {
-       int ret;
+       static struct notifier_block node_memory_callback_nb = {
+               .notifier_call = node_memory_callback,
+               .priority = NODE_CALLBACK_PRI,
+       };
+       int ret, i;
 
        BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
        BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES);
 
        ret = subsys_system_register(&node_subsys, cpu_root_attr_groups);
-       if (!ret) {
-               static struct notifier_block node_memory_callback_nb = {
-                       .notifier_call = node_memory_callback,
-                       .priority = NODE_CALLBACK_PRI,
-               };
-               register_hotmemory_notifier(&node_memory_callback_nb);
-       }
+       if (ret)
+               panic("%s() failed to register subsystem: %d\n", __func__, ret);
+
+       register_hotmemory_notifier(&node_memory_callback_nb);
 
        /*
-        * Note:  we're not going to unregister the node class if we fail
-        * to register the node state class attribute files.
+        * Create all node devices, which will properly link the node
+        * to applicable memory block devices and already created cpu devices.
         */
-       return ret;
+       for_each_online_node(i) {
+               ret = register_one_node(i);
+               if (ret)
+                       panic("%s() failed to add node: %d\n", __func__, ret);
+       }
 }
-postcore_initcall(register_node_type);
index 81bbf1c0afd37553f95586ea0c607fac16130e40..7f876d48af11f15ae995d83af4196553c0a5da0c 100644 (file)
@@ -112,6 +112,7 @@ static inline void link_mem_sections(int nid, unsigned long start_pfn,
 
 extern void unregister_node(struct node *node);
 #ifdef CONFIG_NUMA
+extern void node_dev_init(void);
 /* Core of the node registration - only memory hotplug should use this */
 extern int __register_one_node(int nid);
 
@@ -149,6 +150,9 @@ extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
                                         node_registration_func_t unregister);
 #endif
 #else
+static inline void node_dev_init(void)
+{
+}
 static inline int __register_one_node(int nid)
 {
        return 0;