* [PATCH 0/3] scripts/gdb: Improve s390 support
@ 2025-12-04 16:34 Jens Remus
2025-12-04 16:34 ` [PATCH 1/3] scripts/gdb: add lx_current support for s390 Jens Remus
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jens Remus @ 2025-12-04 16:34 UTC (permalink / raw)
To: linux-kernel, linux-s390, Jan Kiszka, Kieran Bingham
Cc: Jens Remus, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Ilya Leoshkevich
Patch 1 adds $lx_current([CPU]) support for s390 to obtain the task of
the active context or a specific CPU.
Patch 2 adds a $lx_lowcore([CPU]) convenience function on s390 to obtain
the s390 lowcore of the active context of a specific CPU. It is based
on functionality introduced by patch 1.
Patch 3 adds a $lx_cpu() convenience function to obtain the CPU number
of the active context.
Regards,
Jens
Jens Remus (3):
scripts/gdb: add lx_current support for s390
scripts/gdb: add lx_lowcore convenience function on s390
scripts/gdb: add lx_cpu convenience function
scripts/gdb/linux/constants.py.in | 14 +++++++
scripts/gdb/linux/cpus.py | 67 ++++++++++++++++++++++++++++++-
2 files changed, 80 insertions(+), 1 deletion(-)
--
2.51.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] scripts/gdb: add lx_current support for s390
2025-12-04 16:34 [PATCH 0/3] scripts/gdb: Improve s390 support Jens Remus
@ 2025-12-04 16:34 ` Jens Remus
2025-12-04 16:34 ` [PATCH 2/3] scripts/gdb: add lx_lowcore convenience function on s390 Jens Remus
2025-12-04 16:34 ` [PATCH 3/3] scripts/gdb: add lx_cpu convenience function Jens Remus
2 siblings, 0 replies; 4+ messages in thread
From: Jens Remus @ 2025-12-04 16:34 UTC (permalink / raw)
To: linux-kernel, linux-s390, Jan Kiszka, Kieran Bingham
Cc: Jens Remus, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Ilya Leoshkevich
s390 uses lowcore field current_task. Depending on s390 machine feature
MFEATURE_LOWCORE the lowcore of the current CPU is either located at 0
or LOWCORE_ALT_ADDRESS. The lowcore address of any other CPUs can be
retrieved from lowcore_ptr[], which is indexed by CPU number. Note that
due to prefixing the lowcore of the current CPU cannot be addressed using
the address in lowcore_ptr[].
Add helpers to test for s390 machine features, test for s390 relocated
lowcore, and obtain the s390 lowcore address for a particular CPU. Use
these to implement lx_current support for s390.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
scripts/gdb/linux/constants.py.in | 14 +++++++++++++
scripts/gdb/linux/cpus.py | 35 ++++++++++++++++++++++++++++++-
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in
index c3886739a028..68c45fb27635 100644
--- a/scripts/gdb/linux/constants.py.in
+++ b/scripts/gdb/linux/constants.py.in
@@ -24,6 +24,10 @@
#include <linux/slab.h>
#include <linux/threads.h>
#include <linux/vmalloc.h>
+#ifdef CONFIG_S390
+#include <asm/lowcore.h>
+#include <asm/machine.h>
+#endif
/* We need to stringify expanded macros so that they can be parsed */
@@ -122,6 +126,15 @@ LX_GDBPARSED(SLAB_CACHE_DMA32)
LX_GDBPARSED(SLAB_STORE_USER)
LX_GDBPARSED(SLAB_PANIC)
+/* asm/lowcore.h */
+if IS_BUILTIN(CONFIG_S390):
+ LX_GDBPARSED(LOWCORE_ALT_ADDRESS)
+
+/* asm/machine.h */
+if IS_BUILTIN(CONFIG_S390):
+ LX_VALUE(MFEATURE_LOWCORE)
+ LX_GDBPARSED(MAX_MFEATURE_BIT)
+
/* Kernel Configs */
LX_CONFIG(CONFIG_GENERIC_CLOCKEVENTS)
LX_CONFIG(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
@@ -170,3 +183,4 @@ LX_CONFIG(CONFIG_PAGE_OWNER)
LX_CONFIG(CONFIG_SLUB_DEBUG)
LX_CONFIG(CONFIG_SLAB_FREELIST_HARDENED)
LX_CONFIG(CONFIG_MMU)
+LX_CONFIG(CONFIG_S390)
diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
index 6edf4ef61636..12bf37d6a4e5 100644
--- a/scripts/gdb/linux/cpus.py
+++ b/scripts/gdb/linux/cpus.py
@@ -13,7 +13,7 @@
import gdb
-from linux import tasks, utils
+from linux import constants, tasks, utils
task_type = utils.CachedType("struct task_struct")
@@ -206,6 +206,11 @@ def get_current_task(cpu):
if (scratch_reg.cast(utils.get_ulong_type()) > current_tp.cast(utils.get_ulong_type())):
current_task = scratch_reg.cast(task_ptr_type)
+ return current_task.dereference()
+ elif utils.is_target_arch("s390"):
+ lowcore = s390_lowcore(cpu)
+ current_task_addr = lowcore["current_task"]
+ current_task = current_task_addr.cast(task_ptr_type)
return current_task.dereference()
else:
raise gdb.GdbError("Sorry, obtaining the current task is not yet "
@@ -225,3 +230,31 @@ number. If CPU is omitted, the CPU of the current context is used."""
LxCurrentFunc()
+
+
+def s390_machine_feature(nr):
+ if nr >= constants.LX_MAX_MFEATURE_BIT:
+ raise gdb.GdbError("Sorry, the s390 machine feature number is "
+ "out of bounds.")
+
+ machine_features = gdb.parse_and_eval("machine_features")
+ bits_per_entry = machine_features[0].type.sizeof * 8
+ entry = machine_features[nr // bits_per_entry]
+ return (entry & (1 << (nr % bits_per_entry))) != 0
+
+
+def s390_machine_has_relocated_lowcore():
+ return s390_machine_feature(constants.LX_MFEATURE_LOWCORE)
+
+
+def s390_lowcore(cpu):
+ if cpu == -1 or cpu == get_current_cpu():
+ if s390_machine_has_relocated_lowcore():
+ lowcore = constants.LX_LOWCORE_ALT_ADDRESS
+ else:
+ lowcore = gdb.Value(0)
+ else:
+ lowcore = gdb.parse_and_eval("lowcore_ptr[{0}]".format(str(cpu)))
+
+ lowcore_ptr_type = gdb.lookup_type("struct lowcore").pointer()
+ return lowcore.cast(lowcore_ptr_type)
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] scripts/gdb: add lx_lowcore convenience function on s390
2025-12-04 16:34 [PATCH 0/3] scripts/gdb: Improve s390 support Jens Remus
2025-12-04 16:34 ` [PATCH 1/3] scripts/gdb: add lx_current support for s390 Jens Remus
@ 2025-12-04 16:34 ` Jens Remus
2025-12-04 16:34 ` [PATCH 3/3] scripts/gdb: add lx_cpu convenience function Jens Remus
2 siblings, 0 replies; 4+ messages in thread
From: Jens Remus @ 2025-12-04 16:34 UTC (permalink / raw)
To: linux-kernel, linux-s390, Jan Kiszka, Kieran Bingham
Cc: Jens Remus, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Ilya Leoshkevich
lx_lowcore is a convenience function to retrieve the lowcore of the
active context or a specific CPU on s390.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
scripts/gdb/linux/cpus.py | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
index 12bf37d6a4e5..3e17550cd577 100644
--- a/scripts/gdb/linux/cpus.py
+++ b/scripts/gdb/linux/cpus.py
@@ -258,3 +258,20 @@ def s390_lowcore(cpu):
lowcore_ptr_type = gdb.lookup_type("struct lowcore").pointer()
return lowcore.cast(lowcore_ptr_type)
+
+
+class LxLowcoreFunc(gdb.Function):
+ """Return current s390 lowcore.
+
+$lx_lowcore([CPU]): Return the s390 lowcore for the given CPU number.
+If CPU is omitted, the CPU of the current context is used."""
+
+ def __init__(self):
+ super(LxLowcoreFunc, self).__init__("lx_lowcore")
+
+ def invoke(self, cpu=-1):
+ return s390_lowcore(cpu)
+
+
+if constants.LX_CONFIG_S390:
+ LxLowcoreFunc()
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] scripts/gdb: add lx_cpu convenience function
2025-12-04 16:34 [PATCH 0/3] scripts/gdb: Improve s390 support Jens Remus
2025-12-04 16:34 ` [PATCH 1/3] scripts/gdb: add lx_current support for s390 Jens Remus
2025-12-04 16:34 ` [PATCH 2/3] scripts/gdb: add lx_lowcore convenience function on s390 Jens Remus
@ 2025-12-04 16:34 ` Jens Remus
2 siblings, 0 replies; 4+ messages in thread
From: Jens Remus @ 2025-12-04 16:34 UTC (permalink / raw)
To: linux-kernel, linux-s390, Jan Kiszka, Kieran Bingham
Cc: Jens Remus, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Ilya Leoshkevich
lx_cpu is a convenience function to retrieve the current CPU number.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
scripts/gdb/linux/cpus.py | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
index 3e17550cd577..fa05fc30a090 100644
--- a/scripts/gdb/linux/cpus.py
+++ b/scripts/gdb/linux/cpus.py
@@ -119,6 +119,21 @@ def each_active_cpu():
yield cpu
+class LxCpuFunc(gdb.Function):
+ """Return current CPU number.
+
+$lx_cpu(): Return the current CPU number."""
+
+ def __init__(self):
+ super(LxCpuFunc, self).__init__("lx_cpu")
+
+ def invoke(self):
+ return get_current_cpu()
+
+
+LxCpuFunc()
+
+
class LxCpus(gdb.Command):
"""List CPU status arrays
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-04 16:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-04 16:34 [PATCH 0/3] scripts/gdb: Improve s390 support Jens Remus
2025-12-04 16:34 ` [PATCH 1/3] scripts/gdb: add lx_current support for s390 Jens Remus
2025-12-04 16:34 ` [PATCH 2/3] scripts/gdb: add lx_lowcore convenience function on s390 Jens Remus
2025-12-04 16:34 ` [PATCH 3/3] scripts/gdb: add lx_cpu convenience function Jens Remus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox