linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Sam Bobroff <sam.bobroff@au1.ibm.com>
To: mpe@ellerman.id.au, benh@kernel.crashing.org
Cc: mikey@neuling.org, azanella@linux.vnet.ibm.com,
	linuxppc-dev@lists.ozlabs.org, matt@ozlabs.org
Subject: [PATCH 3/3] selftests/powerpc: Add transactional syscall test
Date: Thu, 19 Mar 2015 15:43:48 +1100	[thread overview]
Message-ID: <b4a4ea23b20098512cf350b97ce98e0d1ea58531.1426740212.git.sam.bobroff@au1.ibm.com> (raw)
In-Reply-To: <cover.1426740212.git.sam.bobroff@au1.ibm.com>
In-Reply-To: <cover.1426740212.git.sam.bobroff@au1.ibm.com>

Check that a syscall made during an active transaction will fail with
the correct failure code and that one made during a suspended
transaction will succeed.

Signed-off-by: Sam Bobroff <sam.bobroff@au1.ibm.com>
---
 tools/testing/selftests/powerpc/tm/Makefile     |    3 +-
 tools/testing/selftests/powerpc/tm/tm-syscall.c |  113 +++++++++++++++++++++++
 2 files changed, 115 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-syscall.c

diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index 2cede23..d8dab0d 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,5 @@
-PROGS := tm-resched-dscr
+PROGS := tm-resched-dscr tm-syscall
+CFLAGS:=$(CFLAGS) -mhtm -Wl,-z,now
 
 all: $(PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-syscall.c b/tools/testing/selftests/powerpc/tm/tm-syscall.c
new file mode 100644
index 0000000..7c60e53
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-syscall.c
@@ -0,0 +1,113 @@
+/* Test the kernel's system call code to ensure that a system call
+ * made from within an active HTM transaction is aborted with the
+ * correct failure code.
+ * Conversely, ensure that a system call made from within a
+ * suspended transaction can succeed.
+ *
+ * It is important to compile with -Wl,-z,now to prevent
+ * lazy symbol resolution from affecting the results.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <asm/tm.h>
+#include <asm/cputable.h>
+#include <linux/auxvec.h>
+
+#include "utils.h"
+
+#define TM_RETRIES 10
+#define TM_TEST_RUNS 1000
+
+int t_failure_persistent(void)
+{
+	long texasr = __builtin_get_texasr();
+	long failure_code = (texasr >> 56) & 0xff;
+
+	return failure_code & TM_CAUSE_PERSISTENT;
+}
+
+int t_failure_code_syscall(void)
+{
+	long texasr = __builtin_get_texasr();
+	long failure_code = (texasr >> 56) & 0xff;
+
+	return (failure_code & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL;
+}
+
+int t_active_getppid(void)
+{
+	int i;
+
+	for (i = 0; i < TM_RETRIES; i++) {
+		if (__builtin_tbegin(0)) {
+			getppid();
+			__builtin_tend(0);
+			return 1;
+		}
+		if (t_failure_persistent())
+			return 0;
+	}
+	return 0;
+}
+
+int t_active_getppid_test(void)
+{
+	int i;
+
+	for (i = 0; i < TM_TEST_RUNS; i++) {
+		if (t_active_getppid())
+			return 0;
+		if (!t_failure_persistent())
+			return 0;
+		if (!t_failure_code_syscall())
+			return 0;
+	}
+	return 1;
+}
+
+int t_suspended_getppid(void)
+{
+	int i;
+
+	for (i = 0; i < TM_RETRIES; i++) {
+		if (__builtin_tbegin(0)) {
+			__builtin_tsuspend();
+			getppid();
+			__builtin_tresume();
+			__builtin_tend(0);
+			return 1;
+		}
+		if (t_failure_persistent())
+			return 0;
+	}
+	return 0;
+}
+
+int t_suspended_getppid_test(void)
+{
+	int i;
+
+	for (i = 0; i < TM_TEST_RUNS; i++) {
+		if (!t_suspended_getppid())
+			return 0;
+	}
+	return 1;
+}
+
+int tm_syscall(void)
+{
+	SKIP_IF(!((long)get_auxv_entry(AT_HWCAP2) & PPC_FEATURE2_HTM));
+	setbuf(stdout, 0);
+	FAIL_IF(!t_active_getppid_test());
+	printf("%d active transactions correctly aborted.\n", TM_TEST_RUNS);
+	FAIL_IF(!t_suspended_getppid_test());
+	printf("%d suspended transactions succeeded.\n", TM_TEST_RUNS);
+	return 0;
+}
+
+int main(void)
+{
+	return test_harness(tm_syscall, "tm_syscall");
+}
+
-- 
1.7.10.4

  parent reply	other threads:[~2015-03-19  4:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19  4:43 [PATCH 0/3] powerpc/tm: Abort syscalls in active transactions Sam Bobroff
2015-03-19  4:43 ` [PATCH 1/3] " Sam Bobroff
2015-03-19  5:01   ` Michael Neuling
2015-03-20  9:04   ` Anshuman Khandual
2015-03-24  2:04     ` Michael Ellerman
2015-03-24  4:26       ` Anshuman Khandual
2015-03-24 13:02         ` Michael Ellerman
2015-03-19  4:43 ` [PATCH 2/3] selftests/powerpc: Move get_auxv_entry() to harness.c Sam Bobroff
2015-03-19  4:43 ` Sam Bobroff [this message]
2015-03-20  9:25   ` [PATCH 3/3] selftests/powerpc: Add transactional syscall test Anshuman Khandual
2015-03-24  1:52     ` Sam Bobroff
2015-03-24  2:02       ` Michael Ellerman
2015-03-30  0:06         ` Sam Bobroff

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=b4a4ea23b20098512cf350b97ce98e0d1ea58531.1426740212.git.sam.bobroff@au1.ibm.com \
    --to=sam.bobroff@au1.ibm.com \
    --cc=azanella@linux.vnet.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=matt@ozlabs.org \
    --cc=mikey@neuling.org \
    --cc=mpe@ellerman.id.au \
    /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;
as well as URLs for NNTP newsgroup(s).