ia64/xen-unstable

changeset 18788:07d0be88571f

hvm: fix single stepping on debugger

The debuggee domain will die with unexpected trap
on single stepping of emulated instruction.

Signed-off-by: Kouya Shimura <kouya@jp.fujitsu.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Nov 11 11:47:03 2008 +0000 (2008-11-11)
parents 7be8e7eefbd7
children 2bd99c5faa42
files xen/arch/x86/hvm/svm/svm.c xen/arch/x86/hvm/vmx/realmode.c xen/arch/x86/hvm/vmx/vmx.c
line diff
     1.1 --- a/xen/arch/x86/hvm/svm/svm.c	Tue Nov 11 11:35:00 2008 +0000
     1.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Tue Nov 11 11:47:03 2008 +0000
     1.3 @@ -739,6 +739,23 @@ static void svm_inject_exception(
     1.4      struct vmcb_struct *vmcb = curr->arch.hvm_svm.vmcb;
     1.5      eventinj_t event = vmcb->eventinj;
     1.6  
     1.7 +    switch ( trapnr )
     1.8 +    {
     1.9 +    case TRAP_debug:
    1.10 +        if ( guest_cpu_user_regs()->eflags & X86_EFLAGS_TF )
    1.11 +        {
    1.12 +            __restore_debug_registers(curr);
    1.13 +            vmcb->dr6 |= 0x4000;
    1.14 +        }
    1.15 +    case TRAP_int3:
    1.16 +        if ( curr->domain->debugger_attached )
    1.17 +        {
    1.18 +            /* Debug/Int3: Trap to debugger. */
    1.19 +            domain_pause_for_debugger();
    1.20 +            return;
    1.21 +        }
    1.22 +    }
    1.23 +
    1.24      if ( unlikely(event.fields.v) &&
    1.25           (event.fields.type == X86_EVENTTYPE_HW_EXCEPTION) )
    1.26      {
    1.27 @@ -765,13 +782,6 @@ static void svm_inject_exception(
    1.28      {
    1.29          HVMTRACE_2D(INJ_EXC, trapnr, errcode);
    1.30      }
    1.31 -
    1.32 -    if ( (trapnr == TRAP_debug) &&
    1.33 -         (guest_cpu_user_regs()->eflags & X86_EFLAGS_TF) )
    1.34 -    {
    1.35 -        __restore_debug_registers(curr);
    1.36 -        vmcb->dr6 |= 0x4000;
    1.37 -    }
    1.38  }
    1.39  
    1.40  static int svm_event_pending(struct vcpu *v)
     2.1 --- a/xen/arch/x86/hvm/vmx/realmode.c	Tue Nov 11 11:35:00 2008 +0000
     2.2 +++ b/xen/arch/x86/hvm/vmx/realmode.c	Tue Nov 11 11:47:03 2008 +0000
     2.3 @@ -149,17 +149,25 @@ static void realmode_emulate_one(struct 
     2.4              hvmemul_ctxt->exn_insn_len = 0;
     2.5          }
     2.6  
     2.7 -        if ( curr->arch.hvm_vcpu.guest_cr[0] & X86_CR0_PE )
     2.8 +        if ( unlikely(curr->domain->debugger_attached) &&
     2.9 +             ((hvmemul_ctxt->exn_vector == TRAP_debug) ||
    2.10 +              (hvmemul_ctxt->exn_vector == TRAP_int3)) )
    2.11 +        {
    2.12 +            domain_pause_for_debugger();
    2.13 +        }
    2.14 +        else if ( curr->arch.hvm_vcpu.guest_cr[0] & X86_CR0_PE )
    2.15          {
    2.16              gdprintk(XENLOG_ERR, "Exception %02x in protected mode.\n",
    2.17                       hvmemul_ctxt->exn_vector);
    2.18              goto fail;
    2.19          }
    2.20 -
    2.21 -        realmode_deliver_exception(
    2.22 -            hvmemul_ctxt->exn_vector,
    2.23 -            hvmemul_ctxt->exn_insn_len,
    2.24 -            hvmemul_ctxt);
    2.25 +        else
    2.26 +        {
    2.27 +            realmode_deliver_exception(
    2.28 +                hvmemul_ctxt->exn_vector,
    2.29 +                hvmemul_ctxt->exn_insn_len,
    2.30 +                hvmemul_ctxt);
    2.31 +        }
    2.32      }
    2.33  
    2.34      return;
     3.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Tue Nov 11 11:35:00 2008 +0000
     3.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Tue Nov 11 11:47:03 2008 +0000
     3.3 @@ -1118,6 +1118,24 @@ static void __vmx_inject_exception(int t
     3.4  void vmx_inject_hw_exception(int trap, int error_code)
     3.5  {
     3.6      unsigned long intr_info = __vmread(VM_ENTRY_INTR_INFO);
     3.7 +    struct vcpu *curr = current;
     3.8 +
     3.9 +    switch ( trap )
    3.10 +    {
    3.11 +    case TRAP_debug:
    3.12 +        if ( guest_cpu_user_regs()->eflags & X86_EFLAGS_TF )
    3.13 +        {
    3.14 +            __restore_debug_registers(curr);
    3.15 +            write_debugreg(6, read_debugreg(6) | 0x4000);
    3.16 +        }
    3.17 +    case TRAP_int3:
    3.18 +        if ( curr->domain->debugger_attached )
    3.19 +        {
    3.20 +            /* Debug/Int3: Trap to debugger. */
    3.21 +            domain_pause_for_debugger();
    3.22 +            return;
    3.23 +        }
    3.24 +    }
    3.25  
    3.26      if ( unlikely(intr_info & INTR_INFO_VALID_MASK) &&
    3.27           (((intr_info >> 8) & 7) == X86_EVENTTYPE_HW_EXCEPTION) )
    3.28 @@ -1134,13 +1152,6 @@ void vmx_inject_hw_exception(int trap, i
    3.29                           TRC_PAR_LONG(current->arch.hvm_vcpu.guest_cr[2]));
    3.30      else
    3.31          HVMTRACE_2D(INJ_EXC, trap, error_code);
    3.32 -
    3.33 -    if ( (trap == TRAP_debug) &&
    3.34 -         (guest_cpu_user_regs()->eflags & X86_EFLAGS_TF) )
    3.35 -    {
    3.36 -        __restore_debug_registers(current);
    3.37 -        write_debugreg(6, read_debugreg(6) | 0x4000);
    3.38 -    }
    3.39  }
    3.40  
    3.41  void vmx_inject_extint(int trap)