From nobody Fri Oct 24 22:13:28 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518788130209888.7118236443002; Fri, 16 Feb 2018 05:35:30 -0800 (PST) Received: from localhost ([::1]:48387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emgAc-0008Km-P3 for importer@patchew.org; Fri, 16 Feb 2018 08:35:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emfsx-0001g0-V9 for qemu-devel@nongnu.org; Fri, 16 Feb 2018 08:17:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emfsv-00069c-5F for qemu-devel@nongnu.org; Fri, 16 Feb 2018 08:17:07 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40512 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1emfsu-00068x-Vw for qemu-devel@nongnu.org; Fri, 16 Feb 2018 08:17:05 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2C928182D32 for ; Fri, 16 Feb 2018 13:17:04 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B698213AEE2; Fri, 16 Feb 2018 13:17:03 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, maxime.coquelin@redhat.com, marcandre.lureau@redhat.com, peterx@redhat.com, imammedo@redhat.com, mst@redhat.com Date: Fri, 16 Feb 2018 13:16:20 +0000 Message-Id: <20180216131625.9639-25-dgilbert@redhat.com> In-Reply-To: <20180216131625.9639-1-dgilbert@redhat.com> References: <20180216131625.9639-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Feb 2018 13:17:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Feb 2018 13:17:04 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dgilbert@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 24/29] vhost-user: Add VHOST_USER_POSTCOPY_END message 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: aarcange@redhat.com, quintela@redhat.com 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" From: "Dr. David Alan Gilbert" This message is sent just before the end of postcopy to get the client to stop using userfault since we wont respond to any more requests. It should close userfaultfd so that any other pages get mapped to the backing file automatically by the kernel, since at this point we know we've received everything. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu --- contrib/libvhost-user/libvhost-user.c | 23 +++++++++++++++++++++++ contrib/libvhost-user/libvhost-user.h | 1 + docs/interop/vhost-user.txt | 8 ++++++++ hw/virtio/vhost-user.c | 1 + 4 files changed, 33 insertions(+) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/= libvhost-user.c index 1b224af706..1f988ab787 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -99,6 +99,7 @@ vu_request_to_string(unsigned int req) REQ(VHOST_USER_SET_CONFIG), REQ(VHOST_USER_POSTCOPY_ADVISE), REQ(VHOST_USER_POSTCOPY_LISTEN), + REQ(VHOST_USER_POSTCOPY_END), REQ(VHOST_USER_MAX), }; #undef REQ @@ -1095,6 +1096,26 @@ vu_set_postcopy_listen(VuDev *dev, VhostUserMsg *vms= g) vmsg->payload.u64 =3D 0; /* Success */ return true; } + +static bool +vu_set_postcopy_end(VuDev *dev, VhostUserMsg *vmsg) +{ + DPRINT("%s: Entry\n", __func__); + dev->postcopy_listening =3D false; + if (dev->postcopy_ufd > 0) { + close(dev->postcopy_ufd); + dev->postcopy_ufd =3D -1; + DPRINT("%s: Done close\n", __func__); + } + + vmsg->fd_num =3D 0; + vmsg->payload.u64 =3D 0; + vmsg->size =3D sizeof(vmsg->payload.u64); + vmsg->flags =3D VHOST_USER_VERSION | VHOST_USER_REPLY_MASK; + DPRINT("%s: exit\n", __func__); + return true; +} + static bool vu_process_message(VuDev *dev, VhostUserMsg *vmsg) { @@ -1170,6 +1191,8 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg) return vu_set_postcopy_advise(dev, vmsg); case VHOST_USER_POSTCOPY_LISTEN: return vu_set_postcopy_listen(dev, vmsg); + case VHOST_USER_POSTCOPY_END: + return vu_set_postcopy_end(dev, vmsg); default: vmsg_close_fds(vmsg); vu_panic(dev, "Unhandled request: %d", vmsg->request); diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/= libvhost-user.h index fcba53c3c3..9696b89f6e 100644 --- a/contrib/libvhost-user/libvhost-user.h +++ b/contrib/libvhost-user/libvhost-user.h @@ -84,6 +84,7 @@ typedef enum VhostUserRequest { VHOST_USER_SET_CONFIG =3D 25, VHOST_USER_POSTCOPY_ADVISE =3D 26, VHOST_USER_POSTCOPY_LISTEN =3D 27, + VHOST_USER_POSTCOPY_END =3D 28, VHOST_USER_MAX } VhostUserRequest; =20 diff --git a/docs/interop/vhost-user.txt b/docs/interop/vhost-user.txt index 5bbcab2cc4..4bf7d8ef99 100644 --- a/docs/interop/vhost-user.txt +++ b/docs/interop/vhost-user.txt @@ -697,6 +697,14 @@ Master message types =20 Master advises slave that a transition to postcopy mode has happened. =20 + * VHOST_USER_POSTCOPY_END + Id: 28 + Slave payload: u64 + + Master advises that postcopy migration has now completed. The + slave must disable the userfaultfd. The response is an acknowledgeme= nt + only. + Slave message types ------------------- =20 diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 74807091a0..cf7923b25f 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -78,6 +78,7 @@ typedef enum VhostUserRequest { VHOST_USER_SET_CONFIG =3D 25, VHOST_USER_POSTCOPY_ADVISE =3D 26, VHOST_USER_POSTCOPY_LISTEN =3D 27, + VHOST_USER_POSTCOPY_END =3D 28, VHOST_USER_MAX } VhostUserRequest; =20 --=20 2.14.3