* [PATCH] selftests: mm: restore settings from only parent process
@ 2024-03-14 9:40 Muhammad Usama Anjum
2024-04-18 12:52 ` Joey Gouly
0 siblings, 1 reply; 3+ messages in thread
From: Muhammad Usama Anjum @ 2024-03-14 9:40 UTC (permalink / raw)
To: Andrew Morton, Shuah Khan, Muhammad Usama Anjum
Cc: kernel, Joey Gouly, linux-mm, linux-kselftest, linux-kernel
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.
Fixes: c23ea61726d5 ("selftests/mm: protection_keys: save/restore nr_hugepages settings")
Tested-by: Joey Gouly <joey.gouly@arm.com>
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
tools/testing/selftests/mm/protection_keys.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c
index f822ae31af22e..374a308174d2b 100644
--- a/tools/testing/selftests/mm/protection_keys.c
+++ b/tools/testing/selftests/mm/protection_keys.c
@@ -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)
@@ -1773,6 +1776,7 @@ void save_settings(void)
exit(__LINE__);
}
+ parent_pid = getpid();
atexit(restore_settings_atexit);
close(fd);
}
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests: mm: restore settings from only parent process
2024-03-14 9:40 [PATCH] selftests: mm: restore settings from only parent process Muhammad Usama Anjum
@ 2024-04-18 12:52 ` Joey Gouly
2024-04-18 17:25 ` Muhammad Usama Anjum
0 siblings, 1 reply; 3+ messages in thread
From: Joey Gouly @ 2024-04-18 12:52 UTC (permalink / raw)
To: Muhammad Usama Anjum
Cc: Andrew Morton, Shuah Khan, kernel, linux-mm, linux-kselftest,
linux-kernel
Hi again,
On Thu, Mar 14, 2024 at 02:40:45PM +0500, Muhammad Usama Anjum wrote:
> 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.
>
> Fixes: c23ea61726d5 ("selftests/mm: protection_keys: save/restore nr_hugepages settings")
> Tested-by: Joey Gouly <joey.gouly@arm.com>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> tools/testing/selftests/mm/protection_keys.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c
> index f822ae31af22e..374a308174d2b 100644
> --- a/tools/testing/selftests/mm/protection_keys.c
> +++ b/tools/testing/selftests/mm/protection_keys.c
> @@ -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)
> @@ -1773,6 +1776,7 @@ void save_settings(void)
> exit(__LINE__);
> }
>
> + parent_pid = getpid();
> atexit(restore_settings_atexit);
> close(fd);
> }
After more testing, this is not actually enough. It passes sometimes, which is
why I gave my Tested-by, but it can still fail the same way as I originally
said.
assert() at protection_keys.c::812 test_nr: 19 iteration: 1
running abort_hooks()...
errno at assert: 12
I think the parent process needs to wait for all it's child processes (recursively).
This is due to the test_pkey_alloc_exhaust() calling become_child(), where it
exits, and that exit may be from the original PID.
Thanks,
Joey
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests: mm: restore settings from only parent process
2024-04-18 12:52 ` Joey Gouly
@ 2024-04-18 17:25 ` Muhammad Usama Anjum
0 siblings, 0 replies; 3+ messages in thread
From: Muhammad Usama Anjum @ 2024-04-18 17:25 UTC (permalink / raw)
To: Joey Gouly
Cc: Muhammad Usama Anjum, Andrew Morton, Shuah Khan, kernel, linux-mm,
linux-kselftest, linux-kernel
On 4/18/24 5:52 PM, Joey Gouly wrote:> Hi again,
>
> On Thu, Mar 14, 2024 at 02:40:45PM +0500, Muhammad Usama Anjum wrote:
>> 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.
>>
>> Fixes: c23ea61726d5 ("selftests/mm: protection_keys: save/restore nr_hugepages settings")
>> Tested-by: Joey Gouly <joey.gouly@arm.com>
>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>> ---
>> tools/testing/selftests/mm/protection_keys.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c
>> index f822ae31af22e..374a308174d2b 100644
>> --- a/tools/testing/selftests/mm/protection_keys.c
>> +++ b/tools/testing/selftests/mm/protection_keys.c
>> @@ -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)
>> @@ -1773,6 +1776,7 @@ void save_settings(void)
>> exit(__LINE__);
>> }
>>
>> + parent_pid = getpid();
>> atexit(restore_settings_atexit);
>> close(fd);
>> }
>
> After more testing, this is not actually enough. It passes sometimes, which is
> why I gave my Tested-by, but it can still fail the same way as I originally
> said.
>
> assert() at protection_keys.c::812 test_nr: 19 iteration: 1
> running abort_hooks()...
> errno at assert: 12
>
> I think the parent process needs to wait for all it's child processes (recursively).
> This is due to the test_pkey_alloc_exhaust() calling become_child(), where it
> exits, and that exit may be from the original PID.
Thanks for reporting. I'll have a look at it.
>
> Thanks,
> Joey
--
BR,
Muhammad Usama Anjum
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-18 17:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-14 9:40 [PATCH] selftests: mm: restore settings from only parent process Muhammad Usama Anjum
2024-04-18 12:52 ` Joey Gouly
2024-04-18 17:25 ` Muhammad Usama Anjum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).