Skip to content

Commit beeac53

Browse files
committed
selftests/powerpc: Add a test of sigreturning to an unaligned address
Add a test of sigreturning to an unaligned address (low two bits set). This should have no effect because the hardware will mask those bits. However it previously falsely triggered a warning when CONFIG_PPC_RFI_SRR_DEBUG=y. Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fd1eaaa commit beeac53

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

tools/testing/selftests/powerpc/signal/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ sigfuz
55
sigreturn_vdso
66
sig_sc_double_restart
77
sigreturn_kernel
8+
sigreturn_unaligned

tools/testing/selftests/powerpc/signal/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
TEST_GEN_PROGS := signal signal_tm sigfuz sigreturn_vdso sig_sc_double_restart
33
TEST_GEN_PROGS += sigreturn_kernel
4+
TEST_GEN_PROGS += sigreturn_unaligned
45

56
CFLAGS += -maltivec
67
$(OUTPUT)/signal_tm: CFLAGS += -mhtm
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Test sigreturn to an unaligned address, ie. low 2 bits set.
4+
* Nothing bad should happen.
5+
* This was able to trigger warnings with CONFIG_PPC_RFI_SRR_DEBUG=y.
6+
*/
7+
8+
#include <signal.h>
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <string.h>
12+
#include <ucontext.h>
13+
#include <unistd.h>
14+
15+
#include "utils.h"
16+
17+
18+
static void sigusr1_handler(int signo, siginfo_t *info, void *ptr)
19+
{
20+
ucontext_t *uc = ptr;
21+
22+
UCONTEXT_NIA(uc) |= 3;
23+
}
24+
25+
static int test_sigreturn_unaligned(void)
26+
{
27+
struct sigaction action;
28+
29+
memset(&action, 0, sizeof(action));
30+
action.sa_sigaction = sigusr1_handler;
31+
action.sa_flags = SA_SIGINFO;
32+
33+
FAIL_IF(sigaction(SIGUSR1, &action, NULL) == -1);
34+
35+
raise(SIGUSR1);
36+
37+
return 0;
38+
}
39+
40+
int main(void)
41+
{
42+
return test_harness(test_sigreturn_unaligned, "sigreturn_unaligned");
43+
}

0 commit comments

Comments
 (0)