clone3: allow creation of time namespace with offset
Subsystems (7)
This is an attempt to add time namespace support to clone3(). I am not really sure which way clone3() should handle time namespaces. The time namespace through /proc cannot be used with clone3() because the offsets for the time namespace need to be written before a process has been created in that time namespace. This means it is necessary to somehow tell clone3() the offsets for the clocks.
The time namespace offers the possibility to set offsets for CLOCK_MONOTONIC and CLOCK_BOOTTIME. My first approach was to extend 'struct clone_args` with '__aligned_u64 monotonic_offset' and '__aligned_u64 boottime_offset'. The problem with this approach was that it was not possible to set nanoseconds for the clocks in the time namespace.
One of the motivations for clone3() with CLONE_NEWTIME was to enable CRIU to restore a process in a time namespace with the corresponding offsets. And although the nanosecond value can probably never be restored to the same value it had during checkpointing, because the clock keeps on running between CRIU pausing all processes and CRIU actually reading the value of the clocks, the nanosecond value is still necessary for CRIU to not restore a process where the clock jumps back due to CRIU restoring it with a nanonsecond value that is too small.
Requiring nanoseconds as well as seconds for two clocks during clone3() means that it would require 4 additional members to 'struct clone_args':
__aligned_u64 tls;
__aligned_u64 set_tid;
__aligned_u64 set_tid_size;
+ __aligned_u64 boottime_offset_seconds;
+ __aligned_u64 boottime_offset_nanoseconds;
+ __aligned_u64 monotonic_offset_seconds;
+ __aligned_u64 monotonic_offset_nanoseconds;};
To avoid four additional members to 'struct clone_args' this patchset uses another approach:
__aligned_u64 tls;
__aligned_u64 set_tid;
__aligned_u64 set_tid_size;+ __aligned_u64 timens_offset;
+ __aligned_u64 timens_offset_size;
};
timens_offset is a pointer to an array just as previously done with set_tid and timens_offset_size is the size of the array.
The timens_offset array is expected to contain a struct like this:
struct set_timens_offset {
int clockid;
struct timespec val;
};This way it is possible to pass the information of multiple clocks with seconds and nanonseconds to clone3().
To me this seems the better approach, but I am not totally convinced that it is the right thing. If there are other ideas how to pass two clock offsets with seconds and nanonseconds to clone3() I would be happy to hear other ideas.
Adrian
PATCH 1/4 ns: prepare time namespace for clone3()
To enable clone3()ing a process directly into a new time namespace with a clock offset, this changes the time namespace code by renaming the variable proc_timens_offset (which was used to set a timens offset via /proc) to set_timens_offset to avoid confusion why it will be used in clone3() without being related to /proc.
This also moves out the code of actually setting the clock offsets to its own function to be later used via clone3().
--- fs/proc/base.c | 4 +- include/linux/time_namespace.h | 16 +++-- kernel/time/namespace.c | 126 +++++++++++++++++---------------- 3 files changed, 78 insertions(+), 68 deletions(-)
fs/proc/base.c +2 -2
@@ -1554,7 +1554,7 @@ static ssize_t timens_offsets_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { struct inode *inode = file_inode(file); -struct proc_timens_offset offsets[2 ]; +struct set_timens_offset offsets[2 ];char *kbuf =NULL , *pos, *next_line;struct task_struct *p;int ret, noffsets;
@@ -1572,7 +1572,7 @@ static ssize_t timens_offsets_write(struct file *file, const char __user *buf, ret = -EINVAL ; noffsets =0 ;for (pos = kbuf; pos; pos = next_line) { -struct proc_timens_offset *off = &offsets[noffsets]; +struct set_timens_offset *off = &offsets[noffsets];int err;/* Find the end of line and ensure we don't look past it */
include/linux/time_namespace.h +10 -6
@@ -30,6 +30,15 @@ struct time_namespace {extern struct time_namespace init_time_ns; +/* +* This structure is used to set the time namespace offset +* via /proc as well as via clone3(). +*/ +struct set_timens_offset { +int clockid; +struct timespec64 val; +}; +#ifdef CONFIG_TIME_NS extern int vdso_join_timens (struct task_struct *task,struct time_namespace *ns);
@@ -54,13 +63,8 @@ static inline void put_time_ns(struct time_namespace *ns)void proc_timens_show_offsets (struct task_struct *p,struct seq_file *m); -struct proc_timens_offset { -int clockid; -struct timespec64 val; -}; -int proc_timens_set_offset (struct file *file,struct task_struct *p, -struct proc_timens_offset *offsets,int n); +struct set_timens_offset *offsets,int n);static inline void timens_add_monotonic (struct timespec64 *ts) {
kernel/time/namespace.c +66 -60
147 lines not on this page · raw message
base-commit: 8b614cb8f1dcac8ca77cf4dd85f46ef3055f8238
Signature · 1 line
2.24.1
Re: [PATCH 1/4] ns: prepare time namespace for clone3()
On Tue, Mar 17, 2020 at 09:30:41AM +0100, Adrian Reber wrote:
...
include/linux/time_namespace.h struct time_namespace { · line 41
Quoted 9 lines
include/linux/time_namespace.h +9
-0+/* +* This structure is used to set the time namespace offset +* via /proc as well as via clone3(). +*/ +struct set_timens_offset { +int clockid; +struct timespec64 val; +}; +
I'm sorry, I didn't follow this series much so can't comment right now. Still this structure made me a bit wonder -- the @val seems to be 8 byte aligned and I guess we have a useless pad between these members. If so can we swap them? Or it is already part of api?
Re: [PATCH 1/4] ns: prepare time namespace for clone3()
Quoted 16 lines · Cyrill Gorcunov
On Tue, Mar 17, 2020 at 09:30:41AM +0100, Adrian Reber wrote:
...include/linux/time_namespace.h struct time_namespace { · line 41
Quoted 9 lines
include/linux/time_namespace.h +9
-0+/* +* This structure is used to set the time namespace offset +* via /proc as well as via clone3(). +*/ +struct set_timens_offset { +int clockid; +struct timespec64 val; +}; +I'm sorry, I didn't follow this series much so can't comment right now. Still this structure made me a bit wonder -- the @val seems to be 8 byte aligned and I guess we have a useless pad between these members. If so can we swap them? Or it is already part of api?
It's not part of the api yet. We're still arguing about how and what we want to pass down.
Re: [PATCH 1/4] ns: prepare time namespace for clone3()
Quoted 18 lines · Christian Brauner
Quoted 16 lines · Cyrill Gorcunov
On Tue, Mar 17, 2020 at 09:30:41AM +0100, Adrian Reber wrote:
...include/linux/time_namespace.h struct time_namespace { · line 41
Quoted 9 lines
include/linux/time_namespace.h +9
-0+/* +* This structure is used to set the time namespace offset +* via /proc as well as via clone3(). +*/ +struct set_timens_offset { +int clockid; +struct timespec64 val; +}; +I'm sorry, I didn't follow this series much so can't comment right now. Still this structure made me a bit wonder -- the @val seems to be 8 byte aligned and I guess we have a useless pad between these members. If so can we swap them? Or it is already part of api?
Quoted 2 lines
It's not part of the api yet. We're still arguing about how and what we want to pass down.
I see, thanks for info! So I think we could swap the members.
Re: [PATCH 1/4] ns: prepare time namespace for clone3()
Quoted 19 lines · Cyrill Gorcunov
Quoted 18 lines · Christian Brauner
Quoted 16 lines · Cyrill Gorcunov
On Tue, Mar 17, 2020 at 09:30:41AM +0100, Adrian Reber wrote:
...include/linux/time_namespace.h struct time_namespace { · line 41
Quoted 9 lines
include/linux/time_namespace.h +9
-0+/* +* This structure is used to set the time namespace offset +* via /proc as well as via clone3(). +*/ +struct set_timens_offset { +int clockid; +struct timespec64 val; +}; +I'm sorry, I didn't follow this series much so can't comment right now. Still this structure made me a bit wonder -- the @val seems to be 8 byte aligned and I guess we have a useless pad between these members. If so can we swap them? Or it is already part of api?
Quoted 4 lines
Quoted 2 lines
It's not part of the api yet. We're still arguing about how and what we want to pass down.
I see, thanks for info! So I think we could swap the members.
Yeah, _if_ we go with a version of this struct we definitely need to ensure proper padding/alignment!
Re: [PATCH 1/4] ns: prepare time namespace for clone3()
Quoted 20 lines · Christian Brauner
Quoted 19 lines · Cyrill Gorcunov
Quoted 18 lines · Christian Brauner
Quoted 16 lines · Cyrill Gorcunov
On Tue, Mar 17, 2020 at 09:30:41AM +0100, Adrian Reber wrote:
...include/linux/time_namespace.h struct time_namespace { · line 41
Quoted 9 lines
include/linux/time_namespace.h +9
-0+/* +* This structure is used to set the time namespace offset +* via /proc as well as via clone3(). +*/ +struct set_timens_offset { +int clockid; +struct timespec64 val; +}; +I'm sorry, I didn't follow this series much so can't comment right now. Still this structure made me a bit wonder -- the @val seems to be 8 byte aligned and I guess we have a useless pad between these members. If so can we swap them? Or it is already part of api?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
It's not part of the api yet. We're still arguing about how and what we want to pass down.
I see, thanks for info! So I think we could swap the members.
Yeah, _if_ we go with a version of this struct we definitely need to ensure proper padding/alignment!
Input/ideas totally welcome of course!
Re: [PATCH 1/4] ns: prepare time namespace for clone3()
Quoted 7 lines · Christian Brauner
Quoted 5 lines
Quoted 2 lines
I see, thanks for info! So I think we could swap the members.
Yeah, _if_ we go with a version of this struct we definitely need to ensure proper padding/alignment!
Input/ideas totally welcome of course!
I'll try to take a look once time permit, but no promises though.
PATCH 2/4 clone3: allow creation of time namespace with offset
In reply to Adrian ReberThis extends clone3() to support the time namespace via CLONE_NEWTIME. In addition to creating a new process in a new time namespace this allows setting the clock offset in the newly created time namspace.
The time namespace allows to set an offset for two clocks. CLOCK_MONOTONIC and CLOCK_BOOTTIME.
This clone3() extension also offers setting both offsets through the newly introduced clone_args members timens_offset and timens_offset_size.
timens_offset: Pointer to an array of clock offsets for the
newly created process in a time namespaces. This requires that a new time namespace has been requested via CLONE_NEWTIME. It is only possible to set an offset for CLOCK_MONOTONIC and CLOCK_BOOTTIME. The array can therefore never have more than two elements.
clone3() expects the array to contain the following struct:
struct set_timens_offset {
int clockid;
struct timespec val;
};
timens_offset_size: This defines the size of the array referenced
in timens_offset. Currently this is limited to two elements.
To create a new process using clone3() in a new time namespace with clock offsets, something like this can be used:
struct set_timens_offset timens_offset[2];
timens_offset[0].clockid = CLOCK_BOOTTIME;
timens_offset[0].val.tv_sec = -1000;
timens_offset[0].val.tv_nsec = 42;
timens_offset[1].clockid = CLOCK_MONOTONIC;
timens_offset[1].val.tv_sec = 1000000;
timens_offset[1].val.tv_nsec = 37;
struct _clone_args args = {
.flags = CLONE_NEWTIME,
.timens_offset = ptr_to_u64(timens_offset),
.timens_offset_size = 2;
};Although the command-line tool unshare only supports setting the offset in seconds and not nanoseconds, it is possible to set nanoseconds using the /proc interface of the time namespace. Therefore (and for CRIU) it probably makes sense to offer nanoseconds also via clone3().
The main motivation for the clone3() integration is to enable CRIU to restore time namespaces. Not sure how useful the restoration of the nanosecond value for CRIU is, as during the time the process is paused by CRIU the clock will continue to run, so that the nanosecond value will not be the same as when the process has been paused. Between pausing the process and reading all time namespace information for all paused process the nanosecond value will change, so that CRIU will never be able to restore a process with exactly the same nanosecond value the process had when it was paused. It will make sure, however, that the nanosecond value will not jump back. So maybe it is useful for CRIU in the end.
--- include/linux/nsproxy.h | 4 +++- include/linux/sched/task.h | 3 +++ include/linux/time_namespace.h | 7 +++++-- include/uapi/linux/sched.h | 19 +++++++++++++++++ kernel/fork.c | 35 ++++++++++++++++++++++++++++++-- kernel/nsproxy.c | 5 +++-- kernel/time/namespace.c | 11 +++++++++- tools/include/uapi/linux/sched.h | 1 + 8 files changed, 77 insertions(+), 8 deletions(-)
include/linux/nsproxy.h +3 -1
@@ -11,6 +11,7 @@ struct ipc_namespace;struct pid_namespace ;struct cgroup_namespace ;struct fs_struct ; +struct set_timens_offset ;/* * A structure to contain pointers to all per-process
@@ -67,7 +68,8 @@ extern struct nsproxy init_nsproxy;* */ -int copy_namespaces (unsigned long flags,struct task_struct *tsk); +int copy_namespaces (unsigned long flags,struct task_struct *tsk, +struct set_timens_offset *offsets,int noffsets);void exit_task_namespaces (struct task_struct *tsk);void switch_task_namespaces (struct task_struct *tsk,struct nsproxy *new);void free_nsproxy (struct nsproxy *ns);
include/linux/sched/task.h +3 -0
@@ -9,6 +9,7 @@#include <linux/sched.h> #include <linux/uaccess.h> +#include <linux/time.h> struct task_struct ;struct rusage ;
@@ -29,6 +30,8 @@ struct kernel_clone_args {pid_t *set_tid;/* Number of elements in *set_tid */ size_t set_tid_size; +struct set_timens_offset *timens_offset; +size_t timens_offset_size; };/*
include/linux/time_namespace.h +5 -2
@@ -53,7 +53,8 @@ struct time_namespace *copy_time_ns(unsigned long flags,struct user_namespace *user_ns, struct time_namespace *old_ns);void free_time_ns (struct kref *kref); -int timens_on_fork (struct nsproxy *nsproxy,struct task_struct *tsk); +int timens_on_fork (struct nsproxy *nsproxy,struct task_struct *tsk, +struct set_timens_offset *offsets,int noffsets);struct vdso_data *arch_get_vdso_data (void *vvar_page);static inline void put_time_ns (struct time_namespace *ns)
@@ -121,7 +122,9 @@ struct time_namespace *copy_time_ns(unsigned long flags, }static inline int timens_on_fork (struct nsproxy *nsproxy, -struct task_struct *tsk) +struct task_struct *tsk, +struct set_timens_offset *offsets, +int noffsets) {return 0 ; }
include/uapi/linux/sched.h +19 -0
@@ -81,6 +81,22 @@* @set_tid_size: This defines the size of the array referenced * in @set_tid. This cannot be larger than the * kernel's limit of nested PID namespaces. +* @timens_offset: Pointer to an array of clock offsets for the +* newly created process in a time namespaces. +* This requires that a new time namespace has been +* requested via CLONE_NEWTIME. It is only possible +* to set an offset for CLOCK_MONOTONIC and +* CLOCK_BOOTTIME. The array can therefore never +* have more than two elements. +* clone3() expects the array to contain the +* following struct: +* struct set_timens_offset { +* int clockid; +* struct timespec val; +* }; +* @timens_offset_size: This defines the size of the array referenced +* in @timens_offset. Currently this is limited +* to two elements. * * The structure is versioned by size and thus extensible. * New struct members must go at the end of the struct and
@@ -97,11 +113,14 @@ struct clone_args {__aligned_u64 tls;__aligned_u64 set_tid;__aligned_u64 set_tid_size; +__aligned_u64 timens_offset; + __aligned_u64 timens_offset_size; };#endif #define CLONE_ARGS_SIZE_VER0 64/* sizeof first published struct */ #define CLONE_ARGS_SIZE_VER1 80/* sizeof second published struct */ +#define CLONE_ARGS_SIZE_VER2 96/* sizeof third published struct */ /* * Scheduling policies
kernel/fork.c +33 -2
@@ -94,6 +94,7 @@#include <linux/thread_info.h> #include <linux/stackleak.h> #include <linux/kasan.h> +#include <linux/time_namespace.h> #include <asm/pgtable.h> #include <asm/pgalloc.h>
@@ -2081,7 +2082,8 @@ static __latent_entropy struct task_struct *copy_process( retval =copy_mm (clone_flags, p);if (retval) goto bad_fork_cleanup_signal; - retval =copy_namespaces (clone_flags, p); + retval =copy_namespaces (clone_flags, p, args->timens_offset, + args->timens_offset_size);if (retval) goto bad_fork_cleanup_mm; retval =copy_io (clone_flags, p);
@@ -2604,6 +2606,7 @@ noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,int err;struct clone_args args;pid_t *kset_tid = kargs->set_tid; +struct set_timens_offset *ktimens_offset = kargs->timens_offset;if (unlikely (usize >PAGE_SIZE ))return -E2BIG ;
@@ -2623,6 +2626,23 @@ noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,if (unlikely (args.set_tid && args.set_tid_size ==0 ))return -EINVAL ; +/* +* Currently the time namespace supports setting two clocks: +* CLOCK_MONOTONIC and CLOCK_BOOTTIME +*/ +if (unlikely (args.timens_offset_size >2 )) +return -EINVAL ; + +if (unlikely (!args.timens_offset && args.timens_offset_size >0 )) +return -EINVAL ; + +if (unlikely (args.timens_offset && args.timens_offset_size ==0 )) +return -EINVAL ; + +if (unlikely ((args.timens_offset && args.timens_offset_size) + && !(args.flags &CLONE_NEWTIME ))) +return -EINVAL ; +/* * Verify that higher 32bits of exit_signal are unset and that * it is a valid signal
@@ -2641,6 +2661,7 @@ noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs, .stack_size = args.stack_size, .tls = args.tls, .set_tid_size = args.set_tid_size, + .timens_offset_size = args.timens_offset_size, }; if (args.set_tid &&
@@ -2648,7 +2669,15 @@ noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs, (kargs->set_tid_size * sizeof(pid_t))))return -EFAULT ; +if (args.timens_offset && +copy_from_user (ktimens_offset, +u64_to_user_ptr (args.timens_offset), + (kargs->timens_offset_size * +sizeof (struct set_timens_offset )))) +return -EFAULT ; + kargs->set_tid = kset_tid; + kargs->timens_offset = ktimens_offset;return 0 ; }
@@ -2691,7 +2720,7 @@ static bool clone3_args_valid(struct kernel_clone_args *kargs)* - make the CLONE_DETACHED bit reuseable for clone3 * - make the CSIGNAL bits reuseable for clone3 */ -if (kargs->flags & (CLONE_DETACHED |CSIGNAL )) +if (kargs->flags & ((CLONE_DETACHED |CSIGNAL ) & ~CLONE_NEWTIME ))return false; if ((kargs->flags & (CLONE_SIGHAND | CLONE_CLEAR_SIGHAND)) ==
@@ -2725,8 +2754,10 @@ SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size)struct kernel_clone_args kargs;pid_t set_tid[MAX_PID_NS_LEVEL ]; +struct set_timens_offset timens_offset[2 ]; kargs.set_tid = set_tid; + kargs.timens_offset = timens_offset; err =copy_clone_args_from_user (&kargs, uargs, size);if (err)
kernel/nsproxy.c +3 -2
@@ -146,7 +146,8 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,* called from clone. This now handles copy for nsproxy and all * namespaces therein. */ -int copy_namespaces (unsigned long flags,struct task_struct *tsk) +int copy_namespaces (unsigned long flags,struct task_struct *tsk, +struct set_timens_offset *offsets,int noffsets) {struct nsproxy *old_ns = tsk->nsproxy;struct user_namespace *user_ns =task_cred_xxx (tsk, user_ns);
@@ -178,7 +179,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)if (IS_ERR (new_ns))return PTR_ERR (new_ns); - ret =timens_on_fork (new_ns, tsk); + ret =timens_on_fork (new_ns, tsk, offsets, noffsets);if (ret) {free_nsproxy (new_ns);return ret;
kernel/time/namespace.c +10 -1
@@ -370,7 +370,8 @@ static int timens_set_offset(struct task_struct *p, struct time_namespace *ns,return err; } -int timens_on_fork (struct nsproxy *nsproxy,struct task_struct *tsk) +int timens_on_fork (struct nsproxy *nsproxy,struct task_struct *tsk, +struct set_timens_offset *offsets,int noffsets) {struct ns_common *nsc = &nsproxy->time_ns_for_children->ns;struct time_namespace *ns =to_time_ns (nsc);
@@ -380,6 +381,14 @@ int timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk)if (nsproxy->time_ns == nsproxy->time_ns_for_children)return 0 ; +if (noffsets) { +if (!ns_capable (ns->user_ns,CAP_SYS_TIME )) +return -EPERM ; + err =timens_set_offset (tsk, ns, offsets, noffsets); +if (err) +return err; + } +timens_set_vvar_page (tsk, ns); err =vdso_join_timens (tsk, ns);
tools/include/uapi/linux/sched.h +1 -0
@@ -102,6 +102,7 @@ struct clone_args {#define CLONE_ARGS_SIZE_VER0 64/* sizeof first published struct */ #define CLONE_ARGS_SIZE_VER1 80/* sizeof second published struct */ +#define CLONE_ARGS_SIZE_VER2 96/* sizeof third published struct */ /* * Scheduling policies
Signature · 1 line
2.24.1
Quoted 32 lines · Adrian Reber
This extends
clone3()to support the time namespace viaCLONE_NEWTIME. In addition to creating a new process in a new time namespace this allows setting the clock offset in the newly created time namspace.The time namespace allows to set an offset for two clocks.
CLOCK_MONOTONICandCLOCK_BOOTTIME.This
clone3()extension also offers setting both offsets through the newly introducedclone_argsmemberstimens_offsetandtimens_offset_size.
timens_offset: Pointer to an array of clock offsets for the
newly created process in a time namespaces. This requires that a new time namespace has been requested viaCLONE_NEWTIME. It is only possible to set an offset forCLOCK_MONOTONICandCLOCK_BOOTTIME. The array can therefore never have more than two elements.
clone3()expects the array to contain the following struct:
structset_timens_offset{
int clockid;
struct timespec val;
};
timens_offset_size: This defines the size of the array referenced
intimens_offset. Currently this is limited to two elements.To create a new process using
clone3()in a new time namespace with clock offsets, something like this can be used:
Quoted 14 lines
struct set_timens_offset timens_offset[2];
timens_offset[0].clockid = CLOCK_BOOTTIME;
timens_offset[0].val.tv_sec = -1000;
timens_offset[0].val.tv_nsec = 42;
timens_offset[1].clockid = CLOCK_MONOTONIC;
timens_offset[1].val.tv_sec = 1000000;
timens_offset[1].val.tv_nsec = 37;
struct _clone_args args = {
.flags = CLONE_NEWTIME,
.timens_offset = ptr_to_u64(timens_offset),
.timens_offset_size = 2;
};In all honesty, this would be a terrible API and I think we need to come up with something better than this. I don't want to pass down an array of structs and in general would like to avoid this array + size pattern. That pattern kinda made sense for the pid array because of pid namespaces being nested but not for this case, I think. Also, why require the additional clockid argument here? That makes sense for clock_settime() and clock_gettime() but here we could just do:
struct timens {
struct timespec clock_bootime;
struct timespec clock_monotonic;
};no? And since you need to expose that struct in a header somewhere anyway you can version it by size just like clone_args. So the kernel can apply the same pattern to be backwards compatible that we have with struct clone_args and for openat2()'s struct open_how via copy_struct_from_user. Then you only need one additional pointer in struct clone_args.
What do we think?
Christian
PATCH 3/4 clone3: align structs and comments
In reply to Adrian ReberTo follow the existing style this commit aligns the comments and structure settings to have the same look as before. Just with more spaces.
--- include/uapi/linux/sched.h | 72 +++++++++++++++++++------------------- kernel/fork.c | 18 +++++----- 2 files changed, 45 insertions(+), 45 deletions(-)
include/uapi/linux/sched.h +36 -36
@@ -45,42 +45,42 @@#ifndef __ASSEMBLY__/** * struct clone_args - arguments for the clone3 syscall -* @flags: Flags for the new process as listed above. -* All flags are valid except for CSIGNAL and -* CLONE_DETACHED. -* @pidfd: If CLONE_PIDFD is set, a pidfd will be -* returned in this argument. -* @child_tid: If CLONE_CHILD_SETTID is set, the TID of the -* child process will be returned in the child's -* memory. -* @parent_tid: If CLONE_PARENT_SETTID is set, the TID of -* the child process will be returned in the -* parent's memory. -* @exit_signal: The exit_signal the parent process will be -* sent when the child exits. -* @stack: Specify the location of the stack for the -* child process. -* Note, @stack is expected to point to the -* lowest address. The stack direction will be -* determined by the kernel and set up -* appropriately based on @stack_size. -* @stack_size: The size of the stack for the child process. -* @tls: If CLONE_SETTLS is set, the tls descriptor -* is set to tls. -* @set_tid: Pointer to an array of type *pid_t. The size -* of the array is defined using @set_tid_size. -* This array is used to select PIDs/TIDs for -* newly created processes. The first element in -* this defines the PID in the most nested PID -* namespace. Each additional element in the array -* defines the PID in the parent PID namespace of -* the original PID namespace. If the array has -* less entries than the number of currently -* nested PID namespaces only the PIDs in the -* corresponding namespaces are set. -* @set_tid_size: This defines the size of the array referenced -* in @set_tid. This cannot be larger than the -* kernel's limit of nested PID namespaces. +* @flags: Flags for the new process as listed above. +* All flags are valid except for CSIGNAL and +* CLONE_DETACHED. +* @pidfd: If CLONE_PIDFD is set, a pidfd will be +* returned in this argument. +* @child_tid: If CLONE_CHILD_SETTID is set, the TID of the +* child process will be returned in the child's +* memory. +* @parent_tid: If CLONE_PARENT_SETTID is set, the TID of +* the child process will be returned in the +* parent's memory. +* @exit_signal: The exit_signal the parent process will be +* sent when the child exits. +* @stack: Specify the location of the stack for the +* child process. +* Note, @stack is expected to point to the +* lowest address. The stack direction will be +* determined by the kernel and set up +* appropriately based on @stack_size. +* @stack_size: The size of the stack for the child process. +* @tls: If CLONE_SETTLS is set, the tls descriptor +* is set to tls. +* @set_tid: Pointer to an array of type *pid_t. The size +* of the array is defined using @set_tid_size. +* This array is used to select PIDs/TIDs for +* newly created processes. The first element in +* this defines the PID in the most nested PID +* namespace. Each additional element in the array +* defines the PID in the parent PID namespace of +* the original PID namespace. If the array has +* less entries than the number of currently +* nested PID namespaces only the PIDs in the +* corresponding namespaces are set. +* @set_tid_size: This defines the size of the array referenced +* in @set_tid. This cannot be larger than the +* kernel's limit of nested PID namespaces. * @timens_offset: Pointer to an array of clock offsets for the * newly created process in a time namespaces. * This requires that a new time namespace has been
kernel/fork.c +9 -9
@@ -2652,15 +2652,15 @@ noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,return -EINVAL ; *kargs = (struct kernel_clone_args ){ - .flags = args.flags, - .pidfd =u64_to_user_ptr (args.pidfd), - .child_tid =u64_to_user_ptr (args.child_tid), - .parent_tid =u64_to_user_ptr (args.parent_tid), - .exit_signal = args.exit_signal, - .stack = args.stack, - .stack_size = args.stack_size, - .tls = args.tls, - .set_tid_size = args.set_tid_size, + .flags = args.flags, + .pidfd =u64_to_user_ptr (args.pidfd), + .child_tid =u64_to_user_ptr (args.child_tid), + .parent_tid =u64_to_user_ptr (args.parent_tid), + .exit_signal = args.exit_signal, + .stack = args.stack, + .stack_size = args.stack_size, + .tls = args.tls, + .set_tid_size = args.set_tid_size, .timens_offset_size = args.timens_offset_size, };
Signature · 1 line
2.24.1
PATCH 4/4 selftests: add clone3() in time namespace test
In reply to Adrian ReberThis adds a test to use clone3() with CLONE_NEWTIME. The test tries to set CLOCK_BOOTTIME to 1 in the new process in the new time namespace and CLOCK_MONOTONIC to +10000.
--- tools/testing/selftests/timens/Makefile | 4 +- tools/testing/selftests/timens/clone3.c | 134 ++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/timens/clone3.c
tools/testing/selftests/timens/Makefile +2 -2
@@ -1,7 +1,7 @@ -TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs exec +TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs exec clone3 TEST_GEN_PROGS_EXTENDED := gettime_perf -CFLAGS := -Wall -Werror -pthread +CFLAGS := -Wall -Werror -pthread -I../../../../usr/include/ LDLIBS := -lrt -ldl include ../lib.mk
tools/testing/selftests/timens/clone3.c new file +134 -0
134 lines not on this page · raw message
Signature · 1 line
2.24.1
Quoted 41 lines · Adrian Reber
This is an attempt to add time namespace support to
clone3(). I am not really sure which wayclone3()should handle time namespaces. The time namespace through /proc cannot be used withclone3()because the offsets for the time namespace need to be written before a process has been created in that time namespace. This means it is necessary to somehow tellclone3()the offsets for the clocks.The time namespace offers the possibility to set offsets for
CLOCK_MONOTONICandCLOCK_BOOTTIME. My first approach was to extend 'struct clone_args` with '__aligned_u64monotonic_offset' and '__aligned_u64boottime_offset'. The problem with this approach was that it was not possible to set nanoseconds for the clocks in the time namespace.One of the motivations for
clone3()withCLONE_NEWTIMEwas to enable CRIU to restore a process in a time namespace with the corresponding offsets. And although the nanosecond value can probably never be restored to the same value it had during checkpointing, because the clock keeps on running between CRIU pausing all processes and CRIU actually reading the value of the clocks, the nanosecond value is still necessary for CRIU to not restore a process where the clock jumps back due to CRIU restoring it with a nanonsecond value that is too small.Requiring nanoseconds as well as seconds for two clocks during
clone3()means that it would require 4 additional members to 'structclone_args':__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +4
-0+ __aligned_u64 boottime_offset_seconds; + __aligned_u64 boottime_offset_nanoseconds; + __aligned_u64 monotonic_offset_seconds; + __aligned_u64 monotonic_offset_nanoseconds; };To avoid four additional members to 'struct
clone_args' this patchset uses another approach:__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;
Review
Quoted 2 lines
(quoted diff) +2
-0+ __aligned_u64 timens_offset; + __aligned_u64 timens_offset_size;
Hm, so for set_tid we did set_tid and set_tid_size which makes sense because set_tid wasn't actually a struct. But I'm not a fan of establishing a pattern whereby we always have to grow two member, the object and it's size; at least when we're adding a struct. So at a first glance here are two possible ideas:
- Don't add a size argument and assume that struct timens_offset won't grow. I'm not sure how likely it is it will grow.
- Make the size the first member of struct timens_offset the size of the struct. (See examples for this pattern in the sched syscalls.)
Christian
Quoted 45 lines · Christian Brauner
Quoted 41 lines · Adrian Reber
This is an attempt to add time namespace support to
clone3(). I am not really sure which wayclone3()should handle time namespaces. The time namespace through /proc cannot be used withclone3()because the offsets for the time namespace need to be written before a process has been created in that time namespace. This means it is necessary to somehow tellclone3()the offsets for the clocks.The time namespace offers the possibility to set offsets for
CLOCK_MONOTONICandCLOCK_BOOTTIME. My first approach was to extend 'struct clone_args` with '__aligned_u64monotonic_offset' and '__aligned_u64boottime_offset'. The problem with this approach was that it was not possible to set nanoseconds for the clocks in the time namespace.One of the motivations for
clone3()withCLONE_NEWTIMEwas to enable CRIU to restore a process in a time namespace with the corresponding offsets. And although the nanosecond value can probably never be restored to the same value it had during checkpointing, because the clock keeps on running between CRIU pausing all processes and CRIU actually reading the value of the clocks, the nanosecond value is still necessary for CRIU to not restore a process where the clock jumps back due to CRIU restoring it with a nanonsecond value that is too small.Requiring nanoseconds as well as seconds for two clocks during
clone3()means that it would require 4 additional members to 'structclone_args':__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +4
-0+ __aligned_u64 boottime_offset_seconds; + __aligned_u64 boottime_offset_nanoseconds; + __aligned_u64 monotonic_offset_seconds; + __aligned_u64 monotonic_offset_nanoseconds; };To avoid four additional members to 'struct
clone_args' this patchset uses another approach:__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 2 lines
(quoted diff) +2
-0+ __aligned_u64 timens_offset; + __aligned_u64 timens_offset_size;
Quoted 9 lines
Hm, so for
set_tidwe didset_tidandset_tid_sizewhich makes sense becauseset_tidwasn't actually a struct. But I'm not a fan of establishing a pattern whereby we always have to grow two member, the object and it's size; at least when we're adding a struct. So at a first glance here are two possible ideas:
- Don't add a size argument and assume that structtimens_offsetwon't grow. I'm not sure how likely it is it will grow.
- Make the size the first member of structtimens_offsetthe size of the struct. (See examples for this pattern in the sched syscalls.)
Oh, and I should point out right way that I consider this material for the v5.8 merge window. It's too late in this cycle to land this with any confidence in v5.7. Just so there's no disappointment. :) The good news is that this leaves us with ample time to figure this out.
Christian
[CC += linux-api; please CC on future versions]
Quoted 67 lines · Adrian Reber
This is an attempt to add time namespace support to
clone3(). I am not really sure which wayclone3()should handle time namespaces. The time namespace through /proc cannot be used withclone3()because the offsets for the time namespace need to be written before a process has been created in that time namespace. This means it is necessary to somehow tellclone3()the offsets for the clocks.The time namespace offers the possibility to set offsets for
CLOCK_MONOTONICandCLOCK_BOOTTIME. My first approach was to extend 'struct clone_args` with '__aligned_u64monotonic_offset' and '__aligned_u64boottime_offset'. The problem with this approach was that it was not possible to set nanoseconds for the clocks in the time namespace.One of the motivations for
clone3()withCLONE_NEWTIMEwas to enable CRIU to restore a process in a time namespace with the corresponding offsets. And although the nanosecond value can probably never be restored to the same value it had during checkpointing, because the clock keeps on running between CRIU pausing all processes and CRIU actually reading the value of the clocks, the nanosecond value is still necessary for CRIU to not restore a process where the clock jumps back due to CRIU restoring it with a nanonsecond value that is too small.Requiring nanoseconds as well as seconds for two clocks during
clone3()means that it would require 4 additional members to 'structclone_args':__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +4
-0+ __aligned_u64 boottime_offset_seconds; + __aligned_u64 boottime_offset_nanoseconds; + __aligned_u64 monotonic_offset_seconds; + __aligned_u64 monotonic_offset_nanoseconds; };To avoid four additional members to 'struct
clone_args' this patchset uses another approach:__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +2
-0+ __aligned_u64 timens_offset; + __aligned_u64 timens_offset_size; };
timens_offsetis a pointer to an array just as previously done withset_tidandtimens_offset_sizeis the size of the array.The
timens_offsetarray is expected to contain a struct like this:struct set_timens_offset { int clockid; struct timespec val; };This way it is possible to pass the information of multiple clocks with seconds and nanonseconds to
clone3().To me this seems the better approach, but I am not totally convinced that it is the right thing. If there are other ideas how to pass two clock offsets with seconds and nanonseconds to
clone3()I would be happy to hear other ideas.Adrian
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Quoted 42 lines · Michael Kerrisk (man-pages)
[CC += linux-api; please CC on future versions]
Quoted 39 lines · Adrian Reber
Requiring nanoseconds as well as seconds for two clocks during
clone3()means that it would require 4 additional members to 'structclone_args':__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +4
-0+ __aligned_u64 boottime_offset_seconds; + __aligned_u64 boottime_offset_nanoseconds; + __aligned_u64 monotonic_offset_seconds; + __aligned_u64 monotonic_offset_nanoseconds; };To avoid four additional members to 'struct
clone_args' this patchset uses another approach:__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +2
-0+ __aligned_u64 timens_offset; + __aligned_u64 timens_offset_size; };
timens_offsetis a pointer to an array just as previously done withset_tidandtimens_offset_sizeis the size of the array.The
timens_offsetarray is expected to contain a struct like this:struct set_timens_offset { int clockid; struct timespec val; };This way it is possible to pass the information of multiple clocks with seconds and nanonseconds to
clone3().To me this seems the better approach, but I am not totally convinced that it is the right thing. If there are other ideas how to pass two clock offsets with seconds and nanonseconds to
clone3()I would be happy to hear other ideas.
While I agree this does make the API cleaner, I am a little worried that it risks killing some of the ideas we discussed for seccomp deep inspection. In particular, having a pointer to variable-sized data inside the struct means that now the cBPF program can't just be given a copy of the struct data from userspace to check.
I'm sure it's a solveable problem (and it was one we were bound to run into at some point), it'll just mean we'll need a more complicated way of filtering such syscalls.
Signature · 4 lines
Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH <https://www.cyphar.com/>
Quoted 44 lines · Aleksa Sarai
Quoted 42 lines · Michael Kerrisk (man-pages)
[CC += linux-api; please CC on future versions]
Quoted 39 lines · Adrian Reber
Requiring nanoseconds as well as seconds for two clocks during
clone3()means that it would require 4 additional members to 'structclone_args':__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +4
-0+ __aligned_u64 boottime_offset_seconds; + __aligned_u64 boottime_offset_nanoseconds; + __aligned_u64 monotonic_offset_seconds; + __aligned_u64 monotonic_offset_nanoseconds; };To avoid four additional members to 'struct
clone_args' this patchset uses another approach:__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +2
-0+ __aligned_u64 timens_offset; + __aligned_u64 timens_offset_size; };
timens_offsetis a pointer to an array just as previously done withset_tidandtimens_offset_sizeis the size of the array.The
timens_offsetarray is expected to contain a struct like this:struct set_timens_offset { int clockid; struct timespec val; };This way it is possible to pass the information of multiple clocks with seconds and nanonseconds to
clone3().To me this seems the better approach, but I am not totally convinced that it is the right thing. If there are other ideas how to pass two clock offsets with seconds and nanonseconds to
clone3()I would be happy to hear other ideas.
Quoted 5 lines
While I agree this does make the API cleaner, I am a little worried that it risks killing some of the ideas we discussed for seccomp deep inspection. In particular, having a pointer to variable-sized data inside the struct means that now the cBPF program can't just be given a copy of the struct data from userspace to check.
I suggested two alternative approaches in a response to this. The easiest one would be to simple assume that the struct doesn't change size.
(But haven't we crossed that bridge with the set_tid array already?)
Quoted 30 lines · Adrian Reber
This is an attempt to add time namespace support to
clone3(). I am not really sure which wayclone3()should handle time namespaces. The time namespace through /proc cannot be used withclone3()because the offsets for the time namespace need to be written before a process has been created in that time namespace. This means it is necessary to somehow tellclone3()the offsets for the clocks.The time namespace offers the possibility to set offsets for
CLOCK_MONOTONICandCLOCK_BOOTTIME. My first approach was to extend 'struct clone_args` with '__aligned_u64monotonic_offset' and '__aligned_u64boottime_offset'. The problem with this approach was that it was not possible to set nanoseconds for the clocks in the time namespace.One of the motivations for
clone3()withCLONE_NEWTIMEwas to enable CRIU to restore a process in a time namespace with the corresponding offsets. And although the nanosecond value can probably never be restored to the same value it had during checkpointing, because the clock keeps on running between CRIU pausing all processes and CRIU actually reading the value of the clocks, the nanosecond value is still necessary for CRIU to not restore a process where the clock jumps back due to CRIU restoring it with a nanonsecond value that is too small.Requiring nanoseconds as well as seconds for two clocks during
clone3()means that it would require 4 additional members to 'structclone_args':__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;
Review
Quoted 5 lines
(quoted diff) +4
-0+ __aligned_u64 boottime_offset_seconds; + __aligned_u64 boottime_offset_nanoseconds; + __aligned_u64 monotonic_offset_seconds; + __aligned_u64 monotonic_offset_nanoseconds; };
Wouldn't it be sufficient to have the two nanosecond values, rather than both seconds and nanoseconds? With 64-bit nanoseconds you can represent several hundred years, and these would always start at zero during boot.
Regardless of this, I think you need a signed offset, not unsigned.
Arnd
Quoted 37 lines · Arnd Bergmann
Quoted 30 lines · Adrian Reber
This is an attempt to add time namespace support to
clone3(). I am not really sure which wayclone3()should handle time namespaces. The time namespace through /proc cannot be used withclone3()because the offsets for the time namespace need to be written before a process has been created in that time namespace. This means it is necessary to somehow tellclone3()the offsets for the clocks.The time namespace offers the possibility to set offsets for
CLOCK_MONOTONICandCLOCK_BOOTTIME. My first approach was to extend 'struct clone_args` with '__aligned_u64monotonic_offset' and '__aligned_u64boottime_offset'. The problem with this approach was that it was not possible to set nanoseconds for the clocks in the time namespace.One of the motivations for
clone3()withCLONE_NEWTIMEwas to enable CRIU to restore a process in a time namespace with the corresponding offsets. And although the nanosecond value can probably never be restored to the same value it had during checkpointing, because the clock keeps on running between CRIU pausing all processes and CRIU actually reading the value of the clocks, the nanosecond value is still necessary for CRIU to not restore a process where the clock jumps back due to CRIU restoring it with a nanonsecond value that is too small.Requiring nanoseconds as well as seconds for two clocks during
clone3()means that it would require 4 additional members to 'structclone_args':__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 5 lines
(quoted diff) +4
-0+ __aligned_u64 boottime_offset_seconds; + __aligned_u64 boottime_offset_nanoseconds; + __aligned_u64 monotonic_offset_seconds; + __aligned_u64 monotonic_offset_nanoseconds; };
Quoted 4 lines
Wouldn't it be sufficient to have the two nanosecond values, rather than both seconds and nanoseconds? With 64-bit nanoseconds you can represent several hundred years, and these would always start at zero during boot.
I like this. Just using nanoseconds will make it easier and should indeed be enough.
Quoted 1 line
Regardless of this, I think you need a signed offset, not unsigned.
Right, that was just a quick test at some point.
Christian and I have also been discussing this a bit and Christian prefers a pointer to a struct. Maybe something like this:
__aligned_u64 tls;
__aligned_u64 set_tid;
__aligned_u64 set_tid_size;+ __aligned_u64 timens_offset;
};
With Arnd's idea of only using nanoseconds, timens_offset would then contain something like this:
struct timens_offset {
__aligned_s64 monotonic_offset_ns;
__aligned_s64 boottime_offset_ns;
};I kind of prefer adding boottime and monotonic directly to struct clone_args
__aligned_u64 tls;
__aligned_u64 set_tid;
__aligned_u64 set_tid_size;+ __aligned_s64 monotonic_offset_ns;
+ __aligned_s64 boottime_offset_ns;
};
But setting the time namespace offset is probably something which does not happen very often while using clone3(), so maybe the pointer to a struct approach is better.
I will resend the patches using the pointer to a struct approach if there are no other ideas how to do this.
Adrian
Quoted 13 lines · Adrian Reber
With Arnd's idea of only using nanoseconds,
timens_offsetwould then contain something like this:struct timens_offset { __aligned_s64 monotonic_offset_ns; __aligned_s64 boottime_offset_ns; };I kind of prefer adding boottime and monotonic directly to struct
clone_args__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;
Review
Quoted 3 lines
(quoted diff) +2
-0+ __aligned_s64 monotonic_offset_ns; + __aligned_s64 boottime_offset_ns; };
I would also prefer the second approach using two 64-bit integers instead of a pointer, as it keeps the interface simpler to implement and simpler to interpret by other tools.
Arnd
Quoted 19 lines · Arnd Bergmann
Quoted 13 lines · Adrian Reber
With Arnd's idea of only using nanoseconds,
timens_offsetwould then contain something like this:struct timens_offset { __aligned_s64 monotonic_offset_ns; __aligned_s64 boottime_offset_ns; };I kind of prefer adding boottime and monotonic directly to struct
clone_args__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 3 lines
(quoted diff) +2
-0+ __aligned_s64 monotonic_offset_ns; + __aligned_s64 boottime_offset_ns; };
Quoted 3 lines
I would also prefer the second approach using two 64-bit integers instead of a pointer, as it keeps the interface simpler to implement and simpler to interpret by other tools.
Why I don't like has two reasons. There's the scenario where we have added new extensions after the new boottime member and then we introduce another offset. Then you'd be looking at:
__aligned_u64 tls;__aligned_u64 set_tid;__aligned_u64 set_tid_size;
+ __aligned_s64 monotonic_offset_ns;
+ __aligned_s64 boottime_offset_ns;__aligned_s64 something_1__aligned_s64 anything_2
+ __aligned_s64 sometime_offset_ns
which bothers me just by looking at it. That's in addition to adding two new members to the struct when most people will never set CLONE_NEWTIME. We'll also likely have more features in the future that will want to pass down more info than we want to directly expose in struct clone_args, e.g. for a long time I have been thinking about adding a struct for CLONE_NEWUSER that allows you to specify the id mappings you want the new user namespace to get. We surely don't want to force all new info into the uppermost struct. So I'm not convinced we should here.
Christian
Quoted 37 lines · Christian Brauner
Quoted 19 lines · Arnd Bergmann
Quoted 13 lines · Adrian Reber
With Arnd's idea of only using nanoseconds,
timens_offsetwould then contain something like this:struct timens_offset { __aligned_s64 monotonic_offset_ns; __aligned_s64 boottime_offset_ns; };I kind of prefer adding boottime and monotonic directly to struct
clone_args__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 3 lines
(quoted diff) +2
-0+ __aligned_s64 monotonic_offset_ns; + __aligned_s64 boottime_offset_ns; };Quoted 3 lines
I would also prefer the second approach using two 64-bit integers instead of a pointer, as it keeps the interface simpler to implement and simpler to interpret by other tools.
Why I don't like has two reasons. There's the scenario where we have added new extensions after the new boottime member and then we introduce another offset. Then you'd be looking at:
__aligned_u64tls;__aligned_u64set_tid;__aligned_u64set_tid_size;
+__aligned_s64monotonic_offset_ns;
+__aligned_s64boottime_offset_ns;__aligned_s64something_1__aligned_s64anything_2
+__aligned_s64sometime_offset_ns
Quoted 8 lines
which bothers me just by looking at it. That's in addition to adding two new members to the struct when most people will never set
CLONE_NEWTIME. We'll also likely have more features in the future that will want to pass down more info than we want to directly expose in structclone_args, e.g. for a long time I have been thinking about adding a struct forCLONE_NEWUSERthat allows you to specify the id mappings you want the new user namespace to get. We surely don't want to force all new info into the uppermost struct. So I'm not convinced we should here.
I think here we can start thinking about a netlink-like interface.
struct clone_args {
....
u64 attrs_offset;
}struct clone_attr {
u16 cla_len;
u16 cla_type;
}....
int parse_clone_attributes(struct kernel_clone_args *kargs, struct clone_args *args, size_t args_size)
{
u64 off = args->attrs_offset;
while (off < size) {
struct clone_attr *attr;
if (off + sizeof(struct clone_attr) uargs_size)
return -EINVAL;
attr = (struct clone_attr *) ((void *)args + off);
if (attr->cla_type > CLONE_ATTR_TYPE_MAX)
return -ENOSYS;
kargs->attrs[attr->cla_type] = CLONE_ATTR_DATA(attr);
off += CLONE_ATTR_LEN(attr);
}
return 0;
}This interface doesn't suffer from problems what you enumerated before:
* clone_args contains only fields which are often used.
* per-feature attributes can be extended in a future without breaking backward compatibility.
* unused features don't affect clone3 argument size.
* seccomp-friendly (I am not 100% sure about this)
Quoted 47 lines · Andrei Vagin
Quoted 37 lines · Christian Brauner
Quoted 19 lines · Arnd Bergmann
Quoted 13 lines · Adrian Reber
With Arnd's idea of only using nanoseconds,
timens_offsetwould then contain something like this:struct timens_offset { __aligned_s64 monotonic_offset_ns; __aligned_s64 boottime_offset_ns; };I kind of prefer adding boottime and monotonic directly to struct
clone_args__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 3 lines
(quoted diff) +2
-0+ __aligned_s64 monotonic_offset_ns; + __aligned_s64 boottime_offset_ns; };Quoted 3 lines
I would also prefer the second approach using two 64-bit integers instead of a pointer, as it keeps the interface simpler to implement and simpler to interpret by other tools.
Why I don't like has two reasons. There's the scenario where we have added new extensions after the new boottime member and then we introduce another offset. Then you'd be looking at:
__aligned_u64tls;__aligned_u64set_tid;__aligned_u64set_tid_size;
+__aligned_s64monotonic_offset_ns;
+__aligned_s64boottime_offset_ns;__aligned_s64something_1__aligned_s64anything_2
+__aligned_s64sometime_offset_nsQuoted 8 lines
which bothers me just by looking at it. That's in addition to adding two new members to the struct when most people will never set
CLONE_NEWTIME. We'll also likely have more features in the future that will want to pass down more info than we want to directly expose in structclone_args, e.g. for a long time I have been thinking about adding a struct forCLONE_NEWUSERthat allows you to specify the id mappings you want the new user namespace to get. We surely don't want to force all new info into the uppermost struct. So I'm not convinced we should here.
Quoted 1 line
I think here we can start thinking about a netlink-like interface.
I think netlink is just not a great model for an API and I would not want us to go down that route.
I kept thinking about this for a bit and I think that we will end up growing more namespace-related functionality. So one thing that came to my mind is the following layout:
struct {
struct {
__s64 monotonic;
__s64 boot;
} time;
} namespaces;struct _clone_args {
__aligned_u64 flags;
__aligned_u64 pidfd;
__aligned_u64 child_tid;
__aligned_u64 parent_tid;
__aligned_u64 exit_signal;
__aligned_u64 stack;
__aligned_u64 stack_size;
__aligned_u64 tls;
__aligned_u64 set_tid;
__aligned_u64 set_tid_size;
__aligned_u64 namespaces;
__aligned_u64 namespaces_size;
};Then when we end up adding id mapping support for CLONE_NEWUSER we can extend this with:
struct {
struct {
__aligned_u64 monotonic;
__aligned_u64 boot;
} time;
struct {
/* id mapping members */
} user;
} namespaces;Thoughts? Other ideas?
Christian
Quoted 93 lines · Christian Brauner
Quoted 47 lines · Andrei Vagin
Quoted 37 lines · Christian Brauner
Quoted 19 lines · Arnd Bergmann
Quoted 13 lines · Adrian Reber
With Arnd's idea of only using nanoseconds,
timens_offsetwould then contain something like this:struct timens_offset { __aligned_s64 monotonic_offset_ns; __aligned_s64 boottime_offset_ns; };I kind of prefer adding boottime and monotonic directly to struct
clone_args__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 3 lines
(quoted diff) +2
-0+ __aligned_s64 monotonic_offset_ns; + __aligned_s64 boottime_offset_ns; };Quoted 3 lines
I would also prefer the second approach using two 64-bit integers instead of a pointer, as it keeps the interface simpler to implement and simpler to interpret by other tools.
Why I don't like has two reasons. There's the scenario where we have added new extensions after the new boottime member and then we introduce another offset. Then you'd be looking at:
__aligned_u64tls;__aligned_u64set_tid;__aligned_u64set_tid_size;
+__aligned_s64monotonic_offset_ns;
+__aligned_s64boottime_offset_ns;__aligned_s64something_1__aligned_s64anything_2
+__aligned_s64sometime_offset_nsQuoted 8 lines
which bothers me just by looking at it. That's in addition to adding two new members to the struct when most people will never set
CLONE_NEWTIME. We'll also likely have more features in the future that will want to pass down more info than we want to directly expose in structclone_args, e.g. for a long time I have been thinking about adding a struct forCLONE_NEWUSERthat allows you to specify the id mappings you want the new user namespace to get. We surely don't want to force all new info into the uppermost struct. So I'm not convinced we should here.Quoted 1 line
I think here we can start thinking about a netlink-like interface.
I think netlink is just not a great model for an API and I would not want us to go down that route.
I kept thinking about this for a bit and I think that we will end up growing more namespace-related functionality. So one thing that came to my mind is the following layout:
struct { struct { __s64 monotonic; __s64 boot; } time; } namespaces;struct _clone_args { __aligned_u64 flags; __aligned_u64 pidfd; __aligned_u64 child_tid; __aligned_u64 parent_tid; __aligned_u64 exit_signal; __aligned_u64 stack; __aligned_u64 stack_size; __aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size; __aligned_u64 namespaces; __aligned_u64 namespaces_size; };Then when we end up adding id mapping support for
CLONE_NEWUSERwe can extend this with:struct { struct { __aligned_u64 monotonic; __aligned_u64 boot; } time; struct { /* id mapping members */ } user; } namespaces;
Quoted 1 line
Thoughts? Other ideas?
Works for me.
If we add the user namespace id mappings and then at some point a third element for the time namespace appears it would also start to be mixed. Just as you mentioned that a few mails ago.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
__aligned_u64set_tid_size;
+__aligned_s64monotonic_offset_ns;
+__aligned_s64boottime_offset_ns;__aligned_s64something_1__aligned_s64anything_2
+__aligned_s64sometime_offset_ns
If we can live with something like this in the namespaces struct you proposed, it works for me.
Adrian
Quoted 80 lines · Adrian Reber
Quoted 79 lines · Christian Brauner
Quoted 47 lines · Andrei Vagin
Quoted 37 lines · Christian Brauner
Quoted 19 lines · Arnd Bergmann
Quoted 13 lines · Adrian Reber
With Arnd's idea of only using nanoseconds,
timens_offsetwould then contain something like this:struct timens_offset { __aligned_s64 monotonic_offset_ns; __aligned_s64 boottime_offset_ns; };I kind of prefer adding boottime and monotonic directly to struct
clone_args__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 3 lines
(quoted diff) +2
-0+ __aligned_s64 monotonic_offset_ns; + __aligned_s64 boottime_offset_ns; };Quoted 3 lines
I would also prefer the second approach using two 64-bit integers instead of a pointer, as it keeps the interface simpler to implement and simpler to interpret by other tools.
Why I don't like has two reasons. There's the scenario where we have added new extensions after the new boottime member and then we introduce another offset. Then you'd be looking at:
__aligned_u64tls;__aligned_u64set_tid;__aligned_u64set_tid_size;
+__aligned_s64monotonic_offset_ns;
+__aligned_s64boottime_offset_ns;__aligned_s64something_1__aligned_s64anything_2
+__aligned_s64sometime_offset_nsQuoted 8 lines
which bothers me just by looking at it. That's in addition to adding two new members to the struct when most people will never set
CLONE_NEWTIME. We'll also likely have more features in the future that will want to pass down more info than we want to directly expose in structclone_args, e.g. for a long time I have been thinking about adding a struct forCLONE_NEWUSERthat allows you to specify the id mappings you want the new user namespace to get. We surely don't want to force all new info into the uppermost struct. So I'm not convinced we should here.Quoted 1 line
I think here we can start thinking about a netlink-like interface.
I think netlink is just not a great model for an API and I would not want us to go down that route.
I kept thinking about this for a bit and I think that we will end up growing more namespace-related functionality. So one thing that came to my mind is the following layout:
struct { struct { __s64 monotonic; __s64 boot; } time; } namespaces;struct _clone_args { __aligned_u64 flags; __aligned_u64 pidfd; __aligned_u64 child_tid; __aligned_u64 parent_tid; __aligned_u64 exit_signal; __aligned_u64 stack; __aligned_u64 stack_size; __aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size; __aligned_u64 namespaces; __aligned_u64 namespaces_size; };
Quoted 7 lines
Quoted 7 lines
Then when we end up adding id mapping support for
CLONE_NEWUSERwe can extend this with:struct { struct { __aligned_u64 monotonic; __aligned_u64 boot;
s/__aligned_u64/__s64/g
Sorry, leftover from my first draft.
Quoted 7 lines
Quoted 7 lines
} time; struct { /* id mapping members */ } user; } namespaces;
Quoted 7 lines
Quoted 1 line
Thoughts? Other ideas?
Works for me.
If we add the user namespace id mappings and then at some point a third element for the time namespace appears it would also start to be mixed. Just as you mentioned that a few mails ago.
I think you misunderstand me or I'm misunderstanding you. That new time namespace member would go into struct time {} so
struct {
struct {
__s64 monotonic;
__s64 boot;
__s64 someothertime;
} time;
struct {
/* id mapping members */
} user;
} namespaces;Christian
Quoted 111 lines · Christian Brauner
Quoted 80 lines · Adrian Reber
Quoted 79 lines · Christian Brauner
Quoted 47 lines · Andrei Vagin
Quoted 37 lines · Christian Brauner
Quoted 19 lines · Arnd Bergmann
Quoted 13 lines · Adrian Reber
With Arnd's idea of only using nanoseconds,
timens_offsetwould then contain something like this:struct timens_offset { __aligned_s64 monotonic_offset_ns; __aligned_s64 boottime_offset_ns; };I kind of prefer adding boottime and monotonic directly to struct
clone_args__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 3 lines
(quoted diff) +2
-0+ __aligned_s64 monotonic_offset_ns; + __aligned_s64 boottime_offset_ns; };Quoted 3 lines
I would also prefer the second approach using two 64-bit integers instead of a pointer, as it keeps the interface simpler to implement and simpler to interpret by other tools.
Why I don't like has two reasons. There's the scenario where we have added new extensions after the new boottime member and then we introduce another offset. Then you'd be looking at:
__aligned_u64tls;__aligned_u64set_tid;__aligned_u64set_tid_size;
+__aligned_s64monotonic_offset_ns;
+__aligned_s64boottime_offset_ns;__aligned_s64something_1__aligned_s64anything_2
+__aligned_s64sometime_offset_nsQuoted 8 lines
which bothers me just by looking at it. That's in addition to adding two new members to the struct when most people will never set
CLONE_NEWTIME. We'll also likely have more features in the future that will want to pass down more info than we want to directly expose in structclone_args, e.g. for a long time I have been thinking about adding a struct forCLONE_NEWUSERthat allows you to specify the id mappings you want the new user namespace to get. We surely don't want to force all new info into the uppermost struct. So I'm not convinced we should here.Quoted 1 line
I think here we can start thinking about a netlink-like interface.
I think netlink is just not a great model for an API and I would not want us to go down that route.
I kept thinking about this for a bit and I think that we will end up growing more namespace-related functionality. So one thing that came to my mind is the following layout:
struct { struct { __s64 monotonic; __s64 boot; } time; } namespaces;struct _clone_args { __aligned_u64 flags; __aligned_u64 pidfd; __aligned_u64 child_tid; __aligned_u64 parent_tid; __aligned_u64 exit_signal; __aligned_u64 stack; __aligned_u64 stack_size; __aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size; __aligned_u64 namespaces; __aligned_u64 namespaces_size; };Quoted 7 lines
Quoted 7 lines
Then when we end up adding id mapping support for
CLONE_NEWUSERwe can extend this with:struct { struct { __aligned_u64 monotonic; __aligned_u64 boot;s/__aligned_u64/__s64/g
Sorry, leftover from my first draft.
Quoted 7 lines
Quoted 7 lines
} time; struct { /* id mapping members */ } user; } namespaces;Quoted 7 lines
Quoted 1 line
Thoughts? Other ideas?
Works for me.
If we add the user namespace id mappings and then at some point a third element for the time namespace appears it would also start to be mixed. Just as you mentioned that a few mails ago.
I think you misunderstand me or I'm misunderstanding you. That new time namespace member would go into struct time {} so
Quoted 11 lines
struct {
struct {
__s64 monotonic;
__s64 boot;
__s64 someothertime;
} time;
struct {
/* id mapping members */
} user;
} namespaces;My question was about how does the kernel know how 'struct namespaces' is structured. How can an older kernel (which only is aware of two clocks) deal with a, like in this example, third clock. Will the size '__aligned_u64 namespaces_size' be used for versioning?
Adrian
Quoted 124 lines · Adrian Reber
Quoted 111 lines · Christian Brauner
Quoted 80 lines · Adrian Reber
Quoted 79 lines · Christian Brauner
Quoted 47 lines · Andrei Vagin
Quoted 37 lines · Christian Brauner
Quoted 19 lines · Arnd Bergmann
Quoted 13 lines · Adrian Reber
With Arnd's idea of only using nanoseconds,
timens_offsetwould then contain something like this:struct timens_offset { __aligned_s64 monotonic_offset_ns; __aligned_s64 boottime_offset_ns; };I kind of prefer adding boottime and monotonic directly to struct
clone_args__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 3 lines
(quoted diff) +2
-0+ __aligned_s64 monotonic_offset_ns; + __aligned_s64 boottime_offset_ns; };Quoted 3 lines
I would also prefer the second approach using two 64-bit integers instead of a pointer, as it keeps the interface simpler to implement and simpler to interpret by other tools.
Why I don't like has two reasons. There's the scenario where we have added new extensions after the new boottime member and then we introduce another offset. Then you'd be looking at:
__aligned_u64tls;__aligned_u64set_tid;__aligned_u64set_tid_size;
+__aligned_s64monotonic_offset_ns;
+__aligned_s64boottime_offset_ns;__aligned_s64something_1__aligned_s64anything_2
+__aligned_s64sometime_offset_nsQuoted 8 lines
which bothers me just by looking at it. That's in addition to adding two new members to the struct when most people will never set
CLONE_NEWTIME. We'll also likely have more features in the future that will want to pass down more info than we want to directly expose in structclone_args, e.g. for a long time I have been thinking about adding a struct forCLONE_NEWUSERthat allows you to specify the id mappings you want the new user namespace to get. We surely don't want to force all new info into the uppermost struct. So I'm not convinced we should here.Quoted 1 line
I think here we can start thinking about a netlink-like interface.
I think netlink is just not a great model for an API and I would not want us to go down that route.
I kept thinking about this for a bit and I think that we will end up growing more namespace-related functionality. So one thing that came to my mind is the following layout:
struct { struct { __s64 monotonic; __s64 boot; } time; } namespaces;struct _clone_args { __aligned_u64 flags; __aligned_u64 pidfd; __aligned_u64 child_tid; __aligned_u64 parent_tid; __aligned_u64 exit_signal; __aligned_u64 stack; __aligned_u64 stack_size; __aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size; __aligned_u64 namespaces; __aligned_u64 namespaces_size; };Quoted 7 lines
Quoted 7 lines
Then when we end up adding id mapping support for
CLONE_NEWUSERwe can extend this with:struct { struct { __aligned_u64 monotonic; __aligned_u64 boot;s/__aligned_u64/__s64/g
Sorry, leftover from my first draft.
Quoted 7 lines
Quoted 7 lines
} time; struct { /* id mapping members */ } user; } namespaces;Quoted 7 lines
Quoted 1 line
Thoughts? Other ideas?
Works for me.
If we add the user namespace id mappings and then at some point a third element for the time namespace appears it would also start to be mixed. Just as you mentioned that a few mails ago.
I think you misunderstand me or I'm misunderstanding you. That new time namespace member would go into struct time {} so
Quoted 11 lines
struct { struct { __s64 monotonic; __s64 boot; __s64 someothertime; } time; struct { /* id mapping members */ } user; } namespaces;
Quoted 4 lines
My question was about how does the kernel know how 'struct namespaces' is structured. How can an older kernel (which only is aware of two clocks) deal with a, like in this example, third clock. Will the size '
__aligned_u64namespaces_size' be used for versioning?
Yes, that would be the idea.
I don't want to give the impression that I think this is the best solution. It's one solution that I think is feasible. But if we have something better that is also future proof I'm happy to hear ideas.
Christian
Quoted 120 lines · Christian Brauner
Quoted 119 lines · Adrian Reber
Quoted 118 lines · Christian Brauner
Quoted 80 lines · Adrian Reber
Quoted 79 lines · Christian Brauner
Quoted 47 lines · Andrei Vagin
Quoted 37 lines · Christian Brauner
Quoted 19 lines · Arnd Bergmann
Quoted 13 lines · Adrian Reber
With Arnd's idea of only using nanoseconds,
timens_offsetwould then contain something like this:struct timens_offset { __aligned_s64 monotonic_offset_ns; __aligned_s64 boottime_offset_ns; };I kind of prefer adding boottime and monotonic directly to struct
clone_args__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 3 lines
(quoted diff) +2
-0+ __aligned_s64 monotonic_offset_ns; + __aligned_s64 boottime_offset_ns; };Quoted 3 lines
I would also prefer the second approach using two 64-bit integers instead of a pointer, as it keeps the interface simpler to implement and simpler to interpret by other tools.
Why I don't like has two reasons. There's the scenario where we have added new extensions after the new boottime member and then we introduce another offset. Then you'd be looking at:
__aligned_u64tls;__aligned_u64set_tid;__aligned_u64set_tid_size;
+__aligned_s64monotonic_offset_ns;
+__aligned_s64boottime_offset_ns;__aligned_s64something_1__aligned_s64anything_2
+__aligned_s64sometime_offset_nsQuoted 8 lines
which bothers me just by looking at it. That's in addition to adding two new members to the struct when most people will never set
CLONE_NEWTIME. We'll also likely have more features in the future that will want to pass down more info than we want to directly expose in structclone_args, e.g. for a long time I have been thinking about adding a struct forCLONE_NEWUSERthat allows you to specify the id mappings you want the new user namespace to get. We surely don't want to force all new info into the uppermost struct. So I'm not convinced we should here.Quoted 1 line
I think here we can start thinking about a netlink-like interface.
I think netlink is just not a great model for an API and I would not want us to go down that route.
I kept thinking about this for a bit and I think that we will end up growing more namespace-related functionality. So one thing that came to my mind is the following layout:
struct { struct { __s64 monotonic; __s64 boot; } time; } namespaces;struct _clone_args { __aligned_u64 flags; __aligned_u64 pidfd; __aligned_u64 child_tid; __aligned_u64 parent_tid; __aligned_u64 exit_signal; __aligned_u64 stack; __aligned_u64 stack_size; __aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size; __aligned_u64 namespaces; __aligned_u64 namespaces_size; };Quoted 7 lines
Quoted 7 lines
Then when we end up adding id mapping support for
CLONE_NEWUSERwe can extend this with:struct { struct { __aligned_u64 monotonic; __aligned_u64 boot;s/__aligned_u64/__s64/g
Sorry, leftover from my first draft.
Quoted 7 lines
Quoted 7 lines
} time; struct { /* id mapping members */ } user; } namespaces;Quoted 7 lines
Quoted 1 line
Thoughts? Other ideas?
Works for me.
If we add the user namespace id mappings and then at some point a third element for the time namespace appears it would also start to be mixed. Just as you mentioned that a few mails ago.
I think you misunderstand me or I'm misunderstanding you. That new time namespace member would go into struct time {} so
struct { struct { __s64 monotonic; __s64 boot; __s64 someothertime; } time;
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
struct { /* id mapping members */ } user; } namespaces;
So far, this seems like the least worst approach to me :-).
I think it's reasonable to assume that there will be another time NS offset to add one day. I don't think anyone expected CLOCK_BOOTIME (added in 2011) at the time that CLOCK_MONOTONIC appeared (as part of the POSIX timers API in Linux 2.6.0 2003); similarly, we probably can't conceive now what clock might be added in the future that should also be governed by time namespaces.
But...
Quoted 6 lines
Quoted 4 lines
My question was about how does the kernel know how 'struct namespaces' is structured. How can an older kernel (which only is aware of two clocks) deal with a, like in this example, third clock. Will the size '
__aligned_u64namespaces_size' be used for versioning?Yes, that would be the idea.
The idea implied here (if I understand correctly) of "binary chop on the structure size to see what your kernel supports" is pretty clunky, IMO. It's worth at least considering alternatives. For example, seccomp has a number of interesting interfaces to discover what the running kernel supports [1]. Maybe it is worth considering something similar for clone3()?
Cheers,
Michael
[1]/proc/sys/kernel/seccomp/actions_avail (see seccomp(2)) SECCOMP_GET_ACTION_AVAIL (see secommp(2)) cgroups also provides something similar in the form of /sys/kernel/cgroup/features (see cgroups(7))
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Quoted 144 lines · Michael Kerrisk (man-pages)
Quoted 120 lines · Christian Brauner
Quoted 119 lines · Adrian Reber
Quoted 118 lines · Christian Brauner
Quoted 80 lines · Adrian Reber
Quoted 79 lines · Christian Brauner
Quoted 47 lines · Andrei Vagin
Quoted 37 lines · Christian Brauner
Quoted 19 lines · Arnd Bergmann
Quoted 13 lines · Adrian Reber
With Arnd's idea of only using nanoseconds,
timens_offsetwould then contain something like this:struct timens_offset { __aligned_s64 monotonic_offset_ns; __aligned_s64 boottime_offset_ns; };I kind of prefer adding boottime and monotonic directly to struct
clone_args__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 3 lines
(quoted diff) +2
-0+ __aligned_s64 monotonic_offset_ns; + __aligned_s64 boottime_offset_ns; };Quoted 3 lines
I would also prefer the second approach using two 64-bit integers instead of a pointer, as it keeps the interface simpler to implement and simpler to interpret by other tools.
Why I don't like has two reasons. There's the scenario where we have added new extensions after the new boottime member and then we introduce another offset. Then you'd be looking at:
__aligned_u64tls;__aligned_u64set_tid;__aligned_u64set_tid_size;
+__aligned_s64monotonic_offset_ns;
+__aligned_s64boottime_offset_ns;__aligned_s64something_1__aligned_s64anything_2
+__aligned_s64sometime_offset_nsQuoted 8 lines
which bothers me just by looking at it. That's in addition to adding two new members to the struct when most people will never set
CLONE_NEWTIME. We'll also likely have more features in the future that will want to pass down more info than we want to directly expose in structclone_args, e.g. for a long time I have been thinking about adding a struct forCLONE_NEWUSERthat allows you to specify the id mappings you want the new user namespace to get. We surely don't want to force all new info into the uppermost struct. So I'm not convinced we should here.Quoted 1 line
I think here we can start thinking about a netlink-like interface.
I think netlink is just not a great model for an API and I would not want us to go down that route.
I kept thinking about this for a bit and I think that we will end up growing more namespace-related functionality. So one thing that came to my mind is the following layout:
struct { struct { __s64 monotonic; __s64 boot; } time; } namespaces;struct _clone_args { __aligned_u64 flags; __aligned_u64 pidfd; __aligned_u64 child_tid; __aligned_u64 parent_tid; __aligned_u64 exit_signal; __aligned_u64 stack; __aligned_u64 stack_size; __aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size; __aligned_u64 namespaces; __aligned_u64 namespaces_size; };Quoted 7 lines
Quoted 7 lines
Then when we end up adding id mapping support for
CLONE_NEWUSERwe can extend this with:struct { struct { __aligned_u64 monotonic; __aligned_u64 boot;s/__aligned_u64/__s64/g
Sorry, leftover from my first draft.
Quoted 7 lines
Quoted 7 lines
} time; struct { /* id mapping members */ } user; } namespaces;Quoted 7 lines
Quoted 1 line
Thoughts? Other ideas?
Works for me.
If we add the user namespace id mappings and then at some point a third element for the time namespace appears it would also start to be mixed. Just as you mentioned that a few mails ago.
I think you misunderstand me or I'm misunderstanding you. That new time namespace member would go into struct time {} so
struct { struct { __s64 monotonic; __s64 boot; __s64 someothertime; } time;Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
struct { /* id mapping members */ } user; } namespaces;So far, this seems like the least worst approach to me :-).
I think it's reasonable to assume that there will be another time NS offset to add one day. I don't think anyone expected
CLOCK_BOOTIME(added in 2011) at the time thatCLOCK_MONOTONICappeared (as part of the POSIX timers API in Linux 2.6.0 2003); similarly, we probably can't conceive now what clock might be added in the future that should also be governed by time namespaces.But...
Quoted 5 lines
Quoted 4 lines
My question was about how does the kernel know how 'struct namespaces' is structured. How can an older kernel (which only is aware of two clocks) deal with a, like in this example, third clock. Will the size '
__aligned_u64namespaces_size' be used for versioning?
Quoted 8 lines
Quoted 1 line
Yes, that would be the idea.
The idea implied here (if I understand correctly) of "binary chop on the structure size to see what your kernel supports" is pretty clunky, IMO. It's worth at least considering alternatives. For example, seccomp has a number of interesting interfaces to discover what the running kernel supports [1]. Maybe it is worth considering something similar for
clone3()?
Yes, that's definitely something I've been thinking about and I've also discussed this publicly on the libc-alpha mailing list since Florian (Weimer) wants this for glibc. _But_ I didn't want to simply go my own way and so Aleksa and I stuck our heads together and tried to come up with a generic way that e.g. would work for both openat2() and for clone3(), in fact we tried to come up with a generic way that could potentially be used by any syscall that makes use of the new copy_struct_from_user() helper that Aleksa and I pushed upstream. We haven't yet gotten around to actually try and implementing our ideas. I'll try to get around to this during this cycle (/me makes note to "sit down" with Aleksa). We'll definitely take a look at seccomp and cgroups too.
Christian
Quoted 15 lines
Cheers,
Michael
[1]
/proc/sys/kernel/seccomp/actions_avail(see seccomp(2))SECCOMP_GET_ACTION_AVAIL(see secommp(2)) cgroups also provides something similar in the form of/sys/kernel/cgroup/features(see cgroups(7))Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Quoted 154 lines · Christian Brauner
Quoted 144 lines · Michael Kerrisk (man-pages)
Quoted 120 lines · Christian Brauner
Quoted 119 lines · Adrian Reber
Quoted 118 lines · Christian Brauner
Quoted 80 lines · Adrian Reber
Quoted 79 lines · Christian Brauner
Quoted 47 lines · Andrei Vagin
Quoted 37 lines · Christian Brauner
Quoted 19 lines · Arnd Bergmann
Quoted 13 lines · Adrian Reber
With Arnd's idea of only using nanoseconds,
timens_offsetwould then contain something like this:struct timens_offset { __aligned_s64 monotonic_offset_ns; __aligned_s64 boottime_offset_ns; };I kind of prefer adding boottime and monotonic directly to struct
clone_args__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;Review
Quoted 3 lines
(quoted diff) +2
-0+ __aligned_s64 monotonic_offset_ns; + __aligned_s64 boottime_offset_ns; };Quoted 3 lines
I would also prefer the second approach using two 64-bit integers instead of a pointer, as it keeps the interface simpler to implement and simpler to interpret by other tools.
Why I don't like has two reasons. There's the scenario where we have added new extensions after the new boottime member and then we introduce another offset. Then you'd be looking at:
__aligned_u64tls;__aligned_u64set_tid;__aligned_u64set_tid_size;
+__aligned_s64monotonic_offset_ns;
+__aligned_s64boottime_offset_ns;__aligned_s64something_1__aligned_s64anything_2
+__aligned_s64sometime_offset_nsQuoted 8 lines
which bothers me just by looking at it. That's in addition to adding two new members to the struct when most people will never set
CLONE_NEWTIME. We'll also likely have more features in the future that will want to pass down more info than we want to directly expose in structclone_args, e.g. for a long time I have been thinking about adding a struct forCLONE_NEWUSERthat allows you to specify the id mappings you want the new user namespace to get. We surely don't want to force all new info into the uppermost struct. So I'm not convinced we should here.Quoted 1 line
I think here we can start thinking about a netlink-like interface.
I think netlink is just not a great model for an API and I would not want us to go down that route.
I kept thinking about this for a bit and I think that we will end up growing more namespace-related functionality. So one thing that came to my mind is the following layout:
struct { struct { __s64 monotonic; __s64 boot; } time; } namespaces;struct _clone_args { __aligned_u64 flags; __aligned_u64 pidfd; __aligned_u64 child_tid; __aligned_u64 parent_tid; __aligned_u64 exit_signal; __aligned_u64 stack; __aligned_u64 stack_size; __aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size; __aligned_u64 namespaces; __aligned_u64 namespaces_size; };Quoted 7 lines
Quoted 7 lines
Then when we end up adding id mapping support for
CLONE_NEWUSERwe can extend this with:struct { struct { __aligned_u64 monotonic; __aligned_u64 boot;s/__aligned_u64/__s64/g
Sorry, leftover from my first draft.
Quoted 7 lines
Quoted 7 lines
} time; struct { /* id mapping members */ } user; } namespaces;Quoted 7 lines
Quoted 1 line
Thoughts? Other ideas?
Works for me.
If we add the user namespace id mappings and then at some point a third element for the time namespace appears it would also start to be mixed. Just as you mentioned that a few mails ago.
I think you misunderstand me or I'm misunderstanding you. That new time namespace member would go into struct time {} so
struct { struct { __s64 monotonic; __s64 boot; __s64 someothertime; } time;Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
struct { /* id mapping members */ } user; } namespaces;So far, this seems like the least worst approach to me :-).
I think it's reasonable to assume that there will be another time NS offset to add one day. I don't think anyone expected
CLOCK_BOOTIME(added in 2011) at the time thatCLOCK_MONOTONICappeared (as part of the POSIX timers API in Linux 2.6.0 2003); similarly, we probably can't conceive now what clock might be added in the future that should also be governed by time namespaces.But...
Quoted 5 lines
Quoted 4 lines
My question was about how does the kernel know how 'struct namespaces' is structured. How can an older kernel (which only is aware of two clocks) deal with a, like in this example, third clock. Will the size '
__aligned_u64namespaces_size' be used for versioning?Quoted 8 lines
Quoted 1 line
Yes, that would be the idea.
The idea implied here (if I understand correctly) of "binary chop on the structure size to see what your kernel supports" is pretty clunky, IMO. It's worth at least considering alternatives. For example, seccomp has a number of interesting interfaces to discover what the running kernel supports [1]. Maybe it is worth considering something similar for
clone3()?
Quoted 12 lines
Yes, that's definitely something I've been thinking about and I've also discussed this publicly on the libc-alpha mailing list since Florian (Weimer) wants this for glibc. _But_ I didn't want to simply go my own way and so Aleksa and I stuck our heads together and tried to come up with a generic way that e.g. would work for both
openat2()and forclone3(), in fact we tried to come up with a generic way that could potentially be used by any syscall that makes use of the newcopy_struct_from_user()helper that Aleksa and I pushed upstream. We haven't yet gotten around to actually try and implementing our ideas. I'll try to get around to this during this cycle (/me makes note to "sit down" with Aleksa). We'll definitely take a look at seccomp and cgroups too.
Great! Thanks for thinking about this. Just by the way, on discussions such as the one you had with Florian, it would be great if you CCed linux-api@ (and also for the patch series that implements this idea).
Cheers,
Michael
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Hi Adrian,
If there was a revision to this patch, I missed it. Is there still a plan to bring CLONE_NEWTIME to clone3()?
Thanks,
Michael
Quoted 67 lines · Adrian Reber
This is an attempt to add time namespace support to
clone3(). I am not really sure which wayclone3()should handle time namespaces. The time namespace through /proc cannot be used withclone3()because the offsets for the time namespace need to be written before a process has been created in that time namespace. This means it is necessary to somehow tellclone3()the offsets for the clocks.The time namespace offers the possibility to set offsets for
CLOCK_MONOTONICandCLOCK_BOOTTIME. My first approach was to extend 'struct clone_args` with '__aligned_u64monotonic_offset' and '__aligned_u64boottime_offset'. The problem with this approach was that it was not possible to set nanoseconds for the clocks in the time namespace.One of the motivations for
clone3()withCLONE_NEWTIMEwas to enable CRIU to restore a process in a time namespace with the corresponding offsets. And although the nanosecond value can probably never be restored to the same value it had during checkpointing, because the clock keeps on running between CRIU pausing all processes and CRIU actually reading the value of the clocks, the nanosecond value is still necessary for CRIU to not restore a process where the clock jumps back due to CRIU restoring it with a nanonsecond value that is too small.Requiring nanoseconds as well as seconds for two clocks during
clone3()means that it would require 4 additional members to 'structclone_args':__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +4
-0+ __aligned_u64 boottime_offset_seconds; + __aligned_u64 boottime_offset_nanoseconds; + __aligned_u64 monotonic_offset_seconds; + __aligned_u64 monotonic_offset_nanoseconds; };To avoid four additional members to 'struct
clone_args' this patchset uses another approach:__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +2
-0+ __aligned_u64 timens_offset; + __aligned_u64 timens_offset_size; };
timens_offsetis a pointer to an array just as previously done withset_tidandtimens_offset_sizeis the size of the array.The
timens_offsetarray is expected to contain a struct like this:struct set_timens_offset { int clockid; struct timespec val; };This way it is possible to pass the information of multiple clocks with seconds and nanonseconds to
clone3().To me this seems the better approach, but I am not totally convinced that it is the right thing. If there are other ideas how to pass two clock offsets with seconds and nanonseconds to
clone3()I would be happy to hear other ideas.Adrian
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Quoted 4 lines · Michael Kerrisk (man-pages)
Hi Adrian,
If there was a revision to this patch, I missed it. Is there still a plan to bring
CLONE_NEWTIMEtoclone3()?
Good that you ask. The discussion ended at the point that we do not have a way to figure out what a syscall supports from user-space. I talked a bit with Christian about it and he mentioned that there were some ideas floating around how to do that. At that point it made more sense to me to wait for such a solution to appear before continuing the clone3() time namespace work.
Adrian
Quoted 75 lines · Adrian Reber
Quoted 67 lines
This is an attempt to add time namespace support to
clone3(). I am not really sure which wayclone3()should handle time namespaces. The time namespace through /proc cannot be used withclone3()because the offsets for the time namespace need to be written before a process has been created in that time namespace. This means it is necessary to somehow tellclone3()the offsets for the clocks.The time namespace offers the possibility to set offsets for
CLOCK_MONOTONICandCLOCK_BOOTTIME. My first approach was to extend 'struct clone_args` with '__aligned_u64monotonic_offset' and '__aligned_u64boottime_offset'. The problem with this approach was that it was not possible to set nanoseconds for the clocks in the time namespace.One of the motivations for
clone3()withCLONE_NEWTIMEwas to enable CRIU to restore a process in a time namespace with the corresponding offsets. And although the nanosecond value can probably never be restored to the same value it had during checkpointing, because the clock keeps on running between CRIU pausing all processes and CRIU actually reading the value of the clocks, the nanosecond value is still necessary for CRIU to not restore a process where the clock jumps back due to CRIU restoring it with a nanonsecond value that is too small.Requiring nanoseconds as well as seconds for two clocks during
clone3()means that it would require 4 additional members to 'structclone_args':__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +4
-0+ __aligned_u64 boottime_offset_seconds; + __aligned_u64 boottime_offset_nanoseconds; + __aligned_u64 monotonic_offset_seconds; + __aligned_u64 monotonic_offset_nanoseconds; };To avoid four additional members to 'struct
clone_args' this patchset uses another approach:__aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size;(quoted diff) +2
-0+ __aligned_u64 timens_offset; + __aligned_u64 timens_offset_size; };
timens_offsetis a pointer to an array just as previously done withset_tidandtimens_offset_sizeis the size of the array.The
timens_offsetarray is expected to contain a struct like this:struct set_timens_offset { int clockid; struct timespec val; };This way it is possible to pass the information of multiple clocks with seconds and nanonseconds to
clone3().To me this seems the better approach, but I am not totally convinced that it is the right thing. If there are other ideas how to pass two clock offsets with seconds and nanonseconds to
clone3()I would be happy to hear other ideas.Adrian
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Quoted 6 lines · Adrian Reber
Quoted 4 lines · Michael Kerrisk (man-pages)
Hi Adrian,
If there was a revision to this patch, I missed it. Is there still a plan to bring
CLONE_NEWTIMEtoclone3()?
Quoted 6 lines
Good that you ask. The discussion ended at the point that we do not have a way to figure out what a syscall supports from user-space. I talked a bit with Christian about it and he mentioned that there were some ideas floating around how to do that. At that point it made more sense to me to wait for such a solution to appear before continuing the
clone3()time namespace work.
We need to have a little talk at ksummit about some aspects of syscall design. I'm writing something up for this. But we're not in a rush anyway, I take it.
Christian