Commit 5c382300 authored by Alok N Kataria's avatar Alok N Kataria Committed by Linus Torvalds

[PATCH] kmalloc_node IRQ safety fix

In kmalloc_node we are checking if the allocation is for the same node when
interrupts are "on".  This may lead to an allocation on another node than
intended.

This patch just shifts the check for the current node in __cache_alloc_node
when interrupts are disabled.
Signed-off-by: default avatarAlok N Kataria <alokk@calsoftinc.com>
Acked-by: default avatarChristoph Lameter <clameter@sgi.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 0f9578b7
...@@ -2510,16 +2510,12 @@ cache_alloc_debugcheck_after(kmem_cache_t *cachep, ...@@ -2510,16 +2510,12 @@ cache_alloc_debugcheck_after(kmem_cache_t *cachep,
#define cache_alloc_debugcheck_after(a,b,objp,d) (objp) #define cache_alloc_debugcheck_after(a,b,objp,d) (objp)
#endif #endif
static inline void *____cache_alloc(kmem_cache_t *cachep, unsigned int __nocast flags)
static inline void *__cache_alloc(kmem_cache_t *cachep, unsigned int __nocast flags)
{ {
unsigned long save_flags;
void* objp; void* objp;
struct array_cache *ac; struct array_cache *ac;
cache_alloc_debugcheck_before(cachep, flags); check_irq_off();
local_irq_save(save_flags);
ac = ac_data(cachep); ac = ac_data(cachep);
if (likely(ac->avail)) { if (likely(ac->avail)) {
STATS_INC_ALLOCHIT(cachep); STATS_INC_ALLOCHIT(cachep);
...@@ -2529,6 +2525,18 @@ static inline void *__cache_alloc(kmem_cache_t *cachep, unsigned int __nocast fl ...@@ -2529,6 +2525,18 @@ static inline void *__cache_alloc(kmem_cache_t *cachep, unsigned int __nocast fl
STATS_INC_ALLOCMISS(cachep); STATS_INC_ALLOCMISS(cachep);
objp = cache_alloc_refill(cachep, flags); objp = cache_alloc_refill(cachep, flags);
} }
return objp;
}
static inline void *__cache_alloc(kmem_cache_t *cachep, unsigned int __nocast flags)
{
unsigned long save_flags;
void* objp;
cache_alloc_debugcheck_before(cachep, flags);
local_irq_save(save_flags);
objp = ____cache_alloc(cachep, flags);
local_irq_restore(save_flags); local_irq_restore(save_flags);
objp = cache_alloc_debugcheck_after(cachep, flags, objp, objp = cache_alloc_debugcheck_after(cachep, flags, objp,
__builtin_return_address(0)); __builtin_return_address(0));
...@@ -2856,7 +2864,10 @@ void *kmem_cache_alloc_node(kmem_cache_t *cachep, unsigned int __nocast flags, i ...@@ -2856,7 +2864,10 @@ void *kmem_cache_alloc_node(kmem_cache_t *cachep, unsigned int __nocast flags, i
cache_alloc_debugcheck_before(cachep, flags); cache_alloc_debugcheck_before(cachep, flags);
local_irq_save(save_flags); local_irq_save(save_flags);
ptr = __cache_alloc_node(cachep, flags, nodeid); if (nodeid == numa_node_id())
ptr = ____cache_alloc(cachep, flags);
else
ptr = __cache_alloc_node(cachep, flags, nodeid);
local_irq_restore(save_flags); local_irq_restore(save_flags);
ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, __builtin_return_address(0)); ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, __builtin_return_address(0));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment