From: sashiko-bot@kernel.org
To: "Shrikanth Hegde" <sshegde@linux.ibm.com>
Cc: "Eugenio Perez" <eperezma@redhat.com>,
virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH v14 12/13] virt/steal_governor: Implement steal_governor policy loop
Date: Mon, 28 Sep 2026 05:51:56 +0000 [thread overview]
Message-ID: <20260928055157.15EFF1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260928053728.797539-13-sshegde@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Missing bounds check on interval_ms allows infinite workqueue spinloop
- [High] TOCTOU data race in preferred_cpus_valid() causes erroneous driver shutdown
- [Medium] Integer overflow in steal_ratio denominator when VM is paused
--
commit 5f38399332407b64e0ce2da43681c27f1e1287d5
Author: Shrikanth Hegde <sshegde@linux.ibm.com>
virt/steal_governor: Implement steal_governor policy loop
Schedule work at regular intervals to implement the steal_governor
policy loop, which monitors steal time and takes action on the state of
preferred CPUs. The interval is determined by the interval_ms parameter.
> diff --git a/drivers/virt/steal_governor.c b/drivers/virt/steal_governor.c
> index 27f53ea16498b..6e31f9923dea4 100644
> --- a/drivers/virt/steal_governor.c
> +++ b/drivers/virt/steal_governor.c
[ ... ]
> +static bool preferred_cpus_valid(void)
> +{
> + if (cpumask_empty(cpu_preferred_mask)) {
> + pr_err("empty preferred mask. stopping\n");
> + return false;
> + }
> +
> + if (!cpumask_subset(cpu_preferred_mask, cpu_active_mask)) {
[Severity: High]
Does this lockless read of cpu_preferred_mask and cpu_active_mask race
with CPU hotplug?
Since CPU hotplug clears the preferred mask bit before the active mask bit,
it seems cpumask_subset() can read a torn state where a word is read from
the preferred mask before the bit is cleared, and the corresponding word
is read from the active mask after the bit is cleared, returning false.
> + pr_err("preferred: %*pbl is not subset of active: %*pbl, stopping\n",
> + cpumask_pr_args(cpu_preferred_mask),
> + cpumask_pr_args(cpu_active_mask));
> + return false;
> + }
> +
> + return true;
> +}
> +
> +static void steal_governor_loop(struct work_struct *work)
> +{
> + u64 curr_steal, delta_steal, delta_ns, steal_ratio;
> + ktime_t now;
> +
> + now = ktime_get();
> + delta_ns = ktime_to_ns(ktime_sub(now, sg_ctx.time));
> +
> + if (unlikely(delta_ns < NSEC_PER_MSEC)) {
> + pr_err_ratelimited("work scheduled too soon delta_ns: %llu\n", delta_ns);
> + goto requeue_work;
[Severity: High]
Can this create an infinite spinloop if interval_ms is set to 0?
If interval_ms is 0, the delay is 0 jiffies. When the work executes, it will
take this branch because delta_ns < 1ms. It jumps directly to requeue_work
without updating sg_ctx.time, which schedules it again with 0 delay. This
will continuously spin and consume an entire CPU core.
> + }
> +
> + curr_steal = get_system_steal_time();
> + delta_steal = curr_steal > sg_ctx.steal ? curr_steal - sg_ctx.steal : 0;
> + sg_ctx.steal = curr_steal;
> + sg_ctx.time = now;
> +
> + /*
> + * steal_ratio = (delta_steal * 100*100)/(delta_ns * num_cpus())
> + * To avoid possible overflow, divide the denominator early.
> + * Note minimum interval is 100ms.
> + */
> + delta_ns = max_t(u64, div_u64(delta_ns * get_system_cpus(), 10000), 1);
[Severity: Medium]
Will this silently overflow the 64-bit multiplication if the VM is paused
for an extended period?
Since the multiplication of delta_ns * get_system_cpus() happens before
the division, a large time delta (e.g., a large VM suspended for a long time)
can overflow U64_MAX, leading to a wildly incorrect steal_ratio calculation.
> + steal_ratio = div64_u64(delta_steal, delta_ns);
> +
> + if (steal_ratio > sg_ctx.high_threshold)
> + decrease_preferred_cpus();
> + else if (steal_ratio <= sg_ctx.low_threshold)
> + increase_preferred_cpus();
> + /*
> + * else: steal ratio is within bounds. Still do design checks so that
> + * module restores to active if CPU hotplug breaks those assumptions.
> + */
> + if (!preferred_cpus_valid()) {
[Severity: High]
Does calling preferred_cpus_valid() here without cpus_read_lock() lead
to a false teardown?
If a hotplug operation is happening concurrently, the torn state read in
preferred_cpus_valid() will cause the governor to erroneously shut down
the policy loop permanently.
> + restore_preferred_to_active();
> + return;
> + }
> +
> +requeue_work:
> + schedule_delayed_work(&sg_ctx.work, sg_ctx.delay);
[Severity: High]
Does this immediately spin if sg_ctx.delay is 0, as mentioned above?
> +}
> +
> static int __init steal_governor_init(void)
> {
[ ... ]
> sg_ctx.delay = msecs_to_jiffies(sg_ctx.interval_ms);
[Severity: High]
Is it possible for sg_ctx.interval_ms to be 0 here?
The module parameter interval_ms doesn't appear to be bounds-checked
before this point, meaning it could be set to 0 and trigger the infinite
workqueue spinloop.
> + INIT_DELAYED_WORK(&sg_ctx.work, steal_governor_loop);
> + sg_ctx.steal = get_system_steal_time();
> + sg_ctx.time = ktime_get();
> + schedule_delayed_work(&sg_ctx.work, sg_ctx.delay);
> pr_info("enabled. interval: %ums, high_threshold: %u, low_threshold: %u\n",
> sg_ctx.interval_ms, sg_ctx.high_threshold, sg_ctx.low_threshold);
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260928053728.797539-1-sshegde@linux.ibm.com?part=12
next prev parent reply other threads:[~2026-09-28 5:51 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 5:37 [PATCH v14 00/13] sched, steal_governor: Introduce preferred CPUs and steal-driven vCPU backoff Shrikanth Hegde
2026-09-28 5:37 ` [PATCH v14 01/13] sched/cputime: Add kcpustat_field_total helper Shrikanth Hegde
2026-09-28 5:54 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 02/13] cpumask: Introduce cpumask_intersects_and Shrikanth Hegde
2026-09-28 5:44 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 03/13] sched/docs: Document cpu_preferred_mask and Preferred CPU concept Shrikanth Hegde
2026-09-28 5:42 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 04/13] cpumask: Introduce cpu_preferred_mask Shrikanth Hegde
2026-09-28 5:46 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 05/13] sysfs: Add preferred CPU file Shrikanth Hegde
2026-09-28 5:47 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 06/13] sched/core: Try to use a preferred CPU in is_cpu_allowed Shrikanth Hegde
2026-09-28 6:00 ` sashiko-bot
2026-09-28 6:48 ` Shrikanth Hegde
2026-09-28 5:37 ` [PATCH v14 07/13] sched/fair: Load balance only among preferred CPUs Shrikanth Hegde
2026-09-28 5:55 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 08/13] sched/core: Push current task from non preferred CPU Shrikanth Hegde
2026-09-28 5:56 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 09/13] sched/debug: Add migration stats due to non preferred CPUs Shrikanth Hegde
2026-09-28 5:48 ` sashiko-bot
2026-09-29 12:18 ` Nathan Chancellor
2026-09-29 12:43 ` Shrikanth Hegde
2026-09-29 14:57 ` Shrikanth Hegde
2026-09-28 5:37 ` [PATCH v14 10/13] virt: Introduce steal governor driver Shrikanth Hegde
2026-09-28 5:47 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 11/13] virt/steal_governor: Add control knobs for handling steal values Shrikanth Hegde
2026-09-28 5:46 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 12/13] virt/steal_governor: Implement steal_governor policy loop Shrikanth Hegde
2026-09-28 5:51 ` sashiko-bot [this message]
2026-09-28 6:52 ` Shrikanth Hegde
2026-09-28 5:37 ` [PATCH v14 13/13] virt/steal_governor: Enable the driver Shrikanth Hegde
2026-09-28 5:48 ` sashiko-bot
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=20260928055157.15EFF1F000FF@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