ia64/xen-unstable

changeset 14638:ea55ead0fd47

hvm vmx: Better management of VMX control bitmaps.
Distinguish between 'nice to have' and 'must have' features.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Thu Mar 29 10:41:37 2007 +0100 (2007-03-29)
parents 78af882eb6fc
children 98b049ed2540
files xen/arch/x86/hvm/vmx/vmcs.c
line diff
     1.1 --- a/xen/arch/x86/hvm/vmx/vmcs.c	Wed Mar 28 20:19:11 2007 +0100
     1.2 +++ b/xen/arch/x86/hvm/vmx/vmcs.c	Thu Mar 29 10:41:37 2007 +0100
     1.3 @@ -37,41 +37,6 @@
     1.4  #include <xen/keyhandler.h>
     1.5  #include <asm/shadow.h>
     1.6  
     1.7 -/* Basic flags for Pin-based VM-execution controls. */
     1.8 -#define MONITOR_PIN_BASED_EXEC_CONTROLS                 \
     1.9 -    ( PIN_BASED_EXT_INTR_MASK |                         \
    1.10 -      PIN_BASED_NMI_EXITING )
    1.11 -
    1.12 -/* Basic flags for CPU-based VM-execution controls. */
    1.13 -#ifdef __x86_64__
    1.14 -#define MONITOR_CPU_BASED_EXEC_CONTROLS_SUBARCH         \
    1.15 -    ( CPU_BASED_CR8_LOAD_EXITING |                      \
    1.16 -      CPU_BASED_CR8_STORE_EXITING )
    1.17 -#else
    1.18 -#define MONITOR_CPU_BASED_EXEC_CONTROLS_SUBARCH 0
    1.19 -#endif
    1.20 -#define MONITOR_CPU_BASED_EXEC_CONTROLS                 \
    1.21 -    ( MONITOR_CPU_BASED_EXEC_CONTROLS_SUBARCH |         \
    1.22 -      CPU_BASED_HLT_EXITING |                           \
    1.23 -      CPU_BASED_INVDPG_EXITING |                        \
    1.24 -      CPU_BASED_MWAIT_EXITING |                         \
    1.25 -      CPU_BASED_MOV_DR_EXITING |                        \
    1.26 -      CPU_BASED_ACTIVATE_IO_BITMAP |                    \
    1.27 -      CPU_BASED_USE_TSC_OFFSETING )
    1.28 -
    1.29 -/* Basic flags for VM-Exit controls. */
    1.30 -#ifdef __x86_64__
    1.31 -#define MONITOR_VM_EXIT_CONTROLS_SUBARCH VM_EXIT_IA32E_MODE
    1.32 -#else
    1.33 -#define MONITOR_VM_EXIT_CONTROLS_SUBARCH 0
    1.34 -#endif
    1.35 -#define MONITOR_VM_EXIT_CONTROLS                        \
    1.36 -    ( MONITOR_VM_EXIT_CONTROLS_SUBARCH |                \
    1.37 -      VM_EXIT_ACK_INTR_ON_EXIT )
    1.38 -
    1.39 -/* Basic flags for VM-Entry controls. */
    1.40 -#define MONITOR_VM_ENTRY_CONTROLS                       0x00000000
    1.41 -
    1.42  /* Dynamic (run-time adjusted) execution control flags. */
    1.43  static u32 vmx_pin_based_exec_control;
    1.44  static u32 vmx_cpu_based_exec_control;
    1.45 @@ -80,41 +45,56 @@ static u32 vmx_vmentry_control;
    1.46  
    1.47  static u32 vmcs_revision_id;
    1.48  
    1.49 -static u32 adjust_vmx_controls(u32 ctrls, u32 msr)
    1.50 +static u32 adjust_vmx_controls(u32 ctl_min, u32 ctl_max, u32 msr)
    1.51  {
    1.52 -    u32 vmx_msr_low, vmx_msr_high;
    1.53 +    u32 vmx_msr_low, vmx_msr_high, ctl = ctl_max;
    1.54  
    1.55      rdmsr(msr, vmx_msr_low, vmx_msr_high);
    1.56  
    1.57 -    /* Bit == 0 means must be zero. */
    1.58 -    BUG_ON(ctrls & ~vmx_msr_high);
    1.59 +    ctl &= vmx_msr_high; /* bit == 0 in high word ==> must be zero */
    1.60 +    ctl |= vmx_msr_low;  /* bit == 1 in low word  ==> must be one  */
    1.61  
    1.62 -    /* Bit == 1 means must be one. */
    1.63 -    ctrls |= vmx_msr_low;
    1.64 +    /* Ensure minimum (required) set of control bits are supported. */
    1.65 +    BUG_ON(ctl_min & ~ctl);
    1.66 +    BUG_ON(ctl_min & ~ctl_max);
    1.67  
    1.68 -    return ctrls;
    1.69 +    return ctl;
    1.70  }
    1.71  
    1.72  void vmx_init_vmcs_config(void)
    1.73  {
    1.74 -    u32 vmx_msr_low, vmx_msr_high;
    1.75 +    u32 vmx_msr_low, vmx_msr_high, min, max;
    1.76      u32 _vmx_pin_based_exec_control;
    1.77      u32 _vmx_cpu_based_exec_control;
    1.78      u32 _vmx_vmexit_control;
    1.79      u32 _vmx_vmentry_control;
    1.80  
    1.81 -    _vmx_pin_based_exec_control =
    1.82 -        adjust_vmx_controls(MONITOR_PIN_BASED_EXEC_CONTROLS,
    1.83 -                            MSR_IA32_VMX_PINBASED_CTLS_MSR);
    1.84 -    _vmx_cpu_based_exec_control =
    1.85 -        adjust_vmx_controls(MONITOR_CPU_BASED_EXEC_CONTROLS,
    1.86 -                            MSR_IA32_VMX_PROCBASED_CTLS_MSR);
    1.87 -    _vmx_vmexit_control =
    1.88 -        adjust_vmx_controls(MONITOR_VM_EXIT_CONTROLS,
    1.89 -                            MSR_IA32_VMX_EXIT_CTLS_MSR);
    1.90 -    _vmx_vmentry_control =
    1.91 -        adjust_vmx_controls(MONITOR_VM_ENTRY_CONTROLS,
    1.92 -                            MSR_IA32_VMX_ENTRY_CTLS_MSR);
    1.93 +    min = max = PIN_BASED_EXT_INTR_MASK | PIN_BASED_NMI_EXITING;
    1.94 +    _vmx_pin_based_exec_control = adjust_vmx_controls(
    1.95 +        min, max, MSR_IA32_VMX_PINBASED_CTLS_MSR);
    1.96 +
    1.97 +    min = max = (CPU_BASED_HLT_EXITING |
    1.98 +                 CPU_BASED_INVDPG_EXITING |
    1.99 +                 CPU_BASED_MWAIT_EXITING |
   1.100 +                 CPU_BASED_MOV_DR_EXITING |
   1.101 +                 CPU_BASED_ACTIVATE_IO_BITMAP |
   1.102 +                 CPU_BASED_USE_TSC_OFFSETING);
   1.103 +#ifdef __x86_64__
   1.104 +    min = max |= CPU_BASED_CR8_LOAD_EXITING | CPU_BASED_CR8_STORE_EXITING;
   1.105 +#endif
   1.106 +    _vmx_cpu_based_exec_control = adjust_vmx_controls(
   1.107 +        min, max, MSR_IA32_VMX_PROCBASED_CTLS_MSR);
   1.108 +
   1.109 +    min = max = VM_EXIT_ACK_INTR_ON_EXIT;
   1.110 +#ifdef __x86_64__
   1.111 +    min = max |= VM_EXIT_IA32E_MODE;
   1.112 +#endif
   1.113 +    _vmx_vmexit_control = adjust_vmx_controls(
   1.114 +        min, max, MSR_IA32_VMX_EXIT_CTLS_MSR);
   1.115 +
   1.116 +    min = max = 0;
   1.117 +    _vmx_vmentry_control = adjust_vmx_controls(
   1.118 +        min, max, MSR_IA32_VMX_ENTRY_CTLS_MSR);
   1.119  
   1.120      rdmsr(MSR_IA32_VMX_BASIC_MSR, vmx_msr_low, vmx_msr_high);
   1.121