Skip to content

Commit 9cdeb40

Browse files
Borislav PetkovBorislav Petkov
authored andcommitted
EDAC, MCE: Rework MCE injection
Add sysfs injection facilities for testing of the MCE decoding code. Remove large parts of amd64_edac_dbg.c, as a result, which did only NB MCE injection anyway and the new injection code supports that functionality already. Add an injection module so that MCE decoding code in production kernels like those in RHEL and SLES can be tested. Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
1 parent 30e1f7a commit 9cdeb40

7 files changed

Lines changed: 203 additions & 207 deletions

File tree

‎drivers/edac/Kconfig‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ config EDAC_DEBUG
3939
there're four debug levels (x=0,1,2,3 from low to high).
4040
Usually you should select 'N'.
4141

42-
config EDAC_DECODE_MCE
42+
config EDAC_DECODE_MCE
4343
tristate "Decode MCEs in human-readable form (only on AMD for now)"
4444
depends on CPU_SUP_AMD && X86_MCE
4545
default y
@@ -51,6 +51,16 @@ config EDAC_DEBUG
5151
which occur really early upon boot, before the module infrastructure
5252
has been initialized.
5353

54+
config EDAC_MCE_INJ
55+
tristate "Simple MCE injection interface over /sysfs"
56+
depends on EDAC_DECODE_MCE
57+
default n
58+
help
59+
This is a simple interface to inject MCEs over /sysfs and test
60+
the MCE decoding code in EDAC.
61+
62+
This is currently AMD-only.
63+
5464
config EDAC_MM_EDAC
5565
tristate "Main Memory EDAC (Error Detection And Correction) reporting"
5666
help
@@ -72,7 +82,7 @@ config EDAC_AMD64
7282
Families of Memory Controllers (K8, F10h and F11h)
7383

7484
config EDAC_AMD64_ERROR_INJECTION
75-
bool "Sysfs Error Injection facilities"
85+
bool "Sysfs HW Error injection facilities"
7686
depends on EDAC_AMD64
7787
help
7888
Recent Opterons (Family 10h and later) provide for Memory Error

‎drivers/edac/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ ifdef CONFIG_PCI
1717
edac_core-objs += edac_pci.o edac_pci_sysfs.o
1818
endif
1919

20+
obj-$(CONFIG_EDAC_MCE_INJ) += mce_amd_inj.o
21+
2022
obj-$(CONFIG_EDAC_DECODE_MCE) += edac_mce_amd.o
2123

2224
obj-$(CONFIG_EDAC_AMD76X) += amd76x_edac.o

‎drivers/edac/amd64_edac.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ extern const char *ext_msgs[32];
486486
extern const char *htlink_msgs[8];
487487

488488
#ifdef CONFIG_EDAC_DEBUG
489-
#define NUM_DBG_ATTRS 9
489+
#define NUM_DBG_ATTRS 5
490490
#else
491491
#define NUM_DBG_ATTRS 0
492492
#endif

‎drivers/edac/amd64_edac_dbg.c‎

Lines changed: 12 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,16 @@
11
#include "amd64_edac.h"
22

3-
/*
4-
* accept a hex value and store it into the virtual error register file, field:
5-
* nbeal and nbeah. Assume virtual error values have already been set for: NBSL,
6-
* NBSH and NBCFG. Then proceed to map the error values to a MC, CSROW and
7-
* CHANNEL
8-
*/
9-
static ssize_t amd64_nbea_store(struct mem_ctl_info *mci, const char *data,
10-
size_t count)
11-
{
12-
struct amd64_pvt *pvt = mci->pvt_info;
13-
u64 value;
14-
int ret = 0;
15-
struct mce m;
16-
17-
ret = strict_strtoull(data, 16, &value);
18-
if (ret != -EINVAL) {
19-
struct err_regs *regs = &pvt->ctl_error_info;
20-
21-
debugf0("received NBEA= 0x%llx\n", value);
22-
23-
/* place the value into the virtual error packet */
24-
pvt->ctl_error_info.nbeal = (u32) value;
25-
value >>= 32;
26-
pvt->ctl_error_info.nbeah = (u32) value;
27-
28-
m.addr = value;
29-
m.status = regs->nbsl | ((u64)regs->nbsh << 32);
30-
31-
/* Process the Mapping request */
32-
/* TODO: Add race prevention */
33-
amd_decode_nb_mce(pvt->mc_node_id, &m, regs->nbcfg);
34-
35-
return count;
36-
}
37-
return ret;
3+
#define EDAC_DCT_ATTR_SHOW(reg) \
4+
static ssize_t amd64_##reg##_show(struct mem_ctl_info *mci, char *data) \
5+
{ \
6+
struct amd64_pvt *pvt = mci->pvt_info; \
7+
return sprintf(data, "0x%016llx\n", (u64)pvt->reg); \
388
}
399

40-
/* display back what the last NBEA (MCA NB Address (MC4_ADDR)) was written */
41-
static ssize_t amd64_nbea_show(struct mem_ctl_info *mci, char *data)
42-
{
43-
struct amd64_pvt *pvt = mci->pvt_info;
44-
u64 value;
45-
46-
value = pvt->ctl_error_info.nbeah;
47-
value <<= 32;
48-
value |= pvt->ctl_error_info.nbeal;
49-
50-
return sprintf(data, "%llx\n", value);
51-
}
52-
53-
/* store the NBSL (MCA NB Status Low (MC4_STATUS)) value user desires */
54-
static ssize_t amd64_nbsl_store(struct mem_ctl_info *mci, const char *data,
55-
size_t count)
56-
{
57-
struct amd64_pvt *pvt = mci->pvt_info;
58-
unsigned long value;
59-
int ret = 0;
60-
61-
ret = strict_strtoul(data, 16, &value);
62-
if (ret != -EINVAL) {
63-
debugf0("received NBSL= 0x%lx\n", value);
64-
65-
pvt->ctl_error_info.nbsl = (u32) value;
66-
67-
return count;
68-
}
69-
return ret;
70-
}
71-
72-
/* display back what the last NBSL value written */
73-
static ssize_t amd64_nbsl_show(struct mem_ctl_info *mci, char *data)
74-
{
75-
struct amd64_pvt *pvt = mci->pvt_info;
76-
u32 value;
77-
78-
value = pvt->ctl_error_info.nbsl;
79-
80-
return sprintf(data, "%x\n", value);
81-
}
82-
83-
/* store the NBSH (MCA NB Status High) value user desires */
84-
static ssize_t amd64_nbsh_store(struct mem_ctl_info *mci, const char *data,
85-
size_t count)
86-
{
87-
struct amd64_pvt *pvt = mci->pvt_info;
88-
unsigned long value;
89-
int ret = 0;
90-
91-
ret = strict_strtoul(data, 16, &value);
92-
if (ret != -EINVAL) {
93-
debugf0("received NBSH= 0x%lx\n", value);
94-
95-
pvt->ctl_error_info.nbsh = (u32) value;
96-
97-
return count;
98-
}
99-
return ret;
100-
}
101-
102-
/* display back what the last NBSH value written */
103-
static ssize_t amd64_nbsh_show(struct mem_ctl_info *mci, char *data)
104-
{
105-
struct amd64_pvt *pvt = mci->pvt_info;
106-
u32 value;
107-
108-
value = pvt->ctl_error_info.nbsh;
109-
110-
return sprintf(data, "%x\n", value);
111-
}
112-
113-
/* accept and store the NBCFG (MCA NB Configuration) value user desires */
114-
static ssize_t amd64_nbcfg_store(struct mem_ctl_info *mci,
115-
const char *data, size_t count)
116-
{
117-
struct amd64_pvt *pvt = mci->pvt_info;
118-
unsigned long value;
119-
int ret = 0;
120-
121-
ret = strict_strtoul(data, 16, &value);
122-
if (ret != -EINVAL) {
123-
debugf0("received NBCFG= 0x%lx\n", value);
124-
125-
pvt->ctl_error_info.nbcfg = (u32) value;
126-
127-
return count;
128-
}
129-
return ret;
130-
}
131-
132-
/* various show routines for the controls of a MCI */
133-
static ssize_t amd64_nbcfg_show(struct mem_ctl_info *mci, char *data)
134-
{
135-
struct amd64_pvt *pvt = mci->pvt_info;
136-
137-
return sprintf(data, "%x\n", pvt->ctl_error_info.nbcfg);
138-
}
139-
140-
141-
static ssize_t amd64_dhar_show(struct mem_ctl_info *mci, char *data)
142-
{
143-
struct amd64_pvt *pvt = mci->pvt_info;
144-
145-
return sprintf(data, "%x\n", pvt->dhar);
146-
}
147-
148-
149-
static ssize_t amd64_dbam_show(struct mem_ctl_info *mci, char *data)
150-
{
151-
struct amd64_pvt *pvt = mci->pvt_info;
152-
153-
return sprintf(data, "%x\n", pvt->dbam0);
154-
}
155-
156-
157-
static ssize_t amd64_topmem_show(struct mem_ctl_info *mci, char *data)
158-
{
159-
struct amd64_pvt *pvt = mci->pvt_info;
160-
161-
return sprintf(data, "%llx\n", pvt->top_mem);
162-
}
163-
164-
165-
static ssize_t amd64_topmem2_show(struct mem_ctl_info *mci, char *data)
166-
{
167-
struct amd64_pvt *pvt = mci->pvt_info;
168-
169-
return sprintf(data, "%llx\n", pvt->top_mem2);
170-
}
10+
EDAC_DCT_ATTR_SHOW(dhar);
11+
EDAC_DCT_ATTR_SHOW(dbam0);
12+
EDAC_DCT_ATTR_SHOW(top_mem);
13+
EDAC_DCT_ATTR_SHOW(top_mem2);
17114

17215
static ssize_t amd64_hole_show(struct mem_ctl_info *mci, char *data)
17316
{
@@ -186,38 +29,6 @@ static ssize_t amd64_hole_show(struct mem_ctl_info *mci, char *data)
18629
*/
18730
struct mcidev_sysfs_attribute amd64_dbg_attrs[] = {
18831

189-
{
190-
.attr = {
191-
.name = "nbea_ctl",
192-
.mode = (S_IRUGO | S_IWUSR)
193-
},
194-
.show = amd64_nbea_show,
195-
.store = amd64_nbea_store,
196-
},
197-
{
198-
.attr = {
199-
.name = "nbsl_ctl",
200-
.mode = (S_IRUGO | S_IWUSR)
201-
},
202-
.show = amd64_nbsl_show,
203-
.store = amd64_nbsl_store,
204-
},
205-
{
206-
.attr = {
207-
.name = "nbsh_ctl",
208-
.mode = (S_IRUGO | S_IWUSR)
209-
},
210-
.show = amd64_nbsh_show,
211-
.store = amd64_nbsh_store,
212-
},
213-
{
214-
.attr = {
215-
.name = "nbcfg_ctl",
216-
.mode = (S_IRUGO | S_IWUSR)
217-
},
218-
.show = amd64_nbcfg_show,
219-
.store = amd64_nbcfg_store,
220-
},
22132
{
22233
.attr = {
22334
.name = "dhar",
@@ -231,23 +42,23 @@ struct mcidev_sysfs_attribute amd64_dbg_attrs[] = {
23142
.name = "dbam",
23243
.mode = (S_IRUGO)
23344
},
234-
.show = amd64_dbam_show,
45+
.show = amd64_dbam0_show,
23546
.store = NULL,
23647
},
23748
{
23849
.attr = {
23950
.name = "topmem",
24051
.mode = (S_IRUGO)
24152
},
242-
.show = amd64_topmem_show,
53+
.show = amd64_top_mem_show,
24354
.store = NULL,
24455
},
24556
{
24657
.attr = {
24758
.name = "topmem2",
24859
.mode = (S_IRUGO)
24960
},
250-
.show = amd64_topmem2_show,
61+
.show = amd64_top_mem2_show,
25162
.store = NULL,
25263
},
25364
{

‎drivers/edac/edac_mce_amd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,7 @@ static inline void amd_decode_err_code(u16 ec)
324324
pr_emerg(HW_ERR "Huh? Unknown MCE error 0x%x\n", ec);
325325
}
326326

327-
static int amd_decode_mce(struct notifier_block *nb, unsigned long val,
328-
void *data)
327+
int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
329328
{
330329
struct mce *m = (struct mce *)data;
331330
int node, ecc;
@@ -379,6 +378,7 @@ static int amd_decode_mce(struct notifier_block *nb, unsigned long val,
379378

380379
return NOTIFY_STOP;
381380
}
381+
EXPORT_SYMBOL_GPL(amd_decode_mce);
382382

383383
static struct notifier_block amd_mce_dec_nb = {
384384
.notifier_call = amd_decode_mce,

‎drivers/edac/edac_mce_amd.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _EDAC_MCE_AMD_H
22
#define _EDAC_MCE_AMD_H
33

4+
#include <linux/notifier.h>
5+
46
#include <asm/mce.h>
57

68
#define ERROR_CODE(x) ((x) & 0xffff)
@@ -61,10 +63,10 @@ struct err_regs {
6163
u32 nbeal;
6264
};
6365

64-
6566
void amd_report_gart_errors(bool);
6667
void amd_register_ecc_decoder(void (*f)(int, struct mce *, u32));
6768
void amd_unregister_ecc_decoder(void (*f)(int, struct mce *, u32));
6869
void amd_decode_nb_mce(int, struct mce *, u32);
70+
int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data);
6971

7072
#endif /* _EDAC_MCE_AMD_H */

0 commit comments

Comments
 (0)