Skip to content

Commit e606d81

Browse files
committed
Merge branch 'ras-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull RAS updates from Ingo Molnar: "The main changes were: - Lots of enhancements for AMD SMCA (Scalable MCA features/extensions) systems: extract, decode and print more hardware error information and add matching support on the injection/testing side as well. (Yazn Ghannam) - Various MCE handling improvements on modern Intel Xeons. (Tony Luck) - Plus misc fixes and enhancements" * 'ras-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (21 commits) x86/RAS/mce_amd_inj: Remove debugfs dir recursively on exit x86/RAS/mce_amd_inj: Fix signed wrap around when decrementing index 'i' x86/RAS/mce_amd_inj: Fix some W= warnings x86/MCE/AMD, EDAC: Handle reserved bank 4 on Fam17h properly x86/mce/AMD: Extract the error address on SMCA systems x86/mce, EDAC/mce_amd: Print MCA_SYND and MCA_IPID during MCE on SMCA systems x86/mce/AMD: Save MCA_IPID in MCE struct on SMCA systems x86/mce/AMD: Ensure the deferred error interrupt is of type APIC on SMCA systems x86/mce/AMD: Update sysfs bank names for SMCA systems x86/mce/AMD, EDAC/mce_amd: Define and use tables for known SMCA IP types EDAC/mce_amd: Use SMCA prefix for error descriptions arrays EDAC/mce_amd: Add missing SMCA error descriptions x86/mce/AMD: Read MSRs on the CPU allocating the threshold blocks x86/RAS: Add syndrome support to mce_amd_inj EDAC/mce_amd: Print syndrome register value on SMCA systems x86/mce: Add support for new MCA_SYND register x86/mce/AMD: Use msr_ops.misc() in allocate_threshold_blocks() x86/mce: Drop X86_FEATURE_MCE_RECOVERY and the related model string test x86/mce: Improve memcpy_mcsafe() x86/mce: Add PCI quirks to identify Xeons with machine check recovery ...
2 parents 12b7bcb + b199ac6 commit e606d81

14 files changed

Lines changed: 407 additions & 286 deletions

File tree

‎arch/x86/include/asm/cpufeatures.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
#define X86_FEATURE_APERFMPERF ( 3*32+28) /* APERFMPERF */
107107
#define X86_FEATURE_EAGER_FPU ( 3*32+29) /* "eagerfpu" Non lazy FPU restore */
108108
#define X86_FEATURE_NONSTOP_TSC_S3 ( 3*32+30) /* TSC doesn't stop in S3 state */
109-
#define X86_FEATURE_MCE_RECOVERY ( 3*32+31) /* cpu has recoverable machine checks */
110109

111110
/* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
112111
#define X86_FEATURE_XMM3 ( 4*32+ 0) /* "pni" SSE-3 */

‎arch/x86/include/asm/mce.h‎

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
#define MCI_STATUS_AR (1ULL<<55) /* Action required */
4141

4242
/* AMD-specific bits */
43+
#define MCI_STATUS_TCC (1ULL<<55) /* Task context corrupt */
44+
#define MCI_STATUS_SYNDV (1ULL<<53) /* synd reg. valid */
4345
#define MCI_STATUS_DEFERRED (1ULL<<44) /* uncorrected error, deferred exception */
4446
#define MCI_STATUS_POISON (1ULL<<43) /* access poisonous data */
45-
#define MCI_STATUS_TCC (1ULL<<55) /* Task context corrupt */
4647

4748
/*
4849
* McaX field if set indicates a given bank supports MCA extensions:
@@ -110,6 +111,7 @@
110111
#define MSR_AMD64_SMCA_MC0_MISC0 0xc0002003
111112
#define MSR_AMD64_SMCA_MC0_CONFIG 0xc0002004
112113
#define MSR_AMD64_SMCA_MC0_IPID 0xc0002005
114+
#define MSR_AMD64_SMCA_MC0_SYND 0xc0002006
113115
#define MSR_AMD64_SMCA_MC0_DESTAT 0xc0002008
114116
#define MSR_AMD64_SMCA_MC0_DEADDR 0xc0002009
115117
#define MSR_AMD64_SMCA_MC0_MISC1 0xc000200a
@@ -119,6 +121,7 @@
119121
#define MSR_AMD64_SMCA_MCx_MISC(x) (MSR_AMD64_SMCA_MC0_MISC0 + 0x10*(x))
120122
#define MSR_AMD64_SMCA_MCx_CONFIG(x) (MSR_AMD64_SMCA_MC0_CONFIG + 0x10*(x))
121123
#define MSR_AMD64_SMCA_MCx_IPID(x) (MSR_AMD64_SMCA_MC0_IPID + 0x10*(x))
124+
#define MSR_AMD64_SMCA_MCx_SYND(x) (MSR_AMD64_SMCA_MC0_SYND + 0x10*(x))
122125
#define MSR_AMD64_SMCA_MCx_DESTAT(x) (MSR_AMD64_SMCA_MC0_DESTAT + 0x10*(x))
123126
#define MSR_AMD64_SMCA_MCx_DEADDR(x) (MSR_AMD64_SMCA_MC0_DEADDR + 0x10*(x))
124127
#define MSR_AMD64_SMCA_MCx_MISCy(x, y) ((MSR_AMD64_SMCA_MC0_MISC1 + y) + (0x10*(x)))
@@ -334,44 +337,47 @@ extern void apei_mce_report_mem_error(int corrected,
334337
* Scalable MCA.
335338
*/
336339
#ifdef CONFIG_X86_MCE_AMD
337-
enum amd_ip_types {
338-
SMCA_F17H_CORE = 0, /* Core errors */
339-
SMCA_DF, /* Data Fabric */
340-
SMCA_UMC, /* Unified Memory Controller */
341-
SMCA_PB, /* Parameter Block */
342-
SMCA_PSP, /* Platform Security Processor */
343-
SMCA_SMU, /* System Management Unit */
344-
N_AMD_IP_TYPES
345-
};
346-
347-
struct amd_hwid {
348-
const char *name;
349-
unsigned int hwid;
350-
};
351-
352-
extern struct amd_hwid amd_hwids[N_AMD_IP_TYPES];
353340

354-
enum amd_core_mca_blocks {
341+
/* These may be used by multiple smca_hwid_mcatypes */
342+
enum smca_bank_types {
355343
SMCA_LS = 0, /* Load Store */
356344
SMCA_IF, /* Instruction Fetch */
357-
SMCA_L2_CACHE, /* L2 cache */
358-
SMCA_DE, /* Decoder unit */
359-
RES, /* Reserved */
360-
SMCA_EX, /* Execution unit */
345+
SMCA_L2_CACHE, /* L2 Cache */
346+
SMCA_DE, /* Decoder Unit */
347+
SMCA_EX, /* Execution Unit */
361348
SMCA_FP, /* Floating Point */
362-
SMCA_L3_CACHE, /* L3 cache */
363-
N_CORE_MCA_BLOCKS
349+
SMCA_L3_CACHE, /* L3 Cache */
350+
SMCA_CS, /* Coherent Slave */
351+
SMCA_PIE, /* Power, Interrupts, etc. */
352+
SMCA_UMC, /* Unified Memory Controller */
353+
SMCA_PB, /* Parameter Block */
354+
SMCA_PSP, /* Platform Security Processor */
355+
SMCA_SMU, /* System Management Unit */
356+
N_SMCA_BANK_TYPES
364357
};
365358

366-
extern const char * const amd_core_mcablock_names[N_CORE_MCA_BLOCKS];
359+
struct smca_bank_name {
360+
const char *name; /* Short name for sysfs */
361+
const char *long_name; /* Long name for pretty-printing */
362+
};
363+
364+
extern struct smca_bank_name smca_bank_names[N_SMCA_BANK_TYPES];
365+
366+
#define HWID_MCATYPE(hwid, mcatype) ((hwid << 16) | mcatype)
367367

368-
enum amd_df_mca_blocks {
369-
SMCA_CS = 0, /* Coherent Slave */
370-
SMCA_PIE, /* Power management, Interrupts, etc */
371-
N_DF_BLOCKS
368+
struct smca_hwid_mcatype {
369+
unsigned int bank_type; /* Use with smca_bank_types for easy indexing. */
370+
u32 hwid_mcatype; /* (hwid,mcatype) tuple */
371+
u32 xec_bitmap; /* Bitmap of valid ExtErrorCodes; current max is 21. */
372372
};
373373

374-
extern const char * const amd_df_mcablock_names[N_DF_BLOCKS];
374+
struct smca_bank_info {
375+
struct smca_hwid_mcatype *type;
376+
u32 type_instance;
377+
};
378+
379+
extern struct smca_bank_info smca_banks[MAX_NR_BANKS];
380+
375381
#endif
376382

377383
#endif /* _ASM_X86_MCE_H */

‎arch/x86/include/asm/pmem.h‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ static inline void arch_memcpy_to_pmem(void *dst, const void *src, size_t n)
4646

4747
static inline int arch_memcpy_from_pmem(void *dst, const void *src, size_t n)
4848
{
49-
if (static_cpu_has(X86_FEATURE_MCE_RECOVERY))
50-
return memcpy_mcsafe(dst, src, n);
51-
memcpy(dst, src, n);
52-
return 0;
49+
return memcpy_mcsafe(dst, src, n);
5350
}
5451

5552
/**

‎arch/x86/include/asm/string_64.h‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define _ASM_X86_STRING_64_H
33

44
#ifdef __KERNEL__
5+
#include <linux/jump_label.h>
56

67
/* Written 2002 by Andi Kleen */
78

@@ -78,6 +79,9 @@ int strcmp(const char *cs, const char *ct);
7879
#define memset(s, c, n) __memset(s, c, n)
7980
#endif
8081

82+
__must_check int memcpy_mcsafe_unrolled(void *dst, const void *src, size_t cnt);
83+
DECLARE_STATIC_KEY_FALSE(mcsafe_key);
84+
8185
/**
8286
* memcpy_mcsafe - copy memory with indication if a machine check happened
8387
*
@@ -86,10 +90,23 @@ int strcmp(const char *cs, const char *ct);
8690
* @cnt: number of bytes to copy
8791
*
8892
* Low level memory copy function that catches machine checks
93+
* We only call into the "safe" function on systems that can
94+
* actually do machine check recovery. Everyone else can just
95+
* use memcpy().
8996
*
9097
* Return 0 for success, -EFAULT for fail
9198
*/
92-
int memcpy_mcsafe(void *dst, const void *src, size_t cnt);
99+
static __always_inline __must_check int
100+
memcpy_mcsafe(void *dst, const void *src, size_t cnt)
101+
{
102+
#ifdef CONFIG_X86_MCE
103+
if (static_branch_unlikely(&mcsafe_key))
104+
return memcpy_mcsafe_unrolled(dst, src, cnt);
105+
else
106+
#endif
107+
memcpy(dst, src, cnt);
108+
return 0;
109+
}
93110

94111
#endif /* __KERNEL__ */
95112

‎arch/x86/include/uapi/asm/mce.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ struct mce {
2626
__u32 socketid; /* CPU socket ID */
2727
__u32 apicid; /* CPU initial apic ID */
2828
__u64 mcgcap; /* MCGCAP MSR: machine check capabilities of CPU */
29+
__u64 synd; /* MCA_SYND MSR: only valid on SMCA systems */
30+
__u64 ipid; /* MCA_IPID MSR: only valid on SMCA systems */
2931
};
3032

3133
#define MCE_GET_RECORD_LEN _IOR('M', 1, int)

‎arch/x86/kernel/cpu/mcheck/mce.c‎

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/debugfs.h>
4242
#include <linux/irq_work.h>
4343
#include <linux/export.h>
44+
#include <linux/jump_label.h>
4445

4546
#include <asm/processor.h>
4647
#include <asm/traps.h>
@@ -292,6 +293,13 @@ static void print_mce(struct mce *m)
292293
if (m->misc)
293294
pr_cont("MISC %llx ", m->misc);
294295

296+
if (mce_flags.smca) {
297+
if (m->synd)
298+
pr_cont("SYND %llx ", m->synd);
299+
if (m->ipid)
300+
pr_cont("IPID %llx ", m->ipid);
301+
}
302+
295303
pr_cont("\n");
296304
/*
297305
* Note this output is parsed by external tools and old fields
@@ -568,6 +576,7 @@ static void mce_read_aux(struct mce *m, int i)
568576
{
569577
if (m->status & MCI_STATUS_MISCV)
570578
m->misc = mce_rdmsrl(msr_ops.misc(i));
579+
571580
if (m->status & MCI_STATUS_ADDRV) {
572581
m->addr = mce_rdmsrl(msr_ops.addr(i));
573582

@@ -579,6 +588,23 @@ static void mce_read_aux(struct mce *m, int i)
579588
m->addr >>= shift;
580589
m->addr <<= shift;
581590
}
591+
592+
/*
593+
* Extract [55:<lsb>] where lsb is the least significant
594+
* *valid* bit of the address bits.
595+
*/
596+
if (mce_flags.smca) {
597+
u8 lsb = (m->addr >> 56) & 0x3f;
598+
599+
m->addr &= GENMASK_ULL(55, lsb);
600+
}
601+
}
602+
603+
if (mce_flags.smca) {
604+
m->ipid = mce_rdmsrl(MSR_AMD64_SMCA_MCx_IPID(i));
605+
606+
if (m->status & MCI_STATUS_SYNDV)
607+
m->synd = mce_rdmsrl(MSR_AMD64_SMCA_MCx_SYND(i));
582608
}
583609
}
584610

@@ -1633,17 +1659,6 @@ static int __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
16331659

16341660
if (c->x86 == 6 && c->x86_model == 45)
16351661
quirk_no_way_out = quirk_sandybridge_ifu;
1636-
/*
1637-
* MCG_CAP.MCG_SER_P is necessary but not sufficient to know
1638-
* whether this processor will actually generate recoverable
1639-
* machine checks. Check to see if this is an E7 model Xeon.
1640-
* We can't do a model number check because E5 and E7 use the
1641-
* same model number. E5 doesn't support recovery, E7 does.
1642-
*/
1643-
if (mca_cfg.recovery || (mca_cfg.ser &&
1644-
!strncmp(c->x86_model_id,
1645-
"Intel(R) Xeon(R) CPU E7-", 24)))
1646-
set_cpu_cap(c, X86_FEATURE_MCE_RECOVERY);
16471662
}
16481663
if (cfg->monarch_timeout < 0)
16491664
cfg->monarch_timeout = 0;
@@ -2080,6 +2095,7 @@ void mce_disable_bank(int bank)
20802095
* mce=bootlog Log MCEs from before booting. Disabled by default on AMD.
20812096
* mce=nobootlog Don't log MCEs from before booting.
20822097
* mce=bios_cmci_threshold Don't program the CMCI threshold
2098+
* mce=recovery force enable memcpy_mcsafe()
20832099
*/
20842100
static int __init mcheck_enable(char *str)
20852101
{
@@ -2676,8 +2692,14 @@ static int __init mcheck_debugfs_init(void)
26762692
static int __init mcheck_debugfs_init(void) { return -EINVAL; }
26772693
#endif
26782694

2695+
DEFINE_STATIC_KEY_FALSE(mcsafe_key);
2696+
EXPORT_SYMBOL_GPL(mcsafe_key);
2697+
26792698
static int __init mcheck_late_init(void)
26802699
{
2700+
if (mca_cfg.recovery)
2701+
static_branch_inc(&mcsafe_key);
2702+
26812703
mcheck_debugfs_init();
26822704

26832705
/*

0 commit comments

Comments
 (0)