Re: [PATCH 10/15] KVM: MMU: lockless walking shadow page table

From: Xiao Guangrong
Date: Fri Jun 10 2011 - 00:21:07 EST


On 06/10/2011 04:09 AM, Paul E. McKenney wrote:
> On Tue, Jun 07, 2011 at 09:04:34PM +0800, Xiao Guangrong wrote:
>> Using rcu to protect shadow pages table to be freed, so we can safely walk it,
>> it should run fast and is needed by mmio page fault
>
> A couple of question below.

Thanks for your review!

>> + if (atomic_read(&kvm->arch.reader_counter)) {
>
> This is the slowpath to be executed if there are currently readers
> in kvm->arch.reader_counter(), correct?
>

Yes, we will free the pages in RCU context if it is in kvm->arch.reader_counter

>> + free_mmu_pages_unlock_parts(invalid_list);
>> + sp = list_first_entry(invalid_list, struct kvm_mmu_page, link);
>> + list_del_init(invalid_list);
>> + call_rcu(&sp->rcu, free_invalid_pages_rcu);
>> + return;
>> + }
>
> OK, so it also looks like kvm->arch.reader_counter could transition from
> zero to non-zero at this point due to a concurrent call from a reader in
> the kvm_mmu_walk_shadow_page_lockless() function. Does the following code
> avoid messing up the reader? If so, why bother with the slowpath above?
>

Actually, we have split the free operation to two steps, the first step is
kvm_mmu_prepare_zap_page(), it isolates the page from shadow page table, so
after call it, we can not get the page from the shadow page table, and the
later steps is kvm_mmu_commit_zap_page(), it frees the page.

kvm_mmu_walk_shadow_page_lockless() get the page from shadow page table,
so, even if kvm->arch.reader_counter transition from zero to non-zero in
the fallowing code, we can sure the page is not used by
kvm_mmu_walk_shadow_page_lockless(), so we can free the page directly.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/