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

asm-generic/bitops: Always inline all bit manipulation helpers

Make it consistent with the atomic/atomic-instrumented.h helpers.

And defconfig size is actually going down!

text data bss dec hex filename
22352096 8213152 1917164 32482412 1efa46c vmlinux.x86-64.defconfig.before
22350551 8213184 1917164 32480899 1ef9e83 vmlinux.x86-64.defconfig.after

Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Marco Elver <elver@google.com>
Link: https://lore.kernel.org/r/20220113155357.4706-2-bp@alien8.de

authored by

Borislav Petkov and committed by
Peter Zijlstra
acb13ea0 61cc4534

+14 -14
+6 -6
include/asm-generic/bitops/instrumented-atomic.h
··· 23 23 * Note that @nr may be almost arbitrarily large; this function is not 24 24 * restricted to acting on a single-word quantity. 25 25 */ 26 - static inline void set_bit(long nr, volatile unsigned long *addr) 26 + static __always_inline void set_bit(long nr, volatile unsigned long *addr) 27 27 { 28 28 instrument_atomic_write(addr + BIT_WORD(nr), sizeof(long)); 29 29 arch_set_bit(nr, addr); ··· 36 36 * 37 37 * This is a relaxed atomic operation (no implied memory barriers). 38 38 */ 39 - static inline void clear_bit(long nr, volatile unsigned long *addr) 39 + static __always_inline void clear_bit(long nr, volatile unsigned long *addr) 40 40 { 41 41 instrument_atomic_write(addr + BIT_WORD(nr), sizeof(long)); 42 42 arch_clear_bit(nr, addr); ··· 52 52 * Note that @nr may be almost arbitrarily large; this function is not 53 53 * restricted to acting on a single-word quantity. 54 54 */ 55 - static inline void change_bit(long nr, volatile unsigned long *addr) 55 + static __always_inline void change_bit(long nr, volatile unsigned long *addr) 56 56 { 57 57 instrument_atomic_write(addr + BIT_WORD(nr), sizeof(long)); 58 58 arch_change_bit(nr, addr); ··· 65 65 * 66 66 * This is an atomic fully-ordered operation (implied full memory barrier). 67 67 */ 68 - static inline bool test_and_set_bit(long nr, volatile unsigned long *addr) 68 + static __always_inline bool test_and_set_bit(long nr, volatile unsigned long *addr) 69 69 { 70 70 kcsan_mb(); 71 71 instrument_atomic_read_write(addr + BIT_WORD(nr), sizeof(long)); ··· 79 79 * 80 80 * This is an atomic fully-ordered operation (implied full memory barrier). 81 81 */ 82 - static inline bool test_and_clear_bit(long nr, volatile unsigned long *addr) 82 + static __always_inline bool test_and_clear_bit(long nr, volatile unsigned long *addr) 83 83 { 84 84 kcsan_mb(); 85 85 instrument_atomic_read_write(addr + BIT_WORD(nr), sizeof(long)); ··· 93 93 * 94 94 * This is an atomic fully-ordered operation (implied full memory barrier). 95 95 */ 96 - static inline bool test_and_change_bit(long nr, volatile unsigned long *addr) 96 + static __always_inline bool test_and_change_bit(long nr, volatile unsigned long *addr) 97 97 { 98 98 kcsan_mb(); 99 99 instrument_atomic_read_write(addr + BIT_WORD(nr), sizeof(long));
+8 -8
include/asm-generic/bitops/instrumented-non-atomic.h
··· 22 22 * region of memory concurrently, the effect may be that only one operation 23 23 * succeeds. 24 24 */ 25 - static inline void __set_bit(long nr, volatile unsigned long *addr) 25 + static __always_inline void __set_bit(long nr, volatile unsigned long *addr) 26 26 { 27 27 instrument_write(addr + BIT_WORD(nr), sizeof(long)); 28 28 arch___set_bit(nr, addr); ··· 37 37 * region of memory concurrently, the effect may be that only one operation 38 38 * succeeds. 39 39 */ 40 - static inline void __clear_bit(long nr, volatile unsigned long *addr) 40 + static __always_inline void __clear_bit(long nr, volatile unsigned long *addr) 41 41 { 42 42 instrument_write(addr + BIT_WORD(nr), sizeof(long)); 43 43 arch___clear_bit(nr, addr); ··· 52 52 * region of memory concurrently, the effect may be that only one operation 53 53 * succeeds. 54 54 */ 55 - static inline void __change_bit(long nr, volatile unsigned long *addr) 55 + static __always_inline void __change_bit(long nr, volatile unsigned long *addr) 56 56 { 57 57 instrument_write(addr + BIT_WORD(nr), sizeof(long)); 58 58 arch___change_bit(nr, addr); 59 59 } 60 60 61 - static inline void __instrument_read_write_bitop(long nr, volatile unsigned long *addr) 61 + static __always_inline void __instrument_read_write_bitop(long nr, volatile unsigned long *addr) 62 62 { 63 63 if (IS_ENABLED(CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC)) { 64 64 /* ··· 90 90 * This operation is non-atomic. If two instances of this operation race, one 91 91 * can appear to succeed but actually fail. 92 92 */ 93 - static inline bool __test_and_set_bit(long nr, volatile unsigned long *addr) 93 + static __always_inline bool __test_and_set_bit(long nr, volatile unsigned long *addr) 94 94 { 95 95 __instrument_read_write_bitop(nr, addr); 96 96 return arch___test_and_set_bit(nr, addr); ··· 104 104 * This operation is non-atomic. If two instances of this operation race, one 105 105 * can appear to succeed but actually fail. 106 106 */ 107 - static inline bool __test_and_clear_bit(long nr, volatile unsigned long *addr) 107 + static __always_inline bool __test_and_clear_bit(long nr, volatile unsigned long *addr) 108 108 { 109 109 __instrument_read_write_bitop(nr, addr); 110 110 return arch___test_and_clear_bit(nr, addr); ··· 118 118 * This operation is non-atomic. If two instances of this operation race, one 119 119 * can appear to succeed but actually fail. 120 120 */ 121 - static inline bool __test_and_change_bit(long nr, volatile unsigned long *addr) 121 + static __always_inline bool __test_and_change_bit(long nr, volatile unsigned long *addr) 122 122 { 123 123 __instrument_read_write_bitop(nr, addr); 124 124 return arch___test_and_change_bit(nr, addr); ··· 129 129 * @nr: bit number to test 130 130 * @addr: Address to start counting from 131 131 */ 132 - static inline bool test_bit(long nr, const volatile unsigned long *addr) 132 + static __always_inline bool test_bit(long nr, const volatile unsigned long *addr) 133 133 { 134 134 instrument_atomic_read(addr + BIT_WORD(nr), sizeof(long)); 135 135 return arch_test_bit(nr, addr);