# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1215701118 -3600
# Node ID f454f2cac170a511b6727f84a8032a8132e05d84
# Parent b7598d2e479198399ae0a91ca5d8779df14e5a8b
x86 hvm: New boot option 'softtsc' to cause RDTSC to be trapped-and-emulated.
Signed-off-by: Dan Magenheimer <dan.magenheimer@xxxxxxxxxx>
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
xen/arch/x86/hvm/hvm.c | 19 ++++++++++++++++++-
xen/arch/x86/hvm/svm/svm.c | 4 ++++
xen/arch/x86/hvm/svm/vmcb.c | 4 +++-
xen/arch/x86/hvm/vmx/vmcs.c | 3 ++-
xen/arch/x86/hvm/vmx/vmx.c | 5 +++++
xen/include/asm-x86/hvm/support.h | 3 +++
6 files changed, 35 insertions(+), 3 deletions(-)
diff -r b7598d2e4791 -r f454f2cac170 xen/arch/x86/hvm/hvm.c
--- a/xen/arch/x86/hvm/hvm.c Thu Jul 10 15:32:18 2008 +0100
+++ b/xen/arch/x86/hvm/hvm.c Thu Jul 10 15:45:18 2008 +0100
@@ -57,6 +57,9 @@ unsigned int opt_hvm_debug_level __read_
unsigned int opt_hvm_debug_level __read_mostly;
integer_param("hvm_debug", opt_hvm_debug_level);
+int opt_softtsc;
+boolean_param("softtsc", opt_softtsc);
+
struct hvm_function_table hvm_funcs __read_mostly;
/* I/O permission bitmap is globally shared by all HVM guests. */
@@ -148,7 +151,11 @@ u64 hvm_get_guest_tsc(struct vcpu *v)
{
u64 host_tsc;
- rdtscll(host_tsc);
+ if ( opt_softtsc )
+ host_tsc = hvm_get_guest_time(v);
+ else
+ rdtscll(host_tsc);
+
return host_tsc + v->arch.hvm_vcpu.cache_tsc_offset;
}
@@ -1649,6 +1656,16 @@ void hvm_cpuid(unsigned int input, unsig
if ( vlapic_hw_disabled(vcpu_vlapic(v)) )
__clear_bit(X86_FEATURE_APIC & 31, edx);
}
+}
+
+void hvm_rdtsc_intercept(struct cpu_user_regs *regs)
+{
+ uint64_t tsc;
+ struct vcpu *v = current;
+
+ tsc = hvm_get_guest_tsc(v);
+ regs->eax = (uint32_t)tsc;
+ regs->edx = (uint32_t)(tsc >> 32);
}
int hvm_msr_read_intercept(struct cpu_user_regs *regs)
diff -r b7598d2e4791 -r f454f2cac170 xen/arch/x86/hvm/svm/svm.c
--- a/xen/arch/x86/hvm/svm/svm.c Thu Jul 10 15:32:18 2008 +0100
+++ b/xen/arch/x86/hvm/svm/svm.c Thu Jul 10 15:45:18 2008 +0100
@@ -1340,6 +1340,10 @@ asmlinkage void svm_vmexit_handler(struc
hvm_triple_fault();
break;
+ case VMEXIT_RDTSC:
+ hvm_rdtsc_intercept(regs);
+ break;
+
case VMEXIT_RDTSCP:
case VMEXIT_MONITOR:
case VMEXIT_MWAIT:
diff -r b7598d2e4791 -r f454f2cac170 xen/arch/x86/hvm/svm/vmcb.c
--- a/xen/arch/x86/hvm/svm/vmcb.c Thu Jul 10 15:32:18 2008 +0100
+++ b/xen/arch/x86/hvm/svm/vmcb.c Thu Jul 10 15:45:18 2008 +0100
@@ -165,7 +165,9 @@ static int construct_vmcb(struct vcpu *v
/* TSC. */
vmcb->tsc_offset = 0;
-
+ if ( opt_softtsc )
+ vmcb->general1_intercepts |= GENERAL1_INTERCEPT_RDTSC;
+
/* Guest EFER: *must* contain SVME or VMRUN will fail. */
vmcb->efer = EFER_SVME;
diff -r b7598d2e4791 -r f454f2cac170 xen/arch/x86/hvm/vmx/vmcs.c
--- a/xen/arch/x86/hvm/vmx/vmcs.c Thu Jul 10 15:32:18 2008 +0100
+++ b/xen/arch/x86/hvm/vmx/vmcs.c Thu Jul 10 15:45:18 2008 +0100
@@ -95,7 +95,8 @@ static void vmx_init_vmcs_config(void)
CPU_BASED_MWAIT_EXITING |
CPU_BASED_MOV_DR_EXITING |
CPU_BASED_ACTIVATE_IO_BITMAP |
- CPU_BASED_USE_TSC_OFFSETING);
+ CPU_BASED_USE_TSC_OFFSETING |
+ (opt_softtsc ? CPU_BASED_RDTSC_EXITING : 0));
opt = (CPU_BASED_ACTIVATE_MSR_BITMAP |
CPU_BASED_TPR_SHADOW |
CPU_BASED_ACTIVATE_SECONDARY_CONTROLS);
diff -r b7598d2e4791 -r f454f2cac170 xen/arch/x86/hvm/vmx/vmx.c
--- a/xen/arch/x86/hvm/vmx/vmx.c Thu Jul 10 15:32:18 2008 +0100
+++ b/xen/arch/x86/hvm/vmx/vmx.c Thu Jul 10 15:45:18 2008 +0100
@@ -2205,6 +2205,11 @@ asmlinkage void vmx_vmexit_handler(struc
vmx_invlpg_intercept(exit_qualification);
break;
}
+ case EXIT_REASON_RDTSC:
+ inst_len = __get_instruction_length();
+ __update_guest_eip(inst_len);
+ hvm_rdtsc_intercept(regs);
+ break;
case EXIT_REASON_VMCALL:
{
int rc;
diff -r b7598d2e4791 -r f454f2cac170 xen/include/asm-x86/hvm/support.h
--- a/xen/include/asm-x86/hvm/support.h Thu Jul 10 15:32:18 2008 +0100
+++ b/xen/include/asm-x86/hvm/support.h Thu Jul 10 15:45:18 2008 +0100
@@ -125,6 +125,9 @@ void hvm_hlt(unsigned long rflags);
void hvm_hlt(unsigned long rflags);
void hvm_triple_fault(void);
+extern int opt_softtsc;
+void hvm_rdtsc_intercept(struct cpu_user_regs *regs);
+
/* These functions all return X86EMUL return codes. */
int hvm_set_efer(uint64_t value);
int hvm_set_cr0(unsigned long value);
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|