Commit 529871bb authored by Juergen Gross's avatar Juergen Gross

xen: avoid deadlock in xenbus

When starting the xenwatch thread a theoretical 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);
    ...
    event->handle->callback();
    ...
    mutex_unlock(&xenwatch_mutex);

The callback could call unregister_xenbus_watch() which does:

    ...
    if (current->pid != xenwatch_pid)
        mutex_lock(&xenwatch_mutex);
    ...

In case a watch is firing before xenwatch_pid could be set and the
callback of that watch unregisters a watch, then a self-deadlock would
occur.

Avoid this by setting xenwatch_pid in xenwatch_thread().
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Reviewed-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
parent 4ca83dcf
...@@ -857,6 +857,8 @@ static int xenwatch_thread(void *unused) ...@@ -857,6 +857,8 @@ static int xenwatch_thread(void *unused)
struct list_head *ent; struct list_head *ent;
struct xs_watch_event *event; struct xs_watch_event *event;
xenwatch_pid = current->pid;
for (;;) { for (;;) {
wait_event_interruptible(watch_events_waitq, wait_event_interruptible(watch_events_waitq,
!list_empty(&watch_events)); !list_empty(&watch_events));
...@@ -925,7 +927,6 @@ int xs_init(void) ...@@ -925,7 +927,6 @@ int xs_init(void)
task = kthread_run(xenwatch_thread, NULL, "xenwatch"); task = kthread_run(xenwatch_thread, NULL, "xenwatch");
if (IS_ERR(task)) if (IS_ERR(task))
return PTR_ERR(task); return PTR_ERR(task);
xenwatch_pid = task->pid;
/* shutdown watches for kexec boot */ /* shutdown watches for kexec boot */
xs_reset_watches(); xs_reset_watches();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment