ia64/xen-unstable

changeset 18026:f454f2cac170

x86 hvm: New boot option 'softtsc' to cause RDTSC to be trapped-and-emulated.

Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jul 10 15:45:18 2008 +0100 (2008-07-10)
parents b7598d2e4791
children d5efa03793a2
files xen/arch/x86/hvm/hvm.c xen/arch/x86/hvm/svm/svm.c xen/arch/x86/hvm/svm/vmcb.c xen/arch/x86/hvm/vmx/vmcs.c xen/arch/x86/hvm/vmx/vmx.c xen/include/asm-x86/hvm/support.h
line diff
     1.1 --- a/xen/arch/x86/hvm/hvm.c	Thu Jul 10 15:32:18 2008 +0100
     1.2 +++ b/xen/arch/x86/hvm/hvm.c	Thu Jul 10 15:45:18 2008 +0100
     1.3 @@ -57,6 +57,9 @@ int hvm_enabled __read_mostly;
     1.4  unsigned int opt_hvm_debug_level __read_mostly;
     1.5  integer_param("hvm_debug", opt_hvm_debug_level);
     1.6  
     1.7 +int opt_softtsc;
     1.8 +boolean_param("softtsc", opt_softtsc);
     1.9 +
    1.10  struct hvm_function_table hvm_funcs __read_mostly;
    1.11  
    1.12  /* I/O permission bitmap is globally shared by all HVM guests. */
    1.13 @@ -148,7 +151,11 @@ u64 hvm_get_guest_tsc(struct vcpu *v)
    1.14  {
    1.15      u64 host_tsc;
    1.16  
    1.17 -    rdtscll(host_tsc);
    1.18 +    if ( opt_softtsc )
    1.19 +        host_tsc = hvm_get_guest_time(v);
    1.20 +    else
    1.21 +        rdtscll(host_tsc);
    1.22 +
    1.23      return host_tsc + v->arch.hvm_vcpu.cache_tsc_offset;
    1.24  }
    1.25  
    1.26 @@ -1651,6 +1658,16 @@ void hvm_cpuid(unsigned int input, unsig
    1.27      }
    1.28  }
    1.29  
    1.30 +void hvm_rdtsc_intercept(struct cpu_user_regs *regs)
    1.31 +{
    1.32 +    uint64_t tsc;
    1.33 +    struct vcpu *v = current;
    1.34 +
    1.35 +    tsc = hvm_get_guest_tsc(v);
    1.36 +    regs->eax = (uint32_t)tsc;
    1.37 +    regs->edx = (uint32_t)(tsc >> 32);
    1.38 +}
    1.39 +
    1.40  int hvm_msr_read_intercept(struct cpu_user_regs *regs)
    1.41  {
    1.42      uint32_t ecx = regs->ecx;
     2.1 --- a/xen/arch/x86/hvm/svm/svm.c	Thu Jul 10 15:32:18 2008 +0100
     2.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Thu Jul 10 15:45:18 2008 +0100
     2.3 @@ -1340,6 +1340,10 @@ asmlinkage void svm_vmexit_handler(struc
     2.4          hvm_triple_fault();
     2.5          break;
     2.6  
     2.7 +    case VMEXIT_RDTSC:
     2.8 +        hvm_rdtsc_intercept(regs);
     2.9 +        break;
    2.10 +
    2.11      case VMEXIT_RDTSCP:
    2.12      case VMEXIT_MONITOR:
    2.13      case VMEXIT_MWAIT:
     3.1 --- a/xen/arch/x86/hvm/svm/vmcb.c	Thu Jul 10 15:32:18 2008 +0100
     3.2 +++ b/xen/arch/x86/hvm/svm/vmcb.c	Thu Jul 10 15:45:18 2008 +0100
     3.3 @@ -165,7 +165,9 @@ static int construct_vmcb(struct vcpu *v
     3.4  
     3.5      /* TSC. */
     3.6      vmcb->tsc_offset = 0;
     3.7 -    
     3.8 +    if ( opt_softtsc )
     3.9 +        vmcb->general1_intercepts |= GENERAL1_INTERCEPT_RDTSC;
    3.10 +
    3.11      /* Guest EFER: *must* contain SVME or VMRUN will fail. */
    3.12      vmcb->efer = EFER_SVME;
    3.13  
     4.1 --- a/xen/arch/x86/hvm/vmx/vmcs.c	Thu Jul 10 15:32:18 2008 +0100
     4.2 +++ b/xen/arch/x86/hvm/vmx/vmcs.c	Thu Jul 10 15:45:18 2008 +0100
     4.3 @@ -95,7 +95,8 @@ static void vmx_init_vmcs_config(void)
     4.4             CPU_BASED_MWAIT_EXITING |
     4.5             CPU_BASED_MOV_DR_EXITING |
     4.6             CPU_BASED_ACTIVATE_IO_BITMAP |
     4.7 -           CPU_BASED_USE_TSC_OFFSETING);
     4.8 +           CPU_BASED_USE_TSC_OFFSETING |
     4.9 +           (opt_softtsc ? CPU_BASED_RDTSC_EXITING : 0));
    4.10      opt = (CPU_BASED_ACTIVATE_MSR_BITMAP |
    4.11             CPU_BASED_TPR_SHADOW |
    4.12             CPU_BASED_ACTIVATE_SECONDARY_CONTROLS);
     5.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Thu Jul 10 15:32:18 2008 +0100
     5.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Thu Jul 10 15:45:18 2008 +0100
     5.3 @@ -2205,6 +2205,11 @@ asmlinkage void vmx_vmexit_handler(struc
     5.4          vmx_invlpg_intercept(exit_qualification);
     5.5          break;
     5.6      }
     5.7 +    case EXIT_REASON_RDTSC:
     5.8 +        inst_len = __get_instruction_length();
     5.9 +        __update_guest_eip(inst_len);
    5.10 +        hvm_rdtsc_intercept(regs);
    5.11 +        break;
    5.12      case EXIT_REASON_VMCALL:
    5.13      {
    5.14          int rc;
     6.1 --- a/xen/include/asm-x86/hvm/support.h	Thu Jul 10 15:32:18 2008 +0100
     6.2 +++ b/xen/include/asm-x86/hvm/support.h	Thu Jul 10 15:45:18 2008 +0100
     6.3 @@ -125,6 +125,9 @@ int hvm_do_hypercall(struct cpu_user_reg
     6.4  void hvm_hlt(unsigned long rflags);
     6.5  void hvm_triple_fault(void);
     6.6  
     6.7 +extern int opt_softtsc;
     6.8 +void hvm_rdtsc_intercept(struct cpu_user_regs *regs);
     6.9 +
    6.10  /* These functions all return X86EMUL return codes. */
    6.11  int hvm_set_efer(uint64_t value);
    6.12  int hvm_set_cr0(unsigned long value);