ia64/xen-unstable

changeset 8571:b7e88c83b2a0

More code cleanups, mainly to do_iret() implementations.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Jan 11 19:44:54 2006 +0100 (2006-01-11)
parents c96ea9ebcd29
children 1c186b28289b
files xen/arch/x86/domain.c xen/arch/x86/mm.c xen/arch/x86/traps.c xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_64/traps.c xen/include/asm-x86/domain.h
line diff
     1.1 --- a/xen/arch/x86/domain.c	Wed Jan 11 19:26:03 2006 +0100
     1.2 +++ b/xen/arch/x86/domain.c	Wed Jan 11 19:44:54 2006 +0100
     1.3 @@ -480,14 +480,6 @@ void new_thread(struct vcpu *d,
     1.4  
     1.5  #ifdef __x86_64__
     1.6  
     1.7 -void toggle_guest_mode(struct vcpu *v)
     1.8 -{
     1.9 -    v->arch.flags ^= TF_kernel_mode;
    1.10 -    __asm__ __volatile__ ( "swapgs" );
    1.11 -    update_pagetables(v);
    1.12 -    write_ptbase(v);
    1.13 -}
    1.14 -
    1.15  #define loadsegment(seg,value) ({               \
    1.16      int __r = 1;                                \
    1.17      __asm__ __volatile__ (                      \
     2.1 --- a/xen/arch/x86/mm.c	Wed Jan 11 19:26:03 2006 +0100
     2.2 +++ b/xen/arch/x86/mm.c	Wed Jan 11 19:44:54 2006 +0100
     2.3 @@ -297,7 +297,6 @@ int map_ldt_shadow_page(unsigned int off
     2.4  
     2.5  #if defined(__x86_64__)
     2.6      /* If in user mode, switch to kernel mode just to read LDT mapping. */
     2.7 -    extern void toggle_guest_mode(struct vcpu *);
     2.8      int user_mode = !(v->arch.flags & TF_kernel_mode);
     2.9  #define TOGGLE_MODE() if ( user_mode ) toggle_guest_mode(v)
    2.10  #elif defined(__i386__)
    2.11 @@ -2971,7 +2970,6 @@ void ptwr_flush(struct domain *d, const 
    2.12  
    2.13  #ifdef CONFIG_X86_64
    2.14      struct vcpu *v = current;
    2.15 -    extern void toggle_guest_mode(struct vcpu *);
    2.16      int user_mode = !(v->arch.flags & TF_kernel_mode);
    2.17  #endif
    2.18  
     3.1 --- a/xen/arch/x86/traps.c	Wed Jan 11 19:26:03 2006 +0100
     3.2 +++ b/xen/arch/x86/traps.c	Wed Jan 11 19:44:54 2006 +0100
     3.3 @@ -596,7 +596,6 @@ static inline int guest_io_okay(
     3.4      u16 x;
     3.5  #if defined(__x86_64__)
     3.6      /* If in user mode, switch to kernel mode just to read I/O bitmap. */
     3.7 -    extern void toggle_guest_mode(struct vcpu *);
     3.8      int user_mode = !(v->arch.flags & TF_kernel_mode);
     3.9  #define TOGGLE_MODE() if ( user_mode ) toggle_guest_mode(v)
    3.10  #elif defined(__i386__)
     4.1 --- a/xen/arch/x86/x86_32/traps.c	Wed Jan 11 19:26:03 2006 +0100
     4.2 +++ b/xen/arch/x86/x86_32/traps.c	Wed Jan 11 19:44:54 2006 +0100
     4.3 @@ -157,38 +157,37 @@ asmlinkage void do_double_fault(void)
     4.4          __asm__ __volatile__ ( "hlt" );
     4.5  }
     4.6  
     4.7 +static inline void pop_from_guest_stack(
     4.8 +    void *dst, struct cpu_user_regs *regs, unsigned int bytes)
     4.9 +{
    4.10 +    if ( unlikely(copy_from_user(dst, (void __user *)regs->esp, bytes)) )
    4.11 +        domain_crash_synchronous();
    4.12 +    regs->esp += bytes;
    4.13 +}
    4.14 +
    4.15  asmlinkage unsigned long do_iret(void)
    4.16  {
    4.17      struct cpu_user_regs *regs = guest_cpu_user_regs();
    4.18  
    4.19 -    /* Restore EAX (clobbered by hypercall). */
    4.20 -    if ( copy_from_user(&regs->eax, (void __user *)regs->esp, 4) )
    4.21 -        domain_crash_synchronous();
    4.22 -    regs->esp += 4;
    4.23 +    /* Pop and restore EAX (clobbered by hypercall). */
    4.24 +    pop_from_guest_stack(&regs->eax, regs, 4);
    4.25  
    4.26 -    /* Restore EFLAGS, CS and EIP. */
    4.27 -    if ( copy_from_user(&regs->eip, (void __user *)regs->esp, 12) )
    4.28 -        domain_crash_synchronous();
    4.29 +    /* Pop and restore EFLAGS, CS and EIP. */
    4.30 +    pop_from_guest_stack(&regs->eip, regs, 12);
    4.31  
    4.32      if ( VM86_MODE(regs) )
    4.33      {
    4.34 -        /* Return to VM86 mode: restore ESP,SS,ES,DS,FS and GS. */
    4.35 -        if(copy_from_user(&regs->esp, (void __user *)(regs->esp+12), 24))
    4.36 -            domain_crash_synchronous();
    4.37 +        /* Return to VM86 mode: pop and restore ESP,SS,ES,DS,FS and GS. */
    4.38 +        pop_from_guest_stack(&regs->esp, regs, 24);
    4.39      }
    4.40      else if ( RING_0(regs) )
    4.41      {
    4.42          domain_crash_synchronous();
    4.43      }
    4.44 -    else if ( RING_1(regs) ) {
    4.45 -        /* Return to ring 1: pop EFLAGS,CS and EIP. */
    4.46 -        regs->esp += 12;
    4.47 -    }
    4.48 -    else
    4.49 +    else if ( !RING_1(regs) )
    4.50      {
    4.51 -        /* Return to ring 2/3: restore ESP and SS. */
    4.52 -        if ( copy_from_user(&regs->esp, (void __user *)(regs->esp+12), 8) )
    4.53 -            domain_crash_synchronous();
    4.54 +        /* Return to ring 2/3: pop and restore ESP and SS. */
    4.55 +        pop_from_guest_stack(&regs->esp, regs, 8);
    4.56      }
    4.57  
    4.58      /* Fixup EFLAGS. */
     5.1 --- a/xen/arch/x86/x86_64/traps.c	Wed Jan 11 19:26:03 2006 +0100
     5.2 +++ b/xen/arch/x86/x86_64/traps.c	Wed Jan 11 19:44:54 2006 +0100
     5.3 @@ -114,7 +114,13 @@ asmlinkage void do_double_fault(struct c
     5.4          __asm__ __volatile__ ( "hlt" );
     5.5  }
     5.6  
     5.7 -extern void toggle_guest_mode(struct vcpu *);
     5.8 +void toggle_guest_mode(struct vcpu *v)
     5.9 +{
    5.10 +    v->arch.flags ^= TF_kernel_mode;
    5.11 +    __asm__ __volatile__ ( "swapgs" );
    5.12 +    update_pagetables(v);
    5.13 +    write_ptbase(v);
    5.14 +}
    5.15  
    5.16  long do_iret(void)
    5.17  {
    5.18 @@ -122,13 +128,17 @@ long do_iret(void)
    5.19      struct iret_context iret_saved;
    5.20      struct vcpu *v = current;
    5.21  
    5.22 -    if ( unlikely(copy_from_user(&iret_saved, (void *)regs->rsp, sizeof(iret_saved))) ||
    5.23 -         unlikely(pagetable_get_paddr(v->arch.guest_table_user) == 0) )
    5.24 -        return -EFAULT;
    5.25 +    if ( unlikely(copy_from_user(&iret_saved, (void *)regs->rsp,
    5.26 +                                 sizeof(iret_saved))) )
    5.27 +        domain_crash_synchronous();
    5.28  
    5.29 -    /* Returning to user mode. */
    5.30 -    if ( (iret_saved.cs & 0x03) == 3 )
    5.31 +    /* Returning to user mode? */
    5.32 +    if ( (iret_saved.cs & 3) == 3 )
    5.33 +    {
    5.34 +        if ( unlikely(pagetable_get_paddr(v->arch.guest_table_user) == 0) )
    5.35 +            return -EFAULT;
    5.36          toggle_guest_mode(v);
    5.37 +    }
    5.38  
    5.39      regs->rip    = iret_saved.rip;
    5.40      regs->cs     = iret_saved.cs | 3; /* force guest privilege */
     6.1 --- a/xen/include/asm-x86/domain.h	Wed Jan 11 19:26:03 2006 +0100
     6.2 +++ b/xen/include/asm-x86/domain.h	Wed Jan 11 19:44:54 2006 +0100
     6.3 @@ -46,7 +46,10 @@ struct mapcache {
     6.4      struct vcpu_maphash vcpu_maphash[MAX_VIRT_CPUS];
     6.5  };
     6.6  
     6.7 -extern void mapcache_init(struct domain *d);
     6.8 +extern void mapcache_init(struct domain *);
     6.9 +
    6.10 +/* x86/64: toggle guest between kernel and user modes. */
    6.11 +extern void toggle_guest_mode(struct vcpu *);
    6.12  
    6.13  struct arch_domain
    6.14  {