Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE

2020-09-18 Thread Ganesh



On 9/18/20 12:10 PM, Michael Ellerman wrote:

Hi Ganesh,

Ganesh Goudar  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 0xe000
+
+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..7fc10b77 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 ..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 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+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;
+
+   injec

Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE

2020-09-18 Thread Ganesh



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 
Signed-off-by: Mahesh Salgaonkar 
---
  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 0xe000
+
+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..7fc10b77 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 ..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 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+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 cou

Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE

2020-09-17 Thread Michael Ellerman
Hi Ganesh,

Ganesh Goudar  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 0xe000
> +
> +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..7fc10b77 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 ..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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +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))
> + 

Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE

2020-09-17 Thread Michal Suchánek
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 
> Signed-off-by: Mahesh Salgaonkar 
> ---
>  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 0xe000
> +
> +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..7fc10b77 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 ..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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +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 mis

Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE

2020-09-17 Thread kernel test robot
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 

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-...@lists.01.org


.config.gz
Description: application/gzip


Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE

2020-09-17 Thread kernel test robot
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 

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_

[PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE

2020-09-16 Thread Ganesh Goudar
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 
Signed-off-by: Mahesh Salgaonkar 
---
 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 0xe000
+
+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..7fc10b77 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 ..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 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+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 con