ia64/xen-unstable

changeset 3828:917ea52007ea

bitkeeper revision 1.1201 (42108e93jNjU6R-4pZQGJCtUzl_HkQ)

Fix SMP booting. Clean up x86/64 a bit.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Mon Feb 14 11:42:11 2005 +0000 (2005-02-14)
parents 33647e6b3f4e
children f9224ed982ae 39538bfd72f0
files xen/arch/x86/domain.c xen/arch/x86/smpboot.c xen/arch/x86/x86_64/entry.S xen/drivers/char/console.c xen/include/asm-x86/shadow.h
line diff
     1.1 --- a/xen/arch/x86/domain.c	Mon Feb 14 10:39:59 2005 +0000
     1.2 +++ b/xen/arch/x86/domain.c	Mon Feb 14 11:42:11 2005 +0000
     1.3 @@ -541,6 +541,14 @@ void new_thread(struct exec_domain *d,
     1.4  
     1.5  #ifdef __x86_64__
     1.6  
     1.7 +void toggle_guest_mode(struct exec_domain *ed)
     1.8 +{
     1.9 +    ed->arch.flags ^= TF_kernel_mode;
    1.10 +    __asm__ __volatile__ ( "swapgs" );
    1.11 +    update_pagetables(ed);
    1.12 +    write_ptbase(ed);
    1.13 +}
    1.14 +
    1.15  #define loadsegment(seg,value) ({               \
    1.16      int __r = 1;                                \
    1.17      __asm__ __volatile__ (                      \
    1.18 @@ -655,12 +663,7 @@ static void switch_segments(
    1.19          }
    1.20  
    1.21          if ( !(n->arch.flags & TF_kernel_mode) )
    1.22 -        {
    1.23 -            n->arch.flags |= TF_kernel_mode;
    1.24 -            __asm__ __volatile__ ( "swapgs" );
    1.25 -            update_pagetables(n);
    1.26 -            write_ptbase(n);
    1.27 -        }
    1.28 +            toggle_guest_mode(n);
    1.29  
    1.30          regs->entry_vector  = TRAP_syscall;
    1.31          regs->rflags       &= 0xFFFCBEFFUL;
    1.32 @@ -681,10 +684,7 @@ long do_switch_to_user(void)
    1.33           unlikely(pagetable_val(ed->arch.guest_table_user) == 0) )
    1.34          return -EFAULT;
    1.35  
    1.36 -    ed->arch.flags &= ~TF_kernel_mode;
    1.37 -    __asm__ __volatile__ ( "swapgs" );
    1.38 -    update_pagetables(ed);
    1.39 -    write_ptbase(ed);
    1.40 +    toggle_guest_mode(ed);
    1.41  
    1.42      regs->rip    = stu.rip;
    1.43      regs->cs     = stu.cs;
     2.1 --- a/xen/arch/x86/smpboot.c	Mon Feb 14 10:39:59 2005 +0000
     2.2 +++ b/xen/arch/x86/smpboot.c	Mon Feb 14 11:42:11 2005 +0000
     2.3 @@ -668,7 +668,7 @@ static void __init do_boot_cpu (int apic
     2.4  
     2.5      set_bit(DF_IDLETASK, &idle->d_flags);
     2.6  
     2.7 -    ed->arch.guest_table = mk_pagetable(__pa(idle_pg_table));
     2.8 +    ed->arch.monitor_table = mk_pagetable(__pa(idle_pg_table));
     2.9  
    2.10      map_cpu_to_boot_apicid(cpu, apicid);
    2.11  
     3.1 --- a/xen/arch/x86/x86_64/entry.S	Mon Feb 14 10:39:59 2005 +0000
     3.2 +++ b/xen/arch/x86/x86_64/entry.S	Mon Feb 14 11:42:11 2005 +0000
     3.3 @@ -19,6 +19,7 @@
     3.4          movq (reg),reg;
     3.5  
     3.6          ALIGN
     3.7 +/* %rbx: struct exec_domain */
     3.8  restore_all_guest:
     3.9          btr   $_TF_failsafe_return,EDOMAIN_thread_flags(%rbx)
    3.10          jc    failsafe_callback
    3.11 @@ -37,9 +38,11 @@ restore_all_guest:
    3.12  1:      sysretl
    3.13  
    3.14          ALIGN
    3.15 +/* No special register assumptions. */
    3.16  iret_exit_to_guest:
    3.17          addq  $8,%rsp
    3.18  FLT1:   iretq
    3.19 +
    3.20  .section .fixup,"ax"
    3.21  FIX1:   popq  -15*8-8(%rsp)            # error_code/entry_vector
    3.22          SAVE_ALL                       # 15*8 bytes pushed
    3.23 @@ -79,6 +82,7 @@ failsafe_callback:
    3.24          RESTORE_ALL
    3.25          addq $8,%rsp
    3.26  FLT2:   iret 
    3.27 +
    3.28  .section .fixup,"ax"
    3.29  FIX2:   pushq %rbx
    3.30          GET_CURRENT(%rbx)
    3.31 @@ -91,6 +95,7 @@ FIX2:   pushq %rbx
    3.32  .previous
    3.33  
    3.34          ALIGN
    3.35 +/* No special register assumptions. */
    3.36  restore_all_xen:
    3.37          RESTORE_ALL
    3.38          addq  $8,%rsp
    3.39 @@ -130,6 +135,7 @@ ENTRY(syscall_enter)
    3.40          pushq restore_all_guest(%rip)
    3.41          jmp   create_bounce_frame
    3.42  
    3.43 +/* %rbx: struct exec_domain */
    3.44  hypercall:
    3.45          sti
    3.46          movq  %r10,%rcx
    3.47 @@ -138,6 +144,7 @@ hypercall:
    3.48          callq *(%r10,%rax,8)
    3.49          movq %rax,XREGS_rax(%rsp)       # save the return value
    3.50  
    3.51 +/* %rbx: struct exec_domain */
    3.52  test_all_events:
    3.53          cli                             # tests must not race interrupts
    3.54  /*test_softirqs:*/  
    3.55 @@ -163,6 +170,7 @@ test_all_events:
    3.56          jmp   restore_all_guest
    3.57  
    3.58          ALIGN
    3.59 +/* %rbx: struct exec_domain */
    3.60  process_softirqs:
    3.61          sti       
    3.62          call SYMBOL_NAME(do_softirq)
    3.63 @@ -170,8 +178,8 @@ process_softirqs:
    3.64                  
    3.65  /* CREATE A BASIC EXCEPTION FRAME ON GUEST OS STACK:                     */
    3.66  /*   { RCX, R11, [DS-GS,] [CR2,] [ERRCODE,] RIP, CS, RFLAGS, RSP, SS }   */
    3.67 -/* %rdx == trap_bounce, %rbx == task_struct                              */
    3.68 -/* %rax,%rcx are clobbered. %rsi contains new XREGS_rsp.                 */
    3.69 +/* %rdx: trap_bounce, %rbx: struct exec_domain                           */
    3.70 +/* On return only %rbx is guaranteed non-clobbered.                      */
    3.71  create_bounce_frame:
    3.72          /* Push new frame at existing %rsp if already in guest-OS mode. */
    3.73          movq  XREGS_rsp+8(%rsp),%rsi
    3.74 @@ -225,19 +233,16 @@ FLT14:  movq  %rax,(%rsi)               
    3.75  FLT15:  movq  %rax,(%rsi)               # RCX
    3.76          /* Rewrite our stack frame and return to guest-OS mode. */
    3.77          /* IA32 Ref. Vol. 3: TF, VM, RF and NT flags are cleared on trap. */
    3.78 -        movb  $0,TRAPBOUNCE_flags(%rdx)
    3.79 -        bts   $_TF_kernel_mode,EDOMAIN_thread_flags(%rbx)
    3.80 -        jc    1f
    3.81 -        swapgs
    3.82 -        movq  %rbx,%rdi
    3.83 -        call  SYMBOL_NAME(write_ptbase)
    3.84 -1:      movl  $TRAP_syscall,XREGS_entry_vector+8(%rsp)
    3.85 +        movl  $TRAP_syscall,XREGS_entry_vector+8(%rsp)
    3.86          andl  $0xfffcbeff,XREGS_eflags+8(%rsp)
    3.87          movl  $__GUEST_SS,XREGS_ss+8(%rsp)
    3.88          movq  %rsi,XREGS_rsp+8(%rsp)
    3.89          movl  $__GUEST_CS,XREGS_cs+8(%rsp)
    3.90          movq  TRAPBOUNCE_eip(%rdx),%rax
    3.91          movq  %rax,XREGS_rip+8(%rsp)
    3.92 +        movb  $0,TRAPBOUNCE_flags(%rdx)
    3.93 +        testb $TF_kernel_mode,EDOMAIN_thread_flags(%rbx)
    3.94 +        jz    SYMBOL_NAME(toggle_guest_mode)
    3.95          ret
    3.96  .section .fixup,"ax"
    3.97  FIX3:   sti
    3.98 @@ -264,6 +269,7 @@ DBLFLT2:jmp   process_guest_exception_an
    3.99  .previous
   3.100  
   3.101          ALIGN
   3.102 +/* %rbx: struct exec_domain */
   3.103  process_guest_exception_and_events:
   3.104          leaq  EDOMAIN_trap_bounce(%rbx),%rdx
   3.105          testb $TBF_EXCEPTION,TRAPBOUNCE_flags(%rdx)
   3.106 @@ -273,6 +279,7 @@ process_guest_exception_and_events:
   3.107          jmp   test_all_events
   3.108  
   3.109          ALIGN
   3.110 +/* No special register assumptions. */
   3.111  ENTRY(ret_from_intr)
   3.112          GET_CURRENT(%rbx)
   3.113          testb $3,XREGS_cs(%rsp)
   3.114 @@ -280,6 +287,7 @@ ENTRY(ret_from_intr)
   3.115          jmp   restore_all_xen
   3.116  
   3.117          ALIGN
   3.118 +/* No special register assumptions. */
   3.119  error_code:
   3.120          SAVE_ALL
   3.121          testb $X86_EFLAGS_IF>>8,XREGS_eflags+1(%rsp)
   3.122 @@ -294,6 +302,7 @@ 1:      sti
   3.123          jz    restore_all_xen
   3.124          jmp   process_guest_exception_and_events
   3.125  
   3.126 +/* No special register assumptions. */
   3.127  exception_with_ints_disabled:
   3.128          testb $3,XREGS_cs(%rsp)         # interrupts disabled outside Xen?
   3.129          jnz   1b                        # it really does happen!
   3.130 @@ -315,6 +324,7 @@ 1:      movq  XREGS_error_code(%rsp),%ra
   3.131          movq  %rax,XREGS_kernel_sizeof(%rsp)
   3.132          jmp   restore_all_xen           # return to fixup code
   3.133  
   3.134 +/* No special register assumptions. */
   3.135  FATAL_exception_with_ints_disabled:
   3.136          movl  XREGS_entry_vector(%rsp),%edi
   3.137          movq  %rsp,%rsi
     4.1 --- a/xen/drivers/char/console.c	Mon Feb 14 10:39:59 2005 +0000
     4.2 +++ b/xen/drivers/char/console.c	Mon Feb 14 11:42:11 2005 +0000
     4.3 @@ -553,6 +553,8 @@ static int __init debugtrace_init(void)
     4.4      debugtrace_buf = (unsigned char *)alloc_xenheap_pages(order);
     4.5      ASSERT(debugtrace_buf != NULL);
     4.6  
     4.7 +    memset(debugtrace_buf, '\0', debugtrace_bytes);
     4.8 +
     4.9      return 0;
    4.10  }
    4.11  __initcall(debugtrace_init);
     5.1 --- a/xen/include/asm-x86/shadow.h	Mon Feb 14 10:39:59 2005 +0000
     5.2 +++ b/xen/include/asm-x86/shadow.h	Mon Feb 14 11:42:11 2005 +0000
     5.3 @@ -739,11 +739,8 @@ static inline void __update_pagetables(s
     5.4      if ( unlikely(smfn == 0) )
     5.5          smfn = shadow_l2_table(d, gpfn);
     5.6  #ifdef CONFIG_VMX
     5.7 -    else
     5.8 -        if (shadow_mode_translate(ed->domain) )
     5.9 -        {
    5.10 -            vmx_update_shadow_state(ed, gpfn, smfn);
    5.11 -        }
    5.12 +    else if ( shadow_mode_translate(ed->domain) )
    5.13 +        vmx_update_shadow_state(ed, gpfn, smfn);
    5.14  #endif
    5.15  
    5.16      ed->arch.shadow_table = mk_pagetable(smfn<<PAGE_SHIFT);
    5.17 @@ -756,28 +753,16 @@ static inline void update_pagetables(str
    5.18  {
    5.19       if ( unlikely(shadow_mode_enabled(ed->domain)) )
    5.20       {
    5.21 -         SH_VVLOG("update_pagetables( gptbase=%p, mode=%d )",
    5.22 -             pagetable_val(ed->arch.guest_table),
    5.23 -                  shadow_mode(ed->domain)); 
    5.24 -
    5.25           shadow_lock(ed->domain);
    5.26           __update_pagetables(ed);
    5.27           shadow_unlock(ed->domain);
    5.28 -
    5.29 -         SH_VVLOG("leaving update_pagetables:\n"
    5.30 -                  "( gptbase=%p, mode=%d ) sh=%p",
    5.31 -                  pagetable_val(ed->arch.guest_table),
    5.32 -                  shadow_mode(ed->domain), 
    5.33 -                  pagetable_val(ed->arch.shadow_table) );
    5.34       }
    5.35 -     else
    5.36  #ifdef __x86_64__
    5.37 -         if ( !(ed->arch.flags & TF_kernel_mode) )
    5.38 -             ed->arch.monitor_table = ed->arch.guest_table_user;
    5.39 -         else
    5.40 +     else if ( !(ed->arch.flags & TF_kernel_mode) )
    5.41 +         ed->arch.monitor_table = ed->arch.guest_table_user;
    5.42  #endif
    5.43 -             ed->arch.monitor_table = ed->arch.guest_table;
    5.44 -
    5.45 +     else
    5.46 +         ed->arch.monitor_table = ed->arch.guest_table;
    5.47  }
    5.48  
    5.49  #if SHADOW_DEBUG