linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] powerpc/sstep: Fix kernel crash if VSX is not present
@ 2018-05-21  4:21 Ravi Bangoria
  2018-05-21  4:21 ` [PATCH 1/3] powerpc/sstep: Introduce GETTYPE macro Ravi Bangoria
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ravi Bangoria @ 2018-05-21  4:21 UTC (permalink / raw)
  To: mpe, mikey
  Cc: benh, paulus, naveen.n.rao, matthew.brown.dev, cyrilbur, anton,
	sandipan, linuxppc-dev, linux-kernel, Ravi Bangoria

This is a next version to RFC patch:
  https://lkml.org/lkml/2018/5/16/36

kbuild test robot reported the following build failure with RFC.

   error: unused variable 'type' [-Werror=unused-variable]
     int type;
         ^~~~

I've fixed it along with following changes.

1st patch introduces a new macro to simplify code a bit.
2nd patch fixes the kernel crash when VSX is not supported
    or disabled.
3rd patch fixes emulate_step() tests

Ravi Bangoria (3):
  powerpc/sstep: Introduce GETTYPE macro
  powerpc/sstep: Fix kernel crash if VSX is not present
  powerpc/sstep: Fix emulate_step test if VSX not present

 arch/powerpc/include/asm/sstep.h     |  2 ++
 arch/powerpc/kernel/align.c          |  2 +-
 arch/powerpc/lib/sstep.c             | 15 ++++++++++++---
 arch/powerpc/lib/test_emulate_step.c | 21 +++++++++++++++------
 4 files changed, 30 insertions(+), 10 deletions(-)

-- 
2.16.2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] powerpc/sstep: Introduce GETTYPE macro
  2018-05-21  4:21 [PATCH 0/3] powerpc/sstep: Fix kernel crash if VSX is not present Ravi Bangoria
@ 2018-05-21  4:21 ` Ravi Bangoria
  2018-06-04 14:11   ` [1/3] " Michael Ellerman
  2018-05-21  4:21 ` [PATCH 2/3] powerpc/sstep: Fix kernel crash if VSX is not present Ravi Bangoria
  2018-05-21  4:21 ` [PATCH 3/3] powerpc/sstep: Fix emulate_step test if VSX " Ravi Bangoria
  2 siblings, 1 reply; 5+ messages in thread
From: Ravi Bangoria @ 2018-05-21  4:21 UTC (permalink / raw)
  To: mpe, mikey
  Cc: benh, paulus, naveen.n.rao, matthew.brown.dev, cyrilbur, anton,
	sandipan, linuxppc-dev, linux-kernel, Ravi Bangoria

Replace 'op->type & INSTR_TYPE_MASK' expression with GETTYPE(op->type)
macro.

Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
---
 arch/powerpc/include/asm/sstep.h | 2 ++
 arch/powerpc/kernel/align.c      | 2 +-
 arch/powerpc/lib/sstep.c         | 6 +++---
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/include/asm/sstep.h b/arch/powerpc/include/asm/sstep.h
index ab9d849644d0..9a2dfee26f9f 100644
--- a/arch/powerpc/include/asm/sstep.h
+++ b/arch/powerpc/include/asm/sstep.h
@@ -97,6 +97,8 @@ enum instruction_type {
 #define SIZE(n)		((n) << 12)
 #define GETSIZE(w)	((w) >> 12)
 
+#define GETTYPE(t)	((t) & INSTR_TYPE_MASK)
+
 #define MKOP(t, f, s)	((t) | (f) | SIZE(s))
 
 struct instruction_op {
diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c
index 3e6c0744c174..11550a3d1ac2 100644
--- a/arch/powerpc/kernel/align.c
+++ b/arch/powerpc/kernel/align.c
@@ -339,7 +339,7 @@ int fix_alignment(struct pt_regs *regs)
 	if (r < 0)
 		return -EINVAL;
 
-	type = op.type & INSTR_TYPE_MASK;
+	type = GETTYPE(op.type);
 	if (!OP_IS_LOAD_STORE(type)) {
 		if (op.type != CACHEOP + DCBZ)
 			return -EINVAL;
diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index 34d68f1b1b40..db6bba259d91 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -2641,7 +2641,7 @@ void emulate_update_regs(struct pt_regs *regs, struct instruction_op *op)
 	unsigned long next_pc;
 
 	next_pc = truncate_if_32bit(regs->msr, regs->nip + 4);
-	switch (op->type & INSTR_TYPE_MASK) {
+	switch (GETTYPE(op->type)) {
 	case COMPUTE:
 		if (op->type & SETREG)
 			regs->gpr[op->reg] = op->val;
@@ -2739,7 +2739,7 @@ int emulate_loadstore(struct pt_regs *regs, struct instruction_op *op)
 
 	err = 0;
 	size = GETSIZE(op->type);
-	type = op->type & INSTR_TYPE_MASK;
+	type = GETTYPE(op->type);
 	cross_endian = (regs->msr & MSR_LE) != (MSR_KERNEL & MSR_LE);
 	ea = truncate_if_32bit(regs->msr, op->ea);
 
@@ -3001,7 +3001,7 @@ int emulate_step(struct pt_regs *regs, unsigned int instr)
 	}
 
 	err = 0;
-	type = op.type & INSTR_TYPE_MASK;
+	type = GETTYPE(op.type);
 
 	if (OP_IS_LOAD_STORE(type)) {
 		err = emulate_loadstore(regs, &op);
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] powerpc/sstep: Fix kernel crash if VSX is not present
  2018-05-21  4:21 [PATCH 0/3] powerpc/sstep: Fix kernel crash if VSX is not present Ravi Bangoria
  2018-05-21  4:21 ` [PATCH 1/3] powerpc/sstep: Introduce GETTYPE macro Ravi Bangoria
@ 2018-05-21  4:21 ` Ravi Bangoria
  2018-05-21  4:21 ` [PATCH 3/3] powerpc/sstep: Fix emulate_step test if VSX " Ravi Bangoria
  2 siblings, 0 replies; 5+ messages in thread
From: Ravi Bangoria @ 2018-05-21  4:21 UTC (permalink / raw)
  To: mpe, mikey
  Cc: benh, paulus, naveen.n.rao, matthew.brown.dev, cyrilbur, anton,
	sandipan, linuxppc-dev, linux-kernel, Ravi Bangoria

emulate_step() is not checking runtime VSX feature flag before
emulating an instruction. This is causing kernel crash when kernel
is compiled with CONFIG_VSX=y but running on a machine where VSX
is not supported or disabled. Ex, while running emulate_step tests
on P6 machine:

  Oops: Exception in kernel mode, sig: 4 [#1]
  NIP [c000000000095c24] .load_vsrn+0x28/0x54
  LR [c000000000094bdc] .emulate_loadstore+0x167c/0x17b0
  Call Trace:
    0x40fe240c7ae147ae (unreliable)
    .emulate_loadstore+0x167c/0x17b0
    .emulate_step+0x25c/0x5bc
    .test_lxvd2x_stxvd2x+0x64/0x154
    .test_emulate_step+0x38/0x4c
    .do_one_initcall+0x5c/0x2c0
    .kernel_init_freeable+0x314/0x4cc
    .kernel_init+0x24/0x160
    .ret_from_kernel_thread+0x58/0xb4

With fix:
  emulate_step_test: lxvd2x         : FAIL
  emulate_step_test: stxvd2x        : FAIL

Fixes: https://github.com/linuxppc/linux/issues/148

Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
---
 arch/powerpc/lib/sstep.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index db6bba259d91..23b7ddf04521 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -2544,6 +2544,15 @@ int analyse_instr(struct instruction_op *op, const struct pt_regs *regs,
 #endif /* __powerpc64__ */
 
 	}
+
+#ifdef CONFIG_VSX
+	if ((GETTYPE(op->type) == LOAD_VSX ||
+	     GETTYPE(op->type) == STORE_VSX) &&
+	    !cpu_has_feature(CPU_FTR_VSX)) {
+		return -1;
+	}
+#endif /* CONFIG_VSX */
+
 	return 0;
 
  logical_done:
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] powerpc/sstep: Fix emulate_step test if VSX not present
  2018-05-21  4:21 [PATCH 0/3] powerpc/sstep: Fix kernel crash if VSX is not present Ravi Bangoria
  2018-05-21  4:21 ` [PATCH 1/3] powerpc/sstep: Introduce GETTYPE macro Ravi Bangoria
  2018-05-21  4:21 ` [PATCH 2/3] powerpc/sstep: Fix kernel crash if VSX is not present Ravi Bangoria
@ 2018-05-21  4:21 ` Ravi Bangoria
  2 siblings, 0 replies; 5+ messages in thread
From: Ravi Bangoria @ 2018-05-21  4:21 UTC (permalink / raw)
  To: mpe, mikey
  Cc: benh, paulus, naveen.n.rao, matthew.brown.dev, cyrilbur, anton,
	sandipan, linuxppc-dev, linux-kernel, Ravi Bangoria

emulate_step() tests are failing if VSX is not supported or disabled.

  emulate_step_test: lxvd2x         : FAIL
  emulate_step_test: stxvd2x        : FAIL

If !CPU_FTR_VSX, emulate_step() failure is expected and testcase should
PASS with a valid justification. After patch:

  emulate_step_test: lxvd2x         : PASS (!CPU_FTR_VSX)
  emulate_step_test: stxvd2x        : PASS (!CPU_FTR_VSX)

Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
---
 arch/powerpc/lib/test_emulate_step.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/lib/test_emulate_step.c b/arch/powerpc/lib/test_emulate_step.c
index 2534c1447554..6c47daa61614 100644
--- a/arch/powerpc/lib/test_emulate_step.c
+++ b/arch/powerpc/lib/test_emulate_step.c
@@ -387,10 +387,14 @@ static void __init test_lxvd2x_stxvd2x(void)
 	/* lxvd2x vsr39, r3, r4 */
 	stepped = emulate_step(&regs, TEST_LXVD2X(39, 3, 4));
 
-	if (stepped == 1)
+	if (stepped == 1 && cpu_has_feature(CPU_FTR_VSX)) {
 		show_result("lxvd2x", "PASS");
-	else
-		show_result("lxvd2x", "FAIL");
+	} else {
+		if (!cpu_has_feature(CPU_FTR_VSX))
+			show_result("lxvd2x", "PASS (!CPU_FTR_VSX)");
+		else
+			show_result("lxvd2x", "FAIL");
+	}
 
 
 	/*** stxvd2x ***/
@@ -404,10 +408,15 @@ static void __init test_lxvd2x_stxvd2x(void)
 	stepped = emulate_step(&regs, TEST_STXVD2X(39, 3, 4));
 
 	if (stepped == 1 && cached_b[0] == c.b[0] && cached_b[1] == c.b[1] &&
-	    cached_b[2] == c.b[2] && cached_b[3] == c.b[3])
+	    cached_b[2] == c.b[2] && cached_b[3] == c.b[3] &&
+	    cpu_has_feature(CPU_FTR_VSX)) {
 		show_result("stxvd2x", "PASS");
-	else
-		show_result("stxvd2x", "FAIL");
+	} else {
+		if (!cpu_has_feature(CPU_FTR_VSX))
+			show_result("stxvd2x", "PASS (!CPU_FTR_VSX)");
+		else
+			show_result("stxvd2x", "FAIL");
+	}
 }
 #else
 static void __init test_lxvd2x_stxvd2x(void)
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [1/3] powerpc/sstep: Introduce GETTYPE macro
  2018-05-21  4:21 ` [PATCH 1/3] powerpc/sstep: Introduce GETTYPE macro Ravi Bangoria
@ 2018-06-04 14:11   ` Michael Ellerman
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2018-06-04 14:11 UTC (permalink / raw)
  To: Ravi Bangoria, mikey
  Cc: sandipan, Ravi Bangoria, linux-kernel, matthew.brown.dev, paulus,
	anton, naveen.n.rao, linuxppc-dev, cyrilbur

On Mon, 2018-05-21 at 04:21:06 UTC, Ravi Bangoria wrote:
> Replace 'op->type & INSTR_TYPE_MASK' expression with GETTYPE(op->type)
> macro.
> 
> Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/e6684d07e4308430b9b6497265781a

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-06-04 14:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-21  4:21 [PATCH 0/3] powerpc/sstep: Fix kernel crash if VSX is not present Ravi Bangoria
2018-05-21  4:21 ` [PATCH 1/3] powerpc/sstep: Introduce GETTYPE macro Ravi Bangoria
2018-06-04 14:11   ` [1/3] " Michael Ellerman
2018-05-21  4:21 ` [PATCH 2/3] powerpc/sstep: Fix kernel crash if VSX is not present Ravi Bangoria
2018-05-21  4:21 ` [PATCH 3/3] powerpc/sstep: Fix emulate_step test if VSX " Ravi Bangoria

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).