ia64/xen-unstable

changeset 127:88c1cf85fc8f

bitkeeper revision 1.22.2.4 (3e4300a2YBCCfKhkAv-qMwF-eDVQTQ)

Many files:
Fast application -> guest-OS trap handling (no longer 'bounce' thru ring 0).
author kaf24@labyrinth.cl.cam.ac.uk
date Fri Feb 07 00:41:06 2003 +0000 (2003-02-07)
parents 25df5d63ff28
children 6e6899e5357c
files xen-2.4.16/arch/i386/entry.S xen-2.4.16/arch/i386/i8259.c xen-2.4.16/arch/i386/io_apic.c xen-2.4.16/arch/i386/process.c xen-2.4.16/arch/i386/traps.c xen-2.4.16/include/asm-i386/irq.h xen-2.4.16/include/asm-i386/processor.h xen-2.4.16/include/hypervisor-ifs/hypervisor-if.h xenolinux-2.4.16-sparse/arch/xeno/kernel/traps.c xenolinux-2.4.16-sparse/include/asm-xeno/hypervisor.h
line diff
     1.1 --- a/xen-2.4.16/arch/i386/entry.S	Thu Feb 06 23:40:07 2003 +0000
     1.2 +++ b/xen-2.4.16/arch/i386/entry.S	Fri Feb 07 00:41:06 2003 +0000
     1.3 @@ -527,6 +527,7 @@ ENTRY(hypervisor_call_table)
     1.4          .long SYMBOL_NAME(do_set_debugreg)
     1.5          .long SYMBOL_NAME(do_get_debugreg)
     1.6          .long SYMBOL_NAME(do_update_descriptor)
     1.7 +        .long SYMBOL_NAME(do_set_fast_trap)
     1.8          .rept NR_syscalls-(.-hypervisor_call_table)/4
     1.9          .long SYMBOL_NAME(sys_ni_syscall)
    1.10  	.endr
     2.1 --- a/xen-2.4.16/arch/i386/i8259.c	Thu Feb 06 23:40:07 2003 +0000
     2.2 +++ b/xen-2.4.16/arch/i386/i8259.c	Fri Feb 07 00:41:06 2003 +0000
     2.3 @@ -46,7 +46,7 @@ BUILD_COMMON_IRQ()
     2.4  
     2.5  /*
     2.6   * ISA PIC or low IO-APIC triggered (INTA-cycle or APIC) interrupts:
     2.7 - * (these are usually mapped to vectors 0x20-0x2f)
     2.8 + * (these are usually mapped to vectors 0x30-0x3f)
     2.9   */
    2.10      BUILD_16_IRQS(0x0)
    2.11  
    2.12 @@ -64,7 +64,7 @@ BUILD_COMMON_IRQ()
    2.13      BUILD_16_IRQS(0x1) BUILD_16_IRQS(0x2) BUILD_16_IRQS(0x3)
    2.14      BUILD_16_IRQS(0x4) BUILD_16_IRQS(0x5) BUILD_16_IRQS(0x6) BUILD_16_IRQS(0x7)
    2.15      BUILD_16_IRQS(0x8) BUILD_16_IRQS(0x9) BUILD_16_IRQS(0xa) BUILD_16_IRQS(0xb)
    2.16 -    BUILD_16_IRQS(0xc) BUILD_16_IRQS(0xd)
    2.17 +    BUILD_16_IRQS(0xc)
    2.18  #endif
    2.19  
    2.20  #undef BUILD_16_IRQS
    2.21 @@ -111,7 +111,7 @@ BUILD_COMMON_IRQ()
    2.22          IRQLIST_16(0x1), IRQLIST_16(0x2), IRQLIST_16(0x3),
    2.23  	IRQLIST_16(0x4), IRQLIST_16(0x5), IRQLIST_16(0x6), IRQLIST_16(0x7),
    2.24  	IRQLIST_16(0x8), IRQLIST_16(0x9), IRQLIST_16(0xa), IRQLIST_16(0xb),
    2.25 -	IRQLIST_16(0xc), IRQLIST_16(0xd)
    2.26 +	IRQLIST_16(0xc)
    2.27  #endif
    2.28      };
    2.29  
    2.30 @@ -344,7 +344,7 @@ void __init init_8259A(int auto_eoi)
    2.31       * outb_p - this has to work on a wide range of PC hardware.
    2.32       */
    2.33      outb_p(0x11, 0x20);	/* ICW1: select 8259A-1 init */
    2.34 -    outb_p(0x20 + 0, 0x21);	/* ICW2: 8259A-1 IR0-7 mapped to 0x20-0x27 */
    2.35 +    outb_p(0x30 + 0, 0x21);	/* ICW2: 8259A-1 IR0-7 mapped to 0x30-0x37 */
    2.36      outb_p(0x04, 0x21);	/* 8259A-1 (the master) has a slave on IR2 */
    2.37      if (auto_eoi)
    2.38          outb_p(0x03, 0x21);	/* master does Auto EOI */
    2.39 @@ -352,7 +352,7 @@ void __init init_8259A(int auto_eoi)
    2.40          outb_p(0x01, 0x21);	/* master expects normal EOI */
    2.41  
    2.42      outb_p(0x11, 0xA0);	/* ICW1: select 8259A-2 init */
    2.43 -    outb_p(0x20 + 8, 0xA1);	/* ICW2: 8259A-2 IR0-7 mapped to 0x28-0x2f */
    2.44 +    outb_p(0x30 + 8, 0xA1);	/* ICW2: 8259A-2 IR0-7 mapped to 0x38-0x3f */
    2.45      outb_p(0x02, 0xA1);	/* 8259A-2 is a slave on master's IR2 */
    2.46      outb_p(0x01, 0xA1);	/* (slave's support for AEOI in flat mode
    2.47                             is to be investigated) */
     3.1 --- a/xen-2.4.16/arch/i386/io_apic.c	Thu Feb 06 23:40:07 2003 +0000
     3.2 +++ b/xen-2.4.16/arch/i386/io_apic.c	Fri Feb 07 00:41:06 2003 +0000
     3.3 @@ -495,8 +495,10 @@ static int __init assign_irq_vector(int 
     3.4  		return IO_APIC_VECTOR(irq);
     3.5  next:
     3.6  	current_vector += 8;
     3.7 -	if (current_vector == HYPERVISOR_CALL_VECTOR)
     3.8 -		goto next;
     3.9 +        /* XXX Skip the guestOS -> Xen syscall vector! XXX */
    3.10 +	if (current_vector == HYPERVISOR_CALL_VECTOR) goto next;
    3.11 +        /* XXX Skip the Linux/BSD fast-trap vector! XXX */
    3.12 +        if (current_vector == 0x80) goto next;
    3.13  
    3.14  	if (current_vector > FIRST_SYSTEM_VECTOR) {
    3.15  		offset++;
     4.1 --- a/xen-2.4.16/arch/i386/process.c	Thu Feb 06 23:40:07 2003 +0000
     4.2 +++ b/xen-2.4.16/arch/i386/process.c	Fri Feb 07 00:41:06 2003 +0000
     4.3 @@ -326,6 +326,11 @@ void new_thread(struct task_struct *p,
     4.4  
     4.5      __save_flags(regs->eflags);
     4.6      regs->eflags |= X86_EFLAGS_IF;
     4.7 +
     4.8 +    /* No fast trap at start of day. */
     4.9 +    p->thread.fast_trap_idx    = 0x20;
    4.10 +    p->thread.fast_trap_desc.a = 0;
    4.11 +    p->thread.fast_trap_desc.b = 0;
    4.12  }
    4.13  
    4.14  
    4.15 @@ -363,12 +368,17 @@ void new_thread(struct task_struct *p,
    4.16  /* NB. prev_p passed in %eax, next_p passed in %edx */
    4.17  void __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
    4.18  {
    4.19 +    extern struct desc_struct idt_table[];
    4.20      struct thread_struct *prev = &prev_p->thread,
    4.21          *next = &next_p->thread;
    4.22      struct tss_struct *tss = init_tss + smp_processor_id();
    4.23  
    4.24      unlazy_fpu(prev_p);
    4.25  
    4.26 +    /* Switch the fast-trap handler. */
    4.27 +    CLEAR_FAST_TRAP(&prev_p->thread);
    4.28 +    SET_FAST_TRAP(&next_p->thread);
    4.29 +
    4.30      tss->esp0 = next->esp0;
    4.31      tss->esp1 = next->esp1;
    4.32      tss->ss1  = next->ss1;
     5.1 --- a/xen-2.4.16/arch/i386/traps.c	Thu Feb 06 23:40:07 2003 +0000
     5.2 +++ b/xen-2.4.16/arch/i386/traps.c	Fri Feb 07 00:41:06 2003 +0000
     5.3 @@ -277,20 +277,21 @@ asmlinkage void do_general_protection(st
     5.4       * Cunning trick to allow arbitrary "INT n" handling.
     5.5       * 
     5.6       * We set DPL == 0 on all vectors in the IDT. This prevents any INT <n>
     5.7 -     * instruction from trapping to the appropriate vector, when that might not 
     5.8 +     * instruction from trapping to the appropriate vector, when that might not
     5.9       * be expected by Xen or the guest OS. For example, that entry might be for
    5.10       * a fault handler (unlike traps, faults don't increment EIP), or might
    5.11       * expect an error code on the stack (which a software trap never
    5.12       * provides), or might be a hardware interrupt handler that doesn't like
    5.13 -     * being called spuriously.  
    5.14 +     * being called spuriously.
    5.15       * 
    5.16       * Instead, a GPF occurs with the faulting IDT vector in the error code.
    5.17 -     * Bit 1 is set to indicate that an IDT entry caused the fault.
    5.18 -     * Bit 0 is clear to indicate that it's a software fault, not hardware.
    5.19 +     * Bit 1 is set to indicate that an IDT entry caused the fault. Bit 0 is 
    5.20 +     * clear to indicate that it's a software fault, not hardware.
    5.21       * 
    5.22 -     * NOTE: Vectors 3 and 4 are dealt with from their own handler. This is okay
    5.23 -     * because they can only be triggered by an explicit DPL-checked instruction.
    5.24 -     * The DPL specified by the guest OS for these vectors is NOT CHECKED!!
    5.25 +     * NOTE: Vectors 3 and 4 are dealt with from their own handler. This is
    5.26 +     * okay because they can only be triggered by an explicit DPL-checked
    5.27 +     * instruction. The DPL specified by the guest OS for these vectors is NOT
    5.28 +     * CHECKED!!
    5.29       */
    5.30      if ( (error_code & 3) == 2 )
    5.31      {
    5.32 @@ -298,6 +299,7 @@ asmlinkage void do_general_protection(st
    5.33          ti = current->thread.traps + (error_code>>3);
    5.34          if ( ti->dpl >= (regs->xcs & 3) )
    5.35          {
    5.36 +            if ( (error_code>>3)==0x80 ) { printk("!!!\n"); BUG(); }
    5.37              gtb->flags = GTBF_TRAP_NOCODE;
    5.38              gtb->cs    = ti->cs;
    5.39              gtb->eip   = ti->address;
    5.40 @@ -570,6 +572,43 @@ long do_set_trap_table(trap_info_t *trap
    5.41  }
    5.42  
    5.43  
    5.44 +long do_set_fast_trap(int idx)
    5.45 +{
    5.46 +    trap_info_t *ti;
    5.47 +
    5.48 +    /* Index 0 is special: it disables fast traps. */
    5.49 +    if ( idx == 0 )
    5.50 +    {
    5.51 +        CLEAR_FAST_TRAP(&current->thread);
    5.52 +        memset(idt_table+current->thread.fast_trap_idx, 0, 8);
    5.53 +        current->thread.fast_trap_idx    = 0x20;
    5.54 +        current->thread.fast_trap_desc.a = 0;
    5.55 +        current->thread.fast_trap_desc.b = 0;
    5.56 +        return 0;
    5.57 +    }
    5.58 +
    5.59 +    /*
    5.60 +     * We only fast-trap vectors 0x20-0x2f, and vector 0x80.
    5.61 +     * The former range is used by Windows and MS-DOS.
    5.62 +     * Vector 0x80 is used by Linux and the BSD variants.
    5.63 +     */
    5.64 +    if ( (idx != 0x80) && ((idx < 0x20) || (idx > 0x2f)) ) return -1;
    5.65 +
    5.66 +    ti = current->thread.traps + idx;
    5.67 +
    5.68 +    CLEAR_FAST_TRAP(&current->thread);
    5.69 +
    5.70 +    current->thread.fast_trap_idx    = idx;
    5.71 +    current->thread.fast_trap_desc.a = (ti->cs << 16) | (ti->address & 0xffff);
    5.72 +    current->thread.fast_trap_desc.b = 
    5.73 +        (ti->address & 0xffff0000) | 0x8f00 | (ti->dpl&3)<<13;
    5.74 +
    5.75 +    SET_FAST_TRAP(&current->thread);
    5.76 +
    5.77 +    return 0;
    5.78 +}
    5.79 +
    5.80 +
    5.81  long do_fpu_taskswitch(void)
    5.82  {
    5.83      current->flags |= PF_GUEST_STTS;
     6.1 --- a/xen-2.4.16/include/asm-i386/irq.h	Thu Feb 06 23:40:07 2003 +0000
     6.2 +++ b/xen-2.4.16/include/asm-i386/irq.h	Fri Feb 07 00:41:06 2003 +0000
     6.3 @@ -10,8 +10,6 @@
     6.4  #define SA_SHIRQ        0x04000000
     6.5  
     6.6  #define TIMER_IRQ 0
     6.7 -/* 256 in architecture, minus 16 allocated to processor. */
     6.8 -#define NR_IRQS 224
     6.9  
    6.10  extern void disable_irq(unsigned int);
    6.11  extern void disable_irq_nosync(unsigned int);
    6.12 @@ -21,14 +19,14 @@ extern void enable_irq(unsigned int);
    6.13   * IDT vectors usable for external interrupt sources start
    6.14   * at 0x20:
    6.15   */
    6.16 -#define FIRST_EXTERNAL_VECTOR	0x20
    6.17 +#define FIRST_EXTERNAL_VECTOR	0x30
    6.18  
    6.19 -#define SYSCALL_VECTOR		0x80   /* application -> OS     */
    6.20 -#define KDBENTER_VECTOR		0x81   /* anyone      -> KDB    */
    6.21 -#define HYPERVISOR_CALL_VECTOR	0x82   /* OS          -> monitor*/
    6.22 +#define NR_IRQS (256 - FIRST_EXTERNAL_VECTOR)
    6.23 +
    6.24 +#define HYPERVISOR_CALL_VECTOR	0x82
    6.25  
    6.26  /*
    6.27 - * Vectors 0x20-0x2f are used for ISA interrupts.
    6.28 + * Vectors 0x30-0x3f are used for ISA interrupts.
    6.29   */
    6.30  
    6.31  /*
    6.32 @@ -55,11 +53,11 @@ extern void enable_irq(unsigned int);
    6.33  #define LOCAL_TIMER_VECTOR	0xef
    6.34  
    6.35  /*
    6.36 - * First APIC vector available to drivers: (vectors 0x30-0xee)
    6.37 - * we start at 0x31 to spread out vectors evenly between priority
    6.38 - * levels. (0x80 is the syscall vector)
    6.39 + * First APIC vector available to drivers: (vectors 0x40-0xee)
    6.40 + * we start at 0x41 to spread out vectors evenly between priority
    6.41 + * levels. (0x82 is the syscall vector)
    6.42   */
    6.43 -#define FIRST_DEVICE_VECTOR	0x31
    6.44 +#define FIRST_DEVICE_VECTOR	0x41
    6.45  #define FIRST_SYSTEM_VECTOR	0xef
    6.46  
    6.47  extern int irq_vector[NR_IRQS];
     7.1 --- a/xen-2.4.16/include/asm-i386/processor.h	Thu Feb 06 23:40:07 2003 +0000
     7.2 +++ b/xen-2.4.16/include/asm-i386/processor.h	Fri Feb 07 00:41:06 2003 +0000
     7.3 @@ -10,6 +10,7 @@
     7.4  #include <asm/page.h>
     7.5  #include <asm/types.h>
     7.6  #include <asm/cpufeature.h>
     7.7 +#include <asm/desc.h>
     7.8  #include <xeno/config.h>
     7.9  #include <hypervisor-ifs/hypervisor-if.h>
    7.10  
    7.11 @@ -352,15 +353,23 @@ struct thread_struct {
    7.12  /* floating point info */
    7.13      union i387_union	i387;
    7.14  /* Trap info. */
    7.15 +    int                 fast_trap_idx;
    7.16 +    struct desc_struct  fast_trap_desc;
    7.17      trap_info_t         traps[256];
    7.18  };
    7.19  
    7.20 +#define CLEAR_FAST_TRAP(_p) \
    7.21 +    (memset(idt_table + (_p)->fast_trap_idx, 0, 8))
    7.22 +#define SET_FAST_TRAP(_p)   \
    7.23 +    (memcpy(idt_table + (_p)->fast_trap_idx, &((_p)->fast_trap_desc), 8))
    7.24 +
    7.25  #define INIT_THREAD  {						\
    7.26  	sizeof(idle0_stack) + (long) &idle0_stack, /* esp0 */   \
    7.27  	0, 0, 0, 0, 0, 0,		      			\
    7.28  	{ [0 ... 7] = 0 },	/* debugging registers */	\
    7.29  	0, 0, 0,						\
    7.30  	{ { 0, }, },		/* 387 state */			\
    7.31 +	0, { 0, 0 },						\
    7.32  	{ {0} }			/* io permissions */		\
    7.33  }
    7.34  
     8.1 --- a/xen-2.4.16/include/hypervisor-ifs/hypervisor-if.h	Thu Feb 06 23:40:07 2003 +0000
     8.2 +++ b/xen-2.4.16/include/hypervisor-ifs/hypervisor-if.h	Fri Feb 07 00:41:06 2003 +0000
     8.3 @@ -88,6 +88,7 @@ typedef struct
     8.4  #define __HYPERVISOR_set_debugreg         11
     8.5  #define __HYPERVISOR_get_debugreg         12
     8.6  #define __HYPERVISOR_update_descriptor    13
     8.7 +#define __HYPERVISOR_set_fast_trap        14
     8.8  
     8.9  #define TRAP_INSTR "int $0x82"
    8.10  
     9.1 --- a/xenolinux-2.4.16-sparse/arch/xeno/kernel/traps.c	Thu Feb 06 23:40:07 2003 +0000
     9.2 +++ b/xenolinux-2.4.16-sparse/arch/xeno/kernel/traps.c	Fri Feb 07 00:41:06 2003 +0000
     9.3 @@ -562,5 +562,6 @@ static trap_info_t trap_table[] = {
     9.4  void __init trap_init(void)
     9.5  {
     9.6      HYPERVISOR_set_trap_table(trap_table);    
     9.7 +    HYPERVISOR_set_fast_trap(SYSCALL_VECTOR);
     9.8      cpu_init();
     9.9  }
    10.1 --- a/xenolinux-2.4.16-sparse/include/asm-xeno/hypervisor.h	Thu Feb 06 23:40:07 2003 +0000
    10.2 +++ b/xenolinux-2.4.16-sparse/include/asm-xeno/hypervisor.h	Fri Feb 07 00:41:06 2003 +0000
    10.3 @@ -288,6 +288,16 @@ static inline int HYPERVISOR_update_desc
    10.4          : "=a" (ret) : "0" (__HYPERVISOR_set_gdt), 
    10.5          "b" (pa), "c" (word1), "d" (word2) );
    10.6  
    10.7 +    return ret;
    10.8 +}
    10.9 +
   10.10 +static inline int HYPERVISOR_set_fast_trap(int idx)
   10.11 +{
   10.12 +    int ret;
   10.13 +    __asm__ __volatile__ (
   10.14 +        TRAP_INSTR
   10.15 +        : "=a" (ret) : "0" (__HYPERVISOR_set_fast_trap), 
   10.16 +        "b" (idx) );
   10.17  
   10.18      return ret;
   10.19  }