Re: [PATCH v4 1/6] mm/highmem: introduce copy_mc_can_batch() and __copy_mc_pages()

From: Garg, Shivank

Date: Sun Dec 06 2026 - 09:48:22 EST


On Fri, 2026-12-04 at 11:45 +0800, Jiangtian Feng wrote:
> [Some people who received this message don't often get email from jiangtianfeng@xxxxxxxxxxxxxxxxx. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> Hi Shivank,
>
> > Add copy_mc_can_batch(), which tells whether a page range can be copied
> > with a single copy_mc_to_kernel() call, and __copy_mc_pages(), which
> > does that copy.
>
> There is a pending interaction with the arm64 copy_mc work. I am
> preparing a respin of Ruidong's v15 series:
>
> https://lore.kernel.org/all/20260618092124.3901230-1-tianruidong@xxxxxxxxxxxxxxxxx/
>
> The respin selects ARCH_HAS_COPY_MC when ACPI_APEI_SEA is enabled and
> provides architecture-specific copy_mc_highpage() and
> copy_mc_user_highpage() helpers. Consequently, ARCH_HAS_COPY_MC would
> also enable this raw-range fast path on preemptible arm64 kernels.
>
> Your range wrappers handle KMSAN metadata, but the arm64 helpers have
> additional semantics. When enabled, they reset the destination KASAN
> hardware tag and copy MTE tags and their page/folio state. The user
> variant also maintains the dcache-clean state needed for later
> icache/dcache synchronization. They queue the actual source page when
> either the data or MTE-tag copy fails; the latter failure has no
> copy_mc_to_kernel() residual from which to derive a PFN. The raw fast
> path would bypass these operations.
>
> Could we separate raw-range batching from ARCH_HAS_COPY_MC with an
> explicit opt-in, for example ARCH_HAS_COPY_MC_BATCH? The Kconfig help
> should state that selecting it requires the architecture's per-page
> helpers to have no additional semantics beyond the raw copy, KMSAN
> metadata and residual-based source-page queueing. That description is
> only about raw-range equivalence; the ordinary copy_mc_to_kernel()
> contract remains unchanged.
>
> copy_mc_can_batch() would then check ARCH_HAS_COPY_MC_BATCH instead of
> ARCH_HAS_COPY_MC. x86-64 and ppc64 can select the new symbol alongside
> ARCH_HAS_COPY_MC, preserving the fast path covered by this series.
> Other architectures retain your range helpers and caller conversions,
> but take their existing per-page fallback. No arm64 exclusion is needed
> for raw batching. The range-order change and its failure-order effects
> remain a separate review item; this opt-in only prevents bypassing the
> architecture helpers.
>
> This seems preferable to making arm64 disable PREEMPTION or dropping
> the generic range work, and leaves room for a future arm64 range helper
> that handles its tag/cache/failure semantics explicitly. x86-64 and
> ppc64 would retain responsibility for validating their respective raw
> fast paths; arm64 would validate the per-page fallback.
>
> Would that split work for v5? I think the selector and the x86/ppc
> selections belong in this series, so that adding a new ARCH_HAS_COPY_MC
> architecture cannot silently opt into raw batching. If you prefer a
> different ownership or ordering for the prerequisite, please let me
> know so we do not post competing versions.
>

Hi Jiangtian,

Thanks for catching and alerting me on this.

Instead of inventing new Kconfig symbol ARCH_HAS_COPY_MC_BATCH, how about I
reuse __HAVE_ARCH_COPY_MC{_USER}_HIGHPAGE checks that you're adding[1]?

static inline bool copy_mc_can_batch(void)
{
#if defined(__HAVE_ARCH_COPY_MC_HIGHPAGE) || defined(__HAVE_ARCH_COPY_MC_USER_HIGHPAGE)
return false;
#else
return IS_ENABLED(CONFIG_ARCH_HAS_COPY_MC) &&
IS_ENABLED(CONFIG_PREEMPTION) && !IS_ENABLED(CONFIG_HIGHMEM);
#endif
}

That way batching is only used where it is the generic helper repeated
over the range, and arch-specific COPY_MC cases, falls back to the per-page loop
without having to know about batching. It also needs no x86 or powerpc changes.

If you prefer an explicit ARCH_HAS_COPY_MC_BATCH instead, I'm fine with that
too. Let me know your thoughts.

[1] https://lore.kernel.org/linux-mm/20261205012435.1406255-7-jiangtianfeng@xxxxxxxxxxxxxxxxx

--
Thanks,
Shivank