All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Satish Kharat <satishkh@cisco.com>,
	Sashiko Bot <sashiko-bot@kernel.org>,
	 Oliver Upton <oupton@kernel.org>, Marc Zyngier <maz@kernel.org>
Subject: [PATCH v2 3/6] KVM: Add dedicated flag to track if multi-vCPU request needs at least one kick
Date: Thu, 19 Nov 2026 15:56:53 -0800	[thread overview]
Message-ID: <20261119235656.70315-4-seanjc@google.com> (raw)
In-Reply-To: <20261119235656.70315-1-seanjc@google.com>

Add a dedicated flag to track if a multi-vCPU request needs to kick at
least one CPU, so that non-waiting requests can avoid using the per-CPU
cpu_kick_mask by immediately sending a reschedule IPI instead of populating
and processing a cpumask set.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 virt/kvm/kvm_main.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c2231a130c4c..d2a858d4b8e9 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -213,19 +213,11 @@ static void ack_kick(void *_completed)
 {
 }
 
-static inline bool kvm_kick_many_cpus(struct cpumask *cpus, bool wait)
-{
-	if (cpumask_empty(cpus))
-		return false;
-
-	smp_call_function_many(cpus, ack_kick, NULL, wait);
-	return true;
-}
-
 struct kvm_cpu_kick {
 	int me;
 	unsigned int req;
 	struct cpumask *cpus;
+	bool need_kick;
 };
 
 static __always_inline struct kvm_cpu_kick kvm_init_cpu_kick(unsigned int req)
@@ -242,12 +234,12 @@ static __always_inline struct kvm_cpu_kick kvm_init_cpu_kick(unsigned int req)
 
 static bool kvm_finish_cpu_kick(struct kvm_cpu_kick *kick)
 {
-	bool kicked;
-
-	kicked = kvm_kick_many_cpus(kick->cpus, !!(kick->req & KVM_REQUEST_WAIT));
+	if (kick->need_kick)
+		smp_call_function_many(kick->cpus, ack_kick, NULL,
+				       !!(kick->req & KVM_REQUEST_WAIT));
 
 	put_cpu();
-	return kicked;
+	return kick->need_kick;
 }
 
 static void kvm_make_vcpu_request(struct kvm_vcpu *vcpu,
@@ -273,8 +265,10 @@ static void kvm_make_vcpu_request(struct kvm_vcpu *vcpu,
 	 */
 	if (kvm_request_needs_ipi(vcpu, kick->req)) {
 		cpu = READ_ONCE(vcpu->cpu);
-		if (cpu != -1 && cpu != kick->me)
+		if (cpu != -1 && cpu != kick->me) {
+			kick->need_kick = true;
 			__cpumask_set_cpu(cpu, kick->cpus);
+		}
 	}
 }
 
-- 
2.56.1.708.g77570a6a1d-goog


  parent reply	other threads:[~2026-11-19 23:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 23:56 [PATCH v2 0/6] KVM: Send reschedule IPIs for non-waiting requests Sean Christopherson
2026-11-19 23:56 ` [PATCH v2 1/6] s390/smp: Export arch_smp_send_reschedule() for KVM Sean Christopherson
2026-11-23 12:39   ` Christian Borntraeger
2026-11-24 15:54   ` Heiko Carstens
2026-11-26  6:31   ` Christian Borntraeger
2026-11-19 23:56 ` [PATCH v2 2/6] KVM: Add struct and helpers to handle kicking multiple (v)CPUs Sean Christopherson
2026-11-19 23:56 ` Sean Christopherson [this message]
2026-11-19 23:56 ` [PATCH v2 4/6] KVM: Don't kick offline CPUs when making a multi-vCPU request Sean Christopherson
2026-11-19 23:56 ` [PATCH v2 5/6] KVM: Send reschedule IPIs instead of SMP function calls for non-waiting requests Sean Christopherson
2026-11-21 15:24   ` Satish Kharat
2026-11-19 23:56 ` [PATCH v2 6/6] KVM: Extract and dedup the kick code to check if a CPU needs an IPI Sean Christopherson
2026-11-27 14:22 ` [PATCH v2 0/6] KVM: Send reschedule IPIs for non-waiting requests Paolo Bonzini

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=20261119235656.70315-4-seanjc@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=sashiko-bot@kernel.org \
    --cc=satishkh@cisco.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.