ia64/xen-unstable

changeset 16029:772674585a1a

hvm: Avoid need for ugly setcpucontext() in HVM domain builder by
pre-setting the vcpu0 to runnable inside Xen, and have the builder
insert a JMP instruction to reach the hvmloader entry point from
address 0x0.
Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Mon Oct 01 15:12:05 2007 +0100 (2007-10-01)
parents 9eff4c97053b
children 22273a5336e5
files tools/libxc/xc_hvm_build.c xen/arch/x86/hvm/hvm.c
line diff
     1.1 --- a/tools/libxc/xc_hvm_build.c	Mon Oct 01 14:11:15 2007 +0100
     1.2 +++ b/tools/libxc/xc_hvm_build.c	Mon Oct 01 15:12:05 2007 +0100
     1.3 @@ -21,14 +21,6 @@
     1.4  
     1.5  #define SCRATCH_PFN 0xFFFFF
     1.6  
     1.7 -/* Need to provide the right flavour of vcpu context for Xen */
     1.8 -typedef union
     1.9 -{
    1.10 -    vcpu_guest_context_x86_64_t c64;
    1.11 -    vcpu_guest_context_x86_32_t c32;   
    1.12 -    vcpu_guest_context_t c;
    1.13 -} vcpu_guest_context_either_t;
    1.14 -
    1.15  static void build_e820map(void *e820_page, unsigned long long mem_size)
    1.16  {
    1.17      struct e820entry *e820entry =
    1.18 @@ -154,12 +146,11 @@ static int loadelfimage(
    1.19  
    1.20  static int setup_guest(int xc_handle,
    1.21                         uint32_t dom, int memsize,
    1.22 -                       char *image, unsigned long image_size,
    1.23 -                       vcpu_guest_context_either_t *ctxt)
    1.24 +                       char *image, unsigned long image_size)
    1.25  {
    1.26      xen_pfn_t *page_array = NULL;
    1.27      unsigned long i, nr_pages = (unsigned long)memsize << (20 - PAGE_SHIFT);
    1.28 -    unsigned long shared_page_nr;
    1.29 +    unsigned long shared_page_nr, entry_eip;
    1.30      struct xen_add_to_physmap xatp;
    1.31      struct shared_info *shared_info;
    1.32      void *e820_page;
    1.33 @@ -263,20 +254,20 @@ static int setup_guest(int xc_handle,
    1.34      xc_set_hvm_param(xc_handle, dom, HVM_PARAM_BUFIOREQ_PFN, shared_page_nr-2);
    1.35      xc_set_hvm_param(xc_handle, dom, HVM_PARAM_IOREQ_PFN, shared_page_nr);
    1.36  
    1.37 -    free(page_array);
    1.38 -
    1.39 -    /* Set [er]ip in the way that's right for Xen */
    1.40 -    if ( strstr(caps, "x86_64") )
    1.41 +    /* Insert JMP <rel32> instruction at address 0x0 to reach entry point. */
    1.42 +    entry_eip = elf_uval(&elf, elf.ehdr, e_entry);
    1.43 +    if ( entry_eip != 0 )
    1.44      {
    1.45 -        ctxt->c64.user_regs.rip = elf_uval(&elf, elf.ehdr, e_entry); 
    1.46 -        ctxt->c64.flags = VGCF_online;
    1.47 -    }
    1.48 -    else
    1.49 -    {
    1.50 -        ctxt->c32.user_regs.eip = elf_uval(&elf, elf.ehdr, e_entry);
    1.51 -        ctxt->c32.flags = VGCF_online;
    1.52 +        char *page0 = xc_map_foreign_range(
    1.53 +            xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, 0);
    1.54 +        if ( page0 == NULL )
    1.55 +            goto error_out;
    1.56 +        page0[0] = 0xe9;
    1.57 +        *(uint32_t *)&page0[1] = entry_eip - 5;
    1.58 +        munmap(page0, PAGE_SIZE);
    1.59      }
    1.60  
    1.61 +    free(page_array);
    1.62      return 0;
    1.63  
    1.64   error_out:
    1.65 @@ -290,42 +281,13 @@ static int xc_hvm_build_internal(int xc_
    1.66                                   char *image,
    1.67                                   unsigned long image_size)
    1.68  {
    1.69 -    struct xen_domctl launch_domctl;
    1.70 -    vcpu_guest_context_either_t ctxt;
    1.71 -    int rc;
    1.72 -
    1.73      if ( (image == NULL) || (image_size == 0) )
    1.74      {
    1.75          ERROR("Image required");
    1.76 -        goto error_out;
    1.77 -    }
    1.78 -
    1.79 -    memset(&ctxt, 0, sizeof(ctxt));
    1.80 -
    1.81 -    if ( setup_guest(xc_handle, domid, memsize, image, image_size, &ctxt) < 0 )
    1.82 -    {
    1.83 -        goto error_out;
    1.84 +        return -1;
    1.85      }
    1.86  
    1.87 -    if ( lock_pages(&ctxt, sizeof(ctxt) ) )
    1.88 -    {
    1.89 -        PERROR("%s: ctxt mlock failed", __func__);
    1.90 -        goto error_out;
    1.91 -    }
    1.92 -
    1.93 -    memset(&launch_domctl, 0, sizeof(launch_domctl));
    1.94 -    launch_domctl.domain = (domid_t)domid;
    1.95 -    launch_domctl.u.vcpucontext.vcpu = 0;
    1.96 -    set_xen_guest_handle(launch_domctl.u.vcpucontext.ctxt, &ctxt.c);
    1.97 -    launch_domctl.cmd = XEN_DOMCTL_setvcpucontext;
    1.98 -    rc = xc_domctl(xc_handle, &launch_domctl);
    1.99 -
   1.100 -    unlock_pages(&ctxt, sizeof(ctxt));
   1.101 -
   1.102 -    return rc;
   1.103 -
   1.104 - error_out:
   1.105 -    return -1;
   1.106 +    return setup_guest(xc_handle, domid, memsize, image, image_size);
   1.107  }
   1.108  
   1.109  static inline int is_loadable_phdr(Elf32_Phdr *phdr)
     2.1 --- a/xen/arch/x86/hvm/hvm.c	Mon Oct 01 14:11:15 2007 +0100
     2.2 +++ b/xen/arch/x86/hvm/hvm.c	Mon Oct 01 15:12:05 2007 +0100
     2.3 @@ -443,6 +443,8 @@ int hvm_vcpu_initialise(struct vcpu *v)
     2.4      spin_lock_init(&v->arch.hvm_vcpu.tm_lock);
     2.5      INIT_LIST_HEAD(&v->arch.hvm_vcpu.tm_list);
     2.6  
     2.7 +    v->arch.guest_context.user_regs.eflags = 2;
     2.8 +
     2.9      if ( v->vcpu_id == 0 )
    2.10      {
    2.11          /* NB. All these really belong in hvm_domain_initialise(). */
    2.12 @@ -453,6 +455,10 @@ int hvm_vcpu_initialise(struct vcpu *v)
    2.13   
    2.14          /* Init guest TSC to start from zero. */
    2.15          hvm_set_guest_time(v, 0);
    2.16 +
    2.17 +        /* Can start up without SIPI-SIPI or setvcpucontext domctl. */
    2.18 +        v->is_initialised = 1;
    2.19 +        clear_bit(_VPF_down, &v->pause_flags);
    2.20      }
    2.21  
    2.22      return 0;