From: "Garg, Shivank" <shivankg@amd.com>
To: "tejavojjala@google.com" <tejavojjala@google.com>,
"Rao, Bharata Bhasker" <bharata@amd.com>,
"rppt@kernel.org" <rppt@kernel.org>,
"david.laight.linux@gmail.com" <david.laight.linux@gmail.com>,
"ankur.a.arora@oracle.com" <ankur.a.arora@oracle.com>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"vbabka@kernel.org" <vbabka@kernel.org>,
"ying.huang@linux.alibaba.com" <ying.huang@linux.alibaba.com>,
"david@kernel.org" <david@kernel.org>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"mingo@redhat.com" <mingo@redhat.com>,
"surenb@google.com" <surenb@google.com>,
"sashiko-reviews@lists.linux.dev"
<sashiko-reviews@lists.linux.dev>,
"xiangzao@linux.alibaba.com" <xiangzao@linux.alibaba.com>,
"peterz@infradead.org" <peterz@infradead.org>,
"nhuhuan@google.com" <nhuhuan@google.com>,
"Salunke, Hrushikesh" <Hrushikesh.Salunke@amd.com>,
"tglx@kernel.org" <tglx@kernel.org>,
"liam@infradead.org" <liam@infradead.org>,
"hpa@zytor.com" <hpa@zytor.com>,
"mhocko@suse.com" <mhocko@suse.com>,
"bp@alien8.de" <bp@alien8.de>, "ljs@kernel.org" <ljs@kernel.org>,
"rientjes@google.com" <rientjes@google.com>,
"pfalcato@suse.de" <pfalcato@suse.de>,
"torvalds@linuxfoundation.org" <torvalds@linuxfoundation.org>,
"kaitao.cheng@linux.dev" <kaitao.cheng@linux.dev>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
"x86@kernel.org" <x86@kernel.org>
Subject: Re: [PATCH v3] mm: introduce copy_mc_highpages() and batch copy in folio_mc_copy()
Date: Tue, 17 Nov 2026 05:27:36 +0000 [thread overview]
Message-ID: <2dd5ed03f167563d8b37a4e1ae4b17d2d8aa31a2.camel@amd.com> (raw)
In-Reply-To: <sashiko-outbox-214828@kernel.org>
On Sat, 2026-11-14 at 17:12 +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found no new issues
> in this patch, but noticed 1 related pre-existing issue it does not
> introduce:
> - [Critical] mm: missing hwpoison check in copy_mc_user_highpage() and
> copy_mc_highpage() [1]
> --
>
> commit fae95970ccf2607d670f06862e40d3ba9313200a
> Author: Shivank Garg <shivankg@amd.com>
>
> mm: introduce copy_mc_highpages() and batch copy in folio_mc_copy()
>
> This commit introduces copy_mc_highpages() to copy page ranges with a
> single copy_mc_to_kernel() call when possible and updates folio_mc_copy()
> to use it.
>
> > diff --git a/include/linux/highmem.h b/include/linux/highmem.h
> > index d7aac9de1c8a4..a79e9d68359c8 100644
> > --- a/include/linux/highmem.h
> > +++ b/include/linux/highmem.h
> > @@ -484,6 +484,57 @@ static inline int copy_mc_highpage(struct page *to, struct page *from)
> > }
> > #endif
> >
> > +/**
> > + * copy_mc_highpages() - copy a page range with machine check handling
> > + * @to: first destination page
> > + * @from: first source page
> > + * @nr_pages: number of pages
> > + *
> > + * Range variant of copy_mc_highpage(). On a machine check, the poisoned
> > + * source page is queued for memory_failure().
> > + *
> > + * Context: Process context. May sleep.
> > + * Return: 0 on success, -EHWPOISON if a machine check was handled.
> > + */
> > +static inline int copy_mc_highpages(struct page *to, struct page *from,
> > + unsigned long nr_pages)
> > +{
> > + unsigned long len = nr_pages << PAGE_SHIFT;
> > + unsigned long i, ret;
> > +
> > + might_sleep();
> > +
> > + /*
> > + * When copying we want to operate on the largest extent possible to
> > + * allow for architecture specific extent based optimizations.
> > + *
> > + * copy_mc_to_kernel() does not call cond_resched(). That is fine on
> > + * preemptible kernels, where the scheduler can preempt the copy at
> > + * any point, so copy the whole range at once if copy_mc_to_kernel() is
> > + * available and the pages are in the linear map. Otherwise, copy one
> > + * page at a time and reschedule in between.
> > + */
> > + if (IS_ENABLED(CONFIG_ARCH_HAS_COPY_MC) && IS_ENABLED(CONFIG_PREEMPTION) &&
> > + !IS_ENABLED(CONFIG_HIGHMEM)) {
> > + ret = copy_mc_to_kernel(page_address(to), page_address(from), len);
> > + if (ret) {
> > + memory_failure_queue(page_to_pfn(from) +
> > + ((len - ret) >> PAGE_SHIFT), 0);
> > + return -EHWPOISON;
> > + }
> > + for (i = 0; i < nr_pages; i++)
> > + kmsan_copy_page_meta(to + i, from + i);
> > + return 0;
> > + }
> > +
> > + for (i = 0; i < nr_pages; i++) {
> > + cond_resched();
> > + if (copy_mc_highpage(to + i, from + i))
> > + return -EHWPOISON;
> > + }
>
> [Severity: Critical]
> This problem wasn't introduced by this patch, but can copy_mc_highpage()
> and copy_mc_user_highpage() (as well as the new copy_mc_highpages() fast
> path) return 0 when the source page or its containing folio is already
> marked PG_hwpoison [1]?
Yes, the patch keeps the existing behavior. PG_hwpoison marked pages are copied without errors but Real poison issue returns non-zero and folio_mc_copy() fails! Should we consider this as blocker?
Yuanhe's patch adds the check to copy !copy_mc branch but copy_mc branch can still copy such a page. [1]
Since it's pre-existing issue, I'd prefer to keep it out of this patch.
For solution, should we consider folio_contain_hwpoisoned_page() check in the folio_mc_copy()? It's racy but best-effort, and would avoid adding
cost of checking each page within large folio.
[1] https://lore.kernel.org/linux-mm/sashiko-outbox-208876@kernel.org/#t
> Neither helper checks PageHWPoison() or folio_contain_hwpoisoned_page()
> before copying. copy_mc_to_kernel() only catches synchronous #MC
> exceptions raised during the copy itself (and falls back to plain memcpy()
> when unavailable or on x86 without X86_FEATURE_ERMS or
> copy_mc_fragile_enabled).
>
> If a source folio was poisoned via software injection (such as
> MADV_HWPOISON) or a prior memory_failure() where reading does not trigger
> a synchronous #MC, callers such as folio_mc_copy() or wp_page_copy() treat
> the copy as successful and copy corrupted data into a fresh destination
> folio without PG_hwpoison set, or trigger an unrecoverable kernel #MC when
> copy_mc_to_kernel() is not active.
>
> [1] https://sashiko.dev/#/bug/linux-3af4aa7d-d182-430b-b982-583f6aea4594
next prev parent reply other threads:[~2026-11-17 5:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 17:09 [PATCH v3] mm: introduce copy_mc_highpages() and batch copy in folio_mc_copy() Shivank Garg
2026-11-14 17:12 ` sashiko-bot
2026-11-17 5:27 ` Garg, Shivank [this message]
2026-11-19 17:27 ` David Hildenbrand (Arm)
2026-11-22 7:30 ` Andrew Morton
2026-11-22 17:13 ` Garg, Shivank
2026-11-22 7:30 ` + mm-introduce-copy_mc_highpages-and-batch-copy-in-folio_mc_copy.patch added to mm-unstable branch Andrew Morton
2026-11-22 16:00 ` David Hildenbrand (Arm)
2026-11-22 16:44 ` [merged] mm-introduce-copy_mc_highpages-and-batch-copy-in-folio_mc_copy.patch removed from -mm tree Andrew Morton
2026-11-23 16:23 ` [PATCH v3] mm: introduce copy_mc_highpages() and batch copy in folio_mc_copy() David Hildenbrand (Arm)
2026-11-26 18:44 ` Garg, Shivank
2026-11-26 20:43 ` David Hildenbrand (Arm)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2dd5ed03f167563d8b37a4e1ae4b17d2d8aa31a2.camel@amd.com \
--to=shivankg@amd.com \
--cc=Hrushikesh.Salunke@amd.com \
--cc=akpm@linux-foundation.org \
--cc=ankur.a.arora@oracle.com \
--cc=bharata@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david.laight.linux@gmail.com \
--cc=david@kernel.org \
--cc=hpa@zytor.com \
--cc=kaitao.cheng@linux.dev \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=nhuhuan@google.com \
--cc=peterz@infradead.org \
--cc=pfalcato@suse.de \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=surenb@google.com \
--cc=tejavojjala@google.com \
--cc=tglx@kernel.org \
--cc=torvalds@linuxfoundation.org \
--cc=vbabka@kernel.org \
--cc=x86@kernel.org \
--cc=xiangzao@linux.alibaba.com \
--cc=ying.huang@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.