ia64/xen-unstable

changeset 167:c3ddf307ddd1

bitkeeper revision 1.33.1.2 (3e4d06a61MzolTel67UVRTtXwIP_sA)

dom_builder.c:
Cleaned up the user-space domain builder.
author kaf24@labyrinth.cl.cam.ac.uk
date Fri Feb 14 15:09:26 2003 +0000 (2003-02-14)
parents f07ac15565b7
children 3f8ad6ef593d
files tools/domain_builder/dom_builder.c
line diff
     1.1 --- a/tools/domain_builder/dom_builder.c	Fri Feb 14 14:42:14 2003 +0000
     1.2 +++ b/tools/domain_builder/dom_builder.c	Fri Feb 14 15:09:26 2003 +0000
     1.3 @@ -25,6 +25,9 @@
     1.4  #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED)
     1.5  #define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED|_PAGE_DIRTY)
     1.6  
     1.7 +/* Round _n up to nearest multiple of _m. */
     1.8 +#define ROUND_UP(_n,_m) (((_n) + (_m) - 1) / (_m))
     1.9 +
    1.10  /* standardized error reporting function */
    1.11  static void dberr(char *msg)
    1.12  {
    1.13 @@ -230,25 +233,32 @@ out:
    1.14   * requests that are handeled by the hypervisor in the ordinary
    1.15   * manner. this way, many potentially messy things are avoided...
    1.16   */ 
    1.17 -static dom_meminfo_t * setup_guestos(int dom, int kernel_fd, 
    1.18 +#define PAGE_TO_VADDR(_pfn) ((void *)(dom_mem->vaddr + ((_pfn) * PAGE_SIZE)))
    1.19 +static dom_meminfo_t *setup_guestos(int dom, int kernel_fd, 
    1.20      unsigned long virt_load_addr, size_t ksize, dom_mem_t *dom_mem)
    1.21  {
    1.22 -    dom_meminfo_t * meminfo = (dom_meminfo_t *)malloc(sizeof(dom_meminfo_t));
    1.23 -    unsigned long * page_array = (unsigned long *)(dom_mem->vaddr);
    1.24 -    page_update_request_t * pgt_updates = (page_update_request_t *)
    1.25 -        (dom_mem->vaddr + ((ksize + (PAGE_SIZE-1)) & PAGE_MASK));
    1.26 +    dom_meminfo_t *meminfo;
    1.27 +    unsigned long *page_array;
    1.28 +    page_update_request_t *pgt_updates;
    1.29      dom_mem_t mem_map;
    1.30 -    dom_meminfo_t * ret = NULL;
    1.31 -    int alloc_index = dom_mem->tot_pages - 1, num_pt_pages;
    1.32 +    dom_meminfo_t *ret = NULL;
    1.33 +    int alloc_index, num_pt_pages;
    1.34      unsigned long l2tab;
    1.35      unsigned long l1tab = 0;
    1.36      unsigned long num_pgt_updates = 0;
    1.37 -    unsigned long pgt_update_arr = (unsigned long)pgt_updates;
    1.38      unsigned long count, pt_start;
    1.39 +    dom0_op_t pgupdate_req;
    1.40 +    char cmd_path[MAX_PATH];
    1.41 +    int cmd_fd;
    1.42  
    1.43 -    /* Count bottom-level PTs. Round up to a whole PT. */
    1.44 -    num_pt_pages = 
    1.45 -        (l1_table_offset(virt_load_addr) + dom_mem->tot_pages + 1023) / 1024;
    1.46 +    meminfo     = (dom_meminfo_t *)malloc(sizeof(dom_meminfo_t));
    1.47 +    page_array  = (unsigned long *)dom_mem->vaddr;
    1.48 +    pgt_updates = (page_update_request_t *)dom_mem->vaddr;
    1.49 +    alloc_index = dom_mem->tot_pages - 1;
    1.50 +
    1.51 +    /* Count bottom-level PTs, rounding up. Include one PTE for shared info. */
    1.52 +    num_pt_pages = ROUND_UP(l1_table_offset(virt_load_addr) +
    1.53 +                            dom_mem->tot_pages + 1, 1024);
    1.54      /* We must also count the page directory. */
    1.55      num_pt_pages++;
    1.56  
    1.57 @@ -259,19 +269,10 @@ static dom_meminfo_t * setup_guestos(int
    1.58       * end of the allocated physical address space.
    1.59       */
    1.60      l2tab = *(page_array + alloc_index) << PAGE_SHIFT; 
    1.61 +    memset(PAGE_TO_VADDR(alloc_index), 0, PAGE_SIZE);
    1.62      alloc_index--;
    1.63      meminfo->l2_pgt_addr = l2tab;
    1.64      meminfo->virt_shinfo_addr = virt_load_addr + nr_2_page(dom_mem->tot_pages);
    1.65 -    count = ((unsigned long)pgt_updates - (unsigned long)(dom_mem->vaddr)) 
    1.66 -        >> PAGE_SHIFT;
    1.67 -
    1.68 -    /* zero out l2 page */
    1.69 -    if(map_dom_mem(l2tab >> PAGE_SHIFT, 1, dom_mem->domain, &mem_map)){
    1.70 -        dberr("Unable to map l2 page into Domain Builder.");
    1.71 -        goto out;
    1.72 -    }
    1.73 -    memset((void *)mem_map.vaddr, 0, PAGE_SIZE);
    1.74 -    dom_mem_cleanup(&mem_map);
    1.75  
    1.76      /* pin down l2tab addr as page dir page - causes hypervisor to provide
    1.77       * correct protection for the page
    1.78 @@ -281,28 +282,16 @@ static dom_meminfo_t * setup_guestos(int
    1.79      pgt_updates++;
    1.80      num_pgt_updates++;
    1.81  
    1.82 -    /* this loop initializes page tables and does one extra entry 
    1.83 -     * to be used by the shared info page. shared info is not in
    1.84 -     * the domains physical address space and is not owned by the
    1.85 -     * domain.
    1.86 -     */
    1.87 +    /* Initialise the page tables. */
    1.88      l2tab += l2_table_offset(virt_load_addr) * sizeof(l2_pgentry_t);
    1.89 -    for(count = 0;
    1.90 -        count < dom_mem->tot_pages + 1; 
    1.91 -        count++){
    1.92 -        
    1.93 -        if(!((unsigned long)l1tab & (PAGE_SIZE-1))){
    1.94 +    for ( count = 0; count < dom_mem->tot_pages; count++ )
    1.95 +    {    
    1.96 +        if ( !((unsigned long)l1tab & (PAGE_SIZE-1)) ) 
    1.97 +        {
    1.98              l1tab = *(page_array + alloc_index) << PAGE_SHIFT;
    1.99 +            memset(PAGE_TO_VADDR(alloc_index), 0, PAGE_SIZE);
   1.100              alloc_index--;
   1.101  			
   1.102 -            /* zero out l1 page */
   1.103 -            if(map_dom_mem(l1tab >> PAGE_SHIFT, 1, dom_mem->domain, &mem_map)){
   1.104 -                dberr("Unable to map l1 page into Domain Builder.");
   1.105 -                goto out;
   1.106 -            }
   1.107 -            memset((void *)mem_map.vaddr, 0, PAGE_SIZE);
   1.108 -            dom_mem_cleanup(&mem_map);
   1.109 -
   1.110              l1tab += l1_table_offset(virt_load_addr + nr_2_page(count)) 
   1.111                  * sizeof(l1_pgentry_t);
   1.112  
   1.113 @@ -342,29 +331,25 @@ static dom_meminfo_t * setup_guestos(int
   1.114      meminfo->virt_startinfo_addr = virt_load_addr + nr_2_page(alloc_index - 1);
   1.115      meminfo->domain = dom;
   1.116  
   1.117 -    /* copy the guest os image */
   1.118 +    /*
   1.119 +     * Send the page update requests down to the hypervisor.
   1.120 +     * NB. We must do this before loading the guest OS image!
   1.121 +     */
   1.122 +    sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
   1.123 +    if ( (cmd_fd = open(cmd_path, O_WRONLY)) < 0 ) goto out;
   1.124 +    pgupdate_req.cmd = DO_PGUPDATES;
   1.125 +    pgupdate_req.u.pgupdate.pgt_update_arr  = (unsigned long)dom_mem->vaddr;
   1.126 +    pgupdate_req.u.pgupdate.num_pgt_updates = num_pgt_updates;
   1.127 +    write(cmd_fd, &pgupdate_req, sizeof(dom0_op_t));
   1.128 +    close(cmd_fd);
   1.129 +
   1.130 +    /* Load the guest OS image. */
   1.131      if(!(read(kernel_fd, (char *)dom_mem->vaddr, ksize) > 0)){
   1.132          dberr("Error reading kernel image, could not"
   1.133                " read the whole image. Terminating.\n");
   1.134          goto out;
   1.135      }
   1.136  
   1.137 -    {
   1.138 -        dom0_op_t pgupdate_req;
   1.139 -        char cmd_path[MAX_PATH];
   1.140 -        int cmd_fd;
   1.141 -
   1.142 -        sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
   1.143 -        if ( (cmd_fd = open(cmd_path, O_WRONLY)) < 0 ) goto out;
   1.144 -
   1.145 -        pgupdate_req.cmd = DO_PGUPDATES;
   1.146 -        pgupdate_req.u.pgupdate.pgt_update_arr  = pgt_update_arr;
   1.147 -        pgupdate_req.u.pgupdate.num_pgt_updates = num_pgt_updates;
   1.148 -
   1.149 -        write(cmd_fd, &pgupdate_req, sizeof(dom0_op_t));
   1.150 -        close(cmd_fd);
   1.151 -    }
   1.152 -
   1.153      ret = meminfo;
   1.154  out:
   1.155