ia64/xen-unstable

changeset 12898:6edf8b33e7d1

[BUILDER] Enable shadow mode for shadow translate guests much earlier.

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
author Ian Campbell <ian.campbell@xensource.com>
date Mon Dec 11 11:57:36 2006 +0000 (2006-12-11)
parents 57b36b893a8d
children 37141c3a3d39
files tools/libxc/xc_linux_build.c
line diff
     1.1 --- a/tools/libxc/xc_linux_build.c	Mon Dec 11 09:56:02 2006 +0000
     1.2 +++ b/tools/libxc/xc_linux_build.c	Mon Dec 11 11:57:36 2006 +0000
     1.3 @@ -175,11 +175,10 @@ static int load_initrd(int xc_handle, do
     1.4      return 0;
     1.5  }
     1.6  
     1.7 -#define alloc_pt(ltab, vltab, pltab)                                    \
     1.8 +#define alloc_pt(ltab, vltab)                                           \
     1.9  do {                                                                    \
    1.10 -    pltab = ppt_alloc++;                                                \
    1.11 -    ltab = (uint64_t)page_array[pltab] << PAGE_SHIFT;                   \
    1.12 -    pltab <<= PAGE_SHIFT;                                               \
    1.13 +    ltab = ppt_alloc++;                                                 \
    1.14 +    ltab = (uint64_t)page_array[ltab] << PAGE_SHIFT;                    \
    1.15      if ( vltab != NULL )                                                \
    1.16          munmap(vltab, PAGE_SIZE);                                       \
    1.17      if ( (vltab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,       \
    1.18 @@ -202,43 +201,32 @@ static int setup_pg_tables(int xc_handle
    1.19  {
    1.20      l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
    1.21      l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
    1.22 -    unsigned long l1tab = 0, pl1tab;
    1.23 -    unsigned long l2tab = 0, pl2tab;
    1.24 +    unsigned long l1tab = 0;
    1.25 +    unsigned long l2tab = 0;
    1.26      unsigned long ppt_alloc;
    1.27      unsigned long count;
    1.28  
    1.29      ppt_alloc = (vpt_start - dsi_v_start) >> PAGE_SHIFT;
    1.30 -    alloc_pt(l2tab, vl2tab, pl2tab);
    1.31 +    alloc_pt(l2tab, vl2tab);
    1.32      vl2e = &vl2tab[l2_table_offset(dsi_v_start)];
    1.33 -    if (shadow_mode_enabled)
    1.34 -        ctxt->ctrlreg[3] = xen_pfn_to_cr3(pl2tab >> PAGE_SHIFT);
    1.35 -    else
    1.36 -        ctxt->ctrlreg[3] = xen_pfn_to_cr3(l2tab >> PAGE_SHIFT);
    1.37 +    ctxt->ctrlreg[3] = xen_pfn_to_cr3(l2tab >> PAGE_SHIFT);
    1.38  
    1.39      for ( count = 0; count < ((v_end - dsi_v_start) >> PAGE_SHIFT); count++ )
    1.40      {
    1.41          if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
    1.42          {
    1.43 -            alloc_pt(l1tab, vl1tab, pl1tab);
    1.44 +            alloc_pt(l1tab, vl1tab);
    1.45              vl1e = &vl1tab[l1_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
    1.46 -            if (shadow_mode_enabled)
    1.47 -                *vl2e = pl1tab | L2_PROT;
    1.48 -            else
    1.49 -                *vl2e = l1tab | L2_PROT;
    1.50 -            vl2e++;
    1.51 +            *vl2e++ = l1tab | L2_PROT;
    1.52          }
    1.53  
    1.54 -        if ( shadow_mode_enabled )
    1.55 -        {
    1.56 -            *vl1e = (count << PAGE_SHIFT) | L1_PROT;
    1.57 -        }
    1.58 -        else
    1.59 -        {
    1.60 -            *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
    1.61 +        *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
    1.62 +
    1.63 +        if ( !shadow_mode_enabled )
    1.64              if ( (count >= ((vpt_start-dsi_v_start)>>PAGE_SHIFT)) &&
    1.65                   (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) )
    1.66                  *vl1e &= ~_PAGE_RW;
    1.67 -        }
    1.68 +
    1.69          vl1e++;
    1.70      }
    1.71      munmap(vl1tab, PAGE_SIZE);
    1.72 @@ -266,7 +254,7 @@ static int setup_pg_tables_pae(int xc_ha
    1.73      l1_pgentry_64_t *vl1tab = NULL, *vl1e = NULL;
    1.74      l2_pgentry_64_t *vl2tab = NULL, *vl2e = NULL;
    1.75      l3_pgentry_64_t *vl3tab = NULL, *vl3e = NULL;
    1.76 -    uint64_t l1tab, l2tab, l3tab, pl1tab, pl2tab, pl3tab;
    1.77 +    uint64_t l1tab, l2tab, l3tab;
    1.78      unsigned long ppt_alloc, count, nmfn;
    1.79  
    1.80      /* First allocate page for page dir. */
    1.81 @@ -287,12 +275,9 @@ static int setup_pg_tables_pae(int xc_ha
    1.82          page_array[ppt_alloc] = nmfn;
    1.83      }
    1.84  
    1.85 -    alloc_pt(l3tab, vl3tab, pl3tab);
    1.86 +    alloc_pt(l3tab, vl3tab);
    1.87      vl3e = &vl3tab[l3_table_offset_pae(dsi_v_start)];
    1.88 -    if (shadow_mode_enabled)
    1.89 -        ctxt->ctrlreg[3] = xen_pfn_to_cr3(pl3tab >> PAGE_SHIFT);
    1.90 -    else
    1.91 -        ctxt->ctrlreg[3] = xen_pfn_to_cr3(l3tab >> PAGE_SHIFT);
    1.92 +    ctxt->ctrlreg[3] = xen_pfn_to_cr3(l3tab >> PAGE_SHIFT);
    1.93  
    1.94      for ( count = 0; count < ((v_end - dsi_v_start) >> PAGE_SHIFT); count++)
    1.95      {
    1.96 @@ -300,42 +285,33 @@ static int setup_pg_tables_pae(int xc_ha
    1.97          {
    1.98              if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
    1.99              {
   1.100 -                alloc_pt(l2tab, vl2tab, pl2tab);
   1.101 +                alloc_pt(l2tab, vl2tab);
   1.102                  vl2e = &vl2tab[l2_table_offset_pae(
   1.103                      dsi_v_start + (count << PAGE_SHIFT))];
   1.104 -                if (shadow_mode_enabled)
   1.105 -                    *vl3e = pl2tab | L3_PROT;
   1.106 -                else
   1.107 -                    *vl3e++ = l2tab | L3_PROT;
   1.108 +                *vl3e++ = l2tab | L3_PROT;
   1.109              }
   1.110  
   1.111 -            alloc_pt(l1tab, vl1tab, pl1tab);
   1.112 +            alloc_pt(l1tab, vl1tab);
   1.113              vl1e = &vl1tab[l1_table_offset_pae(
   1.114                  dsi_v_start + (count << PAGE_SHIFT))];
   1.115 -            if (shadow_mode_enabled)
   1.116 -                *vl2e = pl1tab | L2_PROT;
   1.117 -            else
   1.118 -                *vl2e++ = l1tab | L2_PROT;
   1.119 +            *vl2e++ = l1tab | L2_PROT;
   1.120 +
   1.121          }
   1.122  
   1.123 -        if ( shadow_mode_enabled )
   1.124 -        {
   1.125 -            *vl1e = (count << PAGE_SHIFT) | L1_PROT;
   1.126 -        }
   1.127 -        else
   1.128 -        {
   1.129 -            *vl1e = ((uint64_t)page_array[count] << PAGE_SHIFT) | L1_PROT;
   1.130 +        *vl1e = ((uint64_t)page_array[count] << PAGE_SHIFT) | L1_PROT;
   1.131 +
   1.132 +        if ( !shadow_mode_enabled )
   1.133              if ( (count >= ((vpt_start-dsi_v_start)>>PAGE_SHIFT)) &&
   1.134                   (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) )
   1.135                  *vl1e &= ~_PAGE_RW;
   1.136 -        }
   1.137 +
   1.138          vl1e++;
   1.139      }
   1.140  
   1.141      /* Xen requires a mid-level pgdir mapping 0xC0000000 region. */
   1.142      if ( (vl3tab[3] & _PAGE_PRESENT) == 0 )
   1.143      {
   1.144 -        alloc_pt(l2tab, vl2tab, pl2tab);
   1.145 +        alloc_pt(l2tab, vl2tab);
   1.146          vl3tab[3] = l2tab | L3_PROT;
   1.147      }
   1.148  
   1.149 @@ -371,69 +347,48 @@ static int setup_pg_tables_64(int xc_han
   1.150      l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
   1.151      l3_pgentry_t *vl3tab=NULL, *vl3e=NULL;
   1.152      l4_pgentry_t *vl4tab=NULL, *vl4e=NULL;
   1.153 -    unsigned long l2tab = 0, pl2tab;
   1.154 -    unsigned long l1tab = 0, pl1tab;
   1.155 -    unsigned long l3tab = 0, pl3tab;
   1.156 -    unsigned long l4tab = 0, pl4tab;
   1.157 +    unsigned long l2tab = 0;
   1.158 +    unsigned long l1tab = 0;
   1.159 +    unsigned long l3tab = 0;
   1.160 +    unsigned long l4tab = 0;
   1.161      unsigned long ppt_alloc;
   1.162      unsigned long count;
   1.163  
   1.164      /* First allocate page for page dir. */
   1.165      ppt_alloc = (vpt_start - dsi_v_start) >> PAGE_SHIFT;
   1.166 -    alloc_pt(l4tab, vl4tab, pl4tab);
   1.167 +    alloc_pt(l4tab, vl4tab);
   1.168      vl4e = &vl4tab[l4_table_offset(dsi_v_start)];
   1.169 -    if (shadow_mode_enabled)
   1.170 -        ctxt->ctrlreg[3] = xen_pfn_to_cr3(pl4tab >> PAGE_SHIFT);
   1.171 -    else
   1.172 -        ctxt->ctrlreg[3] = xen_pfn_to_cr3(l4tab >> PAGE_SHIFT);
   1.173 +    ctxt->ctrlreg[3] = xen_pfn_to_cr3(l4tab >> PAGE_SHIFT);
   1.174  
   1.175      for ( count = 0; count < ((v_end-dsi_v_start)>>PAGE_SHIFT); count++)
   1.176      {
   1.177          if ( !((unsigned long)vl1e & (PAGE_SIZE-1)) )
   1.178          {
   1.179 -            alloc_pt(l1tab, vl1tab, pl1tab);
   1.180 +            alloc_pt(l1tab, vl1tab);
   1.181  
   1.182              if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
   1.183              {
   1.184 -                alloc_pt(l2tab, vl2tab, pl2tab);
   1.185 +                alloc_pt(l2tab, vl2tab);
   1.186                  if ( !((unsigned long)vl3e & (PAGE_SIZE-1)) )
   1.187                  {
   1.188 -                    alloc_pt(l3tab, vl3tab, pl3tab);
   1.189 +                    alloc_pt(l3tab, vl3tab);
   1.190                      vl3e = &vl3tab[l3_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   1.191 -                    if (shadow_mode_enabled)
   1.192 -                        *vl4e = pl3tab | L4_PROT;
   1.193 -                    else
   1.194 -                        *vl4e = l3tab | L4_PROT;
   1.195 -                    vl4e++;
   1.196 +                    *vl4e++ = l3tab | L4_PROT;
   1.197                  }
   1.198                  vl2e = &vl2tab[l2_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   1.199 -                if (shadow_mode_enabled)
   1.200 -                    *vl3e = pl2tab | L3_PROT;
   1.201 -                else
   1.202 -                    *vl3e = l2tab | L3_PROT;
   1.203 -                vl3e++;
   1.204 +                *vl3e++ = l2tab | L3_PROT;
   1.205              }
   1.206              vl1e = &vl1tab[l1_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   1.207 -            if (shadow_mode_enabled)
   1.208 -                *vl2e = pl1tab | L2_PROT;
   1.209 -            else
   1.210 -                *vl2e = l1tab | L2_PROT;
   1.211 -            vl2e++;
   1.212 +            *vl2e++ = l1tab | L2_PROT;
   1.213          }
   1.214  
   1.215 -        if ( shadow_mode_enabled )
   1.216 -        {
   1.217 -            *vl1e = (count << PAGE_SHIFT) | L1_PROT;
   1.218 -        }
   1.219 -        else
   1.220 -        {
   1.221 -            *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
   1.222 +        *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
   1.223 +
   1.224 +        if ( !shadow_mode_enabled )
   1.225              if ( (count >= ((vpt_start-dsi_v_start)>>PAGE_SHIFT)) &&
   1.226                   (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) )
   1.227 -                {
   1.228 -                    *vl1e &= ~_PAGE_RW;
   1.229 -                }
   1.230 -        }
   1.231 +                *vl1e &= ~_PAGE_RW;
   1.232 +
   1.233          vl1e++;
   1.234      }
   1.235  
   1.236 @@ -772,6 +727,27 @@ static int setup_guest(int xc_handle,
   1.237          goto error_out;
   1.238      }
   1.239  
   1.240 +
   1.241 +    if ( shadow_mode_enabled )
   1.242 +    {
   1.243 +        /*
   1.244 +         * Enable shadow translate mode. This must happen after
   1.245 +         * populate physmap because the p2m reservation is based on
   1.246 +         * the domains current memory allocation.
   1.247 +         */
   1.248 +        if ( xc_shadow_control(xc_handle, dom,
   1.249 +                           XEN_DOMCTL_SHADOW_OP_ENABLE_TRANSLATE,
   1.250 +                           NULL, 0, NULL, 0, NULL) < 0 )
   1.251 +        {
   1.252 +            PERROR("Could not enable translation mode");
   1.253 +            goto error_out;
   1.254 +        }
   1.255 +
   1.256 +        /* Reinitialise the gpfn->gmfn array. */
   1.257 +        for ( i = 0; i < nr_pages; i++ )
   1.258 +            page_array[i] = i;
   1.259 +    }
   1.260 +
   1.261      rc = (load_funcs.loadimage)(image, image_size,
   1.262                             xc_handle, dom, page_array,
   1.263                             &dsi);
   1.264 @@ -973,15 +949,6 @@ static int setup_guest(int xc_handle,
   1.265      {
   1.266          struct xen_add_to_physmap xatp;
   1.267  
   1.268 -        /* Enable shadow translate mode */
   1.269 -        if ( xc_shadow_control(xc_handle, dom,
   1.270 -                               XEN_DOMCTL_SHADOW_OP_ENABLE_TRANSLATE,
   1.271 -                               NULL, 0, NULL, 0, NULL) < 0 )
   1.272 -        {
   1.273 -            PERROR("Could not enable translation mode");
   1.274 -            goto error_out;
   1.275 -        }
   1.276 -
   1.277          guest_shared_info_mfn = (vsharedinfo_start-dsi.v_start) >> PAGE_SHIFT;
   1.278  
   1.279          /* Map shared info frame into guest physmap. */
   1.280 @@ -1083,8 +1050,7 @@ static int setup_guest(int xc_handle,
   1.281          if ( pfn >= nr_pages )
   1.282              goto error_out;
   1.283          domctl.domain = (domid_t)dom;
   1.284 -        domctl.u.hypercall_init.gmfn   = shadow_mode_enabled ?
   1.285 -            pfn : page_array[pfn];
   1.286 +        domctl.u.hypercall_init.gmfn = page_array[pfn];
   1.287          domctl.cmd = XEN_DOMCTL_hypercall_init;
   1.288          if ( xc_domctl(xc_handle, &domctl) )
   1.289              goto error_out;