[patch] slab: Fix a cpu hotplug race condition while tuning slab cpu caches



Fix a cpu hotplug race condition while tuning slab cpu caches.

CPU online (cpu_up) and tuning slab caches (do_tune_cpucache)
can race and can lead to a situation where we do not have an
arraycache allocated for a newly onlined cpu.

The race can be explained as follows:

cpu_online_map 00000111
cpu_up(3)
cpuup_callback CPU_UP_PREPARE:
mutex_lock(&cache_chain_mutex);
...
allocate_array_cache for cpu 3
...
mutex_unlock(&cache_chain_mutex);
... slabinfo_write
... mutex_lock(&cache_chain_mutex);
... do_tune_cpucache
... allocate new arraycache for cpu0,1,2, NULL rest
... ...
mutex_lock(&cpu_bitmask_lock); ...
cpu_online_map 00001111
mutex_unlock(&cpu_bitmask_lock); ...
on_each_cpu swap the new array_cache with old
^^^^
CPU 3 gets assigned with a NULL array cache

Hence, when do_ccupdate_local is run on CPU 3, CPU 3 gets a NULL array_cache,
and caused badness thereon.

So don't allow cpus to come and go while in do_tune_cpucache.
The other code path of do_tune_cpucache through kmem_cache_create
is already protected through lock_cpu_hotplug.

Signed-off-by: Alok N Kataria <alokk@xxxxxxxxxxxxxx>
Signed-off-by: Ravikiran Thirumalai <kiran@xxxxxxxxxxxx>
Signed-off-by: Shai Fultheim <shai@xxxxxxxxxxxx>

Index: linux-2.6.19-rc1slab/mm/slab.c
===================================================================
--- linux-2.6.19-rc1slab.orig/mm/slab.c 2006-10-13 12:35:02.578841000 -0700
+++ linux-2.6.19-rc1slab/mm/slab.c 2006-10-13 12:35:46.848841000 -0700
@@ -4072,6 +4072,7 @@ ssize_t slabinfo_write(struct file *file
return -EINVAL;

/* Find the cache in the chain of caches. */
+ lock_cpu_hotplug();
mutex_lock(&cache_chain_mutex);
res = -EINVAL;
list_for_each_entry(cachep, &cache_chain, next) {
@@ -4087,6 +4088,7 @@ ssize_t slabinfo_write(struct file *file
}
}
mutex_unlock(&cache_chain_mutex);
+ unlock_cpu_hotplug();
if (res >= 0)
res = count;
return res;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: [patch] slab: Fix a cpu hotplug race condition while tuning slab cpu caches
    ... CPU online and tuning slab caches ... res = -EINVAL; ...
    (Linux-Kernel)
  • Re: PGR 3 Question and observation
    ... > When you are in a race the CPU cars will always smack into you causing you ... > find it hard to believe that a race driver would willing smash into you at ... > high speeds to gain an advantage for not only would you be in trouble but at ... to be hit be a CPU driver who seems to be just following his line. ...
    (alt.games.video.xbox)
  • Re: [RFC patch 00/15] Tracer Timestamping
    ... read hw cnt low ... we therefore increment the high bits twice in the given race. ... Either you do the _same_ incrementation twice effectively writing ... If the low part is a per CPU value then the high part has to be a per ...
    (Linux-Kernel)
  • Re: [PATCH] Fix signal race during process exit
    ... timer-generated signals aren't very common. ... If these two functions are running on different CPUs then the race is still ... different CPU can run release_task, ... It seems silly to be trying to deliver timer signals to processes which are ...
    (Linux-Kernel)
  • Re: [RFC patch 00/15] Tracer Timestamping
    ... read hw cnt low ... we therefore increment the high bits twice in the given race. ... If this is a per-CPU counter then you just need a per-CPU version of ... CPU value too. ...
    (Linux-Kernel)