All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest
@ 2020-09-16 17:22 Ganesh Goudar
  2020-09-16 17:22 ` [PATCH 1/3] powerpc/mce: remove nmi_enter/exit from real mode handler Ganesh Goudar
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Ganesh Goudar @ 2020-09-16 17:22 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: mahesh, msuchanek, Ganesh Goudar, npiggin

This patch series fixes mce handling for pseries, provides debugfs
interface for mce injection and adds selftest to test mce handling
on pseries/powernv machines running in hash mmu mode.
debugfs interface and sleftest are added only for slb multihit
injection, We can add other tests in future if possible.

Ganesh Goudar (3):
  powerpc/mce: remove nmi_enter/exit from real mode handler
  powerpc/mce: Add debugfs interface to inject MCE
  selftest/powerpc: Add slb multihit selftest

 arch/powerpc/Kconfig.debug                    |   9 ++
 arch/powerpc/kernel/mce.c                     |   7 +-
 arch/powerpc/sysdev/Makefile                  |   2 +
 arch/powerpc/sysdev/mce_error_inject.c        | 149 ++++++++++++++++++
 tools/testing/selftests/powerpc/Makefile      |   3 +-
 tools/testing/selftests/powerpc/mces/Makefile |   6 +
 .../selftests/powerpc/mces/slb_multihit.sh    |   9 ++
 7 files changed, 183 insertions(+), 2 deletions(-)
 create mode 100644 arch/powerpc/sysdev/mce_error_inject.c
 create mode 100644 tools/testing/selftests/powerpc/mces/Makefile
 create mode 100755 tools/testing/selftests/powerpc/mces/slb_multihit.sh

-- 
2.26.2


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

* [PATCH 1/3] powerpc/mce: remove nmi_enter/exit from real mode handler
  2020-09-16 17:22 [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest Ganesh Goudar
@ 2020-09-16 17:22 ` Ganesh Goudar
  2020-09-17 12:20   ` Michal Suchánek
  2020-09-16 17:22 ` [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE Ganesh Goudar
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Ganesh Goudar @ 2020-09-16 17:22 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: mahesh, msuchanek, Ganesh Goudar, npiggin

Use of nmi_enter/exit in real mode handler causes the kernel to panic
and reboot on injecting slb mutihit on pseries machine running in hash
mmu mode, As these calls try to accesses memory outside RMO region in
real mode handler where translation is disabled.

Add check to not to use these calls on pseries machine running in hash
mmu mode.

Fixes: 116ac378bb3f ("powerpc/64s: machine check interrupt update NMI accounting")
Signed-off-by: Ganesh Goudar <ganeshgr@linux.ibm.com>
---
 arch/powerpc/kernel/mce.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
index ada59f6c4298..1d42fe0f5f9c 100644
--- a/arch/powerpc/kernel/mce.c
+++ b/arch/powerpc/kernel/mce.c
@@ -591,10 +591,15 @@ EXPORT_SYMBOL_GPL(machine_check_print_event_info);
 long notrace machine_check_early(struct pt_regs *regs)
 {
 	long handled = 0;
-	bool nested = in_nmi();
+	bool nested;
+	bool is_pseries_hpt_guest;
 	u8 ftrace_enabled = this_cpu_get_ftrace_enabled();
 
 	this_cpu_set_ftrace_enabled(0);
+	is_pseries_hpt_guest = machine_is(pseries) &&
+			       mmu_has_feature(MMU_FTR_HPTE_TABLE);
+	/* Do not use nmi_enter/exit for pseries hpte guest */
+	nested = is_pseries_hpt_guest ? true : in_nmi();
 
 	if (!nested)
 		nmi_enter();
-- 
2.26.2


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

* [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE
  2020-09-16 17:22 [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest Ganesh Goudar
  2020-09-16 17:22 ` [PATCH 1/3] powerpc/mce: remove nmi_enter/exit from real mode handler Ganesh Goudar
@ 2020-09-16 17:22 ` Ganesh Goudar
  2020-09-17  8:24     ` kernel test robot
                     ` (3 more replies)
  2020-09-16 17:22 ` [PATCH 3/3] selftest/powerpc: Add slb multihit selftest Ganesh Goudar
  2020-09-17 12:29 ` [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest Michal Suchánek
  3 siblings, 4 replies; 16+ messages in thread
From: Ganesh Goudar @ 2020-09-16 17:22 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: mahesh, msuchanek, Ganesh Goudar, npiggin

To test machine check handling, add debugfs interface to inject
slb multihit errors.

To inject slb multihit:
 #echo 1 > /sys/kernel/debug/powerpc/mce_error_inject/inject_slb_multihit

Signed-off-by: Ganesh Goudar <ganeshgr@linux.ibm.com>
Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
---
 arch/powerpc/Kconfig.debug             |   9 ++
 arch/powerpc/sysdev/Makefile           |   2 +
 arch/powerpc/sysdev/mce_error_inject.c | 148 +++++++++++++++++++++++++
 3 files changed, 159 insertions(+)
 create mode 100644 arch/powerpc/sysdev/mce_error_inject.c

diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index b88900f4832f..61db133f2f0d 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -398,3 +398,12 @@ config KASAN_SHADOW_OFFSET
 	hex
 	depends on KASAN
 	default 0xe0000000
+
+config MCE_ERROR_INJECT
+	bool "Enable MCE error injection through debugfs"
+	depends on DEBUG_FS
+	default y
+	help
+	  This option creates an mce_error_inject directory in the
+	  powerpc debugfs directory that allows limited injection of
+	  Machine Check Errors (MCEs).
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
index 026b3f01a991..7fc102222b77 100644
--- a/arch/powerpc/sysdev/Makefile
+++ b/arch/powerpc/sysdev/Makefile
@@ -52,3 +52,5 @@ obj-$(CONFIG_PPC_XICS)		+= xics/
 obj-$(CONFIG_PPC_XIVE)		+= xive/
 
 obj-$(CONFIG_GE_FPGA)		+= ge/
+
+obj-$(CONFIG_MCE_ERROR_INJECT)	+= mce_error_inject.o
diff --git a/arch/powerpc/sysdev/mce_error_inject.c b/arch/powerpc/sysdev/mce_error_inject.c
new file mode 100644
index 000000000000..ca4726bfa2d9
--- /dev/null
+++ b/arch/powerpc/sysdev/mce_error_inject.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Machine Check Exception injection code
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+#include <linux/fs.h>
+#include <linux/debugfs.h>
+#include <asm/debugfs.h>
+
+static inline unsigned long get_slb_index(void)
+{
+	unsigned long index;
+
+	index = get_paca()->stab_rr;
+
+	/*
+	 * simple round-robin replacement of slb starting at SLB_NUM_BOLTED.
+	 */
+	if (index < (mmu_slb_size - 1))
+		index++;
+	else
+		index = SLB_NUM_BOLTED;
+	get_paca()->stab_rr = index;
+	return index;
+}
+
+#define slb_esid_mask(ssize)	\
+	(((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
+
+static inline unsigned long mk_esid_data(unsigned long ea, int ssize,
+					 unsigned long slot)
+{
+	return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
+}
+
+#define slb_vsid_shift(ssize)	\
+	((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
+
+static inline unsigned long mk_vsid_data(unsigned long ea, int ssize,
+					 unsigned long flags)
+{
+	return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
+		((unsigned long)ssize << SLB_VSID_SSIZE_SHIFT);
+}
+
+static void insert_slb_entry(char *p, int ssize)
+{
+	unsigned long flags, entry;
+	struct paca_struct *paca;
+
+	flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
+
+	preempt_disable();
+
+	paca = get_paca();
+
+	entry = get_slb_index();
+	asm volatile("slbmte %0,%1" :
+			: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
+			  "r" (mk_esid_data((unsigned long)p, ssize, entry))
+			: "memory");
+
+	entry = get_slb_index();
+	asm volatile("slbmte %0,%1" :
+			: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
+			  "r" (mk_esid_data((unsigned long)p, ssize, entry))
+			: "memory");
+	preempt_enable();
+	p[0] = '!';
+}
+
+static void inject_vmalloc_slb_multihit(void)
+{
+	char *p;
+
+	p = vmalloc(2048);
+	if (!p)
+		return;
+
+	insert_slb_entry(p, MMU_SEGSIZE_1T);
+	vfree(p);
+}
+
+static void inject_kmalloc_slb_multihit(void)
+{
+	char *p;
+
+	p = kmalloc(2048, GFP_KERNEL);
+	if (!p)
+		return;
+
+	insert_slb_entry(p, MMU_SEGSIZE_1T);
+	kfree(p);
+}
+
+static ssize_t inject_slb_multihit(const char __user *u_buf, size_t count)
+{
+	char buf[32];
+	size_t buf_size;
+
+	buf_size = min(count, (sizeof(buf) - 1));
+	if (copy_from_user(buf, u_buf, buf_size))
+		return -EFAULT;
+	buf[buf_size] = '\0';
+
+	if (buf[0] != '1')
+		return -EINVAL;
+
+	inject_vmalloc_slb_multihit();
+	inject_kmalloc_slb_multihit();
+	return count;
+}
+
+static ssize_t inject_write(struct file *file, const char __user *buf,
+			    size_t count, loff_t *ppos)
+{
+	static ssize_t (*func)(const char __user *, size_t);
+
+	func = file->f_inode->i_private;
+	return func(buf, count);
+}
+
+static const struct file_operations inject_fops = {
+	.write		= inject_write,
+	.llseek		= default_llseek,
+};
+
+static int mce_error_inject_setup(void)
+{
+	struct dentry *mce_error_inject_dir;
+
+	mce_error_inject_dir = debugfs_create_dir("mce_error_inject",
+						  powerpc_debugfs_root);
+
+	if (mmu_has_feature(MMU_FTR_HPTE_TABLE)) {
+		(void)debugfs_create_file("inject_slb_multihit", 0200,
+					  mce_error_inject_dir,
+					  &inject_slb_multihit,
+					  &inject_fops);
+	}
+
+	return 0;
+}
+
+device_initcall(mce_error_inject_setup);
-- 
2.26.2


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

* [PATCH 3/3] selftest/powerpc: Add slb multihit selftest
  2020-09-16 17:22 [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest Ganesh Goudar
  2020-09-16 17:22 ` [PATCH 1/3] powerpc/mce: remove nmi_enter/exit from real mode handler Ganesh Goudar
  2020-09-16 17:22 ` [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE Ganesh Goudar
@ 2020-09-16 17:22 ` Ganesh Goudar
  2020-09-17 12:29 ` [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest Michal Suchánek
  3 siblings, 0 replies; 16+ messages in thread
From: Ganesh Goudar @ 2020-09-16 17:22 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: mahesh, msuchanek, Ganesh Goudar, npiggin

Add selftest to check if the system recovers from slb multihit
errors.

Signed-off-by: Ganesh Goudar <ganeshgr@linux.ibm.com>
---
 tools/testing/selftests/powerpc/Makefile             | 3 ++-
 tools/testing/selftests/powerpc/mces/Makefile        | 6 ++++++
 tools/testing/selftests/powerpc/mces/slb_multihit.sh | 9 +++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/mces/Makefile
 create mode 100755 tools/testing/selftests/powerpc/mces/slb_multihit.sh

diff --git a/tools/testing/selftests/powerpc/Makefile b/tools/testing/selftests/powerpc/Makefile
index 0830e63818c1..3c900b30da79 100644
--- a/tools/testing/selftests/powerpc/Makefile
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -31,7 +31,8 @@ SUB_DIRS = alignment		\
 	   vphn         \
 	   math		\
 	   ptrace	\
-	   security
+	   security	\
+	   mces
 
 endif
 
diff --git a/tools/testing/selftests/powerpc/mces/Makefile b/tools/testing/selftests/powerpc/mces/Makefile
new file mode 100644
index 000000000000..5a356295e952
--- /dev/null
+++ b/tools/testing/selftests/powerpc/mces/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+# Makefile for machine check exceptions selftests
+
+TEST_PROGS := slb_multihit.sh
+
+include ../../lib.mk
diff --git a/tools/testing/selftests/powerpc/mces/slb_multihit.sh b/tools/testing/selftests/powerpc/mces/slb_multihit.sh
new file mode 100755
index 000000000000..35c17c619d0a
--- /dev/null
+++ b/tools/testing/selftests/powerpc/mces/slb_multihit.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+if [ ! -e "/sys/kernel/debug/powerpc/mce_error_inject/inject_slb_multihit" ] ; then
+        exit 0;
+fi
+
+echo 1 > /sys/kernel/debug/powerpc/mce_error_inject/inject_slb_multihit
+exit 0
-- 
2.26.2


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

* Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE
  2020-09-16 17:22 ` [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE Ganesh Goudar
@ 2020-09-17  8:24     ` kernel test robot
  2020-09-17  8:36     ` kernel test robot
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2020-09-17  8:24 UTC (permalink / raw)
  To: Ganesh Goudar, linuxppc-dev, mpe
  Cc: mahesh, msuchanek, kbuild-all, npiggin, Ganesh Goudar

[-- Attachment #1: Type: text/plain, Size: 10308 bytes --]

Hi Ganesh,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on v5.9-rc5 next-20200916]
[cannot apply to scottwood/next mpe/next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ganesh-Goudar/powerpc-mce-Fix-mce-handler-and-add-selftest/20200917-092355
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-randconfig-r021-20200917 (attached as .config)
compiler: powerpc-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arch/powerpc/sysdev/mce_error_inject.c: In function 'get_slb_index':
>> arch/powerpc/sysdev/mce_error_inject.c:17:10: error: implicit declaration of function 'get_paca' [-Werror=implicit-function-declaration]
      17 |  index = get_paca()->stab_rr;
         |          ^~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:17:20: error: invalid type argument of '->' (have 'int')
      17 |  index = get_paca()->stab_rr;
         |                    ^~
>> arch/powerpc/sysdev/mce_error_inject.c:22:15: error: 'mmu_slb_size' undeclared (first use in this function)
      22 |  if (index < (mmu_slb_size - 1))
         |               ^~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:22:15: note: each undeclared identifier is reported only once for each function it appears in
>> arch/powerpc/sysdev/mce_error_inject.c:25:11: error: 'SLB_NUM_BOLTED' undeclared (first use in this function)
      25 |   index = SLB_NUM_BOLTED;
         |           ^~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:26:12: error: invalid type argument of '->' (have 'int')
      26 |  get_paca()->stab_rr = index;
         |            ^~
   arch/powerpc/sysdev/mce_error_inject.c: In function 'mk_esid_data':
>> arch/powerpc/sysdev/mce_error_inject.c:31:15: error: 'MMU_SEGSIZE_256M' undeclared (first use in this function); did you mean 'MMU_PAGE_256M'?
      31 |  (((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
         |               ^~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:36:15: note: in expansion of macro 'slb_esid_mask'
      36 |  return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
         |               ^~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:31:35: error: 'ESID_MASK' undeclared (first use in this function); did you mean 'NMI_MASK'?
      31 |  (((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
         |                                   ^~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:36:15: note: in expansion of macro 'slb_esid_mask'
      36 |  return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
         |               ^~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:31:47: error: 'ESID_MASK_1T' undeclared (first use in this function)
      31 |  (((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
         |                                               ^~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:36:15: note: in expansion of macro 'slb_esid_mask'
      36 |  return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
         |               ^~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:36:39: error: 'SLB_ESID_V' undeclared (first use in this function)
      36 |  return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
         |                                       ^~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c: In function 'mk_vsid_data':
>> arch/powerpc/sysdev/mce_error_inject.c:45:10: error: implicit declaration of function 'get_kernel_vsid' [-Werror=implicit-function-declaration]
      45 |  return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
         |          ^~~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:40:14: error: 'MMU_SEGSIZE_256M' undeclared (first use in this function); did you mean 'MMU_PAGE_256M'?
      40 |  ((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
         |              ^~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:45:40: note: in expansion of macro 'slb_vsid_shift'
      45 |  return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
         |                                        ^~~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:40:33: error: 'SLB_VSID_SHIFT' undeclared (first use in this function)
      40 |  ((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
         |                                 ^~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:45:40: note: in expansion of macro 'slb_vsid_shift'
      45 |  return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
         |                                        ^~~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:40:50: error: 'SLB_VSID_SHIFT_1T' undeclared (first use in this function)
      40 |  ((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
         |                                                  ^~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:45:40: note: in expansion of macro 'slb_vsid_shift'
      45 |  return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
         |                                        ^~~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:46:28: error: 'SLB_VSID_SSIZE_SHIFT' undeclared (first use in this function)
      46 |   ((unsigned long)ssize << SLB_VSID_SSIZE_SHIFT);
         |                            ^~~~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c: In function 'insert_slb_entry':
>> arch/powerpc/sysdev/mce_error_inject.c:54:10: error: 'SLB_VSID_KERNEL' undeclared (first use in this function)
      54 |  flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
         |          ^~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:54:28: error: 'mmu_psize_defs' undeclared (first use in this function)
      54 |  flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
         |                            ^~~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:58:7: error: assignment to 'struct paca_struct *' from 'int' makes pointer from integer without a cast [-Werror=int-conversion]
      58 |  paca = get_paca();
         |       ^
>> arch/powerpc/sysdev/mce_error_inject.c:52:22: error: variable 'paca' set but not used [-Werror=unused-but-set-variable]
      52 |  struct paca_struct *paca;
         |                      ^~~~
   arch/powerpc/sysdev/mce_error_inject.c: In function 'inject_vmalloc_slb_multihit':
>> arch/powerpc/sysdev/mce_error_inject.c:83:22: error: 'MMU_SEGSIZE_1T' undeclared (first use in this function)
      83 |  insert_slb_entry(p, MMU_SEGSIZE_1T);
         |                      ^~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c: In function 'inject_kmalloc_slb_multihit':
   arch/powerpc/sysdev/mce_error_inject.c:95:22: error: 'MMU_SEGSIZE_1T' undeclared (first use in this function)
      95 |  insert_slb_entry(p, MMU_SEGSIZE_1T);
         |                      ^~~~~~~~~~~~~~
   cc1: all warnings being treated as errors

# https://github.com/0day-ci/linux/commit/4ab1196e8e542fdf0e7cda8638dfb0e5771fd98e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ganesh-Goudar/powerpc-mce-Fix-mce-handler-and-add-selftest/20200917-092355
git checkout 4ab1196e8e542fdf0e7cda8638dfb0e5771fd98e
vim +/get_paca +17 arch/powerpc/sysdev/mce_error_inject.c

    12	
    13	static inline unsigned long get_slb_index(void)
    14	{
    15		unsigned long index;
    16	
  > 17		index = get_paca()->stab_rr;
    18	
    19		/*
    20		 * simple round-robin replacement of slb starting at SLB_NUM_BOLTED.
    21		 */
  > 22		if (index < (mmu_slb_size - 1))
    23			index++;
    24		else
  > 25			index = SLB_NUM_BOLTED;
    26		get_paca()->stab_rr = index;
    27		return index;
    28	}
    29	
    30	#define slb_esid_mask(ssize)	\
  > 31		(((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
    32	
    33	static inline unsigned long mk_esid_data(unsigned long ea, int ssize,
    34						 unsigned long slot)
    35	{
  > 36		return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
    37	}
    38	
    39	#define slb_vsid_shift(ssize)	\
  > 40		((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
    41	
    42	static inline unsigned long mk_vsid_data(unsigned long ea, int ssize,
    43						 unsigned long flags)
    44	{
  > 45		return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
  > 46			((unsigned long)ssize << SLB_VSID_SSIZE_SHIFT);
    47	}
    48	
    49	static void insert_slb_entry(char *p, int ssize)
    50	{
    51		unsigned long flags, entry;
  > 52		struct paca_struct *paca;
    53	
  > 54		flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
    55	
    56		preempt_disable();
    57	
  > 58		paca = get_paca();
    59	
    60		entry = get_slb_index();
    61		asm volatile("slbmte %0,%1" :
    62				: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
    63				  "r" (mk_esid_data((unsigned long)p, ssize, entry))
    64				: "memory");
    65	
    66		entry = get_slb_index();
    67		asm volatile("slbmte %0,%1" :
    68				: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
    69				  "r" (mk_esid_data((unsigned long)p, ssize, entry))
    70				: "memory");
    71		preempt_enable();
    72		p[0] = '!';
    73	}
    74	
    75	static void inject_vmalloc_slb_multihit(void)
    76	{
    77		char *p;
    78	
    79		p = vmalloc(2048);
    80		if (!p)
    81			return;
    82	
  > 83		insert_slb_entry(p, MMU_SEGSIZE_1T);
    84		vfree(p);
    85	}
    86	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32054 bytes --]

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

* Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE
@ 2020-09-17  8:24     ` kernel test robot
  0 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2020-09-17  8:24 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 10508 bytes --]

Hi Ganesh,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on v5.9-rc5 next-20200916]
[cannot apply to scottwood/next mpe/next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ganesh-Goudar/powerpc-mce-Fix-mce-handler-and-add-selftest/20200917-092355
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-randconfig-r021-20200917 (attached as .config)
compiler: powerpc-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arch/powerpc/sysdev/mce_error_inject.c: In function 'get_slb_index':
>> arch/powerpc/sysdev/mce_error_inject.c:17:10: error: implicit declaration of function 'get_paca' [-Werror=implicit-function-declaration]
      17 |  index = get_paca()->stab_rr;
         |          ^~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:17:20: error: invalid type argument of '->' (have 'int')
      17 |  index = get_paca()->stab_rr;
         |                    ^~
>> arch/powerpc/sysdev/mce_error_inject.c:22:15: error: 'mmu_slb_size' undeclared (first use in this function)
      22 |  if (index < (mmu_slb_size - 1))
         |               ^~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:22:15: note: each undeclared identifier is reported only once for each function it appears in
>> arch/powerpc/sysdev/mce_error_inject.c:25:11: error: 'SLB_NUM_BOLTED' undeclared (first use in this function)
      25 |   index = SLB_NUM_BOLTED;
         |           ^~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:26:12: error: invalid type argument of '->' (have 'int')
      26 |  get_paca()->stab_rr = index;
         |            ^~
   arch/powerpc/sysdev/mce_error_inject.c: In function 'mk_esid_data':
>> arch/powerpc/sysdev/mce_error_inject.c:31:15: error: 'MMU_SEGSIZE_256M' undeclared (first use in this function); did you mean 'MMU_PAGE_256M'?
      31 |  (((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
         |               ^~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:36:15: note: in expansion of macro 'slb_esid_mask'
      36 |  return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
         |               ^~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:31:35: error: 'ESID_MASK' undeclared (first use in this function); did you mean 'NMI_MASK'?
      31 |  (((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
         |                                   ^~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:36:15: note: in expansion of macro 'slb_esid_mask'
      36 |  return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
         |               ^~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:31:47: error: 'ESID_MASK_1T' undeclared (first use in this function)
      31 |  (((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
         |                                               ^~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:36:15: note: in expansion of macro 'slb_esid_mask'
      36 |  return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
         |               ^~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:36:39: error: 'SLB_ESID_V' undeclared (first use in this function)
      36 |  return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
         |                                       ^~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c: In function 'mk_vsid_data':
>> arch/powerpc/sysdev/mce_error_inject.c:45:10: error: implicit declaration of function 'get_kernel_vsid' [-Werror=implicit-function-declaration]
      45 |  return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
         |          ^~~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:40:14: error: 'MMU_SEGSIZE_256M' undeclared (first use in this function); did you mean 'MMU_PAGE_256M'?
      40 |  ((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
         |              ^~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:45:40: note: in expansion of macro 'slb_vsid_shift'
      45 |  return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
         |                                        ^~~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:40:33: error: 'SLB_VSID_SHIFT' undeclared (first use in this function)
      40 |  ((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
         |                                 ^~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:45:40: note: in expansion of macro 'slb_vsid_shift'
      45 |  return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
         |                                        ^~~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:40:50: error: 'SLB_VSID_SHIFT_1T' undeclared (first use in this function)
      40 |  ((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
         |                                                  ^~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c:45:40: note: in expansion of macro 'slb_vsid_shift'
      45 |  return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
         |                                        ^~~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:46:28: error: 'SLB_VSID_SSIZE_SHIFT' undeclared (first use in this function)
      46 |   ((unsigned long)ssize << SLB_VSID_SSIZE_SHIFT);
         |                            ^~~~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c: In function 'insert_slb_entry':
>> arch/powerpc/sysdev/mce_error_inject.c:54:10: error: 'SLB_VSID_KERNEL' undeclared (first use in this function)
      54 |  flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
         |          ^~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:54:28: error: 'mmu_psize_defs' undeclared (first use in this function)
      54 |  flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
         |                            ^~~~~~~~~~~~~~
>> arch/powerpc/sysdev/mce_error_inject.c:58:7: error: assignment to 'struct paca_struct *' from 'int' makes pointer from integer without a cast [-Werror=int-conversion]
      58 |  paca = get_paca();
         |       ^
>> arch/powerpc/sysdev/mce_error_inject.c:52:22: error: variable 'paca' set but not used [-Werror=unused-but-set-variable]
      52 |  struct paca_struct *paca;
         |                      ^~~~
   arch/powerpc/sysdev/mce_error_inject.c: In function 'inject_vmalloc_slb_multihit':
>> arch/powerpc/sysdev/mce_error_inject.c:83:22: error: 'MMU_SEGSIZE_1T' undeclared (first use in this function)
      83 |  insert_slb_entry(p, MMU_SEGSIZE_1T);
         |                      ^~~~~~~~~~~~~~
   arch/powerpc/sysdev/mce_error_inject.c: In function 'inject_kmalloc_slb_multihit':
   arch/powerpc/sysdev/mce_error_inject.c:95:22: error: 'MMU_SEGSIZE_1T' undeclared (first use in this function)
      95 |  insert_slb_entry(p, MMU_SEGSIZE_1T);
         |                      ^~~~~~~~~~~~~~
   cc1: all warnings being treated as errors

# https://github.com/0day-ci/linux/commit/4ab1196e8e542fdf0e7cda8638dfb0e5771fd98e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ganesh-Goudar/powerpc-mce-Fix-mce-handler-and-add-selftest/20200917-092355
git checkout 4ab1196e8e542fdf0e7cda8638dfb0e5771fd98e
vim +/get_paca +17 arch/powerpc/sysdev/mce_error_inject.c

    12	
    13	static inline unsigned long get_slb_index(void)
    14	{
    15		unsigned long index;
    16	
  > 17		index = get_paca()->stab_rr;
    18	
    19		/*
    20		 * simple round-robin replacement of slb starting at SLB_NUM_BOLTED.
    21		 */
  > 22		if (index < (mmu_slb_size - 1))
    23			index++;
    24		else
  > 25			index = SLB_NUM_BOLTED;
    26		get_paca()->stab_rr = index;
    27		return index;
    28	}
    29	
    30	#define slb_esid_mask(ssize)	\
  > 31		(((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
    32	
    33	static inline unsigned long mk_esid_data(unsigned long ea, int ssize,
    34						 unsigned long slot)
    35	{
  > 36		return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
    37	}
    38	
    39	#define slb_vsid_shift(ssize)	\
  > 40		((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
    41	
    42	static inline unsigned long mk_vsid_data(unsigned long ea, int ssize,
    43						 unsigned long flags)
    44	{
  > 45		return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
  > 46			((unsigned long)ssize << SLB_VSID_SSIZE_SHIFT);
    47	}
    48	
    49	static void insert_slb_entry(char *p, int ssize)
    50	{
    51		unsigned long flags, entry;
  > 52		struct paca_struct *paca;
    53	
  > 54		flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
    55	
    56		preempt_disable();
    57	
  > 58		paca = get_paca();
    59	
    60		entry = get_slb_index();
    61		asm volatile("slbmte %0,%1" :
    62				: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
    63				  "r" (mk_esid_data((unsigned long)p, ssize, entry))
    64				: "memory");
    65	
    66		entry = get_slb_index();
    67		asm volatile("slbmte %0,%1" :
    68				: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
    69				  "r" (mk_esid_data((unsigned long)p, ssize, entry))
    70				: "memory");
    71		preempt_enable();
    72		p[0] = '!';
    73	}
    74	
    75	static void inject_vmalloc_slb_multihit(void)
    76	{
    77		char *p;
    78	
    79		p = vmalloc(2048);
    80		if (!p)
    81			return;
    82	
  > 83		insert_slb_entry(p, MMU_SEGSIZE_1T);
    84		vfree(p);
    85	}
    86	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 32054 bytes --]

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

* Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE
  2020-09-16 17:22 ` [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE Ganesh Goudar
@ 2020-09-17  8:36     ` kernel test robot
  2020-09-17  8:36     ` kernel test robot
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2020-09-17  8:36 UTC (permalink / raw)
  To: Ganesh Goudar, linuxppc-dev, mpe
  Cc: mahesh, msuchanek, kbuild-all, npiggin, Ganesh Goudar

[-- Attachment #1: Type: text/plain, Size: 2709 bytes --]

Hi Ganesh,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on powerpc/next]
[also build test WARNING on v5.9-rc5 next-20200916]
[cannot apply to scottwood/next mpe/next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ganesh-Goudar/powerpc-mce-Fix-mce-handler-and-add-selftest/20200917-092355
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-allyesconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   arch/powerpc/sysdev/mce_error_inject.c: In function 'insert_slb_entry':
>> arch/powerpc/sysdev/mce_error_inject.c:52:22: warning: variable 'paca' set but not used [-Wunused-but-set-variable]
      52 |  struct paca_struct *paca;
         |                      ^~~~

# https://github.com/0day-ci/linux/commit/4ab1196e8e542fdf0e7cda8638dfb0e5771fd98e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ganesh-Goudar/powerpc-mce-Fix-mce-handler-and-add-selftest/20200917-092355
git checkout 4ab1196e8e542fdf0e7cda8638dfb0e5771fd98e
vim +/paca +52 arch/powerpc/sysdev/mce_error_inject.c

    48	
    49	static void insert_slb_entry(char *p, int ssize)
    50	{
    51		unsigned long flags, entry;
  > 52		struct paca_struct *paca;
    53	
    54		flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
    55	
    56		preempt_disable();
    57	
    58		paca = get_paca();
    59	
    60		entry = get_slb_index();
    61		asm volatile("slbmte %0,%1" :
    62				: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
    63				  "r" (mk_esid_data((unsigned long)p, ssize, entry))
    64				: "memory");
    65	
    66		entry = get_slb_index();
    67		asm volatile("slbmte %0,%1" :
    68				: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
    69				  "r" (mk_esid_data((unsigned long)p, ssize, entry))
    70				: "memory");
    71		preempt_enable();
    72		p[0] = '!';
    73	}
    74	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 70430 bytes --]

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

* Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE
@ 2020-09-17  8:36     ` kernel test robot
  0 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2020-09-17  8:36 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2779 bytes --]

Hi Ganesh,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on powerpc/next]
[also build test WARNING on v5.9-rc5 next-20200916]
[cannot apply to scottwood/next mpe/next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ganesh-Goudar/powerpc-mce-Fix-mce-handler-and-add-selftest/20200917-092355
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-allyesconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   arch/powerpc/sysdev/mce_error_inject.c: In function 'insert_slb_entry':
>> arch/powerpc/sysdev/mce_error_inject.c:52:22: warning: variable 'paca' set but not used [-Wunused-but-set-variable]
      52 |  struct paca_struct *paca;
         |                      ^~~~

# https://github.com/0day-ci/linux/commit/4ab1196e8e542fdf0e7cda8638dfb0e5771fd98e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ganesh-Goudar/powerpc-mce-Fix-mce-handler-and-add-selftest/20200917-092355
git checkout 4ab1196e8e542fdf0e7cda8638dfb0e5771fd98e
vim +/paca +52 arch/powerpc/sysdev/mce_error_inject.c

    48	
    49	static void insert_slb_entry(char *p, int ssize)
    50	{
    51		unsigned long flags, entry;
  > 52		struct paca_struct *paca;
    53	
    54		flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
    55	
    56		preempt_disable();
    57	
    58		paca = get_paca();
    59	
    60		entry = get_slb_index();
    61		asm volatile("slbmte %0,%1" :
    62				: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
    63				  "r" (mk_esid_data((unsigned long)p, ssize, entry))
    64				: "memory");
    65	
    66		entry = get_slb_index();
    67		asm volatile("slbmte %0,%1" :
    68				: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
    69				  "r" (mk_esid_data((unsigned long)p, ssize, entry))
    70				: "memory");
    71		preempt_enable();
    72		p[0] = '!';
    73	}
    74	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 70430 bytes --]

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

* Re: [PATCH 1/3] powerpc/mce: remove nmi_enter/exit from real mode handler
  2020-09-16 17:22 ` [PATCH 1/3] powerpc/mce: remove nmi_enter/exit from real mode handler Ganesh Goudar
@ 2020-09-17 12:20   ` Michal Suchánek
  2020-09-18 12:04     ` Ganesh
  0 siblings, 1 reply; 16+ messages in thread
From: Michal Suchánek @ 2020-09-17 12:20 UTC (permalink / raw)
  To: Ganesh Goudar; +Cc: linuxppc-dev, npiggin, mahesh

Hello,

On Wed, Sep 16, 2020 at 10:52:26PM +0530, Ganesh Goudar wrote:
> Use of nmi_enter/exit in real mode handler causes the kernel to panic
> and reboot on injecting slb mutihit on pseries machine running in hash
> mmu mode, As these calls try to accesses memory outside RMO region in
> real mode handler where translation is disabled.
> 
> Add check to not to use these calls on pseries machine running in hash
> mmu mode.
> 
> Fixes: 116ac378bb3f ("powerpc/64s: machine check interrupt update NMI accounting")
> Signed-off-by: Ganesh Goudar <ganeshgr@linux.ibm.com>
> ---
>  arch/powerpc/kernel/mce.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
> index ada59f6c4298..1d42fe0f5f9c 100644
> --- a/arch/powerpc/kernel/mce.c
> +++ b/arch/powerpc/kernel/mce.c
> @@ -591,10 +591,15 @@ EXPORT_SYMBOL_GPL(machine_check_print_event_info);
>  long notrace machine_check_early(struct pt_regs *regs)
>  {
>  	long handled = 0;
> -	bool nested = in_nmi();
> +	bool nested;
> +	bool is_pseries_hpt_guest;
>  	u8 ftrace_enabled = this_cpu_get_ftrace_enabled();
>  
>  	this_cpu_set_ftrace_enabled(0);
> +	is_pseries_hpt_guest = machine_is(pseries) &&
> +			       mmu_has_feature(MMU_FTR_HPTE_TABLE);
> +	/* Do not use nmi_enter/exit for pseries hpte guest */
> +	nested = is_pseries_hpt_guest ? true : in_nmi();
As pointed out already in another comment nesting is supported natively
since 69ea03b56ed2c7189ccd0b5910ad39f3cad1df21. You can simply do
nmi_enter and nmi_exit unconditionally - or only based on
is_pseries_hpt_guest.

The other question is what is the value of calling nmi_enter here at
all. It crashes in one case, we simply skip it for that case, and we are
good. Maybe we could skip it altogether?

Thanks

Michal

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

* Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE
  2020-09-16 17:22 ` [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE Ganesh Goudar
  2020-09-17  8:24     ` kernel test robot
  2020-09-17  8:36     ` kernel test robot
@ 2020-09-17 12:23   ` Michal Suchánek
  2020-09-18 12:06     ` Ganesh
  2020-09-18  6:40   ` Michael Ellerman
  3 siblings, 1 reply; 16+ messages in thread
From: Michal Suchánek @ 2020-09-17 12:23 UTC (permalink / raw)
  To: Ganesh Goudar; +Cc: linuxppc-dev, npiggin, mahesh

Hello,

On Wed, Sep 16, 2020 at 10:52:27PM +0530, Ganesh Goudar wrote:
> To test machine check handling, add debugfs interface to inject
> slb multihit errors.
> 
> To inject slb multihit:
>  #echo 1 > /sys/kernel/debug/powerpc/mce_error_inject/inject_slb_multihit
> 
> Signed-off-by: Ganesh Goudar <ganeshgr@linux.ibm.com>
> Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
> ---
>  arch/powerpc/Kconfig.debug             |   9 ++
>  arch/powerpc/sysdev/Makefile           |   2 +
>  arch/powerpc/sysdev/mce_error_inject.c | 148 +++++++++++++++++++++++++
>  3 files changed, 159 insertions(+)
>  create mode 100644 arch/powerpc/sysdev/mce_error_inject.c
> 
> diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
> index b88900f4832f..61db133f2f0d 100644
> --- a/arch/powerpc/Kconfig.debug
> +++ b/arch/powerpc/Kconfig.debug
> @@ -398,3 +398,12 @@ config KASAN_SHADOW_OFFSET
>  	hex
>  	depends on KASAN
>  	default 0xe0000000
> +
> +config MCE_ERROR_INJECT
> +	bool "Enable MCE error injection through debugfs"
> +	depends on DEBUG_FS
> +	default y
> +	help
> +	  This option creates an mce_error_inject directory in the
> +	  powerpc debugfs directory that allows limited injection of
> +	  Machine Check Errors (MCEs).
> diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
> index 026b3f01a991..7fc102222b77 100644
> --- a/arch/powerpc/sysdev/Makefile
> +++ b/arch/powerpc/sysdev/Makefile
> @@ -52,3 +52,5 @@ obj-$(CONFIG_PPC_XICS)		+= xics/
>  obj-$(CONFIG_PPC_XIVE)		+= xive/
>  
>  obj-$(CONFIG_GE_FPGA)		+= ge/
> +
> +obj-$(CONFIG_MCE_ERROR_INJECT)	+= mce_error_inject.o
> diff --git a/arch/powerpc/sysdev/mce_error_inject.c b/arch/powerpc/sysdev/mce_error_inject.c
> new file mode 100644
> index 000000000000..ca4726bfa2d9
> --- /dev/null
> +++ b/arch/powerpc/sysdev/mce_error_inject.c
> @@ -0,0 +1,148 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Machine Check Exception injection code
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/slab.h>
> +#include <linux/vmalloc.h>
> +#include <linux/fs.h>
> +#include <linux/debugfs.h>
> +#include <asm/debugfs.h>
> +
> +static inline unsigned long get_slb_index(void)
> +{
> +	unsigned long index;
> +
> +	index = get_paca()->stab_rr;
> +
> +	/*
> +	 * simple round-robin replacement of slb starting at SLB_NUM_BOLTED.
> +	 */
> +	if (index < (mmu_slb_size - 1))
> +		index++;
> +	else
> +		index = SLB_NUM_BOLTED;
> +	get_paca()->stab_rr = index;
> +	return index;
> +}
> +
> +#define slb_esid_mask(ssize)	\
> +	(((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
> +
> +static inline unsigned long mk_esid_data(unsigned long ea, int ssize,
> +					 unsigned long slot)
> +{
> +	return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
> +}
> +
> +#define slb_vsid_shift(ssize)	\
> +	((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
> +
> +static inline unsigned long mk_vsid_data(unsigned long ea, int ssize,
> +					 unsigned long flags)
> +{
> +	return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
> +		((unsigned long)ssize << SLB_VSID_SSIZE_SHIFT);
> +}
> +
> +static void insert_slb_entry(char *p, int ssize)
> +{
> +	unsigned long flags, entry;
> +	struct paca_struct *paca;
> +
> +	flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
> +
> +	preempt_disable();
> +
> +	paca = get_paca();
This seems unused?
> +
> +	entry = get_slb_index();
> +	asm volatile("slbmte %0,%1" :
> +			: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
> +			  "r" (mk_esid_data((unsigned long)p, ssize, entry))
> +			: "memory");
> +
> +	entry = get_slb_index();
> +	asm volatile("slbmte %0,%1" :
> +			: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
> +			  "r" (mk_esid_data((unsigned long)p, ssize, entry))
> +			: "memory");
> +	preempt_enable();
> +	p[0] = '!';
> +}
> +
> +static void inject_vmalloc_slb_multihit(void)
> +{
> +	char *p;
> +
> +	p = vmalloc(2048);
> +	if (!p)
> +		return;
> +
> +	insert_slb_entry(p, MMU_SEGSIZE_1T);
> +	vfree(p);
> +}
> +
> +static void inject_kmalloc_slb_multihit(void)
> +{
> +	char *p;
> +
> +	p = kmalloc(2048, GFP_KERNEL);
> +	if (!p)
> +		return;
> +
> +	insert_slb_entry(p, MMU_SEGSIZE_1T);
> +	kfree(p);
> +}
> +
> +static ssize_t inject_slb_multihit(const char __user *u_buf, size_t count)
> +{
> +	char buf[32];
> +	size_t buf_size;
> +
> +	buf_size = min(count, (sizeof(buf) - 1));
> +	if (copy_from_user(buf, u_buf, buf_size))
> +		return -EFAULT;
> +	buf[buf_size] = '\0';
> +
> +	if (buf[0] != '1')
> +		return -EINVAL;
> +
> +	inject_vmalloc_slb_multihit();
> +	inject_kmalloc_slb_multihit();
This is missing the test of multihit in paca which is for some reason
special.

Thanks

Michal
> +	return count;
> +}
> +
> +static ssize_t inject_write(struct file *file, const char __user *buf,
> +			    size_t count, loff_t *ppos)
> +{
> +	static ssize_t (*func)(const char __user *, size_t);
> +
> +	func = file->f_inode->i_private;
> +	return func(buf, count);
> +}
> +
> +static const struct file_operations inject_fops = {
> +	.write		= inject_write,
> +	.llseek		= default_llseek,
> +};
> +
> +static int mce_error_inject_setup(void)
> +{
> +	struct dentry *mce_error_inject_dir;
> +
> +	mce_error_inject_dir = debugfs_create_dir("mce_error_inject",
> +						  powerpc_debugfs_root);
> +
> +	if (mmu_has_feature(MMU_FTR_HPTE_TABLE)) {
> +		(void)debugfs_create_file("inject_slb_multihit", 0200,
> +					  mce_error_inject_dir,
> +					  &inject_slb_multihit,
> +					  &inject_fops);
> +	}
> +
> +	return 0;
> +}
> +
> +device_initcall(mce_error_inject_setup);
> -- 
> 2.26.2
> 

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

* Re: [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest
  2020-09-16 17:22 [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest Ganesh Goudar
                   ` (2 preceding siblings ...)
  2020-09-16 17:22 ` [PATCH 3/3] selftest/powerpc: Add slb multihit selftest Ganesh Goudar
@ 2020-09-17 12:29 ` Michal Suchánek
  2020-09-18 11:49   ` Ganesh
  3 siblings, 1 reply; 16+ messages in thread
From: Michal Suchánek @ 2020-09-17 12:29 UTC (permalink / raw)
  To: Ganesh Goudar; +Cc: linuxppc-dev, npiggin, mahesh

Hello,

On Wed, Sep 16, 2020 at 10:52:25PM +0530, Ganesh Goudar wrote:
> This patch series fixes mce handling for pseries, provides debugfs
> interface for mce injection and adds selftest to test mce handling
> on pseries/powernv machines running in hash mmu mode.
> debugfs interface and sleftest are added only for slb multihit
> injection, We can add other tests in future if possible.
> 
> Ganesh Goudar (3):
>   powerpc/mce: remove nmi_enter/exit from real mode handler
>   powerpc/mce: Add debugfs interface to inject MCE
>   selftest/powerpc: Add slb multihit selftest

Is the below logic sound? It does not agree with what is added here:

void machine_check_exception(struct pt_regs *regs)
{
	int recover = 0;

	/*
	 * BOOK3S_64 does not call this handler as a non-maskable interrupt
	 * (it uses its own early real-mode handler to handle the MCE proper
	 * and then raises irq_work to call this handler when interrupts are
	 * enabled).
	 *
	 * This is silly. The BOOK3S_64 should just call a different function
	 * rather than expecting semantics to magically change. Something
	 * like 'non_nmi_machine_check_exception()', perhaps?
	 */
	const bool nmi = !IS_ENABLED(CONFIG_PPC_BOOK3S_64);

	if (nmi) nmi_enter();

Thanks

Michal

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

* Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE
  2020-09-16 17:22 ` [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE Ganesh Goudar
                     ` (2 preceding siblings ...)
  2020-09-17 12:23   ` Michal Suchánek
@ 2020-09-18  6:40   ` Michael Ellerman
  2020-09-18 12:07     ` Ganesh
  3 siblings, 1 reply; 16+ messages in thread
From: Michael Ellerman @ 2020-09-18  6:40 UTC (permalink / raw)
  To: Ganesh Goudar, linuxppc-dev
  Cc: mahesh, msuchanek, Ganesh Goudar, Kees Cook, npiggin

Hi Ganesh,

Ganesh Goudar <ganeshgr@linux.ibm.com> writes:
> To test machine check handling, add debugfs interface to inject
> slb multihit errors.
>
> To inject slb multihit:
>  #echo 1 > /sys/kernel/debug/powerpc/mce_error_inject/inject_slb_multihit

Rather than creating a new ad-hoc way to trigger this, can you please
integrate it into drivers/misc/lkdtm.

There's enough code here that I think you should create
drivers/misc/lkdtm/powerpc.c and put the code in there. Then add an
LKDTM entry point for this, maybe called PPC_SLB_MULTIHIT.

Please Cc Kees when you repost.

cheers


>  arch/powerpc/Kconfig.debug             |   9 ++
>  arch/powerpc/sysdev/Makefile           |   2 +
>  arch/powerpc/sysdev/mce_error_inject.c | 148 +++++++++++++++++++++++++
>  3 files changed, 159 insertions(+)
>  create mode 100644 arch/powerpc/sysdev/mce_error_inject.c
>
> diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
> index b88900f4832f..61db133f2f0d 100644
> --- a/arch/powerpc/Kconfig.debug
> +++ b/arch/powerpc/Kconfig.debug
> @@ -398,3 +398,12 @@ config KASAN_SHADOW_OFFSET
>  	hex
>  	depends on KASAN
>  	default 0xe0000000
> +
> +config MCE_ERROR_INJECT
> +	bool "Enable MCE error injection through debugfs"
> +	depends on DEBUG_FS
> +	default y
> +	help
> +	  This option creates an mce_error_inject directory in the
> +	  powerpc debugfs directory that allows limited injection of
> +	  Machine Check Errors (MCEs).
> diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
> index 026b3f01a991..7fc102222b77 100644
> --- a/arch/powerpc/sysdev/Makefile
> +++ b/arch/powerpc/sysdev/Makefile
> @@ -52,3 +52,5 @@ obj-$(CONFIG_PPC_XICS)		+= xics/
>  obj-$(CONFIG_PPC_XIVE)		+= xive/
>  
>  obj-$(CONFIG_GE_FPGA)		+= ge/
> +
> +obj-$(CONFIG_MCE_ERROR_INJECT)	+= mce_error_inject.o
> diff --git a/arch/powerpc/sysdev/mce_error_inject.c b/arch/powerpc/sysdev/mce_error_inject.c
> new file mode 100644
> index 000000000000..ca4726bfa2d9
> --- /dev/null
> +++ b/arch/powerpc/sysdev/mce_error_inject.c
> @@ -0,0 +1,148 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Machine Check Exception injection code
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/slab.h>
> +#include <linux/vmalloc.h>
> +#include <linux/fs.h>
> +#include <linux/debugfs.h>
> +#include <asm/debugfs.h>
> +
> +static inline unsigned long get_slb_index(void)
> +{
> +	unsigned long index;
> +
> +	index = get_paca()->stab_rr;
> +
> +	/*
> +	 * simple round-robin replacement of slb starting at SLB_NUM_BOLTED.
> +	 */
> +	if (index < (mmu_slb_size - 1))
> +		index++;
> +	else
> +		index = SLB_NUM_BOLTED;
> +	get_paca()->stab_rr = index;
> +	return index;
> +}
> +
> +#define slb_esid_mask(ssize)	\
> +	(((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
> +
> +static inline unsigned long mk_esid_data(unsigned long ea, int ssize,
> +					 unsigned long slot)
> +{
> +	return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
> +}
> +
> +#define slb_vsid_shift(ssize)	\
> +	((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
> +
> +static inline unsigned long mk_vsid_data(unsigned long ea, int ssize,
> +					 unsigned long flags)
> +{
> +	return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
> +		((unsigned long)ssize << SLB_VSID_SSIZE_SHIFT);
> +}
> +
> +static void insert_slb_entry(char *p, int ssize)
> +{
> +	unsigned long flags, entry;
> +	struct paca_struct *paca;
> +
> +	flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
> +
> +	preempt_disable();
> +
> +	paca = get_paca();
> +
> +	entry = get_slb_index();
> +	asm volatile("slbmte %0,%1" :
> +			: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
> +			  "r" (mk_esid_data((unsigned long)p, ssize, entry))
> +			: "memory");
> +
> +	entry = get_slb_index();
> +	asm volatile("slbmte %0,%1" :
> +			: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
> +			  "r" (mk_esid_data((unsigned long)p, ssize, entry))
> +			: "memory");
> +	preempt_enable();
> +	p[0] = '!';
> +}
> +
> +static void inject_vmalloc_slb_multihit(void)
> +{
> +	char *p;
> +
> +	p = vmalloc(2048);
> +	if (!p)
> +		return;
> +
> +	insert_slb_entry(p, MMU_SEGSIZE_1T);
> +	vfree(p);
> +}
> +
> +static void inject_kmalloc_slb_multihit(void)
> +{
> +	char *p;
> +
> +	p = kmalloc(2048, GFP_KERNEL);
> +	if (!p)
> +		return;
> +
> +	insert_slb_entry(p, MMU_SEGSIZE_1T);
> +	kfree(p);
> +}
> +
> +static ssize_t inject_slb_multihit(const char __user *u_buf, size_t count)
> +{
> +	char buf[32];
> +	size_t buf_size;
> +
> +	buf_size = min(count, (sizeof(buf) - 1));
> +	if (copy_from_user(buf, u_buf, buf_size))
> +		return -EFAULT;
> +	buf[buf_size] = '\0';
> +
> +	if (buf[0] != '1')
> +		return -EINVAL;
> +
> +	inject_vmalloc_slb_multihit();
> +	inject_kmalloc_slb_multihit();
> +	return count;
> +}
> +
> +static ssize_t inject_write(struct file *file, const char __user *buf,
> +			    size_t count, loff_t *ppos)
> +{
> +	static ssize_t (*func)(const char __user *, size_t);
> +
> +	func = file->f_inode->i_private;
> +	return func(buf, count);
> +}
> +
> +static const struct file_operations inject_fops = {
> +	.write		= inject_write,
> +	.llseek		= default_llseek,
> +};
> +
> +static int mce_error_inject_setup(void)
> +{
> +	struct dentry *mce_error_inject_dir;
> +
> +	mce_error_inject_dir = debugfs_create_dir("mce_error_inject",
> +						  powerpc_debugfs_root);
> +
> +	if (mmu_has_feature(MMU_FTR_HPTE_TABLE)) {
> +		(void)debugfs_create_file("inject_slb_multihit", 0200,
> +					  mce_error_inject_dir,
> +					  &inject_slb_multihit,
> +					  &inject_fops);
> +	}
> +
> +	return 0;
> +}
> +
> +device_initcall(mce_error_inject_setup);
> -- 
> 2.26.2

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

* Re: [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest
  2020-09-17 12:29 ` [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest Michal Suchánek
@ 2020-09-18 11:49   ` Ganesh
  0 siblings, 0 replies; 16+ messages in thread
From: Ganesh @ 2020-09-18 11:49 UTC (permalink / raw)
  To: Michal Suchánek, npiggin; +Cc: linuxppc-dev, mahesh

On 9/17/20 5:59 PM, Michal Suchánek wrote:
> Hello,
>
> On Wed, Sep 16, 2020 at 10:52:25PM +0530, Ganesh Goudar wrote:
>> This patch series fixes mce handling for pseries, provides debugfs
>> interface for mce injection and adds selftest to test mce handling
>> on pseries/powernv machines running in hash mmu mode.
>> debugfs interface and sleftest are added only for slb multihit
>> injection, We can add other tests in future if possible.
>>
>> Ganesh Goudar (3):
>>    powerpc/mce: remove nmi_enter/exit from real mode handler
>>    powerpc/mce: Add debugfs interface to inject MCE
>>    selftest/powerpc: Add slb multihit selftest
> Is the below logic sound? It does not agree with what is added here:
>
> void machine_check_exception(struct pt_regs *regs)
> {
> 	int recover = 0;
>
> 	/*
> 	 * BOOK3S_64 does not call this handler as a non-maskable interrupt
> 	 * (it uses its own early real-mode handler to handle the MCE proper
> 	 * and then raises irq_work to call this handler when interrupts are
> 	 * enabled).
> 	 *
> 	 * This is silly. The BOOK3S_64 should just call a different function
> 	 * rather than expecting semantics to magically change. Something
> 	 * like 'non_nmi_machine_check_exception()', perhaps?
> 	 */
> 	const bool nmi = !IS_ENABLED(CONFIG_PPC_BOOK3S_64);
>
> 	if (nmi) nmi_enter();
>
> Thanks
>
> Michal
Looks like Nick Piggin has the Justification for it, Ill leave Nick to 
answer this.

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

* Re: [PATCH 1/3] powerpc/mce: remove nmi_enter/exit from real mode handler
  2020-09-17 12:20   ` Michal Suchánek
@ 2020-09-18 12:04     ` Ganesh
  0 siblings, 0 replies; 16+ messages in thread
From: Ganesh @ 2020-09-18 12:04 UTC (permalink / raw)
  To: Michal Suchánek, npiggin; +Cc: linuxppc-dev, mahesh

On 9/17/20 5:50 PM, Michal Suchánek wrote:

> Hello,
>
> On Wed, Sep 16, 2020 at 10:52:26PM +0530, Ganesh Goudar wrote:
>> Use of nmi_enter/exit in real mode handler causes the kernel to panic
>> and reboot on injecting slb mutihit on pseries machine running in hash
>> mmu mode, As these calls try to accesses memory outside RMO region in
>> real mode handler where translation is disabled.
>>
>> Add check to not to use these calls on pseries machine running in hash
>> mmu mode.
>>
>> Fixes: 116ac378bb3f ("powerpc/64s: machine check interrupt update NMI accounting")
>> Signed-off-by: Ganesh Goudar <ganeshgr@linux.ibm.com>
>> ---
>>   arch/powerpc/kernel/mce.c | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
>> index ada59f6c4298..1d42fe0f5f9c 100644
>> --- a/arch/powerpc/kernel/mce.c
>> +++ b/arch/powerpc/kernel/mce.c
>> @@ -591,10 +591,15 @@ EXPORT_SYMBOL_GPL(machine_check_print_event_info);
>>   long notrace machine_check_early(struct pt_regs *regs)
>>   {
>>   	long handled = 0;
>> -	bool nested = in_nmi();
>> +	bool nested;
>> +	bool is_pseries_hpt_guest;
>>   	u8 ftrace_enabled = this_cpu_get_ftrace_enabled();
>>   
>>   	this_cpu_set_ftrace_enabled(0);
>> +	is_pseries_hpt_guest = machine_is(pseries) &&
>> +			       mmu_has_feature(MMU_FTR_HPTE_TABLE);
>> +	/* Do not use nmi_enter/exit for pseries hpte guest */
>> +	nested = is_pseries_hpt_guest ? true : in_nmi();
> As pointed out already in another comment nesting is supported natively
> since 69ea03b56ed2c7189ccd0b5910ad39f3cad1df21. You can simply do
> nmi_enter and nmi_exit unconditionally - or only based on
> is_pseries_hpt_guest.
ok
> The other question is what is the value of calling nmi_enter here at
> all. It crashes in one case, we simply skip it for that case, and we are
> good. Maybe we could skip it altogether?
Not sure why nmi_enter/exit is needed here, Again, Nick may have a reason.
> Thanks
>
> Michal

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

* Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE
  2020-09-17 12:23   ` Michal Suchánek
@ 2020-09-18 12:06     ` Ganesh
  0 siblings, 0 replies; 16+ messages in thread
From: Ganesh @ 2020-09-18 12:06 UTC (permalink / raw)
  To: Michal Suchánek; +Cc: linuxppc-dev, npiggin, mahesh


On 9/17/20 5:53 PM, Michal Suchánek wrote:
> Hello,
>
> On Wed, Sep 16, 2020 at 10:52:27PM +0530, Ganesh Goudar wrote:
>> To test machine check handling, add debugfs interface to inject
>> slb multihit errors.
>>
>> To inject slb multihit:
>>   #echo 1 > /sys/kernel/debug/powerpc/mce_error_inject/inject_slb_multihit
>>
>> Signed-off-by: Ganesh Goudar <ganeshgr@linux.ibm.com>
>> Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
>> ---
>>   arch/powerpc/Kconfig.debug             |   9 ++
>>   arch/powerpc/sysdev/Makefile           |   2 +
>>   arch/powerpc/sysdev/mce_error_inject.c | 148 +++++++++++++++++++++++++
>>   3 files changed, 159 insertions(+)
>>   create mode 100644 arch/powerpc/sysdev/mce_error_inject.c
>>
>> diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
>> index b88900f4832f..61db133f2f0d 100644
>> --- a/arch/powerpc/Kconfig.debug
>> +++ b/arch/powerpc/Kconfig.debug
>> @@ -398,3 +398,12 @@ config KASAN_SHADOW_OFFSET
>>   	hex
>>   	depends on KASAN
>>   	default 0xe0000000
>> +
>> +config MCE_ERROR_INJECT
>> +	bool "Enable MCE error injection through debugfs"
>> +	depends on DEBUG_FS
>> +	default y
>> +	help
>> +	  This option creates an mce_error_inject directory in the
>> +	  powerpc debugfs directory that allows limited injection of
>> +	  Machine Check Errors (MCEs).
>> diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
>> index 026b3f01a991..7fc102222b77 100644
>> --- a/arch/powerpc/sysdev/Makefile
>> +++ b/arch/powerpc/sysdev/Makefile
>> @@ -52,3 +52,5 @@ obj-$(CONFIG_PPC_XICS)		+= xics/
>>   obj-$(CONFIG_PPC_XIVE)		+= xive/
>>   
>>   obj-$(CONFIG_GE_FPGA)		+= ge/
>> +
>> +obj-$(CONFIG_MCE_ERROR_INJECT)	+= mce_error_inject.o
>> diff --git a/arch/powerpc/sysdev/mce_error_inject.c b/arch/powerpc/sysdev/mce_error_inject.c
>> new file mode 100644
>> index 000000000000..ca4726bfa2d9
>> --- /dev/null
>> +++ b/arch/powerpc/sysdev/mce_error_inject.c
>> @@ -0,0 +1,148 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Machine Check Exception injection code
>> + */
>> +
>> +#include <linux/kernel.h>
>> +#include <linux/slab.h>
>> +#include <linux/vmalloc.h>
>> +#include <linux/fs.h>
>> +#include <linux/debugfs.h>
>> +#include <asm/debugfs.h>
>> +
>> +static inline unsigned long get_slb_index(void)
>> +{
>> +	unsigned long index;
>> +
>> +	index = get_paca()->stab_rr;
>> +
>> +	/*
>> +	 * simple round-robin replacement of slb starting at SLB_NUM_BOLTED.
>> +	 */
>> +	if (index < (mmu_slb_size - 1))
>> +		index++;
>> +	else
>> +		index = SLB_NUM_BOLTED;
>> +	get_paca()->stab_rr = index;
>> +	return index;
>> +}
>> +
>> +#define slb_esid_mask(ssize)	\
>> +	(((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
>> +
>> +static inline unsigned long mk_esid_data(unsigned long ea, int ssize,
>> +					 unsigned long slot)
>> +{
>> +	return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
>> +}
>> +
>> +#define slb_vsid_shift(ssize)	\
>> +	((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
>> +
>> +static inline unsigned long mk_vsid_data(unsigned long ea, int ssize,
>> +					 unsigned long flags)
>> +{
>> +	return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
>> +		((unsigned long)ssize << SLB_VSID_SSIZE_SHIFT);
>> +}
>> +
>> +static void insert_slb_entry(char *p, int ssize)
>> +{
>> +	unsigned long flags, entry;
>> +	struct paca_struct *paca;
>> +
>> +	flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
>> +
>> +	preempt_disable();
>> +
>> +	paca = get_paca();
> This seems unused?
Thanks, ill remove it.
>> +
>> +	entry = get_slb_index();
>> +	asm volatile("slbmte %0,%1" :
>> +			: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
>> +			  "r" (mk_esid_data((unsigned long)p, ssize, entry))
>> +			: "memory");
>> +
>> +	entry = get_slb_index();
>> +	asm volatile("slbmte %0,%1" :
>> +			: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
>> +			  "r" (mk_esid_data((unsigned long)p, ssize, entry))
>> +			: "memory");
>> +	preempt_enable();
>> +	p[0] = '!';
>> +}
>> +
>> +static void inject_vmalloc_slb_multihit(void)
>> +{
>> +	char *p;
>> +
>> +	p = vmalloc(2048);
>> +	if (!p)
>> +		return;
>> +
>> +	insert_slb_entry(p, MMU_SEGSIZE_1T);
>> +	vfree(p);
>> +}
>> +
>> +static void inject_kmalloc_slb_multihit(void)
>> +{
>> +	char *p;
>> +
>> +	p = kmalloc(2048, GFP_KERNEL);
>> +	if (!p)
>> +		return;
>> +
>> +	insert_slb_entry(p, MMU_SEGSIZE_1T);
>> +	kfree(p);
>> +}
>> +
>> +static ssize_t inject_slb_multihit(const char __user *u_buf, size_t count)
>> +{
>> +	char buf[32];
>> +	size_t buf_size;
>> +
>> +	buf_size = min(count, (sizeof(buf) - 1));
>> +	if (copy_from_user(buf, u_buf, buf_size))
>> +		return -EFAULT;
>> +	buf[buf_size] = '\0';
>> +
>> +	if (buf[0] != '1')
>> +		return -EINVAL;
>> +
>> +	inject_vmalloc_slb_multihit();
>> +	inject_kmalloc_slb_multihit();
> This is missing the test of multihit in paca which is for some reason
> special.
I will add it, Thanks
> Thanks
>
> Michal
>> +	return count;
>> +}
>> +
>> +static ssize_t inject_write(struct file *file, const char __user *buf,
>> +			    size_t count, loff_t *ppos)
>> +{
>> +	static ssize_t (*func)(const char __user *, size_t);
>> +
>> +	func = file->f_inode->i_private;
>> +	return func(buf, count);
>> +}
>> +
>> +static const struct file_operations inject_fops = {
>> +	.write		= inject_write,
>> +	.llseek		= default_llseek,
>> +};
>> +
>> +static int mce_error_inject_setup(void)
>> +{
>> +	struct dentry *mce_error_inject_dir;
>> +
>> +	mce_error_inject_dir = debugfs_create_dir("mce_error_inject",
>> +						  powerpc_debugfs_root);
>> +
>> +	if (mmu_has_feature(MMU_FTR_HPTE_TABLE)) {
>> +		(void)debugfs_create_file("inject_slb_multihit", 0200,
>> +					  mce_error_inject_dir,
>> +					  &inject_slb_multihit,
>> +					  &inject_fops);
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +device_initcall(mce_error_inject_setup);
>> -- 
>> 2.26.2
>>

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

* Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE
  2020-09-18  6:40   ` Michael Ellerman
@ 2020-09-18 12:07     ` Ganesh
  0 siblings, 0 replies; 16+ messages in thread
From: Ganesh @ 2020-09-18 12:07 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev; +Cc: mahesh, msuchanek, Kees Cook, npiggin


On 9/18/20 12:10 PM, Michael Ellerman wrote:
> Hi Ganesh,
>
> Ganesh Goudar <ganeshgr@linux.ibm.com> writes:
>> To test machine check handling, add debugfs interface to inject
>> slb multihit errors.
>>
>> To inject slb multihit:
>>   #echo 1 > /sys/kernel/debug/powerpc/mce_error_inject/inject_slb_multihit
> Rather than creating a new ad-hoc way to trigger this, can you please
> integrate it into drivers/misc/lkdtm.
>
> There's enough code here that I think you should create
> drivers/misc/lkdtm/powerpc.c and put the code in there. Then add an
> LKDTM entry point for this, maybe called PPC_SLB_MULTIHIT.
>
> Please Cc Kees when you repost.
Sure, Thanks
> cheers
>
>
>>   arch/powerpc/Kconfig.debug             |   9 ++
>>   arch/powerpc/sysdev/Makefile           |   2 +
>>   arch/powerpc/sysdev/mce_error_inject.c | 148 +++++++++++++++++++++++++
>>   3 files changed, 159 insertions(+)
>>   create mode 100644 arch/powerpc/sysdev/mce_error_inject.c
>>
>> diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
>> index b88900f4832f..61db133f2f0d 100644
>> --- a/arch/powerpc/Kconfig.debug
>> +++ b/arch/powerpc/Kconfig.debug
>> @@ -398,3 +398,12 @@ config KASAN_SHADOW_OFFSET
>>   	hex
>>   	depends on KASAN
>>   	default 0xe0000000
>> +
>> +config MCE_ERROR_INJECT
>> +	bool "Enable MCE error injection through debugfs"
>> +	depends on DEBUG_FS
>> +	default y
>> +	help
>> +	  This option creates an mce_error_inject directory in the
>> +	  powerpc debugfs directory that allows limited injection of
>> +	  Machine Check Errors (MCEs).
>> diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
>> index 026b3f01a991..7fc102222b77 100644
>> --- a/arch/powerpc/sysdev/Makefile
>> +++ b/arch/powerpc/sysdev/Makefile
>> @@ -52,3 +52,5 @@ obj-$(CONFIG_PPC_XICS)		+= xics/
>>   obj-$(CONFIG_PPC_XIVE)		+= xive/
>>   
>>   obj-$(CONFIG_GE_FPGA)		+= ge/
>> +
>> +obj-$(CONFIG_MCE_ERROR_INJECT)	+= mce_error_inject.o
>> diff --git a/arch/powerpc/sysdev/mce_error_inject.c b/arch/powerpc/sysdev/mce_error_inject.c
>> new file mode 100644
>> index 000000000000..ca4726bfa2d9
>> --- /dev/null
>> +++ b/arch/powerpc/sysdev/mce_error_inject.c
>> @@ -0,0 +1,148 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Machine Check Exception injection code
>> + */
>> +
>> +#include <linux/kernel.h>
>> +#include <linux/slab.h>
>> +#include <linux/vmalloc.h>
>> +#include <linux/fs.h>
>> +#include <linux/debugfs.h>
>> +#include <asm/debugfs.h>
>> +
>> +static inline unsigned long get_slb_index(void)
>> +{
>> +	unsigned long index;
>> +
>> +	index = get_paca()->stab_rr;
>> +
>> +	/*
>> +	 * simple round-robin replacement of slb starting at SLB_NUM_BOLTED.
>> +	 */
>> +	if (index < (mmu_slb_size - 1))
>> +		index++;
>> +	else
>> +		index = SLB_NUM_BOLTED;
>> +	get_paca()->stab_rr = index;
>> +	return index;
>> +}
>> +
>> +#define slb_esid_mask(ssize)	\
>> +	(((ssize) == MMU_SEGSIZE_256M) ? ESID_MASK : ESID_MASK_1T)
>> +
>> +static inline unsigned long mk_esid_data(unsigned long ea, int ssize,
>> +					 unsigned long slot)
>> +{
>> +	return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
>> +}
>> +
>> +#define slb_vsid_shift(ssize)	\
>> +	((ssize) == MMU_SEGSIZE_256M ? SLB_VSID_SHIFT : SLB_VSID_SHIFT_1T)
>> +
>> +static inline unsigned long mk_vsid_data(unsigned long ea, int ssize,
>> +					 unsigned long flags)
>> +{
>> +	return (get_kernel_vsid(ea, ssize) << slb_vsid_shift(ssize)) | flags |
>> +		((unsigned long)ssize << SLB_VSID_SSIZE_SHIFT);
>> +}
>> +
>> +static void insert_slb_entry(char *p, int ssize)
>> +{
>> +	unsigned long flags, entry;
>> +	struct paca_struct *paca;
>> +
>> +	flags = SLB_VSID_KERNEL | mmu_psize_defs[MMU_PAGE_64K].sllp;
>> +
>> +	preempt_disable();
>> +
>> +	paca = get_paca();
>> +
>> +	entry = get_slb_index();
>> +	asm volatile("slbmte %0,%1" :
>> +			: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
>> +			  "r" (mk_esid_data((unsigned long)p, ssize, entry))
>> +			: "memory");
>> +
>> +	entry = get_slb_index();
>> +	asm volatile("slbmte %0,%1" :
>> +			: "r" (mk_vsid_data((unsigned long)p, ssize, flags)),
>> +			  "r" (mk_esid_data((unsigned long)p, ssize, entry))
>> +			: "memory");
>> +	preempt_enable();
>> +	p[0] = '!';
>> +}
>> +
>> +static void inject_vmalloc_slb_multihit(void)
>> +{
>> +	char *p;
>> +
>> +	p = vmalloc(2048);
>> +	if (!p)
>> +		return;
>> +
>> +	insert_slb_entry(p, MMU_SEGSIZE_1T);
>> +	vfree(p);
>> +}
>> +
>> +static void inject_kmalloc_slb_multihit(void)
>> +{
>> +	char *p;
>> +
>> +	p = kmalloc(2048, GFP_KERNEL);
>> +	if (!p)
>> +		return;
>> +
>> +	insert_slb_entry(p, MMU_SEGSIZE_1T);
>> +	kfree(p);
>> +}
>> +
>> +static ssize_t inject_slb_multihit(const char __user *u_buf, size_t count)
>> +{
>> +	char buf[32];
>> +	size_t buf_size;
>> +
>> +	buf_size = min(count, (sizeof(buf) - 1));
>> +	if (copy_from_user(buf, u_buf, buf_size))
>> +		return -EFAULT;
>> +	buf[buf_size] = '\0';
>> +
>> +	if (buf[0] != '1')
>> +		return -EINVAL;
>> +
>> +	inject_vmalloc_slb_multihit();
>> +	inject_kmalloc_slb_multihit();
>> +	return count;
>> +}
>> +
>> +static ssize_t inject_write(struct file *file, const char __user *buf,
>> +			    size_t count, loff_t *ppos)
>> +{
>> +	static ssize_t (*func)(const char __user *, size_t);
>> +
>> +	func = file->f_inode->i_private;
>> +	return func(buf, count);
>> +}
>> +
>> +static const struct file_operations inject_fops = {
>> +	.write		= inject_write,
>> +	.llseek		= default_llseek,
>> +};
>> +
>> +static int mce_error_inject_setup(void)
>> +{
>> +	struct dentry *mce_error_inject_dir;
>> +
>> +	mce_error_inject_dir = debugfs_create_dir("mce_error_inject",
>> +						  powerpc_debugfs_root);
>> +
>> +	if (mmu_has_feature(MMU_FTR_HPTE_TABLE)) {
>> +		(void)debugfs_create_file("inject_slb_multihit", 0200,
>> +					  mce_error_inject_dir,
>> +					  &inject_slb_multihit,
>> +					  &inject_fops);
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +device_initcall(mce_error_inject_setup);
>> -- 
>> 2.26.2

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

end of thread, other threads:[~2020-09-18 12:15 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16 17:22 [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest Ganesh Goudar
2020-09-16 17:22 ` [PATCH 1/3] powerpc/mce: remove nmi_enter/exit from real mode handler Ganesh Goudar
2020-09-17 12:20   ` Michal Suchánek
2020-09-18 12:04     ` Ganesh
2020-09-16 17:22 ` [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE Ganesh Goudar
2020-09-17  8:24   ` kernel test robot
2020-09-17  8:24     ` kernel test robot
2020-09-17  8:36   ` kernel test robot
2020-09-17  8:36     ` kernel test robot
2020-09-17 12:23   ` Michal Suchánek
2020-09-18 12:06     ` Ganesh
2020-09-18  6:40   ` Michael Ellerman
2020-09-18 12:07     ` Ganesh
2020-09-16 17:22 ` [PATCH 3/3] selftest/powerpc: Add slb multihit selftest Ganesh Goudar
2020-09-17 12:29 ` [PATCH 0/3] powerpc/mce: Fix mce handler and add selftest Michal Suchánek
2020-09-18 11:49   ` Ganesh

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.