tests/tcg/s390x: Test STCKF condition code on a faulting store
Add a small test to prevent regressions. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Reviewed-by: Eric Farman <farman@linux.ibm.com> Link: https://lore.kernel.org/qemu-devel/20260714203206.363028-3-iii@linux.ibm.com Signed-off-by: Eric Farman <farman@linux.ibm.com>
Ilya Leoshkevich committed
Jul 14, 2026 at 22:29 UTC
e79ea4472691fd7f7b3436dafbabd17c78fc8bf4
2 files changed
+45
tests/tcg/s390x/Makefile.target
+1
@@ -50,6 +50,7 @@ TESTS+=cvb
50
TESTS+=ts
51
TESTS+=ex-smc
52
TESTS+=divide-to-integer
53
+TESTS+=stckf
54
55
cdsg: CFLAGS+=-pthread
56
cdsg: LDFLAGS+=-pthread
tests/tcg/s390x/stckf.c
new
+44
@@ -0,0 +1,44 @@
1
+/*
2
+ * Test that a faulting STORE CLOCK FAST does not clobber the condition code.
3
+ *
4
+ * SPDX-License-Identifier: GPL-2.0-or-later
5
+ */
6
+#include <assert.h>
7
+#include <signal.h>
8
+#include <stdlib.h>
9
+#include <unistd.h>
10
+
11
+static void handle_sigsegv(int sig, siginfo_t *info, void *ucontext)
12
+{
13
+ mcontext_t *mcontext = &((ucontext_t *)ucontext)->uc_mcontext;
14
+
15
+ /* The condition code must be the one set by SLGR, not garbage. */
16
+ _exit(((mcontext->psw.mask >> 44) & 3) == 3 ? EXIT_SUCCESS : EXIT_FAILURE);
17
+}
18
+
19
+int main(void)
20
+{
21
+ struct sigaction act = {
22
+ .sa_sigaction = handle_sigsegv,
23
+ .sa_flags = SA_SIGINFO,
24
+ };
25
+ int err;
26
+
27
+ err = sigaction(SIGSEGV, &act, NULL);
28
+ assert(err == 0);
29
+
30
+ asm volatile(
31
+ "lghi %%r1,100\n"
32
+ "lghi %%r2,0\n"
33
+ "clgr %%r1,%%r2\n" /* CC_OP_LTUGTU_64 */
34
+ /* cc_src=100 is not valid for CC_OP_SUBU */
35
+ "ipm %%r0\n" /* force cc_src to env */
36
+ "lghi %%r3,5\n"
37
+ "lghi %%r4,3\n"
38
+ "slgr %%r3,%%r4\n" /* CC_OP_SUBU, cc=3 */
39
+ "lghi %%r5,0\n"
40
+ "stckf 0(%%r5)\n" /* faults; cc must stay 3 */
41
+ : : : "r0", "r1", "r2", "r3", "r4", "r5", "cc", "memory");
42
+
43
+ return EXIT_FAILURE;
44
+}