Skip to content

Commit

Permalink
selftests: mm: restore settings from only parent process
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
musamaanjum authored and akpm00 committed Mar 26, 2024
1 parent 950bf45 commit c52eb6d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tools/testing/selftests/mm/protection_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1745,9 +1745,12 @@ void pkey_setup_shadow(void)
shadow_pkey_reg = __read_pkey_reg();
}

pid_t parent_pid;

void restore_settings_atexit(void)
{
cat_into_file(buf, "/proc/sys/vm/nr_hugepages");
if (parent_pid == getpid())
cat_into_file(buf, "/proc/sys/vm/nr_hugepages");
}

void save_settings(void)
Expand All @@ -1773,6 +1776,7 @@ void save_settings(void)
exit(__LINE__);
}

parent_pid = getpid();
atexit(restore_settings_atexit);
close(fd);
}
Expand Down

0 comments on commit c52eb6d

Please sign in to comment.