From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 1/2] KVM: selftests: Drop superfluous use of pthread_attr_setaffinity_np()
Date: Tue, 07 Jul 2026 15:21:05 +0000 [thread overview]
Message-ID: <20260707152105.8FE671F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707150706.1198541-2-seanjc@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The assertion intended to verify CPU affinity inheritance can silently pass if `pthread_getaffinity_np` fails, because `cpuset` is not cleared before the call and its return value is ignored.
--
--- Patch [1]: [PATCH v2 1/2] KVM: selftests: Drop superfluous use of pthread_attr_setaffinity_np() ---
commit 4058c4b23733ee3e6fc2f4b8ebc85f63f4492c52
Author: Sean Christopherson <seanjc@google.com>
KVM: selftests: Drop superfluous use of pthread_attr_setaffinity_np()
This commit removes explicit CPU affinity setting for the worker child thread
in the steal time test, relying on inheritance from the parent thread instead.
It adds an assertion to verify the affinity was properly inherited. It also
allows the test to build against non-glibc C libraries lacking
pthread_attr_setaffinity_np().
Link: https://man7.org/linux/man-pages/man3/pthread_setaffinity_np.3.html [1]
Link: https://man7.org/linux/man-pages/man3/pthread_create.3.html [1]
Closes: https://lore.kernel.org/all/20250829142556.72577-4-aqibaf@amazon.com
> diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
> index 76fcdd1fd3cb4..a244bf9f701f7 100644
> --- a/tools/testing/selftests/kvm/steal_time.c
> +++ b/tools/testing/selftests/kvm/steal_time.c
[ ... ]
> @@ -558,7 +555,11 @@ int main(int ac, char **av)
>
> /* Steal time from the VCPU. The steal time thread has the same CPU affinity as the VCPUs. */
> run_delay = get_run_delay();
> - pthread_create(&thread, &attr, do_steal_time, NULL);
> + pthread_create(&thread, NULL, do_steal_time, NULL);
> + pthread_getaffinity_np(thread, sizeof(cpuset), &cpuset);
[Severity: Medium]
Can this assertion spuriously pass if pthread_getaffinity_np() fails?
Because cpuset is not cleared before calling pthread_getaffinity_np() in
main(), and the return value isn't checked, cpuset will retain its previous
value if the call fails. This could happen if the child thread completes
its execution before pthread_getaffinity_np() is called.
Since cpuset was already populated with CPU 0 earlier in main(), the
TEST_ASSERT would read the stale data and pass even if the thread did not
inherit the affinity.
> + TEST_ASSERT(CPU_COUNT(&cpuset) == 1 && CPU_ISSET(0, &cpuset),
> + "Worker failed to inherit parent's CPU affinity");
> +
> do
> sched_yield();
> while (get_run_delay() - run_delay < MIN_RUN_DELAY_NS);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260707150706.1198541-1-seanjc@google.com?part=1
next prev parent reply other threads:[~2026-07-07 15:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 15:07 [PATCH v2 0/2] KVM: selftest: Fix steal time w/ non-glibc builds Sean Christopherson
2026-07-07 15:07 ` [PATCH v2 1/2] KVM: selftests: Drop superfluous use of pthread_attr_setaffinity_np() Sean Christopherson
2026-07-07 15:21 ` sashiko-bot [this message]
2026-07-07 16:03 ` Sean Christopherson
2026-07-07 15:07 ` [PATCH v2 2/2] KVM: selftests: Randomize pCPU in steal time test Sean Christopherson
2026-07-07 15:29 ` sashiko-bot
2026-07-07 16:15 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260707152105.8FE671F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox