linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Ganesh <ganeshgr@linux.ibm.com>
To: "Michal Suchánek" <msuchanek@suse.de>
Cc: linuxppc-dev@lists.ozlabs.org, npiggin@gmail.com,
	mahesh@linux.vnet.ibm.com
Subject: Re: [PATCH 2/3] powerpc/mce: Add debugfs interface to inject MCE
Date: Fri, 18 Sep 2020 17:36:35 +0530	[thread overview]
Message-ID: <81ae9861-e80a-5bf8-bcab-d8fb4730e277@linux.ibm.com> (raw)
In-Reply-To: <20200917122348.GQ29778@kitsune.suse.cz>


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
>>

  reply	other threads:[~2020-09-18 12:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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:36   ` kernel test robot
2020-09-17 12:23   ` Michal Suchánek
2020-09-18 12:06     ` Ganesh [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81ae9861-e80a-5bf8-bcab-d8fb4730e277@linux.ibm.com \
    --to=ganeshgr@linux.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mahesh@linux.vnet.ibm.com \
    --cc=msuchanek@suse.de \
    --cc=npiggin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).