kvm mmu notifier
PATCH 1/1 kvm mmu notifier
Hello,
this is the mmu notifier patch for kvm updated according to last comments.
arch/x86/kvm/Kconfig +1 -0
@@ -21,6 +21,7 @@ config KVM tristate "Kernel-based Virtual Machine (KVM) support" depends on HAVE_KVM select PREEMPT_NOTIFIERS + select MMU_NOTIFIER select ANON_INODES ---help--- Support hosting fully virtualized guest machines using hardware
arch/x86/kvm/mmu.c +120 -0
180 lines not on this page · raw message
arch/x86/kvm/paging_tmpl.h +19 -0
@@ -263,6 +263,12 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *page, pfn = vcpu->arch.update_pte.pfn;if (is_error_pfn (pfn))return ; +if (unlikely (atomic_read (&vcpu->kvm->mmu_notifier_count))) +return ; +smp_rmb (); +if (unlikely (atomic_read (&vcpu->kvm->mmu_notifier_seq) != + vcpu->arch.update_pte.mmu_seq)) +return ;kvm_get_pfn (pfn); mmu_set_spte(vcpu, spte, page->role.access, pte_access, 0, 0, gpte & PT_DIRTY_MASK, NULL, largepage, gpte_to_gfn(gpte),
@@ -380,6 +386,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,int r;pfn_t pfn;int largepage =0 ; +int mmu_seq;pgprintk ("%s: addr %lx err %x\n" , __func__, addr, error_code);kvm_mmu_audit (vcpu,"pre page fault" );
@@ -413,6 +420,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, largepage =1 ; } } + mmu_seq =atomic_read (&vcpu->kvm->mmu_notifier_seq); +/* implicit mb(), we'll read before PT lock is unlocked */ pfn =gfn_to_pfn (vcpu->kvm, walker.gfn);up_read (¤t->mm->mmap_sem);
@@ -424,6 +433,11 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, }spin_lock (&vcpu->kvm->mmu_lock); +if (unlikely (atomic_read (&vcpu->kvm->mmu_notifier_count))) + goto out_unlock; +smp_rmb (); +if (unlikely (atomic_read (&vcpu->kvm->mmu_notifier_seq) != mmu_seq)) + goto out_unlock;kvm_mmu_free_some_pages (vcpu); shadow_pte =FNAME (fetch)(vcpu, addr, &walker, user_fault, write_fault, largepage, &write_pt, pfn);
@@ -439,6 +453,11 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,spin_unlock (&vcpu->kvm->mmu_lock);return write_pt; + +out_unlock: +spin_unlock (&vcpu->kvm->mmu_lock); +kvm_release_pfn_clean (pfn); +return 0 ; }static gpa_t FNAME (gva_to_gpa )(struct kvm_vcpu *vcpu,gva_t vaddr)
arch/x86/kvm/x86.c +1 -0
@@ -27,6 +27,7 @@#include <linux/module.h> #include <linux/mman.h> #include <linux/highmem.h> +#include <linux/mmu_notifier.h> #include <asm/uaccess.h> #include <asm/msr.h>
include/asm-x86/kvm_host.h +5 -0
@@ -13,6 +13,7 @@#include <linux/types.h> #include <linux/mm.h> +#include <linux/mmu_notifier.h> #include <linux/kvm.h> #include <linux/kvm_para.h>
@@ -251,6 +252,7 @@ struct kvm_vcpu_arch {gfn_t gfn;/* presumed gfn during guest pte update */ pfn_t pfn;/* pfn corresponding to that gfn */ int largepage; +int mmu_seq; } update_pte;struct i387_fxsave_struct host_fx_image;
@@ -450,6 +452,9 @@ void kvm_mmu_set_base_ptes(u64 base_pte);void kvm_mmu_set_mask_ptes (u64 user_mask,u64 accessed_mask,u64 dirty_mask,u64 nx_mask,u64 x_mask); +#define KVM_ARCH_WANT_MMU_NOTIFIER +int kvm_unmap_hva (struct kvm *kvm,unsigned long hva); +int kvm_age_hva (struct kvm *kvm,unsigned long hva);int kvm_mmu_reset_context (struct kvm_vcpu *vcpu);void kvm_mmu_slot_remove_write_access (struct kvm *kvm,int slot);void kvm_mmu_zap_all (struct kvm *kvm);
include/linux/kvm_host.h +6 -0
@@ -121,6 +121,12 @@ struct kvm {struct kvm_coalesced_mmio_dev *coalesced_mmio_dev;struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;#endif + +#ifdef KVM_ARCH_WANT_MMU_NOTIFIER +struct mmu_notifier mmu_notifier; +atomic_t mmu_notifier_seq; +atomic_t mmu_notifier_count; +#endif };/* The guest did something we don't support. */
virt/kvm/kvm_main.c +148 -0
166 lines not on this page · raw message
This is the kvm-userland compatibility bit to build against old kernels without mmu notifier.
kernel/include-compat/linux/mmu_notifier.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _LINUX_MMU_NOTIFIER_H +#define _LINUX_MMU_NOTIFIER_H + +struct mmu_notifier {}; + +#endif
Quoted 2 lines · Marcelo Tosatti
These two functions share the same memslot iteration code, you could avoid duplication.
Ok, I'll look into cleaning this up a bit.
Quoted 6 lines
arch/x86/kvm/paging_tmpl.h static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *page, · line 268
Quoted 3 lines
arch/x86/kvm/paging_tmpl.h +3
-0+if (unlikely (atomic_read (&vcpu->kvm->mmu_notifier_count))) +return ; +smp_rmb ();I don't think you need
smp_rmb()on x86 since atomic operations serialize.barrier()should suffice.
atomic_read doesn't issue any atomic op, and reads are out of order on x86. So it's needed.
Quoted 1 line
Wrap this sequence in a well documented function?
It would be nice cleanup, agreed.
Quoted 14 lines
Quoted 14 lines
virt/kvm/kvm_main.c +14
-0+static void kvm_mmu_notifier_invalidate_range_start (struct mmu_notifier *mn, +struct mm_struct *mm, +unsigned long start, +unsigned long end) +{ +struct kvm *kvm =mmu_notifier_to_kvm (mn); +int need_tlb_flush =0 ; + +/* +* The count increase must become visible at unlock time as no +* spte can be established without taking the mmu_lock and +* count is also read inside the mmu_lock critical section. +*/ +atomic_inc (&kvm->mmu_notifier_count);
Quoted 8 lines
virt/kvm/kvm_main.c void kvm_vcpu_uninit(struct kvm_vcpu *vcpu) · line 250
Quoted 5 lines
virt/kvm/kvm_main.c +5
-0+ +spin_lock (&kvm->mmu_lock); +for (; start < end; start +=PAGE_SIZE ) + need_tlb_flush |=kvm_unmap_hva (kvm, start); +spin_unlock (&kvm->mmu_lock);You don't handle large mappings here at all, which means that there might be external mappings even after ->range_start, ->range_end.
Well if I don't handle large mappings it won't be because of the above function. The above function is common code, it doesn't know anything about the lowlevel spte implementation yet. If something it's a business of kvm_unmap_hva to handle large mappings. I thought it does but maybe not and we need to fix it.
Quoted 4 lines
This is not a problem now because QEMU kills all the shadow mappings before
munmap()on hugetlbfs, but it will be a practical problem if ballooning supports largepages (which will probably happen in the future), or with fancy hugetlb features.
We need to handle large mappings too, especially if we intend to remove page pinning from them as well.
Quoted 9 lines
virt/kvm/kvm_main.c void kvm_vcpu_uninit(struct kvm_vcpu *vcpu) · line 289
Quoted 7 lines
virt/kvm/kvm_main.c +7
-0+atomic_inc (&kvm->mmu_notifier_seq); +/* +* The sequence increase must be visible before count +* decrease. The page fault has to read count before sequence +* for this write order to be effective. +*/ +wmb ();
smp_mb_after_atomic_inc?
Surely more finegrined, agreed.
Quoted 2 lines
Is it worth to flush remote TLB's just due to the young bit? Aging can happen often.
This is more important for the linux ptes than the sptes. Because we do for the main pagetables, I do for secondary ones too to be consistent. For both, if we don't flush the tlb, the young bit will never be set again until the entry goes away of the tlb for other reasons.
Quoted 2 lines
-
mmu_notifier_countcould be a non-atomic type (range_end()does not grabmmu_lockbut could).
Yes, I considered this but I preferred not to take the lock in range_end. Not sure if it makes any real difference but this looks nicer to me.
Quoted 3 lines
- why the MMU notifier API pass
mm_structinstead of vma ? As it stands, VM pte aging/swapping/nuking of QEMU non-guest mappings interferes with guest pagefault processing for no reason.
It doesn't interfere with guest pagefault, with the special exception of do_wp_page which is by far not a fast path for KVM unless we truly need the mmu notifier invoked anyway. The memslot <-> vma isn't an identity. Registering in the vma would waste more ram and complicate the unregister event. Initially we considered doing it in the vma but that idea was obsoleted quickly.
Quoted 1 line
- isnt the logic susceptible to
mmu_seqwraparound ? :-)
You mean a false negative because 4G invalidate events happened in between get_user_pages and the spte establishment? I doubt it's a practical matter but I like theoretical safe things, so that would be the best argument to make mmu_notifier_seq 64bit instead of an atomic_t.
Hi Marcelo and everyone,
I cleanedup the mmu notifier kvm patch. I also like math guarantee that there won't be overflow (gfn_to_pfn may be slow compared to a flood of invalidate_page unmapping ptes) so I changed the counter to long and the sequence number to unsigned long. I'm quite sure it was already more than impossible but going 64bit guarantees it +100%. There isn't any significant downside doing so; reads had to be protected anyway so we lose nothing for reads. And the spinlock was already taken by all but range_end and it doesn't change anything to increase the counter inside or outside the spinlock, so the only difference is that I had to take the spinlock in range_end too (which is a fairly slow path and the lock may be already hot because it was taken by range_start before) so won't make much difference and it simplifies the logic a lot too (now all sequence number/counter are under the spinlock and all smb_wmb/rmb goes away).
Given mmu-notifier are in -mm and everyone seem to agrees about them being merged during .27 merge window, I think it'd be fairly safe to apply kvm mmu notifier patch.
I'm testing this on both mmu-notifier capable 2.6.26-rc7, as well as on 2.6.24-r8 which is my "stable" kernel of choice right now without mmu notifiers and it works fine on both.
arch/x86/kvm/Kconfig +1 -0
@@ -21,6 +21,7 @@ config KVM tristate "Kernel-based Virtual Machine (KVM) support" depends on HAVE_KVM select PREEMPT_NOTIFIERS + select MMU_NOTIFIER select ANON_INODES ---help--- Support hosting fully virtualized guest machines using hardware
arch/x86/kvm/mmu.c +96 -0
156 lines not on this page · raw message
arch/x86/kvm/paging_tmpl.h +12 -0
@@ -263,6 +263,8 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *page, pfn = vcpu->arch.update_pte.pfn;if (is_error_pfn (pfn))return ; +if (mmu_notifier_retry (vcpu, vcpu->arch.update_pte.mmu_seq)) +return ;kvm_get_pfn (pfn); mmu_set_spte(vcpu, spte, page->role.access, pte_access, 0, 0, gpte & PT_DIRTY_MASK, NULL, largepage, gpte_to_gfn(gpte),
@@ -380,6 +382,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,int r;pfn_t pfn;int largepage =0 ; +unsigned long mmu_seq;pgprintk ("%s: addr %lx err %x\n" , __func__, addr, error_code);kvm_mmu_audit (vcpu,"pre page fault" );
@@ -413,6 +416,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, largepage =1 ; } } + mmu_seq = vcpu->kvm->mmu_notifier_seq; +/* implicit mb(), we'll read before PT lock is unlocked */ pfn =gfn_to_pfn (vcpu->kvm, walker.gfn);up_read (¤t->mm->mmap_sem);
@@ -424,6 +429,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, }spin_lock (&vcpu->kvm->mmu_lock); +if (mmu_notifier_retry (vcpu, mmu_seq)) + goto out_unlock;kvm_mmu_free_some_pages (vcpu); shadow_pte =FNAME (fetch)(vcpu, addr, &walker, user_fault, write_fault, largepage, &write_pt, pfn);
@@ -439,6 +446,11 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,spin_unlock (&vcpu->kvm->mmu_lock);return write_pt; + +out_unlock: +spin_unlock (&vcpu->kvm->mmu_lock); +kvm_release_pfn_clean (pfn); +return 0 ; }static gpa_t FNAME (gva_to_gpa )(struct kvm_vcpu *vcpu,gva_t vaddr)
include/asm-x86/kvm_host.h +6 -0
@@ -13,6 +13,7 @@#include <linux/types.h> #include <linux/mm.h> +#include <linux/mmu_notifier.h> #include <linux/kvm.h> #include <linux/kvm_para.h>
@@ -257,6 +258,7 @@ struct kvm_vcpu_arch {gfn_t gfn;/* presumed gfn during guest pte update */ pfn_t pfn;/* pfn corresponding to that gfn */ int largepage; +unsigned long mmu_seq; } update_pte;struct i387_fxsave_struct host_fx_image;
@@ -733,4 +735,8 @@ asmlinkage void kvm_handle_fault_on_reboot(void);KVM_EX_ENTRY " 666b, 667b \n\t" \ ".popsection" +#define KVM_ARCH_WANT_MMU_NOTIFIER +int kvm_unmap_hva (struct kvm *kvm,unsigned long hva); +int kvm_age_hva (struct kvm *kvm,unsigned long hva); +#endif
include/linux/kvm_host.h +24 -0
@@ -121,6 +121,12 @@ struct kvm {struct kvm_coalesced_mmio_dev *coalesced_mmio_dev;struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;#endif + +#ifdef KVM_ARCH_WANT_MMU_NOTIFIER +struct mmu_notifier mmu_notifier; +unsigned long mmu_notifier_seq; +long mmu_notifier_count; +#endif };/* The guest did something we don't support. */
@@ -331,4 +337,22 @@ int kvm_trace_ioctl(unsigned int ioctl, unsigned long arg)#define kvm_trace_cleanup () ((void)0)#endif +#ifdef KVM_ARCH_WANT_MMU_NOTIFIER +static inline int mmu_notifier_retry (struct kvm_vcpu *vcpu,unsigned long mmu_seq) +{ +if (unlikely (vcpu->kvm->mmu_notifier_count)) +return 1 ; +/* +* Both reads happen under the mmu_lock and both values are +* modified under mmu_lock, so there's no need of smb_rmb() +* here in between, otherwise mmu_notifier_count should be +* read before mmu_notifier_seq, see +* mmu_notifier_invalidate_range_end write side. +*/ +if (vcpu->kvm->mmu_notifier_seq != mmu_seq) +return 1 ; +return 0 ; +} +#endif +#endif
virt/kvm/kvm_main.c +135 -0
153 lines not on this page · raw message
This is the compat code for kvm-userland:
kernel/include-compat/linux/mmu_notifier.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _LINUX_MMU_NOTIFIER_H +#define _LINUX_MMU_NOTIFIER_H + +struct mmu_notifier {}; + +#endif
And this is the locking change to allow a readonly-browsing of memslots with only mmu_lock hold.
arch/x86/kvm/x86.c +14 -7
@@ -3871,16 +3871,23 @@ int kvm_arch_set_memory_region(struct kvm *kvm,*/ if (!user_alloc) {if (npages && !old.rmap) { +unsigned long userspace_addr; +down_write (¤t->mm->mmap_sem); - memslot->userspace_addr =do_mmap (NULL ,0 , - npages *PAGE_SIZE , -PROT_READ |PROT_WRITE , -MAP_SHARED |MAP_ANONYMOUS , -0 ); + userspace_addr =do_mmap (NULL ,0 , + npages *PAGE_SIZE , +PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANONYMOUS , +0 );up_write (¤t->mm->mmap_sem); -if (IS_ERR ((void *)memslot->userspace_addr)) -return PTR_ERR ((void *)memslot->userspace_addr); +if (IS_ERR ((void *)userspace_addr)) +return PTR_ERR ((void *)userspace_addr); + +/* set userspace_addr atomically for kvm_hva_to_rmapp */ +spin_lock (&kvm->mmu_lock); + memslot->userspace_addr = userspace_addr; +spin_unlock (&kvm->mmu_lock); }else {if (!old.user_alloc && old.rmap) {int ret;
virt/kvm/kvm_main.c +13 -1
@@ -342,7 +342,15 @@ int __kvm_set_memory_region(struct kvm *kvm,memset (new.rmap,0 , npages *sizeof (*new.rmap)); new.user_alloc = user_alloc; - new.userspace_addr = mem->userspace_addr; +/* +* hva_to_rmmap() serialzies with the mmu_lock and to be +* safe it has to ignore memslots with !user_alloc && +* !userspace_addr. +*/ +if (user_alloc) + new.userspace_addr = mem->userspace_addr; +else + new.userspace_addr =0 ; }if (npages && !new.lpage_info) {int largepages = npages /KVM_PAGES_PER_HPAGE ;
@@ -374,14 +382,18 @@ int __kvm_set_memory_region(struct kvm *kvm,memset (new.dirty_bitmap,0 , dirty_bytes); } +spin_lock (&kvm->mmu_lock);if (mem->slot >= kvm->nmemslots) kvm->nmemslots = mem->slot +1 ; *memslot = new; +spin_unlock (&kvm->mmu_lock); r =kvm_arch_set_memory_region (kvm, mem, old, user_alloc);if (r) { +spin_lock (&kvm->mmu_lock); *memslot = old; +spin_unlock (&kvm->mmu_lock); goto out_free; }
Hi Andrea,
arch/x86/kvm/mmu.c static void rmap_write_protect(struct kvm *kvm, u64 gfn) · line 664
Quoted 9 lines · Andrea Arcangeli
arch/x86/kvm/mmu.c +9
-0+static int kvm_unmap_rmapp (struct kvm *kvm,unsigned long *rmapp) +{ +u64 *spte; +int need_tlb_flush =0 ; + +while ((spte =rmap_next (kvm, rmapp,NULL ))) { +BUG_ON (!(*spte &PT_PRESENT_MASK )); +rmap_printk ("kvm_rmap_unmap_hva: spte %p %llx\n" , spte, *spte); +rmap_remove (kvm, spte);
There's a locking issue with rmap_remove. Other than concurrent memslot changes which your "read-only browsing" patch covers, there's concurrent alias changes.
The mmu_shrink path is similarly vulnerable at the moment (see
http://article.gmane.org/gmane.comp.emulators.kvm.devel/19102), we should change memslots and aliases to be protected by mmu_lock.
arch/x86/kvm/mmu.c static void rmap_write_protect(struct kvm *kvm, u64 gfn) · line 669
Quoted 5 lines
arch/x86/kvm/mmu.c +5
-0+set_shadow_pte (spte, shadow_trap_nonpresent_pte); + need_tlb_flush =1 ; + } +return need_tlb_flush; +}
Still need to nuke large page mappings on invalidate_range, right? Presently not an issue for invalidate_page.
Other than that looks much simpler, thanks.
Hi Andrea,
Few comments below.
Quoted 29 lines · Andrea Arcangeli
arch/x86/kvm/mmu.c +28
-0+ } +return need_tlb_flush; +} + +int kvm_unmap_hva (struct kvm *kvm,unsigned long hva) +{ +int i; +int need_tlb_flush =0 ; + +/* +* If mmap_sem isn't taken, we can look the memslots with only +* the mmu_lock by skipping over the slots with userspace_addr == 0. +*/ +for (i =0 ; i < kvm->nmemslots; i++) { +struct kvm_memory_slot *memslot = &kvm->memslots[i]; +unsigned long start = memslot->userspace_addr; +unsigned long end; + +/* mmu_lock protects userspace_addr */ +if (!start) +continue ; +int kvm_age_hva (struct kvm *kvm,unsigned long hva) +{ +int i; +int young =0 ; + +/* +* If mmap_sem isn't taken, we can look the memslots with only
arch/x86/kvm/mmu.c static void rmap_write_protect(struct kvm *kvm, u64 gfn) · line 736
Quoted 10 lines
arch/x86/kvm/mmu.c +10
-0+* the mmu_lock by skipping over the slots with userspace_addr == 0. +*/ +for (i =0 ; i < kvm->nmemslots; i++) { +struct kvm_memory_slot *memslot = &kvm->memslots[i]; +unsigned long start = memslot->userspace_addr; +unsigned long end; + +/* mmu_lock protects userspace_addr */ +if (!start) +continue ;
These two functions share the same memslot iteration code, you could avoid duplication.
arch/x86/kvm/paging_tmpl.h static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *page, · line 268
Quoted 3 lines
arch/x86/kvm/paging_tmpl.h +3
-0+if (unlikely (atomic_read (&vcpu->kvm->mmu_notifier_count))) +return ; +smp_rmb ();
I don't think you need smp_rmb() on x86 since atomic operations serialize. barrier() should suffice.
arch/x86/kvm/mmu.c static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn) · line 1318
Quoted 6 lines
arch/x86/kvm/mmu.c +5
-0spin_lock (&vcpu->kvm->mmu_lock); +if (unlikely (atomic_read (&vcpu->kvm->mmu_notifier_count))) + goto out_unlock; +smp_rmb (); +if (unlikely (atomic_read (&vcpu->kvm->mmu_notifier_seq) != mmu_seq)) + goto out_unlock;
Wrap this sequence in a well documented function?
Quoted 9 lines
virt/kvm/kvm_main.c +9
-0+static void kvm_mmu_notifier_invalidate_range_start (struct mmu_notifier *mn, +struct mm_struct *mm, +unsigned long start, +unsigned long end) +{ +struct kvm *kvm =mmu_notifier_to_kvm (mn); +int need_tlb_flush =0 ; + +/*
virt/kvm/kvm_main.c void kvm_vcpu_uninit(struct kvm_vcpu *vcpu) · line 250
Quoted 10 lines
virt/kvm/kvm_main.c +10
-0+* The count increase must become visible at unlock time as no +* spte can be established without taking the mmu_lock and +* count is also read inside the mmu_lock critical section. +*/ +atomic_inc (&kvm->mmu_notifier_count); + +spin_lock (&kvm->mmu_lock); +for (; start < end; start +=PAGE_SIZE ) + need_tlb_flush |=kvm_unmap_hva (kvm, start); +spin_unlock (&kvm->mmu_lock);
You don't handle large mappings here at all, which means that there might be external mappings even after ->range_start, ->range_end.
This is not a problem now because QEMU kills all the shadow mappings before munmap() on hugetlbfs, but it will be a practical problem if ballooning supports largepages (which will probably happen in the future), or with fancy hugetlb features.
virt/kvm/kvm_main.c void kvm_vcpu_uninit(struct kvm_vcpu *vcpu) · line 289
Quoted 7 lines
virt/kvm/kvm_main.c +7
-0+atomic_inc (&kvm->mmu_notifier_seq); +/* +* The sequence increase must be visible before count +* decrease. The page fault has to read count before sequence +* for this write order to be effective. +*/ +wmb ();
smp_mb_after_atomic_inc ?
virt/kvm/kvm_main.c void kvm_vcpu_uninit(struct kvm_vcpu *vcpu) · line 306
Quoted 13 lines
virt/kvm/kvm_main.c +13
-0+static int kvm_mmu_notifier_clear_flush_young (struct mmu_notifier *mn, +struct mm_struct *mm, +unsigned long address) +{ +struct kvm *kvm =mmu_notifier_to_kvm (mn); +int young; + +spin_lock (&kvm->mmu_lock); + young =kvm_age_hva (kvm, address); +spin_unlock (&kvm->mmu_lock); + +if (young) +kvm_flush_remote_tlbs (kvm);
Is it worth to flush remote TLB's just due to the young bit? Aging can happen often.
- mmu_notifier_count could be a non-atomic type (range_end() does not grab mmu_lock but could).
- why the MMU notifier API pass mm_struct instead of vma ? As it stands, VM pte aging/swapping/nuking of QEMU non-guest mappings interferes with guest pagefault processing for no reason.
- isnt the logic susceptible to mmu_seq wraparound ? :-)