qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: qemu-devel@nongnu.org, "Michael S . Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] libvhost-user: handle NOFD flag in call/kick/err better
Date: Wed, 18 Sep 2019 11:49:14 +0200	[thread overview]
Message-ID: <317365a128caca1e683b94677d93dea98c2928c2.camel@sipsolutions.net> (raw)
In-Reply-To: <20190918093932.GC26027@stefanha-x1.localdomain> (sfid-20190918_113946_369130_4FBC46BB)

On Wed, 2019-09-18 at 10:39 +0100, Stefan Hajnoczi wrote:
> 
> >  vu_check_queue_msg_file(VuDev *dev, VhostUserMsg *vmsg)
> >  {
> >      int index = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
> > +    bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK;
> >  
> >      if (index >= dev->max_queues) {
> >          vmsg_close_fds(vmsg);
> > @@ -927,8 +928,12 @@ vu_check_queue_msg_file(VuDev *dev, VhostUserMsg *vmsg)
> >          return false;
> >      }
> >  
> > -    if (vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK ||
> > -        vmsg->fd_num != 1) {
> > +    if (nofd) {
> > +        vmsg_close_fds(vmsg);
> > +        return true;
> > +    }

So in this particular code you quoted, I actually just aligned to have
the same "bool nofd" variable - and I made it return "true" when no FD
was given.

It couldn't make use of what you proposed:

> With the following change to vmsg_close_fds():
> 
>   for (i = 0; i < vmsg->fd_num; i++) {
>       close(vmsg->fds[i]);
>   }
> + for (i = 0; i < sizeof(vmsg->fd_num) / sizeof(vmsg->fd_num[0]); i++) {
> +     vmsg->fds[i] = -1;
> + }
> + vmsg->fd_num = 0;
> 
> ...the message handler functions below can use vmsg->fds[0] (-1) without
> worrying about NOFD.  This makes the code simpler.

because fd_num != 1 leads to the original code returning false, which
leads to the ring not getting started in vu_set_vring_kick_exec(). So we
need the special code here, can be argued if I should pull out the test
into the "bool nofd" variable or not ... *shrug*

The changes in vu_set_vring_kick_exec() and vu_set_vring_err_exec()
would indeed then not be necessary, but in vu_set_vring_call_exec() we
should still avoid the eventfd_write() if it's going to get -1.


So, yeah - could be a bit simpler there. I'd say being explicit here is
easier to understand and thus nicer, but your (or Michael's I guess?)
call.

johannes



  reply	other threads:[~2019-09-18  9:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-17 12:25 [Qemu-devel] [PATCH] libvhost-user: handle NOFD flag in call/kick/err better Johannes Berg
2019-09-17 17:13 ` no-reply
2019-09-17 17:14 ` no-reply
2019-09-18  9:39 ` Stefan Hajnoczi
2019-09-18  9:49   ` Johannes Berg [this message]
2019-09-20  8:58     ` Stefan Hajnoczi

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=317365a128caca1e683b94677d93dea98c2928c2.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).