From patchwork Mon Nov 1 09:03:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 294162 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 oA18xjGv011067 for ; Mon, 1 Nov 2010 08:59:45 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754936Ab0KAI7W (ORCPT ); Mon, 1 Nov 2010 04:59:22 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:58345 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1754862Ab0KAI7V (ORCPT ); Mon, 1 Nov 2010 04:59:21 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 04340170933; Mon, 1 Nov 2010 16:59:20 +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 oA18t5nW026226; Mon, 1 Nov 2010 16:55:06 +0800 Received: from [10.167.225.99] (unknown [10.167.225.99]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id CC1D214C0A1; Mon, 1 Nov 2010 17:01:06 +0800 (CST) Message-ID: <4CCE8270.5020300@cn.fujitsu.com> Date: Mon, 01 Nov 2010 17:03:44 +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 6/7] KVM: fix the race while wakeup all pv guest 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 08:59:46 +0000 (UTC) diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c index d57ec92..6ef3373 100644 --- a/virt/kvm/async_pf.c +++ b/virt/kvm/async_pf.c @@ -200,7 +200,7 @@ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu) { struct kvm_async_pf *work; - if (!list_empty(&vcpu->async_pf.done)) + if (!list_empty_careful(&vcpu->async_pf.done)) return 0; work = kmem_cache_zalloc(async_pf_cache, GFP_ATOMIC); @@ -211,7 +211,10 @@ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu) get_page(bad_page); INIT_LIST_HEAD(&work->queue); /* for list_del to work */ + spin_lock(&vcpu->async_pf.lock); list_add_tail(&work->link, &vcpu->async_pf.done); + spin_unlock(&vcpu->async_pf.lock); + vcpu->async_pf.queued++; return 0; }