From patchwork Fri Apr 19 11:50:27 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: 13636308 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 A4E59C4345F for ; Fri, 19 Apr 2024 11:50:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FE456B0085; Fri, 19 Apr 2024 07:50:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1ADDD6B0088; Fri, 19 Apr 2024 07:50:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 057BB6B0089; Fri, 19 Apr 2024 07:50:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D96D96B0085 for ; Fri, 19 Apr 2024 07:50:09 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5AB041C1531 for ; Fri, 19 Apr 2024 11:50:09 +0000 (UTC) X-FDA: 82026112938.13.F5A679B Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf04.hostedemail.com (Postfix) with ESMTP id 3B17A40010 for ; Fri, 19 Apr 2024 11:50:06 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=FlJAu8fM; spf=pass (imf04.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=1713527406; 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:references:dkim-signature; bh=z9WIM6YavLTQP91U7MIc+stBgKRj4iLdvQwcWSz5yMo=; b=x+HHdBW2gPUEUk5h7yYEn6qowFGrcxjcCuBDDU83qQfq1pFtZGp9WUU/aNTYFknsL6FZlF igJlvM0KADTt5Ud6BXw/Ky1Btk99me7SRrbuvf2SGeZWOwEPmEHR2evVTd1a0fZ09JUxSG G+G5c0AUcoX2B5Ttk3AZElJD1bx8hLQ= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=FlJAu8fM; spf=pass (imf04.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=1713527406; a=rsa-sha256; cv=none; b=Mz8GCN/cdQ3yROUSGej0hmC5hpA3jQwq/ljxeLTyicklXjh+f34UKNAfuztNwvyRv/4X74 ZWwB330TBo1KNhh70cFRPT9AJS8t4KQhcuT5cut0z075gA2mTqk0nE9gp3D3dw8z+VZp0Y CRIgLFEEvKcqsQOKPuoHLsnSY9Y40ko= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1713527404; bh=Lep34Beis5C2ihwH+Dc5DzCkhyzByh/1RyjpIIWrCf0=; h=From:To:Cc:Subject:Date:From; b=FlJAu8fMvcBak3ke9sp8Ks2GnEYU/NmHOnQcAFdOzNcwCHpIbjM32jwOdl9axlvmV fyHkSXvfa+bmxWoj/ssL4MmdQ+oKK2gOu4Efn4B+n/pNiTUn+lhFZTxHuu/oieYpfI lb14UsrWh0T+fHyHYx7L6g6Bn29GOL4t3w3SEueYGWa01LoN9lPO9Tn3m0147Hal+G 2VrPIBhgtUieTPiUjnTJSfl/VrHzbYazcI3yOjgeVJO/PDgt8RJFIXZUYIOBdV0qqC z1UcE3SS3dv2ItyrMafEVg3JZE/I+zVf3SzFQvQFNKx8dsUygSbAod8JHvoE3NN6H5 OXT8xwapuKQwQ== Received: from localhost.localdomain (broslavsky.collaboradmins.com [68.183.210.73]) (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 919A7378214D; Fri, 19 Apr 2024 11:50:01 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan , Muhammad Usama Anjum Cc: kernel@collabora.com, Joey Gouly , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] selftests: mm: protection_keys: save/restore nr_hugepages value from launch script Date: Fri, 19 Apr 2024 16:50:27 +0500 Message-Id: <20240419115027.3848958-1-usama.anjum@collabora.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 3B17A40010 X-Stat-Signature: jrc7r4hy1os7dzgj3pan9tyqh4ric156 X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1713527406-665974 X-HE-Meta: U2FsdGVkX1/Oj/lrRHTmHqX2kv91MIFEz0ylH/oQcMrVDb5lIfj8HHoeO3zyBwxV+xW2OWp8mSrWdi+nNCzUJVj83y7PaLumXsjgYDGqmZqvLfLhO4n0d0V96LO85B2EXoThABEVbjTSeUjG9ImsB4TmUpDkk5xS9rd912mpdgI6vnqC2b9AUm7eMD+EgOa8zRnNSvw6CvwphQKuwIUTcgoIiQGjAG6K7YU7xDjIh32na7tLYDbSiRYC+CQ+mVprFWj/EWlydQj2rUgFaLcY3ADALy57nLsHBtJAOhi5rFBa2XZehtgO2eWYbZ3qX3BJft/Z+E/N43AhqlTB0d7BqYpUapSTV9lsTtK75iFTYrP0LBsKLxQ9EqddKHrk6vmg+rM2PvV+r4rOkMeLBfrvG7Vu5LZEofl5Yg3Z/p0W7Rt3XHjBAqFB95iHznoy82UlelRCRcwB/W5aUZZY/em+feFiJmiK2RvLobekBsZYm37kTtKEeYeXbxmJ7QVamP3Ups878RXfX7yvCmq4R6/VNOV327vjTEuGlHD4rjOXDoxW53Lxr3t7docmQuqbQb5wuQYsQ2KPjrJ/DJJ0a+J8z/4GnK4zRskHN4YsayULME1vB/PzN8tyTu81vEIrwr4F6i0X60EBEoB7Ks6wTLfTvH1zJZbyVI00ECt3ilcZQjxcVma7rZjJ1zS37kiDdFm5mmKd+ULSO84WZtf49RmgaQwoHt36HFq0AfqEeolRl9PvCNBl/SmQJvnrO7L0VapbtpdGHPFOJoGEsm+WAZZ/Qu9NtX/J6uMQnETw2efleK/6kqxjkZpuxH2fnUR3UQXbToWedhFDRjhAQuSe4qL9HWmRLY18PeBOwvicBlXDxq2JrGVjVfOZCGHdMGKihNZmr2eg6YhyzXFGObHzDaxD4PG8JDL3+eL+eCoIWkAg87EQfaLGrwbo7ze7pemfC2pYQChl1va+QELc47upwFG x2+26enM bz46vWNMbjlnXoDw= 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: The save/restore of nr_hugepages was added to the test itself by using the atexit() functionality. But it is broken as parent exits after creating child. Hence calling the atexit() function early. That's not it. The child exits after creating its child and so on. The parent cannot wait to get the termination status for its children as it'll keep on holding the resources until the new pkey allocation fails. It is impossible to wait for exits of all the grand and great grand children. Hence the restoring of nr_hugepages value from parent is wrong. Let's save/restore the nr_hugepages settings in the launch script instead of doing it in the test. Fixes: c52eb6db7b7d ("selftests: mm: restore settings from only parent process") Reported-by: Joey Gouly Closes: https://lore.kernel.org/all/20240418125250.GA2941398@e124191.cambridge.arm.com Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/protection_keys.c | 38 -------------------- tools/testing/selftests/mm/run_vmtests.sh | 2 ++ 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c index 374a308174d2b..48dc151f8fca8 100644 --- a/tools/testing/selftests/mm/protection_keys.c +++ b/tools/testing/selftests/mm/protection_keys.c @@ -54,7 +54,6 @@ 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) { @@ -1745,42 +1744,6 @@ void pkey_setup_shadow(void) shadow_pkey_reg = __read_pkey_reg(); } -pid_t parent_pid; - -void restore_settings_atexit(void) -{ - if (parent_pid == getpid()) - 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__); - } - - parent_pid = getpid(); - atexit(restore_settings_atexit); - close(fd); -} - int main(void) { int nr_iterations = 22; @@ -1788,7 +1751,6 @@ int main(void) srand((unsigned int)time(NULL)); - save_settings(); setup_handlers(); printf("has pkeys: %d\n", pkeys_supported); diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index 223c2304f885c..3157204b90476 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -390,6 +390,7 @@ CATEGORY="ksm_numa" run_test ./ksm_tests -N -m 0 CATEGORY="ksm" run_test ./ksm_functional_tests # protection_keys tests +nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages) if [ -x ./protection_keys_32 ] then CATEGORY="pkey" run_test ./protection_keys_32 @@ -399,6 +400,7 @@ if [ -x ./protection_keys_64 ] then CATEGORY="pkey" run_test ./protection_keys_64 fi +echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages if [ -x ./soft-dirty ] then