[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251204163425.370783-2-jremus@linux.ibm.com>
Date: Thu, 4 Dec 2025 17:34:23 +0100
From: Jens Remus <jremus@...ux.ibm.com>
To: linux-kernel@...r.kernel.org, linux-s390@...r.kernel.org,
Jan Kiszka <jan.kiszka@...mens.com>,
Kieran Bingham <kbingham@...nel.org>
Cc: Jens Remus <jremus@...ux.ibm.com>, Heiko Carstens <hca@...ux.ibm.com>,
Vasily Gorbik <gor@...ux.ibm.com>,
Alexander Gordeev <agordeev@...ux.ibm.com>,
Ilya Leoshkevich <iii@...ux.ibm.com>
Subject: [PATCH 1/3] scripts/gdb: add lx_current support for s390
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@...ux.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
Powered by blists - more mailing lists