Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3528408ybz; Mon, 27 Apr 2020 17:48:48 -0700 (PDT) X-Google-Smtp-Source: APiQypLEaVlO2h4wTeEzwGzelegSokfGYHCdQ7W8m6Uqv9dBtQiMEZcgx94leMIFzxB9ZxX2zqS7 X-Received: by 2002:a17:906:27d1:: with SMTP id k17mr21628286ejc.134.1588034927974; Mon, 27 Apr 2020 17:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588034927; cv=none; d=google.com; s=arc-20160816; b=1J+t8LsKxurK9/V2C7Df/o1h9OfdBEudKKwsAOC7XZI1+7LEuFtyN18fQAh7ApQebZ Wk1rGQwMHU484oWeXeURGv0Xf/hqZBw8UnDNELII0Re81ZRaoJ+iPaeQYSPaIgbWDVHh KGURoX2hJFkcFvih+EWfYfgSmC7ytH5XpWuqfdTHg1PMVkOcKsVA0hZM/Jwy7TXbZ9on q/Bgv2f+mt34qgHE/2zAt1swC2pcMAOOnquYJLfcub5O1kOYo+xmW65iKCFqcPQMKgUH MJGujDCNk6Mbijpw3kZDiAcq/8JycixTSndB7EnOoxsHK/xzl2Cu3f9jZBSiHr1bg7S+ cn8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=VhGS8dYUF43wLQV+THWnzQsHj2BDh87oypEgi/eQ6Kg=; b=AxsmFio8ORuax7dUnQM4tGUfpB6izgiqaceUS4b6x9ma0bG7y1kjo9kI3c4V1+04TJ ZJj69Awwi6ObtKsE/HN7NPnzpexNcIkvfnQfuA5/N653xPhscHS+he75A5ZA8mrDnjDc p36YvbN6G7V5cuquUR2mFsBcVemT06nWx19yvr7vYWzRFiT7qYYKfjaIWcNconXVRruk /EulNFqSLXCkPzHy5Iaq8hUphhPqruCJBV+DqEjZ1mREAzANFIzvbmKsX+K2x+a7+cFr 5JRp1lkaP0aDiC1TpVSvy3sDKd7Tgm0AfLIdzc6hi3ai/6Sj6E/lhHK14cT3x83T4xOF 5cxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OiQeazIF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fx7si881345ejb.149.2020.04.27.17.48.25; Mon, 27 Apr 2020 17:48:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OiQeazIF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726335AbgD1AoZ (ORCPT + 99 others); Mon, 27 Apr 2020 20:44:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726263AbgD1AoZ (ORCPT ); Mon, 27 Apr 2020 20:44:25 -0400 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B7EAC03C1A8; Mon, 27 Apr 2020 17:44:25 -0700 (PDT) Received: by mail-ot1-x342.google.com with SMTP id g19so29706778otk.5; Mon, 27 Apr 2020 17:44:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VhGS8dYUF43wLQV+THWnzQsHj2BDh87oypEgi/eQ6Kg=; b=OiQeazIF2D+is/AHjp1Cf0TjfxsAC2pwsqBg7M2opP/nWx3JsneE7+JQ4c4RUaWaVt gOakvIsDK/12Dlyoe3srTPPINtf+EyHumf1GBwHuQBzt69dwvU0ZXqOevZOt3sanyM3s TvNEF4EqKj2oGaRvYahMKienDyiOPM0ApMbRg2Inpef3idPjPm9q06vvWI6ebOmeHIeU zL0FRTw2Q67kN21sdqperJ2OkN9iJMXLGGYznamBomMNU4vMt1bU/yb2BrL7XD3Hw/XH hGouTHbjMyYa36hzazNTcVq7dnP3r3tH7eFYJns/BuRizMuASe1XH3Y0l9OdxQPAt45h oGCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VhGS8dYUF43wLQV+THWnzQsHj2BDh87oypEgi/eQ6Kg=; b=pVKL3FZS0bbjAN1SeAdBsgX4GOyhWQl0Z1guVbwvQ0aOM2dBrGg2AmnoCwRmcHV1+v KbSBX76B9LOqTs7XGeJ7LUtGcQvfaMQJlLGbW+enbAgmYHyrhJegbAL3F6e7K3ibSzeK HHn1trfnreeCwrhu526bE11nU9tSbOSXOZWshNHWuv9BdMqovOJmvj22lnRdQJyVF1nX l+0YiGek7v4tQYntdvLO2e3ZIvbvHSfH/QF6SNzv7vG81bxQPgNV5uLdp+VcAhrYHiT+ cwBNbeD93QLSobjQWgRoUC9El38LwcYVg/gksJ0wpX/1+oDCbIyfGP3jry0ELHfOFanR km5g== X-Gm-Message-State: AGi0PuYjpox54N9pWICv76sRGQe/YTQ60fbXa/6IC7yPy2dsIP9J5oCz vysD6GwpeV8KQJfx6c4MdsnPBsGKbz1SrYGUdeU= X-Received: by 2002:a05:6830:20d9:: with SMTP id z25mr12751170otq.254.1588034664624; Mon, 27 Apr 2020 17:44:24 -0700 (PDT) MIME-Version: 1.0 References: <1587709364-19090-1-git-send-email-wanpengli@tencent.com> <1587709364-19090-3-git-send-email-wanpengli@tencent.com> <20200427183656.GO14870@linux.intel.com> In-Reply-To: <20200427183656.GO14870@linux.intel.com> From: Wanpeng Li Date: Tue, 28 Apr 2020 08:44:13 +0800 Message-ID: Subject: Re: [PATCH v3 2/5] KVM: X86: Introduce need_cancel_enter_guest helper To: Sean Christopherson Cc: LKML , kvm , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Haiwei Li Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 28 Apr 2020 at 02:36, Sean Christopherson wrote: > > On Sun, Apr 26, 2020 at 10:05:00AM +0800, Wanpeng Li wrote: > > On Fri, 24 Apr 2020 at 14:23, Wanpeng Li wrote: > > > > > > From: Wanpeng Li > > > > > > Introduce need_cancel_enter_guest() helper, we need to check some > > > conditions before doing CONT_RUN, in addition, it can also catch > > > the case vmexit occurred while another event was being delivered > > > to guest software since vmx_complete_interrupts() adds the request > > > bit. > > > > > > Tested-by: Haiwei Li > > > Cc: Haiwei Li > > > Signed-off-by: Wanpeng Li > > > --- > > > arch/x86/kvm/vmx/vmx.c | 12 +++++++----- > > > arch/x86/kvm/x86.c | 10 ++++++++-- > > > arch/x86/kvm/x86.h | 1 + > > > 3 files changed, 16 insertions(+), 7 deletions(-) > > > > > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > > > index f1f6638..5c21027 100644 > > > --- a/arch/x86/kvm/vmx/vmx.c > > > +++ b/arch/x86/kvm/vmx/vmx.c > > > @@ -6577,7 +6577,7 @@ bool __vmx_vcpu_run(struct vcpu_vmx *vmx, unsigned long *regs, bool launched); > > > > > > static enum exit_fastpath_completion vmx_vcpu_run(struct kvm_vcpu *vcpu) > > > { > > > - enum exit_fastpath_completion exit_fastpath; > > > + enum exit_fastpath_completion exit_fastpath = EXIT_FASTPATH_NONE; > > > struct vcpu_vmx *vmx = to_vmx(vcpu); > > > unsigned long cr3, cr4; > > > > > > @@ -6754,10 +6754,12 @@ static enum exit_fastpath_completion vmx_vcpu_run(struct kvm_vcpu *vcpu) > > > vmx_recover_nmi_blocking(vmx); > > > vmx_complete_interrupts(vmx); > > > > > > - exit_fastpath = vmx_exit_handlers_fastpath(vcpu); > > > - /* static call is better with retpolines */ > > > - if (exit_fastpath == EXIT_FASTPATH_CONT_RUN) > > > - goto cont_run; > > > + if (!kvm_need_cancel_enter_guest(vcpu)) { > > > + exit_fastpath = vmx_exit_handlers_fastpath(vcpu); > > > + /* static call is better with retpolines */ > > > + if (exit_fastpath == EXIT_FASTPATH_CONT_RUN) > > > + goto cont_run; > > > + } > > > > The kvm_need_cancel_enter_guest() should not before > > vmx_exit_handlers_fastpath() which will break IPI fastpath. How about > > applying something like below, otherwise, maybe introduce another > > EXIT_FASTPATH_CONT_FAIL to indicate fails due to > > kvm_need_cancel_enter_guest() if checking it after > > vmx_exit_handlers_fastpath(), then we return 1 in vmx_handle_exit() > > directly instead of kvm_skip_emulated_instruction(). VMX-preemption > > timer exit doesn't need to skip emulated instruction but wrmsr > > TSCDEADLINE MSR exit does which results in a little complex here. > > > > Paolo, what do you think? > > > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > > index 853d3af..9317924 100644 > > --- a/arch/x86/kvm/vmx/vmx.c > > +++ b/arch/x86/kvm/vmx/vmx.c > > @@ -6564,6 +6564,9 @@ static enum exit_fastpath_completion > > handle_fastpath_preemption_timer(struct kvm > > { > > struct vcpu_vmx *vmx = to_vmx(vcpu); > > > > + if (kvm_need_cancel_enter_guest(vcpu)) > > + return EXIT_FASTPATH_NONE; > > + > > if (!vmx->req_immediate_exit && > > !unlikely(vmx->loaded_vmcs->hv_timer_soft_disabled)) { > > kvm_lapic_expired_hv_timer(vcpu); > > @@ -6771,12 +6774,10 @@ static enum exit_fastpath_completion > > vmx_vcpu_run(struct kvm_vcpu *vcpu) > > vmx_recover_nmi_blocking(vmx); > > vmx_complete_interrupts(vmx); > > > > - if (!(kvm_need_cancel_enter_guest(vcpu))) { > > - exit_fastpath = vmx_exit_handlers_fastpath(vcpu); > > - if (exit_fastpath == EXIT_FASTPATH_CONT_RUN) { > > - vmx_sync_pir_to_irr(vcpu); > > - goto cont_run; > > - } > > + exit_fastpath = vmx_exit_handlers_fastpath(vcpu); > > + if (exit_fastpath == EXIT_FASTPATH_CONT_RUN) { > > Relying on the handlers to check kvm_need_cancel_enter_guest() will be > error prone and costly to maintain. I also don't like that it buries the > logic. > > What about adding another flavor, e.g.: > > exit_fastpath = vmx_exit_handlers_fastpath(vcpu); > if (exit_fastpath == EXIT_FASTPATH_CONT_RUN && > kvm_need_cancel_enter_guest(vcpu)) > exit_fastpath = EXIT_FASTPATH_NOP; > > That would also allow you to enable preemption timer without first having > to add CONT_RUN, which would be a very good thing for bisection. I miss understand the second part, do you mean don't need to add CONT_RUN in patch 1/5? Wanpeng