ia64/xen-unstable

changeset 5658:50ac4630390b

The patch extends the VMCS handling to support both 32-bit and 64-bit
guests. Please apply. It also includes cleanups.

Signed-off-by: Jun Nakajima <jun.nakajima@intel.com>
Signed-off-by: Chengyuan Li <chengyuan.li@intel.com>
Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Jul 04 08:20:20 2005 +0000 (2005-07-04)
parents cb6b221bef55
children 22ccddf93c40
files xen/arch/x86/vmx_platform.c xen/arch/x86/vmx_vmcs.c xen/include/asm-x86/vmx_intercept.h
line diff
     1.1 --- a/xen/arch/x86/vmx_platform.c	Mon Jul 04 08:18:42 2005 +0000
     1.2 +++ b/xen/arch/x86/vmx_platform.c	Mon Jul 04 08:20:20 2005 +0000
     1.3 @@ -503,7 +503,7 @@ static int vmx_decode(const unsigned cha
     1.4  
     1.5  int inst_copy_from_guest(unsigned char *buf, unsigned long guest_eip, int inst_len)
     1.6  {
     1.7 -    l1_pgentry_t gpte;
     1.8 +    unsigned long gpa;
     1.9      unsigned long mfn;
    1.10      unsigned char *inst_start;
    1.11      int remaining = 0;
    1.12 @@ -513,8 +513,9 @@ int inst_copy_from_guest(unsigned char *
    1.13  
    1.14      if ( vmx_paging_enabled(current) )
    1.15      {
    1.16 -        gpte = gva_to_gpte(guest_eip);
    1.17 -        mfn = phys_to_machine_mapping(l1e_get_pfn(gpte));
    1.18 +        gpa = gva_to_gpa(guest_eip);
    1.19 +        mfn = phys_to_machine_mapping(gpa >> PAGE_SHIFT);
    1.20 +
    1.21          /* Does this cross a page boundary ? */
    1.22          if ( (guest_eip & PAGE_MASK) != ((guest_eip + inst_len) & PAGE_MASK) )
    1.23          {
    1.24 @@ -533,8 +534,9 @@ int inst_copy_from_guest(unsigned char *
    1.25  
    1.26      if ( remaining )
    1.27      {
    1.28 -        gpte = gva_to_gpte(guest_eip+inst_len+remaining);
    1.29 -        mfn = phys_to_machine_mapping(l1e_get_pfn(gpte));
    1.30 +        gpa = gva_to_gpa(guest_eip+inst_len+remaining);
    1.31 +        mfn = phys_to_machine_mapping(gpa >> PAGE_SHIFT);
    1.32 +
    1.33          inst_start = map_domain_page(mfn);
    1.34          memcpy((char *)buf+inst_len, inst_start, remaining);
    1.35          unmap_domain_page(inst_start);
     2.1 --- a/xen/arch/x86/vmx_vmcs.c	Mon Jul 04 08:18:42 2005 +0000
     2.2 +++ b/xen/arch/x86/vmx_vmcs.c	Mon Jul 04 08:20:20 2005 +0000
     2.3 @@ -65,8 +65,12 @@ static inline int construct_vmcs_control
     2.4  
     2.5      error |= __vmwrite(CPU_BASED_VM_EXEC_CONTROL, 
     2.6                         MONITOR_CPU_BASED_EXEC_CONTROLS);
     2.7 -
     2.8 +#if defined (__x86_64__)
     2.9 +    error |= __vmwrite(VM_EXIT_CONTROLS, 
    2.10 +      MONITOR_VM_EXIT_CONTROLS | VM_EXIT_CONTROLS_IA_32E_MODE);
    2.11 +#else
    2.12      error |= __vmwrite(VM_EXIT_CONTROLS, MONITOR_VM_EXIT_CONTROLS);
    2.13 +#endif
    2.14      error |= __vmwrite(VM_ENTRY_CONTROLS, MONITOR_VM_ENTRY_CONTROLS);
    2.15  
    2.16      return error;
    2.17 @@ -93,6 +97,11 @@ struct host_execution_env {
    2.18      unsigned long tr_base;
    2.19      unsigned long ds_base;
    2.20      unsigned long cs_base;
    2.21 +#ifdef __x86_64__ 
    2.22 +    unsigned long fs_base; 
    2.23 +    unsigned long gs_base; 
    2.24 +#endif 
    2.25 +
    2.26      /* control registers */
    2.27      unsigned long cr3;
    2.28      unsigned long cr0;
    2.29 @@ -230,8 +239,8 @@ construct_init_vmcs_guest(struct cpu_use
    2.30      /* interrupt */
    2.31      error |= __vmwrite(VM_ENTRY_INTR_INFO_FIELD, 0);
    2.32      /* mask */
    2.33 -    error |= __vmwrite(CR0_GUEST_HOST_MASK, 0xffffffff);
    2.34 -    error |= __vmwrite(CR4_GUEST_HOST_MASK, 0xffffffff);
    2.35 +    error |= __vmwrite(CR0_GUEST_HOST_MASK, -1UL);
    2.36 +    error |= __vmwrite(CR4_GUEST_HOST_MASK, -1UL);
    2.37  
    2.38      error |= __vmwrite(PAGE_FAULT_ERROR_CODE_MASK, 0);
    2.39      error |= __vmwrite(PAGE_FAULT_ERROR_CODE_MATCH, 0);
    2.40 @@ -298,9 +307,19 @@ construct_init_vmcs_guest(struct cpu_use
    2.41      shadow_cr &= ~X86_CR0_PG;
    2.42      error |= __vmwrite(CR0_READ_SHADOW, shadow_cr);
    2.43      /* CR3 is set in vmx_final_setup_guest */
    2.44 +#ifdef __x86_64__
    2.45 +    error |= __vmwrite(GUEST_CR4, host_env->cr4 & ~X86_CR4_PAE);
    2.46 +    printk("construct_init_vmcs_guest: guest CR4 is %lx\n", host_env->cr4 );
    2.47 +#else
    2.48      error |= __vmwrite(GUEST_CR4, host_env->cr4);
    2.49 +#endif
    2.50      shadow_cr = host_env->cr4;
    2.51 +
    2.52 +#ifdef __x86_64__
    2.53 +    shadow_cr &= ~(X86_CR4_PGE | X86_CR4_VMXE | X86_CR4_PAE);
    2.54 +#else
    2.55      shadow_cr &= ~(X86_CR4_PGE | X86_CR4_VMXE);
    2.56 +#endif
    2.57      error |= __vmwrite(CR4_READ_SHADOW, shadow_cr);
    2.58  
    2.59      error |= __vmwrite(GUEST_ES_BASE, host_env->ds_base);
    2.60 @@ -339,16 +358,24 @@ static inline int construct_vmcs_host(st
    2.61      error |= __vmwrite(HOST_ES_SELECTOR, host_env->ds_selector);
    2.62      error |= __vmwrite(HOST_SS_SELECTOR, host_env->ds_selector);
    2.63      error |= __vmwrite(HOST_DS_SELECTOR, host_env->ds_selector);
    2.64 +#if defined (__i386__)
    2.65      error |= __vmwrite(HOST_FS_SELECTOR, host_env->ds_selector);
    2.66      error |= __vmwrite(HOST_GS_SELECTOR, host_env->ds_selector);
    2.67 +    error |= __vmwrite(HOST_FS_BASE, host_env->ds_base); 
    2.68 +    error |= __vmwrite(HOST_GS_BASE, host_env->ds_base); 
    2.69  
    2.70 +#else
    2.71 +    rdmsrl(MSR_FS_BASE, host_env->fs_base); 
    2.72 +    rdmsrl(MSR_GS_BASE, host_env->gs_base); 
    2.73 +    error |= __vmwrite(HOST_FS_BASE, host_env->fs_base); 
    2.74 +    error |= __vmwrite(HOST_GS_BASE, host_env->gs_base); 
    2.75 +
    2.76 +#endif
    2.77      host_env->cs_selector = __HYPERVISOR_CS;
    2.78      error |= __vmwrite(HOST_CS_SELECTOR, host_env->cs_selector);
    2.79  
    2.80      host_env->ds_base = 0;
    2.81      host_env->cs_base = 0;
    2.82 -    error |= __vmwrite(HOST_FS_BASE, host_env->ds_base);
    2.83 -    error |= __vmwrite(HOST_GS_BASE, host_env->ds_base);
    2.84  
    2.85  /* Debug */
    2.86      __asm__ __volatile__ ("sidt  (%0) \n" :: "a"(&desc) : "memory");
    2.87 @@ -366,6 +393,12 @@ static inline int construct_vmcs_host(st
    2.88      host_env->cr4 = crn;
    2.89      error |= __vmwrite(HOST_CR4, crn);
    2.90      error |= __vmwrite(HOST_RIP, (unsigned long) vmx_asm_vmexit_handler);
    2.91 +#ifdef __x86_64__ 
    2.92 +    /* TBD: support cr8 for 64-bit guest */ 
    2.93 +    __vmwrite(VIRTUAL_APIC_PAGE_ADDR, 0); 
    2.94 +    __vmwrite(TPR_THRESHOLD, 0); 
    2.95 +    __vmwrite(SECONDARY_VM_EXEC_CONTROL, 0); 
    2.96 +#endif 
    2.97  
    2.98      return error;
    2.99  }
     3.1 --- a/xen/include/asm-x86/vmx_intercept.h	Mon Jul 04 08:18:42 2005 +0000
     3.2 +++ b/xen/include/asm-x86/vmx_intercept.h	Mon Jul 04 08:20:20 2005 +0000
     3.3 @@ -8,7 +8,7 @@
     3.4  #include <xen/errno.h>
     3.5  #include <public/io/ioreq.h>
     3.6  
     3.7 -#define MAX_IO_HANDLER 6
     3.8 +#define MAX_IO_HANDLER 10
     3.9  
    3.10  typedef int (*intercept_action_t)(ioreq_t*);
    3.11