Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/mm/kugepaged: restore thp settings at exit

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.

Link: https://lkml.kernel.org/r/20231207161211.2374093-6-ryan.roberts@arm.com
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Alistair Popple <apopple@nvidia.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Tested-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Tested-by: John Hubbard <jhubbard@nvidia.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Barry Song <v-songbaohua@oppo.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Rientjes <rientjes@google.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Itaru Kitayama <itaru.kitayama@gmail.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Yin Fengwei <fengwei.yin@intel.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Ryan Roberts and committed by
Andrew Morton
b6aab338 19eaf449

+11 -6
+11 -6
tools/testing/selftests/mm/khugepaged.c
··· 374 374 write_settings(current_settings()); 375 375 } 376 376 377 - static void restore_settings(int sig) 377 + static void restore_settings_atexit(void) 378 378 { 379 379 if (skip_settings_restore) 380 - goto out; 380 + return; 381 381 382 382 printf("Restore THP and khugepaged settings..."); 383 383 write_settings(&saved_settings); 384 384 success("OK"); 385 - if (sig) 386 - exit(EXIT_FAILURE); 387 - out: 388 - exit(exit_status); 385 + 386 + skip_settings_restore = true; 387 + } 388 + 389 + static void restore_settings(int sig) 390 + { 391 + /* exit() will invoke the restore_settings_atexit handler. */ 392 + exit(sig ? EXIT_FAILURE : exit_status); 389 393 } 390 394 391 395 static void save_settings(void) ··· 419 415 420 416 success("OK"); 421 417 418 + atexit(restore_settings_atexit); 422 419 signal(SIGTERM, restore_settings); 423 420 signal(SIGINT, restore_settings); 424 421 signal(SIGHUP, restore_settings);