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

selftests/powerpc: Fix prefixes in alignment_handler signal handler

The signal handler in the alignment handler self test has the ability
to jump over the instruction that triggered the signal. It does this
by incrementing the PT_NIP in the user context by 4. If it were a
prefixed instruction this will mean that the suffix is then executed
which is incorrect. Instead check if the major opcode indicates a
prefixed instruction (e.g. it is 1) and if so increment PT_NIP by 8.

If ISA v3.1 is not available treat it as a word instruction even if
the major opcode is 1.

Fixes: 620a6473df36 ("selftests/powerpc: Add prefixed loads/stores to alignment_handler test")
Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
[mpe: Fix 32-bit build, rename haveprefixes to prefixes_enabled]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200824131231.14008-1-jniethe5@gmail.com

authored by

Jordan Niethe and committed by
Michael Ellerman
db96221a 364b236a

+9 -1
+9 -1
tools/testing/selftests/powerpc/alignment/alignment_handler.c
··· 62 62 int debug; 63 63 int testing; 64 64 volatile int gotsig; 65 + bool prefixes_enabled; 65 66 char *cipath = "/dev/fb0"; 66 67 long cioffset; 67 68 ··· 76 75 } 77 76 gotsig = sig; 78 77 #ifdef __powerpc64__ 79 - ucp->uc_mcontext.gp_regs[PT_NIP] += 4; 78 + if (prefixes_enabled) { 79 + u32 inst = *(u32 *)ucp->uc_mcontext.gp_regs[PT_NIP]; 80 + ucp->uc_mcontext.gp_regs[PT_NIP] += ((inst >> 26 == 1) ? 8 : 4); 81 + } else { 82 + ucp->uc_mcontext.gp_regs[PT_NIP] += 4; 83 + } 80 84 #else 81 85 ucp->uc_mcontext.uc_regs->gregs[PT_NIP] += 4; 82 86 #endif ··· 651 645 perror("sigaction"); 652 646 exit(1); 653 647 } 648 + 649 + prefixes_enabled = have_hwcap2(PPC_FEATURE2_ARCH_3_1); 654 650 655 651 rc |= test_harness(test_alignment_handler_vsx_206, 656 652 "test_alignment_handler_vsx_206");