All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: sashiko-reviews@lists.linux.dev
Cc: Hisam Mehboob <hisamshar@gmail.com>, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: selftests: Use KVM's task pinning APIs in steal_time
Date: Tue, 7 Jul 2026 07:04:13 -0700	[thread overview]
Message-ID: <ak0HXd8HMyKDCU1U@google.com> (raw)
In-Reply-To: <20260706164913.3A7A91F000E9@smtp.kernel.org>

On Mon, Jul 06, 2026, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] Race condition causing intermittent test failure (ESRCH) due to late thread pinning
> --
> 
> commit 27b6bbfae99d5564cda41cbc7b8c36c7b9a4ed64
> Author: Sean Christopherson <seanjc@google.com>
> 
> KVM: selftests: Use KVM's task pinning APIs in steal_time
> 
> This commit updates the steal_time test to use KVM's task pinning APIs
> (pin_self_to_cpu and pin_task_to_cpu) to pin the vCPU and stealer threads
> to pCPU0. This removes the use of pthread_attr_setaffinity_np, allowing
> the test to build against non-glibc C libraries.
> 
> Link: https://lore.kernel.org/all/aLIroyJSWQ26wnY4@google.com/
> 
> > diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
> > index 76fcdd1fd3cb4..19a97d6a36076 100644
> > --- a/tools/testing/selftests/kvm/steal_time.c
> > +++ b/tools/testing/selftests/kvm/steal_time.c
> [ ... ]
> > @@ -558,7 +552,9 @@ 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);
> > +		pin_task_to_cpu(thread, 0);
> 
> [Severity: Medium]
> Could this introduce a race condition that causes intermittent test failures?
> 
> Since pthread_create is called before pinning, there is a small window
> where the child thread (do_steal_time) could execute and complete its very
> brief 200us run before the parent thread executes pin_task_to_cpu.
> 
> If the child thread exits before pin_task_to_cpu attempts to set its
> affinity, it will return ESRCH and trigger the TEST_ASSERT inside
> pin_task_to_cpu, abruptly aborting the test.
> 
> Is the explicit pin_task_to_cpu call necessary here?

Nope, which means we can simply drop the problematic pthread_attr_setaffinity_np(),
though I think it makes sense to add a sanity check that the worker did indeed
inherit the affinity, if only to document what's happening.

I'll send a v2.

Thanks for posting this Hisam!

> Since the main thread already called pin_self_to_cpu(0) earlier, the new
> thread created by pthread_create should automatically inherit the parent's
> CPU affinity mask.

      reply	other threads:[~2026-07-07 14:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 16:36 [PATCH] KVM: selftests: Use KVM's task pinning APIs in steal_time Hisam Mehboob
2026-07-06 16:49 ` sashiko-bot
2026-07-07 14:04   ` Sean Christopherson [this message]

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=ak0HXd8HMyKDCU1U@google.com \
    --to=seanjc@google.com \
    --cc=hisamshar@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.