diff options
author | Alexander Potapenko <glider@google.com> | 2016-03-25 17:22:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-03-25 19:37:42 -0400 |
commit | 505f5dcb1c419e55a9621a01f83eb5745d8d7398 (patch) | |
tree | 4d608fdad5254972f8bba02f437060764e30bc6f /mm/mempool.c | |
parent | 7ed2f9e663854db313f177a511145630e398b402 (diff) |
mm, kasan: add GFP flags to KASAN API
Add GFP flags to KASAN hooks for future patches to use.
This patch is based on the "mm: kasan: unified support for SLUB and SLAB
allocators" patch originally prepared by Dmitry Chernenkov.
Signed-off-by: Alexander Potapenko <glider@google.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Andrey Konovalov <adech.fo@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Konstantin Serebryany <kcc@google.com>
Cc: Dmitry Chernenkov <dmitryc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/mempool.c')
-rw-r--r-- | mm/mempool.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/mm/mempool.c b/mm/mempool.c index 07c383ddbbab..9b7a14a791cc 100644 --- a/mm/mempool.c +++ b/mm/mempool.c | |||
@@ -112,12 +112,12 @@ static void kasan_poison_element(mempool_t *pool, void *element) | |||
112 | kasan_free_pages(element, (unsigned long)pool->pool_data); | 112 | kasan_free_pages(element, (unsigned long)pool->pool_data); |
113 | } | 113 | } |
114 | 114 | ||
115 | static void kasan_unpoison_element(mempool_t *pool, void *element) | 115 | static void kasan_unpoison_element(mempool_t *pool, void *element, gfp_t flags) |
116 | { | 116 | { |
117 | if (pool->alloc == mempool_alloc_slab) | 117 | if (pool->alloc == mempool_alloc_slab) |
118 | kasan_slab_alloc(pool->pool_data, element); | 118 | kasan_slab_alloc(pool->pool_data, element, flags); |
119 | if (pool->alloc == mempool_kmalloc) | 119 | if (pool->alloc == mempool_kmalloc) |
120 | kasan_krealloc(element, (size_t)pool->pool_data); | 120 | kasan_krealloc(element, (size_t)pool->pool_data, flags); |
121 | if (pool->alloc == mempool_alloc_pages) | 121 | if (pool->alloc == mempool_alloc_pages) |
122 | kasan_alloc_pages(element, (unsigned long)pool->pool_data); | 122 | kasan_alloc_pages(element, (unsigned long)pool->pool_data); |
123 | } | 123 | } |
@@ -130,12 +130,12 @@ static void add_element(mempool_t *pool, void *element) | |||
130 | pool->elements[pool->curr_nr++] = element; | 130 | pool->elements[pool->curr_nr++] = element; |
131 | } | 131 | } |
132 | 132 | ||
133 | static void *remove_element(mempool_t *pool) | 133 | static void *remove_element(mempool_t *pool, gfp_t flags) |
134 | { | 134 | { |
135 | void *element = pool->elements[--pool->curr_nr]; | 135 | void *element = pool->elements[--pool->curr_nr]; |
136 | 136 | ||
137 | BUG_ON(pool->curr_nr < 0); | 137 | BUG_ON(pool->curr_nr < 0); |
138 | kasan_unpoison_element(pool, element); | 138 | kasan_unpoison_element(pool, element, flags); |
139 | check_element(pool, element); | 139 | check_element(pool, element); |
140 | return element; | 140 | return element; |
141 | } | 141 | } |
@@ -154,7 +154,7 @@ void mempool_destroy(mempool_t *pool) | |||
154 | return; | 154 | return; |
155 | 155 | ||
156 | while (pool->curr_nr) { | 156 | while (pool->curr_nr) { |
157 | void *element = remove_element(pool); | 157 | void *element = remove_element(pool, GFP_KERNEL); |
158 | pool->free(element, pool->pool_data); | 158 | pool->free(element, pool->pool_data); |
159 | } | 159 | } |
160 | kfree(pool->elements); | 160 | kfree(pool->elements); |
@@ -250,7 +250,7 @@ int mempool_resize(mempool_t *pool, int new_min_nr) | |||
250 | spin_lock_irqsave(&pool->lock, flags); | 250 | spin_lock_irqsave(&pool->lock, flags); |
251 | if (new_min_nr <= pool->min_nr) { | 251 | if (new_min_nr <= pool->min_nr) { |
252 | while (new_min_nr < pool->curr_nr) { | 252 | while (new_min_nr < pool->curr_nr) { |
253 | element = remove_element(pool); | 253 | element = remove_element(pool, GFP_KERNEL); |
254 | spin_unlock_irqrestore(&pool->lock, flags); | 254 | spin_unlock_irqrestore(&pool->lock, flags); |
255 | pool->free(element, pool->pool_data); | 255 | pool->free(element, pool->pool_data); |
256 | spin_lock_irqsave(&pool->lock, flags); | 256 | spin_lock_irqsave(&pool->lock, flags); |
@@ -347,7 +347,7 @@ repeat_alloc: | |||
347 | 347 | ||
348 | spin_lock_irqsave(&pool->lock, flags); | 348 | spin_lock_irqsave(&pool->lock, flags); |
349 | if (likely(pool->curr_nr)) { | 349 | if (likely(pool->curr_nr)) { |
350 | element = remove_element(pool); | 350 | element = remove_element(pool, gfp_temp); |
351 | spin_unlock_irqrestore(&pool->lock, flags); | 351 | spin_unlock_irqrestore(&pool->lock, flags); |
352 | /* paired with rmb in mempool_free(), read comment there */ | 352 | /* paired with rmb in mempool_free(), read comment there */ |
353 | smp_wmb(); | 353 | smp_wmb(); |