Re: [PATCH v2 09/12] KVM: selftests: Add KVM syscall wrappers for pthread_{cancel,join}()

[email protected] Fri, 31 Jul 2026 17:18:08 +0000
Newsgroups dev.linux.lists.kvmarm,org.kernel.vger.kvm
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The `kvm_pthread_join` and `kvm_pthread_cancel` wrappers are defined using the `__KVM_SYSCALL_DEFINE` macro, which incorrectly assumes the wrapped function sets the thread-local `errno` variable on failure.
--

--- Patch [9]: [PATCH v2 09/12] KVM: selftests: Add KVM syscall wrappers for pthread_{cancel,join}() ---
commit b9978e67ef4ca95fc0d3b87b0d80bdb48e623a21
Author: Sean Christopherson <[email protected]>

KVM: selftests: Add KVM syscall wrappers for pthread_{cancel,join}()

This commit adds kvm_pthread_join() and kvm_pthread_cancel() wrappers to
KVM selftests. These wrappers automatically assert that the underlying pthread
functions succeed, removing the need for manual error checking across multiple
tests.

> diff --git a/tools/testing/selftests/kvm/include/kvm_syscalls.h b/tools/testing/selftests/kvm/include/kvm_syscalls.h
> index e75be83787798..d6c18e13b9c8b 100644
> --- a/tools/testing/selftests/kvm/include/kvm_syscalls.h
> +++ b/tools/testing/selftests/kvm/include/kvm_syscalls.h
> @@ -101,6 +101,8 @@ __KVM_SYSCALL_DEFINE(sched_setaffinity, 3, pid_t, pid, size_t, cpusetsize, cpu_s
>  typedef void *(*pthread_fn_t)(void *);
>  __KVM_SYSCALL_DEFINE(pthread_create, 4, pthread_t *, thread,
>  		     const pthread_attr_t *, attr, pthread_fn_t, fn, void *, arg);
> +__KVM_SYSCALL_DEFINE(pthread_join, 2, pthread_t, thread, void **, thread_return);
> +__KVM_SYSCALL_DEFINE(pthread_cancel, 1, pthread_t, thread);

[Severity: Medium]
Will this produce misleading error messages on test failures?

Pthread functions like pthread_join and pthread_cancel return their error
codes directly and do not set the thread-local errno variable.

Since these wrappers use the __KVM_SYSCALL_DEFINE macro, if the underlying
pthread function fails, the __KVM_SYSCALL_ERROR macro will format the
error message using the stale errno instead of the returned error code. This
could result in test assertions printing an incorrect errno (e.g., "Success")
rather than the actual error string.

-- 
Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=9