All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Marc-André Lureau" <mlureau@redhat.com>
Cc: "haifeng lin" <haifeng.lin@huawei.com>,
	"thibaut collet" <thibaut.collet@6wind.com>,
	jasowang@redhat.com,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	qemu-devel@nongnu.org, pbonzini@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 4/9] vhost: alloc shareable log
Date: Wed, 29 Jul 2015 20:22:15 +0300	[thread overview]
Message-ID: <20150729202057-mutt-send-email-mst@redhat.com> (raw)
In-Reply-To: <1279508338.593439.1438189491214.JavaMail.zimbra@redhat.com>

On Wed, Jul 29, 2015 at 01:04:51PM -0400, Marc-André Lureau wrote:
> Hi
> 
> ----- Original Message -----
> > * Marc-André Lureau (marcandre.lureau@redhat.com) wrote:
> > > If the backend is of type VHOST_BACKEND_TYPE_USER, allocate
> > > shareable memory.
> > > 
> > > Note: vhost_log_get() can use a global "vhost_log" that can be shared by
> > > several vhost devices. We may want instead a common shareable log and a
> > > common non-shareable one.
> > > 
> > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > > ---
> > >  hw/virtio/vhost.c         | 38 +++++++++++++++++++++++++++++++-------
> > >  include/hw/virtio/vhost.h |  3 ++-
> > >  2 files changed, 33 insertions(+), 8 deletions(-)
> > > 
> > > 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 <linux/vhost.h>
> > >  #include "exec/address-spaces.h"
> > >  #include "hw/virtio/virtio-bus.h"
> > > @@ -286,20 +287,34 @@ static uint64_t vhost_get_log_size(struct vhost_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 = g_malloc0(sizeof *log + size *
> > > sizeof(*(log->log)));
> > > +    struct vhost_log *log;
> > > +    uint64_t logsize = size * sizeof(*(log->log));
> > > +    int fd = -1;
> > > +
> > > +    log = g_new0(struct vhost_log, 1);
> > > +    if (share) {
> > > +        log->log = qemu_memfd_alloc("vhost-log", logsize,
> > > +                                    F_SEAL_GROW|F_SEAL_SHRINK|F_SEAL_SEAL,
> > > &fd);
> > > +        memset(log->log, 0, logsize);
> > 
> > qemu_memfd_alloc can return NULL can't it - so that needs checking?
> > 
> > > +    } else {
> > > +        log->log = g_malloc0(logsize);
> > 
> > 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 pointed out, I followed the existing pattern).
> 
> Maybe we are just screwed if it happens, live migration shouldn't succeed if it can't be done properly imho.
> 
> What's your take on this Michael?
> 
> cheers

I guess we could fail migration in that case ...
Since current code uses g_malloc0 I feel this can be addressed by
a separate patch later.

--  
MST

  parent reply	other threads:[~2015-07-29 17:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-28 17:36 [Qemu-devel] [PATCH v2 0/9] vhost-user: add migration log support (for 2.5) Marc-André Lureau
2015-07-28 17:36 ` [Qemu-devel] [PATCH v2 1/9] configure: probe for memfd Marc-André Lureau
2015-07-28 17:36 ` [Qemu-devel] [PATCH v2 2/9] posix: add linux-only memfd fallback Marc-André Lureau
2015-08-03 11:31   ` Marc-André Lureau
2015-07-28 17:36 ` [Qemu-devel] [PATCH v2 3/9] osdep: add memfd helpers Marc-André Lureau
2015-08-03 11:32   ` Marc-André Lureau
2015-07-28 17:36 ` [Qemu-devel] [PATCH v2 4/9] vhost: alloc shareable log Marc-André Lureau
2015-07-29 16:53   ` Dr. David Alan Gilbert
2015-07-29 17:04     ` Marc-André Lureau
2015-07-29 17:08       ` Dr. David Alan Gilbert
2015-07-29 17:22       ` Michael S. Tsirkin [this message]
2015-07-28 17:36 ` [Qemu-devel] [PATCH v2 5/9] vhost: document log resizing Marc-André Lureau
2015-07-28 17:36 ` [Qemu-devel] [PATCH v2 6/9] vhost: use variable arguments for vhost_call() Marc-André Lureau
2015-08-01  2:47   ` l
2015-08-03 11:03     ` Marc-André Lureau
2015-07-28 17:36 ` [Qemu-devel] [PATCH v2 7/9] vhost-user: start and end the va_list Marc-André Lureau
2015-07-28 17:36 ` [Qemu-devel] [PATCH v2 8/9] vhost-user: send log shm fd along with log_base Marc-André Lureau
2015-07-28 17:36 ` [Qemu-devel] [PATCH v2 9/9] vhost-user: document migration log Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150729202057-mutt-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=haifeng.lin@huawei.com \
    --cc=jasowang@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mlureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thibaut.collet@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.