Re: [PATCH v2 3/6] KVM: MMU: fix page dirty tracking lost while syncpage

From: Avi Kivity
Date: Wed Jul 21 2010 - 14:34:41 EST


On 07/16/2010 06:25 AM, Xiao Guangrong wrote:
In sync-page path, if spte.writable is changed, it will lose page dirty
tracking, for example:

assume spte.writable = 0 in a unsync-page, when it's synced, it map spte
to writable(that is spte.writable = 1), later guest write spte.gfn, it means
spte.gfn is dirty, then guest changed this mapping to read-only, after it's
synced, spte.writable = 0

So, when host release the spte, it detect spte.writable = 0 and not mark page
dirty


Subtle, good catch.

set_pte:
+ if (is_writable_pte(*sptep)&& !is_writable_pte(spte))
+ kvm_set_pfn_dirty(pfn);
update_spte(sptep, spte);

I think this has to be done after the tlb flush, otherwise we have

set_pfn_dirty
(some other cpu) write out page, mark as clean
(some other vcpu writes through stale tlb entry)
update_spte
tlb flush

but perhaps mmu notifiers protect us here, if the cleaner wants to write out the page it has to clear the dirty bit in sptes as well, and that will block on mmu_lock.

Later on we can use the dirty bit instead of writeable bit, except on EPT. But let's start with your fix.

--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

--
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/