* [PATCH v2 0/3] powerpc/tm: MSR oops printing and selftests
@ 2015-11-20 4:15 Michael Neuling
2015-11-20 4:15 ` [PATCH v2 1/3] powerpc: Print MSR TM bits in oops messages Michael Neuling
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Michael Neuling @ 2015-11-20 4:15 UTC (permalink / raw)
To: mpe, benh; +Cc: mikey, sam.bobroff, linuxppc-dev, paulus
Here are 3 non-urgent TM patches. These were left off my other post
of the urgent fixes.
v2:
- Added invalid stack with signal delievery during tm selftest
- Added selftest binaries to .gitignore
- Improved signal return selftest based on mpe's feedback
- Improved oops message printing based on mpe's feedback
- Dropped get_tm_stackpointer() renaming patch in leui of more
extensive rewrite later
Michael Neuling (3):
powerpc: Print MSR TM bits in oops message
selftests/powerpc: Add TM signal return test
selftests/powerpc: Add TM signal with invalid stack test
arch/powerpc/kernel/process.c | 51 ++++++++++++---
tools/testing/selftests/powerpc/tm/.gitignore | 2 +
tools/testing/selftests/powerpc/tm/Makefile | 2 +-
.../selftests/powerpc/tm/tm-signal-msr-resv.c | 71 +++++++++++++++++++++
.../testing/selftests/powerpc/tm/tm-signal-stack.c | 73 ++++++++++++++++++++++
5 files changed, 190 insertions(+), 9 deletions(-)
create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c
create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-stack.c
--
2.5.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/3] powerpc: Print MSR TM bits in oops messages
2015-11-20 4:15 [PATCH v2 0/3] powerpc/tm: MSR oops printing and selftests Michael Neuling
@ 2015-11-20 4:15 ` Michael Neuling
2015-12-15 11:27 ` [v2,1/3] " Michael Ellerman
2015-11-20 4:15 ` [PATCH v2 2/3] selftests/powerpc: Add TM signal return test Michael Neuling
2015-11-20 4:15 ` [PATCH v2 3/3] selftests/powerpc: Add TM signal with invalid stack test Michael Neuling
2 siblings, 1 reply; 9+ messages in thread
From: Michael Neuling @ 2015-11-20 4:15 UTC (permalink / raw)
To: mpe, benh; +Cc: mikey, sam.bobroff, linuxppc-dev, paulus
Print MSR TM bits in oops messages. This appends them to the end
like this:
MSR: 8000000502823031 <SF,VEC,VSX,FP,ME,IR,DR,LE,TM[TE]>
You get the TM[] only if at least one TM MSR bit is set. Inside the
TM[], E means Enabled (bit 32), S means Suspended (bit 33), and T
means Transactional (bit 34)
If no bits are set, you get no TM[] output.
Include rework of printbits() to handle this case.
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
arch/powerpc/kernel/process.c | 51 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 43 insertions(+), 8 deletions(-)
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 646bf4d..f086e8b 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -952,10 +952,12 @@ static void show_instructions(struct pt_regs *regs)
printk("\n");
}
-static struct regbit {
+struct regbit {
unsigned long bit;
const char *name;
-} msr_bits[] = {
+};
+
+static struct regbit msr_bits[] = {
#if defined(CONFIG_PPC64) && !defined(CONFIG_BOOKE)
{MSR_SF, "SF"},
{MSR_HV, "HV"},
@@ -985,16 +987,49 @@ static struct regbit {
{0, NULL}
};
-static void printbits(unsigned long val, struct regbit *bits)
+static void print_bits(unsigned long val, struct regbit *bits, const char *sep)
{
- const char *sep = "";
+ const char *s = "";
- printk("<");
for (; bits->bit; ++bits)
if (val & bits->bit) {
- printk("%s%s", sep, bits->name);
- sep = ",";
+ printk("%s%s", s, bits->name);
+ s = sep;
}
+}
+
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+static struct regbit msr_tm_bits[] = {
+ {MSR_TS_T, "T"},
+ {MSR_TS_S, "S"},
+ {MSR_TM, "E"},
+ {0, NULL}
+};
+
+static void print_tm_bits(unsigned long val)
+{
+/*
+ * This only prints something if at least one of the TM bit is set.
+ * Inside the TM[], the output means:
+ * E: Enabled (bit 32)
+ * S: Suspended (bit 33)
+ * T: Transactional (bit 34)
+ */
+ if (val & (MSR_TM | MSR_TS_S | MSR_TS_T)) {
+ printk(",TM[");
+ print_bits(val, msr_tm_bits, "");
+ printk("]");
+ }
+}
+#else
+static void print_tm_bits(unsigned long val) {}
+#endif
+
+static void print_msr_bits(unsigned long val)
+{
+ printk("<");
+ print_bits(val, msr_bits, ",");
+ print_tm_bits(val);
printk(">");
}
@@ -1019,7 +1054,7 @@ void show_regs(struct pt_regs * regs)
printk("REGS: %p TRAP: %04lx %s (%s)\n",
regs, regs->trap, print_tainted(), init_utsname()->release);
printk("MSR: "REG" ", regs->msr);
- printbits(regs->msr, msr_bits);
+ print_msr_bits(regs->msr);
printk(" CR: %08lx XER: %08lx\n", regs->ccr, regs->xer);
trap = TRAP(regs);
if ((regs->trap != 0xc00) && cpu_has_feature(CPU_FTR_CFAR))
--
2.5.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/3] selftests/powerpc: Add TM signal return test
2015-11-20 4:15 [PATCH v2 0/3] powerpc/tm: MSR oops printing and selftests Michael Neuling
2015-11-20 4:15 ` [PATCH v2 1/3] powerpc: Print MSR TM bits in oops messages Michael Neuling
@ 2015-11-20 4:15 ` Michael Neuling
2015-11-23 11:32 ` Anshuman Khandual
2015-12-15 11:27 ` [v2,2/3] " Michael Ellerman
2015-11-20 4:15 ` [PATCH v2 3/3] selftests/powerpc: Add TM signal with invalid stack test Michael Neuling
2 siblings, 2 replies; 9+ messages in thread
From: Michael Neuling @ 2015-11-20 4:15 UTC (permalink / raw)
To: mpe, benh; +Cc: mikey, sam.bobroff, linuxppc-dev, paulus
Test the kernel's signal return code to ensure that it doesn't crash
when both the transactional and suspend MSR bits are set in the signal
context.
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
tools/testing/selftests/powerpc/tm/.gitignore | 1 +
tools/testing/selftests/powerpc/tm/Makefile | 2 +-
.../selftests/powerpc/tm/tm-signal-msr-resv.c | 71 ++++++++++++++++++++++
3 files changed, 73 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c
diff --git a/tools/testing/selftests/powerpc/tm/.gitignore b/tools/testing/selftests/powerpc/tm/.gitignore
index 2699635d..61c318f 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -1,2 +1,3 @@
tm-resched-dscr
tm-syscall
+tm-signal-msr-resv
diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index 4bea62a..0c28db7 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv
all: $(TEST_PROGS)
diff --git a/tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c b/tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c
new file mode 100644
index 0000000..bdad348
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ *
+ * Test the kernel's signal return code to ensure that it doesn't
+ * crash when both the transactional and suspend MSR bits are set in
+ * the signal context.
+ *
+ * For this test, we send ourselves a SIGUSR1. In the SIGUSR1 handler
+ * we modify the signal context to set both MSR TM S and T bits (which
+ * is "reserved" by the PowerISA). When we return from the signal
+ * handler (implicit sigreturn), the kernel should detect reserved MSR
+ * value and send us with a SIGSEGV.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include "utils.h"
+
+int segv_expected = 0;
+
+void signal_segv(int signum)
+{
+ if (segv_expected && (signum == SIGSEGV))
+ _exit(0);
+ _exit(1);
+}
+
+void signal_usr1(int signum, siginfo_t *info, void *uc)
+{
+ ucontext_t *ucp = uc;
+
+ /* Link tm checkpointed context to normal context */
+ ucp->uc_link = ucp;
+ /* Set all TM bits so that the context is now invalid */
+#ifdef __powerpc64__
+ ucp->uc_mcontext.gp_regs[PT_MSR] |= (7ULL << 32);
+#else
+ ucp->uc_mcontext.regs->gpr[PT_MSR] |= (7ULL);
+#endif
+ /* Should segv on return becuase of invalid context */
+ segv_expected = 1;
+}
+
+int tm_signal_msr_resv()
+{
+ struct sigaction act;
+
+ act.sa_sigaction = signal_usr1;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = SA_SIGINFO;
+ if (sigaction(SIGUSR1, &act, NULL) < 0) {
+ perror("sigaction sigusr1");
+ exit(1);
+ }
+ if (signal(SIGSEGV, signal_segv) == SIG_ERR)
+ exit(1);
+
+ raise(SIGUSR1);
+
+ /* We shouldn't get here as we exit in the segv handler */
+ return 1;
+}
+
+int main(void)
+{
+ return test_harness(tm_signal_msr_resv, "tm_signal_msr_resv");
+}
--
2.5.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/3] selftests/powerpc: Add TM signal with invalid stack test
2015-11-20 4:15 [PATCH v2 0/3] powerpc/tm: MSR oops printing and selftests Michael Neuling
2015-11-20 4:15 ` [PATCH v2 1/3] powerpc: Print MSR TM bits in oops messages Michael Neuling
2015-11-20 4:15 ` [PATCH v2 2/3] selftests/powerpc: Add TM signal return test Michael Neuling
@ 2015-11-20 4:15 ` Michael Neuling
2015-11-23 11:32 ` Anshuman Khandual
2015-12-15 11:27 ` [v2, " Michael Ellerman
2 siblings, 2 replies; 9+ messages in thread
From: Michael Neuling @ 2015-11-20 4:15 UTC (permalink / raw)
To: mpe, benh; +Cc: mikey, sam.bobroff, linuxppc-dev, paulus
Test the kernels signal generation code to ensure it can handle an
invalid stack pointer when transactional.
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
tools/testing/selftests/powerpc/tm/.gitignore | 1 +
tools/testing/selftests/powerpc/tm/Makefile | 2 +-
.../testing/selftests/powerpc/tm/tm-signal-stack.c | 73 ++++++++++++++++++++++
3 files changed, 75 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-stack.c
diff --git a/tools/testing/selftests/powerpc/tm/.gitignore b/tools/testing/selftests/powerpc/tm/.gitignore
index 61c318f..e666821 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -1,3 +1,4 @@
tm-resched-dscr
tm-syscall
tm-signal-msr-resv
+tm-signal-stack
diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index 0c28db7..0e45c7e 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack
all: $(TEST_PROGS)
diff --git a/tools/testing/selftests/powerpc/tm/tm-signal-stack.c b/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
new file mode 100644
index 0000000..62f2a5f
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ *
+ * Test the kernel's signal delievery code to ensure that we don't
+ * trelaim twice in the kernel signal delivery code. This can happen
+ * if we trigger a signal when in a transaction and the stack pointer
+ * is bogus.
+ *
+ * This test case registers a SEGV handler, sets the stack pointer
+ * (r1) to NULL, starts a transaction and then generates a SEGV. The
+ * SEGV should be handled but we exit here as the stack pointer is
+ * invalid and hance we can't sigreturn. We only need to check that
+ * this flow doesn't crash the kernel.
+ */
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <signal.h>
+
+#include "utils.h"
+
+void signal_segv(int signum)
+{
+ /* This should never actually run since stack is foobar */
+ exit(1);
+}
+
+int tm_signal_stack()
+{
+ int pid;
+
+ pid = fork();
+ if (pid < 0)
+ exit(1);
+
+ if (pid) { /* Parent */
+ /*
+ * It's likely the whole machine will crash here so if
+ * the child ever exits, we are good.
+ */
+ wait(NULL);
+ return 0;
+ }
+
+ /*
+ * The flow here is:
+ * 1) register a signal handler (so signal delievery occurs)
+ * 2) make stack pointer (r1) = NULL
+ * 3) start transaction
+ * 4) cause segv
+ */
+ if (signal(SIGSEGV, signal_segv) == SIG_ERR)
+ exit(1);
+ asm volatile("li 1, 0 ;" /* stack ptr == NULL */
+ "1:"
+ ".long 0x7C00051D ;" /* tbegin */
+ "beq 1b ;" /* retry forever */
+ ".long 0x7C0005DD ; ;" /* tsuspend */
+ "ld 2, 0(1) ;" /* trigger segv" */
+ : : : "memory");
+
+ /* This should never get here due to above segv */
+ return 1;
+}
+
+int main(void)
+{
+ return test_harness(tm_signal_stack, "tm_signal_stack");
+}
--
2.5.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] selftests/powerpc: Add TM signal return test
2015-11-20 4:15 ` [PATCH v2 2/3] selftests/powerpc: Add TM signal return test Michael Neuling
@ 2015-11-23 11:32 ` Anshuman Khandual
2015-12-15 11:27 ` [v2,2/3] " Michael Ellerman
1 sibling, 0 replies; 9+ messages in thread
From: Anshuman Khandual @ 2015-11-23 11:32 UTC (permalink / raw)
To: Michael Neuling, mpe, benh; +Cc: linuxppc-dev, paulus, sam.bobroff
On 11/20/2015 09:45 AM, Michael Neuling wrote:
> Test the kernel's signal return code to ensure that it doesn't crash
> when both the transactional and suspend MSR bits are set in the signal
> context.
>
> Signed-off-by: Michael Neuling <mikey@neuling.org>
Tested-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/3] selftests/powerpc: Add TM signal with invalid stack test
2015-11-20 4:15 ` [PATCH v2 3/3] selftests/powerpc: Add TM signal with invalid stack test Michael Neuling
@ 2015-11-23 11:32 ` Anshuman Khandual
2015-12-15 11:27 ` [v2, " Michael Ellerman
1 sibling, 0 replies; 9+ messages in thread
From: Anshuman Khandual @ 2015-11-23 11:32 UTC (permalink / raw)
To: Michael Neuling, mpe, benh; +Cc: linuxppc-dev, paulus, sam.bobroff
On 11/20/2015 09:45 AM, Michael Neuling wrote:
> Test the kernels signal generation code to ensure it can handle an
> invalid stack pointer when transactional.
>
> Signed-off-by: Michael Neuling <mikey@neuling.org>
Tested-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [v2,1/3] powerpc: Print MSR TM bits in oops messages
2015-11-20 4:15 ` [PATCH v2 1/3] powerpc: Print MSR TM bits in oops messages Michael Neuling
@ 2015-12-15 11:27 ` Michael Ellerman
0 siblings, 0 replies; 9+ messages in thread
From: Michael Ellerman @ 2015-12-15 11:27 UTC (permalink / raw)
To: Michael Neuling, benh; +Cc: linuxppc-dev, mikey, paulus, sam.bobroff
On Fri, 2015-20-11 at 04:15:32 UTC, Michael Neuling wrote:
> Print MSR TM bits in oops messages. This appends them to the end
> like this:
>
> MSR: 8000000502823031 <SF,VEC,VSX,FP,ME,IR,DR,LE,TM[TE]>
>
> You get the TM[] only if at least one TM MSR bit is set. Inside the
> TM[], E means Enabled (bit 32), S means Suspended (bit 33), and T
> means Transactional (bit 34)
>
> If no bits are set, you get no TM[] output.
>
> Include rework of printbits() to handle this case.
>
> Signed-off-by: Michael Neuling <mikey@neuling.org>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/801c0b2c4db3a33d56b3e192
cheers
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [v2,2/3] selftests/powerpc: Add TM signal return test
2015-11-20 4:15 ` [PATCH v2 2/3] selftests/powerpc: Add TM signal return test Michael Neuling
2015-11-23 11:32 ` Anshuman Khandual
@ 2015-12-15 11:27 ` Michael Ellerman
1 sibling, 0 replies; 9+ messages in thread
From: Michael Ellerman @ 2015-12-15 11:27 UTC (permalink / raw)
To: Michael Neuling, benh; +Cc: linuxppc-dev, mikey, paulus, sam.bobroff
On Fri, 2015-20-11 at 04:15:33 UTC, Michael Neuling wrote:
> Test the kernel's signal return code to ensure that it doesn't crash
> when both the transactional and suspend MSR bits are set in the signal
> context.
>
> Signed-off-by: Michael Neuling <mikey@neuling.org>
> Tested-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/25007a69e852389985ee9823
cheers
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [v2, 3/3] selftests/powerpc: Add TM signal with invalid stack test
2015-11-20 4:15 ` [PATCH v2 3/3] selftests/powerpc: Add TM signal with invalid stack test Michael Neuling
2015-11-23 11:32 ` Anshuman Khandual
@ 2015-12-15 11:27 ` Michael Ellerman
1 sibling, 0 replies; 9+ messages in thread
From: Michael Ellerman @ 2015-12-15 11:27 UTC (permalink / raw)
To: Michael Neuling, benh; +Cc: linuxppc-dev, mikey, paulus, sam.bobroff
On Fri, 2015-20-11 at 04:15:34 UTC, Michael Neuling wrote:
> Test the kernels signal generation code to ensure it can handle an
> invalid stack pointer when transactional.
>
> Signed-off-by: Michael Neuling <mikey@neuling.org>
> Tested-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/a26f415bf71640f0141e5e94
cheers
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-12-15 11:27 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-20 4:15 [PATCH v2 0/3] powerpc/tm: MSR oops printing and selftests Michael Neuling
2015-11-20 4:15 ` [PATCH v2 1/3] powerpc: Print MSR TM bits in oops messages Michael Neuling
2015-12-15 11:27 ` [v2,1/3] " Michael Ellerman
2015-11-20 4:15 ` [PATCH v2 2/3] selftests/powerpc: Add TM signal return test Michael Neuling
2015-11-23 11:32 ` Anshuman Khandual
2015-12-15 11:27 ` [v2,2/3] " Michael Ellerman
2015-11-20 4:15 ` [PATCH v2 3/3] selftests/powerpc: Add TM signal with invalid stack test Michael Neuling
2015-11-23 11:32 ` Anshuman Khandual
2015-12-15 11:27 ` [v2, " Michael Ellerman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.