Skip to content

Commit b45bc2e

Browse files
committed
Merge branch 'slab/for-6.3/fixes' into slab/for-linus
Two fixes for SLAB and SLUB - Make it possible to use kmem_cache_alloc_bulk() early in boot when interrupts are not yet enabled, as code doing that start to appear via the maple tree (by Thomas Gleixner). - Fix debugfs-related memory leak (by Greg Kroah-Hartman).
2 parents 0028517 + f545154 commit b45bc2e

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

mm/slab.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3473,14 +3473,15 @@ cache_alloc_debugcheck_after_bulk(struct kmem_cache *s, gfp_t flags,
34733473
int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
34743474
void **p)
34753475
{
3476-
size_t i;
34773476
struct obj_cgroup *objcg = NULL;
3477+
unsigned long irqflags;
3478+
size_t i;
34783479

34793480
s = slab_pre_alloc_hook(s, NULL, &objcg, size, flags);
34803481
if (!s)
34813482
return 0;
34823483

3483-
local_irq_disable();
3484+
local_irq_save(irqflags);
34843485
for (i = 0; i < size; i++) {
34853486
void *objp = kfence_alloc(s, s->object_size, flags) ?:
34863487
__do_cache_alloc(s, flags, NUMA_NO_NODE);
@@ -3489,7 +3490,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
34893490
goto error;
34903491
p[i] = objp;
34913492
}
3492-
local_irq_enable();
3493+
local_irq_restore(irqflags);
34933494

34943495
cache_alloc_debugcheck_after_bulk(s, flags, size, p, _RET_IP_);
34953496

@@ -3502,7 +3503,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
35023503
/* FIXME: Trace call missing. Christoph would like a bulk variant */
35033504
return size;
35043505
error:
3505-
local_irq_enable();
3506+
local_irq_restore(irqflags);
35063507
cache_alloc_debugcheck_after_bulk(s, flags, i, p, _RET_IP_);
35073508
slab_post_alloc_hook(s, objcg, flags, i, p, false, s->object_size);
35083509
kmem_cache_free_bulk(s, i, p);
@@ -3604,8 +3605,9 @@ EXPORT_SYMBOL(kmem_cache_free);
36043605

36053606
void kmem_cache_free_bulk(struct kmem_cache *orig_s, size_t size, void **p)
36063607
{
3608+
unsigned long flags;
36073609

3608-
local_irq_disable();
3610+
local_irq_save(flags);
36093611
for (int i = 0; i < size; i++) {
36103612
void *objp = p[i];
36113613
struct kmem_cache *s;
@@ -3615,9 +3617,9 @@ void kmem_cache_free_bulk(struct kmem_cache *orig_s, size_t size, void **p)
36153617

36163618
/* called via kfree_bulk */
36173619
if (!folio_test_slab(folio)) {
3618-
local_irq_enable();
3620+
local_irq_restore(flags);
36193621
free_large_kmalloc(folio, objp);
3620-
local_irq_disable();
3622+
local_irq_save(flags);
36213623
continue;
36223624
}
36233625
s = folio_slab(folio)->slab_cache;
@@ -3634,7 +3636,7 @@ void kmem_cache_free_bulk(struct kmem_cache *orig_s, size_t size, void **p)
36343636

36353637
__cache_free(s, objp, _RET_IP_);
36363638
}
3637-
local_irq_enable();
3639+
local_irq_restore(flags);
36383640

36393641
/* FIXME: add tracing */
36403642
}

mm/slub.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3913,6 +3913,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
39133913
size_t size, void **p, struct obj_cgroup *objcg)
39143914
{
39153915
struct kmem_cache_cpu *c;
3916+
unsigned long irqflags;
39163917
int i;
39173918

39183919
/*
@@ -3921,7 +3922,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
39213922
* handlers invoking normal fastpath.
39223923
*/
39233924
c = slub_get_cpu_ptr(s->cpu_slab);
3924-
local_lock_irq(&s->cpu_slab->lock);
3925+
local_lock_irqsave(&s->cpu_slab->lock, irqflags);
39253926

39263927
for (i = 0; i < size; i++) {
39273928
void *object = kfence_alloc(s, s->object_size, flags);
@@ -3942,7 +3943,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
39423943
*/
39433944
c->tid = next_tid(c->tid);
39443945

3945-
local_unlock_irq(&s->cpu_slab->lock);
3946+
local_unlock_irqrestore(&s->cpu_slab->lock, irqflags);
39463947

39473948
/*
39483949
* Invoking slow path likely have side-effect
@@ -3956,7 +3957,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
39563957
c = this_cpu_ptr(s->cpu_slab);
39573958
maybe_wipe_obj_freeptr(s, p[i]);
39583959

3959-
local_lock_irq(&s->cpu_slab->lock);
3960+
local_lock_irqsave(&s->cpu_slab->lock, irqflags);
39603961

39613962
continue; /* goto for-loop */
39623963
}
@@ -3965,7 +3966,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
39653966
maybe_wipe_obj_freeptr(s, p[i]);
39663967
}
39673968
c->tid = next_tid(c->tid);
3968-
local_unlock_irq(&s->cpu_slab->lock);
3969+
local_unlock_irqrestore(&s->cpu_slab->lock, irqflags);
39693970
slub_put_cpu_ptr(s->cpu_slab);
39703971

39713972
return i;
@@ -6449,7 +6450,7 @@ static void debugfs_slab_add(struct kmem_cache *s)
64496450

64506451
void debugfs_slab_release(struct kmem_cache *s)
64516452
{
6452-
debugfs_remove_recursive(debugfs_lookup(s->name, slab_debugfs_root));
6453+
debugfs_lookup_and_remove(s->name, slab_debugfs_root);
64536454
}
64546455

64556456
static int __init slab_debugfs_init(void)

0 commit comments

Comments
 (0)