public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: Shuai Xue <xueshuai@linux•alibaba.com>
To: Ruidong Tian <tianruidong@linux•alibaba.com>,
	catalin.marinas@arm•com, will@kernel•org, rafael@kernel•org,
	tony.luck@intel•com, guohanjun@huawei•com, mchehab@kernel•org,
	tongtiangen@huawei•com, james.morse@arm•com,
	robin.murphy@arm•com, andreyknvl@gmail•com, dvyukov@google•com,
	vincenzo.frascino@arm•com, mpe@ellerman•id.au, npiggin@gmail•com,
	ryabinin.a.a@gmail•com, glider@google•com,
	christophe.leroy@csgroup•eu, aneesh.kumar@kernel•org,
	naveen.n.rao@linux•ibm.com, tglx@linutronix•de, mingo@redhat•com
Cc: linux-arm-kernel@lists•infradead.org, linux-mm@kvack•org,
	linuxppc-dev@lists•ozlabs.org, linux-kernel@vger•kernel.org,
	kasan-dev@googlegroups•com
Subject: Re: [PATCH v14 8/8] lib/tests: memcpy_kunit: add memcpy_mc() and memcpy_mc_large() test
Date: Thu, 28 May 2026 11:17:17 +0800	[thread overview]
Message-ID: <2e413153-c9e7-41dc-ad8e-522871381bf7@linux.alibaba.com> (raw)
In-Reply-To: <20260518084956.2538442-9-tianruidong@linux.alibaba.com>



On 5/18/26 4:49 PM, Ruidong Tian wrote:
> 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:

Same build issue as with copy_mc_page_test: memcpy_mc() is an arm64-
only symbol.

1. Cross-architecture build break (BLOCKER, same as patch 6)

    These tests are gated on CONFIG_ARCH_HAS_COPY_MC, which is also
    selected by x86_64 and ppc64. Neither architecture provides a
    memcpy_mc() symbol -- they use copy_mc_to_kernel() directly.

    On x86_64:

        lib/tests/memcpy_kunit.c: error: implicit declaration of
        function 'memcpy_mc' [-Werror=implicit-function-declaration]

    Fix: guard with __HAVE_ARCH_MEMCPY_MC instead:

        #ifdef __HAVE_ARCH_MEMCPY_MC
        static void memcpy_mc_test(...) { ... }
        static void memcpy_mc_large_test(...) { ... }
        #endif


> 
> Signed-off-by: Ruidong Tian <tianruidong@linux•alibaba.com>
> ---
>   lib/tests/memcpy_kunit.c | 113 ++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 112 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/tests/memcpy_kunit.c b/lib/tests/memcpy_kunit.c
> index 85df53ccfb0c..b4b2dafb50f1 100644
> --- a/lib/tests/memcpy_kunit.c
> +++ b/lib/tests/memcpy_kunit.c
> @@ -552,6 +552,115 @@ static void copy_mc_page_test(struct kunit *test)
>   		memcmp(page_dst + PAGE_SIZE, page_zero, PAGE_SIZE), 0,
>   		"copy_mc_page overflow into adjacent page");
>   }
> +/*
> + * memcpy_mc() is a Machine-Check safe memcpy variant.
> + * Signature: int 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 = { };
> +	int ret, 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, control.data, sizeof(dest.data));
> +	KUNIT_ASSERT_EQ(test, ret, 0);
> +	compare("complete overwrite", dest, control);
> +
> +	/* 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;
> +	memcpy(ptr++, zero.data, count++);
> +	ptr += 8;
> +	memcpy(ptr++, zero.data, count++);


    This is a verbatim paste from memcpy_test(). The intent is to
    verify that the memcpy_mc macro doesn't double-evaluate arguments,
    but the test doesn't actually call memcpy_mc(). Please change the
    two memcpy() calls to memcpy_mc() and assert their return values.

Thanks
Shuai


  reply	other threads:[~2026-05-28  3:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-18  8:49 [PATCH v14 0/8] arm64: add ARCH_HAS_COPY_MC support Ruidong Tian
2026-05-18  8:49 ` [PATCH v14 1/8] uaccess: add generic fallback version of copy_mc_to_user() Ruidong Tian
2026-05-27  9:16   ` Shuai Xue
2026-05-18  8:49 ` [PATCH v14 2/8] ACPI: APEI: GHES: use exception context to gate SIGBUS on poison consumption Ruidong Tian
2026-05-27  9:34   ` Shuai Xue
2026-05-18  8:49 ` [PATCH v14 3/8] arm64: add support for ARCH_HAS_COPY_MC Ruidong Tian
2026-05-27 11:35   ` Shuai Xue
2026-06-04  8:10     ` Ruidong Tian
2026-05-18  8:49 ` [PATCH v14 4/8] mm/hwpoison: return -EFAULT when copy fail in copy_mc_[user]_highpage() Ruidong Tian
2026-05-27 11:44   ` Shuai Xue
2026-05-18  8:49 ` [PATCH v14 5/8] arm64: support copy_mc_[user]_highpage() Ruidong Tian
2026-05-27 12:11   ` Shuai Xue
2026-05-18  8:49 ` [PATCH v14 6/8] lib/test: memcpy_kunit: add copy_page() and copy_mc_page() tests Ruidong Tian
2026-05-27 13:43   ` Shuai Xue
2026-05-18  8:49 ` [PATCH v14 7/8] arm64: introduce copy_mc_to_kernel() implementation Ruidong Tian
2026-05-28  3:10   ` Shuai Xue
2026-05-18  8:49 ` [PATCH v14 8/8] lib/tests: memcpy_kunit: add memcpy_mc() and memcpy_mc_large() test Ruidong Tian
2026-05-28  3:17   ` Shuai Xue [this message]
2026-05-18 15:05 ` [PATCH v14 0/8] arm64: add ARCH_HAS_COPY_MC support Kefeng Wang
2026-06-05  7:33   ` Ruidong Tian

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=2e413153-c9e7-41dc-ad8e-522871381bf7@linux.alibaba.com \
    --to=xueshuai@linux$(echo .)alibaba.com \
    --cc=andreyknvl@gmail$(echo .)com \
    --cc=aneesh.kumar@kernel$(echo .)org \
    --cc=catalin.marinas@arm$(echo .)com \
    --cc=christophe.leroy@csgroup$(echo .)eu \
    --cc=dvyukov@google$(echo .)com \
    --cc=glider@google$(echo .)com \
    --cc=guohanjun@huawei$(echo .)com \
    --cc=james.morse@arm$(echo .)com \
    --cc=kasan-dev@googlegroups$(echo .)com \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-mm@kvack$(echo .)org \
    --cc=linuxppc-dev@lists$(echo .)ozlabs.org \
    --cc=mchehab@kernel$(echo .)org \
    --cc=mingo@redhat$(echo .)com \
    --cc=mpe@ellerman$(echo .)id.au \
    --cc=naveen.n.rao@linux$(echo .)ibm.com \
    --cc=npiggin@gmail$(echo .)com \
    --cc=rafael@kernel$(echo .)org \
    --cc=robin.murphy@arm$(echo .)com \
    --cc=ryabinin.a.a@gmail$(echo .)com \
    --cc=tglx@linutronix$(echo .)de \
    --cc=tianruidong@linux$(echo .)alibaba.com \
    --cc=tongtiangen@huawei$(echo .)com \
    --cc=tony.luck@intel$(echo .)com \
    --cc=vincenzo.frascino@arm$(echo .)com \
    --cc=will@kernel$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox