From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKUqq-0005pX-Ml for qemu-devel@nongnu.org; Wed, 29 Jul 2015 13:09:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZKUql-0005pL-12 for qemu-devel@nongnu.org; Wed, 29 Jul 2015 13:09:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKUqk-0005p8-Py for qemu-devel@nongnu.org; Wed, 29 Jul 2015 13:09:02 -0400 Date: Wed, 29 Jul 2015 18:08:58 +0100 From: "Dr. David Alan Gilbert" Message-ID: <20150729170857.GM2267@work-vm> References: <1438105003-29501-1-git-send-email-marcandre.lureau@redhat.com> <1438105003-29501-5-git-send-email-marcandre.lureau@redhat.com> <20150729165325.GL2267@work-vm> <1279508338.593439.1438189491214.JavaMail.zimbra@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1279508338.593439.1438189491214.JavaMail.zimbra@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 4/9] vhost: alloc shareable log List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Marc-Andr=E9?= Lureau Cc: haifeng lin , mst@redhat.com, thibaut collet , jasowang@redhat.com, qemu-devel@nongnu.org, pbonzini@redhat.com, =?iso-8859-1?Q?Marc-Andr=E9?= Lureau * Marc-Andr=E9 Lureau (mlureau@redhat.com) wrote: > Hi >=20 > ----- Original Message ----- > > * Marc-Andr=E9 Lureau (marcandre.lureau@redhat.com) wrote: > > > If the backend is of type VHOST_BACKEND_TYPE_USER, allocate > > > shareable memory. > > >=20 > > > Note: vhost_log_get() can use a global "vhost_log" that can be shar= ed by > > > several vhost devices. We may want instead a common shareable log a= nd a > > > common non-shareable one. > > >=20 > > > Signed-off-by: Marc-Andr=E9 Lureau > > > --- > > > hw/virtio/vhost.c | 38 +++++++++++++++++++++++++++++++----= --- > > > include/hw/virtio/vhost.h | 3 ++- > > > 2 files changed, 33 insertions(+), 8 deletions(-) > > >=20 > > > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c > > > index 2712c6f..862e786 100644 > > > --- a/hw/virtio/vhost.c > > > +++ b/hw/virtio/vhost.c > > > @@ -18,6 +18,7 @@ > > > #include "qemu/atomic.h" > > > #include "qemu/range.h" > > > #include "qemu/error-report.h" > > > +#include "qemu/memfd.h" > > > #include > > > #include "exec/address-spaces.h" > > > #include "hw/virtio/virtio-bus.h" > > > @@ -286,20 +287,34 @@ static uint64_t vhost_get_log_size(struct vho= st_dev > > > *dev) > > > } > > > return log_size; > > > } > > > -static struct vhost_log *vhost_log_alloc(uint64_t size) > > > + > > > +static struct vhost_log *vhost_log_alloc(uint64_t size, bool share= ) > > > { > > > - struct vhost_log *log =3D g_malloc0(sizeof *log + size * > > > sizeof(*(log->log))); > > > + struct vhost_log *log; > > > + uint64_t logsize =3D size * sizeof(*(log->log)); > > > + int fd =3D -1; > > > + > > > + log =3D g_new0(struct vhost_log, 1); > > > + if (share) { > > > + log->log =3D qemu_memfd_alloc("vhost-log", logsize, > > > + F_SEAL_GROW|F_SEAL_SHRINK|F_SE= AL_SEAL, > > > &fd); > > > + memset(log->log, 0, logsize); > >=20 > > qemu_memfd_alloc can return NULL can't it - so that needs checking? > >=20 > > > + } else { > > > + log->log =3D g_malloc0(logsize); > >=20 > > I know the old code also used g_malloc0, but if the log isn't 'small' > > then g_try_malloc0 is possibly safer and properly return errors > > if it can't be allocated. >=20 > Yeah, I agree it's better to check for the return value here (as you po= inted out, I followed the existing pattern). >=20 > Maybe we are just screwed if it happens, live migration shouldn't succe= ed if it can't be done properly imho. Probably; we try to be careful particularly on the source of memory alloc= ations during migration, since the VM is running just fine, and it's unfortunate to kill it at that point. Dave > What's your take on this Michael? >=20 > cheers -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK