lkml.org 
[lkml]   [2021]   [Jun]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 3/7] mm/thp: fix vma_address() if virtual address below file offset
On Thu, Jun 03, 2021 at 02:40:30PM -0700, Hugh Dickins wrote:
> static inline unsigned long
> -__vma_address(struct page *page, struct vm_area_struct *vma)
> +vma_address(struct page *page, struct vm_area_struct *vma)
> {
> - pgoff_t pgoff = page_to_pgoff(page);
> - return vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
> + pgoff_t pgoff;
> + unsigned long address;
> +
> + VM_BUG_ON_PAGE(PageKsm(page), page); /* KSM page->index unusable */
> + pgoff = page_to_pgoff(page);
> + if (pgoff >= vma->vm_pgoff) {
> + address = vma->vm_start +
> + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
> + /* Check for address beyond vma (or wrapped through 0?) */
> + if (address < vma->vm_start || address >= vma->vm_end)
> + address = -EFAULT;
> + } else if (PageHead(page) &&
> + pgoff + compound_nr(page) > vma->vm_pgoff) {

I think on 32-bit, you need ...

pgoff + compound_nr(page) - 1 >= vma->vm_pgoff

... right?

> + address = vma->vm_start;
> + } else {
> + address = -EFAULT;
> + }
> + return address;
> }

\
 
 \ /
  Last update: 2021-06-04 19:38    [W:0.151 / U:0.408 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site