All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] powerpc/emulate_step: Fix kernel crash when VSX is not present
@ 2018-05-16  5:40 Ravi Bangoria
  2018-05-16  7:08   ` Naveen N. Rao
  0 siblings, 1 reply; 3+ messages in thread
From: Ravi Bangoria @ 2018-05-16  5:40 UTC (permalink / raw)
  To: mpe
  Cc: benh, paulus, naveen.n.rao, anton, cyrilbur, matthew.brown.dev,
	sandipan, linuxppc-dev, linux-kernel, Ravi Bangoria

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

  ...
  emulate_step_test: lvx            : PASS
  emulate_step_test: stvx           : PASS
  Oops: Exception in kernel mode, sig: 4 [#1]
  NIP [c000000000095c24] .load_vsrn+0x28/0x54
  LR [c000000000094bdc] .emulate_loadstore+0x167c/0x17b0
  Call Trace:
  [c0000000494c3770] [40fe240c7ae147ae] 0x40fe240c7ae147ae (unreliable)
  [c0000000494c37f0] [c000000000094bdc] .emulate_loadstore+0x167c/0x17b0
  [c0000000494c3900] [c000000000094f6c] .emulate_step+0x25c/0x5bc
  [c0000000494c39b0] [c000000000ec90dc] .test_lxvd2x_stxvd2x+0x64/0x154
  [c0000000494c3b90] [c000000000ec9204] .test_emulate_step+0x38/0x4c
  [c0000000494c3c00] [c00000000000de2c] .do_one_initcall+0x5c/0x2c0
  [c0000000494c3cd0] [c000000000eb4bf8] .kernel_init_freeable+0x314/0x4cc
  [c0000000494c3db0] [c00000000000e1e4] .kernel_init+0x24/0x160
  [c0000000494c3e30] [c00000000000bc24] .ret_from_kernel_thread+0x58/0xb4

With fix:
  ...
  emulate_step_test: stvx           : PASS
  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>
---
Note: VSX was first introduced on P6. But there are many VSX instructions
      which were introduced in later versions. So ideally, analyse_instr()
      should check for ISA version along with opcode.

 arch/powerpc/lib/sstep.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index 34d68f1b1b40..470942f9c567 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -1173,6 +1173,7 @@ int analyse_instr(struct instruction_op *op, const struct pt_regs *regs,
 	unsigned long int val, val2;
 	unsigned int mb, me, sh;
 	long ival;
+	int type;
 
 	op->type = COMPUTE;
 
@@ -2544,6 +2545,15 @@ int analyse_instr(struct instruction_op *op, const struct pt_regs *regs,
 #endif /* __powerpc64__ */
 
 	}
+
+#ifdef CONFIG_VSX
+	type = op->type & INSTR_TYPE_MASK;
+	if ((type == LOAD_VSX || 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] 3+ messages in thread

* Re: [RFC] powerpc/emulate_step: Fix kernel crash when VSX is not present
  2018-05-16  5:40 [RFC] powerpc/emulate_step: Fix kernel crash when VSX is not present Ravi Bangoria
@ 2018-05-16  7:08   ` Naveen N. Rao
  0 siblings, 0 replies; 3+ messages in thread
From: Naveen N. Rao @ 2018-05-16  7:08 UTC (permalink / raw)
  To: mpe, Ravi Bangoria, Michael Neuling
  Cc: anton, cyrilbur, linux-kernel, linuxppc-dev, matthew.brown.dev,
	paulus, sandipan

[Adding Mikey]

Ravi Bangoria wrote:
> emulate_step() is not checking runtime VSX feature flag before
> emulating an instruction. This can cause kernel oops when kernel
> is compiled with CONFIG_VSX=y but running on machine where VSX is
> not supported or disabled. Ex, while running emulate_step tests on
> P6 machine:
> 
>   ...
>   emulate_step_test: lvx            : PASS
>   emulate_step_test: stvx           : PASS
>   Oops: Exception in kernel mode, sig: 4 [#1]
>   NIP [c000000000095c24] .load_vsrn+0x28/0x54
>   LR [c000000000094bdc] .emulate_loadstore+0x167c/0x17b0
>   Call Trace:
>   [c0000000494c3770] [40fe240c7ae147ae] 0x40fe240c7ae147ae (unreliable)
>   [c0000000494c37f0] [c000000000094bdc] .emulate_loadstore+0x167c/0x17b0
>   [c0000000494c3900] [c000000000094f6c] .emulate_step+0x25c/0x5bc
>   [c0000000494c39b0] [c000000000ec90dc] .test_lxvd2x_stxvd2x+0x64/0x154
>   [c0000000494c3b90] [c000000000ec9204] .test_emulate_step+0x38/0x4c
>   [c0000000494c3c00] [c00000000000de2c] .do_one_initcall+0x5c/0x2c0
>   [c0000000494c3cd0] [c000000000eb4bf8] .kernel_init_freeable+0x314/0x4cc
>   [c0000000494c3db0] [c00000000000e1e4] .kernel_init+0x24/0x160
>   [c0000000494c3e30] [c00000000000bc24] .ret_from_kernel_thread+0x58/0xb4
> 
> With fix:
>   ...
>   emulate_step_test: stvx           : PASS
>   emulate_step_test: lxvd2x         : FAIL
>   emulate_step_test: stxvd2x        : FAIL

Those tests should also be updated to skip testing these instructions if 
!CPU_FTR_VSX.

> 
> 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>
> ---
> Note: VSX was first introduced on P6. But there are many VSX instructions
>       which were introduced in later versions. So ideally, analyse_instr()
>       should check for ISA version along with opcode.

Yes, this patch should be useful for when VSX is not present. For 
specific instructions, we should add a cpu feature check.

- Naveen

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

* Re: [RFC] powerpc/emulate_step: Fix kernel crash when VSX is not present
@ 2018-05-16  7:08   ` Naveen N. Rao
  0 siblings, 0 replies; 3+ messages in thread
From: Naveen N. Rao @ 2018-05-16  7:08 UTC (permalink / raw)
  To: mpe, Ravi Bangoria, Michael Neuling
  Cc: anton, cyrilbur, linux-kernel, linuxppc-dev, matthew.brown.dev,
	paulus, sandipan

[Adding Mikey]

Ravi Bangoria wrote:
> emulate_step() is not checking runtime VSX feature flag before
> emulating an instruction. This can cause kernel oops when kernel
> is compiled with CONFIG_VSX=3Dy but running on machine where VSX is
> not supported or disabled. Ex, while running emulate_step tests on
> P6 machine:
>=20
>   ...
>   emulate_step_test: lvx            : PASS
>   emulate_step_test: stvx           : PASS
>   Oops: Exception in kernel mode, sig: 4 [#1]
>   NIP [c000000000095c24] .load_vsrn+0x28/0x54
>   LR [c000000000094bdc] .emulate_loadstore+0x167c/0x17b0
>   Call Trace:
>   [c0000000494c3770] [40fe240c7ae147ae] 0x40fe240c7ae147ae (unreliable)
>   [c0000000494c37f0] [c000000000094bdc] .emulate_loadstore+0x167c/0x17b0
>   [c0000000494c3900] [c000000000094f6c] .emulate_step+0x25c/0x5bc
>   [c0000000494c39b0] [c000000000ec90dc] .test_lxvd2x_stxvd2x+0x64/0x154
>   [c0000000494c3b90] [c000000000ec9204] .test_emulate_step+0x38/0x4c
>   [c0000000494c3c00] [c00000000000de2c] .do_one_initcall+0x5c/0x2c0
>   [c0000000494c3cd0] [c000000000eb4bf8] .kernel_init_freeable+0x314/0x4cc
>   [c0000000494c3db0] [c00000000000e1e4] .kernel_init+0x24/0x160
>   [c0000000494c3e30] [c00000000000bc24] .ret_from_kernel_thread+0x58/0xb4
>=20
> With fix:
>   ...
>   emulate_step_test: stvx           : PASS
>   emulate_step_test: lxvd2x         : FAIL
>   emulate_step_test: stxvd2x        : FAIL

Those tests should also be updated to skip testing these instructions if=20
!CPU_FTR_VSX.

>=20
> Fixes: https://github.com/linuxppc/linux/issues/148
>=20
> Reported-by: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
> ---
> Note: VSX was first introduced on P6. But there are many VSX instructions
>       which were introduced in later versions. So ideally, analyse_instr(=
)
>       should check for ISA version along with opcode.

Yes, this patch should be useful for when VSX is not present. For=20
specific instructions, we should add a cpu feature check.

- Naveen

=

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

end of thread, other threads:[~2018-05-16  7:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-16  5:40 [RFC] powerpc/emulate_step: Fix kernel crash when VSX is not present Ravi Bangoria
2018-05-16  7:08 ` Naveen N. Rao
2018-05-16  7:08   ` Naveen N. Rao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.