ia64/xen-unstable

changeset 14768:f80a97d26276

xen x86/64: Fix int80 direct trap. It must check for events and also
disable interrupts before exiting to guest context.

Also sprinkle about some assertions about interrupt-enable status.

Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Fri Apr 06 15:07:34 2007 +0100 (2007-04-06)
parents bd73cb523111
children f76df7aa0e45
files xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_64/compat/entry.S xen/arch/x86/x86_64/entry.S xen/arch/x86/x86_64/traps.c xen/include/asm-x86/desc.h xen/include/asm-x86/x86_32/asm_defns.h xen/include/asm-x86/x86_64/asm_defns.h
line diff
     1.1 --- a/xen/arch/x86/x86_32/entry.S	Fri Apr 06 14:35:25 2007 +0100
     1.2 +++ b/xen/arch/x86/x86_32/entry.S	Fri Apr 06 15:07:34 2007 +0100
     1.3 @@ -283,6 +283,7 @@ bad_hypercall:
     1.4  /* %edx == trap_bounce, %ebx == struct vcpu                       */
     1.5  /* %eax,%ecx are clobbered. %gs:%esi contain new UREGS_ss/UREGS_esp. */
     1.6  create_bounce_frame:
     1.7 +        ASSERT_INTERRUPTS_ENABLED
     1.8          movl UREGS_eflags+4(%esp),%ecx
     1.9          movb UREGS_cs+4(%esp),%cl
    1.10          testl $(2|X86_EFLAGS_VM),%ecx
     2.1 --- a/xen/arch/x86/x86_64/compat/entry.S	Fri Apr 06 14:35:25 2007 +0100
     2.2 +++ b/xen/arch/x86/x86_64/compat/entry.S	Fri Apr 06 15:07:34 2007 +0100
     2.3 @@ -137,6 +137,7 @@ compat_bad_hypercall:
     2.4  
     2.5  /* %rbx: struct vcpu, interrupts disabled */
     2.6  compat_restore_all_guest:
     2.7 +        ASSERT_INTERRUPTS_DISABLED
     2.8          RESTORE_ALL
     2.9          addq  $8,%rsp
    2.10  .Lft0:  iretq
    2.11 @@ -188,13 +189,14 @@ ENTRY(compat_post_handle_exception)
    2.12  
    2.13  ENTRY(compat_int80_direct_trap)
    2.14          call  compat_create_bounce_frame
    2.15 -        jmp   compat_restore_all_guest
    2.16 +        jmp   compat_test_all_events
    2.17  
    2.18  /* CREATE A BASIC EXCEPTION FRAME ON GUEST OS (RING-1) STACK:            */
    2.19  /*   {[ERRCODE,] EIP, CS, EFLAGS, [ESP, SS]}                             */
    2.20  /* %rdx: trap_bounce, %rbx: struct vcpu                                  */
    2.21  /* On return only %rbx is guaranteed non-clobbered.                      */
    2.22  compat_create_bounce_frame:
    2.23 +        ASSERT_INTERRUPTS_ENABLED
    2.24          mov   %fs,%edi
    2.25          testb $2,UREGS_cs+8(%rsp)
    2.26          jz    1f
     3.1 --- a/xen/arch/x86/x86_64/entry.S	Fri Apr 06 14:35:25 2007 +0100
     3.2 +++ b/xen/arch/x86/x86_64/entry.S	Fri Apr 06 15:07:34 2007 +0100
     3.3 @@ -38,6 +38,7 @@ 1:      call  create_bounce_frame
     3.4  
     3.5  /* %rbx: struct vcpu, interrupts disabled */
     3.6  restore_all_guest:
     3.7 +        ASSERT_INTERRUPTS_DISABLED
     3.8          RESTORE_ALL
     3.9          testw $TRAP_syscall,4(%rsp)
    3.10          jz    iret_exit_to_guest
    3.11 @@ -230,7 +231,7 @@ ENTRY(int80_direct_trap)
    3.12  
    3.13          /* Check that the callback is non-null. */
    3.14          leaq  VCPU_int80_bounce(%rbx),%rdx
    3.15 -        cmp   $0, TRAPBOUNCE_flags(%rdx)
    3.16 +        cmp   $0,TRAPBOUNCE_flags(%rdx)
    3.17          jz    int80_slow_path
    3.18  
    3.19          movq  VCPU_domain(%rbx),%rax
    3.20 @@ -238,7 +239,7 @@ ENTRY(int80_direct_trap)
    3.21          jnz   compat_int80_direct_trap
    3.22  
    3.23          call  create_bounce_frame
    3.24 -        jmp   restore_all_guest
    3.25 +        jmp   test_all_events
    3.26  
    3.27  int80_slow_path:
    3.28          /* 
    3.29 @@ -256,6 +257,7 @@ int80_slow_path:
    3.30  /* %rdx: trap_bounce, %rbx: struct vcpu                           */
    3.31  /* On return only %rbx is guaranteed non-clobbered.                      */
    3.32  create_bounce_frame:
    3.33 +        ASSERT_INTERRUPTS_ENABLED
    3.34          testb $TF_kernel_mode,VCPU_thread_flags(%rbx)
    3.35          jnz   1f
    3.36          /* Push new frame at registered guest-OS stack base. */
     4.1 --- a/xen/arch/x86/x86_64/traps.c	Fri Apr 06 14:35:25 2007 +0100
     4.2 +++ b/xen/arch/x86/x86_64/traps.c	Fri Apr 06 15:07:34 2007 +0100
     4.3 @@ -170,7 +170,8 @@ asmlinkage void do_double_fault(struct c
     4.4             regs->r9,  regs->r10, regs->r11);
     4.5      printk("r12: %016lx   r13: %016lx   r14: %016lx\n",
     4.6             regs->r12, regs->r13, regs->r14);
     4.7 -    printk("r15: %016lx\n", regs->r15);
     4.8 +    printk("r15: %016lx    cs: %016lx    ss: %016lx\n",
     4.9 +           regs->r15, (long)regs->cs, (long)regs->ss);
    4.10      show_stack_overflow(cpu, regs->rsp);
    4.11  
    4.12      panic("DOUBLE FAULT -- system shutdown\n");
    4.13 @@ -260,11 +261,14 @@ void __init percpu_traps_init(void)
    4.14          idt_table[TRAP_double_fault].a |= 1UL << 32; /* IST1 */
    4.15          idt_table[TRAP_nmi].a          |= 2UL << 32; /* IST2 */
    4.16  
    4.17 -#ifdef CONFIG_COMPAT
    4.18 -        /* The hypercall entry vector is only accessible from ring 1. */
    4.19 +        /*
    4.20 +         * The 32-on-64 hypercall entry vector is only accessible from ring 1.
    4.21 +         * Also note that this is a trap gate, not an interrupt gate.
    4.22 +         */
    4.23          _set_gate(idt_table+HYPERCALL_VECTOR, 15, 1, &compat_hypercall);
    4.24 +
    4.25 +        /* Fast trap for int80 (faster than taking the #GP-fixup path). */
    4.26          _set_gate(idt_table+0x80, 15, 3, &int80_direct_trap);
    4.27 -#endif
    4.28      }
    4.29  
    4.30      stack_bottom = (char *)get_stack_bottom();
     5.1 --- a/xen/include/asm-x86/desc.h	Fri Apr 06 14:35:25 2007 +0100
     5.2 +++ b/xen/include/asm-x86/desc.h	Fri Apr 06 15:07:34 2007 +0100
     5.3 @@ -106,7 +106,7 @@
     5.4      ((((sel)>>3) < FIRST_RESERVED_GDT_ENTRY) || /* Guest seg? */        \
     5.5       ((sel) == (!IS_COMPAT(d) ?                                         \
     5.6                  FLAT_KERNEL_CS :                /* Xen default seg? */  \
     5.7 -                FLAT_COMPAT_KERNEL_CS)) ||      /* Xen default compat seg? */  \
     5.8 +                FLAT_COMPAT_KERNEL_CS)) ||                              \
     5.9       ((sel) & 4))                               /* LDT seg? */
    5.10  
    5.11  #endif /* __ASSEMBLY__ */
     6.1 --- a/xen/include/asm-x86/x86_32/asm_defns.h	Fri Apr 06 14:35:25 2007 +0100
     6.2 +++ b/xen/include/asm-x86/x86_32/asm_defns.h	Fri Apr 06 15:07:34 2007 +0100
     6.3 @@ -8,10 +8,20 @@
     6.4  #define SETUP_EXCEPTION_FRAME_POINTER           \
     6.5          movl  %esp,%ebp;                        \
     6.6          notl  %ebp
     6.7 +#define ASSERT_INTERRUPT_STATUS(x)              \
     6.8 +        pushf;                                  \
     6.9 +        testb $X86_EFLAGS_IF>>8,1(%esp);        \
    6.10 +        j##x  1f;                               \
    6.11 +        ud2a;                                   \
    6.12 +1:      addl  $4,%esp;
    6.13  #else
    6.14  #define SETUP_EXCEPTION_FRAME_POINTER
    6.15 +#define ASSERT_INTERRUPT_STATUS(x)
    6.16  #endif
    6.17  
    6.18 +#define ASSERT_INTERRUPTS_ENABLED  ASSERT_INTERRUPT_STATUS(nz)
    6.19 +#define ASSERT_INTERRUPTS_DISABLED ASSERT_INTERRUPT_STATUS(z)
    6.20 +
    6.21  #define __SAVE_ALL_PRE                                  \
    6.22          cld;                                            \
    6.23          pushl %eax;                                     \
     7.1 --- a/xen/include/asm-x86/x86_64/asm_defns.h	Fri Apr 06 14:35:25 2007 +0100
     7.2 +++ b/xen/include/asm-x86/x86_64/asm_defns.h	Fri Apr 06 15:07:34 2007 +0100
     7.3 @@ -8,10 +8,20 @@
     7.4  #define SETUP_EXCEPTION_FRAME_POINTER           \
     7.5          movq  %rsp,%rbp;                        \
     7.6          notq  %rbp
     7.7 +#define ASSERT_INTERRUPT_STATUS(x)              \
     7.8 +        pushf;                                  \
     7.9 +        testb $X86_EFLAGS_IF>>8,1(%rsp);        \
    7.10 +        j##x  1f;                               \
    7.11 +        ud2a;                                   \
    7.12 +1:      addq  $8,%rsp;
    7.13  #else
    7.14  #define SETUP_EXCEPTION_FRAME_POINTER
    7.15 +#define ASSERT_INTERRUPT_STATUS(x)
    7.16  #endif
    7.17  
    7.18 +#define ASSERT_INTERRUPTS_ENABLED  ASSERT_INTERRUPT_STATUS(nz)
    7.19 +#define ASSERT_INTERRUPTS_DISABLED ASSERT_INTERRUPT_STATUS(z)
    7.20 +
    7.21  #define SAVE_ALL                                \
    7.22          cld;                                    \
    7.23          pushq %rdi;                             \