x86/CPU/AMD: Add CPUID faulting support
PATCH 1/1 x86/CPU/AMD: Add CPUID faulting support
From: "Borislav Petkov (AMD)" <[email protected]>
Add CPUID faulting support on AMD using the same user interface.
Signed-off-by Borislav Petkov (AMD) <[email protected]>
--- arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/amd.c | 4 ++++ arch/x86/kernel/process.c | 20 ++++++++++++++------ 4 files changed, 21 insertions(+), 6 deletions(-)
arch/x86/include/asm/cpufeatures.h +2 -0
@@ -457,6 +457,8 @@#define X86_FEATURE_AUTOIBRS (20*32+ 8)/* Automatic IBRS */ #define X86_FEATURE_NO_SMM_CTL_MSR (20*32+ 9)/* SMM_CTL MSR is not present */ +#define X86_FEATURE_GP_ON_USER_CPUID (20*32+17)/* User CPUID faulting */ +#define X86_FEATURE_SBPB (20*32+27)/* Selective Branch Prediction Barrier */ #define X86_FEATURE_IBPB_BRTYPE (20*32+28)/* MSR_PRED_CMD[IBPB] flushes all branch type predictions */ #define X86_FEATURE_SRSO_NO (20*32+29)/* CPU is not affected by SRSO */
arch/x86/include/asm/msr-index.h +1 -0
@@ -830,6 +830,7 @@#define MSR_K7_HWCR_SMMLOCK BIT_ULL(MSR_K7_HWCR_SMMLOCK_BIT)#define MSR_K7_HWCR_IRPERF_EN_BIT 30#define MSR_K7_HWCR_IRPERF_EN BIT_ULL(MSR_K7_HWCR_IRPERF_EN_BIT) +#define MSR_K7_HWCR_CPUID_USER_DIS_BIT 35#define MSR_K7_FID_VID_CTL 0xc0010041#define MSR_K7_FID_VID_STATUS 0xc0010042#define MSR_K7_HWCR_CPB_DIS_BIT 25
arch/x86/kernel/cpu/amd.c +4 -0
@@ -489,6 +489,10 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) }bsp_determine_snp (c); + +if (cpu_has (c,X86_FEATURE_GP_ON_USER_CPUID )) +setup_force_cpu_cap (X86_FEATURE_CPUID_FAULT ); +return ; warn:
arch/x86/kernel/process.c +14 -6
@@ -333,13 +333,21 @@ DEFINE_PER_CPU(u64, msr_misc_features_shadow);static void set_cpuid_faulting (bool on) { -u64 msrval; - msrval =this_cpu_read (msr_misc_features_shadow); - msrval &= ~MSR_MISC_FEATURES_ENABLES_CPUID_FAULT ; - msrval |= (on <<MSR_MISC_FEATURES_ENABLES_CPUID_FAULT_BIT ); -this_cpu_write (msr_misc_features_shadow, msrval); -wrmsrq (MSR_MISC_FEATURES_ENABLES , msrval); +if (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) { +u64 msrval; + + msrval =this_cpu_read (msr_misc_features_shadow); + msrval &= ~MSR_MISC_FEATURES_ENABLES_CPUID_FAULT ; + msrval |= (on <<MSR_MISC_FEATURES_ENABLES_CPUID_FAULT_BIT ); +this_cpu_write (msr_misc_features_shadow, msrval); +wrmsrq (MSR_MISC_FEATURES_ENABLES , msrval); + }else if (boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) { +if (on) +msr_set_bit (MSR_K7_HWCR ,MSR_K7_HWCR_CPUID_USER_DIS_BIT ); +else +msr_clear_bit (MSR_K7_HWCR ,MSR_K7_HWCR_CPUID_USER_DIS_BIT ); + } }static void disable_cpuid (void )
Signature · 1 line
2.43.0
Quoted 5 lines · Borislav Petkov
From: "Borislav Petkov (AMD)" <[email protected]>
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]>
The following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 65f55a30176662ee37fe18b47430ee30b57bfc98 Gitweb: https://git.kernel.org/tip/65f55a30176662ee37fe18b47430ee30b57bfc98 Author: Borislav Petkov (AMD) <[email protected]> AuthorDate: Wed, 28 May 2025 23:31:05 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Sat, 21 Jun 2025 20:30:26 +02:00
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]>
--- arch/x86/include/asm/cpufeatures.h | 3 +++ arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/amd.c | 4 ++++ arch/x86/kernel/process.c | 20 ++++++++++++++------ 4 files changed, 22 insertions(+), 6 deletions(-)
arch/x86/include/asm/cpufeatures.h +3 -0
@@ -457,9 +457,12 @@#define X86_FEATURE_WRMSR_XX_BASE_NS (20*32+ 1)/* WRMSR to {FS,GS,KERNEL_GS}_BASE is non-serializing */ #define X86_FEATURE_LFENCE_RDTSC (20*32+ 2)/* LFENCE always serializing / synchronizes RDTSC */ #define X86_FEATURE_NULL_SEL_CLR_BASE (20*32+ 6)/* Null Selector Clears Base */ +#define X86_FEATURE_AUTOIBRS (20*32+ 8)/* Automatic IBRS */ #define X86_FEATURE_NO_SMM_CTL_MSR (20*32+ 9)/* SMM_CTL MSR is not present */ +#define X86_FEATURE_GP_ON_USER_CPUID (20*32+17)/* User CPUID faulting */ +#define X86_FEATURE_PREFETCHI (20*32+20)/* Prefetch Data/Instruction to Cache Level */ #define X86_FEATURE_SBPB (20*32+27)/* Selective Branch Prediction Barrier */ #define X86_FEATURE_IBPB_BRTYPE (20*32+28)/* MSR_PRED_CMD[IBPB] flushes all branch type predictions */
arch/x86/include/asm/msr-index.h +1 -0
@@ -830,6 +830,7 @@#define MSR_K7_HWCR_SMMLOCK BIT_ULL(MSR_K7_HWCR_SMMLOCK_BIT)#define MSR_K7_HWCR_IRPERF_EN_BIT 30#define MSR_K7_HWCR_IRPERF_EN BIT_ULL(MSR_K7_HWCR_IRPERF_EN_BIT) +#define MSR_K7_HWCR_CPUID_USER_DIS_BIT 35#define MSR_K7_FID_VID_CTL 0xc0010041#define MSR_K7_FID_VID_STATUS 0xc0010042#define MSR_K7_HWCR_CPB_DIS_BIT 25
arch/x86/kernel/cpu/amd.c +4 -0
@@ -489,6 +489,10 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) }bsp_determine_snp (c); + +if (cpu_has (c,X86_FEATURE_GP_ON_USER_CPUID )) +setup_force_cpu_cap (X86_FEATURE_CPUID_FAULT ); +return ; warn:
arch/x86/kernel/process.c +14 -6
@@ -334,13 +334,21 @@ DEFINE_PER_CPU(u64, msr_misc_features_shadow);static void set_cpuid_faulting (bool on) { -u64 msrval; - msrval =this_cpu_read (msr_misc_features_shadow); - msrval &= ~MSR_MISC_FEATURES_ENABLES_CPUID_FAULT ; - msrval |= (on <<MSR_MISC_FEATURES_ENABLES_CPUID_FAULT_BIT ); -this_cpu_write (msr_misc_features_shadow, msrval); -wrmsrq (MSR_MISC_FEATURES_ENABLES , msrval); +if (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) { +u64 msrval; + + msrval =this_cpu_read (msr_misc_features_shadow); + msrval &= ~MSR_MISC_FEATURES_ENABLES_CPUID_FAULT ; + msrval |= (on <<MSR_MISC_FEATURES_ENABLES_CPUID_FAULT_BIT ); +this_cpu_write (msr_misc_features_shadow, msrval); +wrmsrq (MSR_MISC_FEATURES_ENABLES , msrval); + }else if (boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) { +if (on) +msr_set_bit (MSR_K7_HWCR ,MSR_K7_HWCR_CPUID_USER_DIS_BIT ); +else +msr_clear_bit (MSR_K7_HWCR ,MSR_K7_HWCR_CPUID_USER_DIS_BIT ); + } }static void disable_cpuid (void )