From patchwork Tue Jan 7 14:29:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13929050 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 C205AE77197 for ; Tue, 7 Jan 2025 14:29:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 366146B00A2; Tue, 7 Jan 2025 09:29:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3158B6B00A4; Tue, 7 Jan 2025 09:29:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B4CF6B00A6; Tue, 7 Jan 2025 09:29:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id EA2E36B00A2 for ; Tue, 7 Jan 2025 09:29:48 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9A5D41609B4 for ; Tue, 7 Jan 2025 14:29:48 +0000 (UTC) X-FDA: 82980889656.19.0F468BA Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf02.hostedemail.com (Postfix) with ESMTP id F38BD80002 for ; Tue, 7 Jan 2025 14:29:46 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf02.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736260187; a=rsa-sha256; cv=none; b=wJEPLNtD01RH+pnKRKRH5sE1O1itlX0Ahv4ADAM02dZdzFzRatla8Qix/OBguffD01jigq 4jG34wjpkXq8umWEO/aBsz7Z4F2fHNiAWCK1azY3Xz0RHlQ2RRZcIHJpdyErmwbcMb13JR mj6FsPmNh1P38DCzOxBstK+03xNFKoY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf02.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736260187; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=Jkj5IVdv3mK5vW69KtvHyFjTpobFa70oxSJBez5lB3M=; b=0QdpFjSq9P52P4MvEFQoWE6OGPMV9EaTQDsC7f6klQs0WQWZGQpufp77fIH0c9Wz8sRAV4 VcWl2UeW5TpSVjhOxhQYqeGu3CCdPI3mTMQvMa+DSUJO620pBDnPBtGMKydbQjkvm/QE19 /B9BT/GgZzBaPqJjb6PJM0NhUPvU2cY= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 90A771424; Tue, 7 Jan 2025 06:30:14 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 355483F59E; Tue, 7 Jan 2025 06:29:45 -0800 (PST) From: Ryan Roberts To: Andrew Morton , Shuah Khan , Lorenzo Stoakes , Christian Brauner Cc: Ryan Roberts , linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1] selftests/mm: static process_madvise() wrapper for guard-pages Date: Tue, 7 Jan 2025 14:29:35 +0000 Message-ID: <20250107142937.1870478-1-ry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JPLE2geFJ+6S/+nD7qEEMLjR5qT9IM5nv5V0XmECaMkCnFP9n1Z9ArLAZXVWUy7F/RFU+uzaobFZEvyswrGAoY QOgCjA+o zOqFjUUBucdO7tU6vTG0jyBRW0mN8Ux3zJiXT299H57hzdlhYIzXAMd0aRs/bKu6TNtsasBuvuOplTXCEeDz3bZ+5e0qwQZ2MqsJGdCcBXjapIDoCjJ6rLd55G8DkHgQdvmMVtlxuEtM//mfxFKA9lLUrqxhkh3kQKxaFh/sFqDFvr3jbAyqeGsTz3cv88D+WWcd5qkiI4fGuHNw= 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: List-Subscribe: List-Unsubscribe: The recently introduced guard-pages mm selftest uses the process_madvise() syscall, a wrapper for which was added to glibc v2.36. For those of us stuck with older distributions this causes a compile error when compiling the mm selftests. For example Ubuntu 22.04 uses glibc 2.35, which does not have the wrapper. To workaround the issue, let's introduce our own static process_madvise() wrapper that uses glibc's syscall() helper. While we are at it, add the guard-page test suite to run_vmtests.sh so that it can be automatically run by CI systems. Signed-off-by: Ryan Roberts Reviewed-by: Lorenzo Stoakes --- Applies on top of mm-unstable (f349e79bfbf3) Thanks, Ryan tools/testing/selftests/mm/guard-pages.c | 10 ++++++++-- tools/testing/selftests/mm/run_vmtests.sh | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) -- 2.43.0 diff --git a/tools/testing/selftests/mm/guard-pages.c b/tools/testing/selftests/mm/guard-pages.c index d8f8dee9ebbd..ece37212a8a2 100644 --- a/tools/testing/selftests/mm/guard-pages.c +++ b/tools/testing/selftests/mm/guard-pages.c @@ -55,6 +55,12 @@ static int pidfd_open(pid_t pid, unsigned int flags) return syscall(SYS_pidfd_open, pid, flags); } +static ssize_t sys_process_madvise(int pidfd, const struct iovec *iovec, + size_t n, int advice, unsigned int flags) +{ + return syscall(__NR_process_madvise, pidfd, iovec, n, advice, flags); +} + /* * Enable our signal catcher and try to read/write the specified buffer. The * return value indicates whether the read/write succeeds without a fatal @@ -419,7 +425,7 @@ TEST_F(guard_pages, process_madvise) ASSERT_EQ(munmap(&ptr_region[99 * page_size], page_size), 0); /* Now guard in one step. */ - count = process_madvise(pidfd, vec, 6, MADV_GUARD_INSTALL, 0); + count = sys_process_madvise(pidfd, vec, 6, MADV_GUARD_INSTALL, 0); /* OK we don't have permission to do this, skip. */ if (count == -1 && errno == EPERM) @@ -440,7 +446,7 @@ TEST_F(guard_pages, process_madvise) ASSERT_FALSE(try_read_write_buf(&ptr3[19 * page_size])); /* Now do the same with unguard... */ - count = process_madvise(pidfd, vec, 6, MADV_GUARD_REMOVE, 0); + count = sys_process_madvise(pidfd, vec, 6, MADV_GUARD_REMOVE, 0); /* ...and everything should now succeed. */ diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index 2fc290d9430c..00c3f07ea100 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -45,6 +45,8 @@ separated by spaces: vmalloc smoke tests - hmm hmm smoke tests +- madv_guard + test madvise(2) MADV_GUARD_INSTALL and MADV_GUARD_REMOVE options - madv_populate test memadvise(2) MADV_POPULATE_{READ,WRITE} options - memfd_secret @@ -375,6 +377,9 @@ CATEGORY="mremap" run_test ./mremap_dontunmap CATEGORY="hmm" run_test bash ./test_hmm.sh smoke +# MADV_GUARD_INSTALL and MADV_GUARD_REMOVE tests +CATEGORY="madv_guard" run_test ./guard-pages + # MADV_POPULATE_READ and MADV_POPULATE_WRITE tests CATEGORY="madv_populate" run_test ./madv_populate