qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: QEMU <qemu-devel@nongnu.org>, Johannes Berg <johannes.berg@intel.com>
Subject: Re: [Qemu-devel] [PATCH] libvhost-user-glib: fix VugDev main fd cleanup
Date: Tue, 27 Aug 2019 14:47:48 +0400	[thread overview]
Message-ID: <CAJ+F1CJo+oo74_Y6c1PGKq4uULUKXwky3cxSpopxLVmcow-9_w@mail.gmail.com> (raw)
In-Reply-To: <20190827083124.30791-1-johannes@sipsolutions.net>

Hi

On Tue, Aug 27, 2019 at 12:32 PM Johannes Berg
<johannes@sipsolutions.net> wrote:
>
> From: Johannes Berg <johannes.berg@intel.com>
>
> If you try to make a device implementation that can handle multiple
> connections and allow disconnections (which requires overriding the
> VHOST_USER_NONE handling), then glib will warn that we remove a src
> while it's still on the mainloop, and will poll() an FD that doesn't
> exist anymore.
>
> Fix this by just using the internal add_watch() function that has
> all necessary cleanups built in via the hashtable, rather than
> treating the "main" fd of a device specially.

It would be easier to see a backtrace of the error (under gdb with
G_DEBUG=fatal_criticals)

>
> Fixes: 8bb7ddb78a1c ("libvhost-user: add glib source helper")
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> ---
>  contrib/libvhost-user/libvhost-user-glib.c | 3 +--
>  contrib/libvhost-user/libvhost-user-glib.h | 1 -
>  2 files changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/contrib/libvhost-user/libvhost-user-glib.c b/contrib/libvhost-user/libvhost-user-glib.c
> index 99edd2f3de45..a092a55c1d57 100644
> --- a/contrib/libvhost-user/libvhost-user-glib.c
> +++ b/contrib/libvhost-user/libvhost-user-glib.c
> @@ -146,7 +146,7 @@ vug_init(VugDev *dev, uint16_t max_queues, int socket,
>      dev->fdmap = g_hash_table_new_full(NULL, NULL, NULL,
>                                         (GDestroyNotify) g_source_destroy);
>
> -    dev->src = vug_source_new(dev, socket, G_IO_IN, vug_watch, NULL);
> +    set_watch(&dev->parent, socket, VU_WATCH_IN, vug_watch, NULL);
>
>      return true;
>  }
> @@ -157,5 +157,4 @@ vug_deinit(VugDev *dev)
>      g_assert(dev);
>
>      g_hash_table_unref(dev->fdmap);
> -    g_source_unref(dev->src);

I think the main problem here is that src is not owned, since
vug_source_new() does g_source_unref(). This is looks unfortunate.

However, the source should be destroyed (detached from the main
context). I think this is ultimately what your change is about.

Imho, we should change the behaviour of the function to return a ref
source. This needs fixing the hashtable destroy callback. It will be
more consistent with other usages of the functions that also need
fixing in contrib/vhost-user-input/main.c for example.


>  }
> diff --git a/contrib/libvhost-user/libvhost-user-glib.h b/contrib/libvhost-user/libvhost-user-glib.h
> index 64d539d93aba..32a6ec6df063 100644
> --- a/contrib/libvhost-user/libvhost-user-glib.h
> +++ b/contrib/libvhost-user/libvhost-user-glib.h
> @@ -22,7 +22,6 @@ typedef struct VugDev {
>      VuDev parent;
>
>      GHashTable *fdmap; /* fd -> gsource */
> -    GSource *src;
>  } VugDev;
>
>  bool vug_init(VugDev *dev, uint16_t max_queues, int socket,
> --
> 2.23.0
>
>


-- 
Marc-André Lureau


  reply	other threads:[~2019-08-27 10:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-27  8:31 [Qemu-devel] [PATCH] libvhost-user-glib: fix VugDev main fd cleanup Johannes Berg
2019-08-27 10:47 ` Marc-André Lureau [this message]
2019-08-27 11:37   ` Johannes Berg
2019-08-27 11:44     ` Marc-André Lureau
2019-08-27 12:05       ` Johannes Berg

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=CAJ+F1CJo+oo74_Y6c1PGKq4uULUKXwky3cxSpopxLVmcow-9_w@mail.gmail.com \
    --to=marcandre.lureau@gmail.com \
    --cc=johannes.berg@intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=qemu-devel@nongnu.org \
    /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).