Commit 8030089f authored by Gleb Natapov's avatar Gleb Natapov Committed by Avi Kivity

KVM: improve hva_to_pfn() readability

Improve vma handling code readability in hva_to_pfn() and fix
async pf handling code to properly check vma returned by find_vma().
Signed-off-by: default avatarGleb Natapov <gleb@redhat.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent fc5f06fa
...@@ -952,6 +952,12 @@ unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn) ...@@ -952,6 +952,12 @@ unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn)
} }
EXPORT_SYMBOL_GPL(gfn_to_hva); 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, static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,
bool *async) bool *async)
{ {
...@@ -974,7 +980,7 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic, ...@@ -974,7 +980,7 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,
struct vm_area_struct *vma; struct vm_area_struct *vma;
if (atomic) if (atomic)
goto return_fault_page; return get_fault_pfn();
down_read(&current->mm->mmap_sem); down_read(&current->mm->mmap_sem);
if (is_hwpoison_address(addr)) { if (is_hwpoison_address(addr)) {
...@@ -983,22 +989,20 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic, ...@@ -983,22 +989,20 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,
return page_to_pfn(hwpoison_page); 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 || if (vma == NULL)
!(vma->vm_flags & VM_PFNMAP)) { pfn = get_fault_pfn();
if (async && !(vma->vm_flags & VM_PFNMAP) && else if ((vma->vm_flags & VM_PFNMAP)) {
(vma->vm_flags & VM_WRITE)) 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; *async = true;
up_read(&current->mm->mmap_sem); pfn = get_fault_pfn();
return_fault_page:
get_page(fault_page);
return page_to_pfn(fault_page);
} }
pfn = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
up_read(&current->mm->mmap_sem); up_read(&current->mm->mmap_sem);
BUG_ON(!kvm_is_mmio_pfn(pfn));
} else } else
pfn = page_to_pfn(page[0]); pfn = page_to_pfn(page[0]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment