[LTP] [PATCH v5] clone3: Add clone3's clone_args cgroup

Wei Gao wegao@suse.com
Wed Aug 30 01:26:38 CEST 2023


Hi Richard

Thanks for your review. I flag my comments in former email start with [GW].

Thanks.
Regards
Gao Wei


-----Original Message-----
From: Richard Palethorpe <rpalethorpe@suse.de> 
Sent: Friday, August 25, 2023 6:36 PM
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v5] clone3: Add clone3's clone_args cgroup

Hello,

Wei Gao via ltp <ltp@lists.linux.it> writes:

> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
>  include/lapi/sched.h                        |   8 ++
>  include/tst_cgroup.h                        |   4 +
>  include/tst_clone.h                         |   1 +
>  lib/tst_cgroup.c                            |   9 ++
>  lib/tst_clone.c                             |   1 +
>  runtest/syscalls                            |   1 +
>  testcases/kernel/syscalls/clone3/.gitignore |   1 +
>  testcases/kernel/syscalls/clone3/clone303.c | 101 
> ++++++++++++++++++++
>  8 files changed, 126 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/clone3/clone303.c
>
> diff --git a/include/lapi/sched.h b/include/lapi/sched.h index 
> 1065665d1..ac766efc5 100644
> --- a/include/lapi/sched.h
> +++ b/include/lapi/sched.h
> @@ -13,6 +13,7 @@
>  #include <inttypes.h>
>  #include "config.h"
>  #include "lapi/syscalls.h"
> +#include "lapi/sched.h"
>  
>  struct sched_attr {
>  	uint32_t size;
> @@ -54,6 +55,9 @@ struct clone_args {
>  	uint64_t __attribute__((aligned(8))) stack;
>  	uint64_t __attribute__((aligned(8))) stack_size;
>  	uint64_t __attribute__((aligned(8))) tls;
> +	uint64_t __attribute__((aligned(8))) set_tid;
> +	uint64_t __attribute__((aligned(8))) set_tid_size;
> +	uint64_t __attribute__((aligned(8))) cgroup;
>  };
>  
>  static inline int clone3(struct clone_args *args, size_t size) @@ 
> -133,4 +137,8 @@ static inline int getcpu(unsigned *cpu, unsigned *node)
>  # define CLONE_NEWTIME		0x00000080
>  #endif
>  
> +#ifndef CLONE_INTO_CGROUP
> +# define CLONE_INTO_CGROUP 0x200000000ULL #endif
> +
>  #endif /* LAPI_SCHED_H__ */
> diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h index 
> 2826ddad1..be14d07c6 100644
> --- a/include/tst_cgroup.h
> +++ b/include/tst_cgroup.h
> @@ -157,6 +157,10 @@ const char *
>  tst_cg_group_name(const struct tst_cg_group *const cg)
>  		      __attribute__ ((nonnull, warn_unused_result));
>  
> +/* This call returns a fd pointing to a v2 directory */ int 
> +tst_cg_group_unified_dir_fd(const struct tst_cg_group *const cg)
> +		      __attribute__ ((nonnull, warn_unused_result));
> +
>  /* Remove a descendant CGroup */
>  struct tst_cg_group *
>  tst_cg_group_rm(struct tst_cg_group *const cg) diff --git 
> a/include/tst_clone.h b/include/tst_clone.h index 9ffdc68d1..7b278dfa7 
> 100644
> --- a/include/tst_clone.h
> +++ b/include/tst_clone.h
> @@ -11,6 +11,7 @@
>  struct tst_clone_args {
>  	uint64_t flags;
>  	uint64_t exit_signal;
> +	uint64_t cgroup;

This is not used in the test being added so I will not merge it because I don't want to do any more work than necessary (I would still merge the rest of the test, but there is another issue below). The reason is because it may cause some test which does use tst_clone_args to fail because it increases the struct size. If some other test does not initialise the members correctly we may start sending uninitialised data to the kernel.

In general I don't want to add anything which isn't immediately necessary without having to think about any potential problems it could cause.

[GW]:  The point of this case is test cgroup parameter, if you remove this then following error will happen:
tst_clone.c:18:21: error: 'const struct tst_clone_args' has no member named 'cgroup'
   .cgroup = tst_args->cgroup,


>  };
>  
>  /* clone3 with fallbacks to clone when possible. Be aware that it 
> diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c index 
> 274c73fea..43055e8cf 100644
> --- a/lib/tst_cgroup.c
> +++ b/lib/tst_cgroup.c
> @@ -1112,6 +1112,15 @@ const char *tst_cg_group_name(const struct tst_cg_group *const cg)
>  	return cg->group_name;
>  }
>  
> +int tst_cg_group_unified_dir_fd(const struct tst_cg_group *const cg) 
> +{
> +	for (int i = 0; cg->dirs[i]; i++) {
> +		if (cg->dirs[i]->dir_root->ver == TST_CG_V2)
> +			return cg->dirs[i]->dir_fd;

The loop is unecessary; cg->dirs_by_ctrl[0] is always the V2 directory if it exists.

[GW]: I have updated and sent new Patch

Otherwise the test LGTM. I'll set to changes requested in patchwork.

--
Thank you,
Richard.


More information about the ltp mailing list