Skip to contentSkip to conversation

scripts/gdb/symbols: determine KASLR offset on s390 during early boot

PATCH Applied Ilya Leoshkevich 1 participant 4 messages May 15, 2025 GDB kernel debugging helper scripts

lore
Share & tools
lore
#0 lore raw

cover scripts/gdb/symbols: determine KASLR offset on s390 during early boot

Hi,

I noticed that debugging s390 early boot using the support I introduced in commit 28939c3e9925 ("scripts/gdb/symbols: determine KASLR offset on s390") does not work.

The reason is that decompressor does not provide the vmcoreinfo note, so KASLR offset needs to be extracted in a different way, which this series implements. Patches 1-2 are trivial refactorings, and patch 3 is the implementation.

Best regards,
Ilya

Ilya Leoshkevich (3):
scripts/gdb/symbols: factor out get_vmlinux() scripts/gdb/symbols: factor out pagination_off() scripts/gdb/symbols: determine KASLR offset on s390 during early boot

 scripts/gdb/linux/symbols.py | 38 +++++++++++++++++++-----------------
 scripts/gdb/linux/utils.py   | 20 +++++++++++++++++++
 2 files changed, 40 insertions(+), 18 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/3 scripts/gdb/symbols: factor out get_vmlinux()

Move the code that determines the current vmlinux file into a separate function. It will be useful later in order to analyze the kernel image in physical memory during s390 early boot.

---
 scripts/gdb/linux/symbols.py | 6 +-----
 scripts/gdb/linux/utils.py   | 9 +++++++++
 2 files changed, 10 insertions(+), 5 deletions(-)
scripts/gdb/linux/symbols.py +1 -5
index b255177301e9..25c4627c60e5 100644
@@ -178,11 +178,7 @@ lx-symbols command."""
                 saved_states.append({'breakpoint': bp, 'enabled': bp.enabled})
 
         # drop all current symbols and reload vmlinux
-        orig_vmlinux = 'vmlinux'
-        for obj in gdb.objfiles():
-            if (obj.filename.endswith('vmlinux') or
-                obj.filename.endswith('vmlinux.debug')):
-                orig_vmlinux = obj.filename
+        orig_vmlinux = utils.get_vmlinux()
         gdb.execute("symbol-file", to_string=True)
         kerneloffset = get_kerneloffset()
         if kerneloffset is None:
scripts/gdb/linux/utils.py +9 -0
index 03ebdccf5f69..fc94ff6a6d72 100644
@@ -251,3 +251,12 @@ def parse_vmcore(s):
     else:
         kerneloffset = int(match.group(1), 16)
     return VmCore(kerneloffset=kerneloffset)
+
+
+def get_vmlinux():
+    vmlinux = 'vmlinux'
+    for obj in gdb.objfiles():
+        if (obj.filename.endswith('vmlinux') or
+            obj.filename.endswith('vmlinux.debug')):
+            vmlinux = obj.filename
+    return vmlinux
Signature · 1 line
2.49.0
#2 lore raw

PATCH 2/3 scripts/gdb/symbols: factor out pagination_off()

In reply to Ilya Leoshkevich

Move the code that turns off pagination into a separate function. It will be useful later in order to prevent hangs when loading symbols for kernel image in physical memory during s390 early boot.

---
 scripts/gdb/linux/symbols.py | 20 +++++++-------------
 scripts/gdb/linux/utils.py   | 11 +++++++++++
 2 files changed, 18 insertions(+), 13 deletions(-)
scripts/gdb/linux/symbols.py +7 -13
index 25c4627c60e5..0c7af712c44c 100644
@@ -38,19 +38,13 @@ if hasattr(gdb, 'Breakpoint'):
             # Disable pagination while reporting symbol (re-)loading.
             # The console input is blocked in this context so that we would
             # get stuck waiting for the user to acknowledge paged output.
-            show_pagination = gdb.execute("show pagination", to_string=True)
-            pagination = show_pagination.endswith("on.\n")
-            gdb.execute("set pagination off")
-
-            if module_name in cmd.loaded_modules:
-                gdb.write("refreshing all symbols to reload module "
-                          "'{0}'\n".format(module_name))
-                cmd.load_all_symbols()
-            else:
-                cmd.load_module_symbols(module)
-
-            # restore pagination state
-            gdb.execute("set pagination %s" % ("on" if pagination else "off"))
+            with utils.pagination_off():
+                if module_name in cmd.loaded_modules:
+                    gdb.write("refreshing all symbols to reload module "
+                              "'{0}'\n".format(module_name))
+                    cmd.load_all_symbols()
+                else:
+                    cmd.load_module_symbols(module)
 
             return False
 
scripts/gdb/linux/utils.py +11 -0
index fc94ff6a6d72..dc379ab11af0 100644
@@ -260,3 +260,14 @@ def get_vmlinux():
             obj.filename.endswith('vmlinux.debug')):
             vmlinux = obj.filename
     return vmlinux
+
+
[email protected]
+def pagination_off():
+    show_pagination = gdb.execute("show pagination", to_string=True)
+    pagination = show_pagination.endswith("on.\n")
+    gdb.execute("set pagination off")
+    try:
+        yield
+    finally:
+        gdb.execute("set pagination %s" % ("on" if pagination else "off"))
Signature · 1 line
2.49.0
#3 lore raw

PATCH 3/3 scripts/gdb/symbols: determine KASLR offset on s390 during early boot

In reply to Ilya Leoshkevich

Using lx-symbols during s390 early boot fails with:

    Error occurred in Python: 'utf-8' codec can't decode byte 0xcb in position 0: invalid continuation byte

The reason is that s390 decompressor's startup_kernel() does not create vmcoreinfo note, and sets vmcore_info to kernel's physical base. This confuses get_vmcore_s390().

Fix by handling this special case. Extract vm_layout.kaslr_offset from the kernel image in physical memory, which is placed there by the decompressor using the __bootdata_preserved mechanism, and generate a synthetic vmcoreinfo note from it.

---
 scripts/gdb/linux/symbols.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)
scripts/gdb/linux/symbols.py +12 -0
index 0c7af712c44c..2332bd8eddf1 100644
@@ -54,6 +54,18 @@ def get_vmcore_s390():
         vmcore_info = 0x0e0c
         paddr_vmcoreinfo_note = gdb.parse_and_eval("*(unsigned long long *)" +
                                                    hex(vmcore_info))
+        if paddr_vmcoreinfo_note == 0 or paddr_vmcoreinfo_note & 1:
+            # In the early boot case, extract vm_layout.kaslr_offset from the
+            # vmlinux image in physical memory.
+            if paddr_vmcoreinfo_note == 0:
+                kaslr_offset_phys = 0
+            else:
+                kaslr_offset_phys = paddr_vmcoreinfo_note - 1
+            with utils.pagination_off():
+                gdb.execute("symbol-file {0} -o {1}".format(
+                    utils.get_vmlinux(), hex(kaslr_offset_phys)))
+            kaslr_offset = gdb.parse_and_eval("vm_layout.kaslr_offset")
+            return "KERNELOFFSET=" + hex(kaslr_offset)[2:]
         inferior = gdb.selected_inferior()
         elf_note = inferior.read_memory(paddr_vmcoreinfo_note, 12)
         n_namesz, n_descsz, n_type = struct.unpack(">III", elf_note)
Signature · 1 line
2.49.0