From: Matt Fleming <matt@readmodwrite.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Marco Elver <elver@google.com>
Cc: Alexander Potapenko <glider@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
Oscar Salvador <osalvador@suse.de>,
Vlastimil Babka <vbabka@kernel.org>,
Caleb Kan <ckan@cloudflare.com>,
Caleb Kan <calebkan1106@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
kasan-dev@googlegroups.com, kernel-team@cloudflare.com,
Matt Fleming <mfleming@cloudflare.com>
Subject: [PATCH v3 10/10] scripts/gdb: Decode compressed stack depot frames
Date: Fri, 13 Nov 2026 18:57:02 +0000 [thread overview]
Message-ID: <20261113185702.1332171-11-matt@readmodwrite.com> (raw)
In-Reply-To: <20261113185702.1332171-1-matt@readmodwrite.com>
From: Matt Fleming <mfleming@cloudflare.com>
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.
Signed-off-by: Matt Fleming <mfleming@cloudflare.com>
---
scripts/gdb/linux/constants.py.in | 5 +++++
scripts/gdb/linux/stackdepot.py | 23 +++++++++++++++++++----
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in
index dab8b80bed69..da6b39c3dc13 100644
--- a/scripts/gdb/linux/constants.py.in
+++ b/scripts/gdb/linux/constants.py.in
@@ -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)
diff --git a/scripts/gdb/linux/stackdepot.py b/scripts/gdb/linux/stackdepot.py
index aaa18af25cd1..f689cacb3cb7 100644
--- a/scripts/gdb/linux/stackdepot.py
+++ b/scripts/gdb/linux/stackdepot.py
@@ -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)
--
2.43.0
prev parent reply other threads:[~2026-11-13 18:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 18:56 [PATCH v3 00/10] stackdepot: store compressed frames in stack records Matt Fleming
2026-11-13 18:56 ` [PATCH v3 01/10] stackdepot: add caller-owned stack trace fetching Matt Fleming
2026-11-13 18:56 ` [PATCH v3 02/10] mm/kmemleak: use stack_depot_fetch_into() for leak reports Matt Fleming
2026-11-13 18:56 ` [PATCH v3 03/10] kmsan: use stack_depot_fetch_into() for origin reports Matt Fleming
2026-11-13 18:56 ` [PATCH v3 04/10] mm/slub: use stack_depot_fetch_into() for owner tracking Matt Fleming
2026-11-13 18:56 ` [PATCH v3 05/10] drm/locking: print deadlock backtraces with stack_depot_snprint() Matt Fleming
2026-11-13 18:56 ` [PATCH v3 06/10] mm/page_owner: Read stack traces with stack_depot_fetch_into() Matt Fleming
2026-11-13 18:56 ` [PATCH v3 07/10] stackdepot: Remove stack_depot_fetch() Matt Fleming
2026-11-13 18:57 ` [PATCH v3 08/10] stackdepot: add architecture hooks for compact frame storage Matt Fleming
2026-11-13 18:57 ` [PATCH v3 09/10] stackdepot: Store compressed frames in stack records Matt Fleming
2026-11-13 18:57 ` Matt Fleming [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261113185702.1332171-11-matt@readmodwrite.com \
--to=matt@readmodwrite.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=calebkan1106@gmail.com \
--cc=ckan@cloudflare.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=kernel-team@cloudflare.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mfleming@cloudflare.com \
--cc=osalvador@suse.de \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®