| 
    
 [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [linux-2.6.18-xen] avoid deadlock in xenbus
 # HG changeset patch
# User Juergen Gross <jgross@xxxxxxxx>
# Date 1504097189 -7200
#      Wed Aug 30 14:46:29 2017 +0200
# Node ID 47fd5e5ac7f7e7d56c763b4d3b7fbe456a280c91
# Parent  7d14715efcac409ac1e80b9ca8408533e07eb190
avoid deadlock in xenbus
When starting the xenwatch thread a deadlock situation is possible:
xs_init() contains:
    task = kthread_run(xenwatch_thread, NULL, "xenwatch");
    if (IS_ERR(task))
        return PTR_ERR(task);
    xenwatch_pid = task->pid;
And xenwatch_thread() does:
    mutex_lock(&xenwatch_mutex);
    ...
    xenwatch_handle_callback(msg);
    mutex_unlock(&xenwatch_mutex);
xenwatch_handle_callback() does:
    ...
    if (current->pid != xenwatch_pid)
        do_exit(0);
So xenwatch_mutex will be held for ever in case a watch event is being
handled by the xenwatch thread before xenwatch_pid has been set.
Avoid this by setting xenwatch_pid in xenwatch_thread().
Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
Committed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
diff -r 7d14715efcac -r 47fd5e5ac7f7 drivers/xen/xenbus/xenbus_xs.c
--- a/drivers/xen/xenbus/xenbus_xs.c    Tue Jun 20 14:22:21 2017 +0200
+++ b/drivers/xen/xenbus/xenbus_xs.c    Wed Aug 30 14:46:29 2017 +0200
@@ -776,6 +776,8 @@ static int xenwatch_thread(void *unused)
        struct xs_stored_msg *msg;
 
        current->flags |= PF_NOFREEZE;
+       xenwatch_pid = current->pid;
+
        for (;;) {
                wait_event_interruptible(watch_events_waitq,
                                         !list_empty(&watch_events));
@@ -944,7 +946,6 @@ int xs_init(void)
        task = kthread_run(xenwatch_thread, NULL, "xenwatch");
        if (IS_ERR(task))
                return PTR_ERR(task);
-       xenwatch_pid = task->pid;
 
        task = kthread_run(xenbus_thread, NULL, "xenbus");
        if (IS_ERR(task))
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog
  | 
  
![]()  | 
            
         Lists.xenproject.org is hosted with RackSpace, monitoring our  |