ia64/xen-unstable

changeset 18787:7be8e7eefbd7

vmx: Clean up exception delivery logic.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Nov 11 11:35:00 2008 +0000 (2008-11-11)
parents 7e8db19d72a5
children 07d0be88571f
files xen/arch/x86/hvm/vmx/intr.c xen/arch/x86/hvm/vmx/vmx.c xen/arch/x86/hvm/vmx/vpmu_core2.c xen/include/asm-x86/hvm/vmx/vmx.h
line diff
     1.1 --- a/xen/arch/x86/hvm/vmx/intr.c	Tue Nov 11 11:13:57 2008 +0000
     1.2 +++ b/xen/arch/x86/hvm/vmx/intr.c	Tue Nov 11 11:35:00 2008 +0000
     1.3 @@ -140,12 +140,12 @@ asmlinkage void vmx_intr_assist(void)
     1.4  
     1.5      if ( intack.source == hvm_intsrc_nmi )
     1.6      {
     1.7 -        vmx_inject_nmi(v);
     1.8 +        vmx_inject_nmi();
     1.9      }
    1.10      else
    1.11      {
    1.12          HVMTRACE_2D(INJ_VIRQ, intack.vector, /*fake=*/ 0);
    1.13 -        vmx_inject_extint(v, intack.vector);
    1.14 +        vmx_inject_extint(intack.vector);
    1.15          pt_intr_post(v, intack);
    1.16      }
    1.17  
     2.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Tue Nov 11 11:13:57 2008 +0000
     2.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Tue Nov 11 11:35:00 2008 +0000
     2.3 @@ -187,7 +187,7 @@ static enum handler_return long_mode_do_
     2.4      check_long_mode:
     2.5          if ( !(hvm_long_mode_enabled(v)) )
     2.6          {
     2.7 -            vmx_inject_hw_exception(v, TRAP_gp_fault, 0);
     2.8 +            vmx_inject_hw_exception(TRAP_gp_fault, 0);
     2.9              return HNDL_exception_raised;
    2.10          }
    2.11          break;
    2.12 @@ -284,7 +284,7 @@ static enum handler_return long_mode_do_
    2.13   uncanonical_address:
    2.14      HVM_DBG_LOG(DBG_LEVEL_0, "Not cano address of msr write %x", ecx);
    2.15   gp_fault:
    2.16 -    vmx_inject_hw_exception(v, TRAP_gp_fault, 0);
    2.17 +    vmx_inject_hw_exception(TRAP_gp_fault, 0);
    2.18   exception_raised:
    2.19      return HNDL_exception_raised;
    2.20  }
    2.21 @@ -1094,8 +1094,7 @@ void ept_sync_domain(struct domain *d)
    2.22      }
    2.23  }
    2.24  
    2.25 -static void __vmx_inject_exception(
    2.26 -    struct vcpu *v, int trap, int type, int error_code)
    2.27 +static void __vmx_inject_exception(int trap, int type, int error_code)
    2.28  {
    2.29      unsigned long intr_fields;
    2.30  
    2.31 @@ -1114,15 +1113,9 @@ static void __vmx_inject_exception(
    2.32      }
    2.33  
    2.34      __vmwrite(VM_ENTRY_INTR_INFO, intr_fields);
    2.35 -
    2.36 -    if ( trap == TRAP_page_fault )
    2.37 -        HVMTRACE_LONG_2D(PF_INJECT, error_code,
    2.38 -            TRC_PAR_LONG(v->arch.hvm_vcpu.guest_cr[2]));
    2.39 -    else
    2.40 -        HVMTRACE_2D(INJ_EXC, trap, error_code);
    2.41  }
    2.42  
    2.43 -void vmx_inject_hw_exception(struct vcpu *v, int trap, int error_code)
    2.44 +void vmx_inject_hw_exception(int trap, int error_code)
    2.45  {
    2.46      unsigned long intr_info = __vmread(VM_ENTRY_INTR_INFO);
    2.47  
    2.48 @@ -1134,37 +1127,41 @@ void vmx_inject_hw_exception(struct vcpu
    2.49              error_code = 0;
    2.50      }
    2.51  
    2.52 -    __vmx_inject_exception(v, trap, X86_EVENTTYPE_HW_EXCEPTION, error_code);
    2.53 +    __vmx_inject_exception(trap, X86_EVENTTYPE_HW_EXCEPTION, error_code);
    2.54 +
    2.55 +    if ( trap == TRAP_page_fault )
    2.56 +        HVMTRACE_LONG_2D(PF_INJECT, error_code,
    2.57 +                         TRC_PAR_LONG(current->arch.hvm_vcpu.guest_cr[2]));
    2.58 +    else
    2.59 +        HVMTRACE_2D(INJ_EXC, trap, error_code);
    2.60 +
    2.61 +    if ( (trap == TRAP_debug) &&
    2.62 +         (guest_cpu_user_regs()->eflags & X86_EFLAGS_TF) )
    2.63 +    {
    2.64 +        __restore_debug_registers(current);
    2.65 +        write_debugreg(6, read_debugreg(6) | 0x4000);
    2.66 +    }
    2.67  }
    2.68  
    2.69 -void vmx_inject_extint(struct vcpu *v, int trap)
    2.70 +void vmx_inject_extint(int trap)
    2.71  {
    2.72 -    __vmx_inject_exception(v, trap, X86_EVENTTYPE_EXT_INTR,
    2.73 +    __vmx_inject_exception(trap, X86_EVENTTYPE_EXT_INTR,
    2.74                             HVM_DELIVER_NO_ERROR_CODE);
    2.75  }
    2.76  
    2.77 -void vmx_inject_nmi(struct vcpu *v)
    2.78 +void vmx_inject_nmi(void)
    2.79  {
    2.80 -    __vmx_inject_exception(v, 2, X86_EVENTTYPE_NMI,
    2.81 +    __vmx_inject_exception(2, X86_EVENTTYPE_NMI,
    2.82                             HVM_DELIVER_NO_ERROR_CODE);
    2.83  }
    2.84  
    2.85  static void vmx_inject_exception(
    2.86      unsigned int trapnr, int errcode, unsigned long cr2)
    2.87  {
    2.88 -    struct vcpu *curr = current;
    2.89 -
    2.90 -    vmx_inject_hw_exception(curr, trapnr, errcode);
    2.91 -
    2.92      if ( trapnr == TRAP_page_fault )
    2.93 -        curr->arch.hvm_vcpu.guest_cr[2] = cr2;
    2.94 +        current->arch.hvm_vcpu.guest_cr[2] = cr2;
    2.95  
    2.96 -    if ( (trapnr == TRAP_debug) &&
    2.97 -         (guest_cpu_user_regs()->eflags & X86_EFLAGS_TF) )
    2.98 -    {
    2.99 -        __restore_debug_registers(curr);
   2.100 -        write_debugreg(6, read_debugreg(6) | 0x4000);
   2.101 -    }
   2.102 +    vmx_inject_hw_exception(trapnr, errcode);
   2.103  }
   2.104  
   2.105  static int vmx_event_pending(struct vcpu *v)
   2.106 @@ -1315,7 +1312,7 @@ static void __update_guest_eip(unsigned 
   2.107      }
   2.108  
   2.109      if ( regs->eflags & X86_EFLAGS_TF )
   2.110 -        vmx_inject_exception(TRAP_debug, HVM_DELIVER_NO_ERROR_CODE, 0);
   2.111 +        vmx_inject_hw_exception(TRAP_debug, HVM_DELIVER_NO_ERROR_CODE);
   2.112  }
   2.113  
   2.114  static void vmx_fpu_dirty_intercept(void)
   2.115 @@ -1636,7 +1633,6 @@ static int vmx_msr_read_intercept(struct
   2.116  {
   2.117      u64 msr_content = 0;
   2.118      u32 ecx = regs->ecx, eax, edx;
   2.119 -    struct vcpu *v = current;
   2.120  
   2.121      HVM_DBG_LOG(DBG_LEVEL_1, "ecx=%x", ecx);
   2.122  
   2.123 @@ -1712,7 +1708,7 @@ done:
   2.124      return X86EMUL_OKAY;
   2.125  
   2.126  gp_fault:
   2.127 -    vmx_inject_hw_exception(v, TRAP_gp_fault, 0);
   2.128 +    vmx_inject_hw_exception(TRAP_gp_fault, 0);
   2.129      return X86EMUL_EXCEPTION;
   2.130  }
   2.131  
   2.132 @@ -1849,7 +1845,7 @@ static int vmx_msr_write_intercept(struc
   2.133  
   2.134          if ( (rc < 0) ||
   2.135               (vmx_add_host_load_msr(ecx) < 0) )
   2.136 -            vmx_inject_hw_exception(v, TRAP_machine_check, 0);
   2.137 +            vmx_inject_hw_exception(TRAP_machine_check, 0);
   2.138          else
   2.139          {
   2.140              __vmwrite(GUEST_IA32_DEBUGCTL, msr_content);
   2.141 @@ -1889,7 +1885,7 @@ static int vmx_msr_write_intercept(struc
   2.142      return X86EMUL_OKAY;
   2.143  
   2.144  gp_fault:
   2.145 -    vmx_inject_hw_exception(v, TRAP_gp_fault, 0);
   2.146 +    vmx_inject_hw_exception(TRAP_gp_fault, 0);
   2.147      return X86EMUL_EXCEPTION;
   2.148  }
   2.149  
   2.150 @@ -2197,7 +2193,7 @@ asmlinkage void vmx_vmexit_handler(struc
   2.151              }
   2.152  
   2.153              v->arch.hvm_vcpu.guest_cr[2] = exit_qualification;
   2.154 -            vmx_inject_hw_exception(v, TRAP_page_fault, regs->error_code);
   2.155 +            vmx_inject_hw_exception(TRAP_page_fault, regs->error_code);
   2.156              break;
   2.157          case TRAP_nmi:
   2.158              if ( (intr_info & INTR_INFO_INTR_TYPE_MASK) !=
   2.159 @@ -2317,7 +2313,7 @@ asmlinkage void vmx_vmexit_handler(struc
   2.160      case EXIT_REASON_VMWRITE:
   2.161      case EXIT_REASON_VMXOFF:
   2.162      case EXIT_REASON_VMXON:
   2.163 -        vmx_inject_hw_exception(v, TRAP_invalid_op, HVM_DELIVER_NO_ERROR_CODE);
   2.164 +        vmx_inject_hw_exception(TRAP_invalid_op, HVM_DELIVER_NO_ERROR_CODE);
   2.165          break;
   2.166  
   2.167      case EXIT_REASON_TPR_BELOW_THRESHOLD:
   2.168 @@ -2326,7 +2322,7 @@ asmlinkage void vmx_vmexit_handler(struc
   2.169      case EXIT_REASON_IO_INSTRUCTION:
   2.170      case EXIT_REASON_APIC_ACCESS:
   2.171          if ( !handle_mmio() )
   2.172 -            hvm_inject_exception(TRAP_gp_fault, 0, 0);
   2.173 +            vmx_inject_hw_exception(TRAP_gp_fault, 0);
   2.174          break;
   2.175  
   2.176      case EXIT_REASON_INVD:
     3.1 --- a/xen/arch/x86/hvm/vmx/vpmu_core2.c	Tue Nov 11 11:13:57 2008 +0000
     3.2 +++ b/xen/arch/x86/hvm/vmx/vpmu_core2.c	Tue Nov 11 11:35:00 2008 +0000
     3.3 @@ -335,7 +335,7 @@ static int core2_vpmu_do_wrmsr(struct cp
     3.4      case MSR_CORE_PERF_GLOBAL_STATUS:
     3.5          gdprintk(XENLOG_INFO, "Can not write readonly MSR: "
     3.6                   "MSR_PERF_GLOBAL_STATUS(0x38E)!\n");
     3.7 -        vmx_inject_hw_exception(current, TRAP_gp_fault, 0);
     3.8 +        vmx_inject_hw_exception(TRAP_gp_fault, 0);
     3.9          return 1;
    3.10      case MSR_IA32_PEBS_ENABLE:
    3.11          if ( msr_content & 1 )
     4.1 --- a/xen/include/asm-x86/hvm/vmx/vmx.h	Tue Nov 11 11:13:57 2008 +0000
     4.2 +++ b/xen/include/asm-x86/hvm/vmx/vmx.h	Tue Nov 11 11:35:00 2008 +0000
     4.3 @@ -351,9 +351,9 @@ static inline int __vmxon(u64 addr)
     4.4      return rc;
     4.5  }
     4.6  
     4.7 -void vmx_inject_hw_exception(struct vcpu *v, int trap, int error_code);
     4.8 -void vmx_inject_extint(struct vcpu *v, int trap);
     4.9 -void vmx_inject_nmi(struct vcpu *v);
    4.10 +void vmx_inject_hw_exception(int trap, int error_code);
    4.11 +void vmx_inject_extint(int trap);
    4.12 +void vmx_inject_nmi(void);
    4.13  
    4.14  void ept_p2m_init(struct domain *d);
    4.15