ia64/xen-unstable

changeset 16429:f2711b7eae95

hvm: Clean up VMCS/VMCB construction.
Signed-off-by: Keir Fraser <keir.fraser@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Nov 22 19:55:42 2007 +0000 (2007-11-22)
parents 69b56d3289f5
children 2e05a6173be0
files xen/arch/x86/hvm/svm/vmcb.c xen/arch/x86/hvm/vmx/vmcs.c xen/include/asm-x86/hvm/svm/vmcb.h
line diff
     1.1 --- a/xen/arch/x86/hvm/svm/vmcb.c	Thu Nov 22 19:23:40 2007 +0000
     1.2 +++ b/xen/arch/x86/hvm/svm/vmcb.c	Thu Nov 22 19:55:42 2007 +0000
     1.3 @@ -40,8 +40,6 @@
     1.4  
     1.5  extern int svm_dbg_on;
     1.6  
     1.7 -#define GUEST_SEGMENT_LIMIT 0xffffffff
     1.8 -
     1.9  #define IOPM_SIZE   (12 * 1024)
    1.10  #define MSRPM_SIZE  (8  * 1024)
    1.11  
    1.12 @@ -110,7 +108,6 @@ static int construct_vmcb(struct vcpu *v
    1.13  {
    1.14      struct arch_svm_struct *arch_svm = &v->arch.hvm_svm;
    1.15      struct vmcb_struct *vmcb = arch_svm->vmcb;
    1.16 -    svm_segment_attributes_t attrib;
    1.17  
    1.18      /* TLB control, and ASID assigment. */
    1.19      svm_asid_init_vcpu(v);
    1.20 @@ -173,12 +170,12 @@ static int construct_vmcb(struct vcpu *v
    1.21      vmcb->efer = EFER_SVME;
    1.22  
    1.23      /* Guest segment limits. */
    1.24 -    vmcb->cs.limit = GUEST_SEGMENT_LIMIT;
    1.25 -    vmcb->es.limit = GUEST_SEGMENT_LIMIT;
    1.26 -    vmcb->ss.limit = GUEST_SEGMENT_LIMIT;
    1.27 -    vmcb->ds.limit = GUEST_SEGMENT_LIMIT;
    1.28 -    vmcb->fs.limit = GUEST_SEGMENT_LIMIT;
    1.29 -    vmcb->gs.limit = GUEST_SEGMENT_LIMIT;
    1.30 +    vmcb->cs.limit = ~0u;
    1.31 +    vmcb->es.limit = ~0u;
    1.32 +    vmcb->ss.limit = ~0u;
    1.33 +    vmcb->ds.limit = ~0u;
    1.34 +    vmcb->fs.limit = ~0u;
    1.35 +    vmcb->gs.limit = ~0u;
    1.36  
    1.37      /* Guest segment bases. */
    1.38      vmcb->cs.base = 0;
    1.39 @@ -189,20 +186,12 @@ static int construct_vmcb(struct vcpu *v
    1.40      vmcb->gs.base = 0;
    1.41  
    1.42      /* Guest segment AR bytes. */
    1.43 -    attrib.bytes = 0;
    1.44 -    attrib.fields.type = 0x3; /* type = 3 */
    1.45 -    attrib.fields.s = 1;      /* code or data, i.e. not system */
    1.46 -    attrib.fields.dpl = 0;    /* DPL = 0 */
    1.47 -    attrib.fields.p = 1;      /* segment present */
    1.48 -    attrib.fields.db = 1;     /* 32-bit */
    1.49 -    attrib.fields.g = 1;      /* 4K pages in limit */
    1.50 -    vmcb->es.attr = attrib;
    1.51 -    vmcb->ss.attr = attrib;
    1.52 -    vmcb->ds.attr = attrib;
    1.53 -    vmcb->fs.attr = attrib;
    1.54 -    vmcb->gs.attr = attrib;
    1.55 -    attrib.fields.type = 0xb; /* type=0xb -> executable/readable, accessed */
    1.56 -    vmcb->cs.attr = attrib;
    1.57 +    vmcb->es.attr.bytes = 0xc93; /* read/write, accessed */
    1.58 +    vmcb->ss.attr.bytes = 0xc93;
    1.59 +    vmcb->ds.attr.bytes = 0xc93;
    1.60 +    vmcb->fs.attr.bytes = 0xc93;
    1.61 +    vmcb->gs.attr.bytes = 0xc93;
    1.62 +    vmcb->cs.attr.bytes = 0xc9b; /* exec/read, accessed */
    1.63  
    1.64      /* Guest IDT. */
    1.65      vmcb->idtr.base = 0;
    1.66 @@ -219,8 +208,7 @@ static int construct_vmcb(struct vcpu *v
    1.67      vmcb->ldtr.attr.bytes = 0;
    1.68  
    1.69      /* Guest TSS. */
    1.70 -    attrib.fields.type = 0xb; /* 32-bit TSS (busy) */
    1.71 -    vmcb->tr.attr = attrib;
    1.72 +    vmcb->tr.attr.bytes = 0x08b; /* 32-bit TSS (busy) */
    1.73      vmcb->tr.base = 0;
    1.74      vmcb->tr.limit = 0xff;
    1.75  
     2.1 --- a/xen/arch/x86/hvm/vmx/vmcs.c	Thu Nov 22 19:23:40 2007 +0000
     2.2 +++ b/xen/arch/x86/hvm/vmx/vmcs.c	Thu Nov 22 19:55:42 2007 +0000
     2.3 @@ -443,11 +443,8 @@ void vmx_disable_intercept_for_msr(struc
     2.4      }
     2.5  }
     2.6  
     2.7 -#define GUEST_SEGMENT_LIMIT     0xffffffff
     2.8 -
     2.9  static int construct_vmcs(struct vcpu *v)
    2.10  {
    2.11 -    union vmcs_arbytes arbytes;
    2.12      uint16_t sysenter_cs;
    2.13      unsigned long sysenter_eip;
    2.14  
    2.15 @@ -537,46 +534,39 @@ static int construct_vmcs(struct vcpu *v
    2.16      __vmwrite(GUEST_CS_BASE, 0);
    2.17  
    2.18      /* Guest segment limits. */
    2.19 -    __vmwrite(GUEST_ES_LIMIT, GUEST_SEGMENT_LIMIT);
    2.20 -    __vmwrite(GUEST_SS_LIMIT, GUEST_SEGMENT_LIMIT);
    2.21 -    __vmwrite(GUEST_DS_LIMIT, GUEST_SEGMENT_LIMIT);
    2.22 -    __vmwrite(GUEST_FS_LIMIT, GUEST_SEGMENT_LIMIT);
    2.23 -    __vmwrite(GUEST_GS_LIMIT, GUEST_SEGMENT_LIMIT);
    2.24 -    __vmwrite(GUEST_CS_LIMIT, GUEST_SEGMENT_LIMIT);
    2.25 +    __vmwrite(GUEST_ES_LIMIT, ~0u);
    2.26 +    __vmwrite(GUEST_SS_LIMIT, ~0u);
    2.27 +    __vmwrite(GUEST_DS_LIMIT, ~0u);
    2.28 +    __vmwrite(GUEST_FS_LIMIT, ~0u);
    2.29 +    __vmwrite(GUEST_GS_LIMIT, ~0u);
    2.30 +    __vmwrite(GUEST_CS_LIMIT, ~0u);
    2.31  
    2.32      /* Guest segment AR bytes. */
    2.33 -    arbytes.bytes = 0;
    2.34 -    arbytes.fields.seg_type = 0x3;          /* type = 3 */
    2.35 -    arbytes.fields.s = 1;                   /* code or data, i.e. not system */
    2.36 -    arbytes.fields.dpl = 0;                 /* DPL = 3 */
    2.37 -    arbytes.fields.p = 1;                   /* segment present */
    2.38 -    arbytes.fields.default_ops_size = 1;    /* 32-bit */
    2.39 -    arbytes.fields.g = 1;
    2.40 -    arbytes.fields.null_bit = 0;            /* not null */
    2.41 -    __vmwrite(GUEST_ES_AR_BYTES, arbytes.bytes);
    2.42 -    __vmwrite(GUEST_SS_AR_BYTES, arbytes.bytes);
    2.43 -    __vmwrite(GUEST_DS_AR_BYTES, arbytes.bytes);
    2.44 -    __vmwrite(GUEST_FS_AR_BYTES, arbytes.bytes);
    2.45 -    __vmwrite(GUEST_GS_AR_BYTES, arbytes.bytes);
    2.46 -    arbytes.fields.seg_type = 0xb;          /* type = 0xb */
    2.47 -    __vmwrite(GUEST_CS_AR_BYTES, arbytes.bytes);
    2.48 +    __vmwrite(GUEST_ES_AR_BYTES, 0xc093); /* read/write, accessed */
    2.49 +    __vmwrite(GUEST_SS_AR_BYTES, 0xc093);
    2.50 +    __vmwrite(GUEST_DS_AR_BYTES, 0xc093);
    2.51 +    __vmwrite(GUEST_FS_AR_BYTES, 0xc093);
    2.52 +    __vmwrite(GUEST_GS_AR_BYTES, 0xc093);
    2.53 +    __vmwrite(GUEST_CS_AR_BYTES, 0xc09b); /* exec/read, accessed */
    2.54 +
    2.55 +    /* Guest IDT. */
    2.56 +    __vmwrite(GUEST_IDTR_BASE, 0);
    2.57 +    __vmwrite(GUEST_IDTR_LIMIT, 0);
    2.58  
    2.59      /* Guest GDT. */
    2.60      __vmwrite(GUEST_GDTR_BASE, 0);
    2.61      __vmwrite(GUEST_GDTR_LIMIT, 0);
    2.62  
    2.63 -    /* Guest IDT. */
    2.64 -    __vmwrite(GUEST_IDTR_BASE, 0);
    2.65 -    __vmwrite(GUEST_IDTR_LIMIT, 0);
    2.66 +    /* Guest LDT. */
    2.67 +    __vmwrite(GUEST_LDTR_AR_BYTES, 0x0082); /* LDT */
    2.68 +    __vmwrite(GUEST_LDTR_SELECTOR, 0);
    2.69 +    __vmwrite(GUEST_LDTR_BASE, 0);
    2.70 +    __vmwrite(GUEST_LDTR_LIMIT, 0);
    2.71  
    2.72 -    /* Guest LDT and TSS. */
    2.73 -    arbytes.fields.s = 0;                   /* not code or data segement */
    2.74 -    arbytes.fields.seg_type = 0x2;          /* LTD */
    2.75 -    arbytes.fields.default_ops_size = 0;    /* 16-bit */
    2.76 -    arbytes.fields.g = 0;
    2.77 -    __vmwrite(GUEST_LDTR_AR_BYTES, arbytes.bytes);
    2.78 -    arbytes.fields.seg_type = 0xb;          /* 32-bit TSS (busy) */
    2.79 -    __vmwrite(GUEST_TR_AR_BYTES, arbytes.bytes);
    2.80 +    /* Guest TSS. */
    2.81 +    __vmwrite(GUEST_TR_AR_BYTES, 0x008b); /* 32-bit TSS (busy) */
    2.82 +    __vmwrite(GUEST_TR_BASE, 0);
    2.83 +    __vmwrite(GUEST_TR_LIMIT, 0xff);
    2.84  
    2.85      __vmwrite(GUEST_INTERRUPTIBILITY_INFO, 0);
    2.86      __vmwrite(GUEST_DR7, 0);
    2.87 @@ -600,13 +590,6 @@ static int construct_vmcs(struct vcpu *v
    2.88          __vmwrite(TPR_THRESHOLD, 0);
    2.89      }
    2.90  
    2.91 -    __vmwrite(GUEST_LDTR_SELECTOR, 0);
    2.92 -    __vmwrite(GUEST_LDTR_BASE, 0);
    2.93 -    __vmwrite(GUEST_LDTR_LIMIT, 0);
    2.94 -
    2.95 -    __vmwrite(GUEST_TR_BASE, 0);
    2.96 -    __vmwrite(GUEST_TR_LIMIT, 0xff);
    2.97 -
    2.98      vmx_vmcs_exit(v);
    2.99  
   2.100      paging_update_paging_modes(v); /* will update HOST & GUEST_CR3 as reqd */
     3.1 --- a/xen/include/asm-x86/hvm/svm/vmcb.h	Thu Nov 22 19:23:40 2007 +0000
     3.2 +++ b/xen/include/asm-x86/hvm/svm/vmcb.h	Thu Nov 22 19:55:42 2007 +0000
     3.3 @@ -303,8 +303,7 @@ enum VMEXIT_EXITCODE
     3.4      VMEXIT_INVALID          =  -1
     3.5  };
     3.6  
     3.7 -/* Definitions of segment state are borrowed by the generic HVM code. */
     3.8 -typedef segment_attributes_t svm_segment_attributes_t;
     3.9 +/* Definition of segment state is borrowed by the generic HVM code. */
    3.10  typedef segment_register_t svm_segment_register_t;
    3.11  
    3.12  typedef union