Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3188379ybz; Mon, 27 Apr 2020 11:32:31 -0700 (PDT) X-Google-Smtp-Source: APiQypISSFKNR1bAg/Rih080rH73e65tQF6mTRuUYegxlAnh8h2iSBzOGJQfcGQ5YTslo54JJJ0m X-Received: by 2002:aa7:d455:: with SMTP id q21mr19236296edr.235.1588012351672; Mon, 27 Apr 2020 11:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588012351; cv=none; d=google.com; s=arc-20160816; b=gmvs1GALuvYgdsEcFDBLE53jB5D14QmYw/ojXhXPLQevDWbYhMFWj5TSs+BjVLKiDc P1cpM6W6Z2YGxyauwNC47hB1a+z99JYDXjU3ODZsfvnojNdnzR6Pe7E6YgwlX36/iTTv TYWhbpbCcWcDe1m7I/D32yG9dyud7DwXXgFNBfYMm4ocwlJBMl4u1/ivfJcJs9Jc5tlE yMl16vn6cxBqgCI8MIVECP2/YqwOvi0BJd399tn/9F+Z0ru8O843FYnicAJnAAM6RRcV NGx518X1p8F2DSX4nevVAK17rg5a7xbxQ1dw1K/eA0xJy1QUCU8tbIswFbSXEPnO/EMX NL9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=cGQqgbpnmB0SlkM0fPotUVPfL5gQi4zJ1Ap60eCUhC0=; b=Vl3kya1/ubK4qM6n1R0eHFplXhouMT8cR6Y9V9rhGFlG1C2Ddj2EpnLrSyfty/mgaH FucaFClzZgy1cu8c/GjujJaLJDFZ8fAivP/xG5EtoNOScAfiib/wwtb2mQO7IE8VmX1m Q9jXT23DTk6BC5pTXdevYVjXrXvVyZ1136CgOvUMmTiMMmxwpiG09X1tiljUu29vpxrV jA3TYocJ4fClRg/AbsKWaJt7ZueIlQeMCdZR/SxvoE0/kWINRveQJZ7LZ3pBhnEhei8o bPhZ7sOcRMUw60XVKTwYpoakq0Wv45maR++T0By5CircHHVEGnH0O6aeIpivs1dorpc0 ZWzw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g12si248425ejw.314.2020.04.27.11.32.07; Mon, 27 Apr 2020 11:32:31 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726583AbgD0SaP (ORCPT + 99 others); Mon, 27 Apr 2020 14:30:15 -0400 Received: from mga03.intel.com ([134.134.136.65]:34512 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbgD0SaP (ORCPT ); Mon, 27 Apr 2020 14:30:15 -0400 IronPort-SDR: FH5ieVHTDZl2NcHKKYf3Qs7DeErajLnY5EAM0OEBjnqhXdmMpwSrJk3Wab0NNYh1W3Q0BZorGQ 6oo8xKHAu1mw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2020 11:30:14 -0700 IronPort-SDR: dzNpUWnLy+BqQgkoHYn8J7WnmojkK9OYjkNk7tmyxglsZJEl8zaAD+fCzVBM4QOOGsJNp/sxSe LJqMy4MasX9w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,325,1583222400"; d="scan'208";a="281861522" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by fmsmga004.fm.intel.com with ESMTP; 27 Apr 2020 11:30:13 -0700 Date: Mon, 27 Apr 2020 11:30:13 -0700 From: Sean Christopherson To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Haiwei Li Subject: Re: [PATCH v3 2/5] KVM: X86: Introduce need_cancel_enter_guest helper Message-ID: <20200427183013.GN14870@linux.intel.com> References: <1587709364-19090-1-git-send-email-wanpengli@tencent.com> <1587709364-19090-3-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1587709364-19090-3-git-send-email-wanpengli@tencent.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 24, 2020 at 02:22:41PM +0800, 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; > + } > > return exit_fastpath; > } > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 59958ce..4561104 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -1581,6 +1581,13 @@ int kvm_emulate_wrmsr(struct kvm_vcpu *vcpu) > } > EXPORT_SYMBOL_GPL(kvm_emulate_wrmsr); > > +bool kvm_need_cancel_enter_guest(struct kvm_vcpu *vcpu) What about kvm_vcpu__pending()? Not sure what a good ??? would be. The "cancel_enter_guest" wording is a bit confusing when this is called from the VM-Exit path. > +{ > + return (vcpu->mode == EXITING_GUEST_MODE || kvm_request_pending(vcpu) > + || need_resched() || signal_pending(current)); Parantheses around the whole statement are unnecessary. Personal preference is to put the || before the newline. > +} > +EXPORT_SYMBOL_GPL(kvm_need_cancel_enter_guest); > + > /* > * The fast path for frequent and performance sensitive wrmsr emulation, > * i.e. the sending of IPI, sending IPI early in the VM-Exit flow reduces > @@ -8373,8 +8380,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > if (kvm_lapic_enabled(vcpu) && vcpu->arch.apicv_active) > kvm_x86_ops.sync_pir_to_irr(vcpu); > > - if (vcpu->mode == EXITING_GUEST_MODE || kvm_request_pending(vcpu) > - || need_resched() || signal_pending(current)) { > + if (kvm_need_cancel_enter_guest(vcpu)) { > vcpu->mode = OUTSIDE_GUEST_MODE; > smp_wmb(); > local_irq_enable(); > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > index 7b5ed8e..1906e7e 100644 > --- a/arch/x86/kvm/x86.h > +++ b/arch/x86/kvm/x86.h > @@ -364,5 +364,6 @@ static inline bool kvm_dr7_valid(u64 data) > void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu); > void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu); > u64 kvm_spec_ctrl_valid_bits(struct kvm_vcpu *vcpu); > +bool kvm_need_cancel_enter_guest(struct kvm_vcpu *vcpu); > > #endif > -- > 2.7.4 >