powerpc/pseries: Serialize cpu hotplug operations during deactivate Vs deallocate
authorGautham R Shenoy <ego@in.ibm.com>
Thu, 26 Nov 2009 09:59:05 +0000 (09:59 +0000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Wed, 9 Dec 2009 06:09:36 +0000 (17:09 +1100)
Currently the cpu-allocation/deallocation process comprises of two steps:
- Set the indicators and to update the device tree with DLPAR node
  information.

- Online/offline the allocated/deallocated CPU.

This is achieved by writing to the sysfs tunables "probe" during allocation
and "release" during deallocation.

At the sametime, the userspace can independently online/offline the CPUs of
the system using the sysfs tunable "online".

It is quite possible that when a userspace tool offlines a CPU
for the purpose of deallocation and is in the process of updating the device
tree, some other userspace tool could bring the CPU back online by writing to
the "online" sysfs tunable thereby causing the deallocate process to fail.

The solution to this is to serialize writes to the "probe/release" sysfs
tunable with the writes to the "online" sysfs tunable.

This patch employs a mutex to provide this serialization, which is a no-op on
all architectures except PPC_PSERIES

Signed-off-by: Gautham R Shenoy <ego@in.ibm.com>
Acked-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/platforms/pseries/dlpar.c
drivers/base/cpu.c
include/linux/cpu.h

index 642e1b2e5c4246ddb01c6a0113506e855a5b5206..fd2f0afeb4de9ad46a070401fcf694315eaf20e8 100644 (file)
@@ -436,6 +436,18 @@ int dlpar_release_drc(u32 drc_index)
 
 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
 
+static DEFINE_MUTEX(pseries_cpu_hotplug_mutex);
+
+void cpu_hotplug_driver_lock()
+{
+       mutex_lock(&pseries_cpu_hotplug_mutex);
+}
+
+void cpu_hotplug_driver_unlock()
+{
+       mutex_unlock(&pseries_cpu_hotplug_mutex);
+}
+
 static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
 {
        struct device_node *dn;
@@ -443,13 +455,18 @@ static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
        char *cpu_name;
        int rc;
 
+       cpu_hotplug_driver_lock();
        rc = strict_strtoul(buf, 0, &drc_index);
-       if (rc)
-               return -EINVAL;
+       if (rc) {
+               rc = -EINVAL;
+               goto out;
+       }
 
        dn = dlpar_configure_connector(drc_index);
-       if (!dn)
-               return -EINVAL;
+       if (!dn) {
+               rc = -EINVAL;
+               goto out;
+       }
 
        /* configure-connector reports cpus as living in the base
         * directory of the device tree.  CPUs actually live in the
@@ -459,7 +476,8 @@ static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
                           GFP_KERNEL);
        if (!cpu_name) {
                dlpar_free_cc_nodes(dn);
-               return -ENOMEM;
+               rc = -ENOMEM;
+               goto out;
        }
 
        sprintf(cpu_name, "/cpus%s", dn->full_name);
@@ -469,7 +487,8 @@ static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
        rc = dlpar_acquire_drc(drc_index);
        if (rc) {
                dlpar_free_cc_nodes(dn);
-               return -EINVAL;
+               rc = -EINVAL;
+               goto out;
        }
 
        rc = dlpar_attach_node(dn);
@@ -479,6 +498,8 @@ static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
        }
 
        rc = online_node_cpus(dn);
+out:
+       cpu_hotplug_driver_unlock();
 
        return rc ? rc : count;
 }
@@ -499,26 +520,30 @@ static ssize_t dlpar_cpu_release(const char *buf, size_t count)
                return -EINVAL;
        }
 
+       cpu_hotplug_driver_lock();
        rc = offline_node_cpus(dn);
        if (rc) {
                of_node_put(dn);
-               return -EINVAL;
+               rc = -EINVAL;
+               goto out;
        }
 
        rc = dlpar_release_drc(*drc_index);
        if (rc) {
                of_node_put(dn);
-               return -EINVAL;
+               goto out;
        }
 
        rc = dlpar_detach_node(dn);
        if (rc) {
                dlpar_acquire_drc(*drc_index);
-               return rc;
+               goto out;
        }
 
        of_node_put(dn);
-       return count;
+out:
+       cpu_hotplug_driver_unlock();
+       return rc ? rc : count;
 }
 
 static int __init pseries_dlpar_init(void)
index 7c03af7b84a93c8822a8d75ef02c9cd5b0f3993f..27fd775375b04965b834d7817db43efa059a2c97 100644 (file)
@@ -35,6 +35,7 @@ static ssize_t __ref store_online(struct sys_device *dev, struct sysdev_attribut
        struct cpu *cpu = container_of(dev, struct cpu, sysdev);
        ssize_t ret;
 
+       cpu_hotplug_driver_lock();
        switch (buf[0]) {
        case '0':
                ret = cpu_down(cpu->sysdev.id);
@@ -49,6 +50,7 @@ static ssize_t __ref store_online(struct sys_device *dev, struct sysdev_attribut
        default:
                ret = -EINVAL;
        }
+       cpu_hotplug_driver_unlock();
 
        if (ret >= 0)
                ret = count;
index c972f7ccb7d35a9f487c8c642c6dcf84ef5de51a..e287863ac053d9788756ac79c9271ba562d455b1 100644 (file)
@@ -117,6 +117,19 @@ extern void put_online_cpus(void);
 #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
 int cpu_down(unsigned int cpu);
 
+#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
+extern void cpu_hotplug_driver_lock(void);
+extern void cpu_hotplug_driver_unlock(void);
+#else
+static inline void cpu_hotplug_driver_lock(void)
+{
+}
+
+static inline void cpu_hotplug_driver_unlock(void)
+{
+}
+#endif
+
 #else          /* CONFIG_HOTPLUG_CPU */
 
 #define get_online_cpus()      do { } while (0)