From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 1/2] KVM: mmu_notifier: Flush TLBs before releasing mmu_lock Date: Thu, 16 Feb 2012 13:57:10 +0200 Message-ID: <4F3CEF16.5060405@redhat.com> References: <20120210152831.6ac3ac87.yoshikawa.takuya@oss.ntt.co.jp> <20120214171044.GK9440@redhat.com> <20120214172947.GA22362@amt.cnet> <20120214185356.GQ9440@redhat.com> <20120214194342.GA24117@amt.cnet> <4F3B7867.7000807@redhat.com> <4F3B7F1F.40402@redhat.com> <4F3B9902.5000306@linux.vnet.ibm.com> <4F3BBC35.6010502@redhat.com> <4F3C8B0A.4020800@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti , Andrea Arcangeli , Takuya Yoshikawa , kvm@vger.kernel.org To: Xiao Guangrong Return-path: Received: from mx1.redhat.com ([209.132.183.28]:10932 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751769Ab2BPL5Q (ORCPT ); Thu, 16 Feb 2012 06:57:16 -0500 In-Reply-To: <4F3C8B0A.4020800@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: On 02/16/2012 06:50 AM, Xiao Guangrong wrote: > I think we do not need handle all tlb-flushed request here since all of these > request can be delayed to the point where mmu-lock is released , we can simply > do it: > > void kvm_mmu_defer_remote_flush(kvm, need_flush) > { > if (need_flush) > ++kvm->tlbs_dirty; > } > > void kvm_mmu_commit_remote_flush(struct kvm *kvm) > { > int dirty_count = kvm->tlbs_dirty; > > smp_mb(); > > if (!dirty_count) > return; > > if (make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH)) > ++kvm->stat.remote_tlb_flush; <-- point A > cmpxchg(&kvm->tlbs_dirty, dirty_count, 0); > } > > if this is ok, we only need do small change in the current code, since > kvm_mmu_commit_remote_flush is very similar with kvm_flush_remote_tlbs(). Suppose at point A another thread executes defer_remote_flush(), commit_remote_flush(), and defer_remote_flush() again. This brings the balue of tlbs_dirty back to 1 again, with the tlbs dirty. The cmpxchg() then resets tlbs_dirty, leaving the actual tlbs dirty. -- error compiling committee.c: too many arguments to function