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: 13478089 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 27830C10DC1 for ; Mon, 4 Dec 2023 10:21:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFA146B0283; Mon, 4 Dec 2023 05:21:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B82276B0285; Mon, 4 Dec 2023 05:21:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FDC06B0289; Mon, 4 Dec 2023 05:21:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8D92B6B0283 for ; Mon, 4 Dec 2023 05:21:09 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 45D1F140186 for ; Mon, 4 Dec 2023 10:21:09 +0000 (UTC) X-FDA: 81528743058.27.22E8C36 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP id B05591A000F for ; Mon, 4 Dec 2023 10:21:07 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701685267; 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=nujK6Tjb+pxtj0tIwTcRlIIllYyZp5Ttoqe+G0ErqQk=; b=o9TH+7ayGSMxZecihUMCoOqHQSVWVwWPqFwQtv4mPj+oxh0YxDMkZACBr2u5wF1eYr8td/ AyCK9F8+zL9ehpdpNhkXnSSxxledNRoXtNa601E2ca5Ws/az1yhMRRRrXAkAua7JiwONUp y9FOGwlnvdTo9eueomUjQyPtEun8nOA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701685267; a=rsa-sha256; cv=none; b=4nmjaIV/JSdN15CuLcMSfFjT/qKMunN8KCSaFJmvhVC23qt6sbHeZsPtQgXc+3Fu7lMHDF 4fmyK1yOm7qx+zmof5VkZaLEa6NuuSPHMJkb6KED50WVm8AaygDnCE+Mag1AVBJ5dT1dUv DMERrpfz3jWN++io6CFVPG9RqyKmU74= 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-Rspam-User: X-Stat-Signature: 7rpxauy1xh1pfq9wok9fm1pknxukshc8 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B05591A000F X-HE-Tag: 1701685267-746052 X-HE-Meta: U2FsdGVkX1+8ggRMLy8xfOaxkAxK2fQzWQXw7ycEG4PJ+9pZ2sVY4Vx6oSfKLNYVkgp45a2mofVwAjyETRZK7rWGX4h86MMIwOTnVRZNJSeHjL5Wxmc1/koH4h2XYCMlTu0HbK47Hd65sVg7ixXOKf6b4LmJ3Sl31iqtR8DgrC2c2TP5JsMsN78K8vZ9jpPQKkmpbUD2pwWtCr0PquXzxZJe4XL8ztJZ/jlmDzfzYDadplCunpGky18fZtbTIMYLQt4UX/RRJkzhPIsRA3AaeIxCI/f1b73ZDYRXwzD2zx69JPUrdYfZGOj69aSdaZ3wFQ2ChxtBk5sHAreVW/aarE0ZdQVHlYaXmXdRUARtF0EVDYQMZzeyKzKOC5y92Ak5/HcWQdKot1kX7MXUgzu5IYmTsAcYlHiLdq0FVOGOgW8aDKNNcyvEtx2rzWnq2cWrYh8nfh7PU7KKsfme/rmiNHdMnoAFRWmQFdJnBdo+gw6KHsK0lbJZJ9T71rOMmeBDFJAybPfBdtD5axA/dtugbivNUdrYfObHjJeDLZwAdUMlhmzt2oI1aYh8zbeUr7Oe4PMxxXbvY8bOPfVd76RB2nFyWv/pLG2oC3wmH/nUWGvdpLiU7ecHO3LDyHMiYquTsMsN3FHXGnfS1r4/Ubr2bOOLM72MzNTzBgc4Pdigs5VSH8AO7v3RoXd41OjslXRqxjlwpayI9GWhwggdM6Wdr5E3XAtht6tq4iPh3Ta9GqmSem+PvGwm9Zlw9P9SV/31begGFPzMhlUM7bSeqa9E03R1DfU9MBfZ/t5bNepg8S5zYI617LUSGDNzWUDcNZyZWGsH/AvDXf8FsbAvBuFBlP09PUP8NOfAzcHB9R3QZPXNUOxluv2O6eJooA6gJsO8AxDBIrTEsredcZzKXOFEUJEqL+fvywzmkGKq8bDFoT5vIASodLscB6KDsZK+CrCv/yguojBUEQQJmQeHqER k02jZIbX C+WJlQO8CmNnM9rMgrXn2BC1mjU9Wj2iUCh7LOcI7haxIYoplPj3XwRprIHGfbPYAzO4eHMPEowO65MDQ89F3IKnnjJh/v42tdfo+Un52q33c/XKfsowHhWQQrQEXzcR4fJhKKUJrc2ReC6jR8rD/kYPRinZufRaAENhR2AbCDnPaOSKm+dkrA8cHsTDo6ViAt8qukRDNW4tGVbeNCw0zSiPuJayA8qk60IHO6l9IWOi/Vbb1sbig6HZqsqhcJRQVRdJg 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 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);