From patchwork Mon Dec 4 10:20:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 173204 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2665907vqy; Mon, 4 Dec 2023 02:21:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmor/CCYwUFbcCdtOgMtOds0ZlErCCKySfd+jVnVoqkc1nGbvldpiETRp5+4csZjkhshVf X-Received: by 2002:a05:6a20:258b:b0:18c:64e0:447b with SMTP id k11-20020a056a20258b00b0018c64e0447bmr1205282pzd.28.1701685300445; Mon, 04 Dec 2023 02:21:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701685300; cv=none; d=google.com; s=arc-20160816; b=pXT6IBJxfNYhkrahnXzCh4TZIJhtTvq0lvFfi2Na8cuLpKmItymutzohJXsuHkUQE9 Q3a+htpf9GpczmPZ7ytA34j0Jy5G3+oDdfnxzh/D4gu187Fs+9kZ5j+mGzOtdtLG1Jzo IPCnen5U/YxPrACFAw6WAvLFi4rF9GDZu4uNtFGQT0dWrum6Dn+UTM1J3dGmSeQtkh5P Da3aERSFpiENChy/6BSiUm5BQWfkpBQnu8+4chd0XvA2dwQMZZnyjLdTbbHrMUSU46FQ MV3bEKLYduWUdHYjwSoocouRUFU+46YpekhqY1NqRiNvyp84WOFPOjmT8B+dVx4pyYgS fWoA== 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=nujK6Tjb+pxtj0tIwTcRlIIllYyZp5Ttoqe+G0ErqQk=; fh=q/mRw8BjqfXMwBZlJBUekkoSHkVT4tbxFKy9NNgF+Vc=; b=hrfw6G30J3OP9dfKM2nvEw2FQhSElZb7Jw2rvJfufu9AmHN/b1LJak5q+LOnfWyor6 igyrTsS4v5uppMXuHm+j00dRpUNrkNiTYsEz4LCuqXvj3NdrkDNT5dZNHCeKyWSgGmJ+ zsiBK2Q2ShcJq8397KLPvFAyezoORChfTrE81Yyb2PemvfM2KdRrp+MK5qs61VUkfyTy 7IaeCmjigivbsftn1OopmII8/aeKyvycsp4lD1ITyq0ezb+ko7vtiUpc2aj8FTzMYaQx 8b6rEicrIt25im1ARUfclIbnabFkEny3kZYxDTPWs4345HKLQfCMYmWBvti3W9aACfDu E2uA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id il15-20020a17090b164f00b0027cdee52324si2396377pjb.74.2023.12.04.02.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 02:21:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 2D947809717A; Mon, 4 Dec 2023 02:21:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232459AbjLDKVO (ORCPT + 99 others); Mon, 4 Dec 2023 05:21:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343768AbjLDKVA (ORCPT ); Mon, 4 Dec 2023 05:21:00 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3C51685 for ; Mon, 4 Dec 2023 02:21:07 -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 3FE0416F2; Mon, 4 Dec 2023 02:21:54 -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 28D103F6C4; Mon, 4 Dec 2023 02:21:04 -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 v8 05/10] selftests/mm/kugepaged: Restore thp settings at exit Date: Mon, 4 Dec 2023 10:20:22 +0000 Message-Id: <20231204102027.57185-6-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231204102027.57185-1-ryan.roberts@arm.com> References: <20231204102027.57185-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 02:21:37 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784346365451774527 X-GMAIL-MSGID: 1784346365451774527 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 Signed-off-by: Ryan Roberts Reviewed-by: David Hildenbrand --- 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);