mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] Remove obsolete RELOC_HIDE() macro from compiler-gcc.h
@ 2025-12-23 20:18 Uros Bizjak
  2025-12-23 20:18 ` [PATCH 1/3] x86/boot: replace FS/GS inline asm with segment-qualified accesses Uros Bizjak
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Uros Bizjak @ 2025-12-23 20:18 UTC (permalink / raw)
  To: x86, linux-kernel
  Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, H. Peter Anvin, Linus Torvalds

The GCC specific macro was historically used to workaround very old
compiler bugs (including pre-4.1 ppc64 GCC). These compilers are long
obsolete.

The generic RELOC_HIDE() macro should be used instead.

The removal causes GCC to detect several reads from addresses below 4kB in
the boot code. GCC treats absolute addresses smaller than min-pagesize param
(defaulting to 4kB) as assumed results of pointer arithmetics from NULL.
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

To solve the issue, replace open-coded inline assembly used for
FS/GS memory accesses in arch/x86/boot/boot.h with segment-qualified
pointer dereferences. The compiler allows pointer arithmetic from
NULL in __seg_fs and __seg_gs named address spaces.

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 the x86
boot code with GCC inhibits warnings for addresses below 4kB.

The removal of the GCC specific macro results in the
following code size reduction:

     text    data     bss     dec     hex filename
  28526453        4823511  737108 34087072        20820a0 vmlinux-old.o
  28520945        4823463  737108 34081516        2080aec vmlinux-new.o

  ./bloat-o-meter vmlinux-old.o vmlinux-new.o
  add/remove: 4/14 grow/shrink: 189/674 up/down: 4433/-7865 (-3432)
  ...
  Total: Before=24103512, After=24100080, chg -0.01%

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>
Cc: Linus Torvalds <torvalds@linux-foundation.org>

Uros Bizjak (3):
  x86/boot: replace FS/GS inline asm with segment-qualified accesses
  x86/boot: disable GCC min-pagesize assumption in boot code
  compiler-gcc: Remove obsolete RELOC_HIDE() macro

 arch/x86/boot/Makefile       |  3 ++
 arch/x86/boot/boot.h         | 58 +++++++++++-------------------------
 include/linux/compiler-gcc.h | 25 ----------------
 3 files changed, 21 insertions(+), 65 deletions(-)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-12-23 20:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-23 20:18 [PATCH 0/3] Remove obsolete RELOC_HIDE() macro from compiler-gcc.h Uros Bizjak
2025-12-23 20:18 ` [PATCH 1/3] x86/boot: replace FS/GS inline asm with segment-qualified accesses Uros Bizjak
2025-12-23 20:18 ` [PATCH 2/3] x86/boot: disable GCC min-pagesize assumption in boot code Uros Bizjak
2025-12-23 20:18 ` [PATCH 3/3] compiler-gcc: Remove obsolete RELOC_HIDE() macro Uros Bizjak

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®