From: sashiko-bot@kernel.org
To: "Shivank Garg" <shivankg@amd.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@kernel.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Michal Hocko" <mhocko@suse.com>,
"Borislav Petkov" <bp@alien8.de>,
"Ankur Arora" <ankur.a.arora@oracle.com>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Bharata B Rao" <bharata@amd.com>,
"Hrushikesh Salunke" <hsalunke@amd.com>,
"Ingo Molnar" <mingo@redhat.com>,
"H . Peter Anvin" <hpa@zytor.com>,
"David Laight" <david.laight.linux@gmail.com>,
"David Rientjes" <rientjes@google.com>,
"Linus Torvalds" <torvalds@linuxfoundation.org>,
"Teja Vojjala" <tejavojjala@google.com>,
"Huan Nguyen" <nhuhuan@google.com>,
"Pedro Falcato" <pfalcato@suse.de>,
"Peter Zijlstra" <peterz@infradead.org>
Cc: linux-mm@kvack.org, x86@kernel.org
Subject: Re: [PATCH v3] mm: introduce copy_mc_highpages() and batch copy in folio_mc_copy()
Date: Sat, 14 Nov 2026 17:12:22 +0000 [thread overview]
Message-ID: <sashiko-outbox-214828@kernel.org> (raw)
In-Reply-To: <20261113-batpagecopy-v3-1-297f5b2fd28e@amd.com>
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]?
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
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261113-batpagecopy-v3-1-297f5b2fd28e@amd.com?part=1
prev parent reply other threads:[~2026-11-14 17:12 UTC|newest]
Thread overview: 2+ 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 [this message]
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=sashiko-outbox-214828@kernel.org \
--to=sashiko-bot@kernel.org \
--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=hsalunke@amd.com \
--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=shivankg@amd.com \
--cc=surenb@google.com \
--cc=tejavojjala@google.com \
--cc=tglx@kernel.org \
--cc=torvalds@linuxfoundation.org \
--cc=vbabka@kernel.org \
--cc=x86@kernel.org \
/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.