Received: by 2002:ab2:5c0e:0:b0:1ef:a325:1205 with SMTP id i14csp268760lqk; Thu, 14 Mar 2024 02:32:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV5lz0X0kyO3KKtQ1rt2hcWdxASDByZC3e6hLIvWU3H267VYV58cliHZl1vdVYQ0S4Y6PAwpwicjIjCZT6CFleYG8ducAgbNKSMCyhTiw== X-Google-Smtp-Source: AGHT+IFe52bzJGlByF7mtDApwYq0k7k2msHpWv+FA65Jd68r2wgKpSZdRV+u56O/ZvwTbowxp6VA X-Received: by 2002:a05:6402:1f81:b0:568:9fc9:ec72 with SMTP id c1-20020a0564021f8100b005689fc9ec72mr52117edc.35.1710408767320; Thu, 14 Mar 2024 02:32:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710408767; cv=pass; d=google.com; s=arc-20160816; b=YxeGipjt/bRzi+E0m1bxHT3KnpkO2vy8eD+pJwr0gO7+Qt7+Y+z1nJClFgGCLZ+J7N qbQZLbOzk6MoQNXNj8+tsOJ7pPRU/4Ebj2NvnlKVlSTHr3LlFDWodoBoLS/eFz6GFJtb A6WUWFtW/64007xGD2/kONcdAkhrIKZCb2ooN7YM/L7CegzxaByp0VDtDZ931AFyW4dM A8HvTkBYc5ow++B0oA1neLZBnf3mM9y36cWamBHbIEUn9wEGEDDeZZZ7m02YydXjzNmp UPo6jklfL9F++25z9DXgNeJOGx7Jy6eHKtdbMPWCANdAW2MyOMsD9RX9ifOzIvsaQUOk lHcQ== 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=ElD7ZV89wMdNomPANITyD9nJyuyDpwx4OptZzBLJ5h0=; fh=rh/yaYTbUjjkA1dtZju0cMyvUpMhU7LqGFl10CnFtjc=; b=nXG0MLLLMIk4MA3q309XLrKOZRBO37dBc+nNbnTUecYTI2IDxMlVknXQYT3DWTF+eq 5FNmmi0OnVhUlCb2XZ3kU8KeDtUI1qCc+vEkmsTFsREByLTTr0bwwXRYolmAJ5ZqoMeL CMxmk3u3fLiPPyTqdu3w2WE6y82DFS5flpEOAsOV6q+dAXMaInElOYQgmwWi/K4IKFj7 yJNs4b2QeRojGdtCxJra16Y8Qsgv3WR6CuqEakGxsdG0FqmXwBkuaDmQYRA4nrCBQzJL i3leZXX1pw7EaEBHHpsjQtfqbHFEuMDt+0UeplPiK5q2vWiqy5ma0HCXLEu9r0Etvb2K 72Nw==; 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-103055-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103055-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w18-20020a05640234d200b0056850dd2268si564869edc.624.2024.03.14.02.32.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 02:32:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-103055-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-103055-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103055-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0FC801F21C5C for ; Thu, 14 Mar 2024 09:32:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E14D06E2A3; Thu, 14 Mar 2024 09:32:13 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6D7D6CDC8; Thu, 14 Mar 2024 09:32:10 +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=1710408733; cv=none; b=LhA+KKsPwLS4dfh+BdqBBieO21XxD6Z/XJDJOiLwuAEopqaps7yGHg0b9qOFtDKbbZXND2X73Zyr8emfasyeJaj7u3oQ2cMlPxEYKxvsH+1kE9MCrUW4NF703ctNuIn56cYQp/vW5ixmyyvV0+EvWTUWDSLN4tM/zUyUqoov7MM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710408733; c=relaxed/simple; bh=IiRqSA1zOuDlbi4cvqhX+73KjmiiLkECrRVJMoOMrR8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RTM7dQJTguwInw2zmH/hmRvMl1kIVPTL+k84hIKytDCP2TeNytT2Fg569IQOifBzTuwbLIZ2HvvhkGI2B2JwoKAoYc4qsMtkvzyJ2dKvCdRa8LYlELYb65Nd42CBNEJLBXLmnwzTiay/DI5ue+onKEFJ2J8jcbdd/VOYyiEww/k= 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 C12621007; Thu, 14 Mar 2024 02:32:40 -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 5499F3F762; Thu, 14 Mar 2024 02:32:03 -0700 (PDT) Date: Thu, 14 Mar 2024 09:31:55 +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: <20240314093155.GA3049647@e124191.cambridge.arm.com> References: <20240125154608.720072-1-usama.anjum@collabora.com> <20240125154608.720072-5-usama.anjum@collabora.com> <20240313145811.GA2896554@e124191.cambridge.arm.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: On Wed, Mar 13, 2024 at 11:12:58PM +0500, Muhammad Usama Anjum wrote: > 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, works for me: Tested-by: Joey Gouly