Commit 934692a4 authored by Jiaqi Yan's avatar Jiaqi Yan Committed by Wupeng Ma
Browse files

mm/hwpoison: introduce copy_mc_highpage

mainline inclusion
from mainline-v5.4-rc1
commit 6efc7afb
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8K5CO

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6efc7afb5cc98488410d44695685d003d832534d

--------------------------------

Similar to how copy_mc_user_highpage is implemented for copy_user_highpage
on #MC supported architecture, introduce the #MC handled version of
copy_highpage.

This helper has immediate usage when khugepaged wants to copy file-backed
memory pages and tolerate #MC.

Link: https://lkml.kernel.org/r/20230329151121.949896-3-jiaqiyan@google.com


Signed-off-by: default avatarJiaqi Yan <jiaqiyan@google.com>
Reviewed-by: default avatarYang Shi <shy828301@gmail.com>
Cc: David Stevens <stevensd@chromium.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Tong Tiangen <tongtiangen@huawei.com>
Cc: Tony Luck <tony.luck@intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
(wupeng: backport copy_mc_highpage for this patch)
Signed-off-by: default avatarMa Wupeng <mawupeng1@huawei.com>
parent c7295dc9
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -396,4 +396,32 @@ static inline void memcpy_to_page(struct page *page, size_t offset,
	kunmap_atomic(to);
}

#ifdef copy_mc_to_kernel
/*
 * If architecture supports machine check exception handling, define the
 * #MC versions of copy_user_highpage and copy_highpage. They copy a memory
 * page with #MC in source page (@from) handled, and return the number
 * of bytes not copied if there was a #MC, otherwise 0 for success.
 */
static inline int copy_mc_highpage(struct page *to, struct page *from)
{
	char *vfrom, *vto;
	int ret;

	vfrom = kmap_atomic(from);
	vto = kmap_atomic(to);
	ret = copy_mc_to_kernel(vto, vfrom, PAGE_SIZE);
	kunmap_atomic(vto);
	kunmap_atomic(vfrom);

	return ret;
}
#else
static inline int copy_mc_highpage(struct page *to, struct page *from)
{
	copy_highpage(to, from);
	return 0;
}
#endif

#endif /* _LINUX_HIGHMEM_H */