Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211221135101.2085547-3-mpe@ellerman.id.au

+45
+1
tools/testing/selftests/powerpc/signal/.gitignore
··· 5 5 sigreturn_vdso 6 6 sig_sc_double_restart 7 7 sigreturn_kernel 8 + sigreturn_unaligned
+1
tools/testing/selftests/powerpc/signal/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 TEST_GEN_PROGS := signal signal_tm sigfuz sigreturn_vdso sig_sc_double_restart 3 3 TEST_GEN_PROGS += sigreturn_kernel 4 + TEST_GEN_PROGS += sigreturn_unaligned 4 5 5 6 CFLAGS += -maltivec 6 7 $(OUTPUT)/signal_tm: CFLAGS += -mhtm
+43
tools/testing/selftests/powerpc/signal/sigreturn_unaligned.c
··· 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 + }