scripts/gdb/symbols: make lx-symbols skip the s390 decompressor
Subsystems (2)
cover scripts/gdb/symbols: make lx-symbols skip the s390 decompressor
Hi,
In order to debug the early s390 kernel boot, one has to skip the decompressor code, which requires some private scripts or memorized commands. This series makes it work out of the box with the lx-symbols command.
Patch 1 adds helper infrastructure to the s390 decompressor code; it is already acked by Heiko.
Patch 2 is the implementation; it would be great to have an Ack from one of the GDB scripts maintainers.
We would like to get this series via the s390 tree, if possible.
Best regards,
Ilya
Ilya Leoshkevich (2):
s390/boot: Introduce jump_to_kernel() function scripts/gdb/symbols: make lx-symbols skip the s390 decompressor
arch/s390/boot/Makefile | 2 +- arch/s390/boot/boot.h | 1 + arch/s390/boot/ipl_data.c | 9 ++++++++- arch/s390/boot/startup.c | 2 +- arch/s390/boot/trampoline.S | 9 +++++++++ scripts/gdb/linux/symbols.py | 26 ++++++++++++++++++++++++++ 6 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 arch/s390/boot/trampoline.S
Signature · 1 line
2.49.0
PATCH 1/2 s390/boot: Introduce jump_to_kernel() function
Introduce a global function that jumps from the decompressor to the decompressed kernel. Put its address into svc_old_psw, from where GDB can take it without loading decompressor symbols. It should be available throughout the entire decompressor execution, because it's placed there statically, and nothing in the decompressor uses the SVC instruction.
--- arch/s390/boot/Makefile | 2 +- arch/s390/boot/boot.h | 1 + arch/s390/boot/ipl_data.c | 9 ++++++++- arch/s390/boot/startup.c | 2 +- arch/s390/boot/trampoline.S | 9 +++++++++ 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 arch/s390/boot/trampoline.S
arch/s390/boot/Makefile +1 -1
@@ -27,7 +27,7 @@ CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char obj-y := head.o als.o startup.o physmem_info.o ipl_parm.o ipl_report.o vmem.o obj-y += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o obj-y += version.o pgm_check.o ctype.o ipl_data.o relocs.o alternative.o -obj-y += uv.o printk.o +obj-y += uv.o printk.o trampoline.o obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o obj-y += $(if $(CONFIG_KERNEL_UNCOMPRESSED),,decompressor.o) info.o obj-$(CONFIG_KERNEL_ZSTD) += clz_ctz.o
arch/s390/boot/boot.h +1 -0
@@ -74,6 +74,7 @@ void print_stacktrace(unsigned long sp);void error (char *m);int get_random (unsigned long limit,unsigned long *value);void boot_rb_dump (void ); +void __noreturn jump_to_kernel (psw_t *psw);#ifndef boot_fmt#define boot_fmt (fmt) fmt
arch/s390/boot/ipl_data.c +8 -1
@@ -16,7 +16,9 @@ struct ipl_lowcore {struct ccw0 ccwpgm[2 ];/* 0x0008 */ u8 fill[56 ];/* 0x0018 */ struct ccw0 ccwpgmcc[20 ];/* 0x0050 */ -u8 pad_0xf0[0x01a0 -0x00f0 ];/* 0x00f0 */ +u8 pad_0xf0[0x0140 -0x00f0 ];/* 0x00f0 */ +psw_t svc_old_psw;/* 0x0140 */ +u8 pad_0x150[0x01a0 -0x0150 ];/* 0x0150 */ psw_t restart_psw;/* 0x01a0 */ psw_t external_new_psw;/* 0x01b0 */ psw_t svc_new_psw;/* 0x01c0 */
@@ -75,6 +77,11 @@ static struct ipl_lowcore ipl_lowcore __used __section(".ipldata") = { [18] = CCW0(CCW_CMD_READ_IPL, 0x690, 0x50, CCW_FLAG_SLI | CCW_FLAG_CC), [19] = CCW0(CCW_CMD_READ_IPL, 0x6e0, 0x50, CCW_FLAG_SLI), }, +/* +* Let the GDB's lx-symbols command find the jump_to_kernel symbol +* without having to load decompressor symbols. +*/ + .svc_old_psw = { .mask = 0, .addr = (unsigned long)jump_to_kernel }, .restart_psw = { .mask = 0, .addr = IPL_START, }, .external_new_psw = { .mask = PSW_MASK_DISABLED, .addr = __LC_EXT_NEW_PSW, }, .svc_new_psw = { .mask = PSW_MASK_DISABLED, .addr = __LC_SVC_NEW_PSW, },
arch/s390/boot/startup.c +1 -1
@@ -642,5 +642,5 @@ void startup_kernel(void) psw.addr = __kaslr_offset + vmlinux.entry; psw.mask =PSW_KERNEL_BITS ;boot_debug ("Starting kernel at: 0x%016lx\n" , psw.addr); -__load_psw (psw); +jump_to_kernel (&psw); }
arch/s390/boot/trampoline.S new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <linux/linkage.h> + +# This function is identical to __load_psw(), but the lx-symbols GDB command +# puts a breakpoint on it, so it needs to be kept separate. +SYM_CODE_START(jump_to_kernel) + lpswe 0(%r2) +SYM_CODE_END(jump_to_kernel)
Signature · 1 line
2.49.0
PATCH 2/2 scripts/gdb/symbols: make lx-symbols skip the s390 decompressor
In reply to Ilya LeoshkevichWhen one starts QEMU with the -S flag and attaches GDB, the kernel is not yet loaded, and the current instruction is an entry point to the decompressor. In case the intention is to debug the early kernel boot, and not the decompressor, e.g., put a breakpoint on some kernel function and see all the invocations, one has to skip the decompressor.
There are many ways to do this, and so far people wrote private scripts or memorized certain command sequences.
Make it work out of the box like this:
$ gdb -ex 'target remote :6812' -ex 'source vmlinux-gdb.py' vmlinux
Remote debugging using :6812
0x0000000000010000 in ?? ()
(gdb) lx-symbols
loading vmlinux
(gdb) x/i $pc
=> 0x3ffe0100000 <startup_continue>: lghi %r2,0Implement this by reading the address of the jump_to_kernel() function from the lowcore, and step until DAT is turned on.
--- scripts/gdb/linux/symbols.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
scripts/gdb/linux/symbols.py +26 -0
@@ -84,6 +84,30 @@ def get_kerneloffset(): return None +def is_in_s390_decompressor(): + # DAT is always off in decompressor. Use this as an indicator. + # Note that in the kernel, DAT can be off during kexec() or restart. + # Accept this imprecision in order to avoid complicating things. + # It is unlikely that someone will run lx-symbols at these points. + pswm = int(gdb.parse_and_eval("$pswm")) + return (pswm & 0x0400000000000000) == 0 + + +def skip_decompressor(): + if utils.is_target_arch("s390"): + if is_in_s390_decompressor(): + # The address of the jump_to_kernel function is statically placed + # into svc_old_psw.addr (see ipl_data.c); read it from there. DAT + # is off, so we do not need to care about lowcore relocation. + svc_old_pswa = 0x148 + jump_to_kernel = int(gdb.parse_and_eval("*(unsigned long long *)" + + hex(svc_old_pswa))) + gdb.execute("tbreak *" + hex(jump_to_kernel)) + gdb.execute("continue") + while is_in_s390_decompressor(): + gdb.execute("stepi") + + class LxSymbols(gdb.Command): """(Re-)load symbols of Linux kernel and currently loaded modules.
@@ -204,6 +228,8 @@ lx-symbols command.""" saved_state['breakpoint'].enabled = saved_state['enabled'] def invoke(self, arg, from_tty): + skip_decompressor() + self.module_paths = [os.path.abspath(os.path.expanduser(p)) for p in arg.split()] self.module_paths.append(os.getcwd())
Signature · 1 line
2.49.0
Jan Kiszka
maintainerQuoted 19 lines · Ilya Leoshkevich
When one starts QEMU with the -S flag and attaches GDB, the kernel is not yet loaded, and the current instruction is an entry point to the decompressor. In case the intention is to debug the early kernel boot, and not the decompressor, e.g., put a breakpoint on some kernel function and see all the invocations, one has to skip the decompressor.
There are many ways to do this, and so far people wrote private scripts or memorized certain command sequences.
Make it work out of the box like this:
$ gdb -ex 'target remote :6812' -ex 'source vmlinux-gdb.py' vmlinux Remote debugging using :6812 0x0000000000010000 in ?? () (gdb) lx-symbols loading vmlinux (gdb) x/i $pc => 0x3ffe0100000 <startup_continue>: lghi %r2,0
Quoted 2 lines
Implement this by reading the address of the
jump_to_kernel()function from the lowcore, and step until DAT is turned on.
Why do you need to stepi until there? SW breakpoint will likely need to output of the decompressor first. No HW breakpoint available? Or missing <end-of-decompressor> address?
Quoted 42 lines
Signed-off-by Ilya Leoshkevich <[email protected]>--- scripts/gdb/linux/symbols.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)scripts/gdb/linux/symbols.py +24
-0@@ -84,6 +84,30 @@ def get_kerneloffset(): return None +def is_in_s390_decompressor(): + # DAT is always off in decompressor. Use this as an indicator. + # Note that in the kernel, DAT can be off during kexec() or restart. + # Accept this imprecision in order to avoid complicating things. + # It is unlikely that someone will run lx-symbols at these points. + pswm = int(gdb.parse_and_eval("$pswm")) + return (pswm & 0x0400000000000000) == 0 + + +def skip_decompressor(): + if utils.is_target_arch("s390"): + if is_in_s390_decompressor(): + # The address of the jump_to_kernel function is statically placed + # into svc_old_psw.addr (see ipl_data.c); read it from there. DAT + # is off, so we do not need to care about lowcore relocation. + svc_old_pswa = 0x148 + jump_to_kernel = int(gdb.parse_and_eval("*(unsigned long long *)" + + hex(svc_old_pswa))) + gdb.execute("tbreak *" + hex(jump_to_kernel)) + gdb.execute("continue") + while is_in_s390_decompressor(): + gdb.execute("stepi") + + class LxSymbols(gdb.Command): """(Re-)load symbols of Linux kernel and currently loaded modules.
scripts/gdb/linux/symbols.py lx-symbols command.""" · line 235
Quoted 8 lines
scripts/gdb/linux/symbols.py +2
-0@@ -204,6 +228,8 @@ lx-symbols command.""" saved_state['breakpoint'].enabled = saved_state['enabled'] def invoke(self, arg, from_tty): + skip_decompressor() + self.module_paths = [os.path.abspath(os.path.expanduser(p)) for p in arg.split()] self.module_paths.append(os.getcwd())
Otherwise, this series looks good to me and could be picked up if there is no better way to reach the end of the decompressor.
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Quoted 30 lines · Jan Kiszka
Quoted 25 lines · Ilya Leoshkevich
When one starts QEMU with the -S flag and attaches GDB, the kernel is
not yet loaded, and the current instruction is an entry point to the
decompressor. In case the intention is to debug the early kernel boot,
and not the decompressor, e.g., put a breakpoint on some kernel function and see all the invocations, one has to skip the decompressor.There are many ways to do this, and so far people wrote private scripts
or memorized certain command sequences.Make it work out of the box like this:
$ gdb -ex 'target remote :6812' -ex 'source vmlinux-gdb.py' vmlinux Remote debugging using :6812 0x0000000000010000 in ?? () (gdb) lx-symbols loading vmlinux (gdb) x/i $pc => 0x3ffe0100000 <startup_continue>: lghi %r2,0Quoted 3 lines
Implement this by reading the address of the
jump_to_kernel()function
from the lowcore, and step until DAT is turned on.
Quoted 5 lines
Why do you need to stepi until there? SW breakpoint will likely need to
output of the decompressor first. No HW breakpoint available? Or missing
<end-of-decompressor> address?
jump_to_kernel is <end-of-decompressor>; the code from this patch puts an SW breakpoint there, and this works fine.
However, the problem is that once jump_to_kernel is reached, even though the kernel is already in place, paging is still off.
jump_to_kernel contains a single "lpswe" instruction, which both jumps to kernel and enables paging, therefore, we must "stepi" over it. The loop is there just for future-proofing. Everything happens very quickly, there are no thousands of "stepi"s.
Quoted 57 lines
Quoted 57 lines
Signed-off-by Ilya Leoshkevich <[email protected]>---
scripts/gdb/linux/symbols.py | 26 ++++++++++++++++++++++++++1 file changed, 26 insertions(+)scripts/gdb/linux/symbols.py +0
-0@@ -84,6 +84,30 @@ def get_kerneloffset():return None
+defis_in_s390_decompressor():
+ # DAT is always off in decompressor. Use this as an indicator. + # Note that in the kernel, DAT can be off duringkexec()or restart.
+ # Accept this imprecision in order to avoid complicating things.
+ # It is unlikely that someone will run lx-symbols at these points.
+ pswm = int(gdb.parse_and_eval("$pswm"))
+ return (pswm &0x0400000000000000) == 0scripts/gdb/linux/symbols.py +6
-0+ + +def skip_decompressor(): + if utils.is_target_arch("s390"): + if is_in_s390_decompressor(): + # The address of the jump_to_kernel function isstatically placed
+ # into svc_old_psw.addr (seeipl_data.c); read it from there. DAT
+ # is off, so we do not need to care about lowcore relocation.
+svc_old_pswa=0x148
+jump_to_kernel= int(gdb.parse_and_eval("*(unsigned long long *)" +
+hex(svc_old_pswa)))
+gdb.execute("tbreak *" + hex(jump_to_kernel))+gdb.execute("continue")
+ whileis_in_s390_decompressor():
+gdb.execute("stepi")scripts/gdb/linux/symbols.py +2
-0+ +class LxSymbols(gdb.Command):
"""(Re-)load symbols of Linux kernel and currently loaded modules.scripts/gdb/linux/symbols.py +0
-0@@ -204,6 +228,8 @@ lx-symbols command."""saved_state['breakpoint'].enabled =
saved_state['enabled']
definvoke(self, arg, from_tty):
+skip_decompressor()
+
Quoted 8 lines
Quoted 4 lines
self.module_paths = [os.path.abspath(os.path.expanduser(p))
for p inarg.split()] self.module_paths.append(os.getcwd())Otherwise, this series looks good to me and could be picked up if there
is no better way to reach the end of the decompressor.
Could you please ack this patch if the explanation above is satisfactory? We would like to take this series via the s390 tree, if possible.
Quoted 1 line
Jan
Quoted 40 lines · Ilya Leoshkevich
Quoted 30 lines · Jan Kiszka
Quoted 25 lines · Ilya Leoshkevich
When one starts QEMU with the -S flag and attaches GDB, the kernel is
not yet loaded, and the current instruction is an entry point to the
decompressor. In case the intention is to debug the early kernel boot,
and not the decompressor, e.g., put a breakpoint on some kernel function and see all the invocations, one has to skip the decompressor.There are many ways to do this, and so far people wrote private scripts
or memorized certain command sequences.Make it work out of the box like this:
$ gdb -ex 'target remote :6812' -ex 'source vmlinux-gdb.py' vmlinux Remote debugging using :6812 0x0000000000010000 in ?? () (gdb) lx-symbols loading vmlinux (gdb) x/i $pc => 0x3ffe0100000 <startup_continue>: lghi %r2,0Quoted 3 lines
Implement this by reading the address of the
jump_to_kernel()function
from the lowcore, and step until DAT is turned on.Quoted 5 lines
Why do you need to stepi until there? SW breakpoint will likely need to
output of the decompressor first. No HW breakpoint available? Or missing
<end-of-decompressor> address?
jump_to_kernelis <end-of-decompressor>; the code from this patch puts an SW breakpoint there, and this works fine.
Quoted 8 lines
However, the problem is that once
jump_to_kernelis reached, even though the kernel is already in place, paging is still off.
jump_to_kernelcontains a single "lpswe" instruction, which both jumps to kernel and enables paging, therefore, we must "stepi" over it. The loop is there just for future-proofing. Everything happens very quickly, there are no thousands of "stepi"s.
OK, makes sense to me now.
Quoted 66 lines
Quoted 57 lines
Quoted 57 lines
Signed-off-by Ilya Leoshkevich <[email protected]>---
scripts/gdb/linux/symbols.py | 26 ++++++++++++++++++++++++++1 file changed, 26 insertions(+)scripts/gdb/linux/symbols.py +0
-0@@ -84,6 +84,30 @@ def get_kerneloffset():return None
+defis_in_s390_decompressor():
+ # DAT is always off in decompressor. Use this as an indicator. + # Note that in the kernel, DAT can be off duringkexec()or restart.
+ # Accept this imprecision in order to avoid complicating things.
+ # It is unlikely that someone will run lx-symbols at these points.
+ pswm = int(gdb.parse_and_eval("$pswm"))
+ return (pswm &0x0400000000000000) == 0scripts/gdb/linux/symbols.py +6
-0+ + +def skip_decompressor(): + if utils.is_target_arch("s390"): + if is_in_s390_decompressor(): + # The address of the jump_to_kernel function isstatically placed
+ # into svc_old_psw.addr (seeipl_data.c); read it from there. DAT
+ # is off, so we do not need to care about lowcore relocation.
+svc_old_pswa=0x148
+jump_to_kernel= int(gdb.parse_and_eval("*(unsigned long long *)" +
+hex(svc_old_pswa)))
+gdb.execute("tbreak *" + hex(jump_to_kernel))+gdb.execute("continue")
+ whileis_in_s390_decompressor():
+gdb.execute("stepi")scripts/gdb/linux/symbols.py +2
-0+ +class LxSymbols(gdb.Command):
"""(Re-)load symbols of Linux kernel and currently loaded modules.scripts/gdb/linux/symbols.py +0
-0@@ -204,6 +228,8 @@ lx-symbols command."""saved_state['breakpoint'].enabled =
saved_state['enabled']
definvoke(self, arg, from_tty):
+skip_decompressor()
+Quoted 8 lines
Quoted 4 lines
self.module_paths = [os.path.abspath(os.path.expanduser(p))
for p inarg.split()] self.module_paths.append(os.getcwd())Otherwise, this series looks good to me and could be picked up if there
is no better way to reach the end of the decompressor.
Quoted 4 lines
Could you please ack this patch if the explanation above is satisfactory? We would like to take this series via the s390 tree, if possible.
Sorry, should have also read your cover letter:
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Quoted 22 lines · Ilya Leoshkevich
Hi,
In order to debug the early s390 kernel boot, one has to skip the decompressor code, which requires some private scripts or memorized commands. This series makes it work out of the box with the lx-symbols command.
Patch 1 adds helper infrastructure to the s390 decompressor code; it is already acked by Heiko.
Patch 2 is the implementation; it would be great to have an Ack from one of the GDB scripts maintainers.
We would like to get this series via the s390 tree, if possible.
Best regards,
IlyaIlya Leoshkevich (2):
s390/boot: Introducejump_to_kernel()functionscripts/gdb/symbols: make lx-symbols skip the s390 decompressor
Quoted 8 lines
arch/s390/boot/Makefile | 2 +- arch/s390/boot/boot.h | 1 + arch/s390/boot/ipl_data.c | 9 ++++++++- arch/s390/boot/startup.c | 2 +- arch/s390/boot/trampoline.S | 9 +++++++++ scripts/gdb/linux/symbols.py | 26 ++++++++++++++++++++++++++ 6 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 arch/s390/boot/trampoline.S
Thanks!
Quoted 24 lines · Ilya Leoshkevich
Hi,
In order to debug the early s390 kernel boot, one has to skip the decompressor code, which requires some private scripts or memorized commands. This series makes it work out of the box with the lx- symbols
command.Patch 1 adds helper infrastructure to the s390 decompressor code; it is
already acked by Heiko.Patch 2 is the implementation; it would be great to have an Ack from one of the GDB scripts maintainers.
We would like to get this series via the s390 tree, if possible.
Best regards,
IlyaIlya Leoshkevich (2):
s390/boot: Introducejump_to_kernel()functionscripts/gdb/symbols: make lx-symbols skip the s390 decompressor
Quoted 8 lines
arch/s390/boot/Makefile | 2 +- arch/s390/boot/boot.h | 1 + arch/s390/boot/ipl_data.c | 9 ++++++++- arch/s390/boot/startup.c | 2 +- arch/s390/boot/trampoline.S | 9 +++++++++
scripts/gdb/linux/symbols.py| 26 ++++++++++++++++++++++++++6 files changed, 46 insertions(+), 3 deletions(-)create mode 100644
arch/s390/boot/trampoline.S
Gentle ping. Any feedback would be greatly appreciated.
Quoted 22 lines · Ilya Leoshkevich
Hi,
In order to debug the early s390 kernel boot, one has to skip the decompressor code, which requires some private scripts or memorized commands. This series makes it work out of the box with the lx-symbols command.
Patch 1 adds helper infrastructure to the s390 decompressor code; it is already acked by Heiko.
Patch 2 is the implementation; it would be great to have an Ack from one of the GDB scripts maintainers.
We would like to get this series via the s390 tree, if possible.
Best regards,
IlyaIlya Leoshkevich (2):
s390/boot: Introducejump_to_kernel()functionscripts/gdb/symbols: make lx-symbols skip the s390 decompressor
Quoted 8 lines
arch/s390/boot/Makefile | 2 +- arch/s390/boot/boot.h | 1 + arch/s390/boot/ipl_data.c | 9 ++++++++- arch/s390/boot/startup.c | 2 +- arch/s390/boot/trampoline.S | 9 +++++++++ scripts/gdb/linux/symbols.py | 26 ++++++++++++++++++++++++++ 6 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 arch/s390/boot/trampoline.S
Applied, thanks!