When execute the following command to test clone3 on LoongArch:
# cd tools/testing/selftests/clone3 && make && ./clone3
we can see the following error info:
# [5719] Trying clone3() with flags 0x80 (size 0)
# Invalid argument - Failed to create new process
# [5719] clone3() with flags says: -22 expected 0
not ok 18 [5719] Result (-22) is different than expected (0)
This is because if CONFIG_TIME_NS is not set, but the flag
CLONE_NEWTIME (0x80) is used to clone a time namespace, it
will return -EINVAL in copy_time_ns().
Here is the related code in include/linux/time_namespace.h:
#ifdef CONFIG_TIME_NS
...
struct time_namespace *copy_time_ns(unsigned long flags,
struct user_namespace *user_ns,
struct time_namespace *old_ns);
...
#else
...
static inline
struct time_namespace *copy_time_ns(unsigned long flags,
struct user_namespace *user_ns,
struct time_namespace *old_ns)
{
if (flags & CLONE_NEWTIME)
return ERR_PTR(-EINVAL);
return old_ns;
}
...
#endif
Here is the complete call stack:
clone3()
kernel_clone()
copy_process()
copy_namespaces()
create_new_namespaces()
copy_time_ns()
clone_time_ns()
If kernel does not support CONFIG_TIME_NS, /proc/self/ns/time
will be not exist, and then we should skip clone3() test with
CLONE_NEWTIME.
With this patch under !CONFIG_TIME_NS:
# cd tools/testing/selftests/clone3 && make && ./clone3
...
# Time namespaces are not supported
ok 18 # SKIP Skipping clone3() with CLONE_NEWTIME
# Totals: pass:17 fail:0 xfail:0 xpass:0 skip:1 error:0
Fixes: 515bddf0ec41 ("selftests/clone3: test clone3 with CLONE_NEWTIME")
Suggested-by: Thomas Gleixner <[email protected]>
Signed-off-by: Tiezhu Yang <[email protected]>
---
tools/testing/selftests/clone3/clone3.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/clone3/clone3.c b/tools/testing/selftests/clone3/clone3.c
index e495f89..c721f8a 100644
--- a/tools/testing/selftests/clone3/clone3.c
+++ b/tools/testing/selftests/clone3/clone3.c
@@ -196,7 +196,12 @@ int main(int argc, char *argv[])
CLONE3_ARGS_NO_TEST);
/* Do a clone3() in a new time namespace */
- test_clone3(CLONE_NEWTIME, 0, 0, CLONE3_ARGS_NO_TEST);
+ if (access("/proc/self/ns/time", F_OK) == 0) {
+ test_clone3(CLONE_NEWTIME, 0, 0, CLONE3_ARGS_NO_TEST);
+ } else {
+ ksft_print_msg("Time namespaces are not supported\n");
+ ksft_test_result_skip("Skipping clone3() with CLONE_NEWTIME\n");
+ }
ksft_finished();
}
--
2.1.0
On Mon, Jun 05 2023 at 20:33, Tiezhu Yang wrote:
> When execute the following command to test clone3 on LoongArch:
>
> # cd tools/testing/selftests/clone3 && make && ./clone3
>
> we can see the following error info:
>
> # [5719] Trying clone3() with flags 0x80 (size 0)
> # Invalid argument - Failed to create new process
> # [5719] clone3() with flags says: -22 expected 0
> not ok 18 [5719] Result (-22) is different than expected (0)
>
> This is because if CONFIG_TIME_NS is not set, but the flag
> CLONE_NEWTIME (0x80) is used to clone a time namespace, it
> will return -EINVAL in copy_time_ns().
>
> Here is the related code in include/linux/time_namespace.h:
>
> #ifdef CONFIG_TIME_NS
> ...
> struct time_namespace *copy_time_ns(unsigned long flags,
> struct user_namespace *user_ns,
> struct time_namespace *old_ns);
> ...
> #else
> ...
> static inline
> struct time_namespace *copy_time_ns(unsigned long flags,
> struct user_namespace *user_ns,
> struct time_namespace *old_ns)
> {
> if (flags & CLONE_NEWTIME)
> return ERR_PTR(-EINVAL);
>
> return old_ns;
> }
> ...
> #endif
There is really no point in copying that code into the changelog. The
textual explanation that it returns -EINVAL is good enough.
> Here is the complete call stack:
>
> clone3()
> kernel_clone()
> copy_process()
> copy_namespaces()
> create_new_namespaces()
> copy_time_ns()
> clone_time_ns()
Uninteresting too.
> If kernel does not support CONFIG_TIME_NS, /proc/self/ns/time
> will be not exist, and then we should skip clone3() test with
> CLONE_NEWTIME.
Correct.
> With this patch under !CONFIG_TIME_NS:
>
> # cd tools/testing/selftests/clone3 && make && ./clone3
> ...
> # Time namespaces are not supported
> ok 18 # SKIP Skipping clone3() with CLONE_NEWTIME
> # Totals: pass:17 fail:0 xfail:0 xpass:0 skip:1 error:0
> Fixes: 515bddf0ec41 ("selftests/clone3: test clone3 with CLONE_NEWTIME")
> Suggested-by: Thomas Gleixner <[email protected]>
> Signed-off-by: Tiezhu Yang <[email protected]>
> ---
> tools/testing/selftests/clone3/clone3.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/clone3/clone3.c b/tools/testing/selftests/clone3/clone3.c
> index e495f89..c721f8a 100644
> --- a/tools/testing/selftests/clone3/clone3.c
> +++ b/tools/testing/selftests/clone3/clone3.c
> @@ -196,7 +196,12 @@ int main(int argc, char *argv[])
> CLONE3_ARGS_NO_TEST);
>
> /* Do a clone3() in a new time namespace */
> - test_clone3(CLONE_NEWTIME, 0, 0, CLONE3_ARGS_NO_TEST);
> + if (access("/proc/self/ns/time", F_OK) == 0) {
> + test_clone3(CLONE_NEWTIME, 0, 0, CLONE3_ARGS_NO_TEST);
> + } else {
> + ksft_print_msg("Time namespaces are not supported\n");
> + ksft_test_result_skip("Skipping clone3() with CLONE_NEWTIME\n");
> + }
Patch looks good otherwise.
Thanks,
tglx
On 06/06/2023 04:18 PM, Thomas Gleixner wrote:
> On Mon, Jun 05 2023 at 20:33, Tiezhu Yang wrote:
>> When execute the following command to test clone3 on LoongArch:
>>
>> # cd tools/testing/selftests/clone3 && make && ./clone3
>>
>> we can see the following error info:
>>
>> # [5719] Trying clone3() with flags 0x80 (size 0)
>> # Invalid argument - Failed to create new process
>> # [5719] clone3() with flags says: -22 expected 0
>> not ok 18 [5719] Result (-22) is different than expected (0)
>>
>> This is because if CONFIG_TIME_NS is not set, but the flag
>> CLONE_NEWTIME (0x80) is used to clone a time namespace, it
>> will return -EINVAL in copy_time_ns().
>>
>> Here is the related code in include/linux/time_namespace.h:
>>
>> #ifdef CONFIG_TIME_NS
>> ...
>> struct time_namespace *copy_time_ns(unsigned long flags,
>> struct user_namespace *user_ns,
>> struct time_namespace *old_ns);
>> ...
>> #else
>> ...
>> static inline
>> struct time_namespace *copy_time_ns(unsigned long flags,
>> struct user_namespace *user_ns,
>> struct time_namespace *old_ns)
>> {
>> if (flags & CLONE_NEWTIME)
>> return ERR_PTR(-EINVAL);
>>
>> return old_ns;
>> }
>> ...
>> #endif
>
> There is really no point in copying that code into the changelog. The
> textual explanation that it returns -EINVAL is good enough.
OK, let me remove the code in the commit message.
>> Here is the complete call stack:
>>
>> clone3()
>> kernel_clone()
>> copy_process()
>> copy_namespaces()
>> create_new_namespaces()
>> copy_time_ns()
>> clone_time_ns()
>
> Uninteresting too.
Will remove it too.
>
>> If kernel does not support CONFIG_TIME_NS, /proc/self/ns/time
>> will be not exist, and then we should skip clone3() test with
>> CLONE_NEWTIME.
>
> Correct.
>
>> With this patch under !CONFIG_TIME_NS:
>>
>> # cd tools/testing/selftests/clone3 && make && ./clone3
>> ...
>> # Time namespaces are not supported
>> ok 18 # SKIP Skipping clone3() with CLONE_NEWTIME
>> # Totals: pass:17 fail:0 xfail:0 xpass:0 skip:1 error:0
>
>> Fixes: 515bddf0ec41 ("selftests/clone3: test clone3 with CLONE_NEWTIME")
>> Suggested-by: Thomas Gleixner <[email protected]>
>> Signed-off-by: Tiezhu Yang <[email protected]>
>> ---
>> tools/testing/selftests/clone3/clone3.c | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/clone3/clone3.c b/tools/testing/selftests/clone3/clone3.c
>> index e495f89..c721f8a 100644
>> --- a/tools/testing/selftests/clone3/clone3.c
>> +++ b/tools/testing/selftests/clone3/clone3.c
>> @@ -196,7 +196,12 @@ int main(int argc, char *argv[])
>> CLONE3_ARGS_NO_TEST);
>>
>> /* Do a clone3() in a new time namespace */
>> - test_clone3(CLONE_NEWTIME, 0, 0, CLONE3_ARGS_NO_TEST);
>> + if (access("/proc/self/ns/time", F_OK) == 0) {
>> + test_clone3(CLONE_NEWTIME, 0, 0, CLONE3_ARGS_NO_TEST);
>> + } else {
>> + ksft_print_msg("Time namespaces are not supported\n");
>> + ksft_test_result_skip("Skipping clone3() with CLONE_NEWTIME\n");
>> + }
>
> Patch looks good otherwise.
Thank you, I will send v5 on Friday with updated commit message
if no more comments.
Thanks,
Tiezhu