ia64/xen-unstable

changeset 9226:3f8123ae34ba

Currently if one tries to execute VMX instruction from inside the
VMX guest, the Xen hyper visor has no handling of it resulting in a
bug(). This patch handles such VMX instructions from the guest returning
invalid opcode to the guest. Also the macro VMX_INVALID_ERROR_CODE is
renamed to the more meaningful VMX_DELIVER_NO_ERROR_CODE.

Signed-Off-By: Nitin A Kamble <nitin.a.kamble@intel.com>
Signed-Off-By: Jun Nakajima <jun.nakajima@intel.com>=20
author kaf24@firebug.cl.cam.ac.uk
date Sat Mar 11 10:47:55 2006 +0100 (2006-03-11)
parents a5a50f6fbc09
children 1f30a0ac3033
files xen/arch/x86/hvm/svm/intr.c xen/arch/x86/hvm/vmx/io.c xen/arch/x86/hvm/vmx/vmx.c xen/include/asm-x86/hvm/support.h xen/include/asm-x86/hvm/vmx/vmx.h
line diff
     1.1 --- a/xen/arch/x86/hvm/svm/intr.c	Sat Mar 11 10:44:48 2006 +0100
     1.2 +++ b/xen/arch/x86/hvm/svm/intr.c	Sat Mar 11 10:47:55 2006 +0100
     1.3 @@ -187,7 +187,7 @@ asmlinkage void svm_intr_assist(void)
     1.4              }
     1.5              /* let's inject this interrupt */
     1.6              TRACE_3D(TRC_VMX_INT, v->domain->domain_id, intr_vector, 0);
     1.7 -            svm_inject_extint(v, intr_vector, VMX_INVALID_ERROR_CODE);
     1.8 +            svm_inject_extint(v, intr_vector, VMX_DELIVER_NO_ERROR_CODE);
     1.9              interrupt_post_injection(v, intr_vector, intr_type);
    1.10              break;
    1.11          case VLAPIC_DELIV_MODE_SMI:
     2.1 --- a/xen/arch/x86/hvm/vmx/io.c	Sat Mar 11 10:44:48 2006 +0100
     2.2 +++ b/xen/arch/x86/hvm/vmx/io.c	Sat Mar 11 10:47:55 2006 +0100
     2.3 @@ -165,7 +165,7 @@ asmlinkage void vmx_intr_assist(void)
     2.4      case VLAPIC_DELIV_MODE_EXT:
     2.5      case VLAPIC_DELIV_MODE_FIXED:
     2.6      case VLAPIC_DELIV_MODE_LPRI:
     2.7 -        vmx_inject_extint(v, highest_vector, VMX_INVALID_ERROR_CODE);
     2.8 +        vmx_inject_extint(v, highest_vector, VMX_DELIVER_NO_ERROR_CODE);
     2.9          TRACE_3D(TRC_VMX_INT, v->domain->domain_id, highest_vector, 0);
    2.10          break;
    2.11      case VLAPIC_DELIV_MODE_SMI:
     3.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Sat Mar 11 10:44:48 2006 +0100
     3.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Sat Mar 11 10:47:55 2006 +0100
     3.3 @@ -1917,7 +1917,7 @@ asmlinkage void vmx_vmexit_handler(struc
     3.4      /* don't bother H/W interrutps */
     3.5      if (exit_reason != EXIT_REASON_EXTERNAL_INTERRUPT &&
     3.6          exit_reason != EXIT_REASON_VMCALL &&
     3.7 -        exit_reason != EXIT_REASON_IO_INSTRUCTION)
     3.8 +        exit_reason != EXIT_REASON_IO_INSTRUCTION) 
     3.9          HVM_DBG_LOG(DBG_LEVEL_0, "exit reason = %x", exit_reason);
    3.10  
    3.11      if (exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY) {
    3.12 @@ -2052,6 +2052,7 @@ asmlinkage void vmx_vmexit_handler(struc
    3.13          __update_guest_eip(inst_len);
    3.14          break;
    3.15      }
    3.16 +#if 0 /* keep this for debugging */
    3.17      case EXIT_REASON_VMCALL:
    3.18          __get_instruction_length(inst_len);
    3.19          __vmread(GUEST_RIP, &eip);
    3.20 @@ -2060,6 +2061,7 @@ asmlinkage void vmx_vmexit_handler(struc
    3.21          hvm_print_line(v, regs.eax); /* provides the current domain */
    3.22          __update_guest_eip(inst_len);
    3.23          break;
    3.24 +#endif
    3.25      case EXIT_REASON_CR_ACCESS:
    3.26      {
    3.27          __vmread(GUEST_RIP, &eip);
    3.28 @@ -2100,6 +2102,21 @@ asmlinkage void vmx_vmexit_handler(struc
    3.29      case EXIT_REASON_MWAIT_INSTRUCTION:
    3.30          __hvm_bug(&regs);
    3.31          break;
    3.32 +    case EXIT_REASON_VMCALL:
    3.33 +    case EXIT_REASON_VMCLEAR:
    3.34 +    case EXIT_REASON_VMLAUNCH:
    3.35 +    case EXIT_REASON_VMPTRLD:
    3.36 +    case EXIT_REASON_VMPTRST:
    3.37 +    case EXIT_REASON_VMREAD:
    3.38 +    case EXIT_REASON_VMRESUME:
    3.39 +    case EXIT_REASON_VMWRITE:
    3.40 +    case EXIT_REASON_VMOFF:
    3.41 +    case EXIT_REASON_VMON:
    3.42 +        /* Report invalid opcode exception when a VMX guest tries to execute 
    3.43 +            any of the VMX instructions */
    3.44 +        vmx_inject_exception(v, TRAP_invalid_op, VMX_DELIVER_NO_ERROR_CODE);
    3.45 +        break;
    3.46 +
    3.47      default:
    3.48          __hvm_bug(&regs);       /* should not happen */
    3.49      }
     4.1 --- a/xen/include/asm-x86/hvm/support.h	Sat Mar 11 10:44:48 2006 +0100
     4.2 +++ b/xen/include/asm-x86/hvm/support.h	Sat Mar 11 10:47:55 2006 +0100
     4.3 @@ -99,7 +99,7 @@ enum hval_bitmaps {
     4.4  
     4.5  #define PC_DEBUG_PORT   0x80
     4.6  
     4.7 -#define VMX_INVALID_ERROR_CODE  -1
     4.8 +#define VMX_DELIVER_NO_ERROR_CODE  -1
     4.9  
    4.10  /*
    4.11   * This works for both 32bit & 64bit eflags filteration
     5.1 --- a/xen/include/asm-x86/hvm/vmx/vmx.h	Sat Mar 11 10:44:48 2006 +0100
     5.2 +++ b/xen/include/asm-x86/hvm/vmx/vmx.h	Sat Mar 11 10:47:55 2006 +0100
     5.3 @@ -119,7 +119,15 @@ extern unsigned int cpu_rev;
     5.4  #define EXIT_REASON_RDPMC               15
     5.5  #define EXIT_REASON_RDTSC               16
     5.6  #define EXIT_REASON_VMCALL              18
     5.7 -
     5.8 +#define EXIT_REASON_VMCLEAR             19
     5.9 +#define EXIT_REASON_VMLAUNCH            20
    5.10 +#define EXIT_REASON_VMPTRLD             21
    5.11 +#define EXIT_REASON_VMPTRST             22
    5.12 +#define EXIT_REASON_VMREAD              23
    5.13 +#define EXIT_REASON_VMRESUME            24
    5.14 +#define EXIT_REASON_VMWRITE             25
    5.15 +#define EXIT_REASON_VMOFF               26
    5.16 +#define EXIT_REASON_VMON                27
    5.17  #define EXIT_REASON_CR_ACCESS           28
    5.18  #define EXIT_REASON_DR_ACCESS           29
    5.19  #define EXIT_REASON_IO_INSTRUCTION      30
    5.20 @@ -425,7 +433,7 @@ static inline int __vmx_inject_exception
    5.21  
    5.22      /* Reflect it back into the guest */
    5.23      intr_fields = (INTR_INFO_VALID_MASK | type | trap);
    5.24 -    if (error_code != VMX_INVALID_ERROR_CODE) {
    5.25 +    if (error_code != VMX_DELIVER_NO_ERROR_CODE) {
    5.26          __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, error_code);
    5.27          intr_fields |= INTR_INFO_DELIEVER_CODE_MASK;
    5.28       }
    5.29 @@ -455,7 +463,7 @@ static inline int vmx_reflect_exception(
    5.30      if (vector & INTR_INFO_DELIEVER_CODE_MASK)
    5.31          __vmread(VM_EXIT_INTR_ERROR_CODE, &error_code);
    5.32      else
    5.33 -        error_code = VMX_INVALID_ERROR_CODE;
    5.34 +        error_code = VMX_DELIVER_NO_ERROR_CODE;
    5.35      vector &= 0xff;
    5.36  
    5.37  #ifndef NDEBUG