From patchwork Mon Nov 28 19:02:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 13057883 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 552EBC433FE for ; Mon, 28 Nov 2022 19:03:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6D706B0074; Mon, 28 Nov 2022 14:03:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A1DB86B0075; Mon, 28 Nov 2022 14:03:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BEC06B0078; Mon, 28 Nov 2022 14:03:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7E3DA6B0074 for ; Mon, 28 Nov 2022 14:03:15 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 40BF2120BE2 for ; Mon, 28 Nov 2022 19:03:15 +0000 (UTC) X-FDA: 80183773950.23.4BEB453 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf03.hostedemail.com (Postfix) with ESMTP id BF84D20025 for ; Mon, 28 Nov 2022 19:03:13 +0000 (UTC) Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.17.1.19/8.17.1.19) with ESMTP id 2ASI100O021099 for ; Mon, 28 Nov 2022 11:03:12 -0800 Received: from mail.thefacebook.com ([163.114.132.120]) by m0089730.ppops.net (PPS) with ESMTPS id 3m3f6ej26x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 28 Nov 2022 11:03:12 -0800 Received: from twshared21592.39.frc1.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 28 Nov 2022 11:03:11 -0800 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id D530210980373; Mon, 28 Nov 2022 11:02:58 -0800 (PST) From: Song Liu To: , CC: , , , , , , , Song Liu Subject: [PATCH bpf-next v5 3/6] selftests/vm: extend test_vmalloc to test execmem_* APIs Date: Mon, 28 Nov 2022 11:02:42 -0800 Message-ID: <20221128190245.2337461-4-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221128190245.2337461-1-song@kernel.org> References: <20221128190245.2337461-1-song@kernel.org> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: cK_onENshVx0mwnpagGsMBF38wGUFXHx X-Proofpoint-ORIG-GUID: cK_onENshVx0mwnpagGsMBF38wGUFXHx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-28_17,2022-11-28_02,2022-06-22_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669662193; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YxTb08SNMQ4JElTV17KkObjri9osXLkCju8go8Wp/ys=; b=4OtshCdrMo51wDe+jAS41JWA7UG3pl8LDWolhwLYfnzePWccPoKoGqtbAbg3Gi+60BDhru GZ+g8TCY2FznHNdwJkSDHhbRJnUJe1j7rV7mane0mWDASubs1KVSoDEhGzYMvwpgaBue9T dSXFxXO5SY8jOe0U8xhoLxA1ZJV/Y9o= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf03.hostedemail.com: domain of "prvs=3331966363=songliubraving@meta.com" designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=3331966363=songliubraving@meta.com" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669662193; a=rsa-sha256; cv=none; b=NDf5c+HVb7z8DrZujubMP8oFuiNHQJvG9Zv3CZhdjM0ypr1K1db4fQWvvhRGEMiz4kI37P ceCq58AL4+a/iboq4CdCjbC7IzdWXO/h+Hy4sWQtsVsXHYHkkUyV9UkFGpL1F4a1775+jQ jZuyxlGmHePUjZxcIdFwKxX2gwycqXg= X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf03.hostedemail.com: domain of "prvs=3331966363=songliubraving@meta.com" designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=3331966363=songliubraving@meta.com" X-Stat-Signature: djgxrnexi9oyyfguxdqa15qirmypbfni X-Rspamd-Queue-Id: BF84D20025 X-Rspamd-Server: rspam08 X-HE-Tag: 1669662193-819142 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add logic to test execmem_[alloc|fill|free] in test_vmalloc.c. No need to change tools/testing/selftests/vm/test_vmalloc.sh. Gate the export of execmem_* with DEBUG_TEST_VMALLOC_EXEMEM_ALLOC so they are only exported when the developers are running tests. Signed-off-by: Song Liu --- lib/test_vmalloc.c | 35 +++++++++++++++++++++++++++++++++++ mm/vmalloc.c | 12 ++++++++++++ 2 files changed, 47 insertions(+) diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c index cf7780572f5b..9c78f0693f59 100644 --- a/lib/test_vmalloc.c +++ b/lib/test_vmalloc.c @@ -50,6 +50,7 @@ __param(int, run_test_mask, INT_MAX, "\t\tid: 128, name: pcpu_alloc_test\n" "\t\tid: 256, name: kvfree_rcu_1_arg_vmalloc_test\n" "\t\tid: 512, name: kvfree_rcu_2_arg_vmalloc_test\n" + "\t\tid: 1024, name: execmem_alloc_test\n" /* Add a new test case description here. */ ); @@ -352,6 +353,39 @@ kvfree_rcu_2_arg_vmalloc_test(void) return 0; } +/* This should match the define in vmalloc.c */ +#define DEBUG_TEST_VMALLOC_EXEMEM_ALLOC 0 + +static int +execmem_alloc_test(void) +{ + int i; + + for (i = 0; i < test_loop_count; i++) { +#if DEBUG_TEST_VMALLOC_EXEMEM_ALLOC + /* allocate variable size, up to 64kB */ + size_t size = (i % 1024 + 1) * 64; + void *p, *tmp; + + p = execmem_alloc(size, 64); + if (!p) + return -1; + + tmp = execmem_fill(p, "a", 1); + if (tmp != p) + return -1; + + tmp = execmem_fill(p + size - 1, "b", 1); + if (tmp != p + size - 1) + return -1; + + execmem_free(p); +#endif + } + + return 0; +} + struct test_case_desc { const char *test_name; int (*test_func)(void); @@ -368,6 +402,7 @@ static struct test_case_desc test_case_array[] = { { "pcpu_alloc_test", pcpu_alloc_test }, { "kvfree_rcu_1_arg_vmalloc_test", kvfree_rcu_1_arg_vmalloc_test }, { "kvfree_rcu_2_arg_vmalloc_test", kvfree_rcu_2_arg_vmalloc_test }, + { "execmem_alloc_test", execmem_alloc_test }, /* Add a new test case here. */ }; diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 1f7f2134f9bd..95ee8282b66c 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3387,6 +3387,9 @@ static void move_vmap_to_free_text_tree(void *addr) spin_unlock(&free_text_area_lock); } +/* This should match the define in test_vmalloc.c */ +#define DEBUG_TEST_VMALLOC_EXEMEM_ALLOC 0 + /** * execmem_alloc - allocate virtually contiguous RO+X memory * @size: allocation size @@ -3459,6 +3462,9 @@ void *execmem_alloc(unsigned long size, unsigned long align) kmem_cache_free(vmap_area_cachep, va); return NULL; } +#if DEBUG_TEST_VMALLOC_EXEMEM_ALLOC +EXPORT_SYMBOL_GPL(execmem_alloc); +#endif void __weak *arch_fill_execmem(void *dst, void *src, size_t len) { @@ -3510,6 +3516,9 @@ void *execmem_fill(void *dst, void *src, size_t len) spin_unlock(&vmap_area_lock); return ERR_PTR(-EINVAL); } +#if DEBUG_TEST_VMALLOC_EXEMEM_ALLOC +EXPORT_SYMBOL_GPL(execmem_fill); +#endif static struct vm_struct *find_and_unlink_text_vm(unsigned long start, unsigned long end) { @@ -3633,6 +3642,9 @@ void execmem_free(void *addr) out: spin_unlock(&free_text_area_lock); } +#if DEBUG_TEST_VMALLOC_EXEMEM_ALLOC +EXPORT_SYMBOL_GPL(execmem_free); +#endif /** * vmalloc_huge - allocate virtually contiguous memory, allow huge pages