History

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 ...

Linus Torvalds committed 4 years ago

Commit 4e23eee2 parents 3bc1bc0 36d4b3638 files · +1076 −789Browse files

Unified · Split

38 files
  1. Documentation/core-api/mm-api.rst +4 −4
  2. MAINTAINERS +1 −1
  3. arch/alpha/include/asm/bitops.h +17 −15
  4. arch/arm/include/asm/bitops.h +10 −8
  5. arch/hexagon/include/asm/bitops.h +15 −9
  6. arch/ia64/include/asm/bitops.h +22 −20
  7. arch/ia64/include/asm/processor.h +1 −1
  8. arch/m68k/include/asm/bitops.h +34 −15
  9. arch/powerpc/include/asm/archrandom.h +1 −8
  10. arch/powerpc/kernel/setup-common.c +8 −0
  11. arch/s390/include/asm/bitops.h +31 −30
  12. arch/sh/include/asm/bitops-op32.h +22 −12
  13. arch/sparc/include/asm/bitops_32.h +9 −9
  14. arch/sparc/lib/atomic32.c +6 −6
  15. arch/x86/include/asm/bitops.h +12 −10
  16. arch/x86/platform/olpc/olpc-xo1-sci.c +1 −1
  17. drivers/iommu/intel/dmar.c +1 −1
  18. drivers/net/ethernet/intel/ice/ice_switch.c +1 −1
  19. drivers/net/ethernet/mellanox/mlx4/fw.c +1 −1
  20. include/asm-generic/bitops/generic-non-atomic.h +161 −0
  21. include/asm-generic/bitops/instrumented-non-atomic.h +21 −14
  22. include/asm-generic/bitops/non-atomic.h +9 −112
  23. include/asm-generic/bitops/non-instrumented-non-atomic.h +16 −0
  24. include/linux/bitmap.h +27 −10
  25. include/linux/bitops.h +50 −0
  26. include/linux/cpumask.h +100 −22
  27. include/linux/gfp.h +2 −346
  28. include/linux/gfp_types.h +348 −0
  29. include/linux/nodemask.h +19 −5
  30. lib/Makefile +1 −1
  31. lib/bitmap.c +5 −6
  32. lib/cpumask.c +7 −90
  33. lib/nodemask.c +0 −8
  34. lib/test_bitmap.c +68 −0
  35. tools/include/asm-generic/bitops/non-atomic.h +20 −14
  36. tools/include/linux/bitmap.h +6 −6
  37. tools/include/linux/bitops.h +16 −0
  38. tools/lib/bitmap.c +3 −3
Documentation/core-api/mm-api.rst+4−4
@@ -22,16 +22,16 @@ Memory Allocation Controls · 21 unmodified lines
2222 .. kernel-doc:: include/linux/gfp.h
2323 :internal:
2424
25−.. kernel-doc:: include/linux/gfp.h
25+.. kernel-doc:: include/linux/gfp_types.h
2626 :doc: Page mobility and placement hints
2727
28−.. kernel-doc:: include/linux/gfp.h
28+.. kernel-doc:: include/linux/gfp_types.h
2929 :doc: Watermark modifiers
3030
31−.. kernel-doc:: include/linux/gfp.h
31+.. kernel-doc:: include/linux/gfp_types.h
3232 :doc: Reclaim modifiers
3333
34−.. kernel-doc:: include/linux/gfp.h
34+.. kernel-doc:: include/linux/gfp_types.h
3535 :doc: Useful GFP flag combinations
3636
3737 The Slab Cache
MAINTAINERS+1−1
@@ -3603,7 +3603,6 @@ F: lib/bitmap.c · 3602 unmodified lines
36033603 F: lib/cpumask.c
36043604 F: lib/find_bit.c
36053605 F: lib/find_bit_benchmark.c
3606−F: lib/nodemask.c
36073606 F: lib/test_bitmap.c
36083607 F: tools/include/linux/bitmap.h
36093608 F: tools/include/linux/find.h
@@ -13136,6 +13135,7 @@ W: http://www.linux-mm.org · 9526 unmodified lines
1313613135 T: git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
1313713136 T: quilt git://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new
1313813137 F: include/linux/gfp.h
13138+F: include/linux/gfp_types.h
1313913139 F: include/linux/memory_hotplug.h
1314013140 F: include/linux/mm.h
1314113141 F: include/linux/mmzone.h
arch/alpha/include/asm/bitops.h+17−15
@@ -46,8 +46,8 @@ set_bit(unsigned long nr, volatile void * addr) · 45 unmodified lines
4646 /*
4747 * WARNING: non atomic version.
4848 */
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)
5151 {
5252 int *m = ((int *) addr) + (nr >> 5);
5353
@@ -82,8 +82,8 @@ clear_bit_unlock(unsigned long nr, volatile void * addr) · 28 unmodified lines
8282 /*
8383 * WARNING: non atomic version.
8484 */
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)
8787 {
8888 int *m = ((int *) addr) + (nr >> 5);
8989
@@ -94,7 +94,7 @@ static inline void · 4 unmodified lines
9494 __clear_bit_unlock(unsigned long nr, volatile void * addr)
9595 {
9696 smp_mb();
97− __clear_bit(nr, addr);
97+ arch___clear_bit(nr, addr);
9898 }
9999
100100 static inline void
@@ -118,8 +118,8 @@ change_bit(unsigned long nr, volatile void * addr) · 17 unmodified lines
118118 /*
119119 * WARNING: non atomic version.
120120 */
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)
123123 {
124124 int *m = ((int *) addr) + (nr >> 5);
125125
@@ -186,8 +186,8 @@ test_and_set_bit_lock(unsigned long nr, volatile void *addr) · 60 unmodified lines
186186 /*
187187 * WARNING: non atomic version.
188188 */
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)
191191 {
192192 unsigned long mask = 1 << (nr & 0x1f);
193193 int *m = ((int *) addr) + (nr >> 5);
@@ -230,8 +230,8 @@ test_and_clear_bit(unsigned long nr, volatile void * addr) · 36 unmodified lines
230230 /*
231231 * WARNING: non atomic version.
232232 */
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)
235235 {
236236 unsigned long mask = 1 << (nr & 0x1f);
237237 int *m = ((int *) addr) + (nr >> 5);
@@ -272,8 +272,8 @@ test_and_change_bit(unsigned long nr, volatile void * addr) · 34 unmodified lines
272272 /*
273273 * WARNING: non atomic version.
274274 */
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)
277277 {
278278 unsigned long mask = 1 << (nr & 0x1f);
279279 int *m = ((int *) addr) + (nr >> 5);
@@ -283,8 +283,8 @@ __test_and_change_bit(unsigned long nr, volatile void * addr) · 3 unmodified lines
283283 return (old & mask) != 0;
284284 }
285285
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)
288288 {
289289 return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) != 0UL;
290290 }
@@ -450,6 +450,8 @@ sched_find_first_bit(const unsigned long b[2]) · 159 unmodified lines
450450 return __ffs(tmp) + ofs;
451451 }
452452
453+#include <asm-generic/bitops/non-instrumented-non-atomic.h>
454+
453455 #include <asm-generic/bitops/le.h>
454456
455457 #include <asm-generic/bitops/ext2-atomic-setbit.h>
arch/arm/include/asm/bitops.h+10−8
@@ -160,18 +160,20 @@ extern int _test_and_change_bit(int nr, volatile unsigned long * p); · 159 unmodified lines
160160 /*
161161 * Little endian assembly bitops. nr = 0 -> byte 0 bit 0.
162162 */
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);
167168
168169 /*
169170 * Big endian assembly bitops. nr = 0 -> byte 3 bit 0.
170171 */
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);
175177
176178 #ifndef CONFIG_SMP
177179 /*
arch/hexagon/include/asm/bitops.h+15−9
@@ -127,38 +127,45 @@ static inline void change_bit(int nr, volatile void *addr) · 126 unmodified lines
127127 * be atomic, particularly for things like slab_lock and slab_unlock.
128128 *
129129 */
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)
131132 {
132133 test_and_clear_bit(nr, addr);
133134 }
134135
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)
136138 {
137139 test_and_set_bit(nr, addr);
138140 }
139141
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)
141144 {
142145 test_and_change_bit(nr, addr);
143146 }
144147
145148 /* 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)
147151 {
148152 return test_and_clear_bit(nr, addr);
149153 }
150154
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)
152157 {
153158 return test_and_set_bit(nr, addr);
154159 }
155160
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)
157163 {
158164 return test_and_change_bit(nr, addr);
159165 }
160166
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)
162169 {
163170 int retval;
164171
@@ -172,8 +179,6 @@ static inline int __test_bit(int nr, const volatile unsigned long *addr) · 7 unmodified lines
172179 return retval;
173180 }
174181
175−#define test_bit(nr, addr) __test_bit(nr, addr)
176−
177182 /*
178183 * ffz - find first zero in word.
179184 * @word: The word to search
@@ -271,6 +276,7 @@ static inline unsigned long __fls(unsigned long word) · 91 unmodified lines
271276 }
272277
273278 #include <asm-generic/bitops/lock.h>
279+#include <asm-generic/bitops/non-instrumented-non-atomic.h>
274280
275281 #include <asm-generic/bitops/fls64.h>
276282 #include <asm-generic/bitops/sched.h>
arch/ia64/include/asm/bitops.h+22−20
@@ -53,7 +53,7 @@ set_bit (int nr, volatile void *addr) · 52 unmodified lines
5353 }
5454
5555 /**
56− * __set_bit - Set a bit in memory
56+ * arch___set_bit - Set a bit in memory
5757 * @nr: the bit to set
5858 * @addr: the address to start counting from
5959 *
@@ -61,8 +61,8 @@ set_bit (int nr, volatile void *addr) · 1 unmodified line
6161 * If it's called on the same region of memory simultaneously, the effect
6262 * may be that only one operation succeeds.
6363 */
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)
6666 {
6767 *((__u32 *) addr + (nr >> 5)) |= (1 << (nr & 31));
6868 }
@@ -135,7 +135,7 @@ __clear_bit_unlock(int nr, void *addr) · 66 unmodified lines
135135 }
136136
137137 /**
138− * __clear_bit - Clears a bit in memory (non-atomic version)
138+ * arch___clear_bit - Clears a bit in memory (non-atomic version)
139139 * @nr: the bit to clear
140140 * @addr: the address to start counting from
141141 *
@@ -143,8 +143,8 @@ __clear_bit_unlock(int nr, void *addr) · 1 unmodified line
143143 * If it's called on the same region of memory simultaneously, the effect
144144 * may be that only one operation succeeds.
145145 */
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)
148148 {
149149 *((__u32 *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
150150 }
@@ -175,7 +175,7 @@ change_bit (int nr, volatile void *addr) · 24 unmodified lines
175175 }
176176
177177 /**
178− * __change_bit - Toggle a bit in memory
178+ * arch___change_bit - Toggle a bit in memory
179179 * @nr: the bit to toggle
180180 * @addr: the address to start counting from
181181 *
@@ -183,8 +183,8 @@ change_bit (int nr, volatile void *addr) · 1 unmodified line
183183 * If it's called on the same region of memory simultaneously, the effect
184184 * may be that only one operation succeeds.
185185 */
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)
188188 {
189189 *((__u32 *) addr + (nr >> 5)) ^= (1 << (nr & 31));
190190 }
@@ -224,7 +224,7 @@ test_and_set_bit (int nr, volatile void *addr) · 33 unmodified lines
224224 #define test_and_set_bit_lock test_and_set_bit
225225
226226 /**
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
228228 * @nr: Bit to set
229229 * @addr: Address to count from
230230 *
@@ -232,8 +232,8 @@ test_and_set_bit (int nr, volatile void *addr) · 1 unmodified line
232232 * If two examples of this operation race, one can appear to succeed
233233 * but actually fail. You must protect multiple accesses with a lock.
234234 */
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)
237237 {
238238 __u32 *p = (__u32 *) addr + (nr >> 5);
239239 __u32 m = 1 << (nr & 31);
@@ -269,7 +269,7 @@ test_and_clear_bit (int nr, volatile void *addr) · 29 unmodified lines
269269 }
270270
271271 /**
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
273273 * @nr: Bit to clear
274274 * @addr: Address to count from
275275 *
@@ -277,8 +277,8 @@ test_and_clear_bit (int nr, volatile void *addr) · 1 unmodified line
277277 * If two examples of this operation race, one can appear to succeed
278278 * but actually fail. You must protect multiple accesses with a lock.
279279 */
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)
282282 {
283283 __u32 *p = (__u32 *) addr + (nr >> 5);
284284 __u32 m = 1 << (nr & 31);
@@ -314,14 +314,14 @@ test_and_change_bit (int nr, volatile void *addr) · 29 unmodified lines
314314 }
315315
316316 /**
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
318318 * @nr: Bit to change
319319 * @addr: Address to count from
320320 *
321321 * This operation is non-atomic and can be reordered.
322322 */
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)
325325 {
326326 __u32 old, bit = (1 << (nr & 31));
327327 __u32 *m = (__u32 *) addr + (nr >> 5);
@@ -331,8 +331,8 @@ __test_and_change_bit (int nr, void *addr) · 3 unmodified lines
331331 return (old & bit) != 0;
332332 }
333333
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)
336336 {
337337 return 1 & (((const volatile __u32 *) addr)[nr >> 5] >> (nr & 31));
338338 }
@@ -443,6 +443,8 @@ static __inline__ unsigned long __arch_hweight64(unsigned long x) · 104 unmodified lines
443443
444444 #ifdef __KERNEL__
445445
446+#include <asm-generic/bitops/non-instrumented-non-atomic.h>
447+
446448 #include <asm-generic/bitops/le.h>
447449
448450 #include <asm-generic/bitops/ext2-atomic-setbit.h>
arch/ia64/include/asm/processor.h+1−1
@@ -538,7 +538,7 @@ ia64_get_irr(unsigned int vector) · 537 unmodified lines
538538 {
539539 unsigned int reg = vector / 64;
540540 unsigned int bit = vector % 64;
541− u64 irr;
541+ unsigned long irr;
542542
543543 switch (reg) {
544544 case 0: irr = ia64_getreg(_IA64_REG_CR_IRR0); break;
arch/m68k/include/asm/bitops.h+34−15
@@ -65,8 +65,11 @@ static inline void bfset_mem_set_bit(int nr, volatile unsigned long *vaddr) · 64 unmodified lines
6565 bfset_mem_set_bit(nr, vaddr))
6666 #endif
6767
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+}
7073
7174 static inline void bclr_reg_clear_bit(int nr, volatile unsigned long *vaddr)
7275 {
@@ -105,8 +108,11 @@ static inline void bfclr_mem_clear_bit(int nr, volatile unsigned long *vaddr) · 32 unmodified lines
105108 bfclr_mem_clear_bit(nr, vaddr))
106109 #endif
107110
108−#define __clear_bit(nr, vaddr) clear_bit(nr, vaddr)
109−
111+static __always_inline void
112+arch___clear_bit(unsigned long nr, volatile unsigned long *addr)
113+{
114+ clear_bit(nr, addr);
115+}
110116
111117 static inline void bchg_reg_change_bit(int nr, volatile unsigned long *vaddr)
112118 {
@@ -145,14 +151,17 @@ static inline void bfchg_mem_change_bit(int nr, volatile unsigned long *vaddr) · 32 unmodified lines
145151 bfchg_mem_change_bit(nr, vaddr))
146152 #endif
147153
148−#define __change_bit(nr, vaddr) change_bit(nr, vaddr)
149−
150−
151−static inline int test_bit(int nr, const volatile unsigned long *vaddr)
154+static __always_inline void
155+arch___change_bit(unsigned long nr, volatile unsigned long *addr)
152156 {
153− return (vaddr[nr >> 5] & (1UL << (nr & 31))) != 0;
157+ change_bit(nr, addr);
154158 }
155159
160+static __always_inline bool
161+arch_test_bit(unsigned long nr, const volatile unsigned long *addr)
162+{
163+ return (addr[nr >> 5] & (1UL << (nr & 31))) != 0;
164+}
156165
157166 static inline int bset_reg_test_and_set_bit(int nr,
158167 volatile unsigned long *vaddr)
@@ -201,8 +210,11 @@ static inline int bfset_mem_test_and_set_bit(int nr, · 42 unmodified lines
201210 bfset_mem_test_and_set_bit(nr, vaddr))
202211 #endif
203212
204−#define __test_and_set_bit(nr, vaddr) test_and_set_bit(nr, vaddr)
205−
213+static __always_inline bool
214+arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr)
215+{
216+ return test_and_set_bit(nr, addr);
217+}
206218
207219 static inline int bclr_reg_test_and_clear_bit(int nr,
208220 volatile unsigned long *vaddr)
@@ -251,8 +263,11 @@ static inline int bfclr_mem_test_and_clear_bit(int nr, · 42 unmodified lines
251263 bfclr_mem_test_and_clear_bit(nr, vaddr))
252264 #endif
253265
254−#define __test_and_clear_bit(nr, vaddr) test_and_clear_bit(nr, vaddr)
255−
266+static __always_inline bool
267+arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
268+{
269+ return test_and_clear_bit(nr, addr);
270+}
256271
257272 static inline int bchg_reg_test_and_change_bit(int nr,
258273 volatile unsigned long *vaddr)
@@ -301,8 +316,11 @@ static inline int bfchg_mem_test_and_change_bit(int nr, · 42 unmodified lines
301316 bfchg_mem_test_and_change_bit(nr, vaddr))
302317 #endif
303318
304−#define __test_and_change_bit(nr, vaddr) test_and_change_bit(nr, vaddr)
305−
319+static __always_inline bool
320+arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
321+{
322+ return test_and_change_bit(nr, addr);
323+}
306324
307325 /*
308326 * The true 68020 and more advanced processors support the "bfffo"
@@ -522,6 +540,7 @@ static inline unsigned long __fls(unsigned long x) · 213 unmodified lines
522540 #define clear_bit_unlock clear_bit
523541 #define __clear_bit_unlock clear_bit_unlock
524542
543+#include <asm-generic/bitops/non-instrumented-non-atomic.h>
525544 #include <asm-generic/bitops/ext2-atomic.h>
526545 #include <asm-generic/bitops/fls64.h>
527546 #include <asm-generic/bitops/sched.h>
arch/powerpc/include/asm/archrandom.h+1−8
@@ -2,19 +2,12 @@ · 1 unmodified line
22 #ifndef _ASM_POWERPC_ARCHRANDOM_H
33 #define _ASM_POWERPC_ARCHRANDOM_H
44
5−#include <asm/machdep.h>
6−
75 static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs)
86 {
97 return 0;
108 }
119
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);
1811
1912 #ifdef CONFIG_PPC_POWERNV
2013 int pnv_get_random_long(unsigned long *v);
arch/powerpc/kernel/setup-common.c+8−0
@@ -171,6 +171,14 @@ EXPORT_SYMBOL_GPL(machine_power_off); · 170 unmodified lines
171171 void (*pm_power_off)(void);
172172 EXPORT_SYMBOL_GPL(pm_power_off);
173173
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+
174182 void machine_halt(void)
175183 {
176184 machine_shutdown();
arch/s390/include/asm/bitops.h+31−30
@@ -113,75 +113,76 @@ static inline bool arch_test_and_change_bit(unsigned long nr, · 112 unmodified lines
113113 return old & mask;
114114 }
115115
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)
117118 {
118− unsigned long *addr = __bitops_word(nr, ptr);
119+ unsigned long *p = __bitops_word(nr, addr);
119120 unsigned long mask = __bitops_mask(nr);
120121
121− *addr |= mask;
122+ *p |= mask;
122123 }
123124
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)
126127 {
127− unsigned long *addr = __bitops_word(nr, ptr);
128+ unsigned long *p = __bitops_word(nr, addr);
128129 unsigned long mask = __bitops_mask(nr);
129130
130− *addr &= ~mask;
131+ *p &= ~mask;
131132 }
132133
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)
135136 {
136− unsigned long *addr = __bitops_word(nr, ptr);
137+ unsigned long *p = __bitops_word(nr, addr);
137138 unsigned long mask = __bitops_mask(nr);
138139
139− *addr ^= mask;
140+ *p ^= mask;
140141 }
141142
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)
144145 {
145− unsigned long *addr = __bitops_word(nr, ptr);
146+ unsigned long *p = __bitops_word(nr, addr);
146147 unsigned long mask = __bitops_mask(nr);
147148 unsigned long old;
148149
149− old = *addr;
150− *addr |= mask;
150+ old = *p;
151+ *p |= mask;
151152 return old & mask;
152153 }
153154
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)
156157 {
157− unsigned long *addr = __bitops_word(nr, ptr);
158+ unsigned long *p = __bitops_word(nr, addr);
158159 unsigned long mask = __bitops_mask(nr);
159160 unsigned long old;
160161
161− old = *addr;
162− *addr &= ~mask;
162+ old = *p;
163+ *p &= ~mask;
163164 return old & mask;
164165 }
165166
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)
168169 {
169− unsigned long *addr = __bitops_word(nr, ptr);
170+ unsigned long *p = __bitops_word(nr, addr);
170171 unsigned long mask = __bitops_mask(nr);
171172 unsigned long old;
172173
173− old = *addr;
174− *addr ^= mask;
174+ old = *p;
175+ *p ^= mask;
175176 return old & mask;
176177 }
177178
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)
180181 {
181− const volatile unsigned long *addr = __bitops_word(nr, ptr);
182+ const volatile unsigned long *p = __bitops_word(nr, addr);
182183 unsigned long mask = __bitops_mask(nr);
183184
184− return *addr & mask;
185+ return *p & mask;
185186 }
186187
187188 static inline bool arch_test_and_set_bit_lock(unsigned long nr,
arch/sh/include/asm/bitops-op32.h+22−12
@@ -2,6 +2,8 @@ · 1 unmodified line
22 #ifndef __ASM_SH_BITOPS_OP32_H
33 #define __ASM_SH_BITOPS_OP32_H
44
5+#include <linux/bits.h>
6+
57 /*
68 * The bit modifying instructions on SH-2A are only capable of working
79 * with a 3-bit immediate, which signifies the shift position for the bit
@@ -16,7 +18,8 @@ · 8 unmodified lines
1618 #define BYTE_OFFSET(nr) ((nr) % BITS_PER_BYTE)
1719 #endif
1820
19−static inline void __set_bit(int nr, volatile unsigned long *addr)
21+static __always_inline void
22+arch___set_bit(unsigned long nr, volatile unsigned long *addr)
2023 {
2124 if (__builtin_constant_p(nr)) {
2225 __asm__ __volatile__ (
@@ -33,7 +36,8 @@ static inline void __set_bit(int nr, volatile unsigned long *addr) · 10 unmodified lines
3336 }
3437 }
3538
36−static inline void __clear_bit(int nr, volatile unsigned long *addr)
39+static __always_inline void
40+arch___clear_bit(unsigned long nr, volatile unsigned long *addr)
3741 {
3842 if (__builtin_constant_p(nr)) {
3943 __asm__ __volatile__ (
@@ -52,7 +56,7 @@ static inline void __clear_bit(int nr, volatile unsigned long *addr) · 12 unmodified lines
5256 }
5357
5458 /**
55− * __change_bit - Toggle a bit in memory
59+ * arch___change_bit - Toggle a bit in memory
5660 * @nr: the bit to change
5761 * @addr: the address to start counting from
5862 *
@@ -60,7 +64,8 @@ static inline void __clear_bit(int nr, volatile unsigned long *addr) · 1 unmodified line
6064 * If it's called on the same region of memory simultaneously, the effect
6165 * may be that only one operation succeeds.
6266 */
63−static inline void __change_bit(int nr, volatile unsigned long *addr)
67+static __always_inline void
68+arch___change_bit(unsigned long nr, volatile unsigned long *addr)
6469 {
6570 if (__builtin_constant_p(nr)) {
6671 __asm__ __volatile__ (
@@ -79,7 +84,7 @@ static inline void __change_bit(int nr, volatile unsigned long *addr) · 12 unmodified lines
7984 }
8085
8186 /**
82− * __test_and_set_bit - Set a bit and return its old value
87+ * arch___test_and_set_bit - Set a bit and return its old value
8388 * @nr: Bit to set
8489 * @addr: Address to count from
8590 *
@@ -87,7 +92,8 @@ static inline void __change_bit(int nr, volatile unsigned long *addr) · 1 unmodified line
8792 * If two examples of this operation race, one can appear to succeed
8893 * but actually fail. You must protect multiple accesses with a lock.
8994 */
90−static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
95+static __always_inline bool
96+arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr)
9197 {
9298 unsigned long mask = BIT_MASK(nr);
9399 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -98,7 +104,7 @@ static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) · 4 unmodified lines
98104 }
99105
100106 /**
101− * __test_and_clear_bit - Clear a bit and return its old value
107+ * arch___test_and_clear_bit - Clear a bit and return its old value
102108 * @nr: Bit to clear
103109 * @addr: Address to count from
104110 *
@@ -106,7 +112,8 @@ static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) · 1 unmodified line
106112 * If two examples of this operation race, one can appear to succeed
107113 * but actually fail. You must protect multiple accesses with a lock.
108114 */
109−static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
115+static __always_inline bool
116+arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
110117 {
111118 unsigned long mask = BIT_MASK(nr);
112119 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -117,8 +124,8 @@ static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) · 4 unmodified lines
117124 }
118125
119126 /* WARNING: non atomic and it can be reordered! */
120−static inline int __test_and_change_bit(int nr,
121− volatile unsigned long *addr)
127+static __always_inline bool
128+arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
122129 {
123130 unsigned long mask = BIT_MASK(nr);
124131 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -129,13 +136,16 @@ static inline int __test_and_change_bit(int nr, · 4 unmodified lines
129136 }
130137
131138 /**
132− * test_bit - Determine whether a bit is set
139+ * arch_test_bit - Determine whether a bit is set
133140 * @nr: bit number to test
134141 * @addr: Address to start counting from
135142 */
136−static inline int test_bit(int nr, const volatile unsigned long *addr)
143+static __always_inline bool
144+arch_test_bit(unsigned long nr, const volatile unsigned long *addr)
137145 {
138146 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
139147 }
140148
149+#include <asm-generic/bitops/non-instrumented-non-atomic.h>
150+
141151 #endif /* __ASM_SH_BITOPS_OP32_H */
arch/sparc/include/asm/bitops_32.h+9−9
@@ -19,9 +19,9 @@ · 18 unmodified lines
1919 #error only <linux/bitops.h> can be included directly
2020 #endif
2121
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);
2525
2626 /*
2727 * Set bit 'nr' in 32-bit quantity at address 'addr' where bit '0'
@@ -36,7 +36,7 @@ static inline int test_and_set_bit(unsigned long nr, volatile unsigned long *add · 8 unmodified lines
3636 ADDR = ((unsigned long *) addr) + (nr >> 5);
3737 mask = 1 << (nr & 31);
3838
39− return ___set_bit(ADDR, mask) != 0;
39+ return sp32___set_bit(ADDR, mask) != 0;
4040 }
4141
4242 static inline void set_bit(unsigned long nr, volatile unsigned long *addr)
@@ -46,7 +46,7 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) · 3 unmodified lines
4646 ADDR = ((unsigned long *) addr) + (nr >> 5);
4747 mask = 1 << (nr & 31);
4848
49− (void) ___set_bit(ADDR, mask);
49+ (void) sp32___set_bit(ADDR, mask);
5050 }
5151
5252 static inline int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
@@ -56,7 +56,7 @@ static inline int test_and_clear_bit(unsigned long nr, volatile unsigned long *a · 3 unmodified lines
5656 ADDR = ((unsigned long *) addr) + (nr >> 5);
5757 mask = 1 << (nr & 31);
5858
59− return ___clear_bit(ADDR, mask) != 0;
59+ return sp32___clear_bit(ADDR, mask) != 0;
6060 }
6161
6262 static inline void clear_bit(unsigned long nr, volatile unsigned long *addr)
@@ -66,7 +66,7 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) · 3 unmodified lines
6666 ADDR = ((unsigned long *) addr) + (nr >> 5);
6767 mask = 1 << (nr & 31);
6868
69− (void) ___clear_bit(ADDR, mask);
69+ (void) sp32___clear_bit(ADDR, mask);
7070 }
7171
7272 static inline int test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
@@ -76,7 +76,7 @@ static inline int test_and_change_bit(unsigned long nr, volatile unsigned long * · 3 unmodified lines
7676 ADDR = ((unsigned long *) addr) + (nr >> 5);
7777 mask = 1 << (nr & 31);
7878
79− return ___change_bit(ADDR, mask) != 0;
79+ return sp32___change_bit(ADDR, mask) != 0;
8080 }
8181
8282 static inline void change_bit(unsigned long nr, volatile unsigned long *addr)
@@ -86,7 +86,7 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) · 3 unmodified lines
8686 ADDR = ((unsigned long *) addr) + (nr >> 5);
8787 mask = 1 << (nr & 31);
8888
89− (void) ___change_bit(ADDR, mask);
89+ (void) sp32___change_bit(ADDR, mask);
9090 }
9191
9292 #include <asm-generic/bitops/non-atomic.h>
arch/sparc/lib/atomic32.c+6−6
@@ -120,7 +120,7 @@ void arch_atomic_set(atomic_t *v, int i) · 119 unmodified lines
120120 }
121121 EXPORT_SYMBOL(arch_atomic_set);
122122
123−unsigned long ___set_bit(unsigned long *addr, unsigned long mask)
123+unsigned long sp32___set_bit(unsigned long *addr, unsigned long mask)
124124 {
125125 unsigned long old, flags;
126126
@@ -131,9 +131,9 @@ unsigned long ___set_bit(unsigned long *addr, unsigned long mask) · 4 unmodified lines
131131
132132 return old & mask;
133133 }
134−EXPORT_SYMBOL(___set_bit);
134+EXPORT_SYMBOL(sp32___set_bit);
135135
136−unsigned long ___clear_bit(unsigned long *addr, unsigned long mask)
136+unsigned long sp32___clear_bit(unsigned long *addr, unsigned long mask)
137137 {
138138 unsigned long old, flags;
139139
@@ -144,9 +144,9 @@ unsigned long ___clear_bit(unsigned long *addr, unsigned long mask) · 4 unmodified lines
144144
145145 return old & mask;
146146 }
147−EXPORT_SYMBOL(___clear_bit);
147+EXPORT_SYMBOL(sp32___clear_bit);
148148
149−unsigned long ___change_bit(unsigned long *addr, unsigned long mask)
149+unsigned long sp32___change_bit(unsigned long *addr, unsigned long mask)
150150 {
151151 unsigned long old, flags;
152152
@@ -157,7 +157,7 @@ unsigned long ___change_bit(unsigned long *addr, unsigned long mask) · 4 unmodified lines
157157
158158 return old & mask;
159159 }
160−EXPORT_SYMBOL(___change_bit);
160+EXPORT_SYMBOL(sp32___change_bit);
161161
162162 unsigned long __cmpxchg_u32(volatile u32 *ptr, u32 old, u32 new)
163163 {
arch/x86/include/asm/bitops.h+12−10
@@ -63,7 +63,7 @@ arch_set_bit(long nr, volatile unsigned long *addr) · 62 unmodified lines
6363 }
6464
6565 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)
6767 {
6868 asm volatile(__ASM_SIZE(bts) " %1,%0" : : ADDR, "Ir" (nr) : "memory");
6969 }
@@ -89,7 +89,7 @@ arch_clear_bit_unlock(long nr, volatile unsigned long *addr) · 19 unmodified lines
8989 }
9090
9191 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)
9393 {
9494 asm volatile(__ASM_SIZE(btr) " %1,%0" : : ADDR, "Ir" (nr) : "memory");
9595 }
@@ -114,7 +114,7 @@ arch___clear_bit_unlock(long nr, volatile unsigned long *addr) · 18 unmodified lines
114114 }
115115
116116 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)
118118 {
119119 asm volatile(__ASM_SIZE(btc) " %1,%0" : : ADDR, "Ir" (nr) : "memory");
120120 }
@@ -145,7 +145,7 @@ arch_test_and_set_bit_lock(long nr, volatile unsigned long *addr) · 24 unmodified lines
145145 }
146146
147147 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)
149149 {
150150 bool oldbit;
151151
@@ -171,7 +171,7 @@ arch_test_and_clear_bit(long nr, volatile unsigned long *addr) · 19 unmodified lines
171171 * this without also updating arch/x86/kernel/kvm.c
172172 */
173173 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)
175175 {
176176 bool oldbit;
177177
@@ -183,7 +183,7 @@ arch___test_and_clear_bit(long nr, volatile unsigned long *addr) · 5 unmodified lines
183183 }
184184
185185 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)
187187 {
188188 bool oldbit;
189189
@@ -219,10 +219,12 @@ static __always_inline bool variable_test_bit(long nr, volatile const unsigned l · 29 unmodified lines
219219 return oldbit;
220220 }
221221
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+}
226228
227229 /**
228230 * __ffs - find first set bit in word
arch/x86/platform/olpc/olpc-xo1-sci.c+1−1
@@ -80,7 +80,7 @@ static void send_ebook_state(void) · 79 unmodified lines
8080 return;
8181 }
8282
83− if (!!test_bit(SW_TABLET_MODE, ebook_switch_idev->sw) == state)
83+ if (test_bit(SW_TABLET_MODE, ebook_switch_idev->sw) == !!state)
8484 return; /* Nothing new to report. */
8585
8686 input_report_switch(ebook_switch_idev, SW_TABLET_MODE, state);
drivers/iommu/intel/dmar.c+1−1
@@ -494,7 +494,7 @@ static int dmar_parse_one_rhsa(struct acpi_dmar_header *header, void *arg) · 493 unmodified lines
494494 if (drhd->reg_base_addr == rhsa->base_address) {
495495 int node = pxm_to_node(rhsa->proximity_domain);
496496
497− if (!node_online(node))
497+ if (node != NUMA_NO_NODE && !node_online(node))
498498 node = NUMA_NO_NODE;
499499 drhd->iommu->node = node;
500500 return 0;
drivers/net/ethernet/intel/ice/ice_switch.c+1−1
@@ -4971,7 +4971,7 @@ ice_find_free_recp_res_idx(struct ice_hw *hw, const unsigned long *profiles, · 4970 unmodified lines
49714971 bitmap_zero(recipes, ICE_MAX_NUM_RECIPES);
49724972 bitmap_zero(used_idx, ICE_MAX_FV_WORDS);
49734973
4974− bitmap_set(possible_idx, 0, ICE_MAX_FV_WORDS);
4974+ bitmap_fill(possible_idx, ICE_MAX_FV_WORDS);
49754975
49764976 /* For each profile we are going to associate the recipe with, add the
49774977 * recipes that are associated with that profile. This will give us
drivers/net/ethernet/mellanox/mlx4/fw.c+1−1
@@ -463,7 +463,7 @@ int mlx4_QUERY_FUNC_CAP_wrapper(struct mlx4_dev *dev, int slave, · 462 unmodified lines
463463
464464 field = min(
465465 bitmap_weight(actv_ports.ports, dev->caps.num_ports),
466− dev->caps.num_ports);
466+ (unsigned int) dev->caps.num_ports);
467467 MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_NUM_PORTS_OFFSET);
468468
469469 size = dev->caps.function_caps; /* set PF behaviours */
include/asm-generic/bitops/generic-non-atomic.h+161−0
@@ -0,0 +1,161 @@
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 */
include/asm-generic/bitops/instrumented-non-atomic.h+21−14
@@ -14,7 +14,7 @@ · 13 unmodified lines
1414 #include <linux/instrumented.h>
1515
1616 /**
17− * __set_bit - Set a bit in memory
17+ * ___set_bit - Set a bit in memory
1818 * @nr: the bit to set
1919 * @addr: the address to start counting from
2020 *
@@ -22,14 +22,15 @@ · 1 unmodified line
2222 * region of memory concurrently, the effect may be that only one operation
2323 * succeeds.
2424 */
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)
2627 {
2728 instrument_write(addr + BIT_WORD(nr), sizeof(long));
2829 arch___set_bit(nr, addr);
2930 }
3031
3132 /**
32− * __clear_bit - Clears a bit in memory
33+ * ___clear_bit - Clears a bit in memory
3334 * @nr: the bit to clear
3435 * @addr: the address to start counting from
3536 *
@@ -37,14 +38,15 @@ static __always_inline void __set_bit(long nr, volatile unsigned long *addr) · 1 unmodified line
3738 * region of memory concurrently, the effect may be that only one operation
3839 * succeeds.
3940 */
40−static __always_inline void __clear_bit(long nr, volatile unsigned long *addr)
41+static __always_inline void
42+___clear_bit(unsigned long nr, volatile unsigned long *addr)
4143 {
4244 instrument_write(addr + BIT_WORD(nr), sizeof(long));
4345 arch___clear_bit(nr, addr);
4446 }
4547
4648 /**
47− * __change_bit - Toggle a bit in memory
49+ * ___change_bit - Toggle a bit in memory
4850 * @nr: the bit to change
4951 * @addr: the address to start counting from
5052 *
@@ -52,7 +54,8 @@ static __always_inline void __clear_bit(long nr, volatile unsigned long *addr) · 1 unmodified line
5254 * region of memory concurrently, the effect may be that only one operation
5355 * succeeds.
5456 */
55−static __always_inline void __change_bit(long nr, volatile unsigned long *addr)
57+static __always_inline void
58+___change_bit(unsigned long nr, volatile unsigned long *addr)
5659 {
5760 instrument_write(addr + BIT_WORD(nr), sizeof(long));
5861 arch___change_bit(nr, addr);
@@ -83,53 +86,57 @@ static __always_inline void __instrument_read_write_bitop(long nr, volatile unsi · 24 unmodified lines
8386 }
8487
8588 /**
86− * __test_and_set_bit - Set a bit and return its old value
89+ * ___test_and_set_bit - Set a bit and return its old value
8790 * @nr: Bit to set
8891 * @addr: Address to count from
8992 *
9093 * This operation is non-atomic. If two instances of this operation race, one
9194 * can appear to succeed but actually fail.
9295 */
93−static __always_inline bool __test_and_set_bit(long nr, volatile unsigned long *addr)
96+static __always_inline bool
97+___test_and_set_bit(unsigned long nr, volatile unsigned long *addr)
9498 {
9599 __instrument_read_write_bitop(nr, addr);
96100 return arch___test_and_set_bit(nr, addr);
97101 }
98102
99103 /**
100− * __test_and_clear_bit - Clear a bit and return its old value
104+ * ___test_and_clear_bit - Clear a bit and return its old value
101105 * @nr: Bit to clear
102106 * @addr: Address to count from
103107 *
104108 * This operation is non-atomic. If two instances of this operation race, one
105109 * can appear to succeed but actually fail.
106110 */
107−static __always_inline bool __test_and_clear_bit(long nr, volatile unsigned long *addr)
111+static __always_inline bool
112+___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
108113 {
109114 __instrument_read_write_bitop(nr, addr);
110115 return arch___test_and_clear_bit(nr, addr);
111116 }
112117
113118 /**
114− * __test_and_change_bit - Change a bit and return its old value
119+ * ___test_and_change_bit - Change a bit and return its old value
115120 * @nr: Bit to change
116121 * @addr: Address to count from
117122 *
118123 * This operation is non-atomic. If two instances of this operation race, one
119124 * can appear to succeed but actually fail.
120125 */
121−static __always_inline bool __test_and_change_bit(long nr, volatile unsigned long *addr)
126+static __always_inline bool
127+___test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
122128 {
123129 __instrument_read_write_bitop(nr, addr);
124130 return arch___test_and_change_bit(nr, addr);
125131 }
126132
127133 /**
128− * test_bit - Determine whether a bit is set
134+ * _test_bit - Determine whether a bit is set
129135 * @nr: bit number to test
130136 * @addr: Address to start counting from
131137 */
132−static __always_inline bool test_bit(long nr, const volatile unsigned long *addr)
138+static __always_inline bool
139+_test_bit(unsigned long nr, const volatile unsigned long *addr)
133140 {
134141 instrument_atomic_read(addr + BIT_WORD(nr), sizeof(long));
135142 return arch_test_bit(nr, addr);
include/asm-generic/bitops/non-atomic.h+9−112
@@ -2,121 +2,18 @@ · 1 unmodified line
22 #ifndef _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
33 #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
44
5−#include <asm/types.h>
5+#include <asm-generic/bitops/generic-non-atomic.h>
66
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
2110
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
2514
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
3116
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>
12118
12219 #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
include/asm-generic/bitops/non-instrumented-non-atomic.h+16−0
@@ -0,0 +1,16 @@
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 */
include/linux/bitmap.h+27−10
@@ -71,9 +71,9 @@ struct device; · 70 unmodified lines
7171 * bitmap_release_region(bitmap, pos, order) Free specified bit region
7272 * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region
7373 * 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
7475 * bitmap_to_arr32(buf, src, nbits) Copy nbits from buf to u32[] dst
7576 * bitmap_to_arr64(buf, src, nbits) Copy nbits from buf to u64[] dst
76− * bitmap_to_arr64(buf, src, nbits) Copy nbits from buf to u64[] dst
7777 * bitmap_get_value8(map, start) Get 8bit value from map at start
7878 * bitmap_set_value8(map, value, start) Set 8bit value to map at start
7979 *
@@ -148,13 +148,13 @@ void __bitmap_shift_left(unsigned long *dst, const unsigned long *src, · 68 unmodified lines
148148 unsigned int shift, unsigned int nbits);
149149 void bitmap_cut(unsigned long *dst, const unsigned long *src,
150150 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,
152152 const unsigned long *bitmap2, unsigned int nbits);
153153 void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
154154 const unsigned long *bitmap2, unsigned int nbits);
155155 void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
156156 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,
158158 const unsigned long *bitmap2, unsigned int nbits);
159159 void __bitmap_replace(unsigned long *dst,
160160 const unsigned long *old, const unsigned long *new,
@@ -163,7 +163,7 @@ bool __bitmap_intersects(const unsigned long *bitmap1, · 2 unmodified lines
163163 const unsigned long *bitmap2, unsigned int nbits);
164164 bool __bitmap_subset(const unsigned long *bitmap1,
165165 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);
167167 void __bitmap_set(unsigned long *map, unsigned int start, int len);
168168 void __bitmap_clear(unsigned long *map, unsigned int start, int len);
169169
@@ -238,20 +238,32 @@ extern int bitmap_print_list_to_buf(char *buf, const unsigned long *maskp, · 68 unmodified lines
238238 static inline void bitmap_zero(unsigned long *dst, unsigned int nbits)
239239 {
240240 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);
242246 }
243247
244248 static inline void bitmap_fill(unsigned long *dst, unsigned int nbits)
245249 {
246250 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);
248256 }
249257
250258 static inline void bitmap_copy(unsigned long *dst, const unsigned long *src,
251259 unsigned int nbits)
252260 {
253261 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);
255267 }
256268
257269 /*
@@ -303,7 +315,7 @@ void bitmap_to_arr64(u64 *buf, const unsigned long *bitmap, unsigned int nbits); · 45 unmodified lines
303315 bitmap_copy_clear_tail((unsigned long *)(buf), (const unsigned long *)(bitmap), (nbits))
304316 #endif
305317
306−static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
318+static inline bool bitmap_and(unsigned long *dst, const unsigned long *src1,
307319 const unsigned long *src2, unsigned int nbits)
308320 {
309321 if (small_const_nbits(nbits))
@@ -329,7 +341,7 @@ static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1, · 19 unmodified lines
329341 __bitmap_xor(dst, src1, src2, nbits);
330342 }
331343
332−static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1,
344+static inline bool bitmap_andnot(unsigned long *dst, const unsigned long *src1,
333345 const unsigned long *src2, unsigned int nbits)
334346 {
335347 if (small_const_nbits(nbits))
@@ -419,7 +431,8 @@ static inline bool bitmap_full(const unsigned long *src, unsigned int nbits) · 83 unmodified lines
419431 return find_first_zero_bit(src, nbits) == nbits;
420432 }
421433
422−static __always_inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
434+static __always_inline
435+unsigned int bitmap_weight(const unsigned long *src, unsigned int nbits)
423436 {
424437 if (small_const_nbits(nbits))
425438 return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
@@ -431,6 +444,8 @@ static __always_inline void bitmap_set(unsigned long *map, unsigned int start, · 5 unmodified lines
431444 {
432445 if (__builtin_constant_p(nbits) && nbits == 1)
433446 __set_bit(start, map);
447+ else if (small_const_nbits(start + nbits))
448+ *map |= GENMASK(start + nbits - 1, start);
434449 else if (__builtin_constant_p(start & BITMAP_MEM_MASK) &&
435450 IS_ALIGNED(start, BITMAP_MEM_ALIGNMENT) &&
436451 __builtin_constant_p(nbits & BITMAP_MEM_MASK) &&
@@ -445,6 +460,8 @@ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start, · 8 unmodified lines
445460 {
446461 if (__builtin_constant_p(nbits) && nbits == 1)
447462 __clear_bit(start, map);
463+ else if (small_const_nbits(start + nbits))
464+ *map &= ~GENMASK(start + nbits - 1, start);
448465 else if (__builtin_constant_p(start & BITMAP_MEM_MASK) &&
449466 IS_ALIGNED(start, BITMAP_MEM_ALIGNMENT) &&
450467 __builtin_constant_p(nbits & BITMAP_MEM_MASK) &&
include/linux/bitops.h+50−0
@@ -26,12 +26,62 @@ extern unsigned int __sw_hweight16(unsigned int w); · 25 unmodified lines
2626 extern unsigned int __sw_hweight32(unsigned int w);
2727 extern unsigned long __sw_hweight64(__u64 w);
2828
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+
2963 /*
3064 * Include this here because some architectures need generic_ffs/fls in
3165 * scope
3266 */
3367 #include <asm/bitops.h>
3468
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
84+
3585 static inline int get_bitmask_order(unsigned int count)
3686 {
3787 int order;
include/linux/cpumask.h+100−22
@@ -12,6 +12,8 @@ · 11 unmodified lines
1212 #include <linux/bitmap.h>
1313 #include <linux/atomic.h>
1414 #include <linux/bug.h>
15+#include <linux/gfp_types.h>
16+#include <linux/numa.h>
1517
1618 /* Don't assign or return these: may not be this big! */
1719 typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
@@ -162,7 +164,21 @@ static inline unsigned int cpumask_last(const struct cpumask *srcp) · 144 unmodified lines
162164 return find_last_bit(cpumask_bits(srcp), nr_cpumask_bits);
163165 }
164166
165−unsigned int __pure cpumask_next(int n, const struct cpumask *srcp);
167+/**
168+ * cpumask_next - get the next cpu in a cpumask
169+ * @n: the cpu prior to the place to search (ie. return will be > @n)
170+ * @srcp: the cpumask pointer
171+ *
172+ * Returns >= nr_cpu_ids if no further cpus set.
173+ */
174+static inline
175+unsigned int cpumask_next(int n, const struct cpumask *srcp)
176+{
177+ /* -1 is a legal arg here. */
178+ if (n != -1)
179+ cpumask_check(n);
180+ return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n + 1);
181+}
166182
167183 /**
168184 * cpumask_next_zero - get the next unset cpu in a cpumask
@@ -179,9 +195,6 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp) · 10 unmodified lines
179195 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
180196 }
181197
182−int __pure cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
183−int __pure cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
184−
185198 #if NR_CPUS == 1
186199 /* Uniprocessor: there is only one valid CPU */
187200 static inline unsigned int cpumask_local_spread(unsigned int i, int node)
@@ -200,11 +213,30 @@ static inline int cpumask_any_distribute(const struct cpumask *srcp) · 12 unmodified lines
200213 }
201214 #else
202215 unsigned int cpumask_local_spread(unsigned int i, int node);
203−int cpumask_any_and_distribute(const struct cpumask *src1p,
216+unsigned int cpumask_any_and_distribute(const struct cpumask *src1p,
204217 const struct cpumask *src2p);
205−int cpumask_any_distribute(const struct cpumask *srcp);
218+unsigned int cpumask_any_distribute(const struct cpumask *srcp);
206219 #endif /* NR_CPUS */
207220
221+/**
222+ * cpumask_next_and - get the next cpu in *src1p & *src2p
223+ * @n: the cpu prior to the place to search (ie. return will be > @n)
224+ * @src1p: the first cpumask pointer
225+ * @src2p: the second cpumask pointer
226+ *
227+ * Returns >= nr_cpu_ids if no further cpus set in both.
228+ */
229+static inline
230+unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
231+ const struct cpumask *src2p)
232+{
233+ /* -1 is a legal arg here. */
234+ if (n != -1)
235+ cpumask_check(n);
236+ return find_next_and_bit(cpumask_bits(src1p), cpumask_bits(src2p),
237+ nr_cpumask_bits, n + 1);
238+}
239+
208240 /**
209241 * for_each_cpu - iterate over every cpu in a mask
210242 * @cpu: the (optionally unsigned) integer iterator
@@ -229,7 +261,7 @@ int cpumask_any_distribute(const struct cpumask *srcp); · 18 unmodified lines
229261 (cpu) = cpumask_next_zero((cpu), (mask)), \
230262 (cpu) < nr_cpu_ids;)
231263
232−int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap);
264+unsigned int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap);
233265
234266 /**
235267 * for_each_cpu_wrap - iterate over every cpu in a mask, starting at a specified location
@@ -265,6 +297,26 @@ int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool · 29 unmodified lines
265297 (cpu) = cpumask_next_and((cpu), (mask1), (mask2)), \
266298 (cpu) < nr_cpu_ids;)
267299
300+/**
301+ * cpumask_any_but - return a "random" in a cpumask, but not this one.
302+ * @mask: the cpumask to search
303+ * @cpu: the cpu to ignore.
304+ *
305+ * Often used to find any cpu but smp_processor_id() in a mask.
306+ * Returns >= nr_cpu_ids if no cpus set.
307+ */
308+static inline
309+unsigned int cpumask_any_but(const struct cpumask *mask, unsigned int cpu)
310+{
311+ unsigned int i;
312+
313+ cpumask_check(cpu);
314+ for_each_cpu(i, mask)
315+ if (i != cpu)
316+ break;
317+ return i;
318+}
319+
268320 #define CPU_BITS_NONE \
269321 { \
270322 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
@@ -311,9 +363,9 @@ static __always_inline void __cpumask_clear_cpu(int cpu, struct cpumask *dstp) · 40 unmodified lines
311363 * @cpu: cpu number (< nr_cpu_ids)
312364 * @cpumask: the cpumask pointer
313365 *
314− * Returns 1 if @cpu is set in @cpumask, else returns 0
366+ * Returns true if @cpu is set in @cpumask, else returns false
315367 */
316−static __always_inline int cpumask_test_cpu(int cpu, const struct cpumask *cpumask)
368+static __always_inline bool cpumask_test_cpu(int cpu, const struct cpumask *cpumask)
317369 {
318370 return test_bit(cpumask_check(cpu), cpumask_bits((cpumask)));
319371 }
@@ -323,11 +375,11 @@ static __always_inline int cpumask_test_cpu(int cpu, const struct cpumask *cpuma · 3 unmodified lines
323375 * @cpu: cpu number (< nr_cpu_ids)
324376 * @cpumask: the cpumask pointer
325377 *
326− * Returns 1 if @cpu is set in old bitmap of @cpumask, else returns 0
378+ * Returns true if @cpu is set in old bitmap of @cpumask, else returns false
327379 *
328380 * test_and_set_bit wrapper for cpumasks.
329381 */
330−static __always_inline int cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask)
382+static __always_inline bool cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask)
331383 {
332384 return test_and_set_bit(cpumask_check(cpu), cpumask_bits(cpumask));
333385 }
@@ -337,11 +389,11 @@ static __always_inline int cpumask_test_and_set_cpu(int cpu, struct cpumask *cpu · 3 unmodified lines
337389 * @cpu: cpu number (< nr_cpu_ids)
338390 * @cpumask: the cpumask pointer
339391 *
340− * Returns 1 if @cpu is set in old bitmap of @cpumask, else returns 0
392+ * Returns true if @cpu is set in old bitmap of @cpumask, else returns false
341393 *
342394 * test_and_clear_bit wrapper for cpumasks.
343395 */
344−static __always_inline int cpumask_test_and_clear_cpu(int cpu, struct cpumask *cpumask)
396+static __always_inline bool cpumask_test_and_clear_cpu(int cpu, struct cpumask *cpumask)
345397 {
346398 return test_and_clear_bit(cpumask_check(cpu), cpumask_bits(cpumask));
347399 }
@@ -370,9 +422,9 @@ static inline void cpumask_clear(struct cpumask *dstp) · 22 unmodified lines
370422 * @src1p: the first input
371423 * @src2p: the second input
372424 *
373− * If *@dstp is empty, returns 0, else returns 1
425+ * If *@dstp is empty, returns false, else returns true
374426 */
375−static inline int cpumask_and(struct cpumask *dstp,
427+static inline bool cpumask_and(struct cpumask *dstp,
376428 const struct cpumask *src1p,
377429 const struct cpumask *src2p)
378430 {
@@ -413,9 +465,9 @@ static inline void cpumask_xor(struct cpumask *dstp, · 34 unmodified lines
413465 * @src1p: the first input
414466 * @src2p: the second input
415467 *
416− * If *@dstp is empty, returns 0, else returns 1
468+ * If *@dstp is empty, returns false, else returns true
417469 */
418−static inline int cpumask_andnot(struct cpumask *dstp,
470+static inline bool cpumask_andnot(struct cpumask *dstp,
419471 const struct cpumask *src1p,
420472 const struct cpumask *src2p)
421473 {
@@ -478,9 +530,9 @@ static inline bool cpumask_intersects(const struct cpumask *src1p, · 56 unmodified lines
478530 * @src1p: the first input
479531 * @src2p: the second input
480532 *
481− * Returns 1 if *@src1p is a subset of *@src2p, else returns 0
533+ * Returns true if *@src1p is a subset of *@src2p, else returns false
482534 */
483−static inline int cpumask_subset(const struct cpumask *src1p,
535+static inline bool cpumask_subset(const struct cpumask *src1p,
484536 const struct cpumask *src2p)
485537 {
486538 return bitmap_subset(cpumask_bits(src1p), cpumask_bits(src2p),
@@ -682,9 +734,35 @@ typedef struct cpumask *cpumask_var_t; · 195 unmodified lines
682734 #define __cpumask_var_read_mostly __read_mostly
683735
684736 bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
685−bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
686−bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
687−bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
737+
738+static inline
739+bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
740+{
741+ return alloc_cpumask_var_node(mask, flags | __GFP_ZERO, node);
742+}
743+
744+/**
745+ * alloc_cpumask_var - allocate a struct cpumask
746+ * @mask: pointer to cpumask_var_t where the cpumask is returned
747+ * @flags: GFP_ flags
748+ *
749+ * Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is
750+ * a nop returning a constant 1 (in <linux/cpumask.h>).
751+ *
752+ * See alloc_cpumask_var_node.
753+ */
754+static inline
755+bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
756+{
757+ return alloc_cpumask_var_node(mask, flags, NUMA_NO_NODE);
758+}
759+
760+static inline
761+bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
762+{
763+ return alloc_cpumask_var(mask, flags | __GFP_ZERO);
764+}
765+
688766 void alloc_bootmem_cpumask_var(cpumask_var_t *mask);
689767 void free_cpumask_var(cpumask_var_t mask);
690768 void free_bootmem_cpumask_var(cpumask_var_t mask);
include/linux/gfp.h+2−346
@@ -2,357 +2,13 @@ · 1 unmodified line
22 #ifndef __LINUX_GFP_H
33 #define __LINUX_GFP_H
44
5−#include <linux/mmdebug.h>
5+#include <linux/gfp_types.h>
6+
67 #include <linux/mmzone.h>
7−#include <linux/stddef.h>
8−#include <linux/linkage.h>
98 #include <linux/topology.h>
109
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−
2510 struct vm_area_struct;
2611
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−
35612 /* Convert GFP flags to their corresponding migrate type */
35713 #define GFP_MOVABLE_MASK (__GFP_RECLAIMABLE|__GFP_MOVABLE)
35814 #define GFP_MOVABLE_SHIFT 3
include/linux/gfp_types.h+348−0
@@ -0,0 +1,348 @@
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 */
include/linux/nodemask.h+19−5
@@ -94,6 +94,7 @@ · 93 unmodified lines
9494 #include <linux/bitmap.h>
9595 #include <linux/minmax.h>
9696 #include <linux/numa.h>
97+#include <linux/random.h>
9798
9899 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
99100 extern nodemask_t _unused_nodemask_arg_;
@@ -276,7 +277,14 @@ static inline unsigned int __next_node(int n, const nodemask_t *srcp) · 176 unmodified lines
276277 * the first node in src if needed. Returns MAX_NUMNODES if src is empty.
277278 */
278279 #define next_node_in(n, src) __next_node_in((n), &(src))
279−unsigned int __next_node_in(int node, const nodemask_t *srcp);
280+static inline unsigned int __next_node_in(int node, const nodemask_t *srcp)
281+{
282+ unsigned int ret = __next_node(node, srcp);
283+
284+ if (ret == MAX_NUMNODES)
285+ ret = __first_node(srcp);
286+ return ret;
287+}
280288
281289 static inline void init_nodemask_of_node(nodemask_t *mask, int node)
282290 {
@@ -493,14 +501,20 @@ static inline int num_node_state(enum node_states state) · 210 unmodified lines
493501
494502 #endif
495503
504+static inline int node_random(const nodemask_t *maskp)
505+{
496506 #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1)
497−extern int node_random(const nodemask_t *maskp);
507+ int w, bit = NUMA_NO_NODE;
508+
509+ w = nodes_weight(*maskp);
510+ if (w)
511+ bit = bitmap_ord_to_pos(maskp->bits,
512+ get_random_int() % w, MAX_NUMNODES);
513+ return bit;
498514 #else
499−static inline int node_random(const nodemask_t *mask)
500−{
501515 return 0;
502−}
503516 #endif
517+}
504518
505519 #define node_online_map node_states[N_ONLINE]
506520 #define node_possible_map node_states[N_POSSIBLE]
lib/Makefile+1−1
@@ -33,7 +33,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ · 32 unmodified lines
3333 flex_proportions.o ratelimit.o show_mem.o \
3434 is_single_threaded.o plist.o decompress.o kobject_uevent.o \
3535 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 \
3737 buildid.o cpumask.o
3838
3939 lib-$(CONFIG_PRINTK) += dump_stack.o
lib/bitmap.c+5−6
@@ -237,7 +237,7 @@ void bitmap_cut(unsigned long *dst, const unsigned long *src, · 236 unmodified lines
237237 }
238238 EXPORT_SYMBOL(bitmap_cut);
239239
240−int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
240+bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
241241 const unsigned long *bitmap2, unsigned int bits)
242242 {
243243 unsigned int k;
@@ -275,7 +275,7 @@ void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1, · 31 unmodified lines
275275 }
276276 EXPORT_SYMBOL(__bitmap_xor);
277277
278−int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
278+bool __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
279279 const unsigned long *bitmap2, unsigned int bits)
280280 {
281281 unsigned int k;
@@ -333,10 +333,9 @@ bool __bitmap_subset(const unsigned long *bitmap1, · 51 unmodified lines
333333 }
334334 EXPORT_SYMBOL(__bitmap_subset);
335335
336−int __bitmap_weight(const unsigned long *bitmap, unsigned int bits)
336+unsigned int __bitmap_weight(const unsigned long *bitmap, unsigned int bits)
337337 {
338− unsigned int k, lim = bits/BITS_PER_LONG;
339− int w = 0;
338+ unsigned int k, lim = bits/BITS_PER_LONG, w = 0;
340339
341340 for (k = 0; k < lim; k++)
342341 w += hweight_long(bitmap[k]);
@@ -1564,7 +1563,7 @@ void bitmap_to_arr64(u64 *buf, const unsigned long *bitmap, unsigned int nbits) · 1221 unmodified lines
15641563
15651564 /* Clear tail bits in the last element of array beyond nbits. */
15661565 if (nbits % 64)
1567− buf[-1] &= GENMASK_ULL(nbits % 64, 0);
1566+ buf[-1] &= GENMASK_ULL((nbits - 1) % 64, 0);
15681567 }
15691568 EXPORT_SYMBOL(bitmap_to_arr64);
15701569 #endif
lib/cpumask.c+7−90
@@ -7,61 +7,6 @@ · 6 unmodified lines
77 #include <linux/memblock.h>
88 #include <linux/numa.h>
99
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−
6510 /**
6611 * cpumask_next_wrap - helper to implement for_each_cpu_wrap
6712 * @n: the cpu prior to the place to search
@@ -74,9 +19,9 @@ EXPORT_SYMBOL(cpumask_any_but); · 6 unmodified lines
7419 * Note: the @wrap argument is required for the start condition when
7520 * we cannot assume @start is set in @mask.
7621 */
77−int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
22+unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
7823 {
79− int next;
24+ unsigned int next;
8025
8126 again:
8227 next = cpumask_next(n, mask);
@@ -125,34 +70,6 @@ bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node) · 42 unmodified lines
12570 }
12671 EXPORT_SYMBOL(alloc_cpumask_var_node);
12772
128−bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
129−{
130− return alloc_cpumask_var_node(mask, flags | __GFP_ZERO, node);
131−}
132−EXPORT_SYMBOL(zalloc_cpumask_var_node);
133−
134−/**
135− * alloc_cpumask_var - allocate a struct cpumask
136− * @mask: pointer to cpumask_var_t where the cpumask is returned
137− * @flags: GFP_ flags
138− *
139− * Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is
140− * a nop returning a constant 1 (in <linux/cpumask.h>).
141− *
142− * See alloc_cpumask_var_node.
143− */
144−bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
145−{
146− return alloc_cpumask_var_node(mask, flags, NUMA_NO_NODE);
147−}
148−EXPORT_SYMBOL(alloc_cpumask_var);
149−
150−bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
151−{
152− return alloc_cpumask_var(mask, flags | __GFP_ZERO);
153−}
154−EXPORT_SYMBOL(zalloc_cpumask_var);
155−
15673 /**
15774 * alloc_bootmem_cpumask_var - allocate a struct cpumask from the bootmem arena.
15875 * @mask: pointer to cpumask_var_t where the cpumask is returned
@@ -206,7 +123,7 @@ void __init free_bootmem_cpumask_var(cpumask_var_t mask) · 47 unmodified lines
206123 */
207124 unsigned int cpumask_local_spread(unsigned int i, int node)
208125 {
209− int cpu;
126+ unsigned int cpu;
210127
211128 /* Wrap: we always want a cpu. */
212129 i %= num_online_cpus();
@@ -244,10 +161,10 @@ static DEFINE_PER_CPU(int, distribute_cpu_mask_prev); · 31 unmodified lines
244161 *
245162 * Returns >= nr_cpu_ids if the intersection is empty.
246163 */
247−int cpumask_any_and_distribute(const struct cpumask *src1p,
164+unsigned int cpumask_any_and_distribute(const struct cpumask *src1p,
248165 const struct cpumask *src2p)
249166 {
250− int next, prev;
167+ unsigned int next, prev;
251168
252169 /* NOTE: our first selection will skip 0. */
253170 prev = __this_cpu_read(distribute_cpu_mask_prev);
@@ -263,9 +180,9 @@ int cpumask_any_and_distribute(const struct cpumask *src1p, · 9 unmodified lines
263180 }
264181 EXPORT_SYMBOL(cpumask_any_and_distribute);
265182
266−int cpumask_any_distribute(const struct cpumask *srcp)
183+unsigned int cpumask_any_distribute(const struct cpumask *srcp)
267184 {
268− int next, prev;
185+ unsigned int next, prev;
269186
270187 /* NOTE: our first selection will skip 0. */
271188 prev = __this_cpu_read(distribute_cpu_mask_prev);
lib/nodemask.c+0−8
@@ -3,14 +3,6 @@ · 2 unmodified lines
33 #include <linux/module.h>
44 #include <linux/random.h>
55
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−}
146 EXPORT_SYMBOL(__next_node_in);
157
168 #ifdef CONFIG_NUMA
lib/test_bitmap.c+68−0
@@ -604,6 +604,12 @@ static void __init test_bitmap_arr64(void) · 603 unmodified lines
604604 pr_err("bitmap_copy_arr64(nbits == %d:"
605605 " tail is not safely cleared: %d\n", nbits, next_bit);
606606
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+
607613 if (nbits < EXP1_IN_BITS - 64)
608614 expect_eq_uint(arr[DIV_ROUND_UP(nbits, 64)], 0xa5a5a5a5);
609615 }
@@ -869,6 +875,67 @@ static void __init test_bitmap_print_buf(void) · 259 unmodified lines
869875 }
870876 }
871877
878+static void __init test_bitmap_const_eval(void)
879+{
880+ DECLARE_BITMAP(bitmap, BITS_PER_LONG);
881+ unsigned long initvar = BIT(2);
882+ unsigned long bitopvar = 0;
883+ unsigned long var = 0;
884+ int res;
885+
886+ /*
887+ * Compilers must be able to optimize all of those to compile-time
888+ * constants on any supported optimization level (-O2, -Os) and any
889+ * architecture. Otherwise, trigger a build bug.
890+ * The whole function gets optimized out then, there's nothing to do
891+ * in runtime.
892+ */
893+
894+ /*
895+ * Equals to `unsigned long bitmap[1] = { GENMASK(6, 5), }`.
896+ * Clang on s390 optimizes bitops at compile-time as intended, but at
897+ * the same time stops treating @bitmap and @bitopvar as compile-time
898+ * constants after regular test_bit() is executed, thus triggering the
899+ * build bugs below. So, call const_test_bit() there directly until
900+ * the compiler is fixed.
901+ */
902+ bitmap_clear(bitmap, 0, BITS_PER_LONG);
903+#if defined(__s390__) && defined(__clang__)
904+ if (!const_test_bit(7, bitmap))
905+#else
906+ if (!test_bit(7, bitmap))
907+#endif
908+ bitmap_set(bitmap, 5, 2);
909+
910+ /* Equals to `unsigned long bitopvar = BIT(20)` */
911+ __change_bit(31, &bitopvar);
912+ bitmap_shift_right(&bitopvar, &bitopvar, 11, BITS_PER_LONG);
913+
914+ /* Equals to `unsigned long var = BIT(25)` */
915+ var |= BIT(25);
916+ if (var & BIT(0))
917+ var ^= GENMASK(9, 6);
918+
919+ /* __const_hweight<32|64>(GENMASK(6, 5)) == 2 */
920+ res = bitmap_weight(bitmap, 20);
921+ BUILD_BUG_ON(!__builtin_constant_p(res));
922+ BUILD_BUG_ON(res != 2);
923+
924+ /* !(BIT(31) & BIT(18)) == 1 */
925+ res = !test_bit(18, &bitopvar);
926+ BUILD_BUG_ON(!__builtin_constant_p(res));
927+ BUILD_BUG_ON(!res);
928+
929+ /* BIT(2) & GENMASK(14, 8) == 0 */
930+ res = initvar & GENMASK(14, 8);
931+ BUILD_BUG_ON(!__builtin_constant_p(res));
932+ BUILD_BUG_ON(res);
933+
934+ /* ~BIT(25) */
935+ BUILD_BUG_ON(!__builtin_constant_p(~var));
936+ BUILD_BUG_ON(~var != ~BIT(25));
937+}
938+
872939 static void __init selftest(void)
873940 {
874941 test_zero_clear();
@@ -884,6 +951,7 @@ static void __init selftest(void) · 9 unmodified lines
884951 test_for_each_set_clump8();
885952 test_bitmap_cut();
886953 test_bitmap_print_buf();
954+ test_bitmap_const_eval();
887955 }
888956
889957 KSTM_MODULE_LOADERS(test_bitmap);
tools/include/asm-generic/bitops/non-atomic.h+20−14
@@ -2,10 +2,10 @@ · 1 unmodified line
22 #ifndef _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
33 #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
44
5−#include <asm/types.h>
5+#include <linux/bits.h>
66
77 /**
8− * __set_bit - Set a bit in memory
8+ * ___set_bit - Set a bit in memory
99 * @nr: the bit to set
1010 * @addr: the address to start counting from
1111 *
@@ -13,7 +13,8 @@ · 1 unmodified line
1313 * If it's called on the same region of memory simultaneously, the effect
1414 * may be that only one operation succeeds.
1515 */
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)
1718 {
1819 unsigned long mask = BIT_MASK(nr);
1920 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -21,7 +22,8 @@ static inline void __set_bit(int nr, volatile unsigned long *addr) · 1 unmodified line
2122 *p |= mask;
2223 }
2324
24−static inline void __clear_bit(int nr, volatile unsigned long *addr)
25+static __always_inline void
26+___clear_bit(unsigned long nr, volatile unsigned long *addr)
2527 {
2628 unsigned long mask = BIT_MASK(nr);
2729 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -30,7 +32,7 @@ static inline void __clear_bit(int nr, volatile unsigned long *addr) · 2 unmodified lines
3032 }
3133
3234 /**
33− * __change_bit - Toggle a bit in memory
35+ * ___change_bit - Toggle a bit in memory
3436 * @nr: the bit to change
3537 * @addr: the address to start counting from
3638 *
@@ -38,7 +40,8 @@ static inline void __clear_bit(int nr, volatile unsigned long *addr) · 1 unmodified line
3840 * If it's called on the same region of memory simultaneously, the effect
3941 * may be that only one operation succeeds.
4042 */
41−static inline void __change_bit(int nr, volatile unsigned long *addr)
43+static __always_inline void
44+___change_bit(unsigned long nr, volatile unsigned long *addr)
4245 {
4346 unsigned long mask = BIT_MASK(nr);
4447 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -47,7 +50,7 @@ static inline void __change_bit(int nr, volatile unsigned long *addr) · 2 unmodified lines
4750 }
4851
4952 /**
50− * __test_and_set_bit - Set a bit and return its old value
53+ * ___test_and_set_bit - Set a bit and return its old value
5154 * @nr: Bit to set
5255 * @addr: Address to count from
5356 *
@@ -55,7 +58,8 @@ static inline void __change_bit(int nr, volatile unsigned long *addr) · 1 unmodified line
5558 * If two examples of this operation race, one can appear to succeed
5659 * but actually fail. You must protect multiple accesses with a lock.
5760 */
58−static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
61+static __always_inline bool
62+___test_and_set_bit(unsigned long nr, volatile unsigned long *addr)
5963 {
6064 unsigned long mask = BIT_MASK(nr);
6165 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -66,7 +70,7 @@ static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) · 4 unmodified lines
6670 }
6771
6872 /**
69− * __test_and_clear_bit - Clear a bit and return its old value
73+ * ___test_and_clear_bit - Clear a bit and return its old value
7074 * @nr: Bit to clear
7175 * @addr: Address to count from
7276 *
@@ -74,7 +78,8 @@ static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) · 1 unmodified line
7478 * If two examples of this operation race, one can appear to succeed
7579 * but actually fail. You must protect multiple accesses with a lock.
7680 */
77−static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
81+static __always_inline bool
82+___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
7883 {
7984 unsigned long mask = BIT_MASK(nr);
8085 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -85,8 +90,8 @@ static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) · 4 unmodified lines
8590 }
8691
8792 /* WARNING: non atomic and it can be reordered! */
88−static inline int __test_and_change_bit(int nr,
89− volatile unsigned long *addr)
93+static __always_inline bool
94+___test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
9095 {
9196 unsigned long mask = BIT_MASK(nr);
9297 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -97,11 +102,12 @@ static inline int __test_and_change_bit(int nr, · 4 unmodified lines
97102 }
98103
99104 /**
100− * test_bit - Determine whether a bit is set
105+ * _test_bit - Determine whether a bit is set
101106 * @nr: bit number to test
102107 * @addr: Address to start counting from
103108 */
104−static inline int test_bit(int nr, const volatile unsigned long *addr)
109+static __always_inline bool
110+_test_bit(unsigned long nr, const volatile unsigned long *addr)
105111 {
106112 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
107113 }
tools/include/linux/bitmap.h+6−6
@@ -11,10 +11,10 @@ · 10 unmodified lines
1111 #define DECLARE_BITMAP(name,bits) \
1212 unsigned long name[BITS_TO_LONGS(bits)]
1313
14−int __bitmap_weight(const unsigned long *bitmap, int bits);
14+unsigned int __bitmap_weight(const unsigned long *bitmap, int bits);
1515 void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
1616 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,
1818 const unsigned long *bitmap2, unsigned int bits);
1919 bool __bitmap_equal(const unsigned long *bitmap1,
2020 const unsigned long *bitmap2, unsigned int bits);
@@ -45,7 +45,7 @@ static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) · 24 unmodified lines
4545 dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits);
4646 }
4747
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)
4949 {
5050 if (small_const_nbits(nbits))
5151 return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
@@ -53,7 +53,7 @@ static inline int bitmap_empty(const unsigned long *src, unsigned nbits) · 1 unmodified line
5353 return find_first_bit(src, nbits) == nbits;
5454 }
5555
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)
5757 {
5858 if (small_const_nbits(nbits))
5959 return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
@@ -61,7 +61,7 @@ static inline int bitmap_full(const unsigned long *src, unsigned int nbits) · 1 unmodified line
6161 return find_first_zero_bit(src, nbits) == nbits;
6262 }
6363
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)
6565 {
6666 if (small_const_nbits(nbits))
6767 return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
@@ -146,7 +146,7 @@ size_t bitmap_scnprintf(unsigned long *bitmap, unsigned int nbits, · 78 unmodified lines
146146 * @src2: operand 2
147147 * @nbits: size of bitmap
148148 */
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,
150150 const unsigned long *src2, unsigned int nbits)
151151 {
152152 if (small_const_nbits(nbits))
tools/include/linux/bitops.h+16−0
@@ -25,6 +25,22 @@ extern unsigned int __sw_hweight16(unsigned int w); · 24 unmodified lines
2525 extern unsigned int __sw_hweight32(unsigned int w);
2626 extern unsigned long __sw_hweight64(__u64 w);
2727
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+
2844 /*
2945 * Include this here because some architectures need generic_ffs/fls in
3046 * scope
tools/lib/bitmap.c+3−3
@@ -5,9 +5,9 @@ · 4 unmodified lines
55 */
66 #include <linux/bitmap.h>
77
8−int __bitmap_weight(const unsigned long *bitmap, int bits)
8+unsigned int __bitmap_weight(const unsigned long *bitmap, int bits)
99 {
10− int k, w = 0, lim = bits/BITS_PER_LONG;
10+ unsigned int k, w = 0, lim = bits/BITS_PER_LONG;
1111
1212 for (k = 0; k < lim; k++)
1313 w += hweight_long(bitmap[k]);
@@ -57,7 +57,7 @@ size_t bitmap_scnprintf(unsigned long *bitmap, unsigned int nbits, · 43 unmodified lines
5757 return ret;
5858 }
5959
60−int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
60+bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
6161 const unsigned long *bitmap2, unsigned int bits)
6262 {
6363 unsigned int k;