Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wanpeng Li" <kernellwp@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 09/10] KVM: Add IPI-aware directed-yield candidate selection
Date: Fri, 12 Jun 2026 01:48:34 +0000	[thread overview]
Message-ID: <20260612014835.07F5D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260612013355.59231-10-kernellwp@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The new candidate filter incorrectly excludes woken-up, runnable vCPUs from being yield targets by strictly requiring the `preempted` flag.
--

commit f2a5464aa09eda51a02ed6e5f04bf8ea0072c9ba
Author: Wanpeng Li <wanpengli@tencent.com>

KVM: Add IPI-aware directed-yield candidate selection

This commit introduces a priority-based candidate filter for directed yields
in kvm_vcpu_on_spin(). It prefers recent IPI receivers or vCPUs with pending
interrupts before falling back to the legacy preempted heuristic.

> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c

[ ... ]

> +static bool kvm_vcpu_is_good_yield_candidate(struct kvm_vcpu *me,
> +					     struct kvm_vcpu *vcpu,
> +					     bool yield_to_kernel_mode)
> +{
> +	/* Priority 1: confirmed recent IPI receiver. */
> +	if (kvm_vcpu_is_ipi_receiver(me, vcpu))
> +		return true;
> +
> +	/* Priority 2: arch-specific pending-interrupt hint. */
> +	if (kvm_arch_dy_has_pending_interrupt(vcpu))
> +		return true;
> +
> +	/* Priority 3: preempted, with optional in-kernel requirement. */
> +	if (!READ_ONCE(vcpu->preempted))
> +		return false;

[Severity: High]
Does this code inadvertently exclude runnable but non-preempted vCPUs
from being yield targets?

In the previous implementation, the preempted check was part of a compound
skip condition:

	if (READ_ONCE(vcpu->preempted) && yield_to_kernel_mode &&
	    !kvm_arch_dy_has_pending_interrupt(vcpu) &&
	    !kvm_arch_vcpu_preempted_in_kernel(vcpu))
		continue;

This meant that if a vCPU was not preempted (for instance, it was recently
woken up from a blocking state and is ready to run), it bypassed the skip
condition and was considered a valid target.

By explicitly returning false here when vcpu->preempted is false, this
new filter seems to drop those valid targets.

> +
> +	if (yield_to_kernel_mode && !kvm_arch_vcpu_preempted_in_kernel(vcpu))
> +		return false;
> +
> +	return true;
> +}

[ ... ]

>  		if (kvm_vcpu_is_blocking(vcpu) && !vcpu_dy_runnable(vcpu))
>  			continue;
>  
> -		/*
> -		 * Treat the target vCPU as being in-kernel if it has a pending
> -		 * interrupt, as the vCPU trying to yield may be spinning
> -		 * waiting on IPI delivery, i.e. the target vCPU is in-kernel
> -		 * for the purposes of directed yield.
> -		 */
> -		if (READ_ONCE(vcpu->preempted) && yield_to_kernel_mode &&
> -		    !kvm_arch_dy_has_pending_interrupt(vcpu) &&
> -		    !kvm_arch_vcpu_preempted_in_kernel(vcpu))
> -			continue;
> +		if (first_round) {
> +			/* Strict round: IPI-aware and legacy preempted filters. */
> +			if (!kvm_vcpu_is_good_yield_candidate(me, vcpu,
> +							      yield_to_kernel_mode))
> +				continue;
> +		} else {
> +			/*
> +			 * Relaxed round: only require preempted. This is the
> +			 * safety net for missed IPI tracking (e.g. APICv) or
> +			 * transient runnable-set changes since the strict
> +			 * scan.
> +			 */
> +			if (!READ_ONCE(vcpu->preempted))
> +				continue;

[Severity: High]
Similarly, does this relaxed round unconditionally skip non-preempted
vCPUs?

If the vCPU is simply runnable but not marked as preempted, this safety net
will completely bypass it.

>  		}
>  
>  		if (!kvm_vcpu_eligible_for_directed_yield(vcpu))

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260612013355.59231-1-kernellwp@gmail.com?part=9

  reply	other threads:[~2026-06-12  1:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-12  1:33 [PATCH v3 00/10] sched/fair, KVM: Semantics-aware directed yield for oversubscribed KVM Wanpeng Li
2026-06-12  1:33 ` [PATCH v3 01/10] sched/fair: Add EEVDF lag credit primitive for nominated next-buddy Wanpeng Li
2026-06-12  1:49   ` sashiko-bot
2026-06-12  5:34   ` K Prateek Nayak
2026-06-12  1:33 ` [PATCH v3 02/10] sched/fair: Credit a persistent, queue-depth-scaled vlag margin Wanpeng Li
2026-06-12  1:53   ` sashiko-bot
2026-06-12  6:07   ` K Prateek Nayak
2026-06-12  1:33 ` [PATCH v3 03/10] sched/fair: Credit queued next-buddy via canonical requeue Wanpeng Li
2026-06-12  1:55   ` sashiko-bot
2026-06-12  1:33 ` [PATCH v3 04/10] sched/fair: Credit nominated next-buddy in yield_to_task_fair() Wanpeng Li
2026-06-12  1:54   ` sashiko-bot
2026-06-12  1:33 ` [PATCH v3 05/10] sched/fair: Force a local resched on yield_to() so the buddy is picked Wanpeng Li
2026-06-12  1:50   ` sashiko-bot
2026-06-12  1:33 ` [PATCH v3 06/10] KVM: x86: Add IPI tracking infrastructure for directed yield Wanpeng Li
2026-06-12  1:33 ` [PATCH v3 07/10] KVM: x86/lapic: Track unicast fixed IPI delivery Wanpeng Li
2026-06-12  1:33 ` [PATCH v3 08/10] KVM: x86/lapic: Clear IPI tracking on matching-vector EOI Wanpeng Li
2026-06-12  3:46   ` sashiko-bot
2026-06-12  1:33 ` [PATCH v3 09/10] KVM: Add IPI-aware directed-yield candidate selection Wanpeng Li
2026-06-12  1:48   ` sashiko-bot [this message]
2026-06-12  1:33 ` [PATCH v3 10/10] KVM: Add relaxed preempted-only fallback for directed yield Wanpeng Li
2026-06-12  5:17 ` [PATCH v3 00/10] sched/fair, KVM: Semantics-aware directed yield for oversubscribed KVM K Prateek Nayak
2026-06-12  9:43 ` 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=20260612014835.07F5D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kernellwp@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox