From nobody Thu Nov 23 16:07:56 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Sbjgx1zrpz51nZB; Thu, 23 Nov 2023 16:07:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Sbjgw6vzRz4PyV; Thu, 23 Nov 2023 16:07:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700755677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cGP6WRiDs04MiV+szh1/oufXXB8h3ERmw3iqIGndEmM=; b=Fk2ulx8y2xvfoOjuS/nYoZpFYhMTW+2ouxikZ9ZI6pzUFDesFFXyh9tWVFCZpgM6PQse7d dkKo8ru5j/xaTvIdfu24aFKsVIqRjcTJoevnsALNa4tbSuRAzE1QkXJq05DaG8IUlMuoZB XSnmQiQV7Qy1B27/kqINp/JxjOqmIvGYxbWPx+GtYbLO6PPNbxigcGChE4VTiClNgcfLFG vf5MiNy/Pn+YOxssrsCcOvEBJjGHf7IWixq1Q0aokkSIsl54ItqbQAmrQIdg9s8g1Sxmtv pJpywUDr1wt/DXB5D+K/Ie8850ZeJWE/vd97Ra0NYutp2DbGh0KDJnd8x/HW3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700755677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cGP6WRiDs04MiV+szh1/oufXXB8h3ERmw3iqIGndEmM=; b=wrc1sAJQ9+eQwsD1KR/xUwg5VznJSh7XmFaes5nY9+3M0uUVxkzZb/cmat0hdKYmKrtHkU DDN6qXAHU2Ktyjk1VpeDFZYGU53/oNbk+DXPdF1fern1DaoKZO+WYDw86A6RzedekAyoDh UPNY9ig2KE3/2vzgIAuRlEuWtZB4UGpmTs5Xi8Vg8RiyQ93/LjOz6o8/CpLFcUltIKkDsw l6ha+cCTQL8lSHsG2LxBYYVW3dSA2E4BHfTpRjbGFweeA4o0iS6Gx257RYQ1oIkSKEU+Op 5boiILMy5ENieLTNKKT5GrnuhwabMltKKL2vDuVwTKuZ6KBVHtRLXsSdcS1rag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700755677; a=rsa-sha256; cv=none; b=XOYg+uBJsZPRtXr+PZaez5YoY3Neaq3g3nF7bCTUbSNtid0QH+yFgDmgRCBRR6ufQL/H90 c3Lz9GvkxxIydvF9M8tbYm6oNKw4Vt+kQpSf32BjF2MmQk2GB1yPAR4bftRZEOGTnqJx8B gk67KUQ5neQD8wu6YdsJ6DKGDOstp2/fuuJUam5MXWkxzNJOyY4biVsN5QvKIL0ilW+j5R W2/ZOFc27l6TOTjqHQBHFDB3vr9v8b/eGg3CkYi4+ptWiPEUlt10jTrFlgCQHQJlTk5qw/ 4UnQnQxxzsdcqhttvcOnEll1JCEH0zVqCiIgN1ZBzy9IdNqXJKNkiqSOHgdW0A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Sbjgw61BLz17hJ; Thu, 23 Nov 2023 16:07:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3ANG7u7o007392; Thu, 23 Nov 2023 16:07:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3ANG7u3q007389; Thu, 23 Nov 2023 16:07:56 GMT (envelope-from git) Date: Thu, 23 Nov 2023 16:07:56 GMT Message-Id: <202311231607.3ANG7u3q007389@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 4eb861d362d6 - main - shutdown: audit shutdown_post_sync event callbacks List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4eb861d362d6a9493df7f77eab8e28f9c826702a Auto-Submitted: auto-generated The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=4eb861d362d6a9493df7f77eab8e28f9c826702a commit 4eb861d362d6a9493df7f77eab8e28f9c826702a Author: Mitchell Horne AuthorDate: 2023-11-23 15:58:27 +0000 Commit: Mitchell Horne CommitDate: 2023-11-23 16:07:42 +0000 shutdown: audit shutdown_post_sync event callbacks Ensure they are all panic/debugger safe. Most handlers for this event are for disk drivers/geom modules. There are a mix of checks being used here (or not), so let's standardize on checking the presence of the RB_NOSYNC flag. This flag is set whenever: 1. The kernel has panicked and kern.sync_on_panic=0* 2. We reboot from within the kernel debugger (the "reset" command) 3. Userspace requested it, e.g. by 'reboot -n' Name the functions consistently. *This sysctl is tuned to zero by default, but its existence means that these handlers can be executed after a panic, at the user's discretion. IMO this use-case is implicitly understood to be risky, and we'd be better off eliminating it altogether. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D42337 --- sys/dev/iscsi/iscsi.c | 8 +++++--- sys/geom/journal/g_journal.c | 8 +++++--- sys/geom/mirror/g_mirror.c | 3 ++- sys/geom/raid/g_raid.c | 4 ++++ sys/geom/raid3/g_raid3.c | 4 ++++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/sys/dev/iscsi/iscsi.c b/sys/dev/iscsi/iscsi.c index ecf4fe21a165..311b339caf7a 100644 --- a/sys/dev/iscsi/iscsi.c +++ b/sys/dev/iscsi/iscsi.c @@ -44,11 +44,13 @@ #include #include #include +#include #include #include #include #include #include + #include #include @@ -2711,10 +2713,10 @@ iscsi_shutdown_pre(struct iscsi_softc *sc) } static void -iscsi_shutdown_post(struct iscsi_softc *sc) +iscsi_shutdown_post_sync(struct iscsi_softc *sc, int howto) { - if (!KERNEL_PANICKED()) { + if ((howto & RB_NOSYNC) == 0) { ISCSI_DEBUG("removing all sessions due to shutdown"); iscsi_terminate_sessions(sc); } @@ -2751,7 +2753,7 @@ iscsi_load(void) * cam_periph_runccb(). */ sc->sc_shutdown_post_eh = EVENTHANDLER_REGISTER(shutdown_post_sync, - iscsi_shutdown_post, sc, SHUTDOWN_PRI_DEFAULT - 1); + iscsi_shutdown_post_sync, sc, SHUTDOWN_PRI_DEFAULT - 1); return (0); } diff --git a/sys/geom/journal/g_journal.c b/sys/geom/journal/g_journal.c index 147e83cc7e21..11a75e541fda 100644 --- a/sys/geom/journal/g_journal.c +++ b/sys/geom/journal/g_journal.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -2655,13 +2656,14 @@ static eventhandler_tag g_journal_event_shutdown = NULL; static eventhandler_tag g_journal_event_lowmem = NULL; static void -g_journal_shutdown(void *arg, int howto __unused) +g_journal_shutdown_post_sync(void *arg, int howto) { struct g_class *mp; struct g_geom *gp, *gp2; - if (KERNEL_PANICKED()) + if ((howto & RB_NOSYNC) != 0) return; + mp = arg; g_topology_lock(); LIST_FOREACH_SAFE(gp, &mp->geom, geom, gp2) { @@ -2738,7 +2740,7 @@ g_journal_init(struct g_class *mp) (g_journal_cache_limit / 100) * g_journal_cache_switch; } g_journal_event_shutdown = EVENTHANDLER_REGISTER(shutdown_post_sync, - g_journal_shutdown, mp, EVENTHANDLER_PRI_FIRST); + g_journal_shutdown_post_sync, mp, EVENTHANDLER_PRI_FIRST); if (g_journal_event_shutdown == NULL) GJ_DEBUG(0, "Warning! Cannot register shutdown event."); g_journal_event_lowmem = EVENTHANDLER_REGISTER(vm_lowmem, diff --git a/sys/geom/mirror/g_mirror.c b/sys/geom/mirror/g_mirror.c index b2bcea2f0dbb..c6f95f28ba89 100644 --- a/sys/geom/mirror/g_mirror.c +++ b/sys/geom/mirror/g_mirror.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -3546,7 +3547,7 @@ g_mirror_shutdown_post_sync(void *arg, int howto) struct g_mirror_softc *sc; int error; - if (KERNEL_PANICKED()) + if ((howto & RB_NOSYNC) != 0) return; mp = arg; diff --git a/sys/geom/raid/g_raid.c b/sys/geom/raid/g_raid.c index 437cef416ca3..6938491d696c 100644 --- a/sys/geom/raid/g_raid.c +++ b/sys/geom/raid/g_raid.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -2457,6 +2458,9 @@ g_raid_shutdown_post_sync(void *arg, int howto) struct g_raid_softc *sc; struct g_raid_volume *vol; + if ((howto & RB_NOSYNC) != 0) + return; + mp = arg; g_topology_lock(); g_raid_shutdown = 1; diff --git a/sys/geom/raid3/g_raid3.c b/sys/geom/raid3/g_raid3.c index 8f12f14cf09b..721610cefbec 100644 --- a/sys/geom/raid3/g_raid3.c +++ b/sys/geom/raid3/g_raid3.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -3573,6 +3574,9 @@ g_raid3_shutdown_post_sync(void *arg, int howto) struct g_raid3_softc *sc; int error; + if ((howto & RB_NOSYNC) != 0) + return; + mp = arg; g_topology_lock(); g_raid3_shutdown = 1;