From patchwork Wed Nov 22 16:29:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 168432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1448839vqb; Wed, 22 Nov 2023 08:31:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/DuyU7BSrr7+OHVy8t8usYifevdqiHeqg/WW9b3FG/tkr1fRSexJlGWhh0ju1vjnekG03 X-Received: by 2002:a17:90b:1a8c:b0:285:5694:886 with SMTP id ng12-20020a17090b1a8c00b0028556940886mr346528pjb.12.1700670711503; Wed, 22 Nov 2023 08:31:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700670711; cv=none; d=google.com; s=arc-20160816; b=OsJySbPtGy1zLXfLN3YVc5h4S8oWSXbQjDUj0lbf+D+o5E/rfhgMXvbmlpxNgLaxBf MAlmYhnGeeaIqwvtrc6mtMwh9R+JbIs3fA3leo7a2D2k4M+K5O/P5WbnC0g28IqDsxMY ToFIYAQBSn8DNCMvZB7IK0ispZP4HgGHO0bdIs0UHAeC+00BhjR2RYQjCDBXiJ7zliai MFEkgkUSCF1NCYQs1H+BVYyzep1TYZ+gHCx8LvIEnsSnKrjLuCIxJj4UxKHotzD5EPs+ SC+qE3Dodo6IId2Vrh64n3v5pHdiUjgTAFUoNdgZ/ZjkzdgGKi56iH809J6hLiVVIcVE 0YKQ== 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=/EYrnf/ZbB63lyuSv0fKQ4km7AIKVUkTF9kM/Ly2yKI=; fh=7axEUdnMUApK6aLYLrmxIYzEqwt8JUQTbtI9r8kD7PQ=; b=tDlc7nWNct5pVXibXZnrh/8yuk2jyB0kIAa92ZqwKX4MhuMrcubN9uCjiWSJC2YJta /cw8j9bEmr8dFyh4XUvvzEsTS+FAo/1y71o+5j9xjgzEQC3ihwkc1vSdGP1jKiRnsErJ zDXKlQGXvWn192SeAbphfSS+UDJDcDGpzQlD7/+1XOPo0Hch7wSKXarzumODJgh5I9F0 okpalWKUBNiZ6ao7nQcHMgONjlWq+5uEOaMMgQqwc1AjHnfDQg+q2w/FVDE2VcVudxJ3 UYNeTnQ3KgUkbpwK6r1UgC1bEpGyEnGUmNW5Rx6u85SKakYf3Z5VZ2+ILhwkFkyBLots CXIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id o8-20020a17090ac70800b00279866aa14csi1740841pjt.16.2023.11.22.08.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 08:31:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 57A4F8266307; Wed, 22 Nov 2023 08:31:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343587AbjKVQaf (ORCPT + 99 others); Wed, 22 Nov 2023 11:30:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbjKVQaX (ORCPT ); Wed, 22 Nov 2023 11:30:23 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3C5521B3 for ; Wed, 22 Nov 2023 08:30:20 -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 CF476C15; Wed, 22 Nov 2023 08:31:06 -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 60F583F73F; Wed, 22 Nov 2023 08:30:17 -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 Cc: Ryan Roberts , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH v7 05/10] selftests/mm/kugepaged: Restore thp settings at exit Date: Wed, 22 Nov 2023 16:29:45 +0000 Message-Id: <20231122162950.3854897-6-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231122162950.3854897-1-ryan.roberts@arm.com> References: <20231122162950.3854897-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Wed, 22 Nov 2023 08:31:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783282491998077431 X-GMAIL-MSGID: 1783282491998077431 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. Signed-off-by: Ryan Roberts Reviewed-by: Alistair Popple --- tools/testing/selftests/mm/khugepaged.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) -- 2.25.1 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);