Skip to content

Commit 4dd39dd

Browse files
committed
Merge tag 'x86-cpu-2025-07-29' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 cpu update from Ingo Molnar: "Add user-space CPUID faulting support for AMD CPUs" * tag 'x86-cpu-2025-07-29' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/CPU/AMD: Add CPUID faulting support
2 parents 1645f6a + 5bf2f51 commit 4dd39dd

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,12 @@
458458
#define X86_FEATURE_LFENCE_RDTSC (20*32+ 2) /* LFENCE always serializing / synchronizes RDTSC */
459459
#define X86_FEATURE_VERW_CLEAR (20*32+ 5) /* The memory form of VERW mitigates TSA */
460460
#define X86_FEATURE_NULL_SEL_CLR_BASE (20*32+ 6) /* Null Selector Clears Base */
461+
461462
#define X86_FEATURE_AUTOIBRS (20*32+ 8) /* Automatic IBRS */
462463
#define X86_FEATURE_NO_SMM_CTL_MSR (20*32+ 9) /* SMM_CTL MSR is not present */
463464

465+
#define X86_FEATURE_GP_ON_USER_CPUID (20*32+17) /* User CPUID faulting */
466+
464467
#define X86_FEATURE_PREFETCHI (20*32+20) /* Prefetch Data/Instruction to Cache Level */
465468
#define X86_FEATURE_SBPB (20*32+27) /* Selective Branch Prediction Barrier */
466469
#define X86_FEATURE_IBPB_BRTYPE (20*32+28) /* MSR_PRED_CMD[IBPB] flushes all branch type predictions */

arch/x86/include/asm/msr-index.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@
831831
#define MSR_K7_HWCR_SMMLOCK BIT_ULL(MSR_K7_HWCR_SMMLOCK_BIT)
832832
#define MSR_K7_HWCR_IRPERF_EN_BIT 30
833833
#define MSR_K7_HWCR_IRPERF_EN BIT_ULL(MSR_K7_HWCR_IRPERF_EN_BIT)
834+
#define MSR_K7_HWCR_CPUID_USER_DIS_BIT 35
834835
#define MSR_K7_FID_VID_CTL 0xc0010041
835836
#define MSR_K7_FID_VID_STATUS 0xc0010042
836837
#define MSR_K7_HWCR_CPB_DIS_BIT 25

arch/x86/kernel/cpu/amd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,11 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
530530
}
531531

532532
bsp_determine_snp(c);
533-
534533
tsa_init(c);
535534

535+
if (cpu_has(c, X86_FEATURE_GP_ON_USER_CPUID))
536+
setup_force_cpu_cap(X86_FEATURE_CPUID_FAULT);
537+
536538
return;
537539

538540
warn:

arch/x86/kernel/process.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,21 @@ DEFINE_PER_CPU(u64, msr_misc_features_shadow);
334334

335335
static void set_cpuid_faulting(bool on)
336336
{
337-
u64 msrval;
338337

339-
msrval = this_cpu_read(msr_misc_features_shadow);
340-
msrval &= ~MSR_MISC_FEATURES_ENABLES_CPUID_FAULT;
341-
msrval |= (on << MSR_MISC_FEATURES_ENABLES_CPUID_FAULT_BIT);
342-
this_cpu_write(msr_misc_features_shadow, msrval);
343-
wrmsrq(MSR_MISC_FEATURES_ENABLES, msrval);
338+
if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) {
339+
u64 msrval;
340+
341+
msrval = this_cpu_read(msr_misc_features_shadow);
342+
msrval &= ~MSR_MISC_FEATURES_ENABLES_CPUID_FAULT;
343+
msrval |= (on << MSR_MISC_FEATURES_ENABLES_CPUID_FAULT_BIT);
344+
this_cpu_write(msr_misc_features_shadow, msrval);
345+
wrmsrq(MSR_MISC_FEATURES_ENABLES, msrval);
346+
} else if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
347+
if (on)
348+
msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_CPUID_USER_DIS_BIT);
349+
else
350+
msr_clear_bit(MSR_K7_HWCR, MSR_K7_HWCR_CPUID_USER_DIS_BIT);
351+
}
344352
}
345353

346354
static void disable_cpuid(void)

0 commit comments

Comments
 (0)