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: 13456679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4347DC48BD7 for ; Wed, 15 Nov 2023 13:28:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D64646B0343; Wed, 15 Nov 2023 08:28:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D15606B0344; Wed, 15 Nov 2023 08:28:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B910A6B0345; Wed, 15 Nov 2023 08:28:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A015B6B0343 for ; Wed, 15 Nov 2023 08:28:15 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 68D9640B2E for ; Wed, 15 Nov 2023 13:28:15 +0000 (UTC) X-FDA: 81460267350.26.CED4C59 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf15.hostedemail.com (Postfix) with ESMTP id AD4E3A000C for ; Wed, 15 Nov 2023 13:28:13 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700054893; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/EYrnf/ZbB63lyuSv0fKQ4km7AIKVUkTF9kM/Ly2yKI=; b=ai2+om+aIA2ZNhy+Z99Mo9ufWxbzal8+jRo1yG0auTgWqLsLwI7MHFvS7B6kommrVBOt/E 6x1h3fxB9vmUVrUA4z0s0H4nRi1XLrzWjQmk1/X/l69KidSvfC66RBp36ugS0SuBd40+bE 7+oR8qqpoU60sWDi4Eqzk8zJgD6OASQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700054893; a=rsa-sha256; cv=none; b=R2plOTnhbtZaeABndxenmTQM4cbIsfCCo5rF12YHODZEYSoxC8q28xV78k7llZq55iCTUc ryFQ7m1dfY5jtN0UqkXTVtNjZDtzC7fbJKsEX9hcSNKCNQMq8mIAxFQ6ZSbDJqJDdQ/CqY 2bWXd2/fMLkAxJS7vMc2ILOwimiJ5ng= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=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 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-Stat-Signature: on3rdck6gyi7fam81m3mf8kcipnrerwf X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: AD4E3A000C X-Rspam-User: X-HE-Tag: 1700054893-152293 X-HE-Meta: U2FsdGVkX1+cCiyTS5uUhXcne1G5TuWqsF0hu2xCXOgRUGbkrq38QYWfwYjrMonCBJ5mRANuDrBPcwTzjX42ft/DPEhgMGQarU3ESKDUrYENVAShuK+jv0I0yoPgGlsuNvtRTMOxgme5W1XE2vpZHLXg2s/S7iTpFL85wNczIpguJHceXyehbKFrcWOPS2PHBRx4hzNeWEy0syGMhaQFGYUI0lfdYiu63fMZn5blxmUUIQmigkt+pV/8JTlIy2OO3joT2K9zsT0y/Zonv44JRd700YscmtIwhodKSX8kOlifJjl8GIqUI0eCqV36MLS0EuvqQmXHYggP/X4FHEZO8kg9usr40sDcGreubf4JfaFFDhyvCcyi3PQds+efpKtUszXEMlBlVcFoT1Ns94hBDcLO1hjXVDSmvdwAzgGUOMU51BTYTxHbcPNbC8fFr5MaNEE/N8EC6Cg+jvmyY1ALNR5xew4XFmf950zUIR1ti9V5ZGwmg23OGAkP7gQ6tXgruUAU6KYaRJOfJwoa1FSiJJ8kPIxN2A+LMOXD6xzCciuvhjNC1e2wjrOqKZoiM2wPO0TdZ0Pjp1nHZrcJ3FlnL2r/ixV7XwryrD48hsKrdM//uwBILTMGAZ/sZkuXId+aamYL1p1JCXVQDzrkFjWxZ946dalquhy2zguGhwhFkfHlOCyMrvjilxp54/bTFsrJyrTNaRSq1XFtRYvJUX0G2qXfXCbe4T/IcR+L92tqNGM4+nP6QGQcQHie5HyguqLkUyI8EjX9/25LZjyufxu/wj591R1UkrzlGz62v2GIyW5Qmd0JEGjRrXjmLnB1mGk5UILr5jzBpptDFJjjJ6LXFBWDtyMJgvnRHWlEXBO9EasepP+4zvRXuUVQoMFS0N+GQz9YMMc0JSp6OkqqqeSEj2mZ/eHDD8gO8RHuKjG6Su/om0EmwsBY+XhVcRDxJh6fDDXzELcl9n+4GwwcP+2 hog4VB8y NVPXmfp5BsO/zaaH+RJLznQbPIfoIywrNe6Osbc31t0x30z3JWbDZ9JXu19TX+GPPqbv1Gpf9p3BNDmfE9qKNtH9I5OnOW9bEUMsjde24csHTatmqL2Cg3ESI91BfHoYbBm5+c/YM3J/xMv+GdFZI54ScjGzAAtHhaBFH7W1Uqdy2i8KEXP7gcQYQ7e3s8l5G+Wjhp6iZ5xtjnFqSoLY+X28YixENW58ZGnjL X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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);