From: Joey Gouly <joey.gouly@arm.com>
To: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuah@kernel.org>,
kernel@collabora.com, Ryan Roberts <ryan.roberts@arm.com>,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 4/5] selftests/mm: protection_keys: save/restore nr_hugepages settings
Date: Wed, 13 Mar 2024 14:58:11 +0000 [thread overview]
Message-ID: <20240313145811.GA2896554@e124191.cambridge.arm.com> (raw)
In-Reply-To: <20240125154608.720072-5-usama.anjum@collabora.com>
Hi Muhammad,
On Thu, Jan 25, 2024 at 08:46:07PM +0500, Muhammad Usama Anjum wrote:
> Save and restore nr_hugepages before changing it during the test. A test
> should not change system wide settings.
>
> Fixes: 5f23f6d082a9 ("x86/pkeys: Add self-tests")
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> tools/testing/selftests/mm/protection_keys.c | 34 ++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c
> index 48dc151f8fca8..f822ae31af22e 100644
> --- a/tools/testing/selftests/mm/protection_keys.c
> +++ b/tools/testing/selftests/mm/protection_keys.c
> @@ -54,6 +54,7 @@ int test_nr;
> u64 shadow_pkey_reg;
> int dprint_in_signal;
> char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE];
> +char buf[256];
>
> void cat_into_file(char *str, char *file)
> {
> @@ -1744,6 +1745,38 @@ void pkey_setup_shadow(void)
> shadow_pkey_reg = __read_pkey_reg();
> }
>
> +void restore_settings_atexit(void)
> +{
> + cat_into_file(buf, "/proc/sys/vm/nr_hugepages");
> +}
> +
> +void save_settings(void)
> +{
> + int fd;
> + int err;
> +
> + if (geteuid())
> + return;
> +
> + fd = open("/proc/sys/vm/nr_hugepages", O_RDONLY);
> + if (fd < 0) {
> + fprintf(stderr, "error opening\n");
> + perror("error: ");
> + exit(__LINE__);
> + }
> +
> + /* -1 to guarantee leaving the trailing \0 */
> + err = read(fd, buf, sizeof(buf)-1);
> + if (err < 0) {
> + fprintf(stderr, "error reading\n");
> + perror("error: ");
> + exit(__LINE__);
> + }
> +
> + atexit(restore_settings_atexit);
> + close(fd);
> +}
> +
> int main(void)
> {
> int nr_iterations = 22;
> @@ -1751,6 +1784,7 @@ int main(void)
>
> srand((unsigned int)time(NULL));
>
> + save_settings();
> setup_handlers();
>
> printf("has pkeys: %d\n", pkeys_supported);
> --
> 2.42.0
>
This break the tests for me:
assert() at protection_keys.c::812 test_nr: 19 iteration: 1
running abort_hooks()...
This is because some of the tests fork, so on their atexit() they will set the
nr_hugepages back to the previous setting. Specifically the
test_pkey_alloc_exhaust() test.
Thanks,
Joey
next prev parent reply other threads:[~2024-03-13 14:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-25 15:46 [PATCH v3 0/5] selftests/mm: Improve run_vmtests.sh Muhammad Usama Anjum
2024-01-25 15:46 ` [PATCH v3 1/5] selftests/mm: hugetlb_reparenting_test: do not unmount Muhammad Usama Anjum
2024-01-25 15:46 ` [PATCH v3 2/5] selftests/mm: run_vmtests: remove sudo and conform to tap Muhammad Usama Anjum
2024-02-01 12:04 ` Ryan Roberts
2024-02-01 12:24 ` Muhammad Usama Anjum
2024-02-01 12:45 ` Ryan Roberts
2024-01-25 15:46 ` [PATCH v3 3/5] selftests/mm: save and restore nr_hugepages value Muhammad Usama Anjum
2024-01-25 15:46 ` [PATCH v3 4/5] selftests/mm: protection_keys: save/restore nr_hugepages settings Muhammad Usama Anjum
2024-03-13 14:58 ` Joey Gouly [this message]
2024-03-13 18:12 ` Muhammad Usama Anjum
2024-03-14 9:31 ` Joey Gouly
2024-01-25 15:46 ` [PATCH v3 5/5] selftests/mm: run_vmtests.sh: add missing tests Muhammad Usama Anjum
2024-02-01 12:11 ` Ryan Roberts
2024-02-01 12:26 ` Muhammad Usama Anjum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240313145811.GA2896554@e124191.cambridge.arm.com \
--to=joey.gouly@arm.com \
--cc=akpm@linux-foundation.org \
--cc=kernel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryan.roberts@arm.com \
--cc=shuah@kernel.org \
--cc=usama.anjum@collabora.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox