hugepage: fix broken check for offset alignment in hugepage mappings
For hugepage mappings, the file offset, like the address and size, needs to be aligned to the size of a hugepage. In commit68589bc353
, the check for this was moved into prepare_hugepage_range() along with the address and size checks. But since BenH's rework of the get_unmapped_area() paths leading up to commit4b1d89290b
, prepare_hugepage_range() is only called for MAP_FIXED mappings, not for other mappings. This means we're no longer ever checking for an aligned offset - I've confirmed that mmap() will (apparently) succeed with a misaligned offset on both powerpc and i386 at least. This patch restores the check, removing it from prepare_hugepage_range() and putting it back into hugetlbfs_file_mmap(). I'm putting it there, rather than in the get_unmapped_area() path so it only needs to go in one place, than separately in the half-dozen or so arch-specific implementations of hugetlb_get_unmapped_area(). Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Cc: Adam Litke <agl@us.ibm.com> Cc: Andi Kleen <ak@suse.de> Cc: "David S. Miller" <davem@davemloft.net> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
4a58448b0a
commit
dec4ad86c2
@@ -82,14 +82,19 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* vma alignment has already been checked by prepare_hugepage_range.
|
||||
* If you add any error returns here, do so after setting VM_HUGETLB,
|
||||
* so is_vm_hugetlb_page tests below unmap_region go the right way
|
||||
* when do_mmap_pgoff unwinds (may be important on powerpc and ia64).
|
||||
* vma address alignment (but not the pgoff alignment) has
|
||||
* already been checked by prepare_hugepage_range. If you add
|
||||
* any error returns here, do so after setting VM_HUGETLB, so
|
||||
* is_vm_hugetlb_page tests below unmap_region go the right
|
||||
* way when do_mmap_pgoff unwinds (may be important on powerpc
|
||||
* and ia64).
|
||||
*/
|
||||
vma->vm_flags |= VM_HUGETLB | VM_RESERVED;
|
||||
vma->vm_ops = &hugetlb_vm_ops;
|
||||
|
||||
if (vma->vm_pgoff & ~(HPAGE_MASK >> PAGE_SHIFT))
|
||||
return -EINVAL;
|
||||
|
||||
vma_len = (loff_t)(vma->vm_end - vma->vm_start);
|
||||
|
||||
mutex_lock(&inode->i_mutex);
|
||||
@@ -132,7 +137,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
|
||||
return -ENOMEM;
|
||||
|
||||
if (flags & MAP_FIXED) {
|
||||
if (prepare_hugepage_range(addr, len, pgoff))
|
||||
if (prepare_hugepage_range(addr, len))
|
||||
return -EINVAL;
|
||||
return addr;
|
||||
}
|
||||
|
Reference in New Issue
Block a user