On Mon, 6 Jul 2026 16:15:54 +0800 Hongfu Li <[email protected]> wrote:
> The main changes in this series are to refactor shared tracing and assertion
> helpers into a common file, unify both pkey selftests on pkey_assert() and
> per-test tracing for consistent diagnostics, and add missing mmap() return
> checks with MAP_FAILED used throughout for readability and consistency.
Thanks, I've updated mm.git to this version.
> v10:
> - Add patch 6/6 to fix a pre-existing cleartid race: remove unused
> settid/cleartid clone flags and wait for the clone child to exit in
> the sigsegv test.
Below is how v10 altered mm.git. As you mentioned, this is all from
the addition of [patch 6/6].
btw, I thought the official way to wait for a child thread to exit is
pthread_join()? Why is that sched_yield() loop used?
tools/testing/selftests/mm/pkey_sighandler_tests.c | 20 ++++++-----
1 file changed, 12 insertions(+), 8 deletions(-)
--- a/tools/testing/selftests/mm/pkey_sighandler_tests.c~b
+++ a/tools/testing/selftests/mm/pkey_sighandler_tests.c
@@ -290,7 +290,6 @@ static void test_sigsegv_handler_with_di
static stack_t sigstack;
void *stack;
int pkey;
- int parent_pid = 0;
int child_pid = 0;
u64 pkey_reg;
long ret;
@@ -330,11 +329,10 @@ static void test_sigsegv_handler_with_di
/* Use clone to avoid newer glibcs using rseq on new threads */
ret = clone_raw(CLONE_VM | CLONE_FS | CLONE_FILES |
CLONE_SIGHAND | CLONE_THREAD | CLONE_SYSVSEM |
- CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID |
CLONE_DETACHED,
stack + STACK_SIZE,
- &parent_pid,
- &child_pid);
+ NULL,
+ NULL);
if (ret < 0) {
errno = -ret;
@@ -344,11 +342,19 @@ static void test_sigsegv_handler_with_di
syscall_raw(SYS_exit, 0, 0, 0, 0, 0, 0);
}
+ child_pid = ret;
+
pthread_mutex_lock(&mutex);
while (siginfo.si_signo == 0)
pthread_cond_wait(&cond, &mutex);
pthread_mutex_unlock(&mutex);
+ /* Wait for child to exit before returning */
+ do {
+ sched_yield();
+ ret = syscall_raw(SYS_tkill, child_pid, 0, 0, 0, 0, 0);
+ } while (ret != -ESRCH && ret != -EINVAL);
+
ksft_test_result(siginfo.si_signo == SIGSEGV &&
siginfo.si_code == SEGV_MAPERR &&
siginfo.si_addr == NULL,
@@ -445,7 +451,6 @@ static void test_pkru_sigreturn(void)
static stack_t sigstack;
void *stack;
int pkey;
- int parent_pid = 0;
int child_pid = 0;
u64 pkey_reg;
long ret;
@@ -504,11 +509,10 @@ static void test_pkru_sigreturn(void)
/* Use clone to avoid newer glibcs using rseq on new threads */
ret = clone_raw(CLONE_VM | CLONE_FS | CLONE_FILES |
CLONE_SIGHAND | CLONE_THREAD | CLONE_SYSVSEM |
- CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID |
CLONE_DETACHED,
stack + STACK_SIZE,
- &parent_pid,
- &child_pid);
+ NULL,
+ NULL);
if (ret < 0) {
errno = -ret;
_