Skip to contentSkip to conversation

stackdepot: store compressed frames in stack records

PATCH New Matt Fleming 2 participants 14 messages Nov 13 – Nov 14

Subsystems (13)
lore
Share & tools
lore
#0 lore raw

v3 cover stackdepot: store compressed frames in stack records

From: Matt Fleming <[email protected]>

Hi,

Cloudflare runs KASAN on pre-production servers, and on some of them stack depot keeps running out of pools even with stack_depot_max_pools raised to 65,536. Once the depot is full, new persistent traces get no handle and later KASAN reports lose the allocation and free history.

v2 of this series [1] tackled that with a trie that shares common frame prefixes. Marco asked how much of the saving came from compressed frames alone [2]. It turns out we can get a decent saving with just frame compression and none of the trie complexity.

When every frame of a persistent record can be compressed with the arch hooks, the record stores 32-bit frames instead of unsigned longs. Evictable records are always allocated at maximum size, so they stay uncompressed.

On our production KASAN hosts this reduced stack depot pools per 1000 stacks by 41.5% on x86-64 and 27.1% on arm64. arm64 saves less because we run a lot of BPF programs, and their code lives outside the +/-2 GiB range around _text that can be compressed.

Compressed records aren't contiguous unsigned long arrays, so callers can no longer borrow stack depot's storage. Patches 1-7 move every stack_depot_fetch() user to stack_depot_fetch_into() or the print helpers and then remove stack_depot_fetch(). Patch 8 adds the arch hooks, patch 9 stores compressed frames, and patch 10 teaches the GDB helper to decode them.

Changes in v3:
- Drop the trie backend, the stackdepot.trie_enabled boot parameter and the trie KUnit tests.
- Drop STACK_DEPOT_FLAG_COUNTABLE. page_owner reads traces with stack_depot_fetch_into() instead.
- Remove stack_depot_fetch() now that it has no users.
- stack_depot_print() and stack_depot_snprint() decompress one frame at a time instead of copying 16-frame chunks.
- Store compressed frames directly in hash records, using the u16 size and u16 flags header layout from v2's COUNTABLE patch.
- The GDB helper decodes compressed frames instead of rejecting trie handles.
- v2's patch 1 landed as 8f56ea8e0706 ("stackdepot: stop preallocating after the final pool").

Thanks to Caleb, who wrote v1 and v2.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/r/CANpmjNMP=NdD8ZE9rPwikUBcLwc8V=J648X05YGPn41yAZ5hmw@mail.gmail.com/

Caleb Kan (6):
stackdepot: add caller-owned stack trace fetching mm/kmemleak: use stack_depot_fetch_into() for leak reports
kmsan: use stack_depot_fetch_into() for origin reports mm/slub: use stack_depot_fetch_into() for owner tracking drm/locking: print deadlock backtraces with stack_depot_snprint()
stackdepot: add architecture hooks for compact frame storage

Matt Fleming (4):
mm/page_owner: Read stack traces with stack_depot_fetch_into()
stackdepot: Remove stack_depot_fetch()
stackdepot: Store compressed frames in stack records scripts/gdb: Decode compressed stack depot frames

 arch/arm64/include/asm/stackdepot.h |  37 ++++
 arch/um/include/asm/Kbuild          |   1 +
 arch/x86/include/asm/stackdepot.h   |  37 ++++
 drivers/gpu/drm/drm_modeset_lock.c  |   5 +-
 include/asm-generic/Kbuild          |   1 +
 include/asm-generic/stackdepot.h    |  19 ++
 include/linux/stackdepot.h          |  45 +++-
 lib/Kconfig.debug                   |  16 ++
 lib/stackdepot.c                    | 164 ++++++++++++---
 lib/tests/Makefile                  |   1 +
 lib/tests/stackdepot_kunit.c        | 312 ++++++++++++++++++++++++++++
 mm/kmemleak.c                       |   4 +-
 mm/kmsan/kmsan_test.c               |   4 +-
 mm/kmsan/report.c                   |  28 +--
 mm/page_owner.c                     |   8 +-
 mm/slub.c                           |  12 +-
 scripts/gdb/linux/constants.py.in   |   5 +
 scripts/gdb/linux/stackdepot.py     |  23 +-
 18 files changed, 650 insertions(+), 72 deletions(-)
 create mode 100644 arch/arm64/include/asm/stackdepot.h
 create mode 100644 arch/x86/include/asm/stackdepot.h
 create mode 100644 include/asm-generic/stackdepot.h
 create mode 100644 lib/tests/stackdepot_kunit.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/10 stackdepot: add caller-owned stack trace fetching

From: Caleb Kan <[email protected]>

stack_depot_fetch() returns a pointer to contiguous storage owned by stack depot. That cannot work once a later patch stores compressed frames, so callers need an interface that copies the trace.

Add stack_depot_fetch_into() to copy a complete trace into caller-owned storage. Leave the destination unchanged when it is too small, keep a zero handle as a no-op, and document that callers must keep the handle valid while copying it. Warn and return 0 if a caller passes a NULL buffer or zero capacity for a valid handle.

Unpoison the copied entries before returning them because lib/stackdepot.c is not instrumented by KMSAN. Add built-in KUnit tests for exact and oversized destinations, zero handles, and undersized buffers. Later patches add tests for stack depot internals.

[mfleming: reworded for compressed frames]
---
 include/linux/stackdepot.h   | 36 +++++++++++++++
 lib/Kconfig.debug            | 16 +++++++
 lib/stackdepot.c             | 29 ++++++++++++
 lib/tests/Makefile           |  1 +
 lib/tests/stackdepot_kunit.c | 89 ++++++++++++++++++++++++++++++++++++
 5 files changed, 171 insertions(+)
 create mode 100644 lib/tests/stackdepot_kunit.c
include/linux/stackdepot.h +36 -0
index 2cc21ffcdaf9..734529767c8a 100644
@@ -199,6 +199,42 @@ struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle)
 unsigned int stack_depot_fetch(depot_stack_handle_t handle,
 			       unsigned long **entries);
 
+/**
+ * stack_depot_fetch_into - Fetch a stack trace into caller-owned storage
+ *
+ * @handle:	Stack depot handle
+ * @entries:	Caller-owned buffer to copy the stack trace into
+ * @max_entries:	Number of frames that fit in @entries
+ *
+ * Copies the stored frames into caller-owned @entries. If fewer frames are
+ * stored than @max_entries, only the stored frames are written and their count
+ * is returned. If more frames are stored than @max_entries, the copy is skipped
+ * entirely and 0 is returned.
+ *
+ * Passing a NULL @entries buffer or zero @max_entries for a valid @handle is
+ * invalid. Callers must provide storage for @max_entries frames.
+ *
+ * Callers should size @entries to match the save-side stack depth cap (for
+ * example, %CONFIG_STACKDEPOT_MAX_FRAMES or the local stack_trace_save() limit)
+ * when losing diagnostics on an undersized buffer would be surprising.
+ *
+ * A non-zero invalid @handle, including a post-put handle, may WARN. Its return
+ * value and copied contents are undefined because the record may have been
+ * reused for another stack.
+ *
+ * Callers must ensure @handle remains valid for the duration of this call.
+ * Persistent handles saved without %STACK_DEPOT_FLAG_GET require no extra
+ * reference; handles saved with %STACK_DEPOT_FLAG_GET require a held reference.
+ * Callers must not call stack_depot_put() on persistent handles.
+ * Racing this helper with stack_depot_put() on the same handle is invalid.
+ *
+ * Return: Number of frames copied, 0 if @handle is 0, stack depot is disabled,
+ * or @max_entries is less than the number of stored frames.
+ */
+unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,
+				    unsigned long *entries,
+				    unsigned int max_entries);
+
 /**
  * stack_depot_print - Print a stack trace from stack depot
  *
lib/Kconfig.debug +16 -0
index 2d22638ec13a..861d0caf9391 100644
@@ -2818,6 +2818,22 @@ config RESOURCE_KUNIT_TEST
 
 	  If unsure, say N.
 
+config STACKDEPOT_KUNIT_TEST
+	bool "KUnit test for stack depot" if !KUNIT_ALL_TESTS
+	depends on KUNIT=y && STACKDEPOT
+	depends on STACKDEPOT_MAX_FRAMES >= 3
+	default KUNIT_ALL_TESTS
+	help
+	  Enable this option to test stack depot API behavior at boot.
+	  This test is built in, so KUNIT must also be built in.
+
+	  KUnit tests run during boot and output the results to the debug log
+	  in TAP format (https://testanything.org/). Only useful for kernel
+	  developers running the KUnit test harness, and not intended for
+	  inclusion into a production build.
+
+	  If unsure, say N.
+
 config SYSCTL_KUNIT_TEST
 	tristate "KUnit test for sysctl" if !KUNIT_ALL_TESTS
 	depends on KUNIT
lib/stackdepot.c +29 -0
index 90c52f2e0d3f..556f3ecdcc8f 100644
@@ -785,6 +785,35 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
 }
 EXPORT_SYMBOL_GPL(stack_depot_fetch);
 
+unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,
+				    unsigned long *entries,
+				    unsigned int max_entries)
+{
+	struct stack_record *stack;
+	unsigned int nr_entries;
+
+	if (!handle)
+		return 0;
+	if (stack_depot_disabled)
+		return 0;
+	if (WARN_ON_ONCE(!entries || !max_entries))
+		return 0;
+
+	stack = depot_fetch_stack(handle);
+	if (!stack)
+		return 0;
+	nr_entries = stack->size;
+	if (WARN_ON_ONCE(!nr_entries))
+		return 0;
+	if (nr_entries > max_entries)
+		return 0;
+
+	memcpy(entries, stack->entries, nr_entries * sizeof(*entries));
+	kmsan_unpoison_memory(entries, nr_entries * sizeof(*entries));
+	return nr_entries;
+}
+EXPORT_SYMBOL_GPL(stack_depot_fetch_into);
+
 void stack_depot_put(depot_stack_handle_t handle)
 {
 	struct stack_record *stack;
lib/tests/Makefile +1 -0
index df0537e1b91f..bc6532d88150 100644
@@ -49,6 +49,7 @@ obj-$(CONFIG_RANDSTRUCT_KUNIT_TEST) += randstruct_kunit.o
 obj-$(CONFIG_SCANF_KUNIT_TEST) += scanf_kunit.o
 obj-$(CONFIG_SEQ_BUF_KUNIT_TEST) += seq_buf_kunit.o
 obj-$(CONFIG_SLUB_KUNIT_TEST) += slub_kunit.o
+obj-$(CONFIG_STACKDEPOT_KUNIT_TEST) += stackdepot_kunit.o
 obj-$(CONFIG_TEST_SORT) += test_sort.o
 CFLAGS_stackinit_kunit.o += $(call cc-disable-warning, switch-unreachable)
 obj-$(CONFIG_STACKINIT_KUNIT_TEST) += stackinit_kunit.o
lib/tests/stackdepot_kunit.c new file +89 -0

89 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/10 mm/kmemleak: use stack_depot_fetch_into() for leak reports

In reply to Matt Fleming

From: Caleb Kan <[email protected]>

kmemleak stores allocation backtraces as persistent stack depot handles. With compressed frames, stack_depot_fetch() cannot return a pointer to unsigned long stack-record entries, so leak reports would omit the saved backtrace.

Use stack_depot_fetch_into() with a MAX_TRACE-sized local array before formatting the report. MAX_TRACE matches the save-side limit, so every valid kmemleak trace fits without truncation. Preserve frame order and the existing report format.

[mfleming: reworded for compressed frames]
---
 mm/kmemleak.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/kmemleak.c +2 -2
index 20c0eb41c873..61ff4a10ce11 100644
@@ -378,10 +378,10 @@ static void __print_unreferenced(struct seq_file *seq,
 				 bool hex_dump)
 {
 	int i;
-	unsigned long *entries;
+	unsigned long entries[MAX_TRACE];
 	unsigned int nr_entries;
 
-	nr_entries = stack_depot_fetch(object->trace_handle, &entries);
+	nr_entries = stack_depot_fetch_into(object->trace_handle, entries, ARRAY_SIZE(entries));
 	warn_or_seq_printf(seq, "unreferenced object%s 0x%08lx (size %zu):\n",
 			   __object_type_str(object),
 			   object->pointer, object->size);
Signature · 1 line
2.43.0
#3 lore raw

PATCH v3 3/10 kmsan: use stack_depot_fetch_into() for origin reports

In reply to Matt Fleming

From: Caleb Kan <[email protected]>

KMSAN stores ordinary origin stacks and synthetic alloca and chain origins in stack depot and retains the resulting persistent handles. Once a later patch stores compressed frames, these handles can refer to records whose frames must be decompressed before use, while kmsan_print_origin() still relies on the pointer-returning stack_depot_fetch() API.

Use one KMSAN_STACK_DEPTH array to materialize each origin and chained stack in turn. Preserve the chain's head and next-origin handles before reusing the array for the chained stack. The array covers both the regular save limit and the smaller synthetic records.

Pass the scratch array into a common origin-printing helper. Keep local storage for standalone kmsan_print_origin() calls, but let kmsan_report() reuse its existing stack_entries array after printing the report stack. With x86-64 Clang 19, the regular nested report path uses 752 bytes, below its 768-byte size before this conversion.

lib/stackdepot.c is uninstrumented, so stack_depot_fetch_into() unpoisons the successfully copied range before returning it to KMSAN. Remove the now-redundant explicit unpoisoning of chained entries. Origin depth and use-after-free metadata remain in the handle's extra bits and are unchanged.

Update test_stackdepot_roundtrip() to use caller-owned storage while retaining its frame-count and kmsan_check_memory() checks. This verifies that the copy-out API returns initialized entries to instrumented callers.

[mfleming: reworded for compressed frames]
---
 mm/kmsan/kmsan_test.c |  4 ++--
 mm/kmsan/report.c     | 28 ++++++++++++++++------------
 2 files changed, 18 insertions(+), 14 deletions(-)
mm/kmsan/kmsan_test.c +2 -2
index 31f47cc4dab4..7c04e4b21873 100644
@@ -669,7 +669,7 @@ static void test_long_origin_chain(struct kunit *test)
  */
 static void test_stackdepot_roundtrip(struct kunit *test)
 {
-	unsigned long src_entries[16], *dst_entries;
+	unsigned long src_entries[16], dst_entries[16];
 	unsigned int src_nentries, dst_nentries;
 	EXPECTATION_NO_REPORT(expect);
 	depot_stack_handle_t handle;
@@ -680,7 +680,7 @@ static void test_stackdepot_roundtrip(struct kunit *test)
 		stack_trace_save(src_entries, ARRAY_SIZE(src_entries), 1);
 	handle = stack_depot_save(src_entries, src_nentries, GFP_KERNEL);
 	stack_depot_print(handle);
-	dst_nentries = stack_depot_fetch(handle, &dst_entries);
+	dst_nentries = stack_depot_fetch_into(handle, dst_entries, ARRAY_SIZE(dst_entries));
 	KUNIT_EXPECT_TRUE(test, src_nentries == dst_nentries);
 
 	kmsan_check_memory((void *)dst_entries,
mm/kmsan/report.c +16 -12
index d6853ce08954..0770658ba932 100644
@@ -83,9 +83,9 @@ static char *pretty_descr(char *descr)
 	return report_local_descr;
 }
 
-void kmsan_print_origin(depot_stack_handle_t origin)
+static void kmsan_print_origin_with_buf(depot_stack_handle_t origin,
+					unsigned long *entries)
 {
-	unsigned long *entries = NULL, *chained_entries = NULL;
 	unsigned int nr_entries, chained_nr_entries, skipnr;
 	void *pc1 = NULL, *pc2 = NULL;
 	depot_stack_handle_t head;
@@ -97,7 +97,8 @@ void kmsan_print_origin(depot_stack_handle_t origin)
 		return;
 
 	while (true) {
-		nr_entries = stack_depot_fetch(origin, &entries);
+		nr_entries =
+			stack_depot_fetch_into(origin, entries, KMSAN_STACK_DEPTH);
 		depth = kmsan_depth_from_eb(stack_depot_get_extra_bits(origin));
 		magic = nr_entries ? entries[0] : 0;
 		if ((nr_entries == 4) && (magic == KMSAN_ALLOCA_MAGIC_ORIGIN)) {
@@ -123,14 +124,10 @@ void kmsan_print_origin(depot_stack_handle_t origin)
 			origin = entries[2];
 			pr_err("Uninit was stored to memory at:\n");
 			chained_nr_entries =
-				stack_depot_fetch(head, &chained_entries);
-			kmsan_internal_unpoison_memory(
-				chained_entries,
-				chained_nr_entries * sizeof(*chained_entries),
-				/*checked*/ false);
-			skipnr = get_stack_skipnr(chained_entries,
-						  chained_nr_entries);
-			stack_trace_print(chained_entries + skipnr,
+				stack_depot_fetch_into(head, entries,
+						       KMSAN_STACK_DEPTH);
+			skipnr = get_stack_skipnr(entries, chained_nr_entries);
+			stack_trace_print(entries + skipnr,
 					  chained_nr_entries - skipnr, 0);
 			pr_err("\n");
 			continue;
@@ -147,6 +144,13 @@ void kmsan_print_origin(depot_stack_handle_t origin)
 	}
 }
 
+void kmsan_print_origin(depot_stack_handle_t origin)
+{
+	unsigned long entries[KMSAN_STACK_DEPTH];
+
+	kmsan_print_origin_with_buf(origin, entries);
+}
+
 void kmsan_report(depot_stack_handle_t origin, void *address, int size,
 		  int off_first, int off_last, const void __user *user_addr,
 		  enum kmsan_bug_reason reason)
@@ -193,7 +197,7 @@ void kmsan_report(depot_stack_handle_t origin, void *address, int size,
 			  0);
 	pr_err("\n");
 
-	kmsan_print_origin(origin);
+	kmsan_print_origin_with_buf(origin, stack_entries);
 
 	if (size) {
 		pr_err("\n");
Signature · 1 line
2.43.0
#4 lore raw

PATCH v3 4/10 mm/slub: use stack_depot_fetch_into() for owner tracking

In reply to Matt Fleming

From: Caleb Kan <[email protected]>

SLUB owner tracking stores allocation and free stacks as persistent stack depot handles. Compressed frames must be decompressed before use, so __kmem_obj_info() and the alloc_traces and free_traces debugfs files cannot use stack_depot_fetch().

Use stack_depot_fetch_into() with TRACK_ADDRS_COUNT-sized local arrays. This matches the save-side limit. Keep the existing KS_ADDRS_COUNT copy limit and debugfs formatting unchanged. Continue
to copy or print no frames when the fetch returns zero.

[mfleming: reworded for compressed frames]
---
 mm/slub.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
mm/slub.c +7 -5
index cd671b934719..32e6597a5c03 100644
@@ -8328,12 +8328,12 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)
 #ifdef CONFIG_STACKDEPOT
 	{
 		depot_stack_handle_t handle;
-		unsigned long *entries;
+		unsigned long entries[TRACK_ADDRS_COUNT];
 		unsigned int nr_entries;
 
 		handle = READ_ONCE(trackp->handle);
 		if (handle) {
-			nr_entries = stack_depot_fetch(handle, &entries);
+			nr_entries = stack_depot_fetch_into(handle, entries, ARRAY_SIZE(entries));
 			for (i = 0; i < KS_ADDRS_COUNT && i < nr_entries; i++)
 				kpp->kp_stack[i] = (void *)entries[i];
 		}
@@ -8341,7 +8341,7 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)
 		trackp = get_track(s, objp, TRACK_FREE);
 		handle = READ_ONCE(trackp->handle);
 		if (handle) {
-			nr_entries = stack_depot_fetch(handle, &entries);
+			nr_entries = stack_depot_fetch_into(handle, entries, ARRAY_SIZE(entries));
 			for (i = 0; i < KS_ADDRS_COUNT && i < nr_entries; i++)
 				kpp->kp_free_stack[i] = (void *)entries[i];
 		}
@@ -10031,12 +10031,14 @@ static int slab_debugfs_show(struct seq_file *seq, void *v)
 #ifdef CONFIG_STACKDEPOT
 		{
 			depot_stack_handle_t handle;
-			unsigned long *entries;
+			unsigned long entries[TRACK_ADDRS_COUNT];
 			unsigned int nr_entries, j;
 
 			handle = READ_ONCE(l->handle);
 			if (handle) {
-				nr_entries = stack_depot_fetch(handle, &entries);
+				nr_entries =
+					stack_depot_fetch_into(handle, entries,
+							       ARRAY_SIZE(entries));
 				seq_puts(seq, "\n");
 				for (j = 0; j < nr_entries; j++)
 					seq_printf(seq, "        %pS\n", (void *)entries[j]);
Signature · 1 line
2.43.0
#5 lore raw

PATCH v3 5/10 drm/locking: print deadlock backtraces with stack_depot_snprint()

In reply to Matt Fleming

From: Caleb Kan <[email protected]>

When a modeset lock acquisition returns -EDEADLK, DRM saves the call chain and prints it if the caller later attempts another lock or drops its locks without first calling drm_modeset_backoff(). This diagnostic currently fetches the saved stack through stack_depot_fetch().

Later patches compress the frames of persistent stack depot records and remove stack_depot_fetch(), which cannot return a pointer to them. Use stack_depot_snprint() to format the stack. Keep the PAGE_SIZE buffer and leave the warning text, existing indentation, and backtrace unchanged.

[mfleming: reworded for compressed frames]
---
 drivers/gpu/drm/drm_modeset_lock.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/drm_modeset_lock.c +1 -4
index e14814c30d8c..f48b02379b71 100644
@@ -94,16 +94,13 @@ static noinline depot_stack_handle_t __drm_stack_depot_save(void)
 static void __drm_stack_depot_print(depot_stack_handle_t stack_depot)
 {
 	struct drm_printer p = drm_dbg_printer(NULL, DRM_UT_KMS, "drm_modeset_lock");
-	unsigned long *entries;
-	unsigned int nr_entries;
 	char *buf;
 
 	buf = kmalloc(PAGE_SIZE, GFP_NOWAIT | __GFP_NOWARN);
 	if (!buf)
 		return;
 
-	nr_entries = stack_depot_fetch(stack_depot, &entries);
-	stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 2);
+	stack_depot_snprint(stack_depot, buf, PAGE_SIZE, 2);
 
 	drm_printf(&p, "attempting to lock a contended lock without backoff:\n%s", buf);
 
Signature · 1 line
2.43.0
#6 lore raw

PATCH v3 6/10 mm/page_owner: Read stack traces with stack_depot_fetch_into()

In reply to Matt Fleming

From: Matt Fleming <[email protected]>

stack_print() reads stack_record->entries directly. A later patch stores compressed frames inside struct stack_record, so rather than decompressing those frames let's use stack_depot_fetch_into().

Copy the trace with stack_depot_fetch_into() into a stack-local buffer with PAGE_OWNER_STACK_DEPTH elements, which is the maximum number of frames page_owner saves.

---
 mm/page_owner.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/page_owner.c +4 -4
index cfc31c92d765..16429e70e00d 100644
@@ -1068,8 +1068,8 @@ static int stack_print(struct seq_file *m, void *v)
 {
 	int i, nr_base_pages;
 	struct stack *stack = v;
-	unsigned long *entries;
-	unsigned long nr_entries;
+	unsigned long entries[PAGE_OWNER_STACK_DEPTH];
+	unsigned int nr_entries;
 	struct stack_record *stack_record = stack->stack_record;
 	struct stack_print_ctx *ctx = m->private;
 
@@ -1083,8 +1083,8 @@ static int stack_print(struct seq_file *m, void *v)
 		return 0;
 
 	if (ctx->flags & STACK_PRINT_FLAG_STACK) {
-		nr_entries = stack_record->size;
-		entries = stack_record->entries;
+		nr_entries = stack_depot_fetch_into(stack_record->handle.handle,
+						    entries, ARRAY_SIZE(entries));
 		for (i = 0; i < nr_entries; i++)
 			seq_printf(m, " %pS\n", (void *)entries[i]);
 	}
Signature · 1 line
2.43.0
#7 lore raw

PATCH v3 7/10 stackdepot: Remove stack_depot_fetch()

In reply to Matt Fleming

From: Matt Fleming <[email protected]>

All callers now use stack_depot_fetch_into(), stack_depot_print() or stack_depot_snprint(). stack_depot_fetch() hands out a pointer into depot storage, which leaks how frames are stored internally by stackdepot. This will be undesirable when compressed frame support lands in a later patch.

Add a KUnit test that stack_depot_snprint() output and return value match stack_trace_snprint(), including truncation.

---
 include/linux/stackdepot.h   | 11 ------
 lib/stackdepot.c             | 68 ++++++++++++++++--------------------
 lib/tests/stackdepot_kunit.c | 36 +++++++++++++++++++
 3 files changed, 66 insertions(+), 49 deletions(-)
include/linux/stackdepot.h +0 -11
index 734529767c8a..dcc2e1d21f92 100644
@@ -188,17 +188,6 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries,
  */
 struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle);
 
-/**
- * stack_depot_fetch - Fetch a stack trace from stack depot
- *
- * @handle:	Stack depot handle returned from stack_depot_save()
- * @entries:	Pointer to store the address of the stack trace
- *
- * Return: Number of frames for the fetched stack
- */
-unsigned int stack_depot_fetch(depot_stack_handle_t handle,
-			       unsigned long **entries);
-
 /**
  * stack_depot_fetch_into - Fetch a stack trace into caller-owned storage
  *
lib/stackdepot.c +30 -38

101 lines not on this page · raw message

lib/tests/stackdepot_kunit.c +36 -0
index b0c44c096976..ae4f7661a48f 100644
@@ -3,6 +3,8 @@
 #include <kunit/test.h>
 #include <linux/array_size.h>
 #include <linux/gfp.h>
+#include <linux/minmax.h>
+#include <linux/stacktrace.h>
 #include <linux/stackdepot.h>
 #include <linux/string.h>
 
@@ -71,9 +73,43 @@ static void stackdepot_fetch_into_rejects_missing_or_short_stack(struct kunit *t
 	KUNIT_EXPECT_MEMEQ(test, fetched, expected, sizeof(expected));
 }
 
+/* stack_depot_snprint() must match stack_trace_snprint(), with truncation. */
+static void stackdepot_snprint_matches_stack_trace(struct kunit *test)
+{
+	const unsigned int nr = min(40, CONFIG_STACKDEPOT_MAX_FRAMES);
+	const size_t size = 4096;
+	unsigned long entries[40];
+	depot_stack_handle_t handle;
+	char *got, *want;
+	unsigned int i;
+
+	for (i = 0; i < nr; i++)
+		entries[i] = 0x301000UL + 0x1000UL * i;
+	got = kunit_kzalloc(test, size, GFP_KERNEL);
+	want = kunit_kzalloc(test, size, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, got);
+	KUNIT_ASSERT_NOT_NULL(test, want);
+
+	KUNIT_ASSERT_EQ(test, stack_depot_init(), 0);
+	handle = stack_depot_save(entries, nr, GFP_KERNEL);
+	KUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);
+
+	KUNIT_EXPECT_EQ(test, stack_depot_snprint(handle, got, size, 2),
+			stack_trace_snprint(want, size, entries, nr, 2));
+	KUNIT_EXPECT_STREQ(test, got, want);
+
+	/* Truncate part-way through the trace. */
+	memset(got, 0, size);
+	memset(want, 0, size);
+	KUNIT_EXPECT_EQ(test, stack_depot_snprint(handle, got, 700, 0),
+			stack_trace_snprint(want, 700, entries, nr, 0));
+	KUNIT_EXPECT_STREQ(test, got, want);
+}
+
 static struct kunit_case stackdepot_test_cases[] = {
 	KUNIT_CASE(stackdepot_fetch_into_roundtrip),
 	KUNIT_CASE(stackdepot_fetch_into_rejects_missing_or_short_stack),
+	KUNIT_CASE(stackdepot_snprint_matches_stack_trace),
 	{}
 };
 
Signature · 1 line
2.43.0
#8 lore raw

PATCH v3 8/10 stackdepot: add architecture hooks for compact frame storage

In reply to Matt Fleming

From: Caleb Kan <[email protected]>

Stack depot records can reduce their frame storage when an architecture can represent kernel text and module addresses in 32 bits. Add architecture hooks that compress a frame only when decompression reproduces the original address exactly.

Store arm64 frames as signed 32-bit offsets from _text. This covers the 2 GB module relocation window without depending on a 4 GB high-bit boundary. On x86-64, store the low 32 bits when the upper 32 bits are all set. Keep other frames full-width, and provide a generic implementation that always rejects compression.

Make the generic header available to architectures without a specialized implementation and wire it explicitly for UML. Add KUnit coverage for raw fallback, arm64 boundary round trips, and native x86-64 prefix compression.

These hooks do not change stack depot behavior until a later patch uses them to store compressed frames.

[mfleming: simplify arm64 decode, reworded]
---
 arch/arm64/include/asm/stackdepot.h | 37 +++++++++++++
 arch/um/include/asm/Kbuild          |  1 +
 arch/x86/include/asm/stackdepot.h   | 37 +++++++++++++
 include/asm-generic/Kbuild          |  1 +
 include/asm-generic/stackdepot.h    | 19 +++++++
 lib/tests/stackdepot_kunit.c        | 86 +++++++++++++++++++++++++++++
 6 files changed, 181 insertions(+)
 create mode 100644 arch/arm64/include/asm/stackdepot.h
 create mode 100644 arch/x86/include/asm/stackdepot.h
 create mode 100644 include/asm-generic/stackdepot.h
arch/arm64/include/asm/stackdepot.h new file +37 -0
new file mode 100644
index 000000000000..72053527ab21
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_STACKDEPOT_H
+#define __ASM_STACKDEPOT_H
+
+#include <linux/types.h>
+#include <asm/sections.h>
+
+/*
+ * Modules are allocated inside a 2 GB relocation window containing the
+ * kernel image. Store a signed 32-bit offset from _text so compression is
+ * independent of 4 GB high-bit boundaries crossed by that window.
+ */
+static inline unsigned long arch_stack_depot_frame_from_payload(u32 payload)
+{
+	return (unsigned long)_text + (s64)(s32)payload;
+}
+
+static inline bool
+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *payload)
+{
+	u32 candidate;
+
+	candidate = (u32)(frame - (unsigned long)_text);
+	if (arch_stack_depot_frame_from_payload(candidate) != frame)
+		return false;
+
+	*payload = candidate;
+	return true;
+}
+
+static inline void
+arch_stack_depot_frame_decompress(u32 payload, unsigned long *frame)
+{
+	*frame = arch_stack_depot_frame_from_payload(payload);
+}
+
+#endif /* __ASM_STACKDEPOT_H */
arch/um/include/asm/Kbuild +1 -0
index 8fdc0bd9ab6f..14778d2457d7 100644
@@ -21,6 +21,7 @@ generic-y += preempt.h
 generic-y += ring_buffer.h
 generic-y += runtime-const.h
 generic-y += softirq_stack.h
+generic-y += stackdepot.h
 generic-y += switch_to.h
 generic-y += topology.h
 generic-y += trace_clock.h
arch/x86/include/asm/stackdepot.h new file +37 -0
new file mode 100644
index 000000000000..9a8d04fa8c1c
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_STACKDEPOT_H
+#define _ASM_X86_STACKDEPOT_H
+
+#include <linux/types.h>
+
+#ifdef CONFIG_X86_64
+/*
+ * Compress canonical kernel text/module addresses whose upper 32 bits are all
+ * ones. Other kernel virtual addresses stay raw, so decompression reconstructs
+ * the original frame by restoring this prefix.
+ */
+#define STACK_DEPOT_X86_64_FRAME_PREFIX	0xffffffff00000000UL
+#define STACK_DEPOT_X86_64_FRAME_LOW_MASK	0x00000000ffffffffUL
+
+static inline bool
+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *low)
+{
+	if ((frame & ~STACK_DEPOT_X86_64_FRAME_LOW_MASK) !=
+	    STACK_DEPOT_X86_64_FRAME_PREFIX)
+		return false;
+
+	*low = (u32)frame;
+	return true;
+}
+
+static inline void
+arch_stack_depot_frame_decompress(u32 low, unsigned long *frame)
+{
+	*frame = STACK_DEPOT_X86_64_FRAME_PREFIX | low;
+}
+
+#else
+#include <asm-generic/stackdepot.h>
+#endif /* CONFIG_X86_64 */
+
+#endif /* _ASM_X86_STACKDEPOT_H */
include/asm-generic/Kbuild +1 -0
index b7a388bef6ea..76d4792a325a 100644
@@ -55,6 +55,7 @@ mandatory-y += serial.h
 mandatory-y += shmparam.h
 mandatory-y += simd.h
 mandatory-y += softirq_stack.h
+mandatory-y += stackdepot.h
 mandatory-y += switch_to.h
 mandatory-y += timex.h
 mandatory-y += tlbflush.h
include/asm-generic/stackdepot.h new file +19 -0
new file mode 100644
index 000000000000..846975767bdd
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_GENERIC_STACKDEPOT_H
+#define __ASM_GENERIC_STACKDEPOT_H
+
+#include <linux/types.h>
+
+static inline bool
+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *low)
+{
+	return false;
+}
+
+static inline void
+arch_stack_depot_frame_decompress(u32 low, unsigned long *frame)
+{
+	/* Generic code never compresses frames, so this hook is unreachable. */
+}
+
+#endif /* __ASM_GENERIC_STACKDEPOT_H */
lib/tests/stackdepot_kunit.c +86 -0

109 lines not on this page · raw message

Signature · 1 line
2.43.0
#9 lore raw

Re: [PATCH v3 08/10] stackdepot: add architecture hooks for compact frame storage

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] stackdepot: uninitialized frame in arch_stack_depot_frame_decompress() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] stackdepot: uninitialized frame in arch_stack_depot_frame_decompress()
--

commit 29af5949877efb1954b766cd936a7c6ac5d5fb21
Author: Caleb Kan <[email protected]>

stackdepot: add architecture hooks for compact frame storage

This commit introduces architecture hooks for compressing and decompressing stack depot frames into 32-bit payloads on arm64 and x86-64, with a generic no-op fallback for other architectures.

Quoted 13 lines
include/asm-generic/stackdepot.h new file +7 -0
new file mode 100644
index 0000000000000..846975767bdd4
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_GENERIC_STACKDEPOT_H
+#define __ASM_GENERIC_STACKDEPOT_H
+
+#include <linux/types.h>
+
+static inline bool

include/asm-generic/stackdepot.h line 17

Quoted 10 lines
include/asm-generic/stackdepot.h new file +10 -0
+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *low)
+{
+	return false;
+}
+
+static inline void
+arch_stack_depot_frame_decompress(u32 low, unsigned long *frame)
+{
+	/* Generic code never compresses frames, so this hook is unreachable. */
+}

[Severity: High]
Does leaving *frame untouched here cause uninitialized-variable warnings when callers pass an uninitialized local to arch_stack_depot_frame_decompress()?

When commit "stackdepot: Store compressed frames in stack records" wires this into depot_stack_entry(), it declares an uninitialized local frame, calls arch_stack_depot_frame_decompress(..., &frame) when stack->flags & STACK_RECORD_COMPRESSED is set, and returns frame. On architectures using this generic header, the compiler cannot tell that STACK_RECORD_COMPRESSED is never set at runtime, so inlining the empty body leaves frame uninitialized and breaks the build under -Wuninitialized / -Wmaybe-uninitialized. Setting *frame = 0 (or calling unreachable()) would avoid this.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#10 lore raw

PATCH v3 9/10 stackdepot: Store compressed frames in stack records

In reply to Matt Fleming

From: Matt Fleming <[email protected]>

On KASAN machines stack depot can exhaust stack_depot_max_pools. Frame addresses for some architectures (currently x86-64 and arm64) can be losslessly compressed when stored in stackdepot, thereby reducing the number of pools and saving memory.

When every frame of a persistent record can be compressed with the arch hooks, store the 32-bit compressed frames in a new 'compressed_entries' union member and mark the record STACK_RECORD_COMPRESSED. Narrow 'size' to u16 and add a u16 'flags' field so the 32-byte header size is unchanged (CONFIG_STACKDEPOT_MAX_FRAMES is at most 256). A record with any frame that cannot be compressed keeps all its frames uncompressed.

Evictable records (saved with STACK_DEPOT_FLAG_GET) are not compressed because those records always allocate the maximum size anyway and compressing frames doesn't shrink the allocation.

The hash is still computed over the uncompressed frames, so identical traces deduplicate regardless of representation.

Record sizes for common frame counts:

  frames   uncompressed   compressed   reduction
  ------   ------------   ----------   ---------
       8           96 B         64 B       33.3%
      16          160 B         96 B       40.0%
      28          256 B        144 B       43.8%
      32          288 B        160 B       44.4%
      64          544 B        288 B       47.1%

On production KASAN hosts this reduced the number of stack depot pools per 1000 stacks:

  arch     uncompressed   compressed   saving
  ------   ------------   ----------   ------
  x86-64          15.80         9.25    41.5%
  arm64           15.97        11.64    27.1%

arm64 saves less because we run a lot of BPF programs whose code addresses can't be compressed.

---
 include/linux/stackdepot.h   |   8 ++-
 lib/stackdepot.c             | 101 ++++++++++++++++++++++++++++++----
 lib/tests/stackdepot_kunit.c | 103 ++++++++++++++++++++++++++++++++++-
 3 files changed, 199 insertions(+), 13 deletions(-)
include/linux/stackdepot.h +7 -1
index dcc2e1d21f92..de42f6540266 100644
@@ -20,6 +20,7 @@
 #ifndef _LINUX_STACKDEPOT_H
 #define _LINUX_STACKDEPOT_H
 
+#include <linux/bits.h>
 #include <linux/gfp.h>
 
 typedef u32 depot_stack_handle_t;
@@ -50,14 +51,19 @@ union handle_parts {
 	};
 };
 
+/* Frames are compressed into @compressed_entries; see asm/stackdepot.h. */
+#define STACK_RECORD_COMPRESSED	BIT(0)
+
 struct stack_record {
 	struct list_head hash_list;	/* Links in the hash table */
 	u32 hash;			/* Hash in hash table */
-	u32 size;			/* Number of stored frames */
+	u16 size;			/* Number of stored frames */
+	u16 flags;			/* STACK_RECORD_* */
 	union handle_parts handle;	/* Constant after initialization */
 	refcount_t count;
 	union {
 		unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES];	/* Frames */
+		u32 compressed_entries[CONFIG_STACKDEPOT_MAX_FRAMES];
 		struct {
 			/*
 			 * An important invariant of the implementation is to
lib/stackdepot.c +90 -11

172 lines not on this page · raw message

lib/tests/stackdepot_kunit.c +102 -1

122 lines not on this page · raw message

Signature · 1 line
2.43.0
#11 lore raw

Re: [PATCH v3 09/10] stackdepot: Store compressed frames in stack records

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] stackdepot: uninitialized frame in depot_stack_entry() on generic arches --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] stackdepot: uninitialized frame in depot_stack_entry() on generic arches
--

commit 8ef363f0fde887ad99497bbd2e7b00c5bd8bac35
Author: Matt Fleming <[email protected]>

stackdepot: Store compressed frames in stack records

This commit stores stack frames in a 32-bit compressed array inside struct stack_record when all frames of a persistent stack trace can be compressed by architecture hooks.

Quoted 4 lines
lib/stackdepot.c +0 -0
index 8f1aaa0c6d889..f323f1e97e129 100644

[ ... ]

Quoted 19 lines
lib/stackdepot.c +14 -1
@@ -419,9 +422,37 @@ static struct stack_record *depot_pop_free(void)
 	return stack;
 }
 
-static inline size_t depot_stack_record_size(struct stack_record *s, unsigned int nr_entries)
+/* Check whether every frame of a stack can be stored in 32 bits. */
+static bool depot_entries_compressible(const unsigned long *entries,
+				       unsigned int nr_entries)
+{
+	u32 payload;
+
+	for (unsigned int i = 0; i < nr_entries; i++) {
+		if (!arch_stack_depot_frame_try_compress(entries[i], &payload))
+			return false;
+	}
+	return true;
+}
+
+static inline unsigned long depot_stack_entry(const struct stack_record *stack,

lib/stackdepot.c static struct stack_record *depot_pop_free(void) · line 447

Quoted 10 lines
lib/stackdepot.c +8 -1
+					      unsigned int i)
 {
-	const size_t used = flex_array_size(s, entries, nr_entries);
+	unsigned long frame;
+
+	if (!(stack->flags & STACK_RECORD_COMPRESSED))
+		return stack->entries[i];
+	arch_stack_depot_frame_decompress(stack->compressed_entries[i], &frame);
+	return frame;
+}

[Severity: High]
Does depot_stack_entry() return an uninitialized frame on architectures using the generic header?

include/asm-generic/stackdepot.h:arch_stack_depot_frame_decompress() {
	/* Generic code never compresses frames, so this hook is unreachable. */
}

Because stack->flags is read at runtime and the generic arch_stack_depot_frame_decompress() neither writes to *frame nor calls unreachable(), the compiler cannot tell that the compressed branch is dead. In depot_stack_equal(), the early return when
!(stack->flags & STACK_RECORD_COMPRESSED) folds the same check inside the inlined depot_stack_entry() call, leaving frame unconditionally uninitialized in the loop and triggering -Wuninitialized build failures under CONFIG_WERROR=y.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
#12 lore raw

PATCH v3 10/10 scripts/gdb: Decode compressed stack depot frames

In reply to Matt Fleming

From: Matt Fleming <[email protected]>

lx-stack_depot_lookup reads stack_record->entries directly and would misread compressed frames as full-width addresses. Export STACK_RECORD_COMPRESSED through constants.py.in and decompress frames the same way as arch_stack_depot_frame_decompress() on x86-64 and arm64.

Other architectures never compress frames (the generic hook rejects compression), but the helper raises an error if it meets compressed frames there.

---
 scripts/gdb/linux/constants.py.in |  5 +++++
 scripts/gdb/linux/stackdepot.py   | 23 +++++++++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)
scripts/gdb/linux/constants.py.in +5 -0
index dab8b80bed69..da6b39c3dc13 100644
@@ -22,6 +22,7 @@
 #include <linux/radix-tree.h>
 #include <linux/maple_tree.h>
 #include <linux/slab.h>
+#include <linux/stackdepot.h>
 #include <linux/threads.h>
 #include <linux/vmalloc.h>
 
@@ -112,6 +113,10 @@ if IS_BUILTIN(CONFIG_PAGE_OWNER):
     LX_GDBPARSED(PAGE_EXT_OWNER)
     LX_GDBPARSED(PAGE_EXT_OWNER_ALLOCATED)
 
+/* linux/stackdepot.h */
+if IS_BUILTIN(CONFIG_STACKDEPOT):
+    LX_GDBPARSED(STACK_RECORD_COMPRESSED)
+
 /* linux/slab.h */
 LX_GDBPARSED(SLAB_RED_ZONE)
 LX_GDBPARSED(SLAB_POISON)
scripts/gdb/linux/stackdepot.py +19 -4
index aaa18af25cd1..f689cacb3cb7 100644
@@ -20,6 +20,21 @@ def help():
     gdb.write("Unrecognized command\n")
     raise gdb.GdbError(t)
 
+def stack_record_entry(stack, i):
+    if not int(stack['flags']) & constants.LX_STACK_RECORD_COMPRESSED:
+        return int(stack['entries'][i])
+
+    # Mirror arch_stack_depot_frame_decompress().
+    payload = int(stack['compressed_entries'][i])
+    if utils.is_target_arch("x86-64"):
+        return 0xffffffff00000000 | payload
+    if utils.is_target_arch("aarch64"):
+        text = int(gdb.parse_and_eval("(unsigned long)_text"))
+        if payload & 0x80000000:
+            payload -= 1 << 32
+        return (text + payload) & 0xffffffffffffffff
+    raise gdb.GdbError("compressed stack depot frames are not supported on this architecture\n")
+
 def stack_depot_fetch(handle):
     global DEPOT_STACK_ALIGN
     global stack_record_type
@@ -40,7 +55,7 @@ def stack_depot_fetch(handle):
     pool_index = parts['pool_index_plus_1'] - 1
     if pool_index >= pools_num:
         gdb.write("pool index %d out of bounds (%d) for stack id 0x%08x\n" % (pool_index, pools_num, handle))
-        return gdb.Value(0), 0
+        return [], 0
 
     stack_pools = gdb.parse_and_eval('stack_pools')
 
@@ -48,10 +63,10 @@ def stack_depot_fetch(handle):
         pool = stack_pools[pool_index]
         stack = (pool + gdb.Value(offset).cast(utils.get_size_t_type())).cast(stack_record_type.get_type().pointer())
         size = int(stack['size'].cast(utils.get_ulong_type()))
-        return stack['entries'], size
+        return [stack_record_entry(stack, i) for i in range(size)], size
     except Exception as e:
         gdb.write("%s\n" % e)
-        return gdb.Value(0), 0
+        return [], 0
 
 def stack_depot_print(handle):
     if not constants.LX_CONFIG_STACKDEPOT:
@@ -61,7 +76,7 @@ def stack_depot_print(handle):
     if nr_entries > 0:
         for i in range(0, nr_entries):
             try:
-                gdb.execute("x /i 0x%x" % (int(entries[i])))
+                gdb.execute("x /i 0x%x" % entries[i])
             except Exception as e:
                 gdb.write("%s\n" % e)
 
Signature · 1 line
2.43.0
#13 lore raw

Re: [PATCH v3 10/10] scripts/gdb: Decode compressed stack depot frames

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] scripts/gdb: stack_record_entry() reads _text contents instead of its address --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] scripts/gdb: stack_record_entry() reads _text contents instead of its address
--

commit 9494b015f36a201275730fea0979762f1a250f80
Author: Matt Fleming <[email protected]>

scripts/gdb: Decode compressed stack depot frames

This commit exports STACK_RECORD_COMPRESSED to the GDB scripts and decodes compressed stack depot frames on x86-64 and arm64 in stack_depot_fetch().

Quoted 8 lines
scripts/gdb/linux/stackdepot.py +0 -0
index aaa18af25cd12..f689cacb3cb70 100644
@@ -20,6 +20,21 @@ def help():
     gdb.write("Unrecognized command\n")
     raise gdb.GdbError(t)
 

scripts/gdb/linux/stackdepot.py def help(): · line 32

Quoted 10 lines
scripts/gdb/linux/stackdepot.py +10 -0
+def stack_record_entry(stack, i):
+    if not int(stack['flags']) & constants.LX_STACK_RECORD_COMPRESSED:
+        return int(stack['entries'][i])
+
+    # Mirror arch_stack_depot_frame_decompress().
+    payload = int(stack['compressed_entries'][i])
+    if utils.is_target_arch("x86-64"):
+        return 0xffffffff00000000 | payload
+    if utils.is_target_arch("aarch64"):
+        text = int(gdb.parse_and_eval("(unsigned long)_text"))

[Severity: Low]
Does gdb.parse_and_eval("(unsigned long)_text") read the memory contents at _text instead of taking its address?

Unlike in C where char _text[] decays to a pointer, _text is defined only in the linker script as an untyped ELF symbol, so casting it without & in GDB reads the first 8 bytes at .head.text and produces bogus decompressed frame addresses on arm64. Using (unsigned long)&_text, as in scripts/gdb/linux/mm.py, evaluates to the symbol's address.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10