Commit d913b904 authored by Chris J Arges's avatar Chris J Arges Committed by Paolo Bonzini

kvm: svm: move WARN_ON in svm_adjust_tsc_offset

When running the tsc_adjust kvm-unit-test on an AMD processor with the
IA32_TSC_ADJUST feature enabled, the WARN_ON in svm_adjust_tsc_offset can be
triggered. This WARN_ON checks for a negative adjustment in case __scale_tsc
is called; however it may trigger unnecessary warnings.

This patch moves the WARN_ON to trigger only if __scale_tsc will actually be
called from svm_adjust_tsc_offset. In addition make adj in kvm_set_msr_common
s64 since this can have signed values.
Signed-off-by: default avatarChris J Arges <chris.j.arges@canonical.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 54b98bff
...@@ -1056,9 +1056,11 @@ static void svm_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment, bool ho ...@@ -1056,9 +1056,11 @@ static void svm_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment, bool ho
{ {
struct vcpu_svm *svm = to_svm(vcpu); struct vcpu_svm *svm = to_svm(vcpu);
if (host) {
if (svm->tsc_ratio != TSC_RATIO_DEFAULT)
WARN_ON(adjustment < 0); WARN_ON(adjustment < 0);
if (host) adjustment = svm_scale_tsc(vcpu, (u64)adjustment);
adjustment = svm_scale_tsc(vcpu, adjustment); }
svm->vmcb->control.tsc_offset += adjustment; svm->vmcb->control.tsc_offset += adjustment;
if (is_guest_mode(vcpu)) if (is_guest_mode(vcpu))
......
...@@ -2143,7 +2143,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ...@@ -2143,7 +2143,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
case MSR_IA32_TSC_ADJUST: case MSR_IA32_TSC_ADJUST:
if (guest_cpuid_has_tsc_adjust(vcpu)) { if (guest_cpuid_has_tsc_adjust(vcpu)) {
if (!msr_info->host_initiated) { if (!msr_info->host_initiated) {
u64 adj = data - vcpu->arch.ia32_tsc_adjust_msr; s64 adj = data - vcpu->arch.ia32_tsc_adjust_msr;
kvm_x86_ops->adjust_tsc_offset(vcpu, adj, true); kvm_x86_ops->adjust_tsc_offset(vcpu, adj, true);
} }
vcpu->arch.ia32_tsc_adjust_msr = data; vcpu->arch.ia32_tsc_adjust_msr = data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment