From patchwork Mon Nov 1 09:05:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 294182 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oA1912NJ011259 for ; Mon, 1 Nov 2010 09:01:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754943Ab0KAJAi (ORCPT ); Mon, 1 Nov 2010 05:00:38 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:54748 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753649Ab0KAJAh (ORCPT ); Mon, 1 Nov 2010 05:00:37 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 7862D170701; Mon, 1 Nov 2010 17:00:36 +0800 (CST) Received: from fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id oA18uKvp026309; Mon, 1 Nov 2010 16:56:21 +0800 Received: from [10.167.225.99] (unknown [10.167.225.99]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 81C2110C245; Mon, 1 Nov 2010 17:02:22 +0800 (CST) Message-ID: <4CCE82BC.3090000@cn.fujitsu.com> Date: Mon, 01 Nov 2010 17:05:00 +0800 From: Xiao Guangrong User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 MIME-Version: 1.0 To: Avi Kivity CC: Marcelo Tosatti , Gleb Natapov , LKML , KVM Subject: [RFC PATCH v2 7/7] KVM: KVM: don't break vcpu 'halt' state due to apfs References: <4CCE8143.3090105@cn.fujitsu.com> In-Reply-To: <4CCE8143.3090105@cn.fujitsu.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Mon, 01 Nov 2010 09:01:03 +0000 (UTC) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 189664a..c57fb38 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6105,13 +6105,20 @@ void kvm_arch_flush_shadow(struct kvm *kvm) int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu) { - return (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE && + if ((vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE && !vcpu->arch.apf.halted) - || !list_empty_careful(&vcpu->async_pf.done) || vcpu->arch.mp_state == KVM_MP_STATE_SIPI_RECEIVED || vcpu->arch.nmi_pending || (kvm_arch_interrupt_allowed(vcpu) && - kvm_cpu_has_interrupt(vcpu)); + kvm_cpu_has_interrupt(vcpu))) + return 1; + + if (!list_empty_careful(&vcpu->async_pf.done)) { + vcpu->arch.apf.halted = false; + return 2; + } + + return 0; } void kvm_vcpu_kick(struct kvm_vcpu *vcpu) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 462b982..8def043 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -436,6 +436,12 @@ void kvm_arch_hardware_disable(void *garbage); int kvm_arch_hardware_setup(void); void kvm_arch_hardware_unsetup(void); void kvm_arch_check_processor_compat(void *rtn); + +/* + * return value: > 0 if the vcpu is runnable, 0 if not. + * Especially, if the return value == 1, we should make a + * 'KVM_REQ_UNHALT' request. + */ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu); void kvm_free_physmem(struct kvm *kvm); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index dbe1d6a..9ccf105 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1375,14 +1375,21 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn) void kvm_vcpu_block(struct kvm_vcpu *vcpu) { DEFINE_WAIT(wait); + int ret; for (;;) { prepare_to_wait(&vcpu->wq, &wait, TASK_INTERRUPTIBLE); - if (kvm_arch_vcpu_runnable(vcpu)) { + ret = kvm_arch_vcpu_runnable(vcpu); + + if (ret == 1) { kvm_make_request(KVM_REQ_UNHALT, vcpu); break; } + + if (ret > 1) + break; + if (kvm_cpu_has_pending_timer(vcpu)) break; if (signal_pending(current))