* [LTP] [PATCH] syscalls: epoll_pwait01: Work around a race
@ 2021-01-12 13:29 Cyril Hrubis
2021-01-13 0:54 ` Petr Vorel
2021-01-13 8:41 ` Li Wang
0 siblings, 2 replies; 3+ messages in thread
From: Cyril Hrubis @ 2021-01-12 13:29 UTC (permalink / raw)
To: ltp
There was a race that would manifest on slower machines.
The call to epoll_pwait() could time out before the child has chance to
run, and that would cause the signal to be sent to the parent when it
was already sleeping in wait().
Ideally the whole test should be rewritten into new library and fixed
properly, however as we are just before a release this is an attempt for
a minimal fix.
The logic in the test is changed so that:
- epoll_wait() sleeps indefinitely
- the child:
- waits for the parent to get asleep
- sends the signal
- sleeps
- writes to the pipe
This causes the child to actually run, while the parent is blocked in
the epoll_wait(), which greatly increases the changes of the signal
arriving at the right time.
Fixes: #765
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c
index ed05da8fe..1f08112ad 100644
--- a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c
+++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c
@@ -121,8 +121,8 @@ static void verify_sigmask(void)
return;
}
- if (TEST_RETURN != 0) {
- tst_resm(TFAIL, "epoll_pwait() returned %li, expected 0",
+ if (TEST_RETURN != 1) {
+ tst_resm(TFAIL, "epoll_pwait() returned %li, expected 1",
TEST_RETURN);
return;
}
@@ -153,6 +153,7 @@ static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
static void do_test(sigset_t *sigmask)
{
pid_t cpid;
+ char b;
cpid = tst_fork();
if (cpid < 0)
@@ -161,13 +162,15 @@ static void do_test(sigset_t *sigmask)
if (cpid == 0)
do_child();
- TEST(epoll_pwait(epfd, &epevs, 1, 100, sigmask));
+ TEST(epoll_pwait(epfd, &epevs, 1, -1, sigmask));
if (sigmask != NULL)
verify_sigmask();
else
verify_nonsigmask();
+ SAFE_READ(cleanup, 1, fds[0], &b, 1);
+
tst_record_childstatus(cleanup, cpid);
}
@@ -179,6 +182,8 @@ static void do_child(void)
}
SAFE_KILL(cleanup, getppid(), SIGUSR1);
+ usleep(10000);
+ SAFE_WRITE(cleanup, 1, fds[1], "w", 1);
cleanup();
tst_exit();
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [LTP] [PATCH] syscalls: epoll_pwait01: Work around a race
2021-01-12 13:29 [LTP] [PATCH] syscalls: epoll_pwait01: Work around a race Cyril Hrubis
@ 2021-01-13 0:54 ` Petr Vorel
2021-01-13 8:41 ` Li Wang
1 sibling, 0 replies; 3+ messages in thread
From: Petr Vorel @ 2021-01-13 0:54 UTC (permalink / raw)
To: ltp
Hi Cyril,
> There was a race that would manifest on slower machines.
> The call to epoll_pwait() could time out before the child has chance to
> run, and that would cause the signal to be sent to the parent when it
> was already sleeping in wait().
> Ideally the whole test should be rewritten into new library and fixed
> properly, however as we are just before a release this is an attempt for
> a minimal fix.
> The logic in the test is changed so that:
> - epoll_wait() sleeps indefinitely
> - the child:
> - waits for the parent to get asleep
> - sends the signal
> - sleeps
> - writes to the pipe
> This causes the child to actually run, while the parent is blocked in
> the epoll_wait(), which greatly increases the changes of the signal
> arriving at the right time.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
LGTM.
> Fixes: #765
Kind regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread
* [LTP] [PATCH] syscalls: epoll_pwait01: Work around a race
2021-01-12 13:29 [LTP] [PATCH] syscalls: epoll_pwait01: Work around a race Cyril Hrubis
2021-01-13 0:54 ` Petr Vorel
@ 2021-01-13 8:41 ` Li Wang
1 sibling, 0 replies; 3+ messages in thread
From: Li Wang @ 2021-01-13 8:41 UTC (permalink / raw)
To: ltp
On Tue, Jan 12, 2021 at 9:28 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> There was a race that would manifest on slower machines.
>
> The call to epoll_pwait() could time out before the child has chance to
> run, and that would cause the signal to be sent to the parent when it
> was already sleeping in wait().
>
> Ideally the whole test should be rewritten into new library and fixed
> properly, however as we are just before a release this is an attempt for
> a minimal fix.
>
> The logic in the test is changed so that:
>
> - epoll_wait() sleeps indefinitely
> - the child:
> - waits for the parent to get asleep
> - sends the signal
> - sleeps
> - writes to the pipe
>
> This causes the child to actually run, while the parent is blocked in
> the epoll_wait(), which greatly increases the changes of the signal
> arriving at the right time.
>
> Fixes: #765
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
>
Reviewed-by: Li Wang <liwang@redhat.com>
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210113/13811696/attachment-0001.htm>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-13 8:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-12 13:29 [LTP] [PATCH] syscalls: epoll_pwait01: Work around a race Cyril Hrubis
2021-01-13 0:54 ` Petr Vorel
2021-01-13 8:41 ` Li Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox