diff options
| author | Borislav Petkov <bp@suse.de> | 2014-11-22 05:09:12 -0500 |
|---|---|---|
| committer | Borislav Petkov <bp@suse.de> | 2014-11-25 07:09:33 -0500 |
| commit | fd19fcd6324d29c97ba69ac3433e392989af401c (patch) | |
| tree | bb347fdc8f49988c54b14d1982e79da5ec9d7a16 /drivers/edac | |
| parent | 0a98babd85b2e69d64ef6f2f8a5d029ddaa702e1 (diff) | |
EDAC, mce_amd_inj: Convert mce_amd_inj module to debugfs
This module's interface belongs in debugfs, not in sysfs.
Signed-off-by: Borislav Petkov <bp@suse.de>
Diffstat (limited to 'drivers/edac')
| -rw-r--r-- | drivers/edac/Kconfig | 10 | ||||
| -rw-r--r-- | drivers/edac/mce_amd_inj.c | 180 |
2 files changed, 83 insertions, 107 deletions
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig index 4316c9e955b3..49c265255a07 100644 --- a/drivers/edac/Kconfig +++ b/drivers/edac/Kconfig | |||
| @@ -61,14 +61,14 @@ config EDAC_DECODE_MCE | |||
| 61 | has been initialized. | 61 | has been initialized. |
| 62 | 62 | ||
| 63 | config EDAC_MCE_INJ | 63 | config EDAC_MCE_INJ |
| 64 | tristate "Simple MCE injection interface over /sysfs" | 64 | tristate "Simple MCE injection interface" |
| 65 | depends on EDAC_DECODE_MCE | 65 | depends on EDAC_DECODE_MCE && DEBUG_FS |
| 66 | default n | 66 | default n |
| 67 | help | 67 | help |
| 68 | This is a simple interface to inject MCEs over /sysfs and test | 68 | This is a simple debugfs interface to inject MCEs and test different |
| 69 | the MCE decoding code in EDAC. | 69 | aspects of the MCE handling code. |
| 70 | 70 | ||
| 71 | This is currently AMD-only. | 71 | WARNING: Do not even assume this interface is staying stable! |
| 72 | 72 | ||
| 73 | config EDAC_MM_EDAC | 73 | config EDAC_MM_EDAC |
| 74 | tristate "Main Memory EDAC (Error Detection And Correction) reporting" | 74 | tristate "Main Memory EDAC (Error Detection And Correction) reporting" |
diff --git a/drivers/edac/mce_amd_inj.c b/drivers/edac/mce_amd_inj.c index 5e46a9fea31b..9b5023d6f553 100644 --- a/drivers/edac/mce_amd_inj.c +++ b/drivers/edac/mce_amd_inj.c | |||
| @@ -1,173 +1,149 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * A simple MCE injection facility for testing the MCE decoding code. This | 2 | * A simple MCE injection facility for testing different aspects of the RAS |
| 3 | * driver should be built as module so that it can be loaded on production | 3 | * code. This driver should be built as module so that it can be loaded |
| 4 | * kernels for testing purposes. | 4 | * on production kernels for testing purposes. |
| 5 | * | 5 | * |
| 6 | * This file may be distributed under the terms of the GNU General Public | 6 | * This file may be distributed under the terms of the GNU General Public |
| 7 | * License version 2. | 7 | * License version 2. |
| 8 | * | 8 | * |
| 9 | * Copyright (c) 2010: Borislav Petkov <bp@alien8.de> | 9 | * Copyright (c) 2010-14: Borislav Petkov <bp@alien8.de> |
| 10 | * Advanced Micro Devices Inc. | 10 | * Advanced Micro Devices Inc. |
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | #include <linux/kobject.h> | 13 | #include <linux/kobject.h> |
| 14 | #include <linux/debugfs.h> | ||
| 14 | #include <linux/device.h> | 15 | #include <linux/device.h> |
| 15 | #include <linux/edac.h> | ||
| 16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
| 17 | #include <asm/mce.h> | 17 | #include <asm/mce.h> |
| 18 | 18 | ||
| 19 | #include "mce_amd.h" | 19 | #include "mce_amd.h" |
| 20 | 20 | ||
| 21 | struct edac_mce_attr { | ||
| 22 | struct attribute attr; | ||
| 23 | ssize_t (*show) (struct kobject *kobj, struct edac_mce_attr *attr, char *buf); | ||
| 24 | ssize_t (*store)(struct kobject *kobj, struct edac_mce_attr *attr, | ||
| 25 | const char *buf, size_t count); | ||
| 26 | }; | ||
| 27 | |||
| 28 | #define EDAC_MCE_ATTR(_name, _mode, _show, _store) \ | ||
| 29 | static struct edac_mce_attr mce_attr_##_name = __ATTR(_name, _mode, _show, _store) | ||
| 30 | |||
| 31 | static struct kobject *mce_kobj; | ||
| 32 | |||
| 33 | /* | 21 | /* |
| 34 | * Collect all the MCi_XXX settings | 22 | * Collect all the MCi_XXX settings |
| 35 | */ | 23 | */ |
| 36 | static struct mce i_mce; | 24 | static struct mce i_mce; |
| 25 | static struct dentry *dfs_inj; | ||
| 37 | 26 | ||
| 38 | #define MCE_INJECT_STORE(reg) \ | 27 | #define MCE_INJECT_SET(reg) \ |
| 39 | static ssize_t edac_inject_##reg##_store(struct kobject *kobj, \ | 28 | static int inj_##reg##_set(void *data, u64 val) \ |
| 40 | struct edac_mce_attr *attr, \ | ||
| 41 | const char *data, size_t count)\ | ||
| 42 | { \ | 29 | { \ |
| 43 | int ret = 0; \ | 30 | struct mce *m = (struct mce *)data; \ |
| 44 | unsigned long value; \ | ||
| 45 | \ | ||
| 46 | ret = kstrtoul(data, 16, &value); \ | ||
| 47 | if (ret < 0) \ | ||
| 48 | printk(KERN_ERR "Error writing MCE " #reg " field.\n"); \ | ||
| 49 | \ | ||
| 50 | i_mce.reg = value; \ | ||
| 51 | \ | 31 | \ |
| 52 | return count; \ | 32 | m->reg = val; \ |
| 33 | return 0; \ | ||
| 53 | } | 34 | } |
| 54 | 35 | ||
| 55 | MCE_INJECT_STORE(status); | 36 | MCE_INJECT_SET(status); |
| 56 | MCE_INJECT_STORE(misc); | 37 | MCE_INJECT_SET(misc); |
| 57 | MCE_INJECT_STORE(addr); | 38 | MCE_INJECT_SET(addr); |
| 58 | 39 | ||
| 59 | #define MCE_INJECT_SHOW(reg) \ | 40 | #define MCE_INJECT_GET(reg) \ |
| 60 | static ssize_t edac_inject_##reg##_show(struct kobject *kobj, \ | 41 | static int inj_##reg##_get(void *data, u64 *val) \ |
| 61 | struct edac_mce_attr *attr, \ | ||
| 62 | char *buf) \ | ||
| 63 | { \ | 42 | { \ |
| 64 | return sprintf(buf, "0x%016llx\n", i_mce.reg); \ | 43 | struct mce *m = (struct mce *)data; \ |
| 44 | \ | ||
| 45 | *val = m->reg; \ | ||
| 46 | return 0; \ | ||
| 65 | } | 47 | } |
| 66 | 48 | ||
| 67 | MCE_INJECT_SHOW(status); | 49 | MCE_INJECT_GET(status); |
| 68 | MCE_INJECT_SHOW(misc); | 50 | MCE_INJECT_GET(misc); |
| 69 | MCE_INJECT_SHOW(addr); | 51 | MCE_INJECT_GET(addr); |
| 70 | 52 | ||
| 71 | EDAC_MCE_ATTR(status, 0644, edac_inject_status_show, edac_inject_status_store); | 53 | DEFINE_SIMPLE_ATTRIBUTE(status_fops, inj_status_get, inj_status_set, "%llx\n"); |
| 72 | EDAC_MCE_ATTR(misc, 0644, edac_inject_misc_show, edac_inject_misc_store); | 54 | DEFINE_SIMPLE_ATTRIBUTE(misc_fops, inj_misc_get, inj_misc_set, "%llx\n"); |
| 73 | EDAC_MCE_ATTR(addr, 0644, edac_inject_addr_show, edac_inject_addr_store); | 55 | DEFINE_SIMPLE_ATTRIBUTE(addr_fops, inj_addr_get, inj_addr_set, "%llx\n"); |
| 74 | 56 | ||
| 75 | /* | 57 | /* |
| 76 | * This denotes into which bank we're injecting and triggers | 58 | * This denotes into which bank we're injecting and triggers |
| 77 | * the injection, at the same time. | 59 | * the injection, at the same time. |
| 78 | */ | 60 | */ |
| 79 | static ssize_t edac_inject_bank_store(struct kobject *kobj, | 61 | static int inj_bank_set(void *data, u64 val) |
| 80 | struct edac_mce_attr *attr, | ||
| 81 | const char *data, size_t count) | ||
| 82 | { | 62 | { |
| 83 | int ret = 0; | 63 | struct mce *m = (struct mce *)data; |
| 84 | unsigned long value; | ||
| 85 | 64 | ||
| 86 | ret = kstrtoul(data, 10, &value); | 65 | if (val > 5) { |
| 87 | if (ret < 0) { | 66 | if (boot_cpu_data.x86 != 0x15 || val > 6) { |
| 88 | printk(KERN_ERR "Invalid bank value!\n"); | 67 | pr_err("Non-existent MCE bank: %llu\n", val); |
| 89 | return -EINVAL; | ||
| 90 | } | ||
| 91 | |||
| 92 | if (value > 5) | ||
| 93 | if (boot_cpu_data.x86 != 0x15 || value > 6) { | ||
| 94 | printk(KERN_ERR "Non-existent MCE bank: %lu\n", value); | ||
| 95 | return -EINVAL; | 68 | return -EINVAL; |
| 96 | } | 69 | } |
| 70 | } | ||
| 97 | 71 | ||
| 98 | i_mce.bank = value; | 72 | m->bank = val; |
| 99 | 73 | ||
| 100 | amd_decode_mce(NULL, 0, &i_mce); | 74 | amd_decode_mce(NULL, 0, m); |
| 101 | 75 | ||
| 102 | return count; | 76 | return 0; |
| 103 | } | 77 | } |
| 104 | 78 | ||
| 105 | static ssize_t edac_inject_bank_show(struct kobject *kobj, | 79 | static int inj_bank_get(void *data, u64 *val) |
| 106 | struct edac_mce_attr *attr, char *buf) | ||
| 107 | { | 80 | { |
| 108 | return sprintf(buf, "%d\n", i_mce.bank); | 81 | struct mce *m = (struct mce *)data; |
| 109 | } | ||
| 110 | 82 | ||
| 111 | EDAC_MCE_ATTR(bank, 0644, edac_inject_bank_show, edac_inject_bank_store); | 83 | *val = m->bank; |
| 84 | return 0; | ||
| 85 | } | ||
| 112 | 86 | ||
| 113 | static struct edac_mce_attr *sysfs_attrs[] = { &mce_attr_status, &mce_attr_misc, | 87 | DEFINE_SIMPLE_ATTRIBUTE(bank_fops, inj_bank_get, inj_bank_set, "%llu\n"); |
| 114 | &mce_attr_addr, &mce_attr_bank | 88 | |
| 89 | struct dfs_node { | ||
| 90 | char *name; | ||
| 91 | struct dentry *d; | ||
| 92 | const struct file_operations *fops; | ||
| 93 | } dfs_fls[] = { | ||
| 94 | { .name = "status", .fops = &status_fops }, | ||
| 95 | { .name = "misc", .fops = &misc_fops }, | ||
| 96 | { .name = "addr", .fops = &addr_fops }, | ||
| 97 | { .name = "bank", .fops = &bank_fops }, | ||
| 115 | }; | 98 | }; |
| 116 | 99 | ||
| 117 | static int __init edac_init_mce_inject(void) | 100 | static int __init init_mce_inject(void) |
| 118 | { | 101 | { |
| 119 | struct bus_type *edac_subsys = NULL; | 102 | int i; |
| 120 | int i, err = 0; | ||
| 121 | 103 | ||
| 122 | edac_subsys = edac_get_sysfs_subsys(); | 104 | dfs_inj = debugfs_create_dir("mce-inject", NULL); |
| 123 | if (!edac_subsys) | 105 | if (!dfs_inj) |
| 124 | return -EINVAL; | 106 | return -EINVAL; |
| 125 | 107 | ||
| 126 | mce_kobj = kobject_create_and_add("mce", &edac_subsys->dev_root->kobj); | 108 | for (i = 0; i < ARRAY_SIZE(dfs_fls); i++) { |
| 127 | if (!mce_kobj) { | 109 | dfs_fls[i].d = debugfs_create_file(dfs_fls[i].name, |
| 128 | printk(KERN_ERR "Error creating a mce kset.\n"); | 110 | S_IRUSR | S_IWUSR, |
| 129 | err = -ENOMEM; | 111 | dfs_inj, |
| 130 | goto err_mce_kobj; | 112 | &i_mce, |
| 131 | } | 113 | dfs_fls[i].fops); |
| 132 | 114 | ||
| 133 | for (i = 0; i < ARRAY_SIZE(sysfs_attrs); i++) { | 115 | if (!dfs_fls[i].d) |
| 134 | err = sysfs_create_file(mce_kobj, &sysfs_attrs[i]->attr); | 116 | goto err_dfs_add; |
| 135 | if (err) { | ||
| 136 | printk(KERN_ERR "Error creating %s in sysfs.\n", | ||
| 137 | sysfs_attrs[i]->attr.name); | ||
| 138 | goto err_sysfs_create; | ||
| 139 | } | ||
| 140 | } | 117 | } |
| 118 | |||
| 141 | return 0; | 119 | return 0; |
| 142 | 120 | ||
| 143 | err_sysfs_create: | 121 | err_dfs_add: |
| 144 | while (--i >= 0) | 122 | while (--i >= 0) |
| 145 | sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr); | 123 | debugfs_remove(dfs_fls[i].d); |
| 146 | 124 | ||
| 147 | kobject_del(mce_kobj); | 125 | debugfs_remove(dfs_inj); |
| 126 | dfs_inj = NULL; | ||
| 148 | 127 | ||
| 149 | err_mce_kobj: | 128 | return -ENOMEM; |
| 150 | edac_put_sysfs_subsys(); | ||
| 151 | |||
| 152 | return err; | ||
| 153 | } | 129 | } |
| 154 | 130 | ||
| 155 | static void __exit edac_exit_mce_inject(void) | 131 | static void __exit exit_mce_inject(void) |
| 156 | { | 132 | { |
| 157 | int i; | 133 | int i; |
| 158 | 134 | ||
| 159 | for (i = 0; i < ARRAY_SIZE(sysfs_attrs); i++) | 135 | for (i = 0; i < ARRAY_SIZE(dfs_fls); i++) |
| 160 | sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr); | 136 | debugfs_remove(dfs_fls[i].d); |
| 161 | 137 | ||
| 162 | kobject_del(mce_kobj); | 138 | memset(&dfs_fls, 0, sizeof(dfs_fls)); |
| 163 | 139 | ||
| 164 | edac_put_sysfs_subsys(); | 140 | debugfs_remove(dfs_inj); |
| 141 | dfs_inj = NULL; | ||
| 165 | } | 142 | } |
| 166 | 143 | module_init(init_mce_inject); | |
| 167 | module_init(edac_init_mce_inject); | 144 | module_exit(exit_mce_inject); |
| 168 | module_exit(edac_exit_mce_inject); | ||
| 169 | 145 | ||
| 170 | MODULE_LICENSE("GPL"); | 146 | MODULE_LICENSE("GPL"); |
| 171 | MODULE_AUTHOR("Borislav Petkov <bp@alien8.de>"); | 147 | MODULE_AUTHOR("Borislav Petkov <bp@alien8.de>"); |
| 172 | MODULE_AUTHOR("AMD Inc."); | 148 | MODULE_AUTHOR("AMD Inc."); |
| 173 | MODULE_DESCRIPTION("MCE injection facility for testing MCE decoding"); | 149 | MODULE_DESCRIPTION("MCE injection facility for RAS testing"); |
