]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
arch: Introduce CONFIG_FUNCTION_ALIGNMENT
authorPeter Zijlstra <peterz@infradead.org>
Wed, 13 Mar 2024 10:42:51 +0000 (07:42 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:18:49 +0000 (16:18 +0200)
commit d49a0626216b95cd4bf696f6acf55f39a16ab0bb upstream.

Generic function-alignment infrastructure.

Architectures can select FUNCTION_ALIGNMENT_xxB symbols; the
FUNCTION_ALIGNMENT symbol is then set to the largest such selected
size, 0 otherwise.

>From this the -falign-functions compiler argument and __ALIGN macro
are set.

This incorporates the DEBUG_FORCE_FUNCTION_ALIGN_64B knob and future
alignment requirements for x86_64 (later in this series) into a single
place.

NOTE: also removes the 0x90 filler byte from the generic __ALIGN
      primitive, that value makes no sense outside of x86.

NOTE: .balign 0 reverts to a no-op.

Requested-by: Linus Torvalds <torvalds@linux-foundation.org>
Change-Id: I053b3c408d56988381feb8c8bdb5e27ea221755f
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220915111143.719248727@infradead.org
[cascardo: adjust context at arch/x86/Kconfig]
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Makefile
arch/Kconfig
arch/ia64/Kconfig
arch/ia64/Makefile
arch/x86/Kconfig
arch/x86/boot/compressed/head_64.S
arch/x86/include/asm/linkage.h
include/asm-generic/vmlinux.lds.h
include/linux/linkage.h
lib/Kconfig.debug

index 07a0f520f2df75f49b1f1598914f261402a42a33..f6ba673bdee0028104c82f5611c85aea5f5708c6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1000,8 +1000,8 @@ KBUILD_CFLAGS     += $(CC_FLAGS_CFI)
 export CC_FLAGS_CFI
 endif
 
-ifdef CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_64B
-KBUILD_CFLAGS += -falign-functions=64
+ifneq ($(CONFIG_FUNCTION_ALIGNMENT),0)
+KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT)
 endif
 
 # arch Makefile may override CC so keep this after arch Makefile is included
index 2e2dc0975ab450264324992ac512dcc9c13f64f1..a541ce263865c1ce1f4cf2e39401921b9cc5f7d2 100644 (file)
@@ -1303,4 +1303,28 @@ source "kernel/gcov/Kconfig"
 
 source "scripts/gcc-plugins/Kconfig"
 
+config FUNCTION_ALIGNMENT_4B
+       bool
+
+config FUNCTION_ALIGNMENT_8B
+       bool
+
+config FUNCTION_ALIGNMENT_16B
+       bool
+
+config FUNCTION_ALIGNMENT_32B
+       bool
+
+config FUNCTION_ALIGNMENT_64B
+       bool
+
+config FUNCTION_ALIGNMENT
+       int
+       default 64 if FUNCTION_ALIGNMENT_64B
+       default 32 if FUNCTION_ALIGNMENT_32B
+       default 16 if FUNCTION_ALIGNMENT_16B
+       default 8 if FUNCTION_ALIGNMENT_8B
+       default 4 if FUNCTION_ALIGNMENT_4B
+       default 0
+
 endmenu
index 89869aff8ca2932944c31a14777bc4fd4f63b16d..8902d1517894a8933b608c5f9a5289a453d7cdfb 100644 (file)
@@ -63,6 +63,7 @@ config IA64
        select PCI_MSI_ARCH_FALLBACKS if PCI_MSI
        select SET_FS
        select ZONE_DMA32
+       select FUNCTION_ALIGNMENT_32B
        default y
        help
          The Itanium Processor Family is Intel's 64-bit successor to
index 7e548c654a290f286cdce7740bbc4eef7d92f47d..43cde968da88b50eae41219c7e9eb48536cdc8db 100644 (file)
@@ -23,7 +23,7 @@ KBUILD_AFLAGS_KERNEL := -mconstant-gp
 EXTRA          :=
 
 cflags-y       := -pipe $(EXTRA) -ffixed-r13 -mfixed-range=f12-f15,f32-f127 \
-                  -falign-functions=32 -frename-registers -fno-optimize-sibling-calls
+                  -frename-registers -fno-optimize-sibling-calls
 KBUILD_CFLAGS_KERNEL := -mconstant-gp
 
 GAS_STATUS     = $(shell $(srctree)/arch/ia64/scripts/check-gas "$(CC)" "$(OBJDUMP)")
index a9d3fd8e8af1c233ee91c6ca28107ab5d375d526..1404bbacd7a9ff06b508dedc395a2d3db4efdc1c 100644 (file)
@@ -267,6 +267,8 @@ config X86
        select HAVE_ARCH_KCSAN                  if X86_64
        select X86_FEATURE_NAMES                if PROC_FS
        select PROC_PID_ARCH_STATUS             if PROC_FS
+       select FUNCTION_ALIGNMENT_16B           if X86_64 || X86_ALIGNMENT_16
+       select FUNCTION_ALIGNMENT_4B
        imply IMA_SECURE_AND_OR_TRUSTED_BOOT    if EFI
 
 config INSTRUCTION_DECODER
index c3d427c817c7374a835a93f219611da464a8d650..e189a16ae40ac38e057f84b7719ae5ee23d32a1b 100644 (file)
 #include <asm/trapnr.h>
 #include "pgtable.h"
 
+/*
+ * Fix alignment at 16 bytes. Following CONFIG_FUNCTION_ALIGNMENT will result
+ * in assembly errors due to trying to move .org backward due to the excessive
+ * alignment.
+ */
+#undef __ALIGN
+#define __ALIGN                .balign 16, 0x90
+
 /*
  * Locally defined symbols should be marked hidden:
  */
index 5000cf59bdf5b6c31b87461893530bda747fca1c..3d7293d529501c151a57370cd9e86b61461fb205 100644 (file)
 
 #ifdef __ASSEMBLY__
 
-#if defined(CONFIG_X86_64) || defined(CONFIG_X86_ALIGNMENT_16)
-#define __ALIGN                .p2align 4, 0x90
+#define __ALIGN                .balign CONFIG_FUNCTION_ALIGNMENT, 0x90;
 #define __ALIGN_STR    __stringify(__ALIGN)
-#endif
 
 #if defined(CONFIG_RETHUNK) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO)
 #define RET    jmp __x86_return_thunk
index 8471717c5085a73b5110a6b003cac3523f46e2be..dd9ea351bc02effcf231d3b840d9400eeb9fc331 100644 (file)
@@ -81,8 +81,8 @@
 #define RO_EXCEPTION_TABLE
 #endif
 
-/* Align . to a 8 byte boundary equals to maximum function alignment. */
-#define ALIGN_FUNCTION()  . = ALIGN(8)
+/* Align . function alignment. */
+#define ALIGN_FUNCTION()  . = ALIGN(CONFIG_FUNCTION_ALIGNMENT)
 
 /*
  * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which
index dbf8506decca0f5e4f6527b7a070a1c3c8335f43..fc81e51330b27e29df2c1ba6a9918705bf2e0a0a 100644 (file)
@@ -69,8 +69,8 @@
 #endif
 
 #ifndef __ALIGN
-#define __ALIGN                .align 4,0x90
-#define __ALIGN_STR    ".align 4,0x90"
+#define __ALIGN                        .balign CONFIG_FUNCTION_ALIGNMENT
+#define __ALIGN_STR            __stringify(__ALIGN)
 #endif
 
 #ifdef __ASSEMBLY__
index 64d6292cf686481eb4f92a2d1d89c8aaf777b1f6..28faea9b5da625fae23cdf1fc9175b036d356cd2 100644 (file)
@@ -424,6 +424,7 @@ config SECTION_MISMATCH_WARN_ONLY
 config DEBUG_FORCE_FUNCTION_ALIGN_64B
        bool "Force all function address 64B aligned"
        depends on EXPERT && (X86_64 || ARM64 || PPC32 || PPC64 || ARC)
+       select FUNCTION_ALIGNMENT_64B
        help
          There are cases that a commit from one domain changes the function
          address alignment of other domains, and cause magic performance