From patchwork Wed Sep 20 18:53:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Felipe Franciosi X-Patchwork-Id: 816401 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3xy8632mjYz9s7g for ; Thu, 21 Sep 2017 04:53:47 +1000 (AEST) Received: from localhost ([::1]:50201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duk81-0006b8-Hk for incoming@patchwork.ozlabs.org; Wed, 20 Sep 2017 14:53:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duk7W-0006Zx-JH for qemu-devel@nongnu.org; Wed, 20 Sep 2017 14:53:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duk7T-0007Wl-Ie for qemu-devel@nongnu.org; Wed, 20 Sep 2017 14:53:14 -0400 Received: from 206-15-90-246.static.twtelecom.net ([206.15.90.246]:56921 helo=mailrelay.nutanix.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duk7T-0007SR-Cf for qemu-devel@nongnu.org; Wed, 20 Sep 2017 14:53:11 -0400 Received: from felipe-franciosi.dev.eng.nutanix.com. (felipe-franciosi.dev.eng.nutanix.com [10.4.66.171]) by mailrelay.nutanix.com (Postfix) with ESMTP id EB12940F83; Wed, 20 Sep 2017 11:53:09 -0700 (PDT) From: Felipe Franciosi To: Jason Wang , Marc-Andre Lureau , "Michael S. Tsirkin" , Paolo Bonzini Date: Wed, 20 Sep 2017 11:53:06 -0700 Message-Id: <1505933586-11296-1-git-send-email-felipe@nutanix.com> X-Mailer: git-send-email 1.7.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 206.15.90.246 Subject: [Qemu-devel] [PATCH] virtio/vhost: reset dev->log after syncing 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: qemu-devel@nongnu.org, Felipe Franciosi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" vhost_log_put() is called to decomission the dirty log between qemu and a vhost device when stopping the device. Such a call can happen from migration_completion(). Present code sets dev->log_size to zero too early in vhost_log_put(), causing the sync check to always return false. As a consequence, the last pass on the dirty bitmap never happens at the end of migration. If a vhost device was busy (writing to guest memory) until the last moments before vhost_virtqueue_stop(), this error will result in guest memory corruption (at least) following migrations. Signed-off-by: Felipe Franciosi Acked-by: Jason Wang Reviewed-by: Marc-André Lureau --- hw/virtio/vhost.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 5fd69f0..ddc42f0 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -375,8 +375,6 @@ static void vhost_log_put(struct vhost_dev *dev, bool sync) if (!log) { return; } - dev->log = NULL; - dev->log_size = 0; --log->refcnt; if (log->refcnt == 0) { @@ -396,6 +394,9 @@ static void vhost_log_put(struct vhost_dev *dev, bool sync) g_free(log); } + + dev->log = NULL; + dev->log_size = 0; } static bool vhost_dev_log_is_shared(struct vhost_dev *dev)