diff mbox series

selftests/powerpc: Fix prefixes in alignment_handler signal handler

Message ID 20200824131231.14008-1-jniethe5@gmail.com (mailing list archive)
State Accepted
Commit db96221a683342fd4775fd820a4d5376cd2f2ed0
Headers show
Series selftests/powerpc: Fix prefixes in alignment_handler signal handler | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch powerpc/merge (d4ecce4dcc8f8820286cf4e0859850c555e89854)
snowpatch_ozlabs/build-ppc64le warning Upstream build failed, couldn't test patch
snowpatch_ozlabs/build-ppc64be warning Upstream build failed, couldn't test patch
snowpatch_ozlabs/build-ppc64e warning Upstream build failed, couldn't test patch
snowpatch_ozlabs/build-pmac32 warning Upstream build failed, couldn't test patch
snowpatch_ozlabs/checkpatch success total: 0 errors, 0 warnings, 0 checks, 35 lines checked
snowpatch_ozlabs/needsstable success Patch fixes a commit that hasn't been released yet

Commit Message

Jordan Niethe Aug. 24, 2020, 1:12 p.m. UTC
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>
---
 .../selftests/powerpc/alignment/alignment_handler.c   | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Jordan Niethe Aug. 26, 2020, 7:27 a.m. UTC | #1
On Mon, Aug 24, 2020 at 11:12 PM Jordan Niethe <jniethe5@gmail.com> wrote:
>
> 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>
> ---
>  .../selftests/powerpc/alignment/alignment_handler.c   | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/powerpc/alignment/alignment_handler.c b/tools/testing/selftests/powerpc/alignment/alignment_handler.c
> index 55ef15184057..c197ff828120 100644
> --- a/tools/testing/selftests/powerpc/alignment/alignment_handler.c
> +++ b/tools/testing/selftests/powerpc/alignment/alignment_handler.c
> @@ -64,12 +64,14 @@ int bufsize;
>  int debug;
>  int testing;
>  volatile int gotsig;
> +bool haveprefixes;
>  char *cipath = "/dev/fb0";
>  long cioffset;
>
>  void sighandler(int sig, siginfo_t *info, void *ctx)
>  {
>         ucontext_t *ucp = ctx;
> +       u32 inst;
Oh this should be befine __powerpc64__/CONFIG_PPC64 (thank you patchwork).
>
>         if (!testing) {
>                 signal(sig, SIG_DFL);
> @@ -77,7 +79,12 @@ void sighandler(int sig, siginfo_t *info, void *ctx)
>         }
>         gotsig = sig;
>  #ifdef __powerpc64__
> -       ucp->uc_mcontext.gp_regs[PT_NIP] += 4;
> +       if (haveprefixes) {
> +               inst = *(u32 *)ucp->uc_mcontext.gp_regs[PT_NIP];
> +               ucp->uc_mcontext.gp_regs[PT_NIP] += ((inst >> 26 == 1) ? 8 : 4);
> +       } else {
> +               ucp->uc_mcontext.gp_regs[PT_NIP] += 4;
> +       }
>  #else
>         ucp->uc_mcontext.uc_regs->gregs[PT_NIP] += 4;
>  #endif
> @@ -648,6 +655,8 @@ int main(int argc, char *argv[])
>                 exit(1);
>         }
>
> +       haveprefixes = have_hwcap2(PPC_FEATURE2_ARCH_3_1);
> +
>         rc |= test_harness(test_alignment_handler_vsx_206,
>                            "test_alignment_handler_vsx_206");
>         rc |= test_harness(test_alignment_handler_vsx_207,
> --
> 2.17.1
>
Michael Ellerman Sept. 9, 2020, 1:27 p.m. UTC | #2
On Mon, 24 Aug 2020 23:12:31 +1000, Jordan Niethe wrote:
> 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.
> 
> [...]

Applied to powerpc/next.

[1/1] selftests/powerpc: Fix prefixes in alignment_handler signal handler
      https://git.kernel.org/powerpc/c/db96221a683342fd4775fd820a4d5376cd2f2ed0

cheers
diff mbox series

Patch

diff --git a/tools/testing/selftests/powerpc/alignment/alignment_handler.c b/tools/testing/selftests/powerpc/alignment/alignment_handler.c
index 55ef15184057..c197ff828120 100644
--- a/tools/testing/selftests/powerpc/alignment/alignment_handler.c
+++ b/tools/testing/selftests/powerpc/alignment/alignment_handler.c
@@ -64,12 +64,14 @@  int bufsize;
 int debug;
 int testing;
 volatile int gotsig;
+bool haveprefixes;
 char *cipath = "/dev/fb0";
 long cioffset;
 
 void sighandler(int sig, siginfo_t *info, void *ctx)
 {
 	ucontext_t *ucp = ctx;
+	u32 inst;
 
 	if (!testing) {
 		signal(sig, SIG_DFL);
@@ -77,7 +79,12 @@  void sighandler(int sig, siginfo_t *info, void *ctx)
 	}
 	gotsig = sig;
 #ifdef __powerpc64__
-	ucp->uc_mcontext.gp_regs[PT_NIP] += 4;
+	if (haveprefixes) {
+		inst = *(u32 *)ucp->uc_mcontext.gp_regs[PT_NIP];
+		ucp->uc_mcontext.gp_regs[PT_NIP] += ((inst >> 26 == 1) ? 8 : 4);
+	} else {
+		ucp->uc_mcontext.gp_regs[PT_NIP] += 4;
+	}
 #else
 	ucp->uc_mcontext.uc_regs->gregs[PT_NIP] += 4;
 #endif
@@ -648,6 +655,8 @@  int main(int argc, char *argv[])
 		exit(1);
 	}
 
+	haveprefixes = have_hwcap2(PPC_FEATURE2_ARCH_3_1);
+
 	rc |= test_harness(test_alignment_handler_vsx_206,
 			   "test_alignment_handler_vsx_206");
 	rc |= test_harness(test_alignment_handler_vsx_207,