KVM: VMX: Handle the immediate form of MSR instructions
v2 cover KVM: VMX: Handle the immediate form of MSR instructions
This patch set handles two newly introduced VM exit reasons associated with the immediate form of MSR instructions to ensure proper virtualization of these instructions.
The immediate form of MSR access instructions are primarily motivated by performance, not code size: by having the MSR number in an immediate, it is available *much* earlier in the pipeline, which allows the hardware much more leeway about how a particular MSR is handled.
For proper virtualization of the immediate form of MSR instructions, Intel VMX architecture adds the following changes:
1) The immediate form of RDMSR uses VM exit reason 84.
2) The immediate form of WRMSRNS uses VM exit reason 85.
3) For both VM exit reasons 84 and 85, the exit qualification is set to the MSR address causing the VM exit.
4) Bits 3 ~ 6 of the VM exit instruction information field represent the operand register used in the immediate form of MSR instruction.
5) The VM-exit instruction length field records the size of the immediate form of the MSR instruction.
Note: The VMX specification for the immediate form of MSR instructions was inadvertently omitted from the last published ISE, but it will be included in the upcoming edition.
Linux bare metal support of the immediate form of MSR instructions is still under development; however, the KVM support effort is proceeding independently of the bare metal implementation.
Link to v1:
https://lore.kernel.org/lkml/[email protected]/
Changes in v2:
*) Added nested MSR bitmap check for the two new MSR-related VM exit
reasons (Chao).
*) Shortened function names that still convey enough information
(Chao & Sean).
*) Removed VCPU_EXREG_EDX_EAX as it unnecessarily exposes details of a
specific flow across KVM (Sean).
*) Implemented a separate userspace completion callback for the
immediate form RDMSR (Sean).
*) Passed MSR data directly to __kvm_emulate_wrmsr() instead of the
encoded general-purpose register containing it (Sean).
*) Merged modifications to x86.c and vmx.c within the same patch to
facilitate easier code review (Sean).
*) Moved fastpath support in a separate patch, i.e., patch 3 (Sean). *) Cleared the immediate form MSR capability in SVM in patch 4 (Sean).
Xin Li (Intel) (4):
x86/cpufeatures: Add a CPU feature bit for MSR immediate form
instructions
KVM: VMX: Handle the immediate form of MSR instructions
KVM: VMX: Support the immediate form WRMSRNS in fastpath
KVM: x86: Advertise support for the immediate form of MSR instructions
arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/kvm_host.h | 4 ++ arch/x86/include/uapi/asm/vmx.h | 6 +- arch/x86/kernel/cpu/scattered.c | 1 + arch/x86/kvm/cpuid.c | 6 +- arch/x86/kvm/reverse_cpuid.h | 5 ++ arch/x86/kvm/svm/svm.c | 8 ++- arch/x86/kvm/vmx/nested.c | 13 ++++- arch/x86/kvm/vmx/vmx.c | 26 ++++++++- arch/x86/kvm/vmx/vmx.h | 5 ++ arch/x86/kvm/x86.c | 92 ++++++++++++++++++++++-------- arch/x86/kvm/x86.h | 3 +- 12 files changed, 139 insertions(+), 31 deletions(-)
base-commit: 33f843444e28920d6e624c6c24637b4bb5d3c8de
Signature · 1 line
2.50.1
PATCH v2 1/4 x86/cpufeatures: Add a CPU feature bit for MSR immediate form instructions
The immediate form of MSR access instructions are primarily motivated by performance, not code size: by having the MSR number in an immediate, it is available *much* earlier in the pipeline, which allows the hardware much more leeway about how a particular MSR is handled.
Use a scattered CPU feature bit for MSR immediate form instructions.
--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -491,6 +491,7 @@#define X86_FEATURE_TSA_SQ_NO (21*32+11)/* AMD CPU not vulnerable to TSA-SQ */ #define X86_FEATURE_TSA_L1_NO (21*32+12)/* AMD CPU not vulnerable to TSA-L1 */ #define X86_FEATURE_CLEAR_CPU_BUF_VM (21*32+13)/* Clear CPU buffers using VERW before VMRUN */ +#define X86_FEATURE_MSR_IMM (21*32+14)/* MSR immediate form instructions */ /* * BUG word(s)
arch/x86/kernel/cpu/scattered.c +1 -0
@@ -27,6 +27,7 @@ static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_APERFMPERF, CPUID_ECX, 0, 0x00000006, 0 }, { X86_FEATURE_EPB, CPUID_ECX, 3, 0x00000006, 0 }, { X86_FEATURE_INTEL_PPIN, CPUID_EBX, 0, 0x00000007, 1 }, + { X86_FEATURE_MSR_IMM, CPUID_ECX, 5, 0x00000007, 1 }, { X86_FEATURE_APX, CPUID_EDX, 21, 0x00000007, 1 }, { X86_FEATURE_RRSBA_CTRL, CPUID_EDX, 2, 0x00000007, 2 }, { X86_FEATURE_BHI_CTRL, CPUID_EDX, 4, 0x00000007, 2 },
Signature · 1 line
2.50.1
PATCH v2 2/4 KVM: VMX: Handle the immediate form of MSR instructions
In reply to Xin Li (Intel)Handle two newly introduced VM exit reasons associated with the immediate form of MSR instructions.
For proper virtualization of the immediate form of MSR instructions, Intel VMX architecture adds the following changes:
1) The immediate form of RDMSR uses VM exit reason 84.
2) The immediate form of WRMSRNS uses VM exit reason 85.
3) For both VM exit reasons 84 and 85, the exit qualification is set to the MSR address causing the VM exit.
4) Bits 3 ~ 6 of the VM exit instruction information field represent the operand register used in the immediate form of MSR instruction.
5) The VM-exit instruction length field records the size of the immediate form of the MSR instruction.
Add code to properly virtualize the immediate form of MSR instructions.
While at it, add helper functions to centralize guest MSR read/write emulation, which consolidates the MSR emulation logic and makes it easier to extend support for new MSR-related VM exit reasons introduced with the immediate form of MSR instructions.
---
Changes in v2:
*) Added nested MSR bitmap check for the two new MSR-related VM exit
reasons (Chao).
*) Shortened function names that still convey enough information
(Chao & Sean).
*) Removed VCPU_EXREG_EDX_EAX as it unnecessarily exposes details of a
specific flow across KVM (Sean).
*) Implemented a separate userspace completion callback for the
immediate form RDMSR (Sean).
*) Passed MSR data directly to __kvm_emulate_wrmsr() instead of the
encoded general-purpose register containing it (Sean).
*) Merged modifications to x86.c and vmx.c within the same patch to
facilitate easier code review (Sean).
*) Moved fastpath support in a separate following patch (Sean).
--- arch/x86/include/asm/kvm_host.h | 3 ++ arch/x86/include/uapi/asm/vmx.h | 6 ++- arch/x86/kvm/vmx/nested.c | 13 +++++- arch/x86/kvm/vmx/vmx.c | 21 ++++++++++ arch/x86/kvm/vmx/vmx.h | 5 +++ arch/x86/kvm/x86.c | 73 +++++++++++++++++++++++++-------- 6 files changed, 101 insertions(+), 20 deletions(-)
arch/x86/include/asm/kvm_host.h +3 -0
@@ -978,6 +978,7 @@ struct kvm_vcpu_arch {unsigned long guest_debug_dr7;u64 msr_platform_info;u64 msr_misc_features_enables; +u32 cui_rdmsr_imm_reg;u64 mcg_cap;u64 mcg_status;
@@ -2155,7 +2156,9 @@ int __kvm_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data, bool host_initiatint kvm_get_msr (struct kvm_vcpu *vcpu,u32 index,u64 *data);int kvm_set_msr (struct kvm_vcpu *vcpu,u32 index,u64 data);int kvm_emulate_rdmsr (struct kvm_vcpu *vcpu); +int kvm_emulate_rdmsr_imm (struct kvm_vcpu *vcpu,u32 msr,int reg);int kvm_emulate_wrmsr (struct kvm_vcpu *vcpu); +int kvm_emulate_wrmsr_imm (struct kvm_vcpu *vcpu,u32 msr,int reg);int kvm_emulate_as_nop (struct kvm_vcpu *vcpu);int kvm_emulate_invd (struct kvm_vcpu *vcpu);int kvm_emulate_mwait (struct kvm_vcpu *vcpu);
arch/x86/include/uapi/asm/vmx.h +5 -1
@@ -94,6 +94,8 @@#define EXIT_REASON_BUS_LOCK 74#define EXIT_REASON_NOTIFY 75#define EXIT_REASON_TDCALL 77 +#define EXIT_REASON_MSR_READ_IMM 84 +#define EXIT_REASON_MSR_WRITE_IMM 85#define VMX_EXIT_REASONS \ { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \
@@ -158,7 +160,9 @@ { EXIT_REASON_TPAUSE, "TPAUSE" }, \ { EXIT_REASON_BUS_LOCK, "BUS_LOCK" }, \ { EXIT_REASON_NOTIFY, "NOTIFY" }, \ - { EXIT_REASON_TDCALL, "TDCALL" } + { EXIT_REASON_TDCALL, "TDCALL" }, \ + { EXIT_REASON_MSR_READ_IMM, "MSR_READ_IMM" }, \ + { EXIT_REASON_MSR_WRITE_IMM, "MSR_WRITE_IMM" } #define VMX_EXIT_REASON_FLAGS \ { VMX_EXIT_REASONS_FAILED_VMENTRY, "FAILED_VMENTRY" }
arch/x86/kvm/vmx/nested.c +11 -2
@@ -6216,19 +6216,26 @@ static bool nested_vmx_exit_handled_msr(struct kvm_vcpu *vcpu,struct vmcs12 *vmcs12, union vmx_exit_reason exit_reason) { - u32 msr_index = kvm_rcx_read(vcpu); + u32 msr_index;gpa_t bitmap;if (!nested_cpu_has (vmcs12,CPU_BASED_USE_MSR_BITMAPS ))return true; +if (exit_reason.basic ==EXIT_REASON_MSR_READ_IMM || + exit_reason.basic ==EXIT_REASON_MSR_WRITE_IMM ) + msr_index =vmx_get_exit_qual (vcpu); +else + msr_index =kvm_rcx_read (vcpu); +/* * The MSR_BITMAP page is divided into four 1024-byte bitmaps, * for the four combinations of read/write and low/high MSR numbers. * First we need to figure out which of the four to use: */ bitmap = vmcs12->msr_bitmap; -if (exit_reason.basic ==EXIT_REASON_MSR_WRITE ) +if (exit_reason.basic ==EXIT_REASON_MSR_WRITE || + exit_reason.basic ==EXIT_REASON_MSR_WRITE_IMM ) bitmap +=2048 ;if (msr_index >=0xc0000000 ) { msr_index -=0xc0000000 ;
@@ -6527,6 +6534,8 @@ static bool nested_vmx_l1_wants_exit(struct kvm_vcpu *vcpu,return nested_cpu_has2 (vmcs12,SECONDARY_EXEC_DESC );case EXIT_REASON_MSR_READ :case EXIT_REASON_MSR_WRITE : +case EXIT_REASON_MSR_READ_IMM : +case EXIT_REASON_MSR_WRITE_IMM :return nested_vmx_exit_handled_msr (vcpu, vmcs12, exit_reason);case EXIT_REASON_INVALID_STATE :return true;
arch/x86/kvm/vmx/vmx.c +21 -0
@@ -6003,6 +6003,23 @@ static int handle_notify(struct kvm_vcpu *vcpu)return 1 ; } +static int vmx_get_msr_imm_reg (void ) +{ +return vmx_get_instr_info_reg (vmcs_read32 (VMX_INSTRUCTION_INFO )); +} + +static int handle_rdmsr_imm (struct kvm_vcpu *vcpu) +{ +return kvm_emulate_rdmsr_imm (vcpu,vmx_get_exit_qual (vcpu), +vmx_get_msr_imm_reg ()); +} + +static int handle_wrmsr_imm (struct kvm_vcpu *vcpu) +{ +return kvm_emulate_wrmsr_imm (vcpu,vmx_get_exit_qual (vcpu), +vmx_get_msr_imm_reg ()); +} +/* * The exit handlers return 1 if the exit was handled fully and guest execution * may resume. Otherwise they set the kvm_run parameter to indicate what needs
@@ -6061,6 +6078,8 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { [EXIT_REASON_ENCLS] = handle_encls, [EXIT_REASON_BUS_LOCK] = handle_bus_lock_vmexit, [EXIT_REASON_NOTIFY] = handle_notify, + [EXIT_REASON_MSR_READ_IMM] = handle_rdmsr_imm, + [EXIT_REASON_MSR_WRITE_IMM] = handle_wrmsr_imm, }; static const int kvm_vmx_max_exit_handlers =
@@ -6495,6 +6514,8 @@ static int __vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)#ifdef CONFIG_MITIGATION_RETPOLINE if (exit_reason.basic ==EXIT_REASON_MSR_WRITE )return kvm_emulate_wrmsr (vcpu); +else if (exit_reason.basic ==EXIT_REASON_MSR_WRITE_IMM ) +return handle_wrmsr_imm (vcpu);else if (exit_reason.basic ==EXIT_REASON_PREEMPTION_TIMER )return handle_preemption_timer (vcpu);else if (exit_reason.basic ==EXIT_REASON_INTERRUPT_WINDOW )
arch/x86/kvm/vmx/vmx.h +5 -0
@@ -706,6 +706,11 @@ static inline bool vmx_guest_state_valid(struct kvm_vcpu *vcpu)void dump_vmcs (struct kvm_vcpu *vcpu); +static inline int vmx_get_instr_info_reg (u32 vmx_instr_info) +{ +return (vmx_instr_info >>3 ) &0xf ; +} +static inline int vmx_get_instr_info_reg2 (u32 vmx_instr_info) {return (vmx_instr_info >>28 ) &0xf ;
arch/x86/kvm/x86.c +56 -17
124 lines not on this page · raw message
Signature · 1 line
2.50.1
Sean Christopherson
maintainerarch/x86/include/asm/kvm_host.h struct kvm_vcpu_arch { · line 981
Quoted 9 lines · Xin Li (Intel)
arch/x86/include/asm/kvm_host.h +1
-0@@ -978,6 +978,7 @@ struct kvm_vcpu_arch {unsigned long guest_debug_dr7;u64 msr_platform_info;u64 msr_misc_features_enables; +u32 cui_rdmsr_imm_reg;
This should be an "int", mostly because that's how KVM tracks it throughout the various accessors, but also because it'd let us use "-1" for an "invalid" value, e.g. if we ever want to add sanity checks to the completion callback (I don't think that's worth doing).
arch/x86/kvm/vmx/vmx.c static int handle_notify(struct kvm_vcpu *vcpu) · line 6006
Quoted 9 lines
arch/x86/kvm/vmx/vmx.c +1
-0@@ -6003,6 +6003,23 @@ static int handle_notify(struct kvm_vcpu *vcpu)return 1 ; } +static int vmx_get_msr_imm_reg (void )
It's a bit silly, but I think it's worth passing in the @vcpu here. E.g. if we ever want to support caching the vmcs.VMX_INSTRUCTION_INFO. And because it costs literally nothing (barring a truly stupid compiler).
arch/x86/kvm/x86.c static void complete_userspace_rdmsr(struct kvm_vcpu *vcpu) · line 1971
Quoted 9 lines
arch/x86/kvm/x86.c +1
-0@@ -1968,6 +1968,13 @@ static void complete_userspace_rdmsr(struct kvm_vcpu *vcpu) } } +static void complete_userspace_rdmsr_imm (struct kvm_vcpu *vcpu)
No need for this helper, the few lines can be open coded in complete_fast_rdmsr_imm().
Quoted 6 lines
arch/x86/kvm/x86.c +6
-0+{ +if (!vcpu->run->msr.error) +kvm_register_write (vcpu, vcpu->arch.cui_rdmsr_imm_reg, + vcpu->run->msr.data); +} +
Quoted 15 lines · Sean Christopherson
arch/x86/include/asm/kvm_host.h struct kvm_vcpu_arch { · line 981
Quoted 9 lines · Xin Li (Intel)
arch/x86/include/asm/kvm_host.h +1
-0@@ -978,6 +978,7 @@ struct kvm_vcpu_arch {unsigned long guest_debug_dr7;u64 msr_platform_info;u64 msr_misc_features_enables; +u32 cui_rdmsr_imm_reg;This should be an "int", mostly because that's how KVM tracks it throughout the various accessors, but also because it'd let us use "-1" for an "invalid" value, e.g. if we ever want to add sanity checks to the completion callback (I don't think that's worth doing).
Sigh, using u32 was a dumb move on my part.
Quoted 11 lines
arch/x86/kvm/x86.c static void complete_userspace_rdmsr(struct kvm_vcpu *vcpu) · line 1971
Quoted 9 lines
arch/x86/kvm/x86.c +1
-0@@ -1968,6 +1968,13 @@ static void complete_userspace_rdmsr(struct kvm_vcpu *vcpu) } } +static void complete_userspace_rdmsr_imm (struct kvm_vcpu *vcpu)No need for this helper, the few lines can be open coded in
complete_fast_rdmsr_imm().
Yes, the change in v3 is simpler.
Quoted 8 lines
Quoted 7 lines
arch/x86/kvm/x86.c +6
-0+{ +if (!vcpu->run->msr.error) +kvm_register_write (vcpu, vcpu->arch.cui_rdmsr_imm_reg, + vcpu->run->msr.data); +} +
PATCH v2 3/4 KVM: VMX: Support the immediate form WRMSRNS in fastpath
In reply to Xin Li (Intel)Refactored handle_fastpath_set_msr_irqoff() to accept MSR index and data directly via input arguments, enabling it to handle both implicit and immediate form WRMSRNS through appropriate wrappers. Also rename it to __handle_fastpath_wrmsr().
BTW, per Sean's suggestion, rename handle_fastpath_set_msr_irqoff() to handle_fastpath_wrmsr().
---
Change in v2:
*) Moved fastpath support in a separate patch (Sean).
--- arch/x86/kvm/svm/svm.c | 2 +- arch/x86/kvm/vmx/vmx.c | 5 ++++- arch/x86/kvm/x86.c | 19 +++++++++++++------ arch/x86/kvm/x86.h | 3 ++- 4 files changed, 20 insertions(+), 9 deletions(-)
arch/x86/kvm/svm/svm.c +1 -1
@@ -4189,7 +4189,7 @@ static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu)case SVM_EXIT_MSR :if (!svm->vmcb->control.exit_info_1)break ; -return handle_fastpath_set_msr_irqoff (vcpu); +return handle_fastpath_wrmsr (vcpu);case SVM_EXIT_HLT :return handle_fastpath_hlt (vcpu);default :
arch/x86/kvm/vmx/vmx.c +4 -1
@@ -7191,7 +7191,10 @@ static fastpath_t vmx_exit_handlers_fastpath(struct kvm_vcpu *vcpu,switch (vmx_get_exit_reason (vcpu).basic) {case EXIT_REASON_MSR_WRITE : -return handle_fastpath_set_msr_irqoff (vcpu); +return handle_fastpath_wrmsr (vcpu); +case EXIT_REASON_MSR_WRITE_IMM : +return handle_fastpath_wrmsr_imm (vcpu,vmx_get_exit_qual (vcpu), +vmx_get_msr_imm_reg ());case EXIT_REASON_PREEMPTION_TIMER :return handle_fastpath_preemption_timer (vcpu, force_immediate_exit);case EXIT_REASON_HLT :
arch/x86/kvm/x86.c +13 -6
@@ -2202,10 +2202,8 @@ static int handle_fastpath_set_tscdeadline(struct kvm_vcpu *vcpu, u64 data)return 0 ; } -fastpath_t handle_fastpath_set_msr_irqoff (struct kvm_vcpu *vcpu) +static fastpath_t __handle_fastpath_wrmsr (struct kvm_vcpu *vcpu,u32 msr,u64 data) { -u32 msr =kvm_rcx_read (vcpu); -u64 data;fastpath_t ret;bool handled;
@@ -2213,11 +2211,9 @@ fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu)switch (msr) {case APIC_BASE_MSR + (APIC_ICR >>4 ): - data =kvm_read_edx_eax (vcpu); handled = !handle_fastpath_set_x2apic_icr_irqoff (vcpu, data);break ;case MSR_IA32_TSC_DEADLINE : - data =kvm_read_edx_eax (vcpu); handled = !handle_fastpath_set_tscdeadline (vcpu, data);break ;default :
@@ -2239,7 +2235,18 @@ fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu)return ret; } -EXPORT_SYMBOL_GPL (handle_fastpath_set_msr_irqoff); + +fastpath_t handle_fastpath_wrmsr (struct kvm_vcpu *vcpu) +{ +return __handle_fastpath_wrmsr (vcpu,kvm_rcx_read (vcpu),kvm_read_edx_eax (vcpu)); +} +EXPORT_SYMBOL_GPL (handle_fastpath_wrmsr); + +fastpath_t handle_fastpath_wrmsr_imm (struct kvm_vcpu *vcpu,u32 msr,int reg) +{ +return __handle_fastpath_wrmsr (vcpu, msr,kvm_register_read (vcpu, reg)); +} +EXPORT_SYMBOL_GPL (handle_fastpath_wrmsr_imm);/* * Adapt set_msr() to msr_io()'s calling convention
arch/x86/kvm/x86.h +2 -1
@@ -437,7 +437,8 @@ int x86_decode_emulated_instruction(struct kvm_vcpu *vcpu, int emulation_type, void *insn, int insn_len);int x86_emulate_instruction (struct kvm_vcpu *vcpu,gpa_t cr2_or_gpa,int emulation_type,void *insn,int insn_len); -fastpath_t handle_fastpath_set_msr_irqoff (struct kvm_vcpu *vcpu); +fastpath_t handle_fastpath_wrmsr (struct kvm_vcpu *vcpu); +fastpath_t handle_fastpath_wrmsr_imm (struct kvm_vcpu *vcpu,u32 msr,int reg);fastpath_t handle_fastpath_hlt (struct kvm_vcpu *vcpu);extern struct kvm_caps kvm_caps;
Signature · 1 line
2.50.1
PATCH v2 4/4 KVM: x86: Advertise support for the immediate form of MSR instructions
In reply to Xin Li (Intel)Advertise support for the immediate form of MSR instructions to userspace if the instructions are supported by the underlying CPU.
The immediate form of MSR access instructions are primarily motivated by performance, not code size: by having the MSR number in an immediate, it is available *much* earlier in the pipeline, which allows the hardware much more leeway about how a particular MSR is handled.
Explicitly clear the capability in SVM, as its handling is only added for VMX.
---
Change in v2:
*) Cleared the capability in SVM (Sean).
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/cpuid.c | 6 +++++- arch/x86/kvm/reverse_cpuid.h | 5 +++++ arch/x86/kvm/svm/svm.c | 6 +++++- 4 files changed, 16 insertions(+), 2 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -771,6 +771,7 @@ enum kvm_only_cpuid_leafs {CPUID_7_2_EDX ,CPUID_24_0_EBX ,CPUID_8000_0021_ECX , +CPUID_7_1_ECX ,NR_KVM_CPU_CAPS , NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS,
arch/x86/kvm/cpuid.c +5 -1
@@ -985,6 +985,10 @@ void kvm_set_cpu_caps(void)F (LAM ), ); +kvm_cpu_cap_init (CPUID_7_1_ECX , + SCATTERED_F(MSR_IMM), + ); + kvm_cpu_cap_init(CPUID_7_1_EDX, F(AVX_VNNI_INT8), F(AVX_NE_CONVERT),
@@ -1411,9 +1415,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) goto out;cpuid_entry_override (entry,CPUID_7_1_EAX ); +cpuid_entry_override (entry,CPUID_7_1_ECX );cpuid_entry_override (entry,CPUID_7_1_EDX ); entry->ebx =0 ; - entry->ecx =0 ; }if (max_idx >=2 ) { entry =do_host_cpuid (array, function,2 );
arch/x86/kvm/reverse_cpuid.h +5 -0
@@ -25,6 +25,9 @@#define KVM_X86_FEATURE_SGX2 KVM_X86_FEATURE(CPUID_12_EAX, 1)#define KVM_X86_FEATURE_SGX_EDECCSSA KVM_X86_FEATURE(CPUID_12_EAX, 11) +/* Intel-defined sub-features, CPUID level 0x00000007:1 (ECX) */ +#define KVM_X86_FEATURE_MSR_IMM KVM_X86_FEATURE(CPUID_7_1_ECX, 5) +/* Intel-defined sub-features, CPUID level 0x00000007:1 (EDX) */ #define X86_FEATURE_AVX_VNNI_INT8 KVM_X86_FEATURE(CPUID_7_1_EDX, 4)#define X86_FEATURE_AVX_NE_CONVERT KVM_X86_FEATURE(CPUID_7_1_EDX, 5)
@@ -87,6 +90,7 @@ static const struct cpuid_reg reverse_cpuid[] = { [CPUID_7_2_EDX] = { 7, 2, CPUID_EDX}, [CPUID_24_0_EBX] = { 0x24, 0, CPUID_EBX}, [CPUID_8000_0021_ECX] = {0x80000021, 0, CPUID_ECX}, + [CPUID_7_1_ECX] = { 7, 1, CPUID_ECX}, };/*
@@ -128,6 +132,7 @@ static __always_inline u32 __feature_translate(int x86_feature)KVM_X86_TRANSLATE_FEATURE (BHI_CTRL );KVM_X86_TRANSLATE_FEATURE (TSA_SQ_NO );KVM_X86_TRANSLATE_FEATURE (TSA_L1_NO ); +KVM_X86_TRANSLATE_FEATURE (MSR_IMM );default :return x86_feature; }
arch/x86/kvm/svm/svm.c +5 -1
@@ -5301,8 +5301,12 @@ static __init void svm_set_cpu_caps(void)/* CPUID 0x8000001F (SME/SEV features) */ sev_set_cpu_caps (); -/* Don't advertise Bus Lock Detect to guest if SVM support is absent */ +/* +* Clear capabilities that are automatically configured by common code, +* but that require explicit SVM support (that isn't yet implemented). +*/ kvm_cpu_cap_clear (X86_FEATURE_BUS_LOCK_DETECT ); +kvm_cpu_cap_clear (X86_FEATURE_MSR_IMM ); }static __init int svm_hardware_setup (void )
Signature · 1 line
2.50.1