ia64/xen-unstable

changeset 16263:23582bcda6e1

x86: Clean up NMI delivery logic. Allow set_trap_table vector 2 to be
specified as not disabling event delivery, just like any other vector.
Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Mon Oct 29 09:49:39 2007 +0000 (2007-10-29)
parents 63bfed7b662b
children 3bb94bb35dad
files xen/arch/x86/traps.c xen/arch/x86/x86_32/asm-offsets.c xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_64/asm-offsets.c xen/arch/x86/x86_64/compat/entry.S xen/arch/x86/x86_64/compat/traps.c xen/arch/x86/x86_64/entry.S
line diff
     1.1 --- a/xen/arch/x86/traps.c	Mon Oct 29 09:17:38 2007 +0000
     1.2 +++ b/xen/arch/x86/traps.c	Mon Oct 29 09:49:39 2007 +0000
     1.3 @@ -413,6 +413,19 @@ static int do_guest_trap(
     1.4      return 0;
     1.5  }
     1.6  
     1.7 +/*
     1.8 + * Called from asm to set up the NMI trapbounce info.
     1.9 + * Returns 0 if no callback is set up, else 1.
    1.10 + */
    1.11 +asmlinkage int set_guest_nmi_trapbounce(void)
    1.12 +{
    1.13 +    struct vcpu *v = current;
    1.14 +    struct trap_bounce *tb = &v->arch.trap_bounce;
    1.15 +    do_guest_trap(TRAP_nmi, guest_cpu_user_regs(), 0);
    1.16 +    tb->flags &= ~TBF_EXCEPTION; /* not needed for NMI delivery path */
    1.17 +    return !null_trap_bounce(v, tb);
    1.18 +}
    1.19 +
    1.20  static inline int do_trap(
    1.21      int trapnr, struct cpu_user_regs *regs, int use_error_code)
    1.22  {
    1.23 @@ -2706,12 +2719,6 @@ long do_set_trap_table(XEN_GUEST_HANDLE(
    1.24          if ( cur.address == 0 )
    1.25              break;
    1.26  
    1.27 -        if ( (cur.vector == TRAP_nmi) && !TI_GET_IF(&cur) )
    1.28 -        {
    1.29 -            rc = -EINVAL;
    1.30 -            break;
    1.31 -        }
    1.32 -
    1.33          fixup_guest_code_selector(current->domain, cur.cs);
    1.34  
    1.35          memcpy(&dst[cur.vector], &cur, sizeof(cur));
     2.1 --- a/xen/arch/x86/x86_32/asm-offsets.c	Mon Oct 29 09:17:38 2007 +0000
     2.2 +++ b/xen/arch/x86/x86_32/asm-offsets.c	Mon Oct 29 09:49:39 2007 +0000
     2.3 @@ -65,11 +65,6 @@ void __dummy__(void)
     2.4      OFFSET(VCPU_kernel_sp, struct vcpu,
     2.5             arch.guest_context.kernel_sp);
     2.6      OFFSET(VCPU_guest_context_flags, struct vcpu, arch.guest_context.flags);
     2.7 -    OFFSET(VCPU_arch_guest_fpu_ctxt, struct vcpu, arch.guest_context.fpu_ctxt);
     2.8 -    OFFSET(VCPU_nmi_cs, struct vcpu,
     2.9 -           arch.guest_context.trap_ctxt[TRAP_nmi].cs);
    2.10 -    OFFSET(VCPU_nmi_addr, struct vcpu,
    2.11 -           arch.guest_context.trap_ctxt[TRAP_nmi].address);
    2.12      OFFSET(VCPU_nmi_pending, struct vcpu, nmi_pending);
    2.13      OFFSET(VCPU_nmi_masked, struct vcpu, nmi_masked);
    2.14      DEFINE(_VGCF_failsafe_disables_events, _VGCF_failsafe_disables_events);
     3.1 --- a/xen/arch/x86/x86_32/entry.S	Mon Oct 29 09:17:38 2007 +0000
     3.2 +++ b/xen/arch/x86/x86_32/entry.S	Mon Oct 29 09:49:39 2007 +0000
     3.3 @@ -259,18 +259,13 @@ process_softirqs:
     3.4  process_nmi:
     3.5          testb $1,VCPU_nmi_masked(%ebx)
     3.6          jnz  test_guest_events
     3.7 +        sti
     3.8          movb $0,VCPU_nmi_pending(%ebx)
     3.9 -        movzwl VCPU_nmi_cs(%ebx),%eax
    3.10 -        movl VCPU_nmi_addr(%ebx),%ecx
    3.11 +        call set_guest_nmi_trapbounce
    3.12          test %eax,%eax
    3.13 -        jz   test_guest_events
    3.14 +        jz   test_all_events
    3.15          movb $1,VCPU_nmi_masked(%ebx)
    3.16 -        sti
    3.17          leal VCPU_trap_bounce(%ebx),%edx
    3.18 -        movw %ax,TRAPBOUNCE_cs(%edx)
    3.19 -        movl %ecx,TRAPBOUNCE_eip(%edx)
    3.20 -        movw $FLAT_KERNEL_CS,TRAPBOUNCE_cs(%edx)
    3.21 -        movb $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
    3.22          call create_bounce_frame
    3.23          jmp  test_all_events
    3.24  
     4.1 --- a/xen/arch/x86/x86_64/asm-offsets.c	Mon Oct 29 09:17:38 2007 +0000
     4.2 +++ b/xen/arch/x86/x86_64/asm-offsets.c	Mon Oct 29 09:49:39 2007 +0000
     4.3 @@ -86,11 +86,6 @@ void __dummy__(void)
     4.4      OFFSET(VCPU_kernel_sp, struct vcpu, arch.guest_context.kernel_sp);
     4.5      OFFSET(VCPU_kernel_ss, struct vcpu, arch.guest_context.kernel_ss);
     4.6      OFFSET(VCPU_guest_context_flags, struct vcpu, arch.guest_context.flags);
     4.7 -    OFFSET(VCPU_arch_guest_fpu_ctxt, struct vcpu, arch.guest_context.fpu_ctxt);
     4.8 -    OFFSET(VCPU_nmi_cs, struct vcpu,
     4.9 -           arch.guest_context.trap_ctxt[TRAP_nmi].cs);
    4.10 -    OFFSET(VCPU_nmi_addr, struct vcpu,
    4.11 -           arch.guest_context.trap_ctxt[TRAP_nmi].address);
    4.12      OFFSET(VCPU_nmi_pending, struct vcpu, nmi_pending);
    4.13      OFFSET(VCPU_nmi_masked, struct vcpu, nmi_masked);
    4.14      DEFINE(_VGCF_failsafe_disables_events, _VGCF_failsafe_disables_events);
     5.1 --- a/xen/arch/x86/x86_64/compat/entry.S	Mon Oct 29 09:17:38 2007 +0000
     5.2 +++ b/xen/arch/x86/x86_64/compat/entry.S	Mon Oct 29 09:49:39 2007 +0000
     5.3 @@ -133,18 +133,13 @@ compat_process_softirqs:
     5.4  compat_process_nmi:
     5.5          testb $1,VCPU_nmi_masked(%rbx)
     5.6          jnz   compat_test_guest_events
     5.7 +        sti
     5.8          movb  $0,VCPU_nmi_pending(%rbx)
     5.9 -        movzwl VCPU_nmi_cs(%rbx),%eax
    5.10 -        movl  VCPU_nmi_addr(%rbx),%ecx
    5.11 +        call  set_guest_nmi_trapbounce
    5.12          testl %eax,%eax
    5.13 -        jz    compat_test_guest_events
    5.14 +        jz    compat_test_all_events
    5.15          movb  $1,VCPU_nmi_masked(%rbx)
    5.16 -        sti
    5.17          leaq  VCPU_trap_bounce(%rbx),%rdx
    5.18 -        movw  %ax,TRAPBOUNCE_cs(%rdx)
    5.19 -        movl  %ecx,TRAPBOUNCE_eip(%rdx)
    5.20 -        movw  $FLAT_COMPAT_KERNEL_CS,TRAPBOUNCE_cs(%rdx)
    5.21 -        movb  $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
    5.22          call  compat_create_bounce_frame
    5.23          jmp   compat_test_all_events
    5.24  
     6.1 --- a/xen/arch/x86/x86_64/compat/traps.c	Mon Oct 29 09:17:38 2007 +0000
     6.2 +++ b/xen/arch/x86/x86_64/compat/traps.c	Mon Oct 29 09:49:39 2007 +0000
     6.3 @@ -315,12 +315,6 @@ int compat_set_trap_table(XEN_GUEST_HAND
     6.4          if ( cur.address == 0 )
     6.5              break;
     6.6  
     6.7 -        if ( (cur.vector == TRAP_nmi) && !TI_GET_IF(&cur) )
     6.8 -        {
     6.9 -            rc = -EINVAL;
    6.10 -            break;
    6.11 -        }
    6.12 -
    6.13          fixup_guest_code_selector(current->domain, cur.cs);
    6.14  
    6.15          XLAT_trap_info(dst + cur.vector, &cur);
     7.1 --- a/xen/arch/x86/x86_64/entry.S	Mon Oct 29 09:17:38 2007 +0000
     7.2 +++ b/xen/arch/x86/x86_64/entry.S	Mon Oct 29 09:49:39 2007 +0000
     7.3 @@ -235,15 +235,13 @@ process_softirqs:
     7.4  process_nmi:
     7.5          testb $1,VCPU_nmi_masked(%rbx)
     7.6          jnz  test_guest_events
     7.7 +        sti
     7.8          movb $0,VCPU_nmi_pending(%rbx)
     7.9 -        movq VCPU_nmi_addr(%rbx),%rax
    7.10 -        test %rax,%rax
    7.11 -        jz   test_guest_events
    7.12 +        call set_guest_nmi_trapbounce
    7.13 +        test %eax,%eax
    7.14 +        jz   test_all_events
    7.15          movb $1,VCPU_nmi_masked(%rbx)
    7.16 -        sti
    7.17          leaq VCPU_trap_bounce(%rbx),%rdx
    7.18 -        movq %rax,TRAPBOUNCE_eip(%rdx)
    7.19 -        movb $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
    7.20          call create_bounce_frame
    7.21          jmp  test_all_events
    7.22