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

Merge tag 'bitmap-6.0-rc1' of https://github.com/norov/linux

Pull bitmap updates from Yury Norov:

- fix the duplicated comments on bitmap_to_arr64() (Qu Wenruo)

- optimize out non-atomic bitops on compile-time constants (Alexander
Lobakin)

- cleanup bitmap-related headers (Yury Norov)

- x86/olpc: fix 'logical not is only applied to the left hand side'
(Alexander Lobakin)

- lib/nodemask: inline wrappers around bitmap (Yury Norov)

* tag 'bitmap-6.0-rc1' of https://github.com/norov/linux: (26 commits)
lib/nodemask: inline next_node_in() and node_random()
powerpc: drop dependency on <asm/machdep.h> in archrandom.h
x86/olpc: fix 'logical not is only applied to the left hand side'
lib/cpumask: move some one-line wrappers to header file
headers/deps: mm: align MANITAINERS and Docs with new gfp.h structure
headers/deps: mm: Split <linux/gfp_types.h> out of <linux/gfp.h>
headers/deps: mm: Optimize <linux/gfp.h> header dependencies
lib/cpumask: move trivial wrappers around find_bit to the header
lib/cpumask: change return types to unsigned where appropriate
cpumask: change return types to bool where appropriate
lib/bitmap: change type of bitmap_weight to unsigned long
lib/bitmap: change return types to bool where appropriate
arm: align find_bit declarations with generic kernel
iommu/vt-d: avoid invalid memory access via node_online(NUMA_NO_NODE)
lib/test_bitmap: test the tail after bitmap_to_arr64()
lib/bitmap: fix off-by-one in bitmap_to_arr64()
lib: test_bitmap: add compile-time optimization/evaluations assertions
bitmap: don't assume compiler evaluates small mem*() builtins calls
net/ice: fix initializing the bitmap in the switch code
bitops: let optimize out non-atomic bitops on compile-time constants
...

+1077 -790
+4 -4
Documentation/core-api/mm-api.rst
··· 22 22 .. kernel-doc:: include/linux/gfp.h 23 23 :internal: 24 24 25 - .. kernel-doc:: include/linux/gfp.h 25 + .. kernel-doc:: include/linux/gfp_types.h 26 26 :doc: Page mobility and placement hints 27 27 28 - .. kernel-doc:: include/linux/gfp.h 28 + .. kernel-doc:: include/linux/gfp_types.h 29 29 :doc: Watermark modifiers 30 30 31 - .. kernel-doc:: include/linux/gfp.h 31 + .. kernel-doc:: include/linux/gfp_types.h 32 32 :doc: Reclaim modifiers 33 33 34 - .. kernel-doc:: include/linux/gfp.h 34 + .. kernel-doc:: include/linux/gfp_types.h 35 35 :doc: Useful GFP flag combinations 36 36 37 37 The Slab Cache
+1 -1
MAINTAINERS
··· 3603 3603 F: lib/cpumask.c 3604 3604 F: lib/find_bit.c 3605 3605 F: lib/find_bit_benchmark.c 3606 - F: lib/nodemask.c 3607 3606 F: lib/test_bitmap.c 3608 3607 F: tools/include/linux/bitmap.h 3609 3608 F: tools/include/linux/find.h ··· 13135 13136 T: git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm 13136 13137 T: quilt git://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new 13137 13138 F: include/linux/gfp.h 13139 + F: include/linux/gfp_types.h 13138 13140 F: include/linux/memory_hotplug.h 13139 13141 F: include/linux/mm.h 13140 13142 F: include/linux/mmzone.h
+17 -15
arch/alpha/include/asm/bitops.h
··· 46 46 /* 47 47 * WARNING: non atomic version. 48 48 */ 49 - static inline void 50 - __set_bit(unsigned long nr, volatile void * addr) 49 + static __always_inline void 50 + arch___set_bit(unsigned long nr, volatile unsigned long *addr) 51 51 { 52 52 int *m = ((int *) addr) + (nr >> 5); 53 53 ··· 82 82 /* 83 83 * WARNING: non atomic version. 84 84 */ 85 - static __inline__ void 86 - __clear_bit(unsigned long nr, volatile void * addr) 85 + static __always_inline void 86 + arch___clear_bit(unsigned long nr, volatile unsigned long *addr) 87 87 { 88 88 int *m = ((int *) addr) + (nr >> 5); 89 89 ··· 94 94 __clear_bit_unlock(unsigned long nr, volatile void * addr) 95 95 { 96 96 smp_mb(); 97 - __clear_bit(nr, addr); 97 + arch___clear_bit(nr, addr); 98 98 } 99 99 100 100 static inline void ··· 118 118 /* 119 119 * WARNING: non atomic version. 120 120 */ 121 - static __inline__ void 122 - __change_bit(unsigned long nr, volatile void * addr) 121 + static __always_inline void 122 + arch___change_bit(unsigned long nr, volatile unsigned long *addr) 123 123 { 124 124 int *m = ((int *) addr) + (nr >> 5); 125 125 ··· 186 186 /* 187 187 * WARNING: non atomic version. 188 188 */ 189 - static inline int 190 - __test_and_set_bit(unsigned long nr, volatile void * addr) 189 + static __always_inline bool 190 + arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr) 191 191 { 192 192 unsigned long mask = 1 << (nr & 0x1f); 193 193 int *m = ((int *) addr) + (nr >> 5); ··· 230 230 /* 231 231 * WARNING: non atomic version. 232 232 */ 233 - static inline int 234 - __test_and_clear_bit(unsigned long nr, volatile void * addr) 233 + static __always_inline bool 234 + arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) 235 235 { 236 236 unsigned long mask = 1 << (nr & 0x1f); 237 237 int *m = ((int *) addr) + (nr >> 5); ··· 272 272 /* 273 273 * WARNING: non atomic version. 274 274 */ 275 - static __inline__ int 276 - __test_and_change_bit(unsigned long nr, volatile void * addr) 275 + static __always_inline bool 276 + arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr) 277 277 { 278 278 unsigned long mask = 1 << (nr & 0x1f); 279 279 int *m = ((int *) addr) + (nr >> 5); ··· 283 283 return (old & mask) != 0; 284 284 } 285 285 286 - static inline int 287 - test_bit(int nr, const volatile void * addr) 286 + static __always_inline bool 287 + arch_test_bit(unsigned long nr, const volatile unsigned long *addr) 288 288 { 289 289 return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) != 0UL; 290 290 } ··· 449 449 450 450 return __ffs(tmp) + ofs; 451 451 } 452 + 453 + #include <asm-generic/bitops/non-instrumented-non-atomic.h> 452 454 453 455 #include <asm-generic/bitops/le.h> 454 456
+10 -8
arch/arm/include/asm/bitops.h
··· 160 160 /* 161 161 * Little endian assembly bitops. nr = 0 -> byte 0 bit 0. 162 162 */ 163 - extern int _find_first_zero_bit_le(const unsigned long *p, unsigned size); 164 - extern int _find_next_zero_bit_le(const unsigned long *p, int size, int offset); 165 - extern int _find_first_bit_le(const unsigned long *p, unsigned size); 166 - extern int _find_next_bit_le(const unsigned long *p, int size, int offset); 163 + unsigned long _find_first_zero_bit_le(const unsigned long *p, unsigned long size); 164 + unsigned long _find_next_zero_bit_le(const unsigned long *p, 165 + unsigned long size, unsigned long offset); 166 + unsigned long _find_first_bit_le(const unsigned long *p, unsigned long size); 167 + unsigned long _find_next_bit_le(const unsigned long *p, unsigned long size, unsigned long offset); 167 168 168 169 /* 169 170 * Big endian assembly bitops. nr = 0 -> byte 3 bit 0. 170 171 */ 171 - extern int _find_first_zero_bit_be(const unsigned long *p, unsigned size); 172 - extern int _find_next_zero_bit_be(const unsigned long *p, int size, int offset); 173 - extern int _find_first_bit_be(const unsigned long *p, unsigned size); 174 - extern int _find_next_bit_be(const unsigned long *p, int size, int offset); 172 + unsigned long _find_first_zero_bit_be(const unsigned long *p, unsigned long size); 173 + unsigned long _find_next_zero_bit_be(const unsigned long *p, 174 + unsigned long size, unsigned long offset); 175 + unsigned long _find_first_bit_be(const unsigned long *p, unsigned long size); 176 + unsigned long _find_next_bit_be(const unsigned long *p, unsigned long size, unsigned long offset); 175 177 176 178 #ifndef CONFIG_SMP 177 179 /*
+15 -9
arch/hexagon/include/asm/bitops.h
··· 127 127 * be atomic, particularly for things like slab_lock and slab_unlock. 128 128 * 129 129 */ 130 - static inline void __clear_bit(int nr, volatile unsigned long *addr) 130 + static __always_inline void 131 + arch___clear_bit(unsigned long nr, volatile unsigned long *addr) 131 132 { 132 133 test_and_clear_bit(nr, addr); 133 134 } 134 135 135 - static inline void __set_bit(int nr, volatile unsigned long *addr) 136 + static __always_inline void 137 + arch___set_bit(unsigned long nr, volatile unsigned long *addr) 136 138 { 137 139 test_and_set_bit(nr, addr); 138 140 } 139 141 140 - static inline void __change_bit(int nr, volatile unsigned long *addr) 142 + static __always_inline void 143 + arch___change_bit(unsigned long nr, volatile unsigned long *addr) 141 144 { 142 145 test_and_change_bit(nr, addr); 143 146 } 144 147 145 148 /* Apparently, at least some of these are allowed to be non-atomic */ 146 - static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) 149 + static __always_inline bool 150 + arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) 147 151 { 148 152 return test_and_clear_bit(nr, addr); 149 153 } 150 154 151 - static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) 155 + static __always_inline bool 156 + arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr) 152 157 { 153 158 return test_and_set_bit(nr, addr); 154 159 } 155 160 156 - static inline int __test_and_change_bit(int nr, volatile unsigned long *addr) 161 + static __always_inline bool 162 + arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr) 157 163 { 158 164 return test_and_change_bit(nr, addr); 159 165 } 160 166 161 - static inline int __test_bit(int nr, const volatile unsigned long *addr) 167 + static __always_inline bool 168 + arch_test_bit(unsigned long nr, const volatile unsigned long *addr) 162 169 { 163 170 int retval; 164 171 ··· 178 171 179 172 return retval; 180 173 } 181 - 182 - #define test_bit(nr, addr) __test_bit(nr, addr) 183 174 184 175 /* 185 176 * ffz - find first zero in word. ··· 276 271 } 277 272 278 273 #include <asm-generic/bitops/lock.h> 274 + #include <asm-generic/bitops/non-instrumented-non-atomic.h> 279 275 280 276 #include <asm-generic/bitops/fls64.h> 281 277 #include <asm-generic/bitops/sched.h>
+22 -20
arch/ia64/include/asm/bitops.h
··· 53 53 } 54 54 55 55 /** 56 - * __set_bit - Set a bit in memory 56 + * arch___set_bit - Set a bit in memory 57 57 * @nr: the bit to set 58 58 * @addr: the address to start counting from 59 59 * ··· 61 61 * If it's called on the same region of memory simultaneously, the effect 62 62 * may be that only one operation succeeds. 63 63 */ 64 - static __inline__ void 65 - __set_bit (int nr, volatile void *addr) 64 + static __always_inline void 65 + arch___set_bit(unsigned long nr, volatile unsigned long *addr) 66 66 { 67 67 *((__u32 *) addr + (nr >> 5)) |= (1 << (nr & 31)); 68 68 } ··· 135 135 } 136 136 137 137 /** 138 - * __clear_bit - Clears a bit in memory (non-atomic version) 138 + * arch___clear_bit - Clears a bit in memory (non-atomic version) 139 139 * @nr: the bit to clear 140 140 * @addr: the address to start counting from 141 141 * ··· 143 143 * If it's called on the same region of memory simultaneously, the effect 144 144 * may be that only one operation succeeds. 145 145 */ 146 - static __inline__ void 147 - __clear_bit (int nr, volatile void *addr) 146 + static __always_inline void 147 + arch___clear_bit(unsigned long nr, volatile unsigned long *addr) 148 148 { 149 149 *((__u32 *) addr + (nr >> 5)) &= ~(1 << (nr & 31)); 150 150 } ··· 175 175 } 176 176 177 177 /** 178 - * __change_bit - Toggle a bit in memory 178 + * arch___change_bit - Toggle a bit in memory 179 179 * @nr: the bit to toggle 180 180 * @addr: the address to start counting from 181 181 * ··· 183 183 * If it's called on the same region of memory simultaneously, the effect 184 184 * may be that only one operation succeeds. 185 185 */ 186 - static __inline__ void 187 - __change_bit (int nr, volatile void *addr) 186 + static __always_inline void 187 + arch___change_bit(unsigned long nr, volatile unsigned long *addr) 188 188 { 189 189 *((__u32 *) addr + (nr >> 5)) ^= (1 << (nr & 31)); 190 190 } ··· 224 224 #define test_and_set_bit_lock test_and_set_bit 225 225 226 226 /** 227 - * __test_and_set_bit - Set a bit and return its old value 227 + * arch___test_and_set_bit - Set a bit and return its old value 228 228 * @nr: Bit to set 229 229 * @addr: Address to count from 230 230 * ··· 232 232 * If two examples of this operation race, one can appear to succeed 233 233 * but actually fail. You must protect multiple accesses with a lock. 234 234 */ 235 - static __inline__ int 236 - __test_and_set_bit (int nr, volatile void *addr) 235 + static __always_inline bool 236 + arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr) 237 237 { 238 238 __u32 *p = (__u32 *) addr + (nr >> 5); 239 239 __u32 m = 1 << (nr & 31); ··· 269 269 } 270 270 271 271 /** 272 - * __test_and_clear_bit - Clear a bit and return its old value 272 + * arch___test_and_clear_bit - Clear a bit and return its old value 273 273 * @nr: Bit to clear 274 274 * @addr: Address to count from 275 275 * ··· 277 277 * If two examples of this operation race, one can appear to succeed 278 278 * but actually fail. You must protect multiple accesses with a lock. 279 279 */ 280 - static __inline__ int 281 - __test_and_clear_bit(int nr, volatile void * addr) 280 + static __always_inline bool 281 + arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) 282 282 { 283 283 __u32 *p = (__u32 *) addr + (nr >> 5); 284 284 __u32 m = 1 << (nr & 31); ··· 314 314 } 315 315 316 316 /** 317 - * __test_and_change_bit - Change a bit and return its old value 317 + * arch___test_and_change_bit - Change a bit and return its old value 318 318 * @nr: Bit to change 319 319 * @addr: Address to count from 320 320 * 321 321 * This operation is non-atomic and can be reordered. 322 322 */ 323 - static __inline__ int 324 - __test_and_change_bit (int nr, void *addr) 323 + static __always_inline bool 324 + arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr) 325 325 { 326 326 __u32 old, bit = (1 << (nr & 31)); 327 327 __u32 *m = (__u32 *) addr + (nr >> 5); ··· 331 331 return (old & bit) != 0; 332 332 } 333 333 334 - static __inline__ int 335 - test_bit (int nr, const volatile void *addr) 334 + static __always_inline bool 335 + arch_test_bit(unsigned long nr, const volatile unsigned long *addr) 336 336 { 337 337 return 1 & (((const volatile __u32 *) addr)[nr >> 5] >> (nr & 31)); 338 338 } ··· 442 442 #endif /* __KERNEL__ */ 443 443 444 444 #ifdef __KERNEL__ 445 + 446 + #include <asm-generic/bitops/non-instrumented-non-atomic.h> 445 447 446 448 #include <asm-generic/bitops/le.h> 447 449
+1 -1
arch/ia64/include/asm/processor.h
··· 538 538 { 539 539 unsigned int reg = vector / 64; 540 540 unsigned int bit = vector % 64; 541 - u64 irr; 541 + unsigned long irr; 542 542 543 543 switch (reg) { 544 544 case 0: irr = ia64_getreg(_IA64_REG_CR_IRR0); break;
+34 -15
arch/m68k/include/asm/bitops.h
··· 65 65 bfset_mem_set_bit(nr, vaddr)) 66 66 #endif 67 67 68 - #define __set_bit(nr, vaddr) set_bit(nr, vaddr) 69 - 68 + static __always_inline void 69 + arch___set_bit(unsigned long nr, volatile unsigned long *addr) 70 + { 71 + set_bit(nr, addr); 72 + } 70 73 71 74 static inline void bclr_reg_clear_bit(int nr, volatile unsigned long *vaddr) 72 75 { ··· 108 105 bfclr_mem_clear_bit(nr, vaddr)) 109 106 #endif 110 107 111 - #define __clear_bit(nr, vaddr) clear_bit(nr, vaddr) 112 - 108 + static __always_inline void 109 + arch___clear_bit(unsigned long nr, volatile unsigned long *addr) 110 + { 111 + clear_bit(nr, addr); 112 + } 113 113 114 114 static inline void bchg_reg_change_bit(int nr, volatile unsigned long *vaddr) 115 115 { ··· 151 145 bfchg_mem_change_bit(nr, vaddr)) 152 146 #endif 153 147 154 - #define __change_bit(nr, vaddr) change_bit(nr, vaddr) 155 - 156 - 157 - static inline int test_bit(int nr, const volatile unsigned long *vaddr) 148 + static __always_inline void 149 + arch___change_bit(unsigned long nr, volatile unsigned long *addr) 158 150 { 159 - return (vaddr[nr >> 5] & (1UL << (nr & 31))) != 0; 151 + change_bit(nr, addr); 160 152 } 161 153 154 + static __always_inline bool 155 + arch_test_bit(unsigned long nr, const volatile unsigned long *addr) 156 + { 157 + return (addr[nr >> 5] & (1UL << (nr & 31))) != 0; 158 + } 162 159 163 160 static inline int bset_reg_test_and_set_bit(int nr, 164 161 volatile unsigned long *vaddr) ··· 210 201 bfset_mem_test_and_set_bit(nr, vaddr)) 211 202 #endif 212 203 213 - #define __test_and_set_bit(nr, vaddr) test_and_set_bit(nr, vaddr) 214 - 204 + static __always_inline bool 205 + arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr) 206 + { 207 + return test_and_set_bit(nr, addr); 208 + } 215 209 216 210 static inline int bclr_reg_test_and_clear_bit(int nr, 217 211 volatile unsigned long *vaddr) ··· 263 251 bfclr_mem_test_and_clear_bit(nr, vaddr)) 264 252 #endif 265 253 266 - #define __test_and_clear_bit(nr, vaddr) test_and_clear_bit(nr, vaddr) 267 - 254 + static __always_inline bool 255 + arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) 256 + { 257 + return test_and_clear_bit(nr, addr); 258 + } 268 259 269 260 static inline int bchg_reg_test_and_change_bit(int nr, 270 261 volatile unsigned long *vaddr) ··· 316 301 bfchg_mem_test_and_change_bit(nr, vaddr)) 317 302 #endif 318 303 319 - #define __test_and_change_bit(nr, vaddr) test_and_change_bit(nr, vaddr) 320 - 304 + static __always_inline bool 305 + arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr) 306 + { 307 + return test_and_change_bit(nr, addr); 308 + } 321 309 322 310 /* 323 311 * The true 68020 and more advanced processors support the "bfffo" ··· 540 522 #define clear_bit_unlock clear_bit 541 523 #define __clear_bit_unlock clear_bit_unlock 542 524 525 + #include <asm-generic/bitops/non-instrumented-non-atomic.h> 543 526 #include <asm-generic/bitops/ext2-atomic.h> 544 527 #include <asm-generic/bitops/fls64.h> 545 528 #include <asm-generic/bitops/sched.h>
+1 -8
arch/powerpc/include/asm/archrandom.h
··· 2 2 #ifndef _ASM_POWERPC_ARCHRANDOM_H 3 3 #define _ASM_POWERPC_ARCHRANDOM_H 4 4 5 - #include <asm/machdep.h> 6 - 7 5 static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs) 8 6 { 9 7 return 0; 10 8 } 11 9 12 - static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs) 13 - { 14 - if (max_longs && ppc_md.get_random_seed && ppc_md.get_random_seed(v)) 15 - return 1; 16 - return 0; 17 - } 10 + size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs); 18 11 19 12 #ifdef CONFIG_PPC_POWERNV 20 13 int pnv_get_random_long(unsigned long *v);
+8
arch/powerpc/kernel/setup-common.c
··· 171 171 void (*pm_power_off)(void); 172 172 EXPORT_SYMBOL_GPL(pm_power_off); 173 173 174 + size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs) 175 + { 176 + if (max_longs && ppc_md.get_random_seed && ppc_md.get_random_seed(v)) 177 + return 1; 178 + return 0; 179 + } 180 + EXPORT_SYMBOL(arch_get_random_seed_longs); 181 + 174 182 void machine_halt(void) 175 183 { 176 184 machine_shutdown();
+31 -30
arch/s390/include/asm/bitops.h
··· 113 113 return old & mask; 114 114 } 115 115 116 - static inline void arch___set_bit(unsigned long nr, volatile unsigned long *ptr) 116 + static __always_inline void 117 + arch___set_bit(unsigned long nr, volatile unsigned long *addr) 117 118 { 118 - unsigned long *addr = __bitops_word(nr, ptr); 119 + unsigned long *p = __bitops_word(nr, addr); 119 120 unsigned long mask = __bitops_mask(nr); 120 121 121 - *addr |= mask; 122 + *p |= mask; 122 123 } 123 124 124 - static inline void arch___clear_bit(unsigned long nr, 125 - volatile unsigned long *ptr) 125 + static __always_inline void 126 + arch___clear_bit(unsigned long nr, volatile unsigned long *addr) 126 127 { 127 - unsigned long *addr = __bitops_word(nr, ptr); 128 + unsigned long *p = __bitops_word(nr, addr); 128 129 unsigned long mask = __bitops_mask(nr); 129 130 130 - *addr &= ~mask; 131 + *p &= ~mask; 131 132 } 132 133 133 - static inline void arch___change_bit(unsigned long nr, 134 - volatile unsigned long *ptr) 134 + static __always_inline void 135 + arch___change_bit(unsigned long nr, volatile unsigned long *addr) 135 136 { 136 - unsigned long *addr = __bitops_word(nr, ptr); 137 + unsigned long *p = __bitops_word(nr, addr); 137 138 unsigned long mask = __bitops_mask(nr); 138 139 139 - *addr ^= mask; 140 + *p ^= mask; 140 141 } 141 142 142 - static inline bool arch___test_and_set_bit(unsigned long nr, 143 - volatile unsigned long *ptr) 143 + static __always_inline bool 144 + arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr) 144 145 { 145 - unsigned long *addr = __bitops_word(nr, ptr); 146 + unsigned long *p = __bitops_word(nr, addr); 146 147 unsigned long mask = __bitops_mask(nr); 147 148 unsigned long old; 148 149 149 - old = *addr; 150 - *addr |= mask; 150 + old = *p; 151 + *p |= mask; 151 152 return old & mask; 152 153 } 153 154 154 - static inline bool arch___test_and_clear_bit(unsigned long nr, 155 - volatile unsigned long *ptr) 155 + static __always_inline bool 156 + arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) 156 157 { 157 - unsigned long *addr = __bitops_word(nr, ptr); 158 + unsigned long *p = __bitops_word(nr, addr); 158 159 unsigned long mask = __bitops_mask(nr); 159 160 unsigned long old; 160 161 161 - old = *addr; 162 - *addr &= ~mask; 162 + old = *p; 163 + *p &= ~mask; 163 164 return old & mask; 164 165 } 165 166 166 - static inline bool arch___test_and_change_bit(unsigned long nr, 167 - volatile unsigned long *ptr) 167 + static __always_inline bool 168 + arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr) 168 169 { 169 - unsigned long *addr = __bitops_word(nr, ptr); 170 + unsigned long *p = __bitops_word(nr, addr); 170 171 unsigned long mask = __bitops_mask(nr); 171 172 unsigned long old; 172 173 173 - old = *addr; 174 - *addr ^= mask; 174 + old = *p; 175 + *p ^= mask; 175 176 return old & mask; 176 177 } 177 178 178 - static inline bool arch_test_bit(unsigned long nr, 179 - const volatile unsigned long *ptr) 179 + static __always_inline bool 180 + arch_test_bit(unsigned long nr, const volatile unsigned long *addr) 180 181 { 181 - const volatile unsigned long *addr = __bitops_word(nr, ptr); 182 + const volatile unsigned long *p = __bitops_word(nr, addr); 182 183 unsigned long mask = __bitops_mask(nr); 183 184 184 - return *addr & mask; 185 + return *p & mask; 185 186 } 186 187 187 188 static inline bool arch_test_and_set_bit_lock(unsigned long nr,
+22 -12
arch/sh/include/asm/bitops-op32.h
··· 2 2 #ifndef __ASM_SH_BITOPS_OP32_H 3 3 #define __ASM_SH_BITOPS_OP32_H 4 4 5 + #include <linux/bits.h> 6 + 5 7 /* 6 8 * The bit modifying instructions on SH-2A are only capable of working 7 9 * with a 3-bit immediate, which signifies the shift position for the bit ··· 18 16 #define BYTE_OFFSET(nr) ((nr) % BITS_PER_BYTE) 19 17 #endif 20 18 21 - static inline void __set_bit(int nr, volatile unsigned long *addr) 19 + static __always_inline void 20 + arch___set_bit(unsigned long nr, volatile unsigned long *addr) 22 21 { 23 22 if (__builtin_constant_p(nr)) { 24 23 __asm__ __volatile__ ( ··· 36 33 } 37 34 } 38 35 39 - static inline void __clear_bit(int nr, volatile unsigned long *addr) 36 + static __always_inline void 37 + arch___clear_bit(unsigned long nr, volatile unsigned long *addr) 40 38 { 41 39 if (__builtin_constant_p(nr)) { 42 40 __asm__ __volatile__ ( ··· 56 52 } 57 53 58 54 /** 59 - * __change_bit - Toggle a bit in memory 55 + * arch___change_bit - Toggle a bit in memory 60 56 * @nr: the bit to change 61 57 * @addr: the address to start counting from 62 58 * ··· 64 60 * If it's called on the same region of memory simultaneously, the effect 65 61 * may be that only one operation succeeds. 66 62 */ 67 - static inline void __change_bit(int nr, volatile unsigned long *addr) 63 + static __always_inline void 64 + arch___change_bit(unsigned long nr, volatile unsigned long *addr) 68 65 { 69 66 if (__builtin_constant_p(nr)) { 70 67 __asm__ __volatile__ ( ··· 84 79 } 85 80 86 81 /** 87 - * __test_and_set_bit - Set a bit and return its old value 82 + * arch___test_and_set_bit - Set a bit and return its old value 88 83 * @nr: Bit to set 89 84 * @addr: Address to count from 90 85 * ··· 92 87 * If two examples of this operation race, one can appear to succeed 93 88 * but actually fail. You must protect multiple accesses with a lock. 94 89 */ 95 - static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) 90 + static __always_inline bool 91 + arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr) 96 92 { 97 93 unsigned long mask = BIT_MASK(nr); 98 94 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); ··· 104 98 } 105 99 106 100 /** 107 - * __test_and_clear_bit - Clear a bit and return its old value 101 + * arch___test_and_clear_bit - Clear a bit and return its old value 108 102 * @nr: Bit to clear 109 103 * @addr: Address to count from 110 104 * ··· 112 106 * If two examples of this operation race, one can appear to succeed 113 107 * but actually fail. You must protect multiple accesses with a lock. 114 108 */ 115 - static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) 109 + static __always_inline bool 110 + arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) 116 111 { 117 112 unsigned long mask = BIT_MASK(nr); 118 113 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); ··· 124 117 } 125 118 126 119 /* WARNING: non atomic and it can be reordered! */ 127 - static inline int __test_and_change_bit(int nr, 128 - volatile unsigned long *addr) 120 + static __always_inline bool 121 + arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr) 129 122 { 130 123 unsigned long mask = BIT_MASK(nr); 131 124 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); ··· 136 129 } 137 130 138 131 /** 139 - * test_bit - Determine whether a bit is set 132 + * arch_test_bit - Determine whether a bit is set 140 133 * @nr: bit number to test 141 134 * @addr: Address to start counting from 142 135 */ 143 - static inline int test_bit(int nr, const volatile unsigned long *addr) 136 + static __always_inline bool 137 + arch_test_bit(unsigned long nr, const volatile unsigned long *addr) 144 138 { 145 139 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); 146 140 } 141 + 142 + #include <asm-generic/bitops/non-instrumented-non-atomic.h> 147 143 148 144 #endif /* __ASM_SH_BITOPS_OP32_H */
+9 -9
arch/sparc/include/asm/bitops_32.h
··· 19 19 #error only <linux/bitops.h> can be included directly 20 20 #endif 21 21 22 - unsigned long ___set_bit(unsigned long *addr, unsigned long mask); 23 - unsigned long ___clear_bit(unsigned long *addr, unsigned long mask); 24 - unsigned long ___change_bit(unsigned long *addr, unsigned long mask); 22 + unsigned long sp32___set_bit(unsigned long *addr, unsigned long mask); 23 + unsigned long sp32___clear_bit(unsigned long *addr, unsigned long mask); 24 + unsigned long sp32___change_bit(unsigned long *addr, unsigned long mask); 25 25 26 26 /* 27 27 * Set bit 'nr' in 32-bit quantity at address 'addr' where bit '0' ··· 36 36 ADDR = ((unsigned long *) addr) + (nr >> 5); 37 37 mask = 1 << (nr & 31); 38 38 39 - return ___set_bit(ADDR, mask) != 0; 39 + return sp32___set_bit(ADDR, mask) != 0; 40 40 } 41 41 42 42 static inline void set_bit(unsigned long nr, volatile unsigned long *addr) ··· 46 46 ADDR = ((unsigned long *) addr) + (nr >> 5); 47 47 mask = 1 << (nr & 31); 48 48 49 - (void) ___set_bit(ADDR, mask); 49 + (void) sp32___set_bit(ADDR, mask); 50 50 } 51 51 52 52 static inline int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) ··· 56 56 ADDR = ((unsigned long *) addr) + (nr >> 5); 57 57 mask = 1 << (nr & 31); 58 58 59 - return ___clear_bit(ADDR, mask) != 0; 59 + return sp32___clear_bit(ADDR, mask) != 0; 60 60 } 61 61 62 62 static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) ··· 66 66 ADDR = ((unsigned long *) addr) + (nr >> 5); 67 67 mask = 1 << (nr & 31); 68 68 69 - (void) ___clear_bit(ADDR, mask); 69 + (void) sp32___clear_bit(ADDR, mask); 70 70 } 71 71 72 72 static inline int test_and_change_bit(unsigned long nr, volatile unsigned long *addr) ··· 76 76 ADDR = ((unsigned long *) addr) + (nr >> 5); 77 77 mask = 1 << (nr & 31); 78 78 79 - return ___change_bit(ADDR, mask) != 0; 79 + return sp32___change_bit(ADDR, mask) != 0; 80 80 } 81 81 82 82 static inline void change_bit(unsigned long nr, volatile unsigned long *addr) ··· 86 86 ADDR = ((unsigned long *) addr) + (nr >> 5); 87 87 mask = 1 << (nr & 31); 88 88 89 - (void) ___change_bit(ADDR, mask); 89 + (void) sp32___change_bit(ADDR, mask); 90 90 } 91 91 92 92 #include <asm-generic/bitops/non-atomic.h>
+6 -6
arch/sparc/lib/atomic32.c
··· 120 120 } 121 121 EXPORT_SYMBOL(arch_atomic_set); 122 122 123 - unsigned long ___set_bit(unsigned long *addr, unsigned long mask) 123 + unsigned long sp32___set_bit(unsigned long *addr, unsigned long mask) 124 124 { 125 125 unsigned long old, flags; 126 126 ··· 131 131 132 132 return old & mask; 133 133 } 134 - EXPORT_SYMBOL(___set_bit); 134 + EXPORT_SYMBOL(sp32___set_bit); 135 135 136 - unsigned long ___clear_bit(unsigned long *addr, unsigned long mask) 136 + unsigned long sp32___clear_bit(unsigned long *addr, unsigned long mask) 137 137 { 138 138 unsigned long old, flags; 139 139 ··· 144 144 145 145 return old & mask; 146 146 } 147 - EXPORT_SYMBOL(___clear_bit); 147 + EXPORT_SYMBOL(sp32___clear_bit); 148 148 149 - unsigned long ___change_bit(unsigned long *addr, unsigned long mask) 149 + unsigned long sp32___change_bit(unsigned long *addr, unsigned long mask) 150 150 { 151 151 unsigned long old, flags; 152 152 ··· 157 157 158 158 return old & mask; 159 159 } 160 - EXPORT_SYMBOL(___change_bit); 160 + EXPORT_SYMBOL(sp32___change_bit); 161 161 162 162 unsigned long __cmpxchg_u32(volatile u32 *ptr, u32 old, u32 new) 163 163 {
+12 -10
arch/x86/include/asm/bitops.h
··· 63 63 } 64 64 65 65 static __always_inline void 66 - arch___set_bit(long nr, volatile unsigned long *addr) 66 + arch___set_bit(unsigned long nr, volatile unsigned long *addr) 67 67 { 68 68 asm volatile(__ASM_SIZE(bts) " %1,%0" : : ADDR, "Ir" (nr) : "memory"); 69 69 } ··· 89 89 } 90 90 91 91 static __always_inline void 92 - arch___clear_bit(long nr, volatile unsigned long *addr) 92 + arch___clear_bit(unsigned long nr, volatile unsigned long *addr) 93 93 { 94 94 asm volatile(__ASM_SIZE(btr) " %1,%0" : : ADDR, "Ir" (nr) : "memory"); 95 95 } ··· 114 114 } 115 115 116 116 static __always_inline void 117 - arch___change_bit(long nr, volatile unsigned long *addr) 117 + arch___change_bit(unsigned long nr, volatile unsigned long *addr) 118 118 { 119 119 asm volatile(__ASM_SIZE(btc) " %1,%0" : : ADDR, "Ir" (nr) : "memory"); 120 120 } ··· 145 145 } 146 146 147 147 static __always_inline bool 148 - arch___test_and_set_bit(long nr, volatile unsigned long *addr) 148 + arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr) 149 149 { 150 150 bool oldbit; 151 151 ··· 171 171 * this without also updating arch/x86/kernel/kvm.c 172 172 */ 173 173 static __always_inline bool 174 - arch___test_and_clear_bit(long nr, volatile unsigned long *addr) 174 + arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) 175 175 { 176 176 bool oldbit; 177 177 ··· 183 183 } 184 184 185 185 static __always_inline bool 186 - arch___test_and_change_bit(long nr, volatile unsigned long *addr) 186 + arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr) 187 187 { 188 188 bool oldbit; 189 189 ··· 219 219 return oldbit; 220 220 } 221 221 222 - #define arch_test_bit(nr, addr) \ 223 - (__builtin_constant_p((nr)) \ 224 - ? constant_test_bit((nr), (addr)) \ 225 - : variable_test_bit((nr), (addr))) 222 + static __always_inline bool 223 + arch_test_bit(unsigned long nr, const volatile unsigned long *addr) 224 + { 225 + return __builtin_constant_p(nr) ? constant_test_bit(nr, addr) : 226 + variable_test_bit(nr, addr); 227 + } 226 228 227 229 /** 228 230 * __ffs - find first set bit in word
+1 -1
arch/x86/platform/olpc/olpc-xo1-sci.c
··· 80 80 return; 81 81 } 82 82 83 - if (!!test_bit(SW_TABLET_MODE, ebook_switch_idev->sw) == state) 83 + if (test_bit(SW_TABLET_MODE, ebook_switch_idev->sw) == !!state) 84 84 return; /* Nothing new to report. */ 85 85 86 86 input_report_switch(ebook_switch_idev, SW_TABLET_MODE, state);
+1 -1
drivers/iommu/intel/dmar.c
··· 494 494 if (drhd->reg_base_addr == rhsa->base_address) { 495 495 int node = pxm_to_node(rhsa->proximity_domain); 496 496 497 - if (!node_online(node)) 497 + if (node != NUMA_NO_NODE && !node_online(node)) 498 498 node = NUMA_NO_NODE; 499 499 drhd->iommu->node = node; 500 500 return 0;
+1 -1
drivers/net/ethernet/intel/ice/ice_switch.c
··· 4971 4971 bitmap_zero(recipes, ICE_MAX_NUM_RECIPES); 4972 4972 bitmap_zero(used_idx, ICE_MAX_FV_WORDS); 4973 4973 4974 - bitmap_set(possible_idx, 0, ICE_MAX_FV_WORDS); 4974 + bitmap_fill(possible_idx, ICE_MAX_FV_WORDS); 4975 4975 4976 4976 /* For each profile we are going to associate the recipe with, add the 4977 4977 * recipes that are associated with that profile. This will give us
+1 -1
drivers/net/ethernet/mellanox/mlx4/fw.c
··· 463 463 464 464 field = min( 465 465 bitmap_weight(actv_ports.ports, dev->caps.num_ports), 466 - dev->caps.num_ports); 466 + (unsigned int) dev->caps.num_ports); 467 467 MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_NUM_PORTS_OFFSET); 468 468 469 469 size = dev->caps.function_caps; /* set PF behaviours */
+161
include/asm-generic/bitops/generic-non-atomic.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + 3 + #ifndef __ASM_GENERIC_BITOPS_GENERIC_NON_ATOMIC_H 4 + #define __ASM_GENERIC_BITOPS_GENERIC_NON_ATOMIC_H 5 + 6 + #include <linux/bits.h> 7 + 8 + #ifndef _LINUX_BITOPS_H 9 + #error only <linux/bitops.h> can be included directly 10 + #endif 11 + 12 + /* 13 + * Generic definitions for bit operations, should not be used in regular code 14 + * directly. 15 + */ 16 + 17 + /** 18 + * generic___set_bit - Set a bit in memory 19 + * @nr: the bit to set 20 + * @addr: the address to start counting from 21 + * 22 + * Unlike set_bit(), this function is non-atomic and may be reordered. 23 + * If it's called on the same region of memory simultaneously, the effect 24 + * may be that only one operation succeeds. 25 + */ 26 + static __always_inline void 27 + generic___set_bit(unsigned long nr, volatile unsigned long *addr) 28 + { 29 + unsigned long mask = BIT_MASK(nr); 30 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 31 + 32 + *p |= mask; 33 + } 34 + 35 + static __always_inline void 36 + generic___clear_bit(unsigned long nr, volatile unsigned long *addr) 37 + { 38 + unsigned long mask = BIT_MASK(nr); 39 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 40 + 41 + *p &= ~mask; 42 + } 43 + 44 + /** 45 + * generic___change_bit - Toggle a bit in memory 46 + * @nr: the bit to change 47 + * @addr: the address to start counting from 48 + * 49 + * Unlike change_bit(), this function is non-atomic and may be reordered. 50 + * If it's called on the same region of memory simultaneously, the effect 51 + * may be that only one operation succeeds. 52 + */ 53 + static __always_inline void 54 + generic___change_bit(unsigned long nr, volatile unsigned long *addr) 55 + { 56 + unsigned long mask = BIT_MASK(nr); 57 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 58 + 59 + *p ^= mask; 60 + } 61 + 62 + /** 63 + * generic___test_and_set_bit - Set a bit and return its old value 64 + * @nr: Bit to set 65 + * @addr: Address to count from 66 + * 67 + * This operation is non-atomic and can be reordered. 68 + * If two examples of this operation race, one can appear to succeed 69 + * but actually fail. You must protect multiple accesses with a lock. 70 + */ 71 + static __always_inline bool 72 + generic___test_and_set_bit(unsigned long nr, volatile unsigned long *addr) 73 + { 74 + unsigned long mask = BIT_MASK(nr); 75 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 76 + unsigned long old = *p; 77 + 78 + *p = old | mask; 79 + return (old & mask) != 0; 80 + } 81 + 82 + /** 83 + * generic___test_and_clear_bit - Clear a bit and return its old value 84 + * @nr: Bit to clear 85 + * @addr: Address to count from 86 + * 87 + * This operation is non-atomic and can be reordered. 88 + * If two examples of this operation race, one can appear to succeed 89 + * but actually fail. You must protect multiple accesses with a lock. 90 + */ 91 + static __always_inline bool 92 + generic___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) 93 + { 94 + unsigned long mask = BIT_MASK(nr); 95 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 96 + unsigned long old = *p; 97 + 98 + *p = old & ~mask; 99 + return (old & mask) != 0; 100 + } 101 + 102 + /* WARNING: non atomic and it can be reordered! */ 103 + static __always_inline bool 104 + generic___test_and_change_bit(unsigned long nr, volatile unsigned long *addr) 105 + { 106 + unsigned long mask = BIT_MASK(nr); 107 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 108 + unsigned long old = *p; 109 + 110 + *p = old ^ mask; 111 + return (old & mask) != 0; 112 + } 113 + 114 + /** 115 + * generic_test_bit - Determine whether a bit is set 116 + * @nr: bit number to test 117 + * @addr: Address to start counting from 118 + */ 119 + static __always_inline bool 120 + generic_test_bit(unsigned long nr, const volatile unsigned long *addr) 121 + { 122 + /* 123 + * Unlike the bitops with the '__' prefix above, this one *is* atomic, 124 + * so `volatile` must always stay here with no cast-aways. See 125 + * `Documentation/atomic_bitops.txt` for the details. 126 + */ 127 + return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); 128 + } 129 + 130 + /* 131 + * const_*() definitions provide good compile-time optimizations when 132 + * the passed arguments can be resolved at compile time. 133 + */ 134 + #define const___set_bit generic___set_bit 135 + #define const___clear_bit generic___clear_bit 136 + #define const___change_bit generic___change_bit 137 + #define const___test_and_set_bit generic___test_and_set_bit 138 + #define const___test_and_clear_bit generic___test_and_clear_bit 139 + #define const___test_and_change_bit generic___test_and_change_bit 140 + 141 + /** 142 + * const_test_bit - Determine whether a bit is set 143 + * @nr: bit number to test 144 + * @addr: Address to start counting from 145 + * 146 + * A version of generic_test_bit() which discards the `volatile` qualifier to 147 + * allow a compiler to optimize code harder. Non-atomic and to be called only 148 + * for testing compile-time constants, e.g. by the corresponding macros, not 149 + * directly from "regular" code. 150 + */ 151 + static __always_inline bool 152 + const_test_bit(unsigned long nr, const volatile unsigned long *addr) 153 + { 154 + const unsigned long *p = (const unsigned long *)addr + BIT_WORD(nr); 155 + unsigned long mask = BIT_MASK(nr); 156 + unsigned long val = *p; 157 + 158 + return !!(val & mask); 159 + } 160 + 161 + #endif /* __ASM_GENERIC_BITOPS_GENERIC_NON_ATOMIC_H */
+21 -14
include/asm-generic/bitops/instrumented-non-atomic.h
··· 14 14 #include <linux/instrumented.h> 15 15 16 16 /** 17 - * __set_bit - Set a bit in memory 17 + * ___set_bit - Set a bit in memory 18 18 * @nr: the bit to set 19 19 * @addr: the address to start counting from 20 20 * ··· 22 22 * region of memory concurrently, the effect may be that only one operation 23 23 * succeeds. 24 24 */ 25 - static __always_inline void __set_bit(long nr, volatile unsigned long *addr) 25 + static __always_inline void 26 + ___set_bit(unsigned long nr, volatile unsigned long *addr) 26 27 { 27 28 instrument_write(addr + BIT_WORD(nr), sizeof(long)); 28 29 arch___set_bit(nr, addr); 29 30 } 30 31 31 32 /** 32 - * __clear_bit - Clears a bit in memory 33 + * ___clear_bit - Clears a bit in memory 33 34 * @nr: the bit to clear 34 35 * @addr: the address to start counting from 35 36 * ··· 38 37 * region of memory concurrently, the effect may be that only one operation 39 38 * succeeds. 40 39 */ 41 - static __always_inline void __clear_bit(long nr, volatile unsigned long *addr) 40 + static __always_inline void 41 + ___clear_bit(unsigned long nr, volatile unsigned long *addr) 42 42 { 43 43 instrument_write(addr + BIT_WORD(nr), sizeof(long)); 44 44 arch___clear_bit(nr, addr); 45 45 } 46 46 47 47 /** 48 - * __change_bit - Toggle a bit in memory 48 + * ___change_bit - Toggle a bit in memory 49 49 * @nr: the bit to change 50 50 * @addr: the address to start counting from 51 51 * ··· 54 52 * region of memory concurrently, the effect may be that only one operation 55 53 * succeeds. 56 54 */ 57 - static __always_inline void __change_bit(long nr, volatile unsigned long *addr) 55 + static __always_inline void 56 + ___change_bit(unsigned long nr, volatile unsigned long *addr) 58 57 { 59 58 instrument_write(addr + BIT_WORD(nr), sizeof(long)); 60 59 arch___change_bit(nr, addr); ··· 86 83 } 87 84 88 85 /** 89 - * __test_and_set_bit - Set a bit and return its old value 86 + * ___test_and_set_bit - Set a bit and return its old value 90 87 * @nr: Bit to set 91 88 * @addr: Address to count from 92 89 * 93 90 * This operation is non-atomic. If two instances of this operation race, one 94 91 * can appear to succeed but actually fail. 95 92 */ 96 - static __always_inline bool __test_and_set_bit(long nr, volatile unsigned long *addr) 93 + static __always_inline bool 94 + ___test_and_set_bit(unsigned long nr, volatile unsigned long *addr) 97 95 { 98 96 __instrument_read_write_bitop(nr, addr); 99 97 return arch___test_and_set_bit(nr, addr); 100 98 } 101 99 102 100 /** 103 - * __test_and_clear_bit - Clear a bit and return its old value 101 + * ___test_and_clear_bit - Clear a bit and return its old value 104 102 * @nr: Bit to clear 105 103 * @addr: Address to count from 106 104 * 107 105 * This operation is non-atomic. If two instances of this operation race, one 108 106 * can appear to succeed but actually fail. 109 107 */ 110 - static __always_inline bool __test_and_clear_bit(long nr, volatile unsigned long *addr) 108 + static __always_inline bool 109 + ___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) 111 110 { 112 111 __instrument_read_write_bitop(nr, addr); 113 112 return arch___test_and_clear_bit(nr, addr); 114 113 } 115 114 116 115 /** 117 - * __test_and_change_bit - Change a bit and return its old value 116 + * ___test_and_change_bit - Change a bit and return its old value 118 117 * @nr: Bit to change 119 118 * @addr: Address to count from 120 119 * 121 120 * This operation is non-atomic. If two instances of this operation race, one 122 121 * can appear to succeed but actually fail. 123 122 */ 124 - static __always_inline bool __test_and_change_bit(long nr, volatile unsigned long *addr) 123 + static __always_inline bool 124 + ___test_and_change_bit(unsigned long nr, volatile unsigned long *addr) 125 125 { 126 126 __instrument_read_write_bitop(nr, addr); 127 127 return arch___test_and_change_bit(nr, addr); 128 128 } 129 129 130 130 /** 131 - * test_bit - Determine whether a bit is set 131 + * _test_bit - Determine whether a bit is set 132 132 * @nr: bit number to test 133 133 * @addr: Address to start counting from 134 134 */ 135 - static __always_inline bool test_bit(long nr, const volatile unsigned long *addr) 135 + static __always_inline bool 136 + _test_bit(unsigned long nr, const volatile unsigned long *addr) 136 137 { 137 138 instrument_atomic_read(addr + BIT_WORD(nr), sizeof(long)); 138 139 return arch_test_bit(nr, addr);
+9 -112
include/asm-generic/bitops/non-atomic.h
··· 2 2 #ifndef _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ 3 3 #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ 4 4 5 - #include <asm/types.h> 5 + #include <asm-generic/bitops/generic-non-atomic.h> 6 6 7 - /** 8 - * arch___set_bit - Set a bit in memory 9 - * @nr: the bit to set 10 - * @addr: the address to start counting from 11 - * 12 - * Unlike set_bit(), this function is non-atomic and may be reordered. 13 - * If it's called on the same region of memory simultaneously, the effect 14 - * may be that only one operation succeeds. 15 - */ 16 - static __always_inline void 17 - arch___set_bit(unsigned int nr, volatile unsigned long *addr) 18 - { 19 - unsigned long mask = BIT_MASK(nr); 20 - unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 7 + #define arch___set_bit generic___set_bit 8 + #define arch___clear_bit generic___clear_bit 9 + #define arch___change_bit generic___change_bit 21 10 22 - *p |= mask; 23 - } 24 - #define __set_bit arch___set_bit 11 + #define arch___test_and_set_bit generic___test_and_set_bit 12 + #define arch___test_and_clear_bit generic___test_and_clear_bit 13 + #define arch___test_and_change_bit generic___test_and_change_bit 25 14 26 - static __always_inline void 27 - arch___clear_bit(unsigned int nr, volatile unsigned long *addr) 28 - { 29 - unsigned long mask = BIT_MASK(nr); 30 - unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 15 + #define arch_test_bit generic_test_bit 31 16 32 - *p &= ~mask; 33 - } 34 - #define __clear_bit arch___clear_bit 35 - 36 - /** 37 - * arch___change_bit - Toggle a bit in memory 38 - * @nr: the bit to change 39 - * @addr: the address to start counting from 40 - * 41 - * Unlike change_bit(), this function is non-atomic and may be reordered. 42 - * If it's called on the same region of memory simultaneously, the effect 43 - * may be that only one operation succeeds. 44 - */ 45 - static __always_inline 46 - void arch___change_bit(unsigned int nr, volatile unsigned long *addr) 47 - { 48 - unsigned long mask = BIT_MASK(nr); 49 - unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 50 - 51 - *p ^= mask; 52 - } 53 - #define __change_bit arch___change_bit 54 - 55 - /** 56 - * arch___test_and_set_bit - Set a bit and return its old value 57 - * @nr: Bit to set 58 - * @addr: Address to count from 59 - * 60 - * This operation is non-atomic and can be reordered. 61 - * If two examples of this operation race, one can appear to succeed 62 - * but actually fail. You must protect multiple accesses with a lock. 63 - */ 64 - static __always_inline int 65 - arch___test_and_set_bit(unsigned int nr, volatile unsigned long *addr) 66 - { 67 - unsigned long mask = BIT_MASK(nr); 68 - unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 69 - unsigned long old = *p; 70 - 71 - *p = old | mask; 72 - return (old & mask) != 0; 73 - } 74 - #define __test_and_set_bit arch___test_and_set_bit 75 - 76 - /** 77 - * arch___test_and_clear_bit - Clear a bit and return its old value 78 - * @nr: Bit to clear 79 - * @addr: Address to count from 80 - * 81 - * This operation is non-atomic and can be reordered. 82 - * If two examples of this operation race, one can appear to succeed 83 - * but actually fail. You must protect multiple accesses with a lock. 84 - */ 85 - static __always_inline int 86 - arch___test_and_clear_bit(unsigned int nr, volatile unsigned long *addr) 87 - { 88 - unsigned long mask = BIT_MASK(nr); 89 - unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 90 - unsigned long old = *p; 91 - 92 - *p = old & ~mask; 93 - return (old & mask) != 0; 94 - } 95 - #define __test_and_clear_bit arch___test_and_clear_bit 96 - 97 - /* WARNING: non atomic and it can be reordered! */ 98 - static __always_inline int 99 - arch___test_and_change_bit(unsigned int nr, volatile unsigned long *addr) 100 - { 101 - unsigned long mask = BIT_MASK(nr); 102 - unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 103 - unsigned long old = *p; 104 - 105 - *p = old ^ mask; 106 - return (old & mask) != 0; 107 - } 108 - #define __test_and_change_bit arch___test_and_change_bit 109 - 110 - /** 111 - * arch_test_bit - Determine whether a bit is set 112 - * @nr: bit number to test 113 - * @addr: Address to start counting from 114 - */ 115 - static __always_inline int 116 - arch_test_bit(unsigned int nr, const volatile unsigned long *addr) 117 - { 118 - return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); 119 - } 120 - #define test_bit arch_test_bit 17 + #include <asm-generic/bitops/non-instrumented-non-atomic.h> 121 18 122 19 #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
+16
include/asm-generic/bitops/non-instrumented-non-atomic.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __ASM_GENERIC_BITOPS_NON_INSTRUMENTED_NON_ATOMIC_H 4 + #define __ASM_GENERIC_BITOPS_NON_INSTRUMENTED_NON_ATOMIC_H 5 + 6 + #define ___set_bit arch___set_bit 7 + #define ___clear_bit arch___clear_bit 8 + #define ___change_bit arch___change_bit 9 + 10 + #define ___test_and_set_bit arch___test_and_set_bit 11 + #define ___test_and_clear_bit arch___test_and_clear_bit 12 + #define ___test_and_change_bit arch___test_and_change_bit 13 + 14 + #define _test_bit arch_test_bit 15 + 16 + #endif /* __ASM_GENERIC_BITOPS_NON_INSTRUMENTED_NON_ATOMIC_H */
+27 -10
include/linux/bitmap.h
··· 71 71 * bitmap_release_region(bitmap, pos, order) Free specified bit region 72 72 * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region 73 73 * bitmap_from_arr32(dst, buf, nbits) Copy nbits from u32[] buf to dst 74 + * bitmap_from_arr64(dst, buf, nbits) Copy nbits from u64[] buf to dst 74 75 * bitmap_to_arr32(buf, src, nbits) Copy nbits from buf to u32[] dst 75 - * bitmap_to_arr64(buf, src, nbits) Copy nbits from buf to u64[] dst 76 76 * bitmap_to_arr64(buf, src, nbits) Copy nbits from buf to u64[] dst 77 77 * bitmap_get_value8(map, start) Get 8bit value from map at start 78 78 * bitmap_set_value8(map, value, start) Set 8bit value to map at start ··· 148 148 unsigned int shift, unsigned int nbits); 149 149 void bitmap_cut(unsigned long *dst, const unsigned long *src, 150 150 unsigned int first, unsigned int cut, unsigned int nbits); 151 - int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, 151 + bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, 152 152 const unsigned long *bitmap2, unsigned int nbits); 153 153 void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, 154 154 const unsigned long *bitmap2, unsigned int nbits); 155 155 void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1, 156 156 const unsigned long *bitmap2, unsigned int nbits); 157 - int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, 157 + bool __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, 158 158 const unsigned long *bitmap2, unsigned int nbits); 159 159 void __bitmap_replace(unsigned long *dst, 160 160 const unsigned long *old, const unsigned long *new, ··· 163 163 const unsigned long *bitmap2, unsigned int nbits); 164 164 bool __bitmap_subset(const unsigned long *bitmap1, 165 165 const unsigned long *bitmap2, unsigned int nbits); 166 - int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits); 166 + unsigned int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits); 167 167 void __bitmap_set(unsigned long *map, unsigned int start, int len); 168 168 void __bitmap_clear(unsigned long *map, unsigned int start, int len); 169 169 ··· 238 238 static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) 239 239 { 240 240 unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); 241 - memset(dst, 0, len); 241 + 242 + if (small_const_nbits(nbits)) 243 + *dst = 0; 244 + else 245 + memset(dst, 0, len); 242 246 } 243 247 244 248 static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) 245 249 { 246 250 unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); 247 - memset(dst, 0xff, len); 251 + 252 + if (small_const_nbits(nbits)) 253 + *dst = ~0UL; 254 + else 255 + memset(dst, 0xff, len); 248 256 } 249 257 250 258 static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, 251 259 unsigned int nbits) 252 260 { 253 261 unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); 254 - memcpy(dst, src, len); 262 + 263 + if (small_const_nbits(nbits)) 264 + *dst = *src; 265 + else 266 + memcpy(dst, src, len); 255 267 } 256 268 257 269 /* ··· 315 303 bitmap_copy_clear_tail((unsigned long *)(buf), (const unsigned long *)(bitmap), (nbits)) 316 304 #endif 317 305 318 - static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, 306 + static inline bool bitmap_and(unsigned long *dst, const unsigned long *src1, 319 307 const unsigned long *src2, unsigned int nbits) 320 308 { 321 309 if (small_const_nbits(nbits)) ··· 341 329 __bitmap_xor(dst, src1, src2, nbits); 342 330 } 343 331 344 - static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1, 332 + static inline bool bitmap_andnot(unsigned long *dst, const unsigned long *src1, 345 333 const unsigned long *src2, unsigned int nbits) 346 334 { 347 335 if (small_const_nbits(nbits)) ··· 431 419 return find_first_zero_bit(src, nbits) == nbits; 432 420 } 433 421 434 - static __always_inline int bitmap_weight(const unsigned long *src, unsigned int nbits) 422 + static __always_inline 423 + unsigned int bitmap_weight(const unsigned long *src, unsigned int nbits) 435 424 { 436 425 if (small_const_nbits(nbits)) 437 426 return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); ··· 444 431 { 445 432 if (__builtin_constant_p(nbits) && nbits == 1) 446 433 __set_bit(start, map); 434 + else if (small_const_nbits(start + nbits)) 435 + *map |= GENMASK(start + nbits - 1, start); 447 436 else if (__builtin_constant_p(start & BITMAP_MEM_MASK) && 448 437 IS_ALIGNED(start, BITMAP_MEM_ALIGNMENT) && 449 438 __builtin_constant_p(nbits & BITMAP_MEM_MASK) && ··· 460 445 { 461 446 if (__builtin_constant_p(nbits) && nbits == 1) 462 447 __clear_bit(start, map); 448 + else if (small_const_nbits(start + nbits)) 449 + *map &= ~GENMASK(start + nbits - 1, start); 463 450 else if (__builtin_constant_p(start & BITMAP_MEM_MASK) && 464 451 IS_ALIGNED(start, BITMAP_MEM_ALIGNMENT) && 465 452 __builtin_constant_p(nbits & BITMAP_MEM_MASK) &&
+50
include/linux/bitops.h
··· 27 27 extern unsigned long __sw_hweight64(__u64 w); 28 28 29 29 /* 30 + * Defined here because those may be needed by architecture-specific static 31 + * inlines. 32 + */ 33 + 34 + #include <asm-generic/bitops/generic-non-atomic.h> 35 + 36 + /* 37 + * Many architecture-specific non-atomic bitops contain inline asm code and due 38 + * to that the compiler can't optimize them to compile-time expressions or 39 + * constants. In contrary, generic_*() helpers are defined in pure C and 40 + * compilers optimize them just well. 41 + * Therefore, to make `unsigned long foo = 0; __set_bit(BAR, &foo)` effectively 42 + * equal to `unsigned long foo = BIT(BAR)`, pick the generic C alternative when 43 + * the arguments can be resolved at compile time. That expression itself is a 44 + * constant and doesn't bring any functional changes to the rest of cases. 45 + * The casts to `uintptr_t` are needed to mitigate `-Waddress` warnings when 46 + * passing a bitmap from .bss or .data (-> `!!addr` is always true). 47 + */ 48 + #define bitop(op, nr, addr) \ 49 + ((__builtin_constant_p(nr) && \ 50 + __builtin_constant_p((uintptr_t)(addr) != (uintptr_t)NULL) && \ 51 + (uintptr_t)(addr) != (uintptr_t)NULL && \ 52 + __builtin_constant_p(*(const unsigned long *)(addr))) ? \ 53 + const##op(nr, addr) : op(nr, addr)) 54 + 55 + #define __set_bit(nr, addr) bitop(___set_bit, nr, addr) 56 + #define __clear_bit(nr, addr) bitop(___clear_bit, nr, addr) 57 + #define __change_bit(nr, addr) bitop(___change_bit, nr, addr) 58 + #define __test_and_set_bit(nr, addr) bitop(___test_and_set_bit, nr, addr) 59 + #define __test_and_clear_bit(nr, addr) bitop(___test_and_clear_bit, nr, addr) 60 + #define __test_and_change_bit(nr, addr) bitop(___test_and_change_bit, nr, addr) 61 + #define test_bit(nr, addr) bitop(_test_bit, nr, addr) 62 + 63 + /* 30 64 * Include this here because some architectures need generic_ffs/fls in 31 65 * scope 32 66 */ 33 67 #include <asm/bitops.h> 68 + 69 + /* Check that the bitops prototypes are sane */ 70 + #define __check_bitop_pr(name) \ 71 + static_assert(__same_type(arch_##name, generic_##name) && \ 72 + __same_type(const_##name, generic_##name) && \ 73 + __same_type(_##name, generic_##name)) 74 + 75 + __check_bitop_pr(__set_bit); 76 + __check_bitop_pr(__clear_bit); 77 + __check_bitop_pr(__change_bit); 78 + __check_bitop_pr(__test_and_set_bit); 79 + __check_bitop_pr(__test_and_clear_bit); 80 + __check_bitop_pr(__test_and_change_bit); 81 + __check_bitop_pr(test_bit); 82 + 83 + #undef __check_bitop_pr 34 84 35 85 static inline int get_bitmask_order(unsigned int count) 36 86 {
+100 -22
include/linux/cpumask.h
··· 12 12 #include <linux/bitmap.h> 13 13 #include <linux/atomic.h> 14 14 #include <linux/bug.h> 15 + #include <linux/gfp_types.h> 16 + #include <linux/numa.h> 15 17 16 18 /* Don't assign or return these: may not be this big! */ 17 19 typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t; ··· 164 162 return find_last_bit(cpumask_bits(srcp), nr_cpumask_bits); 165 163 } 166 164 167 - unsigned int __pure cpumask_next(int n, const struct cpumask *srcp); 165 + /** 166 + * cpumask_next - get the next cpu in a cpumask 167 + * @n: the cpu prior to the place to search (ie. return will be > @n) 168 + * @srcp: the cpumask pointer 169 + * 170 + * Returns >= nr_cpu_ids if no further cpus set. 171 + */ 172 + static inline 173 + unsigned int cpumask_next(int n, const struct cpumask *srcp) 174 + { 175 + /* -1 is a legal arg here. */ 176 + if (n != -1) 177 + cpumask_check(n); 178 + return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n + 1); 179 + } 168 180 169 181 /** 170 182 * cpumask_next_zero - get the next unset cpu in a cpumask ··· 194 178 cpumask_check(n); 195 179 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1); 196 180 } 197 - 198 - int __pure cpumask_next_and(int n, const struct cpumask *, const struct cpumask *); 199 - int __pure cpumask_any_but(const struct cpumask *mask, unsigned int cpu); 200 181 201 182 #if NR_CPUS == 1 202 183 /* Uniprocessor: there is only one valid CPU */ ··· 213 200 } 214 201 #else 215 202 unsigned int cpumask_local_spread(unsigned int i, int node); 216 - int cpumask_any_and_distribute(const struct cpumask *src1p, 203 + unsigned int cpumask_any_and_distribute(const struct cpumask *src1p, 217 204 const struct cpumask *src2p); 218 - int cpumask_any_distribute(const struct cpumask *srcp); 205 + unsigned int cpumask_any_distribute(const struct cpumask *srcp); 219 206 #endif /* NR_CPUS */ 207 + 208 + /** 209 + * cpumask_next_and - get the next cpu in *src1p & *src2p 210 + * @n: the cpu prior to the place to search (ie. return will be > @n) 211 + * @src1p: the first cpumask pointer 212 + * @src2p: the second cpumask pointer 213 + * 214 + * Returns >= nr_cpu_ids if no further cpus set in both. 215 + */ 216 + static inline 217 + unsigned int cpumask_next_and(int n, const struct cpumask *src1p, 218 + const struct cpumask *src2p) 219 + { 220 + /* -1 is a legal arg here. */ 221 + if (n != -1) 222 + cpumask_check(n); 223 + return find_next_and_bit(cpumask_bits(src1p), cpumask_bits(src2p), 224 + nr_cpumask_bits, n + 1); 225 + } 220 226 221 227 /** 222 228 * for_each_cpu - iterate over every cpu in a mask ··· 261 229 (cpu) = cpumask_next_zero((cpu), (mask)), \ 262 230 (cpu) < nr_cpu_ids;) 263 231 264 - int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap); 232 + unsigned int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap); 265 233 266 234 /** 267 235 * for_each_cpu_wrap - iterate over every cpu in a mask, starting at a specified location ··· 296 264 for ((cpu) = -1; \ 297 265 (cpu) = cpumask_next_and((cpu), (mask1), (mask2)), \ 298 266 (cpu) < nr_cpu_ids;) 267 + 268 + /** 269 + * cpumask_any_but - return a "random" in a cpumask, but not this one. 270 + * @mask: the cpumask to search 271 + * @cpu: the cpu to ignore. 272 + * 273 + * Often used to find any cpu but smp_processor_id() in a mask. 274 + * Returns >= nr_cpu_ids if no cpus set. 275 + */ 276 + static inline 277 + unsigned int cpumask_any_but(const struct cpumask *mask, unsigned int cpu) 278 + { 279 + unsigned int i; 280 + 281 + cpumask_check(cpu); 282 + for_each_cpu(i, mask) 283 + if (i != cpu) 284 + break; 285 + return i; 286 + } 299 287 300 288 #define CPU_BITS_NONE \ 301 289 { \ ··· 363 311 * @cpu: cpu number (< nr_cpu_ids) 364 312 * @cpumask: the cpumask pointer 365 313 * 366 - * Returns 1 if @cpu is set in @cpumask, else returns 0 314 + * Returns true if @cpu is set in @cpumask, else returns false 367 315 */ 368 - static __always_inline int cpumask_test_cpu(int cpu, const struct cpumask *cpumask) 316 + static __always_inline bool cpumask_test_cpu(int cpu, const struct cpumask *cpumask) 369 317 { 370 318 return test_bit(cpumask_check(cpu), cpumask_bits((cpumask))); 371 319 } ··· 375 323 * @cpu: cpu number (< nr_cpu_ids) 376 324 * @cpumask: the cpumask pointer 377 325 * 378 - * Returns 1 if @cpu is set in old bitmap of @cpumask, else returns 0 326 + * Returns true if @cpu is set in old bitmap of @cpumask, else returns false 379 327 * 380 328 * test_and_set_bit wrapper for cpumasks. 381 329 */ 382 - static __always_inline int cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask) 330 + static __always_inline bool cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask) 383 331 { 384 332 return test_and_set_bit(cpumask_check(cpu), cpumask_bits(cpumask)); 385 333 } ··· 389 337 * @cpu: cpu number (< nr_cpu_ids) 390 338 * @cpumask: the cpumask pointer 391 339 * 392 - * Returns 1 if @cpu is set in old bitmap of @cpumask, else returns 0 340 + * Returns true if @cpu is set in old bitmap of @cpumask, else returns false 393 341 * 394 342 * test_and_clear_bit wrapper for cpumasks. 395 343 */ 396 - static __always_inline int cpumask_test_and_clear_cpu(int cpu, struct cpumask *cpumask) 344 + static __always_inline bool cpumask_test_and_clear_cpu(int cpu, struct cpumask *cpumask) 397 345 { 398 346 return test_and_clear_bit(cpumask_check(cpu), cpumask_bits(cpumask)); 399 347 } ··· 422 370 * @src1p: the first input 423 371 * @src2p: the second input 424 372 * 425 - * If *@dstp is empty, returns 0, else returns 1 373 + * If *@dstp is empty, returns false, else returns true 426 374 */ 427 - static inline int cpumask_and(struct cpumask *dstp, 375 + static inline bool cpumask_and(struct cpumask *dstp, 428 376 const struct cpumask *src1p, 429 377 const struct cpumask *src2p) 430 378 { ··· 465 413 * @src1p: the first input 466 414 * @src2p: the second input 467 415 * 468 - * If *@dstp is empty, returns 0, else returns 1 416 + * If *@dstp is empty, returns false, else returns true 469 417 */ 470 - static inline int cpumask_andnot(struct cpumask *dstp, 418 + static inline bool cpumask_andnot(struct cpumask *dstp, 471 419 const struct cpumask *src1p, 472 420 const struct cpumask *src2p) 473 421 { ··· 530 478 * @src1p: the first input 531 479 * @src2p: the second input 532 480 * 533 - * Returns 1 if *@src1p is a subset of *@src2p, else returns 0 481 + * Returns true if *@src1p is a subset of *@src2p, else returns false 534 482 */ 535 - static inline int cpumask_subset(const struct cpumask *src1p, 483 + static inline bool cpumask_subset(const struct cpumask *src1p, 536 484 const struct cpumask *src2p) 537 485 { 538 486 return bitmap_subset(cpumask_bits(src1p), cpumask_bits(src2p), ··· 734 682 #define __cpumask_var_read_mostly __read_mostly 735 683 736 684 bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node); 737 - bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags); 738 - bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node); 739 - bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags); 685 + 686 + static inline 687 + bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node) 688 + { 689 + return alloc_cpumask_var_node(mask, flags | __GFP_ZERO, node); 690 + } 691 + 692 + /** 693 + * alloc_cpumask_var - allocate a struct cpumask 694 + * @mask: pointer to cpumask_var_t where the cpumask is returned 695 + * @flags: GFP_ flags 696 + * 697 + * Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is 698 + * a nop returning a constant 1 (in <linux/cpumask.h>). 699 + * 700 + * See alloc_cpumask_var_node. 701 + */ 702 + static inline 703 + bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) 704 + { 705 + return alloc_cpumask_var_node(mask, flags, NUMA_NO_NODE); 706 + } 707 + 708 + static inline 709 + bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) 710 + { 711 + return alloc_cpumask_var(mask, flags | __GFP_ZERO); 712 + } 713 + 740 714 void alloc_bootmem_cpumask_var(cpumask_var_t *mask); 741 715 void free_cpumask_var(cpumask_var_t mask); 742 716 void free_bootmem_cpumask_var(cpumask_var_t mask);
+2 -346
include/linux/gfp.h
··· 2 2 #ifndef __LINUX_GFP_H 3 3 #define __LINUX_GFP_H 4 4 5 - #include <linux/mmdebug.h> 5 + #include <linux/gfp_types.h> 6 + 6 7 #include <linux/mmzone.h> 7 - #include <linux/stddef.h> 8 - #include <linux/linkage.h> 9 8 #include <linux/topology.h> 10 9 11 - /* The typedef is in types.h but we want the documentation here */ 12 - #if 0 13 - /** 14 - * typedef gfp_t - Memory allocation flags. 15 - * 16 - * GFP flags are commonly used throughout Linux to indicate how memory 17 - * should be allocated. The GFP acronym stands for get_free_pages(), 18 - * the underlying memory allocation function. Not every GFP flag is 19 - * supported by every function which may allocate memory. Most users 20 - * will want to use a plain ``GFP_KERNEL``. 21 - */ 22 - typedef unsigned int __bitwise gfp_t; 23 - #endif 24 - 25 10 struct vm_area_struct; 26 - 27 - /* 28 - * In case of changes, please don't forget to update 29 - * include/trace/events/mmflags.h and tools/perf/builtin-kmem.c 30 - */ 31 - 32 - /* Plain integer GFP bitmasks. Do not use this directly. */ 33 - #define ___GFP_DMA 0x01u 34 - #define ___GFP_HIGHMEM 0x02u 35 - #define ___GFP_DMA32 0x04u 36 - #define ___GFP_MOVABLE 0x08u 37 - #define ___GFP_RECLAIMABLE 0x10u 38 - #define ___GFP_HIGH 0x20u 39 - #define ___GFP_IO 0x40u 40 - #define ___GFP_FS 0x80u 41 - #define ___GFP_ZERO 0x100u 42 - #define ___GFP_ATOMIC 0x200u 43 - #define ___GFP_DIRECT_RECLAIM 0x400u 44 - #define ___GFP_KSWAPD_RECLAIM 0x800u 45 - #define ___GFP_WRITE 0x1000u 46 - #define ___GFP_NOWARN 0x2000u 47 - #define ___GFP_RETRY_MAYFAIL 0x4000u 48 - #define ___GFP_NOFAIL 0x8000u 49 - #define ___GFP_NORETRY 0x10000u 50 - #define ___GFP_MEMALLOC 0x20000u 51 - #define ___GFP_COMP 0x40000u 52 - #define ___GFP_NOMEMALLOC 0x80000u 53 - #define ___GFP_HARDWALL 0x100000u 54 - #define ___GFP_THISNODE 0x200000u 55 - #define ___GFP_ACCOUNT 0x400000u 56 - #define ___GFP_ZEROTAGS 0x800000u 57 - #ifdef CONFIG_KASAN_HW_TAGS 58 - #define ___GFP_SKIP_ZERO 0x1000000u 59 - #define ___GFP_SKIP_KASAN_UNPOISON 0x2000000u 60 - #define ___GFP_SKIP_KASAN_POISON 0x4000000u 61 - #else 62 - #define ___GFP_SKIP_ZERO 0 63 - #define ___GFP_SKIP_KASAN_UNPOISON 0 64 - #define ___GFP_SKIP_KASAN_POISON 0 65 - #endif 66 - #ifdef CONFIG_LOCKDEP 67 - #define ___GFP_NOLOCKDEP 0x8000000u 68 - #else 69 - #define ___GFP_NOLOCKDEP 0 70 - #endif 71 - /* If the above are modified, __GFP_BITS_SHIFT may need updating */ 72 - 73 - /* 74 - * Physical address zone modifiers (see linux/mmzone.h - low four bits) 75 - * 76 - * Do not put any conditional on these. If necessary modify the definitions 77 - * without the underscores and use them consistently. The definitions here may 78 - * be used in bit comparisons. 79 - */ 80 - #define __GFP_DMA ((__force gfp_t)___GFP_DMA) 81 - #define __GFP_HIGHMEM ((__force gfp_t)___GFP_HIGHMEM) 82 - #define __GFP_DMA32 ((__force gfp_t)___GFP_DMA32) 83 - #define __GFP_MOVABLE ((__force gfp_t)___GFP_MOVABLE) /* ZONE_MOVABLE allowed */ 84 - #define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE) 85 - 86 - /** 87 - * DOC: Page mobility and placement hints 88 - * 89 - * Page mobility and placement hints 90 - * --------------------------------- 91 - * 92 - * These flags provide hints about how mobile the page is. Pages with similar 93 - * mobility are placed within the same pageblocks to minimise problems due 94 - * to external fragmentation. 95 - * 96 - * %__GFP_MOVABLE (also a zone modifier) indicates that the page can be 97 - * moved by page migration during memory compaction or can be reclaimed. 98 - * 99 - * %__GFP_RECLAIMABLE is used for slab allocations that specify 100 - * SLAB_RECLAIM_ACCOUNT and whose pages can be freed via shrinkers. 101 - * 102 - * %__GFP_WRITE indicates the caller intends to dirty the page. Where possible, 103 - * these pages will be spread between local zones to avoid all the dirty 104 - * pages being in one zone (fair zone allocation policy). 105 - * 106 - * %__GFP_HARDWALL enforces the cpuset memory allocation policy. 107 - * 108 - * %__GFP_THISNODE forces the allocation to be satisfied from the requested 109 - * node with no fallbacks or placement policy enforcements. 110 - * 111 - * %__GFP_ACCOUNT causes the allocation to be accounted to kmemcg. 112 - */ 113 - #define __GFP_RECLAIMABLE ((__force gfp_t)___GFP_RECLAIMABLE) 114 - #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) 115 - #define __GFP_HARDWALL ((__force gfp_t)___GFP_HARDWALL) 116 - #define __GFP_THISNODE ((__force gfp_t)___GFP_THISNODE) 117 - #define __GFP_ACCOUNT ((__force gfp_t)___GFP_ACCOUNT) 118 - 119 - /** 120 - * DOC: Watermark modifiers 121 - * 122 - * Watermark modifiers -- controls access to emergency reserves 123 - * ------------------------------------------------------------ 124 - * 125 - * %__GFP_HIGH indicates that the caller is high-priority and that granting 126 - * the request is necessary before the system can make forward progress. 127 - * For example, creating an IO context to clean pages. 128 - * 129 - * %__GFP_ATOMIC indicates that the caller cannot reclaim or sleep and is 130 - * high priority. Users are typically interrupt handlers. This may be 131 - * used in conjunction with %__GFP_HIGH 132 - * 133 - * %__GFP_MEMALLOC allows access to all memory. This should only be used when 134 - * the caller guarantees the allocation will allow more memory to be freed 135 - * very shortly e.g. process exiting or swapping. Users either should 136 - * be the MM or co-ordinating closely with the VM (e.g. swap over NFS). 137 - * Users of this flag have to be extremely careful to not deplete the reserve 138 - * completely and implement a throttling mechanism which controls the 139 - * consumption of the reserve based on the amount of freed memory. 140 - * Usage of a pre-allocated pool (e.g. mempool) should be always considered 141 - * before using this flag. 142 - * 143 - * %__GFP_NOMEMALLOC is used to explicitly forbid access to emergency reserves. 144 - * This takes precedence over the %__GFP_MEMALLOC flag if both are set. 145 - */ 146 - #define __GFP_ATOMIC ((__force gfp_t)___GFP_ATOMIC) 147 - #define __GFP_HIGH ((__force gfp_t)___GFP_HIGH) 148 - #define __GFP_MEMALLOC ((__force gfp_t)___GFP_MEMALLOC) 149 - #define __GFP_NOMEMALLOC ((__force gfp_t)___GFP_NOMEMALLOC) 150 - 151 - /** 152 - * DOC: Reclaim modifiers 153 - * 154 - * Reclaim modifiers 155 - * ----------------- 156 - * Please note that all the following flags are only applicable to sleepable 157 - * allocations (e.g. %GFP_NOWAIT and %GFP_ATOMIC will ignore them). 158 - * 159 - * %__GFP_IO can start physical IO. 160 - * 161 - * %__GFP_FS can call down to the low-level FS. Clearing the flag avoids the 162 - * allocator recursing into the filesystem which might already be holding 163 - * locks. 164 - * 165 - * %__GFP_DIRECT_RECLAIM indicates that the caller may enter direct reclaim. 166 - * This flag can be cleared to avoid unnecessary delays when a fallback 167 - * option is available. 168 - * 169 - * %__GFP_KSWAPD_RECLAIM indicates that the caller wants to wake kswapd when 170 - * the low watermark is reached and have it reclaim pages until the high 171 - * watermark is reached. A caller may wish to clear this flag when fallback 172 - * options are available and the reclaim is likely to disrupt the system. The 173 - * canonical example is THP allocation where a fallback is cheap but 174 - * reclaim/compaction may cause indirect stalls. 175 - * 176 - * %__GFP_RECLAIM is shorthand to allow/forbid both direct and kswapd reclaim. 177 - * 178 - * The default allocator behavior depends on the request size. We have a concept 179 - * of so called costly allocations (with order > %PAGE_ALLOC_COSTLY_ORDER). 180 - * !costly allocations are too essential to fail so they are implicitly 181 - * non-failing by default (with some exceptions like OOM victims might fail so 182 - * the caller still has to check for failures) while costly requests try to be 183 - * not disruptive and back off even without invoking the OOM killer. 184 - * The following three modifiers might be used to override some of these 185 - * implicit rules 186 - * 187 - * %__GFP_NORETRY: The VM implementation will try only very lightweight 188 - * memory direct reclaim to get some memory under memory pressure (thus 189 - * it can sleep). It will avoid disruptive actions like OOM killer. The 190 - * caller must handle the failure which is quite likely to happen under 191 - * heavy memory pressure. The flag is suitable when failure can easily be 192 - * handled at small cost, such as reduced throughput 193 - * 194 - * %__GFP_RETRY_MAYFAIL: The VM implementation will retry memory reclaim 195 - * procedures that have previously failed if there is some indication 196 - * that progress has been made else where. It can wait for other 197 - * tasks to attempt high level approaches to freeing memory such as 198 - * compaction (which removes fragmentation) and page-out. 199 - * There is still a definite limit to the number of retries, but it is 200 - * a larger limit than with %__GFP_NORETRY. 201 - * Allocations with this flag may fail, but only when there is 202 - * genuinely little unused memory. While these allocations do not 203 - * directly trigger the OOM killer, their failure indicates that 204 - * the system is likely to need to use the OOM killer soon. The 205 - * caller must handle failure, but can reasonably do so by failing 206 - * a higher-level request, or completing it only in a much less 207 - * efficient manner. 208 - * If the allocation does fail, and the caller is in a position to 209 - * free some non-essential memory, doing so could benefit the system 210 - * as a whole. 211 - * 212 - * %__GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller 213 - * cannot handle allocation failures. The allocation could block 214 - * indefinitely but will never return with failure. Testing for 215 - * failure is pointless. 216 - * New users should be evaluated carefully (and the flag should be 217 - * used only when there is no reasonable failure policy) but it is 218 - * definitely preferable to use the flag rather than opencode endless 219 - * loop around allocator. 220 - * Using this flag for costly allocations is _highly_ discouraged. 221 - */ 222 - #define __GFP_IO ((__force gfp_t)___GFP_IO) 223 - #define __GFP_FS ((__force gfp_t)___GFP_FS) 224 - #define __GFP_DIRECT_RECLAIM ((__force gfp_t)___GFP_DIRECT_RECLAIM) /* Caller can reclaim */ 225 - #define __GFP_KSWAPD_RECLAIM ((__force gfp_t)___GFP_KSWAPD_RECLAIM) /* kswapd can wake */ 226 - #define __GFP_RECLAIM ((__force gfp_t)(___GFP_DIRECT_RECLAIM|___GFP_KSWAPD_RECLAIM)) 227 - #define __GFP_RETRY_MAYFAIL ((__force gfp_t)___GFP_RETRY_MAYFAIL) 228 - #define __GFP_NOFAIL ((__force gfp_t)___GFP_NOFAIL) 229 - #define __GFP_NORETRY ((__force gfp_t)___GFP_NORETRY) 230 - 231 - /** 232 - * DOC: Action modifiers 233 - * 234 - * Action modifiers 235 - * ---------------- 236 - * 237 - * %__GFP_NOWARN suppresses allocation failure reports. 238 - * 239 - * %__GFP_COMP address compound page metadata. 240 - * 241 - * %__GFP_ZERO returns a zeroed page on success. 242 - * 243 - * %__GFP_ZEROTAGS zeroes memory tags at allocation time if the memory itself 244 - * is being zeroed (either via __GFP_ZERO or via init_on_alloc, provided that 245 - * __GFP_SKIP_ZERO is not set). This flag is intended for optimization: setting 246 - * memory tags at the same time as zeroing memory has minimal additional 247 - * performace impact. 248 - * 249 - * %__GFP_SKIP_KASAN_UNPOISON makes KASAN skip unpoisoning on page allocation. 250 - * Only effective in HW_TAGS mode. 251 - * 252 - * %__GFP_SKIP_KASAN_POISON makes KASAN skip poisoning on page deallocation. 253 - * Typically, used for userspace pages. Only effective in HW_TAGS mode. 254 - */ 255 - #define __GFP_NOWARN ((__force gfp_t)___GFP_NOWARN) 256 - #define __GFP_COMP ((__force gfp_t)___GFP_COMP) 257 - #define __GFP_ZERO ((__force gfp_t)___GFP_ZERO) 258 - #define __GFP_ZEROTAGS ((__force gfp_t)___GFP_ZEROTAGS) 259 - #define __GFP_SKIP_ZERO ((__force gfp_t)___GFP_SKIP_ZERO) 260 - #define __GFP_SKIP_KASAN_UNPOISON ((__force gfp_t)___GFP_SKIP_KASAN_UNPOISON) 261 - #define __GFP_SKIP_KASAN_POISON ((__force gfp_t)___GFP_SKIP_KASAN_POISON) 262 - 263 - /* Disable lockdep for GFP context tracking */ 264 - #define __GFP_NOLOCKDEP ((__force gfp_t)___GFP_NOLOCKDEP) 265 - 266 - /* Room for N __GFP_FOO bits */ 267 - #define __GFP_BITS_SHIFT (27 + IS_ENABLED(CONFIG_LOCKDEP)) 268 - #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) 269 - 270 - /** 271 - * DOC: Useful GFP flag combinations 272 - * 273 - * Useful GFP flag combinations 274 - * ---------------------------- 275 - * 276 - * Useful GFP flag combinations that are commonly used. It is recommended 277 - * that subsystems start with one of these combinations and then set/clear 278 - * %__GFP_FOO flags as necessary. 279 - * 280 - * %GFP_ATOMIC users can not sleep and need the allocation to succeed. A lower 281 - * watermark is applied to allow access to "atomic reserves". 282 - * The current implementation doesn't support NMI and few other strict 283 - * non-preemptive contexts (e.g. raw_spin_lock). The same applies to %GFP_NOWAIT. 284 - * 285 - * %GFP_KERNEL is typical for kernel-internal allocations. The caller requires 286 - * %ZONE_NORMAL or a lower zone for direct access but can direct reclaim. 287 - * 288 - * %GFP_KERNEL_ACCOUNT is the same as GFP_KERNEL, except the allocation is 289 - * accounted to kmemcg. 290 - * 291 - * %GFP_NOWAIT is for kernel allocations that should not stall for direct 292 - * reclaim, start physical IO or use any filesystem callback. 293 - * 294 - * %GFP_NOIO will use direct reclaim to discard clean pages or slab pages 295 - * that do not require the starting of any physical IO. 296 - * Please try to avoid using this flag directly and instead use 297 - * memalloc_noio_{save,restore} to mark the whole scope which cannot 298 - * perform any IO with a short explanation why. All allocation requests 299 - * will inherit GFP_NOIO implicitly. 300 - * 301 - * %GFP_NOFS will use direct reclaim but will not use any filesystem interfaces. 302 - * Please try to avoid using this flag directly and instead use 303 - * memalloc_nofs_{save,restore} to mark the whole scope which cannot/shouldn't 304 - * recurse into the FS layer with a short explanation why. All allocation 305 - * requests will inherit GFP_NOFS implicitly. 306 - * 307 - * %GFP_USER is for userspace allocations that also need to be directly 308 - * accessibly by the kernel or hardware. It is typically used by hardware 309 - * for buffers that are mapped to userspace (e.g. graphics) that hardware 310 - * still must DMA to. cpuset limits are enforced for these allocations. 311 - * 312 - * %GFP_DMA exists for historical reasons and should be avoided where possible. 313 - * The flags indicates that the caller requires that the lowest zone be 314 - * used (%ZONE_DMA or 16M on x86-64). Ideally, this would be removed but 315 - * it would require careful auditing as some users really require it and 316 - * others use the flag to avoid lowmem reserves in %ZONE_DMA and treat the 317 - * lowest zone as a type of emergency reserve. 318 - * 319 - * %GFP_DMA32 is similar to %GFP_DMA except that the caller requires a 32-bit 320 - * address. Note that kmalloc(..., GFP_DMA32) does not return DMA32 memory 321 - * because the DMA32 kmalloc cache array is not implemented. 322 - * (Reason: there is no such user in kernel). 323 - * 324 - * %GFP_HIGHUSER is for userspace allocations that may be mapped to userspace, 325 - * do not need to be directly accessible by the kernel but that cannot 326 - * move once in use. An example may be a hardware allocation that maps 327 - * data directly into userspace but has no addressing limitations. 328 - * 329 - * %GFP_HIGHUSER_MOVABLE is for userspace allocations that the kernel does not 330 - * need direct access to but can use kmap() when access is required. They 331 - * are expected to be movable via page reclaim or page migration. Typically, 332 - * pages on the LRU would also be allocated with %GFP_HIGHUSER_MOVABLE. 333 - * 334 - * %GFP_TRANSHUGE and %GFP_TRANSHUGE_LIGHT are used for THP allocations. They 335 - * are compound allocations that will generally fail quickly if memory is not 336 - * available and will not wake kswapd/kcompactd on failure. The _LIGHT 337 - * version does not attempt reclaim/compaction at all and is by default used 338 - * in page fault path, while the non-light is used by khugepaged. 339 - */ 340 - #define GFP_ATOMIC (__GFP_HIGH|__GFP_ATOMIC|__GFP_KSWAPD_RECLAIM) 341 - #define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) 342 - #define GFP_KERNEL_ACCOUNT (GFP_KERNEL | __GFP_ACCOUNT) 343 - #define GFP_NOWAIT (__GFP_KSWAPD_RECLAIM) 344 - #define GFP_NOIO (__GFP_RECLAIM) 345 - #define GFP_NOFS (__GFP_RECLAIM | __GFP_IO) 346 - #define GFP_USER (__GFP_RECLAIM | __GFP_IO | __GFP_FS | __GFP_HARDWALL) 347 - #define GFP_DMA __GFP_DMA 348 - #define GFP_DMA32 __GFP_DMA32 349 - #define GFP_HIGHUSER (GFP_USER | __GFP_HIGHMEM) 350 - #define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE | \ 351 - __GFP_SKIP_KASAN_POISON | __GFP_SKIP_KASAN_UNPOISON) 352 - #define GFP_TRANSHUGE_LIGHT ((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \ 353 - __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM) 354 - #define GFP_TRANSHUGE (GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM) 355 11 356 12 /* Convert GFP flags to their corresponding migrate type */ 357 13 #define GFP_MOVABLE_MASK (__GFP_RECLAIMABLE|__GFP_MOVABLE)
+348
include/linux/gfp_types.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __LINUX_GFP_TYPES_H 3 + #define __LINUX_GFP_TYPES_H 4 + 5 + /* The typedef is in types.h but we want the documentation here */ 6 + #if 0 7 + /** 8 + * typedef gfp_t - Memory allocation flags. 9 + * 10 + * GFP flags are commonly used throughout Linux to indicate how memory 11 + * should be allocated. The GFP acronym stands for get_free_pages(), 12 + * the underlying memory allocation function. Not every GFP flag is 13 + * supported by every function which may allocate memory. Most users 14 + * will want to use a plain ``GFP_KERNEL``. 15 + */ 16 + typedef unsigned int __bitwise gfp_t; 17 + #endif 18 + 19 + /* 20 + * In case of changes, please don't forget to update 21 + * include/trace/events/mmflags.h and tools/perf/builtin-kmem.c 22 + */ 23 + 24 + /* Plain integer GFP bitmasks. Do not use this directly. */ 25 + #define ___GFP_DMA 0x01u 26 + #define ___GFP_HIGHMEM 0x02u 27 + #define ___GFP_DMA32 0x04u 28 + #define ___GFP_MOVABLE 0x08u 29 + #define ___GFP_RECLAIMABLE 0x10u 30 + #define ___GFP_HIGH 0x20u 31 + #define ___GFP_IO 0x40u 32 + #define ___GFP_FS 0x80u 33 + #define ___GFP_ZERO 0x100u 34 + #define ___GFP_ATOMIC 0x200u 35 + #define ___GFP_DIRECT_RECLAIM 0x400u 36 + #define ___GFP_KSWAPD_RECLAIM 0x800u 37 + #define ___GFP_WRITE 0x1000u 38 + #define ___GFP_NOWARN 0x2000u 39 + #define ___GFP_RETRY_MAYFAIL 0x4000u 40 + #define ___GFP_NOFAIL 0x8000u 41 + #define ___GFP_NORETRY 0x10000u 42 + #define ___GFP_MEMALLOC 0x20000u 43 + #define ___GFP_COMP 0x40000u 44 + #define ___GFP_NOMEMALLOC 0x80000u 45 + #define ___GFP_HARDWALL 0x100000u 46 + #define ___GFP_THISNODE 0x200000u 47 + #define ___GFP_ACCOUNT 0x400000u 48 + #define ___GFP_ZEROTAGS 0x800000u 49 + #ifdef CONFIG_KASAN_HW_TAGS 50 + #define ___GFP_SKIP_ZERO 0x1000000u 51 + #define ___GFP_SKIP_KASAN_UNPOISON 0x2000000u 52 + #define ___GFP_SKIP_KASAN_POISON 0x4000000u 53 + #else 54 + #define ___GFP_SKIP_ZERO 0 55 + #define ___GFP_SKIP_KASAN_UNPOISON 0 56 + #define ___GFP_SKIP_KASAN_POISON 0 57 + #endif 58 + #ifdef CONFIG_LOCKDEP 59 + #define ___GFP_NOLOCKDEP 0x8000000u 60 + #else 61 + #define ___GFP_NOLOCKDEP 0 62 + #endif 63 + /* If the above are modified, __GFP_BITS_SHIFT may need updating */ 64 + 65 + /* 66 + * Physical address zone modifiers (see linux/mmzone.h - low four bits) 67 + * 68 + * Do not put any conditional on these. If necessary modify the definitions 69 + * without the underscores and use them consistently. The definitions here may 70 + * be used in bit comparisons. 71 + */ 72 + #define __GFP_DMA ((__force gfp_t)___GFP_DMA) 73 + #define __GFP_HIGHMEM ((__force gfp_t)___GFP_HIGHMEM) 74 + #define __GFP_DMA32 ((__force gfp_t)___GFP_DMA32) 75 + #define __GFP_MOVABLE ((__force gfp_t)___GFP_MOVABLE) /* ZONE_MOVABLE allowed */ 76 + #define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE) 77 + 78 + /** 79 + * DOC: Page mobility and placement hints 80 + * 81 + * Page mobility and placement hints 82 + * --------------------------------- 83 + * 84 + * These flags provide hints about how mobile the page is. Pages with similar 85 + * mobility are placed within the same pageblocks to minimise problems due 86 + * to external fragmentation. 87 + * 88 + * %__GFP_MOVABLE (also a zone modifier) indicates that the page can be 89 + * moved by page migration during memory compaction or can be reclaimed. 90 + * 91 + * %__GFP_RECLAIMABLE is used for slab allocations that specify 92 + * SLAB_RECLAIM_ACCOUNT and whose pages can be freed via shrinkers. 93 + * 94 + * %__GFP_WRITE indicates the caller intends to dirty the page. Where possible, 95 + * these pages will be spread between local zones to avoid all the dirty 96 + * pages being in one zone (fair zone allocation policy). 97 + * 98 + * %__GFP_HARDWALL enforces the cpuset memory allocation policy. 99 + * 100 + * %__GFP_THISNODE forces the allocation to be satisfied from the requested 101 + * node with no fallbacks or placement policy enforcements. 102 + * 103 + * %__GFP_ACCOUNT causes the allocation to be accounted to kmemcg. 104 + */ 105 + #define __GFP_RECLAIMABLE ((__force gfp_t)___GFP_RECLAIMABLE) 106 + #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) 107 + #define __GFP_HARDWALL ((__force gfp_t)___GFP_HARDWALL) 108 + #define __GFP_THISNODE ((__force gfp_t)___GFP_THISNODE) 109 + #define __GFP_ACCOUNT ((__force gfp_t)___GFP_ACCOUNT) 110 + 111 + /** 112 + * DOC: Watermark modifiers 113 + * 114 + * Watermark modifiers -- controls access to emergency reserves 115 + * ------------------------------------------------------------ 116 + * 117 + * %__GFP_HIGH indicates that the caller is high-priority and that granting 118 + * the request is necessary before the system can make forward progress. 119 + * For example, creating an IO context to clean pages. 120 + * 121 + * %__GFP_ATOMIC indicates that the caller cannot reclaim or sleep and is 122 + * high priority. Users are typically interrupt handlers. This may be 123 + * used in conjunction with %__GFP_HIGH 124 + * 125 + * %__GFP_MEMALLOC allows access to all memory. This should only be used when 126 + * the caller guarantees the allocation will allow more memory to be freed 127 + * very shortly e.g. process exiting or swapping. Users either should 128 + * be the MM or co-ordinating closely with the VM (e.g. swap over NFS). 129 + * Users of this flag have to be extremely careful to not deplete the reserve 130 + * completely and implement a throttling mechanism which controls the 131 + * consumption of the reserve based on the amount of freed memory. 132 + * Usage of a pre-allocated pool (e.g. mempool) should be always considered 133 + * before using this flag. 134 + * 135 + * %__GFP_NOMEMALLOC is used to explicitly forbid access to emergency reserves. 136 + * This takes precedence over the %__GFP_MEMALLOC flag if both are set. 137 + */ 138 + #define __GFP_ATOMIC ((__force gfp_t)___GFP_ATOMIC) 139 + #define __GFP_HIGH ((__force gfp_t)___GFP_HIGH) 140 + #define __GFP_MEMALLOC ((__force gfp_t)___GFP_MEMALLOC) 141 + #define __GFP_NOMEMALLOC ((__force gfp_t)___GFP_NOMEMALLOC) 142 + 143 + /** 144 + * DOC: Reclaim modifiers 145 + * 146 + * Reclaim modifiers 147 + * ----------------- 148 + * Please note that all the following flags are only applicable to sleepable 149 + * allocations (e.g. %GFP_NOWAIT and %GFP_ATOMIC will ignore them). 150 + * 151 + * %__GFP_IO can start physical IO. 152 + * 153 + * %__GFP_FS can call down to the low-level FS. Clearing the flag avoids the 154 + * allocator recursing into the filesystem which might already be holding 155 + * locks. 156 + * 157 + * %__GFP_DIRECT_RECLAIM indicates that the caller may enter direct reclaim. 158 + * This flag can be cleared to avoid unnecessary delays when a fallback 159 + * option is available. 160 + * 161 + * %__GFP_KSWAPD_RECLAIM indicates that the caller wants to wake kswapd when 162 + * the low watermark is reached and have it reclaim pages until the high 163 + * watermark is reached. A caller may wish to clear this flag when fallback 164 + * options are available and the reclaim is likely to disrupt the system. The 165 + * canonical example is THP allocation where a fallback is cheap but 166 + * reclaim/compaction may cause indirect stalls. 167 + * 168 + * %__GFP_RECLAIM is shorthand to allow/forbid both direct and kswapd reclaim. 169 + * 170 + * The default allocator behavior depends on the request size. We have a concept 171 + * of so called costly allocations (with order > %PAGE_ALLOC_COSTLY_ORDER). 172 + * !costly allocations are too essential to fail so they are implicitly 173 + * non-failing by default (with some exceptions like OOM victims might fail so 174 + * the caller still has to check for failures) while costly requests try to be 175 + * not disruptive and back off even without invoking the OOM killer. 176 + * The following three modifiers might be used to override some of these 177 + * implicit rules 178 + * 179 + * %__GFP_NORETRY: The VM implementation will try only very lightweight 180 + * memory direct reclaim to get some memory under memory pressure (thus 181 + * it can sleep). It will avoid disruptive actions like OOM killer. The 182 + * caller must handle the failure which is quite likely to happen under 183 + * heavy memory pressure. The flag is suitable when failure can easily be 184 + * handled at small cost, such as reduced throughput 185 + * 186 + * %__GFP_RETRY_MAYFAIL: The VM implementation will retry memory reclaim 187 + * procedures that have previously failed if there is some indication 188 + * that progress has been made else where. It can wait for other 189 + * tasks to attempt high level approaches to freeing memory such as 190 + * compaction (which removes fragmentation) and page-out. 191 + * There is still a definite limit to the number of retries, but it is 192 + * a larger limit than with %__GFP_NORETRY. 193 + * Allocations with this flag may fail, but only when there is 194 + * genuinely little unused memory. While these allocations do not 195 + * directly trigger the OOM killer, their failure indicates that 196 + * the system is likely to need to use the OOM killer soon. The 197 + * caller must handle failure, but can reasonably do so by failing 198 + * a higher-level request, or completing it only in a much less 199 + * efficient manner. 200 + * If the allocation does fail, and the caller is in a position to 201 + * free some non-essential memory, doing so could benefit the system 202 + * as a whole. 203 + * 204 + * %__GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller 205 + * cannot handle allocation failures. The allocation could block 206 + * indefinitely but will never return with failure. Testing for 207 + * failure is pointless. 208 + * New users should be evaluated carefully (and the flag should be 209 + * used only when there is no reasonable failure policy) but it is 210 + * definitely preferable to use the flag rather than opencode endless 211 + * loop around allocator. 212 + * Using this flag for costly allocations is _highly_ discouraged. 213 + */ 214 + #define __GFP_IO ((__force gfp_t)___GFP_IO) 215 + #define __GFP_FS ((__force gfp_t)___GFP_FS) 216 + #define __GFP_DIRECT_RECLAIM ((__force gfp_t)___GFP_DIRECT_RECLAIM) /* Caller can reclaim */ 217 + #define __GFP_KSWAPD_RECLAIM ((__force gfp_t)___GFP_KSWAPD_RECLAIM) /* kswapd can wake */ 218 + #define __GFP_RECLAIM ((__force gfp_t)(___GFP_DIRECT_RECLAIM|___GFP_KSWAPD_RECLAIM)) 219 + #define __GFP_RETRY_MAYFAIL ((__force gfp_t)___GFP_RETRY_MAYFAIL) 220 + #define __GFP_NOFAIL ((__force gfp_t)___GFP_NOFAIL) 221 + #define __GFP_NORETRY ((__force gfp_t)___GFP_NORETRY) 222 + 223 + /** 224 + * DOC: Action modifiers 225 + * 226 + * Action modifiers 227 + * ---------------- 228 + * 229 + * %__GFP_NOWARN suppresses allocation failure reports. 230 + * 231 + * %__GFP_COMP address compound page metadata. 232 + * 233 + * %__GFP_ZERO returns a zeroed page on success. 234 + * 235 + * %__GFP_ZEROTAGS zeroes memory tags at allocation time if the memory itself 236 + * is being zeroed (either via __GFP_ZERO or via init_on_alloc, provided that 237 + * __GFP_SKIP_ZERO is not set). This flag is intended for optimization: setting 238 + * memory tags at the same time as zeroing memory has minimal additional 239 + * performace impact. 240 + * 241 + * %__GFP_SKIP_KASAN_UNPOISON makes KASAN skip unpoisoning on page allocation. 242 + * Only effective in HW_TAGS mode. 243 + * 244 + * %__GFP_SKIP_KASAN_POISON makes KASAN skip poisoning on page deallocation. 245 + * Typically, used for userspace pages. Only effective in HW_TAGS mode. 246 + */ 247 + #define __GFP_NOWARN ((__force gfp_t)___GFP_NOWARN) 248 + #define __GFP_COMP ((__force gfp_t)___GFP_COMP) 249 + #define __GFP_ZERO ((__force gfp_t)___GFP_ZERO) 250 + #define __GFP_ZEROTAGS ((__force gfp_t)___GFP_ZEROTAGS) 251 + #define __GFP_SKIP_ZERO ((__force gfp_t)___GFP_SKIP_ZERO) 252 + #define __GFP_SKIP_KASAN_UNPOISON ((__force gfp_t)___GFP_SKIP_KASAN_UNPOISON) 253 + #define __GFP_SKIP_KASAN_POISON ((__force gfp_t)___GFP_SKIP_KASAN_POISON) 254 + 255 + /* Disable lockdep for GFP context tracking */ 256 + #define __GFP_NOLOCKDEP ((__force gfp_t)___GFP_NOLOCKDEP) 257 + 258 + /* Room for N __GFP_FOO bits */ 259 + #define __GFP_BITS_SHIFT (27 + IS_ENABLED(CONFIG_LOCKDEP)) 260 + #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) 261 + 262 + /** 263 + * DOC: Useful GFP flag combinations 264 + * 265 + * Useful GFP flag combinations 266 + * ---------------------------- 267 + * 268 + * Useful GFP flag combinations that are commonly used. It is recommended 269 + * that subsystems start with one of these combinations and then set/clear 270 + * %__GFP_FOO flags as necessary. 271 + * 272 + * %GFP_ATOMIC users can not sleep and need the allocation to succeed. A lower 273 + * watermark is applied to allow access to "atomic reserves". 274 + * The current implementation doesn't support NMI and few other strict 275 + * non-preemptive contexts (e.g. raw_spin_lock). The same applies to %GFP_NOWAIT. 276 + * 277 + * %GFP_KERNEL is typical for kernel-internal allocations. The caller requires 278 + * %ZONE_NORMAL or a lower zone for direct access but can direct reclaim. 279 + * 280 + * %GFP_KERNEL_ACCOUNT is the same as GFP_KERNEL, except the allocation is 281 + * accounted to kmemcg. 282 + * 283 + * %GFP_NOWAIT is for kernel allocations that should not stall for direct 284 + * reclaim, start physical IO or use any filesystem callback. 285 + * 286 + * %GFP_NOIO will use direct reclaim to discard clean pages or slab pages 287 + * that do not require the starting of any physical IO. 288 + * Please try to avoid using this flag directly and instead use 289 + * memalloc_noio_{save,restore} to mark the whole scope which cannot 290 + * perform any IO with a short explanation why. All allocation requests 291 + * will inherit GFP_NOIO implicitly. 292 + * 293 + * %GFP_NOFS will use direct reclaim but will not use any filesystem interfaces. 294 + * Please try to avoid using this flag directly and instead use 295 + * memalloc_nofs_{save,restore} to mark the whole scope which cannot/shouldn't 296 + * recurse into the FS layer with a short explanation why. All allocation 297 + * requests will inherit GFP_NOFS implicitly. 298 + * 299 + * %GFP_USER is for userspace allocations that also need to be directly 300 + * accessibly by the kernel or hardware. It is typically used by hardware 301 + * for buffers that are mapped to userspace (e.g. graphics) that hardware 302 + * still must DMA to. cpuset limits are enforced for these allocations. 303 + * 304 + * %GFP_DMA exists for historical reasons and should be avoided where possible. 305 + * The flags indicates that the caller requires that the lowest zone be 306 + * used (%ZONE_DMA or 16M on x86-64). Ideally, this would be removed but 307 + * it would require careful auditing as some users really require it and 308 + * others use the flag to avoid lowmem reserves in %ZONE_DMA and treat the 309 + * lowest zone as a type of emergency reserve. 310 + * 311 + * %GFP_DMA32 is similar to %GFP_DMA except that the caller requires a 32-bit 312 + * address. Note that kmalloc(..., GFP_DMA32) does not return DMA32 memory 313 + * because the DMA32 kmalloc cache array is not implemented. 314 + * (Reason: there is no such user in kernel). 315 + * 316 + * %GFP_HIGHUSER is for userspace allocations that may be mapped to userspace, 317 + * do not need to be directly accessible by the kernel but that cannot 318 + * move once in use. An example may be a hardware allocation that maps 319 + * data directly into userspace but has no addressing limitations. 320 + * 321 + * %GFP_HIGHUSER_MOVABLE is for userspace allocations that the kernel does not 322 + * need direct access to but can use kmap() when access is required. They 323 + * are expected to be movable via page reclaim or page migration. Typically, 324 + * pages on the LRU would also be allocated with %GFP_HIGHUSER_MOVABLE. 325 + * 326 + * %GFP_TRANSHUGE and %GFP_TRANSHUGE_LIGHT are used for THP allocations. They 327 + * are compound allocations that will generally fail quickly if memory is not 328 + * available and will not wake kswapd/kcompactd on failure. The _LIGHT 329 + * version does not attempt reclaim/compaction at all and is by default used 330 + * in page fault path, while the non-light is used by khugepaged. 331 + */ 332 + #define GFP_ATOMIC (__GFP_HIGH|__GFP_ATOMIC|__GFP_KSWAPD_RECLAIM) 333 + #define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) 334 + #define GFP_KERNEL_ACCOUNT (GFP_KERNEL | __GFP_ACCOUNT) 335 + #define GFP_NOWAIT (__GFP_KSWAPD_RECLAIM) 336 + #define GFP_NOIO (__GFP_RECLAIM) 337 + #define GFP_NOFS (__GFP_RECLAIM | __GFP_IO) 338 + #define GFP_USER (__GFP_RECLAIM | __GFP_IO | __GFP_FS | __GFP_HARDWALL) 339 + #define GFP_DMA __GFP_DMA 340 + #define GFP_DMA32 __GFP_DMA32 341 + #define GFP_HIGHUSER (GFP_USER | __GFP_HIGHMEM) 342 + #define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE | \ 343 + __GFP_SKIP_KASAN_POISON | __GFP_SKIP_KASAN_UNPOISON) 344 + #define GFP_TRANSHUGE_LIGHT ((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \ 345 + __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM) 346 + #define GFP_TRANSHUGE (GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM) 347 + 348 + #endif /* __LINUX_GFP_TYPES_H */
+20 -6
include/linux/nodemask.h
··· 94 94 #include <linux/bitmap.h> 95 95 #include <linux/minmax.h> 96 96 #include <linux/numa.h> 97 + #include <linux/random.h> 97 98 98 99 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t; 99 100 extern nodemask_t _unused_nodemask_arg_; ··· 277 276 * the first node in src if needed. Returns MAX_NUMNODES if src is empty. 278 277 */ 279 278 #define next_node_in(n, src) __next_node_in((n), &(src)) 280 - unsigned int __next_node_in(int node, const nodemask_t *srcp); 279 + static inline unsigned int __next_node_in(int node, const nodemask_t *srcp) 280 + { 281 + unsigned int ret = __next_node(node, srcp); 282 + 283 + if (ret == MAX_NUMNODES) 284 + ret = __first_node(srcp); 285 + return ret; 286 + } 281 287 282 288 static inline void init_nodemask_of_node(nodemask_t *mask, int node) 283 289 { ··· 501 493 502 494 #endif 503 495 504 - #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1) 505 - extern int node_random(const nodemask_t *maskp); 506 - #else 507 - static inline int node_random(const nodemask_t *mask) 496 + static inline int node_random(const nodemask_t *maskp) 508 497 { 498 + #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1) 499 + int w, bit = NUMA_NO_NODE; 500 + 501 + w = nodes_weight(*maskp); 502 + if (w) 503 + bit = bitmap_ord_to_pos(maskp->bits, 504 + get_random_int() % w, MAX_NUMNODES); 505 + return bit; 506 + #else 509 507 return 0; 510 - } 511 508 #endif 509 + } 512 510 513 511 #define node_online_map node_states[N_ONLINE] 514 512 #define node_possible_map node_states[N_POSSIBLE]
+1 -1
lib/Makefile
··· 33 33 flex_proportions.o ratelimit.o show_mem.o \ 34 34 is_single_threaded.o plist.o decompress.o kobject_uevent.o \ 35 35 earlycpio.o seq_buf.o siphash.o dec_and_lock.o \ 36 - nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o \ 36 + nmi_backtrace.o win_minmax.o memcat_p.o \ 37 37 buildid.o cpumask.o 38 38 39 39 lib-$(CONFIG_PRINTK) += dump_stack.o
+5 -6
lib/bitmap.c
··· 237 237 } 238 238 EXPORT_SYMBOL(bitmap_cut); 239 239 240 - int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, 240 + bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, 241 241 const unsigned long *bitmap2, unsigned int bits) 242 242 { 243 243 unsigned int k; ··· 275 275 } 276 276 EXPORT_SYMBOL(__bitmap_xor); 277 277 278 - int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, 278 + bool __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, 279 279 const unsigned long *bitmap2, unsigned int bits) 280 280 { 281 281 unsigned int k; ··· 333 333 } 334 334 EXPORT_SYMBOL(__bitmap_subset); 335 335 336 - int __bitmap_weight(const unsigned long *bitmap, unsigned int bits) 336 + unsigned int __bitmap_weight(const unsigned long *bitmap, unsigned int bits) 337 337 { 338 - unsigned int k, lim = bits/BITS_PER_LONG; 339 - int w = 0; 338 + unsigned int k, lim = bits/BITS_PER_LONG, w = 0; 340 339 341 340 for (k = 0; k < lim; k++) 342 341 w += hweight_long(bitmap[k]); ··· 1563 1564 1564 1565 /* Clear tail bits in the last element of array beyond nbits. */ 1565 1566 if (nbits % 64) 1566 - buf[-1] &= GENMASK_ULL(nbits % 64, 0); 1567 + buf[-1] &= GENMASK_ULL((nbits - 1) % 64, 0); 1567 1568 } 1568 1569 EXPORT_SYMBOL(bitmap_to_arr64); 1569 1570 #endif
+7 -90
lib/cpumask.c
··· 8 8 #include <linux/numa.h> 9 9 10 10 /** 11 - * cpumask_next - get the next cpu in a cpumask 12 - * @n: the cpu prior to the place to search (ie. return will be > @n) 13 - * @srcp: the cpumask pointer 14 - * 15 - * Returns >= nr_cpu_ids if no further cpus set. 16 - */ 17 - unsigned int cpumask_next(int n, const struct cpumask *srcp) 18 - { 19 - /* -1 is a legal arg here. */ 20 - if (n != -1) 21 - cpumask_check(n); 22 - return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n + 1); 23 - } 24 - EXPORT_SYMBOL(cpumask_next); 25 - 26 - /** 27 - * cpumask_next_and - get the next cpu in *src1p & *src2p 28 - * @n: the cpu prior to the place to search (ie. return will be > @n) 29 - * @src1p: the first cpumask pointer 30 - * @src2p: the second cpumask pointer 31 - * 32 - * Returns >= nr_cpu_ids if no further cpus set in both. 33 - */ 34 - int cpumask_next_and(int n, const struct cpumask *src1p, 35 - const struct cpumask *src2p) 36 - { 37 - /* -1 is a legal arg here. */ 38 - if (n != -1) 39 - cpumask_check(n); 40 - return find_next_and_bit(cpumask_bits(src1p), cpumask_bits(src2p), 41 - nr_cpumask_bits, n + 1); 42 - } 43 - EXPORT_SYMBOL(cpumask_next_and); 44 - 45 - /** 46 - * cpumask_any_but - return a "random" in a cpumask, but not this one. 47 - * @mask: the cpumask to search 48 - * @cpu: the cpu to ignore. 49 - * 50 - * Often used to find any cpu but smp_processor_id() in a mask. 51 - * Returns >= nr_cpu_ids if no cpus set. 52 - */ 53 - int cpumask_any_but(const struct cpumask *mask, unsigned int cpu) 54 - { 55 - unsigned int i; 56 - 57 - cpumask_check(cpu); 58 - for_each_cpu(i, mask) 59 - if (i != cpu) 60 - break; 61 - return i; 62 - } 63 - EXPORT_SYMBOL(cpumask_any_but); 64 - 65 - /** 66 11 * cpumask_next_wrap - helper to implement for_each_cpu_wrap 67 12 * @n: the cpu prior to the place to search 68 13 * @mask: the cpumask pointer ··· 19 74 * Note: the @wrap argument is required for the start condition when 20 75 * we cannot assume @start is set in @mask. 21 76 */ 22 - int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap) 77 + unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap) 23 78 { 24 - int next; 79 + unsigned int next; 25 80 26 81 again: 27 82 next = cpumask_next(n, mask); ··· 69 124 return *mask != NULL; 70 125 } 71 126 EXPORT_SYMBOL(alloc_cpumask_var_node); 72 - 73 - bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node) 74 - { 75 - return alloc_cpumask_var_node(mask, flags | __GFP_ZERO, node); 76 - } 77 - EXPORT_SYMBOL(zalloc_cpumask_var_node); 78 - 79 - /** 80 - * alloc_cpumask_var - allocate a struct cpumask 81 - * @mask: pointer to cpumask_var_t where the cpumask is returned 82 - * @flags: GFP_ flags 83 - * 84 - * Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is 85 - * a nop returning a constant 1 (in <linux/cpumask.h>). 86 - * 87 - * See alloc_cpumask_var_node. 88 - */ 89 - bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) 90 - { 91 - return alloc_cpumask_var_node(mask, flags, NUMA_NO_NODE); 92 - } 93 - EXPORT_SYMBOL(alloc_cpumask_var); 94 - 95 - bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) 96 - { 97 - return alloc_cpumask_var(mask, flags | __GFP_ZERO); 98 - } 99 - EXPORT_SYMBOL(zalloc_cpumask_var); 100 127 101 128 /** 102 129 * alloc_bootmem_cpumask_var - allocate a struct cpumask from the bootmem arena. ··· 123 206 */ 124 207 unsigned int cpumask_local_spread(unsigned int i, int node) 125 208 { 126 - int cpu; 209 + unsigned int cpu; 127 210 128 211 /* Wrap: we always want a cpu. */ 129 212 i %= num_online_cpus(); ··· 161 244 * 162 245 * Returns >= nr_cpu_ids if the intersection is empty. 163 246 */ 164 - int cpumask_any_and_distribute(const struct cpumask *src1p, 247 + unsigned int cpumask_any_and_distribute(const struct cpumask *src1p, 165 248 const struct cpumask *src2p) 166 249 { 167 - int next, prev; 250 + unsigned int next, prev; 168 251 169 252 /* NOTE: our first selection will skip 0. */ 170 253 prev = __this_cpu_read(distribute_cpu_mask_prev); ··· 180 263 } 181 264 EXPORT_SYMBOL(cpumask_any_and_distribute); 182 265 183 - int cpumask_any_distribute(const struct cpumask *srcp) 266 + unsigned int cpumask_any_distribute(const struct cpumask *srcp) 184 267 { 185 - int next, prev; 268 + unsigned int next, prev; 186 269 187 270 /* NOTE: our first selection will skip 0. */ 188 271 prev = __this_cpu_read(distribute_cpu_mask_prev);
-8
lib/nodemask.c
··· 3 3 #include <linux/module.h> 4 4 #include <linux/random.h> 5 5 6 - unsigned int __next_node_in(int node, const nodemask_t *srcp) 7 - { 8 - unsigned int ret = __next_node(node, srcp); 9 - 10 - if (ret == MAX_NUMNODES) 11 - ret = __first_node(srcp); 12 - return ret; 13 - } 14 6 EXPORT_SYMBOL(__next_node_in); 15 7 16 8 #ifdef CONFIG_NUMA
+68
lib/test_bitmap.c
··· 604 604 pr_err("bitmap_copy_arr64(nbits == %d:" 605 605 " tail is not safely cleared: %d\n", nbits, next_bit); 606 606 607 + if ((nbits % 64) && 608 + (arr[(nbits - 1) / 64] & ~GENMASK_ULL((nbits - 1) % 64, 0))) 609 + pr_err("bitmap_to_arr64(nbits == %d): tail is not safely cleared: 0x%016llx (must be 0x%016llx)\n", 610 + nbits, arr[(nbits - 1) / 64], 611 + GENMASK_ULL((nbits - 1) % 64, 0)); 612 + 607 613 if (nbits < EXP1_IN_BITS - 64) 608 614 expect_eq_uint(arr[DIV_ROUND_UP(nbits, 64)], 0xa5a5a5a5); 609 615 } ··· 875 869 } 876 870 } 877 871 872 + static void __init test_bitmap_const_eval(void) 873 + { 874 + DECLARE_BITMAP(bitmap, BITS_PER_LONG); 875 + unsigned long initvar = BIT(2); 876 + unsigned long bitopvar = 0; 877 + unsigned long var = 0; 878 + int res; 879 + 880 + /* 881 + * Compilers must be able to optimize all of those to compile-time 882 + * constants on any supported optimization level (-O2, -Os) and any 883 + * architecture. Otherwise, trigger a build bug. 884 + * The whole function gets optimized out then, there's nothing to do 885 + * in runtime. 886 + */ 887 + 888 + /* 889 + * Equals to `unsigned long bitmap[1] = { GENMASK(6, 5), }`. 890 + * Clang on s390 optimizes bitops at compile-time as intended, but at 891 + * the same time stops treating @bitmap and @bitopvar as compile-time 892 + * constants after regular test_bit() is executed, thus triggering the 893 + * build bugs below. So, call const_test_bit() there directly until 894 + * the compiler is fixed. 895 + */ 896 + bitmap_clear(bitmap, 0, BITS_PER_LONG); 897 + #if defined(__s390__) && defined(__clang__) 898 + if (!const_test_bit(7, bitmap)) 899 + #else 900 + if (!test_bit(7, bitmap)) 901 + #endif 902 + bitmap_set(bitmap, 5, 2); 903 + 904 + /* Equals to `unsigned long bitopvar = BIT(20)` */ 905 + __change_bit(31, &bitopvar); 906 + bitmap_shift_right(&bitopvar, &bitopvar, 11, BITS_PER_LONG); 907 + 908 + /* Equals to `unsigned long var = BIT(25)` */ 909 + var |= BIT(25); 910 + if (var & BIT(0)) 911 + var ^= GENMASK(9, 6); 912 + 913 + /* __const_hweight<32|64>(GENMASK(6, 5)) == 2 */ 914 + res = bitmap_weight(bitmap, 20); 915 + BUILD_BUG_ON(!__builtin_constant_p(res)); 916 + BUILD_BUG_ON(res != 2); 917 + 918 + /* !(BIT(31) & BIT(18)) == 1 */ 919 + res = !test_bit(18, &bitopvar); 920 + BUILD_BUG_ON(!__builtin_constant_p(res)); 921 + BUILD_BUG_ON(!res); 922 + 923 + /* BIT(2) & GENMASK(14, 8) == 0 */ 924 + res = initvar & GENMASK(14, 8); 925 + BUILD_BUG_ON(!__builtin_constant_p(res)); 926 + BUILD_BUG_ON(res); 927 + 928 + /* ~BIT(25) */ 929 + BUILD_BUG_ON(!__builtin_constant_p(~var)); 930 + BUILD_BUG_ON(~var != ~BIT(25)); 931 + } 932 + 878 933 static void __init selftest(void) 879 934 { 880 935 test_zero_clear(); ··· 951 884 test_for_each_set_clump8(); 952 885 test_bitmap_cut(); 953 886 test_bitmap_print_buf(); 887 + test_bitmap_const_eval(); 954 888 } 955 889 956 890 KSTM_MODULE_LOADERS(test_bitmap);
+20 -14
tools/include/asm-generic/bitops/non-atomic.h
··· 2 2 #ifndef _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ 3 3 #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ 4 4 5 - #include <asm/types.h> 5 + #include <linux/bits.h> 6 6 7 7 /** 8 - * __set_bit - Set a bit in memory 8 + * ___set_bit - Set a bit in memory 9 9 * @nr: the bit to set 10 10 * @addr: the address to start counting from 11 11 * ··· 13 13 * If it's called on the same region of memory simultaneously, the effect 14 14 * may be that only one operation succeeds. 15 15 */ 16 - static inline void __set_bit(int nr, volatile unsigned long *addr) 16 + static __always_inline void 17 + ___set_bit(unsigned long nr, volatile unsigned long *addr) 17 18 { 18 19 unsigned long mask = BIT_MASK(nr); 19 20 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); ··· 22 21 *p |= mask; 23 22 } 24 23 25 - static inline void __clear_bit(int nr, volatile unsigned long *addr) 24 + static __always_inline void 25 + ___clear_bit(unsigned long nr, volatile unsigned long *addr) 26 26 { 27 27 unsigned long mask = BIT_MASK(nr); 28 28 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); ··· 32 30 } 33 31 34 32 /** 35 - * __change_bit - Toggle a bit in memory 33 + * ___change_bit - Toggle a bit in memory 36 34 * @nr: the bit to change 37 35 * @addr: the address to start counting from 38 36 * ··· 40 38 * If it's called on the same region of memory simultaneously, the effect 41 39 * may be that only one operation succeeds. 42 40 */ 43 - static inline void __change_bit(int nr, volatile unsigned long *addr) 41 + static __always_inline void 42 + ___change_bit(unsigned long nr, volatile unsigned long *addr) 44 43 { 45 44 unsigned long mask = BIT_MASK(nr); 46 45 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); ··· 50 47 } 51 48 52 49 /** 53 - * __test_and_set_bit - Set a bit and return its old value 50 + * ___test_and_set_bit - Set a bit and return its old value 54 51 * @nr: Bit to set 55 52 * @addr: Address to count from 56 53 * ··· 58 55 * If two examples of this operation race, one can appear to succeed 59 56 * but actually fail. You must protect multiple accesses with a lock. 60 57 */ 61 - static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) 58 + static __always_inline bool 59 + ___test_and_set_bit(unsigned long nr, volatile unsigned long *addr) 62 60 { 63 61 unsigned long mask = BIT_MASK(nr); 64 62 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); ··· 70 66 } 71 67 72 68 /** 73 - * __test_and_clear_bit - Clear a bit and return its old value 69 + * ___test_and_clear_bit - Clear a bit and return its old value 74 70 * @nr: Bit to clear 75 71 * @addr: Address to count from 76 72 * ··· 78 74 * If two examples of this operation race, one can appear to succeed 79 75 * but actually fail. You must protect multiple accesses with a lock. 80 76 */ 81 - static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) 77 + static __always_inline bool 78 + ___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) 82 79 { 83 80 unsigned long mask = BIT_MASK(nr); 84 81 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); ··· 90 85 } 91 86 92 87 /* WARNING: non atomic and it can be reordered! */ 93 - static inline int __test_and_change_bit(int nr, 94 - volatile unsigned long *addr) 88 + static __always_inline bool 89 + ___test_and_change_bit(unsigned long nr, volatile unsigned long *addr) 95 90 { 96 91 unsigned long mask = BIT_MASK(nr); 97 92 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); ··· 102 97 } 103 98 104 99 /** 105 - * test_bit - Determine whether a bit is set 100 + * _test_bit - Determine whether a bit is set 106 101 * @nr: bit number to test 107 102 * @addr: Address to start counting from 108 103 */ 109 - static inline int test_bit(int nr, const volatile unsigned long *addr) 104 + static __always_inline bool 105 + _test_bit(unsigned long nr, const volatile unsigned long *addr) 110 106 { 111 107 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); 112 108 }
+6 -6
tools/include/linux/bitmap.h
··· 11 11 #define DECLARE_BITMAP(name,bits) \ 12 12 unsigned long name[BITS_TO_LONGS(bits)] 13 13 14 - int __bitmap_weight(const unsigned long *bitmap, int bits); 14 + unsigned int __bitmap_weight(const unsigned long *bitmap, int bits); 15 15 void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, 16 16 const unsigned long *bitmap2, int bits); 17 - int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, 17 + bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, 18 18 const unsigned long *bitmap2, unsigned int bits); 19 19 bool __bitmap_equal(const unsigned long *bitmap1, 20 20 const unsigned long *bitmap2, unsigned int bits); ··· 45 45 dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits); 46 46 } 47 47 48 - static inline int bitmap_empty(const unsigned long *src, unsigned nbits) 48 + static inline bool bitmap_empty(const unsigned long *src, unsigned int nbits) 49 49 { 50 50 if (small_const_nbits(nbits)) 51 51 return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); ··· 53 53 return find_first_bit(src, nbits) == nbits; 54 54 } 55 55 56 - static inline int bitmap_full(const unsigned long *src, unsigned int nbits) 56 + static inline bool bitmap_full(const unsigned long *src, unsigned int nbits) 57 57 { 58 58 if (small_const_nbits(nbits)) 59 59 return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); ··· 61 61 return find_first_zero_bit(src, nbits) == nbits; 62 62 } 63 63 64 - static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) 64 + static inline unsigned int bitmap_weight(const unsigned long *src, unsigned int nbits) 65 65 { 66 66 if (small_const_nbits(nbits)) 67 67 return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); ··· 146 146 * @src2: operand 2 147 147 * @nbits: size of bitmap 148 148 */ 149 - static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, 149 + static inline bool bitmap_and(unsigned long *dst, const unsigned long *src1, 150 150 const unsigned long *src2, unsigned int nbits) 151 151 { 152 152 if (small_const_nbits(nbits))
+16
tools/include/linux/bitops.h
··· 26 26 extern unsigned long __sw_hweight64(__u64 w); 27 27 28 28 /* 29 + * Defined here because those may be needed by architecture-specific static 30 + * inlines. 31 + */ 32 + 33 + #define bitop(op, nr, addr) \ 34 + op(nr, addr) 35 + 36 + #define __set_bit(nr, addr) bitop(___set_bit, nr, addr) 37 + #define __clear_bit(nr, addr) bitop(___clear_bit, nr, addr) 38 + #define __change_bit(nr, addr) bitop(___change_bit, nr, addr) 39 + #define __test_and_set_bit(nr, addr) bitop(___test_and_set_bit, nr, addr) 40 + #define __test_and_clear_bit(nr, addr) bitop(___test_and_clear_bit, nr, addr) 41 + #define __test_and_change_bit(nr, addr) bitop(___test_and_change_bit, nr, addr) 42 + #define test_bit(nr, addr) bitop(_test_bit, nr, addr) 43 + 44 + /* 29 45 * Include this here because some architectures need generic_ffs/fls in 30 46 * scope 31 47 *
+3 -3
tools/lib/bitmap.c
··· 5 5 */ 6 6 #include <linux/bitmap.h> 7 7 8 - int __bitmap_weight(const unsigned long *bitmap, int bits) 8 + unsigned int __bitmap_weight(const unsigned long *bitmap, int bits) 9 9 { 10 - int k, w = 0, lim = bits/BITS_PER_LONG; 10 + unsigned int k, w = 0, lim = bits/BITS_PER_LONG; 11 11 12 12 for (k = 0; k < lim; k++) 13 13 w += hweight_long(bitmap[k]); ··· 57 57 return ret; 58 58 } 59 59 60 - int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, 60 + bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, 61 61 const unsigned long *bitmap2, unsigned int bits) 62 62 { 63 63 unsigned int k;