Skip to contentSkip to conversation

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

PATCH Applied Stefan Hajnoczi 1 participant 4 messages Sep 15, 2020 – Sep 23, 2020 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

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

v2:
* Rebased onto qemu.git/master for meson

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/test-fdmon-epoll.c | 73 ++++++++++++++++++++++++++++++++++++++++
 util/fdmon-poll.c        |  1 +
 tests/meson.build        |  3 ++
 4 files changed, 78 insertions(+)
 create mode 100644 tests/test-fdmon-epoll.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 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
#2 lore raw

PATCH v2 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/test-fdmon-epoll.c | 73 ++++++++++++++++++++++++++++++++++++++++
 tests/meson.build        |  3 ++
 3 files changed, 77 insertions(+)
 create mode 100644 tests/test-fdmon-epoll.c
MAINTAINERS +1 -0
index 3d17cad19a..99e4010623 100644
@@ -2132,6 +2132,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/test-fdmon-epoll.c new file +73 -0

73 lines not on this page · raw message

tests/meson.build +3 -0
index dae8a77df1..62277e6858 100644
@@ -169,6 +169,9 @@ if have_block
   if 'CONFIG_NETTLE' in config_host or 'CONFIG_GCRYPT' in config_host
     tests += {'test-crypto-pbkdf': [io]}
   endif
+  if 'CONFIG_EPOLL_CREATE1' in config_host
+    tests += {'test-fdmon-epoll': [testblock]}
+  endif
   benchs += {
      'benchmark-crypto-hash': [crypto],
      'benchmark-crypto-hmac': [crypto],
Signature · 1 line
2.26.2
author Applied
#3 lore raw
In reply to Stefan Hajnoczi
Quoted 11 lines · Stefan Hajnoczi

v2:
* Rebased onto qemu.git/master for meson

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

Quoted 10 lines
 MAINTAINERS              |  1 +
 tests/test-fdmon-epoll.c | 73 ++++++++++++++++++++++++++++++++++++++++
 util/fdmon-poll.c        |  1 +
 tests/meson.build        |  3 ++
 4 files changed, 78 insertions(+)
 create mode 100644 tests/test-fdmon-epoll.c
Signature · 1 line
2.26.2

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan