Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp45424rdb; Thu, 25 Jan 2024 07:51:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IECjrY0H1jEEVx1nC6+/NTqIDz1gERKaBpwVbBSm+8p1hWrhrv2/9t6dHrfcaMXAXINRmuI X-Received: by 2002:a17:903:1107:b0:1d8:877f:51d9 with SMTP id n7-20020a170903110700b001d8877f51d9mr1179989plh.8.1706197890109; Thu, 25 Jan 2024 07:51:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706197890; cv=pass; d=google.com; s=arc-20160816; b=Zd90PisSie/IWVrW6q3qqU4eg5b4AQUf3v4k0BpTZOyepQ0rLh1gxj/kLO3AacnwRY t7aPgRCDMNT/lRDb+FA7Huo+YtqHu56v5G5TLqxaTIYr36huLH2dI21vKSad1Q3EOwES vI0zRmoP3Z+lg1oBL6m6vE6lxpQwMWKAQnucvan/qs0W9gXXu+ncn8qKkEEPUotaT6lo 392go2nILUnCDu4fUVP2dxPGnJVDmnpNVqQoc4xCs0LTfA28eAJmdOYRzJTdTYgNSKBB xLPmkwrkhXda6u+HZ5LAnBkXYL+tJ7sloKJafd8LZ7b/bsuETkRjmToO0aTQ1Yp6Evig fOkw== 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=/Vt0auslnwTqOQlpWBRcRWAUjgRqu5psbNXLByWhXNA=; fh=GI+QUBHPqwETgj91+OjmAHfGmBmxeZg5KGm08En4mD4=; b=KurXd+AKeYRnZWSNQpxnfq0kKjQUKiczQTPImJR5KDxWWlt9f3HSE5LDViu614ry7y 0W2i61XL5bJkdjX/0NojSHeI+gMxVKpE8VHOVisrGo/arQ+V6c/IajooLQQTIvpTwRqF 0OtiQmWDhtYRycDs1DAzau+1okKnMpaBEcRCYTdX8a4ZlqTZEvajocbWoVb44caPvLsM /pDjG5bYMsw9epXFSN6kYEEyGzpq+iRmwW46F6kY1KjcGC+hJDLaWPpF5wyEuDMgFhZe A7Lql3xlYEoOD+sIjxTe/yx6i+WPN+l1EzA/g0mfwBe+1VPQ/SfWlaGSvihB28eLE3E7 Xgig== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=FrGw2wr9; 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-38846-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38846-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 k15-20020a170902c40f00b001d71213e8b2si1207944plk.508.2024.01.25.07.51.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 07:51:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38846-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=FrGw2wr9; 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-38846-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38846-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 3FFA8B24B99 for ; Thu, 25 Jan 2024 15:48:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DF9577F0C; Thu, 25 Jan 2024 15:47:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="FrGw2wr9" 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 E513A76906; Thu, 25 Jan 2024 15:47:09 +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=1706197631; cv=none; b=RxT5Zm/zxst2+2Kx8DntmQjjasamxSNj7BkK5uI8B3/SX2ick4R1OHd+A1Uj/TJEoT4e0CcPmHuLDRkhQVcOjeBl4d8PRqelxjXs2kt8CJ6H+MiU++qlDxH7Yd+RGKNQBBZsdznQjJWrtCXeITGS7Gevm3qdonASgqTu5ryrPeY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706197631; c=relaxed/simple; bh=VhAHDNe75pln/83b0IF4gK7LDikmUOQyoWwqkY00mK4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r2KBc3kkDLFe0oBhQt2gLdwTJemH+gOf2hKn14KDsmfqDNFzDgTT5qaudEb91pODfzj49fwiCO3UZddYicK6TDDfZ2l3qXcTGrt/WcrK69gcqU55RqQMK/L0faA9dqs8q02gAZ2XP5C522ruzSH0tTKA6+/EotWcuQivQCuw4Qs= 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=FrGw2wr9; 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=1706197628; bh=VhAHDNe75pln/83b0IF4gK7LDikmUOQyoWwqkY00mK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FrGw2wr9tOpj1o2El1l4vuB1W314NWo7egQbv93gBtqVgLnN9/8lMnVd5QEISk0i/ P+PfLP8Rf5Hs/DWxR8CntipCjFruIfWx4s/9b3OmhDoxgRlwQVzTpdWWU1e+R+nyQE aXoeOEZFU5n6MSvmzYxED9LKOtGTK6bV6SHBXUfvbZJXqWhH8okkJp9pUGGUKrFQqz vMyQtOMGlHzsBAd0G6l4tC6NWDSssISpgeq2vc5wZM3DPhzwZ91tKva1fIguYTAtqj 0YHgF9SMDHf7V/s98YMljk1yQh5tpUkoyagRJEuUlXESfzsMMqc+Ek0m7OPQ3ETE4+ ru1PKBGXn2I6w== 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 B314837820C2; Thu, 25 Jan 2024 15:47:05 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, Ryan Roberts , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/5] selftests/mm: protection_keys: save/restore nr_hugepages settings Date: Thu, 25 Jan 2024 20:46:07 +0500 Message-ID: <20240125154608.720072-5-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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