Skip to contentSkip to conversation

scripts/gdb: Fix interrupts.py after maple tree conversion

PATCH Superseded Florian Fainelli 2 participants 3 messages Jun 24, 2025 – Jun 25, 2025 GDB kernel debugging helper scripts

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scripts/gdb: Fix interrupts.py after maple tree conversion

In commit 721255b9826b ("genirq: Use a maple tree for interrupt descriptor management"), the irq_desc_tree was replaced with a sparse_irqs tree using a maple tree structure.

A new module (mapletree.py) is added whose mtree_load() implementation is largely copied after the C version and uses the same variable and intermediate function names wherever possible to ensure that both the C and Python version be updated in the future.

Fixes 721255b9826b ("genirq: Use a maple tree for interrupt descriptor management")

---
Changes in v2:

- do a proper Python implementation of mtree_load() since we cannot assume that context in which we will be interfacing with the target permits making direct function calls from the kernel.

 scripts/gdb/linux/constants.py.in |   7 +
 scripts/gdb/linux/interrupts.py   |  10 +-
 scripts/gdb/linux/mapletree.py    | 252 ++++++++++++++++++++++++++++++
 scripts/gdb/linux/xarray.py       |  28 ++++
 4 files changed, 292 insertions(+), 5 deletions(-)
 create mode 100644 scripts/gdb/linux/mapletree.py
 create mode 100644 scripts/gdb/linux/xarray.py
scripts/gdb/linux/constants.py.in +7 -0
index d5e3069f42a7..c3886739a028 100644
@@ -20,6 +20,7 @@
 #include <linux/of_fdt.h>
 #include <linux/page_ext.h>
 #include <linux/radix-tree.h>
+#include <linux/maple_tree.h>
 #include <linux/slab.h>
 #include <linux/threads.h>
 #include <linux/vmalloc.h>
@@ -93,6 +94,12 @@ LX_GDBPARSED(RADIX_TREE_MAP_SIZE)
 LX_GDBPARSED(RADIX_TREE_MAP_SHIFT)
 LX_GDBPARSED(RADIX_TREE_MAP_MASK)
 
+/* linux/maple_tree.h */
+LX_VALUE(MAPLE_NODE_SLOTS)
+LX_VALUE(MAPLE_RANGE64_SLOTS)
+LX_VALUE(MAPLE_ARANGE64_SLOTS)
+LX_GDBPARSED(MAPLE_NODE_MASK)
+
 /* linux/vmalloc.h */
 LX_VALUE(VM_IOREMAP)
 LX_VALUE(VM_ALLOC)
scripts/gdb/linux/interrupts.py +5 -5
index 8bd0d7108ae0..1401be6a28fb 100644
@@ -7,7 +7,7 @@ import gdb
 from linux import constants
 from linux import cpus
 from linux import utils
-from linux import radixtree
+from linux import mapletree
 
 irq_desc_type = utils.CachedType("struct irq_desc")
 
@@ -23,12 +23,12 @@ def irqd_is_level(desc):
 def show_irq_desc(prec, irq):
     text = ""
 
-    desc = radixtree.lookup(gdb.parse_and_eval("&irq_desc_tree"), irq)
+    desc = mapletree.mtree_load(gdb.parse_and_eval("&sparse_irqs"), irq)
     if desc is None:
         return text
 
-    desc = desc.cast(irq_desc_type.get_type())
-    if desc is None:
+    desc = desc.cast(irq_desc_type.get_type().pointer())
+    if desc == 0:
         return text
 
     if irq_settings_is_hidden(desc):
@@ -221,7 +221,7 @@ class LxInterruptList(gdb.Command):
             gdb.write("CPU%-8d" % cpu)
         gdb.write("\n")
 
-        if utils.gdb_eval_or_none("&irq_desc_tree") is None:
+        if utils.gdb_eval_or_none("&irq_desc_tree") or utils.gdb_eval_or_none("&sparse_irqs") is None:
             return
 
         for irq in range(nr_irqs):
scripts/gdb/linux/mapletree.py new file +252 -0

252 lines not on this page · raw message

scripts/gdb/linux/xarray.py new file +28 -0
new file mode 100644
index 000000000000..f4477b5def75
@@ -0,0 +1,28 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+#  Xarray helpers
+#
+# Copyright (c) 2025 Broadcom
+#
+# Authors:
+#  Florian Fainelli <[email protected]>
+
+import gdb
+
+from linux import utils
+from linux import constants
+
+def xa_is_internal(entry):
+    ulong_type = utils.get_ulong_type()
+    return ((entry.cast(ulong_type) & 3) == 2)
+
+def xa_mk_internal(v):
+    return ((v << 2) | 2)
+
+def xa_is_zero(entry):
+    ulong_type = utils.get_ulong_type()
+    return entry.cast(ulong_type) == xa_mk_internal(257)
+
+def xa_is_node(entry):
+    ulong_type = utils.get_ulong_type()
+    return xa_is_internal(entry) and (entry.cast(ulong_type) > 4096)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 8 lines · On Mon, 23 Jun 2025 20:27:45 -0700 Florian Fainelli…

In commit 721255b9826b ("genirq: Use a maple tree for interrupt descriptor management"), the irq_desc_tree was replaced with a sparse_irqs tree using a maple tree structure.

A new module (mapletree.py) is added whose mtree_load() implementation is largely copied after the C version and uses the same variable and intermediate function names wherever possible to ensure that both the C and Python version be updated in the future.

butbutbut. What is actually being "fixed" here? The above contains no description of any problem.

#2 lore raw
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Mon, 23 Jun 2025 20:27:45 -0700 Florian Fainelli…

In commit 721255b9826b ("genirq: Use a maple tree for interrupt descriptor management"), the irq_desc_tree was replaced with a sparse_irqs tree using a maple tree structure.

Quoted 7 lines
Quoted 4 lines

A new module (mapletree.py) is added whose mtree_load() implementation is largely copied after the C version and uses the same variable and intermediate function names wherever possible to ensure that both the C and Python version be updated in the future.

butbutbut. What is actually being "fixed" here? The above contains no description of any problem.

OK, I also thought this was clear enough that the script stopped working and printed nothing, but does not hurt to state that clearly. v3 coming up shortly, thanks!

Signature · 1 line
Florian