* [PATCH net-next] stddef: don't include compiler_types.h in the uAPI header
@ 2025-08-18 18:18 Jakub Kicinski
2025-08-19 4:06 ` Kees Cook
2025-08-19 9:26 ` kernel test robot
0 siblings, 2 replies; 6+ messages in thread
From: Jakub Kicinski @ 2025-08-18 18:18 UTC (permalink / raw)
To: davem
Cc: netdev, edumazet, pabeni, andrew+netdev, horms, Jakub Kicinski,
dhowells, kees, gustavoars, aleksander.lobakin, tstruk
The uAPI stddef header includes compiler_types.h, a non-uAPI
header. There is a hack in scripts/headers_install.sh which
strips includes of compiler.h and compiler_types.h.
But AFAICT there is nothing in stddef.h which would need
the include. The include dates back to when uAPI stddef.h
was first created, back then the including of compiler.h
was the only line in the file. So presumably stddef.h
has been including compiler headers to retain some
chain of dependency? Perhaps someone with more build system
understanding knows what that chain would be, given
kernel doesn't include uAPI stddef.h, and user space
has the compiler headers stripped.
Since nothing needs this include, let's remove it.
Builds pass on x86, arm64, csky, m68k, riscv32.
The direct motivation for the change is that the includes
of compiler.h and co. make it hard to include uAPI headers
from tools/.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
More than happy for someone else to take this via their tree, FWIW.
CC: dhowells@redhat.com
CC: kees@kernel.org
CC: gustavoars@kernel.org
CC: aleksander.lobakin@intel.com
CC: tstruk@gigaio.com
---
include/uapi/linux/stddef.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/include/uapi/linux/stddef.h b/include/uapi/linux/stddef.h
index b87df1b485c2..3da0266643e6 100644
--- a/include/uapi/linux/stddef.h
+++ b/include/uapi/linux/stddef.h
@@ -2,8 +2,6 @@
#ifndef _UAPI_LINUX_STDDEF_H
#define _UAPI_LINUX_STDDEF_H
-#include <linux/compiler_types.h>
-
#ifndef __always_inline
#define __always_inline inline
#endif
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] stddef: don't include compiler_types.h in the uAPI header
2025-08-18 18:18 [PATCH net-next] stddef: don't include compiler_types.h in the uAPI header Jakub Kicinski
@ 2025-08-19 4:06 ` Kees Cook
2025-08-20 17:17 ` Jakub Kicinski
2025-08-19 9:26 ` kernel test robot
1 sibling, 1 reply; 6+ messages in thread
From: Kees Cook @ 2025-08-19 4:06 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, dhowells,
gustavoars, aleksander.lobakin, tstruk
On Mon, Aug 18, 2025 at 11:18:48AM -0700, Jakub Kicinski wrote:
> [...]
> header. There is a hack in scripts/headers_install.sh which
> strips includes of compiler.h and compiler_types.h.
This looks like the last user of compiler_types.h in include/uapi, so
it'd probably be best to also remove portion of the hack from
scripts/headers_install.sh while you're at it.
> [...]
> understanding knows what that chain would be, given
> kernel doesn't include uAPI stddef.h, and user space
> has the compiler headers stripped.
Uh, yes it does:
$ git grep uapi/linux/stddef.h
include/linux/stddef.h:#include <uapi/linux/stddef.h>
> [...]
> Since nothing needs this include, let's remove it.
But yes, nothing uses compiler_types.h via uapi/linux/stddef.h. That
does seem to be true.
I find the change of subject between stddef.h ("nothing includes the
uapi header") and compiler_types.h ("nothing needs this include") to be
confusing in the commit log. :)
> [...]
> Builds pass on x86, arm64, csky, m68k, riscv32.
> The direct motivation for the change is that the includes
> of compiler.h and co. make it hard to include uAPI headers
> from tools/.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
If you can clear that up and everything is building, then this change
would be fine my me.
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] stddef: don't include compiler_types.h in the uAPI header
2025-08-18 18:18 [PATCH net-next] stddef: don't include compiler_types.h in the uAPI header Jakub Kicinski
2025-08-19 4:06 ` Kees Cook
@ 2025-08-19 9:26 ` kernel test robot
1 sibling, 0 replies; 6+ messages in thread
From: kernel test robot @ 2025-08-19 9:26 UTC (permalink / raw)
To: Jakub Kicinski, davem
Cc: llvm, oe-kbuild-all, netdev, edumazet, pabeni, andrew+netdev,
horms, Jakub Kicinski, dhowells, kees, gustavoars,
aleksander.lobakin, tstruk
Hi Jakub,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Jakub-Kicinski/stddef-don-t-include-compiler_types-h-in-the-uAPI-header/20250819-022023
base: net-next/main
patch link: https://lore.kernel.org/r/20250818181848.799566-1-kuba%40kernel.org
patch subject: [PATCH net-next] stddef: don't include compiler_types.h in the uAPI header
config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20250819/202508191741.O5OYysnF-lkp@intel.com/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250819/202508191741.O5OYysnF-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508191741.O5OYysnF-lkp@intel.com/
All error/warnings (new ones prefixed by >>):
In file included from <built-in>:3:
In file included from lib/vdso/gettimeofday.c:5:
In file included from include/vdso/auxclock.h:5:
In file included from include/uapi/linux/time.h:5:
>> include/linux/types.h:265:21: error: field has incomplete type 'struct task_struct'
265 | struct task_struct __rcu *task;
| ^
include/linux/types.h:265:9: note: forward declaration of 'struct task_struct'
265 | struct task_struct __rcu *task;
| ^
>> include/linux/types.h:265:26: error: expected ';' at end of declaration list
265 | struct task_struct __rcu *task;
| ^
| ;
In file included from <built-in>:3:
In file included from lib/vdso/gettimeofday.c:6:
In file included from include/vdso/datapage.h:7:
In file included from include/linux/compiler.h:5:
In file included from include/linux/compiler_types.h:89:
>> include/linux/compiler_attributes.h:55:9: warning: '__always_inline' macro redefined [-Wmacro-redefined]
55 | #define __always_inline inline __attribute__((__In file included from arch/arm64/kernel/vdso32/note.c:11:
In file included from include/linux/elfnote.h:62:
In file included from include/uapi/linux/elf.h:5:
>> include/linux/types.h:265:21: error: field has incomplete type 'struct task_struct'
alw ays_inline__))
| ^
include/uapi/linux/stddef.h:6:9: note: previous definition is here
6 | #define __always_inline inline
| ^
265 | struct task_struct __rcu *task;
| ^
In file included from <built-in>:3:
In file included from lib/vdso/gettimeofday.c:6:
In file included from include/vdso/datapage.h:7:
In file included from include/linux/compiler.h:5:
>> include/linux/compiler_types.h:346:10: warning: '__counted_by' macro redefined [-Wmacro-redefined]
346 | # define __counted_by(member) __attribute__((__counted_by__(member)))
| ^
include/uapi/linux/stddef.h:60:9: note: previous definition is here
60 | #define __counted_by(m)
| ^
In file included from include/linux/types.h:265:9: note: forward declaration of 'struct task_struct'
265 | struct task_struct __rcu *task;
| ^
<built-in>:3:
In file included from lib/vdso/gettimeofday.c:6:
In file included from include/vdso/datapage.h:7:
In file included from include/linux/compiler.h:5:
>> include/linux/compiler_types.h:367include/linux/types.h:265:26: error: expected ';' at end of declaration list
: 265 | struct task_struct __rcu *task;
| ^
| ;
9: warning: '__counted_by_le' macro redefined [-Wmacro-redefined]
367 | #define __counted_by_le(member) __counted_by(member)
| ^
include/uapi/linux/stddef.h:64:9: note: previous definition is here
64 | #define __counted_by_le(m)
| ^
In file included from <built-in>:3:
In file included from lib/vdso/gettimeofday.c:6:
In file included from include/vdso/datapage.h:7:
In file included from include/linux/compiler.h:5:
>> include/linux/compiler_types.h:368:9: warning: '__counted_by_be' macro redefined [-Wmacro-redefined]
368 | #define __counted_by_be(member)
| ^
include/uapi/linux/stddef.h:68:9: note: previous definition is here
68 | #define __counted_by_be(m)
| ^
>> error: expected ';' after struct
>> arch/arm64/kernel/vdso32/note.c:14:1: error: unknown type name '_note_14'
14 | ELFNOTE32("Linux", 0, LINUX_VERSION_CODE);
| ^
include/linux/elfnote.h:95:37: note: expanded from macro 'ELFNOTE32'
95 | #define ELFNOTE32(name, type, desc) ELFNOTE(32, name, type, desc)
| ^
include/linux/elfnote.h:93:2: note: expanded from macro 'ELFNOTE'
93 | _ELFNOTE(size, name, __LINE__, type, desc)
| ^
include/linux/elfnote.h:79:4: note: expanded from macro '_ELFNOTE'
79 | } _ELFNOTE_PASTE(_note_, unique) \
| ^
include/linux/elfnote.h:71:29: note: expanded from macro '_ELFNOTE_PASTE'
71 | #define _ELFNOTE_PASTE(a,b) a##b
| ^
<scratch space>:11:1: note: expanded from here
11 | _note_14
| ^
>> error: expected ';' after struct
>> arch/arm64/kernel/vdso32/note.c:15:1: error: unknown type name '_note_15'
15 | BUILD_SALT;
| ^
include/linux/build-salt.h:16:8: note: expanded from macro 'BUILD_SALT'
16 | ELFNOTE32("Linux", LINUX_ELFNOTE_BUILD_SALT, CONFIG_BUILD_SALT)
| ^
include/linux/elfnote.h:95:37: note: expanded from macro 'ELFNOTE32'
95 | #define ELFNOTE32(name, type, desc) ELFNOTE(32, name, type, desc)
| ^
include/linux/elfnote.h:93:2: note: expanded from macro 'ELFNOTE'
93 | _ELFNOTE(size, name, __LINE__, type, desc)
| ^
include/linux/elfnote.h:79:4: note: expanded from macro '_ELFNOTE'
79 | } _ELFNOTE_PASTE(_note_, unique) \
| ^
include/linux/elfnote.h:71:29: note: expanded from macro '_ELFNOTE_PASTE'
71 | #define _ELFNOTE_PASTE(a,b) a##b
| ^
<scratch space>:21:1: note: expanded from here
21 | _note_15
| ^
6 errors generated.
make[3]: *** [arch/arm64/kernel/vdso32/Makefile:144: arch/arm64/kernel/vdso32/note.o] Error 1
4 warnings and 2 errors generated.
make[3]: *** [arch/arm64/kernel/vdso32/Makefile:146: arch/arm64/kernel/vdso32/vgettimeofday.o] Error 1
make[3]: Target 'arch/arm64/kernel/vdso32/vdso.so' not remade because of errors.
make[2]: *** [arch/arm64/Makefile:208: vdso_prepare] Error 2
make[2]: Target 'prepare' not remade because of errors.
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +/__always_inline +55 include/linux/compiler_attributes.h
86cffecdeaa278 Kees Cook 2021-11-05 45
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 46 /*
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 47 * Note: users of __always_inline currently do not write "inline" themselves,
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 48 * which seems to be required by gcc to apply the attribute according
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 49 * to its docs (and also "warning: always_inline function might not be
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 50 * inlinable [-Wattributes]" is emitted).
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 51 *
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 52 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-always_005finline-function-attribute
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 53 * clang: mentioned
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 54 */
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 @55 #define __always_inline inline __attribute__((__always_inline__))
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 56
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] stddef: don't include compiler_types.h in the uAPI header
2025-08-19 4:06 ` Kees Cook
@ 2025-08-20 17:17 ` Jakub Kicinski
2025-08-26 2:54 ` Kees Cook
0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2025-08-20 17:17 UTC (permalink / raw)
To: Kees Cook
Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, dhowells,
gustavoars, aleksander.lobakin, tstruk
On Mon, 18 Aug 2025 21:06:10 -0700 Kees Cook wrote:
> > Since nothing needs this include, let's remove it.
>
> But yes, nothing uses compiler_types.h via uapi/linux/stddef.h. That
> does seem to be true.
While staring at the kbuild bot report (which I can't repro :|)
I realized this include is to give kernel's __counted_by and friends
precedence over the empty uAPI-facing defines.
Not sure this is the most fortunate approach, personally I'd rather wrap
our empty user-space-facing defines under ifndef __KERNEL__. I think
it'd be better from "include what you need" perspective. Perhaps stddef
pulling in compiler annotations is expected, dunno...
Would you be okay with:
diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
index 6bbccb43f7e7..4c20c62c4faf 100755
--- a/scripts/headers_install.sh
+++ b/scripts/headers_install.sh
@@ -32,7 +32,7 @@ fi
sed -E -e '
s/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g
s/__attribute_const__([[:space:]]|$)/\1/g
- s@^#include <linux/compiler(|_types).h>@@
+ s@^#include <linux/compiler.h>@@
s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g
s/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g
s@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @
diff --git a/include/uapi/linux/stddef.h b/include/uapi/linux/stddef.h
index b87df1b485c2..9a28f7d9a334 100644
--- a/include/uapi/linux/stddef.h
+++ b/include/uapi/linux/stddef.h
@@ -2,7 +2,9 @@
#ifndef _UAPI_LINUX_STDDEF_H
#define _UAPI_LINUX_STDDEF_H
+#ifdef __KERNEL__
#include <linux/compiler_types.h>
+#endif
? As you pointed out compiler_types.h is only included under stddef.h
so the special handling in the installation script is easily avoided.
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] stddef: don't include compiler_types.h in the uAPI header
2025-08-20 17:17 ` Jakub Kicinski
@ 2025-08-26 2:54 ` Kees Cook
2025-08-26 13:47 ` Jakub Kicinski
0 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2025-08-26 2:54 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, dhowells,
gustavoars, aleksander.lobakin, tstruk
On Wed, Aug 20, 2025 at 10:17:52AM -0700, Jakub Kicinski wrote:
> I realized this include is to give kernel's __counted_by and friends
> precedence over the empty uAPI-facing defines.
Right.
> Not sure this is the most fortunate approach, personally I'd rather wrap
> our empty user-space-facing defines under ifndef __KERNEL__. I think
> it'd be better from "include what you need" perspective. Perhaps stddef
> pulling in compiler annotations is expected, dunno...
I'm trying to leave the door open for userspace to start using these, if
they defined them too.
> Would you be okay with:
>
> diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
> index 6bbccb43f7e7..4c20c62c4faf 100755
> --- a/scripts/headers_install.sh
> +++ b/scripts/headers_install.sh
> @@ -32,7 +32,7 @@ fi
> sed -E -e '
> s/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g
> s/__attribute_const__([[:space:]]|$)/\1/g
> - s@^#include <linux/compiler(|_types).h>@@
> + s@^#include <linux/compiler.h>@@
> s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g
> s/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g
> s@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @
> diff --git a/include/uapi/linux/stddef.h b/include/uapi/linux/stddef.h
> index b87df1b485c2..9a28f7d9a334 100644
> --- a/include/uapi/linux/stddef.h
> +++ b/include/uapi/linux/stddef.h
> @@ -2,7 +2,9 @@
> #ifndef _UAPI_LINUX_STDDEF_H
> #define _UAPI_LINUX_STDDEF_H
>
> +#ifdef __KERNEL__
> #include <linux/compiler_types.h>
> +#endif
>
> ? As you pointed out compiler_types.h is only included under stddef.h
> so the special handling in the installation script is easily avoided.
I think this should be fine, but something is itching at my mind that
doing __KERNEL__ checks in uAPI is fragile. I can't substantiate this
sensation, though. :P
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] stddef: don't include compiler_types.h in the uAPI header
2025-08-26 2:54 ` Kees Cook
@ 2025-08-26 13:47 ` Jakub Kicinski
0 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2025-08-26 13:47 UTC (permalink / raw)
To: Kees Cook
Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, dhowells,
gustavoars, aleksander.lobakin, tstruk
On Mon, 25 Aug 2025 19:54:44 -0700 Kees Cook wrote:
> > Not sure this is the most fortunate approach, personally I'd rather wrap
> > our empty user-space-facing defines under ifndef __KERNEL__. I think
> > it'd be better from "include what you need" perspective. Perhaps stddef
> > pulling in compiler annotations is expected, dunno...
>
> I'm trying to leave the door open for userspace to start using these, if
> they defined them too.
Makes sense.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-08-26 13:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18 18:18 [PATCH net-next] stddef: don't include compiler_types.h in the uAPI header Jakub Kicinski
2025-08-19 4:06 ` Kees Cook
2025-08-20 17:17 ` Jakub Kicinski
2025-08-26 2:54 ` Kees Cook
2025-08-26 13:47 ` Jakub Kicinski
2025-08-19 9:26 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).