* [PATCH MANUALSEL 5.10] KVM: x86: Yield to IPI target vCPU only if it is busy
@ 2022-03-09 16:46 Sasha Levin
2022-03-09 16:51 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Sasha Levin @ 2022-03-09 16:46 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Li RongQing, Paolo Bonzini, Sasha Levin, tglx, mingo, bp,
dave.hansen, x86, kvm
From: Li RongQing <lirongqing@baidu.com>
[ 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
Signed-off-by: Li RongQing <lirongqing@baidu.com>
Message-Id: <1644380201-29423-1-git-send-email-lirongqing@baidu.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
arch/x86/kernel/kvm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 7462b79c39de..8fe6eb5bed3f 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH MANUALSEL 5.10] KVM: x86: Yield to IPI target vCPU only if it is busy
2022-03-09 16:46 [PATCH MANUALSEL 5.10] KVM: x86: Yield to IPI target vCPU only if it is busy Sasha Levin
@ 2022-03-09 16:51 ` Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2022-03-09 16:51 UTC (permalink / raw)
To: Sasha Levin, linux-kernel, stable
Cc: Li RongQing, tglx, mingo, bp, dave.hansen, x86, kvm
On 3/9/22 17:46, Sasha Levin wrote:
> From: Li RongQing <lirongqing@baidu.com>
>
> [ 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
>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> Message-Id: <1644380201-29423-1-git-send-email-lirongqing@baidu.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> arch/x86/kernel/kvm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> index 7462b79c39de..8fe6eb5bed3f 100644
> --- a/arch/x86/kernel/kvm.c
> +++ b/arch/x86/kernel/kvm.c
> @@ -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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-03-09 17:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-09 16:46 [PATCH MANUALSEL 5.10] KVM: x86: Yield to IPI target vCPU only if it is busy Sasha Levin
2022-03-09 16:51 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).