Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scripts/gdb/symbols: determine KASLR offset on s390

Use QEMU's qemu.PhyMemMode [1] functionality to read vmcore from the
physical memory the same way the existing dump tooling does this.
Gracefully handle non-QEMU targets, early boot, and memory corruptions;
print a warning if such situation is detected.

[1] https://qemu-project.gitlab.io/qemu/system/gdb.html#examining-physical-memory

Link: https://lkml.kernel.org/r/20250303110437.79070-1-iii@linux.ibm.com
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Acked-by: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Andrew Donnellan <ajd@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Kieran Bingham <kbingham@kernel.org>
Cc: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Ilya Leoshkevich and committed by
Andrew Morton
28939c3e 8a56f266

+65 -1
+30 -1
scripts/gdb/linux/symbols.py
··· 14 14 import gdb 15 15 import os 16 16 import re 17 + import struct 17 18 18 19 from itertools import count 19 20 from linux import modules, utils, constants ··· 53 52 gdb.execute("set pagination %s" % ("on" if pagination else "off")) 54 53 55 54 return False 55 + 56 + 57 + def get_vmcore_s390(): 58 + with utils.qemu_phy_mem_mode(): 59 + vmcore_info = 0x0e0c 60 + paddr_vmcoreinfo_note = gdb.parse_and_eval("*(unsigned long long *)" + 61 + hex(vmcore_info)) 62 + inferior = gdb.selected_inferior() 63 + elf_note = inferior.read_memory(paddr_vmcoreinfo_note, 12) 64 + n_namesz, n_descsz, n_type = struct.unpack(">III", elf_note) 65 + desc_paddr = paddr_vmcoreinfo_note + len(elf_note) + n_namesz + 1 66 + return gdb.parse_and_eval("(char *)" + hex(desc_paddr)).string() 67 + 68 + 69 + def get_kerneloffset(): 70 + if utils.is_target_arch('s390'): 71 + try: 72 + vmcore_str = get_vmcore_s390() 73 + except gdb.error as e: 74 + gdb.write("{}\n".format(e)) 75 + return None 76 + return utils.parse_vmcore(vmcore_str).kerneloffset 77 + return None 56 78 57 79 58 80 class LxSymbols(gdb.Command): ··· 184 160 obj.filename.endswith('vmlinux.debug')): 185 161 orig_vmlinux = obj.filename 186 162 gdb.execute("symbol-file", to_string=True) 187 - gdb.execute("symbol-file {0}".format(orig_vmlinux)) 163 + kerneloffset = get_kerneloffset() 164 + if kerneloffset is None: 165 + offset_arg = "" 166 + else: 167 + offset_arg = " -o " + hex(kerneloffset) 168 + gdb.execute("symbol-file {0}{1}".format(orig_vmlinux, offset_arg)) 188 169 189 170 self.loaded_modules = [] 190 171 module_list = modules.module_list()
+35
scripts/gdb/linux/utils.py
··· 11 11 # This work is licensed under the terms of the GNU GPL version 2. 12 12 # 13 13 14 + import contextlib 15 + import dataclasses 16 + import re 17 + import typing 18 + 14 19 import gdb 15 20 16 21 ··· 221 216 return gdb.parse_and_eval(expresssion) 222 217 except gdb.error: 223 218 return None 219 + 220 + 221 + @contextlib.contextmanager 222 + def qemu_phy_mem_mode(): 223 + connection = gdb.selected_inferior().connection 224 + orig = connection.send_packet("qqemu.PhyMemMode") 225 + if orig not in b"01": 226 + raise gdb.error("Unexpected qemu.PhyMemMode") 227 + orig = orig.decode() 228 + if connection.send_packet("Qqemu.PhyMemMode:1") != b"OK": 229 + raise gdb.error("Failed to set qemu.PhyMemMode") 230 + try: 231 + yield 232 + finally: 233 + if connection.send_packet("Qqemu.PhyMemMode:" + orig) != b"OK": 234 + raise gdb.error("Failed to restore qemu.PhyMemMode") 235 + 236 + 237 + @dataclasses.dataclass 238 + class VmCore: 239 + kerneloffset: typing.Optional[int] 240 + 241 + 242 + def parse_vmcore(s): 243 + match = re.search(r"KERNELOFFSET=([0-9a-f]+)", s) 244 + if match is None: 245 + kerneloffset = None 246 + else: 247 + kerneloffset = int(match.group(1), 16) 248 + return VmCore(kerneloffset=kerneloffset)