From patchwork Thu Mar 25 13:58:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Litke X-Patchwork-Id: 48519 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0360DB7C98 for ; Fri, 26 Mar 2010 01:13:56 +1100 (EST) Received: from localhost ([127.0.0.1]:50902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NunnG-0005bb-1G for incoming@patchwork.ozlabs.org; Thu, 25 Mar 2010 10:12:18 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nuna0-0002xe-Kl for qemu-devel@nongnu.org; Thu, 25 Mar 2010 09:58:36 -0400 Received: from [140.186.70.92] (port=43171 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NunZz-0002wi-Hy for qemu-devel@nongnu.org; Thu, 25 Mar 2010 09:58:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NunZx-0000pT-Rr for qemu-devel@nongnu.org; Thu, 25 Mar 2010 09:58:35 -0400 Received: from e34.co.us.ibm.com ([32.97.110.152]:45095) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NunZx-0000p6-Me for qemu-devel@nongnu.org; Thu, 25 Mar 2010 09:58:33 -0400 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e34.co.us.ibm.com (8.14.3/8.13.1) with ESMTP id o2PDpiUM000454 for ; Thu, 25 Mar 2010 07:51:44 -0600 Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2PDwJaF110094 for ; Thu, 25 Mar 2010 07:58:20 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2PDwIlC002458 for ; Thu, 25 Mar 2010 07:58:19 -0600 Received: from [9.10.86.177] (aglitke.rchland.ibm.com [9.10.86.177]) by d03av04.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o2PDwIc9002421; Thu, 25 Mar 2010 07:58:18 -0600 Message-ID: <4BAB6BF9.30701@us.ibm.com> Date: Thu, 25 Mar 2010 08:58:17 -0500 From: Adam Litke User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: anthony@codemonkey.ws X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] balloon: Fix overflow when reporting actual memory size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Beginning with its introduction, the virtio balloon has had an overflow error that causes 'info balloon' to misreport the actual memory size when the balloon itself becomes larger than 4G. Use a cast when converting dev->actual from pages to kB to prevent overflows. Before: (qemu) info balloon balloon: actual=5120 (qemu) balloon 1025 (qemu) info balloon balloon: actual=1025 (qemu) balloon 1024 (qemu) info balloon balloon: actual=5120 After: (qemu) info balloon balloon: actual=5120 (qemu) balloon 1025 (qemu) info balloon balloon: actual=1025 (qemu) balloon 1024 (qemu) info balloon balloon: actual=1024 Signed-off-by: Adam Litke --- hw/virtio-balloon.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c index 086d9d1..6eedab1 100644 --- a/hw/virtio-balloon.c +++ b/hw/virtio-balloon.c @@ -78,7 +78,8 @@ static void stat_put(QDict *dict, const char *label, uint64_t val) static QObject *get_stats_qobject(VirtIOBalloon *dev) { QDict *dict = qdict_new(); - uint32_t actual = ram_size - (dev->actual << VIRTIO_BALLOON_PFN_SHIFT); + uint64_t actual = ram_size - ((uint64_t) dev->actual << + VIRTIO_BALLOON_PFN_SHIFT); stat_put(dict, "actual", actual); stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]);