Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arch: Introduce CONFIG_FUNCTION_ALIGNMENT

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>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220915111143.719248727@infradead.org

+44 -10
+2 -2
Makefile
··· 1004 1004 export CC_FLAGS_CFI 1005 1005 endif 1006 1006 1007 - ifdef CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_64B 1008 - KBUILD_CFLAGS += -falign-functions=64 1007 + ifneq ($(CONFIG_FUNCTION_ALIGNMENT),0) 1008 + KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT) 1009 1009 endif 1010 1010 1011 1011 # arch Makefile may override CC so keep this after arch Makefile is included
+24
arch/Kconfig
··· 1428 1428 1429 1429 source "scripts/gcc-plugins/Kconfig" 1430 1430 1431 + config FUNCTION_ALIGNMENT_4B 1432 + bool 1433 + 1434 + config FUNCTION_ALIGNMENT_8B 1435 + bool 1436 + 1437 + config FUNCTION_ALIGNMENT_16B 1438 + bool 1439 + 1440 + config FUNCTION_ALIGNMENT_32B 1441 + bool 1442 + 1443 + config FUNCTION_ALIGNMENT_64B 1444 + bool 1445 + 1446 + config FUNCTION_ALIGNMENT 1447 + int 1448 + default 64 if FUNCTION_ALIGNMENT_64B 1449 + default 32 if FUNCTION_ALIGNMENT_32B 1450 + default 16 if FUNCTION_ALIGNMENT_16B 1451 + default 8 if FUNCTION_ALIGNMENT_8B 1452 + default 4 if FUNCTION_ALIGNMENT_4B 1453 + default 0 1454 + 1431 1455 endmenu
+1
arch/ia64/Kconfig
··· 63 63 select NUMA if !FLATMEM 64 64 select PCI_MSI_ARCH_FALLBACKS if PCI_MSI 65 65 select ZONE_DMA32 66 + select FUNCTION_ALIGNMENT_32B 66 67 default y 67 68 help 68 69 The Itanium Processor Family is Intel's 64-bit successor to
+1 -1
arch/ia64/Makefile
··· 23 23 EXTRA := 24 24 25 25 cflags-y := -pipe $(EXTRA) -ffixed-r13 -mfixed-range=f12-f15,f32-f127 \ 26 - -falign-functions=32 -frename-registers -fno-optimize-sibling-calls 26 + -frename-registers -fno-optimize-sibling-calls 27 27 KBUILD_CFLAGS_KERNEL := -mconstant-gp 28 28 29 29 GAS_STATUS = $(shell $(srctree)/arch/ia64/scripts/check-gas "$(CC)" "$(OBJDUMP)")
+2
arch/x86/Kconfig
··· 290 290 select X86_FEATURE_NAMES if PROC_FS 291 291 select PROC_PID_ARCH_STATUS if PROC_FS 292 292 select HAVE_ARCH_NODE_DEV_GROUP if X86_SGX 293 + select FUNCTION_ALIGNMENT_16B if X86_64 || X86_ALIGNMENT_16 294 + select FUNCTION_ALIGNMENT_4B 293 295 imply IMA_SECURE_AND_OR_TRUSTED_BOOT if EFI 294 296 select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE 295 297
+8
arch/x86/boot/compressed/head_64.S
··· 38 38 #include "pgtable.h" 39 39 40 40 /* 41 + * Fix alignment at 16 bytes. Following CONFIG_FUNCTION_ALIGNMENT will result 42 + * in assembly errors due to trying to move .org backward due to the excessive 43 + * alignment. 44 + */ 45 + #undef __ALIGN 46 + #define __ALIGN .balign 16, 0x90 47 + 48 + /* 41 49 * Locally defined symbols should be marked hidden: 42 50 */ 43 51 .hidden _bss
+1 -3
arch/x86/include/asm/linkage.h
··· 14 14 15 15 #ifdef __ASSEMBLY__ 16 16 17 - #if defined(CONFIG_X86_64) || defined(CONFIG_X86_ALIGNMENT_16) 18 - #define __ALIGN .p2align 4, 0x90 17 + #define __ALIGN .balign CONFIG_FUNCTION_ALIGNMENT, 0x90; 19 18 #define __ALIGN_STR __stringify(__ALIGN) 20 - #endif 21 19 22 20 #if defined(CONFIG_RETHUNK) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO) 23 21 #define RET jmp __x86_return_thunk
+2 -2
include/asm-generic/vmlinux.lds.h
··· 81 81 #define RO_EXCEPTION_TABLE 82 82 #endif 83 83 84 - /* Align . to a 8 byte boundary equals to maximum function alignment. */ 85 - #define ALIGN_FUNCTION() . = ALIGN(8) 84 + /* Align . function alignment. */ 85 + #define ALIGN_FUNCTION() . = ALIGN(CONFIG_FUNCTION_ALIGNMENT) 86 86 87 87 /* 88 88 * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which
+2 -2
include/linux/linkage.h
··· 69 69 #endif 70 70 71 71 #ifndef __ALIGN 72 - #define __ALIGN .align 4,0x90 73 - #define __ALIGN_STR ".align 4,0x90" 72 + #define __ALIGN .balign CONFIG_FUNCTION_ALIGNMENT 73 + #define __ALIGN_STR __stringify(__ALIGN) 74 74 #endif 75 75 76 76 #ifdef __ASSEMBLY__
+1
lib/Kconfig.debug
··· 467 467 config DEBUG_FORCE_FUNCTION_ALIGN_64B 468 468 bool "Force all function address 64B aligned" 469 469 depends on EXPERT && (X86_64 || ARM64 || PPC32 || PPC64 || ARC) 470 + select FUNCTION_ALIGNMENT_64B 470 471 help 471 472 There are cases that a commit from one domain changes the function 472 473 address alignment of other domains, and cause magic performance