From owner-svn-src-head@freebsd.org Thu Mar 22 20:47:26 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D38F8F6A663; Thu, 22 Mar 2018 20:47:25 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 774996AC32; Thu, 22 Mar 2018 20:47:25 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 70A9916437; Thu, 22 Mar 2018 20:47:25 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w2MKlPHj004000; Thu, 22 Mar 2018 20:47:25 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2MKlPrQ003999; Thu, 22 Mar 2018 20:47:25 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201803222047.w2MKlPrQ003999@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 22 Mar 2018 20:47:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r331375 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 331375 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Mar 2018 20:47:26 -0000 Author: kib Date: Thu Mar 22 20:47:25 2018 New Revision: 331375 URL: https://svnweb.freebsd.org/changeset/base/331375 Log: Do not send signals to init directly from shutdown_nice(9), do it from the task context. shutdown_nice() is used from the fast interrupt handlers, mostly for console drivers, where we cannot lock blockable locks. Schedule the task in the fast queue to send the signal from the proper context. Reviewed by: imp Discussed with: bde Sponsored by: The FreeBSD Foundation MFC after: 1 week Modified: head/sys/kern/kern_shutdown.c Modified: head/sys/kern/kern_shutdown.c ============================================================================== --- head/sys/kern/kern_shutdown.c Thu Mar 22 20:44:27 2018 (r331374) +++ head/sys/kern/kern_shutdown.c Thu Mar 22 20:47:25 2018 (r331375) @@ -72,6 +72,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -276,6 +277,28 @@ sys_reboot(struct thread *td, struct reboot_args *uap) return (error); } +static void +shutdown_nice_task_fn(void *arg, int pending __unused) +{ + int howto; + + howto = (uintptr_t)arg; + /* Send a signal to init(8) and have it shutdown the world. */ + PROC_LOCK(initproc); + if (howto & RB_POWEROFF) + kern_psignal(initproc, SIGUSR2); + else if (howto & RB_POWERCYCLE) + kern_psignal(initproc, SIGWINCH); + else if (howto & RB_HALT) + kern_psignal(initproc, SIGUSR1); + else + kern_psignal(initproc, SIGINT); + PROC_UNLOCK(initproc); +} + +static struct task shutdown_nice_task = TASK_INITIALIZER(0, + &shutdown_nice_task_fn, NULL); + /* * Called by events that want to shut down.. e.g on a PC */ @@ -283,20 +306,14 @@ void shutdown_nice(int howto) { - if (initproc != NULL) { - /* Send a signal to init(8) and have it shutdown the world. */ - PROC_LOCK(initproc); - if (howto & RB_POWEROFF) - kern_psignal(initproc, SIGUSR2); - else if (howto & RB_POWERCYCLE) - kern_psignal(initproc, SIGWINCH); - else if (howto & RB_HALT) - kern_psignal(initproc, SIGUSR1); - else - kern_psignal(initproc, SIGINT); - PROC_UNLOCK(initproc); + if (initproc != NULL && !SCHEDULER_STOPPED()) { + shutdown_nice_task.ta_context = (void *)(uintptr_t)howto; + taskqueue_enqueue(taskqueue_fast, &shutdown_nice_task); } else { - /* No init(8) running, so simply reboot. */ + /* + * No init(8) running, or scheduler would not allow it + * to run, so simply reboot. + */ kern_reboot(howto | RB_NOSYNC); } }