Skip to content

Commit 65f55a3

Browse files
committed
x86/CPU/AMD: Add CPUID faulting support
Add CPUID faulting support on AMD using the same user interface. Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/[email protected]
1 parent e04c78d commit 65f55a3

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,12 @@
457457
#define X86_FEATURE_WRMSR_XX_BASE_NS (20*32+ 1) /* WRMSR to {FS,GS,KERNEL_GS}_BASE is non-serializing */
458458
#define X86_FEATURE_LFENCE_RDTSC (20*32+ 2) /* LFENCE always serializing / synchronizes RDTSC */
459459
#define X86_FEATURE_NULL_SEL_CLR_BASE (20*32+ 6) /* Null Selector Clears Base */
460+
460461
#define X86_FEATURE_AUTOIBRS (20*32+ 8) /* Automatic IBRS */
461462
#define X86_FEATURE_NO_SMM_CTL_MSR (20*32+ 9) /* SMM_CTL MSR is not present */
462463

464+
#define X86_FEATURE_GP_ON_USER_CPUID (20*32+17) /* User CPUID faulting */
465+
463466
#define X86_FEATURE_PREFETCHI (20*32+20) /* Prefetch Data/Instruction to Cache Level */
464467
#define X86_FEATURE_SBPB (20*32+27) /* Selective Branch Prediction Barrier */
465468
#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
@@ -830,6 +830,7 @@
830830
#define MSR_K7_HWCR_SMMLOCK BIT_ULL(MSR_K7_HWCR_SMMLOCK_BIT)
831831
#define MSR_K7_HWCR_IRPERF_EN_BIT 30
832832
#define MSR_K7_HWCR_IRPERF_EN BIT_ULL(MSR_K7_HWCR_IRPERF_EN_BIT)
833+
#define MSR_K7_HWCR_CPUID_USER_DIS_BIT 35
833834
#define MSR_K7_FID_VID_CTL 0xc0010041
834835
#define MSR_K7_FID_VID_STATUS 0xc0010042
835836
#define MSR_K7_HWCR_CPB_DIS_BIT 25

arch/x86/kernel/cpu/amd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
489489
}
490490

491491
bsp_determine_snp(c);
492+
493+
if (cpu_has(c, X86_FEATURE_GP_ON_USER_CPUID))
494+
setup_force_cpu_cap(X86_FEATURE_CPUID_FAULT);
495+
492496
return;
493497

494498
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)