Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dongli Zhang" <dongli.zhang@oracle.com>
Cc: kvmarm@lists.linux.dev, "Marc Zyngier" <maz@kernel.org>,
	kvm@vger.kernel.org, "Oliver Upton" <oupton@kernel.org>
Subject: Re: [PATCH v2 3/4] KVM: selftests: Test steal time across vCPU pid changes on x86
Date: Fri, 04 Sep 2026 18:11:03 +0000	[thread overview]
Message-ID: <20260904181104.B25871F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260904175550.430266-4-dongli.zhang@oracle.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The delay accumulation loop can hang indefinitely because the background thread uses a fixed wall-clock timeout instead of synchronizing with the main thread.
- [Medium] Unchecked return values from pthread APIs lead to undefined behavior and potential test hangs.
--

commit 4093ded4f0187a7d185578eeea38cf167b09f1d2
Author: Dongli Zhang <dongli.zhang@oracle.com>

KVM: selftests: Test steal time across vCPU pid changes on x86

This commit adds a selftest to verify that KVM correctly resets steal-time
accounting when a vCPU is run from a new host thread. It creates a background
thread to accumulate run delay and checks if the steal time remains monotonic
across PID changes.

> --- /dev/null
> +++ b/tools/testing/selftests/kvm/steal_time_change_pid.c
> @@ -0,0 +1,162 @@
[ ... ]
> +static void *do_steal_time(void *arg)
> +{
> +	struct timespec ts, stop;
> +
> +	clock_gettime(CLOCK_MONOTONIC, &ts);
> +	stop = timespec_add_ns(ts, MIN_RUN_DELAY_NS);
> +
> +	while (timespec_to_ns(timespec_sub(ts, stop)) < 0)
> +		clock_gettime(CLOCK_MONOTONIC, &ts);

[Severity: Medium]
Does this background thread rely on a fixed wall-clock timeout instead of
synchronizing with the main thread's delay accumulation?

If scheduler interleaving allows the main thread to run during this window,
its accumulated run delay will be strictly less than MIN_RUN_DELAY_NS when
this thread exits. Once this thread exits, CPU 0 becomes uncontended and
the main thread's delay accumulation loop will hang indefinitely.

> +
> +	return NULL;
> +}
[ ... ]
> +int main(void)
> +{
> +	struct kvm_vcpu *vcpu;
> +	struct kvm_vm *vm;
> +	pthread_attr_t attr;
> +	pthread_t thread;
> +	cpu_set_t cpuset;
> +	long run_delay;
> +	long run_delay_delta;
> +
> +	ksft_print_header();
> +	ksft_set_plan(1);
> +
> +	CPU_ZERO(&cpuset);
> +	CPU_SET(0, &cpuset);
> +	pthread_attr_init(&attr);
> +	pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset);
> +	pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);

[Severity: Medium]
If this pthread_setaffinity_np call fails (for example, if CPU 0 is not in
the allowed task mask), could the threads run on different CPUs? This would
prevent the main thread from ever accumulating runqueue wait time, causing it
to hang forever in the sched_yield loop.

[ ... ]
> +	run_delay = get_run_delay();
> +	pthread_create(&thread, &attr, do_steal_time, NULL);

[Severity: Medium]
If pthread_create fails due to resource limits, will the thread variable
remain uninitialized? 

> +
> +	while (get_run_delay() - run_delay < MIN_RUN_DELAY_NS)
> +		sched_yield();

[Severity: Medium]
As mentioned above, if do_steal_time exits before MIN_RUN_DELAY_NS is
accumulated by the main thread, does this spinloop hang permanently because
the background thread is no longer consuming CPU time?

> +
> +	pthread_join(thread, NULL);

[Severity: Medium]
If the thread variable is uninitialized due to a prior pthread_create
failure, does passing it unconditionally to pthread_join invoke undefined
behavior?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260904175550.430266-1-dongli.zhang@oracle.com?part=3

  reply	other threads:[~2026-09-04 18:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04 17:55 [PATCH v2 0/4] KVM: Reset steal time accounting on vCPU pid change Dongli Zhang
2026-09-04 17:55 ` [PATCH v2 1/4] KVM: Move last_steal to common struct kvm_vcpu Dongli Zhang
2026-09-04 18:07   ` sashiko-bot
2026-09-04 20:22     ` Dongli Zhang
2026-09-04 17:55 ` [PATCH v2 2/4] KVM: Reset last_steal on vCPU pid change Dongli Zhang
2026-09-04 17:55 ` [PATCH v2 3/4] KVM: selftests: Test steal time across vCPU pid changes on x86 Dongli Zhang
2026-09-04 18:11   ` sashiko-bot [this message]
2026-09-04 20:27     ` Dongli Zhang
2026-09-04 17:55 ` [PATCH v2 4/4] KVM: selftests: Add arm64 coverage for steal time pid changes Dongli Zhang

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=20260904181104.B25871F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dongli.zhang@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox