Skip to contentSkip to conversation

libxl: poll: Avoid fd deregistration race POLLNVAL

PATCH In review Ian Jackson 3 participants 22 messages Jul 9, 2015 – Jul 15, 2015

lore
Share & tools
lore
#0 lore raw

cover libxl: poll: Avoid fd deregistration race POLLNVAL

The first three patches in this series fix a race which I think is the cause of a bug reported by Jim Fehlig (thanks, Jim). They are IMO backport candidates.

The next 5 provide a test case which reproduces the bug. I actually developed these patches in the opposite order, and have verified that the without the fix, the test case fails the POLLNVAL assertion as expected.

The final patch is a fix to another libxl event test.

Thanks,
Ian.

#1 lore raw

PATCH 1/9 libxl: poll: Make libxl__poller_get have only one success return path

In preparation for doing some more work on successful exit.

No functional change.

---
 tools/libxl/libxl_event.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
tools/libxl/libxl_event.c +7 -8
index 9072df4..b332dd7 100644
@@ -1627,15 +1627,14 @@ libxl__poller *libxl__poller_get(libxl__gc *gc)
     libxl__poller *p = LIBXL_LIST_FIRST(&CTX->pollers_idle);
     if (p) {
         LIBXL_LIST_REMOVE(p, entry);
-        return p;
-    }
-
-    p = libxl__zalloc(NOGC, sizeof(*p));
+    } else {
+        p = libxl__zalloc(NOGC, sizeof(*p));
 
-    rc = libxl__poller_init(gc, p);
-    if (rc) {
-        free(p);
-        return NULL;
+        rc = libxl__poller_init(gc, p);
+        if (rc) {
+            free(p);
+            return NULL;
+        }
     }
 
     return p;
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 2/9 libxl: poll: Use poller_get and poller_put for poller_app

In reply to Ian Jackson

This makes the code more regular. We are going to want to do some more work in poller_get and poller_put, which work also wants to be done for poller_app.

Two very minor functional changes:

* We call malloc an extra time since poller_app is now a pointer

* ERROR_FAIL on poller_get failing for poller_app is generated in libxl_ctx_init rather than passed through by libxl_poller_init from libxl__pipe_nonblock.

---
 tools/libxl/libxl.c          |   11 ++++++++---
 tools/libxl/libxl_event.c    |    4 ++--
 tools/libxl/libxl_internal.h |    2 +-
 3 files changed, 11 insertions(+), 6 deletions(-)
tools/libxl/libxl.c +8 -3
index e9a2d26..97a60cf 100644
@@ -59,6 +59,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
 
     ctx->osevent_hooks = 0;
 
+    ctx->poller_app = 0;
     LIBXL_LIST_INIT(&ctx->pollers_event);
     LIBXL_LIST_INIT(&ctx->pollers_idle);
 
@@ -103,8 +104,11 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
     rc = libxl__atfork_init(ctx);
     if (rc) goto out;
 
-    rc = libxl__poller_init(gc, &ctx->poller_app);
-    if (rc) goto out;
+    ctx->poller_app = libxl__poller_get(gc);
+    if (!ctx->poller_app) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
 
     ctx->xch = xc_interface_open(lg,lg,0);
     if (!ctx->xch) {
@@ -183,7 +187,8 @@ int libxl_ctx_free(libxl_ctx *ctx)
     if (ctx->xsh) xs_daemon_close(ctx->xsh);
     if (ctx->xce) xc_evtchn_close(ctx->xce);
 
-    libxl__poller_dispose(&ctx->poller_app);
+    libxl__poller_put(ctx, ctx->poller_app);
+    ctx->poller_app = NULL;
     assert(LIBXL_LIST_EMPTY(&ctx->pollers_event));
     libxl__poller *poller, *poller_tmp;
     LIBXL_LIST_FOREACH_SAFE(poller, &ctx->pollers_idle, entry, poller_tmp) {
tools/libxl/libxl_event.c +2 -2
index b332dd7..942e02c 100644
@@ -1138,7 +1138,7 @@ int libxl_osevent_beforepoll(libxl_ctx *ctx, int *nfds_io,
 {
     EGC_INIT(ctx);
     CTX_LOCK;
-    int rc = beforepoll_internal(gc, &ctx->poller_app,
+    int rc = beforepoll_internal(gc, ctx->poller_app,
                                  nfds_io, fds, timeout_upd, now);
     CTX_UNLOCK;
     EGC_FREE;
@@ -1291,7 +1291,7 @@ void libxl_osevent_afterpoll(libxl_ctx *ctx, int nfds, const struct pollfd *fds,
 {
     EGC_INIT(ctx);
     CTX_LOCK;
-    afterpoll_internal(egc, &ctx->poller_app, nfds, fds, now);
+    afterpoll_internal(egc, ctx->poller_app, nfds, fds, now);
     CTX_UNLOCK;
     EGC_FREE;
 }
tools/libxl/libxl_internal.h +1 -1
index d52589e..a33725e 100644
@@ -401,7 +401,7 @@ struct libxl__ctx {
       /* See the comment for OSEVENT_HOOK_INTERN in libxl_event.c
        * for restrictions on the use of the osevent fields. */
 
-    libxl__poller poller_app; /* libxl_osevent_beforepoll and _afterpoll */
+    libxl__poller *poller_app; /* libxl_osevent_beforepoll and _afterpoll */
     LIBXL_LIST_HEAD(, libxl__poller) pollers_event, pollers_idle;
 
     LIBXL_SLIST_HEAD(libxl__osevent_hook_nexi, libxl__osevent_hook_nexus)
Signature · 1 line
1.7.10.4
Acked-by on v1 2/9
#4 lore raw

Re: [PATCH 2/9] libxl: poll: Use poller_get and poller_put for poller_app

Quoted 6 lines · Ian Jackson

This makes the code more regular. We are going to want to do some more work in poller_get and poller_put, which work also wants to be done for poller_app.

Two very minor functional changes:

Quoted 8 lines

* We call malloc an extra time since poller_app is now a pointer

* ERROR_FAIL on poller_get failing for poller_app is generated in libxl_ctx_init rather than passed through by libxl_poller_init from libxl__pipe_nonblock.

#5 lore raw

PATCH 3/9 libxl: poll: Avoid fd deregistration race POLLNVAL crash

In reply to Ian Jackson

It can happen that an fd is deregistered, and closed, and then a new fd opened, and reregistered, all while another thread is in poll().

If this happens poll might report POLLNVAL, but the event loop would
think that the fd was supposed to have been valid, and then fail an
assertion:
libxl_event.c:1183: afterpoll_check_fd: Assertion `poller->fds_changed || !(fds[slot].revents & 0x020)' failed.

We can't simply ignore POLLNVAL because if we have bugs which cause messed-up fds, it is a serious problem which we really need to detect.

Instead, add extra tracking to spot when this possibility arises, and abort on POLLNVAL if we are sure that it is unexpected.

---
 tools/libxl/libxl.c          |    2 ++
 tools/libxl/libxl_event.c    |   12 +++++++++++-
 tools/libxl/libxl_internal.h |   13 +++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)
tools/libxl/libxl.c +2 -0
index 97a60cf..6297a94 100644
@@ -62,6 +62,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
     ctx->poller_app = 0;
     LIBXL_LIST_INIT(&ctx->pollers_event);
     LIBXL_LIST_INIT(&ctx->pollers_idle);
+    LIBXL_LIST_INIT(&ctx->pollers_fds_changed);
 
     LIBXL_LIST_INIT(&ctx->efds);
     LIBXL_TAILQ_INIT(&ctx->etimes);
@@ -190,6 +191,7 @@ int libxl_ctx_free(libxl_ctx *ctx)
     libxl__poller_put(ctx, ctx->poller_app);
     ctx->poller_app = NULL;
     assert(LIBXL_LIST_EMPTY(&ctx->pollers_event));
+    assert(LIBXL_LIST_EMPTY(&ctx->pollers_fds_changed));
     libxl__poller *poller, *poller_tmp;
     LIBXL_LIST_FOREACH_SAFE(poller, &ctx->pollers_idle, entry, poller_tmp) {
         libxl__poller_dispose(poller);
tools/libxl/libxl_event.c +11 -1
index 942e02c..8acecfa 100644
@@ -225,6 +225,7 @@ int libxl__ev_fd_modify(libxl__gc *gc, libxl__ev_fd *ev, short events)
 void libxl__ev_fd_deregister(libxl__gc *gc, libxl__ev_fd *ev)
 {
     CTX_LOCK;
+    libxl__poller *poller;
 
     if (!libxl__ev_fd_isregistered(ev)) {
         DBG("ev_fd=%p deregister unregistered",ev);
@@ -237,6 +238,9 @@ void libxl__ev_fd_deregister(libxl__gc *gc, libxl__ev_fd *ev)
     LIBXL_LIST_REMOVE(ev, entry);
     ev->fd = -1;
 
+    LIBXL_LIST_FOREACH(poller, &CTX->pollers_fds_changed, fds_changed_entry)
+        poller->fds_changed = 1;
+
  out:
     CTX_UNLOCK;
 }
@@ -1110,6 +1114,8 @@ static int beforepoll_internal(libxl__gc *gc, libxl__poller *poller,
 
     *nfds_io = used;
 
+    poller->fds_changed = 0;
+
     libxl__ev_time *etime = LIBXL_TAILQ_FIRST(&CTX->etimes);
     if (etime) {
         int our_timeout;
@@ -1174,7 +1180,7 @@ static int afterpoll_check_fd(libxl__poller *poller,
             /* again, stale slot entry */
             continue;
 
-        assert(!(fds[slot].revents & POLLNVAL));
+        assert(poller->fds_changed || !(fds[slot].revents & POLLNVAL));
 
         /* we mask in case requested events have changed */
         int slot_revents = fds[slot].revents & events;
@@ -1601,6 +1607,7 @@ int libxl__poller_init(libxl__gc *gc, libxl__poller *p)
     int rc;
     p->fd_polls = 0;
     p->fd_rindices = 0;
+    p->fds_changed = 0;
 
     rc = libxl__pipe_nonblock(CTX, p->wakeup_pipe);
     if (rc) goto out;
@@ -1637,12 +1644,15 @@ libxl__poller *libxl__poller_get(libxl__gc *gc)
         }
     }
 
+    LIBXL_LIST_INSERT_HEAD(&CTX->pollers_fds_changed, p,
+                           fds_changed_entry);
     return p;
 }
 
 void libxl__poller_put(libxl_ctx *ctx, libxl__poller *p)
 {
     if (!p) return;
+    LIBXL_LIST_REMOVE(p, fds_changed_entry);
     LIBXL_LIST_INSERT_HEAD(&ctx->pollers_idle, p, entry);
 }
 
tools/libxl/libxl_internal.h +13 -0
index a33725e..5b7a9f6 100644
@@ -362,6 +362,18 @@ struct libxl__poller {
     int (*fd_rindices)[3]; /* see libxl_event.c:beforepoll_internal */
 
     int wakeup_pipe[2]; /* 0 means no fd allocated */
+
+    /*
+     * We also use the poller to record whether any fds have been
+     * deregistered since we entered poll.  Each poller which is not
+     * idle is on the list pollers_fds_changed.  fds_changed is
+     * cleared by beforepoll, and tested by afterpoll.  Whenever an fd
+     * event is deregistered, we set the fds_changed of all non-idle
+     * pollers.  So afterpoll can tell whether any POLLNVAL is
+     * plausibly due to an fd being closed and reopened.
+     */
+    LIBXL_LIST_ENTRY(libxl__poller) fds_changed_entry;
+    bool fds_changed;
 };
 
 struct libxl__gc {
@@ -403,6 +415,7 @@ struct libxl__ctx {
 
     libxl__poller *poller_app; /* libxl_osevent_beforepoll and _afterpoll */
     LIBXL_LIST_HEAD(, libxl__poller) pollers_event, pollers_idle;
+    LIBXL_LIST_HEAD(, libxl__poller) pollers_fds_changed;
 
     LIBXL_SLIST_HEAD(libxl__osevent_hook_nexi, libxl__osevent_hook_nexus)
         hook_fd_nexi_idle, hook_timeout_nexi_idle;
Signature · 1 line
1.7.10.4
Acked-by on v1 3/9
#6 lore raw

Re: [PATCH 3/9] libxl: poll: Avoid fd deregistration race POLLNVAL crash

Quoted 11 lines · Ian Jackson

It can happen that an fd is deregistered, and closed, and then a new fd opened, and reregistered, all while another thread is in poll().

If this happens poll might report POLLNVAL, but the event loop would
think that the fd was supposed to have been valid, and then fail an
assertion:
libxl_event.c:1183: afterpoll_check_fd: Assertion `poller->fds_changed || !(fds[slot].revents & 0x020)' failed.

We can't simply ignore POLLNVAL because if we have bugs which cause messed-up fds, it is a serious problem which we really need to detect.

Quoted 6 lines

Instead, add extra tracking to spot when this possibility arises, and abort on POLLNVAL if we are sure that it is unexpected.

#7 lore raw

PATCH 4/9 libxl: event tests: Improve Makefile doc comment

In reply to Ian Jackson

Including the explanation of how to run these tests.

---
 tools/libxl/Makefile |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/libxl/Makefile +7 -1
index cc9c152..44a4da7 100644
@@ -109,7 +109,13 @@ LIBXL_TESTS += timedereg
 # "outside libxl" file is compiled exactly like a piece of application
 # code.  They must share information via explicit libxl entrypoints.
 # Unlike proper parts of libxl, it is permissible for libxl_test_FOO.c
-# to use private global variables for its state.
+# to use private global variables for its state.  Note that all the
+# "inside" parts are compiled into a single test library, so their
+# symbol names must be unique.
+#
+# To run these tests, either use LD_PRELOAD to get libxenlight_test.so
+# loaded, or rename it to libxenlight.so so it is the target of the
+# appropriate symlinks.
 
 LIBXL_TEST_OBJS += $(foreach t, $(LIBXL_TESTS),libxl_test_$t.o)
 TEST_PROG_OBJS += $(foreach t, $(LIBXL_TESTS),test_$t.o) test_common.o
Signature · 1 line
1.7.10.4
Acked-by on v1 4/9
#8 lore raw

Re: [PATCH 4/9] libxl: event tests: Improve Makefile doc comment

Quoted 3 lines · Ian Jackson

Including the explanation of how to run these tests.

Quoted 25 lines
---
 tools/libxl/Makefile |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/libxl/Makefile +7 -1
index cc9c152..44a4da7 100644
@@ -109,7 +109,13 @@ LIBXL_TESTS += timedereg
 # "outside libxl" file is compiled exactly like a piece of application
 # code.  They must share information via explicit libxl entrypoints.
 # Unlike proper parts of libxl, it is permissible for libxl_test_FOO.c
-# to use private global variables for its state.
+# to use private global variables for its state.  Note that all the
+# "inside" parts are compiled into a single test library, so their
+# symbol names must be unique.
+#
+# To run these tests, either use LD_PRELOAD to get libxenlight_test.so
+# loaded, or rename it to libxenlight.so so it is the target of the
+# appropriate symlinks.
 
 LIBXL_TEST_OBJS += $(foreach t, $(LIBXL_TESTS),libxl_test_$t.o)
 TEST_PROG_OBJS += $(foreach t, $(LIBXL_TESTS),test_$t.o) test_common.o
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH 5/9 libxl: event tests: Contemplate separate tests

In reply to Ian Jackson

Split LIBXL_TESTS into two variables, each of which gets all of LIBXL_TESTS, so that we can have tests which do use generic test helper inside functions, rather than test-specific ones.

---
 tools/libxl/Makefile |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
tools/libxl/Makefile +6 -3
index 44a4da7..512b0e1 100644
@@ -100,6 +100,9 @@ LIBXL_OBJS += libxl_genid.o
 LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
 
 LIBXL_TESTS += timedereg
+LIBXL_TESTS_PROGS = $(LIBXL_TESTS)
+LIBXL_TESTS_INSIDE = $(LIBXL_TESTS)
+
 # Each entry FOO in LIBXL_TESTS has two main .c files:
 #   libxl_test_FOO.c  "inside libxl" code to support the test case
 #   test_FOO.c        "outside libxl" code to exercise the test case
@@ -117,9 +120,9 @@ LIBXL_TESTS += timedereg
 # loaded, or rename it to libxenlight.so so it is the target of the
 # appropriate symlinks.
 
-LIBXL_TEST_OBJS += $(foreach t, $(LIBXL_TESTS),libxl_test_$t.o)
-TEST_PROG_OBJS += $(foreach t, $(LIBXL_TESTS),test_$t.o) test_common.o
-TEST_PROGS += $(foreach t, $(LIBXL_TESTS),test_$t)
+LIBXL_TEST_OBJS += $(foreach t, $(LIBXL_TESTS_INSIDE),libxl_test_$t.o)
+TEST_PROG_OBJS += $(foreach t, $(LIBXL_TESTS_PROGS),test_$t.o) test_common.o
+TEST_PROGS += $(foreach t, $(LIBXL_TESTS_PROGS),test_$t)
 
 $(LIBXL_OBJS) $(LIBXL_TEST_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h
 
Signature · 1 line
1.7.10.4
Acked-by on v1 5/9
#10 lore raw

Re: [PATCH 5/9] libxl: event tests: Contemplate separate tests

Quoted 5 lines · Ian Jackson

Split LIBXL_TESTS into two variables, each of which gets all of LIBXL_TESTS, so that we can have tests which do use generic test helper inside functions, rather than test-specific ones.

Quoted 33 lines
---
 tools/libxl/Makefile |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
tools/libxl/Makefile +6 -3
index 44a4da7..512b0e1 100644
@@ -100,6 +100,9 @@ LIBXL_OBJS += libxl_genid.o
 LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
 
 LIBXL_TESTS += timedereg
+LIBXL_TESTS_PROGS = $(LIBXL_TESTS)
+LIBXL_TESTS_INSIDE = $(LIBXL_TESTS)
+
 # Each entry FOO in LIBXL_TESTS has two main .c files:
 #   libxl_test_FOO.c  "inside libxl" code to support the test case
 #   test_FOO.c        "outside libxl" code to exercise the test case
@@ -117,9 +120,9 @@ LIBXL_TESTS += timedereg
 # loaded, or rename it to libxenlight.so so it is the target of the
 # appropriate symlinks.
 
-LIBXL_TEST_OBJS += $(foreach t, $(LIBXL_TESTS),libxl_test_$t.o)
-TEST_PROG_OBJS += $(foreach t, $(LIBXL_TESTS),test_$t.o) test_common.o
-TEST_PROGS += $(foreach t, $(LIBXL_TESTS),test_$t)
+LIBXL_TEST_OBJS += $(foreach t, $(LIBXL_TESTS_INSIDE),libxl_test_$t.o)
+TEST_PROG_OBJS += $(foreach t, $(LIBXL_TESTS_PROGS),test_$t.o) test_common.o
+TEST_PROGS += $(foreach t, $(LIBXL_TESTS_PROGS),test_$t)
 
 $(LIBXL_OBJS) $(LIBXL_TEST_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h
 
Signature · 1 line
1.7.10.4
#11 lore raw

PATCH 6/9 libxl: event tests: Provide libxl_test_fdevent

In reply to Ian Jackson

We are going to use this shortly. But, it is nicely self-contained.

---
 tools/libxl/Makefile             |    2 +-
 tools/libxl/libxl_test_fdevent.c |   79 ++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_test_fdevent.h |   12 ++++++
 3 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 tools/libxl/libxl_test_fdevent.c
 create mode 100644 tools/libxl/libxl_test_fdevent.h
tools/libxl/Makefile +1 -1
index 512b0e1..b92809c 100644
@@ -101,7 +101,7 @@ LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
 
 LIBXL_TESTS += timedereg
 LIBXL_TESTS_PROGS = $(LIBXL_TESTS)
-LIBXL_TESTS_INSIDE = $(LIBXL_TESTS)
+LIBXL_TESTS_INSIDE = $(LIBXL_TESTS) fdevent
 
 # Each entry FOO in LIBXL_TESTS has two main .c files:
 #   libxl_test_FOO.c  "inside libxl" code to support the test case
tools/libxl/libxl_test_fdevent.c new file +79 -0

79 lines not on this page · raw message

tools/libxl/libxl_test_fdevent.h new file +12 -0
new file mode 100644
index 0000000..82a307e
@@ -0,0 +1,12 @@
+#ifndef TEST_FDEVENT_H
+#define TEST_FDEVENT_H
+
+#include <pthread.h>
+
+int libxl_test_fdevent(libxl_ctx *ctx, int fd, short events,
+                       libxl_asyncop_how *ao_how)
+                       LIBXL_EXTERNAL_CALLERS_ONLY;
+/* This operation waits for one of the poll events to occur on fd, and
+ * then completes successfully.  (Or, it can be aborted.) */
+
+#endif /*TEST_FDEVENT_H*/
Signature · 1 line
1.7.10.4
#13 lore raw

PATCH 7/9 libxl: event tests: Provide miniature poll machinery

In reply to Ian Jackson

This allows a test case to have a poll-based event loop with exact control of the sequence of operations.

---
 tools/libxl/test_common.c |   44 +++++++++++++++++++++++++++++++++++++++++++-
 tools/libxl/test_common.h |   15 +++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
tools/libxl/test_common.c +43 -1
index 83b94eb..c6bbbab 100644
@@ -12,4 +12,46 @@ void test_common_setup(int level)
 
     int rc = libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, logger);
     assert(!rc);
-}    
+}
+
+struct timeval now;
+
+void test_common_get_now(void)
+{
+    int r = gettimeofday(&now, 0);  assert(!r);
+}
+
+int poll_nfds, poll_nfds_allocd;
+struct pollfd *poll_fds;
+int poll_timeout;
+
+void test_common_beforepoll(void)
+{
+    for (;;) {
+        test_common_get_now();
+
+        poll_timeout = -1;
+        poll_nfds = poll_nfds_allocd;
+        int rc = libxl_osevent_beforepoll(ctx, &poll_nfds, poll_fds,
+                                          &poll_timeout, now);
+        if (!rc) return;
+        assert(rc == ERROR_BUFFERFULL);
+
+        assert(poll_nfds > poll_nfds_allocd);
+        poll_fds = realloc(poll_fds, poll_nfds * sizeof(poll_fds[0]));
+        assert(poll_fds);
+        poll_nfds_allocd = poll_nfds;
+    }
+}
+
+void test_common_dopoll(void) {
+    errno = 0;
+    int r = poll(poll_fds, poll_nfds, poll_timeout);
+    fprintf(stderr, "poll: r=%d errno=%s\n", r, strerror(errno));
+}
+
+void test_common_afterpoll(void)
+{
+    test_common_get_now();
+    libxl_osevent_afterpoll(ctx, poll_nfds, poll_fds, now);
+}
tools/libxl/test_common.h +15 -0
index 8b2471e..10c7166 100644
@@ -6,9 +6,24 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
 void test_common_setup(int level);
 
 extern libxl_ctx *ctx;
 
+void test_common_get_now(void);
+
+extern struct timeval now;
+
+void test_common_beforepoll(void);
+void test_common_dopoll(void);
+void test_common_afterpoll(void);
+
+extern int poll_nfds, poll_nfds_allocd;
+extern struct pollfd *poll_fds;
+extern int poll_timeout;
+
 #endif /*TEST_COMMON_H*/
Signature · 1 line
1.7.10.4
#15 lore raw

PATCH 8/9 libxl: event tests: Introduce `fdderegrace' test

In reply to Ian Jackson

This exercises the potential race between fd deregistration and poll(). (Because we have control of the individual steps, we can do the whole test in a single thread and ensure that the pessimal order is always reached.)

---
 .gitignore                     |    1 +
 tools/libxl/Makefile           |    2 +-
 tools/libxl/test_fdderegrace.c |   56 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 tools/libxl/test_fdderegrace.c
.gitignore +1 -0
index 3f42ded..464f3f4 100644
@@ -289,6 +289,7 @@ tools/libxl/testidl.c
 tools/libxl/*.pyc
 tools/libxl/libxl-save-helper
 tools/libxl/test_timedereg
+tools/libxl/test_fdderegrace
 tools/libxl/xen-init-dom0
 tools/blktap2/control/tap-ctl
 tools/firmware/etherboot/eb-roms.h
tools/libxl/Makefile +1 -1
index b92809c..95195c5 100644
@@ -100,7 +100,7 @@ LIBXL_OBJS += libxl_genid.o
 LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
 
 LIBXL_TESTS += timedereg
-LIBXL_TESTS_PROGS = $(LIBXL_TESTS)
+LIBXL_TESTS_PROGS = $(LIBXL_TESTS) fdderegrace
 LIBXL_TESTS_INSIDE = $(LIBXL_TESTS) fdevent
 
 # Each entry FOO in LIBXL_TESTS has two main .c files:
tools/libxl/test_fdderegrace.c new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
1.7.10.4
Acked-by on v1 8/9
#16 lore raw

Re: [PATCH 8/9] libxl: event tests: Introduce `fdderegrace' test

Quoted 6 lines · Ian Jackson

This exercises the potential race between fd deregistration and poll(). (Because we have control of the individual steps, we can do the whole test in a single thread and ensure that the pessimal order is always reached.)

#17 lore raw

PATCH 9/9 libxl: event tests: test_timedereg: Fix rc handling

In reply to Ian Jackson

In 31c836f4 "libxl: events: Permit timeouts to signal ao abort", timeout callbacks take an extra rc argument.

In that patch the wrong assertion is made about the rc in test_timedereg's `occurs' callback. Fix this to make the test pass again.

---
 tools/libxl/libxl_test_timedereg.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_test_timedereg.c +1 -1
index c464663..a567db6 100644
@@ -67,7 +67,7 @@ static void occurs(libxl__egc *egc, libxl__ev_time *ev,
     int off = ev - &et[0][0];
     LOG(DEBUG,"occurs[%d][%d] seq=%d rc=%d", off/NTIMES, off%NTIMES, seq, rc);
 
-    assert(!rc);
+    assert(rc == ERROR_TIMEDOUT);
 
     switch (seq) {
     case 0:
Signature · 1 line
1.7.10.4
Acked-by on v1 9/9
#18 lore raw

Re: [PATCH 9/9] libxl: event tests: test_timedereg: Fix rc handling

Quoted 8 lines · Ian Jackson

In 31c836f4 "libxl: events: Permit timeouts to signal ao abort", timeout callbacks take an extra rc argument.

In that patch the wrong assertion is made about the rc in test_timedereg's `occurs' callback. Fix this to make the test pass again.

Quoted 19 lines
---
 tools/libxl/libxl_test_timedereg.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_test_timedereg.c +1 -1
index c464663..a567db6 100644
@@ -67,7 +67,7 @@ static void occurs(libxl__egc *egc, libxl__ev_time *ev,
     int off = ev - &et[0][0];
     LOG(DEBUG,"occurs[%d][%d] seq=%d rc=%d", off/NTIMES, off%NTIMES, seq, rc);
 
-    assert(!rc);
+    assert(rc == ERROR_TIMEDOUT);
 
     switch (seq) {
     case 0:
Signature · 1 line
1.7.10.4
#19 lore raw

Re: [PATCH 9/9] libxl: event tests: test_timedereg: Fix rc handling [and 1 more messages]

Wei Liu writes ("Re: [PATCH 9/9] libxl: event tests: test_timedereg: Fix rc handling"):

Quoted 1 line

Thanks for the review.

Jim Fehlig writes ("Re: [Xen-devel] [PATCH 0/9] libxl: poll: Avoid fd deregistration race POLLNVAL"):

Quoted 3 lines

FYI, I ran these patches in my test setup over the weekend and never encountered the bug. So for patches 1-3

And, thanks for the report and the testing. I have pushed all 9 to staging for 4.6, and queued the first three for backport.

Ian.

Tested-by on the v1 series
#20 lore raw
In reply to Ian Jackson
Quoted 4 lines · Ian Jackson

The first three patches in this series fix a race which I think is the cause of a bug reported by Jim Fehlig (thanks, Jim). They are IMO backport candidates.

FYI, I ran these patches in my test setup over the weekend and never encountered the bug. So for patches 1-3

Regards,
Jim

#21 lore raw

Jim Fehlig writes ("Re: [Xen-devel] [PATCH 0/9] libxl: poll: Avoid fd deregistration race POLLNVAL"):

Quoted 9 lines
Quoted 3 lines · Ian Jackson

The first three patches in this series fix a race which I think is the cause of a bug reported by Jim Fehlig (thanks, Jim). They are IMO backport candidates.

FYI, I ran these patches in my test setup over the weekend and never encountered the bug. So for patches 1-3

Thanks for all your valuable testing!

Ian.