From patchwork Fri Aug 5 11:36:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladi Prosek X-Patchwork-Id: 9265269 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 8A46160754 for ; Fri, 5 Aug 2016 11:37:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72EB32766D for ; Fri, 5 Aug 2016 11:37:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 670FA2843B; Fri, 5 Aug 2016 11:37:24 +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 F14222766D for ; Fri, 5 Aug 2016 11:37:23 +0000 (UTC) Received: from localhost ([::1]:44698 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVdRL-00059V-5E for patchwork-qemu-devel@patchwork.kernel.org; Fri, 05 Aug 2016 07:37:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVdR5-00058r-4Z for qemu-devel@nongnu.org; Fri, 05 Aug 2016 07:37:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bVdR0-0001co-2f for qemu-devel@nongnu.org; Fri, 05 Aug 2016 07:37:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVdQz-0001cd-TL for qemu-devel@nongnu.org; Fri, 05 Aug 2016 07:37:02 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C23DC057FAC; Fri, 5 Aug 2016 11:37:01 +0000 (UTC) Received: from dhcp-1-107.brq.redhat.com (ovpn-112-72.ams2.redhat.com [10.36.112.72]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u75BauiM020480; Fri, 5 Aug 2016 07:36:57 -0400 From: Ladi Prosek To: qemu-devel@nongnu.org Date: Fri, 5 Aug 2016 13:36:32 +0200 Message-Id: <1470396992-14564-1-git-send-email-lprosek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 05 Aug 2016 11:37:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3] 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: Ladi Prosek , pbonzini@redhat.com, liang.z.li@intel.com, dgilbert@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The stats_vq_elem field keeps track of the state of the balloon stats virtqueue protocol but it wasn't preserved across migrations, resulting in losing guest memory status updates on the receiving VM. This commit adds a new VM state change handler which resets stats_vq_elem to NULL when the VM is stopped, eliminating the need for the field to be migrated. When the VM starts running again, the field is reinitialized by re-popping the element from the virtqueue. Signed-off-by: Ladi Prosek Suggested-by: Michael S. Tsirkin --- hw/virtio/virtio-balloon.c | 23 +++++++++++++++++++++++ include/hw/virtio/virtio-balloon.h | 1 + 2 files changed, 24 insertions(+) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 5af429a..65457e9 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -423,6 +423,26 @@ static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f, return 0; } +static void virtio_balloon_vmstate_cb(void *opaque, int running, + RunState state) +{ + VirtIOBalloon *s = opaque; + + if (!running) { + /* put the stats element back if the VM is not running */ + if (s->stats_vq_elem != NULL) { + virtqueue_discard(s->svq, s->stats_vq_elem, s->stats_vq_offset); + g_free(s->stats_vq_elem); + s->stats_vq_elem = NULL; + } + + } else { + /* poll stats queue for the element we may have discarded + * when the VM was stopped */ + virtio_balloon_receive_stats(VIRTIO_DEVICE(s), s->svq); + } +} + static void virtio_balloon_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -446,6 +466,8 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp) s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats); reset_stats(s); + + s->change = qemu_add_vm_change_state_handler(virtio_balloon_vmstate_cb, s); } static void virtio_balloon_device_unrealize(DeviceState *dev, Error **errp) @@ -453,6 +475,7 @@ static void virtio_balloon_device_unrealize(DeviceState *dev, Error **errp) VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIOBalloon *s = VIRTIO_BALLOON(dev); + qemu_del_vm_change_state_handler(s->change); balloon_stats_destroy_timer(s); qemu_remove_balloon_handler(s); virtio_cleanup(vdev); diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h index 1ea13bd..d72ff7f 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -43,6 +43,7 @@ typedef struct VirtIOBalloon { int64_t stats_last_update; int64_t stats_poll_interval; uint32_t host_features; + VMChangeStateEntry *change; } VirtIOBalloon; #endif