From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKUms-0003Ys-VH for qemu-devel@nongnu.org; Wed, 29 Jul 2015 13:05:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZKUmn-00078e-9i for qemu-devel@nongnu.org; Wed, 29 Jul 2015 13:05:02 -0400 Received: from mx3-phx2.redhat.com ([209.132.183.24]:54557) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKUmn-00077G-1v for qemu-devel@nongnu.org; Wed, 29 Jul 2015 13:04:57 -0400 Date: Wed, 29 Jul 2015 13:04:51 -0400 (EDT) From: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Message-ID: <1279508338.593439.1438189491214.JavaMail.zimbra@redhat.com> In-Reply-To: <20150729165325.GL2267@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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 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: "Dr. David Alan Gilbert" Cc: haifeng lin , mst@redhat.com, thibaut collet , jasowang@redhat.com, qemu-devel@nongnu.org, pbonzini@redhat.com, =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Hi ----- Original Message ----- > * Marc-Andr=C3=A9 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 shared b= y > > several vhost devices. We may want instead a common shareable log and a > > common non-shareable one. > >=20 > > Signed-off-by: Marc-Andr=C3=A9 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 vhost_d= ev > > *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_SEAL_S= EAL, > > &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. Yeah, I agree it's better to check for the return value here (as you pointe= d out, I followed the existing pattern). Maybe we are just screwed if it happens, live migration shouldn't succeed i= f it can't be done properly imho. What's your take on this Michael? cheers