mm/highmem: refuse to copy hwpoisoned folios in the !copy_mc fallbacks
Subsystems (2)
PATCH v3 1/1 mm/highmem: refuse to copy hwpoisoned folios in the !copy_mc fallbacks
The !copy_mc fallbacks of copy_mc_user_highpage() and copy_mc_highpage() return 0 after a plain copy. With PG_hwpoison set while the data stays readable, there is no fault to recover
from: the copy completes, the destination folio carries no poison marker, and the poison is consumed silently.
Check the source page with is_page_hwpoison() in both fallbacks, before the copy, and return PAGE_SIZE, the not-copied-bytes convention of the real copy_mc paths, so the callers take their existing error paths. On archs with copy_mc this code does not compile.
Measured on arm64, where the fallback code compiles: a kernel-space microbenchmark measures 90.00 ns per copy before the patch and 90.71 ns after, 0.8% of the copy itself.
---
Changes since v2:
v2: https://lore.kernel.org/r/[email protected]/
- Keep only the check before the copy (Huang Ying): the copy is back-to-back with the check, so a flag landing within the copy is negligible.
- Add the kernel-space microbenchmark asked for during v2 review (Huang Ying). The bare copy and the copy with the check are interleaved in the same boot, 20 rounds of 200k copies each, with the CPU pinned; the zero-variance baseline bounds the resolution below 1 ns.
include/linux/highmem.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/highmem.h +6 -0
@@ -473,12 +473,18 @@ static inline int copy_mc_highpage(struct page *to, struct page *from)static inline int copy_mc_user_highpage (struct page *to,struct page *from,unsigned long vaddr,struct vm_area_struct *vma) { +/* Don't touch data that is already marked poisoned. */ +if (is_page_hwpoison (from)) +return PAGE_SIZE ;copy_user_highpage (to, from, vaddr, vma);return 0 ; }static inline int copy_mc_highpage (struct page *to,struct page *from) { +/* Don't touch data that is already marked poisoned. */ +if (is_page_hwpoison (from)) +return PAGE_SIZE ;copy_highpage (to, from);return 0 ; }
Signature · 1 line
2.43.7
Quoted 5 lines · Yuanhe Shu
The !copy_mc fallbacks of
copy_mc_user_highpage()andcopy_mc_highpage()return 0 after a plain copy. WithPG_hwpoisonset while the data stays readable, there is no fault to recover
from: the copy completes, the destination folio carries no poison marker, and the poison is consumed silently.
IIUC, this is just RAS debug behavior, not real-world behavior. When poisoned memory is accessed, an MCE/SEA is triggered, and the kernel will panic without a proper copy_mc_* implementation. This patch reduces the probability of a panic, which I think is its main value.
Quoted 10 lines
Check the source page with
is_page_hwpoison()in both fallbacks, before the copy, and returnPAGE_SIZE, the not-copied-bytes convention of the realcopy_mcpaths, so the callers take their existing error paths. On archs withcopy_mcthis code does not compile.Measured on arm64, where the fallback code compiles: a kernel-space microbenchmark measures 90.00 ns per copy before the patch and 90.71 ns after, 0.8% of the copy itself.
Quoted 6 lines
Suggested-by "Huang, Ying" <[email protected]>Suggested-by Kaitao Cheng <[email protected]>Assisted-by LLMSigned-off-by Yuanhe Shu <[email protected]>---
---
Best Regards,
Huang, Ying
David Hildenbrand (Arm)
maintainerOn 11/10/26 12:26, Yuanhe Shu wrote:
While the file touches highmem.h, this really isn't about highmem at all, right?
This really affects any architecture except the ones that define copy_mc_to_kernel (x86+powerpc).
Or am I missing something? Would be good to clarify that.
Quoted 12 lines
The !copy_mc fallbacks of
copy_mc_user_highpage()andcopy_mc_highpage()return 0 after a plain copy. WithPG_hwpoisonset while the data stays readable, there is no fault to recover
from: the copy completes, the destination folio carries no poison marker, and the poison is consumed silently.Check the source page with
is_page_hwpoison()in both fallbacks, before the copy, and returnPAGE_SIZE, the not-copied-bytes convention of the realcopy_mcpaths, so the callers take their existing error paths. On archs withcopy_mcthis code does not compile.
Quoted 3 lines
Measured on arm64, where the fallback code compiles: a kernel-space microbenchmark measures 90.00 ns per copy before the patch and 90.71 ns after, 0.8% of the copy itself.
CCing Catalin. I'm surprised that arm64 cannot recover from a copy from a hwpoisoned page.
Signature · 3 lines
Cheers, David
Quoted 21 lines · David Hildenbrand (Arm)
On 11/10/26 12:26, Yuanhe Shu wrote:
While the file touches
highmem.h, this really isn't about highmem at all, right?This really affects any architecture except the ones that define
copy_mc_to_kernel(x86+powerpc).Or am I missing something? Would be good to clarify that.
Quoted 12 lines
The !copy_mc fallbacks of
copy_mc_user_highpage()andcopy_mc_highpage()return 0 after a plain copy. WithPG_hwpoisonset while the data stays readable, there is no fault to recover
from: the copy completes, the destination folio carries no poison marker, and the poison is consumed silently.Check the source page with
is_page_hwpoison()in both fallbacks, before the copy, and returnPAGE_SIZE, the not-copied-bytes convention of the realcopy_mcpaths, so the callers take their existing error paths. On archs withcopy_mcthis code does not compile.
Quoted 7 lines
Quoted 3 lines
Measured on arm64, where the fallback code compiles: a kernel-space microbenchmark measures 90.00 ns per copy before the patch and 90.71 ns after, 0.8% of the copy itself.
CCing Catalin. I'm surprised that arm64 cannot recover from a copy from a hwpoisoned page.
+1
We have been trying to support this feature in the mainline for over three years. This year, Alibaba took over and released new v14 and v15[1].
In server scenarios, COPY_MC is very useful because it helps avoid unnecessary panic behavior in the system. We would like to receive some guidance to accelerate the integration of this feature into the mainline.
CCed Ruidong/Tiangen
[1] v15 https://lore.kernel.org/linux-arm-kernel/[email protected]/
Hi Kefeng, David, Catalin, Tiangen, and Ying,
Thank you for raising this and for the continued work and review on arm64 COPY_MC support.
I would like to provide an update on our side. Ruidong has left Alibaba and is no longer focusing on kernel development. I will be taking over the development and upstreaming of the arm64 ARCH_HAS_COPY_MC series, building on Tiangen's and Ruidong's work.
This work is already underway. I will follow up on the feedback from previous revisions and plan to submit an updated series in the near future.
I have also added my colleagues Shuai Xue and Baolin Wang to Cc. Please keep me copied on further discussions of this series. Any additional guidance on outstanding issues or priorities for the next revision would be appreciated.
Best regards,
Weilin
Quoted 6 lines · David Hildenbrand
On 11/10/26 12:26, Yuanhe Shu wrote:
While the file touches
highmem.h, this really isn't about highmem at all, right?This really affects any architecture except the ones that define
copy_mc_to_kernel(x86+powerpc).
I think is_page_hwpoison() is compiled out unless CONFIG_MEMORY_FAILURE is enabled. Only arm64, parisc, powerpc and x86 enable it with the latter two having proper mc support.
Quoted 12 lines
Quoted 12 lines
The !copy_mc fallbacks of
copy_mc_user_highpage()andcopy_mc_highpage()return 0 after a plain copy. WithPG_hwpoisonset while the data stays readable, there is no fault to recover
from: the copy completes, the destination folio carries no poison marker, and the poison is consumed silently.Check the source page with
is_page_hwpoison()in both fallbacks, before the copy, and returnPAGE_SIZE, the not-copied-bytes convention of the realcopy_mcpaths, so the callers take their existing error paths. On archs withcopy_mcthis code does not compile.
Quoted 6 lines
Quoted 3 lines
Measured on arm64, where the fallback code compiles: a kernel-space microbenchmark measures 90.00 ns per copy before the patch and 90.71 ns after, 0.8% of the copy itself.
CCing Catalin. I'm surprised that arm64 cannot recover from a copy from a hwpoisoned page.
Yeah, it's been around for some time. Lack of review cycles on our side as well.
Signature · 1 line
Catalin
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mm/highmem: missing is_page_hwpoison() check in copy_mc_to_kernel branch --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mm/highmem: missing is_page_hwpoison() check in copy_mc_to_kernel branch
--
commit 5b18d6f721e579b691687c6c8c6355f1e1a00b17
Author: Yuanhe Shu <[email protected]>
mm/highmem: refuse to copy hwpoisoned folios in the !copy_mc fallbacks
This commit checks is_page_hwpoison(from) in the !copy_mc_to_kernel fallback implementations of copy_mc_user_highpage() and copy_mc_highpage() and returns PAGE_SIZE when the source page is marked hwpoisoned.
Quoted 13 lines
include/linux/highmem.h +3
-0@@ -473,12 +473,18 @@ static inline int copy_mc_highpage(struct page *to, struct page *from)static inline int copy_mc_user_highpage (struct page *to,struct page *from,unsigned long vaddr,struct vm_area_struct *vma) { +/* Don't touch data that is already marked poisoned. */ +if (is_page_hwpoison (from)) +return PAGE_SIZE ;copy_user_highpage (to, from, vaddr, vma);return 0 ;
include/linux/highmem.h static inline int copy_mc_highpage(struct page *to, struct page *from) · line 490
Quoted 10 lines
include/linux/highmem.h +3
-0}static inline int copy_mc_highpage (struct page *to,struct page *from) { +/* Don't touch data that is already marked poisoned. */ +if (is_page_hwpoison (from)) +return PAGE_SIZE ;copy_highpage (to, from);return 0 ; }
[Severity: Medium]
Should the #ifdef copy_mc_to_kernel implementations of copy_mc_user_highpage() and copy_mc_highpage() also check is_page_hwpoison(from) before mapping and copying the source page?
copy_mc_to_kernel() only catches hardware exceptions raised during the memory read and never inspects page flags. On architectures that define copy_mc_to_kernel, copying a page with PG_hwpoison already set while the underlying memory remains readable (for example, an uncorrupted subpage of a poisoned hugetlb folio, an asynchronous patrol-scrubber notification, or on x86 when copy_mc_to_kernel() falls back to plain memcpy()) still succeeds and returns 0, silently consuming the poison and leaving the destination folio without PG_hwpoison. When the source page does have physical DRAM poison, reading it also triggers an avoidable kernel-mode machine check and queues a redundant memory_failure_queue() work item.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
David Hildenbrand (Arm)
maintainerQuoted 46 lines · On 11/11/26 12:27, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mm/highmem: missingis_page_hwpoison()check incopy_mc_to_kernelbranch
--commit
5b18d6f721e579b691687c6c8c6355f1e1a00b17
Author: Yuanhe Shu <[email protected]>mm/highmem: refuse to copy hwpoisoned folios in the !copy_mc fallbacks
This commit checks
is_page_hwpoison(from)in the !copy_mc_to_kernel fallback implementations ofcopy_mc_user_highpage()andcopy_mc_highpage()and returnsPAGE_SIZEwhen the source page is marked hwpoisoned.Quoted 13 lines
include/linux/highmem.h +3
-0@@ -473,12 +473,18 @@ static inline int copy_mc_highpage(struct page *to, struct page *from)static inline int copy_mc_user_highpage (struct page *to,struct page *from,unsigned long vaddr,struct vm_area_struct *vma) { +/* Don't touch data that is already marked poisoned. */ +if (is_page_hwpoison (from)) +return PAGE_SIZE ;copy_user_highpage (to, from, vaddr, vma);return 0 ;include/linux/highmem.h static inline int copy_mc_highpage(struct page *to, struct page *from) · line 490
Quoted 10 lines
include/linux/highmem.h +3
-0}static inline int copy_mc_highpage (struct page *to,struct page *from) { +/* Don't touch data that is already marked poisoned. */ +if (is_page_hwpoison (from)) +return PAGE_SIZE ;copy_highpage (to, from);return 0 ; }[Severity: Medium]
Should the #ifdefcopy_mc_to_kernelimplementations ofcopy_mc_user_highpage()andcopy_mc_highpage()also checkis_page_hwpoison(from)before mapping and copying the source page?
Quoted 2 lines
copy_mc_to_kernel()only catches hardware exceptions raised during the memory read and never inspects page flags.
I'd leave that out for now. This commit is explicitly about fallbacks.
Signature · 3 lines
Cheers, David
Quoted 16 lines · Yuanhe Shu
The !copy_mc fallbacks of
copy_mc_user_highpage()andcopy_mc_highpage()return 0 after a plain copy. WithPG_hwpoisonset while the data stays readable, there is no fault to recover
from: the copy completes, the destination folio carries no poison marker, and the poison is consumed silently.Check the source page with
is_page_hwpoison()in both fallbacks, before the copy, and returnPAGE_SIZE, the not-copied-bytes convention of the realcopy_mcpaths, so the callers take their existing error paths. On archs withcopy_mcthis code does not compile.Measured on arm64, where the fallback code compiles: a kernel-space microbenchmark measures 90.00 ns per copy before the patch and 90.71 ns after, 0.8% of the copy itself.
Quoted 6 lines
Suggested-by "Huang, Ying" <[email protected]>Suggested-by Kaitao Cheng <[email protected]>Assisted-by LLMSigned-off-by Yuanhe Shu <[email protected]>---
Queueing this, hoping for even more review :)
Signature · 3 lines
Cheers, David
Quoted 6 lines · Yuanhe Shu
The !copy_mc fallbacks of
copy_mc_user_highpage()andcopy_mc_highpage()return 0 after a plain copy. WithPG_hwpoisonset while the data stays readable, there is no fault to recover
from: the copy completes, the destination folio carries no poison marker, and the poison is consumed silently.
Quoted 7 lines
Check the source page with
is_page_hwpoison()in both fallbacks, before the copy, and returnPAGE_SIZE, the not-copied-bytes convention of the realcopy_mcpaths, so the callers take their existing error paths. On archs withcopy_mcthis code does not compile.[...]
Applied, thanks!
tree: mm/core.git
branch: core-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even though the patches have already been applied. If possible, patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. Further, this is not a guarantee that the patches will go upstream. If in doubt, please check the listed branch.
[1/1] mm/highmem: refuse to copy hwpoisoned folios in the !copy_mc fallbacks
https://git.kernel.org/mm/core/c/35c0195e
Signature · 3 lines
Cheers, David
Quoted 12 lines · Yuanhe Shu
The !copy_mc fallbacks of
copy_mc_user_highpage()andcopy_mc_highpage()return 0 after a plain copy. WithPG_hwpoisonset while the data stays readable, there is no fault to recover
from: the copy completes, the destination folio carries no poison marker, and the poison is consumed silently.Check the source page with
is_page_hwpoison()in both fallbacks, before the copy, and returnPAGE_SIZE, the not-copied-bytes convention of the realcopy_mcpaths, so the callers take their existing error paths. On archs withcopy_mcthis code does not compile.
Quoted 8 lines
Measured on arm64, where the fallback code compiles: a kernel-space microbenchmark measures 90.00 ns per copy before the patch and 90.71 ns after, 0.8% of the copy itself.
Suggested-by "Huang, Ying" <[email protected]>Suggested-by Kaitao Cheng <[email protected]>Assisted-by LLMSigned-off-by Yuanhe Shu <[email protected]>
Thanks.
.