From f0d847af61b5f8dd8c596d15ab2eaeca032806c0 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Thu, 22 Mar 2018 15:34:37 +0000 Subject: [PATCH] Drop any recursed taking of Giant once and for all at the top of kern_reboot(). The shutdown path is now safe to run without Giant. Discussed with: kib@ Sponsored by: Netflix --- sys/kern/kern_shutdown.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index e5ea9644ad3f..e64e1dd39b62 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -366,6 +366,17 @@ kern_reboot(int howto) { static int once = 0; + /* + * Normal paths here don't hold Giant, but we can wind up here + * unexpectedly with it held. Drop it now so we don't have to + * drop and pick it up elsewhere. The paths it is locking will + * never be returned to, and it is preferable to preclude + * deadlock than to lock against code that won't ever + * continue. + */ + while (mtx_owned(&Giant)) + mtx_unlock(&Giant); + #if defined(SMP) /* * Bind us to the first CPU so that all shutdown code runs there. Some