Linux virtualization list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shrikanth Hegde" <sshegde@linux.ibm.com>
Cc: virtualization@lists.linux.dev,
	"Eugenio Perez" <eperezma@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH v13 12/13] virt/steal_governor: Implement steal_governor policy loop
Date: Wed, 09 Sep 2026 14:16:32 +0000	[thread overview]
Message-ID: <20260909141632.C7A4A1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260909135617.871006-13-sshegde@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Lockless access to `cpu_active_mask` in `preferred_cpus_valid()` can lead to a spurious failure of `cpumask_subset()`, causing the driver to permanently shut down.
--

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

virt/steal_governor: Implement steal_governor policy loop

This patch implements the core policy loop for the steal_governor driver using
a delayed workqueue. It periodically calculates the steal time ratio and
dynamically adjusts the preferred CPU mask based on high or low contention
thresholds.

> 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]
Can this lockless check spuriously fail and cause the driver to incorrectly
shut down?

Because cpus_read_lock() is not held here, there appears to be a race
condition with CPU hotplug operations (such as sched_cpu_deactivate()). When a
CPU is taken offline, it is removed from the relevant masks sequentially.

If cpumask_subset() reads cpu_preferred_mask while the dying CPU's bit is
still set, and then reads cpu_active_mask after the CPU's bit has been cleared,
the subset evaluation will spuriously return 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)
> +{

[ ... ]

> +	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()) {
> +		restore_preferred_to_active();
> +		return;

[Severity: High]
If preferred_cpus_valid() spuriously fails due to the lockless race described
above, does this early return permanently disable the driver?

By returning here without requeueing the work via schedule_delayed_work(),
the periodic loop is halted completely, leaving the driver non-functional
until the module is manually reloaded.

> +	}
> +
> +requeue_work:
> +	schedule_delayed_work(&sg_ctx.work, sg_ctx.delay);
> +}

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

  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
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 [this message]
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=20260909141632.C7A4A1F00A3A@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