Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1948925lql; Wed, 13 Mar 2024 12:45:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXkAhW8B5ELgK4uTkpZqHa5cmeHSqi8K1a7exOG+prVOmJMcyqiIMzGGB6PmbzQAGzC4NoQ0s67cbIOO8jURUojlb/acac2cdbHYGJArg== X-Google-Smtp-Source: AGHT+IEFMzXHmQ4Vst/cxCe7xignvZ0fsCOkty40dvW20lCa3+6JNJLEKDv88NnCmyxLXsf9pX7l X-Received: by 2002:a05:6a00:9388:b0:6e6:9ae5:f635 with SMTP id ka8-20020a056a00938800b006e69ae5f635mr3744151pfb.8.1710359138084; Wed, 13 Mar 2024 12:45:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710359138; cv=pass; d=google.com; s=arc-20160816; b=0LBDJ+3KLXmBexZsSfsdvyQQHLIfoc7tMBqjkJjjkzZjk81ZhcQFCYnw5rpQbdscjg En6R/+AlAXohrI2DHjFpV11MM4YSiFgsbi4XyBQDM38GbUTB+9ExtrONvlceKFWZRTk9 /wxk+qE0HfMLpgsmAUB5EEWMOKTw9K3TZ+bj7rFlVyIRi0Psq3GK7mp8eZHVHfCgRpXP edXZXeuFI8O8Gki402mgvNf7Reql3ulSWSW/4oLD+QZn3U6M2SLVvQFMgStN7Mx50Jk/ GFAEpfiK6POwopU9mSh/6MpaTBUePoY7RD4IoIep0ZHaeMzDDGO6hOWG5o1kjwE+sLh6 YRyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:cc:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=E5EATbr7ik6BdyfS1f5n+IQYWvgzlzVXxY9x4afcmOc=; fh=Z0cJ23kDmR8E3SYVmUhqTd5lpif939KJHnLJuQVmQq4=; b=SSrZ1MnVy7D+JxXB1G263leIP541uufCEcDzirCkDhS1f3xmgYxBCPHNYHJdVI75iz eotJLESh8Z1o2HSE307uIQVsKvIgwOxpdnvvZzZ+JFFoVKIQ42n7LTQwP+q2RAfhKucn NSgfyDo8YofP9r/n7Hc24AMDVAX1CtAWwXP7wwCFKiRhHFQxrFBgpTLPFTjwGyOH7PEZ 3FsWWmTBymR5SrH7o362JncV0rPQ/VKDg7vdcbTx71XOnwL1sa3OeGZSK7pklBrL6evd /FUs0gjAUOPIq+bZJHpIqGg6rPaJRWYlk7FrQBoh3mJnBwflz0N9NgXU9iBC+T++T5R1 nLKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=HF+a7X5l; 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-102337-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102337-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ei6-20020a056a0080c600b006e65739f8c1si9478092pfb.347.2024.03.13.12.45.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 12:45:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102337-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=HF+a7X5l; 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-102337-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102337-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8BA50B2EF81 for ; Wed, 13 Mar 2024 19:03:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E5BEF6A8D9; Wed, 13 Mar 2024 18:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="HF+a7X5l" 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 4F2886A8BA; Wed, 13 Mar 2024 18:12:33 +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=1710353555; cv=none; b=RRdnioLwxn6sQhhQ74Xn+ODthZSz0CtipgYIWMqE0M8Rf6kk6IFb15PFfYPheJyHfSpklhdTiyHUdu+8s14wORmibI/BQqOl/zna/81rOj5nMuVjjS4YIPqdYxDCst2Sq/Gc0G2ZGIcnQBE8UKHRpLJQiwmzssfCWYjbpwvFEdU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710353555; c=relaxed/simple; bh=msE+LoodrnJuR41WimKwSvVNdBUojEMdM6lEeYgLaLE=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=NAO8G6ZEzWGhxfE0UcJVxmiZTU6QJ212g2/2mhnhTvD0e1wb5yoxFVcsE1HlLm9sSPET3dbg4b81HjP1yPJFnWHZDNdnIZNpp1Cf2zeiF72KX4A/dJxgSC6j9wIUUCKlPn3tErJ3aqqSDuoNuCrN4FtgEnaJt74QYH39qKrPkw0= 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=HF+a7X5l; 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=1710353551; bh=msE+LoodrnJuR41WimKwSvVNdBUojEMdM6lEeYgLaLE=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=HF+a7X5lXjnxaIDWE/8k8QRhMGELdabzRPU9htidGUlZ/EkTMOnUa2qc40ZRT3e5v PXC1jq4Zty8ILQfh1SXwhw9ef53eHANm63bltn1VsnnJpWbj8AimTd/hTRX+MehWL2 N5VuZOLXcOb7nlGDoKOCTYK5UYa8sSeN1Yb/JVAn25GMy91aMtu5Ay5EUZEovc3Wy6 ERV6xwp0yoPWRhiCe3z7nbem9T2YSM+9Ho6xace7PVCBt6ttEEtMxKRlR2dpoVStrY sBFyGkwe2sSDtEai0T0RRdfJz9fgPUO1+dBd0mnz6dvvAJ5RmoCcifOM4/05w3lRTq To+iwhhdmvJxg== Received: from [10.193.1.1] (broslavsky.collaboradmins.com [68.183.210.73]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 3126537802F2; Wed, 13 Mar 2024 18:12:26 +0000 (UTC) Message-ID: Date: Wed, 13 Mar 2024 23:12:58 +0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: Muhammad Usama Anjum , Andrew Morton , Shuah Khan , kernel@collabora.com, Ryan Roberts , 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 To: Joey Gouly References: <20240125154608.720072-1-usama.anjum@collabora.com> <20240125154608.720072-5-usama.anjum@collabora.com> <20240313145811.GA2896554@e124191.cambridge.arm.com> Content-Language: en-US From: Muhammad Usama Anjum In-Reply-To: <20240313145811.GA2896554@e124191.cambridge.arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/13/24 7:58 PM, Joey Gouly wrote: > 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 >> --- >> 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. Thank you for reporting. Please can you test the following patch: --- a/tools/testing/selftests/mm/protection_keys.c +++ b/tools/testing/selftests/mm/protection_keys.c @@ -1745,9 +1745,12 @@ void pkey_setup_shadow(void) shadow_pkey_reg = __read_pkey_reg(); } +pid_t parent_pid; + void restore_settings_atexit(void) { - cat_into_file(buf, "/proc/sys/vm/nr_hugepages"); + if (parent_pid == getpid()) + cat_into_file(buf, "/proc/sys/vm/nr_hugepages"); } void save_settings(void) @@ -1773,6 +1776,7 @@ void save_settings(void) exit(__LINE__); } + parent_pid = getpid(); atexit(restore_settings_atexit); close(fd); } > > Thanks, > Joey > -- BR, Muhammad Usama Anjum