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

[S390] smp: Fix locking order.

On some smp sysfs store attributes get_online_cpus() may block on
cpu_hotplug.lock, but we hold already smp_cpu_state_mutex. Since the
locking order on cpu hotplug via arch_update_cpu_topology is inverse
this might lead to deadlocks.
So make sure locking order is always the same.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

authored by

Heiko Carstens and committed by
Martin Schwidefsky
0b18d318 f291e172

+6 -6
+6 -6
arch/s390/kernel/smp.c
··· 890 890 if (val != 0 && val != 1) 891 891 return -EINVAL; 892 892 893 - mutex_lock(&smp_cpu_state_mutex); 894 893 get_online_cpus(); 894 + mutex_lock(&smp_cpu_state_mutex); 895 895 rc = -EBUSY; 896 896 if (cpu_online(cpu)) 897 897 goto out; ··· 919 919 break; 920 920 } 921 921 out: 922 - put_online_cpus(); 923 922 mutex_unlock(&smp_cpu_state_mutex); 923 + put_online_cpus(); 924 924 return rc ? rc : count; 925 925 } 926 926 static SYSDEV_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store); ··· 1095 1095 int cpu; 1096 1096 int rc; 1097 1097 1098 - mutex_lock(&smp_cpu_state_mutex); 1099 1098 get_online_cpus(); 1099 + mutex_lock(&smp_cpu_state_mutex); 1100 1100 newcpus = cpu_present_map; 1101 1101 rc = smp_rescan_cpus(); 1102 1102 if (rc) ··· 1109 1109 } 1110 1110 rc = 0; 1111 1111 out: 1112 - put_online_cpus(); 1113 1112 mutex_unlock(&smp_cpu_state_mutex); 1113 + put_online_cpus(); 1114 1114 if (!cpus_empty(newcpus)) 1115 1115 topology_schedule_update(); 1116 1116 return rc ? rc : count; ··· 1139 1139 if (val != 0 && val != 1) 1140 1140 return -EINVAL; 1141 1141 rc = 0; 1142 - mutex_lock(&smp_cpu_state_mutex); 1143 1142 get_online_cpus(); 1143 + mutex_lock(&smp_cpu_state_mutex); 1144 1144 if (cpu_management == val) 1145 1145 goto out; 1146 1146 rc = topology_set_cpu_management(val); 1147 1147 if (!rc) 1148 1148 cpu_management = val; 1149 1149 out: 1150 - put_online_cpus(); 1151 1150 mutex_unlock(&smp_cpu_state_mutex); 1151 + put_online_cpus(); 1152 1152 return rc ? rc : count; 1153 1153 } 1154 1154 static SYSDEV_ATTR(dispatching, 0644, dispatching_show, dispatching_store);