Skip to contentSkip to conversation

kbuild: uapi: Avoid testing certain headers on ARCH=arm with CC=clang

PATCH In review Nathan Chancellor 2 participants 3 messages Jan 11 – Jan 12

Subsystems (3)
lore
Share & tools
lore

Nathan Chancellor

author maintainer
#0 lore raw

PATCH 1/1 kbuild: uapi: Avoid testing certain headers on ARCH=arm with CC=clang

After commit e3970d77ec50 ("kbuild: uapi: drop dependency on CC_CAN_LINK"), which enables compile testing of UAPI headers in more circumstances due to dropping the dependency on CONFIG_CC_CAN_LINK, there are new instances of -Wunaligned-access when building with clang targeting ARCH=arm in a few headers:

In file included from <built-in>:1:
./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 {
        |         ^

1 error generated.

In file included from <built-in>:1:
In file included from ./usr/include/linux/vboxguest.h:14:
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::(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::(unnamed at usr/include/linux/vbox_vmmdev_types.h:249:3)' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
    254 |                         } u;
        |                           ^

2 errors generated.

These warnings are now fatal after commit 3788d69db18d ("kbuild: uapi:
fail header test on compiler warnings"). -Wunaligned-access is only enabled at W=1 for the rest of the kernel because of numerous instances of it.

To keep the build working while the root cause of the warnings is investigated and resolved, disable testing these header files for ARCH=arm when building with clang. This should be a minimal loss of coverage; if the issue pointed out by this warning existed in the wild, it should have been noticed in real testing at this point since some of these structures have been around for many years. It is likely the case that since these structures are for specialized applications, they have never been used on an ARM platform that does not support unaligned access.

Fixes e3970d77ec50 ("kbuild: uapi: drop dependency on CC_CAN_LINK")
---
 usr/include/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
usr/include/Makefile +6 -0
index 6d86a53c6f0a..d23a0c0363bd 100644
@@ -52,6 +52,12 @@ ifeq ($(SRCARCH),arc)
 no-header-test += linux/bpf_perf_event.h
 endif
 
+ifeq ($(SRCARCH)_$(CONFIG_CC_IS_CLANG),arm_y)
+no-header-test += linux/hyperv.h
+no-header-test += linux/vboxguest.h
+no-header-test += linux/vbox_vmmdev_types.h
+endif
+
 ifeq ($(SRCARCH),openrisc)
 no-header-test += linux/bpf_perf_event.h
 endif

---
base-commit: e3970d77ec504e54c3f91a48b2125775c16ba4c0
change-id: 20260110-uapi-test-disable-headers-arm-clang-unaligned-access-a2e104a20a1e

Best regards,

Signature · 1 line
Nathan Chancellor <[email protected]>
maintainer
#1 lore raw
Quoted 4 lines · Nathan Chancellor

To keep the build working while the root cause of the warnings is investigated and resolved, disable testing these header files for ARCH=arm when building with clang.

I think we can just safely mark the internal unions as __packed as well. The (untested) change below would annotate all of them as being potentially misaligned so they can be stored at an odd start offset, and correctly produce warnings when someone takes the address of a member.

Arnd

include/uapi/linux/hyperv.h +1 -1
index aaa502a7bff4..02ea5f2e43d4 100644
@@ -362,7 +362,7 @@ struct hv_kvp_exchg_msg_value {
                __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
                __u32 value_u32;
                __u64 value_u64;
-       };
+       } __packed;
 } __attribute__((packed));
 
 struct hv_kvp_msg_enumerate {
include/uapi/linux/vbox_vmmdev_types.h +5 -5
index 6073858d52a2..15ccfb5d624c 100644
@@ -229,14 +229,14 @@ struct vmmdev_hgcm_function_parameter32 {
                                __u32 phys_addr;
                                __u32 linear_addr;
                        } u;
-               } pointer;
+               } __packed pointer;
                struct {
                        /** Size of the buffer described by the page list. */
                        __u32 size;
                        /** Relative to the request header. */
                        __u32 offset;
-               } page_list;
-       } u;
+               } __packed page_list;
+       } __packed u;
 } __packed;
 VMMDEV_ASSERT_SIZE(vmmdev_hgcm_function_parameter32, 4 + 8);
 
@@ -251,14 +251,14 @@ 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. */
                        __u32 size;
                        /** Relative to the request header. */
                        __u32 offset;
-               } page_list;
+               } __packed page_list;
        } __packed u;
 } __packed;
 VMMDEV_ASSERT_SIZE(vmmdev_hgcm_function_parameter64, 4 + 12);
author maintainer
#2 lore raw
Quoted 11 lines · Arnd Bergmann
Quoted 4 lines · Nathan Chancellor

To keep the build working while the root cause of the warnings is investigated and resolved, disable testing these header files for ARCH=arm when building with clang.

I think we can just safely mark the internal unions as __packed as well. The (untested) change below would annotate all of them as being potentially misaligned so they can be stored at an odd start offset, and correctly produce warnings when someone takes the address of a member.

Yeah, this diff appears to avoid those warnings in my testing. Would you want to send these changes as formal patches so we can get formal acks from the maintainers of these files to take them via the kbuild tree with Thomas's UAPI testing changes?

Quoted 52 lines
include/uapi/linux/hyperv.h +1 -1
index aaa502a7bff4..02ea5f2e43d4 100644
@@ -362,7 +362,7 @@ struct hv_kvp_exchg_msg_value {
                __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
                __u32 value_u32;
                __u64 value_u64;
-       };
+       } __packed;
 } __attribute__((packed));
 
 struct hv_kvp_msg_enumerate {
include/uapi/linux/vbox_vmmdev_types.h +5 -5
index 6073858d52a2..15ccfb5d624c 100644
@@ -229,14 +229,14 @@ struct vmmdev_hgcm_function_parameter32 {
                                __u32 phys_addr;
                                __u32 linear_addr;
                        } u;
-               } pointer;
+               } __packed pointer;
                struct {
                        /** Size of the buffer described by the page list. */
                        __u32 size;
                        /** Relative to the request header. */
                        __u32 offset;
-               } page_list;
-       } u;
+               } __packed page_list;
+       } __packed u;
 } __packed;
 VMMDEV_ASSERT_SIZE(vmmdev_hgcm_function_parameter32, 4 + 8);
 
@@ -251,14 +251,14 @@ 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. */
                        __u32 size;
                        /** Relative to the request header. */
                        __u32 offset;
-               } page_list;
+               } __packed page_list;
        } __packed u;
 } __packed;
 VMMDEV_ASSERT_SIZE(vmmdev_hgcm_function_parameter64, 4 + 12);