Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 271492
b: refs/heads/master
c: 27fc51b
h: refs/heads/master
v: v3
  • Loading branch information
Nadav Har'El authored and Avi Kivity committed Sep 25, 2011
1 parent 8d177f5 commit 3cef354
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d5c1785d2f3aabe284d91bc7fc8f0abc58525dc9
refs/heads/master: 27fc51b21cea3386a6672699631975d1097f9d39
31 changes: 21 additions & 10 deletions trunk/arch/x86/kvm/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1777,15 +1777,23 @@ static void vmx_set_tsc_khz(struct kvm_vcpu *vcpu, u32 user_tsc_khz)
*/
static void vmx_write_tsc_offset(struct kvm_vcpu *vcpu, u64 offset)
{
vmcs_write64(TSC_OFFSET, offset);
if (is_guest_mode(vcpu))
if (is_guest_mode(vcpu)) {
/*
* We're here if L1 chose not to trap the TSC MSR. Since
* prepare_vmcs12() does not copy tsc_offset, we need to also
* set the vmcs12 field here.
* We're here if L1 chose not to trap WRMSR to TSC. According
* to the spec, this should set L1's TSC; The offset that L1
* set for L2 remains unchanged, and still needs to be added
* to the newly set TSC to get L2's TSC.
*/
get_vmcs12(vcpu)->tsc_offset = offset -
to_vmx(vcpu)->nested.vmcs01_tsc_offset;
struct vmcs12 *vmcs12;
to_vmx(vcpu)->nested.vmcs01_tsc_offset = offset;
/* recalculate vmcs02.TSC_OFFSET: */
vmcs12 = get_vmcs12(vcpu);
vmcs_write64(TSC_OFFSET, offset +
(nested_cpu_has(vmcs12, CPU_BASED_USE_TSC_OFFSETING) ?
vmcs12->tsc_offset : 0));
} else {
vmcs_write64(TSC_OFFSET, offset);
}
}

static void vmx_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment)
Expand Down Expand Up @@ -6485,8 +6493,11 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)

set_cr4_guest_host_mask(vmx);

vmcs_write64(TSC_OFFSET,
vmx->nested.vmcs01_tsc_offset + vmcs12->tsc_offset);
if (vmcs12->cpu_based_vm_exec_control & CPU_BASED_USE_TSC_OFFSETING)
vmcs_write64(TSC_OFFSET,
vmx->nested.vmcs01_tsc_offset + vmcs12->tsc_offset);
else
vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset);

if (enable_vpid) {
/*
Expand Down Expand Up @@ -6893,7 +6904,7 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu)

load_vmcs12_host_state(vcpu, vmcs12);

/* Update TSC_OFFSET if vmx_adjust_tsc_offset() was used while L2 ran */
/* Update TSC_OFFSET if TSC was changed while L2 ran */
vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset);

/* This is needed for same reason as it was needed in prepare_vmcs02 */
Expand Down

0 comments on commit 3cef354

Please sign in to comment.