Skip to contentSkip to conversation

KVM: x86: Yield to IPI target vCPU only if it is busy

PATCH NAK Sasha Levin 2 participants 2 messages Mar 9, 2022

Subsystems (2)
lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

PATCH 1/1 KVM: x86: Yield to IPI target vCPU only if it is busy

From: Li RongQing <[email protected]>

[ Upstream commit 9ee83635d872812f3920209c606c6ea9e412ffcc ]

When sending a call-function IPI-many to vCPUs, yield to the IPI target vCPU which is marked as preempted.

but when emulating HLT, an idling vCPU will be voluntarily scheduled out and mark as preempted from the guest kernel perspective. yielding to idle vCPU is pointless and increase unnecessary vmexit, maybe miss the true preempted vCPU

so yield to IPI target vCPU only if vCPU is busy and preempted

Message-Id: <[email protected]>

---
 arch/x86/kernel/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/kvm.c +1 -1
index 7462b79c39de..8fe6eb5bed3f 100644
@@ -590,7 +590,7 @@ static void kvm_smp_send_call_func_ipi(const struct cpumask *mask)
 
 	/* Make sure other vCPUs get a chance to run if they need to. */
 	for_each_cpu(cpu, mask) {
-		if (vcpu_is_preempted(cpu)) {
+		if (!idle_cpu(cpu) && vcpu_is_preempted(cpu)) {
 			kvm_hypercall1(KVM_HC_SCHED_YIELD, per_cpu(x86_cpu_to_apicid, cpu));
 			break;
 		}
Signature · 1 line
2.34.1
maintainer NAK
#1 lore raw
Quoted 27 lines · Sasha Levin

From: Li RongQing <[email protected]>

[ Upstream commit 9ee83635d872812f3920209c606c6ea9e412ffcc ]

When sending a call-function IPI-many to vCPUs, yield to the IPI target vCPU which is marked as preempted.

but when emulating HLT, an idling vCPU will be voluntarily scheduled out and mark as preempted from the guest kernel perspective. yielding to idle vCPU is pointless and increase unnecessary vmexit, maybe miss the true preempted vCPU

so yield to IPI target vCPU only if vCPU is busy and preempted

Message-Id: <[email protected]>

---
  arch/x86/kernel/kvm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/kvm.c +0 -0
index 7462b79c39de..8fe6eb5bed3f 100644

arch/x86/kernel/kvm.c static void kvm_smp_send_call_func_ipi(const struct cpumask *mask) · line 596

Quoted 8 lines
arch/x86/kernel/kvm.c +1 -1
@@ -590,7 +590,7 @@ static void kvm_smp_send_call_func_ipi(const struct cpumask *mask)
 
  	/* Make sure other vCPUs get a chance to run if they need to. */
  	for_each_cpu(cpu, mask) {
-		if (vcpu_is_preempted(cpu)) {
+		if (!idle_cpu(cpu) && vcpu_is_preempted(cpu)) {
  			kvm_hypercall1(KVM_HC_SCHED_YIELD, per_cpu(x86_cpu_to_apicid, cpu));
  			break;
  		}

NACK