mm: hwpoison: support recovery from HugePage copy-on-write faults
Subsystems (3)
PATCH v2 1/1 mm: hwpoison: support recovery from HugePage copy-on-write faults
copy-on-write of hugetlb user pages with uncorrectable errors will result in a kernel crash. This is because the copy is performed in kernel mode and in general we can not handle accessing memory with such errors while in kernel mode. Commit a873dfe1032a ("mm, hwpoison: try to recover from copy-on write faults") introduced the routine copy_user_highpage_mc() to gracefully handle copying of user pages with uncorrectable errors. However, the separate hugetlb copy-on-write code paths were not modified as part of commit a873dfe1032a.
Modify hugetlb copy-on-write code paths to use copy_mc_user_highpage() so that they can also gracefully handle uncorrectable errors in user pages. This involves changing the hugetlb specific routine copy_user_large_folio() from type void to int so that it can return an error. Modify the hugetlb userfaultfd code in the same way so that it can return -EHWPOISON if it encounters an uncorrectable error.
---
v2:
- Update changelog and code based on newest branch, thanks for Mike's changelog.
include/linux/mm.h | 6 ++--- mm/hugetlb.c | 17 ++++++++++--- mm/memory.c | 59 +++++++++++++++++++++++++++++----------------- 3 files changed, 55 insertions(+), 27 deletions(-)
include/linux/mm.h +3 -3
@@ -3730,9 +3730,9 @@ extern const struct attribute_group memory_failure_attr_group;extern void clear_huge_page (struct page *page,unsigned long addr_hint,unsigned int pages_per_huge_page); -void copy_user_large_folio (struct folio *dst,struct folio *src, -unsigned long addr_hint, -struct vm_area_struct *vma); +int copy_user_large_folio (struct folio *dst,struct folio *src, +unsigned long addr_hint, +struct vm_area_struct *vma);long copy_folio_from_user (struct folio *dst_folio,const void __user *usr_src,bool allow_pagefault);
mm/hugetlb.c +14 -3
@@ -5142,10 +5142,14 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, ret =PTR_ERR (new_folio);break ; } -copy_user_large_folio (new_folio, + ret =copy_user_large_folio (new_folio,page_folio (ptepage), addr, dst_vma);put_page (ptepage); +if (ret) { +folio_put (new_folio); +break ; + }/* Install the new hugetlb folio if src pte stable */ dst_ptl =huge_pte_lock (h, dst, dst_pte);
@@ -5662,7 +5666,10 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, goto out_release_all; } -copy_user_large_folio (new_folio,page_folio (old_page), address, vma); +if (copy_user_large_folio (new_folio,page_folio (old_page), address, vma)) { + ret =VM_FAULT_HWPOISON_LARGE ; + goto out_release_all; + }__folio_mark_uptodate (new_folio); mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, haddr,
@@ -6305,9 +6312,13 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, *foliop =NULL ; goto out; } -copy_user_large_folio (folio, *foliop, dst_addr, dst_vma); + ret =copy_user_large_folio (folio, *foliop, dst_addr, dst_vma);folio_put (*foliop); *foliop =NULL ; +if (ret) { +folio_put (folio); + goto out; + } }/*
mm/memory.c +38 -21
129 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 16 lines · Liu Shixin
copy-on-write of hugetlb user pages with uncorrectable errors will result in a kernel crash. This is because the copy is performed in kernel mode and in general we can not handle accessing memory with such errors while in kernel mode. Commit
a873dfe1032a("mm, hwpoison: try to recover from copy-on write faults") introduced the routinecopy_user_highpage_mc()to gracefully handle copying of user pages with uncorrectable errors. However, the separate hugetlb copy-on-write code paths were not modified as part of commita873dfe1032a.Modify hugetlb copy-on-write code paths to use
copy_mc_user_highpage()so that they can also gracefully handle uncorrectable errors in user pages. This involves changing the hugetlb specific routinecopy_user_large_folio()from type void to int so that it can return an error. Modify the hugetlb userfaultfd code in the same way so that it can return-EHWPOISONif it encounters an uncorrectable error.
Quoted 2 lines
Signed-off-by Liu Shixin <[email protected]>Acked-by Mike Kravetz <[email protected]>
Looks good to me.