Skip to content

Commit 077168e

Browse files
weihuang-amdsuryasaimadhu
authored andcommitted
x86/mce/amd: Add PPIN support for AMD MCE
Newer AMD CPUs support a feature called protected processor identification number (PPIN). This feature can be detected via CPUID_Fn80000008_EBX[23]. However, CPUID alone is not enough to read the processor identification number - MSR_AMD_PPIN_CTL also needs to be configured properly. If, for any reason, MSR_AMD_PPIN_CTL[PPIN_EN] can not be turned on, such as disabled in BIOS, the CPU capability bit X86_FEATURE_AMD_PPIN needs to be cleared. When the X86_FEATURE_AMD_PPIN capability is available, the identification number is issued together with the MCE error info in order to keep track of the source of MCE errors. [ bp: Massage. ] Co-developed-by: Smita Koralahalli Channabasappa <[email protected]> Signed-off-by: Smita Koralahalli Channabasappa <[email protected]> Signed-off-by: Wei Huang <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Tony Luck <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent d8ecca4 commit 077168e

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
#define X86_FEATURE_AMD_IBRS (13*32+14) /* "" Indirect Branch Restricted Speculation */
300300
#define X86_FEATURE_AMD_STIBP (13*32+15) /* "" Single Thread Indirect Branch Predictors */
301301
#define X86_FEATURE_AMD_STIBP_ALWAYS_ON (13*32+17) /* "" Single Thread Indirect Branch Predictors always-on preferred */
302+
#define X86_FEATURE_AMD_PPIN (13*32+23) /* Protected Processor Inventory Number */
302303
#define X86_FEATURE_AMD_SSBD (13*32+24) /* "" Speculative Store Bypass Disable */
303304
#define X86_FEATURE_VIRT_SSBD (13*32+25) /* Virtualized Speculative Store Bypass Disable */
304305
#define X86_FEATURE_AMD_SSB_NO (13*32+26) /* "" Speculative Store Bypass is fixed in hardware. */

arch/x86/kernel/cpu/amd.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,35 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c)
393393
per_cpu(cpu_llc_id, cpu) = c->phys_proc_id;
394394
}
395395

396+
static void amd_detect_ppin(struct cpuinfo_x86 *c)
397+
{
398+
unsigned long long val;
399+
400+
if (!cpu_has(c, X86_FEATURE_AMD_PPIN))
401+
return;
402+
403+
/* When PPIN is defined in CPUID, still need to check PPIN_CTL MSR */
404+
if (rdmsrl_safe(MSR_AMD_PPIN_CTL, &val))
405+
goto clear_ppin;
406+
407+
/* PPIN is locked in disabled mode, clear feature bit */
408+
if ((val & 3UL) == 1UL)
409+
goto clear_ppin;
410+
411+
/* If PPIN is disabled, try to enable it */
412+
if (!(val & 2UL)) {
413+
wrmsrl_safe(MSR_AMD_PPIN_CTL, val | 2UL);
414+
rdmsrl_safe(MSR_AMD_PPIN_CTL, &val);
415+
}
416+
417+
/* If PPIN_EN bit is 1, return from here; otherwise fall through */
418+
if (val & 2UL)
419+
return;
420+
421+
clear_ppin:
422+
clear_cpu_cap(c, X86_FEATURE_AMD_PPIN);
423+
}
424+
396425
u16 amd_get_nb_id(int cpu)
397426
{
398427
return per_cpu(cpu_llc_id, cpu);
@@ -940,6 +969,7 @@ static void init_amd(struct cpuinfo_x86 *c)
940969
amd_detect_cmp(c);
941970
amd_get_topology(c);
942971
srat_detect_node(c);
972+
amd_detect_ppin(c);
943973

944974
init_amd_cacheinfo(c);
945975

arch/x86/kernel/cpu/mce/core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ void mce_setup(struct mce *m)
142142

143143
if (this_cpu_has(X86_FEATURE_INTEL_PPIN))
144144
rdmsrl(MSR_PPIN, m->ppin);
145+
else if (this_cpu_has(X86_FEATURE_AMD_PPIN))
146+
rdmsrl(MSR_AMD_PPIN, m->ppin);
145147

146148
m->microcode = boot_cpu_data.microcode;
147149
}

0 commit comments

Comments
 (0)