Skip to contentSkip to conversation

fdmon-poll: reset npfd when upgrading to fdmon-epoll

PATCH Superseded Stefan Hajnoczi 2 participants 4 messages Aug 21, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover fdmon-poll: reset npfd when upgrading to fdmon-epoll

Fix an assertion failure when aio_poll() is called in a aio_disable_external() region. The failure happens when fdmon-poll is first upgraded to fdmon-epoll and then downgraded again due to aio_disable_external().

Stefan Hajnoczi (2):
fdmon-poll: reset npfd when upgrading to fdmon-epoll
tests: add test-fdmon-epoll

 MAINTAINERS              |  1 +
 tests/Makefile.include   |  4 +++
 tests/test-fdmon-epoll.c | 73 ++++++++++++++++++++++++++++++++++++++++
 util/fdmon-poll.c        |  1 +
 4 files changed, 79 insertions(+)
 create mode 100644 tests/test-fdmon-epoll.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/2 fdmon-poll: reset npfd when upgrading to fdmon-epoll

npfd keeps track of how many pollfds are currently being monitored. It must be reset to 0 when fdmon_poll_wait() returns.

When npfd reaches a treshold we switch to fdmon-epoll because it scales better.

This patch resets npfd in the case where we switch to fdmon-epoll. Forgetting to do so results in the following assertion failure:

util/fdmon-poll.c:65: fdmon_poll_wait: Assertion `npfd == 0' failed.

Fixes 1f050a4690f62a1e7dabc4f44141e9f762c3769f ("aio-posix: extract ppoll(2) and epoll(7) fd monitoring")
---
 util/fdmon-poll.c | 1 +
 1 file changed, 1 insertion(+)
util/fdmon-poll.c +1 -0
index 488067b679..5fe3b47865 100644
@@ -73,6 +73,7 @@ static int fdmon_poll_wait(AioContext *ctx, AioHandlerList *ready_list,
 
     /* epoll(7) is faster above a certain number of fds */
     if (fdmon_epoll_try_upgrade(ctx, npfd)) {
+        npfd = 0; /* we won't need pollfds[], reset npfd */
         return ctx->fdmon_ops->wait(ctx, ready_list, timeout);
     }
 
Signature · 1 line
2.26.2
Reviewed-by on v1 1/2
#2 lore raw
Quoted 24 lines · Stefan Hajnoczi

npfd keeps track of how many pollfds are currently being monitored. It must be reset to 0 when fdmon_poll_wait() returns.

When npfd reaches a treshold we switch to fdmon-epoll because it scales better.

This patch resets npfd in the case where we switch to fdmon-epoll. Forgetting to do so results in the following assertion failure:

util/fdmon-poll.c:65: fdmon_poll_wait: Assertion `npfd == 0' failed.

Fixes 1f050a4690f62a1e7dabc4f44141e9f762c3769f ("aio-posix: extract ppoll(2) and epoll(7) fd monitoring")
---
 util/fdmon-poll.c | 1 +
 1 file changed, 1 insertion(+)
util/fdmon-poll.c +0 -0
index 488067b679..5fe3b47865 100644

util/fdmon-poll.c static int fdmon_poll_wait(AioContext *ctx, AioHandlerList *ready_list, · line 79

Quoted 7 lines
util/fdmon-poll.c +1 -0
@@ -73,6 +73,7 @@ static int fdmon_poll_wait(AioContext *ctx, AioHandlerList *ready_list,
 
     /* epoll(7) is faster above a certain number of fds */
     if (fdmon_epoll_try_upgrade(ctx, npfd)) {
+        npfd = 0; /* we won't need pollfds[], reset npfd */
         return ctx->fdmon_ops->wait(ctx, ready_list, timeout);
     }
 
#3 lore raw

PATCH 2/2 tests: add test-fdmon-epoll

In reply to Stefan Hajnoczi

Test aio_disable_external(), which switches from fdmon-epoll back to fdmon-poll. This resulted in an assertion failure that was fixed in the previous patch.

---
 MAINTAINERS              |  1 +
 tests/Makefile.include   |  4 +++
 tests/test-fdmon-epoll.c | 73 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+)
 create mode 100644 tests/test-fdmon-epoll.c
MAINTAINERS +1 -0
index 0886eb3d2b..6d2e99b94f 100644
@@ -2109,6 +2109,7 @@ F: migration/block*
 F: include/block/aio.h
 F: include/block/aio-wait.h
 F: scripts/qemugdb/aio.py
+F: tests/test-fdmon-epoll.c
 T: git https://github.com/stefanha/qemu.git block
 
 Block SCSI subsystem
tests/Makefile.include +4 -0
index c7e4646ded..b785e487b7 100644
@@ -78,6 +78,9 @@ check-unit-$(CONFIG_SOFTMMU) += tests/test-iov$(EXESUF)
 check-unit-y += tests/test-bitmap$(EXESUF)
 check-unit-$(CONFIG_BLOCK) += tests/test-aio$(EXESUF)
 check-unit-$(CONFIG_BLOCK) += tests/test-aio-multithread$(EXESUF)
+ifeq ($(CONFIG_EPOLL_CREATE1),y)
+check-unit-$(CONFIG_BLOCK) += tests/test-fdmon-epoll$(EXESUF)
+endif
 check-unit-$(CONFIG_BLOCK) += tests/test-throttle$(EXESUF)
 check-unit-$(CONFIG_BLOCK) += tests/test-thread-pool$(EXESUF)
 check-unit-$(CONFIG_BLOCK) += tests/test-hbitmap$(EXESUF)
@@ -408,6 +411,7 @@ tests/test-char$(EXESUF): tests/test-char.o $(test-util-obj-y) $(test-io-obj-y)
 tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y)
 tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y)
 tests/test-aio-multithread$(EXESUF): tests/test-aio-multithread.o $(test-block-obj-y)
+tests/test-fdmon-epoll$(EXESUF): tests/test-fdmon-epoll.o $(test-block-obj-y)
 tests/test-throttle$(EXESUF): tests/test-throttle.o $(test-block-obj-y)
 tests/test-bdrv-drain$(EXESUF): tests/test-bdrv-drain.o $(test-block-obj-y) $(test-util-obj-y)
 tests/test-bdrv-graph-mod$(EXESUF): tests/test-bdrv-graph-mod.o $(test-block-obj-y) $(test-util-obj-y)
tests/test-fdmon-epoll.c new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
2.26.2