kselftest: introduce new epoll test case

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
339ddb53d3 (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>
This commit is contained in:
Davidlohr Bueso 2021-05-06 18:04:04 -07:00 committed by Linus Torvalds
parent 7e6cdd7fd9
commit 1e3b918d1d

View 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