Skip to content

Commit 44b6ed4

Browse files
committed
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
2 parents 4404621 + fca41af commit 44b6ed4

File tree

14 files changed

+74
-37
lines changed

14 files changed

+74
-37
lines changed

MAINTAINERS

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4447,6 +4447,18 @@ F: include/linux/compiler-clang.h
44474447
F: scripts/clang-tools/
44484448
K: \b(?i:clang|llvm)\b
44494449

4450+
CLANG CONTROL FLOW INTEGRITY SUPPORT
4451+
M: Sami Tolvanen <[email protected]>
4452+
M: Kees Cook <[email protected]>
4453+
R: Nathan Chancellor <[email protected]>
4454+
R: Nick Desaulniers <[email protected]>
4455+
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+
44504462
CLEANCACHE API
44514463
M: Konrad Rzeszutek Wilk <[email protected]>
44524464

arch/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ config ARCH_THREAD_STACK_ALLOCATOR
285285
config ARCH_WANTS_DYNAMIC_TASK_STRUCT
286286
bool
287287

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+
288295
config ARCH_32BIT_OFF_T
289296
bool
290297
depends on !64BIT

arch/arm64/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ config ARM64
9393
select ARCH_WANT_FRAME_POINTERS
9494
select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36)
9595
select ARCH_WANT_LD_ORPHAN_WARN
96+
select ARCH_WANTS_NO_INSTR
9697
select ARCH_HAS_UBSAN_SANITIZE_ALL
9798
select ARM_AMBA
9899
select ARM_ARCH_TIMER

arch/arm64/include/asm/compiler.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,20 @@
2323
#define __builtin_return_address(val) \
2424
(void *)(ptrauth_clear_pac((unsigned long)__builtin_return_address(val)))
2525

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+
2642
#endif /* __ASM_COMPILER_H */

arch/arm64/include/asm/memory.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -321,22 +321,6 @@ static inline void *phys_to_virt(phys_addr_t x)
321321
#define virt_to_pfn(x) __phys_to_pfn(__virt_to_phys((unsigned long)(x)))
322322
#define sym_to_pfn(x) __phys_to_pfn(__pa_symbol(x))
323323

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-
340324
/*
341325
* virt_to_page(x) convert a _valid_ virtual address to struct page *
342326
* virt_addr_valid(x) indicates whether a virtual address is valid

arch/s390/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ config S390
117117
select ARCH_USE_BUILTIN_BSWAP
118118
select ARCH_USE_CMPXCHG_LOCKREF
119119
select ARCH_WANTS_DYNAMIC_TASK_STRUCT
120+
select ARCH_WANTS_NO_INSTR
120121
select ARCH_WANT_DEFAULT_BPF_JIT
121122
select ARCH_WANT_IPC_PARSE_VERSION
122123
select BUILDTIME_TABLE_SORT

arch/x86/Kconfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ config X86
103103
select ARCH_SUPPORTS_DEBUG_PAGEALLOC
104104
select ARCH_SUPPORTS_NUMA_BALANCING if X86_64
105105
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
108108
select ARCH_USE_BUILTIN_BSWAP
109109
select ARCH_USE_MEMTEST
110110
select ARCH_USE_QUEUED_RWLOCKS
@@ -113,6 +113,7 @@ config X86
113113
select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
114114
select ARCH_WANT_DEFAULT_BPF_JIT if X86_64
115115
select ARCH_WANTS_DYNAMIC_TASK_STRUCT
116+
select ARCH_WANTS_NO_INSTR
116117
select ARCH_WANT_HUGE_PMD_SHARE
117118
select ARCH_WANT_LD_ORPHAN_WARN
118119
select ARCH_WANTS_THP_SWAP if X86_64

drivers/firmware/qemu_fw_cfg.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)
299299
return 0;
300300
}
301301

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)
303304
{
304305
return sprintf(buf, "%u\n", fw_cfg_rev);
305306
}
306307

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 = {
311309
.attr = { .name = "rev", .mode = S_IRUSR },
312310
.show = fw_cfg_showrev,
313311
};

include/linux/compiler.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
219219
__v; \
220220
})
221221

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+
222232
#endif /* __KERNEL__ */
223233

224234
/*

include/linux/compiler_attributes.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@
2727
*/
2828
#ifndef __has_attribute
2929
# 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
3131
# define __GCC4_has_attribute___copy__ 0
3232
# define __GCC4_has_attribute___designated_init__ 0
3333
# define __GCC4_has_attribute___externally_visible__ 1
3434
# define __GCC4_has_attribute___no_caller_saved_registers__ 0
3535
# define __GCC4_has_attribute___noclone__ 1
36+
# define __GCC4_has_attribute___no_profile_instrument_function__ 0
3637
# 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
3940
# define __GCC4_has_attribute___fallthrough__ 0
4041
#endif
4142

@@ -238,6 +239,18 @@
238239
# define __nonstring
239240
#endif
240241

242+
/*
243+
* Optional: only supported since GCC >= 7.1, clang >= 13.0.
244+
*
245+
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fprofile_005finstrument_005ffunction-function-attribute
246+
* clang: https://clang.llvm.org/docs/AttributeReference.html#no-profile-instrument-function
247+
*/
248+
#if __has_attribute(__no_profile_instrument_function__)
249+
# define __no_profile __attribute__((__no_profile_instrument_function__))
250+
#else
251+
# define __no_profile
252+
#endif
253+
241254
/*
242255
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute
243256
* clang: https://clang.llvm.org/docs/AttributeReference.html#noreturn

0 commit comments

Comments
 (0)