Skip to content

Commit 0dcab41

Browse files
aeglsuryasaimadhu
authored andcommitted
x86/cpu: Merge Intel and AMD ppin_init() functions
The code to decide whether a system supports the PPIN (Protected Processor Inventory Number) MSR was cloned from the Intel implementation. Apart from the X86_FEATURE bit and the MSR numbers it is identical. Merge the two functions into common x86 code, but use x86_match_cpu() instead of the switch (c->x86_model) that was used by the old Intel code. No functional change. Signed-off-by: Tony Luck <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7f99cb5 commit 0dcab41

File tree

3 files changed

+74
-72
lines changed

3 files changed

+74
-72
lines changed

arch/x86/kernel/cpu/amd.c

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

397-
static void amd_detect_ppin(struct cpuinfo_x86 *c)
398-
{
399-
unsigned long long val;
400-
401-
if (!cpu_has(c, X86_FEATURE_AMD_PPIN))
402-
return;
403-
404-
/* When PPIN is defined in CPUID, still need to check PPIN_CTL MSR */
405-
if (rdmsrl_safe(MSR_AMD_PPIN_CTL, &val))
406-
goto clear_ppin;
407-
408-
/* PPIN is locked in disabled mode, clear feature bit */
409-
if ((val & 3UL) == 1UL)
410-
goto clear_ppin;
411-
412-
/* If PPIN is disabled, try to enable it */
413-
if (!(val & 2UL)) {
414-
wrmsrl_safe(MSR_AMD_PPIN_CTL, val | 2UL);
415-
rdmsrl_safe(MSR_AMD_PPIN_CTL, &val);
416-
}
417-
418-
/* If PPIN_EN bit is 1, return from here; otherwise fall through */
419-
if (val & 2UL)
420-
return;
421-
422-
clear_ppin:
423-
clear_cpu_cap(c, X86_FEATURE_AMD_PPIN);
424-
}
425-
426397
u32 amd_get_nodes_per_socket(void)
427398
{
428399
return nodes_per_socket;
@@ -947,7 +918,6 @@ static void init_amd(struct cpuinfo_x86 *c)
947918
amd_detect_cmp(c);
948919
amd_get_topology(c);
949920
srat_detect_node(c);
950-
amd_detect_ppin(c);
951921

952922
init_amd_cacheinfo(c);
953923

arch/x86/kernel/cpu/common.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,78 @@ EXPORT_SYMBOL_GPL(get_llc_id);
8888
/* L2 cache ID of each logical CPU */
8989
DEFINE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id) = BAD_APICID;
9090

91+
static struct ppin_info {
92+
int feature;
93+
int msr_ppin_ctl;
94+
} ppin_info[] = {
95+
[X86_VENDOR_INTEL] = {
96+
.feature = X86_FEATURE_INTEL_PPIN,
97+
.msr_ppin_ctl = MSR_PPIN_CTL,
98+
},
99+
[X86_VENDOR_AMD] = {
100+
.feature = X86_FEATURE_AMD_PPIN,
101+
.msr_ppin_ctl = MSR_AMD_PPIN_CTL,
102+
},
103+
};
104+
105+
static const struct x86_cpu_id ppin_cpuids[] = {
106+
X86_MATCH_FEATURE(X86_FEATURE_AMD_PPIN, &ppin_info[X86_VENDOR_AMD]),
107+
108+
/* Legacy models without CPUID enumeration */
109+
X86_MATCH_INTEL_FAM6_MODEL(IVYBRIDGE_X, &ppin_info[X86_VENDOR_INTEL]),
110+
X86_MATCH_INTEL_FAM6_MODEL(HASWELL_X, &ppin_info[X86_VENDOR_INTEL]),
111+
X86_MATCH_INTEL_FAM6_MODEL(BROADWELL_D, &ppin_info[X86_VENDOR_INTEL]),
112+
X86_MATCH_INTEL_FAM6_MODEL(BROADWELL_X, &ppin_info[X86_VENDOR_INTEL]),
113+
X86_MATCH_INTEL_FAM6_MODEL(SKYLAKE_X, &ppin_info[X86_VENDOR_INTEL]),
114+
X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, &ppin_info[X86_VENDOR_INTEL]),
115+
X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, &ppin_info[X86_VENDOR_INTEL]),
116+
X86_MATCH_INTEL_FAM6_MODEL(SAPPHIRERAPIDS_X, &ppin_info[X86_VENDOR_INTEL]),
117+
X86_MATCH_INTEL_FAM6_MODEL(XEON_PHI_KNL, &ppin_info[X86_VENDOR_INTEL]),
118+
X86_MATCH_INTEL_FAM6_MODEL(XEON_PHI_KNM, &ppin_info[X86_VENDOR_INTEL]),
119+
120+
{}
121+
};
122+
123+
static void ppin_init(struct cpuinfo_x86 *c)
124+
{
125+
const struct x86_cpu_id *id;
126+
unsigned long long val;
127+
struct ppin_info *info;
128+
129+
id = x86_match_cpu(ppin_cpuids);
130+
if (!id)
131+
return;
132+
133+
/*
134+
* Testing the presence of the MSR is not enough. Need to check
135+
* that the PPIN_CTL allows reading of the PPIN.
136+
*/
137+
info = (struct ppin_info *)id->driver_data;
138+
139+
if (rdmsrl_safe(info->msr_ppin_ctl, &val))
140+
goto clear_ppin;
141+
142+
if ((val & 3UL) == 1UL) {
143+
/* PPIN locked in disabled mode */
144+
goto clear_ppin;
145+
}
146+
147+
/* If PPIN is disabled, try to enable */
148+
if (!(val & 2UL)) {
149+
wrmsrl_safe(info->msr_ppin_ctl, val | 2UL);
150+
rdmsrl_safe(info->msr_ppin_ctl, &val);
151+
}
152+
153+
/* Is the enable bit set? */
154+
if (val & 2UL) {
155+
set_cpu_cap(c, info->feature);
156+
return;
157+
}
158+
159+
clear_ppin:
160+
clear_cpu_cap(c, info->feature);
161+
}
162+
91163
/* correctly size the local cpu masks */
92164
void __init setup_cpu_local_masks(void)
93165
{
@@ -1655,6 +1727,8 @@ static void identify_cpu(struct cpuinfo_x86 *c)
16551727
c->x86_capability[i] |= boot_cpu_data.x86_capability[i];
16561728
}
16571729

1730+
ppin_init(c);
1731+
16581732
/* Init Machine Check Exception if available. */
16591733
mcheck_cpu_init(c);
16601734

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

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -470,47 +470,6 @@ void intel_clear_lmce(void)
470470
wrmsrl(MSR_IA32_MCG_EXT_CTL, val);
471471
}
472472

473-
static void intel_ppin_init(struct cpuinfo_x86 *c)
474-
{
475-
unsigned long long val;
476-
477-
/*
478-
* Even if testing the presence of the MSR would be enough, we don't
479-
* want to risk the situation where other models reuse this MSR for
480-
* other purposes.
481-
*/
482-
switch (c->x86_model) {
483-
case INTEL_FAM6_IVYBRIDGE_X:
484-
case INTEL_FAM6_HASWELL_X:
485-
case INTEL_FAM6_BROADWELL_D:
486-
case INTEL_FAM6_BROADWELL_X:
487-
case INTEL_FAM6_SKYLAKE_X:
488-
case INTEL_FAM6_ICELAKE_X:
489-
case INTEL_FAM6_ICELAKE_D:
490-
case INTEL_FAM6_SAPPHIRERAPIDS_X:
491-
case INTEL_FAM6_XEON_PHI_KNL:
492-
case INTEL_FAM6_XEON_PHI_KNM:
493-
494-
if (rdmsrl_safe(MSR_PPIN_CTL, &val))
495-
return;
496-
497-
if ((val & 3UL) == 1UL) {
498-
/* PPIN locked in disabled mode */
499-
return;
500-
}
501-
502-
/* If PPIN is disabled, try to enable */
503-
if (!(val & 2UL)) {
504-
wrmsrl_safe(MSR_PPIN_CTL, val | 2UL);
505-
rdmsrl_safe(MSR_PPIN_CTL, &val);
506-
}
507-
508-
/* Is the enable bit set? */
509-
if (val & 2UL)
510-
set_cpu_cap(c, X86_FEATURE_INTEL_PPIN);
511-
}
512-
}
513-
514473
/*
515474
* Enable additional error logs from the integrated
516475
* memory controller on processors that support this.
@@ -535,7 +494,6 @@ void mce_intel_feature_init(struct cpuinfo_x86 *c)
535494
{
536495
intel_init_cmci();
537496
intel_init_lmce();
538-
intel_ppin_init(c);
539497
intel_imc_init(c);
540498
}
541499

0 commit comments

Comments
 (0)