ia64/xen-unstable

changeset 1132:22160502f0cd

bitkeeper revision 1.754 (403e554b5Rm0IFijoz1AZr8EH1Ek7A)

Many files:
Clean up domain building tools to play nicely with a tightened-up pagetable interface.
author kaf24@scramble.cl.cam.ac.uk
date Thu Feb 26 20:21:31 2004 +0000 (2004-02-26)
parents 0f6c3cc5f40c
children cd5a94809f8a
files tools/xc/lib/xc_linux_build.c tools/xc/lib/xc_linux_restore.c tools/xc/lib/xc_linux_save.c tools/xc/lib/xc_netbsd_build.c tools/xc/lib/xc_private.c tools/xc/lib/xc_private.h xen/common/domain.c
line diff
     1.1 --- a/tools/xc/lib/xc_linux_build.c	Thu Feb 26 16:38:27 2004 +0000
     1.2 +++ b/tools/xc/lib/xc_linux_build.c	Thu Feb 26 20:21:31 2004 +0000
     1.3 @@ -87,7 +87,7 @@ static int copy_to_domain_page(int pm_ha
     1.4                                 unsigned long dst_pfn, 
     1.5                                 void *src_page)
     1.6  {
     1.7 -    void *vaddr = map_pfn(pm_handle, dst_pfn);
     1.8 +    void *vaddr = map_pfn_writeable(pm_handle, dst_pfn);
     1.9      if ( vaddr == NULL )
    1.10          return -1;
    1.11      memcpy(vaddr, src_page, PAGE_SIZE);
    1.12 @@ -106,13 +106,13 @@ static int setup_guestos(int xc_handle,
    1.13                           const char *cmdline,
    1.14                           unsigned long shared_info_frame)
    1.15  {
    1.16 -    l1_pgentry_t *vl1tab;
    1.17 -    l2_pgentry_t *vl2tab;
    1.18 +    l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
    1.19 +    l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
    1.20      unsigned long *page_array = NULL;
    1.21      mmu_update_t *pgt_update_arr = NULL, *pgt_updates = NULL;
    1.22      int alloc_index, num_pt_pages;
    1.23 -    unsigned long l2tab, l2e, l1e=0;
    1.24 -    unsigned long l1tab = 0;
    1.25 +    unsigned long l2tab;
    1.26 +    unsigned long l1tab;
    1.27      unsigned long num_pgt_updates = 0;
    1.28      unsigned long count, pt_start, i, j;
    1.29      unsigned long initrd_addr = 0, initrd_len = 0;
    1.30 @@ -126,7 +126,7 @@ static int setup_guestos(int xc_handle,
    1.31      if ( (pm_handle = init_pfn_mapper()) < 0 )
    1.32          goto error_out;
    1.33  
    1.34 -    pgt_updates = malloc((tot_pages + 1024) * 3 * sizeof(mmu_update_t));
    1.35 +    pgt_updates = malloc((tot_pages + 1) * sizeof(mmu_update_t));
    1.36      page_array = malloc(tot_pages * sizeof(unsigned long));
    1.37      pgt_update_arr = pgt_updates;
    1.38      if ( (pgt_update_arr == NULL) || (page_array == NULL) )
    1.39 @@ -210,6 +210,41 @@ static int setup_guestos(int xc_handle,
    1.40      alloc_index--;
    1.41      builddomain->ctxt.pt_base = l2tab;
    1.42  
    1.43 +    /* Initialise the page tables. */
    1.44 +    if ( (vl2tab = map_pfn_writeable(pm_handle, l2tab >> PAGE_SHIFT)) == NULL )
    1.45 +        goto error_out;
    1.46 +    memset(vl2tab, 0, PAGE_SIZE);
    1.47 +    vl2e = &vl2tab[l2_table_offset(virt_load_addr)];
    1.48 +    for ( count = 0; count < tot_pages; count++ )
    1.49 +    {    
    1.50 +        if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
    1.51 +        {
    1.52 +            l1tab = page_array[alloc_index--] << PAGE_SHIFT;
    1.53 +            if ( vl1tab != NULL )
    1.54 +                unmap_pfn(pm_handle, vl1tab);
    1.55 +            if ( (vl1tab = map_pfn_writeable(pm_handle, 
    1.56 +                                             l1tab >> PAGE_SHIFT)) == NULL )
    1.57 +                goto error_out;
    1.58 +            memset(vl1tab, 0, PAGE_SIZE);
    1.59 +            vl1e = &vl1tab[l1_table_offset(virt_load_addr + 
    1.60 +                                           (count<<PAGE_SHIFT))];
    1.61 +            *vl2e++ = l1tab | L2_PROT;
    1.62 +        }
    1.63 +
    1.64 +        *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
    1.65 +        if ( count >= pt_start )
    1.66 +            *vl1e &= ~_PAGE_RW;
    1.67 +        vl1e++;
    1.68 +
    1.69 +        pgt_updates->ptr = 
    1.70 +            (page_array[count] << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE;
    1.71 +        pgt_updates->val = count;
    1.72 +        pgt_updates++;
    1.73 +        num_pgt_updates++;
    1.74 +    }
    1.75 +    unmap_pfn(pm_handle, vl1tab);
    1.76 +    unmap_pfn(pm_handle, vl2tab);
    1.77 +
    1.78      /*
    1.79       * Pin down l2tab addr as page dir page - causes hypervisor to provide
    1.80       * correct protection for the page
    1.81 @@ -219,63 +254,10 @@ static int setup_guestos(int xc_handle,
    1.82      pgt_updates++;
    1.83      num_pgt_updates++;
    1.84  
    1.85 -    /* Initialise the page tables. */
    1.86 -    if ( (vl2tab = map_pfn(pm_handle, l2tab >> PAGE_SHIFT)) == NULL )
    1.87 -        goto error_out;
    1.88 -    memset(vl2tab, 0, PAGE_SIZE);
    1.89 -    unmap_pfn(pm_handle, vl2tab);
    1.90 -    l2e = l2tab + (l2_table_offset(virt_load_addr)*sizeof(l2_pgentry_t));
    1.91 -    for ( count = 0; count < tot_pages; count++ )
    1.92 -    {    
    1.93 -        if ( (l1e & (PAGE_SIZE-1)) == 0 )
    1.94 -        {
    1.95 -            l1tab = page_array[alloc_index] << PAGE_SHIFT;
    1.96 -            if ( (vl1tab = map_pfn(pm_handle, l1tab >> PAGE_SHIFT)) == NULL )
    1.97 -                goto error_out;
    1.98 -            memset(vl1tab, 0, PAGE_SIZE);
    1.99 -            unmap_pfn(pm_handle, vl1tab);
   1.100 -            alloc_index--;
   1.101 -  
   1.102 -            l1e = l1tab + (l1_table_offset(virt_load_addr+(count<<PAGE_SHIFT))*
   1.103 -                           sizeof(l1_pgentry_t));
   1.104 -
   1.105 -            /* Make appropriate entry in the page directory. */
   1.106 -            pgt_updates->ptr = l2e;
   1.107 -            pgt_updates->val = l1tab | L2_PROT;
   1.108 -            pgt_updates++;
   1.109 -            num_pgt_updates++;
   1.110 -            l2e += sizeof(l2_pgentry_t);
   1.111 -        }
   1.112 -
   1.113 -        if ( count < pt_start )
   1.114 -        {
   1.115 -            pgt_updates->ptr = l1e;
   1.116 -            pgt_updates->val = (page_array[count] << PAGE_SHIFT) | L1_PROT;
   1.117 -            pgt_updates++;
   1.118 -            num_pgt_updates++;
   1.119 -            l1e += sizeof(l1_pgentry_t);
   1.120 -        }
   1.121 -        else
   1.122 -        {
   1.123 -            pgt_updates->ptr = l1e;
   1.124 -            pgt_updates->val = 
   1.125 -                ((page_array[count] << PAGE_SHIFT) | L1_PROT) & ~_PAGE_RW;
   1.126 -            pgt_updates++;
   1.127 -            num_pgt_updates++;
   1.128 -            l1e += sizeof(l1_pgentry_t);
   1.129 -        }
   1.130 -
   1.131 -        pgt_updates->ptr = 
   1.132 -            (page_array[count] << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE;
   1.133 -        pgt_updates->val = count;
   1.134 -        pgt_updates++;
   1.135 -        num_pgt_updates++;
   1.136 -    }
   1.137 -
   1.138      *virt_startinfo_addr =
   1.139          virt_load_addr + ((alloc_index-1) << PAGE_SHIFT);
   1.140  
   1.141 -    start_info = map_pfn(pm_handle, page_array[alloc_index-1]);
   1.142 +    start_info = map_pfn_writeable(pm_handle, page_array[alloc_index-1]);
   1.143      memset(start_info, 0, sizeof(*start_info));
   1.144      start_info->pt_base     = virt_load_addr + ((tot_pages-1) << PAGE_SHIFT);
   1.145      start_info->mod_start   = initrd_addr;
   1.146 @@ -289,7 +271,7 @@ static int setup_guestos(int xc_handle,
   1.147      unmap_pfn(pm_handle, start_info);
   1.148  
   1.149      /* shared_info page starts its life empty. */
   1.150 -    shared_info = map_pfn(pm_handle, shared_info_frame);
   1.151 +    shared_info = map_pfn_writeable(pm_handle, shared_info_frame);
   1.152      memset(shared_info, 0, PAGE_SIZE);
   1.153      unmap_pfn(pm_handle, shared_info);
   1.154  
     2.1 --- a/tools/xc/lib/xc_linux_restore.c	Thu Feb 26 16:38:27 2004 +0000
     2.2 +++ b/tools/xc/lib/xc_linux_restore.c	Thu Feb 26 20:21:31 2004 +0000
     2.3 @@ -132,7 +132,7 @@ int xc_linux_restore(int xc_handle,
     2.4      unsigned long *pfn_type = NULL;
     2.5  
     2.6      /* A temporary mapping, and a copy, of one frame of guest memory. */
     2.7 -    unsigned long *ppage, page[1024];
     2.8 +    unsigned long *ppage;
     2.9  
    2.10      /* A copy of the pfn-to-mfn table frame list. */
    2.11      unsigned long pfn_to_mfn_frame_list[1024];
    2.12 @@ -241,7 +241,7 @@ int xc_linux_restore(int xc_handle,
    2.13          goto out;
    2.14  
    2.15      /* Copy saved contents of shared-info page. No checking needed. */
    2.16 -    ppage = map_pfn(pm_handle, shared_info_frame);
    2.17 +    ppage = map_pfn_writeable(pm_handle, shared_info_frame);
    2.18      memcpy(ppage, shared_info, PAGE_SIZE);
    2.19      unmap_pfn(pm_handle, ppage);
    2.20  
    2.21 @@ -270,55 +270,42 @@ int xc_linux_restore(int xc_handle,
    2.22  
    2.23          mfn = pfn_to_mfn_table[i];
    2.24  
    2.25 -        if ( !checked_read(gfd, page, PAGE_SIZE) )
    2.26 +        ppage = map_pfn_writeable(pm_handle, mfn);
    2.27 +
    2.28 +        if ( !checked_read(gfd, ppage, PAGE_SIZE) )
    2.29          {
    2.30              ERROR("Error when reading from state file");
    2.31              goto out;
    2.32          }
    2.33  
    2.34 -        ppage = map_pfn(pm_handle, mfn);
    2.35 -        switch ( pfn_type[i] )
    2.36 +        if ( pfn_type[i] == L1TAB )
    2.37          {
    2.38 -        case L1TAB:
    2.39 -            memset(ppage, 0, PAGE_SIZE);
    2.40 -            if ( add_mmu_update(xc_handle, mmu_updates, &mmu_update_idx,
    2.41 -                                (mfn<<PAGE_SHIFT) | MMU_EXTENDED_COMMAND,
    2.42 -                                MMUEXT_PIN_L1_TABLE) )
    2.43 -                goto out;
    2.44              for ( j = 0; j < 1024; j++ )
    2.45              {
    2.46 -                if ( page[j] & _PAGE_PRESENT )
    2.47 +                if ( ppage[j] & _PAGE_PRESENT )
    2.48                  {
    2.49 -                    if ( (pfn = page[j] >> PAGE_SHIFT) >= nr_pfns )
    2.50 +                    if ( (pfn = ppage[j] >> PAGE_SHIFT) >= nr_pfns )
    2.51                      {
    2.52                          ERROR("Frame number in page table is out of range");
    2.53                          goto out;
    2.54                      }
    2.55 -                    if ( (pfn_type[pfn] != NONE) && (page[j] & _PAGE_RW) )
    2.56 +                    if ( (pfn_type[pfn] != NONE) && (ppage[j] & _PAGE_RW) )
    2.57                      {
    2.58                          ERROR("Write access requested for a restricted frame");
    2.59                          goto out;
    2.60                      }
    2.61 -                    page[j] &= (PAGE_SIZE - 1) & ~(_PAGE_GLOBAL | _PAGE_PAT);
    2.62 -                    page[j] |= pfn_to_mfn_table[pfn] << PAGE_SHIFT;
    2.63 +                    ppage[j] &= (PAGE_SIZE - 1) & ~(_PAGE_GLOBAL | _PAGE_PAT);
    2.64 +                    ppage[j] |= pfn_to_mfn_table[pfn] << PAGE_SHIFT;
    2.65                  }
    2.66 -                if ( add_mmu_update(xc_handle, mmu_updates, &mmu_update_idx,
    2.67 -                                    (mfn<<PAGE_SHIFT)+(j*sizeof(l1_pgentry_t)),
    2.68 -                                    page[j]) )
    2.69 -                    goto out;
    2.70              }
    2.71 -            break;
    2.72 -        case L2TAB:
    2.73 -            memset(ppage, 0, PAGE_SIZE);
    2.74 -            if ( add_mmu_update(xc_handle, mmu_updates, &mmu_update_idx,
    2.75 -                                (mfn<<PAGE_SHIFT) | MMU_EXTENDED_COMMAND,
    2.76 -                                MMUEXT_PIN_L2_TABLE) )
    2.77 -                goto out;
    2.78 +        }
    2.79 +        else if ( pfn_type[i] == L2TAB )
    2.80 +        {
    2.81              for ( j = 0; j < (HYPERVISOR_VIRT_START>>L2_PAGETABLE_SHIFT); j++ )
    2.82              {
    2.83 -                if ( page[j] & _PAGE_PRESENT )
    2.84 +                if ( ppage[j] & _PAGE_PRESENT )
    2.85                  {
    2.86 -                    if ( (pfn = page[j] >> PAGE_SHIFT) >= nr_pfns )
    2.87 +                    if ( (pfn = ppage[j] >> PAGE_SHIFT) >= nr_pfns )
    2.88                      {
    2.89                          ERROR("Frame number in page table is out of range");
    2.90                          goto out;
    2.91 @@ -328,27 +315,12 @@ int xc_linux_restore(int xc_handle,
    2.92                          ERROR("Page table mistyping");
    2.93                          goto out;
    2.94                      }
    2.95 -                    /* Haven't reached the L1 table yet. Ensure it is safe! */
    2.96 -                    if ( pfn > i )
    2.97 -                    {
    2.98 -                        unsigned long **l1 = map_pfn(pm_handle, 
    2.99 -                                                     pfn_to_mfn_table[pfn]);
   2.100 -                        memset(l1, 0, PAGE_SIZE);
   2.101 -                        unmap_pfn(pm_handle, l1);
   2.102 -                    }
   2.103 -                    page[j] &= (PAGE_SIZE - 1) & ~(_PAGE_GLOBAL | _PAGE_PSE);
   2.104 -                    page[j] |= pfn_to_mfn_table[pfn] << PAGE_SHIFT;
   2.105 +                    ppage[j] &= (PAGE_SIZE - 1) & ~(_PAGE_GLOBAL | _PAGE_PSE);
   2.106 +                    ppage[j] |= pfn_to_mfn_table[pfn] << PAGE_SHIFT;
   2.107                  }
   2.108 -                if ( add_mmu_update(xc_handle, mmu_updates, &mmu_update_idx,
   2.109 -                                    (mfn<<PAGE_SHIFT)+(j*sizeof(l2_pgentry_t)),
   2.110 -                                    page[j]) )
   2.111 -                    goto out;
   2.112              }
   2.113 -            break;
   2.114 -        default:
   2.115 -            memcpy(ppage, page, PAGE_SIZE);
   2.116 -            break;
   2.117          }
   2.118 +
   2.119          unmap_pfn(pm_handle, ppage);
   2.120  
   2.121          if ( add_mmu_update(xc_handle, mmu_updates, &mmu_update_idx,
   2.122 @@ -356,6 +328,31 @@ int xc_linux_restore(int xc_handle,
   2.123              goto out;
   2.124      }
   2.125  
   2.126 +    /*
   2.127 +     * Pin page tables. Do this after writing to them as otherwise Xen
   2.128 +     * will barf when doing the type-checking.
   2.129 +     */
   2.130 +    for ( i = 0; i < nr_pfns; i++ )
   2.131 +    {
   2.132 +        if ( pfn_type[i] == L1TAB )
   2.133 +        {
   2.134 +            if ( add_mmu_update(xc_handle, mmu_updates, &mmu_update_idx,
   2.135 +                                (pfn_to_mfn_table[i]<<PAGE_SHIFT) | 
   2.136 +                                MMU_EXTENDED_COMMAND,
   2.137 +                                MMUEXT_PIN_L1_TABLE) )
   2.138 +                goto out;
   2.139 +        }
   2.140 +        else if ( pfn_type[i] == L2TAB )
   2.141 +        {
   2.142 +            if ( add_mmu_update(xc_handle, mmu_updates, &mmu_update_idx,
   2.143 +                                (pfn_to_mfn_table[i]<<PAGE_SHIFT) | 
   2.144 +                                MMU_EXTENDED_COMMAND,
   2.145 +                                MMUEXT_PIN_L2_TABLE) )
   2.146 +                goto out;
   2.147 +        }
   2.148 +    }
   2.149 +
   2.150 +
   2.151      if ( flush_mmu_updates(xc_handle, mmu_updates, &mmu_update_idx) )
   2.152          goto out;
   2.153  
   2.154 @@ -369,7 +366,7 @@ int xc_linux_restore(int xc_handle,
   2.155          goto out;
   2.156      }
   2.157      ctxt.i386_ctxt.esi = mfn = pfn_to_mfn_table[pfn];
   2.158 -    p_srec = map_pfn(pm_handle, mfn);
   2.159 +    p_srec = map_pfn_writeable(pm_handle, mfn);
   2.160      p_srec->resume_info.nr_pages    = nr_pfns;
   2.161      p_srec->resume_info.shared_info = shared_info_frame << PAGE_SHIFT;
   2.162      p_srec->resume_info.flags       = 0;
   2.163 @@ -412,7 +409,7 @@ int xc_linux_restore(int xc_handle,
   2.164              ERROR("PFN-to-MFN frame number is bad");
   2.165              goto out;
   2.166          }
   2.167 -        ppage = map_pfn(pm_handle, pfn_to_mfn_table[pfn]);
   2.168 +        ppage = map_pfn_writeable(pm_handle, pfn_to_mfn_table[pfn]);
   2.169          memcpy(ppage, &pfn_to_mfn_table[i], copy_size);        
   2.170          unmap_pfn(pm_handle, ppage);
   2.171      }
     3.1 --- a/tools/xc/lib/xc_linux_save.c	Thu Feb 26 16:38:27 2004 +0000
     3.2 +++ b/tools/xc/lib/xc_linux_save.c	Thu Feb 26 20:21:31 2004 +0000
     3.3 @@ -189,7 +189,7 @@ int xc_linux_save(int xc_handle,
     3.4      }
     3.5  
     3.6      /* If the suspend-record MFN is okay then grab a copy of it to @srec. */
     3.7 -    p_srec = map_pfn(pm_handle, ctxt.i386_ctxt.esi);
     3.8 +    p_srec = map_pfn_readonly(pm_handle, ctxt.i386_ctxt.esi);
     3.9      memcpy(&srec, p_srec, sizeof(srec));
    3.10      unmap_pfn(pm_handle, p_srec);
    3.11  
    3.12 @@ -206,7 +206,8 @@ int xc_linux_save(int xc_handle,
    3.13      }
    3.14  
    3.15      /* Grab a copy of the pfn-to-mfn table frame list. */
    3.16 -    p_pfn_to_mfn_frame_list = map_pfn(pm_handle, srec.pfn_to_mfn_frame_list);
    3.17 +    p_pfn_to_mfn_frame_list = map_pfn_readonly(
    3.18 +        pm_handle, srec.pfn_to_mfn_frame_list);
    3.19      memcpy(pfn_to_mfn_frame_list, p_pfn_to_mfn_frame_list, PAGE_SIZE);
    3.20      unmap_pfn(pm_handle, p_pfn_to_mfn_frame_list);
    3.21  
    3.22 @@ -243,7 +244,7 @@ int xc_linux_save(int xc_handle,
    3.23              }
    3.24              if ( pfn_to_mfn_frame != NULL )
    3.25                  unmap_pfn(pm_handle, pfn_to_mfn_frame);
    3.26 -            pfn_to_mfn_frame = map_pfn(pm_handle, mfn);
    3.27 +            pfn_to_mfn_frame = map_pfn_readonly(pm_handle, mfn);
    3.28          }
    3.29          
    3.30          mfn = pfn_to_mfn_frame[i & 1023];
    3.31 @@ -306,7 +307,7 @@ int xc_linux_save(int xc_handle,
    3.32      }
    3.33  
    3.34      /* Start writing out the saved-domain record. */
    3.35 -    ppage = map_pfn(pm_handle, shared_info_frame);
    3.36 +    ppage = map_pfn_readonly(pm_handle, shared_info_frame);
    3.37      if ( !checked_write(gfd, "XenoLinuxSuspend",    16) ||
    3.38           !checked_write(gfd, name,                  sizeof(name)) ||
    3.39           !checked_write(gfd, &srec.nr_pfns,         sizeof(unsigned long)) ||
    3.40 @@ -335,7 +336,7 @@ int xc_linux_save(int xc_handle,
    3.41  
    3.42          mfn = pfn_to_mfn_table[i];
    3.43  
    3.44 -        ppage = map_pfn(pm_handle, mfn);
    3.45 +        ppage = map_pfn_readonly(pm_handle, mfn);
    3.46          memcpy(page, ppage, PAGE_SIZE);
    3.47          unmap_pfn(pm_handle, ppage);
    3.48  
     4.1 --- a/tools/xc/lib/xc_netbsd_build.c	Thu Feb 26 16:38:27 2004 +0000
     4.2 +++ b/tools/xc/lib/xc_netbsd_build.c	Thu Feb 26 20:21:31 2004 +0000
     4.3 @@ -84,13 +84,13 @@ static int setup_guestos(int xc_handle,
     4.4                           const char *cmdline,
     4.5                           unsigned long shared_info_frame)
     4.6  {
     4.7 -    l1_pgentry_t *vl1tab;
     4.8 -    l2_pgentry_t *vl2tab;
     4.9 +    l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
    4.10 +    l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
    4.11      unsigned long *page_array = NULL;
    4.12      mmu_update_t *pgt_update_arr = NULL, *pgt_updates = NULL;
    4.13      int alloc_index, num_pt_pages;
    4.14 -    unsigned long l2tab, l2e, l1e=0;
    4.15 -    unsigned long l1tab = 0;
    4.16 +    unsigned long l2tab;
    4.17 +    unsigned long l1tab;
    4.18      unsigned long num_pgt_updates = 0;
    4.19      unsigned long count, pt_start;
    4.20      unsigned long symtab_addr = 0, symtab_len = 0;
    4.21 @@ -104,7 +104,7 @@ static int setup_guestos(int xc_handle,
    4.22      if ( (pm_handle = init_pfn_mapper()) < 0 )
    4.23          goto error_out;
    4.24  
    4.25 -    pgt_updates = malloc((tot_pages + 1024) * 3 * sizeof(mmu_update_t));
    4.26 +    pgt_updates = malloc((tot_pages + 1) * sizeof(mmu_update_t));
    4.27      page_array = malloc(tot_pages * sizeof(unsigned long));
    4.28      pgt_update_arr = pgt_updates;
    4.29      if ( (pgt_update_arr == NULL) || (page_array == NULL) )
    4.30 @@ -145,6 +145,41 @@ static int setup_guestos(int xc_handle,
    4.31      alloc_index--;
    4.32      builddomain->ctxt.pt_base = l2tab;
    4.33  
    4.34 +    /* Initialise the page tables. */
    4.35 +    if ( (vl2tab = map_pfn_writeable(pm_handle, l2tab >> PAGE_SHIFT)) == NULL )
    4.36 +        goto error_out;
    4.37 +    memset(vl2tab, 0, PAGE_SIZE);
    4.38 +    vl2e = &vl2tab[l2_table_offset(*virt_load_addr)];
    4.39 +    for ( count = 0; count < tot_pages; count++ )
    4.40 +    {
    4.41 +        if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
    4.42 +        {
    4.43 +            l1tab = page_array[alloc_index--] << PAGE_SHIFT;
    4.44 +            if ( vl1tab != NULL )
    4.45 +                unmap_pfn(pm_handle, vl1tab);
    4.46 +            if ( (vl1tab = map_pfn_writeable(pm_handle,
    4.47 +                                             l1tab >> PAGE_SHIFT)) == NULL )
    4.48 +                goto error_out;
    4.49 +            memset(vl1tab, 0, PAGE_SIZE);
    4.50 +            vl1e = &vl1tab[l1_table_offset(*virt_load_addr + 
    4.51 +                                           (count<<PAGE_SHIFT))];
    4.52 +            *vl2e++ = l1tab | L2_PROT;
    4.53 +        }
    4.54 +
    4.55 +        *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
    4.56 +        if ( count >= pt_start )
    4.57 +            *vl1e &= ~_PAGE_RW;
    4.58 +        vl1e++;
    4.59 +
    4.60 +        pgt_updates->ptr = 
    4.61 +            (page_array[count] << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE;
    4.62 +        pgt_updates->val = count;
    4.63 +        pgt_updates++;
    4.64 +        num_pgt_updates++;
    4.65 +    }
    4.66 +    unmap_pfn(pm_handle, vl1tab);
    4.67 +    unmap_pfn(pm_handle, vl2tab);
    4.68 +
    4.69      /*
    4.70       * Pin down l2tab addr as page dir page - causes hypervisor to provide
    4.71       * correct protection for the page
    4.72 @@ -154,64 +189,10 @@ static int setup_guestos(int xc_handle,
    4.73      pgt_updates++;
    4.74      num_pgt_updates++;
    4.75  
    4.76 -    /* Initialise the page tables. */
    4.77 -    if ( (vl2tab = map_pfn(pm_handle, l2tab >> PAGE_SHIFT)) == NULL )
    4.78 -        goto error_out;
    4.79 -    memset(vl2tab, 0, PAGE_SIZE);
    4.80 -    unmap_pfn(pm_handle, vl2tab);
    4.81 -    l2e = l2tab + (l2_table_offset(*virt_load_addr)*sizeof(l2_pgentry_t));
    4.82 -    for ( count = 0; count < tot_pages; count++ )
    4.83 -    {
    4.84 -        if ( (l1e & (PAGE_SIZE-1)) == 0 )
    4.85 -        {
    4.86 -            l1tab = page_array[alloc_index] << PAGE_SHIFT;
    4.87 -            if ( (vl1tab = map_pfn(pm_handle, l1tab >> PAGE_SHIFT)) == NULL )
    4.88 -                goto error_out;
    4.89 -            memset(vl1tab, 0, PAGE_SIZE);
    4.90 -            unmap_pfn(pm_handle, vl1tab);
    4.91 -            alloc_index--;
    4.92 -  
    4.93 -            l1e = l1tab + (l1_table_offset(*virt_load_addr + 
    4.94 -                                           (count<<PAGE_SHIFT)) *
    4.95 -                           sizeof(l1_pgentry_t));
    4.96 -
    4.97 -            /* Make appropriate entry in the page directory. */
    4.98 -            pgt_updates->ptr = l2e;
    4.99 -            pgt_updates->val = l1tab | L2_PROT;
   4.100 -            pgt_updates++;
   4.101 -            num_pgt_updates++;
   4.102 -            l2e += sizeof(l2_pgentry_t);
   4.103 -        }
   4.104 -
   4.105 -        if ( count < pt_start )
   4.106 -        {
   4.107 -            pgt_updates->ptr = l1e;
   4.108 -            pgt_updates->val = (page_array[count] << PAGE_SHIFT) | L1_PROT;
   4.109 -            pgt_updates++;
   4.110 -            num_pgt_updates++;
   4.111 -            l1e += sizeof(l1_pgentry_t);
   4.112 -        }
   4.113 -        else
   4.114 -        {
   4.115 -            pgt_updates->ptr = l1e;
   4.116 -            pgt_updates->val = 
   4.117 -                ((page_array[count] << PAGE_SHIFT) | L1_PROT) & ~_PAGE_RW;
   4.118 -            pgt_updates++;
   4.119 -            num_pgt_updates++;
   4.120 -            l1e += sizeof(l1_pgentry_t);
   4.121 -        }
   4.122 -
   4.123 -        pgt_updates->ptr = 
   4.124 -            (page_array[count] << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE;
   4.125 -        pgt_updates->val = count;
   4.126 -        pgt_updates++;
   4.127 -        num_pgt_updates++;
   4.128 -    }
   4.129 -
   4.130      *virt_startinfo_addr =
   4.131          *virt_load_addr + ((alloc_index-1) << PAGE_SHIFT);
   4.132  
   4.133 -    start_info = map_pfn(pm_handle, page_array[alloc_index-1]);
   4.134 +    start_info = map_pfn_writeable(pm_handle, page_array[alloc_index-1]);
   4.135      memset(start_info, 0, sizeof(*start_info));
   4.136      start_info->pt_base     = *virt_load_addr + ((tot_pages-1) << PAGE_SHIFT);
   4.137      start_info->mod_start   = symtab_addr;
   4.138 @@ -225,7 +206,7 @@ static int setup_guestos(int xc_handle,
   4.139      unmap_pfn(pm_handle, start_info);
   4.140  
   4.141      /* shared_info page starts its life empty. */
   4.142 -    shared_info = map_pfn(pm_handle, shared_info_frame);
   4.143 +    shared_info = map_pfn_writeable(pm_handle, shared_info_frame);
   4.144      memset(shared_info, 0, PAGE_SIZE);
   4.145      unmap_pfn(pm_handle, shared_info);
   4.146  
   4.147 @@ -542,8 +523,9 @@ loadelfimage(gzFile kernel_gfd, int pm_h
   4.148                      goto out;
   4.149                  }
   4.150                  curpos += c;
   4.151 -                vaddr = map_pfn(pm_handle, page_array[(iva - *virt_load_addr)
   4.152 -                                                     >> PAGE_SHIFT]);
   4.153 +                vaddr = map_pfn_writeable(pm_handle, 
   4.154 +                                          page_array[(iva - *virt_load_addr)
   4.155 +                                                    >> PAGE_SHIFT]);
   4.156                  if ( vaddr == NULL )
   4.157                  {
   4.158                      ERROR("Couldn't map guest memory");
   4.159 @@ -650,8 +632,9 @@ loadelfimage(gzFile kernel_gfd, int pm_h
   4.160                  }
   4.161                  curpos += c;
   4.162  
   4.163 -                vaddr = map_pfn(pm_handle, page_array[(maxva - *virt_load_addr)
   4.164 -                                                     >> PAGE_SHIFT]);
   4.165 +                vaddr = map_pfn_writeable(pm_handle, 
   4.166 +                                          page_array[(maxva - *virt_load_addr)
   4.167 +                                                    >> PAGE_SHIFT]);
   4.168                  if ( vaddr == NULL )
   4.169                  {
   4.170                      ERROR("Couldn't map guest memory");
   4.171 @@ -696,8 +679,9 @@ loadelfimage(gzFile kernel_gfd, int pm_h
   4.172          c = PAGE_SIZE - (symva & (PAGE_SIZE - 1));
   4.173          if ( c > s - i )
   4.174              c = s - i;
   4.175 -        vaddr = map_pfn(pm_handle, page_array[(symva - *virt_load_addr)
   4.176 -                                             >> PAGE_SHIFT]);
   4.177 +        vaddr = map_pfn_writeable(pm_handle, 
   4.178 +                                  page_array[(symva - *virt_load_addr)
   4.179 +                                            >> PAGE_SHIFT]);
   4.180          if ( vaddr == NULL )
   4.181          {
   4.182              ERROR("Couldn't map guest memory");
     5.1 --- a/tools/xc/lib/xc_private.c	Thu Feb 26 16:38:27 2004 +0000
     5.2 +++ b/tools/xc/lib/xc_private.c	Thu Feb 26 20:21:31 2004 +0000
     5.3 @@ -16,7 +16,7 @@ int close_pfn_mapper(int pm_handle)
     5.4      return close(pm_handle);
     5.5  }
     5.6  
     5.7 -void *map_pfn(int pm_handle, unsigned long pfn)
     5.8 +void *map_pfn_writeable(int pm_handle, unsigned long pfn)
     5.9  {
    5.10      void *vaddr = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE,
    5.11                         MAP_SHARED, pm_handle, pfn << PAGE_SHIFT);
    5.12 @@ -25,6 +25,15 @@ void *map_pfn(int pm_handle, unsigned lo
    5.13      return vaddr;
    5.14  }
    5.15  
    5.16 +void *map_pfn_readonly(int pm_handle, unsigned long pfn)
    5.17 +{
    5.18 +    void *vaddr = mmap(NULL, PAGE_SIZE, PROT_READ,
    5.19 +                       MAP_SHARED, pm_handle, pfn << PAGE_SHIFT);
    5.20 +    if ( vaddr == MAP_FAILED )
    5.21 +        return NULL;
    5.22 +    return vaddr;
    5.23 +}
    5.24 +
    5.25  void unmap_pfn(int pm_handle, void *vaddr)
    5.26  {
    5.27      (void)munmap(vaddr, PAGE_SIZE);
     6.1 --- a/tools/xc/lib/xc_private.h	Thu Feb 26 16:38:27 2004 +0000
     6.2 +++ b/tools/xc/lib/xc_private.h	Thu Feb 26 20:21:31 2004 +0000
     6.3 @@ -44,8 +44,8 @@
     6.4  #define PAGE_SIZE               (1UL << PAGE_SHIFT)
     6.5  #define PAGE_MASK               (~(PAGE_SIZE-1))
     6.6  
     6.7 -typedef struct { unsigned long l1_lo; } l1_pgentry_t;
     6.8 -typedef struct { unsigned long l2_lo; } l2_pgentry_t;
     6.9 +typedef unsigned long l1_pgentry_t;
    6.10 +typedef unsigned long l2_pgentry_t;
    6.11  
    6.12  #define l1_table_offset(_a) \
    6.13            (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
    6.14 @@ -149,7 +149,8 @@ static inline int do_block_io_op(int xc_
    6.15   */
    6.16  int init_pfn_mapper(void);
    6.17  int close_pfn_mapper(int pm_handle);
    6.18 -void *map_pfn(int pm_handle, unsigned long pfn);
    6.19 +void *map_pfn_writeable(int pm_handle, unsigned long pfn);
    6.20 +void *map_pfn_readonly(int pm_handle, unsigned long pfn);
    6.21  void unmap_pfn(int pm_handle, void *vaddr);
    6.22  
    6.23  #endif /* __XC_PRIVATE_H__ */
     7.1 --- a/xen/common/domain.c	Thu Feb 26 16:38:27 2004 +0000
     7.2 +++ b/xen/common/domain.c	Thu Feb 26 20:21:31 2004 +0000
     7.3 @@ -160,11 +160,11 @@ void __kill_domain(struct task_struct *p
     7.4      write_lock_irqsave(&tasklist_lock, flags);
     7.5      pp = &task_list;                       /* Delete from task_list. */
     7.6      while ( *pp != p ) 
     7.7 -        *pp = (*pp)->next_list;
     7.8 +        pp = &(*pp)->next_list;
     7.9      *pp = p->next_list;
    7.10      pp = &task_hash[TASK_HASH(p->domain)]; /* Delete from task_hash. */
    7.11      while ( *pp != p ) 
    7.12 -        *pp = (*pp)->next_hash;
    7.13 +        pp = &(*pp)->next_hash;
    7.14      *pp = p->next_hash;
    7.15      write_unlock_irqrestore(&tasklist_lock, flags);
    7.16