arch/x86/Makefile | 5 +++++ arch/x86/boot/Makefile | 1 + arch/x86/realmode/rm/Makefile | 1 + 3 files changed, 7 insertions(+)
Currently the CHECKFLAGS from the normal build are also used for the
realmode code. This leads to inconsistent flags confusing sparse and
the logic in the kernel headers. Since recently this inconsistent state
is detected by asm-generic/bitsperlong.h, triggering a warning.
Fix the CHECKFLAGS to let sparse properly check this code and
also avoid the warning.
Technically the replacement of -D__x86_64__ is not necessary, as it will
only be added to CHECKFLAGS later in the file.
Replace it anyways for consistency.
Reported-by: Mark Bloch <mbloch@nvidia.com>
Closes: https://lore.kernel.org/lkml/3bbcf456-322c-46f9-b238-88fb8ad227b2@nvidia.com/
Fixes: 62357a5888ea ("asm-generic/bitsperlong.h: Add sanity checks for __BITS_PER_LONG")
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
arch/x86/Makefile | 5 +++++
arch/x86/boot/Makefile | 1 +
arch/x86/realmode/rm/Makefile | 1 +
3 files changed, 7 insertions(+)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 46fec0b08487..bdafa3635dd1 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -61,6 +61,11 @@ REALMODE_CFLAGS += $(cc_stack_align4)
REALMODE_CFLAGS += $(CLANG_FLAGS)
export REALMODE_CFLAGS
+REALMODE_CHECKFLAGS := $(subst -m64, -m16, \
+ $(subst -m32, -m16, \
+ $(subst -D__x86_64__, -D__i386__, \
+ $(CHECKFLAGS))))
+
# BITS is used as extension for files which are available in a 32 bit
# and a 64 bit version to simplify shared Makefiles.
# e.g.: obj-y += foo_$(BITS).o
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 3f9fb3698d66..20b569930229 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -55,6 +55,7 @@ KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP
KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
KBUILD_CFLAGS += $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
+CHECKFLAGS := $(REALMODE_CHECKFLAGS)
$(obj)/bzImage: asflags-y := $(SVGA_MODE)
diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
index a0fb39abc5c8..725c5ef6cdf1 100644
--- a/arch/x86/realmode/rm/Makefile
+++ b/arch/x86/realmode/rm/Makefile
@@ -67,3 +67,4 @@ KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
-I$(srctree)/arch/x86/boot
KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
+CHECKFLAGS := $(REALMODE_CHECKFLAGS)
---
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
change-id: 20260521-x86-sparse-boot-cb427318607d
Best regards,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
On 22/05/2026 10:03, Thomas Weißschuh wrote:
> Currently the CHECKFLAGS from the normal build are also used for the
> realmode code. This leads to inconsistent flags confusing sparse and
> the logic in the kernel headers. Since recently this inconsistent state
> is detected by asm-generic/bitsperlong.h, triggering a warning.
>
> Fix the CHECKFLAGS to let sparse properly check this code and
> also avoid the warning.
>
> Technically the replacement of -D__x86_64__ is not necessary, as it will
> only be added to CHECKFLAGS later in the file.
> Replace it anyways for consistency.
>
> Reported-by: Mark Bloch <mbloch@nvidia.com>
> Closes: https://lore.kernel.org/lkml/3bbcf456-322c-46f9-b238-88fb8ad227b2@nvidia.com/
> Fixes: 62357a5888ea ("asm-generic/bitsperlong.h: Add sanity checks for __BITS_PER_LONG")
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> arch/x86/Makefile | 5 +++++
> arch/x86/boot/Makefile | 1 +
> arch/x86/realmode/rm/Makefile | 1 +
> 3 files changed, 7 insertions(+)
>
> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> index 46fec0b08487..bdafa3635dd1 100644
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -61,6 +61,11 @@ REALMODE_CFLAGS += $(cc_stack_align4)
> REALMODE_CFLAGS += $(CLANG_FLAGS)
> export REALMODE_CFLAGS
>
> +REALMODE_CHECKFLAGS := $(subst -m64, -m16, \
> + $(subst -m32, -m16, \
> + $(subst -D__x86_64__, -D__i386__, \
> + $(CHECKFLAGS))))
> +
> # BITS is used as extension for files which are available in a 32 bit
> # and a 64 bit version to simplify shared Makefiles.
> # e.g.: obj-y += foo_$(BITS).o
> diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
> index 3f9fb3698d66..20b569930229 100644
> --- a/arch/x86/boot/Makefile
> +++ b/arch/x86/boot/Makefile
> @@ -55,6 +55,7 @@ KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP
> KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
> KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
> KBUILD_CFLAGS += $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
> +CHECKFLAGS := $(REALMODE_CHECKFLAGS)
>
> $(obj)/bzImage: asflags-y := $(SVGA_MODE)
>
> diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
> index a0fb39abc5c8..725c5ef6cdf1 100644
> --- a/arch/x86/realmode/rm/Makefile
> +++ b/arch/x86/realmode/rm/Makefile
> @@ -67,3 +67,4 @@ KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
> -I$(srctree)/arch/x86/boot
> KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
> KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
> +CHECKFLAGS := $(REALMODE_CHECKFLAGS)
>
> ---
> base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
> change-id: 20260521-x86-sparse-boot-cb427318607d
>
> Best regards,
> --
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
>
Tested-by: Mark Bloch <mbloch@nvidia.com>
© 2016 - 2026 Red Hat, Inc.