From: Jens Remus <jremus@linux.ibm.com>
To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org,
Jan Kiszka <jan.kiszka@siemens.com>,
Kieran Bingham <kbingham@kernel.org>
Cc: Jens Remus <jremus@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH 1/3] scripts/gdb: add lx_current support for s390
Date: Thu, 4 Dec 2025 17:34:23 +0100 [thread overview]
Message-ID: <20251204163425.370783-2-jremus@linux.ibm.com> (raw)
In-Reply-To: <20251204163425.370783-1-jremus@linux.ibm.com>
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
next prev parent reply other threads:[~2025-12-04 16:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-04 16:34 [PATCH 0/3] scripts/gdb: Improve s390 support Jens Remus
2025-12-04 16:34 ` Jens Remus [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251204163425.370783-2-jremus@linux.ibm.com \
--to=jremus@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=jan.kiszka@siemens.com \
--cc=kbingham@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®