[LTP] [PATCH] syscalls/gettid02: fix s390x and couple races

Jan Stancek jstancek@redhat.com
Fri Oct 27 11:58:33 CEST 2023


On Fri, Oct 20, 2023 at 10:55 AM Li Wang <liwang@redhat.com> wrote:
>
>
>
> On Thu, Oct 19, 2023 at 7:40 PM Jan Stancek <jstancek@redhat.com> wrote:
>>
>> s390x is big endian where sizeof(int) == 4 and sizeof(void *) == 8.
>> This test currently fails on s390x because in pthread_join, "&tids[i]"
>> is treated as "void**" and due to different type size it writes over
>> 2 entries of tids[] array. So for small tid values test reports:
>>         gettid02.c:29: TPASS: Expect: parent ID (14048) differs from thread[0] ID (14049)
>>         gettid02.c:29: TPASS: Expect: parent ID (14048) differs from thread[1] ID (14050)
>>         gettid02.c:29: TPASS: Expect: parent ID (14048) differs from thread[2] ID (14051)
>>         gettid02.c:29: TPASS: Expect: parent ID (14048) differs from thread[3] ID (14052)
>>         gettid02.c:29: TPASS: Expect: parent ID (14048) differs from thread[4] ID (14053)
>>         gettid02.c:29: TPASS: Expect: parent ID (14048) differs from thread[5] ID (14054)
>>         gettid02.c:29: TPASS: Expect: parent ID (14048) differs from thread[6] ID (14055)
>>         gettid02.c:29: TPASS: Expect: parent ID (14048) differs from thread[7] ID (14056)
>>         gettid02.c:29: TPASS: Expect: parent ID (14048) differs from thread[8] ID (14057)
>>         gettid02.c:29: TPASS: Expect: parent ID (14048) differs from thread[9] ID (14058)
>>         gettid02.c:49: TINFO: thread[0] and thread[1] have the same ID
>>         gettid02.c:49: TINFO: thread[0] and thread[2] have the same ID
>>         gettid02.c:49: TINFO: thread[0] and thread[3] have the same ID
>>         ...
>> which is clearly wrong, since each thread above printed different ID.
>>
>> This construct is race-y on slower s390x systems:
>>         for (int i = 0; i < THREADS_NUM; i++)
>>                 SAFE_PTHREAD_CREATE(&thread, NULL, threaded, &i);
>> because by the time thread starts and looks at "&i", the loop can
>> already move on and increment "i".
>>
>> Also, potentially starting and waiting for each thread could be an issue, since kernel is
>> free to re-use tid for already finished threads.
>
>
> Make sense!
>
> Reviewed-by: Li Wang <liwang@redhat.com>

Pushed with modified commit message.



More information about the ltp mailing list