]> xenbits.xensource.com Git - legacy/linux-2.6.18-xen.git/commitdiff
Fix access to xenstore hangs after hot-remove CPU.
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 4 Dec 2007 10:02:30 +0000 (10:02 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 4 Dec 2007 10:02:30 +0000 (10:02 +0000)
CPU hotplug doesn't support user-space event channels.

$ echo 0 > /sys/devices/system/cpu/cpu1/online
$ xenstore-ls
... hangs up ...

Signed-off-by: Kouya Shimura <kouya@jp.fujitsu.com>
drivers/xen/evtchn/evtchn.c

index bedf3f0699b032c1a959c36492174bd9fdf4e407..0510f0071bec18280365c29fa23cd954c32a38fc 100644 (file)
@@ -48,6 +48,7 @@
 #include <linux/init.h>
 #include <linux/gfp.h>
 #include <linux/mutex.h>
+#include <linux/cpu.h>
 #include <xen/evtchn.h>
 #include <xen/public/evtchn.h>
 
@@ -231,6 +232,15 @@ static ssize_t evtchn_write(struct file *file, const char __user *buf,
        return rc;
 }
 
+static unsigned int next_bind_cpu(cpumask_t map)
+{
+       static unsigned int bind_cpu;
+       bind_cpu = next_cpu(bind_cpu, map);
+       if (bind_cpu >= NR_CPUS)
+               bind_cpu = first_cpu(map);
+       return bind_cpu;
+}
+
 static void evtchn_bind_to_user(struct per_user_data *u, int port)
 {
        spin_lock_irq(&port_user_lock);
@@ -238,13 +248,8 @@ static void evtchn_bind_to_user(struct per_user_data *u, int port)
        BUG_ON(port_user[port] != NULL);
        port_user[port] = u;
 
-       if (u->bind_cpu == -1) {
-               static unsigned int bind_cpu;
-               bind_cpu = next_cpu(bind_cpu, cpu_online_map);
-               if (bind_cpu >= NR_CPUS)
-                       bind_cpu = first_cpu(cpu_online_map);
-               u->bind_cpu = bind_cpu;
-       }
+       if (u->bind_cpu == -1)
+               u->bind_cpu = next_bind_cpu(cpu_online_map);
 
        rebind_evtchn_to_cpu(port, u->bind_cpu);
 
@@ -483,6 +488,38 @@ static struct miscdevice evtchn_miscdev = {
        .fops         = &evtchn_fops,
 };
 
+static int __cpuinit evtchn_cpu_notify(struct notifier_block *nfb,
+                       unsigned long action, void *hcpu)
+{
+       int hotcpu = (unsigned long)hcpu;
+       cpumask_t map = cpu_online_map;
+       int port, newcpu;
+       struct per_user_data *u;
+
+       switch (action) {
+       case CPU_DOWN_PREPARE:
+               cpu_clear(hotcpu, map);
+               spin_lock_irq(&port_user_lock);
+               for (port = 0; port < NR_EVENT_CHANNELS; port++) {
+                       if ((u = port_user[port]) != NULL && 
+                           u->bind_cpu == hotcpu &&
+                           (newcpu = next_bind_cpu(map)) < NR_CPUS) {
+                               rebind_evtchn_to_cpu(port, newcpu);
+                               u->bind_cpu = newcpu;
+                       }
+               }
+               spin_unlock_irq(&port_user_lock);
+               break;
+       default:
+               return NOTIFY_DONE;
+       }
+       return NOTIFY_OK;
+}
+
+static struct notifier_block __cpuinitdata evtchn_cpu_nfb = {
+       .notifier_call = evtchn_cpu_notify
+};
+
 static int __init evtchn_init(void)
 {
        int err;
@@ -500,6 +537,8 @@ static int __init evtchn_init(void)
                return err;
        }
 
+       register_cpu_notifier(&evtchn_cpu_nfb);
+
        printk("Event-channel device installed.\n");
 
        return 0;
@@ -508,6 +547,7 @@ static int __init evtchn_init(void)
 static void evtchn_cleanup(void)
 {
        misc_deregister(&evtchn_miscdev);
+       unregister_cpu_notifier(&evtchn_cpu_nfb);
 }
 
 module_init(evtchn_init);