* [PATCH v16 1/9] uaccess: add generic fallback version of copy_mc_to_user()
2026-12-05 1:24 [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Jiangtian Feng
@ 2026-12-05 1:24 ` Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 2/9] ACPI: APEI: GHES: use exception context to gate SIGBUS on poison consumption Jiangtian Feng
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Jiangtian Feng @ 2026-12-05 1:24 UTC (permalink / raw)
To: catalin.marinas, will, akpm, rafael
Cc: mark.rutland, james.morse, robin.murphy, nikumbh.adi, tony.luck,
guohanjun, mchehab, lenb, xueshuai, tongtiangen, tianruidong,
tongweilin, baolin.wang, ashok.raj, jonathan.cameron, david,
liam, vbabka, rppt, mhocko, ljs, surenb, shivankg,
wangkefeng.wang, xiangzao, ying.huang, linmiaohe, nao.horiguchi,
ziy, tujinjiang, mgorman, kaitao.cheng, chengkaitao, muchun.song,
nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
usama.arif, kas, kees, andreyknvl, dvyukov, glider, ryabinin.a.a,
vincenzo.frascino, tglx, mingo, bp, dave.hansen, hpa, maddy, mpe,
npiggin, chleroy, ritesh.list, sshegde, aneesh.kumar,
naveen.n.rao, linux-arm-kernel, linux-acpi, linux-mm,
linux-hardening, kasan-dev, linuxppc-dev, x86, linux-kernel,
Mauro Carvalho Chehab, Jonathan Cameron, Jiangtian Feng
From: Tong Tiangen <tongtiangen@huawei.com>
x86/powerpc has it's implementation of copy_mc_to_user(), we add generic
fallback in include/linux/uaccess.h prepare for other architechures to
enable CONFIG_ARCH_HAS_COPY_MC.
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Shuai Xue <xueshuai@linux.alibaba.com>
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
arch/powerpc/include/asm/uaccess.h | 1 +
arch/x86/include/asm/uaccess.h | 1 +
include/linux/uaccess.h | 8 ++++++++
3 files changed, 10 insertions(+)
diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
index 49039074b33f..be6430a230c1 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -458,6 +458,7 @@ copy_mc_to_user(void __user *to, const void *from, unsigned long n)
return n;
}
+#define copy_mc_to_user copy_mc_to_user
#endif
extern size_t copy_from_user_flushcache(void *dst, const void __user *src, size_t size);
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index f4700ad6b5ec..7a69d407eb3c 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -442,6 +442,7 @@ copy_mc_to_kernel(void *to, const void *from, unsigned len);
unsigned long __must_check
copy_mc_to_user(void __user *to, const void *from, unsigned len);
+#define copy_mc_to_user copy_mc_to_user
#endif
/*
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index 67cdb0a4f583..689604cb590c 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -243,6 +243,14 @@ copy_mc_to_kernel(void *dst, const void *src, size_t cnt)
}
#endif
+#ifndef copy_mc_to_user
+static inline unsigned long __must_check
+copy_mc_to_user(void __user *dst, const void *src, unsigned long cnt)
+{
+ return copy_to_user(dst, src, cnt);
+}
+#endif
+
static __always_inline void pagefault_disabled_inc(void)
{
current->pagefault_disabled++;
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v16 2/9] ACPI: APEI: GHES: use exception context to gate SIGBUS on poison consumption
2026-12-05 1:24 [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 1/9] uaccess: add generic fallback version of copy_mc_to_user() Jiangtian Feng
@ 2026-12-05 1:24 ` Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 3/9] arm64: extable: merge UACCESS_ERR_ZERO and KACCESS_ERR_ZERO into ACCESS_ERR_ZERO Jiangtian Feng
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Jiangtian Feng @ 2026-12-05 1:24 UTC (permalink / raw)
To: catalin.marinas, will, akpm, rafael
Cc: mark.rutland, james.morse, robin.murphy, nikumbh.adi, tony.luck,
guohanjun, mchehab, lenb, xueshuai, tongtiangen, tianruidong,
tongweilin, baolin.wang, ashok.raj, jonathan.cameron, david,
liam, vbabka, rppt, mhocko, ljs, surenb, shivankg,
wangkefeng.wang, xiangzao, ying.huang, linmiaohe, nao.horiguchi,
ziy, tujinjiang, mgorman, kaitao.cheng, chengkaitao, muchun.song,
nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
usama.arif, kas, kees, andreyknvl, dvyukov, glider, ryabinin.a.a,
vincenzo.frascino, tglx, mingo, bp, dave.hansen, hpa, maddy, mpe,
npiggin, chleroy, ritesh.list, sshegde, aneesh.kumar,
naveen.n.rao, linux-arm-kernel, linux-acpi, linux-mm,
linux-hardening, kasan-dev, linuxppc-dev, x86, linux-kernel,
Jiangtian Feng
From: Ruidong Tian <tianruidong@linux.alibaba.com>
When a GHES SEA (Synchronous External Abort) fires while the CPU
was executing in kernel mode, it typically means that kernel code
itself consumed a poisoned memory location -- e.g. copy_from_user()
/ copy_to_user() invoked from a ioctl() or write() syscall touched
a poisoned user page or page-cache page on behalf of the task.
The expected behaviour in that case is that the faulting kernel
helper returns via its extable fixup and the syscall returns an
error (e.g. -EFAULT) to user space. It is NOT appropriate to deliver
SIGBUS to the current task: the task did not directly dereference
the poisoned address, the kernel did on its behalf, and the kernel
is able to recover.
Up to now ghes_handle_memory_failure() unconditionally promoted any
synchronous recoverable memory error to MF_ACTION_REQUIRED, which
ends up SIGBUS on current -- regardless of whether the poison was
consumed from user space or from inside the kernel on the task's
behalf. That kills tasks that should instead have seen a plain
syscall error.
To fix this, the execution mode in which the exception was taken
must be captured at the arch-level entry point, where pt_regs (and
hence user_mode(regs)) are still available. The estatus node that
later drains the error in IRQ / process context no longer has
access to the original regs.
Introduce:
enum context { ... };
and plumb the value all the way down to the queued estatus node:
* Add an 'enum context context' field to struct ghes_estatus_node
and record it in ghes_in_nmi_queue_one_entry().
* Extend ghes_notify_sea() and the internal
ghes_in_nmi_spool_from_list() with an enum context parameter.
Then consume the recorded context in ghes_handle_memory_failure()
and ghes_handle_arm_hw_error() for the synchronous path:
flags = sync && context != GHES_CTX_KERNEL ? MF_ACTION_REQUIRED : 0;
MF_ACTION_REQUIRED is retained for user-mode and GHES_CTX_NA poison
consumption. The latter includes KVM's apei_claim_sea(NULL) guest-SEA path,
for which sync can still be true. Kernel-mode records use flags=0 because
the context is captured before the arch decides whether a copy fixup is
possible: a successful fixup returns a copy error, while a rejected fixup
continues through the existing fatal SEA path.
Also restrict the existing sync && !queued force-SIGBUS fallback to paths
other than GHES_CTX_KERNEL, preserving the USER and KVM/NA behavior.
Duplicate SEA anti-storm handling still returns -ECANCELED for USER and
KVM/NA, but a duplicate KERNEL record does not bypass the arch fixup path.
Otherwise a second read of an already reported error source could turn a
recoverable kernel copy into a fatal exception.
Qoder, an AI coding assistant, helped adapt the context handling to the
newer queue-aggregation and KVM/NA paths and review the resulting failure
semantics.
Signed-off-by: Ruidong Tian <tianruidong@linux.alibaba.com>
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
arch/arm64/kernel/acpi.c | 2 +-
drivers/acpi/apei/ghes.c | 48 ++++++++++++++++++++++------------------
include/acpi/ghes.h | 15 +++++++++++--
3 files changed, 40 insertions(+), 25 deletions(-)
diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
index 681aa2bbc399..32be5499ea45 100644
--- a/arch/arm64/kernel/acpi.c
+++ b/arch/arm64/kernel/acpi.c
@@ -409,7 +409,7 @@ int apei_claim_sea(struct pt_regs *regs)
*/
local_daif_restore(DAIF_ERRCTX);
nmi_enter();
- err = ghes_notify_sea();
+ err = ghes_notify_sea(GHES_CTX(regs));
nmi_exit();
/*
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index 5d888c82efea..eb4466aa87f2 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -529,7 +529,7 @@ static bool ghes_do_memory_failure(u64 physical_addr, int flags)
}
static bool ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata,
- int sev, bool sync)
+ int sev, bool sync, enum ghes_exec_ctx context)
{
int flags = -1;
int sec_sev = ghes_severity(gdata->error_severity);
@@ -543,7 +543,7 @@ static bool ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata,
(gdata->flags & CPER_SEC_ERROR_THRESHOLD_EXCEEDED))
flags = MF_SOFT_OFFLINE;
if (sev == GHES_SEV_RECOVERABLE && sec_sev == GHES_SEV_RECOVERABLE)
- flags = sync ? MF_ACTION_REQUIRED : 0;
+ flags = sync && context != GHES_CTX_KERNEL ? MF_ACTION_REQUIRED : 0;
if (flags != -1)
return ghes_do_memory_failure(mem_err->physical_addr, flags);
@@ -552,10 +552,10 @@ static bool ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata,
}
static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata,
- int sev, bool sync)
+ int sev, bool sync, enum ghes_exec_ctx context)
{
struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata);
- int flags = sync ? MF_ACTION_REQUIRED : 0;
+ int flags = sync && context != GHES_CTX_KERNEL ? MF_ACTION_REQUIRED : 0;
int length = gdata->error_data_length;
char error_type[120];
bool queued = false;
@@ -954,7 +954,8 @@ static u32 ghes_mem_err_min_len(u64 validation_bits)
}
static void ghes_do_proc(struct ghes *ghes,
- const struct acpi_hest_generic_status *estatus)
+ const struct acpi_hest_generic_status *estatus,
+ enum ghes_exec_ctx context)
{
int sev, sec_sev;
struct acpi_hest_generic_data *gdata;
@@ -1000,11 +1001,11 @@ static void ghes_do_proc(struct ghes *ghes,
atomic_notifier_call_chain(&ghes_report_chain, sev, mem_err);
arch_apei_report_mem_error(sev, mem_err);
- queued |= ghes_handle_memory_failure(gdata, sev, sync);
+ queued |= ghes_handle_memory_failure(gdata, sev, sync, context);
} else if (guid_equal(sec_type, &CPER_SEC_PCIE)) {
ghes_handle_aer(gdata);
} else if (guid_equal(sec_type, &CPER_SEC_PROC_ARM)) {
- queued |= ghes_handle_arm_hw_error(gdata, sev, sync);
+ queued |= ghes_handle_arm_hw_error(gdata, sev, sync, context);
} else if (guid_equal(sec_type, &CPER_SEC_CXL_PROT_ERR)) {
struct cxl_cper_sec_prot_err *prot_err = acpi_hest_get_payload(gdata);
@@ -1037,9 +1038,10 @@ static void ghes_do_proc(struct ghes *ghes,
/*
* If no memory failure work is queued for abnormal synchronous
- * errors, do a force kill.
+ * errors, force kill for USER and KVM/NA. Kernel records are left
+ * for the arch SEA/extable path to decide whether recovery is possible.
*/
- if (sync && !queued) {
+ if (sync && !queued && context != GHES_CTX_KERNEL) {
dev_err(ghes->dev,
HW_ERR GHES_PFX "%s:%d: synchronous unrecoverable error (SIGBUS)\n",
current->comm, task_pid_nr(current));
@@ -1257,7 +1259,7 @@ static int ghes_proc(struct ghes *ghes)
if (ghes_print_estatus(NULL, ghes->generic, estatus))
ghes_estatus_cache_add(ghes->generic, estatus);
}
- ghes_do_proc(ghes, estatus);
+ ghes_do_proc(ghes, estatus, GHES_CTX_NA);
out:
ghes_clear_estatus(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ);
@@ -1364,7 +1366,7 @@ static void ghes_proc_in_irq(struct irq_work *irq_work)
len = cper_estatus_len(estatus);
node_len = GHES_ESTATUS_NODE_LEN(len);
- ghes_do_proc(estatus_node->ghes, estatus);
+ ghes_do_proc(estatus_node->ghes, estatus, estatus_node->context);
if (!ghes_estatus_cached(estatus)) {
generic = estatus_node->generic;
@@ -1402,7 +1404,8 @@ static void ghes_print_queued_estatus(void)
}
static int ghes_in_nmi_queue_one_entry(struct ghes *ghes,
- enum fixed_addresses fixmap_idx)
+ enum fixed_addresses fixmap_idx,
+ enum ghes_exec_ctx context)
{
struct acpi_hest_generic_status *estatus, tmp_header;
struct ghes_estatus_node *estatus_node;
@@ -1431,6 +1434,7 @@ static int ghes_in_nmi_queue_one_entry(struct ghes *ghes,
if (!estatus_node)
return -ENOMEM;
+ estatus_node->context = context;
estatus_node->ghes = ghes;
estatus_node->generic = ghes->generic;
estatus = GHES_ESTATUS_FROM_NODE(estatus_node);
@@ -1452,11 +1456,10 @@ static int ghes_in_nmi_queue_one_entry(struct ghes *ghes,
/* This error has been reported before, don't process it again. */
if (ghes_estatus_cached(estatus)) {
/*
- * Return failure on duplicate SEA entries so that the
- * subsequent SEA handler invocation sends a SIGBUS signal to
- * the task to prevent it from re-entering the handler loop.
+ * Kernel copies must still reach their fixup; retain duplicate
+ * SEA anti-storm handling for user and KVM/NA paths.
*/
- if (is_hest_sync_notify(ghes))
+ if (is_hest_sync_notify(ghes) && context != GHES_CTX_KERNEL)
rc = -ECANCELED;
goto no_work;
}
@@ -1473,14 +1476,15 @@ static int ghes_in_nmi_queue_one_entry(struct ghes *ghes,
}
static int __maybe_unused ghes_in_nmi_spool_from_list(struct list_head *rcu_list,
- enum fixed_addresses fixmap_idx)
+ enum fixed_addresses fixmap_idx,
+ enum ghes_exec_ctx context)
{
int ret = -ENOENT;
struct ghes *ghes;
rcu_read_lock();
list_for_each_entry_rcu(ghes, rcu_list, list) {
- if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx))
+ if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx, context))
ret = 0;
}
rcu_read_unlock();
@@ -1563,7 +1567,7 @@ static LIST_HEAD(ghes_sea);
* Return 0 only if one of the SEA error sources successfully reported an error
* record sent from the firmware.
*/
-int ghes_notify_sea(void)
+int ghes_notify_sea(enum ghes_exec_ctx context)
{
static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sea);
int rv;
@@ -1572,7 +1576,7 @@ int ghes_notify_sea(void)
return -ENOENT;
raw_spin_lock(&ghes_notify_lock_sea);
- rv = ghes_in_nmi_spool_from_list(&ghes_sea, FIX_APEI_GHES_SEA);
+ rv = ghes_in_nmi_spool_from_list(&ghes_sea, FIX_APEI_GHES_SEA, context);
raw_spin_unlock(&ghes_notify_lock_sea);
return rv;
@@ -1627,7 +1631,7 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)
return ret;
raw_spin_lock(&ghes_notify_lock_nmi);
- if (!ghes_in_nmi_spool_from_list(&ghes_nmi, FIX_APEI_GHES_NMI))
+ if (!ghes_in_nmi_spool_from_list(&ghes_nmi, FIX_APEI_GHES_NMI, GHES_CTX_NA))
ret = NMI_HANDLED;
raw_spin_unlock(&ghes_notify_lock_nmi);
@@ -1681,7 +1685,7 @@ static void ghes_nmi_init_cxt(void)
static int __ghes_sdei_callback(struct ghes *ghes,
enum fixed_addresses fixmap_idx)
{
- if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx)) {
+ if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx, GHES_CTX_NA)) {
irq_work_queue(&ghes_proc_irq_work);
return 0;
diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h
index 7acf209061ea..2cd97f700214 100644
--- a/include/acpi/ghes.h
+++ b/include/acpi/ghes.h
@@ -33,10 +33,21 @@ struct ghes {
void __iomem *error_status_vaddr;
};
+enum ghes_exec_ctx {
+ GHES_CTX_NA = -1,
+ GHES_CTX_KERNEL = 0,
+ GHES_CTX_USER = 1
+};
+
+#define GHES_CTX(regs) ((regs) ? (user_mode(regs) ? GHES_CTX_USER \
+ : GHES_CTX_KERNEL) \
+ : GHES_CTX_NA)
+
struct ghes_estatus_node {
struct llist_node llnode;
struct acpi_hest_generic *generic;
struct ghes *ghes;
+ enum ghes_exec_ctx context;
};
struct ghes_estatus_cache {
@@ -139,9 +150,9 @@ static inline void *acpi_hest_get_next(struct acpi_hest_generic_data *gdata)
section = acpi_hest_get_next(section))
#ifdef CONFIG_ACPI_APEI_SEA
-int ghes_notify_sea(void);
+int ghes_notify_sea(enum ghes_exec_ctx context);
#else
-static inline int ghes_notify_sea(void) { return -ENOENT; }
+static inline int ghes_notify_sea(enum ghes_exec_ctx context) { return -ENOENT; }
#endif
struct notifier_block;
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v16 3/9] arm64: extable: merge UACCESS_ERR_ZERO and KACCESS_ERR_ZERO into ACCESS_ERR_ZERO
2026-12-05 1:24 [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 1/9] uaccess: add generic fallback version of copy_mc_to_user() Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 2/9] ACPI: APEI: GHES: use exception context to gate SIGBUS on poison consumption Jiangtian Feng
@ 2026-12-05 1:24 ` Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 4/9] arm64: enable recover from synchronous external abort in kernel context Jiangtian Feng
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Jiangtian Feng @ 2026-12-05 1:24 UTC (permalink / raw)
To: catalin.marinas, will, akpm, rafael
Cc: mark.rutland, james.morse, robin.murphy, nikumbh.adi, tony.luck,
guohanjun, mchehab, lenb, xueshuai, tongtiangen, tianruidong,
tongweilin, baolin.wang, ashok.raj, jonathan.cameron, david,
liam, vbabka, rppt, mhocko, ljs, surenb, shivankg,
wangkefeng.wang, xiangzao, ying.huang, linmiaohe, nao.horiguchi,
ziy, tujinjiang, mgorman, kaitao.cheng, chengkaitao, muchun.song,
nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
usama.arif, kas, kees, andreyknvl, dvyukov, glider, ryabinin.a.a,
vincenzo.frascino, tglx, mingo, bp, dave.hansen, hpa, maddy, mpe,
npiggin, chleroy, ritesh.list, sshegde, aneesh.kumar,
naveen.n.rao, linux-arm-kernel, linux-acpi, linux-mm,
linux-hardening, kasan-dev, linuxppc-dev, x86, linux-kernel,
Jiangtian Feng
From: Ruidong Tian <tianruidong@linux.alibaba.com>
EX_TYPE_UACCESS_ERR_ZERO and EX_TYPE_KACCESS_ERR_ZERO have identical
handling in fixup_exception(): both unconditionally invoke
ex_handler_uaccess_err_zero() to set the error register to -EFAULT,
zero the destination register, and branch to the fixup address.
Merge them into a single EX_TYPE_ACCESS_ERR_ZERO to reduce redundancy
and renumber the subsequent types accordingly.
The _ASM_EXTABLE_UACCESS_ERR_ZERO and _ASM_EXTABLE_KACCESS_ERR_ZERO
helper macros are preserved as-is for caller readability, but both now
emit the unified EX_TYPE_ACCESS_ERR_ZERO type.
Signed-off-by: Ruidong Tian <tianruidong@linux.alibaba.com>
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
arch/arm64/include/asm/asm-extable.h | 15 +++++++--------
arch/arm64/mm/extable.c | 7 +++----
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/arch/arm64/include/asm/asm-extable.h b/arch/arm64/include/asm/asm-extable.h
index d67e2fdd1aee..06b19023939b 100644
--- a/arch/arm64/include/asm/asm-extable.h
+++ b/arch/arm64/include/asm/asm-extable.h
@@ -7,12 +7,11 @@
#define EX_TYPE_NONE 0
#define EX_TYPE_BPF 1
-#define EX_TYPE_UACCESS_ERR_ZERO 2
-#define EX_TYPE_KACCESS_ERR_ZERO 3
-#define EX_TYPE_UACCESS_CPY 4
-#define EX_TYPE_LOAD_UNALIGNED_ZEROPAD 5
+#define EX_TYPE_ACCESS_ERR_ZERO 2
+#define EX_TYPE_UACCESS_CPY 3
+#define EX_TYPE_LOAD_UNALIGNED_ZEROPAD 4
-/* Data fields for EX_TYPE_UACCESS_ERR_ZERO */
+/* Data fields for EX_TYPE_ACCESS_ERR_ZERO */
#define EX_DATA_REG_ERR_SHIFT 0
#define EX_DATA_REG_ERR GENMASK(4, 0)
#define EX_DATA_REG_ZERO_SHIFT 5
@@ -43,7 +42,7 @@
#define _ASM_EXTABLE_UACCESS_ERR_ZERO(insn, fixup, err, zero) \
__ASM_EXTABLE_RAW(insn, fixup, \
- EX_TYPE_UACCESS_ERR_ZERO, \
+ EX_TYPE_ACCESS_ERR_ZERO, \
( \
EX_DATA_REG(ERR, err) | \
EX_DATA_REG(ZERO, zero) \
@@ -96,7 +95,7 @@
#define _ASM_EXTABLE_UACCESS_ERR_ZERO(insn, fixup, err, zero) \
__DEFINE_ASM_GPR_NUMS \
__ASM_EXTABLE_RAW(#insn, #fixup, \
- __stringify(EX_TYPE_UACCESS_ERR_ZERO), \
+ __stringify(EX_TYPE_ACCESS_ERR_ZERO), \
"(" \
EX_DATA_REG(ERR, err) " | " \
EX_DATA_REG(ZERO, zero) \
@@ -105,7 +104,7 @@
#define _ASM_EXTABLE_KACCESS_ERR_ZERO(insn, fixup, err, zero) \
__DEFINE_ASM_GPR_NUMS \
__ASM_EXTABLE_RAW(#insn, #fixup, \
- __stringify(EX_TYPE_KACCESS_ERR_ZERO), \
+ __stringify(EX_TYPE_ACCESS_ERR_ZERO), \
"(" \
EX_DATA_REG(ERR, err) " | " \
EX_DATA_REG(ZERO, zero) \
diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c
index 299a244f68e6..402c5db692ff 100644
--- a/arch/arm64/mm/extable.c
+++ b/arch/arm64/mm/extable.c
@@ -41,7 +41,7 @@ get_ex_fixup(const struct exception_table_entry *ex)
return ((unsigned long)&ex->fixup + ex->fixup);
}
-static bool ex_handler_uaccess_err_zero(const struct exception_table_entry *ex,
+static bool ex_handler_access_err_zero(const struct exception_table_entry *ex,
struct pt_regs *regs)
{
int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
@@ -98,9 +98,8 @@ bool fixup_exception(struct pt_regs *regs, unsigned long esr)
switch (ex->type) {
case EX_TYPE_BPF:
return ex_handler_bpf(ex, regs);
- case EX_TYPE_UACCESS_ERR_ZERO:
- case EX_TYPE_KACCESS_ERR_ZERO:
- return ex_handler_uaccess_err_zero(ex, regs);
+ case EX_TYPE_ACCESS_ERR_ZERO:
+ return ex_handler_access_err_zero(ex, regs);
case EX_TYPE_UACCESS_CPY:
return ex_handler_uaccess_cpy(ex, regs, esr);
case EX_TYPE_LOAD_UNALIGNED_ZEROPAD:
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v16 4/9] arm64: enable recover from synchronous external abort in kernel context
2026-12-05 1:24 [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Jiangtian Feng
` (2 preceding siblings ...)
2026-12-05 1:24 ` [PATCH v16 3/9] arm64: extable: merge UACCESS_ERR_ZERO and KACCESS_ERR_ZERO into ACCESS_ERR_ZERO Jiangtian Feng
@ 2026-12-05 1:24 ` Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 5/9] mm/hwpoison: return -EFAULT when copy fail in copy_mc_[user]_highpage() Jiangtian Feng
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Jiangtian Feng @ 2026-12-05 1:24 UTC (permalink / raw)
To: catalin.marinas, will, akpm, rafael
Cc: mark.rutland, james.morse, robin.murphy, nikumbh.adi, tony.luck,
guohanjun, mchehab, lenb, xueshuai, tongtiangen, tianruidong,
tongweilin, baolin.wang, ashok.raj, jonathan.cameron, david,
liam, vbabka, rppt, mhocko, ljs, surenb, shivankg,
wangkefeng.wang, xiangzao, ying.huang, linmiaohe, nao.horiguchi,
ziy, tujinjiang, mgorman, kaitao.cheng, chengkaitao, muchun.song,
nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
usama.arif, kas, kees, andreyknvl, dvyukov, glider, ryabinin.a.a,
vincenzo.frascino, tglx, mingo, bp, dave.hansen, hpa, maddy, mpe,
npiggin, chleroy, ritesh.list, sshegde, aneesh.kumar,
naveen.n.rao, linux-arm-kernel, linux-acpi, linux-mm,
linux-hardening, kasan-dev, linuxppc-dev, x86, linux-kernel,
Jiangtian Feng
From: Ruidong Tian <tianruidong@linux.alibaba.com>
For the arm64 kernel, when it processes hardware memory errors for
synchronize notifications(do_sea()), if the errors is consumed within the
kernel, the current processing is panic. However, it is not optimal.
Take copy_from/to_user for example, If ld* triggers a memory error, even in
kernel mode, only the associated process is affected. Killing the user
process and isolating the corrupt page is a better choice.
Add new fixup type EX_TYPE_KACCESS_SEA to identify insn that can recover
from memory errors triggered by access to kernel memory, and this fixup
type is used in __arch_copy_to_user(), This make the regular copy_to_user()
will handle kernel memory errors.
[Ruidong: modify subject and rename EX_TYPE_KACCESS_ERR_ZERO_MEM_ERR to
EX_TYPE_KACCESS_SEA]
Also reject EX_TYPE_KACCESS_SEA in insn_may_access_user(). These entries
mark kernel source accesses, not user accesses. Treating them as uaccess
could route a TTBR0/PAN fault through user fault handling instead of
preserving the kernel-access checks.
A successful GHES claim is not sufficient to skip a kernel instruction.
Only an exact EL1 data abort with FSC_EXTABT, no S1PTW and SET=0 is
eligible for an explicit SEA fixup. SET=0 means UER on RAS systems and is
RES0 on non-RAS systems; UC, UEO and other encodings are rejected. UEO
support is left for a separate RAS-version-aware change with
fault-injection coverage. Instruction aborts, table-walk/parity errors and
faults without a suitable handler continue through the existing failure
path. Do not use the SError-only AET encoding for this decision.
Pass the real ESR to fixup_exception_me() and handle EX_TYPE_UACCESS_CPY
with the existing direction-aware handler. The SEA-only path additionally
accepts copy_to_user's kernel source read, matching its scalar path;
copy_from_user's kernel destination and all ordinary translation faults
remain unchanged. MOPS usercopy faults bypass the single-byte try-harder
path so a zero-progress fault cannot repeat the same access.
This bypass applies to ordinary MOPS faults as well: a zero-progress fault
may return the full residual instead of first retrying one byte. This is an
intentional conservative change to avoid repeating an SEA. Scalar faults
retain the existing try-harder behavior.
EX_TYPE_KACCESS_SEA accepts source reads only. In particular, a MOPS
destination write is not implicitly recovered by annotating the whole copy
instruction.
Qoder, an AI coding assistant, helped review the extable type usage and
TTBR0/PAN negative path, restrict the recoverable SEA/SET conditions, and
review the MOPS uaccess direction and repeated-fault paths.
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Signed-off-by: Ruidong Tian <tianruidong@linux.alibaba.com>
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
arch/arm64/include/asm/asm-extable.h | 5 +++
arch/arm64/include/asm/asm-uaccess.h | 4 +++
arch/arm64/include/asm/extable.h | 1 +
arch/arm64/lib/copy_from_user.S | 6 ++--
arch/arm64/lib/copy_to_user.S | 16 +++++-----
arch/arm64/mm/extable.c | 47 +++++++++++++++++++++++++---
arch/arm64/mm/fault.c | 38 +++++++++++++++++-----
7 files changed, 96 insertions(+), 21 deletions(-)
diff --git a/arch/arm64/include/asm/asm-extable.h b/arch/arm64/include/asm/asm-extable.h
index 06b19023939b..8450ec5a3af6 100644
--- a/arch/arm64/include/asm/asm-extable.h
+++ b/arch/arm64/include/asm/asm-extable.h
@@ -10,6 +10,7 @@
#define EX_TYPE_ACCESS_ERR_ZERO 2
#define EX_TYPE_UACCESS_CPY 3
#define EX_TYPE_LOAD_UNALIGNED_ZEROPAD 4
+#define EX_TYPE_KACCESS_SEA 5
/* Data fields for EX_TYPE_ACCESS_ERR_ZERO */
#define EX_DATA_REG_ERR_SHIFT 0
@@ -76,6 +77,10 @@
__ASM_EXTABLE_RAW(\insn, \fixup, EX_TYPE_UACCESS_CPY, \uaccess_is_write)
.endm
+ .macro _asm_extable_kaccess_sea, insn, fixup
+ __ASM_EXTABLE_RAW(\insn, \fixup, EX_TYPE_KACCESS_SEA, 0)
+ .endm
+
#else /* __ASSEMBLER__ */
#include <linux/stringify.h>
diff --git a/arch/arm64/include/asm/asm-uaccess.h b/arch/arm64/include/asm/asm-uaccess.h
index 12aa6a283249..27bf8edbf597 100644
--- a/arch/arm64/include/asm/asm-uaccess.h
+++ b/arch/arm64/include/asm/asm-uaccess.h
@@ -57,6 +57,10 @@ alternative_else_nop_endif
.endm
#endif
+#define KERNEL_SEA(l, x...) \
+9999: x; \
+ _asm_extable_kaccess_sea 9999b, l
+
#define USER(l, x...) \
9999: x; \
_asm_extable_uaccess 9999b, l
diff --git a/arch/arm64/include/asm/extable.h b/arch/arm64/include/asm/extable.h
index 9dc39612bdf5..87fba582b5a7 100644
--- a/arch/arm64/include/asm/extable.h
+++ b/arch/arm64/include/asm/extable.h
@@ -48,4 +48,5 @@ bool ex_handler_bpf(const struct exception_table_entry *ex,
#endif /* !CONFIG_BPF_JIT */
bool fixup_exception(struct pt_regs *regs, unsigned long esr);
+bool fixup_exception_me(struct pt_regs *regs, unsigned long esr);
#endif
diff --git a/arch/arm64/lib/copy_from_user.S b/arch/arm64/lib/copy_from_user.S
index 400057d607ec..04f152ff5b03 100644
--- a/arch/arm64/lib/copy_from_user.S
+++ b/arch/arm64/lib/copy_from_user.S
@@ -54,7 +54,7 @@
.macro cpy1 dst, src, count
.arch_extension mops
- USER_CPY(9997f, 0, cpyfprt [\dst]!, [\src]!, \count!)
+ USER_CPY(9998f, 0, cpyfprt [\dst]!, [\src]!, \count!)
USER_CPY(9996f, 0, cpyfmrt [\dst]!, [\src]!, \count!)
USER_CPY(9996f, 0, cpyfert [\dst]!, [\src]!, \count!)
.endm
@@ -69,9 +69,11 @@ SYM_FUNC_START(__arch_copy_from_user)
ret
// Exception fixups
-9996: b.cs 9997f
+ // MOPS faults skip the zero-progress retry to avoid repeating an SEA.
+9996: b.cs 9998f
// Registers are in Option A format
add dst, dst, count
+ b 9998f
9997: cmp dst, dstin
b.ne 9998f
// Before being absolutely sure we couldn't copy anything, try harder
diff --git a/arch/arm64/lib/copy_to_user.S b/arch/arm64/lib/copy_to_user.S
index 819f2e3fc7a9..451bfeb0143b 100644
--- a/arch/arm64/lib/copy_to_user.S
+++ b/arch/arm64/lib/copy_to_user.S
@@ -20,7 +20,7 @@
* x0 - bytes not copied
*/
.macro ldrb1 reg, ptr, val
- ldrb \reg, [\ptr], \val
+ KERNEL_SEA(9998f, ldrb \reg, [\ptr], \val)
.endm
.macro strb1 reg, ptr, val
@@ -28,7 +28,7 @@
.endm
.macro ldrh1 reg, ptr, val
- ldrh \reg, [\ptr], \val
+ KERNEL_SEA(9998f, ldrh \reg, [\ptr], \val)
.endm
.macro strh1 reg, ptr, val
@@ -36,7 +36,7 @@
.endm
.macro ldr1 reg, ptr, val
- ldr \reg, [\ptr], \val
+ KERNEL_SEA(9998f, ldr \reg, [\ptr], \val)
.endm
.macro str1 reg, ptr, val
@@ -44,7 +44,7 @@
.endm
.macro ldp1 reg1, reg2, ptr, val
- ldp \reg1, \reg2, [\ptr], \val
+ KERNEL_SEA(9998f, ldp \reg1, \reg2, [\ptr], \val)
.endm
.macro stp1 reg1, reg2, ptr, val
@@ -53,7 +53,7 @@
.macro cpy1 dst, src, count
.arch_extension mops
- USER_CPY(9997f, 1, cpyfpwt [\dst]!, [\src]!, \count!)
+ USER_CPY(9998f, 1, cpyfpwt [\dst]!, [\src]!, \count!)
USER_CPY(9996f, 1, cpyfmwt [\dst]!, [\src]!, \count!)
USER_CPY(9996f, 1, cpyfewt [\dst]!, [\src]!, \count!)
.endm
@@ -68,13 +68,15 @@ SYM_FUNC_START(__arch_copy_to_user)
ret
// Exception fixups
-9996: b.cs 9997f
+ // MOPS faults skip the zero-progress retry to avoid repeating an SEA.
+9996: b.cs 9998f
// Registers are in Option A format
add dst, dst, count
+ b 9998f
9997: cmp dst, dstin
b.ne 9998f
// Before being absolutely sure we couldn't copy anything, try harder
- ldrb tmp1w, [srcin]
+KERNEL_SEA(9998f, ldrb tmp1w, [srcin])
USER(9998f, sttrb tmp1w, [dst])
add dst, dst, #1
9998: sub x0, end, dst // bytes not copied
diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c
index 402c5db692ff..5ea013a3247c 100644
--- a/arch/arm64/mm/extable.c
+++ b/arch/arm64/mm/extable.c
@@ -30,6 +30,9 @@ bool insn_may_access_user(unsigned long addr, unsigned long esr)
switch (ex->type) {
case EX_TYPE_UACCESS_CPY:
return cpy_faulted_on_uaccess(ex, esr);
+ case EX_TYPE_KACCESS_SEA:
+ /* These entries mark kernel source accesses, not uaccess. */
+ return false;
default:
return true;
}
@@ -55,10 +58,14 @@ static bool ex_handler_access_err_zero(const struct exception_table_entry *ex,
}
static bool ex_handler_uaccess_cpy(const struct exception_table_entry *ex,
- struct pt_regs *regs, unsigned long esr)
+ struct pt_regs *regs, unsigned long esr,
+ bool allow_kernel_source)
{
- /* Do not fix up faults on kernel memory accesses */
- if (!cpy_faulted_on_uaccess(ex, esr))
+ /* Only SEA may also accept copy_to_user's kernel source read. */
+ if (!cpy_faulted_on_uaccess(ex, esr) &&
+ !(allow_kernel_source &&
+ FIELD_GET(EX_DATA_UACCESS_WRITE, ex->data) &&
+ !(esr & ESR_ELx_WNR)))
return false;
regs->pc = get_ex_fixup(ex);
@@ -101,10 +108,42 @@ bool fixup_exception(struct pt_regs *regs, unsigned long esr)
case EX_TYPE_ACCESS_ERR_ZERO:
return ex_handler_access_err_zero(ex, regs);
case EX_TYPE_UACCESS_CPY:
- return ex_handler_uaccess_cpy(ex, regs, esr);
+ return ex_handler_uaccess_cpy(ex, regs, esr, false);
case EX_TYPE_LOAD_UNALIGNED_ZEROPAD:
return ex_handler_load_unaligned_zeropad(ex, regs);
+ /*
+ * Kernel address faults (e.g. copy_to_user reading from kernel src).
+ * Do not fixup here: a translation fault on a kernel address is a
+ * kernel bug (e.g. NULL pointer dereference) and must oops.
+ * Only SEA (hardware memory error) should be fixed up, which is
+ * handled by fixup_exception_me() through the do_sea path.
+ */
+ case EX_TYPE_KACCESS_SEA:
+ return false;
}
BUG();
}
+
+bool fixup_exception_me(struct pt_regs *regs, unsigned long esr)
+{
+ const struct exception_table_entry *ex;
+
+ ex = search_exception_tables(instruction_pointer(regs));
+ if (!ex)
+ return false;
+
+ switch (ex->type) {
+ case EX_TYPE_ACCESS_ERR_ZERO:
+ return ex_handler_access_err_zero(ex, regs);
+ case EX_TYPE_UACCESS_CPY:
+ return ex_handler_uaccess_cpy(ex, regs, esr, true);
+ case EX_TYPE_KACCESS_SEA:
+ if (esr & ESR_ELx_WNR)
+ return false;
+ regs->pc = get_ex_fixup(ex);
+ return true;
+ }
+
+ return false;
+}
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index b22736853fcd..d8ff65c86728 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -874,21 +874,43 @@ static int do_bad(unsigned long far, unsigned long esr, struct pt_regs *regs)
return 1; /* "fault" */
}
+/*
+ * APEI claimed this as a firmware-first notification.
+ * Some processing deferred to task_work before ret_to_user().
+ */
+static int do_apei_claim_sea(struct pt_regs *regs, unsigned long esr)
+{
+ int ret;
+
+ ret = apei_claim_sea(regs);
+ if (ret)
+ return ret;
+
+ if (user_mode(regs))
+ return 0;
+
+ /* A GHES claim alone does not make a kernel exception safe to skip. */
+ if (!is_el1_data_abort(esr) ||
+ (esr & ESR_ELx_FSC) != ESR_ELx_FSC_EXTABT ||
+ (esr & ESR_ELx_S1PTW) ||
+ (esr & ESR_ELx_SET_MASK))
+ return -ENOENT;
+
+ if (!fixup_exception_me(regs, esr))
+ return -ENOENT;
+
+ return 0;
+}
+
static int do_sea(unsigned long far, unsigned long esr, struct pt_regs *regs)
{
const struct fault_info *inf;
unsigned long siaddr;
- inf = esr_to_fault_info(esr);
-
- if (user_mode(regs) && apei_claim_sea(regs) == 0) {
- /*
- * APEI claimed this as a firmware-first notification.
- * Some processing deferred to task_work before ret_to_user().
- */
+ if (do_apei_claim_sea(regs, esr) == 0)
return 0;
- }
+ inf = esr_to_fault_info(esr);
if (esr & ESR_ELx_FnV) {
siaddr = 0;
} else {
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v16 5/9] mm/hwpoison: return -EFAULT when copy fail in copy_mc_[user]_highpage()
2026-12-05 1:24 [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Jiangtian Feng
` (3 preceding siblings ...)
2026-12-05 1:24 ` [PATCH v16 4/9] arm64: enable recover from synchronous external abort in kernel context Jiangtian Feng
@ 2026-12-05 1:24 ` Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 6/9] arm64: support copy_mc_[user]_highpage() Jiangtian Feng
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Jiangtian Feng @ 2026-12-05 1:24 UTC (permalink / raw)
To: catalin.marinas, will, akpm, rafael
Cc: mark.rutland, james.morse, robin.murphy, nikumbh.adi, tony.luck,
guohanjun, mchehab, lenb, xueshuai, tongtiangen, tianruidong,
tongweilin, baolin.wang, ashok.raj, jonathan.cameron, david,
liam, vbabka, rppt, mhocko, ljs, surenb, shivankg,
wangkefeng.wang, xiangzao, ying.huang, linmiaohe, nao.horiguchi,
ziy, tujinjiang, mgorman, kaitao.cheng, chengkaitao, muchun.song,
nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
usama.arif, kas, kees, andreyknvl, dvyukov, glider, ryabinin.a.a,
vincenzo.frascino, tglx, mingo, bp, dave.hansen, hpa, maddy, mpe,
npiggin, chleroy, ritesh.list, sshegde, aneesh.kumar,
naveen.n.rao, linux-arm-kernel, linux-acpi, linux-mm,
linux-hardening, kasan-dev, linuxppc-dev, x86, linux-kernel,
Jonathan Cameron, Mauro Carvalho Chehab, Jiangtian Feng
From: Tong Tiangen <tongtiangen@huawei.com>
Currently, copy_mc_[user]_highpage() returns zero on success, or in case
of failures, the number of bytes that weren't copied.
While tracking the number of not copied works fine for x86 and PPC, There
are some difficulties in doing the same thing on ARM64 because there is no
available caller-saved register in copy_page()(lib/copy_page.S) to save
"bytes not copied", and the following copy_mc_page() will also encounter
the same problem.
Consider the caller of copy_mc_[user]_highpage() cannot do any processing
on the remaining data(The page has hardware errors), they only check if
copy was succeeded or not, make the interface more generic by using an
error code when copy fails (-EFAULT) or return zero on success.
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: Shuai Xue <xueshuai@linux.alibaba.com>
Reviewed-by: Ashok Raj <ashok.raj@oss.qualcomm.com>
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
include/linux/highmem.h | 8 ++++----
mm/khugepaged.c | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index d7aac9de1c8a..685c62c10408 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -428,8 +428,8 @@ static inline void copy_highpage(struct page *to, struct page *from)
/*
* 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.
+ * page with #MC in source page (@from) handled, and return -EFAULT if there
+ * was a #MC, otherwise 0 for success.
*/
static inline int copy_mc_user_highpage(struct page *to, struct page *from,
unsigned long vaddr, struct vm_area_struct *vma)
@@ -448,7 +448,7 @@ static inline int copy_mc_user_highpage(struct page *to, struct page *from,
if (ret)
memory_failure_queue(page_to_pfn(from), 0);
- return ret;
+ return ret ? -EFAULT : 0;
}
static inline int copy_mc_highpage(struct page *to, struct page *from)
@@ -467,7 +467,7 @@ static inline int copy_mc_highpage(struct page *to, struct page *from)
if (ret)
memory_failure_queue(page_to_pfn(from), 0);
- return ret;
+ return ret ? -EFAULT : 0;
}
#else
static inline int copy_mc_user_highpage(struct page *to, struct page *from,
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 964f78c3856b..4ceb440e242c 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -874,7 +874,7 @@ static enum scan_result __collapse_huge_page_copy(pte_t *pte, struct folio *foli
continue;
}
src_page = pte_page(pteval);
- if (copy_mc_user_highpage(page, src_page, src_addr, vma) > 0) {
+ if (copy_mc_user_highpage(page, src_page, src_addr, vma)) {
result = SCAN_COPY_MC;
break;
}
@@ -2515,7 +2515,7 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
}
for (i = 0; i < nr_pages; i++) {
- if (copy_mc_highpage(dst, folio_page(folio, i)) > 0) {
+ if (copy_mc_highpage(dst, folio_page(folio, i))) {
result = SCAN_COPY_MC;
goto rollback;
}
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v16 6/9] arm64: support copy_mc_[user]_highpage()
2026-12-05 1:24 [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Jiangtian Feng
` (4 preceding siblings ...)
2026-12-05 1:24 ` [PATCH v16 5/9] mm/hwpoison: return -EFAULT when copy fail in copy_mc_[user]_highpage() Jiangtian Feng
@ 2026-12-05 1:24 ` Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 7/9] arm64: introduce copy_mc_to_kernel() implementation Jiangtian Feng
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Jiangtian Feng @ 2026-12-05 1:24 UTC (permalink / raw)
To: catalin.marinas, will, akpm, rafael
Cc: mark.rutland, james.morse, robin.murphy, nikumbh.adi, tony.luck,
guohanjun, mchehab, lenb, xueshuai, tongtiangen, tianruidong,
tongweilin, baolin.wang, ashok.raj, jonathan.cameron, david,
liam, vbabka, rppt, mhocko, ljs, surenb, shivankg,
wangkefeng.wang, xiangzao, ying.huang, linmiaohe, nao.horiguchi,
ziy, tujinjiang, mgorman, kaitao.cheng, chengkaitao, muchun.song,
nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
usama.arif, kas, kees, andreyknvl, dvyukov, glider, ryabinin.a.a,
vincenzo.frascino, tglx, mingo, bp, dave.hansen, hpa, maddy, mpe,
npiggin, chleroy, ritesh.list, sshegde, aneesh.kumar,
naveen.n.rao, linux-arm-kernel, linux-acpi, linux-mm,
linux-hardening, kasan-dev, linuxppc-dev, x86, linux-kernel,
Jiangtian Feng
From: Tong Tiangen <tongtiangen@huawei.com>
Currently, many scenarios that can tolerate memory errors when copying page
have been supported in the kernel[1~9], all of which are implemented by
copy_mc_[user]_highpage(). arm64 should also support this mechanism.
Due to mte, arm64 needs to have its own copy_mc_[user]_highpage()
architecture implementation, macros __HAVE_ARCH_COPY_MC_HIGHPAGE and
__HAVE_ARCH_COPY_MC_USER_HIGHPAGE have been added to control it.
Add new helper copy_mc_page() which provide a page copy implementation with
hardware memory error safe. The code logic of copy_mc_page() is the same as
copy_page(), and the main logic is extracted to copy_page_template.S. Both
the ldp and MOPS source operations in the MC variant carry
EX_TYPE_KACCESS_SEA fixups and return -EFAULT when a recoverable SEA is
consumed.
[Ruidong: add FEAT_MOPS support]
[1] commit d302c2398ba2 ("mm, hwpoison: when copy-on-write hits poison, take page offline")
[2] commit 1cb9dc4b475c ("mm: hwpoison: support recovery from HugePage copy-on-write faults")
[3] commit 6b970599e807 ("mm: hwpoison: support recovery from ksm_might_need_to_copy()")
[4] commit 98c76c9f1ef7 ("mm/khugepaged: recover from poisoned anonymous memory")
[5] commit 12904d953364 ("mm/khugepaged: recover from poisoned file-backed memory")
[6] commit 658be46520ce ("mm: support poison recovery from copy_present_page()")
[7] commit aa549f923f5e ("mm: support poison recovery from do_cow_fault()")
[8] commit f00b295b9b61 ("fs: hugetlbfs: support poisoned recover from hugetlbfs_migrate_folio()")
[9] commit 060913999d7a ("mm: migrate: support poisoned recover from migrate folio")
Select ARCH_HAS_COPY_MC when ACPI_APEI_SEA is enabled, since the recovery
relies on the in-kernel SEA claim path rather than merely on GHES.
Use the existing dstin register alias for the MOPS template invocation.
When MTE tag copying fails, current callers do not publish the destination
page and eventually free it. The existing buddy and hugetlb free paths clear
the tag/lock state, so a tag-only rollback would be insufficient and is not
attempted here.
Match copy_highpage() when the tagging helpers report an already-tagged
destination. Folio migration can legitimately reuse such a page, so the MC
path must not emit a spurious WARN for that case.
Queue the actual source page with flags=0 on each data or tag-copy failure,
matching the generic highpage fallback. A hugetlb tag failure queues the
failing subpage rather than always using the head page. GHES may already
have queued the same PFN; supported RAM callers rely on MM's already-poisoned
handling to avoid a second substantive isolation. Duplicate FIFO entries,
trace events and logs are still possible. This is not a strict exactly-once
or final-recovery guarantee and does not establish dev_pagemap idempotency.
Qoder, an AI coding assistant, helped analyze the MOPS/MTE review feedback,
the destination-page lifecycle, source-page recovery queueing and the
7.4-rc5 integration, and drafted the corresponding description updates.
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Signed-off-by: Ruidong Tian <tianruidong@linux.alibaba.com>
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
arch/arm64/Kconfig | 1 +
arch/arm64/include/asm/asm-extable.h | 1 +
arch/arm64/include/asm/mte.h | 9 +++
arch/arm64/include/asm/page.h | 12 ++++
arch/arm64/lib/Makefile | 2 +
arch/arm64/lib/copy_mc_page.S | 43 ++++++++++++++
arch/arm64/lib/copy_page.S | 67 ++++------------------
arch/arm64/lib/copy_page_template.S | 70 +++++++++++++++++++++++
arch/arm64/lib/mte.S | 29 ++++++++++
arch/arm64/mm/copypage.c | 85 ++++++++++++++++++++++++++++
include/linux/highmem.h | 8 +++
11 files changed, 271 insertions(+), 56 deletions(-)
create mode 100644 arch/arm64/lib/copy_mc_page.S
create mode 100644 arch/arm64/lib/copy_page_template.S
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9b08b2457a55..0c017bdc7759 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -21,6 +21,7 @@ config ARM64
select ARCH_HAS_CACHE_LINE_SIZE
select ARCH_HAS_CC_PLATFORM
select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
+ select ARCH_HAS_COPY_MC if ACPI_APEI_SEA
select ARCH_HAS_CURRENT_STACK_POINTER
select ARCH_HAS_DEBUG_VIRTUAL
select ARCH_HAS_DEBUG_VM_PGTABLE
diff --git a/arch/arm64/include/asm/asm-extable.h b/arch/arm64/include/asm/asm-extable.h
index 8450ec5a3af6..cf4af0a1e8cd 100644
--- a/arch/arm64/include/asm/asm-extable.h
+++ b/arch/arm64/include/asm/asm-extable.h
@@ -10,6 +10,7 @@
#define EX_TYPE_ACCESS_ERR_ZERO 2
#define EX_TYPE_UACCESS_CPY 3
#define EX_TYPE_LOAD_UNALIGNED_ZEROPAD 4
+/* Kernel source reads eligible for SEA recovery, including MOPS copies. */
#define EX_TYPE_KACCESS_SEA 5
/* Data fields for EX_TYPE_ACCESS_ERR_ZERO */
diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h
index ff3d78329be0..4ed248a388aa 100644
--- a/arch/arm64/include/asm/mte.h
+++ b/arch/arm64/include/asm/mte.h
@@ -97,6 +97,11 @@ void mte_zero_clear_page_tags(void *addr);
void mte_clear_folio_tags(struct folio *folio);
void mte_sync_tags(pte_t pte, unsigned int nr_pages);
void mte_copy_page_tags(void *kto, const void *kfrom);
+
+#ifdef CONFIG_ARCH_HAS_COPY_MC
+int mte_copy_mc_page_tags(void *kto, const void *kfrom);
+#endif
+
void mte_thread_init_user(void);
void mte_thread_switch(struct task_struct *next);
void mte_cpu_setup(void);
@@ -136,6 +141,10 @@ static inline void mte_sync_tags(pte_t pte, unsigned int nr_pages)
static inline void mte_copy_page_tags(void *kto, const void *kfrom)
{
}
+static inline int mte_copy_mc_page_tags(void *kto, const void *kfrom)
+{
+ return 0;
+}
static inline void mte_thread_init_user(void)
{
}
diff --git a/arch/arm64/include/asm/page.h b/arch/arm64/include/asm/page.h
index b2eaa63d9056..c74292da41a3 100644
--- a/arch/arm64/include/asm/page.h
+++ b/arch/arm64/include/asm/page.h
@@ -40,6 +40,18 @@ void copy_user_highpage(struct page *to, struct page *from,
void copy_highpage(struct page *to, struct page *from);
#define __HAVE_ARCH_COPY_HIGHPAGE
+#ifdef CONFIG_ARCH_HAS_COPY_MC
+int copy_mc_page(void *to, const void *from);
+#define __HAVE_ARCH_COPY_MC_PAGE
+
+int copy_mc_highpage(struct page *to, struct page *from);
+#define __HAVE_ARCH_COPY_MC_HIGHPAGE
+
+int copy_mc_user_highpage(struct page *to, struct page *from,
+ unsigned long vaddr, struct vm_area_struct *vma);
+#define __HAVE_ARCH_COPY_MC_USER_HIGHPAGE
+#endif
+
struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struct *vma,
unsigned long vaddr);
#define vma_alloc_zeroed_movable_folio vma_alloc_zeroed_movable_folio
diff --git a/arch/arm64/lib/Makefile b/arch/arm64/lib/Makefile
index 38ffd359123c..f7952eb7fb8c 100644
--- a/arch/arm64/lib/Makefile
+++ b/arch/arm64/lib/Makefile
@@ -11,6 +11,8 @@ lib-y := clear_user.o delay.o copy_from_user.o \
lib-$(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) += uaccess_flushcache.o
+lib-$(CONFIG_ARCH_HAS_COPY_MC) += copy_mc_page.o
+
obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
obj-$(CONFIG_ARM64_MTE) += mte.o
diff --git a/arch/arm64/lib/copy_mc_page.S b/arch/arm64/lib/copy_mc_page.S
new file mode 100644
index 000000000000..542a083e2fd8
--- /dev/null
+++ b/arch/arm64/lib/copy_mc_page.S
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <linux/linkage.h>
+#include <linux/const.h>
+#include <asm/assembler.h>
+#include <asm/page.h>
+#include <asm/cpufeature.h>
+#include <asm/alternative.h>
+#include <asm/asm-extable.h>
+#include <asm/asm-uaccess.h>
+
+/*
+ * Copy a page from src to dest (both are page aligned) with memory error safe
+ *
+ * Parameters:
+ * x0 - dest
+ * x1 - src
+ * Returns:
+ * x0 - Return 0 on success, or -EFAULT for a supported source SEA.
+ */
+ .macro ldp1 reg1, reg2, ptr, val
+ KERNEL_SEA(9998f, ldp \reg1, \reg2, [\ptr, \val])
+ .endm
+
+ .macro cpy1 dst, src, count
+ .arch_extension mops
+ KERNEL_SEA(9998f, cpypwn [\dst]!, [\src]!, \count!)
+ KERNEL_SEA(9998f, cpymwn [\dst]!, [\src]!, \count!)
+ KERNEL_SEA(9998f, cpyewn [\dst]!, [\src]!, \count!)
+ .endm
+
+SYM_FUNC_START(__pi_copy_mc_page)
+#include "copy_page_template.S"
+
+ mov x0, #0
+ ret
+
+9998: mov x0, #-EFAULT
+ ret
+
+SYM_FUNC_END(__pi_copy_mc_page)
+SYM_FUNC_ALIAS(copy_mc_page, __pi_copy_mc_page)
+EXPORT_SYMBOL(copy_mc_page)
diff --git a/arch/arm64/lib/copy_page.S b/arch/arm64/lib/copy_page.S
index e6374e7e5511..e520777b5150 100644
--- a/arch/arm64/lib/copy_page.S
+++ b/arch/arm64/lib/copy_page.S
@@ -17,65 +17,20 @@
* x0 - dest
* x1 - src
*/
-SYM_FUNC_START(__pi_copy_page)
-#ifdef CONFIG_AS_HAS_MOPS
- .arch_extension mops
-alternative_if_not ARM64_HAS_MOPS
- b .Lno_mops
-alternative_else_nop_endif
-
- mov x2, #PAGE_SIZE
- cpypwn [x0]!, [x1]!, x2!
- cpymwn [x0]!, [x1]!, x2!
- cpyewn [x0]!, [x1]!, x2!
- ret
-.Lno_mops:
-#endif
- ldp x2, x3, [x1]
- ldp x4, x5, [x1, #16]
- ldp x6, x7, [x1, #32]
- ldp x8, x9, [x1, #48]
- ldp x10, x11, [x1, #64]
- ldp x12, x13, [x1, #80]
- ldp x14, x15, [x1, #96]
- ldp x16, x17, [x1, #112]
-
- add x0, x0, #256
- add x1, x1, #128
-1:
- tst x0, #(PAGE_SIZE - 1)
- stnp x2, x3, [x0, #-256]
- ldp x2, x3, [x1]
- stnp x4, x5, [x0, #16 - 256]
- ldp x4, x5, [x1, #16]
- stnp x6, x7, [x0, #32 - 256]
- ldp x6, x7, [x1, #32]
- stnp x8, x9, [x0, #48 - 256]
- ldp x8, x9, [x1, #48]
- stnp x10, x11, [x0, #64 - 256]
- ldp x10, x11, [x1, #64]
- stnp x12, x13, [x0, #80 - 256]
- ldp x12, x13, [x1, #80]
- stnp x14, x15, [x0, #96 - 256]
- ldp x14, x15, [x1, #96]
- stnp x16, x17, [x0, #112 - 256]
- ldp x16, x17, [x1, #112]
+ .macro ldp1 reg1, reg2, ptr, val
+ ldp \reg1, \reg2, [\ptr, \val]
+ .endm
- add x0, x0, #128
- add x1, x1, #128
-
- b.ne 1b
-
- stnp x2, x3, [x0, #-256]
- stnp x4, x5, [x0, #16 - 256]
- stnp x6, x7, [x0, #32 - 256]
- stnp x8, x9, [x0, #48 - 256]
- stnp x10, x11, [x0, #64 - 256]
- stnp x12, x13, [x0, #80 - 256]
- stnp x14, x15, [x0, #96 - 256]
- stnp x16, x17, [x0, #112 - 256]
+ .macro cpy1 dst, src, count
+ .arch_extension mops
+ cpypwn [\dst]!, [\src]!, \count!
+ cpymwn [\dst]!, [\src]!, \count!
+ cpyewn [\dst]!, [\src]!, \count!
+ .endm
+SYM_FUNC_START(__pi_copy_page)
+#include "copy_page_template.S"
ret
SYM_FUNC_END(__pi_copy_page)
SYM_FUNC_ALIAS(copy_page, __pi_copy_page)
diff --git a/arch/arm64/lib/copy_page_template.S b/arch/arm64/lib/copy_page_template.S
new file mode 100644
index 000000000000..ad931c37dcec
--- /dev/null
+++ b/arch/arm64/lib/copy_page_template.S
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ */
+
+/*
+ * Copy a page from src to dest (both are page aligned)
+ *
+ * Parameters:
+ * x0 - dest
+ * x1 - src
+ */
+dstin .req x0
+src .req x1
+
+#ifdef CONFIG_AS_HAS_MOPS
+alternative_if_not ARM64_HAS_MOPS
+ b .Lno_mops
+alternative_else_nop_endif
+ mov x2, #PAGE_SIZE
+ cpy1 dstin, src, x2
+ b .Lexitfunc
+.Lno_mops:
+#endif
+
+ ldp1 x2, x3, x1, #0
+ ldp1 x4, x5, x1, #16
+ ldp1 x6, x7, x1, #32
+ ldp1 x8, x9, x1, #48
+ ldp1 x10, x11, x1, #64
+ ldp1 x12, x13, x1, #80
+ ldp1 x14, x15, x1, #96
+ ldp1 x16, x17, x1, #112
+
+ add x0, x0, #256
+ add x1, x1, #128
+1:
+ tst x0, #(PAGE_SIZE - 1)
+
+ stnp x2, x3, [x0, #-256]
+ ldp1 x2, x3, x1, #0
+ stnp x4, x5, [x0, #16 - 256]
+ ldp1 x4, x5, x1, #16
+ stnp x6, x7, [x0, #32 - 256]
+ ldp1 x6, x7, x1, #32
+ stnp x8, x9, [x0, #48 - 256]
+ ldp1 x8, x9, x1, #48
+ stnp x10, x11, [x0, #64 - 256]
+ ldp1 x10, x11, x1, #64
+ stnp x12, x13, [x0, #80 - 256]
+ ldp1 x12, x13, x1, #80
+ stnp x14, x15, [x0, #96 - 256]
+ ldp1 x14, x15, x1, #96
+ stnp x16, x17, [x0, #112 - 256]
+ ldp1 x16, x17, x1, #112
+
+ add x0, x0, #128
+ add x1, x1, #128
+
+ b.ne 1b
+
+ stnp x2, x3, [x0, #-256]
+ stnp x4, x5, [x0, #16 - 256]
+ stnp x6, x7, [x0, #32 - 256]
+ stnp x8, x9, [x0, #48 - 256]
+ stnp x10, x11, [x0, #64 - 256]
+ stnp x12, x13, [x0, #80 - 256]
+ stnp x14, x15, [x0, #96 - 256]
+ stnp x16, x17, [x0, #112 - 256]
+.Lexitfunc:
diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S
index 5018ac03b6bf..1afe3ef1502c 100644
--- a/arch/arm64/lib/mte.S
+++ b/arch/arm64/lib/mte.S
@@ -80,6 +80,35 @@ SYM_FUNC_START(mte_copy_page_tags)
ret
SYM_FUNC_END(mte_copy_page_tags)
+#ifdef CONFIG_ARCH_HAS_COPY_MC
+/*
+ * Copy the tags from the source page to the destination one with memory error safe
+ * x0 - address of the destination page
+ * x1 - address of the source page
+ * Returns:
+ * x0 - Return 0 if copy success, or
+ * -EFAULT if anything goes wrong while copying.
+ */
+SYM_FUNC_START(mte_copy_mc_page_tags)
+ mov x2, x0
+ mov x3, x1
+ multitag_transfer_size x5, x6
+1:
+KERNEL_SEA(2f, ldgm x4, [x3])
+ stgm x4, [x2]
+ add x2, x2, x5
+ add x3, x3, x5
+ tst x2, #(PAGE_SIZE - 1)
+ b.ne 1b
+
+ mov x0, #0
+ ret
+
+2: mov x0, #-EFAULT
+ ret
+SYM_FUNC_END(mte_copy_mc_page_tags)
+#endif
+
/*
* Read tags from a user buffer (one tag per byte) and set the corresponding
* tags at the given kernel address. Used by PTRACE_POKEMTETAGS.
diff --git a/arch/arm64/mm/copypage.c b/arch/arm64/mm/copypage.c
index cd5912ba617b..611024fca6d4 100644
--- a/arch/arm64/mm/copypage.c
+++ b/arch/arm64/mm/copypage.c
@@ -72,3 +72,88 @@ void copy_user_highpage(struct page *to, struct page *from,
flush_dcache_page(to);
}
EXPORT_SYMBOL_GPL(copy_user_highpage);
+
+#ifdef CONFIG_ARCH_HAS_COPY_MC
+/*
+ * Return -EFAULT if anything goes wrong while copying page or mte.
+ */
+int copy_mc_highpage(struct page *to, struct page *from)
+{
+ void *kto = page_address(to);
+ void *kfrom = page_address(from);
+ struct folio *src = page_folio(from);
+ struct folio *dst = page_folio(to);
+ unsigned int i, nr_pages;
+ int ret;
+
+ ret = copy_mc_page(kto, kfrom);
+ if (ret) {
+ memory_failure_queue(page_to_pfn(from), 0);
+ return -EFAULT;
+ }
+
+ if (kasan_hw_tags_enabled())
+ page_kasan_tag_reset(to);
+
+ if (!system_supports_mte())
+ return 0;
+
+ if (folio_test_hugetlb(src)) {
+ if (!folio_test_hugetlb_mte_tagged(src) ||
+ from != folio_page(src, 0))
+ return 0;
+
+ folio_try_hugetlb_mte_tagging(dst);
+
+ /*
+ * Populate tags for all subpages.
+ *
+ * Don't assume the first page is head page since
+ * huge page copy may start from any subpage.
+ */
+ nr_pages = folio_nr_pages(src);
+ for (i = 0; i < nr_pages; i++) {
+ kfrom = page_address(folio_page(src, i));
+ kto = page_address(folio_page(dst, i));
+ ret = mte_copy_mc_page_tags(kto, kfrom);
+ if (ret) {
+ memory_failure_queue(page_to_pfn(folio_page(src, i)), 0);
+ return -EFAULT;
+ }
+ }
+ folio_set_hugetlb_mte_tagged(dst);
+ } else if (page_mte_tagged(from)) {
+ /* Migration may reuse an already tagged destination page. */
+ try_page_mte_tagging(to);
+
+ ret = mte_copy_mc_page_tags(kto, kfrom);
+ if (ret) {
+ memory_failure_queue(page_to_pfn(from), 0);
+ return -EFAULT;
+ }
+ set_page_mte_tagged(to);
+ }
+ /*
+ * Failure paths above queue the actual source. GHES may already have
+ * queued it; supported RAM callers rely on flags=0 duplicate requests
+ * collapsing to already-poisoned handling, not repeated isolation.
+ */
+ return 0;
+}
+EXPORT_SYMBOL(copy_mc_highpage);
+
+int copy_mc_user_highpage(struct page *to, struct page *from,
+ unsigned long vaddr, struct vm_area_struct *vma)
+{
+ int ret;
+
+ ret = copy_mc_highpage(to, from);
+ if (ret)
+ return ret;
+
+ flush_dcache_page(to);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(copy_mc_user_highpage);
+#endif
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 685c62c10408..f65d6ef3e991 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -425,6 +425,7 @@ static inline void copy_highpage(struct page *to, struct page *from)
#endif
#ifdef copy_mc_to_kernel
+#ifndef __HAVE_ARCH_COPY_MC_USER_HIGHPAGE
/*
* If architecture supports machine check exception handling, define the
* #MC versions of copy_user_highpage and copy_highpage. They copy a memory
@@ -450,7 +451,9 @@ static inline int copy_mc_user_highpage(struct page *to, struct page *from,
return ret ? -EFAULT : 0;
}
+#endif
+#ifndef __HAVE_ARCH_COPY_MC_HIGHPAGE
static inline int copy_mc_highpage(struct page *to, struct page *from)
{
unsigned long ret;
@@ -469,20 +472,25 @@ static inline int copy_mc_highpage(struct page *to, struct page *from)
return ret ? -EFAULT : 0;
}
+#endif
#else
+#ifndef __HAVE_ARCH_COPY_MC_USER_HIGHPAGE
static inline int copy_mc_user_highpage(struct page *to, struct page *from,
unsigned long vaddr, struct vm_area_struct *vma)
{
copy_user_highpage(to, from, vaddr, vma);
return 0;
}
+#endif
+#ifndef __HAVE_ARCH_COPY_MC_HIGHPAGE
static inline int copy_mc_highpage(struct page *to, struct page *from)
{
copy_highpage(to, from);
return 0;
}
#endif
+#endif
static inline void memcpy_page(struct page *dst_page, size_t dst_off,
struct page *src_page, size_t src_off,
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v16 7/9] arm64: introduce copy_mc_to_kernel() implementation
2026-12-05 1:24 [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Jiangtian Feng
` (5 preceding siblings ...)
2026-12-05 1:24 ` [PATCH v16 6/9] arm64: support copy_mc_[user]_highpage() Jiangtian Feng
@ 2026-12-05 1:24 ` Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 8/9] lib/test: memcpy_kunit: add copy_page() and copy_mc_page() tests Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 9/9] lib/tests: memcpy_kunit: add memcpy_mc() and memcpy_mc_large() test Jiangtian Feng
8 siblings, 0 replies; 10+ messages in thread
From: Jiangtian Feng @ 2026-12-05 1:24 UTC (permalink / raw)
To: catalin.marinas, will, akpm, rafael
Cc: mark.rutland, james.morse, robin.murphy, nikumbh.adi, tony.luck,
guohanjun, mchehab, lenb, xueshuai, tongtiangen, tianruidong,
tongweilin, baolin.wang, ashok.raj, jonathan.cameron, david,
liam, vbabka, rppt, mhocko, ljs, surenb, shivankg,
wangkefeng.wang, xiangzao, ying.huang, linmiaohe, nao.horiguchi,
ziy, tujinjiang, mgorman, kaitao.cheng, chengkaitao, muchun.song,
nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
usama.arif, kas, kees, andreyknvl, dvyukov, glider, ryabinin.a.a,
vincenzo.frascino, tglx, mingo, bp, dave.hansen, hpa, maddy, mpe,
npiggin, chleroy, ritesh.list, sshegde, aneesh.kumar,
naveen.n.rao, linux-arm-kernel, linux-acpi, linux-mm,
linux-hardening, kasan-dev, linuxppc-dev, x86, linux-kernel,
Jiangtian Feng
From: Tong Tiangen <tongtiangen@huawei.com>
The copy_mc_to_kernel() helper is memory copy implementation that handles
source exceptions. It can be used in memory copy scenarios that tolerate
hardware memory errors(e.g: pmem_read/dax_copy_to_iter).
Currently, only x86 and ppc support this helper, Add this for ARM64 as
well, if ARCH_HAS_COPY_MC is defined, by implementing copy_mc_to_kernel()
and memcpy_mc() functions.
The optimized memcpy template copies head and tail blocks out of order and
does not maintain a current destination pointer on every load path. After
a partially completed copy, using the original destination to calculate
the residual can therefore report the entire input length again.
Use the forward copy template shared with the uaccess code instead. Every
completed store advances dst, so the exception exit can calculate the
residual as end - dst. The MOPS main/epilogue fixup converts the Option A
register state to the current destination before the same calculation.
Use forward-only CPYF operations: direction-selecting CPY operations may
choose backward even for non-overlapping inputs, which would invalidate
this residual calculation. This also avoids changing the normal optimized
memcpy implementation.
MOPS copy instructions in the MC variant use EX_TYPE_KACCESS_SEA fixups
like the regular load instructions, but the handler accepts source reads
only and rejects destination writes.
Define __HAVE_ARCH_MEMCPY_MC and its declarations/macros only when
CONFIG_ARCH_HAS_COPY_MC is enabled. Otherwise KASAN generic/SW builds would
include the memcpy_mc() wrapper while memcpy_mc.o is not linked, leaving an
undefined __memcpy_mc reference.
Qoder, an AI coding assistant, helped identify the configuration-dependent
link failure and residual-byte bug, redesign the forward-progress copy path
and review the MOPS descriptions.
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Signed-off-by: Ruidong Tian <tianruidong@linux.alibaba.com>
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
arch/arm64/include/asm/string.h | 9 ++++
arch/arm64/include/asm/uaccess.h | 17 +++++++
arch/arm64/lib/Makefile | 2 +-
arch/arm64/lib/memcpy_mc.S | 84 ++++++++++++++++++++++++++++++++
mm/kasan/shadow.c | 12 +++++
5 files changed, 123 insertions(+), 1 deletion(-)
create mode 100644 arch/arm64/lib/memcpy_mc.S
diff --git a/arch/arm64/include/asm/string.h b/arch/arm64/include/asm/string.h
index 3a3264ff47b9..ac425e2c9744 100644
--- a/arch/arm64/include/asm/string.h
+++ b/arch/arm64/include/asm/string.h
@@ -35,6 +35,12 @@ extern void *memchr(const void *, int, __kernel_size_t);
extern void *memcpy(void *, const void *, __kernel_size_t);
extern void *__memcpy(void *, const void *, __kernel_size_t);
+#ifdef CONFIG_ARCH_HAS_COPY_MC
+#define __HAVE_ARCH_MEMCPY_MC
+extern unsigned long memcpy_mc(void *, const void *, __kernel_size_t);
+extern unsigned long __memcpy_mc(void *, const void *, __kernel_size_t);
+#endif
+
#define __HAVE_ARCH_MEMMOVE
extern void *memmove(void *, const void *, __kernel_size_t);
extern void *__memmove(void *, const void *, __kernel_size_t);
@@ -57,6 +63,9 @@ void memcpy_flushcache(void *dst, const void *src, size_t cnt);
*/
#define memcpy(dst, src, len) __memcpy(dst, src, len)
+#ifdef CONFIG_ARCH_HAS_COPY_MC
+#define memcpy_mc(dst, src, len) __memcpy_mc(dst, src, len)
+#endif
#define memmove(dst, src, len) __memmove(dst, src, len)
#define memset(s, c, n) __memset(s, c, n)
diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
index 9f5bd9c69c24..734dde180a5a 100644
--- a/arch/arm64/include/asm/uaccess.h
+++ b/arch/arm64/include/asm/uaccess.h
@@ -498,5 +498,22 @@ static inline size_t probe_subpage_writeable(const char __user *uaddr,
}
#endif /* CONFIG_ARCH_HAS_SUBPAGE_FAULTS */
+#ifdef CONFIG_ARCH_HAS_COPY_MC
+/**
+ * copy_mc_to_kernel - memory copy that handles source exceptions
+ *
+ * @to: destination address
+ * @from: source address
+ * @size: number of bytes to copy
+ *
+ * Return 0 for success, or bytes not copied.
+ */
+static inline unsigned long __must_check
+copy_mc_to_kernel(void *to, const void *from, unsigned long size)
+{
+ return memcpy_mc(to, from, size);
+}
+#define copy_mc_to_kernel copy_mc_to_kernel
+#endif
#endif /* __ASM_UACCESS_H */
diff --git a/arch/arm64/lib/Makefile b/arch/arm64/lib/Makefile
index f7952eb7fb8c..cdb866ca71e7 100644
--- a/arch/arm64/lib/Makefile
+++ b/arch/arm64/lib/Makefile
@@ -11,7 +11,7 @@ lib-y := clear_user.o delay.o copy_from_user.o \
lib-$(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) += uaccess_flushcache.o
-lib-$(CONFIG_ARCH_HAS_COPY_MC) += copy_mc_page.o
+lib-$(CONFIG_ARCH_HAS_COPY_MC) += copy_mc_page.o memcpy_mc.o
obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
diff --git a/arch/arm64/lib/memcpy_mc.S b/arch/arm64/lib/memcpy_mc.S
new file mode 100644
index 000000000000..c7a217808fee
--- /dev/null
+++ b/arch/arm64/lib/memcpy_mc.S
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2013 ARM Ltd.
+ * Copyright (C) 2013 Linaro.
+ *
+ * This code is based on glibc cortex strings work originally authored by Linaro
+ * be found @
+ *
+ * http://bazaar.linaro.org/linaro-toolchain-dev/cortex-strings/trunk/
+ * files/head:/src/aarch64/
+ */
+
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+#include <asm/cache.h>
+#include <asm/asm-uaccess.h>
+
+/*
+ * Copy a buffer from src to dest (alignment handled by the hardware)
+ *
+ * Parameters:
+ * x0 - dest
+ * x1 - src
+ * x2 - n
+ * Returns:
+ * x0 - bytes not copied
+ */
+ .macro ldrb1 reg, ptr, val
+ KERNEL_SEA(9997f, ldrb \reg, [\ptr], \val)
+ .endm
+
+ .macro strb1 reg, ptr, val
+ strb \reg, [\ptr], \val
+ .endm
+
+ .macro ldrh1 reg, ptr, val
+ KERNEL_SEA(9997f, ldrh \reg, [\ptr], \val)
+ .endm
+
+ .macro strh1 reg, ptr, val
+ strh \reg, [\ptr], \val
+ .endm
+
+ .macro ldr1 reg, ptr, val
+ KERNEL_SEA(9997f, ldr \reg, [\ptr], \val)
+ .endm
+
+ .macro str1 reg, ptr, val
+ str \reg, [\ptr], \val
+ .endm
+
+ .macro ldp1 reg1, reg2, ptr, val
+ KERNEL_SEA(9997f, ldp \reg1, \reg2, [\ptr], \val)
+ .endm
+
+ .macro stp1 reg1, reg2, ptr, val
+ stp \reg1, \reg2, [\ptr], \val
+ .endm
+
+ .macro cpy1 dst, src, count
+ .arch_extension mops
+ KERNEL_SEA(9997f, cpyfp [\dst]!, [\src]!, \count!)
+ KERNEL_SEA(9996f, cpyfm [\dst]!, [\src]!, \count!)
+ KERNEL_SEA(9996f, cpyfe [\dst]!, [\src]!, \count!)
+ .endm
+
+end .req x5
+SYM_FUNC_START(__memcpy_mc)
+ add end, x0, x2
+#include "copy_template.S"
+ mov x0, #0
+ ret
+
+ // Exception fixups
+9996: b.cs 9997f
+ // Registers are in Option A format
+ add dst, dst, count
+9997: sub x0, end, dst // bytes not copied
+ ret
+SYM_FUNC_END(__memcpy_mc)
+
+EXPORT_SYMBOL(__memcpy_mc)
+SYM_FUNC_ALIAS_WEAK(memcpy_mc, __memcpy_mc)
+EXPORT_SYMBOL(memcpy_mc)
diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c
index d286e0a04543..da21a13151b9 100644
--- a/mm/kasan/shadow.c
+++ b/mm/kasan/shadow.c
@@ -79,6 +79,18 @@ void *memcpy(void *dest, const void *src, size_t len)
}
#endif
+#ifdef __HAVE_ARCH_MEMCPY_MC
+#undef memcpy_mc
+unsigned long memcpy_mc(void *dest, const void *src, size_t len)
+{
+ if (!kasan_check_range(src, len, false, _RET_IP_) ||
+ !kasan_check_range(dest, len, true, _RET_IP_))
+ return len;
+
+ return __memcpy_mc(dest, src, len);
+}
+#endif
+
void *__asan_memset(void *addr, int c, ssize_t len)
{
if (!kasan_check_range(addr, len, true, _RET_IP_))
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v16 8/9] lib/test: memcpy_kunit: add copy_page() and copy_mc_page() tests
2026-12-05 1:24 [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Jiangtian Feng
` (6 preceding siblings ...)
2026-12-05 1:24 ` [PATCH v16 7/9] arm64: introduce copy_mc_to_kernel() implementation Jiangtian Feng
@ 2026-12-05 1:24 ` Jiangtian Feng
2026-12-05 1:24 ` [PATCH v16 9/9] lib/tests: memcpy_kunit: add memcpy_mc() and memcpy_mc_large() test Jiangtian Feng
8 siblings, 0 replies; 10+ messages in thread
From: Jiangtian Feng @ 2026-12-05 1:24 UTC (permalink / raw)
To: catalin.marinas, will, akpm, rafael
Cc: mark.rutland, james.morse, robin.murphy, nikumbh.adi, tony.luck,
guohanjun, mchehab, lenb, xueshuai, tongtiangen, tianruidong,
tongweilin, baolin.wang, ashok.raj, jonathan.cameron, david,
liam, vbabka, rppt, mhocko, ljs, surenb, shivankg,
wangkefeng.wang, xiangzao, ying.huang, linmiaohe, nao.horiguchi,
ziy, tujinjiang, mgorman, kaitao.cheng, chengkaitao, muchun.song,
nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
usama.arif, kas, kees, andreyknvl, dvyukov, glider, ryabinin.a.a,
vincenzo.frascino, tglx, mingo, bp, dave.hansen, hpa, maddy, mpe,
npiggin, chleroy, ritesh.list, sshegde, aneesh.kumar,
naveen.n.rao, linux-arm-kernel, linux-acpi, linux-mm,
linux-hardening, kasan-dev, linuxppc-dev, x86, linux-kernel,
Jiangtian Feng
From: Ruidong Tian <tianruidong@linux.alibaba.com>
Add KUnit tests for copy_page() and copy_mc_page(), modeled after
the existing memcpy_test() style: a static page-aligned src and a
two-page dst, filled with random bytes plus non-zero edges, then
verify byte-for-byte equality and that the adjacent page is
untouched.
Keep page_pattern writable because init_page() fills it with memset();
declaring it const triggers a discarded-qualifier compiler warning.
Qoder, an AI coding assistant, helped identify the build warning and review
the test-buffer lifecycle.
Signed-off-by: Ruidong Tian <tianruidong@linux.alibaba.com>
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
lib/tests/memcpy_kunit.c | 67 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 66 insertions(+), 1 deletion(-)
diff --git a/lib/tests/memcpy_kunit.c b/lib/tests/memcpy_kunit.c
index d36933554e46..8bcaaf9ab1ea 100644
--- a/lib/tests/memcpy_kunit.c
+++ b/lib/tests/memcpy_kunit.c
@@ -493,6 +493,67 @@ static void memmove_overlap_test(struct kunit *test)
}
}
+/* --- Page-sized copy tests --- */
+
+static u8 page_src[PAGE_SIZE] __aligned(PAGE_SIZE);
+static u8 page_dst[PAGE_SIZE * 2] __aligned(PAGE_SIZE);
+static u8 page_pattern[PAGE_SIZE] __aligned(PAGE_SIZE);
+
+static void init_page(struct kunit *test)
+{
+ /* Get many bit patterns. */
+ get_random_bytes(page_src, PAGE_SIZE);
+
+ /* Make sure we have non-zero edges. */
+ set_random_nonzero(test, &page_src[0]);
+ set_random_nonzero(test, &page_src[PAGE_SIZE - 1]);
+
+ memset(page_dst, 0xA5, ARRAY_SIZE(page_dst));
+ memset(page_pattern, 0xA5, PAGE_SIZE);
+}
+
+static void copy_page_test(struct kunit *test)
+{
+ init_page(test);
+
+ /* Copy. */
+ copy_page(page_dst, page_src);
+
+ /* Verify byte-for-byte exact. */
+ KUNIT_ASSERT_EQ_MSG(test,
+ memcmp(page_dst, page_src, PAGE_SIZE), 0,
+ "copy_page content mismatch with random data");
+
+ /* Verify no overflow into second page. */
+ KUNIT_ASSERT_EQ_MSG(test,
+ memcmp(page_dst + PAGE_SIZE, page_pattern, PAGE_SIZE), 0,
+ "copy_page overflow into adjacent page");
+}
+
+#ifdef __HAVE_ARCH_COPY_MC_PAGE
+static void copy_mc_page_test(struct kunit *test)
+{
+ int ret;
+
+ init_page(test);
+
+ /* Copy and check return value. */
+ ret = copy_mc_page(page_dst, page_src);
+ KUNIT_ASSERT_EQ_MSG(test, ret, 0,
+ "copy_mc_page returned %d on clean memory", ret);
+
+ /* Verify byte-for-byte exact. */
+ KUNIT_ASSERT_EQ_MSG(test,
+ memcmp(page_dst, page_src, PAGE_SIZE), 0,
+ "copy_mc_page content mismatch with random data");
+
+ /* Verify no overflow into second page. */
+ KUNIT_ASSERT_EQ_MSG(test,
+ memcmp(page_dst + PAGE_SIZE, page_pattern, PAGE_SIZE), 0,
+ "copy_mc_page overflow into adjacent page");
+}
+#endif /* __HAVE_ARCH_COPY_MC_PAGE */
+
static struct kunit_case memcpy_test_cases[] = {
KUNIT_CASE(memset_test),
KUNIT_CASE(memcpy_test),
@@ -500,6 +561,10 @@ static struct kunit_case memcpy_test_cases[] = {
KUNIT_CASE_SLOW(memmove_test),
KUNIT_CASE_SLOW(memmove_large_test),
KUNIT_CASE_SLOW(memmove_overlap_test),
+ KUNIT_CASE(copy_page_test),
+#ifdef __HAVE_ARCH_COPY_MC_PAGE
+ KUNIT_CASE(copy_mc_page_test),
+#endif
{}
};
@@ -510,5 +575,5 @@ static struct kunit_suite memcpy_test_suite = {
kunit_test_suite(memcpy_test_suite);
-MODULE_DESCRIPTION("test cases for memcpy(), memmove(), and memset()");
+MODULE_DESCRIPTION("test cases for memcpy(), memmove(), memset() and copy_page()");
MODULE_LICENSE("GPL");
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v16 9/9] lib/tests: memcpy_kunit: add memcpy_mc() and memcpy_mc_large() test
2026-12-05 1:24 [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Jiangtian Feng
` (7 preceding siblings ...)
2026-12-05 1:24 ` [PATCH v16 8/9] lib/test: memcpy_kunit: add copy_page() and copy_mc_page() tests Jiangtian Feng
@ 2026-12-05 1:24 ` Jiangtian Feng
8 siblings, 0 replies; 10+ messages in thread
From: Jiangtian Feng @ 2026-12-05 1:24 UTC (permalink / raw)
To: catalin.marinas, will, akpm, rafael
Cc: mark.rutland, james.morse, robin.murphy, nikumbh.adi, tony.luck,
guohanjun, mchehab, lenb, xueshuai, tongtiangen, tianruidong,
tongweilin, baolin.wang, ashok.raj, jonathan.cameron, david,
liam, vbabka, rppt, mhocko, ljs, surenb, shivankg,
wangkefeng.wang, xiangzao, ying.huang, linmiaohe, nao.horiguchi,
ziy, tujinjiang, mgorman, kaitao.cheng, chengkaitao, muchun.song,
nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
usama.arif, kas, kees, andreyknvl, dvyukov, glider, ryabinin.a.a,
vincenzo.frascino, tglx, mingo, bp, dave.hansen, hpa, maddy, mpe,
npiggin, chleroy, ritesh.list, sshegde, aneesh.kumar,
naveen.n.rao, linux-arm-kernel, linux-acpi, linux-mm,
linux-hardening, kasan-dev, linuxppc-dev, x86, linux-kernel,
Jiangtian Feng
From: Ruidong Tian <tianruidong@linux.alibaba.com>
memcpy_mc() is the Machine-Check safe memcpy variant that returns the
number of bytes NOT copied on a hardware memory error, or 0 on success.
Add two test cases modeled after the existing memcpy_test() and
memcpy_large_test() implementations.
Signed-off-by: Ruidong Tian <tianruidong@linux.alibaba.com>
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
lib/tests/memcpy_kunit.c | 121 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 120 insertions(+), 1 deletion(-)
diff --git a/lib/tests/memcpy_kunit.c b/lib/tests/memcpy_kunit.c
index 8bcaaf9ab1ea..479fc9b880b3 100644
--- a/lib/tests/memcpy_kunit.c
+++ b/lib/tests/memcpy_kunit.c
@@ -554,6 +554,121 @@ static void copy_mc_page_test(struct kunit *test)
}
#endif /* __HAVE_ARCH_COPY_MC_PAGE */
+#ifdef __HAVE_ARCH_MEMCPY_MC
+/*
+ * memcpy_mc() is a Machine-Check safe memcpy variant.
+ * Signature: unsigned long memcpy_mc(void *dst, const void *src, size_t len)
+ * Returns: 0 on success, or number of bytes NOT copied on MC error.
+ *
+ * In the normal (no-poison) path it must behave identically to memcpy()
+ * and always return 0.
+ */
+static void memcpy_mc_test(struct kunit *test)
+{
+#define TEST_OP "memcpy_mc"
+ struct some_bytes control = {
+ .data = { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ },
+ };
+ struct some_bytes zero = { };
+ struct some_bytes middle = {
+ .data = { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ },
+ };
+ struct some_bytes three = {
+ .data = { 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ },
+ };
+ struct some_bytes dest = { };
+ unsigned long ret;
+ int count;
+ u8 *ptr;
+
+ /* Verify static initializers. */
+ check(control, 0x20);
+ check(zero, 0);
+ compare("static initializers", dest, zero);
+
+ /* Verify assignment. */
+ dest = control;
+ compare("direct assignment", dest, control);
+
+ /* Verify complete overwrite. */
+ ret = memcpy_mc(dest.data, zero.data, sizeof(dest.data));
+ KUNIT_ASSERT_EQ(test, ret, 0);
+ compare("complete overwrite", dest, zero);
+
+ /* Verify middle overwrite: 7 bytes at offset 12. */
+ dest = control;
+ ret = memcpy_mc(dest.data + 12, zero.data, 7);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+ compare("middle overwrite", dest, middle);
+
+ /* Verify zero-length copy is a no-op. */
+ dest = control;
+ ret = memcpy_mc(dest.data, zero.data, 0);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+ compare("zero length", dest, control);
+
+ /* Verify argument side-effects aren't repeated. */
+ dest = control;
+ ptr = dest.data;
+ count = 1;
+ ret = memcpy_mc(ptr++, zero.data, count++);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+ ptr += 8;
+ ret = memcpy_mc(ptr++, zero.data, count++);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+ compare("argument side-effects", dest, three);
+#undef TEST_OP
+}
+
+static void memcpy_mc_large_test(struct kunit *test)
+{
+ init_large(test);
+
+ /* Sweep 1..1024 bytes x shifting offset to cover all template paths. */
+ for (int bytes = 1; bytes <= ARRAY_SIZE(large_src); bytes++) {
+ for (int offset = 0; offset < ARRAY_SIZE(large_src); offset++) {
+ int right_zero_pos = offset + bytes;
+ int right_zero_size = ARRAY_SIZE(large_dst) - right_zero_pos;
+ int ret;
+
+ ret = memcpy_mc(large_dst + offset, large_src, bytes);
+ KUNIT_ASSERT_EQ_MSG(test, ret, 0,
+ "memcpy_mc returned %d with size %d at offset %d",
+ ret, bytes, offset);
+
+ /* No write before copy area. */
+ KUNIT_ASSERT_EQ_MSG(test,
+ memcmp(large_dst, large_zero, offset), 0,
+ "with size %d at offset %d", bytes, offset);
+ /* No write after copy area. */
+ KUNIT_ASSERT_EQ_MSG(test,
+ memcmp(&large_dst[right_zero_pos], large_zero,
+ right_zero_size), 0,
+ "with size %d at offset %d", bytes, offset);
+ /* Byte-for-byte exact. */
+ KUNIT_ASSERT_EQ_MSG(test,
+ memcmp(large_dst + offset, large_src, bytes), 0,
+ "with size %d at offset %d", bytes, offset);
+
+ memset(large_dst + offset, 0, bytes);
+ }
+ cond_resched();
+ }
+}
+#endif /* __HAVE_ARCH_MEMCPY_MC */
+
static struct kunit_case memcpy_test_cases[] = {
KUNIT_CASE(memset_test),
KUNIT_CASE(memcpy_test),
@@ -564,6 +679,10 @@ static struct kunit_case memcpy_test_cases[] = {
KUNIT_CASE(copy_page_test),
#ifdef __HAVE_ARCH_COPY_MC_PAGE
KUNIT_CASE(copy_mc_page_test),
+#endif
+#ifdef __HAVE_ARCH_MEMCPY_MC
+ KUNIT_CASE(memcpy_mc_test),
+ KUNIT_CASE_SLOW(memcpy_mc_large_test),
#endif
{}
};
@@ -575,5 +694,5 @@ static struct kunit_suite memcpy_test_suite = {
kunit_test_suite(memcpy_test_suite);
-MODULE_DESCRIPTION("test cases for memcpy(), memmove(), memset() and copy_page()");
+MODULE_DESCRIPTION("test cases for memcpy(), memmove(), memset(), copy_page() and memcpy_mc()");
MODULE_LICENSE("GPL");
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread