Skip to content

Commit f77d0cd

Browse files
committed
mm, slab: move kfence_shutdown_cache() outside slab_mutex
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 <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 4ec1026 commit f77d0cd

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

mm/slab_common.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ EXPORT_SYMBOL(kmem_buckets_create);
492492
*/
493493
static void kmem_cache_release(struct kmem_cache *s)
494494
{
495+
kfence_shutdown_cache(s);
495496
if (__is_defined(SLAB_SUPPORTS_SYSFS) && slab_state >= FULL)
496497
sysfs_slab_release(s);
497498
else
@@ -521,10 +522,8 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work)
521522

522523
rcu_barrier();
523524

524-
list_for_each_entry_safe(s, s2, &to_destroy, list) {
525-
kfence_shutdown_cache(s);
525+
list_for_each_entry_safe(s, s2, &to_destroy, list)
526526
kmem_cache_release(s);
527-
}
528527
}
529528

530529
void slab_kmem_cache_release(struct kmem_cache *s)
@@ -563,9 +562,6 @@ void kmem_cache_destroy(struct kmem_cache *s)
563562

564563
list_del(&s->list);
565564

566-
if (!err && !rcu_set)
567-
kfence_shutdown_cache(s);
568-
569565
mutex_unlock(&slab_mutex);
570566
cpus_read_unlock();
571567

0 commit comments

Comments
 (0)