From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796433932; b=dXAuF7vnaGI6/ET3urZPyc7YGHg9/HaozzxlPtSNvyZHdZEYaqnU+ubIAhLz7enoOyzH 0bLvNPH6VDH1Xy8TTPbqlbXpX1OQ03+Iusq9/DpqhpKnf56BTiXnfD8TpGHbl5X1uT4dj PISbcyPE/8twd6PIW4c337aAxGEEtxiZqYTT8FHs9YGbiWB9XVqC+xgEtveExadGJUVdS GvG1BFhvoLRjbTXxntSkiZBVhvM+Cap7PWc1CXGIlKFyMN90EADmnCYgBdjUE9VDp0E3N i8BKjc7CURm+VotWKMNYRKJLKxrhegFYJJDpfyBofAJLRT5bnkEosK2IA4BHnsF4KNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796433932; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=oPf6hVQhTUbrqyGSP5YOOcAty6oI0S90rSTaBwOvGVE=; b=S/eLcupTrYDehMd8v4D3EySU+0NG6yj3nxnT8P3NcoqtPDc4CY9aT0tuQmUpeG0EZPrV 8IWfY/lNHRmyw8vei9N4eWCl9nsS09Ay2XxcImDSvW+TGE3paq5fgmlnE72mIwDN0PrrU anTgslVBOT+duOMuQQMtwx5F1xomHNVoVbpRvJZWnl5aPZuoPBsJ5Zs3pAwU3M8pbo6FV t75iMNm0QP685hnl7a6QvjWFMp8oUjTcTfEshRdqdPEcoBX/Lw5HJtr2MIE3naCCpU23h rhzeZ0nvnLOvC+fmvMM+QNl/dHOLFUQwV7/BXzn8v963S8ITHCnzxc+vvCwIJB6p9wA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=VoRvnUrQ; arc=none smtp.remote-ip=115.124.30.124 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FFF1606A32F; Sat, 5 Dec 2026 01:25:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5FFF1606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=VoRvnUrQ DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796433928; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=oPf6hVQhTUbrqyGSP5YOOcAty6oI0S90rSTaBwOvGVE=; b=VoRvnUrQhzp2cifN+x52YSSTYaoBpUX4/Y8/qorP9zKIk78IeBsKE9LP5iDSIY4Ijm6iDyElJ2DPnB5eQBJtUW5nAtjvP2Kq4TBPGn2QDsPmK/AeLoBBlVKghJvHKrChg+/YjFmdJGAb090ZNC8erBCQlRFJEivCN1QCMRhC9Xg= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R461e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033065142238;MF=jiangtianfeng@linux.alibaba.com;NM=1;PH=DS;RN=73;SR=0;TI=SMTPD_---0XGISFCU_1796433923; Received: from h68d07384.sqa.eu95.tbsite.net(mailfrom:jiangtianfeng@linux.alibaba.com fp:SMTPD_---0XGISFCU_1796433923 cluster:ay36) by smtp.aliyun-inc.com; Sat, 05 Dec 2026 09:25:25 +0800 From: Jiangtian Feng To: catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, rafael@kernel.org Cc: mark.rutland@arm.com, james.morse@arm.com, robin.murphy@arm.com, nikumbh.adi@gmail.com, tony.luck@intel.com, guohanjun@huawei.com, mchehab@kernel.org, lenb@kernel.org, xueshuai@linux.alibaba.com, tongtiangen@huawei.com, tianruidong@linux.alibaba.com, tongweilin@linux.alibaba.com, baolin.wang@linux.alibaba.com, ashok.raj@oss.qualcomm.com, jonathan.cameron@oss.qualcomm.com, david@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, mhocko@suse.com, ljs@kernel.org, surenb@google.com, shivankg@amd.com, wangkefeng.wang@huawei.com, xiangzao@linux.alibaba.com, ying.huang@linux.alibaba.com, linmiaohe@huawei.com, nao.horiguchi@gmail.com, ziy@nvidia.com, tujinjiang@huawei.com, mgorman@techsingularity.net, kaitao.cheng@linux.dev, chengkaitao@kylinos.cn, muchun.song@linux.dev, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, kees@kernel.org, andreyknvl@gmail.com, dvyukov@google.com, glider@google.com, ryabinin.a.a@gmail.com, vincenzo.frascino@arm.com, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com, aneesh.kumar@kernel.org, naveen.n.rao@linux.ibm.com, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, kasan-dev@googlegroups.com, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, Jiangtian Feng Subject: [PATCH v16 8/9] lib/test: memcpy_kunit: add copy_page() and copy_mc_page() tests Date: Sat, 5 Dec 2026 09:24:33 +0800 Message-ID: <20261205012435.1406255-9-jiangtianfeng@linux.alibaba.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205012435.1406255-1-jiangtianfeng@linux.alibaba.com> References: <20261205012435.1406255-1-jiangtianfeng@linux.alibaba.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ruidong Tian 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 Signed-off-by: Jiangtian Feng --- 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