]> git.baikalelectronics.ru Git - kernel.git/commitdiff
kselftest: introduce new epoll test case
authorDavidlohr Bueso <dave@stgolabs.net>
Fri, 7 May 2021 01:04:04 +0000 (18:04 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 7 May 2021 02:24:13 +0000 (19:24 -0700)
Patch series "fs/epoll: restore user-visible behavior upon event ready".

This series tries to address a change in user visible behavior, reported
in https://bugzilla.kernel.org/show_bug.cgi?id=208943.

Epoll does not report an event to all the threads running epoll_wait()
on the same epoll descriptor. Unsurprisingly, this was bisected back to
0d50f4d65716 (fs/epoll: remove unnecessary wakeups of nested epoll), which
has had various problems in the past, beyond only nested epoll usage.

This patch (of 2):

This incorporates the testcase originally reported in:

     https://bugzilla.kernel.org/show_bug.cgi?id=208943

Which ensures an event is reported to all threads blocked on the same
epoll descriptor, otherwise only a single thread will receive the wakeup
once the event become ready.

Link: https://lkml.kernel.org/r/20210405231025.33829-1-dave@stgolabs.net
Link: https://lkml.kernel.org/r/20210405231025.33829-2-dave@stgolabs.net
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Cc: Jason Baron <jbaron@akamai.com>
Cc: Roman Penyaev <rpenyaev@suse.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c

index ad7fabd575f9296a124da3e828f59f0f74d0bc8d..65ede506305c8d0e246486abbef6c24f9da481d0 100644 (file)
@@ -3449,4 +3449,48 @@ TEST(epoll63)
        close(sfd[1]);
 }
 
+/*
+ *        t0    t1
+ *     (ew) \  / (ew)
+ *           e0
+ *            | (lt)
+ *           s0
+ */
+TEST(epoll64)
+{
+       pthread_t waiter[2];
+       struct epoll_event e;
+       struct epoll_mtcontext ctx = { 0 };
+
+       signal(SIGUSR1, signal_handler);
+
+       ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
+
+       ctx.efd[0] = epoll_create(1);
+       ASSERT_GE(ctx.efd[0], 0);
+
+       e.events = EPOLLIN;
+       ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
+
+       /*
+        * main will act as the emitter once both waiter threads are
+        * blocked and expects to both be awoken upon the ready event.
+        */
+       ctx.main = pthread_self();
+       ASSERT_EQ(pthread_create(&waiter[0], NULL, waiter_entry1a, &ctx), 0);
+       ASSERT_EQ(pthread_create(&waiter[1], NULL, waiter_entry1a, &ctx), 0);
+
+       usleep(100000);
+       ASSERT_EQ(write(ctx.sfd[1], "w", 1), 1);
+
+       ASSERT_EQ(pthread_join(waiter[0], NULL), 0);
+       ASSERT_EQ(pthread_join(waiter[1], NULL), 0);
+
+       EXPECT_EQ(ctx.count, 2);
+
+       close(ctx.efd[0]);
+       close(ctx.sfd[0]);
+       close(ctx.sfd[1]);
+}
+
 TEST_HARNESS_MAIN