Commit 0f8f554e authored by Gustavo Luiz Duarte's avatar Gustavo Luiz Duarte Committed by Michael Ellerman

selftests/powerpc: Don't rely on segfault to rerun the test

The test case tm-signal-context-force-tm expects a segfault to happen
on returning from signal handler, and then does a setcontext() to run
the test again. However, the test doesn't always segfault, causing the
test to run a single time.

This patch fixes the test by putting it within a loop and jumping, via
setcontext, just prior to the loop in case it segfaults. This way we
get the desired behavior (run the test COUNT_MAX times) regardless if
it segfaults or not. This also reduces the use of setcontext for
control flow logic, keeping it only in the segfault handler.

Also, since 'count' is changed within the signal handler, it is
declared as volatile to prevent any compiler optimization getting
confused with asynchronous changes.
Signed-off-by: default avatarGustavo Luiz Duarte <gustavold@linux.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200211033831.11165-3-gustavold@linux.ibm.com
parent 915b7f6f
......@@ -42,9 +42,10 @@
#endif
/* Setting contexts because the test will crash and we want to recover */
ucontext_t init_context, main_context;
ucontext_t init_context;
static int count, first_time;
/* count is changed in the signal handler, so it must be volatile */
static volatile int count;
void usr_signal_handler(int signo, siginfo_t *si, void *uc)
{
......@@ -98,11 +99,6 @@ void usr_signal_handler(int signo, siginfo_t *si, void *uc)
void seg_signal_handler(int signo, siginfo_t *si, void *uc)
{
if (count == COUNT_MAX) {
/* Return to tm_signal_force_msr() and exit */
setcontext(&main_context);
}
count++;
/* Reexecute the test */
......@@ -126,6 +122,7 @@ void tm_trap_test(void)
*/
getcontext(&init_context);
while (count < COUNT_MAX) {
/* Allocated an alternative signal stack area */
ss.ss_sp = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
......@@ -143,7 +140,8 @@ void tm_trap_test(void)
exit(-1);
}
/* Setting an alternative stack to generate a page fault when
/*
* Setting an alternative stack to generate a page fault when
* the signal is raised.
*/
if (sigaltstack(&ss, NULL)) {
......@@ -153,10 +151,12 @@ void tm_trap_test(void)
/* The signal handler will enable MSR_TS */
sigaction(SIGUSR1, &usr_sa, NULL);
/* If it does not crash, it will segfault, avoid it to retest */
/* If it does not crash, it might segfault, avoid it to retest */
sigaction(SIGSEGV, &seg_sa, NULL);
raise(SIGUSR1);
count++;
}
}
int tm_signal_context_force_tm(void)
......@@ -169,10 +169,6 @@ int tm_signal_context_force_tm(void)
*/
SKIP_IF(!is_ppc64le());
/* Will get back here after COUNT_MAX interactions */
getcontext(&main_context);
if (!first_time++)
tm_trap_test();
return EXIT_SUCCESS;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment