Skip to content

Commit c52eb6d

Browse files
Muhammad Usama Anjumakpm00
authored andcommitted
selftests: mm: restore settings from only parent process
The atexit() is called from parent process as well as forked processes. Hence the child restores the settings at exit while the parent is still executing. Fix this by checking pid of atexit() calling process and only restore THP number from parent process. Link: https://lkml.kernel.org/r/20240314094045.157149-1-usama.anjum@collabora.com Fixes: c23ea61 ("selftests/mm: protection_keys: save/restore nr_hugepages settings") Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Tested-by: Joey Gouly <joey.gouly@arm.com> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 950bf45 commit c52eb6d

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

tools/testing/selftests/mm/protection_keys.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,9 +1745,12 @@ void pkey_setup_shadow(void)
17451745
shadow_pkey_reg = __read_pkey_reg();
17461746
}
17471747

1748+
pid_t parent_pid;
1749+
17481750
void restore_settings_atexit(void)
17491751
{
1750-
cat_into_file(buf, "/proc/sys/vm/nr_hugepages");
1752+
if (parent_pid == getpid())
1753+
cat_into_file(buf, "/proc/sys/vm/nr_hugepages");
17511754
}
17521755

17531756
void save_settings(void)
@@ -1773,6 +1776,7 @@ void save_settings(void)
17731776
exit(__LINE__);
17741777
}
17751778

1779+
parent_pid = getpid();
17761780
atexit(restore_settings_atexit);
17771781
close(fd);
17781782
}

0 commit comments

Comments
 (0)