ia64/xen-unstable

changeset 16277:4b4c75cb6c0f

x86: cache current vcpu in some trap-handling functions.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir@xensource.com>
date Tue Oct 30 11:05:36 2007 +0000 (2007-10-30)
parents 007ff84be506
children 4687dc12f1af
files xen/arch/x86/traps.c
line diff
     1.1 --- a/xen/arch/x86/traps.c	Tue Oct 30 10:39:52 2007 +0000
     1.2 +++ b/xen/arch/x86/traps.c	Tue Oct 30 11:05:36 2007 +0000
     1.3 @@ -128,12 +128,13 @@ boolean_param("ler", opt_ler);
     1.4  static void show_guest_stack(struct cpu_user_regs *regs)
     1.5  {
     1.6      int i;
     1.7 +    struct vcpu *curr = current;
     1.8      unsigned long *stack, addr;
     1.9  
    1.10 -    if ( is_hvm_vcpu(current) )
    1.11 +    if ( is_hvm_vcpu(curr) )
    1.12          return;
    1.13  
    1.14 -    if ( is_pv_32on64_vcpu(current) )
    1.15 +    if ( is_pv_32on64_vcpu(curr) )
    1.16      {
    1.17          compat_show_guest_stack(regs, debug_stack_lines);
    1.18          return;
    1.19 @@ -800,12 +801,13 @@ void propagate_page_fault(unsigned long 
    1.20  static int handle_gdt_ldt_mapping_fault(
    1.21      unsigned long offset, struct cpu_user_regs *regs)
    1.22  {
    1.23 +    struct vcpu *curr = current;
    1.24      /* Which vcpu's area did we fault in, and is it in the ldt sub-area? */
    1.25      unsigned int is_ldt_area = (offset >> (GDT_LDT_VCPU_VA_SHIFT-1)) & 1;
    1.26      unsigned int vcpu_area   = (offset >> GDT_LDT_VCPU_VA_SHIFT);
    1.27  
    1.28      /* Should never fault in another vcpu's area. */
    1.29 -    BUG_ON(vcpu_area != current->vcpu_id);
    1.30 +    BUG_ON(vcpu_area != curr->vcpu_id);
    1.31  
    1.32      /* Byte offset within the gdt/ldt sub-area. */
    1.33      offset &= (1UL << (GDT_LDT_VCPU_VA_SHIFT-1)) - 1UL;
    1.34 @@ -826,7 +828,7 @@ static int handle_gdt_ldt_mapping_fault(
    1.35                  return 0;
    1.36              /* In guest mode? Propagate #PF to guest, with adjusted %cr2. */
    1.37              propagate_page_fault(
    1.38 -                current->arch.guest_context.ldt_base + offset,
    1.39 +                curr->arch.guest_context.ldt_base + offset,
    1.40                  regs->error_code);
    1.41          }
    1.42      }
    1.43 @@ -2472,14 +2474,16 @@ void unset_nmi_callback(void)
    1.44  
    1.45  asmlinkage int do_device_not_available(struct cpu_user_regs *regs)
    1.46  {
    1.47 +    struct vcpu *curr = current;
    1.48 +
    1.49      BUG_ON(!guest_mode(regs));
    1.50  
    1.51 -    setup_fpu(current);
    1.52 +    setup_fpu(curr);
    1.53  
    1.54 -    if ( current->arch.guest_context.ctrlreg[0] & X86_CR0_TS )
    1.55 +    if ( curr->arch.guest_context.ctrlreg[0] & X86_CR0_TS )
    1.56      {
    1.57          do_guest_trap(TRAP_no_device, regs, 0);
    1.58 -        current->arch.guest_context.ctrlreg[0] &= ~X86_CR0_TS;
    1.59 +        curr->arch.guest_context.ctrlreg[0] &= ~X86_CR0_TS;
    1.60      }
    1.61      else
    1.62          TRACE_0D(TRC_PV_MATH_STATE_RESTORE);
    1.63 @@ -2660,7 +2664,7 @@ void __init trap_init(void)
    1.64  long register_guest_nmi_callback(unsigned long address)
    1.65  {
    1.66      struct vcpu *v = current;
    1.67 -    struct domain *d = current->domain;
    1.68 +    struct domain *d = v->domain;
    1.69      struct trap_info *t = &v->arch.guest_context.trap_ctxt[TRAP_nmi];
    1.70  
    1.71      t->vector  = TRAP_nmi;
    1.72 @@ -2692,14 +2696,15 @@ long unregister_guest_nmi_callback(void)
    1.73  long do_set_trap_table(XEN_GUEST_HANDLE(trap_info_t) traps)
    1.74  {
    1.75      struct trap_info cur;
    1.76 -    struct trap_info *dst = current->arch.guest_context.trap_ctxt;
    1.77 +    struct vcpu *curr = current;
    1.78 +    struct trap_info *dst = curr->arch.guest_context.trap_ctxt;
    1.79      long rc = 0;
    1.80  
    1.81      /* If no table is presented then clear the entire virtual IDT. */
    1.82      if ( guest_handle_is_null(traps) )
    1.83      {
    1.84          memset(dst, 0, 256 * sizeof(*dst));
    1.85 -        init_int80_direct_trap(current);
    1.86 +        init_int80_direct_trap(curr);
    1.87          return 0;
    1.88      }
    1.89  
    1.90 @@ -2721,12 +2726,12 @@ long do_set_trap_table(XEN_GUEST_HANDLE(
    1.91          if ( cur.address == 0 )
    1.92              break;
    1.93  
    1.94 -        fixup_guest_code_selector(current->domain, cur.cs);
    1.95 +        fixup_guest_code_selector(curr->domain, cur.cs);
    1.96  
    1.97          memcpy(&dst[cur.vector], &cur, sizeof(cur));
    1.98  
    1.99          if ( cur.vector == 0x80 )
   1.100 -            init_int80_direct_trap(current);
   1.101 +            init_int80_direct_trap(curr);
   1.102  
   1.103          guest_handle_add_offset(traps, 1);
   1.104      }
   1.105 @@ -2734,35 +2739,35 @@ long do_set_trap_table(XEN_GUEST_HANDLE(
   1.106      return rc;
   1.107  }
   1.108  
   1.109 -
   1.110 -long set_debugreg(struct vcpu *p, int reg, unsigned long value)
   1.111 +long set_debugreg(struct vcpu *v, int reg, unsigned long value)
   1.112  {
   1.113      int i;
   1.114 +    struct vcpu *curr = current;
   1.115  
   1.116      switch ( reg )
   1.117      {
   1.118      case 0: 
   1.119          if ( !access_ok(value, sizeof(long)) )
   1.120              return -EPERM;
   1.121 -        if ( p == current ) 
   1.122 +        if ( v == curr ) 
   1.123              asm volatile ( "mov %0, %%db0" : : "r" (value) );
   1.124          break;
   1.125      case 1: 
   1.126          if ( !access_ok(value, sizeof(long)) )
   1.127              return -EPERM;
   1.128 -        if ( p == current ) 
   1.129 +        if ( v == curr ) 
   1.130              asm volatile ( "mov %0, %%db1" : : "r" (value) );
   1.131          break;
   1.132      case 2: 
   1.133          if ( !access_ok(value, sizeof(long)) )
   1.134              return -EPERM;
   1.135 -        if ( p == current ) 
   1.136 +        if ( v == curr ) 
   1.137              asm volatile ( "mov %0, %%db2" : : "r" (value) );
   1.138          break;
   1.139      case 3:
   1.140          if ( !access_ok(value, sizeof(long)) )
   1.141              return -EPERM;
   1.142 -        if ( p == current ) 
   1.143 +        if ( v == curr ) 
   1.144              asm volatile ( "mov %0, %%db3" : : "r" (value) );
   1.145          break;
   1.146      case 6:
   1.147 @@ -2772,7 +2777,7 @@ long set_debugreg(struct vcpu *p, int re
   1.148           */
   1.149          value &= 0xffffefff; /* reserved bits => 0 */
   1.150          value |= 0xffff0ff0; /* reserved bits => 1 */
   1.151 -        if ( p == current ) 
   1.152 +        if ( v == curr ) 
   1.153              asm volatile ( "mov %0, %%db6" : : "r" (value) );
   1.154          break;
   1.155      case 7:
   1.156 @@ -2793,14 +2798,14 @@ long set_debugreg(struct vcpu *p, int re
   1.157              for ( i = 0; i < 16; i += 2 )
   1.158                  if ( ((value >> (i+16)) & 3) == 2 ) return -EPERM;
   1.159          }
   1.160 -        if ( p == current ) 
   1.161 +        if ( v == current ) 
   1.162              asm volatile ( "mov %0, %%db7" : : "r" (value) );
   1.163          break;
   1.164      default:
   1.165          return -EINVAL;
   1.166      }
   1.167  
   1.168 -    p->arch.guest_context.debugreg[reg] = value;
   1.169 +    v->arch.guest_context.debugreg[reg] = value;
   1.170      return 0;
   1.171  }
   1.172