Skip to content

Commit ed74abc

Browse files
musamaanjumakpm00
authored andcommitted
selftests: mm: protection_keys: save/restore nr_hugepages value from launch script
The save/restore of nr_hugepages was added to the test itself by using the atexit() functionality. But it is broken as parent exits after creating child. Hence calling the atexit() function early. That's not it. The child exits after creating its child and so on. The parent cannot wait to get the termination status for its children as it'll keep on holding the resources until the new pkey allocation fails. It is impossible to wait for exits of all the grand and great grand children. Hence the restoring of nr_hugepages value from parent is wrong. Let's save/restore the nr_hugepages settings in the launch script instead of doing it in the test. Link: https://lkml.kernel.org/r/[email protected] Fixes: c52eb6d ("selftests: mm: restore settings from only parent process") Signed-off-by: Muhammad Usama Anjum <[email protected]> Reported-by: Joey Gouly <[email protected]> Closes: https://lore.kernel.org/all/[email protected] Cc: Joey Gouly <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 6fe6046 commit ed74abc

File tree

2 files changed

+2
-38
lines changed

2 files changed

+2
-38
lines changed

tools/testing/selftests/mm/protection_keys.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ int test_nr;
5454
u64 shadow_pkey_reg;
5555
int dprint_in_signal;
5656
char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE];
57-
char buf[256];
5857

5958
void cat_into_file(char *str, char *file)
6059
{
@@ -1745,50 +1744,13 @@ void pkey_setup_shadow(void)
17451744
shadow_pkey_reg = __read_pkey_reg();
17461745
}
17471746

1748-
pid_t parent_pid;
1749-
1750-
void restore_settings_atexit(void)
1751-
{
1752-
if (parent_pid == getpid())
1753-
cat_into_file(buf, "/proc/sys/vm/nr_hugepages");
1754-
}
1755-
1756-
void save_settings(void)
1757-
{
1758-
int fd;
1759-
int err;
1760-
1761-
if (geteuid())
1762-
return;
1763-
1764-
fd = open("/proc/sys/vm/nr_hugepages", O_RDONLY);
1765-
if (fd < 0) {
1766-
fprintf(stderr, "error opening\n");
1767-
perror("error: ");
1768-
exit(__LINE__);
1769-
}
1770-
1771-
/* -1 to guarantee leaving the trailing \0 */
1772-
err = read(fd, buf, sizeof(buf)-1);
1773-
if (err < 0) {
1774-
fprintf(stderr, "error reading\n");
1775-
perror("error: ");
1776-
exit(__LINE__);
1777-
}
1778-
1779-
parent_pid = getpid();
1780-
atexit(restore_settings_atexit);
1781-
close(fd);
1782-
}
1783-
17841747
int main(void)
17851748
{
17861749
int nr_iterations = 22;
17871750
int pkeys_supported = is_pkeys_supported();
17881751

17891752
srand((unsigned int)time(NULL));
17901753

1791-
save_settings();
17921754
setup_handlers();
17931755

17941756
printf("has pkeys: %d\n", pkeys_supported);

tools/testing/selftests/mm/run_vmtests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ CATEGORY="ksm_numa" run_test ./ksm_tests -N -m 0
385385
CATEGORY="ksm" run_test ./ksm_functional_tests
386386

387387
# protection_keys tests
388+
nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages)
388389
if [ -x ./protection_keys_32 ]
389390
then
390391
CATEGORY="pkey" run_test ./protection_keys_32
@@ -394,6 +395,7 @@ if [ -x ./protection_keys_64 ]
394395
then
395396
CATEGORY="pkey" run_test ./protection_keys_64
396397
fi
398+
echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages
397399

398400
if [ -x ./soft-dirty ]
399401
then

0 commit comments

Comments
 (0)