OSDN Git Service

KVM: x86: fix WARN_ON check of an unsigned less than zero
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 12 Feb 2020 12:27:10 +0000 (13:27 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 12 Feb 2020 19:09:46 +0000 (20:09 +0100)
The check cpu->hv_clock.system_time < 0 is redundant since system_time
is a u64 and hence can never be less than zero.  But what was actually
meant is to check that the result is positive, since kernel_ns and
v->kvm->arch.kvmclock_offset are both s64.

Reported-by: Colin King <colin.king@canonical.com>
Suggested-by: Sean Christopherson <sean.j.christopherson@intel.com>
Addresses-Coverity: ("Macro compares unsigned to 0")
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c

index fd9e2f6..fb5d64e 100644 (file)
@@ -2444,7 +2444,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
        vcpu->hv_clock.tsc_timestamp = tsc_timestamp;
        vcpu->hv_clock.system_time = kernel_ns + v->kvm->arch.kvmclock_offset;
        vcpu->last_guest_tsc = tsc_timestamp;
-       WARN_ON(vcpu->hv_clock.system_time < 0);
+       WARN_ON((s64)vcpu->hv_clock.system_time < 0);
 
        /* If the host uses TSC clocksource, then it is stable */
        pvclock_flags = 0;