From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrea Arcangeli Subject: Re: [PATCH 1/2] KVM: mmu_notifier: Flush TLBs before releasing mmu_lock Date: Tue, 14 Feb 2012 18:27:39 +0100 Message-ID: <20120214172739.GM9440@redhat.com> References: <20120210152831.6ac3ac87.yoshikawa.takuya@oss.ntt.co.jp> <4F34CCD1.6050103@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Takuya Yoshikawa , avi@redhat.com, mtosatti@redhat.com, kvm@vger.kernel.org To: Xiao Guangrong Return-path: Received: from mx1.redhat.com ([209.132.183.28]:34052 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751600Ab2BNR2L (ORCPT ); Tue, 14 Feb 2012 12:28:11 -0500 Content-Disposition: inline In-Reply-To: <4F34CCD1.6050103@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: On Fri, Feb 10, 2012 at 03:52:49PM +0800, Xiao Guangrong wrote: > On 02/10/2012 02:28 PM, Takuya Yoshikawa wrote: > > > Other threads may process the same page in that small window and skip > > TLB flush and then return before these functions do flush. > > > > > It is possible that flush tlb in mmu lock only when writeable > spte is invalided? Sometimes, kvm_flush_remote_tlbs need > long time to wait. readonly isn't enough to defer the flush after mmu_lock is released... if you do it only for writable spte, then what can happen is the guest may read random data and would crash. However for this case, the mmu_notifier methods (and only them) are perfectly safe to flush the shadow MMU TLB after the mmu_lock is released because the page reference is guaranteed hold by the caller (not the case for any other place where a spte gets dropped in KVM, all other places dropping sptes, can only on the mmu notifier to block on the mmu_lock in order to have a guarantee of the page not being freed under them, so in every other place the shadow MMU TLB flush must happen before releasing the mmu_lock so the mmu_notifier will wait and prevent the page to be freed until all other CPUs running in guest mode stopped accessing it).