From: Ian Campbell Subject: Re: [PATCH 1/3] libxl: events: Pass correct nfds to poll Date: Mon, 20 Jan 2014 09:41:29 +0000 Message-ID: <1390210889.20516.1.camel@kazak.uk.xensource.com> References: <1389980090-3479-1-git-send-email-ian.jackson@eu.citrix.com> <1389980090-3479-2-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1389980090-3479-2-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: Jim Fehlig , xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org On Fri, 2014-01-17 at 17:34 +0000, Ian Jackson wrote: > libxl_event.c:eventloop_iteration would pass the allocated pollfds > array size, rather than the used size, to poll (and to > afterpoll_internal). > > The effect is that if the number of fds to poll on reduces, libxl will > poll on stale entries. Because of the way the return value from poll > is processed these stale entries are often harmless because any events > coming back from poll ignored by libxl. However, it could cause > malfunctions: > > It could result in unwanted SIGTTIN/SIGTTOU/SIGPIPE, for example, if > the fd has been reused to refer to an object which can generate those > signals. Alternatively, it could result in libxl spinning if the > stale entry refers to an fd which happens now to be ready for the > previously-requested operation. > > I have tested this with a localhost migration and inspected the strace > output. > > Signed-off-by: Ian Jackson > Cc: Jim Fehlig Acked-by: Ian Campbell > --- > tools/libxl/libxl_event.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c > index bdef7ac..1c48fee 100644 > --- a/tools/libxl/libxl_event.c > +++ b/tools/libxl/libxl_event.c > @@ -1386,7 +1386,7 @@ static int eventloop_iteration(libxl__egc *egc, libxl__poller *poller) { > * can unlock it when it polls. > */ > EGC_GC; > - int rc; > + int rc, nfds; > struct timeval now; > > rc = libxl__gettimeofday(gc, &now); > @@ -1395,7 +1395,7 @@ static int eventloop_iteration(libxl__egc *egc, libxl__poller *poller) { > int timeout; > > for (;;) { > - int nfds = poller->fd_polls_allocd; > + nfds = poller->fd_polls_allocd; > timeout = -1; > rc = beforepoll_internal(gc, poller, &nfds, poller->fd_polls, > &timeout, now); > @@ -1413,7 +1413,7 @@ static int eventloop_iteration(libxl__egc *egc, libxl__poller *poller) { > } > > CTX_UNLOCK; > - rc = poll(poller->fd_polls, poller->fd_polls_allocd, timeout); > + rc = poll(poller->fd_polls, nfds, timeout); > CTX_LOCK; > > if (rc < 0) { > @@ -1428,8 +1428,7 @@ static int eventloop_iteration(libxl__egc *egc, libxl__poller *poller) { > rc = libxl__gettimeofday(gc, &now); > if (rc) goto out; > > - afterpoll_internal(egc, poller, > - poller->fd_polls_allocd, poller->fd_polls, now); > + afterpoll_internal(egc, poller, nfds, poller->fd_polls, now); > > rc = 0; > out: