Skip to content

Commit 772dd03

Browse files
surenbaghdasaryanakpm00
authored andcommitted
mm: enumerate all gfp flags
Introduce GFP bits enumeration to let compiler track the number of used bits (which depends on the config options) instead of hardcoding them. That simplifies __GFP_BITS_SHIFT calculation. Link: https://lkml.kernel.org/r/[email protected] Suggested-by: Petr Tesařík <[email protected]> Signed-off-by: Suren Baghdasaryan <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Pasha Tatashin <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Petr Tesarik <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 2864f3d commit 772dd03

File tree

1 file changed

+62
-28
lines changed

1 file changed

+62
-28
lines changed

include/linux/gfp_types.h

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,78 @@ typedef unsigned int __bitwise gfp_t;
2121
* include/trace/events/mmflags.h and tools/perf/builtin-kmem.c
2222
*/
2323

24+
enum {
25+
___GFP_DMA_BIT,
26+
___GFP_HIGHMEM_BIT,
27+
___GFP_DMA32_BIT,
28+
___GFP_MOVABLE_BIT,
29+
___GFP_RECLAIMABLE_BIT,
30+
___GFP_HIGH_BIT,
31+
___GFP_IO_BIT,
32+
___GFP_FS_BIT,
33+
___GFP_ZERO_BIT,
34+
___GFP_UNUSED_BIT, /* 0x200u unused */
35+
___GFP_DIRECT_RECLAIM_BIT,
36+
___GFP_KSWAPD_RECLAIM_BIT,
37+
___GFP_WRITE_BIT,
38+
___GFP_NOWARN_BIT,
39+
___GFP_RETRY_MAYFAIL_BIT,
40+
___GFP_NOFAIL_BIT,
41+
___GFP_NORETRY_BIT,
42+
___GFP_MEMALLOC_BIT,
43+
___GFP_COMP_BIT,
44+
___GFP_NOMEMALLOC_BIT,
45+
___GFP_HARDWALL_BIT,
46+
___GFP_THISNODE_BIT,
47+
___GFP_ACCOUNT_BIT,
48+
___GFP_ZEROTAGS_BIT,
49+
#ifdef CONFIG_KASAN_HW_TAGS
50+
___GFP_SKIP_ZERO_BIT,
51+
___GFP_SKIP_KASAN_BIT,
52+
#endif
53+
#ifdef CONFIG_LOCKDEP
54+
___GFP_NOLOCKDEP_BIT,
55+
#endif
56+
___GFP_LAST_BIT
57+
};
58+
2459
/* 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
60+
#define ___GFP_DMA BIT(___GFP_DMA_BIT)
61+
#define ___GFP_HIGHMEM BIT(___GFP_HIGHMEM_BIT)
62+
#define ___GFP_DMA32 BIT(___GFP_DMA32_BIT)
63+
#define ___GFP_MOVABLE BIT(___GFP_MOVABLE_BIT)
64+
#define ___GFP_RECLAIMABLE BIT(___GFP_RECLAIMABLE_BIT)
65+
#define ___GFP_HIGH BIT(___GFP_HIGH_BIT)
66+
#define ___GFP_IO BIT(___GFP_IO_BIT)
67+
#define ___GFP_FS BIT(___GFP_FS_BIT)
68+
#define ___GFP_ZERO BIT(___GFP_ZERO_BIT)
3469
/* 0x200u unused */
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
70+
#define ___GFP_DIRECT_RECLAIM BIT(___GFP_DIRECT_RECLAIM_BIT)
71+
#define ___GFP_KSWAPD_RECLAIM BIT(___GFP_KSWAPD_RECLAIM_BIT)
72+
#define ___GFP_WRITE BIT(___GFP_WRITE_BIT)
73+
#define ___GFP_NOWARN BIT(___GFP_NOWARN_BIT)
74+
#define ___GFP_RETRY_MAYFAIL BIT(___GFP_RETRY_MAYFAIL_BIT)
75+
#define ___GFP_NOFAIL BIT(___GFP_NOFAIL_BIT)
76+
#define ___GFP_NORETRY BIT(___GFP_NORETRY_BIT)
77+
#define ___GFP_MEMALLOC BIT(___GFP_MEMALLOC_BIT)
78+
#define ___GFP_COMP BIT(___GFP_COMP_BIT)
79+
#define ___GFP_NOMEMALLOC BIT(___GFP_NOMEMALLOC_BIT)
80+
#define ___GFP_HARDWALL BIT(___GFP_HARDWALL_BIT)
81+
#define ___GFP_THISNODE BIT(___GFP_THISNODE_BIT)
82+
#define ___GFP_ACCOUNT BIT(___GFP_ACCOUNT_BIT)
83+
#define ___GFP_ZEROTAGS BIT(___GFP_ZEROTAGS_BIT)
4984
#ifdef CONFIG_KASAN_HW_TAGS
50-
#define ___GFP_SKIP_ZERO 0x1000000u
51-
#define ___GFP_SKIP_KASAN 0x2000000u
85+
#define ___GFP_SKIP_ZERO BIT(___GFP_SKIP_ZERO_BIT)
86+
#define ___GFP_SKIP_KASAN BIT(___GFP_SKIP_KASAN_BIT)
5287
#else
5388
#define ___GFP_SKIP_ZERO 0
5489
#define ___GFP_SKIP_KASAN 0
5590
#endif
5691
#ifdef CONFIG_LOCKDEP
57-
#define ___GFP_NOLOCKDEP 0x4000000u
92+
#define ___GFP_NOLOCKDEP BIT(___GFP_NOLOCKDEP_BIT)
5893
#else
5994
#define ___GFP_NOLOCKDEP 0
6095
#endif
61-
/* If the above are modified, __GFP_BITS_SHIFT may need updating */
6296

6397
/*
6498
* Physical address zone modifiers (see linux/mmzone.h - low four bits)
@@ -249,7 +283,7 @@ typedef unsigned int __bitwise gfp_t;
249283
#define __GFP_NOLOCKDEP ((__force gfp_t)___GFP_NOLOCKDEP)
250284

251285
/* Room for N __GFP_FOO bits */
252-
#define __GFP_BITS_SHIFT (26 + IS_ENABLED(CONFIG_LOCKDEP))
286+
#define __GFP_BITS_SHIFT ___GFP_LAST_BIT
253287
#define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
254288

255289
/**

0 commit comments

Comments
 (0)