Skip to content

Commit

Permalink
fix RCU-callback-after-kmem_cache_destroy problem in sl[aou]b
Browse files Browse the repository at this point in the history
Jesper noted that kmem_cache_destroy() invokes synchronize_rcu() rather than
rcu_barrier() in the SLAB_DESTROY_BY_RCU case, which could result in RCU
callbacks accessing a kmem_cache after it had been destroyed.

Cc: <[email protected]>
Acked-by: Matt Mackall <[email protected]>
Reported-by: Jesper Dangaard Brouer <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
Signed-off-by: Pekka Enberg <[email protected]>
  • Loading branch information
paulmck authored and Pekka Enberg committed Jun 26, 2009
1 parent 28d0325 commit 7ed9f7e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mm/slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -2547,7 +2547,7 @@ void kmem_cache_destroy(struct kmem_cache *cachep)
}

if (unlikely(cachep->flags & SLAB_DESTROY_BY_RCU))
synchronize_rcu();
rcu_barrier();

__kmem_cache_destroy(cachep);
mutex_unlock(&cache_chain_mutex);
Expand Down
2 changes: 2 additions & 0 deletions mm/slob.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ EXPORT_SYMBOL(kmem_cache_create);
void kmem_cache_destroy(struct kmem_cache *c)
{
kmemleak_free(c);
if (c->flags & SLAB_DESTROY_BY_RCU)
rcu_barrier();
slob_free(c, sizeof(struct kmem_cache));
}
EXPORT_SYMBOL(kmem_cache_destroy);
Expand Down
2 changes: 2 additions & 0 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,8 @@ static inline int kmem_cache_close(struct kmem_cache *s)
*/
void kmem_cache_destroy(struct kmem_cache *s)
{
if (s->flags & SLAB_DESTROY_BY_RCU)
rcu_barrier();
down_write(&slub_lock);
s->refcount--;
if (!s->refcount) {
Expand Down

0 comments on commit 7ed9f7e

Please sign in to comment.