Commit fd19fcd6 authored by Borislav Petkov's avatar Borislav Petkov

EDAC, mce_amd_inj: Convert mce_amd_inj module to debugfs

This module's interface belongs in debugfs, not in sysfs.
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
parent 0a98babd
...@@ -61,14 +61,14 @@ config EDAC_DECODE_MCE ...@@ -61,14 +61,14 @@ config EDAC_DECODE_MCE
has been initialized. has been initialized.
config EDAC_MCE_INJ config EDAC_MCE_INJ
tristate "Simple MCE injection interface over /sysfs" tristate "Simple MCE injection interface"
depends on EDAC_DECODE_MCE depends on EDAC_DECODE_MCE && DEBUG_FS
default n default n
help help
This is a simple interface to inject MCEs over /sysfs and test This is a simple debugfs interface to inject MCEs and test different
the MCE decoding code in EDAC. aspects of the MCE handling code.
This is currently AMD-only. WARNING: Do not even assume this interface is staying stable!
config EDAC_MM_EDAC config EDAC_MM_EDAC
tristate "Main Memory EDAC (Error Detection And Correction) reporting" tristate "Main Memory EDAC (Error Detection And Correction) reporting"
......
/* /*
* A simple MCE injection facility for testing the MCE decoding code. This * A simple MCE injection facility for testing different aspects of the RAS
* driver should be built as module so that it can be loaded on production * code. This driver should be built as module so that it can be loaded
* kernels for testing purposes. * on production kernels for testing purposes.
* *
* This file may be distributed under the terms of the GNU General Public * This file may be distributed under the terms of the GNU General Public
* License version 2. * License version 2.
* *
* Copyright (c) 2010: Borislav Petkov <bp@alien8.de> * Copyright (c) 2010-14: Borislav Petkov <bp@alien8.de>
* Advanced Micro Devices Inc. * Advanced Micro Devices Inc.
*/ */
#include <linux/kobject.h> #include <linux/kobject.h>
#include <linux/debugfs.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/edac.h>
#include <linux/module.h> #include <linux/module.h>
#include <asm/mce.h> #include <asm/mce.h>
#include "mce_amd.h" #include "mce_amd.h"
struct edac_mce_attr {
struct attribute attr;
ssize_t (*show) (struct kobject *kobj, struct edac_mce_attr *attr, char *buf);
ssize_t (*store)(struct kobject *kobj, struct edac_mce_attr *attr,
const char *buf, size_t count);
};
#define EDAC_MCE_ATTR(_name, _mode, _show, _store) \
static struct edac_mce_attr mce_attr_##_name = __ATTR(_name, _mode, _show, _store)
static struct kobject *mce_kobj;
/* /*
* Collect all the MCi_XXX settings * Collect all the MCi_XXX settings
*/ */
static struct mce i_mce; static struct mce i_mce;
static struct dentry *dfs_inj;
#define MCE_INJECT_STORE(reg) \ #define MCE_INJECT_SET(reg) \
static ssize_t edac_inject_##reg##_store(struct kobject *kobj, \ static int inj_##reg##_set(void *data, u64 val) \
struct edac_mce_attr *attr, \
const char *data, size_t count)\
{ \ { \
int ret = 0; \ struct mce *m = (struct mce *)data; \
unsigned long value; \
\
ret = kstrtoul(data, 16, &value); \
if (ret < 0) \
printk(KERN_ERR "Error writing MCE " #reg " field.\n"); \
\ \
i_mce.reg = value; \ m->reg = val; \
\ return 0; \
return count; \
} }
MCE_INJECT_STORE(status); MCE_INJECT_SET(status);
MCE_INJECT_STORE(misc); MCE_INJECT_SET(misc);
MCE_INJECT_STORE(addr); MCE_INJECT_SET(addr);
#define MCE_INJECT_SHOW(reg) \ #define MCE_INJECT_GET(reg) \
static ssize_t edac_inject_##reg##_show(struct kobject *kobj, \ static int inj_##reg##_get(void *data, u64 *val) \
struct edac_mce_attr *attr, \
char *buf) \
{ \ { \
return sprintf(buf, "0x%016llx\n", i_mce.reg); \ struct mce *m = (struct mce *)data; \
\
*val = m->reg; \
return 0; \
} }
MCE_INJECT_SHOW(status); MCE_INJECT_GET(status);
MCE_INJECT_SHOW(misc); MCE_INJECT_GET(misc);
MCE_INJECT_SHOW(addr); MCE_INJECT_GET(addr);
EDAC_MCE_ATTR(status, 0644, edac_inject_status_show, edac_inject_status_store); DEFINE_SIMPLE_ATTRIBUTE(status_fops, inj_status_get, inj_status_set, "%llx\n");
EDAC_MCE_ATTR(misc, 0644, edac_inject_misc_show, edac_inject_misc_store); DEFINE_SIMPLE_ATTRIBUTE(misc_fops, inj_misc_get, inj_misc_set, "%llx\n");
EDAC_MCE_ATTR(addr, 0644, edac_inject_addr_show, edac_inject_addr_store); DEFINE_SIMPLE_ATTRIBUTE(addr_fops, inj_addr_get, inj_addr_set, "%llx\n");
/* /*
* This denotes into which bank we're injecting and triggers * This denotes into which bank we're injecting and triggers
* the injection, at the same time. * the injection, at the same time.
*/ */
static ssize_t edac_inject_bank_store(struct kobject *kobj, static int inj_bank_set(void *data, u64 val)
struct edac_mce_attr *attr,
const char *data, size_t count)
{ {
int ret = 0; struct mce *m = (struct mce *)data;
unsigned long value;
ret = kstrtoul(data, 10, &value); if (val > 5) {
if (ret < 0) { if (boot_cpu_data.x86 != 0x15 || val > 6) {
printk(KERN_ERR "Invalid bank value!\n"); pr_err("Non-existent MCE bank: %llu\n", val);
return -EINVAL; return -EINVAL;
} }
if (value > 5)
if (boot_cpu_data.x86 != 0x15 || value > 6) {
printk(KERN_ERR "Non-existent MCE bank: %lu\n", value);
return -EINVAL;
} }
i_mce.bank = value; m->bank = val;
amd_decode_mce(NULL, 0, &i_mce); amd_decode_mce(NULL, 0, m);
return count; return 0;
} }
static ssize_t edac_inject_bank_show(struct kobject *kobj, static int inj_bank_get(void *data, u64 *val)
struct edac_mce_attr *attr, char *buf)
{ {
return sprintf(buf, "%d\n", i_mce.bank); struct mce *m = (struct mce *)data;
}
EDAC_MCE_ATTR(bank, 0644, edac_inject_bank_show, edac_inject_bank_store); *val = m->bank;
return 0;
}
static struct edac_mce_attr *sysfs_attrs[] = { &mce_attr_status, &mce_attr_misc, DEFINE_SIMPLE_ATTRIBUTE(bank_fops, inj_bank_get, inj_bank_set, "%llu\n");
&mce_attr_addr, &mce_attr_bank
struct dfs_node {
char *name;
struct dentry *d;
const struct file_operations *fops;
} dfs_fls[] = {
{ .name = "status", .fops = &status_fops },
{ .name = "misc", .fops = &misc_fops },
{ .name = "addr", .fops = &addr_fops },
{ .name = "bank", .fops = &bank_fops },
}; };
static int __init edac_init_mce_inject(void) static int __init init_mce_inject(void)
{ {
struct bus_type *edac_subsys = NULL; int i;
int i, err = 0;
edac_subsys = edac_get_sysfs_subsys(); dfs_inj = debugfs_create_dir("mce-inject", NULL);
if (!edac_subsys) if (!dfs_inj)
return -EINVAL; return -EINVAL;
mce_kobj = kobject_create_and_add("mce", &edac_subsys->dev_root->kobj); for (i = 0; i < ARRAY_SIZE(dfs_fls); i++) {
if (!mce_kobj) { dfs_fls[i].d = debugfs_create_file(dfs_fls[i].name,
printk(KERN_ERR "Error creating a mce kset.\n"); S_IRUSR | S_IWUSR,
err = -ENOMEM; dfs_inj,
goto err_mce_kobj; &i_mce,
} dfs_fls[i].fops);
for (i = 0; i < ARRAY_SIZE(sysfs_attrs); i++) { if (!dfs_fls[i].d)
err = sysfs_create_file(mce_kobj, &sysfs_attrs[i]->attr); goto err_dfs_add;
if (err) {
printk(KERN_ERR "Error creating %s in sysfs.\n",
sysfs_attrs[i]->attr.name);
goto err_sysfs_create;
}
} }
return 0; return 0;
err_sysfs_create: err_dfs_add:
while (--i >= 0) while (--i >= 0)
sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr); debugfs_remove(dfs_fls[i].d);
kobject_del(mce_kobj); debugfs_remove(dfs_inj);
dfs_inj = NULL;
err_mce_kobj: return -ENOMEM;
edac_put_sysfs_subsys();
return err;
} }
static void __exit edac_exit_mce_inject(void) static void __exit exit_mce_inject(void)
{ {
int i; int i;
for (i = 0; i < ARRAY_SIZE(sysfs_attrs); i++) for (i = 0; i < ARRAY_SIZE(dfs_fls); i++)
sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr); debugfs_remove(dfs_fls[i].d);
kobject_del(mce_kobj); memset(&dfs_fls, 0, sizeof(dfs_fls));
edac_put_sysfs_subsys(); debugfs_remove(dfs_inj);
dfs_inj = NULL;
} }
module_init(init_mce_inject);
module_init(edac_init_mce_inject); module_exit(exit_mce_inject);
module_exit(edac_exit_mce_inject);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_AUTHOR("Borislav Petkov <bp@alien8.de>"); MODULE_AUTHOR("Borislav Petkov <bp@alien8.de>");
MODULE_AUTHOR("AMD Inc."); MODULE_AUTHOR("AMD Inc.");
MODULE_DESCRIPTION("MCE injection facility for testing MCE decoding"); MODULE_DESCRIPTION("MCE injection facility for RAS testing");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment