From patchwork Wed Jul 6 02:36:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liang Li X-Patchwork-Id: 9215341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 39DA86048F for ; Wed, 6 Jul 2016 02:44:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21995285C6 for ; Wed, 6 Jul 2016 02:44:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 166A6285C9; Wed, 6 Jul 2016 02:44:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B1BD4285C6 for ; Wed, 6 Jul 2016 02:44:37 +0000 (UTC) Received: from localhost ([::1]:59021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKcpI-0006Uh-Ux for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Jul 2016 22:44:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKcp3-0006UP-6e for qemu-devel@nongnu.org; Tue, 05 Jul 2016 22:44:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKcox-00071S-VO for qemu-devel@nongnu.org; Tue, 05 Jul 2016 22:44:21 -0400 Received: from mga01.intel.com ([192.55.52.88]:30348) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKcox-00071J-Ox for qemu-devel@nongnu.org; Tue, 05 Jul 2016 22:44:15 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP; 05 Jul 2016 19:44:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,316,1464678000"; d="scan'208";a="134426577" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.123]) by fmsmga004.fm.intel.com with ESMTP; 05 Jul 2016 19:44:13 -0700 From: Liang Li To: qemu-devel@nongnu.org Date: Wed, 6 Jul 2016 10:36:33 +0800 Message-Id: <1467772593-29703-1-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 Subject: [Qemu-devel] [PATCH v2] balloon: Fix failure of updating guest memory status X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Liang Li , Ladi Prosek , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP After live migration, 'guest-stats' can't get the expected memory status in the guest. This issue is caused by commit 4eae2a657d. The value of 's->stats_vq_elem' will be NULL after live migration, and the check in the function 'balloon_stats_poll_cb()' will prevent the 'virtio_notify()' from executing. So guest will not update the memory status. Commit 4eae2a657d is doing the right thing, but 's->stats_vq_elem' should be treated as part of balloon device state and migrated to destination if it's not NULL to make everything works well. Signed-off-by: Liang Li Suggested-by: Paolo Bonzini Cc: Michael S. Tsirkin Cc: Ladi Prosek Cc: Paolo Bonzini --- hw/virtio/virtio-balloon.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 557d3f9..64e80c6 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -31,6 +31,7 @@ #include "hw/virtio/virtio-access.h" #define BALLOON_PAGE_SIZE (1 << VIRTIO_BALLOON_PFN_SHIFT) +#define BALLOON_VERSION 2 static void balloon_page(void *addr, int deflate) { @@ -404,15 +405,24 @@ static void virtio_balloon_save(QEMUFile *f, void *opaque) static void virtio_balloon_save_device(VirtIODevice *vdev, QEMUFile *f) { VirtIOBalloon *s = VIRTIO_BALLOON(vdev); + uint16_t elem_num = 0; qemu_put_be32(f, s->num_pages); qemu_put_be32(f, s->actual); + if (s->stats_vq_elem != NULL) { + elem_num = 1; + } + qemu_put_be16(f, elem_num); + if (elem_num) { + qemu_put_virtqueue_element(f, s->stats_vq_elem); + } } static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id) { - if (version_id != 1) + if (version_id < 1 || version_id > BALLOON_VERSION) { return -EINVAL; + } return virtio_load(VIRTIO_DEVICE(opaque), f, version_id); } @@ -421,9 +431,17 @@ static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f, int version_id) { VirtIOBalloon *s = VIRTIO_BALLOON(vdev); + uint16_t elem_num = 0; s->num_pages = qemu_get_be32(f); s->actual = qemu_get_be32(f); + if (version_id == BALLOON_VERSION) { + elem_num = qemu_get_be16(f); + if (elem_num == 1) { + s->stats_vq_elem = + qemu_get_virtqueue_element(f, sizeof(VirtQueueElement)); + } + } if (balloon_stats_enabled(s)) { balloon_stats_change_timer(s, s->stats_poll_interval); @@ -455,7 +473,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp) reset_stats(s); - register_savevm(dev, "virtio-balloon", -1, 1, + register_savevm(dev, "virtio-balloon", -1, BALLOON_VERSION, virtio_balloon_save, virtio_balloon_load, s); }