mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Uros Bizjak <ubizjak@gmail.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>
Subject: Re: [PATCH v2 1/2] x86/boot: Disable GCC min-pagesize assumption in boot code
Date: Fri, 04 Sep 2026 06:17:56 -0700	[thread overview]
Message-ID: <D7BA2D11-A6C7-4B1D-AD59-BAF85AC7BB58@zytor.com> (raw)
In-Reply-To: <20260904082741.578048-2-ubizjak@gmail.com>

On September 4, 2026 1:25:22 AM PDT, Uros Bizjak <ubizjak@gmail.com> wrote:
>GCC treats absolute addresses smaller than the min-pagesize param
>(which defaults to 4kB) in the generic address space as presumed
>results of pointer arithmetics from NULL. For example, the following
>code, when compiled with -O2 -Warray-bounds (included in -Wall):
>
>  int foo (void) { return *(int *)0x123; }
>
>will emit a rather cryptic warning:
>
>warning: array subscript 0 is outside array bounds of ‘int[0]’ [-Warray-bounds=]
>    1 | int foo (void) { return *(int *)0x123; }
>      |                         ^~~~~~~~~~~~~
>cc1: note: source object is likely at address zero
>
>Currently, the warning is supressed by the GCC specific RELOC_HIDE()
>macro that obfuscates arithmetic on a variable address so that GCC
>doesn't recognize the original var, and make assumptions about it.
>
>The GCC specific RELOC_HIDE() macro was introduced to work around
>certain ppc64 specific compiler bug in pre-4.1 GCC. This bug was
>fixed long ago, and replacing GCC specific macro with a generic one
>triggers the above warning in boot and realmode source code.
>
>The early boot environment does not guarantee any minimum page size,
>so explicitly setting the minimum page size to zero by adding
>--param=min-pagesize=0 to the compiler flags when building x86 boot
>and realmode code with GCC inhibits warnings for addresses below 4kB.
>
>The option is guarded by CONFIG_CC_IS_GCC since it is GCC-specific.
>
>Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
>Cc: Thomas Gleixner <tglx@linutronix.de>
>Cc: Ingo Molnar <mingo@kernel.org>
>Cc: Borislav Petkov <bp@alien8.de>
>Cc: Dave Hansen <dave.hansen@linux.intel.com>
>Cc: "H. Peter Anvin" <hpa@zytor.com>
>---
> arch/x86/boot/Makefile        | 3 +++
> arch/x86/realmode/rm/Makefile | 3 +++
> 2 files changed, 6 insertions(+)
>
>diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
>index 3f9fb3698d66..372e67d2a855 100644
>--- a/arch/x86/boot/Makefile
>+++ b/arch/x86/boot/Makefile
>@@ -55,6 +55,9 @@ KBUILD_CFLAGS	:= $(REALMODE_CFLAGS) -D_SETUP
> KBUILD_AFLAGS	:= $(KBUILD_CFLAGS) -D__ASSEMBLY__
> KBUILD_CFLAGS	+= -fno-asynchronous-unwind-tables
> KBUILD_CFLAGS	+= $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
>+ifdef CONFIG_CC_IS_GCC
>+KBUILD_CFLAGS	+= $(call cc-option,--param=min-pagesize=0)
>+endif
> 
> $(obj)/bzImage: asflags-y  := $(SVGA_MODE)
> 
>diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
>index a0fb39abc5c8..75058f4dd7c1 100644
>--- a/arch/x86/realmode/rm/Makefile
>+++ b/arch/x86/realmode/rm/Makefile
>@@ -67,3 +67,6 @@ 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
>+ifdef CONFIG_CC_IS_GCC
>+KBUILD_CFLAGS	+= $(call cc-option,--param=min-pagesize=0)
>+endif

That seems like a much better answer than that horrible hack. 

Acked-by: H. Peter Anvin <hpa@zytor.com>

  reply	other threads:[~2026-09-04 13:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  8:25 [PATCH v2 0/2] Remove obsolete RELOC_HIDE() macro from compiler-gcc.h Uros Bizjak
2026-09-04  8:25 ` [PATCH v2 1/2] x86/boot: Disable GCC min-pagesize assumption in boot code Uros Bizjak
2026-09-04 13:17   ` H. Peter Anvin [this message]
2026-09-06 20:44     ` Uros Bizjak
2026-09-04  8:25 ` [PATCH v2 2/2] compiler-gcc: Remove obsolete RELOC_HIDE() macro Uros Bizjak
2026-09-04 15:16   ` Linus Torvalds
2026-09-04 15:29     ` Uros Bizjak
2026-09-04 15:39       ` Linus Torvalds
2026-09-05  9:42         ` Uros Bizjak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D7BA2D11-A6C7-4B1D-AD59-BAF85AC7BB58@zytor.com \
    --to=hpa@zytor.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=ubizjak@gmail.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®