ia64/xen-unstable

changeset 1749:8e52f41499a0

bitkeeper revision 1.1062.1.8 (40f2b4a7XA6Vy0Lq6nLBErX9_qDhcQ)

Various cleanups, and fix a domain-destruct bug that left GDT
references hanging.
author kaf24@scramble.cl.cam.ac.uk
date Mon Jul 12 15:56:23 2004 +0000 (2004-07-12)
parents 380963a0e1a5
children cd887a8fa08a 1737fd2e4368
files .rootkeys xen/arch/x86/dom0_ops.c xen/arch/x86/domain.c xen/arch/x86/memory.c xen/arch/x86/shadow.c xen/arch/x86/traps.c xen/arch/x86/x86_32/mm.c xen/common/dom0_ops.c xen/common/domain.c xen/common/elf.c xen/common/kernel.c xen/include/asm-x86/domain.h xen/include/asm-x86/mm.h xen/include/asm-x86/processor.h xen/include/asm-x86/shadow.h xen/include/xen/elf.h xen/include/xen/mm.h xen/include/xen/sched.h xen/include/xen/shadow.h
line diff
     1.1 --- a/.rootkeys	Mon Jul 12 08:25:22 2004 +0000
     1.2 +++ b/.rootkeys	Mon Jul 12 15:56:23 2004 +0000
     1.3 @@ -360,6 +360,7 @@ 3fa152581E5KhrAtqZef2Sr5NKTz4w xen/commo
     1.4  3ddb79bdLX_P6iB7ILiblRLWvebapg xen/common/dom0_ops.c
     1.5  3e6377e4i0c9GtKN65e99OtRbw3AZw xen/common/dom_mem_ops.c
     1.6  3ddb79bdYO5D8Av12NHqPeSviav7cg xen/common/domain.c
     1.7 +40f2b4a27xPOh3R6zD4M_aabz-TDyg xen/common/elf.c
     1.8  3fba5b96H0khoxNiKbjdi0inpXV-Pw xen/common/event_channel.c
     1.9  3ddb79bd9drcFPVxd4w2GPOIjLlXpA xen/common/kernel.c
    1.10  3e4cd9d8LAAghUY0hNIK72uc2ch_Nw xen/common/keyhandler.c
    1.11 @@ -449,6 +450,7 @@ 3ddb79c2jFkPAZTDmU35L6IUssYMgQ xen/inclu
    1.12  3ddb79c3r9-31dIsewPV3P3i8HALsQ xen/include/asm-x86/delay.h
    1.13  3ddb79c34BFiXjBJ_cCKB0aCsV1IDw xen/include/asm-x86/desc.h
    1.14  40715b2dTokMLYGSuD58BnxOqyWVew xen/include/asm-x86/div64.h
    1.15 +40f2b4a2hC3HtChu-ArD8LyojxWMjg xen/include/asm-x86/domain.h
    1.16  3e20b82fl1jmQiKdLy7fxMcutfpjWA xen/include/asm-x86/domain_page.h
    1.17  3ddb79c3NU8Zy40OTrq3D-i30Y3t4A xen/include/asm-x86/fixmap.h
    1.18  3e2d29944GI24gf7vOP_7x8EyuqxeA xen/include/asm-x86/flushtlb.h
    1.19 @@ -527,7 +529,6 @@ 3e4540ccU1sgCx8seIMGlahmMfv7yQ xen/inclu
    1.20  40589969nPq3DMzv24RDb5LXE9brHw xen/include/xen/sched-if.h
    1.21  3ddb79c0LzqqS0LhAQ50ekgj4oGl7Q xen/include/xen/sched.h
    1.22  403a06a7H0hpHcKpAiDe5BPnaXWTlA xen/include/xen/serial.h
    1.23 -40e3392dib7GrcBAu5cT-EUZTYzeEQ xen/include/xen/shadow.h
    1.24  3ddb79c14dXIhP7C2ahnoD08K90G_w xen/include/xen/slab.h
    1.25  3ddb79c09xbS-xxfKxuV3JETIhBzmg xen/include/xen/smp.h
    1.26  3ddb79c1Vi5VleJAOKHAlY0G2zAsgw xen/include/xen/softirq.h
     2.1 --- a/xen/arch/x86/dom0_ops.c	Mon Jul 12 08:25:22 2004 +0000
     2.2 +++ b/xen/arch/x86/dom0_ops.c	Mon Jul 12 15:56:23 2004 +0000
     2.3 @@ -18,7 +18,7 @@
     2.4  #include <asm/pdb.h>
     2.5  #include <xen/trace.h>
     2.6  #include <xen/console.h>
     2.7 -#include <xen/shadow.h>
     2.8 +#include <asm/shadow.h>
     2.9  #include <hypervisor-ifs/sched_ctl.h>
    2.10  
    2.11  #define TRC_DOM0OP_ENTER_BASE  0x00020000
     3.1 --- a/xen/arch/x86/domain.c	Mon Jul 12 08:25:22 2004 +0000
     3.2 +++ b/xen/arch/x86/domain.c	Mon Jul 12 15:56:23 2004 +0000
     3.3 @@ -1,3 +1,9 @@
     3.4 +/******************************************************************************
     3.5 + * arch/x86/domain.c
     3.6 + * 
     3.7 + * x86-specific domain handling (e.g., register setup and context switching).
     3.8 + */
     3.9 +
    3.10  /*
    3.11   *  Copyright (C) 1995  Linus Torvalds
    3.12   *
    3.13 @@ -23,15 +29,10 @@
    3.14  #include <asm/ldt.h>
    3.15  #include <xen/irq.h>
    3.16  #include <xen/event.h>
    3.17 -#include <xen/shadow.h>
    3.18 +#include <asm/shadow.h>
    3.19  #include <xen/console.h>
    3.20 -
    3.21  #include <xen/elf.h>
    3.22  
    3.23 -extern int loadelfimage(char *);
    3.24 -extern int readelfimage_base_and_size(char *, unsigned long,
    3.25 -                  unsigned long *, unsigned long *, unsigned long *);
    3.26 -
    3.27  #if !defined(CONFIG_X86_64BITMODE)
    3.28  /* No ring-3 access in initial page tables. */
    3.29  #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
    3.30 @@ -46,7 +47,6 @@ extern int readelfimage_base_and_size(ch
    3.31  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
    3.32  #define round_pgdown(_p)  ((_p)&PAGE_MASK)
    3.33  
    3.34 -
    3.35  int hlt_counter;
    3.36  
    3.37  void disable_hlt(void)
    3.38 @@ -207,12 +207,6 @@ void machine_power_off(void)
    3.39      machine_restart(0);
    3.40  }
    3.41  
    3.42 -/* this belongs in include/asm, but there doesn't seem to be a suitable place */
    3.43 -void free_perdomain_pt(struct domain *d)
    3.44 -{
    3.45 -    free_page((unsigned long)d->mm.perdomain_pt);
    3.46 -}
    3.47 -
    3.48  void arch_do_createdomain(struct domain *d)
    3.49  {
    3.50      d->shared_info = (void *)get_free_page();
    3.51 @@ -459,14 +453,19 @@ void domain_relinquish_memory(struct dom
    3.52          write_ptbase(&current->mm);
    3.53  
    3.54      /* Exit shadow mode before deconstructing final guest page table. */
    3.55 -    if ( shadow_mode(d) )
    3.56 -        shadow_mode_disable(d);
    3.57 +    shadow_mode_disable(d);
    3.58  
    3.59      /* Drop the in-use reference to the page-table base. */
    3.60      if ( pagetable_val(d->mm.pagetable) != 0 )
    3.61          put_page_and_type(&frame_table[pagetable_val(d->mm.pagetable) >>
    3.62                                        PAGE_SHIFT]);
    3.63  
    3.64 +    /*
    3.65 +     * Relinquish GDT mappings. No need for explicit unmapping of the LDT as 
    3.66 +     * it automatically gets squashed when the guest's mappings go away.
    3.67 +     */
    3.68 +    destroy_gdt(d);
    3.69 +
    3.70      /* Relinquish Xen-heap pages. Currently this can only be 'shared_info'. */
    3.71      page = virt_to_page(d->shared_info);
    3.72      if ( test_and_clear_bit(_PGC_allocated, &page->count_and_flags) )
     4.1 --- a/xen/arch/x86/memory.c	Mon Jul 12 08:25:22 2004 +0000
     4.2 +++ b/xen/arch/x86/memory.c	Mon Jul 12 15:56:23 2004 +0000
     4.3 @@ -91,7 +91,7 @@
     4.4  #include <xen/errno.h>
     4.5  #include <xen/perfc.h>
     4.6  #include <xen/irq.h>
     4.7 -#include <xen/shadow.h>
     4.8 +#include <asm/shadow.h>
     4.9  #include <asm/page.h>
    4.10  #include <asm/flushtlb.h>
    4.11  #include <asm/io.h>
     5.1 --- a/xen/arch/x86/shadow.c	Mon Jul 12 08:25:22 2004 +0000
     5.2 +++ b/xen/arch/x86/shadow.c	Mon Jul 12 15:56:23 2004 +0000
     5.3 @@ -3,7 +3,7 @@
     5.4  #include <xen/config.h>
     5.5  #include <xen/types.h>
     5.6  #include <xen/mm.h>
     5.7 -#include <xen/shadow.h>
     5.8 +#include <asm/shadow.h>
     5.9  #include <asm/domain_page.h>
    5.10  #include <asm/page.h>
    5.11  #include <xen/event.h>
    5.12 @@ -295,29 +295,30 @@ nomem:
    5.13      return -ENOMEM;
    5.14  }
    5.15  
    5.16 -void shadow_mode_disable( struct domain *p )
    5.17 +void __shadow_mode_disable(struct domain *d)
    5.18  {
    5.19 -    struct mm_struct *m = &p->mm;
    5.20 +    struct mm_struct *m = &d->mm;
    5.21      struct shadow_status *next;
    5.22  
    5.23 -    __free_shadow_table( m );
    5.24 +    __free_shadow_table(m);
    5.25      m->shadow_mode = 0;
    5.26  
    5.27      SH_LOG("freed tables count=%d l1=%d l2=%d",
    5.28 -           m->shadow_page_count, perfc_value(shadow_l1_pages), perfc_value(shadow_l2_pages));
    5.29 +           m->shadow_page_count, perfc_value(shadow_l1_pages), 
    5.30 +           perfc_value(shadow_l2_pages));
    5.31  
    5.32      next = m->shadow_ht_extras;
    5.33 -    while( next )
    5.34 +    while ( next )
    5.35      {
    5.36          struct shadow_status * this = next;
    5.37          m->shadow_extras_count--;
    5.38          next = *((struct shadow_status **)(&next[shadow_ht_extra_size]));
    5.39 -        kfree( this );
    5.40 +        kfree(this);
    5.41      }
    5.42  
    5.43      SH_LOG("freed extras, now %d", m->shadow_extras_count);
    5.44  
    5.45 -    if( m->shadow_dirty_bitmap  )
    5.46 +    if ( m->shadow_dirty_bitmap  )
    5.47      {
    5.48          kfree( m->shadow_dirty_bitmap );
    5.49          m->shadow_dirty_bitmap = 0;
    5.50 @@ -475,53 +476,51 @@ out:
    5.51      return rc;
    5.52  }
    5.53  
    5.54 -int shadow_mode_control( struct domain *p, dom0_shadow_control_t *sc )
    5.55 +int shadow_mode_control(struct domain *d, dom0_shadow_control_t *sc)
    5.56  {
    5.57      unsigned int cmd = sc->op;
    5.58      int rc = 0;
    5.59  
    5.60 -    spin_lock(&p->mm.shadow_lock);
    5.61 +    spin_lock(&d->mm.shadow_lock);
    5.62  
    5.63 -    if ( p->mm.shadow_mode && cmd == DOM0_SHADOW_CONTROL_OP_OFF )
    5.64 +    if ( cmd == DOM0_SHADOW_CONTROL_OP_OFF )
    5.65      {
    5.66 -        shadow_mode_disable(p);
    5.67 +        shadow_mode_disable(d);
    5.68      }
    5.69      else if ( cmd == DOM0_SHADOW_CONTROL_OP_ENABLE_TEST )
    5.70      {
    5.71 -        if(p->mm.shadow_mode) shadow_mode_disable(p);
    5.72 -        shadow_mode_enable(p, SHM_test);
    5.73 +        shadow_mode_disable(d);
    5.74 +        shadow_mode_enable(d, SHM_test);
    5.75      } 
    5.76      else if ( cmd == DOM0_SHADOW_CONTROL_OP_ENABLE_LOGDIRTY )
    5.77      {
    5.78 -        if(p->mm.shadow_mode) shadow_mode_disable(p);
    5.79 -        shadow_mode_enable(p, SHM_logdirty);
    5.80 +        shadow_mode_disable(d);
    5.81 +        shadow_mode_enable(d, SHM_logdirty);
    5.82      } 
    5.83 -    else if ( p->mm.shadow_mode && cmd >= DOM0_SHADOW_CONTROL_OP_FLUSH && cmd<=DOM0_SHADOW_CONTROL_OP_CLEAN2 )
    5.84 +    else if ( shadow_mode(d) && 
    5.85 +              (cmd >= DOM0_SHADOW_CONTROL_OP_FLUSH) && 
    5.86 +              (cmd <= DOM0_SHADOW_CONTROL_OP_CLEAN2) )
    5.87      {
    5.88 -        rc = shadow_mode_table_op(p, sc);
    5.89 +        rc = shadow_mode_table_op(d, sc);
    5.90      }
    5.91      else
    5.92      {
    5.93          rc = -EINVAL;
    5.94      }
    5.95  
    5.96 -	flush_tlb_cpu(p->processor);
    5.97 +	flush_tlb_cpu(d->processor);
    5.98     
    5.99 -    spin_unlock(&p->mm.shadow_lock);
   5.100 +    spin_unlock(&d->mm.shadow_lock);
   5.101  
   5.102      return rc;
   5.103  }
   5.104  
   5.105 -
   5.106 -
   5.107 -static inline struct pfn_info *alloc_shadow_page( struct mm_struct *m )
   5.108 +static inline struct pfn_info *alloc_shadow_page(struct mm_struct *m)
   5.109  {
   5.110      m->shadow_page_count++;
   5.111 -
   5.112 -    return alloc_domain_page( NULL );
   5.113 +    return alloc_domain_page(NULL);
   5.114  }
   5.115  
   5.116 -
   5.117  void unshadow_table( unsigned long gpfn, unsigned int type )
   5.118  {
   5.119      unsigned long spfn;
     6.1 --- a/xen/arch/x86/traps.c	Mon Jul 12 08:25:22 2004 +0000
     6.2 +++ b/xen/arch/x86/traps.c	Mon Jul 12 15:56:23 2004 +0000
     6.3 @@ -38,7 +38,7 @@
     6.4  #include <xen/spinlock.h>
     6.5  #include <xen/irq.h>
     6.6  #include <xen/perfc.h>
     6.7 -#include <xen/shadow.h>
     6.8 +#include <asm/shadow.h>
     6.9  #include <asm/domain_page.h>
    6.10  #include <asm/system.h>
    6.11  #include <asm/io.h>
     7.1 --- a/xen/arch/x86/x86_32/mm.c	Mon Jul 12 08:25:22 2004 +0000
     7.2 +++ b/xen/arch/x86/x86_32/mm.c	Mon Jul 12 15:56:23 2004 +0000
     7.3 @@ -212,13 +212,26 @@ int check_descriptor(unsigned long a, un
     7.4  }
     7.5  
     7.6  
     7.7 -long set_gdt(struct domain *p, 
     7.8 +void destroy_gdt(struct domain *d)
     7.9 +{
    7.10 +    int i;
    7.11 +    unsigned long pfn;
    7.12 +
    7.13 +    for ( i = 0; i < 16; i++ )
    7.14 +    {
    7.15 +        if ( (pfn = l1_pgentry_to_pagenr(d->mm.perdomain_pt[i])) != 0 )
    7.16 +            put_page_and_type(&frame_table[pfn]);
    7.17 +        d->mm.perdomain_pt[i] = mk_l1_pgentry(0);
    7.18 +    }
    7.19 +}
    7.20 +
    7.21 +
    7.22 +long set_gdt(struct domain *d, 
    7.23               unsigned long *frames,
    7.24               unsigned int entries)
    7.25  {
    7.26      /* NB. There are 512 8-byte entries per GDT page. */
    7.27      int i, nr_pages = (entries + 511) / 512;
    7.28 -    unsigned long pfn;
    7.29      struct desc_struct *vgdt;
    7.30  
    7.31      /* Check the new GDT. */
    7.32 @@ -226,7 +239,7 @@ long set_gdt(struct domain *p,
    7.33      {
    7.34          if ( unlikely(frames[i] >= max_page) ||
    7.35               unlikely(!get_page_and_type(&frame_table[frames[i]], 
    7.36 -                                         p, PGT_gdt_page)) )
    7.37 +                                         d, PGT_gdt_page)) )
    7.38              goto fail;
    7.39      }
    7.40  
    7.41 @@ -238,20 +251,15 @@ long set_gdt(struct domain *p,
    7.42      unmap_domain_mem(vgdt);
    7.43  
    7.44      /* Tear down the old GDT. */
    7.45 -    for ( i = 0; i < 16; i++ )
    7.46 -    {
    7.47 -        if ( (pfn = l1_pgentry_to_pagenr(p->mm.perdomain_pt[i])) != 0 )
    7.48 -            put_page_and_type(&frame_table[pfn]);
    7.49 -        p->mm.perdomain_pt[i] = mk_l1_pgentry(0);
    7.50 -    }
    7.51 +    destroy_gdt(d);
    7.52  
    7.53      /* Install the new GDT. */
    7.54      for ( i = 0; i < nr_pages; i++ )
    7.55 -        p->mm.perdomain_pt[i] =
    7.56 +        d->mm.perdomain_pt[i] =
    7.57              mk_l1_pgentry((frames[i] << PAGE_SHIFT) | __PAGE_HYPERVISOR);
    7.58  
    7.59 -    SET_GDT_ADDRESS(p, GDT_VIRT_START);
    7.60 -    SET_GDT_ENTRIES(p, (entries*8)-1);
    7.61 +    SET_GDT_ADDRESS(d, GDT_VIRT_START);
    7.62 +    SET_GDT_ENTRIES(d, (entries*8)-1);
    7.63  
    7.64      return 0;
    7.65  
     8.1 --- a/xen/common/dom0_ops.c	Mon Jul 12 08:25:22 2004 +0000
     8.2 +++ b/xen/common/dom0_ops.c	Mon Jul 12 15:56:23 2004 +0000
     8.3 @@ -17,7 +17,7 @@
     8.4  #include <asm/pdb.h>
     8.5  #include <xen/trace.h>
     8.6  #include <xen/console.h>
     8.7 -#include <xen/shadow.h>
     8.8 +#include <asm/shadow.h>
     8.9  #include <hypervisor-ifs/sched_ctl.h>
    8.10  
    8.11  #define TRC_DOM0OP_ENTER_BASE  0x00020000
     9.1 --- a/xen/common/domain.c	Mon Jul 12 08:25:22 2004 +0000
     9.2 +++ b/xen/common/domain.c	Mon Jul 12 15:56:23 2004 +0000
     9.3 @@ -1,3 +1,8 @@
     9.4 +/******************************************************************************
     9.5 + * domain.c
     9.6 + * 
     9.7 + * Generic domain-handling functions.
     9.8 + */
     9.9  
    9.10  #include <xen/config.h>
    9.11  #include <xen/init.h>
    9.12 @@ -8,8 +13,7 @@
    9.13  #include <xen/event.h>
    9.14  #include <xen/time.h>
    9.15  #include <xen/console.h>
    9.16 -#include <xen/shadow.h>
    9.17 -#include <xen/elf.h>
    9.18 +#include <asm/shadow.h>
    9.19  #include <hypervisor-ifs/dom0_ops.h>
    9.20  #include <asm/hardirq.h>
    9.21  #include <asm/domain_page.h>
    9.22 @@ -19,11 +23,6 @@ rwlock_t tasklist_lock __cacheline_align
    9.23  struct domain *task_hash[TASK_HASH_SIZE];
    9.24  struct domain *task_list;
    9.25  
    9.26 -extern void arch_do_createdomain(struct domain *);
    9.27 -extern void arch_final_setup_guestos(struct domain *, full_execution_context_t *c);
    9.28 -extern void free_perdomain_pt(struct domain *);
    9.29 -extern void domain_relinquish_memory(struct domain *d);
    9.30 -
    9.31  struct domain *do_createdomain(domid_t dom_id, unsigned int cpu)
    9.32  {
    9.33      char buf[100];
    9.34 @@ -395,124 +394,7 @@ int final_setup_guestos(struct domain *p
    9.35      set_bit(DF_CONSTRUCTED, &p->flags);
    9.36  
    9.37   out:    
    9.38 -    if (c) kfree(c);
    9.39 -    
    9.40 +    if ( c != NULL )
    9.41 +        kfree(c);
    9.42      return rc;
    9.43  }
    9.44 -
    9.45 -static inline int is_loadable_phdr(Elf_Phdr *phdr)
    9.46 -{
    9.47 -    return ((phdr->p_type == PT_LOAD) &&
    9.48 -            ((phdr->p_flags & (PF_W|PF_X)) != 0));
    9.49 -}
    9.50 -
    9.51 -int readelfimage_base_and_size(char *elfbase, 
    9.52 -                                      unsigned long elfsize,
    9.53 -                                      unsigned long *pkernstart,
    9.54 -                                      unsigned long *pkernend,
    9.55 -                                      unsigned long *pkernentry)
    9.56 -{
    9.57 -    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
    9.58 -    Elf_Phdr *phdr;
    9.59 -    Elf_Shdr *shdr;
    9.60 -    unsigned long kernstart = ~0UL, kernend=0UL;
    9.61 -    char *shstrtab, *guestinfo;
    9.62 -    int h;
    9.63 -
    9.64 -    if ( !IS_ELF(*ehdr) )
    9.65 -    {
    9.66 -        printk("Kernel image does not have an ELF header.\n");
    9.67 -        return -EINVAL;
    9.68 -    }
    9.69 -
    9.70 -    if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize )
    9.71 -    {
    9.72 -        printk("ELF program headers extend beyond end of image.\n");
    9.73 -        return -EINVAL;
    9.74 -    }
    9.75 -
    9.76 -    if ( (ehdr->e_shoff + (ehdr->e_shnum * ehdr->e_shentsize)) > elfsize )
    9.77 -    {
    9.78 -        printk("ELF section headers extend beyond end of image.\n");
    9.79 -        return -EINVAL;
    9.80 -    }
    9.81 -
    9.82 -    /* Find the section-header strings table. */
    9.83 -    if ( ehdr->e_shstrndx == SHN_UNDEF )
    9.84 -    {
    9.85 -        printk("ELF image has no section-header strings table (shstrtab).\n");
    9.86 -        return -EINVAL;
    9.87 -    }
    9.88 -    shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + 
    9.89 -                        (ehdr->e_shstrndx*ehdr->e_shentsize));
    9.90 -    shstrtab = elfbase + shdr->sh_offset;
    9.91 -    
    9.92 -    /* Find the special '__xen_guest' section and check its contents. */
    9.93 -    for ( h = 0; h < ehdr->e_shnum; h++ )
    9.94 -    {
    9.95 -        shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + (h*ehdr->e_shentsize));
    9.96 -        if ( strcmp(&shstrtab[shdr->sh_name], "__xen_guest") != 0 )
    9.97 -            continue;
    9.98 -        guestinfo = elfbase + shdr->sh_offset;
    9.99 -        printk("Xen-ELF header found: '%s'\n", guestinfo);
   9.100 -        if ( (strstr(guestinfo, "GUEST_OS=linux") == NULL) ||
   9.101 -             (strstr(guestinfo, "XEN_VER=1.3") == NULL) )
   9.102 -        {
   9.103 -            printk("ERROR: Xen will only load Linux built for Xen v1.3\n");
   9.104 -            return -EINVAL;
   9.105 -        }
   9.106 -        break;
   9.107 -    }
   9.108 -    if ( h == ehdr->e_shnum )
   9.109 -    {
   9.110 -        printk("Not a Xen-ELF image: '__xen_guest' section not found.\n");
   9.111 -        return -EINVAL;
   9.112 -    }
   9.113 -
   9.114 -    for ( h = 0; h < ehdr->e_phnum; h++ ) 
   9.115 -    {
   9.116 -        phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
   9.117 -        if ( !is_loadable_phdr(phdr) )
   9.118 -            continue;
   9.119 -        if ( phdr->p_vaddr < kernstart )
   9.120 -            kernstart = phdr->p_vaddr;
   9.121 -        if ( (phdr->p_vaddr + phdr->p_memsz) > kernend )
   9.122 -            kernend = phdr->p_vaddr + phdr->p_memsz;
   9.123 -    }
   9.124 -
   9.125 -    if ( (kernstart > kernend) || 
   9.126 -         (ehdr->e_entry < kernstart) || 
   9.127 -         (ehdr->e_entry > kernend) )
   9.128 -    {
   9.129 -        printk("Malformed ELF image.\n");
   9.130 -        return -EINVAL;
   9.131 -    }
   9.132 -
   9.133 -    *pkernstart = kernstart;
   9.134 -    *pkernend   = kernend;
   9.135 -    *pkernentry = ehdr->e_entry;
   9.136 -
   9.137 -    return 0;
   9.138 -}
   9.139 -
   9.140 -int loadelfimage(char *elfbase)
   9.141 -{
   9.142 -    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
   9.143 -    Elf_Phdr *phdr;
   9.144 -    int h;
   9.145 -  
   9.146 -    for ( h = 0; h < ehdr->e_phnum; h++ ) 
   9.147 -    {
   9.148 -        phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
   9.149 -        if ( !is_loadable_phdr(phdr) )
   9.150 -            continue;
   9.151 -        if ( phdr->p_filesz != 0 )
   9.152 -            memcpy((char *)phdr->p_vaddr, elfbase + phdr->p_offset, 
   9.153 -                   phdr->p_filesz);
   9.154 -        if ( phdr->p_memsz > phdr->p_filesz )
   9.155 -            memset((char *)phdr->p_vaddr + phdr->p_filesz, 0, 
   9.156 -                   phdr->p_memsz - phdr->p_filesz);
   9.157 -    }
   9.158 -
   9.159 -    return 0;
   9.160 -}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/xen/common/elf.c	Mon Jul 12 15:56:23 2004 +0000
    10.3 @@ -0,0 +1,128 @@
    10.4 +/******************************************************************************
    10.5 + * elf.c
    10.6 + * 
    10.7 + * Generic Elf-loading routines.
    10.8 + */
    10.9 +
   10.10 +#include <xen/config.h>
   10.11 +#include <xen/init.h>
   10.12 +#include <xen/lib.h>
   10.13 +#include <xen/mm.h>
   10.14 +#include <xen/elf.h>
   10.15 +
   10.16 +static inline int is_loadable_phdr(Elf_Phdr *phdr)
   10.17 +{
   10.18 +    return ((phdr->p_type == PT_LOAD) &&
   10.19 +            ((phdr->p_flags & (PF_W|PF_X)) != 0));
   10.20 +}
   10.21 +
   10.22 +int readelfimage_base_and_size(char *elfbase, 
   10.23 +                                      unsigned long elfsize,
   10.24 +                                      unsigned long *pkernstart,
   10.25 +                                      unsigned long *pkernend,
   10.26 +                                      unsigned long *pkernentry)
   10.27 +{
   10.28 +    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
   10.29 +    Elf_Phdr *phdr;
   10.30 +    Elf_Shdr *shdr;
   10.31 +    unsigned long kernstart = ~0UL, kernend=0UL;
   10.32 +    char *shstrtab, *guestinfo;
   10.33 +    int h;
   10.34 +
   10.35 +    if ( !IS_ELF(*ehdr) )
   10.36 +    {
   10.37 +        printk("Kernel image does not have an ELF header.\n");
   10.38 +        return -EINVAL;
   10.39 +    }
   10.40 +
   10.41 +    if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize )
   10.42 +    {
   10.43 +        printk("ELF program headers extend beyond end of image.\n");
   10.44 +        return -EINVAL;
   10.45 +    }
   10.46 +
   10.47 +    if ( (ehdr->e_shoff + (ehdr->e_shnum * ehdr->e_shentsize)) > elfsize )
   10.48 +    {
   10.49 +        printk("ELF section headers extend beyond end of image.\n");
   10.50 +        return -EINVAL;
   10.51 +    }
   10.52 +
   10.53 +    /* Find the section-header strings table. */
   10.54 +    if ( ehdr->e_shstrndx == SHN_UNDEF )
   10.55 +    {
   10.56 +        printk("ELF image has no section-header strings table (shstrtab).\n");
   10.57 +        return -EINVAL;
   10.58 +    }
   10.59 +    shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + 
   10.60 +                        (ehdr->e_shstrndx*ehdr->e_shentsize));
   10.61 +    shstrtab = elfbase + shdr->sh_offset;
   10.62 +    
   10.63 +    /* Find the special '__xen_guest' section and check its contents. */
   10.64 +    for ( h = 0; h < ehdr->e_shnum; h++ )
   10.65 +    {
   10.66 +        shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + (h*ehdr->e_shentsize));
   10.67 +        if ( strcmp(&shstrtab[shdr->sh_name], "__xen_guest") != 0 )
   10.68 +            continue;
   10.69 +        guestinfo = elfbase + shdr->sh_offset;
   10.70 +        printk("Xen-ELF header found: '%s'\n", guestinfo);
   10.71 +        if ( (strstr(guestinfo, "GUEST_OS=linux") == NULL) ||
   10.72 +             (strstr(guestinfo, "XEN_VER=1.3") == NULL) )
   10.73 +        {
   10.74 +            printk("ERROR: Xen will only load Linux built for Xen v1.3\n");
   10.75 +            return -EINVAL;
   10.76 +        }
   10.77 +        break;
   10.78 +    }
   10.79 +    if ( h == ehdr->e_shnum )
   10.80 +    {
   10.81 +        printk("Not a Xen-ELF image: '__xen_guest' section not found.\n");
   10.82 +        return -EINVAL;
   10.83 +    }
   10.84 +
   10.85 +    for ( h = 0; h < ehdr->e_phnum; h++ ) 
   10.86 +    {
   10.87 +        phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
   10.88 +        if ( !is_loadable_phdr(phdr) )
   10.89 +            continue;
   10.90 +        if ( phdr->p_vaddr < kernstart )
   10.91 +            kernstart = phdr->p_vaddr;
   10.92 +        if ( (phdr->p_vaddr + phdr->p_memsz) > kernend )
   10.93 +            kernend = phdr->p_vaddr + phdr->p_memsz;
   10.94 +    }
   10.95 +
   10.96 +    if ( (kernstart > kernend) || 
   10.97 +         (ehdr->e_entry < kernstart) || 
   10.98 +         (ehdr->e_entry > kernend) )
   10.99 +    {
  10.100 +        printk("Malformed ELF image.\n");
  10.101 +        return -EINVAL;
  10.102 +    }
  10.103 +
  10.104 +    *pkernstart = kernstart;
  10.105 +    *pkernend   = kernend;
  10.106 +    *pkernentry = ehdr->e_entry;
  10.107 +
  10.108 +    return 0;
  10.109 +}
  10.110 +
  10.111 +int loadelfimage(char *elfbase)
  10.112 +{
  10.113 +    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
  10.114 +    Elf_Phdr *phdr;
  10.115 +    int h;
  10.116 +  
  10.117 +    for ( h = 0; h < ehdr->e_phnum; h++ ) 
  10.118 +    {
  10.119 +        phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
  10.120 +        if ( !is_loadable_phdr(phdr) )
  10.121 +            continue;
  10.122 +        if ( phdr->p_filesz != 0 )
  10.123 +            memcpy((char *)phdr->p_vaddr, elfbase + phdr->p_offset, 
  10.124 +                   phdr->p_filesz);
  10.125 +        if ( phdr->p_memsz > phdr->p_filesz )
  10.126 +            memset((char *)phdr->p_vaddr + phdr->p_filesz, 0, 
  10.127 +                   phdr->p_memsz - phdr->p_filesz);
  10.128 +    }
  10.129 +
  10.130 +    return 0;
  10.131 +}
    11.1 --- a/xen/common/kernel.c	Mon Jul 12 08:25:22 2004 +0000
    11.2 +++ b/xen/common/kernel.c	Mon Jul 12 15:56:23 2004 +0000
    11.3 @@ -19,8 +19,8 @@
    11.4  #include <xen/compile.h>
    11.5  #include <xen/console.h>
    11.6  #include <xen/serial.h>
    11.7 -#include <xen/shadow.h>
    11.8  #include <xen/trace.h>
    11.9 +#include <asm/shadow.h>
   11.10  #include <asm/io.h>
   11.11  #include <asm/uaccess.h>
   11.12  #include <asm/domain_page.h>
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/xen/include/asm-x86/domain.h	Mon Jul 12 15:56:23 2004 +0000
    12.3 @@ -0,0 +1,17 @@
    12.4 +
    12.5 +#ifndef __ASM_X86_DOMAIN_H__
    12.6 +#define __ASM_X86_DOMAIN_H__
    12.7 +
    12.8 +extern void arch_do_createdomain(struct domain *d);
    12.9 +
   12.10 +extern void arch_final_setup_guestos(
   12.11 +    struct domain *d, full_execution_context_t *c);
   12.12 +
   12.13 +static inline void free_perdomain_pt(struct domain *d)
   12.14 +{
   12.15 +    free_page((unsigned long)d->mm.perdomain_pt);
   12.16 +}
   12.17 +
   12.18 +extern void domain_relinquish_memory(struct domain *d);
   12.19 +
   12.20 +#endif /* __ASM_X86_DOMAIN_H__ */
    13.1 --- a/xen/include/asm-x86/mm.h	Mon Jul 12 08:25:22 2004 +0000
    13.2 +++ b/xen/include/asm-x86/mm.h	Mon Jul 12 15:56:23 2004 +0000
    13.3 @@ -3,9 +3,6 @@
    13.4  #define __ASM_X86_MM_H__
    13.5  
    13.6  #include <xen/config.h>
    13.7 -#ifdef LINUX_2_6
    13.8 -#include <xen/gfp.h>
    13.9 -#endif
   13.10  #include <xen/list.h>
   13.11  #include <xen/spinlock.h>
   13.12  #include <xen/perfc.h>
   13.13 @@ -20,19 +17,6 @@
   13.14  #include <hypervisor-ifs/hypervisor-if.h>
   13.15  
   13.16  /*
   13.17 - * The following is for page_alloc.c.
   13.18 - */
   13.19 -
   13.20 -void init_page_allocator(unsigned long min, unsigned long max);
   13.21 -unsigned long __get_free_pages(int order);
   13.22 -void __free_pages(unsigned long p, int order);
   13.23 -#define get_free_page()   (__get_free_pages(0))
   13.24 -#define __get_free_page() (__get_free_pages(0))
   13.25 -#define free_pages(_p,_o) (__free_pages(_p,_o))
   13.26 -#define free_page(_p)     (__free_pages(_p,0))
   13.27 -
   13.28 -
   13.29 -/*
   13.30   * Per-page-frame information.
   13.31   */
   13.32  
    14.1 --- a/xen/include/asm-x86/processor.h	Mon Jul 12 08:25:22 2004 +0000
    14.2 +++ b/xen/include/asm-x86/processor.h	Mon Jul 12 15:56:23 2004 +0000
    14.3 @@ -406,7 +406,8 @@ static inline void write_ptbase(struct m
    14.4  #define GET_GDT_ENTRIES(_p)     ((*(u16 *)((_p)->mm.gdt + 0)))
    14.5  #define GET_GDT_ADDRESS(_p)     ((*(unsigned long *)((_p)->mm.gdt + 2)))
    14.6  
    14.7 -long set_gdt(struct domain *p, 
    14.8 +void destroy_gdt(struct domain *d);
    14.9 +long set_gdt(struct domain *d, 
   14.10               unsigned long *frames, 
   14.11               unsigned int entries);
   14.12  
    15.1 --- a/xen/include/asm-x86/shadow.h	Mon Jul 12 08:25:22 2004 +0000
    15.2 +++ b/xen/include/asm-x86/shadow.h	Mon Jul 12 15:56:23 2004 +0000
    15.3 @@ -24,16 +24,26 @@
    15.4  #define shadow_linear_pg_table ((l1_pgentry_t *)SH_LINEAR_PT_VIRT_START)
    15.5  #define shadow_linear_l2_table ((l2_pgentry_t *)(SH_LINEAR_PT_VIRT_START+(SH_LINEAR_PT_VIRT_START>>(L2_PAGETABLE_SHIFT-L1_PAGETABLE_SHIFT))))
    15.6  
    15.7 +#define shadow_mode(_d)      ((_d)->mm.shadow_mode)
    15.8 +#define shadow_lock_init(_d) spin_lock_init(&(_d)->mm.shadow_lock)
    15.9 +
   15.10  extern void shadow_mode_init(void);
   15.11 -extern int shadow_mode_control( struct domain *p, dom0_shadow_control_t *sc );
   15.12 -extern int shadow_fault( unsigned long va, long error_code );
   15.13 -extern void shadow_l1_normal_pt_update( unsigned long pa, unsigned long gpte, 
   15.14 -                                        unsigned long *prev_spfn_ptr,
   15.15 -                                        l1_pgentry_t **prev_spl1e_ptr  );
   15.16 -extern void shadow_l2_normal_pt_update( unsigned long pa, unsigned long gpte );
   15.17 -extern void unshadow_table( unsigned long gpfn, unsigned int type );
   15.18 -extern int shadow_mode_enable( struct domain *p, unsigned int mode );
   15.19 -extern void shadow_mode_disable( struct domain *p );
   15.20 +extern int shadow_mode_control(struct domain *p, dom0_shadow_control_t *sc);
   15.21 +extern int shadow_fault(unsigned long va, long error_code);
   15.22 +extern void shadow_l1_normal_pt_update(unsigned long pa, unsigned long gpte, 
   15.23 +                                       unsigned long *prev_spfn_ptr,
   15.24 +                                       l1_pgentry_t **prev_spl1e_ptr);
   15.25 +extern void shadow_l2_normal_pt_update(unsigned long pa, unsigned long gpte);
   15.26 +extern void unshadow_table(unsigned long gpfn, unsigned int type);
   15.27 +extern int shadow_mode_enable(struct domain *p, unsigned int mode);
   15.28 +
   15.29 +extern void __shadow_mode_disable(struct domain *d);
   15.30 +static inline void shadow_mode_disable(struct domain *d)
   15.31 +{
   15.32 +    if ( shadow_mode(d) )
   15.33 +        __shadow_mode_disable(d);
   15.34 +}
   15.35 +
   15.36  extern unsigned long shadow_l2_table( 
   15.37      struct mm_struct *m, unsigned long gpfn );
   15.38  
   15.39 @@ -77,11 +87,6 @@ printk("DOM%u: (file=shadow.c, line=%d) 
   15.40  
   15.41  /************************************************************************/
   15.42  
   15.43 -#define shadow_mode(d)		(d->mm.shadow_mode)
   15.44 -#define	shadow_lock_init(d)	spin_lock_init(&d->mm.shadow_lock)
   15.45 -
   15.46 -/************************************************************************/
   15.47 -
   15.48  static inline int __mark_dirty( struct mm_struct *m, unsigned int mfn )
   15.49  {
   15.50      unsigned int pfn;
   15.51 @@ -100,14 +105,14 @@ static inline int __mark_dirty( struct m
   15.52      ASSERT(m->shadow_dirty_bitmap);
   15.53      if( likely(pfn<m->shadow_dirty_bitmap_size) )
   15.54      {
   15.55 -	/* These updates occur with mm.shadow_lock held, so use 
   15.56 -	   (__) version of test_and_set */
   15.57 -	if( __test_and_set_bit( pfn, m->shadow_dirty_bitmap ) == 0 )
   15.58 -	{
   15.59 -	    // if we set it
   15.60 -	    m->shadow_dirty_count++;
   15.61 -	    rc = 1;
   15.62 -	}
   15.63 +        /* These updates occur with mm.shadow_lock held, so use 
   15.64 +           (__) version of test_and_set */
   15.65 +        if ( __test_and_set_bit( pfn, m->shadow_dirty_bitmap ) == 0 )
   15.66 +        {
   15.67 +            // if we set it
   15.68 +            m->shadow_dirty_count++;
   15.69 +            rc = 1;
   15.70 +        }
   15.71      }
   15.72      else
   15.73      {
   15.74 @@ -119,7 +124,7 @@ static inline int __mark_dirty( struct m
   15.75                 frame_table[mfn].count_and_flags, 
   15.76                 frame_table[mfn].type_and_flags );
   15.77      }
   15.78 -	
   15.79 +
   15.80      return rc;
   15.81  }
   15.82  
   15.83 @@ -138,13 +143,13 @@ static inline int mark_dirty( struct mm_
   15.84  
   15.85  /************************************************************************/
   15.86  
   15.87 -static inline void l1pte_write_fault( struct mm_struct *m, 
   15.88 -                                      unsigned long *gpte_p, unsigned long *spte_p )
   15.89 +static inline void l1pte_write_fault(
   15.90 +    struct mm_struct *m, unsigned long *gpte_p, unsigned long *spte_p)
   15.91  { 
   15.92      unsigned long gpte = *gpte_p;
   15.93      unsigned long spte = *spte_p;
   15.94  
   15.95 -    switch( m->shadow_mode )
   15.96 +    switch ( m->shadow_mode )
   15.97      {
   15.98      case SHM_test:
   15.99          spte = gpte;
  15.100 @@ -164,13 +169,13 @@ static inline void l1pte_write_fault( st
  15.101      *spte_p = spte;
  15.102  }
  15.103  
  15.104 -static inline void l1pte_read_fault( struct mm_struct *m, 
  15.105 -                                     unsigned long *gpte_p, unsigned long *spte_p )
  15.106 +static inline void l1pte_read_fault(
  15.107 +    struct mm_struct *m, unsigned long *gpte_p, unsigned long *spte_p)
  15.108  { 
  15.109      unsigned long gpte = *gpte_p;
  15.110      unsigned long spte = *spte_p;
  15.111  
  15.112 -    switch( m->shadow_mode )
  15.113 +    switch ( m->shadow_mode )
  15.114      {
  15.115      case SHM_test:
  15.116          spte = gpte;
  15.117 @@ -192,13 +197,13 @@ static inline void l1pte_read_fault( str
  15.118      *spte_p = spte;
  15.119  }
  15.120  
  15.121 -static inline void l1pte_no_fault( struct mm_struct *m, 
  15.122 -                                   unsigned long *gpte_p, unsigned long *spte_p )
  15.123 +static inline void l1pte_no_fault(
  15.124 +    struct mm_struct *m, unsigned long *gpte_p, unsigned long *spte_p)
  15.125  { 
  15.126      unsigned long gpte = *gpte_p;
  15.127      unsigned long spte = *spte_p;
  15.128  
  15.129 -    switch( m->shadow_mode )
  15.130 +    switch ( m->shadow_mode )
  15.131      {
  15.132      case SHM_test:
  15.133          spte = 0;
  15.134 @@ -227,9 +232,11 @@ static inline void l1pte_no_fault( struc
  15.135      *spte_p = spte;
  15.136  }
  15.137  
  15.138 -static inline void l2pde_general( struct mm_struct *m, 
  15.139 -                                  unsigned long *gpde_p, unsigned long *spde_p,
  15.140 -                                  unsigned long sl1pfn)
  15.141 +static inline void l2pde_general(
  15.142 +    struct mm_struct *m, 
  15.143 +    unsigned long *gpde_p,
  15.144 +    unsigned long *spde_p,
  15.145 +    unsigned long sl1pfn)
  15.146  {
  15.147      unsigned long gpde = *gpde_p;
  15.148      unsigned long spde = *spde_p;
  15.149 @@ -256,8 +263,6 @@ static inline void l2pde_general( struct
  15.150  
  15.151  /*********************************************************************/
  15.152  
  15.153 -
  15.154 -
  15.155  #if SHADOW_HASH_DEBUG
  15.156  static void shadow_audit(struct mm_struct *m, int print)
  15.157  {
    16.1 --- a/xen/include/xen/elf.h	Mon Jul 12 08:25:22 2004 +0000
    16.2 +++ b/xen/include/xen/elf.h	Mon Jul 12 15:56:23 2004 +0000
    16.3 @@ -24,6 +24,9 @@
    16.4   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    16.5   */
    16.6  
    16.7 +#ifndef __XEN_ELF_H__
    16.8 +#define __XEN_ELF_H__
    16.9 +
   16.10  typedef u8	Elf_Byte;
   16.11  
   16.12  typedef u32	Elf32_Addr;	/* Unsigned program address */
   16.13 @@ -521,3 +524,8 @@ typedef struct {
   16.14  #define AuxInfo		Aux64Info
   16.15  #endif
   16.16  
   16.17 +extern int loadelfimage(char *);
   16.18 +extern int readelfimage_base_and_size(
   16.19 +    char *, unsigned long, unsigned long *, unsigned long *, unsigned long *);
   16.20 +
   16.21 +#endif /* __XEN_ELF_H__ */
    17.1 --- a/xen/include/xen/mm.h	Mon Jul 12 08:25:22 2004 +0000
    17.2 +++ b/xen/include/xen/mm.h	Mon Jul 12 15:56:23 2004 +0000
    17.3 @@ -2,6 +2,15 @@
    17.4  #ifndef __XEN_MM_H__
    17.5  #define __XEN_MM_H__
    17.6  
    17.7 +/* page_alloc.c */
    17.8 +void init_page_allocator(unsigned long min, unsigned long max);
    17.9 +unsigned long __get_free_pages(int order);
   17.10 +void __free_pages(unsigned long p, int order);
   17.11 +#define get_free_page()   (__get_free_pages(0))
   17.12 +#define __get_free_page() (__get_free_pages(0))
   17.13 +#define free_pages(_p,_o) (__free_pages(_p,_o))
   17.14 +#define free_page(_p)     (__free_pages(_p,0))
   17.15 +
   17.16  #include <asm/mm.h>
   17.17  
   17.18  #endif /* __XEN_MM_H__ */
    18.1 --- a/xen/include/xen/sched.h	Mon Jul 12 08:25:22 2004 +0000
    18.2 +++ b/xen/include/xen/sched.h	Mon Jul 12 15:56:23 2004 +0000
    18.3 @@ -295,4 +295,6 @@ static inline void domain_unpause_by_sys
    18.4  #define IS_PRIV(_d) (test_bit(DF_PRIVILEGED, &(_d)->flags))
    18.5  #define IS_CAPABLE_PHYSDEV(_d) (test_bit(DF_PHYSDEV, &(_d)->flags))
    18.6  
    18.7 +#include <asm/domain.h>
    18.8 +
    18.9  #endif /* __SCHED_H__ */
    19.1 --- a/xen/include/xen/shadow.h	Mon Jul 12 08:25:22 2004 +0000
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,1 +0,0 @@
    19.4 -#include <asm/shadow.h>