diff mbox series

[v2,2/2] KVM: x86: Trace changes to active TSC offset regardless if vCPU in guest-mode

Message ID 20181108095130.64904-2-liran.alon@oracle.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] KVM: nVMX/nSVM: Fix bug which sets vcpu->arch.tsc_offset to L1 tsc_offset | expand

Commit Message

Liran Alon Nov. 8, 2018, 9:51 a.m. UTC
From some unknown reasons, kvm_x86_ops->write_tsc_offset() skipped trace
of change to active TSC offset in case vCPU is in guest-mode.

This patch changes write_tsc_offset() behavior to trace any change
to active TSC offset to aid debugging.

Reviewed-by: Mihai Carabas <mihai.carabas@oracle.com>
Signed-off-by: Liran Alon <liran.alon@oracle.com>
---
 arch/x86/kvm/svm.c | 8 ++++----
 arch/x86/kvm/vmx.c | 5 ++---
 2 files changed, 6 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 842d4bb053d1..bcf1433f0d85 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1456,11 +1456,11 @@  static u64 svm_write_tsc_offset(struct kvm_vcpu *vcpu, u64 l1_offset)
 		g_tsc_offset = svm->vmcb->control.tsc_offset -
 			       svm->nested.hsave->control.tsc_offset;
 		svm->nested.hsave->control.tsc_offset = l1_offset;
-	} else
-		trace_kvm_write_tsc_offset(vcpu->vcpu_id,
-					   svm->vmcb->control.tsc_offset,
-					   l1_offset);
+	}
 
+	trace_kvm_write_tsc_offset(vcpu->vcpu_id,
+				   svm->vmcb->control.tsc_offset,
+				   l1_offset + g_tsc_offset);
 	svm->vmcb->control.tsc_offset = l1_offset + g_tsc_offset;
 
 	mark_dirty(svm->vmcb, VMCB_INTERCEPTS);
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 20d90ebd6cc8..36456314bc0f 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3465,11 +3465,10 @@  static u64 vmx_write_tsc_offset(struct kvm_vcpu *vcpu, u64 l1_offset)
 		struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
 		if (nested_cpu_has(vmcs12, CPU_BASED_USE_TSC_OFFSETING))
 			active_offset += vmcs12->tsc_offset;
-	} else {
-		trace_kvm_write_tsc_offset(vcpu->vcpu_id,
-					   vmcs_read64(TSC_OFFSET), l1_offset);
 	}
 
+	trace_kvm_write_tsc_offset(vcpu->vcpu_id,
+				   vmcs_read64(TSC_OFFSET), active_offset);
 	vmcs_write64(TSC_OFFSET, active_offset);
 	return active_offset;
 }