Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1765513rdb; Thu, 7 Dec 2023 08:13:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9BXhU+5zbOdyEJ9L0P6DpLUWlwV7yWGvyzDQRgDAax7j5DBW+fS0kYpa5KA32IjPd+FQR X-Received: by 2002:a17:903:11c3:b0:1d0:c888:d129 with SMTP id q3-20020a17090311c300b001d0c888d129mr2484543plh.103.1701965594874; Thu, 07 Dec 2023 08:13:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701965594; cv=none; d=google.com; s=arc-20160816; b=QkHqhtC/9ux2a+aO8y3mep4stpCKIEKyx/j66XsWprZW6J40ZqILvKYlOO3wZ61QC2 QheF9Gycgal/yqdSeNi0KIdwaoqKwS7iNrA7rg38LLm/y2C2TdUMhGSQPD2RMRUUJ8gs A2LHe8HHxNGs6viaIDLuXB19UXRpJR5AsxDnhoV8v4TiNuCyY2Faq19acSFsW6ZB8zpA ozpZ6ErHSVUt+nFeMbRTZJ21sUFDutwUOXEmSM1c+ln/UHrn+ZxpPPuBtOCB+8q35n5G Jqsa6neFElJI6tUHZhmyg/KHaANYvLjPOhianIRAGcyBJErEFPYgAAttlvsQl/cz9p1M Dx3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=GddeIfwIZ4cMK5JXZ5MjOUFSR77K0mqoNv12ZjUNlRY=; fh=q/mRw8BjqfXMwBZlJBUekkoSHkVT4tbxFKy9NNgF+Vc=; b=rCyFNZja/F3ClngFT9KXomKhmwJsVPQLfUK5BiNwovWGg4M9brJ74vu0mO98j9PBPY FmgMrg7z+Iju1UZjXaMAmMRY0jZ3nEyXliFC8v/8kM9tfP+Cegd8TTj+qTMuKLMY3R8G bUTqliJF6YNF2JUWwqTCdfXZOtGK7zG1VoBIxrodmpAvpSpC3MnVjcz5tw8LhlaSS6a/ 61S4xeGgASuEVGlvUDqUyYOCPwpNsbcfJnEwYOoM6z9d7GRpvEhR5mDC6xpvtYvr6qnT 9P6fLWwV7e6wQ+t+nSeuI4rRvsKha6SzC71JEeeDNozEyqu02Twpd6BySiq/lyqqDXGr tvWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x3-20020a1709027c0300b001c7345bc01csi1337070pll.450.2023.12.07.08.13.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 08:13:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E31D680C8D62; Thu, 7 Dec 2023 08:13:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443448AbjLGQM6 (ORCPT + 99 others); Thu, 7 Dec 2023 11:12:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233299AbjLGQMh (ORCPT ); Thu, 7 Dec 2023 11:12:37 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 91DA51703 for ; Thu, 7 Dec 2023 08:12:43 -0800 (PST) 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 344A51570; Thu, 7 Dec 2023 08:13:29 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6D0053F762; Thu, 7 Dec 2023 08:12:40 -0800 (PST) From: Ryan Roberts To: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Alistair Popple Cc: Ryan Roberts , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 05/10] selftests/mm/kugepaged: Restore thp settings at exit Date: Thu, 7 Dec 2023 16:12:06 +0000 Message-Id: <20231207161211.2374093-6-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231207161211.2374093-1-ryan.roberts@arm.com> References: <20231207161211.2374093-1-ryan.roberts@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 07 Dec 2023 08:13:14 -0800 (PST) Previously, the saved thp settings would be restored upon a signal or at the natural end of the test suite. But there are some tests that directly call exit() upon failure. In this case, the thp settings were not being restored, which could then influence other tests. Fix this by installing an atexit() handler to do the actual restore. The signal handler can now just call exit() and the atexit handler is invoked. Reviewed-by: Alistair Popple Reviewed-by: David Hildenbrand Tested-by: Kefeng Wang Tested-by: John Hubbard Signed-off-by: Ryan Roberts --- tools/testing/selftests/mm/khugepaged.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c index 030667cb5533..fc47a1c4944c 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -374,18 +374,22 @@ static void pop_settings(void) write_settings(current_settings()); } -static void restore_settings(int sig) +static void restore_settings_atexit(void) { if (skip_settings_restore) - goto out; + return; printf("Restore THP and khugepaged settings..."); write_settings(&saved_settings); success("OK"); - if (sig) - exit(EXIT_FAILURE); -out: - exit(exit_status); + + skip_settings_restore = true; +} + +static void restore_settings(int sig) +{ + /* exit() will invoke the restore_settings_atexit handler. */ + exit(sig ? EXIT_FAILURE : exit_status); } static void save_settings(void) @@ -415,6 +419,7 @@ static void save_settings(void) success("OK"); + atexit(restore_settings_atexit); signal(SIGTERM, restore_settings); signal(SIGINT, restore_settings); signal(SIGHUP, restore_settings); -- 2.25.1