xen: avoid deadlock in xenbus
Juergen Gross
maintainerPATCH 1/1 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().
--- drivers/xen/xenbus/xenbus_xs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/xen/xenbus/xenbus_xs.c +2 -1
@@ -857,6 +857,8 @@ static int xenwatch_thread(void *unused)struct list_head *ent;struct xs_watch_event *event; + xenwatch_pid = current->pid; +for (;;) {wait_event_interruptible (watch_events_waitq, !list_empty (&watch_events));
@@ -925,7 +927,6 @@ int xs_init(void) task =kthread_run (xenwatch_thread,NULL ,"xenwatch" );if (IS_ERR (task))return PTR_ERR (task); - xenwatch_pid = task->pid;/* shutdown watches for kexec boot */ xs_reset_watches ();
Signature · 1 line
2.12.3
Quoted 25 lines · Juergen Gross
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); ...
Quoted 7 lines
In case a watch is firing before
xenwatch_pidcould be set and the callback of that watch unregisters a watch, then a self-deadlock would occur.Avoid this by setting
xenwatch_pidinxenwatch_thread().Signed-off-by Juergen Gross <[email protected]>
+stable?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 25 lines · Juergen Gross
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); ...
Quoted 7 lines
In case a watch is firing before
xenwatch_pidcould be set and the callback of that watch unregisters a watch, then a self-deadlock would occur.Avoid this by setting
xenwatch_pidinxenwatch_thread().Signed-off-by Juergen Gross <[email protected]>
+stable?
Juergen Gross
maintainerQuoted 30 lines · Boris Ostrovsky
Quoted 29 lines · Juergen Gross
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_pidcould be set and the callback of that watch unregisters a watch, then a self-deadlock would occur.
Quoted 7 lines
Quoted 3 lines
Avoid this by setting
xenwatch_pidinxenwatch_thread().Signed-off-by Juergen Gross <[email protected]>Reviewed-by Boris Ostrovsky <[email protected]>+stable?
As this problem is purely theoretical, I don't think the patch is appropriate for stable (at least the stable rules tell me so).
Juergen
Juergen Gross
maintainerQuoted 30 lines · Boris Ostrovsky
Quoted 29 lines · Juergen Gross
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_pidcould be set and the callback of that watch unregisters a watch, then a self-deadlock would occur.
Quoted 7 lines
Quoted 3 lines
Avoid this by setting
xenwatch_pidinxenwatch_thread().Signed-off-by Juergen Gross <[email protected]>Reviewed-by Boris Ostrovsky <[email protected]>+stable?
As this problem is purely theoretical, I don't think the patch is appropriate for stable (at least the stable rules tell me so).
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel