From patchwork Wed Feb 15 12:12:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li RongQing X-Patchwork-Id: 13141582 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 1D4FFC636D4 for ; Wed, 15 Feb 2023 12:12:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233951AbjBOMMg (ORCPT ); Wed, 15 Feb 2023 07:12:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233875AbjBOMMf (ORCPT ); Wed, 15 Feb 2023 07:12:35 -0500 Received: from njjs-sys-mailin01.njjs.baidu.com (mx316.baidu.com [180.101.52.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0176137F05 for ; Wed, 15 Feb 2023 04:12:32 -0800 (PST) Received: from localhost (bjhw-sys-rpm015653cc5.bjhw.baidu.com [10.227.53.39]) by njjs-sys-mailin01.njjs.baidu.com (Postfix) with ESMTP id 44B947F0005E; Wed, 15 Feb 2023 20:12:31 +0800 (CST) From: lirongqing@baidu.com To: kvm@vger.kernel.org, x86@kernel.org Subject: [PATCH] x86/kvm: refine condition for checking vCPU preempted Date: Wed, 15 Feb 2023 20:12:31 +0800 Message-Id: <20230215121231.43436-1-lirongqing@baidu.com> X-Mailer: git-send-email 2.9.4 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Li RongQing Check whether vcpu is preempted or not when HLT is trapped or there is not realtime hint. In other words, it is unnecessary to check preemption if HLT is not intercepted and guest has realtime hint Signed-off-by: Li RongQing --- arch/x86/kernel/kvm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 1cceac5..1a2744d 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -820,8 +820,10 @@ static void __init kvm_guest_init(void) has_steal_clock = 1; static_call_update(pv_steal_clock, kvm_steal_clock); - pv_ops.lock.vcpu_is_preempted = - PV_CALLEE_SAVE(__kvm_vcpu_is_preempted); + if (kvm_para_has_feature(KVM_FEATURE_PV_UNHALT) || + !kvm_para_has_hint(KVM_HINTS_REALTIME)) + pv_ops.lock.vcpu_is_preempted = + PV_CALLEE_SAVE(__kvm_vcpu_is_preempted); } if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))