From: dm.chestnykh@gmail.com
To: ltp@lists.linux.it
Cc: Dmitry Chestnykh <dm.chestnykh@gmail.com>
Subject: [LTP] [PATCH v6] arch_prctl: add ARCH_GET_FS, ARCH_GET_GS tests
Date: Sat, 10 Oct 2026 09:42:40 +0300 [thread overview]
Message-ID: <20261010064240.2467-1-dm.chestnykh@gmail.com> (raw)
In-Reply-To: <20261010063824.2073-1-dm.chestnykh@gmail.com>
From: Dmitry Chestnykh <dm.chestnykh@gmail.com>
Signed-off-by: Dmitry Chestnykh <dm.chestnykh@gmail.com>
---
configure.ac | 1 +
include/lapi/arch_prctl.h | 9 ++
runtest/syscalls | 1 +
.../kernel/syscalls/arch_prctl/.gitignore | 1 +
.../kernel/syscalls/arch_prctl/arch_prctl02.c | 122 ++++++++++++++++++
5 files changed, 134 insertions(+)
create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl02.c
diff --git a/configure.ac b/configure.ac
index e979de0e7..9db3e06ad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,6 +53,7 @@ AC_CHECK_HEADERS_ONCE([ \
aio.h \
asm/ldt.h \
asm/prctl.h \
+ asm/hwcap2.h \
cpuid.h \
emmintrin.h \
ifaddrs.h \
diff --git a/include/lapi/arch_prctl.h b/include/lapi/arch_prctl.h
index a4e7f8458..6d8376e58 100644
--- a/include/lapi/arch_prctl.h
+++ b/include/lapi/arch_prctl.h
@@ -19,4 +19,13 @@
# define ARCH_SET_CPUID 0x1012
#endif
+#ifdef __x86_64__
+# ifdef HAVE_ASM_HWCAP2_H
+# include <asm/hwcap2.h>
+# endif /* HAVE_ASM_HWCAP2_H */
+# ifndef HWCAP2_FSGSBASE
+# define HWCAP2_FSGSBASE (1UL << 1)
+# endif /* HWCAP2_FSGSBASE */
+#endif /* __x86_64__ */
+
#endif /* LAPI_ARCH_PRCTL_H__ */
diff --git a/runtest/syscalls b/runtest/syscalls
index accdf2df9..f2f2a0602 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -32,6 +32,7 @@ alarm06 alarm06
alarm07 alarm07
arch_prctl01 arch_prctl01
+arch_prctl02 arch_prctl02
bind01 bind01
bind02 bind02
diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
index 24871e249..72187b8b4 100644
--- a/testcases/kernel/syscalls/arch_prctl/.gitignore
+++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
@@ -1 +1,2 @@
/arch_prctl01
+/arch_prctl02
diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl02.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl02.c
new file mode 100644
index 000000000..81295234d
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl02.c
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Dmitry Chestnykh <dm.chestnykh@gmail.com>
+ * Author: Dmitry Chestnykh <dm.chestnykh@gmail.com>
+ */
+
+/*\
+ * Test that ``ARCH_GET_FS`` and ``ARCH_GET_GS`` return the same bases read independently
+ * by RDFSBASE and RDGSBASE.
+ */
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/arch_prctl.h"
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __x86_64__
+
+#ifdef HAVE_GETAUXVAL
+# include <sys/auxv.h>
+#endif
+
+static int arch_prctl_get(int code, unsigned long long *out)
+{
+ return tst_syscall(__NR_arch_prctl, code, out);
+}
+
+static int set_gs(unsigned long long val)
+{
+ return tst_syscall(__NR_arch_prctl, ARCH_SET_GS, val);
+}
+
+static bool tag;
+
+static void setup(void)
+{
+ unsigned long long v = 0;
+
+#ifdef AT_HWCAP2
+ v = getauxval(AT_HWCAP2);
+#endif
+ tag = v & HWCAP2_FSGSBASE ? true : false;
+}
+
+#define READ_FS_BASE() ({ \
+ unsigned long long __res_fs; \
+ asm volatile("rdfsbase %0" : "=r"(__res_fs)); \
+ __res_fs; \
+})
+
+#define READ_GS_BASE() ({ \
+ unsigned long long __res_gs; \
+ asm volatile("rdgsbase %0" : "=r"(__res_gs)); \
+ __res_gs; \
+})
+
+static void test_fs(void)
+{
+ unsigned long long fs = READ_FS_BASE();
+ unsigned long long fs_prctl;
+
+ TST_EXP_PASS_SILENT(arch_prctl_get(ARCH_GET_FS, &fs_prctl));
+ if (TST_PASS)
+ TST_EXP_EQ_LU(fs_prctl, fs);
+}
+
+static void test_gs(void)
+{
+ unsigned long long gs, gs_prctl, orig_gs;
+#define TEST_GS_BASE() do { \
+ gs = READ_GS_BASE(); \
+ TST_EXP_PASS_SILENT(arch_prctl_get(ARCH_GET_GS, &gs_prctl)); \
+ if (TST_PASS) { \
+ TST_EXP_EQ_LU(gs_prctl, gs); \
+ } \
+} while (0)
+
+ TEST_GS_BASE();
+ orig_gs = gs;
+
+ if (gs == 0) {
+ unsigned long long test_gs = 0xabababab;
+
+ TST_EXP_PASS_SILENT(set_gs(test_gs));
+ if (TST_PASS)
+ TEST_GS_BASE();
+
+ set_gs(orig_gs);
+ }
+}
+
+static struct tcase {
+ unsigned int idx;
+ void (*test_fn)(void);
+} tcases[] = {
+ {0, test_fs},
+ {1, test_gs}
+};
+
+static void run(unsigned int index)
+{
+ if (!tag)
+ tst_brk(TCONF, "rdfsbase/rdgsbase are not supported/enabled");
+
+ struct tcase *tc = &tcases[index];
+ (*tc->test_fn)();
+}
+
+static struct tst_test test = {
+ .test = run,
+ .setup = setup,
+ .tcnt = ARRAY_SIZE(tcases),
+ .min_kver = "5.9",
+ .supported_archs = (const char *const []){"x86_64", NULL}
+};
+
+#else
+
+TST_TEST_TCONF("Tests needs x86_64 CPU");
+
+#endif /* __x86_64__ */
--
2.56.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-10-10 6:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 19:47 [LTP] [PATCH] arch_prctl: add ARCH_GET_FS, ARCH_GET_GS tests dm.chestnykh
2026-10-09 10:12 ` [LTP] " linuxtestproject.agent
2026-10-09 15:52 ` [LTP] [PATCH v2] " dm.chestnykh
2026-10-09 17:27 ` [LTP] " linuxtestproject.agent
2026-10-09 18:35 ` [LTP] [PATCH v3] " dm.chestnykh
2026-10-09 18:39 ` [LTP] [PATCH v4] " dm.chestnykh
2026-10-09 22:23 ` [LTP] " linuxtestproject.agent
2026-10-10 6:38 ` [LTP] [PATCH v5] " dm.chestnykh
2026-10-10 6:42 ` dm.chestnykh [this message]
2026-10-10 9:35 ` [LTP] " linuxtestproject.agent
2026-10-10 9:44 ` [LTP] [PATCH v7] " dm.chestnykh
2026-10-10 15:49 ` [LTP] " linuxtestproject.agent
2026-10-10 9:35 ` linuxtestproject.agent
2026-10-09 22:23 ` linuxtestproject.agent
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=20261010064240.2467-1-dm.chestnykh@gmail.com \
--to=dm.chestnykh@gmail.com \
--cc=ltp@lists.linux.it \
/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