* [PATCH] selftest/powerpc: Add test for sigreturn in transaction
@ 2016-08-22 16:53 Laurent Dufour
2016-08-22 23:14 ` Cyril Bur
2018-03-14 9:27 ` Michael Ellerman
0 siblings, 2 replies; 3+ messages in thread
From: Laurent Dufour @ 2016-08-22 16:53 UTC (permalink / raw)
To: linuxppc-dev, mpe; +Cc: cyrilbur, wei.guo.simon
Ensure that kernel is throwing away the suspended transaction when
sigreturn() is called otherwise it if fails to restore the signal
frame's TM SPRS.
Signed-off-by: Laurent Dufour <ldufour@linux.vnet.ibm.com>
---
tools/testing/selftests/powerpc/tm/Makefile | 2 +-
tools/testing/selftests/powerpc/tm/tm-sigreturn.c | 89 +++++++++++++++++++++++
2 files changed, 90 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/powerpc/tm/tm-sigreturn.c
diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index 9d301d785d9e..5e0396d79c8a 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,5 +1,5 @@
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
+ tm-vmxcopy tm-fork tm-tar tm-tmspr tm-exec tm-execed tm-sigreturn
all: $(TEST_PROGS)
diff --git a/tools/testing/selftests/powerpc/tm/tm-sigreturn.c b/tools/testing/selftests/powerpc/tm/tm-sigreturn.c
new file mode 100644
index 000000000000..43fa83de23a5
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-sigreturn.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2015, Laurent Dufour, IBM Corp.
+ * Licensed under GPLv2.
+ *
+ * Test the kernel's signal returning code to check reclaim is done if
+ * the sigreturn() is called while in a transaction (suspended since active
+ * is already dropped trough the system call path).
+ *
+ * The kernel must discard the transaction when entering sigreturn,
+ * since restoring the potential TM SPRS from the signal frame is requiring to
+ * not be in a transaction.
+ */
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <signal.h>
+#include <string.h>
+
+#include "utils.h"
+#include "tm.h"
+
+
+void handler(int sig)
+{
+ uint64_t ret;
+
+ asm __volatile__(
+ "li 3,1 ;"
+ "tbegin. ;"
+ "beq 1f ;"
+ "li 3,0 ;"
+ "tsuspend. ;"
+ "1: ;"
+ "std%X[ret] 3, %[ret] ;"
+ : [ret]"=m"(ret)
+ :
+ : "memory", "3", "cr0");
+
+ if (ret)
+ exit(1);
+
+ /*
+ * We return from the signal handle while in a suspended transaction
+ */
+}
+
+
+int tm_sigreturn(void)
+{
+ struct sigaction sa;
+ uint64_t ret = 0;
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = handler;
+ sigemptyset(&sa.sa_mask);
+
+ if (sigaction(SIGSEGV, &sa, NULL))
+ exit(1);
+
+ asm __volatile__(
+ "tbegin. ;"
+ "beq 1f ;"
+ "li 3,0 ;"
+ "std 3,0(3) ;" /* trigger SEGV */
+ "li 3,1 ;"
+ "std%X[ret] 3,%[ret] ;"
+ "tend. ;"
+ "b 2f ;"
+ "1: ;"
+ "li 3,2 ;"
+ "std%X[ret] 3,%[ret] ;"
+ "2: ;"
+ : [ret]"=m"(ret)
+ :
+ : "memory", "3", "cr0");
+
+ if (ret != 2)
+ exit(1);
+
+ exit(0);
+}
+
+int main(void)
+{
+ return test_harness(tm_sigreturn, "tm_sigreturn");
+}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selftest/powerpc: Add test for sigreturn in transaction
2016-08-22 16:53 [PATCH] selftest/powerpc: Add test for sigreturn in transaction Laurent Dufour
@ 2016-08-22 23:14 ` Cyril Bur
2018-03-14 9:27 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Cyril Bur @ 2016-08-22 23:14 UTC (permalink / raw)
To: Laurent Dufour, linuxppc-dev, mpe; +Cc: wei.guo.simon
On Mon, 2016-08-22 at 18:53 +0200, Laurent Dufour wrote:
> Ensure that kernel is throwing away the suspended transaction when
> sigreturn() is called otherwise it if fails to restore the signal
> frame's TM SPRS.
>
> Signed-off-by: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Reviewed-by: Cyril Bur <cyrilbur@gmail.com>
> ---
> tools/testing/selftests/powerpc/tm/Makefile | 2 +-
> tools/testing/selftests/powerpc/tm/tm-sigreturn.c | 89
> +++++++++++++++++++++++
> 2 files changed, 90 insertions(+), 1 deletion(-)
> create mode 100644 tools/testing/selftests/powerpc/tm/tm-sigreturn.c
>
> diff --git a/tools/testing/selftests/powerpc/tm/Makefile
> b/tools/testing/selftests/powerpc/tm/Makefile
> index 9d301d785d9e..5e0396d79c8a 100644
> --- a/tools/testing/selftests/powerpc/tm/Makefile
> +++ b/tools/testing/selftests/powerpc/tm/Makefile
> @@ -1,5 +1,5 @@
> 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
> + tm-vmxcopy tm-fork tm-tar tm-tmspr tm-exec tm-execed tm-
> sigreturn
>
> all: $(TEST_PROGS)
>
> diff --git a/tools/testing/selftests/powerpc/tm/tm-sigreturn.c
> b/tools/testing/selftests/powerpc/tm/tm-sigreturn.c
> new file mode 100644
> index 000000000000..43fa83de23a5
> --- /dev/null
> +++ b/tools/testing/selftests/powerpc/tm/tm-sigreturn.c
> @@ -0,0 +1,89 @@
> +/*
> + * Copyright 2015, Laurent Dufour, IBM Corp.
> + * Licensed under GPLv2.
> + *
> + * Test the kernel's signal returning code to check reclaim is done
> if
> + * the sigreturn() is called while in a transaction (suspended since
> active
> + * is already dropped trough the system call path).
> + *
> + * The kernel must discard the transaction when entering sigreturn,
> + * since restoring the potential TM SPRS from the signal frame is
> requiring to
> + * not be in a transaction.
> + */
> +
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <signal.h>
> +#include <string.h>
> +
> +#include "utils.h"
> +#include "tm.h"
> +
> +
> +void handler(int sig)
> +{
> + uint64_t ret;
> +
> + asm __volatile__(
> + "li 3,1 ;"
> + "tbegin. ;"
> + "beq 1f ;"
> + "li 3,0 ;"
> + "tsuspend. ;"
> + "1: ;"
> + "std%X[ret] 3, %[ret] ;"
> + : [ret]"=m"(ret)
> + :
> + : "memory", "3", "cr0");
> +
> + if (ret)
> + exit(1);
> +
> + /*
> + * We return from the signal handle while in a suspended
> transaction
> + */
> +}
> +
> +
> +int tm_sigreturn(void)
> +{
> + struct sigaction sa;
> + uint64_t ret = 0;
> +
> + memset(&sa, 0, sizeof(sa));
> + sa.sa_handler = handler;
> + sigemptyset(&sa.sa_mask);
> +
> + if (sigaction(SIGSEGV, &sa, NULL))
> + exit(1);
> +
> + asm __volatile__(
> + "tbegin. ;"
> + "beq 1f ;"
> + "li 3,0 ;"
> + "std 3,0(3) ;" /* trigger SEGV
> */
> + "li 3,1 ;"
> + "std%X[ret] 3,%[ret] ;"
> + "tend. ;"
> + "b 2f ;"
> + "1: ;"
> + "li 3,2 ;"
> + "std%X[ret] 3,%[ret] ;"
> + "2: ;"
> + : [ret]"=m"(ret)
> + :
> + : "memory", "3", "cr0");
> +
> + if (ret != 2)
> + exit(1);
> +
> + exit(0);
> +}
> +
> +int main(void)
> +{
> + return test_harness(tm_sigreturn, "tm_sigreturn");
> +}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: selftest/powerpc: Add test for sigreturn in transaction
2016-08-22 16:53 [PATCH] selftest/powerpc: Add test for sigreturn in transaction Laurent Dufour
2016-08-22 23:14 ` Cyril Bur
@ 2018-03-14 9:27 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2018-03-14 9:27 UTC (permalink / raw)
To: Laurent Dufour, linuxppc-dev; +Cc: wei.guo.simon, cyrilbur
On Mon, 2016-08-22 at 16:53:02 UTC, Laurent Dufour wrote:
> Ensure that kernel is throwing away the suspended transaction when
> sigreturn() is called otherwise it if fails to restore the signal
> frame's TM SPRS.
>
> Signed-off-by: Laurent Dufour <ldufour@linux.vnet.ibm.com>
> Reviewed-by: Cyril Bur <cyrilbur@gmail.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/9c96c932871efeabe82fcfdc952f35
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-14 9:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-22 16:53 [PATCH] selftest/powerpc: Add test for sigreturn in transaction Laurent Dufour
2016-08-22 23:14 ` Cyril Bur
2018-03-14 9:27 ` Michael Ellerman
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).