From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liran Alon Subject: Re: [PATCH v3 06/11] KVM: x86: Set current_vcpu per-cpu var before enabling interrupts at host Date: Wed, 27 Dec 2017 12:44:03 +0200 Message-ID: <5A437973.9030307@ORACLE.COM> References: <1514131983-24305-1-git-send-email-liran.alon@oracle.com> <1514131983-24305-7-git-send-email-liran.alon@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: jmattson@google.com, wanpeng.li@hotmail.com, idan.brown@ORACLE.COM, Liam Merwick To: Paolo Bonzini , rkrcmar@redhat.com, kvm@vger.kernel.org Return-path: Received: from userp2130.oracle.com ([156.151.31.86]:57768 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750930AbdL0KoQ (ORCPT ); Wed, 27 Dec 2017 05:44:16 -0500 In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On 27/12/17 12:06, Paolo Bonzini wrote: > On 24/12/2017 17:12, Liran Alon wrote: >> >> + kvm_before_handle_host_interrupts(vcpu); >> local_irq_enable(); >> + kvm_after_handle_host_interrupts(vcpu); >> preempt_enable(); > > This should be around the call to kvm_x86_ops->handle_external_intr, not > here. > > Also, perhaps you could: 1) do the kvm_before_handle_* unconditionally > before the point where NMIs would be injected; 2) remove the > kvm_after_handle_* from vmx_complete_atomic_exit and svm_vcpu_run; 3) > only do kvm_after_handle_* after kvm_x86_ops->handle_external_intr, not > before it. > > Paolo > The intention of this change was that later commit can handle the case where nested posted-interrupts processing is triggered by self-IPI but the CPU has immediately exited guest after resume because of another external interrupt (different than POSTED_INTR_NESTED_VECTOR). In this case, the POSTED_INTR_NESTED_VECTOR interrupt will be triggered on host after vcpu_enter_guest() calls local_irq_enable(). And our handler should re-set vmx->nested.pi_pending to true so that on next vmentry, vmx_complete_nested_posted_interrupt() will re-trigger a self-IPI. Therefore it is not sufficient to put calls to kvm_{before,after}_handle_host_interrupts around call to kvm_x86_ops->handle_external_intr(). But you are correct that it makes sense to also put these calls around that call-site as-well. So as I see it, we have 2 alternatives here: 1. Just add calls around kvm_x86_ops->handle_external_intr(). 2. Go with your suggestion but with a more intuitive approach: Change only vcpu_enter_guest() such that: a. Will call kvm_before_handle_host_interrupts() after setting vcpu->mode = IN_GUEST_MODE. b. Will call kvm_after_handle_host_interrupts() after calls to local_irq_enable() (One in case there is a pending KVM requst and one after guest was run and we exited guest normally). What do you think? Regards, -Liran