From 41716b8d5151d2bec72b6796ed58b6206cdb4779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Tue, 7 Mar 2017 09:17:48 +0000 Subject: [PATCH] xenstore: fix suspension when using the xenstore device Lock the xenstore request mutex when suspending user-space processes, in order to prevent any process from holding this lock when going into suspension, or else the xenstore suspend process is going to deadlock. Submitted by: Liuyingdong Reviewed by: royger MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D9638 --- sys/dev/xen/control/control.c | 2 ++ sys/dev/xen/xenstore/xenstore.c | 17 +++++++++++++++++ sys/xen/xenstore/xenstorevar.h | 11 +++++++++++ 3 files changed, 30 insertions(+) diff --git a/sys/dev/xen/control/control.c b/sys/dev/xen/control/control.c index d4249886332b..d5aa97e03b73 100644 --- a/sys/dev/xen/control/control.c +++ b/sys/dev/xen/control/control.c @@ -199,7 +199,9 @@ xctrl_suspend() #endif EVENTHANDLER_INVOKE(power_suspend_early); + xs_lock(); stop_all_proc(); + xs_unlock(); EVENTHANDLER_INVOKE(power_suspend); #ifdef EARLY_AP_STARTUP diff --git a/sys/dev/xen/xenstore/xenstore.c b/sys/dev/xen/xenstore/xenstore.c index 4f89b7457d0e..9289adfc1a79 100644 --- a/sys/dev/xen/xenstore/xenstore.c +++ b/sys/dev/xen/xenstore/xenstore.c @@ -1699,3 +1699,20 @@ xs_unregister_watch(struct xs_watch *watch) sx_xunlock(&xs.xenwatch_mutex); } } + +void +xs_lock(void) +{ + + sx_xlock(&xs.request_mutex); + return; +} + +void +xs_unlock(void) +{ + + sx_xunlock(&xs.request_mutex); + return; +} + diff --git a/sys/xen/xenstore/xenstorevar.h b/sys/xen/xenstore/xenstorevar.h index 208e5bf09b8e..4c612b4b6881 100644 --- a/sys/xen/xenstore/xenstorevar.h +++ b/sys/xen/xenstore/xenstorevar.h @@ -338,4 +338,15 @@ void xs_unregister_watch(struct xs_watch *watch); */ struct sbuf *xs_join(const char *, const char *); +/** + * Lock the xenstore request mutex. + */ +void xs_lock(void); + +/** + * Unlock the xenstore request mutex. + */ +void xs_unlock(void); + #endif /* _XEN_XENSTORE_XENSTOREVAR_H */ +