Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1776922lql; Wed, 13 Mar 2024 07:58:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXSLtefIMtMDLvSL3F1p7AC74LG7dBYXCQr4qLv6UbAKlvRli14EkKjezob+LgRqVQPB0n4aUpjW1pfYyPJqeBZ4Q6Gnjxm5TR7R9dM/Q== X-Google-Smtp-Source: AGHT+IGzErvHYvSGCi52X9HlBronClM5Q8XmIFZE3TOI3bNn2kmY7HSy8oxXQRO6fPdA/hbhr/wD X-Received: by 2002:a05:6902:2681:b0:dcc:d3ab:2fc0 with SMTP id dx1-20020a056902268100b00dccd3ab2fc0mr2876551ybb.23.1710341905928; Wed, 13 Mar 2024 07:58:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710341905; cv=pass; d=google.com; s=arc-20160816; b=YzwaUW/ql+mNxVL9EeYYEXAhQC0V8/GwDEYf3XJol7ETBwt7QoeASeUO+yqfOexcO9 htLlclOsLh6dG9kqOOH3RwqR1Pi1RpVDihyaI5T41uhPKRp9TJAPGyaJEnhydN9/jb7W NPmCQvPzWD5+a+OkZeCCFwU7tLMjHYrg70xS5CpQ0w3/IKtM0LyVYvn5vONwlJYaVM2T XC8nUpu+/2i3KfHa11BQ/x5AQ28PTTU1RS8Altg1epB3pTJtg8EFFQihuxymAVYnUQ7G fpmI/N8VrFtPFOgx6n7LueOeijwpMJvd/KG4WK6PCaWLVgXAEHE4Ohgpu+t8htpHNs9W Z+jA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=SX8ccgDO/Ui84bL878+12q3n0HgyOtEKhBopQ/x+xgU=; fh=rh/yaYTbUjjkA1dtZju0cMyvUpMhU7LqGFl10CnFtjc=; b=hkFs59iPquFEUYB0E0qLIoRn/hOzNX6wCzVnJpBmc6y3UpNQWIpKGD8XS4ZeG6dqJz qSMsfMECOQ1jXTd19EE3TWvfxX8UxhuNwA72+SvCG70U3K23eh4ItU2wVFF/hnMoZs9Y ekYMmT9f83rADpHjWeNDCCcQxOjKP4nODi23Brj8HxmVQCGC7BK7MPc/ECggs88/CWov 240p0rCoTUk+2o/ianGckTz+8S642fr+yTJ1JcNalWS66qARHys3HV6nNX7KVhPoYYaR UW2VXKLgnphikYu1BkUAWzOgzrLwBlgSgUQ6/DTXX9HAAzutLltNL69XAFl2+dl/E+4B rdpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-101649-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101649-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c14-20020a05622a058e00b0042eee469474si9719839qtb.109.2024.03.13.07.58.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 07:58:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101649-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-101649-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101649-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8C23B1C2198A for ; Wed, 13 Mar 2024 14:58:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A714A44384; Wed, 13 Mar 2024 14:58:21 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F248D3D3A0; Wed, 13 Mar 2024 14:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710341901; cv=none; b=GbbFmOAxm3RJ/BW8tQ/DJqQ4ia4zOMnkvitUhTxSGFMQ9Kd8/OVS1t6wjDfVXlobmIsecFxhebhVoBw897WJyVGzmA6W3OHqhf49M9D+2HlTMeiIwW0cm3AMZRG2Q03eZl5MfHTC97bwC6l11+F/PppyZVheeKIAwBCCLGcBvQU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710341901; c=relaxed/simple; bh=QwvY0M4wqisbXnCkhZw0XjRtdAndOBgHcfzZ0EodrEQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MKi27qTngybxYCxanHsUWQ+8D2bf1YjYq1OuLgtFWYt1rj+kkJKCqQfY/RFh34G3+p8GDsukKLuqyWojv2XcHZLuXUCe1GWnc6pd/Qe5Ix1Zh08YMX32SHFILP0zTV2FzAhpO7F0M4oXWn8nwILgKaWkrGswFS3BT/K5AbdyI7k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C98AF1007; Wed, 13 Mar 2024 07:58:54 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C6FFD3F73F; Wed, 13 Mar 2024 07:58:16 -0700 (PDT) Date: Wed, 13 Mar 2024 14:58:11 +0000 From: Joey Gouly To: Muhammad Usama Anjum Cc: 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 Message-ID: <20240313145811.GA2896554@e124191.cambridge.arm.com> References: <20240125154608.720072-1-usama.anjum@collabora.com> <20240125154608.720072-5-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-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > --- > 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