Linux virtualization list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shrikanth Hegde" <sshegde@linux.ibm.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>,
	virtualization@lists.linux.dev
Subject: Re: [PATCH v13 01/13] sched/cputime: Add kcpustat_field_total helper
Date: Wed, 09 Sep 2026 14:16:11 +0000	[thread overview]
Message-ID: <20260909141611.F11461F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260909135617.871006-2-sshegde@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Splitting a single iteration loop into two independent passes over a concurrently modified cpumask introduces a TOCTOU race, causing a mismatch between accumulated steal time and CPU count.
--

commit f4767f1bec53619b21fdac4c5195173936031ed9
Author: Shrikanth Hegde <sshegde@linux.ibm.com>

sched/cputime: Add kcpustat_field_total helper

This commit introduces a new helper function kcpustat_field_total() to sum up
a given cpustat over a specified cpumask. It then refactors existing code in
the s390 hiperdispatch and procfs uptime to use this helper to simplify the
code and avoid duplication.

> diff --git a/arch/s390/kernel/hiperdispatch.c b/arch/s390/kernel/hiperdispatch.c
> index 2172065222661..c21496f0a141a 100644
> --- a/arch/s390/kernel/hiperdispatch.c
> +++ b/arch/s390/kernel/hiperdispatch.c
> @@ -207,16 +207,12 @@ static unsigned long hd_calculate_steal_percentage(void)
>  {
>  	unsigned long time_delta, steal_delta, steal, percentage;
>  	static ktime_t prev;
> -	int cpus, cpu;
> +	int cpus;
>  	ktime_t now;
>  
> -	cpus = 0;
> -	steal = 0;
>  	percentage = 0;
> -	for_each_cpu(cpu, &hd_vmvl_cpumask) {
> -		steal += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL];
> -		cpus++;
> -	}
> +	steal = kcpustat_field_total(CPUTIME_STEAL, &hd_vmvl_cpumask);
> +	cpus = cpumask_weight(&hd_vmvl_cpumask);

[Severity: Medium]
Does splitting this single loop into two independent passes over
hd_vmvl_cpumask introduce a race condition?

If CPU hotplug operations modify hd_vmvl_cpumask concurrently between the calls
to kcpustat_field_total() and cpumask_weight(), could this result in a
mismatched numerator and denominator?

For example, the first read could see a large mask, while the second read sees
a smaller mask. This mismatch can cause transient artificial spikes in the
steal percentage.

Could this incorrectly trigger a scheduler domain rebuild
(topology_schedule_update()) and lead to an unnecessary performance degradation
during CPU hotplug operations?

>  	/*
>  	 * If there is no vertical medium and low CPUs steal time
>  	 * is 0 as vertical high CPUs shouldn't experience steal time.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909135617.871006-1-sshegde@linux.ibm.com?part=1

  reply	other threads:[~2026-09-09 14:16 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 13:56 [PATCH v13 00/13] sched, steal_governor: Introduce preferred CPUs and steal-driven vCPU backoff Shrikanth Hegde
2026-09-09 13:56 ` [PATCH v13 01/13] sched/cputime: Add kcpustat_field_total helper Shrikanth Hegde
2026-09-09 14:16   ` sashiko-bot [this message]
2026-09-09 13:56 ` [PATCH v13 02/13] cpumask: Introduce cpumask_intersects_and Shrikanth Hegde
2026-09-09 14:02   ` sashiko-bot
2026-09-09 16:03   ` Yury Norov
2026-09-09 13:56 ` [PATCH v13 03/13] sched/docs: Document cpu_preferred_mask and Preferred CPU concept Shrikanth Hegde
2026-09-09 14:01   ` sashiko-bot
2026-09-09 13:56 ` [PATCH v13 04/13] cpumask: Introduce cpu_preferred_mask Shrikanth Hegde
2026-09-09 14:06   ` sashiko-bot
2026-09-09 13:56 ` [PATCH v13 05/13] sysfs: Add preferred CPU file Shrikanth Hegde
2026-09-09 14:04   ` sashiko-bot
2026-09-09 13:56 ` [PATCH v13 06/13] sched/core: Try to use a preferred CPU in is_cpu_allowed Shrikanth Hegde
2026-09-09 14:18   ` sashiko-bot
2026-09-09 16:49     ` Shrikanth Hegde
2026-09-09 13:56 ` [PATCH v13 07/13] sched/fair: Load balance only among preferred CPUs Shrikanth Hegde
2026-09-09 14:33   ` sashiko-bot
2026-09-09 17:09     ` Shrikanth Hegde
2026-09-09 17:19   ` Yury Norov
2026-09-09 13:56 ` [PATCH v13 08/13] sched/core: Push current task from non preferred CPU Shrikanth Hegde
2026-09-09 14:18   ` sashiko-bot
2026-09-09 13:56 ` [PATCH v13 09/13] sched/debug: Add migration stats due to non preferred CPUs Shrikanth Hegde
2026-09-09 14:07   ` sashiko-bot
2026-09-09 13:56 ` [PATCH v13 10/13] virt: Introduce steal governor driver Shrikanth Hegde
2026-09-09 14:09   ` sashiko-bot
2026-09-09 13:56 ` [PATCH v13 11/13] virt/steal_governor: Add control knobs for handling steal values Shrikanth Hegde
2026-09-09 14:06   ` sashiko-bot
2026-09-09 13:56 ` [PATCH v13 12/13] virt/steal_governor: Implement steal_governor policy loop Shrikanth Hegde
2026-09-09 14:16   ` sashiko-bot
2026-09-09 16:52     ` Shrikanth Hegde
2026-09-09 13:56 ` [PATCH v13 13/13] virt/steal_governor: Enable the driver Shrikanth Hegde
2026-09-09 14:17   ` sashiko-bot
2026-09-09 16:58     ` Shrikanth Hegde

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=20260909141611.F11461F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sshegde@linux.ibm.com \
    --cc=virtualization@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