kvm: nVMX: Check memory operand to INVVPID
PATCH 1/1 kvm: nVMX: Check memory operand to INVVPID
The memory operand fetched for INVVPID is 128 bits. Bits 63:16 are reserved and must be zero. Otherwise, the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID). If the INVVPID_TYPE is 0 (individual address invalidation), then bits 127:64 must be in canonical form, or the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID).
--- arch/x86/kvm/vmx.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
arch/x86/kvm/vmx.c +19 -4
@@ -7651,7 +7651,11 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)unsigned long type, types;gva_t gva;struct x86_exception e; -int vpid; +struct { +u64 vpid :16 ; +u64 rsvd :48 ; +u64 gla; + } operand; if (!(vmx->nested.nested_vmx_secondary_ctls_high & SECONDARY_EXEC_ENABLE_VPID) ||
@@ -7681,17 +7685,28 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)if (get_vmx_mem_address (vcpu,vmcs_readl (EXIT_QUALIFICATION ), vmx_instruction_info, false, &gva))return 1 ; -if (kvm_read_guest_virt (&vcpu->arch.emulate_ctxt, gva, &vpid, -sizeof (u32), &e)) { +if (kvm_read_guest_virt (&vcpu->arch.emulate_ctxt, gva, &operand, +sizeof (operand), &e)) {kvm_inject_page_fault (vcpu, &e);return 1 ; } +if (operand.rsvd) { +nested_vmx_failValid (vcpu, +VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); +return kvm_skip_emulated_instruction (vcpu); + }switch (type) {case VMX_VPID_EXTENT_INDIVIDUAL_ADDR : +if (is_noncanonical_address (operand.gla)) { +nested_vmx_failValid (vcpu, +VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); +return kvm_skip_emulated_instruction (vcpu); + } +/* fall through */ case VMX_VPID_EXTENT_SINGLE_CONTEXT :case VMX_VPID_EXTENT_SINGLE_NON_GLOBAL : -if (!vpid) { +if (!operand.vpid) {nested_vmx_failValid (vcpu,VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID );return kvm_skip_emulated_instruction (vcpu);
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
Quoted 52 lines · Jim Mattson
The memory operand fetched for INVVPID is 128 bits. Bits 63:16 are reserved and must be zero. Otherwise, the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID). If the
INVVPID_TYPEis 0 (individual address invalidation), then bits 127:64 must be in canonical form, or the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID).Signed-off-by Jim Mattson <[email protected]>--- arch/x86/kvm/vmx.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)arch/x86/kvm/vmx.c +15
-3@@ -7651,7 +7651,11 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)unsigned long type, types;gva_t gva;struct x86_exception e; -int vpid; +struct { +u64 vpid :16 ; +u64 rsvd :48 ; +u64 gla; + } operand; if (!(vmx->nested.nested_vmx_secondary_ctls_high & SECONDARY_EXEC_ENABLE_VPID) ||@@ -7681,17 +7685,28 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)if (get_vmx_mem_address (vcpu,vmcs_readl (EXIT_QUALIFICATION ), vmx_instruction_info, false, &gva))return 1 ; -if (kvm_read_guest_virt (&vcpu->arch.emulate_ctxt, gva, &vpid, -sizeof (u32), &e)) { +if (kvm_read_guest_virt (&vcpu->arch.emulate_ctxt, gva, &operand, +sizeof (operand), &e)) {kvm_inject_page_fault (vcpu, &e);return 1 ; } +if (operand.rsvd) { +nested_vmx_failValid (vcpu, +VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); +return kvm_skip_emulated_instruction (vcpu); + }switch (type) {case VMX_VPID_EXTENT_INDIVIDUAL_ADDR : +if (is_noncanonical_address (operand.gla)) { +nested_vmx_failValid (vcpu, +VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID );
arch/x86/kvm/vmx.c static int handle_invvpid(struct kvm_vcpu *vcpu) · line 7712
Quoted 10 lines
arch/x86/kvm/vmx.c +4
-1+return kvm_skip_emulated_instruction (vcpu); + } +/* fall through */ case VMX_VPID_EXTENT_SINGLE_CONTEXT :case VMX_VPID_EXTENT_SINGLE_NON_GLOBAL : -if (!vpid) { +if (!operand.vpid) {nested_vmx_failValid (vcpu,VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID );return kvm_skip_emulated_instruction (vcpu);
Looks good to me!
Signature · 3 lines
Thanks, David
Paolo Bonzini
maintainerQuoted 17 lines · Jim Mattson
The memory operand fetched for INVVPID is 128 bits. Bits 63:16 are reserved and must be zero. Otherwise, the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID). If the
INVVPID_TYPEis 0 (individual address invalidation), then bits 127:64 must be in canonical form, or the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID).Signed-off-by Jim Mattson <[email protected]>--- arch/x86/kvm/vmx.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)arch/x86/kvm/vmx.c +0
-0
arch/x86/kvm/vmx.c static int handle_invvpid(struct kvm_vcpu *vcpu) · line 7656
Quoted 7 lines
arch/x86/kvm/vmx.c +3
-1@@ -7651,7 +7651,11 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)unsigned long type, types;gva_t gva;struct x86_exception e; -int vpid; +struct { +u64 vpid :16 ; +u64 rsvd :48 ;
I prefer using an u64 here (and checking the reserved bits via "& ~0xFFFF"). I find bit-endianness confusing because bits are in the opposite order of the declarations (unlike byte-endianness, bits within one word are usually drawn high to low).
Paolo
Quoted 38 lines
arch/x86/kvm/vmx.c +16
-3+u64 gla; + } operand; if (!(vmx->nested.nested_vmx_secondary_ctls_high & SECONDARY_EXEC_ENABLE_VPID) ||@@ -7681,17 +7685,28 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)if (get_vmx_mem_address (vcpu,vmcs_readl (EXIT_QUALIFICATION ), vmx_instruction_info, false, &gva))return 1 ; -if (kvm_read_guest_virt (&vcpu->arch.emulate_ctxt, gva, &vpid, -sizeof (u32), &e)) { +if (kvm_read_guest_virt (&vcpu->arch.emulate_ctxt, gva, &operand, +sizeof (operand), &e)) {kvm_inject_page_fault (vcpu, &e);return 1 ; } +if (operand.rsvd) { +nested_vmx_failValid (vcpu, +VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); +return kvm_skip_emulated_instruction (vcpu); + }switch (type) {case VMX_VPID_EXTENT_INDIVIDUAL_ADDR : +if (is_noncanonical_address (operand.gla)) { +nested_vmx_failValid (vcpu, +VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); +return kvm_skip_emulated_instruction (vcpu); + } +/* fall through */ case VMX_VPID_EXTENT_SINGLE_CONTEXT :case VMX_VPID_EXTENT_SINGLE_NON_GLOBAL : -if (!vpid) { +if (!operand.vpid) {nested_vmx_failValid (vcpu,VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID );return kvm_skip_emulated_instruction (vcpu);
PATCH v2 1/1 kvm: nVMX: Check memory operand to INVVPID
The memory operand fetched for INVVPID is 128 bits. Bits 63:16 are reserved and must be zero. Otherwise, the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID). If the INVVPID_TYPE is 0 (individual address invalidation), then bits 127:64 must be in canonical form, or the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID).
--- arch/x86/kvm/vmx.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
arch/x86/kvm/vmx.c +18 -4
@@ -7651,7 +7651,10 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)unsigned long type, types;gva_t gva;struct x86_exception e; -int vpid; +struct { +u64 vpid; +u64 gla; + } operand; if (!(vmx->nested.nested_vmx_secondary_ctls_high & SECONDARY_EXEC_ENABLE_VPID) ||
@@ -7681,17 +7684,28 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)if (get_vmx_mem_address (vcpu,vmcs_readl (EXIT_QUALIFICATION ), vmx_instruction_info, false, &gva))return 1 ; -if (kvm_read_guest_virt (&vcpu->arch.emulate_ctxt, gva, &vpid, -sizeof (u32), &e)) { +if (kvm_read_guest_virt (&vcpu->arch.emulate_ctxt, gva, &operand, +sizeof (operand), &e)) {kvm_inject_page_fault (vcpu, &e);return 1 ; } +if (operand.vpid >>16 ) { +nested_vmx_failValid (vcpu, +VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); +return kvm_skip_emulated_instruction (vcpu); + }switch (type) {case VMX_VPID_EXTENT_INDIVIDUAL_ADDR : +if (is_noncanonical_address (operand.gla)) { +nested_vmx_failValid (vcpu, +VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); +return kvm_skip_emulated_instruction (vcpu); + } +/* fall through */ case VMX_VPID_EXTENT_SINGLE_CONTEXT :case VMX_VPID_EXTENT_SINGLE_NON_GLOBAL : -if (!vpid) { +if (!operand.vpid) {nested_vmx_failValid (vcpu,VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID );return kvm_skip_emulated_instruction (vcpu);
Signature · 1 line
2.13.2.725.g09c95d1e9-goog
Paolo Bonzini
maintainerQuoted 11 lines · Jim Mattson
The memory operand fetched for INVVPID is 128 bits. Bits 63:16 are reserved and must be zero. Otherwise, the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID). If the
INVVPID_TYPEis 0 (individual address invalidation), then bits 127:64 must be in canonical form, or the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID).Signed-off-by Jim Mattson <[email protected]>--- arch/x86/kvm/vmx.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
Thanks, looks good. Will apply, kvm-unit-tests patches are always welcome. :)
Paolo
Quoted 49 lines
arch/x86/kvm/vmx.c +18
-4@@ -7651,7 +7651,10 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)unsigned long type, types;gva_t gva;struct x86_exception e; -int vpid; +struct { +u64 vpid; +u64 gla; + } operand; if (!(vmx->nested.nested_vmx_secondary_ctls_high & SECONDARY_EXEC_ENABLE_VPID) ||@@ -7681,17 +7684,28 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)if (get_vmx_mem_address (vcpu,vmcs_readl (EXIT_QUALIFICATION ), vmx_instruction_info, false, &gva))return 1 ; -if (kvm_read_guest_virt (&vcpu->arch.emulate_ctxt, gva, &vpid, -sizeof (u32), &e)) { +if (kvm_read_guest_virt (&vcpu->arch.emulate_ctxt, gva, &operand, +sizeof (operand), &e)) {kvm_inject_page_fault (vcpu, &e);return 1 ; } +if (operand.vpid >>16 ) { +nested_vmx_failValid (vcpu, +VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); +return kvm_skip_emulated_instruction (vcpu); + }switch (type) {case VMX_VPID_EXTENT_INDIVIDUAL_ADDR : +if (is_noncanonical_address (operand.gla)) { +nested_vmx_failValid (vcpu, +VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); +return kvm_skip_emulated_instruction (vcpu); + } +/* fall through */ case VMX_VPID_EXTENT_SINGLE_CONTEXT :case VMX_VPID_EXTENT_SINGLE_NON_GLOBAL : -if (!vpid) { +if (!operand.vpid) {nested_vmx_failValid (vcpu,VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID );return kvm_skip_emulated_instruction (vcpu);
Quoted 9 lines · Jim Mattson
The memory operand fetched for INVVPID is 128 bits. Bits 63:16 are reserved and must be zero. Otherwise, the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID). If the
INVVPID_TYPEis 0 (individual address invalidation), then bits 127:64 must be in canonical form, or the instruction fails with VMfail(Invalid operand to INVEPT/INVVPID).Signed-off-by Jim Mattson <[email protected]>---
My r-b still holds :)
Signature · 3 lines
Thanks, David
Paolo Bonzini
maintainerQuoted 4 lines · Jim Mattson
Will apply, kvm-unit-tests patches are always
welcome. :)Working on a crossport of the test. Bear with me.
No problem.
David, any news on the EPT without A/D bugfix, too?
Paolo
PATCH 1/2 Move vmx_{on,off} into vmx.h
Make these functions available to callers outside of vmx.c
--- x86/vmx.c | 19 ------------------- x86/vmx.h | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-)
x86/vmx.c +0 -19
@@ -424,25 +424,6 @@ static void __attribute__((__used__)) syscall_handler(u64 syscall_no) current->syscall_handler (syscall_no); } -static inline int vmx_on () -{ -bool ret; -u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ; - asmvolatile ("push %1; popf; vmxon %2; setbe %0\n\t" - :"=q" (ret) :"q" (rflags),"m" (vmxon_region) :"cc" ); -return ret; -} - -static inline int vmx_off () -{ -bool ret; -u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ; - - asmvolatile ("push %1; popf; vmxoff; setbe %0\n\t" - :"=q" (ret) :"q" (rflags) :"cc" ); -return ret; -} -static const char *const exit_reason_descriptions[] = { [VMX_EXC_NMI ] ="VMX_EXC_NMI" , [VMX_EXTINT ] ="VMX_EXTINT" ,
x86/vmx.h +21 -0
@@ -585,10 +585,31 @@ extern union vmx_ctrl_msr ctrl_exit_rev;extern union vmx_ctrl_msr ctrl_enter_rev;extern union vmx_ept_vpid ept_vpid; +extern u64 *vmxon_region; +void vmx_set_test_stage (u32 s);u32 vmx_get_test_stage (void );void vmx_inc_test_stage (void ); +static int vmx_on (void ) +{ +bool ret; +u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ; + asmvolatile ("push %1; popf; vmxon %2; setbe %0\n\t" + :"=q" (ret) :"q" (rflags),"m" (vmxon_region) :"cc" ); +return ret; +} + +static int vmx_off (void ) +{ +bool ret; +u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ; + + asmvolatile ("push %1; popf; vmxoff; setbe %0\n\t" + :"=q" (ret) :"q" (rflags) :"cc" ); +return ret; +} +static inline int make_vmcs_current (struct vmcs *vmcs) {bool ret;
Signature · 1 line
2.13.2.725.g09c95d1e9-goog
PATCH 2/2 Add basic invvpid test
Tests only for success/failure of invvpid. Does not test actual invvpid functionality.
--- lib/x86/processor.h | 5 ++ x86/unittests.cfg | 6 ++ x86/vmx.c | 6 +- x86/vmx.h | 24 ++++--- x86/vmx_tests.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 219 insertions(+), 16 deletions(-)
lib/x86/processor.h +5 -0
@@ -430,4 +430,9 @@ static inline void write_pkru(u32 pkru) : : "a" (eax), "c" (ecx), "d" (edx)); } +static inline bool is_canonical (u64 addr) +{ +return (s64)(addr <<16 ) >>16 == addr; +} +#endif
x86/unittests.cfg +6 -0
@@ -494,6 +494,12 @@ extra_params = -cpu host,+vmx -m 2048 -append ept_access_test_force_2m_page arch = x86_64 groups = vmx +[vmx_invvpid] +file = vmx.flat +extra_params = -cpu host,+vmx -m 2048 -append invvpid_test_v2 +arch = x86_64 +groups = vmx + [debug] file = debug.flat arch = x86_64
x86/vmx.c +3 -3
@@ -987,9 +987,9 @@ bool ept_ad_bits_supported(void)void vpid_sync (int type,u16 vpid) {switch (type) { -case INVVPID_SINGLE : -if (ept_vpid.val &VPID_CAP_INVVPID_SINGLE ) { -invvpid (INVVPID_SINGLE , vpid,0 ); +case INVVPID_CONTEXT_GLOBAL : +if (ept_vpid.val &VPID_CAP_INVVPID_CXTGLB ) { +invvpid (INVVPID_CONTEXT_GLOBAL , vpid,0 );break ; }case INVVPID_ALL :
x86/vmx.h +14 -10
@@ -13,6 +13,11 @@ struct vmcs {char data[0 ]; }; +struct invvpid_operand { +u64 vpid; +u64 gla; +}; +struct regs {u64 rax;u64 rcx;
@@ -537,8 +542,10 @@ enum vm_instruction_error_number {#define EPT_CAP_INVEPT_ALL (1ull << 26)#define EPT_CAP_AD_FLAG (1ull << 21)#define VPID_CAP_INVVPID (1ull << 32) -#define VPID_CAP_INVVPID_SINGLE (1ull << 41) -#define VPID_CAP_INVVPID_ALL (1ull << 42) +#define VPID_CAP_INVVPID_ADDR (1ull << 40) +#define VPID_CAP_INVVPID_CXTGLB (1ull << 41) +#define VPID_CAP_INVVPID_ALL (1ull << 42) +#define VPID_CAP_INVVPID_CXTLOC (1ull << 43)#define PAGE_SIZE_2M (512 * PAGE_SIZE)#define PAGE_SIZE_1G (512 * PAGE_SIZE_2M)
@@ -569,9 +576,10 @@ enum vm_instruction_error_number {#define INVEPT_SINGLE 1#define INVEPT_GLOBAL 2 -#define INVVPID_SINGLE_ADDRESS 0 -#define INVVPID_SINGLE 1 +#define INVVPID_ADDR 0 +#define INVVPID_CONTEXT_GLOBAL 1#define INVVPID_ALL 2 +#define INVVPID_CONTEXT_LOCAL 3#define ACTV_ACTIVE 0#define ACTV_HLT 1
@@ -687,16 +695,12 @@ static inline bool invept(unsigned long type, u64 eptp)return ret; } -static inline bool invvpid (unsigned long type,u16 vpid,u64 gva) +static inline bool invvpid (unsigned long type,u64 vpid,u64 gla) {bool ret;u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ; -struct { -u64 vpid :16 ; -u64 rsvd :48 ; -u64 gva; - } operand = {vpid,0 , gva}; +struct invvpid_operand operand = {vpid, gla}; asmvolatile ("push %1; popf; invvpid %2, %3; setbe %0" :"=q" (ret) :"r" (rflags),"m" (operand),"r" (type) :"cc" );return ret;
x86/vmx_tests.c +191 -3
232 lines not on this page · raw message
Signature · 1 line
2.13.2.725.g09c95d1e9-goog
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Jim Mattson
Will apply, kvm-unit-tests patches are always
welcome. :)Working on a crossport of the test. Bear with me.
No problem.
David, any news on the EPT without A/D bugfix, too?
Thanks for the reminder. Peter's aiming to get it out today or tomorrow. Sorry for the delay!
Quoted 2 lines
Paolo
PATCH v2 1/4 Save/restore handler in test_for_exception
In reply to Jim MattsonThe default handler for #DE, #UD, and #GP is check_exception_table. Test_for_exception should restore the original handler before returning, rather than blindly clobbering it with NULL.
--- lib/x86/desc.c | 16 ++++++++++------ lib/x86/desc.h | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-)
lib/x86/desc.c +10 -6
@@ -117,13 +117,16 @@ static void check_exception_table(struct ex_regs *regs)unhandled_exception (regs, false); } -static void (*exception_handlers[32 ])(struct ex_regs *regs); +static handler exception_handlers[32 ]; - -void handle_exception (u8 v,void (*func)(struct ex_regs *regs)) +handler handle_exception (u8 v,handler fn) { +handler old; + + old = exception_handlers[v];if (v <32 ) - exception_handlers[v] = func; + exception_handlers[v] = fn; +return old; }#ifndef __x86_64__
@@ -390,14 +393,15 @@ static void exception_handler(struct ex_regs *regs)bool test_for_exception (unsigned int ex,void (*trigger_func)(void *data),void *data) { +handler old;jmp_buf jmpbuf;int ret; -handle_exception (ex, exception_handler); + old =handle_exception (ex, exception_handler); ret =set_exception_jmpbuf (jmpbuf);if (ret ==0 )trigger_func (data); -handle_exception (ex,NULL ); +handle_exception (ex, old);return ret; }
lib/x86/desc.h +3 -1
@@ -20,6 +20,8 @@ struct ex_regs {unsigned long rflags; }; +typedef void (*handler )(struct ex_regs *regs); + typedef struct { u16 prev; u16 res1;
@@ -153,7 +155,7 @@ void set_idt_dpl(int vec, u16 dpl);void set_gdt_entry (int sel,u32 base,u32 limit,u8 access,u8 gran);void set_intr_alt_stack (int e,void *fn);void print_current_tss_info (void ); -void handle_exception (u8 v,void (*func)(struct ex_regs *regs)); +handler handle_exception (u8 v,handler fn);bool test_for_exception (unsigned int ex,void (*trigger_func)(void *data),void *data);
Signature · 1 line
2.13.2.725.g09c95d1e9-goog
PATCH v2 4/4 Add basic invvpid test
Tests only for success/failure of invvpid. Does not test actual invvpid functionality.
--- lib/x86/processor.h | 5 ++ x86/unittests.cfg | 6 ++ x86/vmx.c | 6 +- x86/vmx.h | 24 +++--- x86/vmx_tests.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 250 insertions(+), 16 deletions(-)
lib/x86/processor.h +5 -0
@@ -430,4 +430,9 @@ static inline void write_pkru(u32 pkru) : : "a" (eax), "c" (ecx), "d" (edx)); } +static inline bool is_canonical (u64 addr) +{ +return (s64)(addr <<16 ) >>16 == addr; +} +#endif
x86/unittests.cfg +6 -0
@@ -494,6 +494,12 @@ extra_params = -cpu host,+vmx -m 2048 -append ept_access_test_force_2m_page arch = x86_64 groups = vmx +[vmx_invvpid] +file = vmx.flat +extra_params = -cpu host,+vmx -m 2048 -append invvpid_test_v2 +arch = x86_64 +groups = vmx + [debug] file = debug.flat arch = x86_64
x86/vmx.c +3 -3
@@ -987,9 +987,9 @@ bool ept_ad_bits_supported(void)void vpid_sync (int type,u16 vpid) {switch (type) { -case INVVPID_SINGLE : -if (ept_vpid.val &VPID_CAP_INVVPID_SINGLE ) { -invvpid (INVVPID_SINGLE , vpid,0 ); +case INVVPID_CONTEXT_GLOBAL : +if (ept_vpid.val &VPID_CAP_INVVPID_CXTGLB ) { +invvpid (INVVPID_CONTEXT_GLOBAL , vpid,0 );break ; }case INVVPID_ALL :
x86/vmx.h +14 -10
@@ -13,6 +13,11 @@ struct vmcs {char data[0 ]; }; +struct invvpid_operand { +u64 vpid; +u64 gla; +}; +struct regs {u64 rax;u64 rcx;
@@ -537,8 +542,10 @@ enum vm_instruction_error_number {#define EPT_CAP_INVEPT_ALL (1ull << 26)#define EPT_CAP_AD_FLAG (1ull << 21)#define VPID_CAP_INVVPID (1ull << 32) -#define VPID_CAP_INVVPID_SINGLE (1ull << 41) -#define VPID_CAP_INVVPID_ALL (1ull << 42) +#define VPID_CAP_INVVPID_ADDR (1ull << 40) +#define VPID_CAP_INVVPID_CXTGLB (1ull << 41) +#define VPID_CAP_INVVPID_ALL (1ull << 42) +#define VPID_CAP_INVVPID_CXTLOC (1ull << 43)#define PAGE_SIZE_2M (512 * PAGE_SIZE)#define PAGE_SIZE_1G (512 * PAGE_SIZE_2M)
@@ -569,9 +576,10 @@ enum vm_instruction_error_number {#define INVEPT_SINGLE 1#define INVEPT_GLOBAL 2 -#define INVVPID_SINGLE_ADDRESS 0 -#define INVVPID_SINGLE 1 +#define INVVPID_ADDR 0 +#define INVVPID_CONTEXT_GLOBAL 1#define INVVPID_ALL 2 +#define INVVPID_CONTEXT_LOCAL 3#define ACTV_ACTIVE 0#define ACTV_HLT 1
@@ -687,16 +695,12 @@ static inline bool invept(unsigned long type, u64 eptp)return ret; } -static inline bool invvpid (unsigned long type,u16 vpid,u64 gva) +static inline bool invvpid (unsigned long type,u64 vpid,u64 gla) {bool ret;u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ; -struct { -u64 vpid :16 ; -u64 rsvd :48 ; -u64 gva; - } operand = {vpid,0 , gva}; +struct invvpid_operand operand = {vpid, gla}; asmvolatile ("push %1; popf; invvpid %2, %3; setbe %0" :"=q" (ret) :"r" (rflags),"m" (operand),"r" (type) :"cc" );return ret;
x86/vmx_tests.c +222 -3
263 lines not on this page · raw message
Signature · 1 line
2.13.2.725.g09c95d1e9-goog
PATCH v2 2/4 Specify %cs for exception_handler iret
In reply to Jim MattsonThe exception handler longjmp should happen in the code segment of the exception handler rather than in the code segment of the exception (particularly when the exception occurs in compatibility mode).
--- lib/x86/desc.c | 1 + 1 file changed, 1 insertion(+)
lib/x86/desc.c +1 -0
@@ -388,6 +388,7 @@ static void exception_handler(struct ex_regs *regs)/* longjmp must happen after iret, so do not do it now. */ exception = true; regs->rip = (unsigned long )&exception_handler_longjmp; + regs->cs =read_cs (); } bool test_for_exception(unsigned int ex, void (*trigger_func)(void *data),
Signature · 1 line
2.13.2.725.g09c95d1e9-goog
PATCH v2 3/4 Move vmx_{on,off} into vmx.h
In reply to Jim MattsonMake these functions available to callers outside of vmx.c
--- x86/vmx.c | 19 ------------------- x86/vmx.h | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-)
x86/vmx.c +0 -19
@@ -424,25 +424,6 @@ static void __attribute__((__used__)) syscall_handler(u64 syscall_no) current->syscall_handler (syscall_no); } -static inline int vmx_on () -{ -bool ret; -u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ; - asmvolatile ("push %1; popf; vmxon %2; setbe %0\n\t" - :"=q" (ret) :"q" (rflags),"m" (vmxon_region) :"cc" ); -return ret; -} - -static inline int vmx_off () -{ -bool ret; -u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ; - - asmvolatile ("push %1; popf; vmxoff; setbe %0\n\t" - :"=q" (ret) :"q" (rflags) :"cc" ); -return ret; -} -static const char *const exit_reason_descriptions[] = { [VMX_EXC_NMI ] ="VMX_EXC_NMI" , [VMX_EXTINT ] ="VMX_EXTINT" ,
x86/vmx.h +21 -0
@@ -585,10 +585,31 @@ extern union vmx_ctrl_msr ctrl_exit_rev;extern union vmx_ctrl_msr ctrl_enter_rev;extern union vmx_ept_vpid ept_vpid; +extern u64 *vmxon_region; +void vmx_set_test_stage (u32 s);u32 vmx_get_test_stage (void );void vmx_inc_test_stage (void ); +static int vmx_on (void ) +{ +bool ret; +u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ; + asmvolatile ("push %1; popf; vmxon %2; setbe %0\n\t" + :"=q" (ret) :"q" (rflags),"m" (vmxon_region) :"cc" ); +return ret; +} + +static int vmx_off (void ) +{ +bool ret; +u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ; + + asmvolatile ("push %1; popf; vmxoff; setbe %0\n\t" + :"=q" (ret) :"q" (rflags) :"cc" ); +return ret; +} +static inline int make_vmcs_current (struct vmcs *vmcs) {bool ret;
Signature · 1 line
2.13.2.725.g09c95d1e9-goog
Paolo Bonzini
maintainerRe: [kvm-unit-tests PATCH v2 1/4] Save/restore handler in test_for_exception
In reply to Jim MattsonQuoted 5 lines · Jim Mattson
The default handler for #DE, #UD, and #GP is
check_exception_table.Test_for_exceptionshould restore the original handler before returning, rather than blindly clobbering it with NULL.Signed-off-by Jim Mattson <[email protected]>
Thanks, series tested and applied.
Paolo
Quoted 71 lines
--- lib/x86/desc.c | 16 ++++++++++------ lib/x86/desc.h | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-)lib/x86/desc.c +10
-6@@ -117,13 +117,16 @@ static void check_exception_table(struct ex_regs *regs)unhandled_exception (regs, false); } -static void (*exception_handlers[32 ])(struct ex_regs *regs); +static handler exception_handlers[32 ]; - -void handle_exception (u8 v,void (*func)(struct ex_regs *regs)) +handler handle_exception (u8 v,handler fn) { +handler old; + + old = exception_handlers[v];if (v <32 ) - exception_handlers[v] = func; + exception_handlers[v] = fn; +return old; }#ifndef __x86_64__@@ -390,14 +393,15 @@ static void exception_handler(struct ex_regs *regs)bool test_for_exception (unsigned int ex,void (*trigger_func)(void *data),void *data) { +handler old;jmp_buf jmpbuf;int ret; -handle_exception (ex, exception_handler); + old =handle_exception (ex, exception_handler); ret =set_exception_jmpbuf (jmpbuf);if (ret ==0 )trigger_func (data); -handle_exception (ex,NULL ); +handle_exception (ex, old);return ret; }lib/x86/desc.h +3
-1@@ -20,6 +20,8 @@ struct ex_regs {unsigned long rflags; }; +typedef void (*handler )(struct ex_regs *regs); + typedef struct { u16 prev; u16 res1;@@ -153,7 +155,7 @@ void set_idt_dpl(int vec, u16 dpl);void set_gdt_entry (int sel,u32 base,u32 limit,u8 access,u8 gran);void set_intr_alt_stack (int e,void *fn);void print_current_tss_info (void ); -void handle_exception (u8 v,void (*func)(struct ex_regs *regs)); +handler handle_exception (u8 v,handler fn);bool test_for_exception (unsigned int ex,void (*trigger_func)(void *data),void *data);
Quoted 5 lines · David Matlack
Quoted 4 lines · Paolo Bonzini
Quoted 3 lines · Jim Mattson
Will apply, kvm-unit-tests patches are always
welcome. :)
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Working on a crossport of the test. Bear with me.
No problem.
David, any news on the EPT without A/D bugfix, too?
Thanks for the reminder. Peter's aiming to get it out today or tomorrow. Sorry for the delay!
I could send the patches out but they aren't working yet :-) Debugging the bitrot between Google's kernel & upstream is taking longer than I had hoped.
Since I'm on vacation next week, I won't have it working until sometime during the week of July 10.
Again, sorry for the delay getting started on this.
Peter