Message ID | 20240209-kselftest-mm-check-deps-v1-1-19b09b151522@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-59931-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1109606dyd; Fri, 9 Feb 2024 12:23:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHc6jeafzO2g1JoKlrpKJcV5DkDTeUUPdzbjQqlGYjletk3unYg771kfI4EIuiJCbPEuvbh X-Received: by 2002:ac2:58c6:0:b0:511:6031:3f1c with SMTP id u6-20020ac258c6000000b0051160313f1cmr58525lfo.28.1707510192728; Fri, 09 Feb 2024 12:23:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707510192; cv=pass; d=google.com; s=arc-20160816; b=jNdQAQk+sN7nHdVk+1vZWdX1aKY4JJ3z9RBr9LmP+tzRLBAnX9NSi6e+XqZfewq3y3 5fTiqJPzPzzsMI7179lh+11pWGdCLFVeiZ0sNrqYtfxd4MqGlg0KFONRxvmi2zpZkfHJ bfRA87Dfqc8Yk1Y140RSI3GekQNzh7ZAqyytXtJ1gSTXgqPAjXgK1f0JIc8TC4gtPZK/ 3QeXGwF9CAhXpj8+qMy2hH9SDvXI6piJ0n9uaLuNJ41W4KA/5zSNS31keE0o9GR1oVNp IudaFOCxg4o95f3Ll7OP7Xv2hoZD+yyC5NwMTyqRiOcDqgQQRYNZWQ4sYHeTgiG8qnvl DGeQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=haTz7vGeTtUdMChm3Kq0XW4irGcp+LjPFH2fjf0bf2g=; fh=N//j4QT2O7ax4kyVIG32/mPiaik9BzN/knADIWUYIIg=; b=PEgqlV7EBDYDGhJqo041eY2jJiM+pKTJF1KGhz7c2ga7j2UCJ5oxej3yZAMyXA/cVZ 6ccvAdlSoSo+R+CoS6RuqtGpxKk35m48nAT8xFwmmo+xOiBvNBTEZQP5/7zXZJTuGKsk 2lVI/PN3Ttxw/501F79jWMj4UmrSjll/YqsZZi47Bw+MyB8m+/hn2iQ2xQKbZgeZ2Ktn XSSKKRQOyqwe3TYP7gXtNbrg1nALTKRvHV3OQ9L98zCrfPz7sf6KIrDHhNnDyeBK+hbC WiKJXhR3hnqEfDw86wmAr9PUwi5ACPfaRZ7pbdYKr+NsFJNvSCcAo8ZiV2nUrDVCiXu4 XBsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VILm83tG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-59931-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59931-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCX51rZmArEYZYa9qKAF1MaWJ50dYy6x01GBzwzH6nn0GzjI8y5hkV8k95l/5NNbl4ayDxZTV29kblUEzE25qn57F6pkHw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gb38-20020a170907962600b00a3c123f120bsi309806ejc.608.2024.02.09.12.23.12 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 12:23:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59931-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VILm83tG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-59931-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59931-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 506111F223A9 for <ouuuleilei@gmail.com>; Fri, 9 Feb 2024 20:23:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB6201272C3; Fri, 9 Feb 2024 20:22:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VILm83tG" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 14EF954F86; Fri, 9 Feb 2024 20:22:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707510177; cv=none; b=uPNr2QT5DPY9VkDnN05Fh5nnER0fmhx6rjXkJlJJxITslw9SabCwpnv3ISoyFn7Lu90sFv04KCLUQuBviL1VX4v/QYoFAVrHidm4R1I9rJZnsqezdKF1MdiPR/olSe5t/WC2QN8Xolc6PfrrFYnSTbpyr8GXLnVJotA7T3u/bwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707510177; c=relaxed/simple; bh=Vww2Jj+v4Z8QiE6rCC7eLelQulPvEW9AU9xCOOc5Lhs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=ed0kCbAEaC4u4EveY17jW4UP8t/1CYvK1IwqbCwIihpfKvI4U5/YTLofNR1xgtTm6I9C8M8QbimGJkk8YpcMjq+0Jq4CkY2Zc09DJcbXoHG8lYSFNM5/whnzTE3qcfu3WEXBguR/vuji7OtaPnZsJt2jQqEaZESaXZTgLrzh2po= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VILm83tG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19C39C433F1; Fri, 9 Feb 2024 20:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707510176; bh=Vww2Jj+v4Z8QiE6rCC7eLelQulPvEW9AU9xCOOc5Lhs=; h=From:Date:Subject:To:Cc:From; b=VILm83tG07I926TyXMoIq7o0EQH9hCwIgF/fp3XDX/JF2nr46v6yuLxuldO2ZvcOf J6asXPk7Hjegdp1jJKAfaQEIKcLZslgCR/ryNI6E7g0jEVFlKAJD2rWG3IgemaA/8F mx7RMzb0uFJ2MAtL2G/3/E5SfWXBJdYMwmm8v0Iu1wPIvbeN715hiH2iYUgrkISg7k 5AGJaT8k/lEanSJTYbIDHggvVcGWVlXEz/7st9y41Yt3P39MtWP1cXUZ71Y2PuyP+I sYfSY9Y0NEPSCIB0UkkqCV+WLfSCugyPjwoF89e8dy+My11N9jc31x6Dx+K5ZCxB+b zUcMIgipFn2uw== From: Mark Brown <broonie@kernel.org> Date: Fri, 09 Feb 2024 20:21:52 +0000 Subject: [PATCH] selftests/mm: Don't needlessly use sudo to obtain root in run_vmtests.sh 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240209-kselftest-mm-check-deps-v1-1-19b09b151522@kernel.org> X-B4-Tracking: v=1; b=H4sIAF+JxmUC/x3MSwqAMAxF0a1IxgZqUVC3Ig6kfdXgl0ZEEPduc XgG9z6kiAKlNnso4hKVfUso8ozcNGwjWHwyWWNLY03Ds2IJJ/TkdWU3wc3scSibYqhthSrAl5T qIyLI/Z+7/n0/aEhrBmkAAAA= To: Andrew Morton <akpm@linux-foundation.org>, Shuah Khan <shuah@kernel.org> Cc: Ryan Roberts <Ryan.Roberts@arm.com>, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown <broonie@kernel.org> X-Mailer: b4 0.13-dev-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=1989; i=broonie@kernel.org; h=from:subject:message-id; bh=Vww2Jj+v4Z8QiE6rCC7eLelQulPvEW9AU9xCOOc5Lhs=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlxomdxcmkOMP7U5xLlUuVTjCBZ0WrLPGtq+XfL 3p9ITNu54yJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZcaJnQAKCRAk1otyXVSH 0KH6B/9ApTHhrLOmnmotvLBAK11wu+cHt8ITHTFopBl8aopyk+Y7JyvT+YhnNUxRO8FrGN1labO 8apCpf/+yNMZD9meVzb92MkvfZjyXC3UqaEMva5dlT8adWtGeGBNHQoMen/OJiPm5Xz7taVADj4 itQgs/XjjLYGzZmj6hyA2ch15zqZgAs+uJZpX8nKXXuUkIjEkJFk0c6u5/0FGaHr7QBTFSJUsaG mPOH/CqmlDEUQQrtYxc+sKfUxMz+Czj7XmSZ3Fspo8k7CeQv6J8DpHklaV5Cv3SAK8taXiSx/eN xsEwQvOvjckH5GCqTeVhp6LVYowJlSr/2TnH+q3oWhqlcsoJ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790454207996365446 X-GMAIL-MSGID: 1790454207996365446 |
Series |
selftests/mm: Don't needlessly use sudo to obtain root in run_vmtests.sh
|
|
Commit Message
Mark Brown
Feb. 9, 2024, 8:21 p.m. UTC
When opening yama/ptrace_scope we unconditionally use sudo to ensure we
are running as root, resulting in failures if running in a minimal root
filesystem where sudo is not installed. Since automated test systems will
typically just run all of kselftest as root (and many kselftests rely on
this for full functionality) add a check to see if we're already root and
only invoke sudo if not.
Since I am unclear what the intended effect of the command being run is I
have not added any error handling for the case where we fail to obtain
root.
Signed-off-by: Mark Brown <broonie@kernel.org>
---
tools/testing/selftests/mm/run_vmtests.sh | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
---
base-commit: 445a555e0623387fa9b94e68e61681717e70200a
change-id: 20240209-kselftest-mm-check-deps-01a825e5fed4
Best regards,
Comments
On 09/02/2024 20:21, Mark Brown wrote: > When opening yama/ptrace_scope we unconditionally use sudo to ensure we > are running as root, resulting in failures if running in a minimal root > filesystem where sudo is not installed. Since automated test systems will > typically just run all of kselftest as root (and many kselftests rely on > this for full functionality) add a check to see if we're already root and > only invoke sudo if not. I don't really see the point of this. run_vmtests.sh needs to be run as root; there are lots of operations that depend on it and most tests will fail if not root. So I think it would be much cleaner just to remove this instance sudo. The problem that I was referring to yesterday, about needing sudo was for this case: CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit Here, we are using sudo to deprivilege ourselves from root and run on-fault-limit as nobody. This is required because the test is checking an rlimit that is only enforced for normal users. Somebody on list was talking about skipping this test if sudo wasn't present a couple of weeks back. Not sure if that happened. > > Since I am unclear what the intended effect of the command being run is I > have not added any error handling for the case where we fail to obtain > root. > > Signed-off-by: Mark Brown <broonie@kernel.org> > --- > tools/testing/selftests/mm/run_vmtests.sh | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh > index fe140a9f4f9d..c8ca830dba93 100755 > --- a/tools/testing/selftests/mm/run_vmtests.sh > +++ b/tools/testing/selftests/mm/run_vmtests.sh > @@ -248,6 +248,17 @@ run_test() { > > echo "TAP version 13" | tap_output > > +HAVE_ROOT=0 > +if [ "$(id -u)" = "0" ]; then > + AS_ROOT= > + HAVE_ROOT=1 > +elif [ "$(command -v sudo)" != "" ]; then > + AS_ROOT=sudo > + HAVE_ROOT=1 > +else > + echo # WARNING: Unable to run as root > +fi > + > CATEGORY="hugetlb" run_test ./hugepage-mmap > > shmmax=$(cat /proc/sys/kernel/shmmax) > @@ -363,7 +374,8 @@ CATEGORY="hmm" run_test bash ./test_hmm.sh smoke > # MADV_POPULATE_READ and MADV_POPULATE_WRITE tests > CATEGORY="madv_populate" run_test ./madv_populate > > -(echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope 2>&1) | tap_prefix > +# FIXME: What if we can't get root? > +(echo 0 | ${AS_ROOT} tee /proc/sys/kernel/yama/ptrace_scope 2>&1) | tap_prefix > CATEGORY="memfd_secret" run_test ./memfd_secret > > # KSM KSM_MERGE_TIME_HUGE_PAGES test with size of 100 > > --- > base-commit: 445a555e0623387fa9b94e68e61681717e70200a > change-id: 20240209-kselftest-mm-check-deps-01a825e5fed4 > > Best regards,
On Sat, Feb 10, 2024 at 07:40:16AM +0000, Ryan Roberts wrote: > On 09/02/2024 20:21, Mark Brown wrote: > > When opening yama/ptrace_scope we unconditionally use sudo to ensure we > > are running as root, resulting in failures if running in a minimal root > > filesystem where sudo is not installed. Since automated test systems will > > typically just run all of kselftest as root (and many kselftests rely on > > this for full functionality) add a check to see if we're already root and > > only invoke sudo if not. > I don't really see the point of this. run_vmtests.sh needs to be run as root; > there are lots of operations that depend on it and most tests will fail if not > root. So I think it would be much cleaner just to remove this instance sudo. Ah, I was assuming that some of the suite ran usefully as non-root given that the only point of that sudo was to acquire root. If the whole thing needs to be root then we should instead have a check for root at the top of run_vmtests.sh and just skip the whole thing if we aren't root, but then I'm unclear why it's invoking sudo in the first place. > The problem that I was referring to yesterday, about needing sudo was for this case: > CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit > Here, we are using sudo to deprivilege ourselves from root and run > on-fault-limit as nobody. This is required because the test is checking an > rlimit that is only enforced for normal users. > Somebody on list was talking about skipping this test if sudo wasn't present a > couple of weeks back. Not sure if that happened. Yes, there's a check: if command -v sudo &> /dev/null; then CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit else echo "# SKIP ./on-fault-limit" fi
On 10/02/2024 12:35, Mark Brown wrote: > On Sat, Feb 10, 2024 at 07:40:16AM +0000, Ryan Roberts wrote: >> On 09/02/2024 20:21, Mark Brown wrote: > >>> When opening yama/ptrace_scope we unconditionally use sudo to ensure we >>> are running as root, resulting in failures if running in a minimal root >>> filesystem where sudo is not installed. Since automated test systems will >>> typically just run all of kselftest as root (and many kselftests rely on >>> this for full functionality) add a check to see if we're already root and >>> only invoke sudo if not. > >> I don't really see the point of this. run_vmtests.sh needs to be run as root; >> there are lots of operations that depend on it and most tests will fail if not >> root. So I think it would be much cleaner just to remove this instance sudo. > > Ah, I was assuming that some of the suite ran usefully as non-root given > that the only point of that sudo was to acquire root. If the whole > thing needs to be root then we should instead have a check for root at > the top of run_vmtests.sh and just skip the whole thing if we aren't > root, but then I'm unclear why it's invoking sudo in the first place. I can't speak for how others use the suite, but there are a bunch of setup operations in the script itself that require root (e.g. reserving huge pages). Some of the tests will work without root, I'm sure, but I'm not sure its hugely valuable. Personally, I'd vote for just doing a test for root at the top, as you suggest. > >> The problem that I was referring to yesterday, about needing sudo was for this case: > >> CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit > >> Here, we are using sudo to deprivilege ourselves from root and run >> on-fault-limit as nobody. This is required because the test is checking an >> rlimit that is only enforced for normal users. > >> Somebody on list was talking about skipping this test if sudo wasn't present a >> couple of weeks back. Not sure if that happened. > > Yes, there's a check: > > if command -v sudo &> /dev/null; > then > CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit > else > echo "# SKIP ./on-fault-limit" > fi Ahh that's obviously been added in the last week. The version of mm-unstable I'm looking at doesn't have that. Although the skip message could do with being TAP-compliant.
On Mon, Feb 12, 2024 at 08:32:58AM +0000, Ryan Roberts wrote: > On 10/02/2024 12:35, Mark Brown wrote: > > Ah, I was assuming that some of the suite ran usefully as non-root given > > that the only point of that sudo was to acquire root. If the whole > > thing needs to be root then we should instead have a check for root at > > the top of run_vmtests.sh and just skip the whole thing if we aren't > > root, but then I'm unclear why it's invoking sudo in the first place. > I can't speak for how others use the suite, but there are a bunch of setup > operations in the script itself that require root (e.g. reserving huge pages). > Some of the tests will work without root, I'm sure, but I'm not sure its hugely > valuable. Personally, I'd vote for just doing a test for root at the top, as you > suggest. The hugetlb tests appear to be checking for root while running... I'm not super fussed either way myself, I don't really use these tests myself except in a general "keeping an eye on CI" kind of way so I'd not object if people wanted to just go for just requiring root for the whole thing.
On 12/02/2024 19:13, Mark Brown wrote: > On Mon, Feb 12, 2024 at 08:32:58AM +0000, Ryan Roberts wrote: >> On 10/02/2024 12:35, Mark Brown wrote: > >>> Ah, I was assuming that some of the suite ran usefully as non-root given >>> that the only point of that sudo was to acquire root. If the whole >>> thing needs to be root then we should instead have a check for root at >>> the top of run_vmtests.sh and just skip the whole thing if we aren't >>> root, but then I'm unclear why it's invoking sudo in the first place. > >> I can't speak for how others use the suite, but there are a bunch of setup >> operations in the script itself that require root (e.g. reserving huge pages). >> Some of the tests will work without root, I'm sure, but I'm not sure its hugely >> valuable. Personally, I'd vote for just doing a test for root at the top, as you >> suggest. > > The hugetlb tests appear to be checking for root while running... I'm > not super fussed either way myself, I don't really use these tests > myself except in a general "keeping an eye on CI" kind of way so I'd not > object if people wanted to just go for just requiring root for the whole > thing. My vote is to keep it simple and require root for the whole thing.
diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index fe140a9f4f9d..c8ca830dba93 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -248,6 +248,17 @@ run_test() { echo "TAP version 13" | tap_output +HAVE_ROOT=0 +if [ "$(id -u)" = "0" ]; then + AS_ROOT= + HAVE_ROOT=1 +elif [ "$(command -v sudo)" != "" ]; then + AS_ROOT=sudo + HAVE_ROOT=1 +else + echo # WARNING: Unable to run as root +fi + CATEGORY="hugetlb" run_test ./hugepage-mmap shmmax=$(cat /proc/sys/kernel/shmmax) @@ -363,7 +374,8 @@ CATEGORY="hmm" run_test bash ./test_hmm.sh smoke # MADV_POPULATE_READ and MADV_POPULATE_WRITE tests CATEGORY="madv_populate" run_test ./madv_populate -(echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope 2>&1) | tap_prefix +# FIXME: What if we can't get root? +(echo 0 | ${AS_ROOT} tee /proc/sys/kernel/yama/ptrace_scope 2>&1) | tap_prefix CATEGORY="memfd_secret" run_test ./memfd_secret # KSM KSM_MERGE_TIME_HUGE_PAGES test with size of 100