From patchwork Thu Jan 25 15:46:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13531197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99184C47258 for ; Thu, 25 Jan 2024 15:47:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F6C56B008C; Thu, 25 Jan 2024 10:47:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A5186B0092; Thu, 25 Jan 2024 10:47:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 147D16B0093; Thu, 25 Jan 2024 10:47:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 011786B008C for ; Thu, 25 Jan 2024 10:47:11 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5C7A0807DE for ; Thu, 25 Jan 2024 15:47:11 +0000 (UTC) X-FDA: 81718262262.05.A21822E Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf12.hostedemail.com (Postfix) with ESMTP id ACF4640026 for ; Thu, 25 Jan 2024 15:47:09 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=FrGw2wr9; spf=pass (imf12.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706197629; a=rsa-sha256; cv=none; b=w8OsyeMUt/vP+0jFw/OU73nlgnqYqthV7jRyCxW+vfnrAqtic4d4MZgltOPybl6BfnEWRh PDVk2Vm32tPunsyakwLXu0GjcNsFgaOVLfzLpoGarU25dR7P+vyVXzGl1NC/v3AVFgPlSH lorYJlU8TJlfFa3AH9LMO+6AxSZH5lM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=FrGw2wr9; spf=pass (imf12.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706197629; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/Vt0auslnwTqOQlpWBRcRWAUjgRqu5psbNXLByWhXNA=; b=1tNlf8X6V+i4Dt/soXJyS2CpiXe06pc7yDeA55cGm2tgvnsRtk3dBHPaAlYKB1vdrC+Nbi wfP/I9oQ4ArddBq3/qwNegeYH4ydQywngxt+8U0RMVxtpjR7Hd/SRDiYuiW55ifAWgTmoK Xa1hjHmXmSSrY7nVPacYR48ht72L374= 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> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: ACF4640026 X-Stat-Signature: ys61gb9faxu5761h15ghabirogcj3rzd X-Rspam-User: X-HE-Tag: 1706197629-786075 X-HE-Meta: U2FsdGVkX1+2uwWN2Xh4LvF0J9zgu8tMnKTOhRIs+sVQwQg4oYT5fr6dbaYsBqTZdpXSl+O8zD3+c3pz48aeRpWOfetWDO9FEgkzHzNvybgeDl51x70z2T6k/ybYXFuEMgN/5/E8NBLCIb747jBDdfmmxibcP4z3KSLCzLcZqWE5PMdZCSDYT9s6+3p8Rw5YdTPAuQVMhemEbvfp33tiihN4hv87oE83XQVBsOVGNvxGoIrVKXm2JbPG4aUuvQ+XkOCLXtQI0781TDPIMwQd1yoR9Gt+X3eNXPCPWltpS/TBaf8MspFjK1Wby93Kdk0tt2uUXZMy7mbi1XlfqnDKB2sQuSDJII8aIIs+pl5uzs8XfO8mc+YdkmdQ70CSZpAM7wkM3ZgDRjopIp/lDrt35i6BKrAb26ayiwugAW9hDrG0RvSMTW/Gl439BjUw0n812GNEjzZAyPdw/3OsIo4CtDGIWktQlbDccR0O/w/f3oinGwyjbt+lRypHAZzRB6RD4H0MhIpL/Xaax8typeSbuWHzopRKg7hVE53zHor9nzoTW7RMy5efDwq7V6ddC9fw6i4zaiphimveSOB4TTEwHY4iyLf0ms29r+z1+TbZoABUF+Ft42/KVPg4JxydAxsaML6KSg95Wb8lOppIG8bvii+9TCSo1LQUSy7iSsy67GW3CUb4BBniZofse0INzXt63BwIPjvIoUR/FoAapcznDv0z9NoJJzZqz5WEnFt4nQAHXlsZ8CqxX8l+6ZZXvEF+65bmrnG3K/925RO5WQna/0tFcNfHnG8jvnaHtMWFo5oHQPThBCKXBPhB1lya1jhCbGigqU9C1PjbwrIarRNgB1KXL1dVf/LRsqJ6vrpbomzmqGMqEBwOF5/5stV8Zcly44E1D8hq6LeCTyRUn4jpBZsWKf1nxrIdbuQGzymP1IGJIbkMuWVC/hxUVFyAr9MVeQWXq4VLK9Ytf2PimJ2 DcE5HrCj xr3YnLwwt1TU71ZROS7hLF+Fy3Cljx1tWpYo6esRAoP+dXCgBh1LxDxmTpUo5pow+O2Mb4qIpd+a3cl12e1zcck9jUCVWdwxU/tm7ady+EsWqV/EPenRYA8qnzuVeajhqTTxgze0MdnSVrJ9wT6KG8gv/T52mzxjj9PDaiJfSBdfyxWXPLNHuM9LspHh/o6AbwazJ0JaFIflcN5AWimylHEEQmjbOe5SeT4m9McWBX2tjTmNTmJTpuO/TotLF7gt2dP7Zj9ggL054stcNTd4t7Z8jk+GyRZyDZMb2B48oIZ90OIQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Tested-by: Joey Gouly --- 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);