aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jordan <daniel.m.jordan@oracle.com>2017-08-02 16:31:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-08-02 19:34:46 -0400
commit2be7cfed995e25de1ffaffe14cc065b7ffb528e0 (patch)
treeacd9b18af66852f0b6ee0f3a807e21d0d5b184de
parent4d3f5d04d69e9479a3df88ceb0e2cd8188a49366 (diff)
mm/hugetlb.c: __get_user_pages ignores certain follow_hugetlb_page errors
Commit 9a291a7c9428 ("mm/hugetlb: report -EHWPOISON not -EFAULT when FOLL_HWPOISON is specified") causes __get_user_pages to ignore certain errors from follow_hugetlb_page. After such error, __get_user_pages subsequently calls faultin_page on the same VMA and start address that follow_hugetlb_page failed on instead of returning the error immediately as it should. In follow_hugetlb_page, when hugetlb_fault returns a value covered under VM_FAULT_ERROR, follow_hugetlb_page returns it without setting nr_pages to 0 as __get_user_pages expects in this case, which causes the following to happen in __get_user_pages: the "while (nr_pages)" check succeeds, we skip the "if (!vma..." check because we got a VMA the last time around, we find no page with follow_page_mask, and we call faultin_page, which calls hugetlb_fault for the second time. This issue also slightly changes how __get_user_pages works. Before, it only returned error if it had made no progress (i = 0). But now, follow_hugetlb_page can clobber "i" with an error code since its new return path doesn't check for progress. So if "i" is nonzero before a failing call to follow_hugetlb_page, that indication of progress is lost and __get_user_pages can return error even if some pages were successfully pinned. To fix this, change follow_hugetlb_page so that it updates nr_pages, allowing __get_user_pages to fail immediately and restoring the "error only if no progress" behavior to __get_user_pages. Tested that __get_user_pages returns when expected on error from hugetlb_fault in follow_hugetlb_page. Fixes: 9a291a7c9428 ("mm/hugetlb: report -EHWPOISON not -EFAULT when FOLL_HWPOISON is specified") Link: http://lkml.kernel.org/r/1500406795-58462-1-git-send-email-daniel.m.jordan@oracle.com Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com> Acked-by: Punit Agrawal <punit.agrawal@arm.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com> Cc: James Morse <james.morse@arm.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: zhong jiang <zhongjiang@huawei.com> Cc: <stable@vger.kernel.org> [4.12.x] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/hugetlb.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index bc48ee783dd9..a1a0ac0ad6f6 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -4078,6 +4078,7 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
4078 unsigned long vaddr = *position; 4078 unsigned long vaddr = *position;
4079 unsigned long remainder = *nr_pages; 4079 unsigned long remainder = *nr_pages;
4080 struct hstate *h = hstate_vma(vma); 4080 struct hstate *h = hstate_vma(vma);
4081 int err = -EFAULT;
4081 4082
4082 while (vaddr < vma->vm_end && remainder) { 4083 while (vaddr < vma->vm_end && remainder) {
4083 pte_t *pte; 4084 pte_t *pte;
@@ -4154,11 +4155,7 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
4154 } 4155 }
4155 ret = hugetlb_fault(mm, vma, vaddr, fault_flags); 4156 ret = hugetlb_fault(mm, vma, vaddr, fault_flags);
4156 if (ret & VM_FAULT_ERROR) { 4157 if (ret & VM_FAULT_ERROR) {
4157 int err = vm_fault_to_errno(ret, flags); 4158 err = vm_fault_to_errno(ret, flags);
4158
4159 if (err)
4160 return err;
4161
4162 remainder = 0; 4159 remainder = 0;
4163 break; 4160 break;
4164 } 4161 }
@@ -4213,7 +4210,7 @@ same_page:
4213 */ 4210 */
4214 *position = vaddr; 4211 *position = vaddr;
4215 4212
4216 return i ? i : -EFAULT; 4213 return i ? i : err;
4217} 4214}
4218 4215
4219#ifndef __HAVE_ARCH_FLUSH_HUGETLB_TLB_RANGE 4216#ifndef __HAVE_ARCH_FLUSH_HUGETLB_TLB_RANGE