s390/smp: consolidate locking for smp_rescan()
authorHeiko Carstens <hca@linux.ibm.com>
Wed, 17 Feb 2021 06:10:46 +0000 (07:10 +0100)
committerVasily Gorbik <gor@linux.ibm.com>
Tue, 23 Feb 2021 23:31:22 +0000 (00:31 +0100)
Move locking to __smp_rescan() instead of duplicating it to all call sites.

Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/kernel/smp.c

index e299892..9fa85c9 100644 (file)
@@ -780,6 +780,8 @@ static int __smp_rescan_cpus(struct sclp_core_info *info, bool early)
        u16 core_id;
        int nr, i;
 
+       get_online_cpus();
+       mutex_lock(&smp_cpu_state_mutex);
        nr = 0;
        cpumask_xor(&avail, cpu_possible_mask, cpu_present_mask);
        /*
@@ -800,6 +802,8 @@ static int __smp_rescan_cpus(struct sclp_core_info *info, bool early)
                configured = i < info->configured;
                nr += smp_add_core(&info->core[i], &avail, configured, early);
        }
+       mutex_unlock(&smp_cpu_state_mutex);
+       put_online_cpus();
        return nr;
 }
 
@@ -847,9 +851,7 @@ void __init smp_detect_cpus(void)
        pr_info("%d configured CPUs, %d standby CPUs\n", c_cpus, s_cpus);
 
        /* Add CPUs present at boot */
-       get_online_cpus();
        __smp_rescan_cpus(info, true);
-       put_online_cpus();
        memblock_free_early((unsigned long)info, sizeof(*info));
 }
 
@@ -1178,11 +1180,7 @@ int __ref smp_rescan_cpus(void)
        if (!info)
                return -ENOMEM;
        smp_get_core_info(info, 0);
-       get_online_cpus();
-       mutex_lock(&smp_cpu_state_mutex);
        nr = __smp_rescan_cpus(info, false);
-       mutex_unlock(&smp_cpu_state_mutex);
-       put_online_cpus();
        kfree(info);
        if (nr)
                topology_schedule_update();