selftests/powerpc: Add a test of sigreturning to an unaligned address
authorMichael Ellerman <mpe@ellerman.id.au>
Tue, 21 Dec 2021 13:51:01 +0000 (00:51 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 24 Dec 2021 23:56:05 +0000 (10:56 +1100)
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 <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211221135101.2085547-3-mpe@ellerman.id.au
tools/testing/selftests/powerpc/signal/.gitignore
tools/testing/selftests/powerpc/signal/Makefile
tools/testing/selftests/powerpc/signal/sigreturn_unaligned.c [new file with mode: 0644]

index 8f6c816..9d09157 100644 (file)
@@ -5,3 +5,4 @@ sigfuz
 sigreturn_vdso
 sig_sc_double_restart
 sigreturn_kernel
+sigreturn_unaligned
index 84e2015..f679d26 100644 (file)
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 TEST_GEN_PROGS := signal signal_tm sigfuz sigreturn_vdso sig_sc_double_restart
 TEST_GEN_PROGS += sigreturn_kernel
+TEST_GEN_PROGS += sigreturn_unaligned
 
 CFLAGS += -maltivec
 $(OUTPUT)/signal_tm: CFLAGS += -mhtm
diff --git a/tools/testing/selftests/powerpc/signal/sigreturn_unaligned.c b/tools/testing/selftests/powerpc/signal/sigreturn_unaligned.c
new file mode 100644 (file)
index 0000000..6e58ee4
--- /dev/null
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Test sigreturn to an unaligned address, ie. low 2 bits set.
+ * Nothing bad should happen.
+ * This was able to trigger warnings with CONFIG_PPC_RFI_SRR_DEBUG=y.
+ */
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ucontext.h>
+#include <unistd.h>
+
+#include "utils.h"
+
+
+static void sigusr1_handler(int signo, siginfo_t *info, void *ptr)
+{
+       ucontext_t *uc = ptr;
+
+       UCONTEXT_NIA(uc) |= 3;
+}
+
+static int test_sigreturn_unaligned(void)
+{
+       struct sigaction action;
+
+       memset(&action, 0, sizeof(action));
+       action.sa_sigaction = sigusr1_handler;
+       action.sa_flags = SA_SIGINFO;
+
+       FAIL_IF(sigaction(SIGUSR1, &action, NULL) == -1);
+
+       raise(SIGUSR1);
+
+       return 0;
+}
+
+int main(void)
+{
+       return test_harness(test_sigreturn_unaligned, "sigreturn_unaligned");
+}