From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53490) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpzni-0003fQ-LI for qemu-devel@nongnu.org; Thu, 07 Sep 2017 12:37:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpznd-0007B9-QK for qemu-devel@nongnu.org; Thu, 07 Sep 2017 12:37:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55928) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpznd-0007AX-HN for qemu-devel@nongnu.org; Thu, 07 Sep 2017 12:37:05 -0400 Date: Thu, 7 Sep 2017 17:36:52 +0100 From: "Dr. David Alan Gilbert" Message-ID: <20170907163651.GT2098@work-vm> References: <20170824192730.8440-1-dgilbert@redhat.com> <20170824192730.8440-12-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC v2 11/32] vhub: Open userfaultfd List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Marc-Andr=E9?= Lureau Cc: QEMU , Maxime Coquelin , a.perevalov@samsung.com, "Michael S. Tsirkin" , Laurent Vivier , aarcange@redhat.com, Felipe Franciosi , Peter Xu , Juan Quintela * Marc-Andr=E9 Lureau (marcandre.lureau@gmail.com) wrote: > I would rather use libvhost-user: message prefix (same for similar > libvhost-user patches) Done. > On Thu, Aug 24, 2017 at 12:27 PM, Dr. David Alan Gilbert (git) > wrote: > > From: "Dr. David Alan Gilbert" > > > > Open a userfaultfd (on a postcopy_advise) and send it back in > > the reply to the qemu for it to monitor. > > > > Signed-off-by: Dr. David Alan Gilbert > > --- > > contrib/libvhost-user/libvhost-user.c | 26 +++++++++++++++++++++++--= - > > contrib/libvhost-user/libvhost-user.h | 3 +++ > > 2 files changed, 26 insertions(+), 3 deletions(-) > > > > diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost= -user/libvhost-user.c > > index 47884c0a15..f9b5b12b28 100644 > > --- a/contrib/libvhost-user/libvhost-user.c > > +++ b/contrib/libvhost-user/libvhost-user.c > > @@ -15,6 +15,7 @@ > > > > #include > > #include > > +#include > > #include > > > > #include "qemu/atomic.h" > > @@ -773,11 +774,30 @@ vu_set_vring_enable_exec(VuDev *dev, VhostUserM= sg *vmsg) > > static bool > > vu_set_postcopy_advise(VuDev *dev, VhostUserMsg *vmsg) > > { > > - /* TODO: Open ufd, pass it back in the request > > - * TODO: Add addresses > > - */ > > + struct uffdio_api api_struct; > > + > > + dev->postcopy_ufd =3D syscall(__NR_userfaultfd, O_CLOEXEC | O_NO= NBLOCK); >=20 > This will likely fail to compile on !Linux, could you add some > appropriate #ifdef? Note that we already #include so this file only builds on Linux anyway before I came along, however I'll add some ifdef's for my new code. Dave > > + /* TODO: Add addresses */ > > vmsg->payload.u64 =3D 0xcafe; > > vmsg->size =3D sizeof(vmsg->payload.u64); > > + > > + if (dev->postcopy_ufd =3D=3D -1) { > > + vu_panic(dev, "Userfaultfd not available: %s", strerror(errn= o)); > > + goto out; > > + } > > + api_struct.api =3D UFFD_API; > > + api_struct.features =3D 0; > > + if (ioctl(dev->postcopy_ufd, UFFDIO_API, &api_struct)) { > > + vu_panic(dev, "Failed UFFDIO_API: %s", strerror(errno)); > > + close(dev->postcopy_ufd); > > + dev->postcopy_ufd =3D -1; > > + goto out; > > + } > > + /* TODO: Stash feature flags somewhere */ > > +out: > > + /* Return a ufd to the QEMU */ > > + vmsg->fd_num =3D 1; > > + vmsg->fds[0] =3D dev->postcopy_ufd; > > return true; /* =3D send a reply */ > > } > > > > diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost= -user/libvhost-user.h > > index 3987ce643d..3e8efdd919 100644 > > --- a/contrib/libvhost-user/libvhost-user.h > > +++ b/contrib/libvhost-user/libvhost-user.h > > @@ -234,6 +234,9 @@ struct VuDev { > > * re-initialize */ > > vu_panic_cb panic; > > const VuDevIface *iface; > > + > > + /* Postcopy data */ > > + int postcopy_ufd; > > }; > > > > typedef struct VuVirtqElement { > > -- > > 2.13.5 > > > > >=20 >=20 >=20 > --=20 > Marc-Andr=E9 Lureau -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK