Skip to content

Commit

Permalink
mm, slab: move kfence_shutdown_cache() outside slab_mutex
Browse files Browse the repository at this point in the history
kfence_shutdown_cache() is called under slab_mutex when the cache is
destroyed synchronously, and outside slab_mutex during the delayed
destruction of SLAB_TYPESAFE_BY_RCU caches.

It seems it should always be safe to call it outside of slab_mutex so we
can just move the call to kmem_cache_release(), which is called outside.

Reviewed-by: Jann Horn <jannh@google.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
  • Loading branch information
Vlastimil Babka committed Aug 27, 2024
1 parent 4ec1026 commit f77d0cd
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions mm/slab_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ EXPORT_SYMBOL(kmem_buckets_create);
*/
static void kmem_cache_release(struct kmem_cache *s)
{
kfence_shutdown_cache(s);
if (__is_defined(SLAB_SUPPORTS_SYSFS) && slab_state >= FULL)
sysfs_slab_release(s);
else
Expand Down Expand Up @@ -521,10 +522,8 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work)

rcu_barrier();

list_for_each_entry_safe(s, s2, &to_destroy, list) {
kfence_shutdown_cache(s);
list_for_each_entry_safe(s, s2, &to_destroy, list)
kmem_cache_release(s);
}
}

void slab_kmem_cache_release(struct kmem_cache *s)
Expand Down Expand Up @@ -563,9 +562,6 @@ void kmem_cache_destroy(struct kmem_cache *s)

list_del(&s->list);

if (!err && !rcu_set)
kfence_shutdown_cache(s);

mutex_unlock(&slab_mutex);
cpus_read_unlock();

Expand Down

0 comments on commit f77d0cd

Please sign in to comment.