From mboxrd@z Thu Jan 1 00:00:00 1970 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 79D29C47DDF for ; Thu, 1 Feb 2024 12:45:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 012DB6B0080; Thu, 1 Feb 2024 07:45:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F04E56B0081; Thu, 1 Feb 2024 07:45:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF43A6B0082; Thu, 1 Feb 2024 07:45:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D0C136B0080 for ; Thu, 1 Feb 2024 07:45:33 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B131A160E68 for ; Thu, 1 Feb 2024 12:45:33 +0000 (UTC) X-FDA: 81743206146.11.55EC30D Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf04.hostedemail.com (Postfix) with ESMTP id A43D040021 for ; Thu, 1 Feb 2024 12:45:31 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706791532; 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=/0LIaEp8kHi47V6xNwWkOJuFbrRXImDm9NilErypsPg=; b=3RqAkm0k/TI/idgZv1Zi72WHMA+IVMAtOUMbptHtkBMC1dpAkGSefMjU1iZSR8eget3Uj6 viy/z7Hv/4Q/Y/eVC13lP0V1DnFKTljIRa5WL5qgKfNnlI28IoZBKZOkiofHyWMav0yfhq yZI0fgb/arhqhd1hB+ormszKa8Gvmp8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706791532; a=rsa-sha256; cv=none; b=KD1Ve1sW00dL4Dmrf5/5NF1RfBTGWRmaChLvv3NwEzmH1ZyLRDrsy0WxQoAfvudbEMehM5 qlS4lGeJyxl7R7mTvpeQfPYP0+dHO6EaH8Zt6wmUny3/EMa7VUFrCof4/JC/OmxXQuOnHh k7GFg5pfJIxmYNIvaTNwPowRR0KSb1I= 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 8AE57DA7; Thu, 1 Feb 2024 04:46:13 -0800 (PST) Received: from [10.57.79.60] (unknown [10.57.79.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D66863F762; Thu, 1 Feb 2024 04:45:29 -0800 (PST) Message-ID: Date: Thu, 1 Feb 2024 12:45:29 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/5] selftests/mm: run_vmtests: remove sudo and conform to tap Content-Language: en-GB To: Muhammad Usama Anjum , Andrew Morton , Shuah Khan Cc: kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240125154608.720072-1-usama.anjum@collabora.com> <20240125154608.720072-3-usama.anjum@collabora.com> <8a340f1a-20b5-4792-9bca-b9ed2d95d384@collabora.com> From: Ryan Roberts In-Reply-To: <8a340f1a-20b5-4792-9bca-b9ed2d95d384@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: A43D040021 X-Rspam-User: X-Stat-Signature: b8uwhunwrupwnxe13noampx739nj8rz7 X-Rspamd-Server: rspam01 X-HE-Tag: 1706791531-639354 X-HE-Meta: U2FsdGVkX18cPMDLMsE0gkqmGwZ6DG4BtMBdCxN63m8TPvCeJGYghi5m4zXBfWUjh4u1Q249ijY/IEVX9T3Fbt9PAqu148Yjths6ZvQohGK4TazR0DLzgNOSCrl2q70iSpnoDRekDVzMyUzcUiIa3LEiPIaVfBDdOficuIZf382dxOUQErhhChfNIUvkRUvcRbvM4knTmCIMhk7bt6faRzus77UiWKxzO6CGwMfA3+2jDhkjgj3QpeP9FhMh72g0Xn/JjymARTl9xPo6F5xrp6suO9lv+te5luuevJkWZsCdJjh+yiM4A1rQldIL/tOD+sOpxu5qQMuYP+CJC0TMCL5xak7AC5df8DZqz0F1jAu7pf41Oy83BAFbISO9xBwE3Z8mVFbl6WVBZIw1nVN/97wCbp6xpa2D1bej+WA1cY+8DGujjIYQQeHqyZZCessO0ulFNQKOf9CgLKnuA/A5GJGJobpriVhHw89UNSEqjW+sarat8Z9l3RDs1lsIeFBLX+6x6vRxhhv1zcJ+BYf52hiWY5OLwqkpEsJzaTUdQYYq3SjLSr2d0zv/S1/RqL9lSVyHYIBnXyRi2hec2cMdXCAXq/dQgBJateq0xN9ai5tdlc7x1lu83yjSwaaV7W8kpIhE+1AJalubDhCojNNMc7IB0/2/WNoyQfDznppm/N9Nc+L/qLAvgNsGsc90yHuO2bgAxweB8lFBPMfC6jnV5UjCc/uH71uu1/TL8poOuiUt7tK7Y90GopiMF0RCxAOSvX9mT3HEWLGf/1ylsrnzBRI+HBeWHL1nyUdMfA6Bj5cAvD5lrBo9b1tAe3vXbum5KBVtHhhRrrjvyXrfSXf5Dvjqr4zWB8dYmodeWxfwozWh3Z70hRsAxsSU05uajND6Qn4nsG55EwenJSaWiY7qmf35IXc1v60lE8diYO5zdFEq+7+EgZwxJJ/Al2ZZ+ur8Hd3bhxZQydDA+ZIOgP0 7CW7H9YO 1z7lS/tYEW8Gl1fXoU3g9qd2I3kyLaz6zge+1SHU0O4o+T+vWJaS8ShfXkQQlLHvjEVRWBd/6eTndG/4NRyOV2l5rhpE0F6ZrqgfSBviOnkGi243YHt3fQFexmua55VehUettarm76LFVABOS353qJl8Lj1yaE1AAceBllpphxNOuVq646vTm3B/uyd6FgkCBPVr6zZC6ZRLmJLP/ny1ncqdNvYMscGMNgTchJNNRUcjsi38k2422uojPOGXn+PkBxc8pgicMiXNtDkqjeLfJU7hWkh7+DblGMtK6Ulp/OiNRuHLlqzi0qI4AIA== 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: On 01/02/2024 12:24, Muhammad Usama Anjum wrote: > On 2/1/24 5:04 PM, Ryan Roberts wrote: >> On 25/01/2024 15:46, Muhammad Usama Anjum wrote: >>> 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"); > I'd sent a patch to fix this behavior today. This test should run without > root privileges. > https://lore.kernel.org/all/20240201071307.592317-1-usama.anjum@collabora.com > >>> + 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 >> >> I think changing this is going to give unintended results. run_vmtests.sh must >> already be running as root. "sudo -u nobody" is deprivieging the test to run as >> nobody. The rlimit is not enforced for root so this test must run unprivileged >> to work. See man page for getrlimit(): >> >> Since Linux 2.6.9, no limits are placed on the amount of memory that a >> privileged process may lock, and this limit instead governs the amount of >> memory that an unprivileged process may lock >> >> So I think the correct fix is actually to install sudo on your CI. > run_vmtests.sh is invoked without sudo with following: > make -C tools/testing/selftests/mm run_tests Unfortunately, I live in a world where my build machine isn't always the same as the target machine, so I'm not too familiar with this method of invocation. Regardless, the vast majority of the tests in run_vmtests.sh (as well as the configuration code in the script itself) require root. So invoking run_vmtests.sh as anything other than root is a BadIdea (TM). And when run_vmtests.sh is running as root, then you need the "sudo -u nobody" to deprivilege this particular test. > > Installing sudo in rootfs wouldn't be trivial enough on the CI side. > Alternatively, we can check if sudo is present before executing this test > to avoid error that sudo isn't found. Yeah, that's probably the easiest solution; just skip it if the requirements are not met. > >> >>> >>> CATEGORY="mmap" run_test ./map_populate >>> >> >> >