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: 13465124 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 CEC23C61D99 for ; Wed, 22 Nov 2023 16:30:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61A828D0041; Wed, 22 Nov 2023 11:30:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C9598D0008; Wed, 22 Nov 2023 11:30:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 469568D0041; Wed, 22 Nov 2023 11:30:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2C1B08D0008 for ; Wed, 22 Nov 2023 11:30:23 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EDA2C1A100D for ; Wed, 22 Nov 2023 16:30:22 +0000 (UTC) X-FDA: 81486127884.23.71C8D7A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf25.hostedemail.com (Postfix) with ESMTP id E347FA001D for ; Wed, 22 Nov 2023 16:30:20 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.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=1700670621; 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=i3kEVo0UNqNrhOC7cbzyrKk72f2V5Sqyo/VmgfHA6sYxXA+IX6VN91SJhl2jVzQXNRcQq/ BBlOpfMta0qnd6NJ4wkQTE2UxfIvgGqHp9fRvInEgNehJjdglxQuzp/fwWYzySKaHwZP4c 1kaUqfrxh1C1DkOhlpPpQnDFHdCBybQ= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.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=1700670621; a=rsa-sha256; cv=none; b=GeGUXZ7dpZKdkTEQq8ztkY/JhpGRABm8FJErrILFRz6Et/1x6+v7o2IrDDuaSV85xrAVrS k4QpwyDf9pJboMTK1lUbnCYGiTviaym+J8+igtzGKyITQNDIHZdFCRFWan/OMKk3StZfAF yjemSY0I8bzUML1fi8oEwTEd1z2q8X0= 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-Rspamd-Queue-Id: E347FA001D X-Rspam-User: X-Stat-Signature: uia8pn58o3krj6ciza6dt9c433oqi1hn X-Rspamd-Server: rspam01 X-HE-Tag: 1700670620-211930 X-HE-Meta: U2FsdGVkX19gHjY7Zqnc/MvVaFHynhIWUTphiWnk+pbHT/j49HkJvp5VI7C1B4O2bnBaX8AEcxZqJ+HJ/HU2h0iMT3zAuNMVMcUMghE8hsLzaCc8J4y7Yucs/a0y7ZG7ALuth5LZVarMIVy8Ov9iH8A2QxNiz46NsLXYhZzEGJaX0mrO0yDgsI199cXwd3Cd+sQN1kYH9In2bsyI4FUKEI9Z/WWAiqSTs2NNJtwLQE0wwzks9jfenYo1KXLSwvDcQv8iWdlK7TQ9+mHPeaLN0FcVK3wKHLVwdZLBT3PXt2wZ4YdmjHO6imVHOEBr3EkENTIFtQlJCnSn2N7RdRj0kXRJe158eT/IOjfWdJUduTUvguz2r4SMNt8UuXRCjeWe0kyQokstR/keS1CxQsOqs51hoXKcfuwpMhESigDgXGPU/Bf8Zbdfil4oxgGIMuPKmFQda4Fex8+E8HLBl51N/6D7Ea3EkQTjnWpUQFQWvDF2N94SPuymuSfsjjXv+NbzwsmFdjyJFus4ZNKLO83g7ETulLgyfDLfLLtfq4khWmD+XU/39zTnSKtE0dgmRwpcNKD8QILtaBHiHobD+XHZdTYZ9vqp0CKe+qs8LntmWOiO1K9v3z4wBfWKOcZGkqNbmGxRmrAH6LXpfMDSRYxy1PhtEs5uWNAvRyfwldSQhXQ2AEq8R4CfsGdHEliQlMMDhQ33qp6cuyk6JJ6vYeua4M2tUkQ8r7HC3sv1YLzbC95Rlce+F4ZRh65uhrArH0kc9JaiAhMq/BjIE0kgNz0dANYc71mcTaniuPJFKc5+nmdBNuZW4BvYk5yCp2ucnUsMp9wZg5hriPnznDkETGaA6UgWhcCAErbG0eMLAK9Aut6AZlE6bF8qmRlVqwAY3qcUDLaP9SH4HG45oxr8YMSNjG0cwdXJyYhmFrVvP+UUue/nWqqrlxYiKjElkLufjVikE+mL6zz9hbfiCiVAodS Vs33Y0pU cMa/5juBi/Coi6WWdt71TEKP8aIegAaf/dYMLUvgpz6sbgQylzBWNmC3ThCX9u4tOl+buVusXztFq9wuRs23upBx62wUZmHJ14NheYyUNJACujEhn+Tg5YM1CrFedDChVmJOg1Ro5zO5IWwmnAeJklpADPt52f+RIYK+jqjKodMqpOcvXBhfcPY6eCDF3AmNpM9+8YxyM20VbhDURkCcfScCZdTDFM1AQ3qL+ 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 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);