From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiao Guangrong Subject: Re: [PATCH v4] kvm: make vcpu life cycle separated from kvm instance Date: Thu, 15 Dec 2011 16:57:56 +0800 Message-ID: <4EE9B694.1000905@gmail.com> References: <1323923328-917-1-git-send-email-kernelfans@gmail.com> <4EE9869F.4070702@linux.vnet.ibm.com> <4EE9AF0F.9040206@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: Liu ping fan , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, avi@redhat.com, aliguori@us.ibm.com, gleb@redhat.com, mtosatti@redhat.com, jan.kiszka@web.de To: Xiao Guangrong Return-path: Received: from mail-iy0-f174.google.com ([209.85.210.174]:34835 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751353Ab1LOI6G (ORCPT ); Thu, 15 Dec 2011 03:58:06 -0500 In-Reply-To: <4EE9AF0F.9040206@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: On 12/15/2011 04:25 PM, Xiao Guangrong wrote: > On 12/15/2011 02:53 PM, Liu ping fan wrote: > > >> >>>> +struct kvm_vcpu *kvm_vcpu_get(struct kvm_vcpu *vcpu) >>>> +{ >>>> + if (vcpu == NULL) >>>> + return NULL; >>>> + if (atomic_add_unless(&vcpu->refcount, 1, 0)) >>> >>> >>> Why do not use atomic_inc()? >>> Also, i think a memory barrier is needed after increasing refcount. >>> >> Because when refcout==0, we prepare to destroy vcpu, and do not to >> disturb it by increasing the refcount. > > > Oh, get it. > But i think we can do it like this: On the vcpu free path: hold kvm->lock delete vcpu from the kvm->vcpus release kvm->lock synchronize_rcu() kvm_vcpu_put() then, we can avoid get invalid instance and it can make the code simple?