diff options
author | James Morse <james.morse@arm.com> | 2017-06-02 17:46:46 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-06-02 18:07:38 -0400 |
commit | 9a291a7c9428155e8e623e4a3989f8be47134df5 (patch) | |
tree | 7cef1f6714c62ccc43431ade14559dd0be585e54 | |
parent | 70feee0e1ef331b22cc51f383d532a0d043fbdcc (diff) |
mm/hugetlb: report -EHWPOISON not -EFAULT when FOLL_HWPOISON is specified
KVM uses get_user_pages() to resolve its stage2 faults. KVM sets the
FOLL_HWPOISON flag causing faultin_page() to return -EHWPOISON when it
finds a VM_FAULT_HWPOISON. KVM handles these hwpoison pages as a
special case. (check_user_page_hwpoison())
When huge pages are involved, this doesn't work so well.
get_user_pages() calls follow_hugetlb_page(), which stops early if it
receives VM_FAULT_HWPOISON from hugetlb_fault(), eventually returning
-EFAULT to the caller. The step to map this to -EHWPOISON based on the
FOLL_ flags is missing. The hwpoison special case is skipped, and
-EFAULT is returned to user-space, causing Qemu or kvmtool to exit.
Instead, move this VM_FAULT_ to errno mapping code into a header file
and use it from faultin_page() and follow_hugetlb_page().
With this, KVM works as expected.
This isn't a problem for arm64 today as we haven't enabled
MEMORY_FAILURE, but I can't see any reason this doesn't happen on x86
too, so I think this should be a fix. This doesn't apply earlier than
stable's v4.11.1 due to all sorts of cleanup.
[james.morse@arm.com: add vm_fault_to_errno() call to faultin_page()]
suggested.
Link: http://lkml.kernel.org/r/20170525171035.16359-1-james.morse@arm.com
[akpm@linux-foundation.org: coding-style fixes]
Link: http://lkml.kernel.org/r/20170524160900.28786-1-james.morse@arm.com
Signed-off-by: James Morse <james.morse@arm.com>
Acked-by: Punit Agrawal <punit.agrawal@arm.com>
Acked-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Cc: <stable@vger.kernel.org> [4.11.1+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/mm.h | 11 | ||||
-rw-r--r-- | mm/gup.c | 20 | ||||
-rw-r--r-- | mm/hugetlb.c | 5 |
3 files changed, 24 insertions, 12 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h index 7cb17c6b97de..b892e95d4929 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
@@ -2327,6 +2327,17 @@ static inline struct page *follow_page(struct vm_area_struct *vma, | |||
2327 | #define FOLL_REMOTE 0x2000 /* we are working on non-current tsk/mm */ | 2327 | #define FOLL_REMOTE 0x2000 /* we are working on non-current tsk/mm */ |
2328 | #define FOLL_COW 0x4000 /* internal GUP flag */ | 2328 | #define FOLL_COW 0x4000 /* internal GUP flag */ |
2329 | 2329 | ||
2330 | static inline int vm_fault_to_errno(int vm_fault, int foll_flags) | ||
2331 | { | ||
2332 | if (vm_fault & VM_FAULT_OOM) | ||
2333 | return -ENOMEM; | ||
2334 | if (vm_fault & (VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE)) | ||
2335 | return (foll_flags & FOLL_HWPOISON) ? -EHWPOISON : -EFAULT; | ||
2336 | if (vm_fault & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV)) | ||
2337 | return -EFAULT; | ||
2338 | return 0; | ||
2339 | } | ||
2340 | |||
2330 | typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr, | 2341 | typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr, |
2331 | void *data); | 2342 | void *data); |
2332 | extern int apply_to_page_range(struct mm_struct *mm, unsigned long address, | 2343 | extern int apply_to_page_range(struct mm_struct *mm, unsigned long address, |
@@ -407,12 +407,10 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma, | |||
407 | 407 | ||
408 | ret = handle_mm_fault(vma, address, fault_flags); | 408 | ret = handle_mm_fault(vma, address, fault_flags); |
409 | if (ret & VM_FAULT_ERROR) { | 409 | if (ret & VM_FAULT_ERROR) { |
410 | if (ret & VM_FAULT_OOM) | 410 | int err = vm_fault_to_errno(ret, *flags); |
411 | return -ENOMEM; | 411 | |
412 | if (ret & (VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE)) | 412 | if (err) |
413 | return *flags & FOLL_HWPOISON ? -EHWPOISON : -EFAULT; | 413 | return err; |
414 | if (ret & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV)) | ||
415 | return -EFAULT; | ||
416 | BUG(); | 414 | BUG(); |
417 | } | 415 | } |
418 | 416 | ||
@@ -723,12 +721,10 @@ retry: | |||
723 | ret = handle_mm_fault(vma, address, fault_flags); | 721 | ret = handle_mm_fault(vma, address, fault_flags); |
724 | major |= ret & VM_FAULT_MAJOR; | 722 | major |= ret & VM_FAULT_MAJOR; |
725 | if (ret & VM_FAULT_ERROR) { | 723 | if (ret & VM_FAULT_ERROR) { |
726 | if (ret & VM_FAULT_OOM) | 724 | int err = vm_fault_to_errno(ret, 0); |
727 | return -ENOMEM; | 725 | |
728 | if (ret & (VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE)) | 726 | if (err) |
729 | return -EHWPOISON; | 727 | return err; |
730 | if (ret & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV)) | ||
731 | return -EFAULT; | ||
732 | BUG(); | 728 | BUG(); |
733 | } | 729 | } |
734 | 730 | ||
diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e5828875f7bb..3eedb187e549 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c | |||
@@ -4170,6 +4170,11 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, | |||
4170 | } | 4170 | } |
4171 | ret = hugetlb_fault(mm, vma, vaddr, fault_flags); | 4171 | ret = hugetlb_fault(mm, vma, vaddr, fault_flags); |
4172 | if (ret & VM_FAULT_ERROR) { | 4172 | if (ret & VM_FAULT_ERROR) { |
4173 | int err = vm_fault_to_errno(ret, flags); | ||
4174 | |||
4175 | if (err) | ||
4176 | return err; | ||
4177 | |||
4173 | remainder = 0; | 4178 | remainder = 0; |
4174 | break; | 4179 | break; |
4175 | } | 4180 | } |