Skip to content

Commit ae14c63

Browse files
committed
Revert "mm/slub: use stackdepot to save stack trace in objects"
This reverts commit 7886914. It's not clear why, but it causes unexplained problems in entirely unrelated xfs code. The most likely explanation is some slab corruption, possibly triggered due to CONFIG_SLUB_DEBUG_ON. See [1]. It ends up having a few other problems too, like build errors on arch/arc, and Geert reporting it using much more memory on m68k [3] (it probably does so elsewhere too, but it is probably just more noticeable on m68k). The architecture issues (both build and memory use) are likely just because this change effectively force-enabled STACKDEPOT (along with a very bad default value for the stackdepot hash size). But together with the xfs issue, this all smells like "this commit was not ready" to me. Link: https://lore.kernel.org/linux-xfs/[email protected]/ [1] Link: https://lore.kernel.org/lkml/[email protected]/ [2] Link: https://lore.kernel.org/lkml/CAMuHMdW=eoVzM1Re5FVoEN87nKfiLmM2+Ah7eNu2KXEhCvbZyA@mail.gmail.com/ [3] Reported-by: Christoph Hellwig <[email protected]> Reported-by: kernel test robot <[email protected]> Reported-by: Geert Uytterhoeven <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Randy Dunlap <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5d766d5 commit ae14c63

File tree

2 files changed

+30
-50
lines changed

2 files changed

+30
-50
lines changed

init/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,6 @@ config SLUB_DEBUG
18471847
default y
18481848
bool "Enable SLUB debugging support" if EXPERT
18491849
depends on SLUB && SYSFS
1850-
select STACKDEPOT if STACKTRACE_SUPPORT
18511850
help
18521851
SLUB has extensive debug support features. Disabling these can
18531852
result in significant savings in code size. This also disables

mm/slub.c

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <linux/cpuset.h>
2727
#include <linux/mempolicy.h>
2828
#include <linux/ctype.h>
29-
#include <linux/stackdepot.h>
3029
#include <linux/debugobjects.h>
3130
#include <linux/kallsyms.h>
3231
#include <linux/kfence.h>
@@ -207,8 +206,8 @@ static inline bool kmem_cache_has_cpu_partial(struct kmem_cache *s)
207206
#define TRACK_ADDRS_COUNT 16
208207
struct track {
209208
unsigned long addr; /* Called from address */
210-
#ifdef CONFIG_STACKDEPOT
211-
depot_stack_handle_t handle;
209+
#ifdef CONFIG_STACKTRACE
210+
unsigned long addrs[TRACK_ADDRS_COUNT]; /* Called from address */
212211
#endif
213212
int cpu; /* Was running on cpu */
214213
int pid; /* Pid context */
@@ -612,27 +611,22 @@ static struct track *get_track(struct kmem_cache *s, void *object,
612611
return kasan_reset_tag(p + alloc);
613612
}
614613

615-
#ifdef CONFIG_STACKDEPOT
616-
static depot_stack_handle_t save_stack_depot_trace(gfp_t flags)
617-
{
618-
unsigned long entries[TRACK_ADDRS_COUNT];
619-
depot_stack_handle_t handle;
620-
unsigned int nr_entries;
621-
622-
nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 4);
623-
handle = stack_depot_save(entries, nr_entries, flags);
624-
return handle;
625-
}
626-
#endif
627-
628614
static void set_track(struct kmem_cache *s, void *object,
629615
enum track_item alloc, unsigned long addr)
630616
{
631617
struct track *p = get_track(s, object, alloc);
632618

633619
if (addr) {
634-
#ifdef CONFIG_STACKDEPOT
635-
p->handle = save_stack_depot_trace(GFP_NOWAIT);
620+
#ifdef CONFIG_STACKTRACE
621+
unsigned int nr_entries;
622+
623+
metadata_access_enable();
624+
nr_entries = stack_trace_save(kasan_reset_tag(p->addrs),
625+
TRACK_ADDRS_COUNT, 3);
626+
metadata_access_disable();
627+
628+
if (nr_entries < TRACK_ADDRS_COUNT)
629+
p->addrs[nr_entries] = 0;
636630
#endif
637631
p->addr = addr;
638632
p->cpu = smp_processor_id();
@@ -659,19 +653,14 @@ static void print_track(const char *s, struct track *t, unsigned long pr_time)
659653

660654
pr_err("%s in %pS age=%lu cpu=%u pid=%d\n",
661655
s, (void *)t->addr, pr_time - t->when, t->cpu, t->pid);
662-
#ifdef CONFIG_STACKDEPOT
656+
#ifdef CONFIG_STACKTRACE
663657
{
664-
depot_stack_handle_t handle;
665-
unsigned long *entries;
666-
unsigned int nr_entries;
667-
668-
handle = READ_ONCE(t->handle);
669-
if (!handle) {
670-
pr_err("object allocation/free stack trace missing\n");
671-
} else {
672-
nr_entries = stack_depot_fetch(handle, &entries);
673-
stack_trace_print(entries, nr_entries, 0);
674-
}
658+
int i;
659+
for (i = 0; i < TRACK_ADDRS_COUNT; i++)
660+
if (t->addrs[i])
661+
pr_err("\t%pS\n", (void *)t->addrs[i]);
662+
else
663+
break;
675664
}
676665
#endif
677666
}
@@ -4045,26 +4034,18 @@ void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
40454034
objp = fixup_red_left(s, objp);
40464035
trackp = get_track(s, objp, TRACK_ALLOC);
40474036
kpp->kp_ret = (void *)trackp->addr;
4048-
#ifdef CONFIG_STACKDEPOT
4049-
{
4050-
depot_stack_handle_t handle;
4051-
unsigned long *entries;
4052-
unsigned int nr_entries;
4053-
4054-
handle = READ_ONCE(trackp->handle);
4055-
if (handle) {
4056-
nr_entries = stack_depot_fetch(handle, &entries);
4057-
for (i = 0; i < KS_ADDRS_COUNT && i < nr_entries; i++)
4058-
kpp->kp_stack[i] = (void *)entries[i];
4059-
}
4037+
#ifdef CONFIG_STACKTRACE
4038+
for (i = 0; i < KS_ADDRS_COUNT && i < TRACK_ADDRS_COUNT; i++) {
4039+
kpp->kp_stack[i] = (void *)trackp->addrs[i];
4040+
if (!kpp->kp_stack[i])
4041+
break;
4042+
}
40604043

4061-
trackp = get_track(s, objp, TRACK_FREE);
4062-
handle = READ_ONCE(trackp->handle);
4063-
if (handle) {
4064-
nr_entries = stack_depot_fetch(handle, &entries);
4065-
for (i = 0; i < KS_ADDRS_COUNT && i < nr_entries; i++)
4066-
kpp->kp_free_stack[i] = (void *)entries[i];
4067-
}
4044+
trackp = get_track(s, objp, TRACK_FREE);
4045+
for (i = 0; i < KS_ADDRS_COUNT && i < TRACK_ADDRS_COUNT; i++) {
4046+
kpp->kp_free_stack[i] = (void *)trackp->addrs[i];
4047+
if (!kpp->kp_free_stack[i])
4048+
break;
40684049
}
40694050
#endif
40704051
#endif

0 commit comments

Comments
 (0)