KVM: attempt async pf only if address is contained in vma
Only attempt async pagefault if address is contained within vma.
virt/kvm/kvm_main.c +3 -2
@@ -996,8 +996,9 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,if (vma ==NULL || addr < vma->vm_start || !(vma->vm_flags &VM_PFNMAP )) { -if (async && !(vma->vm_flags &VM_PFNMAP ) && - (vma->vm_flags &VM_WRITE )) +if (async && vma && !(vma->vm_flags &VM_PFNMAP ) && + (vma->vm_flags &VM_WRITE ) && + addr >= vma->vm_start) *async = true;up_read (¤t->mm->mmap_sem); return_fault_page:
Quoted 10 lines · Marcelo Tosatti
Only attempt async pagefault if address is contained within vma.
Signed-off-by Marcelo Tosatti <[email protected]>virt/kvm/kvm_main.c +0
-0
virt/kvm/kvm_main.c static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic, · line 999
Quoted 6 lines
virt/kvm/kvm_main.c +1
-2@@ -996,8 +996,9 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,if (vma ==NULL || addr < vma->vm_start || !(vma->vm_flags &VM_PFNMAP )) { -if (async && !(vma->vm_flags &VM_PFNMAP ) && - (vma->vm_flags &VM_WRITE )) + if (async && vma && !(vma->vm_flags & VM_PFNMAP) &&
actually we should check for addr < vma->vm_start here too. find_vma() is very strange function.
What about patch below (only compile tested for now)?
virt/kvm/kvm_main.c +17 -13
@@ -954,6 +954,12 @@ unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn) }EXPORT_SYMBOL_GPL (gfn_to_hva); +static pfn_t get_fault_pfn (void ) +{ +get_page (fault_page); +return fault_pfn; +} +static pfn_t hva_to_pfn (struct kvm *kvm,unsigned long addr,bool atomic,bool *async) {
@@ -983,7 +989,7 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,struct vm_area_struct *vma;if (atomic) - goto return_fault_page; +return get_fault_pfn ();down_read (¤t->mm->mmap_sem);if (is_hwpoison_address (addr)) {
@@ -992,22 +998,20 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,return page_to_pfn (hwpoison_page); } - vma =find_vma (current->mm, addr); + vma =find_vma_intersection (current->mm, addr, addr+1 ); -if (vma ==NULL || addr < vma->vm_start || - !(vma->vm_flags &VM_PFNMAP )) { -if (async && !(vma->vm_flags &VM_PFNMAP ) && - (vma->vm_flags &VM_WRITE )) +if (vma ==NULL ) +return get_fault_pfn (); +if ((vma->vm_flags &VM_PFNMAP )) { + pfn = ((addr - vma->vm_start) >>PAGE_SHIFT ) + + vma->vm_pgoff; +BUG_ON (!kvm_is_mmio_pfn (pfn)); + }else { +if (async && (vma->vm_flags &VM_WRITE )) *async = true; -up_read (¤t->mm->mmap_sem); -return_fault_page: -get_page (fault_page); -return page_to_pfn (fault_page); + pfn =get_fault_pfn (); } - - pfn = ((addr - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff;up_read (¤t->mm->mmap_sem); -BUG_ON (!kvm_is_mmio_pfn (pfn)); }else pfn =page_to_pfn (page[0 ]);
--
Gleb.
Quoted 20 lines · Gleb Natapov
Quoted 10 lines · Marcelo Tosatti
Only attempt async pagefault if address is contained within vma.
Signed-off-by Marcelo Tosatti <[email protected]>virt/kvm/kvm_main.c +0
-0virt/kvm/kvm_main.c static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic, · line 999
Quoted 6 lines
virt/kvm/kvm_main.c +1
-2@@ -996,8 +996,9 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,if (vma ==NULL || addr < vma->vm_start || !(vma->vm_flags &VM_PFNMAP )) { -if (async && !(vma->vm_flags &VM_PFNMAP ) && - (vma->vm_flags &VM_WRITE )) + if (async && vma && !(vma->vm_flags & VM_PFNMAP) &&actually we should check for addr <
vma->vm_starthere too.find_vma()is very strange function.
Quoted 2 lines
What about patch below (only compile tested for now)?
Works for me.
Quoted 60 lines
virt/kvm/kvm_main.c +17
-14@@ -954,6 +954,12 @@ unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn) }EXPORT_SYMBOL_GPL (gfn_to_hva); +static pfn_t get_fault_pfn (void ) +{ +get_page (fault_page); +return fault_pfn; +} +static pfn_t hva_to_pfn (struct kvm *kvm,unsigned long addr,bool atomic,bool *async) {@@ -983,7 +989,7 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,struct vm_area_struct *vma;if (atomic) - goto return_fault_page; +return get_fault_pfn ();down_read (¤t->mm->mmap_sem);if (is_hwpoison_address (addr)) {@@ -992,22 +998,20 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,return page_to_pfn (hwpoison_page); } - vma =find_vma (current->mm, addr); + vma =find_vma_intersection (current->mm, addr, addr+1 ); -if (vma ==NULL || addr < vma->vm_start || - !(vma->vm_flags &VM_PFNMAP )) { -if (async && !(vma->vm_flags &VM_PFNMAP ) && - (vma->vm_flags &VM_WRITE )) +if (vma ==NULL ) +return get_fault_pfn (); +if ((vma->vm_flags &VM_PFNMAP )) { + pfn = ((addr - vma->vm_start) >>PAGE_SHIFT ) + + vma->vm_pgoff; +BUG_ON (!kvm_is_mmio_pfn (pfn)); + }else { +if (async && (vma->vm_flags &VM_WRITE )) *async = true; -up_read (¤t->mm->mmap_sem); -return_fault_page: -get_page (fault_page); -return page_to_pfn (fault_page); + pfn =get_fault_pfn (); } - - pfn = ((addr - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff;up_read (¤t->mm->mmap_sem); -BUG_ON (!kvm_is_mmio_pfn (pfn)); }else pfn =page_to_pfn (page[0 ]); --
Quoted 5 lines
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Gleb.
Quoted 21 lines · Gleb Natapov
Quoted 20 lines · Gleb Natapov
Quoted 10 lines · Marcelo Tosatti
Only attempt async pagefault if address is contained within vma.
Signed-off-by Marcelo Tosatti <[email protected]>virt/kvm/kvm_main.c +0
-0virt/kvm/kvm_main.c static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic, · line 999
Quoted 6 lines
virt/kvm/kvm_main.c +1
-2@@ -996,8 +996,9 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,if (vma ==NULL || addr < vma->vm_start || !(vma->vm_flags &VM_PFNMAP )) { -if (async && !(vma->vm_flags &VM_PFNMAP ) && - (vma->vm_flags &VM_WRITE )) + if (async && vma && !(vma->vm_flags & VM_PFNMAP) &&actually we should check for addr <
vma->vm_starthere too.find_vma()is very strange function.
Quoted 3 lines
Quoted 2 lines
What about patch below (only compile tested for now)?
Works for me.
Thats much nicer.
Quoted 9 lines
virt/kvm/kvm_main.c static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic, · line 1004
Quoted 9 lines
virt/kvm/kvm_main.c +3
-5- vma =find_vma (current->mm, addr); + vma =find_vma_intersection (current->mm, addr, addr+1 ); -if (vma ==NULL || addr < vma->vm_start || - !(vma->vm_flags &VM_PFNMAP )) { -if (async && !(vma->vm_flags &VM_PFNMAP ) && - (vma->vm_flags &VM_WRITE )) +if (vma ==NULL ) +return get_fault_pfn ();
up_read(mmap_sem)
Quoted 31 lines · Marcelo Tosatti
Quoted 21 lines · Gleb Natapov
Quoted 20 lines · Gleb Natapov
Quoted 10 lines · Marcelo Tosatti
Only attempt async pagefault if address is contained within vma.
Signed-off-by Marcelo Tosatti <[email protected]>virt/kvm/kvm_main.c +0
-0virt/kvm/kvm_main.c static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic, · line 999
Quoted 6 lines
virt/kvm/kvm_main.c +1
-2@@ -996,8 +996,9 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,if (vma ==NULL || addr < vma->vm_start || !(vma->vm_flags &VM_PFNMAP )) { -if (async && !(vma->vm_flags &VM_PFNMAP ) && - (vma->vm_flags &VM_WRITE )) + if (async && vma && !(vma->vm_flags & VM_PFNMAP) &&actually we should check for addr <
vma->vm_starthere too.find_vma()is very strange function.Quoted 3 lines
Quoted 2 lines
What about patch below (only compile tested for now)?
Works for me.
Thats much nicer.
Quoted 3 lines
Quoted 3 lines
virt/kvm/kvm_main.c +1
-1- vma =find_vma (current->mm, addr); + vma =find_vma_intersection (current->mm, addr, addr+1 );
Quoted 8 lines
Quoted 6 lines
virt/kvm/kvm_main.c static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic, · line 1004
Quoted 6 lines
virt/kvm/kvm_main.c +2
-4-if (vma ==NULL || addr < vma->vm_start || - !(vma->vm_flags &VM_PFNMAP )) { -if (async && !(vma->vm_flags &VM_PFNMAP ) && - (vma->vm_flags &VM_WRITE )) +if (vma ==NULL ) +return get_fault_pfn ();
up_read(mmap_sem)
Oops.
Will resent with fix and all.
--
Gleb.