Skip to contentSkip to conversation

powerpc sstep: Add tests for prefixed integer load/stores

PATCH Applied Jordan Niethe 3 participants 8 messages May 25, 2020 – Jul 24, 2020 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 powerpc sstep: Add tests for prefixed integer load/stores

Add tests for the prefixed versions of the integer load/stores that are currently tested. This includes the following instructions:
* Prefixed Load Doubleword (pld)
* Prefixed Load Word and Zero (plwz)
* Prefixed Store Doubleword (pstd)

Skip the new tests if ISA v3.1 is unsupported.

---
 arch/powerpc/include/asm/ppc-opcode.h |  9 +++
 arch/powerpc/lib/test_emulate_step.c  | 95 +++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)
arch/powerpc/include/asm/ppc-opcode.h +9 -0
index 2a39c716c343..9e3ecb42597e 100644
@@ -380,6 +380,14 @@
 #define PPC_INST_VCMPEQUD		0x100000c7
 #define PPC_INST_VCMPEQUB		0x10000006
 
+/* Prefixes */
+#define PPC_PREFIX_MLS			0x06000000
+#define PPC_PREFIX_8LS			0x04000000
+
+/* Prefixed instructions */
+#define PPC_INST_PLD			0xe4000000
+#define PPC_INST_PSTD			0xf4000000
+
 /* macros to insert fields into opcodes */
 #define ___PPC_RA(a)	(((a) & 0x1f) << 16)
 #define ___PPC_RB(b)	(((b) & 0x1f) << 11)
@@ -411,6 +419,7 @@
 #define __PPC_CT(t)	(((t) & 0x0f) << 21)
 #define __PPC_SPR(r)	((((r) & 0x1f) << 16) | ((((r) >> 5) & 0x1f) << 11))
 #define __PPC_RC21	(0x1 << 10)
+#define __PPC_PRFX_R(r)	(((r) & 0x1) << 20)
 
 /*
  * Both low and high 16 bits are added as SIGNED additions, so if low 16 bits
arch/powerpc/lib/test_emulate_step.c +95 -0

140 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/5 powerpc sstep: Add tests for prefixed floating-point load/stores

Add tests for the prefixed versions of the floating-point load/stores that are currently tested. This includes the following instructions:
* Prefixed Load Floating-Point Single (plfs)
* Prefixed Load Floating-Point Double (plfd)
* Prefixed Store Floating-Point Single (pstfs)
* Prefixed Store Floating-Point Double (pstfd)

Skip the new tests if ISA v3.10 is unsupported.

---
 arch/powerpc/include/asm/ppc-opcode.h |   4 +
 arch/powerpc/lib/test_emulate_step.c  | 136 ++++++++++++++++++++++++++
 2 files changed, 140 insertions(+)
arch/powerpc/include/asm/ppc-opcode.h +4 -0
index 9e3ecb42597e..6b5edec0e347 100644
@@ -371,9 +371,13 @@
 #define PPC_INST_LBZCIX			0x7c0006aa
 #define PPC_INST_STBCIX			0x7c0007aa
 #define PPC_INST_LWZX			0x7c00002e
+#define PPC_INST_LFS			0xc0000000
 #define PPC_INST_LFSX			0x7c00042e
+#define PPC_INST_STFS			0xd0000000
 #define PPC_INST_STFSX			0x7c00052e
+#define PPC_INST_LFD			0xc8000000
 #define PPC_INST_LFDX			0x7c0004ae
+#define PPC_INST_STFD			0xd8000000
 #define PPC_INST_STFDX			0x7c0005ae
 #define PPC_INST_LVX			0x7c0000ce
 #define PPC_INST_STVX			0x7c0001ce
arch/powerpc/lib/test_emulate_step.c +136 -0

178 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

PATCH 3/5 powerpc sstep: Set NIP in instruction emulation tests

In reply to Jordan Niethe

The tests for emulation of compute instructions execute and emulate an instruction and then compare the results to verify the emulation. In ISA v3.1 there are instructions that operate relative to the NIP. Therefore set the NIP in the regs used for the emulated instruction to the location of the executed instruction so they will give the same result.

This is a rework of a patch by Balamuruhan S.

---
 arch/powerpc/lib/test_emulate_step.c | 3 +++
 1 file changed, 3 insertions(+)
arch/powerpc/lib/test_emulate_step.c +3 -0
index 9599f3a03ca1..427c2ca8191e 100644
@@ -1076,11 +1076,14 @@ static struct compute_test compute_tests[] = {
 static int __init emulate_compute_instr(struct pt_regs *regs,
 					struct ppc_inst instr)
 {
+	extern s32 patch__exec_instr;
 	struct instruction_op op;
 
 	if (!regs || !ppc_inst_val(instr))
 		return -EINVAL;
 
+	regs->nip = patch_site_addr(&patch__exec_instr);
+
 	if (analyse_instr(&op, regs, instr) != 1 ||
 	    GETTYPE(op.type) != COMPUTE) {
 		pr_info("emulation failed, instruction = 0x%08x\n", ppc_inst_val(instr));
Signature · 1 line
2.17.1
#3 lore raw

PATCH 4/5 powerpc sstep: Let compute tests specify a required cpu feature

In reply to Jordan Niethe

An a array of struct compute_test's are used to declare tests for compute instructions. Add a cpu_feature field to struct compute_test as an optional way to specify a cpu feature that must be present. If not present then skip the test.

---
 arch/powerpc/lib/test_emulate_step.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/powerpc/lib/test_emulate_step.c +6 -0
index 427c2ca8191e..579b5db80674 100644
@@ -690,6 +690,7 @@ static void __init run_tests_load_store(void)
 
 struct compute_test {
 	char *mnemonic;
+	unsigned long cpu_feature;
 	struct {
 		char *descr;
 		unsigned long flags;
@@ -1133,6 +1134,11 @@ static void __init run_tests_compute(void)
 	for (i = 0; i < ARRAY_SIZE(compute_tests); i++) {
 		test = &compute_tests[i];
 
+		if (test->cpu_feature && !early_cpu_has_feature(test->cpu_feature)) {
+			show_result(test->mnemonic, "SKIP (!CPU_FTR)");
+			continue;
+		}
+
 		for (j = 0; j < MAX_SUBTESTS && test->subtests[j].descr; j++) {
 			instr = test->subtests[j].instr;
 			flags = test->subtests[j].flags;
Signature · 1 line
2.17.1
#4 lore raw

PATCH 5/5 powerpc sstep: Add tests for Prefixed Add Immediate

In reply to Jordan Niethe

Use the existing support for testing compute type instructions to test Prefixed Add Immediate (paddi). The R bit of the paddi instruction controls whether current instruction address is used. Add test cases for when R=1 and for R=0. paddi has a 34 bit immediate field formed by concatenating si0 and si1. Add tests for the extreme values of this field.

Skip the paddi tests if ISA v3.1 is unsupported.

Some of these test cases were added by Balamuruhan S.

---
 arch/powerpc/lib/test_emulate_step.c          | 127 ++++++++++++++++++
 .../lib/test_emulate_step_exec_instr.S        |   1 +
 2 files changed, 128 insertions(+)
arch/powerpc/lib/test_emulate_step.c +127 -0
index 579b5db80674..33a72b7d2764 100644
@@ -105,6 +105,13 @@
 					___PPC_RA(a) | ___PPC_RB(b))
 #define TEST_ADDC_DOT(t, a, b)	ppc_inst(PPC_INST_ADDC | ___PPC_RT(t) |		\
 					___PPC_RA(a) | ___PPC_RB(b) | 0x1)
+#define TEST_PADDI(t, a, i, pr)	ppc_inst_prefix(PPC_PREFIX_MLS | __PPC_PRFX_R(pr) |	\
+					IMM_H(i),			\
+					PPC_INST_ADDI |			\
+					___PPC_RT(t) | ___PPC_RA(a) |	\
+					IMM_L(i))
+
+
 
 #define MAX_SUBTESTS	16
 
@@ -699,6 +706,11 @@ struct compute_test {
 	} subtests[MAX_SUBTESTS + 1];
 };
 
+/* Extreme values for si0||si1 (the MLS:D-form 34 bit immediate field) */
+#define SI_MIN BIT(33)
+#define SI_MAX (BIT(33) - 1)
+#define SI_UMAX (BIT(34) - 1)
+
 static struct compute_test compute_tests[] = {
 	{
 		.mnemonic = "nop",
@@ -1071,6 +1083,121 @@ static struct compute_test compute_tests[] = {
 				}
 			}
 		}
+	},
+	{
+		.mnemonic = "paddi",
+		.cpu_feature = CPU_FTR_ARCH_31,
+		.subtests = {
+			{
+				.descr = "RA = LONG_MIN, SI = SI_MIN, R = 0",
+				.instr = TEST_PADDI(21, 22, SI_MIN, 0),
+				.regs = {
+					.gpr[21] = 0,
+					.gpr[22] = LONG_MIN,
+				}
+			},
+			{
+				.descr = "RA = LONG_MIN, SI = SI_MAX, R = 0",
+				.instr = TEST_PADDI(21, 22, SI_MAX, 0),
+				.regs = {
+					.gpr[21] = 0,
+					.gpr[22] = LONG_MIN,
+				}
+			},
+			{
+				.descr = "RA = LONG_MAX, SI = SI_MAX, R = 0",
+				.instr = TEST_PADDI(21, 22, SI_MAX, 0),
+				.regs = {
+					.gpr[21] = 0,
+					.gpr[22] = LONG_MAX,
+				}
+			},
+			{
+				.descr = "RA = ULONG_MAX, SI = SI_UMAX, R = 0",
+				.instr = TEST_PADDI(21, 22, SI_UMAX, 0),
+				.regs = {
+					.gpr[21] = 0,
+					.gpr[22] = ULONG_MAX,
+				}
+			},
+			{
+				.descr = "RA = ULONG_MAX, SI = 0x1, R = 0",
+				.instr = TEST_PADDI(21, 22, 0x1, 0),
+				.regs = {
+					.gpr[21] = 0,
+					.gpr[22] = ULONG_MAX,
+				}
+			},
+			{
+				.descr = "RA = INT_MIN, SI = SI_MIN, R = 0",
+				.instr = TEST_PADDI(21, 22, SI_MIN, 0),
+				.regs = {
+					.gpr[21] = 0,
+					.gpr[22] = INT_MIN,
+				}
+			},
+			{
+				.descr = "RA = INT_MIN, SI = SI_MAX, R = 0",
+				.instr = TEST_PADDI(21, 22, SI_MAX, 0),
+				.regs = {
+					.gpr[21] = 0,
+					.gpr[22] = INT_MIN,
+				}
+			},
+			{
+				.descr = "RA = INT_MAX, SI = SI_MAX, R = 0",
+				.instr = TEST_PADDI(21, 22, SI_MAX, 0),
+				.regs = {
+					.gpr[21] = 0,
+					.gpr[22] = INT_MAX,
+				}
+			},
+			{
+				.descr = "RA = UINT_MAX, SI = 0x1, R = 0",
+				.instr = TEST_PADDI(21, 22, 0x1, 0),
+				.regs = {
+					.gpr[21] = 0,
+					.gpr[22] = UINT_MAX,
+				}
+			},
+			{
+				.descr = "RA = UINT_MAX, SI = SI_MAX, R = 0",
+				.instr = TEST_PADDI(21, 22, SI_MAX, 0),
+				.regs = {
+					.gpr[21] = 0,
+					.gpr[22] = UINT_MAX,
+				}
+			},
+			{
+				.descr = "RA is r0, SI = SI_MIN, R = 0",
+				.instr = TEST_PADDI(21, 0, SI_MIN, 0),
+				.regs = {
+					.gpr[21] = 0x0,
+				}
+			},
+			{
+				.descr = "RA = 0, SI = SI_MIN, R = 0",
+				.instr = TEST_PADDI(21, 22, SI_MIN, 0),
+				.regs = {
+					.gpr[21] = 0x0,
+					.gpr[22] = 0x0,
+				}
+			},
+			{
+				.descr = "RA is r0, SI = 0, R = 1",
+				.instr = TEST_PADDI(21, 0, 0, 1),
+				.regs = {
+					.gpr[21] = 0,
+				}
+			},
+			{
+				.descr = "RA is r0, SI = SI_MIN, R = 1",
+				.instr = TEST_PADDI(21, 0, SI_MIN, 1),
+				.regs = {
+					.gpr[21] = 0,
+				}
+			}
+		}
 	}
 };
 
arch/powerpc/lib/test_emulate_step_exec_instr.S +1 -0
index 1580f34f4f4f..aef53ee77a43 100644
@@ -81,6 +81,7 @@ _GLOBAL(exec_instr)
 
 	/* Placeholder for the test instruction */
 1:	nop
+	nop
 	patch_site 1b patch__exec_instr
 
 	/*
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH 5/5] powerpc sstep: Add tests for Prefixed Add Immediate

Quoted 183 lines · Jordan Niethe

Use the existing support for testing compute type instructions to test Prefixed Add Immediate (paddi). The R bit of the paddi instruction controls whether current instruction address is used. Add test cases for when R=1 and for R=0. paddi has a 34 bit immediate field formed by concatenating si0 and si1. Add tests for the extreme values of this field.

Skip the paddi tests if ISA v3.1 is unsupported.

Some of these test cases were added by Balamuruhan S.

---
 arch/powerpc/lib/test_emulate_step.c          | 127 ++++++++++++++++++
 .../lib/test_emulate_step_exec_instr.S        |   1 +
 2 files changed, 128 insertions(+)
arch/powerpc/lib/test_emulate_step.c +127 -0
index 579b5db80674..33a72b7d2764 100644
@@ -105,6 +105,13 @@
                                        ___PPC_RA(a) | ___PPC_RB(b))
 #define TEST_ADDC_DOT(t, a, b) ppc_inst(PPC_INST_ADDC | ___PPC_RT(t) |         \
                                        ___PPC_RA(a) | ___PPC_RB(b) | 0x1)
+#define TEST_PADDI(t, a, i, pr)        ppc_inst_prefix(PPC_PREFIX_MLS | __PPC_PRFX_R(pr) |     \
+                                       IMM_H(i),                       \
+                                       PPC_INST_ADDI |                 \
+                                       ___PPC_RT(t) | ___PPC_RA(a) |   \
+                                       IMM_L(i))
+
+
 
 #define MAX_SUBTESTS   16
 
@@ -699,6 +706,11 @@ struct compute_test {
        } subtests[MAX_SUBTESTS + 1];
 };
 
+/* Extreme values for si0||si1 (the MLS:D-form 34 bit immediate field) */
+#define SI_MIN BIT(33)
+#define SI_MAX (BIT(33) - 1)
+#define SI_UMAX (BIT(34) - 1)
+
 static struct compute_test compute_tests[] = {
        {
                .mnemonic = "nop",
@@ -1071,6 +1083,121 @@ static struct compute_test compute_tests[] = {
                                }
                        }
                }
+       },
+       {
+               .mnemonic = "paddi",
+               .cpu_feature = CPU_FTR_ARCH_31,
+               .subtests = {
+                       {
+                               .descr = "RA = LONG_MIN, SI = SI_MIN, R = 0",
+                               .instr = TEST_PADDI(21, 22, SI_MIN, 0),
+                               .regs = {
+                                       .gpr[21] = 0,
+                                       .gpr[22] = LONG_MIN,
+                               }
+                       },
+                       {
+                               .descr = "RA = LONG_MIN, SI = SI_MAX, R = 0",
+                               .instr = TEST_PADDI(21, 22, SI_MAX, 0),
+                               .regs = {
+                                       .gpr[21] = 0,
+                                       .gpr[22] = LONG_MIN,
+                               }
+                       },
+                       {
+                               .descr = "RA = LONG_MAX, SI = SI_MAX, R = 0",
+                               .instr = TEST_PADDI(21, 22, SI_MAX, 0),
+                               .regs = {
+                                       .gpr[21] = 0,
+                                       .gpr[22] = LONG_MAX,
+                               }
+                       },
+                       {
+                               .descr = "RA = ULONG_MAX, SI = SI_UMAX, R = 0",
+                               .instr = TEST_PADDI(21, 22, SI_UMAX, 0),
+                               .regs = {
+                                       .gpr[21] = 0,
+                                       .gpr[22] = ULONG_MAX,
+                               }
+                       },
+                       {
+                               .descr = "RA = ULONG_MAX, SI = 0x1, R = 0",
+                               .instr = TEST_PADDI(21, 22, 0x1, 0),
+                               .regs = {
+                                       .gpr[21] = 0,
+                                       .gpr[22] = ULONG_MAX,
+                               }
+                       },
+                       {
+                               .descr = "RA = INT_MIN, SI = SI_MIN, R = 0",
+                               .instr = TEST_PADDI(21, 22, SI_MIN, 0),
+                               .regs = {
+                                       .gpr[21] = 0,
+                                       .gpr[22] = INT_MIN,
+                               }
+                       },
+                       {
+                               .descr = "RA = INT_MIN, SI = SI_MAX, R = 0",
+                               .instr = TEST_PADDI(21, 22, SI_MAX, 0),
+                               .regs = {
+                                       .gpr[21] = 0,
+                                       .gpr[22] = INT_MIN,
+                               }
+                       },
+                       {
+                               .descr = "RA = INT_MAX, SI = SI_MAX, R = 0",
+                               .instr = TEST_PADDI(21, 22, SI_MAX, 0),
+                               .regs = {
+                                       .gpr[21] = 0,
+                                       .gpr[22] = INT_MAX,
+                               }
+                       },
+                       {
+                               .descr = "RA = UINT_MAX, SI = 0x1, R = 0",
+                               .instr = TEST_PADDI(21, 22, 0x1, 0),
+                               .regs = {
+                                       .gpr[21] = 0,
+                                       .gpr[22] = UINT_MAX,
+                               }
+                       },
+                       {
+                               .descr = "RA = UINT_MAX, SI = SI_MAX, R = 0",
+                               .instr = TEST_PADDI(21, 22, SI_MAX, 0),
+                               .regs = {
+                                       .gpr[21] = 0,
+                                       .gpr[22] = UINT_MAX,
+                               }
+                       },
+                       {
+                               .descr = "RA is r0, SI = SI_MIN, R = 0",
+                               .instr = TEST_PADDI(21, 0, SI_MIN, 0),
+                               .regs = {
+                                       .gpr[21] = 0x0,
+                               }
+                       },
+                       {
+                               .descr = "RA = 0, SI = SI_MIN, R = 0",
+                               .instr = TEST_PADDI(21, 22, SI_MIN, 0),
+                               .regs = {
+                                       .gpr[21] = 0x0,
+                                       .gpr[22] = 0x0,
+                               }
+                       },
+                       {
+                               .descr = "RA is r0, SI = 0, R = 1",
+                               .instr = TEST_PADDI(21, 0, 0, 1),
+                               .regs = {
+                                       .gpr[21] = 0,
+                               }
+                       },
+                       {
+                               .descr = "RA is r0, SI = SI_MIN, R = 1",
+                               .instr = TEST_PADDI(21, 0, SI_MIN, 1),
+                               .regs = {
+                                       .gpr[21] = 0,
+                               }
+                       }
+               }
        }
 };
 
arch/powerpc/lib/test_emulate_step_exec_instr.S +1 -1
index 1580f34f4f4f..aef53ee77a43 100644
@@ -81,6 +81,7 @@ _GLOBAL(exec_instr)
 
        /* Placeholder for the test instruction */
 1:     nop
+       nop
        patch_site 1b patch__exec_instr
 
        /*
--
Quoted 2 lines

2.17.1

Because of the alignment requirements of prefixed instructions, the noops to be patched need to be aligned.
mpe, want me to send a new version?

arch/powerpc/lib/test_emulate_step_exec_instr.S +1 -0
@@ -80,6 +80,7 @@ _GLOBAL(exec_instr)
        REST_NVGPRS(r31)
 
        /* Placeholder for the test instruction */
+.align 6
 1:     nop
        nop
        patch_site 1b patch__exec_instr
#6 lore raw

Re: [PATCH 5/5] powerpc sstep: Add tests for Prefixed Add Immediate

Quoted 18 lines · Jordan Niethe
Quoted 17 lines · Jordan Niethe

Use the existing support for testing compute type instructions to test Prefixed Add Immediate (paddi). The R bit of the paddi instruction controls whether current instruction address is used. Add test cases for when R=1 and for R=0. paddi has a 34 bit immediate field formed by concatenating si0 and si1. Add tests for the extreme values of this field.

Skip the paddi tests if ISA v3.1 is unsupported.

Some of these test cases were added by Balamuruhan S.

---
 arch/powerpc/lib/test_emulate_step.c          | 127 ++++++++++++++++++
 .../lib/test_emulate_step_exec_instr.S        |   1 +
 2 files changed, 128 insertions(+)

...

Quoted 11 lines
Quoted 11 lines
arch/powerpc/lib/test_emulate_step_exec_instr.S +1 -0
index 1580f34f4f4f..aef53ee77a43 100644
@@ -81,6 +81,7 @@ _GLOBAL(exec_instr)
 
        /* Placeholder for the test instruction */
 1:     nop
+       nop
        patch_site 1b patch__exec_instr
 
Quoted 8 lines
Quoted 4 lines
arch/powerpc/lib/test_emulate_step_exec_instr.S +0 -1
        /*
--

2.17.1

Because of the alignment requirements of prefixed instructions, the noops to be patched need to be aligned.
mpe, want me to send a new version?

No I'll just squash it in.

arch/powerpc/lib/test_emulate_step_exec_instr.S _GLOBAL(exec_instr) · line 83

Quoted 7 lines
arch/powerpc/lib/test_emulate_step_exec_instr.S +1 -0
@@ -80,6 +80,7 @@ _GLOBAL(exec_instr)
        REST_NVGPRS(r31)
 
        /* Placeholder for the test instruction */
+.align 6

I'll change it to .balign 64.

arch/powerpc/lib/test_emulate_step_exec_instr.S _GLOBAL(exec_instr) · line 86

Quoted 3 lines
arch/powerpc/lib/test_emulate_step_exec_instr.S +0 -0
 1:     nop
        nop
        patch_site 1b patch__exec_instr

cheers

#7 lore raw
In reply to Jordan Niethe
Quoted 7 lines · Jordan Niethe

Add tests for the prefixed versions of the integer load/stores that are currently tested. This includes the following instructions:
* Prefixed Load Doubleword (pld)
* Prefixed Load Word and Zero (plwz)
* Prefixed Store Doubleword (pstd)

Skip the new tests if ISA v3.1 is unsupported.

Applied to powerpc/next.

[1/5] powerpc/sstep: Add tests for prefixed integer load/stores

      https://git.kernel.org/powerpc/c/b6b54b42722a2393056c891c0d05cd8cc40eb776
[2/5] powerpc/sstep: Add tests for prefixed floating-point load/stores
      https://git.kernel.org/powerpc/c/0396de6d8561c721b03fce386eb9682b37a26013
[3/5] powerpc/sstep: Set NIP in instruction emulation tests
      https://git.kernel.org/powerpc/c/1c89cf7fbed36f078b20fd47d308b4fc6dbff5f6
[4/5] powerpc/sstep: Let compute tests specify a required cpu feature
      https://git.kernel.org/powerpc/c/301ebf7d69f6709575d137a41a0291f69f343aed
[5/5] powerpc/sstep: Add tests for Prefixed Add Immediate
      https://git.kernel.org/powerpc/c/4f825900786e1c24e4c48622e12eb493a6cd27b6

cheers