Skip to contentSkip to conversation

powerpc: sstep: Emulation test infrastructure

PATCH In review Sandipan Das 3 participants 7 messages Feb 20, 2019 – Feb 26, 2019 PowerPC

lore
Share & tools
lore
#0 lore raw

cover powerpc: sstep: Emulation test infrastructure

This aims to extend the current test infrastructure for in-kernel instruction emulation by adding support for validating basic integer operations and will verify the GPRs, LR, XER and CR.

There can be multiple test cases for each instruction. Each test case has to be provided with the initial register state (in the form of a pt_regs) and the 32-bit instruction to test.

Apart from verifying the end result, problems with the behaviour of certain instructions for things like setting certain bits in CR or XER (which can also be processor dependent) can be identified.

For example, the newly introduced CA32 bit in XER, exclusive to P9 CPUs as of now, was not being set when expected for some of the arithmetic and shift instructions. With this infrastructure, it will be easier to identify such problems and rectify them. The test cases for the addc[.] instruction demonstrate this for different scenarios where the CA and CA32 bits of XER should be set.

Changelog:
RFC -> v1:
- Integrate with current test infrastructure that already tests some load and store instructions.
- Remove first two patches that introduce new instructions fields in favour of extending the macros in the current infrastructure.
- Add a message to indicate that the tests are being run based on suggestions from Daniel.

Sandipan Das (3):
powerpc: sstep: Add tests for compute type instructions
powerpc: sstep: Add tests for add[.] instruction
powerpc: sstep: Add tests for addc[.] instruction

 arch/powerpc/include/asm/ppc-opcode.h         |   1 +
 arch/powerpc/lib/Makefile                     |   3 +-
 arch/powerpc/lib/test_emulate_step.c          | 535 +++++++++++++++++-
 .../lib/test_emulate_step_exec_instr.S        | 150 +++++
 4 files changed, 684 insertions(+), 5 deletions(-)
 create mode 100644 arch/powerpc/lib/test_emulate_step_exec_instr.S
Signature · 1 line
2.19.2
#1 lore raw

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

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.

---
 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
arch/powerpc/lib/Makefile +2 -1
index 3bf9fc6fd36c..79396e184bca 100644
@@ -30,7 +30,8 @@ obj64-y	+= copypage_64.o copyuser_64.o mem_64.o hweight_64.o \
 
 obj64-$(CONFIG_SMP)	+= locks.o
 obj64-$(CONFIG_ALTIVEC)	+= vmx-helper.o
-obj64-$(CONFIG_KPROBES_SANITY_TEST) += test_emulate_step.o
+obj64-$(CONFIG_KPROBES_SANITY_TEST)	+= test_emulate_step.o \
+					   test_emulate_step_exec_instr.o
 
 obj-y			+= checksum_$(BITS).o checksum_wrappers.o \
 			   string_$(BITS).o memcmp_$(BITS).o
arch/powerpc/lib/test_emulate_step.c +163 -4

202 lines not on this page · raw message

arch/powerpc/lib/test_emulate_step_exec_instr.S new file +150 -0

150 lines not on this page · raw message

Signature · 1 line
2.19.2
#2 lore raw

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

Quoted 13 lines · Sandipan Das

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.

Quoted 7 lines
---
 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

arch/powerpc/lib/test_emulate_step.c +2 -2
index 1c13b3bebeca..9992c1ea7a1d 100644
@@ -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;
arch/powerpc/lib/test_emulate_step_exec_instr.S +2 -2
index 84cef7d78d9d..1580f34f4f4f 100644
@@ -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
#3 lore raw

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

Hi Michael,

Quoted 24 lines · Michael Ellerman
Quoted 13 lines · Sandipan Das

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.

Quoted 7 lines
---
 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,

Quoted 10 lines

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

Thanks for modernizing it :)

- Sandipan

#4 lore raw

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

In reply to Sandipan Das
Quoted 6 lines · Sandipan Das

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.

Quoted 8 lines

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.

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/84022ac17327c5383917f46c162fd943

cheers

#5 lore raw

PATCH 2/3 powerpc: sstep: Add tests for add[.] instruction

In reply to Sandipan Das

This adds test cases for the add[.] instruction.

---
 arch/powerpc/lib/test_emulate_step.c | 176 +++++++++++++++++++++++++++
 1 file changed, 176 insertions(+)
arch/powerpc/lib/test_emulate_step.c +176 -0
index 3d7f7bae51cc..bf88b20e53d7 100644
@@ -49,6 +49,10 @@
 					___PPC_RA(a) | ___PPC_RB(b))
 #define TEST_LXVD2X(s, a, b)	(PPC_INST_LXVD2X | VSX_XX1((s), R##a, R##b))
 #define TEST_STXVD2X(s, a, b)	(PPC_INST_STXVD2X | VSX_XX1((s), R##a, R##b))
+#define TEST_ADD(t, a, b)	(PPC_INST_ADD | ___PPC_RT(t) |		\
+					___PPC_RA(a) | ___PPC_RB(b))
+#define TEST_ADD_DOT(t, a, b)	(PPC_INST_ADD | ___PPC_RT(t) |		\
+					___PPC_RA(a) | ___PPC_RB(b) | 0x1)
 
 #define MAX_SUBTESTS	16
 
@@ -473,6 +477,178 @@ static struct compute_test compute_tests[] = {
 				}
 			}
 		}
+	},
+	{
+		.mnemonic = "add",
+		.subtests = {
+			{
+				.descr = "RA = LONG_MIN, RB = LONG_MIN",
+				.instr = TEST_ADD(20, 21, 22),
+				.regs = {
+					.gpr[21] = LONG_MIN,
+					.gpr[22] = LONG_MIN,
+				}
+			},
+			{
+				.descr = "RA = LONG_MIN, RB = LONG_MAX",
+				.instr = TEST_ADD(20, 21, 22),
+				.regs = {
+					.gpr[21] = LONG_MIN,
+					.gpr[22] = LONG_MAX,
+				}
+			},
+			{
+				.descr = "RA = LONG_MAX, RB = LONG_MAX",
+				.instr = TEST_ADD(20, 21, 22),
+				.regs = {
+					.gpr[21] = LONG_MAX,
+					.gpr[22] = LONG_MAX,
+				}
+			},
+			{
+				.descr = "RA = ULONG_MAX, RB = ULONG_MAX",
+				.instr = TEST_ADD(20, 21, 22),
+				.regs = {
+					.gpr[21] = ULONG_MAX,
+					.gpr[22] = ULONG_MAX,
+				}
+			},
+			{
+				.descr = "RA = ULONG_MAX, RB = 0x1",
+				.instr = TEST_ADD(20, 21, 22),
+				.regs = {
+					.gpr[21] = ULONG_MAX,
+					.gpr[22] = 0x1,
+				}
+			},
+			{
+				.descr = "RA = INT_MIN, RB = INT_MIN",
+				.instr = TEST_ADD(20, 21, 22),
+				.regs = {
+					.gpr[21] = INT_MIN,
+					.gpr[22] = INT_MIN,
+				}
+			},
+			{
+				.descr = "RA = INT_MIN, RB = INT_MAX",
+				.instr = TEST_ADD(20, 21, 22),
+				.regs = {
+					.gpr[21] = INT_MIN,
+					.gpr[22] = INT_MAX,
+				}
+			},
+			{
+				.descr = "RA = INT_MAX, RB = INT_MAX",
+				.instr = TEST_ADD(20, 21, 22),
+				.regs = {
+					.gpr[21] = INT_MAX,
+					.gpr[22] = INT_MAX,
+				}
+			},
+			{
+				.descr = "RA = UINT_MAX, RB = UINT_MAX",
+				.instr = TEST_ADD(20, 21, 22),
+				.regs = {
+					.gpr[21] = UINT_MAX,
+					.gpr[22] = UINT_MAX,
+				}
+			},
+			{
+				.descr = "RA = UINT_MAX, RB = 0x1",
+				.instr = TEST_ADD(20, 21, 22),
+				.regs = {
+					.gpr[21] = UINT_MAX,
+					.gpr[22] = 0x1,
+				}
+			}
+		}
+	},
+	{
+		.mnemonic = "add.",
+		.subtests = {
+			{
+				.descr = "RA = LONG_MIN, RB = LONG_MIN",
+				.flags = IGNORE_CCR,
+				.instr = TEST_ADD_DOT(20, 21, 22),
+				.regs = {
+					.gpr[21] = LONG_MIN,
+					.gpr[22] = LONG_MIN,
+				}
+			},
+			{
+				.descr = "RA = LONG_MIN, RB = LONG_MAX",
+				.instr = TEST_ADD_DOT(20, 21, 22),
+				.regs = {
+					.gpr[21] = LONG_MIN,
+					.gpr[22] = LONG_MAX,
+				}
+			},
+			{
+				.descr = "RA = LONG_MAX, RB = LONG_MAX",
+				.flags = IGNORE_CCR,
+				.instr = TEST_ADD_DOT(20, 21, 22),
+				.regs = {
+					.gpr[21] = LONG_MAX,
+					.gpr[22] = LONG_MAX,
+				}
+			},
+			{
+				.descr = "RA = ULONG_MAX, RB = ULONG_MAX",
+				.instr = TEST_ADD_DOT(20, 21, 22),
+				.regs = {
+					.gpr[21] = ULONG_MAX,
+					.gpr[22] = ULONG_MAX,
+				}
+			},
+			{
+				.descr = "RA = ULONG_MAX, RB = 0x1",
+				.instr = TEST_ADD_DOT(20, 21, 22),
+				.regs = {
+					.gpr[21] = ULONG_MAX,
+					.gpr[22] = 0x1,
+				}
+			},
+			{
+				.descr = "RA = INT_MIN, RB = INT_MIN",
+				.instr = TEST_ADD_DOT(20, 21, 22),
+				.regs = {
+					.gpr[21] = INT_MIN,
+					.gpr[22] = INT_MIN,
+				}
+			},
+			{
+				.descr = "RA = INT_MIN, RB = INT_MAX",
+				.instr = TEST_ADD_DOT(20, 21, 22),
+				.regs = {
+					.gpr[21] = INT_MIN,
+					.gpr[22] = INT_MAX,
+				}
+			},
+			{
+				.descr = "RA = INT_MAX, RB = INT_MAX",
+				.instr = TEST_ADD_DOT(20, 21, 22),
+				.regs = {
+					.gpr[21] = INT_MAX,
+					.gpr[22] = INT_MAX,
+				}
+			},
+			{
+				.descr = "RA = UINT_MAX, RB = UINT_MAX",
+				.instr = TEST_ADD_DOT(20, 21, 22),
+				.regs = {
+					.gpr[21] = UINT_MAX,
+					.gpr[22] = UINT_MAX,
+				}
+			},
+			{
+				.descr = "RA = UINT_MAX, RB = 0x1",
+				.instr = TEST_ADD_DOT(20, 21, 22),
+				.regs = {
+					.gpr[21] = UINT_MAX,
+					.gpr[22] = 0x1,
+				}
+			}
+		}
 	}
 };
 
Signature · 1 line
2.19.2
#6 lore raw

PATCH 3/3 powerpc: sstep: Add tests for addc[.] instruction

In reply to Sandipan Das

This adds test cases for the addc[.] instruction.

---
 arch/powerpc/include/asm/ppc-opcode.h |   1 +
 arch/powerpc/lib/test_emulate_step.c  | 192 ++++++++++++++++++++++++++
 2 files changed, 193 insertions(+)
arch/powerpc/include/asm/ppc-opcode.h +1 -0
index 19a8834e0398..87b73aa56b53 100644
@@ -326,6 +326,7 @@
 #define PPC_INST_ADDI			0x38000000
 #define PPC_INST_ADDIS			0x3c000000
 #define PPC_INST_ADD			0x7c000214
+#define PPC_INST_ADDC			0x7c000014
 #define PPC_INST_SUB			0x7c000050
 #define PPC_INST_BLR			0x4e800020
 #define PPC_INST_BLRL			0x4e800021
arch/powerpc/lib/test_emulate_step.c +192 -0

204 lines not on this page · raw message

Signature · 1 line
2.19.2