[PATCH 1/3] powerpc: sstep: Add tests for compute type instructions

Michael Ellerman mpe at ellerman.id.au
Thu Feb 21 22:13:19 AEDT 2019


Sandipan Das <sandipan at linux.ibm.com> writes:
> This enhances the current selftest framework for validating
> the in-kernel instruction emulation infrastructure by adding
> support for compute type instructions i.e. integer ALU-based
> instructions. Originally, this framework was limited to only
> testing load and store instructions.
>
> While most of the GPRs can be validated, support for SPRs is
> limited to LR, CR and XER for now.
>
> When writing the test cases, one must ensure that the Stack
> Pointer (GPR1) or the Thread Pointer (GPR13) are not touched
> by any means as these are vital non-volatile registers.
>
> Signed-off-by: Sandipan Das <sandipan at linux.ibm.com>
> ---
>  arch/powerpc/lib/Makefile                     |   3 +-
>  arch/powerpc/lib/test_emulate_step.c          | 167 +++++++++++++++++-
>  .../lib/test_emulate_step_exec_instr.S        | 150 ++++++++++++++++
>  3 files changed, 315 insertions(+), 5 deletions(-)
>  create mode 100644 arch/powerpc/lib/test_emulate_step_exec_instr.S

Hi Sandipan,

Thanks for the exceptionally well written asm, I wish all our asm code
was that neat and well commented :)

I'd like to get this merged today so I tweaked it slightly when
applying to use the new patch_site helpers we added recently, see diff
below.

cheers


diff --git a/arch/powerpc/lib/test_emulate_step.c b/arch/powerpc/lib/test_emulate_step.c
index 1c13b3bebeca..9992c1ea7a1d 100644
--- a/arch/powerpc/lib/test_emulate_step.c
+++ b/arch/powerpc/lib/test_emulate_step.c
@@ -865,14 +865,14 @@ static int __init emulate_compute_instr(struct pt_regs *regs,
 static int __init execute_compute_instr(struct pt_regs *regs,
 					unsigned int instr)
 {
-	extern unsigned int exec_instr_execute[];
 	extern int exec_instr(struct pt_regs *regs);
+	extern s32 patch__exec_instr;
 
 	if (!regs || !instr)
 		return -EINVAL;
 
 	/* Patch the NOP with the actual instruction */
-	patch_instruction(&exec_instr_execute[0], instr);
+	patch_instruction_site(&patch__exec_instr, instr);
 	if (exec_instr(regs)) {
 		pr_info("execution failed, instruction = 0x%08x\n", instr);
 		return -EFAULT;
diff --git a/arch/powerpc/lib/test_emulate_step_exec_instr.S b/arch/powerpc/lib/test_emulate_step_exec_instr.S
index 84cef7d78d9d..1580f34f4f4f 100644
--- a/arch/powerpc/lib/test_emulate_step_exec_instr.S
+++ b/arch/powerpc/lib/test_emulate_step_exec_instr.S
@@ -8,6 +8,7 @@
 
 #include <asm/asm-offsets.h>
 #include <asm/ppc_asm.h>
+#include <asm/code-patching-asm.h>
 #include <linux/errno.h>
 
 /* int exec_instr(struct pt_regs *regs) */
@@ -78,10 +79,9 @@ _GLOBAL(exec_instr)
 	REST_GPR(12, r31)
 	REST_NVGPRS(r31)
 
-	.global	exec_instr_execute
-exec_instr_execute:
 	/* Placeholder for the test instruction */
 1:	nop
+	patch_site 1b patch__exec_instr
 
 	/*
 	 * Since GPR3 is overwritten, temporarily restore it back to its


More information about the Linuxppc-dev mailing list