Re: [PATCH v3 08/12] KVM: selftests: Add KVM syscall wrapper for pthread_create()

[email protected] Fri, 31 Jul 2026 20:05:41 +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_create` wrapper incorrectly uses `errno` for error reporting, which `pthread_create` does not set.
--

--- Patch [8]: [PATCH v3 08/12] KVM: selftests: Add KVM syscall wrapper for pthread_create() ---
commit d35383198b73b658a7a90f8c3560d48c6d71d62b
Author: Sean Christopherson <[email protected]>

KVM: selftests: Add KVM syscall wrapper for pthread_create()

This commit adds a wrapper for pthread_create() in KVM selftests to
automatically assert success. It converts various manual checks across
multiple tests to use the new kvm_pthread_create() wrapper.

> diff --git a/tools/testing/selftests/kvm/include/kvm_syscalls.h b/tools/testing/selftests/kvm/include/kvm_syscalls.h
> --- a/tools/testing/selftests/kvm/include/kvm_syscalls.h
> +++ b/tools/testing/selftests/kvm/include/kvm_syscalls.h
[ ... ]
> @@ -97,6 +98,10 @@ __KVM_SYSCALL_DEFINE(madvise, 3, void *, addr, size_t, length, int, advice);
>  __KVM_SYSCALL_DEFINE(sched_getaffinity, 3, pid_t, pid, size_t, cpusetsize, cpu_set_t *, mask);
>  __KVM_SYSCALL_DEFINE(sched_setaffinity, 3, pid_t, pid, size_t, cpusetsize, cpu_set_t *, mask);
>  
> +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);
> +

[Severity: Medium]
Since pthread_create() returns the error code directly rather than setting
errno, will this __KVM_SYSCALL_DEFINE wrapper print stale or zero errno values
on failure?

The __KVM_SYSCALL_DEFINE macro relies on __KVM_SYSCALL_ERROR, which formats
the error using errno:

#define __KVM_SYSCALL_ERROR(_name, _ret) \
    "%s failed, rc: %i errno: %i (%s)", (_name), (_ret), errno, strerror(errno)

If pthread_create() fails, should it be handled differently to ensure the
actual returned error code is passed to strerror() instead of the unmodified
errno?

>  #define kvm_free_fd(fd)		\
>  do {				\
>  	kvm_close(fd);		\

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