epoll_pwait2() timeout regression test
v2 cover epoll_pwait2() timeout regression test
There seems to be a regression in kernel v6.14 where epoll_pwait2() interprets very small timeout values (~1000ns) as infinity and waits for events forever. This patchset adds regression test for this bug and a necessary refactor for do_epoll_pwait() to allow high precision timeouts.
Martin Doucha (2):
epoll_pwait: Refactor timeout to struct timespec Add regression test for epoll_pwait2() timeout
runtest/syscalls | 1 + .../kernel/syscalls/epoll_pwait/.gitignore | 1 + .../syscalls/epoll_pwait/epoll_pwait01.c | 4 +- .../syscalls/epoll_pwait/epoll_pwait02.c | 2 +- .../syscalls/epoll_pwait/epoll_pwait03.c | 9 +- .../syscalls/epoll_pwait/epoll_pwait04.c | 2 +- .../syscalls/epoll_pwait/epoll_pwait06.c | 87 +++++++++++++++++++ .../syscalls/epoll_pwait/epoll_pwait_var.h | 22 ++--- 8 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/2 epoll_pwait: Refactor timeout to struct timespec
Support higher precision timeout in do_epoll_pwait() by passing struct timespec instead of int value in milliseconds. Only one test actually uses the parameter.
---
Changes since v1: None
.../syscalls/epoll_pwait/epoll_pwait01.c | 4 ++-- .../syscalls/epoll_pwait/epoll_pwait02.c | 2 +- .../syscalls/epoll_pwait/epoll_pwait03.c | 9 +++++--- .../syscalls/epoll_pwait/epoll_pwait04.c | 2 +- .../syscalls/epoll_pwait/epoll_pwait_var.h | 22 +++++++++---------- 5 files changed, 21 insertions(+), 18 deletions(-)
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c +2 -2
@@ -30,7 +30,7 @@ static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) {}static void verify_sigmask (void ) { -TEST (do_epoll_pwait (efd, &e,1 ,-1 , &signalset)); +TEST (do_epoll_pwait (efd, &e,1 ,NULL , &signalset));if (TST_RET !=1 ) { tst_res(TFAIL, "do_epoll_pwait() returned %li, expected 1",
@@ -43,7 +43,7 @@ static void verify_sigmask(void)static void verify_nonsigmask (void ) { -TST_EXP_FAIL (do_epoll_pwait (efd, &e,1 ,-1 ,NULL ),EINTR , +TST_EXP_FAIL (do_epoll_pwait (efd, &e,1 ,NULL ,NULL ),EINTR ,"do_epoll_pwait() without sigmask" ); }
testcases/kernel/syscalls/epoll_pwait/epoll_pwait02.c +1 -1
@@ -19,7 +19,7 @@ static struct epoll_event e;static void run (void ) { -TEST (do_epoll_pwait (efd, &e,1 ,-1 ,NULL )); +TEST (do_epoll_pwait (efd, &e,1 ,NULL ,NULL ));if (TST_RET ==1 ) {tst_res (TPASS ,"do_epoll_pwait() succeeded" );
testcases/kernel/syscalls/epoll_pwait/epoll_pwait03.c +6 -3
@@ -13,17 +13,20 @@#include "tst_timer_test.h" #include "epoll_pwait_var.h" -#define USEC_PER_MSEC (1000L) +#define USEC_PER_NSEC (1000L) +#define USEC_PER_SEC (1000000L)static int efd, sfd[2 ];static struct epoll_event e;int sample_fn (int clk_id,long long usec) { -unsigned int ms = usec /USEC_PER_MSEC ; +struct timespec ts; + ts.tv_sec = usec /USEC_PER_SEC ; + ts.tv_nsec = (usec %USEC_PER_SEC ) *USEC_PER_NSEC ;tst_timer_start (clk_id); -TEST (do_epoll_pwait (efd, &e,1 , ms,NULL )); +TEST (do_epoll_pwait (efd, &e,1 , &ts,NULL ));tst_timer_stop ();tst_timer_sample ();
testcases/kernel/syscalls/epoll_pwait/epoll_pwait04.c +1 -1
@@ -20,7 +20,7 @@ static void *bad_addr;static void run (void ) { -TST_EXP_FAIL (do_epoll_pwait (efd, &e,1 ,-1 , bad_addr), +TST_EXP_FAIL (do_epoll_pwait (efd, &e,1 ,NULL , bad_addr),EFAULT ,"with an invalid sigmask pointer" ); }
testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h +11 -11
@@ -14,22 +14,22 @@#define NSEC_PER_MSEC (1000000L)static int do_epoll_pwait (int epfd,struct epoll_event *events,int - maxevents,int timeout,const sigset_t *sigmask) + maxevents,struct timespec *timeout,const sigset_t *sigmask) { -if (tst_variant ==0 ) -return epoll_pwait (epfd, events, maxevents, timeout, sigmask); +if (tst_variant ==0 ) { +int timeout_ms =-1 ; -struct timespec ts; +if (timeout) { + timeout_ms = timeout->tv_sec *MSEC_PER_SEC ; + timeout_ms += (timeout->tv_nsec +NSEC_PER_MSEC -1 ) / +NSEC_PER_MSEC ; + } -if (timeout <0 ) { -return epoll_pwait2 (epfd, events, maxevents,NULL , sigmask); - }else { - ts.tv_sec = timeout /MSEC_PER_SEC ; - ts.tv_nsec =NSEC_PER_MSEC * (timeout %MSEC_PER_SEC ); +return epoll_pwait (epfd, events, maxevents, timeout_ms, + sigmask); } -return epoll_pwait2 (epfd, events, maxevents, &ts, sigmask); - +return epoll_pwait2 (epfd, events, maxevents, timeout, sigmask); }static void epoll_pwait_init (void )
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] epoll_pwait: Refactor timeout to struct timespec
Hi Martin,
Quoted 3 lines
Support higher precision timeout in
do_epoll_pwait()by passing struct timespec instead of int value in milliseconds. Only one test actually uses the parameter.
Ah, you mean epoll_pwait03.c.
...
testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h line 20
Quoted 12 lines
+++
b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.htestcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h +3
-3@@ -14,22 +14,22 @@#define NSEC_PER_MSEC (1000000L)static int do_epoll_pwait (int epfd,struct epoll_event *events,int - maxevents,int timeout,const sigset_t *sigmask) + maxevents,struct timespec *timeout,const sigset_t *sigmask) { -if (tst_variant ==0 ) -return epoll_pwait (epfd, events, maxevents, timeout, sigmask); +if (tst_variant ==0 ) { +int timeout_ms =-1 ;
very nit: I would reverse the condition to save indent for tst_variant == 0:
if (tst_variant != 0) return epoll_pwait2(epfd, events, maxevents, timeout, sigmask);
...
Kind regards,
Petr
Quoted 22 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h +8
-8-struct timespec ts; +if (timeout) { + timeout_ms = timeout->tv_sec *MSEC_PER_SEC ; + timeout_ms += (timeout->tv_nsec +NSEC_PER_MSEC -1 ) / +NSEC_PER_MSEC ; + } -if (timeout <0 ) { -return epoll_pwait2 (epfd, events, maxevents,NULL , sigmask); - }else { - ts.tv_sec = timeout /MSEC_PER_SEC ; - ts.tv_nsec =NSEC_PER_MSEC * (timeout %MSEC_PER_SEC ); +return epoll_pwait (epfd, events, maxevents, timeout_ms, + sigmask); } -return epoll_pwait2 (epfd, events, maxevents, &ts, sigmask); - +return epoll_pwait2 (epfd, events, maxevents, timeout, sigmask); }static void epoll_pwait_init (void )
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] epoll_pwait: Refactor timeout to struct timespec
Hi!
Quoted 7 lines · Petr Vorel
Hi Martin,
Quoted 3 lines
Support higher precision timeout in
do_epoll_pwait()by passing struct timespec instead of int value in milliseconds. Only one test actually uses the parameter.Ah, you mean
epoll_pwait03.c.
Yes.
Quoted 7 lines
Reviewed-by Petr Vorel <[email protected]>...
Quoted 3 lines
+++
b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.htestcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h +0
-0@@ -14,22 +14,22 @@#define NSEC_PER_MSEC (1000000L)
Quoted 10 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h line 20
Quoted 8 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h +3
-3static int do_epoll_pwait (int epfd,struct epoll_event *events,int - maxevents,int timeout,const sigset_t *sigmask) + maxevents,struct timespec *timeout,const sigset_t *sigmask) { -if (tst_variant ==0 ) -return epoll_pwait (epfd, events, maxevents, timeout, sigmask); +if (tst_variant ==0 ) { +int timeout_ms =-1 ;very nit: I would reverse the condition to save indent for
tst_variant== 0:
Feel free to do it during merge, but it'd be better to check (tst_variant == 1) instead in case there will be epoll_pwait3() in the future.
Quoted 4 lines
if (tst_variant != 0) return epoll_pwait2(epfd, events, maxevents, timeout, sigmask);...
Signature · 10 lines
Martin Doucha [email protected] SW Quality Engineer SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] epoll_pwait: Refactor timeout to struct timespec
Hi Martin,
...
Quoted 15 lines
Quoted 4 lines
Quoted 3 lines
+++
b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.htestcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h +0
-0@@ -14,22 +14,22 @@#define NSEC_PER_MSEC (1000000L)Quoted 10 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h line 20
Quoted 8 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h +3
-3static int do_epoll_pwait (int epfd,struct epoll_event *events,int - maxevents,int timeout,const sigset_t *sigmask) + maxevents,struct timespec *timeout,const sigset_t *sigmask) { -if (tst_variant ==0 ) -return epoll_pwait (epfd, events, maxevents, timeout, sigmask); +if (tst_variant ==0 ) { +int timeout_ms =-1 ;very nit: I would reverse the condition to save indent for
tst_variant== 0:
Quoted 2 lines
Feel free to do it during merge, but it'd be better to check (
tst_variant==
1) instead in case there will beepoll_pwait3()in the future.
Thanks for your ack + good point, changed as tst_variant == 1. Patchset merged, thanks!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] epoll_pwait: Refactor timeout to struct timespec
In reply to Martin DouchaSignature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/2 Add regression test for epoll_pwait2() timeout
In reply to Martin Doucha---
Changes since v1:
- Added kernel fix reference
- Use SAFE_EPOLL_*() functions
runtest/syscalls | 1 + .../kernel/syscalls/epoll_pwait/.gitignore | 1 + .../syscalls/epoll_pwait/epoll_pwait06.c | 87 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c
runtest/syscalls +1 -0
@@ -192,6 +192,7 @@ epoll_pwait02 epoll_pwait02 epoll_pwait03 epoll_pwait03 epoll_pwait04 epoll_pwait04 epoll_pwait05 epoll_pwait05 +epoll_pwait06 epoll_pwait06 eventfd01 eventfd01 eventfd02 eventfd02
testcases/kernel/syscalls/epoll_pwait/.gitignore +1 -0
@@ -3,3 +3,4 @@ epoll_pwait02 epoll_pwait03 epoll_pwait04 epoll_pwait05 +epoll_pwait06
testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c new file +87 -0
87 lines not on this page · raw message
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] Add regression test for epoll_pwait2() timeout
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] Add regression test for epoll_pwait2() timeout
In reply to Martin DouchaHi Martin,
LGTM, thanks for this regression test!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Martin,
Quoted 5 lines
There seems to be a regression in kernel v6.14 where
epoll_pwait2()interprets very small timeout values (~1000ns) as infinity and waits for events forever. This patchset adds regression test for this bug and a necessary refactor fordo_epoll_pwait()to allow high precision timeouts.
Good catch! BTW it looks to me 0a65bc27bd64 is from v6.15-rc3 (e.g. 6.15 development cycle), but it was backported to 6.14 stable as 99a0ad16dfd11 to v6.14.4. Obviously fixing commit d9ec73301099 has also been backported (to v6.14.8).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp