Skip to content

Commit 48795f9

Browse files
committed
Merge tag 'x86_cpu_for_v6.14_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 cpuid updates from Borislav Petkov: - Remove the less generic CPU matching infra around struct x86_cpu_desc and use the generic struct x86_cpu_id thing - Remove magic naked numbers for CPUID functions and use proper defines of the prefix CPUID_LEAF_*. Consolidate some of the crazy use around the tree - Smaller cleanups and improvements * tag 'x86_cpu_for_v6.14_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/cpu: Make all all CPUID leaf names consistent x86/fpu: Remove unnecessary CPUID level check x86/fpu: Move CPUID leaf definitions to common code x86/tsc: Remove CPUID "frequency" leaf magic numbers. x86/tsc: Move away from TSC leaf magic numbers x86/cpu: Move TSC CPUID leaf definition x86/cpu: Refresh DCA leaf reading code x86/cpu: Remove unnecessary MwAIT leaf checks x86/cpu: Use MWAIT leaf definition x86/cpu: Move MWAIT leaf definition to common header x86/cpu: Remove 'x86_cpu_desc' infrastructure x86/cpu: Move AMD erratum 1386 table over to 'x86_cpu_id' x86/cpu: Replace PEBS use of 'x86_cpu_desc' use with 'x86_cpu_id' x86/cpu: Expose only stepping min/max interface x86/cpu: Introduce new microcode matching helper x86/cpufeature: Document cpu_feature_enabled() as the default to use x86/paravirt: Remove the WBINVD callback x86/cpufeatures: Free up unused feature bits
2 parents 13b6931 + e5d3a57 commit 48795f9

File tree

33 files changed

+179
-278
lines changed

33 files changed

+179
-278
lines changed

arch/x86/events/intel/core.c

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5381,42 +5381,32 @@ static __init void intel_clovertown_quirk(void)
53815381
x86_pmu.pebs_constraints = NULL;
53825382
}
53835383

5384-
static const struct x86_cpu_desc isolation_ucodes[] = {
5385-
INTEL_CPU_DESC(INTEL_HASWELL, 3, 0x0000001f),
5386-
INTEL_CPU_DESC(INTEL_HASWELL_L, 1, 0x0000001e),
5387-
INTEL_CPU_DESC(INTEL_HASWELL_G, 1, 0x00000015),
5388-
INTEL_CPU_DESC(INTEL_HASWELL_X, 2, 0x00000037),
5389-
INTEL_CPU_DESC(INTEL_HASWELL_X, 4, 0x0000000a),
5390-
INTEL_CPU_DESC(INTEL_BROADWELL, 4, 0x00000023),
5391-
INTEL_CPU_DESC(INTEL_BROADWELL_G, 1, 0x00000014),
5392-
INTEL_CPU_DESC(INTEL_BROADWELL_D, 2, 0x00000010),
5393-
INTEL_CPU_DESC(INTEL_BROADWELL_D, 3, 0x07000009),
5394-
INTEL_CPU_DESC(INTEL_BROADWELL_D, 4, 0x0f000009),
5395-
INTEL_CPU_DESC(INTEL_BROADWELL_D, 5, 0x0e000002),
5396-
INTEL_CPU_DESC(INTEL_BROADWELL_X, 1, 0x0b000014),
5397-
INTEL_CPU_DESC(INTEL_SKYLAKE_X, 3, 0x00000021),
5398-
INTEL_CPU_DESC(INTEL_SKYLAKE_X, 4, 0x00000000),
5399-
INTEL_CPU_DESC(INTEL_SKYLAKE_X, 5, 0x00000000),
5400-
INTEL_CPU_DESC(INTEL_SKYLAKE_X, 6, 0x00000000),
5401-
INTEL_CPU_DESC(INTEL_SKYLAKE_X, 7, 0x00000000),
5402-
INTEL_CPU_DESC(INTEL_SKYLAKE_X, 11, 0x00000000),
5403-
INTEL_CPU_DESC(INTEL_SKYLAKE_L, 3, 0x0000007c),
5404-
INTEL_CPU_DESC(INTEL_SKYLAKE, 3, 0x0000007c),
5405-
INTEL_CPU_DESC(INTEL_KABYLAKE, 9, 0x0000004e),
5406-
INTEL_CPU_DESC(INTEL_KABYLAKE_L, 9, 0x0000004e),
5407-
INTEL_CPU_DESC(INTEL_KABYLAKE_L, 10, 0x0000004e),
5408-
INTEL_CPU_DESC(INTEL_KABYLAKE_L, 11, 0x0000004e),
5409-
INTEL_CPU_DESC(INTEL_KABYLAKE_L, 12, 0x0000004e),
5410-
INTEL_CPU_DESC(INTEL_KABYLAKE, 10, 0x0000004e),
5411-
INTEL_CPU_DESC(INTEL_KABYLAKE, 11, 0x0000004e),
5412-
INTEL_CPU_DESC(INTEL_KABYLAKE, 12, 0x0000004e),
5413-
INTEL_CPU_DESC(INTEL_KABYLAKE, 13, 0x0000004e),
5384+
static const struct x86_cpu_id isolation_ucodes[] = {
5385+
X86_MATCH_VFM_STEPS(INTEL_HASWELL, 3, 3, 0x0000001f),
5386+
X86_MATCH_VFM_STEPS(INTEL_HASWELL_L, 1, 1, 0x0000001e),
5387+
X86_MATCH_VFM_STEPS(INTEL_HASWELL_G, 1, 1, 0x00000015),
5388+
X86_MATCH_VFM_STEPS(INTEL_HASWELL_X, 2, 2, 0x00000037),
5389+
X86_MATCH_VFM_STEPS(INTEL_HASWELL_X, 4, 4, 0x0000000a),
5390+
X86_MATCH_VFM_STEPS(INTEL_BROADWELL, 4, 4, 0x00000023),
5391+
X86_MATCH_VFM_STEPS(INTEL_BROADWELL_G, 1, 1, 0x00000014),
5392+
X86_MATCH_VFM_STEPS(INTEL_BROADWELL_D, 2, 2, 0x00000010),
5393+
X86_MATCH_VFM_STEPS(INTEL_BROADWELL_D, 3, 3, 0x07000009),
5394+
X86_MATCH_VFM_STEPS(INTEL_BROADWELL_D, 4, 4, 0x0f000009),
5395+
X86_MATCH_VFM_STEPS(INTEL_BROADWELL_D, 5, 5, 0x0e000002),
5396+
X86_MATCH_VFM_STEPS(INTEL_BROADWELL_X, 1, 1, 0x0b000014),
5397+
X86_MATCH_VFM_STEPS(INTEL_SKYLAKE_X, 3, 3, 0x00000021),
5398+
X86_MATCH_VFM_STEPS(INTEL_SKYLAKE_X, 4, 7, 0x00000000),
5399+
X86_MATCH_VFM_STEPS(INTEL_SKYLAKE_X, 11, 11, 0x00000000),
5400+
X86_MATCH_VFM_STEPS(INTEL_SKYLAKE_L, 3, 3, 0x0000007c),
5401+
X86_MATCH_VFM_STEPS(INTEL_SKYLAKE, 3, 3, 0x0000007c),
5402+
X86_MATCH_VFM_STEPS(INTEL_KABYLAKE, 9, 13, 0x0000004e),
5403+
X86_MATCH_VFM_STEPS(INTEL_KABYLAKE_L, 9, 12, 0x0000004e),
54145404
{}
54155405
};
54165406

54175407
static void intel_check_pebs_isolation(void)
54185408
{
5419-
x86_pmu.pebs_no_isolation = !x86_cpu_has_min_microcode_rev(isolation_ucodes);
5409+
x86_pmu.pebs_no_isolation = !x86_match_min_microcode_rev(isolation_ucodes);
54205410
}
54215411

54225412
static __init void intel_pebs_isolation_quirk(void)
@@ -5426,16 +5416,16 @@ static __init void intel_pebs_isolation_quirk(void)
54265416
intel_check_pebs_isolation();
54275417
}
54285418

5429-
static const struct x86_cpu_desc pebs_ucodes[] = {
5430-
INTEL_CPU_DESC(INTEL_SANDYBRIDGE, 7, 0x00000028),
5431-
INTEL_CPU_DESC(INTEL_SANDYBRIDGE_X, 6, 0x00000618),
5432-
INTEL_CPU_DESC(INTEL_SANDYBRIDGE_X, 7, 0x0000070c),
5419+
static const struct x86_cpu_id pebs_ucodes[] = {
5420+
X86_MATCH_VFM_STEPS(INTEL_SANDYBRIDGE, 7, 7, 0x00000028),
5421+
X86_MATCH_VFM_STEPS(INTEL_SANDYBRIDGE_X, 6, 6, 0x00000618),
5422+
X86_MATCH_VFM_STEPS(INTEL_SANDYBRIDGE_X, 7, 7, 0x0000070c),
54335423
{}
54345424
};
54355425

54365426
static bool intel_snb_pebs_broken(void)
54375427
{
5438-
return !x86_cpu_has_min_microcode_rev(pebs_ucodes);
5428+
return !x86_match_min_microcode_rev(pebs_ucodes);
54395429
}
54405430

54415431
static void intel_snb_check_microcode(void)

arch/x86/events/intel/pt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/slab.h>
1919
#include <linux/device.h>
2020

21+
#include <asm/cpuid.h>
2122
#include <asm/perf_event.h>
2223
#include <asm/insn.h>
2324
#include <asm/io.h>
@@ -201,10 +202,10 @@ static int __init pt_pmu_hw_init(void)
201202
* otherwise, zero for numerator stands for "not enumerated"
202203
* as per SDM
203204
*/
204-
if (boot_cpu_data.cpuid_level >= CPUID_TSC_LEAF) {
205+
if (boot_cpu_data.cpuid_level >= CPUID_LEAF_TSC) {
205206
u32 eax, ebx, ecx, edx;
206207

207-
cpuid(CPUID_TSC_LEAF, &eax, &ebx, &ecx, &edx);
208+
cpuid(CPUID_LEAF_TSC, &eax, &ebx, &ecx, &edx);
208209

209210
pt_pmu.tsc_art_num = ebx;
210211
pt_pmu.tsc_art_den = eax;

arch/x86/events/intel/pt.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ struct topa_entry {
3737
u64 rsvd4 : 12;
3838
};
3939

40-
/* TSC to Core Crystal Clock Ratio */
41-
#define CPUID_TSC_LEAF 0x15
42-
4340
struct pt_pmu {
4441
struct pmu pmu;
4542
u32 caps[PT_CPUID_REGS_NUM * PT_CPUID_LEAVES];

arch/x86/include/asm/cpu_device_id.h

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
/* x86_cpu_id::flags */
5757
#define X86_CPU_ID_FLAG_ENTRY_VALID BIT(0)
5858

59-
#define X86_STEPPINGS(mins, maxs) GENMASK(maxs, mins)
6059
/**
6160
* X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE - Base macro for CPU matching
6261
* @_vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
@@ -208,6 +207,7 @@
208207
VFM_MODEL(vfm), \
209208
X86_STEPPING_ANY, X86_FEATURE_ANY, data)
210209

210+
#define __X86_STEPPINGS(mins, maxs) GENMASK(maxs, mins)
211211
/**
212212
* X86_MATCH_VFM_STEPPINGS - Match encoded vendor/family/model/stepping
213213
* @vfm: Encoded 8-bits each for vendor, family, model
@@ -218,12 +218,13 @@
218218
*
219219
* feature is set to wildcard
220220
*/
221-
#define X86_MATCH_VFM_STEPPINGS(vfm, steppings, data) \
222-
X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE( \
223-
VFM_VENDOR(vfm), \
224-
VFM_FAMILY(vfm), \
225-
VFM_MODEL(vfm), \
226-
steppings, X86_FEATURE_ANY, data)
221+
#define X86_MATCH_VFM_STEPS(vfm, min_step, max_step, data) \
222+
X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE( \
223+
VFM_VENDOR(vfm), \
224+
VFM_FAMILY(vfm), \
225+
VFM_MODEL(vfm), \
226+
__X86_STEPPINGS(min_step, max_step), \
227+
X86_FEATURE_ANY, data)
227228

228229
/**
229230
* X86_MATCH_VFM_FEATURE - Match encoded vendor/family/model/feature
@@ -242,41 +243,7 @@
242243
VFM_MODEL(vfm), \
243244
X86_STEPPING_ANY, feature, data)
244245

245-
/*
246-
* Match specific microcode revisions.
247-
*
248-
* vendor/family/model/stepping must be all set.
249-
*
250-
* Only checks against the boot CPU. When mixed-stepping configs are
251-
* valid for a CPU model, add a quirk for every valid stepping and
252-
* do the fine-tuning in the quirk handler.
253-
*/
254-
255-
struct x86_cpu_desc {
256-
u8 x86_family;
257-
u8 x86_vendor;
258-
u8 x86_model;
259-
u8 x86_stepping;
260-
u32 x86_microcode_rev;
261-
};
262-
263-
#define INTEL_CPU_DESC(vfm, stepping, revision) { \
264-
.x86_family = VFM_FAMILY(vfm), \
265-
.x86_vendor = VFM_VENDOR(vfm), \
266-
.x86_model = VFM_MODEL(vfm), \
267-
.x86_stepping = (stepping), \
268-
.x86_microcode_rev = (revision), \
269-
}
270-
271-
#define AMD_CPU_DESC(fam, model, stepping, revision) { \
272-
.x86_family = (fam), \
273-
.x86_vendor = X86_VENDOR_AMD, \
274-
.x86_model = (model), \
275-
.x86_stepping = (stepping), \
276-
.x86_microcode_rev = (revision), \
277-
}
278-
279246
extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
280-
extern bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table);
247+
extern bool x86_match_min_microcode_rev(const struct x86_cpu_id *table);
281248

282249
#endif /* _ASM_X86_CPU_DEVICE_ID */

arch/x86/include/asm/cpufeature.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,12 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
132132
x86_this_cpu_test_bit(bit, cpu_info.x86_capability))
133133

134134
/*
135-
* This macro is for detection of features which need kernel
136-
* infrastructure to be used. It may *not* directly test the CPU
137-
* itself. Use the cpu_has() family if you want true runtime
138-
* testing of CPU features, like in hypervisor code where you are
139-
* supporting a possible guest feature where host support for it
135+
* This is the default CPU features testing macro to use in code.
136+
*
137+
* It is for detection of features which need kernel infrastructure to be
138+
* used. It may *not* directly test the CPU itself. Use the cpu_has() family
139+
* if you want true runtime testing of CPU features, like in hypervisor code
140+
* where you are supporting a possible guest feature where host support for it
140141
* is not relevant.
141142
*/
142143
#define cpu_feature_enabled(bit) \
@@ -161,13 +162,6 @@ extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
161162
#define setup_force_cpu_bug(bit) setup_force_cpu_cap(bit)
162163

163164
/*
164-
* Static testing of CPU features. Used the same as boot_cpu_has(). It
165-
* statically patches the target code for additional performance. Use
166-
* static_cpu_has() only in fast paths, where every cycle counts. Which
167-
* means that the boot_cpu_has() variant is already fast enough for the
168-
* majority of cases and you should stick to using it as it is generally
169-
* only two instructions: a RIP-relative MOV and a TEST.
170-
*
171165
* Do not use an "m" constraint for [cap_byte] here: gcc doesn't know
172166
* that this is only used on a fallback path and will sometimes cause
173167
* it to manifest the address of boot_cpu_data in a register, fouling

arch/x86/include/asm/cpufeatures.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
#define X86_FEATURE_CENTAUR_MCR ( 3*32+ 3) /* "centaur_mcr" Centaur MCRs (= MTRRs) */
8484
#define X86_FEATURE_K8 ( 3*32+ 4) /* Opteron, Athlon64 */
8585
#define X86_FEATURE_ZEN5 ( 3*32+ 5) /* CPU based on Zen5 microarchitecture */
86-
#define X86_FEATURE_P3 ( 3*32+ 6) /* P3 */
87-
#define X86_FEATURE_P4 ( 3*32+ 7) /* P4 */
86+
/* Free ( 3*32+ 6) */
87+
/* Free ( 3*32+ 7) */
8888
#define X86_FEATURE_CONSTANT_TSC ( 3*32+ 8) /* "constant_tsc" TSC ticks at a constant rate */
8989
#define X86_FEATURE_UP ( 3*32+ 9) /* "up" SMP kernel running on UP */
9090
#define X86_FEATURE_ART ( 3*32+10) /* "art" Always running timer (ART) */

arch/x86/include/asm/cpuid.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ enum cpuid_regs_idx {
2121
CPUID_EDX,
2222
};
2323

24+
#define CPUID_LEAF_MWAIT 0x5
25+
#define CPUID_LEAF_DCA 0x9
26+
#define CPUID_LEAF_XSTATE 0x0d
27+
#define CPUID_LEAF_TSC 0x15
28+
#define CPUID_LEAF_FREQ 0x16
29+
#define CPUID_LEAF_TILE 0x1d
30+
2431
#ifdef CONFIG_X86_32
2532
bool have_cpuid_p(void);
2633
#else

arch/x86/include/asm/fpu/xstate.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
/* Bit 63 of XCR0 is reserved for future expansion */
1313
#define XFEATURE_MASK_EXTEND (~(XFEATURE_MASK_FPSSE | (1ULL << 63)))
1414

15-
#define XSTATE_CPUID 0x0000000d
16-
17-
#define TILE_CPUID 0x0000001d
18-
1915
#define FXSAVE_SIZE 512
2016

2117
#define XSAVE_HDR_SIZE 64

arch/x86/include/asm/mwait.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#define MWAIT_HINT2SUBSTATE(hint) ((hint) & MWAIT_CSTATE_MASK)
1616
#define MWAIT_C1_SUBSTATE_MASK 0xf0
1717

18-
#define CPUID_MWAIT_LEAF 5
1918
#define CPUID5_ECX_EXTENSIONS_SUPPORTED 0x1
2019
#define CPUID5_ECX_INTERRUPT_BREAK 0x2
2120

arch/x86/include/asm/paravirt.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,6 @@ static inline void halt(void)
180180
PVOP_VCALL0(irq.halt);
181181
}
182182

183-
extern noinstr void pv_native_wbinvd(void);
184-
185-
static __always_inline void wbinvd(void)
186-
{
187-
PVOP_ALT_VCALL0(cpu.wbinvd, "wbinvd", ALT_NOT_XEN);
188-
}
189-
190183
static inline u64 paravirt_read_msr(unsigned msr)
191184
{
192185
return PVOP_CALL1(u64, cpu.read_msr, msr);

0 commit comments

Comments
 (0)