<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 17, 2019 at 3:34 PM Jan Stancek <<a href="mailto:jstancek@redhat.com">jstancek@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Case where defunct tid is used has been observed to sporadically fail:<br>
tgkill03.c:96: FAIL: Defunct tid should have failed with ESRCH: SUCCESS<br>
<br>
glibc __pthread_timedjoin_ex() waits for CLONE_CHILD_CLEARTID to clear tid,<br>
and then resumes. Kernel clears it (glibc pd->tid) at:<br>
do_exit<br>
exit_mm<br>
mm_release<br>
put_user(0, tsk->clear_child_tid);<br>
<br>
but kernel tid is still valid, presumably until:<br>
release_task<br>
__exit_signal<br>
__unhash_process<br>
detach_pid<br>
<br>
To avoid race wait until /proc/<pid>/task/<tid> disappears.<br>
<br>
Signed-off-by: Jan Stancek <<a href="mailto:jstancek@redhat.com" target="_blank">jstancek@redhat.com</a>><br>
---<br>
testcases/kernel/syscalls/tgkill/tgkill03.c | 6 +++++-<br>
1 file changed, 5 insertions(+), 1 deletion(-)<br>
<br>
Changes in v2:<br>
- use helper func suggested by Li (with higher timeout)<br>
- not tested, trying to get s390x to confirm<br>
<br>
diff --git a/testcases/kernel/syscalls/tgkill/tgkill03.c b/testcases/kernel/syscalls/tgkill/tgkill03.c<br>
index f5bbdc5a8d4e..ce046f576b5f 100644<br>
--- a/testcases/kernel/syscalls/tgkill/tgkill03.c<br>
+++ b/testcases/kernel/syscalls/tgkill/tgkill03.c<br>
@@ -7,6 +7,7 @@<br>
<br>
#include <pthread.h><br>
#include <pwd.h><br>
+#include <stdio.h><br>
#include <sys/types.h><br>
<br>
#include "tst_safe_pthread.h"<br>
@@ -42,6 +43,7 @@ static void setup(void)<br>
{<br>
sigset_t sigusr1;<br>
pthread_t defunct_thread;<br>
+ char defunct_tid_path[PATH_MAX];<br>
<br>
sigemptyset(&sigusr1);<br>
sigaddset(&sigusr1, SIGUSR1);<br>
@@ -55,8 +57,9 @@ static void setup(void)<br>
TST_CHECKPOINT_WAIT(0);<br>
<br>
SAFE_PTHREAD_CREATE(&defunct_thread, NULL, defunct_thread_func, NULL);<br>
-<br>
SAFE_PTHREAD_JOIN(defunct_thread, NULL);<br>
+ sprintf(defunct_tid_path, "/proc/%d/task/%d", getpid(), defunct_tid);<br>
+ TST_RETRY_FN_EXP_BACKOFF(access(defunct_tid_path, R_OK), -1, 15);<br>
}<br>
<br>
static void cleanup(void)<br>
@@ -108,4 +111,5 @@ static struct tst_test test = {<br>
.setup = setup,<br>
.cleanup = cleanup,<br>
.test = run,<br>
+ .timeout = 15,<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">I'd like to give a little bit more time here which larger than the exponential backoff macro time.</div><div class="gmail_default" style="font-size:small"></div><div class="gmail_default" style="font-size:small">Anyway, v2 looks good.</div><br></div><div><div class="gmail_default" style="font-size:small">Reviewed-by: Li Wang <<a href="mailto:liwang@redhat.com">liwang@redhat.com</a>></div></div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Regards,<br>Li Wang<br></div></div></div></div></div>