From patchwork Wed Nov 15 13:27:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 165355 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2535367vqg; Wed, 15 Nov 2023 05:28:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEes85fArInEBgOlQNgrPEmrwHV2s89+21FnE1G3F1JqlefvIfcaQ8LBOk2rwWKe/d2gxu0 X-Received: by 2002:a17:90b:1b04:b0:280:9427:1e8f with SMTP id nu4-20020a17090b1b0400b0028094271e8fmr10226690pjb.46.1700054924549; Wed, 15 Nov 2023 05:28:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700054924; cv=none; d=google.com; s=arc-20160816; b=WvhqDcqi1ce7uaWf9TqVsJWQjqocQwTnyyC8ds784gmdtN/zArRncb6Pc6vpMRCHfg L+FxHXG2g0pyJ8MC3WHFoVn7YrZY4ftXW3O3ZY4fWX+fPtNmdBI4gCtL6GTaTiexDEHl +s7dyrAZL5nOS8c+c+fXH8PUfyTmwCDFEgCRlnA4aJQJceowlgNSPHK2ElsdHySQ8QkZ GvXyhHkaskihjBhLEtRt0rUPORqfI/xdrZCQyeVqzmEGlmB9+FYnybeHF7UfzFDfn149 vhHd2G6AHsC2p5hj6+ZDviirB7glGWx/SGIK4Zx395Iu1c+wS1yM8NapVW4gNUJE9ok6 TY2g== 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=q2VdwgxL5uVooi8fE3C5fuN6Vsx+KbjgKUGkWG43F+a8bzZNWJV/MrJyczLhTfSJjk jvvac6XozuFg/ezAq1GOwJqkWHLlVzDgxULPSgrmHWoQqz0+COpjedQTXG1OngfdDpbf GahGY61erpGxPSeQ5D+i0nHBSOWPHwl8xIGC2qC2BefzDeRHDvLLUZ5niBN7e27Wpaks M4fwk1McuWxgg6b9WqxMLpTs5n12O1gsM8XAL994ALIyL3e34H0q9pqfayD8IMCM8w+V g8AzENpCOENAFUXHc/4i9sCCgfkyxLri0CVsb1jM22u+/jG2D7HPsGuVafoMNNHwLuK/ T2Pg== 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 Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id a8-20020a17090a8c0800b0027d27512cd4si10116897pjo.81.2023.11.15.05.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 05:28:44 -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 AA487819477B; Wed, 15 Nov 2023 05:28:43 -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 S1343998AbjKON2Y (ORCPT + 28 others); Wed, 15 Nov 2023 08:28:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343975AbjKON2S (ORCPT ); Wed, 15 Nov 2023 08:28:18 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 438CB1B3 for ; Wed, 15 Nov 2023 05:28:13 -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 8865DDA7; Wed, 15 Nov 2023 05:28:58 -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 1E4A23F7B4; Wed, 15 Nov 2023 05:28:10 -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: [PATCH v7 05/10] selftests/mm/kugepaged: Restore thp settings at exit Date: Wed, 15 Nov 2023 13:27:29 +0000 Message-Id: <20231115132734.931023-6-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231115132734.931023-1-ryan.roberts@arm.com> References: <20231115132734.931023-1-ryan.roberts@arm.com> MIME-Version: 1.0 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]); Wed, 15 Nov 2023 05:28:43 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782636792738438637 X-GMAIL-MSGID: 1782636792738438637 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 --- 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);