From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiao Guangrong Subject: Re: [PATCH 05/12] KVM: MMU: add spte into rmap before logging dirty page Date: Wed, 31 Jul 2013 15:33:54 +0800 Message-ID: <51F8BDE2.7060309@linux.vnet.ibm.com> References: <1375189330-24066-1-git-send-email-xiaoguangrong@linux.vnet.ibm.com> <1375189330-24066-6-git-send-email-xiaoguangrong@linux.vnet.ibm.com> <51F7BF49.1000101@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: gleb@redhat.com, avi.kivity@gmail.com, mtosatti@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org To: Paolo Bonzini Return-path: In-Reply-To: <51F7BF49.1000101@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 07/30/2013 09:27 PM, Paolo Bonzini wrote: > Il 30/07/2013 15:02, Xiao Guangrong ha scritto: >> kvm_vm_ioctl_get_dirty_log() write-protects the spte based on the dirty >> bitmap, we should ensure the writable spte can be found in rmap before the >> dirty bitmap is visible. Otherwise, we cleared the dirty bitmap and failed >> to write-protect the page >> >> It need the memory barrier to prevent out-of-order that will be added in the >> later patch > > Do you mean that the later patch will also introduce a memory barrier? No. Sorry for the confusion. I mean we miss the memory barrier in this patch and will fix it in the latter patch where we introduce the lockless write-protection. The memory barrier is added in [PATCH 11/12] KVM: MMU: locklessly write-protect the page: + /* + * We should put the sptep into rmap before dirty log + * otherwise the lockless spte write-protect path will + * clear the dirty bit map but fail to find the spte. + * + * See the comments in kvm_vm_ioctl_get_dirty_log(). + */ + smp_wmb(); + if (pte_access & ACC_WRITE_MASK) and the barrier in the another side is: + /* + * xchg acts as a full barrier that ensures + * clearing dirty bitmap before read rmap. + * + * See the comments in set_spte(). + */ mask = xchg(&dirty_bitmap[i], 0);