diff options
| author | Alexey Dobriyan <adobriyan@gmail.com> | 2017-11-15 20:32:18 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-11-15 21:21:01 -0500 |
| commit | d50112edde1d0c621520e53747044009f11c656b (patch) | |
| tree | ca4092f2126ac85a63647a48e43ecbf34bb69782 /include/linux | |
| parent | a3ba074447824625d3a267a5fffd2ea21556ebf4 (diff) | |
slab, slub, slob: add slab_flags_t
Add sparse-checked slab_flags_t for struct kmem_cache::flags (SLAB_POISON,
etc).
SLAB is bloated temporarily by switching to "unsigned long", but only
temporarily.
Link: http://lkml.kernel.org/r/20171021100225.GA22428@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Acked-by: Pekka Enberg <penberg@kernel.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/kasan.h | 4 | ||||
| -rw-r--r-- | include/linux/kmemleak.h | 8 | ||||
| -rw-r--r-- | include/linux/slab.h | 60 | ||||
| -rw-r--r-- | include/linux/slab_def.h | 2 | ||||
| -rw-r--r-- | include/linux/slub_def.h | 2 | ||||
| -rw-r--r-- | include/linux/types.h | 1 |
6 files changed, 46 insertions, 31 deletions
diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 5017269e3f04..e3eb834c9a35 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h | |||
| @@ -46,7 +46,7 @@ void kasan_alloc_pages(struct page *page, unsigned int order); | |||
| 46 | void kasan_free_pages(struct page *page, unsigned int order); | 46 | void kasan_free_pages(struct page *page, unsigned int order); |
| 47 | 47 | ||
| 48 | void kasan_cache_create(struct kmem_cache *cache, size_t *size, | 48 | void kasan_cache_create(struct kmem_cache *cache, size_t *size, |
| 49 | unsigned long *flags); | 49 | slab_flags_t *flags); |
| 50 | void kasan_cache_shrink(struct kmem_cache *cache); | 50 | void kasan_cache_shrink(struct kmem_cache *cache); |
| 51 | void kasan_cache_shutdown(struct kmem_cache *cache); | 51 | void kasan_cache_shutdown(struct kmem_cache *cache); |
| 52 | 52 | ||
| @@ -95,7 +95,7 @@ static inline void kasan_free_pages(struct page *page, unsigned int order) {} | |||
| 95 | 95 | ||
| 96 | static inline void kasan_cache_create(struct kmem_cache *cache, | 96 | static inline void kasan_cache_create(struct kmem_cache *cache, |
| 97 | size_t *size, | 97 | size_t *size, |
| 98 | unsigned long *flags) {} | 98 | slab_flags_t *flags) {} |
| 99 | static inline void kasan_cache_shrink(struct kmem_cache *cache) {} | 99 | static inline void kasan_cache_shrink(struct kmem_cache *cache) {} |
| 100 | static inline void kasan_cache_shutdown(struct kmem_cache *cache) {} | 100 | static inline void kasan_cache_shutdown(struct kmem_cache *cache) {} |
| 101 | 101 | ||
diff --git a/include/linux/kmemleak.h b/include/linux/kmemleak.h index 590343f6c1b1..5ac416e2d339 100644 --- a/include/linux/kmemleak.h +++ b/include/linux/kmemleak.h | |||
| @@ -48,14 +48,14 @@ extern void kmemleak_not_leak_phys(phys_addr_t phys) __ref; | |||
| 48 | extern void kmemleak_ignore_phys(phys_addr_t phys) __ref; | 48 | extern void kmemleak_ignore_phys(phys_addr_t phys) __ref; |
| 49 | 49 | ||
| 50 | static inline void kmemleak_alloc_recursive(const void *ptr, size_t size, | 50 | static inline void kmemleak_alloc_recursive(const void *ptr, size_t size, |
| 51 | int min_count, unsigned long flags, | 51 | int min_count, slab_flags_t flags, |
| 52 | gfp_t gfp) | 52 | gfp_t gfp) |
| 53 | { | 53 | { |
| 54 | if (!(flags & SLAB_NOLEAKTRACE)) | 54 | if (!(flags & SLAB_NOLEAKTRACE)) |
| 55 | kmemleak_alloc(ptr, size, min_count, gfp); | 55 | kmemleak_alloc(ptr, size, min_count, gfp); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | static inline void kmemleak_free_recursive(const void *ptr, unsigned long flags) | 58 | static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags) |
| 59 | { | 59 | { |
| 60 | if (!(flags & SLAB_NOLEAKTRACE)) | 60 | if (!(flags & SLAB_NOLEAKTRACE)) |
| 61 | kmemleak_free(ptr); | 61 | kmemleak_free(ptr); |
| @@ -76,7 +76,7 @@ static inline void kmemleak_alloc(const void *ptr, size_t size, int min_count, | |||
| 76 | { | 76 | { |
| 77 | } | 77 | } |
| 78 | static inline void kmemleak_alloc_recursive(const void *ptr, size_t size, | 78 | static inline void kmemleak_alloc_recursive(const void *ptr, size_t size, |
| 79 | int min_count, unsigned long flags, | 79 | int min_count, slab_flags_t flags, |
| 80 | gfp_t gfp) | 80 | gfp_t gfp) |
| 81 | { | 81 | { |
| 82 | } | 82 | } |
| @@ -94,7 +94,7 @@ static inline void kmemleak_free(const void *ptr) | |||
| 94 | static inline void kmemleak_free_part(const void *ptr, size_t size) | 94 | static inline void kmemleak_free_part(const void *ptr, size_t size) |
| 95 | { | 95 | { |
| 96 | } | 96 | } |
| 97 | static inline void kmemleak_free_recursive(const void *ptr, unsigned long flags) | 97 | static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags) |
| 98 | { | 98 | { |
| 99 | } | 99 | } |
| 100 | static inline void kmemleak_free_percpu(const void __percpu *ptr) | 100 | static inline void kmemleak_free_percpu(const void __percpu *ptr) |
diff --git a/include/linux/slab.h b/include/linux/slab.h index af5aa65c7c18..0c4c579f52ed 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h | |||
| @@ -21,13 +21,20 @@ | |||
| 21 | * Flags to pass to kmem_cache_create(). | 21 | * Flags to pass to kmem_cache_create(). |
| 22 | * The ones marked DEBUG are only valid if CONFIG_DEBUG_SLAB is set. | 22 | * The ones marked DEBUG are only valid if CONFIG_DEBUG_SLAB is set. |
| 23 | */ | 23 | */ |
| 24 | #define SLAB_CONSISTENCY_CHECKS 0x00000100UL /* DEBUG: Perform (expensive) checks on alloc/free */ | 24 | /* DEBUG: Perform (expensive) checks on alloc/free */ |
| 25 | #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */ | 25 | #define SLAB_CONSISTENCY_CHECKS ((slab_flags_t __force)0x00000100UL) |
| 26 | #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */ | 26 | /* DEBUG: Red zone objs in a cache */ |
| 27 | #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */ | 27 | #define SLAB_RED_ZONE ((slab_flags_t __force)0x00000400UL) |
| 28 | #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */ | 28 | /* DEBUG: Poison objects */ |
| 29 | #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */ | 29 | #define SLAB_POISON ((slab_flags_t __force)0x00000800UL) |
| 30 | #define SLAB_PANIC 0x00040000UL /* Panic if kmem_cache_create() fails */ | 30 | /* Align objs on cache lines */ |
| 31 | #define SLAB_HWCACHE_ALIGN ((slab_flags_t __force)0x00002000UL) | ||
| 32 | /* Use GFP_DMA memory */ | ||
| 33 | #define SLAB_CACHE_DMA ((slab_flags_t __force)0x00004000UL) | ||
| 34 | /* DEBUG: Store the last owner for bug hunting */ | ||
| 35 | #define SLAB_STORE_USER ((slab_flags_t __force)0x00010000UL) | ||
| 36 | /* Panic if kmem_cache_create() fails */ | ||
| 37 | #define SLAB_PANIC ((slab_flags_t __force)0x00040000UL) | ||
| 31 | /* | 38 | /* |
| 32 | * SLAB_TYPESAFE_BY_RCU - **WARNING** READ THIS! | 39 | * SLAB_TYPESAFE_BY_RCU - **WARNING** READ THIS! |
| 33 | * | 40 | * |
| @@ -65,44 +72,51 @@ | |||
| 65 | * | 72 | * |
| 66 | * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU. | 73 | * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU. |
| 67 | */ | 74 | */ |
| 68 | #define SLAB_TYPESAFE_BY_RCU 0x00080000UL /* Defer freeing slabs to RCU */ | 75 | /* Defer freeing slabs to RCU */ |
| 69 | #define SLAB_MEM_SPREAD 0x00100000UL /* Spread some memory over cpuset */ | 76 | #define SLAB_TYPESAFE_BY_RCU ((slab_flags_t __force)0x00080000UL) |
| 70 | #define SLAB_TRACE 0x00200000UL /* Trace allocations and frees */ | 77 | /* Spread some memory over cpuset */ |
| 78 | #define SLAB_MEM_SPREAD ((slab_flags_t __force)0x00100000UL) | ||
| 79 | /* Trace allocations and frees */ | ||
| 80 | #define SLAB_TRACE ((slab_flags_t __force)0x00200000UL) | ||
| 71 | 81 | ||
| 72 | /* Flag to prevent checks on free */ | 82 | /* Flag to prevent checks on free */ |
| 73 | #ifdef CONFIG_DEBUG_OBJECTS | 83 | #ifdef CONFIG_DEBUG_OBJECTS |
| 74 | # define SLAB_DEBUG_OBJECTS 0x00400000UL | 84 | # define SLAB_DEBUG_OBJECTS ((slab_flags_t __force)0x00400000UL) |
| 75 | #else | 85 | #else |
| 76 | # define SLAB_DEBUG_OBJECTS 0x00000000UL | 86 | # define SLAB_DEBUG_OBJECTS ((slab_flags_t __force)0x00000000UL) |
| 77 | #endif | 87 | #endif |
| 78 | 88 | ||
| 79 | #define SLAB_NOLEAKTRACE 0x00800000UL /* Avoid kmemleak tracing */ | 89 | /* Avoid kmemleak tracing */ |
| 90 | #define SLAB_NOLEAKTRACE ((slab_flags_t __force)0x00800000UL) | ||
| 80 | 91 | ||
| 81 | /* Don't track use of uninitialized memory */ | 92 | /* Don't track use of uninitialized memory */ |
| 82 | #ifdef CONFIG_KMEMCHECK | 93 | #ifdef CONFIG_KMEMCHECK |
| 83 | # define SLAB_NOTRACK 0x01000000UL | 94 | # define SLAB_NOTRACK ((slab_flags_t __force)0x01000000UL) |
| 84 | #else | 95 | #else |
| 85 | # define SLAB_NOTRACK 0x00000000UL | 96 | # define SLAB_NOTRACK ((slab_flags_t __force)0x00000000UL) |
| 86 | #endif | 97 | #endif |
| 98 | /* Fault injection mark */ | ||
| 87 | #ifdef CONFIG_FAILSLAB | 99 | #ifdef CONFIG_FAILSLAB |
| 88 | # define SLAB_FAILSLAB 0x02000000UL /* Fault injection mark */ | 100 | # define SLAB_FAILSLAB ((slab_flags_t __force)0x02000000UL) |
| 89 | #else | 101 | #else |
| 90 | # define SLAB_FAILSLAB 0x00000000UL | 102 | # define SLAB_FAILSLAB ((slab_flags_t __force)0x00000000UL) |
| 91 | #endif | 103 | #endif |
| 104 | /* Account to memcg */ | ||
| 92 | #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB) | 105 | #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB) |
| 93 | # define SLAB_ACCOUNT 0x04000000UL /* Account to memcg */ | 106 | # define SLAB_ACCOUNT ((slab_flags_t __force)0x04000000UL) |
| 94 | #else | 107 | #else |
| 95 | # define SLAB_ACCOUNT 0x00000000UL | 108 | # define SLAB_ACCOUNT ((slab_flags_t __force)0x00000000UL) |
| 96 | #endif | 109 | #endif |
| 97 | 110 | ||
| 98 | #ifdef CONFIG_KASAN | 111 | #ifdef CONFIG_KASAN |
| 99 | #define SLAB_KASAN 0x08000000UL | 112 | #define SLAB_KASAN ((slab_flags_t __force)0x08000000UL) |
| 100 | #else | 113 | #else |
| 101 | #define SLAB_KASAN 0x00000000UL | 114 | #define SLAB_KASAN ((slab_flags_t __force)0x00000000UL) |
| 102 | #endif | 115 | #endif |
| 103 | 116 | ||
| 104 | /* The following flags affect the page allocator grouping pages by mobility */ | 117 | /* The following flags affect the page allocator grouping pages by mobility */ |
| 105 | #define SLAB_RECLAIM_ACCOUNT 0x00020000UL /* Objects are reclaimable */ | 118 | /* Objects are reclaimable */ |
| 119 | #define SLAB_RECLAIM_ACCOUNT ((slab_flags_t __force)0x00020000UL) | ||
| 106 | #define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */ | 120 | #define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */ |
| 107 | /* | 121 | /* |
| 108 | * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests. | 122 | * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests. |
| @@ -128,7 +142,7 @@ void __init kmem_cache_init(void); | |||
| 128 | bool slab_is_available(void); | 142 | bool slab_is_available(void); |
| 129 | 143 | ||
| 130 | struct kmem_cache *kmem_cache_create(const char *, size_t, size_t, | 144 | struct kmem_cache *kmem_cache_create(const char *, size_t, size_t, |
| 131 | unsigned long, | 145 | slab_flags_t, |
| 132 | void (*)(void *)); | 146 | void (*)(void *)); |
| 133 | void kmem_cache_destroy(struct kmem_cache *); | 147 | void kmem_cache_destroy(struct kmem_cache *); |
| 134 | int kmem_cache_shrink(struct kmem_cache *); | 148 | int kmem_cache_shrink(struct kmem_cache *); |
diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h index 8f7d2b1656d2..072e46e9e1d5 100644 --- a/include/linux/slab_def.h +++ b/include/linux/slab_def.h | |||
| @@ -20,7 +20,7 @@ struct kmem_cache { | |||
| 20 | struct reciprocal_value reciprocal_buffer_size; | 20 | struct reciprocal_value reciprocal_buffer_size; |
| 21 | /* 2) touched by every alloc & free from the backend */ | 21 | /* 2) touched by every alloc & free from the backend */ |
| 22 | 22 | ||
| 23 | unsigned int flags; /* constant flags */ | 23 | slab_flags_t flags; /* constant flags */ |
| 24 | unsigned int num; /* # of objs per slab */ | 24 | unsigned int num; /* # of objs per slab */ |
| 25 | 25 | ||
| 26 | /* 3) cache_grow/shrink */ | 26 | /* 3) cache_grow/shrink */ |
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h index 39fa09bcde23..0adae162dc8f 100644 --- a/include/linux/slub_def.h +++ b/include/linux/slub_def.h | |||
| @@ -82,7 +82,7 @@ struct kmem_cache_order_objects { | |||
| 82 | struct kmem_cache { | 82 | struct kmem_cache { |
| 83 | struct kmem_cache_cpu __percpu *cpu_slab; | 83 | struct kmem_cache_cpu __percpu *cpu_slab; |
| 84 | /* Used for retriving partial slabs etc */ | 84 | /* Used for retriving partial slabs etc */ |
| 85 | unsigned long flags; | 85 | slab_flags_t flags; |
| 86 | unsigned long min_partial; | 86 | unsigned long min_partial; |
| 87 | int size; /* The size of an object including meta data */ | 87 | int size; /* The size of an object including meta data */ |
| 88 | int object_size; /* The size of an object without meta data */ | 88 | int object_size; /* The size of an object without meta data */ |
diff --git a/include/linux/types.h b/include/linux/types.h index 34fce54e4f1b..732b52c2eae4 100644 --- a/include/linux/types.h +++ b/include/linux/types.h | |||
| @@ -156,6 +156,7 @@ typedef u32 dma_addr_t; | |||
| 156 | #endif | 156 | #endif |
| 157 | 157 | ||
| 158 | typedef unsigned __bitwise gfp_t; | 158 | typedef unsigned __bitwise gfp_t; |
| 159 | typedef unsigned long __bitwise slab_flags_t; | ||
| 159 | typedef unsigned __bitwise fmode_t; | 160 | typedef unsigned __bitwise fmode_t; |
| 160 | 161 | ||
| 161 | #ifdef CONFIG_PHYS_ADDR_T_64BIT | 162 | #ifdef CONFIG_PHYS_ADDR_T_64BIT |
