From owner-svn-src-head@freebsd.org Fri Sep 25 20:51:08 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3920C3E4AA5; Fri, 25 Sep 2020 20:51:08 +0000 (UTC) (envelope-from imp@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BykbJ0qFzz4ZJY; Fri, 25 Sep 2020 20:51:08 +0000 (UTC) (envelope-from imp@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 00DD01929D; Fri, 25 Sep 2020 20:51:08 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 08PKp7So092925; Fri, 25 Sep 2020 20:51:07 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 08PKp7ji092924; Fri, 25 Sep 2020 20:51:07 GMT (envelope-from imp@FreeBSD.org) Message-Id: <202009252051.08PKp7ji092924@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Fri, 25 Sep 2020 20:51:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366173 - head/sys/sys X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sys/sys X-SVN-Commit-Revision: 366173 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.33 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: Fri, 25 Sep 2020 20:51:08 -0000 Author: imp Date: Fri Sep 25 20:51:07 2020 New Revision: 366173 URL: https://svnweb.freebsd.org/changeset/base/366173 Log: Adjustments to includes for openzfs in _STANDALONE Allow the necessary parts of systm.h to be visible in the _STANDALONE environnment. Limit the reset to only being visible for _KERNEL builds. Map KASSERT, etc to printf on failure in the bootloader until we have more confidence things won't break and leave systems unbootable. Eventually, this should map to a full panic in the bootloader, but that also needs some enhancement to be more useful. Reviewed by: tsoome, jhb Differential Revision: https://reviews.freebsd.org/D26543 Modified: head/sys/sys/systm.h Modified: head/sys/sys/systm.h ============================================================================== --- head/sys/sys/systm.h Fri Sep 25 20:39:20 2020 (r366172) +++ head/sys/sys/systm.h Fri Sep 25 20:51:07 2020 (r366173) @@ -49,6 +49,7 @@ __NULLABILITY_PRAGMA_PUSH +#ifdef _KERNEL extern int cold; /* nonzero if we are doing a cold boot */ extern int suspend_blocked; /* block suspend due to pending shutdown */ extern int rebooting; /* kern_reboot() has been called. */ @@ -83,28 +84,7 @@ enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST VM_GUEST_VMWARE, VM_GUEST_KVM, VM_GUEST_BHYVE, VM_GUEST_VBOX, VM_GUEST_PARALLELS, VM_LAST }; -/* - * These functions need to be declared before the KASSERT macro is invoked in - * !KASSERT_PANIC_OPTIONAL builds, so their declarations are sort of out of - * place compared to other function definitions in this header. On the other - * hand, this header is a bit disorganized anyway. - */ -void panic(const char *, ...) __dead2 __printflike(1, 2); -void vpanic(const char *, __va_list) __dead2 __printflike(1, 0); - -#if defined(WITNESS) || defined(INVARIANT_SUPPORT) -#ifdef KASSERT_PANIC_OPTIONAL -void kassert_panic(const char *fmt, ...) __printflike(1, 2); -#else -#define kassert_panic panic -#endif -#endif - #ifdef INVARIANTS /* The option is always available */ -#define KASSERT(exp,msg) do { \ - if (__predict_false(!(exp))) \ - kassert_panic msg; \ -} while (0) #define VNASSERT(exp, vp, msg) do { \ if (__predict_false(!(exp))) { \ vn_printf(vp, "VNASSERT failed: %s not true at %s:%d (%s)\n",\ @@ -121,9 +101,6 @@ void kassert_panic(const char *fmt, ...) __printflike panic("executing segment marked as unreachable at %s:%d (%s)\n", \ __FILE__, __LINE__, __func__) #else -#define KASSERT(exp,msg) do { \ -} while (0) - #define VNASSERT(exp, vp, msg) do { \ } while (0) #define VNPASS(exp, vp) do { \ @@ -134,14 +111,49 @@ void kassert_panic(const char *fmt, ...) __printflike #ifndef CTASSERT /* Allow lint to override */ #define CTASSERT(x) _Static_assert(x, "compile-time assertion failed") #endif +#endif /* KERNEL */ -#if defined(_KERNEL) -#include /* MAXCPU */ -#include /* curthread */ -#include -#endif +/* + * These functions need to be declared before the KASSERT macro is invoked in + * !KASSERT_PANIC_OPTIONAL builds, so their declarations are sort of out of + * place compared to other function definitions in this header. On the other + * hand, this header is a bit disorganized anyway. + */ +void panic(const char *, ...) __dead2 __printflike(1, 2); +void vpanic(const char *, __va_list) __dead2 __printflike(1, 0); + +#if defined(_STANDALONE) /* + * Until we have more experience with KASSERTS that are called + * from the boot loader, they are off. The bootloader does this + * a little differently than the kernel (we just call printf atm). + * we avoid most of the common functions in the boot loader, so + * declare printf() here too. + */ +int printf(const char *, ...) __printflike(1, 2); +# define kassert_panic printf +#else /* !_STANDALONE */ +# if defined(WITNESS) || defined(INVARIANT_SUPPORT) +# ifdef KASSERT_PANIC_OPTIONAL +void kassert_panic(const char *fmt, ...) __printflike(1, 2); +# else +# define kassert_panic panic +# endif /* KASSERT_PANIC_OPTIONAL */ +# endif /* defined(WITNESS) || defined(INVARIANT_SUPPORT) */ +#endif /* _STANDALONE */ + +#if defined(INVARIANTS) || defined(_STANDALONE) +#define KASSERT(exp,msg) do { \ + if (__predict_false(!(exp))) \ + kassert_panic msg; \ +} while (0) +#else /* !INVARIANTS && !_STANDALONE */ +#define KASSERT(exp,msg) do { \ +} while (0) +#endif /* INVARIANTS || _STANDALONE */ + +/* * Helpful macros for quickly coming up with assertions with informative * panic messages. */ @@ -152,6 +164,18 @@ void kassert_panic(const char *fmt, ...) __printflike KASSERT((ex), ("Assertion %s failed at %s:%d", what, file, line)) /* + * Align variables. + */ +#define __read_mostly __section(".data.read_mostly") +#define __read_frequently __section(".data.read_frequently") +#define __exclusive_cache_line __aligned(CACHE_LINE_SIZE) \ + __section(".data.exclusive_cache_line") +#ifdef _KERNEL +#include /* MAXCPU */ +#include /* curthread */ +#include + +/* * Assert that a pointer can be loaded from memory atomically. * * This assertion enforces stronger alignment than necessary. For example, @@ -181,13 +205,6 @@ void kassert_panic(const char *fmt, ...) __printflike #define SCHEDULER_STOPPED() SCHEDULER_STOPPED_TD(curthread) /* - * Align variables. - */ -#define __read_mostly __section(".data.read_mostly") -#define __read_frequently __section(".data.read_frequently") -#define __exclusive_cache_line __aligned(CACHE_LINE_SIZE) \ - __section(".data.exclusive_cache_line") -/* * XXX the hints declarations are even more misplaced than most declarations * in this file, since they are needed in one file (per arch) and only used * in two files. @@ -626,6 +643,7 @@ void _gone_in_dev(struct device *dev, int major, const #endif #define gone_in(major, msg) __gone_ok(major, msg) _gone_in(major, msg) #define gone_in_dev(dev, major, msg) __gone_ok(major, msg) _gone_in_dev(dev, major, msg) +#endif /* _KERNEL */ __NULLABILITY_PRAGMA_POP