From patchwork Wed Feb 9 04:16:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li RongQing X-Patchwork-Id: 12739615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29E67C433FE for ; Wed, 9 Feb 2022 05:10:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238382AbiBIFHk (ORCPT ); Wed, 9 Feb 2022 00:07:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377730AbiBIEcE (ORCPT ); Tue, 8 Feb 2022 23:32:04 -0500 X-Greylist: delayed 468 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 08 Feb 2022 20:24:33 PST Received: from njjs-sys-mailin08.njjs.baidu.com (mx313.baidu.com [180.101.52.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E55FFC0612BC for ; Tue, 8 Feb 2022 20:24:33 -0800 (PST) Received: from bjhw-sys-rpm015653cc5.bjhw.baidu.com (bjhw-sys-rpm015653cc5.bjhw.baidu.com [10.227.53.39]) by njjs-sys-mailin08.njjs.baidu.com (Postfix) with ESMTP id 1BF1960C004A; Wed, 9 Feb 2022 12:16:42 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by bjhw-sys-rpm015653cc5.bjhw.baidu.com (Postfix) with ESMTP id F14D0D9932; Wed, 9 Feb 2022 12:16:41 +0800 (CST) From: Li RongQing To: kvm@vger.kernel.org, x86@kernel.org, jmattson@google.com, wanpengli@tencent.com, vkuznets@redhat.com, seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org Subject: [PATCH] KVM: x86: Yield to IPI target vCPU only if it is busy Date: Wed, 9 Feb 2022 12:16:41 +0800 Message-Id: <1644380201-29423-1-git-send-email-lirongqing@baidu.com> X-Mailer: git-send-email 1.7.1 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 --- 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 355fe8b..58749f2 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -619,7 +619,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; }