From patchwork Fri Jul 3 20:47:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 491141 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5840D140775 for ; Sat, 4 Jul 2015 06:49:15 +1000 (AEST) Received: from localhost ([::1]:42518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZB7tZ-0000eH-KS for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2015 16:49:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZB7sG-0006iM-5i for qemu-devel@nongnu.org; Fri, 03 Jul 2015 16:47:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZB7sF-0003Yz-6a for qemu-devel@nongnu.org; Fri, 03 Jul 2015 16:47:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59819) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZB7sF-0003Ye-1T for qemu-devel@nongnu.org; Fri, 03 Jul 2015 16:47:51 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 9BFBC2E1224; Fri, 3 Jul 2015 20:47:50 +0000 (UTC) Received: from localhost ([10.3.113.8]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t63KlnSZ019808; Fri, 3 Jul 2015 16:47:49 -0400 From: Eduardo Habkost To: qemu-devel@nongnu.org, Peter Maydell Date: Fri, 3 Jul 2015 17:47:38 -0300 Message-Id: <1435956459-18454-3-git-send-email-ehabkost@redhat.com> In-Reply-To: <1435956459-18454-1-git-send-email-ehabkost@redhat.com> References: <1435956459-18454-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Richard Henderson Subject: [Qemu-devel] [PULL 2/3] target-i386: avoid overflow in the tsc-frequency property X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini The TSC frequency fits comfortably in an int when expressed in kHz, but it may overflow when converted to Hz. In this case, tsc-frequency returns a negative value because x86_cpuid_get_tsc_freq does a 32-bit multiplication before assigning to int64_t. For simplicity just make tsc_khz a 64-bit value. Spotted by Coverity. Signed-off-by: Paolo Bonzini Reviewed-by: Eduardo Habkost Signed-off-by: Eduardo Habkost --- target-i386/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target-i386/cpu.h b/target-i386/cpu.h index d2eaea8..bbeef22 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -961,7 +961,7 @@ typedef struct CPUX86State { uint8_t has_error_code; uint32_t sipi_vector; bool tsc_valid; - int tsc_khz; + int64_t tsc_khz; void *kvm_xsave_buf; uint64_t mcg_cap;