selftests/powerpc: exec() with suspended transaction
authorCyril Bur <cyrilbur@gmail.com>
Wed, 29 Jun 2016 11:41:51 +0000 (21:41 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 26 Jul 2016 04:28:22 +0000 (14:28 +1000)
Perform an exec() class syscall with a suspended transaction.

This is a test for the bug we fixed in 8e96a87c5431 ("powerpc/tm: Always
reclaim in start_thread() for exec() class syscalls").

Signed-off-by: Cyril Bur <cyrilbur@gmail.com>
[mpe: Fix build errors, use a single binary for the test]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
tools/testing/selftests/powerpc/tm/.gitignore
tools/testing/selftests/powerpc/tm/Makefile
tools/testing/selftests/powerpc/tm/tm-exec.c [new file with mode: 0644]
tools/testing/selftests/powerpc/tm/tm-syscall.c
tools/testing/selftests/powerpc/tm/tm.h

index bb942db845bfa4a235d1bde46cd3cc5c6d43d934..82c0a9ce6e748129ffc3794be52b913626d66814 100644 (file)
@@ -6,3 +6,4 @@ tm-vmxcopy
 tm-fork
 tm-tar
 tm-tmspr
+tm-exec
index d0505dbd22d5968749a084ab7c241f4891dc63ce..9d301d785d9ea137afd20517fc6c875816043410 100644 (file)
@@ -1,11 +1,14 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack tm-vmxcopy tm-fork tm-tar tm-tmspr
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \
+       tm-vmxcopy tm-fork tm-tar tm-tmspr tm-exec tm-execed
 
 all: $(TEST_PROGS)
 
 $(TEST_PROGS): ../harness.c ../utils.c
 
+CFLAGS += -mhtm
+
 tm-syscall: tm-syscall-asm.S
-tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include
+tm-syscall: CFLAGS += -I../../../../../usr/include
 tm-tmspr: CFLAGS += -pthread
 
 include ../../lib.mk
diff --git a/tools/testing/selftests/powerpc/tm/tm-exec.c b/tools/testing/selftests/powerpc/tm/tm-exec.c
new file mode 100644 (file)
index 0000000..3d27fa0
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2016, Cyril Bur, IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * Syscalls can be performed provided the transactions are suspended.
+ * The exec() class of syscall is unique as a new process is loaded.
+ *
+ * It makes little sense for after an exec() call for the previously
+ * suspended transaction to still exist.
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <inttypes.h>
+#include <libgen.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "utils.h"
+#include "tm.h"
+
+static char *path;
+
+static int test_exec(void)
+{
+       SKIP_IF(!have_htm());
+
+       asm __volatile__(
+               "tbegin.;"
+               "blt    1f; "
+               "tsuspend.;"
+               "1: ;"
+               : : : "memory");
+
+       execl(path, "tm-exec", "--child", NULL);
+
+       /* Shouldn't get here */
+       perror("execl() failed");
+       return 1;
+}
+
+static int after_exec(void)
+{
+       asm __volatile__(
+               "tbegin.;"
+               "blt    1f;"
+               "tsuspend.;"
+               "1: ;"
+               : : : "memory");
+
+       FAIL_IF(failure_is_nesting());
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       path = argv[0];
+
+       if (argc > 1 && strcmp(argv[1], "--child") == 0)
+               return after_exec();
+
+       return test_harness(test_exec, "tm_exec");
+}
index 60560cb20e380701fcd58aa5d19f749e479c9eb6..454b965a2db34a14eed0acbbfabb34cea31a97bd 100644 (file)
@@ -27,21 +27,6 @@ unsigned retries = 0;
 #define TEST_DURATION 10 /* seconds */
 #define TM_RETRIES 100
 
-long failure_code(void)
-{
-       return __builtin_get_texasru() >> 24;
-}
-
-bool failure_is_persistent(void)
-{
-       return (failure_code() & TM_CAUSE_PERSISTENT) == TM_CAUSE_PERSISTENT;
-}
-
-bool failure_is_syscall(void)
-{
-       return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL;
-}
-
 pid_t getppid_tm(bool suspend)
 {
        int i;
index 24144b25772cf92d74fc74415bfcc6dffa08e14a..60318bad7d7af0335e8bbf691747c9ebad899f45 100644 (file)
@@ -6,8 +6,9 @@
 #ifndef _SELFTESTS_POWERPC_TM_TM_H
 #define _SELFTESTS_POWERPC_TM_TM_H
 
-#include <stdbool.h>
+#include <asm/tm.h>
 #include <asm/cputable.h>
+#include <stdbool.h>
 
 #include "../utils.h"
 
@@ -31,4 +32,24 @@ static inline bool have_htm_nosc(void)
 #endif
 }
 
+static inline long failure_code(void)
+{
+       return __builtin_get_texasru() >> 24;
+}
+
+static inline bool failure_is_persistent(void)
+{
+       return (failure_code() & TM_CAUSE_PERSISTENT) == TM_CAUSE_PERSISTENT;
+}
+
+static inline bool failure_is_syscall(void)
+{
+       return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL;
+}
+
+static inline bool failure_is_nesting(void)
+{
+       return (__builtin_get_texasru() & 0x400000);
+}
+
 #endif /* _SELFTESTS_POWERPC_TM_TM_H */