Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6138635iob; Tue, 10 May 2022 11:11:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu0Eej2An54uFw46fqj9Ek4Nk8cg44HaPlGq7KgRnSHThFBp8LPtIM44vAc5z71HZFi6ME X-Received: by 2002:a17:906:2883:b0:6e8:7012:4185 with SMTP id o3-20020a170906288300b006e870124185mr20676772ejd.204.1652206291394; Tue, 10 May 2022 11:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652206291; cv=none; d=google.com; s=arc-20160816; b=JnH9XnIMeAH+kQXiVqmFoUmixEfDdeAhw5Ot+KDvqAFN368ifCv9aLoMgqC+d0ApNf 8eNvKcy8Xq0I9Hc4tK6QzbQvsbagwvoLJ/mlrXbglR9+J4KV7BtdInRcsaEKShzcYmVm sd1YXOeZjN/YSxuAu80mv7VkzpjPzevJ823lVQcbyLA3N/tL/qt4LakPBSND+3F0TrEc +mqHsMzAURmIV//gklUd9z/u7PFFjbRf52ghcs4/Vubij73WhGUgRyPfTEazTib2gjuy As7lX32mYiWVz/ZMalVSWcswRIdglf9myY3yNkxn6jBuWbRkGr3Tvcl3h0GZQiYnenPJ M8+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=05d1877H9J7mBKFf5YXGkqU62a+q4p5JjVd0+w6HuOQ=; b=eHewX7XRyYP54/0WZbNfjuUa1RxhYjXPwG7w1z53V7HKGsMYSGFffRlE7K0mrNSnw/ zLKfRr2EZkf0Qyu0gKy4LVgqQmbi1ZTe7VmIzyv8epGiVDHh87C0T7G6rCGVWgUr+ZEu lauJiYxgjE8NBqcBOsEt9S8EClja6GnlCjCt7P2Qq8NL4VcYNoXYJ5Djl6WAsd/hOrKw BlulPGuTmM9PxbJyHBVmw/xRA7u6MRta2FyJY6PvaB4LaI2Ti6vsshpZeR80DMouOSKl hGVmCrKHGHsI7L1RHKFfbsrbEZUhegr7eYr50Dz99jtlxN4QWSrDT223+jrwV6BMFEkT mPaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vsuvJgX+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l11-20020aa7c30b000000b0041953d28471si13678810edq.235.2022.05.10.11.11.06; Tue, 10 May 2022 11:11:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vsuvJgX+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244590AbiEJNqw (ORCPT + 99 others); Tue, 10 May 2022 09:46:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243919AbiEJNcV (ORCPT ); Tue, 10 May 2022 09:32:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2B51D54; Tue, 10 May 2022 06:23:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 75BBFB81D7A; Tue, 10 May 2022 13:23:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBDEEC385C2; Tue, 10 May 2022 13:23:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652189023; bh=qS9yeF5Z4kqyQaN+jkF6ZO2qnwVTEewgiRMJ/qCZUY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vsuvJgX+iw44plVfiOEzFKvkjDcRTjxBPRhLoav92kG21ydBkCBmJJGWxys/BmvNb KTy7Hw/dhGdqvLEmYNNEuzlFcRWrTEZpH1U2BKHBmsQWym8DLD7Ax6MEjTyLulT/JK aozR6Cs+KgUR6RRcIHlmoNnNXkGrO1dY+u7J8OI0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aili Yao , Sean Christopherson , Wanpeng Li , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.4 38/52] KVM: LAPIC: Enable timer posted-interrupt only when mwait/hlt is advertised Date: Tue, 10 May 2022 15:08:07 +0200 Message-Id: <20220510130730.967514649@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130729.852544477@linuxfoundation.org> References: <20220510130729.852544477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li [ Upstream commit 1714a4eb6fb0cb79f182873cd011a8ed60ac65e8 ] As commit 0c5f81dad46 ("KVM: LAPIC: Inject timer interrupt via posted interrupt") mentioned that the host admin should well tune the guest setup, so that vCPUs are placed on isolated pCPUs, and with several pCPUs surplus for *busy* housekeeping. In this setup, it is preferrable to disable mwait/hlt/pause vmexits to keep the vCPUs in non-root mode. However, if only some guests isolated and others not, they would not have any benefit from posted timer interrupts, and at the same time lose VMX preemption timer fast paths because kvm_can_post_timer_interrupt() returns true and therefore forces kvm_can_use_hv_timer() to false. By guaranteeing that posted-interrupt timer is only used if MWAIT or HLT are done without vmexit, KVM can make a better choice and use the VMX preemption timer and the corresponding fast paths. Reported-by: Aili Yao Reviewed-by: Sean Christopherson Cc: Aili Yao Cc: Sean Christopherson Signed-off-by: Wanpeng Li Message-Id: <1643112538-36743-1-git-send-email-wanpengli@tencent.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/lapic.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index afe3b8e61514..3696b4de9d99 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -118,7 +118,8 @@ static inline u32 kvm_x2apic_id(struct kvm_lapic *apic) bool kvm_can_post_timer_interrupt(struct kvm_vcpu *vcpu) { - return pi_inject_timer && kvm_vcpu_apicv_active(vcpu); + return pi_inject_timer && kvm_vcpu_apicv_active(vcpu) && + (kvm_mwait_in_guest(vcpu->kvm) || kvm_hlt_in_guest(vcpu->kvm)); } EXPORT_SYMBOL_GPL(kvm_can_post_timer_interrupt); -- 2.35.1