From patchwork Thu Dec 7 16:12:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13483620 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 CB576C10F05 for ; Thu, 7 Dec 2023 16:12:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 533B96B00A1; Thu, 7 Dec 2023 11:12:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BCBE6B00A2; Thu, 7 Dec 2023 11:12:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2712C6B00A3; Thu, 7 Dec 2023 11:12:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0F1326B00A1 for ; Thu, 7 Dec 2023 11:12:46 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C0E381A010F for ; Thu, 7 Dec 2023 16:12:45 +0000 (UTC) X-FDA: 81540515490.19.1696C8C Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf26.hostedemail.com (Postfix) with ESMTP id EF7F8140013 for ; Thu, 7 Dec 2023 16:12:43 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.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=1701965564; 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=GddeIfwIZ4cMK5JXZ5MjOUFSR77K0mqoNv12ZjUNlRY=; b=t8aP865ZXoTreZPpkbSmYucXCU/jGbVJ62ikOujTZOZREfGKWGON2BBOuM3yztn/AOtZxC iXesHRRdbhIQ3qlOaPsML0dHE3QFuuQSL/oPLwloYt17IFNkKHbJOYsQE+URp56idi947S BK0FBlqaaAbTpFsbaSA+qidbEXtrUoM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701965564; a=rsa-sha256; cv=none; b=vdO5JQ4rnkeR2nYALSirya2/HAw9H+lhipv9yXO2Av8+rPVLhlMhEBRvZ9B0+llkCSs1pL N0IBDSiFJqXPJgaNJf06iTcfzjQiJ3LJPuRS+p/MH5YZ6v0RBGdUs4QFeCw8bBerxNq3iB SJd31vSIy2DDXNFiaVaRJFJPzhb4fBY= 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 X-Rspamd-Queue-Id: EF7F8140013 X-Rspam-User: X-Stat-Signature: 55ar5ieaqiko47kootfkgqr3iiwj8dxm X-Rspamd-Server: rspam01 X-HE-Tag: 1701965563-38628 X-HE-Meta: U2FsdGVkX19S4nPbvDclkUtZm3cr9Wvkp7Mnq/BZMmryelbA0HGXlnKtVinXb3JDbu3AyJKluuBe7My83Qd7UP+WhvHPz97JRMKoasXSHK5jO9BTtXYz23NKGxMWtBB8hMPtqCpkRTQwpq+YVqAxazq9lGS2LhWkFdlwL0EZcjWRyjtAnCEb++G4h2x3yO8usUpfzJ1kbI8YaP05D+iMkfYesANy2pXMZzEo3t1KkI8szmUzpolthKpDDcvxJZeNdejkHzsz0UkuSZuC6LppB9e1sxGjSBGEoj9osNPd3aCJFyPerX3CXW9uIbW2h1wOvbHPtOFdZY7SrC22dlV/8FF0TDpuKDpcG3mNkxUdwNSY7VKC0z0ZpQ5qzTRadz7V4i5fMt8dEGUu+Fv5h8TGli0BmwIIHHvlYUHnaYpaKGBdW+WqJmabz2Qq6/mB/aTJfOX1QJ5hQtp4vLupE02AZ3PDwtxLUzfiHhJ/CoVIunW8uqWGlDXNQcq0uq9gU/lC/tIX9COxu1FyqeqmrrUQLXjctlPcE3mJ1XJfaO0xADnrfB9DJ1IlhKfBRbrHV7Y4ZtnhuDbZH1zEIneRX0eMGBkMCB3/g5yp6goGZQXUN8ikCivQyFiLPqnPfKpUBH/4VAQ4HahgP6ov55B9+uEfw5hPUGUwD03B+efDhrxsHqHQhGzcpz8A43fjkmzKLJl1Kj4uwLNVgrTGUVhTrQ1WqbqEs5FhwocSGKDpxovfkNspmIUKoVwzoyBJmAEVFC6KGfysp0Dy0HVs/rl3dbdvEHCBe52OTh7qwrYJ15jszZJylXJtPSHVs8CcJsxA8rdJWvaw+G+vpfKquqvQvxXpEM3CTYR+aV0XiwN6LXm/LCTBVAYdx9qtA9idyP118c5o63IZPL0xHs8H096uKx9id/KfhtlEUMdf6Wyx3HkUrLbChEM0FLE3Z7TbaA4YiElHe/0MlhKAr9Z2u/i+JEK DLeoS/1e hbPk7q9cFDjCEB+8pDCSwwgenf0rmM8R2gsdd2/2FwVERR2ccmu0/qLKDizF+z7DlMBai/Jy/tB8xaFE6RxpT8Yn2GlKCIYTbi1645h3Hk7ptgITLX9VJX7DoaxF+ZGEgwyDBuAvqZ2w47p76arZjskBu57TRfJMI8gadEtlfRGmv9eqhu/AZOBNfplPAb5iGgN0aA280YUO+IFvC6rf+um+McLNd2IkZIJTctzwtkrDtNMy98ERZs/08pLvBD0Cna/eDZOUHxwVtg658u+LG2z2K9E+mJP9cK1fRdtFD2MN8UcU= 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. 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);