Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Feb 2023 13:48:14 -0600
From:      Mike Karels <mike@karels.net>
To:        John Baldwin <jhb@FreeBSD.org>
Cc:        Konstantin Belousov <kostikbel@gmail.com>, Mateusz Guzik <mjguzik@gmail.com>, markj@freebsd.org, src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org
Subject:   Re: git: 68912701700c - main - ffs_suspend.c: clean up includes
Message-ID:  <C4CB519A-FD0C-4B7E-A013-C37B89AA50D2@karels.net>
In-Reply-To: <8ceb993e-1589-fd24-1786-4438acb9a07f@FreeBSD.org>
References:  <202212292056.2BTKuOIu047460@gitrepo.freebsd.org> <CAGudoHEqJVvxp8-PbbrHM9=Qz=jSV8PQR8q848HJOmULiVSZzg@mail.gmail.com> <Y7QXN18gBTKDMj8j@kib.kiev.ua> <8ceb993e-1589-fd24-1786-4438acb9a07f@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 28 Feb 2023, at 12:55, John Baldwin wrote:

> On 1/3/23 3:53 AM, Konstantin Belousov wrote:
>> On Mon, Jan 02, 2023 at 06:29:57PM +0100, Mateusz Guzik wrote:
>>> On 12/29/22, Konstantin Belousov <kib@freebsd.org> wrote:
>>>> The branch main has been updated by kib:
>>>>
>>>> URL:
>>>> https://cgit.FreeBSD.org/src/commit/?id=3D68912701700ca3230f3e2d4b78=
58a038f884a327
>>>>
>>>> commit 68912701700ca3230f3e2d4b7858a038f884a327
>>>> Author:     Konstantin Belousov <kib@FreeBSD.org>
>>>> AuthorDate: 2022-12-28 18:17:53 +0000
>>>> Commit:     Konstantin Belousov <kib@FreeBSD.org>
>>>> CommitDate: 2022-12-29 20:55:39 +0000
>>>>
>>>>      ffs_suspend.c: clean up includes
>>>>
>>>>      Order includes alphabetically.
>>>>      Remove unneeded sys/param.h, it is already included by sys/syst=
m.h.
>>>>
>>>>      Reviewed by:    mckusick
>>>>      Sponsored by:   The FreeBSD Foundation
>>>>      MFC after:      1 week
>>>>      Differential revision:  https://reviews.freebsd.org/D37896
>>>> ---
>>>>   sys/ufs/ffs/ffs_suspend.c | 7 +++----
>>>>   1 file changed, 3 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/sys/ufs/ffs/ffs_suspend.c b/sys/ufs/ffs/ffs_suspend.c
>>>> index d13097109758..e7c976b6e921 100644
>>>> --- a/sys/ufs/ffs/ffs_suspend.c
>>>> +++ b/sys/ufs/ffs/ffs_suspend.c
>>>> @@ -33,15 +33,14 @@
>>>>   #include <sys/cdefs.h>
>>>>   __FBSDID("$FreeBSD$");
>>>>
>>>> -#include <sys/param.h>
>>>>   #include <sys/systm.h>
>>>>   #include <sys/buf.h>
>>>> -#include <sys/ioccom.h>
>>>> -#include <sys/mount.h>
>>>> -#include <sys/vnode.h>
>>>>   #include <sys/conf.h>
>>>> +#include <sys/ioccom.h>
>>>>   #include <sys/jail.h>
>>>> +#include <sys/mount.h>
>>>>   #include <sys/sx.h>
>>>> +#include <sys/vnode.h>
>>>>
>>>>   #include <security/mac/mac_framework.h>
>>>>
>>>>
>>>
>>> tinderbox fails the KCSAN et al kernels:
>>>
>>> In file included from /usr/src/sys/ufs/ffs/ffs_suspend.c:36:
>>> In file included from /usr/src/sys/sys/systm.h:44:
>>> In file included from ./machine/atomic.h:73:
>>> /usr/src/sys/sys/atomic_san.h:117:24: error: unknown type name 'uint8=
_t'
>>> ATOMIC_SAN_FUNCS(char, uint8_t);
>>>                         ^
>>> it bisects to this commit
>>>
>> So the problem is that sys/systm.h includes machine/atomic.h which alw=
ays
>> had the pre-requisite sys/types.h, and this is documented in atomic(9)=
=2E
>> But sys/atomic_san.h uses C89 types in prototypes, not just macros, an=
d
>> this breaks for real.
>>
>> I can
>> 1. Just add sys/types.h to ufs_suspend.c (I prefer not)
>> 2. Add sys/types.h to sys/atomic_san.h.
>> 3. Add sys/types.h to sys/systm.h.
>>
>> IMO #2 is not the best solution, since it pollutes systm.h only someti=
mes,
>> when the right kernel options are used.  I would prefer #3, it seems, =
but
>> want to ensure that there is a consensus about the addition to sys/sys=
tm.h.
>
> FYI, I got a different ream of breakages downstream in CheriBSD due to =
this
> commit removing param.h as well.  I also only ever recalled Bruce telli=
ng me
> to do either <sys/types.h> or <sys/param.h> first (and only one of them=
).
> I don't recall any special rules for <sys/systm.h>.
>
> CheriBSD has a local diff that tries to sort headers in systm.h which i=
s why
> we get larger breakage:
>
> --- a/sys/sys/systm.h
> +++ b/sys/sys/systm.h
> @@ -41,13 +41,22 @@
>  #define        _SYS_SYSTM_H_
>   #include <sys/cdefs.h>
> -#include <machine/atomic.h>
> -#include <machine/cpufunc.h>
>  #include <sys/callout.h>
>  #include <sys/kassert.h>
>  #include <sys/queue.h>
>  #include <sys/stdint.h>                /* for people using printf main=
ly */
>  +#include <machine/atomic.h>
> +#include <machine/cpufunc.h>
>
> I think if we want <sys/systm.h> to be self-contained we should swap <s=
ys/cdefs.h>
> for <sys/types.h>.  I think moving the <machine/*> includes down would =
also be
> more consistent with style(9) as well.

I prefer retaining <sys/param.h> or <sys/types.h> to be the first include=
 in kernel
files, as has long been traditional.  systm.h didn=E2=80=99t originally i=
nclude param.h,
and param.h isn=E2=80=99t anywhere near the top of systm.h.  I=E2=80=99m =
sure it was just added
to unbreak some file that didn=E2=80=99t include param.h when a dependenc=
y on MAXCPU crept
in.  It looks like 15 or more headers in sys/ include <sys/param.h>; syst=
m.h is
not really special in that regard.  Finally, style(9) documents use of ei=
ther
<sys/param.h> or <sys/types.h> first, then <sys/systm.h> if needed.

		Mike



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?C4CB519A-FD0C-4B7E-A013-C37B89AA50D2>