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

Merge tag 'clang-features-v5.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

Pull clang feature updates from Kees Cook:

- Add CC_HAS_NO_PROFILE_FN_ATTR in preparation for PGO support in the
face of the noinstr attribute, paving the way for PGO and fixing
GCOV. (Nick Desaulniers)

- x86_64 LTO coverage is expanded to 32-bit x86. (Nathan Chancellor)

- Small fixes to CFI. (Mark Rutland, Nathan Chancellor)

* tag 'clang-features-v5.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
qemu_fw_cfg: Make fw_cfg_rev_attr a proper kobj_attribute
Kconfig: Introduce ARCH_WANTS_NO_INSTR and CC_HAS_NO_PROFILE_FN_ATTR
compiler_attributes.h: cleanups for GCC 4.9+
compiler_attributes.h: define __no_profile, add to noinstr
x86, lto: Enable Clang LTO for 32-bit as well
CFI: Move function_nocfi() into compiler.h
MAINTAINERS: Add Clang CFI section

+74 -37
+12
MAINTAINERS
··· 4447 4447 F: scripts/clang-tools/ 4448 4448 K: \b(?i:clang|llvm)\b 4449 4449 4450 + CLANG CONTROL FLOW INTEGRITY SUPPORT 4451 + M: Sami Tolvanen <samitolvanen@google.com> 4452 + M: Kees Cook <keescook@chromium.org> 4453 + R: Nathan Chancellor <nathan@kernel.org> 4454 + R: Nick Desaulniers <ndesaulniers@google.com> 4455 + L: clang-built-linux@googlegroups.com 4456 + S: Supported 4457 + B: https://github.com/ClangBuiltLinux/linux/issues 4458 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/clang/features 4459 + F: include/linux/cfi.h 4460 + F: kernel/cfi.c 4461 + 4450 4462 CLEANCACHE API 4451 4463 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 4452 4464 L: linux-kernel@vger.kernel.org
+7
arch/Kconfig
··· 285 285 config ARCH_WANTS_DYNAMIC_TASK_STRUCT 286 286 bool 287 287 288 + config ARCH_WANTS_NO_INSTR 289 + bool 290 + help 291 + An architecture should select this if the noinstr macro is being used on 292 + functions to denote that the toolchain should avoid instrumenting such 293 + functions and is required for correctness. 294 + 288 295 config ARCH_32BIT_OFF_T 289 296 bool 290 297 depends on !64BIT
+1
arch/arm64/Kconfig
··· 93 93 select ARCH_WANT_FRAME_POINTERS 94 94 select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) 95 95 select ARCH_WANT_LD_ORPHAN_WARN 96 + select ARCH_WANTS_NO_INSTR 96 97 select ARCH_HAS_UBSAN_SANITIZE_ALL 97 98 select ARM_AMBA 98 99 select ARM_ARCH_TIMER
+16
arch/arm64/include/asm/compiler.h
··· 23 23 #define __builtin_return_address(val) \ 24 24 (void *)(ptrauth_clear_pac((unsigned long)__builtin_return_address(val))) 25 25 26 + #ifdef CONFIG_CFI_CLANG 27 + /* 28 + * With CONFIG_CFI_CLANG, the compiler replaces function address 29 + * references with the address of the function's CFI jump table 30 + * entry. The function_nocfi macro always returns the address of the 31 + * actual function instead. 32 + */ 33 + #define function_nocfi(x) ({ \ 34 + void *addr; \ 35 + asm("adrp %0, " __stringify(x) "\n\t" \ 36 + "add %0, %0, :lo12:" __stringify(x) \ 37 + : "=r" (addr)); \ 38 + addr; \ 39 + }) 40 + #endif 41 + 26 42 #endif /* __ASM_COMPILER_H */
-16
arch/arm64/include/asm/memory.h
··· 321 321 #define virt_to_pfn(x) __phys_to_pfn(__virt_to_phys((unsigned long)(x))) 322 322 #define sym_to_pfn(x) __phys_to_pfn(__pa_symbol(x)) 323 323 324 - #ifdef CONFIG_CFI_CLANG 325 - /* 326 - * With CONFIG_CFI_CLANG, the compiler replaces function address 327 - * references with the address of the function's CFI jump table 328 - * entry. The function_nocfi macro always returns the address of the 329 - * actual function instead. 330 - */ 331 - #define function_nocfi(x) ({ \ 332 - void *addr; \ 333 - asm("adrp %0, " __stringify(x) "\n\t" \ 334 - "add %0, %0, :lo12:" __stringify(x) \ 335 - : "=r" (addr)); \ 336 - addr; \ 337 - }) 338 - #endif 339 - 340 324 /* 341 325 * virt_to_page(x) convert a _valid_ virtual address to struct page * 342 326 * virt_addr_valid(x) indicates whether a virtual address is valid
+1
arch/s390/Kconfig
··· 117 117 select ARCH_USE_BUILTIN_BSWAP 118 118 select ARCH_USE_CMPXCHG_LOCKREF 119 119 select ARCH_WANTS_DYNAMIC_TASK_STRUCT 120 + select ARCH_WANTS_NO_INSTR 120 121 select ARCH_WANT_DEFAULT_BPF_JIT 121 122 select ARCH_WANT_IPC_PARSE_VERSION 122 123 select BUILDTIME_TABLE_SORT
+3 -2
arch/x86/Kconfig
··· 103 103 select ARCH_SUPPORTS_DEBUG_PAGEALLOC 104 104 select ARCH_SUPPORTS_NUMA_BALANCING if X86_64 105 105 select ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP if NR_CPUS <= 4096 106 - select ARCH_SUPPORTS_LTO_CLANG if X86_64 107 - select ARCH_SUPPORTS_LTO_CLANG_THIN if X86_64 106 + select ARCH_SUPPORTS_LTO_CLANG 107 + select ARCH_SUPPORTS_LTO_CLANG_THIN 108 108 select ARCH_USE_BUILTIN_BSWAP 109 109 select ARCH_USE_MEMTEST 110 110 select ARCH_USE_QUEUED_RWLOCKS ··· 113 113 select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH 114 114 select ARCH_WANT_DEFAULT_BPF_JIT if X86_64 115 115 select ARCH_WANTS_DYNAMIC_TASK_STRUCT 116 + select ARCH_WANTS_NO_INSTR 116 117 select ARCH_WANT_HUGE_PMD_SHARE 117 118 select ARCH_WANT_LD_ORPHAN_WARN 118 119 select ARCH_WANTS_THP_SWAP if X86_64
+3 -5
drivers/firmware/qemu_fw_cfg.c
··· 299 299 return 0; 300 300 } 301 301 302 - static ssize_t fw_cfg_showrev(struct kobject *k, struct attribute *a, char *buf) 302 + static ssize_t fw_cfg_showrev(struct kobject *k, struct kobj_attribute *a, 303 + char *buf) 303 304 { 304 305 return sprintf(buf, "%u\n", fw_cfg_rev); 305 306 } 306 307 307 - static const struct { 308 - struct attribute attr; 309 - ssize_t (*show)(struct kobject *k, struct attribute *a, char *buf); 310 - } fw_cfg_rev_attr = { 308 + static const struct kobj_attribute fw_cfg_rev_attr = { 311 309 .attr = { .name = "rev", .mode = S_IRUSR }, 312 310 .show = fw_cfg_showrev, 313 311 };
+10
include/linux/compiler.h
··· 219 219 __v; \ 220 220 }) 221 221 222 + /* 223 + * With CONFIG_CFI_CLANG, the compiler replaces function addresses in 224 + * instrumented C code with jump table addresses. Architectures that 225 + * support CFI can define this macro to return the actual function address 226 + * when needed. 227 + */ 228 + #ifndef function_nocfi 229 + #define function_nocfi(x) (x) 230 + #endif 231 + 222 232 #endif /* __KERNEL__ */ 223 233 224 234 /*
+16 -3
include/linux/compiler_attributes.h
··· 27 27 */ 28 28 #ifndef __has_attribute 29 29 # define __has_attribute(x) __GCC4_has_attribute_##x 30 - # define __GCC4_has_attribute___assume_aligned__ (__GNUC_MINOR__ >= 9) 30 + # define __GCC4_has_attribute___assume_aligned__ 1 31 31 # define __GCC4_has_attribute___copy__ 0 32 32 # define __GCC4_has_attribute___designated_init__ 0 33 33 # define __GCC4_has_attribute___externally_visible__ 1 34 34 # define __GCC4_has_attribute___no_caller_saved_registers__ 0 35 35 # define __GCC4_has_attribute___noclone__ 1 36 + # define __GCC4_has_attribute___no_profile_instrument_function__ 0 36 37 # define __GCC4_has_attribute___nonstring__ 0 37 - # define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) 38 - # define __GCC4_has_attribute___no_sanitize_undefined__ (__GNUC_MINOR__ >= 9) 38 + # define __GCC4_has_attribute___no_sanitize_address__ 1 39 + # define __GCC4_has_attribute___no_sanitize_undefined__ 1 39 40 # define __GCC4_has_attribute___fallthrough__ 0 40 41 #endif 41 42 ··· 237 236 # define __nonstring __attribute__((__nonstring__)) 238 237 #else 239 238 # define __nonstring 239 + #endif 240 + 241 + /* 242 + * Optional: only supported since GCC >= 7.1, clang >= 13.0. 243 + * 244 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fprofile_005finstrument_005ffunction-function-attribute 245 + * clang: https://clang.llvm.org/docs/AttributeReference.html#no-profile-instrument-function 246 + */ 247 + #if __has_attribute(__no_profile_instrument_function__) 248 + # define __no_profile __attribute__((__no_profile_instrument_function__)) 249 + #else 250 + # define __no_profile 240 251 #endif 241 252 242 253 /*
+1 -1
include/linux/compiler_types.h
··· 210 210 /* Section for code which can't be instrumented at all */ 211 211 #define noinstr \ 212 212 noinline notrace __attribute((__section__(".noinstr.text"))) \ 213 - __no_kcsan __no_sanitize_address 213 + __no_kcsan __no_sanitize_address __no_profile 214 214 215 215 #endif /* __KERNEL__ */ 216 216
-10
include/linux/mm.h
··· 125 125 #endif 126 126 127 127 /* 128 - * With CONFIG_CFI_CLANG, the compiler replaces function addresses in 129 - * instrumented C code with jump table addresses. Architectures that 130 - * support CFI can define this macro to return the actual function address 131 - * when needed. 132 - */ 133 - #ifndef function_nocfi 134 - #define function_nocfi(x) (x) 135 - #endif 136 - 137 - /* 138 128 * To prevent common memory management code establishing 139 129 * a zero page mapping on a read fault. 140 130 * This macro should be defined within <asm/pgtable.h>.
+3
init/Kconfig
··· 83 83 config CC_HAS_ASM_INLINE 84 84 def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null) 85 85 86 + config CC_HAS_NO_PROFILE_FN_ATTR 87 + def_bool $(success,echo '__attribute__((no_profile_instrument_function)) int x();' | $(CC) -x c - -c -o /dev/null -Werror) 88 + 86 89 config CONSTRUCTORS 87 90 bool 88 91
+1
kernel/gcov/Kconfig
··· 5 5 bool "Enable gcov-based kernel profiling" 6 6 depends on DEBUG_FS 7 7 depends on !CC_IS_CLANG || CLANG_VERSION >= 110000 8 + depends on !ARCH_WANTS_NO_INSTR || CC_HAS_NO_PROFILE_FN_ATTR 8 9 select CONSTRUCTORS 9 10 default n 10 11 help