Skip to content

Commit c4cf678

Browse files
Sebastian Andrzej Siewiortehcaster
authored andcommitted
mm/slub: Move the stackdepot related allocation out of IRQ-off section.
The set_track() invocation in free_debug_processing() is invoked with acquired slab_lock(). The lock disables interrupts on PREEMPT_RT and this forbids to allocate memory which is done in stack_depot_save(). Split set_track() into two parts: set_track_prepare() which allocate memory and set_track_update() which only performs the assignment of the trace data structure. Use set_track_prepare() before disabling interrupts. [ [email protected]: make set_track() call set_track_update() instead of open-coded assignments ] Fixes: 5cf909c ("mm/slub: use stackdepot to save stack trace in objects") Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Reviewed-by: Hyeonggon Yoo <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b13bacc commit c4cf678

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

mm/slub.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -726,25 +726,48 @@ static struct track *get_track(struct kmem_cache *s, void *object,
726726
return kasan_reset_tag(p + alloc);
727727
}
728728

729-
static void noinline set_track(struct kmem_cache *s, void *object,
730-
enum track_item alloc, unsigned long addr)
731-
{
732-
struct track *p = get_track(s, object, alloc);
733-
734729
#ifdef CONFIG_STACKDEPOT
730+
static noinline depot_stack_handle_t set_track_prepare(void)
731+
{
732+
depot_stack_handle_t handle;
735733
unsigned long entries[TRACK_ADDRS_COUNT];
736734
unsigned int nr_entries;
737735

738736
nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 3);
739-
p->handle = stack_depot_save(entries, nr_entries, GFP_NOWAIT);
737+
handle = stack_depot_save(entries, nr_entries, GFP_NOWAIT);
738+
739+
return handle;
740+
}
741+
#else
742+
static inline depot_stack_handle_t set_track_prepare(void)
743+
{
744+
return 0;
745+
}
740746
#endif
741747

748+
static void set_track_update(struct kmem_cache *s, void *object,
749+
enum track_item alloc, unsigned long addr,
750+
depot_stack_handle_t handle)
751+
{
752+
struct track *p = get_track(s, object, alloc);
753+
754+
#ifdef CONFIG_STACKDEPOT
755+
p->handle = handle;
756+
#endif
742757
p->addr = addr;
743758
p->cpu = smp_processor_id();
744759
p->pid = current->pid;
745760
p->when = jiffies;
746761
}
747762

763+
static __always_inline void set_track(struct kmem_cache *s, void *object,
764+
enum track_item alloc, unsigned long addr)
765+
{
766+
depot_stack_handle_t handle = set_track_prepare();
767+
768+
set_track_update(s, object, alloc, addr, handle);
769+
}
770+
748771
static void init_tracking(struct kmem_cache *s, void *object)
749772
{
750773
struct track *p;
@@ -1373,6 +1396,10 @@ static noinline int free_debug_processing(
13731396
int cnt = 0;
13741397
unsigned long flags, flags2;
13751398
int ret = 0;
1399+
depot_stack_handle_t handle = 0;
1400+
1401+
if (s->flags & SLAB_STORE_USER)
1402+
handle = set_track_prepare();
13761403

13771404
spin_lock_irqsave(&n->list_lock, flags);
13781405
slab_lock(slab, &flags2);
@@ -1391,7 +1418,7 @@ static noinline int free_debug_processing(
13911418
}
13921419

13931420
if (s->flags & SLAB_STORE_USER)
1394-
set_track(s, object, TRACK_FREE, addr);
1421+
set_track_update(s, object, TRACK_FREE, addr, handle);
13951422
trace(s, slab, object, 0);
13961423
/* Freepointer not overwritten by init_object(), SLAB_POISON moved it */
13971424
init_object(s, object, SLUB_RED_INACTIVE);

0 commit comments

Comments
 (0)