From nobody Sat Feb 7 01:37:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505933665596463.1507748211923; Wed, 20 Sep 2017 11:54:25 -0700 (PDT) Received: from localhost ([::1]:50203 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duk8e-0007BU-Qz for importer@patchew.org; Wed, 20 Sep 2017 14:54:24 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=C3=A9 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 s= ync) if (!log) { return; } - dev->log =3D NULL; - dev->log_size =3D 0; =20 --log->refcnt; if (log->refcnt =3D=3D 0) { @@ -396,6 +394,9 @@ static void vhost_log_put(struct vhost_dev *dev, bool s= ync) =20 g_free(log); } + + dev->log =3D NULL; + dev->log_size =3D 0; } =20 static bool vhost_dev_log_is_shared(struct vhost_dev *dev) --=20 1.7.1