From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ben Guthro Subject: [PV-onHVM][linux-2.6.18-xen.hg][PATCH 1/3] Fix kthread_create Date: Thu, 06 Sep 2007 13:43:47 -0400 Message-ID: <46E03C53.2010105@virtualiron.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050203070604080300070608" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Robert Phillips List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------050203070604080300070608 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This patch fixes live migration with PV-on-HVM drivers. Without this, the kthread_create of the thread to run xen_suspend hangs forever (at least on RHEL4 64bit). The comments in the patch explain the problem in more detail. Signed-off-by: Ben Guthro Signed-off-by: Robert Phillips --------------050203070604080300070608 Content-Type: text/x-patch; name="lm-kthread.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="lm-kthread.patch" diff -r 21dbc5f5a258 drivers/xen/core/reboot.c --- a/drivers/xen/core/reboot.c Wed Jun 27 11:54:32 2007 -0400 +++ b/drivers/xen/core/reboot.c Wed Jun 27 11:54:43 2007 -0400 @@ -78,6 +78,10 @@ static int kthread_create_on_cpu(int (*f int cpu) { struct task_struct *p; + /* NB: kthread_create uses the workqueue and + * blocks until the new thread is running, + * so it will deadlock if called from the worker thread! + */ p = kthread_create(f, arg, name); if (IS_ERR(p)) return PTR_ERR(p); @@ -94,7 +98,10 @@ static void __shutdown_handler(void *unu err = kernel_thread(shutdown_process, NULL, CLONE_FS | CLONE_FILES); else - err = kthread_create_on_cpu(xen_suspend, NULL, "suspend", 0); + /* It is safe to call kernel_thread from this + * (the worker) thread. */ + err = kernel_thread(xen_suspend, NULL, + CLONE_FS | CLONE_FILES); if (err < 0) { printk(KERN_WARNING "Error creating shutdown process (%d): " @@ -138,8 +145,17 @@ static void shutdown_handler(struct xenb shutting_down = SHUTDOWN_POWEROFF; else if (strcmp(str, "reboot") == 0) ctrl_alt_del(); - else if (strcmp(str, "suspend") == 0) + else if (strcmp(str, "suspend") == 0) { shutting_down = SHUTDOWN_SUSPEND; + /* Create new thread from this (the xenwatch) thread. + * If called from worker thread, we'll deadlock. */ + err = kthread_create_on_cpu(xen_suspend, NULL, "suspend", 0); + if (err < 0) { + printk(KERN_WARNING "Error creating shutdown process (%d): " + "retrying...\n", -err); + schedule_delayed_work(&shutdown_work, HZ/2); + } + } else if (strcmp(str, "halt") == 0) shutting_down = SHUTDOWN_HALT; else { @@ -147,7 +163,8 @@ static void shutdown_handler(struct xenb shutting_down = SHUTDOWN_INVALID; } - if (shutting_down != SHUTDOWN_INVALID) + if (shutting_down != SHUTDOWN_INVALID && + shutting_down != SHUTDOWN_SUSPEND) schedule_work(&shutdown_work); kfree(str); diff -r 21dbc5f5a258 drivers/xen/xenbus/xenbus_dev.c --- a/drivers/xen/xenbus/xenbus_dev.c Wed Jun 27 11:54:32 2007 -0400 +++ b/drivers/xen/xenbus/xenbus_dev.c Wed Jun 27 11:54:35 2007 -0400 @@ -386,7 +386,7 @@ static unsigned int xenbus_dev_poll(stru return 0; } -static const struct file_operations xenbus_dev_file_ops = { +static struct file_operations xenbus_dev_file_ops = { .read = xenbus_dev_read, .write = xenbus_dev_write, .open = xenbus_dev_open, --------------050203070604080300070608 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------050203070604080300070608--