Message ID | 20240125154608.720072-3-usama.anjum@collabora.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-38844-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp64770dyb; Thu, 25 Jan 2024 07:47:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmYT8HZAl1RYWp74Ed+SEzvv/gHna2voKOPEF+PDdS/hOpFwypYkDwiXAPofCxg/W5C1E9 X-Received: by 2002:a17:907:d308:b0:a27:4fe1:3084 with SMTP id vg8-20020a170907d30800b00a274fe13084mr656617ejc.133.1706197675440; Thu, 25 Jan 2024 07:47:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706197675; cv=pass; d=google.com; s=arc-20160816; b=QM3V0GSAhp8oe7UxxRazQKPwWasY8ZYguPtqrVLWev+2J2A8xmm1PaHvSiFu0RTzrw +cXNvE1LrXlxQF6WVKZHnVbitx72mRXKYyzhnQH3M2Z6iG220vqCI0mOIm2fKxHYLw2q sbarPYRRf/5I5tLoZAdpIKlWukG9KcPZlq/JC4DpVcFObXXSSlABlUnndzFz3GtRO3Q6 hBwTB6hVEg5ASlNCbY8nEZuAvLwGpQZpHMeqQ4PwRs82k+eKK2VabS+sZ5CYV3HtL5GG Du+LYLsSdxaIKkqn9mLmtRZD5Ue2Qv7JPrrF++/MXchHH4l0315trMReRE/mncWYdaCH JSYw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uilryMeodp0O80cLkN9ybFWwLPFVf+owRaEV1bjSCww=; fh=GI+QUBHPqwETgj91+OjmAHfGmBmxeZg5KGm08En4mD4=; b=nFImRNu9Cc+2H5l+4Sx2Bu0HGQ4AfFnVc38TRr5Zjcq75J7tnYarGnNN4vGLS+NL3r 13ixdU592CFLpTtcMucbH3x6N1rhbmPpYKgBPIhc3DCO5YA+LYrqxgq1JXx13Zfk2B4n KmHyMVwHMZjDIzbhL80MmaQifM3wedxY2oFLgtah8J7BzmmS/KADsqpvzlq5Wq24xmII IzWR0bYq+Ko/zgEFgS0UymF6rm+lp/Y+RXDpby1JyP/hhKU/0OUbag5tzfrdvvtMznBL nHkOmojyh+K4qvXEAWwRzs/YlhP8viGht8qI662YFW1EJL37JZ+YxBohYk1DKeL62muq ssPg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bWAq2bSV; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-38844-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38844-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id wp14-20020a170907060e00b00a315291679esi1071660ejb.1051.2024.01.25.07.47.55 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 07:47:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38844-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bWAq2bSV; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-38844-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38844-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 143C91F224D1 for <ouuuleilei@gmail.com>; Thu, 25 Jan 2024 15:47:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D381768F8; Thu, 25 Jan 2024 15:47:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="bWAq2bSV" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 946CD74E14; Thu, 25 Jan 2024 15:47:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706197625; cv=none; b=CcRCBT0RdqRkJHapaPl4SWXfGGEPnbHwkIwDBTY3JB/JMnC9KyYbzdycu4Nv8LgBlYWLGn7awThvdBEGzjew6ws6SFdWRT77h67H1i7zDhO/TYIx8Myg6UVAnSWgW5/38UHYCoWU8R7x9VPO6XmKmjtDVJHPd1/dgtMIMeb39pQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706197625; c=relaxed/simple; bh=gyo185f2D57JFqFMORChf4Ercnde+3pA9Al2pF3TwpA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fYOpurKjUGhBit38wYhd7LNEvLqPOa2lqqCRsUUoWndXrjuG2Hji7DwdhDQUHalMmawIIz1Dt4nd1TJyj9teS90n+ck6FZS2BaJ9/wAJ9cL0/pMTRqQMN7JbudTssU4raOmD+bWY5LlmG3sTFOEpK8L8hrkke4Q8RZJjCKMfYd0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=bWAq2bSV; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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 <usama.anjum@collabora.com> To: Andrew Morton <akpm@linux-foundation.org>, Shuah Khan <shuah@kernel.org> Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>, kernel@collabora.com, Ryan Roberts <ryan.roberts@arm.com>, 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789077933672043250 X-GMAIL-MSGID: 1789077933672043250 |
Series |
selftests/mm: Improve run_vmtests.sh
|
|
Commit Message
Muhammad Usama Anjum
Jan. 25, 2024, 3:46 p.m. UTC
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 <usama.anjum@collabora.com>
---
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(-)
Comments
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 <usama.anjum@collabora.com> > --- > 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 <string.h> > #include <sys/time.h> > #include <sys/resource.h> > +#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 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. > > CATEGORY="mmap" run_test ./map_populate >
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 <usama.anjum@collabora.com> >> --- >> 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 <string.h> >> #include <sys/time.h> >> #include <sys/resource.h> >> +#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 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. > >> >> CATEGORY="mmap" run_test ./map_populate >> > >
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 <usama.anjum@collabora.com> >>> --- >>> 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 <string.h> >>> #include <sys/time.h> >>> #include <sys/resource.h> >>> +#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 >>> >> >> >
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 <string.h> #include <sys/time.h> #include <sys/resource.h> +#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