Commit b45bc2e0 authored by Vlastimil Babka's avatar Vlastimil Babka

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).
parents 00285177 f5451547
...@@ -3473,14 +3473,15 @@ cache_alloc_debugcheck_after_bulk(struct kmem_cache *s, gfp_t flags, ...@@ -3473,14 +3473,15 @@ cache_alloc_debugcheck_after_bulk(struct kmem_cache *s, gfp_t flags,
int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
void **p) void **p)
{ {
size_t i;
struct obj_cgroup *objcg = NULL; struct obj_cgroup *objcg = NULL;
unsigned long irqflags;
size_t i;
s = slab_pre_alloc_hook(s, NULL, &objcg, size, flags); s = slab_pre_alloc_hook(s, NULL, &objcg, size, flags);
if (!s) if (!s)
return 0; return 0;
local_irq_disable(); local_irq_save(irqflags);
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
void *objp = kfence_alloc(s, s->object_size, flags) ?: void *objp = kfence_alloc(s, s->object_size, flags) ?:
__do_cache_alloc(s, flags, NUMA_NO_NODE); __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, ...@@ -3489,7 +3490,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
goto error; goto error;
p[i] = objp; p[i] = objp;
} }
local_irq_enable(); local_irq_restore(irqflags);
cache_alloc_debugcheck_after_bulk(s, flags, size, p, _RET_IP_); cache_alloc_debugcheck_after_bulk(s, flags, size, p, _RET_IP_);
...@@ -3502,7 +3503,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, ...@@ -3502,7 +3503,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
/* FIXME: Trace call missing. Christoph would like a bulk variant */ /* FIXME: Trace call missing. Christoph would like a bulk variant */
return size; return size;
error: error:
local_irq_enable(); local_irq_restore(irqflags);
cache_alloc_debugcheck_after_bulk(s, flags, i, p, _RET_IP_); cache_alloc_debugcheck_after_bulk(s, flags, i, p, _RET_IP_);
slab_post_alloc_hook(s, objcg, flags, i, p, false, s->object_size); slab_post_alloc_hook(s, objcg, flags, i, p, false, s->object_size);
kmem_cache_free_bulk(s, i, p); kmem_cache_free_bulk(s, i, p);
...@@ -3604,8 +3605,9 @@ EXPORT_SYMBOL(kmem_cache_free); ...@@ -3604,8 +3605,9 @@ EXPORT_SYMBOL(kmem_cache_free);
void kmem_cache_free_bulk(struct kmem_cache *orig_s, size_t size, void **p) void kmem_cache_free_bulk(struct kmem_cache *orig_s, size_t size, void **p)
{ {
unsigned long flags;
local_irq_disable(); local_irq_save(flags);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
void *objp = p[i]; void *objp = p[i];
struct kmem_cache *s; struct kmem_cache *s;
...@@ -3615,9 +3617,9 @@ void kmem_cache_free_bulk(struct kmem_cache *orig_s, size_t size, void **p) ...@@ -3615,9 +3617,9 @@ void kmem_cache_free_bulk(struct kmem_cache *orig_s, size_t size, void **p)
/* called via kfree_bulk */ /* called via kfree_bulk */
if (!folio_test_slab(folio)) { if (!folio_test_slab(folio)) {
local_irq_enable(); local_irq_restore(flags);
free_large_kmalloc(folio, objp); free_large_kmalloc(folio, objp);
local_irq_disable(); local_irq_save(flags);
continue; continue;
} }
s = folio_slab(folio)->slab_cache; 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) ...@@ -3634,7 +3636,7 @@ void kmem_cache_free_bulk(struct kmem_cache *orig_s, size_t size, void **p)
__cache_free(s, objp, _RET_IP_); __cache_free(s, objp, _RET_IP_);
} }
local_irq_enable(); local_irq_restore(flags);
/* FIXME: add tracing */ /* FIXME: add tracing */
} }
......
...@@ -3913,6 +3913,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, ...@@ -3913,6 +3913,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
size_t size, void **p, struct obj_cgroup *objcg) size_t size, void **p, struct obj_cgroup *objcg)
{ {
struct kmem_cache_cpu *c; struct kmem_cache_cpu *c;
unsigned long irqflags;
int i; int i;
/* /*
...@@ -3921,7 +3922,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, ...@@ -3921,7 +3922,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
* handlers invoking normal fastpath. * handlers invoking normal fastpath.
*/ */
c = slub_get_cpu_ptr(s->cpu_slab); c = slub_get_cpu_ptr(s->cpu_slab);
local_lock_irq(&s->cpu_slab->lock); local_lock_irqsave(&s->cpu_slab->lock, irqflags);
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
void *object = kfence_alloc(s, s->object_size, flags); 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, ...@@ -3942,7 +3943,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
*/ */
c->tid = next_tid(c->tid); c->tid = next_tid(c->tid);
local_unlock_irq(&s->cpu_slab->lock); local_unlock_irqrestore(&s->cpu_slab->lock, irqflags);
/* /*
* Invoking slow path likely have side-effect * 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, ...@@ -3956,7 +3957,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
c = this_cpu_ptr(s->cpu_slab); c = this_cpu_ptr(s->cpu_slab);
maybe_wipe_obj_freeptr(s, p[i]); maybe_wipe_obj_freeptr(s, p[i]);
local_lock_irq(&s->cpu_slab->lock); local_lock_irqsave(&s->cpu_slab->lock, irqflags);
continue; /* goto for-loop */ continue; /* goto for-loop */
} }
...@@ -3965,7 +3966,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, ...@@ -3965,7 +3966,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
maybe_wipe_obj_freeptr(s, p[i]); maybe_wipe_obj_freeptr(s, p[i]);
} }
c->tid = next_tid(c->tid); c->tid = next_tid(c->tid);
local_unlock_irq(&s->cpu_slab->lock); local_unlock_irqrestore(&s->cpu_slab->lock, irqflags);
slub_put_cpu_ptr(s->cpu_slab); slub_put_cpu_ptr(s->cpu_slab);
return i; return i;
...@@ -6449,7 +6450,7 @@ static void debugfs_slab_add(struct kmem_cache *s) ...@@ -6449,7 +6450,7 @@ static void debugfs_slab_add(struct kmem_cache *s)
void debugfs_slab_release(struct kmem_cache *s) void debugfs_slab_release(struct kmem_cache *s)
{ {
debugfs_remove_recursive(debugfs_lookup(s->name, slab_debugfs_root)); debugfs_lookup_and_remove(s->name, slab_debugfs_root);
} }
static int __init slab_debugfs_init(void) static int __init slab_debugfs_init(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment