From 6059b880a93c38a90d178b49fa80403c76d1a89f Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Tue, 23 Dec 2025 08:04:08 +0100 Subject: kbuild: uapi: validate that headers do not use libc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The UAPI headers should be self-contained. That means they should not use other headers from libc. Currently this is not enforced and various dependencies have crept in. Add a check to make sure no new ones are added. Signed-off-by: Thomas Weißschuh Link: https://patch.msgid.link/20251223-uapi-nostdinc-v1-1-d91545d794f7@linutronix.de Signed-off-by: Nathan Chancellor --- usr/include/Makefile | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/usr/include/Makefile b/usr/include/Makefile index d8a508042fed..a9a861ec8702 100644 --- a/usr/include/Makefile +++ b/usr/include/Makefile @@ -68,12 +68,89 @@ endif # asm-generic/*.h is used by asm/*.h, and should not be included directly no-header-test += asm-generic/% +# The following are using libc header and types. +# +# Do not add a new header to the list without legitimate reason. +# Please consider to fix the header first. +# +# Sorted alphabetically. +uses-libc += linux/a.out.h +uses-libc += linux/atmbr2684.h +uses-libc += linux/auto_dev-ioctl.h +uses-libc += linux/auto_fs.h +uses-libc += linux/auto_fs4.h +uses-libc += linux/btrfs_tree.h +uses-libc += linux/cec-funcs.h +uses-libc += linux/cec.h +uses-libc += linux/dvb/dmx.h +uses-libc += linux/dvb/video.h +uses-libc += linux/ethtool.h +uses-libc += linux/ethtool_netlink.h +uses-libc += linux/fuse.h +uses-libc += linux/gsmmux.h +uses-libc += linux/icmp.h +uses-libc += linux/idxd.h +uses-libc += linux/if.h +uses-libc += linux/if_arp.h +uses-libc += linux/if_bonding.h +uses-libc += linux/if_pppox.h +uses-libc += linux/if_tunnel.h +uses-libc += linux/input.h +uses-libc += linux/ip6_tunnel.h +uses-libc += linux/joystick.h +uses-libc += linux/llc.h +uses-libc += linux/mctp.h +uses-libc += linux/mdio.h +uses-libc += linux/mii.h +uses-libc += linux/mptcp.h +uses-libc += linux/netdevice.h +uses-libc += linux/netfilter/xt_RATEEST.h +uses-libc += linux/netfilter/xt_hashlimit.h +uses-libc += linux/netfilter/xt_physdev.h +uses-libc += linux/netfilter/xt_rateest.h +uses-libc += linux/netfilter_arp/arp_tables.h +uses-libc += linux/netfilter_arp/arpt_mangle.h +uses-libc += linux/netfilter_bridge.h +uses-libc += linux/netfilter_bridge/ebtables.h +uses-libc += linux/netfilter_ipv4.h +uses-libc += linux/netfilter_ipv4/ip_tables.h +uses-libc += linux/netfilter_ipv6.h +uses-libc += linux/netfilter_ipv6/ip6_tables.h +uses-libc += linux/route.h +uses-libc += linux/shm.h +uses-libc += linux/soundcard.h +uses-libc += linux/string.h +uses-libc += linux/tipc_config.h +uses-libc += linux/uhid.h +uses-libc += linux/uinput.h +uses-libc += linux/vhost.h +uses-libc += linux/vhost_types.h +uses-libc += linux/virtio_ring.h +uses-libc += linux/wireless.h +uses-libc += regulator/regulator.h +uses-libc += scsi/fc/fc_els.h + +ifeq ($(SRCARCH),hexagon) +uses-libc += asm/sigcontext.h +endif + +ifeq ($(SRCARCH),nios2) +uses-libc += asm/ptrace.h +uses-libc += linux/bpf_perf_event.h +endif + +ifeq ($(SRCARCH),s390) +uses-libc += asm/chpid.h +uses-libc += asm/chsc.h +endif + always-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null)) # Include the header twice to detect missing include guard. quiet_cmd_hdrtest = HDRTEST $< cmd_hdrtest = \ $(CC) $(c_flags) -fsyntax-only -Werror -x c /dev/null \ + $(if $(filter-out $(uses-libc), $*.h), -nostdinc) \ $(if $(filter-out $(no-header-test), $*.h), -include $< -include $<); \ $(PERL) $(src)/headers_check.pl $(obj) $<; \ touch $@ -- cgit v1.2.3 From cc45d2ea5cfb820fd95cba1fcc3aed18e80a92d3 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Tue, 23 Dec 2025 08:04:09 +0100 Subject: hexagon: Drop invalid UAPI header asm/signal.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This UAPI header contains declarations of internal kernel symbols. Such declarations are invalid. Normally headers_check.pl would report an error, but apparently its dependency on CC_CAN_LINK prevent its execution on hexagon so far. As the header does not expose any additional UAPI, just make it a regular internal kernel header. asm-generic/signal.h will be used for the UAPI automatically, the same as before. Signed-off-by: Thomas Weißschuh Link: https://patch.msgid.link/20251223-uapi-nostdinc-v1-2-d91545d794f7@linutronix.de Signed-off-by: Nathan Chancellor --- arch/hexagon/include/asm/signal.h | 29 +++++++++++++++++++++++++++++ arch/hexagon/include/uapi/asm/signal.h | 29 ----------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 arch/hexagon/include/asm/signal.h delete mode 100644 arch/hexagon/include/uapi/asm/signal.h diff --git a/arch/hexagon/include/asm/signal.h b/arch/hexagon/include/asm/signal.h new file mode 100644 index 000000000000..a08fc425387d --- /dev/null +++ b/arch/hexagon/include/asm/signal.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef _ASM_SIGNAL_H +#define _ASM_SIGNAL_H + +extern unsigned long __rt_sigtramp_template[2]; + +void do_signal(struct pt_regs *regs); + +#include + +#endif diff --git a/arch/hexagon/include/uapi/asm/signal.h b/arch/hexagon/include/uapi/asm/signal.h deleted file mode 100644 index a08fc425387d..000000000000 --- a/arch/hexagon/include/uapi/asm/signal.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -/* - * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 and - * only version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef _ASM_SIGNAL_H -#define _ASM_SIGNAL_H - -extern unsigned long __rt_sigtramp_template[2]; - -void do_signal(struct pt_regs *regs); - -#include - -#endif -- cgit v1.2.3 From e2772ba5f43df6b13b04041fe52b07e8cac06ce0 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Tue, 23 Dec 2025 08:04:10 +0100 Subject: kbuild: uapi: don't compile test bpf_perf_event.h on xtensa MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The xtensa UAPI headers do not provide 'struct pt_regs', triggering an error: usr/include/linux/bpf_perf_event.h:14:28: error: field 'regs' has incomplete type Disable the header tests for this file on xtensa. Signed-off-by: Thomas Weißschuh Link: https://patch.msgid.link/20251223-uapi-nostdinc-v1-3-d91545d794f7@linutronix.de Signed-off-by: Nathan Chancellor --- usr/include/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/usr/include/Makefile b/usr/include/Makefile index a9a861ec8702..fd29c11c35cb 100644 --- a/usr/include/Makefile +++ b/usr/include/Makefile @@ -65,6 +65,10 @@ no-header-test += asm/uctx.h no-header-test += asm/fbio.h endif +ifeq ($(SRCARCH),xtensa) +no-header-test += linux/bpf_perf_event.h +endif + # asm-generic/*.h is used by asm/*.h, and should not be included directly no-header-test += asm-generic/% -- cgit v1.2.3 From 4ac85d9bc73ed38a3bf98a58f9a44087375332b4 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Tue, 23 Dec 2025 08:04:11 +0100 Subject: kbuild: uapi: split out command conditions into variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The condition logic will become a bit more complicated. Split them out into dedicated variables so they stay readable. Signed-off-by: Thomas Weißschuh Link: https://patch.msgid.link/20251223-uapi-nostdinc-v1-4-d91545d794f7@linutronix.de Signed-off-by: Nathan Chancellor --- usr/include/Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/usr/include/Makefile b/usr/include/Makefile index fd29c11c35cb..fa01bcda21f5 100644 --- a/usr/include/Makefile +++ b/usr/include/Makefile @@ -150,12 +150,15 @@ endif always-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null)) +target-no-libc = $(filter-out $(uses-libc), $*.h) +target-can-compile = $(filter-out $(no-header-test), $*.h) + # Include the header twice to detect missing include guard. quiet_cmd_hdrtest = HDRTEST $< cmd_hdrtest = \ $(CC) $(c_flags) -fsyntax-only -Werror -x c /dev/null \ - $(if $(filter-out $(uses-libc), $*.h), -nostdinc) \ - $(if $(filter-out $(no-header-test), $*.h), -include $< -include $<); \ + $(if $(target-no-libc), -nostdinc) \ + $(if $(target-can-compile), -include $< -include $<); \ $(PERL) $(src)/headers_check.pl $(obj) $<; \ touch $@ -- cgit v1.2.3 From 1e5271393d777f6159d896943b4c44c4f3ecff52 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Thu, 15 Jan 2026 08:35:44 +0100 Subject: hyper-v: Mark inner union in hv_kvp_exchg_msg_value as packed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The unpacked union within a packed struct generates alignment warnings on clang for 32-bit ARM: ./usr/include/linux/hyperv.h:361:2: error: field within 'struct hv_kvp_exchg_msg_value' is less aligned than 'union hv_kvp_exchg_msg_value::(anonymous at ./usr/include/linux/hyperv.h:361:2)' and is usually due to 'struct hv_kvp_exchg_msg_value' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access] 361 | union { | ^ With the recent changes to compile-test the UAPI headers in more cases, this warning in combination with CONFIG_WERROR breaks the build. Fix the warning. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202512140314.DzDxpIVn-lkp@intel.com/ Reported-by: Nathan Chancellor Closes: https://lore.kernel.org/linux-kbuild/20260110-uapi-test-disable-headers-arm-clang-unaligned-access-v1-1-b7b0fa541daa@kernel.org/ Suggested-by: Arnd Bergmann Link: https://lore.kernel.org/linux-kbuild/29b2e736-d462-45b7-a0a9-85f8d8a3de56@app.fastmail.com/ Signed-off-by: Thomas Weißschuh Acked-by: Wei Liu (Microsoft) Tested-by: Nicolas Schier Reviewed-by: Nicolas Schier Acked-by: Greg Kroah-Hartman Link: https://patch.msgid.link/20260115-kbuild-alignment-vbox-v1-1-076aed1623ff@linutronix.de Signed-off-by: Nathan Chancellor --- include/uapi/linux/hyperv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/linux/hyperv.h b/include/uapi/linux/hyperv.h index aaa502a7bff4..1749b35ab2c2 100644 --- a/include/uapi/linux/hyperv.h +++ b/include/uapi/linux/hyperv.h @@ -362,7 +362,7 @@ struct hv_kvp_exchg_msg_value { __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; __u32 value_u32; __u64 value_u64; - }; + } __attribute__((packed)); } __attribute__((packed)); struct hv_kvp_msg_enumerate { -- cgit v1.2.3 From c25d01e1c4f2d43f47af87c00e223f5ca7c71792 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Thu, 15 Jan 2026 08:35:45 +0100 Subject: virt: vbox: uapi: Mark inner unions in packed structs as packed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The unpacked unions within a packed struct generates alignment warnings on clang for 32-bit ARM: ./usr/include/linux/vbox_vmmdev_types.h:239:4: error: field u within 'struct vmmdev_hgcm_function_parameter32' is less aligned than 'union (unnamed union at ./usr/include/linux/vbox_vmmdev_types.h:223:2)' and is usually due to 'struct vmmdev_hgcm_function_parameter32' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access] 239 | } u; | ^ ./usr/include/linux/vbox_vmmdev_types.h:254:6: error: field u within 'struct vmmdev_hgcm_function_parameter64::(anonymous union)::(unnamed at ./usr/include/linux/vbox_vmmdev_types.h:249:3)' is less aligned than 'union (unnamed union at ./usr/include/linux/vbox_vmmdev_types.h:251:4)' and is usually due to 'struct vmmdev_hgcm_function_parameter64::(anonymous union)::(unnamed at ./usr/include/linux/vbox_vmmdev_types.h:249:3)' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access] With the recent changes to compile-test the UAPI headers in more cases, these warning in combination with CONFIG_WERROR breaks the build. Fix the warnings. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202512140314.DzDxpIVn-lkp@intel.com/ Reported-by: Nathan Chancellor Closes: https://lore.kernel.org/linux-kbuild/20260110-uapi-test-disable-headers-arm-clang-unaligned-access-v1-1-b7b0fa541daa@kernel.org/ Suggested-by: Arnd Bergmann Link: https://lore.kernel.org/linux-kbuild/29b2e736-d462-45b7-a0a9-85f8d8a3de56@app.fastmail.com/ Signed-off-by: Thomas Weißschuh Tested-by: Nicolas Schier Reviewed-by: Nicolas Schier Acked-by: Greg Kroah-Hartman Link: https://patch.msgid.link/20260115-kbuild-alignment-vbox-v1-2-076aed1623ff@linutronix.de Signed-off-by: Nathan Chancellor --- include/uapi/linux/vbox_vmmdev_types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/vbox_vmmdev_types.h b/include/uapi/linux/vbox_vmmdev_types.h index 6073858d52a2..11f3627c3729 100644 --- a/include/uapi/linux/vbox_vmmdev_types.h +++ b/include/uapi/linux/vbox_vmmdev_types.h @@ -236,7 +236,7 @@ struct vmmdev_hgcm_function_parameter32 { /** Relative to the request header. */ __u32 offset; } page_list; - } u; + } __packed u; } __packed; VMMDEV_ASSERT_SIZE(vmmdev_hgcm_function_parameter32, 4 + 8); @@ -251,7 +251,7 @@ struct vmmdev_hgcm_function_parameter64 { union { __u64 phys_addr; __u64 linear_addr; - } u; + } __packed u; } __packed pointer; struct { /** Size of the buffer described by the page list. */ -- cgit v1.2.3 From 2a0a30805a7d27470e02137cae72f7c3188e44eb Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Tue, 23 Dec 2025 08:04:12 +0100 Subject: kbuild: uapi: drop dependency on CC_CAN_LINK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The header tests try to compile each header. Some UAPI headers depend on libc headers so they need a full userspace toolchain to build. This dependency is expressed in kconfig as a dependency on CC_CAN_LINK. Many kernel builds do not satisfy CC_CAN_LINK as they only use a minimal kernel (cross-) compiler. In those configurations the UAPI headers are not tested at all. However most UAPI headers do not even depend on any libc headers, and such dependencies are undesired in any case. Also the static analysis performed by headers_check.pl does not need CC_CAN_LINK. Drop the hard dependency on CC_CAN_LINK and instead skip the affected compilation step for exactly those headers which require libc. Signed-off-by: Thomas Weißschuh Link: https://patch.msgid.link/20251223-uapi-nostdinc-v1-5-d91545d794f7@linutronix.de Signed-off-by: Nathan Chancellor --- init/Kconfig | 2 +- usr/include/Makefile | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index fa79feb8fe57..4e7ae65683ee 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -247,7 +247,7 @@ config WERROR config UAPI_HEADER_TEST bool "Compile test UAPI headers" - depends on HEADERS_INSTALL && CC_CAN_LINK + depends on HEADERS_INSTALL help Compile test headers exported to user-space to ensure they are self-contained, i.e. compilable as standalone units. diff --git a/usr/include/Makefile b/usr/include/Makefile index fa01bcda21f5..6d86a53c6f0a 100644 --- a/usr/include/Makefile +++ b/usr/include/Makefile @@ -151,7 +151,8 @@ endif always-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null)) target-no-libc = $(filter-out $(uses-libc), $*.h) -target-can-compile = $(filter-out $(no-header-test), $*.h) +target-can-compile = $(and $(filter-out $(no-header-test), $*.h), \ + $(or $(CONFIG_CC_CAN_LINK), $(target-no-libc))) # Include the header twice to detect missing include guard. quiet_cmd_hdrtest = HDRTEST $< -- cgit v1.2.3