All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jim Fehlig <jfehlig@suse.com>, xen-devel@lists.xensource.com
Subject: Re: [PATCH 3/3] libxl: fd events: Suppress spurious fd events
Date: Fri, 17 Apr 2015 10:17:12 +0100	[thread overview]
Message-ID: <1429262232.25195.216.camel@citrix.com> (raw)
In-Reply-To: <1429208608-6185-4-git-send-email-ian.jackson@eu.citrix.com>

On Thu, 2015-04-16 at 19:23 +0100, Ian Jackson wrote:
> Always recheck with poll() right before making the callback.
> 
> All sorts of things may have happened since poll() originally signaled
> the fd.  We would like the main functional libxl code not to have to
> worry about spurious wakeups.

This works because the recheck and the callback are both done within the
same CTX lock critical section. The major assumption here is that
anything which could invalidate the result of the previous poll must
also happen with the lock held, otherwise you have a race between the
recheck and the callback.

The new call of fd_occurs here is locked, as is the one from
afterpoll_internal (refactored in a previous patch), so good.

Are all of the fd's which are going to be involved in this path owned by
libxl? I believe that is the case (if not then the application would
need to take care). The application may have visibility onto the fds
(via the result of libxl_osevent_beforepoll or the use of the
fd_register hook) but I think it is pretty obvious that the application
should never do anything with those fds other than poll or remember them
to give to libxl later.

Likewise is all of the code in libxl which touches such an fd locked? I
expect this is usually trivially the case because the fd is touched in a
callback, and if it is not the case elsewhere that would be a bug to be
fixed.

(a bit longer than it needed to be, but I figured that having reasoned
it out in writing to keep my thoughts straight I may as well post it)

> In particular, this fixes a bug in the save/restore callout: the save
> helper message reader operates with the fd in blocking mode.  In a
> multithreaded program one thread might have eaten all the messages out
> of the fd while another one is busy returning from poll and reaquiring

"reacquiring"

> the libxl lock, possibly resulting in a deadlock.
> 
> (Also, we abolish the anomalous direct caller of efd->func.)
> 
> Reported-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reported-by: Jim Fehlig <jfehlig@suse.com>
> Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Jim Fehlig <jfehlig@suse.com>
> CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

  reply	other threads:[~2015-04-17  9:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <[PATCH v2 0/3] libxl: fd events: Recheck fd events>
2015-04-16 18:23 ` <21807.61130.841852.546321@mariner.uk.xensource.com> Ian Jackson
2015-04-16 18:23   ` [PATCH 1/3] libxl: fd events: Break out libxl__fd_poll_recheck Ian Jackson
2015-04-17  9:01     ` Ian Campbell
2015-04-16 18:23   ` [PATCH 2/3] libxl: fd events: Break out fd_occurs Ian Jackson
2015-04-17  9:02     ` Ian Campbell
2015-04-17 20:21     ` Konrad Rzeszutek Wilk
2015-04-16 18:23   ` [PATCH 3/3] libxl: fd events: Suppress spurious fd events Ian Jackson
2015-04-17  9:17     ` Ian Campbell [this message]
2015-04-16 18:24   ` [PATCH v2 0/3] libxl: fd events: Recheck with poll Ian Jackson
2015-04-17 20:25     ` Konrad Rzeszutek Wilk
2015-04-22 14:23     ` Ian Campbell
2015-04-16 21:19   ` Jim Fehlig

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=1429262232.25195.216.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jfehlig@suse.com \
    --cc=xen-devel@lists.xensource.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.