* [PATCH v3 0/5] Fix some GDB command error and add some GDB commands
@ 2024-07-23 6:48 Kuan-Ying Lee
2024-07-23 6:48 ` [PATCH v3 1/5] scripts/gdb: fix timerlist parsing issue Kuan-Ying Lee
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Kuan-Ying Lee @ 2024-07-23 6:48 UTC (permalink / raw)
To: kuan-ying.lee, Andrew Morton; +Cc: linux-mm
Fix some GDB command errors and add some useful GDB commands.
Patch 1:
- Fix timerlist parsing issue
Patch 2-3:
- Add rbtree inorder traverse.
- Fix 'lx-mounts' command error.
Patch 4:
- Add 'lx-stack_depot_lookup' command to provides
users with backtrace of a handle.
Patch 5:
- Add 'lx-kasan_mem_to_shadow' command to translate
the memory address to kasan shadow memory address.
v1->v2:
- Add patch to fix 'lx-mounts' and 'lx-timerlist' gdb command errors.
v2->v3:
- Rebase on linux-next:next-20240722.
Kuan-Ying Lee (5):
scripts/gdb: fix timerlist parsing issue
scripts/gdb: add iteration function for rbtree
scripts/gdb: fix lx-mounts command error
scripts/gdb: Add 'lx-stack_depot_lookup' command.
scripts/gdb: Add 'lx-kasan_mem_to_shadow' command
scripts/gdb/linux/kasan.py | 44 +++++++++++++++++++++++++++++++++
scripts/gdb/linux/proc.py | 4 +--
scripts/gdb/linux/rbtree.py | 12 +++++++++
scripts/gdb/linux/stackdepot.py | 27 ++++++++++++++++++++
scripts/gdb/linux/timerlist.py | 31 ++++++++++++-----------
scripts/gdb/vmlinux-gdb.py | 1 +
6 files changed, 102 insertions(+), 17 deletions(-)
create mode 100644 scripts/gdb/linux/kasan.py
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/5] scripts/gdb: fix timerlist parsing issue
2024-07-23 6:48 [PATCH v3 0/5] Fix some GDB command error and add some GDB commands Kuan-Ying Lee
@ 2024-07-23 6:48 ` Kuan-Ying Lee
2024-07-23 6:48 ` [PATCH v3 2/5] scripts/gdb: add iteration function for rbtree Kuan-Ying Lee
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Kuan-Ying Lee @ 2024-07-23 6:48 UTC (permalink / raw)
To: kuan-ying.lee, Andrew Morton, Jan Kiszka, Kieran Bingham,
Thomas Gleixner, Frederic Weisbecker
Cc: linux-mm, stable, linux-kernel
Commit 7988e5ae2be7 ("tick: Split nohz and highres features from
nohz_mode") and commit 7988e5ae2be7 ("tick: Split nohz and
highres features from nohz_mode") move 'tick_stopped' and 'nohz_mode'
to flags field which will break the gdb lx-mounts command:
(gdb) lx-timerlist
Python Exception <class 'gdb.error'>: There is no member named nohz_mode.
Error occurred in Python: There is no member named nohz_mode.
(gdb) lx-timerlist
Python Exception <class 'gdb.error'>: There is no member named tick_stopped.
Error occurred in Python: There is no member named tick_stopped.
We move 'tick_stopped' and 'nohz_mode' to flags field instead.
Fixes: a478ffb2ae23 ("tick: Move individual bit features to debuggable mask accesses")
Fixes: 7988e5ae2be7 ("tick: Split nohz and highres features from nohz_mode")
Cc: <stable@vger.kernel.org>
Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
---
scripts/gdb/linux/timerlist.py | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/scripts/gdb/linux/timerlist.py b/scripts/gdb/linux/timerlist.py
index 64bc87191003..98445671fe83 100644
--- a/scripts/gdb/linux/timerlist.py
+++ b/scripts/gdb/linux/timerlist.py
@@ -87,21 +87,22 @@ def print_cpu(hrtimer_bases, cpu, max_clock_bases):
text += "\n"
if constants.LX_CONFIG_TICK_ONESHOT:
- fmts = [(" .{} : {}", 'nohz_mode'),
- (" .{} : {} nsecs", 'last_tick'),
- (" .{} : {}", 'tick_stopped'),
- (" .{} : {}", 'idle_jiffies'),
- (" .{} : {}", 'idle_calls'),
- (" .{} : {}", 'idle_sleeps'),
- (" .{} : {} nsecs", 'idle_entrytime'),
- (" .{} : {} nsecs", 'idle_waketime'),
- (" .{} : {} nsecs", 'idle_exittime'),
- (" .{} : {} nsecs", 'idle_sleeptime'),
- (" .{}: {} nsecs", 'iowait_sleeptime'),
- (" .{} : {}", 'last_jiffies'),
- (" .{} : {}", 'next_timer'),
- (" .{} : {} nsecs", 'idle_expires')]
- text += "\n".join([s.format(f, ts[f]) for s, f in fmts])
+ TS_FLAG_STOPPED = 1 << 1
+ TS_FLAG_NOHZ = 1 << 4
+ text += f" .{'nohz':15s}: {int(bool(ts['flags'] & TS_FLAG_NOHZ))}\n"
+ text += f" .{'last_tick':15s}: {ts['last_tick']}\n"
+ text += f" .{'tick_stopped':15s}: {int(bool(ts['flags'] & TS_FLAG_STOPPED))}\n"
+ text += f" .{'idle_jiffies':15s}: {ts['idle_jiffies']}\n"
+ text += f" .{'idle_calls':15s}: {ts['idle_calls']}\n"
+ text += f" .{'idle_sleeps':15s}: {ts['idle_sleeps']}\n"
+ text += f" .{'idle_entrytime':15s}: {ts['idle_entrytime']} nsecs\n"
+ text += f" .{'idle_waketime':15s}: {ts['idle_waketime']} nsecs\n"
+ text += f" .{'idle_exittime':15s}: {ts['idle_exittime']} nsecs\n"
+ text += f" .{'idle_sleeptime':15s}: {ts['idle_sleeptime']} nsecs\n"
+ text += f" .{'iowait_sleeptime':15s}: {ts['iowait_sleeptime']} nsecs\n"
+ text += f" .{'last_jiffies':15s}: {ts['last_jiffies']}\n"
+ text += f" .{'next_timer':15s}: {ts['next_timer']}\n"
+ text += f" .{'idle_expires':15s}: {ts['idle_expires']} nsecs\n"
text += "\njiffies: {}\n".format(jiffies)
text += "\n"
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 2/5] scripts/gdb: add iteration function for rbtree
2024-07-23 6:48 [PATCH v3 0/5] Fix some GDB command error and add some GDB commands Kuan-Ying Lee
2024-07-23 6:48 ` [PATCH v3 1/5] scripts/gdb: fix timerlist parsing issue Kuan-Ying Lee
@ 2024-07-23 6:48 ` Kuan-Ying Lee
2024-07-23 6:48 ` [PATCH v3 3/5] scripts/gdb: fix lx-mounts command error Kuan-Ying Lee
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Kuan-Ying Lee @ 2024-07-23 6:48 UTC (permalink / raw)
To: kuan-ying.lee, Andrew Morton, Jan Kiszka, Kieran Bingham,
Miklos Szeredi, Christian Brauner, Ian Kent
Cc: linux-mm, stable, linux-kernel
Add inorder iteration function for rbtree usage.
This is a preparation patch for the next patch to
fix the gdb mounts issue.
Fixes: 2eea9ce4310d ("mounts: keep list of mounts in an rbtree")
Cc: <stable@vger.kernel.org>
Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
---
scripts/gdb/linux/rbtree.py | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/scripts/gdb/linux/rbtree.py b/scripts/gdb/linux/rbtree.py
index fe462855eefd..fcbcc5f4153c 100644
--- a/scripts/gdb/linux/rbtree.py
+++ b/scripts/gdb/linux/rbtree.py
@@ -9,6 +9,18 @@ from linux import utils
rb_root_type = utils.CachedType("struct rb_root")
rb_node_type = utils.CachedType("struct rb_node")
+def rb_inorder_for_each(root):
+ def inorder(node):
+ if node:
+ yield from inorder(node['rb_left'])
+ yield node
+ yield from inorder(node['rb_right'])
+
+ yield from inorder(root['rb_node'])
+
+def rb_inorder_for_each_entry(root, gdbtype, member):
+ for node in rb_inorder_for_each(root):
+ yield utils.container_of(node, gdbtype, member)
def rb_first(root):
if root.type == rb_root_type.get_type():
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 3/5] scripts/gdb: fix lx-mounts command error
2024-07-23 6:48 [PATCH v3 0/5] Fix some GDB command error and add some GDB commands Kuan-Ying Lee
2024-07-23 6:48 ` [PATCH v3 1/5] scripts/gdb: fix timerlist parsing issue Kuan-Ying Lee
2024-07-23 6:48 ` [PATCH v3 2/5] scripts/gdb: add iteration function for rbtree Kuan-Ying Lee
@ 2024-07-23 6:48 ` Kuan-Ying Lee
2024-07-23 6:49 ` [PATCH v3 4/5] scripts/gdb: Add 'lx-stack_depot_lookup' command Kuan-Ying Lee
2024-07-23 6:49 ` [PATCH v3 5/5] scripts/gdb: Add 'lx-kasan_mem_to_shadow' command Kuan-Ying Lee
4 siblings, 0 replies; 6+ messages in thread
From: Kuan-Ying Lee @ 2024-07-23 6:48 UTC (permalink / raw)
To: kuan-ying.lee, Andrew Morton, Jan Kiszka, Kieran Bingham,
Christian Brauner, Ian Kent, Miklos Szeredi
Cc: linux-mm, stable, linux-kernel
(gdb) lx-mounts
mount super_block devname pathname fstype options
Python Exception <class 'gdb.error'>: There is no member named list.
Error occurred in Python: There is no member named list.
We encoutner the above issue after commit 2eea9ce4310d ("mounts: keep
list of mounts in an rbtree"). The commit move a mount from list into
rbtree.
So we can instead use rbtree to iterate all mounts information.
Fixes: 2eea9ce4310d ("mounts: keep list of mounts in an rbtree")
Cc: <stable@vger.kernel.org>
Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
---
scripts/gdb/linux/proc.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/gdb/linux/proc.py b/scripts/gdb/linux/proc.py
index 43c687e7a69d..65dd1bd12964 100644
--- a/scripts/gdb/linux/proc.py
+++ b/scripts/gdb/linux/proc.py
@@ -18,6 +18,7 @@ from linux import utils
from linux import tasks
from linux import lists
from linux import vfs
+from linux import rbtree
from struct import *
@@ -172,8 +173,7 @@ values of that process namespace"""
gdb.write("{:^18} {:^15} {:>9} {} {} options\n".format(
"mount", "super_block", "devname", "pathname", "fstype"))
- for mnt in lists.list_for_each_entry(namespace['list'],
- mount_ptr_type, "mnt_list"):
+ for mnt in rbtree.rb_inorder_for_each_entry(namespace['mounts'], mount_ptr_type, "mnt_node"):
devname = mnt['mnt_devname'].string()
devname = devname if devname else "none"
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 4/5] scripts/gdb: Add 'lx-stack_depot_lookup' command.
2024-07-23 6:48 [PATCH v3 0/5] Fix some GDB command error and add some GDB commands Kuan-Ying Lee
` (2 preceding siblings ...)
2024-07-23 6:48 ` [PATCH v3 3/5] scripts/gdb: fix lx-mounts command error Kuan-Ying Lee
@ 2024-07-23 6:49 ` Kuan-Ying Lee
2024-07-23 6:49 ` [PATCH v3 5/5] scripts/gdb: Add 'lx-kasan_mem_to_shadow' command Kuan-Ying Lee
4 siblings, 0 replies; 6+ messages in thread
From: Kuan-Ying Lee @ 2024-07-23 6:49 UTC (permalink / raw)
To: kuan-ying.lee, Andrew Morton, Jan Kiszka, Kieran Bingham
Cc: linux-mm, linux-kernel
This command allows users to quickly retrieve a stacktrace
using a handle obtained from a memory coredump.
Example output:
(gdb) lx-stack_depot_lookup 0x00c80300
0xffff8000807965b4 <kmem_cache_alloc_noprof+660>: mov x20, x0
0xffff800081a077d8 <kmem_cache_oob_alloc+76>: mov x1, x0
0xffff800081a079a0 <test_version_show+100>: cbnz w0, 0xffff800081a07968 <test_version_show+44>
0xffff800082f4a3fc <kobj_attr_show+60>: ldr x19, [sp, #16]
0xffff800080a0fb34 <sysfs_kf_seq_show+460>: ldp x3, x4, [sp, #96]
0xffff800080a0a550 <kernfs_seq_show+296>: ldp x19, x20, [sp, #16]
0xffff8000808e7b40 <seq_read_iter+836>: mov w5, w0
0xffff800080a0b8ac <kernfs_fop_read_iter+804>: mov x23, x0
0xffff800080914a48 <copy_splice_read+972>: mov x6, x0
0xffff8000809151c4 <do_splice_read+348>: ldr x21, [sp, #32]
Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
---
scripts/gdb/linux/stackdepot.py | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/scripts/gdb/linux/stackdepot.py b/scripts/gdb/linux/stackdepot.py
index bb3a0f843931..37313a5a51a0 100644
--- a/scripts/gdb/linux/stackdepot.py
+++ b/scripts/gdb/linux/stackdepot.py
@@ -13,6 +13,13 @@ if constants.LX_CONFIG_STACKDEPOT:
stack_record_type = utils.CachedType('struct stack_record')
DEPOT_STACK_ALIGN = 4
+def help():
+ t = """Usage: lx-stack_depot_lookup [Hex handle value]
+ Example:
+ lx-stack_depot_lookup 0x00c80300\n"""
+ gdb.write("Unrecognized command\n")
+ raise gdb.GdbError(t)
+
def stack_depot_fetch(handle):
global DEPOT_STACK_ALIGN
global stack_record_type
@@ -57,3 +64,23 @@ def stack_depot_print(handle):
gdb.execute("x /i 0x%x" % (int(entries[i])))
except Exception as e:
gdb.write("%s\n" % e)
+
+class StackDepotLookup(gdb.Command):
+ """Search backtrace by handle"""
+
+ def __init__(self):
+ if constants.LX_CONFIG_STACKDEPOT:
+ super(StackDepotLookup, self).__init__("lx-stack_depot_lookup", gdb.COMMAND_SUPPORT)
+
+ def invoke(self, args, from_tty):
+ if not constants.LX_CONFIG_STACKDEPOT:
+ raise gdb.GdbError('CONFIG_STACKDEPOT is not set')
+
+ argv = gdb.string_to_argv(args)
+ if len(argv) == 1:
+ handle = int(argv[0], 16)
+ stack_depot_print(gdb.Value(handle).cast(utils.get_uint_type()))
+ else:
+ help()
+
+StackDepotLookup()
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 5/5] scripts/gdb: Add 'lx-kasan_mem_to_shadow' command
2024-07-23 6:48 [PATCH v3 0/5] Fix some GDB command error and add some GDB commands Kuan-Ying Lee
` (3 preceding siblings ...)
2024-07-23 6:49 ` [PATCH v3 4/5] scripts/gdb: Add 'lx-stack_depot_lookup' command Kuan-Ying Lee
@ 2024-07-23 6:49 ` Kuan-Ying Lee
4 siblings, 0 replies; 6+ messages in thread
From: Kuan-Ying Lee @ 2024-07-23 6:49 UTC (permalink / raw)
To: kuan-ying.lee, Andrew Morton, Jan Kiszka, Kieran Bingham
Cc: linux-mm, linux-kernel
This command allows users to quickly translate memory address
to the kasan shadow memory address.
Example output:
(gdb) lx-kasan_mem_to_shadow 0xffff000019acc008
shadow addr: 0xffff600003359801
Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
---
scripts/gdb/linux/kasan.py | 44 ++++++++++++++++++++++++++++++++++++++
scripts/gdb/vmlinux-gdb.py | 1 +
2 files changed, 45 insertions(+)
create mode 100644 scripts/gdb/linux/kasan.py
diff --git a/scripts/gdb/linux/kasan.py b/scripts/gdb/linux/kasan.py
new file mode 100644
index 000000000000..56730b3fde0b
--- /dev/null
+++ b/scripts/gdb/linux/kasan.py
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright 2024 Canonical Ltd.
+#
+# Authors:
+# Kuan-Ying Lee <kuan-ying.lee@canonical.com>
+#
+
+import gdb
+from linux import constants, mm
+
+def help():
+ t = """Usage: lx-kasan_mem_to_shadow [Hex memory addr]
+ Example:
+ lx-kasan_mem_to_shadow 0xffff000008eca008\n"""
+ gdb.write("Unrecognized command\n")
+ raise gdb.GdbError(t)
+
+class KasanMemToShadow(gdb.Command):
+ """Translate memory address to kasan shadow address"""
+
+ p_ops = None
+
+ def __init__(self):
+ if constants.LX_CONFIG_KASAN_GENERIC or constants.LX_CONFIG_KASAN_SW_TAGS:
+ super(KasanMemToShadow, self).__init__("lx-kasan_mem_to_shadow", gdb.COMMAND_SUPPORT)
+
+ def invoke(self, args, from_tty):
+ if not constants.LX_CONFIG_KASAN_GENERIC or constants.LX_CONFIG_KASAN_SW_TAGS:
+ raise gdb.GdbError('CONFIG_KASAN_GENERIC or CONFIG_KASAN_SW_TAGS is not set')
+
+ argv = gdb.string_to_argv(args)
+ if len(argv) == 1:
+ if self.p_ops is None:
+ self.p_ops = mm.page_ops().ops
+ addr = int(argv[0], 16)
+ shadow_addr = self.kasan_mem_to_shadow(addr)
+ gdb.write('shadow addr: 0x%x\n' % shadow_addr)
+ else:
+ help()
+ def kasan_mem_to_shadow(self, addr):
+ return (addr >> self.p_ops.KASAN_SHADOW_SCALE_SHIFT) + self.p_ops.KASAN_SHADOW_OFFSET
+
+KasanMemToShadow()
diff --git a/scripts/gdb/vmlinux-gdb.py b/scripts/gdb/vmlinux-gdb.py
index fc53cdf286f1..d4eeed4506fd 100644
--- a/scripts/gdb/vmlinux-gdb.py
+++ b/scripts/gdb/vmlinux-gdb.py
@@ -49,3 +49,4 @@ else:
import linux.page_owner
import linux.slab
import linux.vmalloc
+ import linux.kasan
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-07-23 6:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-23 6:48 [PATCH v3 0/5] Fix some GDB command error and add some GDB commands Kuan-Ying Lee
2024-07-23 6:48 ` [PATCH v3 1/5] scripts/gdb: fix timerlist parsing issue Kuan-Ying Lee
2024-07-23 6:48 ` [PATCH v3 2/5] scripts/gdb: add iteration function for rbtree Kuan-Ying Lee
2024-07-23 6:48 ` [PATCH v3 3/5] scripts/gdb: fix lx-mounts command error Kuan-Ying Lee
2024-07-23 6:49 ` [PATCH v3 4/5] scripts/gdb: Add 'lx-stack_depot_lookup' command Kuan-Ying Lee
2024-07-23 6:49 ` [PATCH v3 5/5] scripts/gdb: Add 'lx-kasan_mem_to_shadow' command Kuan-Ying Lee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox