From patchwork Thu Jan 25 15:46:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13531195 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 BA85CC47258 for ; Thu, 25 Jan 2024 15:47:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47CEF6B0083; Thu, 25 Jan 2024 10:47:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3908C6B0087; Thu, 25 Jan 2024 10:47:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 209A36B0088; Thu, 25 Jan 2024 10:47:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0E79D6B0083 for ; Thu, 25 Jan 2024 10:47:05 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B6D2440884 for ; Thu, 25 Jan 2024 15:47:04 +0000 (UTC) X-FDA: 81718261968.01.3687950 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf13.hostedemail.com (Postfix) with ESMTP id 272D320008 for ; Thu, 25 Jan 2024 15:47:02 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=bWAq2bSV; spf=pass (imf13.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706197623; 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:in-reply-to:references:references:dkim-signature; bh=uilryMeodp0O80cLkN9ybFWwLPFVf+owRaEV1bjSCww=; b=AdY4/pFPl1jO/YY+5uf4ecdebVVApHbg3QmLYDV5tihE3rBUPp55jgHpf3jgSmeD4OObbS Mok5w12eS6hSIJBWpWOa5qWogBWh8bnAMiEswIbPPFO4ekD8lahg1TKjbWn41YoDOk5iT4 XrZQfjAqAyyS0zTliC6jnMsIUrZqgy0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706197623; a=rsa-sha256; cv=none; b=akycAkAnbEJHXfOg8CeMeya9xyyQnF+5T3P2u2cIODVBbiaWTarL5aw62DrdhuuAdCFdiV othyHUezOHlpfdWlB0YiJEPi9Wfh5nHNSTlpUiOgr4qLdhDkOHXav1+IpQ8byupwbN14pe HZGaPoj6Aspd4WMeewY4WpI60J5fXj0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=bWAq2bSV; spf=pass (imf13.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706197622; bh=gyo185f2D57JFqFMORChf4Ercnde+3pA9Al2pF3TwpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bWAq2bSVSNCidNYDMrbqrdFFYzZv9pb2h4iaMc9m0oz1yYUMZ04MoVMg2XeWwcSjo 0lU9piRePhdrqJu0+OY3mJdi3xxUuIbomGx8+n6jXUyeQprrjSxTls49AQcw1M8LK4 4SUMj9IdkpS1cA++zEsNfbx7qU+CcHReDQoDQBFjzv5h+UInk3WPc7lzNZJ4QqveJo DY7Svwdpco2q1EtJ+6cKdLlhsZCDDAKiYQiBnG2hwNXdwkW9O8h9Dh+REFQZPWiBov zSX4aH9PFjdu/KAgVspHZ/74zXc6rAJrDlZUAja8f8TiW+lnTZKPpYzwEwT/fzogGX wiUDegEf7obLw== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 757F237820C2; Thu, 25 Jan 2024 15:46:59 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, Ryan Roberts , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/5] selftests/mm: run_vmtests: remove sudo and conform to tap Date: Thu, 25 Jan 2024 20:46:05 +0500 Message-ID: <20240125154608.720072-3-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240125154608.720072-1-usama.anjum@collabora.com> References: <20240125154608.720072-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 272D320008 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: cz74or739crbf19isfqw513eypmqrf9g X-HE-Tag: 1706197622-480095 X-HE-Meta: U2FsdGVkX1/xokU5E3s736kJ4Da2m2HvOK+gcMTwIwz2JG1XAADUA1J5vQKVMhW4VlFBAG5Ab0kXrK2SZZKwc6DVSNVN3fEjEKYG4+r5fgLoyEVeH+7EfqUiK/CTbxddD8/iHPir1JV9Czwh/+0qSqfD1fsZXABianmDjeS6PtIvGkpSrJGp4OfxbIGx/pZRfP2vmDcpktSEOXu5gai5gy6Xt41ONH86dhPTyf2gdjlQBBfvCsl6Yty3y+4C0w1h5s9LyO5s3stNEv6Sv1/OChzsJ4a90WTVlqmKMvg7DCDFad01e7bh22kWaHoOdwa4yJKNvNFkVSMC1igZeEzasOcFhCapv6MUa/BytHkNhrnT6g3eb+2qih5aebk8vBWg2Klo0lQfjAD6trgVwmmAEuLL9B5ncZ0gqW+DWsntz3JmlqvVoUSj8eEgOmimjPmihEYzQB1yNc8nbeZdfsCemuRwWp4X4K+/m6hT1JUJgnIlUS0pwJ1k4TRTi2xcYTrrcinIVel3RgtYwGnhUCcu1Dvbp4vJXbUWO5PfdOn2w0RR/JQMPjc2MyRe+TFNpEIttSnjbBazGXvJsL78bCufHoTNnOlKs/jRFFsdVugPchRIovsJp5810dS5SbLDeAtmOtnKtHrCPrB25AZXdBMvNSp5/IsHs/5/jDdMlR+WzLgYQevXA9NhzeEP2LoiwxadHctcWdLDm2GiOBCv/PeA9NORjmn5D5CAdRvZaqik51HYiJDp7/rna8XRdGUTEXTY140+z1Y9gVdzu5FkxbSYzHlJdAwuk07jFGYYI45CgCdd5PGRvKeZKlAW8aYVFmFvNMS3d/7UxUTx+fXDs/cCAIsEglE6tfBJifjZNR4jQUEEMab0vfZBtLrcyaN8sq6oUjijQYRd+/Uqurkxerb/+eWej7LWJxup2p1BDErYOIk3cmVfwuBUZ0vpNGpeiSSwn3Xd2EbeLmfy0dXFOmQ WDAJzoHd 6g0IFICdHW36fLDY= 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: Remove sudo as some test running environments may not have sudo available. Instead skip the test if root privileges aren't available in the test. Signed-off-by: Muhammad Usama Anjum --- Changes since v1: - Added this patch in v2 We are allocating 2*RLIMIT_MEMLOCK.rlim_max memory and mmap() isn't failing. This seems like true bug in the kernel. Even the root user shouldn't be able to allocate more memory than allowed MEMLOCKed memory. Any ideas? --- tools/testing/selftests/mm/on-fault-limit.c | 36 ++++++++++----------- tools/testing/selftests/mm/run_vmtests.sh | 2 +- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/mm/on-fault-limit.c b/tools/testing/selftests/mm/on-fault-limit.c index b5888d613f34e..0ea98ffab3589 100644 --- a/tools/testing/selftests/mm/on-fault-limit.c +++ b/tools/testing/selftests/mm/on-fault-limit.c @@ -5,40 +5,38 @@ #include #include #include +#include "../kselftest.h" -static int test_limit(void) +static void test_limit(void) { - int ret = 1; struct rlimit lims; void *map; - if (getrlimit(RLIMIT_MEMLOCK, &lims)) { - perror("getrlimit"); - return ret; - } + if (getrlimit(RLIMIT_MEMLOCK, &lims)) + ksft_exit_fail_msg("getrlimit: %s\n", strerror(errno)); - if (mlockall(MCL_ONFAULT | MCL_FUTURE)) { - perror("mlockall"); - return ret; - } + if (mlockall(MCL_ONFAULT | MCL_FUTURE)) + ksft_exit_fail_msg("mlockall: %s\n", strerror(errno)); map = mmap(NULL, 2 * lims.rlim_max, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0); + + ksft_test_result(map == MAP_FAILED, "Failed mmap\n"); + if (map != MAP_FAILED) - printf("mmap should have failed, but didn't\n"); - else { - ret = 0; munmap(map, 2 * lims.rlim_max); - } - munlockall(); - return ret; } int main(int argc, char **argv) { - int ret = 0; + ksft_print_header(); + ksft_set_plan(1); + + if (getuid()) + ksft_test_result_skip("Require root privileges to run\n"); + else + test_limit(); - ret += test_limit(); - return ret; + ksft_finished(); } diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index 246d53a5d7f28..e373d592dbf5c 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -291,7 +291,7 @@ echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages CATEGORY="compaction" run_test ./compaction_test -CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit +CATEGORY="mlock" run_test ./on-fault-limit CATEGORY="mmap" run_test ./map_populate