cred: #include init.h in cred.h
Subsystems (14)
PATCH 1/38 cred: #include init.h in cred.h
cred.h can't be included as first header because it uses __init and doesn't include init.h which is enough to break compilation on at least ia64.
--- include/linux/cred.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/cred.h +1 -0
@@ -13,6 +13,7 @@#define _LINUX_CRED_H#include <linux/capability.h> +#include <linux/init.h> #include <linux/key.h> #include <asm/atomic.h>
Signature · 1 line
1.5.6.5
A message that is not in the archive (sent off-list or not yet received): 1242968132-1044-1-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 2/38 utsns: extract create_uts_ns()
create_uts_ns() will be used by C/R to create fresh uts_ns.
--- kernel/utsname.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-)
kernel/utsname.c +11 -2
@@ -15,6 +15,16 @@#include <linux/err.h> #include <linux/slab.h> +static struct uts_namespace *create_uts_ns (void ) +{ +struct uts_namespace *uts_ns; + + uts_ns =kmalloc (sizeof (struct uts_namespace ),GFP_KERNEL ); +if (uts_ns) +kref_init (&uts_ns->kref); +return uts_ns; +} +/* * Clone a new ns copying an original utsname, setting refcount to 1 * @old_ns: namespace to clone
@@ -24,14 +34,13 @@ static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns) {struct uts_namespace *ns; - ns =kmalloc (sizeof (struct uts_namespace ),GFP_KERNEL ); + ns =create_uts_ns ();if (!ns)return ERR_PTR (-ENOMEM );down_read (&uts_sem);memcpy (&ns->name, &old_ns->name,sizeof (ns->name));up_read (&uts_sem); -kref_init (&ns->kref);return ns; }
Signature · 1 line
1.5.6.5
PATCH 3/38 ipcns 1/4: remove useless get/put while CLONE_NEWIPC
In reply to a message not in the archivecopy_ipcs() doesn't actually copy anything. If new ipcns is created, it's created from scratch, in this case get/put on old ipcns isn't needed.
--- ipc/namespace.c | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-)
ipc/namespace.c +1 -5
@@ -50,15 +50,11 @@ struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns) {struct ipc_namespace *new_ns; -BUG_ON (!ns); -get_ipc_ns (ns); -if (!(flags &CLONE_NEWIPC )) -return ns; +return get_ipc_ns (ns); new_ns =clone_ipc_ns (ns); -put_ipc_ns (ns);return new_ns; }
Signature · 1 line
1.5.6.5
PATCH 4/38 ipcns 2/4: extract create_ipc_ns()
In reply to a message not in the archiveclone_ipc_ns() is misnamed, it doesn't clone anything and doesn't use passed parameter. Rename it.
create_ipc_ns() will be used by C/R to create fresh ipcns.
--- ipc/namespace.c | 9 ++------- 1 files changed, 2 insertions(+), 7 deletions(-)
ipc/namespace.c +2 -7
@@ -14,7 +14,7 @@#include "util.h" -static struct ipc_namespace *clone_ipc_ns (struct ipc_namespace *old_ns) +static struct ipc_namespace *create_ipc_ns (void ) {struct ipc_namespace *ns;int err;
@@ -48,14 +48,9 @@ static struct ipc_namespace *clone_ipc_ns(struct ipc_namespace *old_ns)struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns) { -struct ipc_namespace *new_ns; -if (!(flags &CLONE_NEWIPC ))return get_ipc_ns (ns); - - new_ns =clone_ipc_ns (ns); - -return new_ns; +return create_ipc_ns (); }/*
Signature · 1 line
1.5.6.5
PATCH 5/38 ipcns 3/4: make free_ipc_ns() static
In reply to a message not in the archive--- include/linux/ipc_namespace.h | 1 - ipc/namespace.c | 48 ++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 25 deletions(-)
include/linux/ipc_namespace.h +0 -1
@@ -94,7 +94,6 @@ static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }#endif #if defined(CONFIG_IPC_NS ) -extern void free_ipc_ns (struct ipc_namespace *ns);extern struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns); extern void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
ipc/namespace.c +24 -24
57 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 6/38 ipcns 4/2: move free_ipcs() proto
In reply to a message not in the archiveFunction is really private to ipc/ and avoid struct kern_ipc_perm forward declaration.
--- include/linux/ipc_namespace.h | 4 ---- ipc/util.h | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-)
include/linux/ipc_namespace.h +0 -4
@@ -96,10 +96,6 @@ static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }#if defined(CONFIG_IPC_NS )extern struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns); -extern void free_ipcs (struct ipc_namespace *ns,struct ipc_ids *ids, -void (*free)(struct ipc_namespace *, -struct kern_ipc_perm *)); -static inline struct ipc_namespace *get_ipc_ns (struct ipc_namespace *ns) {if (ns)
ipc/util.h +2 -1
@@ -171,5 +171,6 @@ static inline void ipc_unlock(struct kern_ipc_perm *perm)struct kern_ipc_perm *ipc_lock_check (struct ipc_ids *ids,int id);int ipcget (struct ipc_namespace *ns,struct ipc_ids *ids,struct ipc_ops *ops,struct ipc_params *params); - +void free_ipcs (struct ipc_namespace *ns,struct ipc_ids *ids, +void (*free)(struct ipc_namespace *,struct kern_ipc_perm *));#endif
Signature · 1 line
1.5.6.5
PATCH 7/38 pidns 1/2: make create_pid_namespace() accept parent pidns
In reply to a message not in the archivecreate_pid_namespace() creates everything, but caller has to assign parent pidns by hand, which is unnatural. At the moment of call new ->level has to be taken from somewhere and parent pidns is already available.
--- kernel/pid_namespace.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
kernel/pid_namespace.c +4 -4
@@ -67,9 +67,10 @@ err_alloc:return NULL ; } -static struct pid_namespace *create_pid_namespace (unsigned int level) +static struct pid_namespace *create_pid_namespace (struct pid_namespace *parent_pid_ns) {struct pid_namespace *ns; +unsigned int level = parent_pid_ns->level +1 ;int i; ns =kmem_cache_zalloc (pid_ns_cachep,GFP_KERNEL );
@@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_namespace(unsigned int level)kref_init (&ns->kref); ns->level = level; + ns->parent =get_pid_ns (parent_pid_ns);set_bit (0 , ns->pidmap[0 ].page);atomic_set (&ns->pidmap[0 ].nr_free,BITS_PER_PAGE -1 );
@@ -125,9 +127,7 @@ struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *oldif (flags &CLONE_THREAD ) goto out_put; - new_ns =create_pid_namespace (old_ns->level +1 ); -if (!IS_ERR (new_ns)) - new_ns->parent =get_pid_ns (old_ns); + new_ns =create_pid_namespace (old_ns); out_put:put_pid_ns (old_ns);
Signature · 1 line
1.5.6.5
PATCH 8/38 pidns 2/2: rewrite copy_pid_ns()
In reply to a message not in the archivecopy_pid_ns() is a perfect example of a case where unwinding leads to more code and makes it less clear. Watch the diffstat.
--- kernel/pid_namespace.c | 18 +++--------------- 1 files changed, 3 insertions(+), 15 deletions(-)
kernel/pid_namespace.c +3 -15
@@ -116,23 +116,11 @@ static void destroy_pid_namespace(struct pid_namespace *ns)struct pid_namespace *copy_pid_ns (unsigned long flags,struct pid_namespace *old_ns) { -struct pid_namespace *new_ns; - -BUG_ON (!old_ns); - new_ns =get_pid_ns (old_ns);if (!(flags &CLONE_NEWPID )) - goto out; - - new_ns =ERR_PTR (-EINVAL ); +return get_pid_ns (old_ns);if (flags &CLONE_THREAD ) - goto out_put; - - new_ns =create_pid_namespace (old_ns); - -out_put: -put_pid_ns (old_ns); -out: -return new_ns; +return ERR_PTR (-EINVAL ); +return create_pid_namespace (old_ns); }void free_pid_ns (struct kref *kref)
Signature · 1 line
1.5.6.5
PATCH 9/38 netns 1/2: don't get/put old netns on CLONE_NEWNET
In reply to a message not in the archivecopy_net_ns() doesn't copy anything, it creates fresh netns, so get/put of old netns isn't needed.
--- net/core/net_namespace.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)
net/core/net_namespace.c +1 -4
@@ -120,10 +120,8 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net)struct net *new_net =NULL ;int err; -get_net (old_net); -if (!(flags &CLONE_NEWNET )) -return old_net; +return get_net (old_net); err = -ENOMEM ; new_net =net_alloc ();
@@ -142,7 +140,6 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net)if (err) goto out_free; out: -put_net (old_net);return new_net; out_free:
Signature · 1 line
1.5.6.5
PATCH 10/38 netns 2/2: extract net_create()
In reply to a message not in the archivenet_create() will be used by C/R to create fresh netns on restart.
--- net/core/net_namespace.c | 44 ++++++++++++++++++++------------------------ 1 files changed, 20 insertions(+), 24 deletions(-)
net/core/net_namespace.c +20 -24
@@ -115,38 +115,34 @@ static void net_free(struct net *net)kmem_cache_free (net_cachep, net); } -struct net *copy_net_ns (unsigned long flags,struct net *old_net) +static struct net *net_create (void ) { -struct net *new_net =NULL ; -int err; - -if (!(flags &CLONE_NEWNET )) -return get_net (old_net); - - err = -ENOMEM ; - new_net =net_alloc (); -if (!new_net) - goto out_err; +struct net *net; +int rv; + net =net_alloc (); +if (!net) +return ERR_PTR (-ENOMEM );mutex_lock (&net_mutex); - err =setup_net (new_net); -if (!err) { + rv =setup_net (net); +if (rv ==0 ) {rtnl_lock (); -list_add_tail (&new_net->list, &net_namespace_list); +list_add_tail (&net->list, &net_namespace_list);rtnl_unlock (); }mutex_unlock (&net_mutex); +if (rv <0 ) { +net_free (net); +return ERR_PTR (rv); + } +return net; +} -if (err) - goto out_free; -out: -return new_net; - -out_free: -net_free (new_net); -out_err: - new_net =ERR_PTR (err); - goto out; +struct net *copy_net_ns (unsigned long flags,struct net *old_net) +{ +if (!(flags &CLONE_NEWNET )) +return get_net (old_net); +return net_create (); }static void cleanup_net (struct work_struct *work)
Signature · 1 line
1.5.6.5
PATCH 12/38 i386: ifdef out struct thread_struct::fs
In reply to a message not in the archiveAfter commit 464d1a78fbf8cf6c7fd970e7b3e2db50a320ce28 aka "[PATCH] i386: Convert i386 PDA code to use %fs"
%fs saved during context switch moved from thread_struct to pt_regs and value on thread_struct became unused.
I don't understand why .fs (OK, .gs first) initializer was added, kernel clearly stopped touching it after the patch.
--- arch/x86/include/asm/processor.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/include/asm/processor.h +2 -1
@@ -428,7 +428,9 @@ struct thread_struct {unsigned short gsindex;#endif unsigned long ip; +#ifdef CONFIG_X86_64 unsigned long fs; +#endif unsigned long gs;/* Hardware debugging registers: */ unsigned long debugreg0;
@@ -874,7 +876,6 @@ static inline void spin_lock_prefetch(const void *x) .vm86_info = NULL, \ .sysenter_cs = __KERNEL_CS, \ .io_bitmap_ptr = NULL, \ - .fs = __KERNEL_PERCPU, \ }/*
Signature · 1 line
1.5.6.5
PATCH 13/38 x86_64: ifdef out struct thread_struct::ip
In reply to a message not in the archivestruct thread_struct::ip isn't used on x86_64, struct pt_regs::ip is used instead.
kgdb should be reading 0 always, but I can't check it.
--- arch/x86/include/asm/processor.h | 2 ++ arch/x86/kernel/kgdb.c | 2 +- 2 files changed, 3 insertions(+), 1 deletions(-)
arch/x86/include/asm/processor.h +2 -0
@@ -427,7 +427,9 @@ struct thread_struct {unsigned short fsindex;unsigned short gsindex;#endif +#ifdef CONFIG_X86_32 unsigned long ip; +#endif #ifdef CONFIG_X86_64 unsigned long fs;#endif
arch/x86/kernel/kgdb.c +1 -1
@@ -142,7 +142,7 @@ void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p) gdb_regs32[GDB_PS ] = *(unsigned long *)(p->thread.sp +8 ); gdb_regs32[GDB_CS ] = __KERNEL_CS; gdb_regs32[GDB_SS ] = __KERNEL_DS; - gdb_regs[GDB_PC ] = p->thread.ip; + gdb_regs[GDB_PC ] =0 ; gdb_regs[GDB_R8 ] =0 ; gdb_regs[GDB_R9 ] =0 ; gdb_regs[GDB_R10 ] =0 ;
Signature · 1 line
1.5.6.5
PATCH 14/38 Remove struct mm_struct::exe_file et al
In reply to a message not in the archiveCommit 925d1c401fa6cfd0df5d2e37da8981494ccdec07 aka "procfs task exe symlink". introduced struct mm_struct::exe_file and struct mm_struct::num_exe_file_vmas.
The rationale is weak: unifying MMU and no-MMU version of /proc/*/exe code. For this a) struct mm_struct becomes bigger, b) mmap/munmap/exit become slower,
c) patch adds more code than removes in fact.
After commit 8feae13110d60cc6287afabc2887366b0eb226c2 aka "NOMMU: Make VMAs per MM as for MMU-mode linux" no-MMU kernels also maintain list of VMAs in ->mmap, so we can switch back for MMU version of /proc/*/exe.
This also helps C/R, no need to save and restore ->exe_file and to count additional references to check if there is a leak of struct file outside group of checkpointed resources.
--- fs/exec.c | 2 - fs/proc/base.c | 105 +++++++++++++--------------------------------- include/linux/mm.h | 12 ----- include/linux/mm_types.h | 6 --- include/linux/proc_fs.h | 20 --------- kernel/fork.c | 3 - mm/mmap.c | 22 ++-------- mm/nommu.c | 16 +------ 8 files changed, 36 insertions(+), 150 deletions(-)
fs/exec.c +0 -2
@@ -938,8 +938,6 @@ int flush_old_exec(struct linux_binprm * bprm)if (retval) goto out; -set_mm_exe_file (bprm->mm, bprm->file); -/* * Release all of the old mmap stuff */
fs/proc/base.c +30 -75
117 lines not on this page · raw message
include/linux/mm.h +0 -12
@@ -1121,18 +1121,6 @@ extern void exit_mmap(struct mm_struct *);extern int mm_take_all_locks (struct mm_struct *mm);extern void mm_drop_all_locks (struct mm_struct *mm); -#ifdef CONFIG_PROC_FS -/* From fs/proc/base.c. callers must _not_ hold the mm's exe_file_lock */ -extern void added_exe_file_vma (struct mm_struct *mm); -extern void removed_exe_file_vma (struct mm_struct *mm); -#else -static inline void added_exe_file_vma (struct mm_struct *mm) -{} - -static inline void removed_exe_file_vma (struct mm_struct *mm) -{} -#endif /* CONFIG_PROC_FS */ -extern int may_expand_vm (struct mm_struct *mm,unsigned long npages); extern int install_special_mapping(struct mm_struct *mm, unsigned long addr, unsigned long len,
include/linux/mm_types.h +0 -6
@@ -269,12 +269,6 @@ struct mm_struct {*/ struct task_struct *owner;#endif - -#ifdef CONFIG_PROC_FS -/* store ref to file /proc/<pid>/exe symlink points to */ -struct file *exe_file; -unsigned long num_exe_file_vmas; -#endif #ifdef CONFIG_MMU_NOTIFIER struct mmu_notifier_mm *mmu_notifier_mm;#endif
include/linux/proc_fs.h +0 -20
@@ -188,12 +188,6 @@ extern void proc_net_remove(struct net *net, const char *name);extern struct proc_dir_entry *proc_net_mkdir (struct net *net,const char *name,struct proc_dir_entry *parent); -/* While the {get|set|dup}_mm_exe_file functions are for mm_structs, they are -* only needed to implement /proc/<pid>|self/exe so we define them here. */ -extern void set_mm_exe_file (struct mm_struct *mm,struct file *new_exe_file); -extern struct file *get_mm_exe_file (struct mm_struct *mm); -extern void dup_mm_exe_file (struct mm_struct *oldmm,struct mm_struct *newmm); -#else #define proc_net_fops_create (net, name, mode, fops) ({ (void)(mode), NULL; })
@@ -240,20 +234,6 @@ static inline int pid_ns_prepare_proc(struct pid_namespace *ns)static inline void pid_ns_release_proc (struct pid_namespace *ns) { } - -static inline void set_mm_exe_file (struct mm_struct *mm, -struct file *new_exe_file) -{} - -static inline struct file *get_mm_exe_file (struct mm_struct *mm) -{ -return NULL ; -} - -static inline void dup_mm_exe_file (struct mm_struct *oldmm, -struct mm_struct *newmm) -{} -#endif /* CONFIG_PROC_FS */ #if !defined(CONFIG_PROC_KCORE )
kernel/fork.c +0 -3
@@ -488,7 +488,6 @@ void mmput(struct mm_struct *mm)if (atomic_dec_and_test (&mm->mm_users)) {exit_aio (mm);exit_mmap (mm); -set_mm_exe_file (mm,NULL );if (!list_empty (&mm->mmlist)) {spin_lock (&mmlist_lock);list_del (&mm->mmlist);
@@ -611,8 +610,6 @@ struct mm_struct *dup_mm(struct task_struct *tsk)if (init_new_context (tsk, mm)) goto fail_nocontext; -dup_mm_exe_file (oldmm, mm); - err =dup_mmap (mm, oldmm);if (err) goto free_pt;
mm/mmap.c +4 -18
@@ -232,11 +232,8 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)might_sleep ();if (vma->vm_ops && vma->vm_ops->close) vma->vm_ops->close (vma); -if (vma->vm_file) { +if (vma->vm_file)fput (vma->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -removed_exe_file_vma (vma->vm_mm); - }mpol_put (vma_policy (vma));kmem_cache_free (vm_area_cachep, vma);return next;
@@ -633,11 +630,8 @@ again: remove_next = 1 + (end > next->vm_end);spin_unlock (&mapping->i_mmap_lock);if (remove_next) { -if (file) { +if (file)fput (file); -if (next->vm_flags &VM_EXECUTABLE ) -removed_exe_file_vma (mm); - } mm->map_count--;mpol_put (vma_policy (next));kmem_cache_free (vm_area_cachep, next);
@@ -1192,8 +1186,6 @@ munmap_back: error = file->f_op->mmap (file, vma);if (error) goto unmap_and_free_vma; -if (vm_flags &VM_EXECUTABLE ) -added_exe_file_vma (mm); }else if (vm_flags &VM_SHARED ) { error =shmem_zero_setup (vma);if (error)
@@ -1849,11 +1841,8 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma, }vma_set_policy (new, pol); -if (new->vm_file) { +if (new->vm_file)get_file (new->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -added_exe_file_vma (mm); - }if (new->vm_ops && new->vm_ops->open) new->vm_ops->open (new);
@@ -2200,11 +2189,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, new_vma->vm_start = addr; new_vma->vm_end = addr + len; new_vma->vm_pgoff = pgoff; -if (new_vma->vm_file) { +if (new_vma->vm_file)get_file (new_vma->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -added_exe_file_vma (mm); - }if (new_vma->vm_ops && new_vma->vm_ops->open) new_vma->vm_ops->open (new_vma);vma_link (mm, new_vma, prev, rb_link, rb_parent);
mm/nommu.c +2 -14
@@ -721,11 +721,8 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)kenter ("%p" , vma);if (vma->vm_ops && vma->vm_ops->close) vma->vm_ops->close (vma); -if (vma->vm_file) { +if (vma->vm_file)fput (vma->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -removed_exe_file_vma (mm); - }put_nommu_region (vma->vm_region);kmem_cache_free (vm_area_cachep, vma); }
@@ -1218,10 +1215,6 @@ unsigned long do_mmap_pgoff(struct file *file,get_file (file); vma->vm_file = file;get_file (file); -if (vm_flags &VM_EXECUTABLE ) { -added_exe_file_vma (current->mm); - vma->vm_mm = current->mm; - } }down_write (&nommu_region_sem);
@@ -1359,11 +1352,8 @@ share: error_put_region:__put_nommu_region (region);if (vma) { -if (vma->vm_file) { +if (vma->vm_file)fput (vma->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -removed_exe_file_vma (vma->vm_mm); - }kmem_cache_free (vm_area_cachep, vma); }kleave (" = %d [pr]" , ret);
@@ -1375,8 +1365,6 @@ error:fput (region->vm_file);kmem_cache_free (vm_region_jar, region);fput (vma->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -removed_exe_file_vma (vma->vm_mm);kmem_cache_free (vm_area_cachep, vma);kleave (" = %d" , ret);return ret;
Signature · 1 line
1.5.6.5
PATCH 15/38 dcache: extract and use d_unlinked()
In reply to a message not in the archived_unlinked() will be used in middle-term to ban checkpointing when opened but unlinked file is detected, and in long term, to detect such situation and special case on it.
--- fs/dcache.c | 7 +++---- fs/namespace.c | 8 ++++---- include/linux/dcache.h | 5 +++++ 3 files changed, 12 insertions(+), 8 deletions(-)
fs/dcache.c +3 -4
@@ -1910,7 +1910,7 @@ char *__d_path(const struct path *path, struct path *root,spin_lock (&vfsmount_lock);prepend (&end, &buflen,"\0" ,1 ); -if (!IS_ROOT (dentry) &&d_unhashed (dentry) && +if (d_unlinked (dentry) && (prepend (&end, &buflen," (deleted)" ,10 ) !=0 )) goto Elong;
@@ -2035,7 +2035,7 @@ char *dentry_path(struct dentry *dentry, char *buf, int buflen)spin_lock (&dcache_lock);prepend (&end, &buflen,"\0" ,1 ); -if (!IS_ROOT (dentry) &&d_unhashed (dentry) && +if (d_unlinked (dentry) && (prepend (&end, &buflen,"//deleted" ,9 ) !=0 )) goto Elong;if (buflen <1 )
@@ -2097,9 +2097,8 @@ SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size)read_unlock (¤t->fs->lock); error = -ENOENT ; -/* Has the current directory has been unlinked? */ spin_lock (&dcache_lock); -if (IS_ROOT (pwd.dentry) || !d_unhashed (pwd.dentry)) { +if (!d_unlinked (pwd.dentry)) {unsigned long len;struct path tmp = root;char * cwd;
fs/namespace.c +4 -4
@@ -1430,7 +1430,7 @@ static int graft_tree(struct vfsmount *mnt, struct path *path) goto out_unlock; err = -ENOENT ; -if (IS_ROOT (path->dentry) || !d_unhashed (path->dentry)) +if (!d_unlinked (path->dentry)) err =attach_recursive_mnt (mnt, path,NULL ); out_unlock:mutex_unlock (&path->dentry->d_inode->i_mutex);
@@ -1612,7 +1612,7 @@ static int do_move_mount(struct path *path, char *old_name)if (IS_DEADDIR (path->dentry->d_inode)) goto out1; -if (!IS_ROOT (path->dentry) &&d_unhashed (path->dentry)) +if (d_unlinked (path->dentry)) goto out1; err = -EINVAL ;
@@ -2175,9 +2175,9 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, error = -ENOENT ;if (IS_DEADDIR (new.dentry->d_inode)) goto out2; -if (d_unhashed (new.dentry) && !IS_ROOT (new.dentry)) +if (d_unlinked (new.dentry)) goto out2; -if (d_unhashed (old.dentry) && !IS_ROOT (old.dentry)) +if (d_unlinked (old.dentry)) goto out2; error = -EBUSY ; if (new.mnt == root.mnt ||
include/linux/dcache.h +5 -0
@@ -351,6 +351,11 @@ static inline int d_unhashed(struct dentry *dentry)return (dentry->d_flags &DCACHE_UNHASHED ); } +static inline int d_unlinked (struct dentry *dentry) +{ +return d_unhashed (dentry) && !IS_ROOT (dentry); +} +static inline struct dentry *dget_parent (struct dentry *dentry) {struct dentry *ret;
Signature · 1 line
1.5.6.5
PATCH 16/38 x86: ptrace debugreg checks rewrite
In reply to a message not in the archiveThis is a mess.
Pre unified-x86 code did check for breakpoint addr
to be "< TASK_SIZE - 3 (or 7)". This was fine from security POV, but banned valid breakpoint usage when address is close to TASK_SIZE. E. g. 1-byte breakpoint at TASK_SIZE - 1 should be allowed, but it wasn't.
Then came commit 84929801e14d968caeb84795bfbb88f04283fbd9 ("[PATCH] x86_64: TASK_SIZE fixes for compatibility mode processes") which for some reason touched ptrace as well and made effective TASK_SIZE of 32-bit process depending on IA32_PAGE_OFFSET which is not a constant!:
#define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? 0xc0000000 : 0xFFFFe000) ^^^^^^^
Maximum addr for breakpoint became dependent on personality of ptracer.
Commit also relaxed danger zone for 32-bit processes from 8 bytes to 4 not taking into account that 8-byte wide breakpoints are possible even for 32-bit processes. This was fine, however, because 64-bit kernel addresses are too far from 32-bit ones.
Then came utrace with commit 2047b08be67b70875d8765fc81d34ce28041bec3 ("x86: x86 ptrace getreg/putreg merge") which copy-pasted and ifdeffed 32-bit part of TASK_SIZE_OF() leaving 8-byte issue as-is.
So, what patch fixes?
1) Too strict logic near TASK_SIZE boundary -- as long as we don't cross TASK_SIZE_MAX, we're fine.
2) Too smart logic of using breakpoints over non-existent kernel boundary -- we should only protect against setting up after TASK_SIZE_MAX, the rest is none of kernel business. This fixes IA32_PAGE_OFFSET beartrap as well.
As a bonus, remove uberhack and big comment determining DR7 validness, rewrite with clear algorithm when it's obvious what's going on.
Make DR validness checker suitable for C/R. On restart DR registers must be checked the same way they are checked on PTRACE_POKEUSR.
Question 1: TIF_DEBUG can set even if none of breakpoints is turned on, should this be optimized?
Question 2: Breakpoints are allowed to be globally enabled, is this a security risk?
--- arch/x86/kernel/ptrace.c | 175 +++++++++++++++++++++++++++------------------- 1 files changed, 103 insertions(+), 72 deletions(-)
arch/x86/kernel/ptrace.c +103 -72
@@ -135,11 +135,6 @@ static int set_segment_reg(struct task_struct *task, return 0; } -static unsigned long debugreg_addr_limit (struct task_struct *task) -{ -return TASK_SIZE -3 ; -} -#else /* CONFIG_X86_64 */ #define FLAG_MASK (FLAG_MASK_32 | X86_EFLAGS_NT)
@@ -263,16 +258,6 @@ static int set_segment_reg(struct task_struct *task, return 0; } - -static unsigned long debugreg_addr_limit (struct task_struct *task) -{ -#ifdef CONFIG_IA32_EMULATION -if (test_tsk_thread_flag (task,TIF_IA32 )) -return IA32_PAGE_OFFSET -3 ; -#endif -return TASK_SIZE_MAX -7 ; -} -#endif /* CONFIG_X86_32 */ static unsigned long get_flags (struct task_struct *task)
@@ -480,77 +465,123 @@ static unsigned long ptrace_get_debugreg(struct task_struct *child, int n)return 0 ; } +static int ptrace_check_debugreg (int _32bit, +unsigned long dr0,unsigned long dr1, +unsigned long dr2,unsigned long dr3, +unsigned long dr6,unsigned long dr7) +{ +/* Breakpoint type: 00: --x, 01: -w-, 10: undefined, 11: rw- */ +unsigned int rw[4 ]; +/* Breakpoint length: 00: 1 byte, 01: 2 bytes, 10: 8 bytes, 11: 4 bytes */ +unsigned int len[4 ]; +int n; + +if (dr0 >=TASK_SIZE_MAX ) +return -EINVAL ; +if (dr1 >=TASK_SIZE_MAX ) +return -EINVAL ; +if (dr2 >=TASK_SIZE_MAX ) +return -EINVAL ; +if (dr3 >=TASK_SIZE_MAX ) +return -EINVAL ; + +for (n =0 ; n <4 ; n++) { + rw[n] = (dr7 >> (16 + n *4 )) &0x3 ; + len[n] = (dr7 >> (16 + n *4 +2 )) &0x3 ; + +if (rw[n] ==0x2 ) +return -EINVAL ; +if (rw[n] ==0x0 && len[n] !=0x0 ) +return -EINVAL ; +if (_32bit && len[n] ==0x2 ) +return -EINVAL ; + +if (len[n] ==0x0 ) + len[n] =1 ; +else if (len[n] ==0x1 ) + len[n] =2 ; +else if (len[n] ==0x2 ) + len[n] =8 ; +else if (len[n] ==0x3 ) + len[n] =4 ; +/* From now breakpoint length is in bytes. */ + } + +if (dr6 & ~0xFFFFFFFFUL ) +return -EINVAL ; +if (dr7 & ~0xFFFFFFFFUL ) +return -EINVAL ; + +if (dr7 ==0 ) +return 0 ; + +if (dr0 + len[0 ] >TASK_SIZE_MAX ) +return -EINVAL ; +if (dr1 + len[1 ] >TASK_SIZE_MAX ) +return -EINVAL ; +if (dr2 + len[2 ] >TASK_SIZE_MAX ) +return -EINVAL ; +if (dr3 + len[3 ] >TASK_SIZE_MAX ) +return -EINVAL ; + +return 0 ; +} +static int ptrace_set_debugreg (struct task_struct *child,int n,unsigned long data) { -int i; +unsigned long dr0, dr1, dr2, dr3, dr6, dr7; +int _32bit;if (unlikely (n ==4 || n ==5 ))return -EIO ; -if (n <4 &&unlikely (data >=debugreg_addr_limit (child))) -return -EIO ; - + dr0 = child->thread.debugreg0; + dr1 = child->thread.debugreg1; + dr2 = child->thread.debugreg2; + dr3 = child->thread.debugreg3; + dr6 = child->thread.debugreg6; + dr7 = child->thread.debugreg7;switch (n) { -case 0 : child->thread.debugreg0 = data;break ; -case 1 : child->thread.debugreg1 = data;break ; -case 2 : child->thread.debugreg2 = data;break ; -case 3 : child->thread.debugreg3 = data;break ; - +case 0 : + dr0 = data; +break ; +case 1 : + dr1 = data; +break ; +case 2 : + dr2 = data; +break ; +case 3 : + dr3 = data; +break ;case 6 : -if ((data & ~0xffffffffUL ) !=0 ) -return -EIO ; - child->thread.debugreg6 = data; + dr6 = data;break ; -case 7 : -/* -* Sanity-check data. Take one half-byte at once with -* check = (val >> (16 + 4*i)) & 0xf. It contains the -* R/Wi and LENi bits; bits 0 and 1 are R/Wi, and bits -* 2 and 3 are LENi. Given a list of invalid values, -* we do mask |= 1 << invalid_value, so that -* (mask >> check) & 1 is a correct test for invalid -* values. -* -* R/Wi contains the type of the breakpoint / -* watchpoint, LENi contains the length of the watched -* data in the watchpoint case. -* -* The invalid values are: -* - LENi == 0x10 (undefined), so mask |= 0x0f00. [32-bit] -* - R/Wi == 0x10 (break on I/O reads or writes), so -* mask |= 0x4444. -* - R/Wi == 0x00 && LENi != 0x00, so we have mask |= -* 0x1110. -* -* Finally, mask = 0x0f00 | 0x4444 | 0x1110 == 0x5f54. -* -* See the Intel Manual "System Programming Guide", -* 15.2.4 -* -* Note that LENi == 0x10 is defined on x86_64 in long -* mode (i.e. even for 32-bit userspace software, but -* 64-bit kernel), so the x86_64 mask value is 0x5454. -* See the AMD manual no. 24593 (AMD64 System Programming) -*/ -#ifdef CONFIG_X86_32 -#define DR7_MASK 0x5f54 -#else -#define DR7_MASK 0x5554 -#endif - data &= ~DR_CONTROL_RESERVED ; -for (i =0 ; i <4 ; i++) -if ((DR7_MASK >> ((data >> (16 +4 *i)) &0xf )) &1 ) -return -EIO ; - child->thread.debugreg7 = data; -if (data) -set_tsk_thread_flag (child,TIF_DEBUG ); -else -clear_tsk_thread_flag (child,TIF_DEBUG ); + dr7 = data & ~DR_CONTROL_RESERVED ;break ; } + _32bit = (sizeof (unsigned long ) ==4 ); +#ifdef CONFIG_COMPAT +if (test_tsk_thread_flag (child,TIF_IA32 )) + _32bit =1 ; +#endif +if (ptrace_check_debugreg (_32bit, dr0, dr1, dr2, dr3, dr6, dr7)) +return -EIO ; + + child->thread.debugreg0 = dr0; + child->thread.debugreg1 = dr1; + child->thread.debugreg2 = dr2; + child->thread.debugreg3 = dr3; + child->thread.debugreg6 = dr6; + child->thread.debugreg7 = dr7; +if (dr7) +set_tsk_thread_flag (child,TIF_DEBUG ); +else +clear_tsk_thread_flag (child,TIF_DEBUG ); +return 0 ; }
Signature · 1 line
1.5.6.5
PATCH 17/38 groups: move code to kernel/groups.c
In reply to a message not in the archiveMove supplementary groups implementation to kernel/groups.c . kernel/sys.c already accumulated quite a few random stuff.
Do strictly copy/paste + add required headers to compile. Compile-tested on many configs and archs.
--- kernel/Makefile | 1 + kernel/groups.c | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/sys.c | 283 ------------------------------------------------------ 3 files changed, 289 insertions(+), 283 deletions(-) create mode 100644 kernel/groups.c
kernel/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o \ hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \ async.o +obj-y += groups.o ifdef CONFIG_FUNCTION_TRACER # Do not trace debug files and internal ftrace files
kernel/groups.c new file +288 -0
288 lines not on this page · raw message
kernel/sys.c +0 -283
289 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 18/38 C/R: core stuff
In reply to a message not in the archiveIntroduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
How C/R works
-------------
User passes to system call pid of process which is the root of process hierarchy to be saved. Hierarchy is formed wrt ->real_parent.
Processes which belong to this hierarchy are frozen.
C/R code walks in-kernel datastructures starting from task_structs and collects references to them in one place for a dump. This includes at least mm_struct, nsproxy and it's belongings, opened files, CPU registers, etc. More or less anything which is userspace-visible must be dumped on one form or another.
Collected data structures are checked for sanity wrt several things:
- still unsupported features (hugetlb mappings) in which case checkpointing is aborted
- structure "leaks" to outside of selected group of processes.
This is done by maintaining mirror refcount from structures collected and comparing it with real refcount. If discrepancy is noticed, structure is used by someone else who is not frozen and thus we're trying to checkpoint live data structure. Depending on what data structure is dumping live data structure can be pretty easy (uts_namespace requires only uts_sem) to pretty hard (net_namespace sockets requires... actually nobody knows what net_namespace will require).
Note! There re multiple levels of correct operation implied:
- kernel shouldn't oops by dumping live data structure
- kernel shouldn't write inconsistent state by dumping live data structure
If all checks for all data structures are OK, C/R code walks collected references in certain order and does actual serializing and writes image to passed file descriptor.
This results in a file which is believed to contain enough information to restore group of process to exactly same user-visible state as before checkpointing module inevitable issues like time.
Image format design
-------------------
Image consists of image header, object images one after another and terminator which is formally an object.
Image header consists of magic ("LinuxC/R") and image version (__le32). This is immutable part of an image. The rest is defined strictly by image version even the rest of image header.
Nobody is making guarantees that image format is immutable!
Once again, image format will change, however it's guaranteed that magic+version part will remain and image version will be bumped.
So far, image header consists of
a) arch of kernel which dumped image to signalize that you can't restore powerpc image on i386 kernel and hint code in case of restoring i386 image on x86_64 kernel.
b) kernel version as found in utsname.
This is done for distributions who eventually may want to support C/R. While the expected way to maintain migrating from older kernels is to write userspace converter which knows everything about two image formats, distro kernels may want to maintain all backward-caompat code in kernel which can be small or big depending on the amount of changes they pull into their kernel.
Just image version isn't realistically sufficient, distributions are expected to leave image version alone and demultiplex backward-compat code depending on utsname which is in case of distro kernels is pretty well known.
Object image
------------
Object images are direct projection of in-kernel data structures which can be shared inside kernel to disk :-) Example: struct mm_struct is dumped to an object of KSTATE_OBJ_MM_STRUCT type, struct cred is dumped to KSTATE_OBJ_CRED type.
There are so far 3 exceptions: VMA, page content and fd. These are formal objects with type and length to simplify reading and restoration of VMAs and file descriptors, respectively. VMA and pages attributed are even variable-sized.
Any object image starts with object header which is object type, object lenth including header and globally unique object id (per-image, of course). Type and length are used in verifying that image is not malformed and object id is used in references of objects to another objects and also verifying.
VMA, pages and file descriptors don't get object id, because they aren't directly collected. But this is fine, as they get invalid object id (0) which is not checked.
Relations in image
------------------
To serialize reference of object A to object B (task_struct::mm) image of object a gets a field of kstate_ref_t type:
struct kstate_image_a {
struct kstate_object_header hdr;
kstate_ref_t ref_b;
};which corresponds to a->b pointer.
Reference consists of position in a dumpfile (if it's known by the time B is dumped and object id of B (which _is_ known).
If there is a loop in pointers A => B => A, position is dumped as 0 and attention is required at restore time. In each loop case it will be dealt individually. (so far, there is one loop: user->user_ns->creator)
C/R dump code tries hard to maintaint streamable property of dump process -- if dumpfile is opened with O_APPEND, it should work).
Changes in kernel internals:
- add struct file_operations::checkpoint hook
Code which operated file knows better what information needs to be saved to allow successful restoration. For usual files on on-disk filesystem add generic_file_checkpoint().
Add ext3 opened regular files and directories for start.
If opened or references file doesn't have ->checkpoint hook, checkpointing is aborted -- this is deny-by-default policy.
- add struct vm_operations_struct::checkpoint
Same as for files. Will be used more by vDSO code.
checkpoint(2), restart(2)
-------------------------
Exact number and semantics of system calls is WIP, it was correctly noticed, that 'freeze' and 'dump' parts needs to be split apart to allow filesystem sync after freeze. For now leave 2 syscalls for people to play with.
Splitting freeze/dump implies persistent C/R context state BTW which is not the case now.
Checkpoint semantics
--------------------
Checkpointing is done on per-container level without "leaks" to outside. In this kernel can provide promises to dump coherent start and to do it without major games with data structures locking.
Works to allow reliable checkpoint on live data structures has been started however it's unclear what the result will be because of even more thing one has to keep inside head simultaneously.
As a semi-direct consequence checkpkointing is not allowed for ordinary users. While it's a nice feature to allow it, they formally can't even create container for themselves (CAP_SYS_ADMIN during nsproxy tweaks).
Regadless, once enabled this will present several security risks:
- anything in image is controlled by untrusted user who will try to check how well checking code on restart(2) is written.
And, yes, nobody is hiding that restart(2) involves honest parsing of slightly more complex that string file format inside kernel.
- user who effectively can turn off ASLR randomization, because he controls VMA boundaries.
These two directions (checkpointing live and restart(2) for everyone) aren't explored in this patchset because they are artificially not independent right now and each one is hard enough for already hard C/R work.
Sorry.
However, code is kept good enough to add each of feature later.
--- fs/ext3/dir.c | 3 + fs/ext3/file.c | 3 + include/linux/Kbuild | 1 + include/linux/fs.h | 12 +- include/linux/kstate-image.h | 118 +++++++++ include/linux/kstate.h | 144 ++++++++++ include/linux/mm.h | 4 + include/linux/syscalls.h | 3 + init/Kconfig | 2 + kernel/Makefile | 1 + kernel/kstate/Kconfig | 7 + kernel/kstate/Makefile | 8 + kernel/kstate/cpt-sys.c | 196 ++++++++++++++ kernel/kstate/kstate-context.c | 49 ++++ kernel/kstate/kstate-file.c | 204 +++++++++++++++ kernel/kstate/kstate-image.c | 116 ++++++++ kernel/kstate/kstate-mm.c | 563 ++++++++++++++++++++++++++++++++++++++++ kernel/kstate/kstate-object.c | 100 +++++++ kernel/kstate/kstate-task.c | 287 ++++++++++++++++++++ kernel/kstate/rst-sys.c | 91 +++++++ kernel/sys_ni.c | 3 + mm/filemap.c | 3 + 22 files changed, 1916 insertions(+), 2 deletions(-) create mode 100644 include/linux/kstate-image.h create mode 100644 include/linux/kstate.h create mode 100644 kernel/kstate/Kconfig create mode 100644 kernel/kstate/Makefile create mode 100644 kernel/kstate/cpt-sys.c create mode 100644 kernel/kstate/kstate-context.c create mode 100644 kernel/kstate/kstate-file.c create mode 100644 kernel/kstate/kstate-image.c create mode 100644 kernel/kstate/kstate-mm.c create mode 100644 kernel/kstate/kstate-object.c create mode 100644 kernel/kstate/kstate-task.c create mode 100644 kernel/kstate/rst-sys.c
fs/ext3/dir.c +3 -0
@@ -48,6 +48,9 @@ const struct file_operations ext3_dir_operations = {#endif .fsync = ext3_sync_file, /* BKL held */ .release = ext3_release_dir, +#ifdef CONFIG_CHECKPOINT + .checkpoint = generic_file_checkpoint, +#endif };
fs/ext3/file.c +3 -0
@@ -126,6 +126,9 @@ const struct file_operations ext3_file_operations = { .fsync = ext3_sync_file, .splice_read = generic_file_splice_read, .splice_write = generic_file_splice_write, +#ifdef CONFIG_CHECKPOINT + .checkpoint = generic_file_checkpoint, +#endif };const struct inode_operations ext3_file_inode_operations = {
include/linux/Kbuild +1 -0
@@ -50,6 +50,7 @@ header-y += coff.h header-y += comstats.h header-y += const.h header-y += cgroupstats.h +header-y += kstate-image.h header-y += cramfs_fs.h header-y += cycx_cfm.h header-y += dcbnl.h
include/linux/fs.h +10 -2
@@ -387,6 +387,7 @@ struct poll_table_struct;struct kstatfs ;struct vm_area_struct ;struct vfsmount ; +struct kstate_context ;struct cred ;extern void __init inode_init (void );
@@ -1508,6 +1509,9 @@ struct file_operations {ssize_t (*splice_write)(struct pipe_inode_info *,struct file *,loff_t *,size_t ,unsigned int );ssize_t (*splice_read)(struct file *,loff_t *,struct pipe_inode_info *,size_t ,unsigned int );int (*setlease)(struct file *,long ,struct file_lock **); +#ifdef CONFIG_CHECKPOINT +int (*checkpoint)(struct file *file,struct kstate_context *ctx); +#endif };struct inode_operations {
@@ -2079,7 +2083,9 @@ extern int __filemap_fdatawrite_range(struct address_space *mapping, loff_t start, loff_t end, int sync_mode);extern int filemap_fdatawrite_range (struct address_space *mapping,loff_t start,loff_t end); - +#ifdef CONFIG_CHECKPOINT +int filemap_checkpoint (struct vm_area_struct *vma,struct kstate_context *ctx); +#endif extern int vfs_fsync (struct file *file,struct dentry *dentry,int datasync);extern void sync_supers (void );extern void sync_filesystems (int wait);
@@ -2201,7 +2207,9 @@ extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, lofextern ssize_t do_sync_write (struct file *filp,const char __user *buf,size_t len,loff_t *ppos);extern int generic_segment_checks (const struct iovec *iov,unsigned long *nr_segs,size_t *count,int access_flags); - +#ifdef CONFIG_CHECKPOINT +int generic_file_checkpoint (struct file *file,struct kstate_context *ctx); +#endif /* fs/splice.c */ extern ssize_t generic_file_splice_read (struct file *,loff_t *,struct pipe_inode_info *,size_t ,unsigned int );
include/linux/kstate-image.h new file +118 -0
118 lines not on this page · raw message
include/linux/kstate.h new file +144 -0
144 lines not on this page · raw message
include/linux/mm.h +4 -0
@@ -16,6 +16,7 @@struct mempolicy ;struct anon_vma ; +struct kstate_context ;struct file_ra_state ;struct user_struct ;struct writeback_control ;
@@ -220,6 +221,9 @@ struct vm_operations_struct {int (*migrate)(struct vm_area_struct *vma,const nodemask_t *from,const nodemask_t *to,unsigned long flags);#endif +#ifdef CONFIG_CHECKPOINT +int (*checkpoint)(struct vm_area_struct *vma,struct kstate_context *ctx); +#endif };struct mmu_gather ;
include/linux/syscalls.h +3 -0
@@ -753,6 +753,9 @@ asmlinkage long sys_ppoll(struct pollfd __user *, unsigned int,asmlinkage long sys_pipe2 (int __user *,int );asmlinkage long sys_pipe (int __user *); +asmlinkage long sys_checkpoint (pid_t pid,int fd,int flags); +asmlinkage long sys_restart (int fd,int flags); +int kernel_execve (const char *filename,char *const argv[],char *const envp[]);#endif
init/Kconfig +2 -0
@@ -608,6 +608,8 @@ config CGROUP_MEM_RES_CTLR_SWAP endif # CGROUPS +source "kernel/kstate/Kconfig" + config MM_OWNER bool
kernel/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_FREEZER) += power/ obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o +obj-$(CONFIG_CHECKPOINT) += kstate/ obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_CGROUPS) += cgroup.o obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o
kernel/kstate/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config CHECKPOINT + bool "Container checkpoint/restart" + select FREEZER + help + Container checkpoint/restart. + + Say N.
kernel/kstate/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +obj-$(CONFIG_CHECKPOINT) += kstate.o +kstate-y := cpt-sys.o rst-sys.o +kstate-y += kstate-context.o +kstate-y += kstate-file.o +kstate-y += kstate-image.o +kstate-y += kstate-mm.o +kstate-y += kstate-object.o +kstate-y += kstate-task.o
kernel/kstate/cpt-sys.c new file +196 -0
196 lines not on this page · raw message
kernel/kstate/kstate-context.c new file +49 -0
49 lines not on this page · raw message
kernel/kstate/kstate-file.c new file +204 -0
204 lines not on this page · raw message
kernel/kstate/kstate-image.c new file +116 -0
116 lines not on this page · raw message
kernel/kstate/kstate-mm.c new file +563 -0
563 lines not on this page · raw message
kernel/kstate/kstate-object.c new file +100 -0
100 lines not on this page · raw message
kernel/kstate/kstate-task.c new file +287 -0
287 lines not on this page · raw message
kernel/kstate/rst-sys.c new file +91 -0
91 lines not on this page · raw message
kernel/sys_ni.c +3 -0
@@ -175,3 +175,6 @@ cond_syscall(compat_sys_timerfd_settime);cond_syscall (compat_sys_timerfd_gettime);cond_syscall (sys_eventfd);cond_syscall (sys_eventfd2); + +cond_syscall (sys_checkpoint); +cond_syscall (sys_restart);
mm/filemap.c +3 -0
@@ -1627,6 +1627,9 @@ EXPORT_SYMBOL(filemap_fault);struct vm_operations_struct generic_file_vm_ops = { .fault = filemap_fault, +#ifdef CONFIG_CHECKPOINT + .checkpoint = filemap_checkpoint, +#endif };/* This is used for a general mmap of a disk file */
Signature · 1 line
1.5.6.5
PATCH 19/38 C/R: multiple tasks
In reply to a message not in the archiveRestore task hierarchy wrt ->real_parent.
First thing soon-to-be-restored task does after birth is to find ->real_parent and glue itself to parent lists.
For this parent is dumped first and restored first, so that at the time child starts restoration, parent is already up and running as task_struct, and we get cheap loop-prevention check.
--- include/linux/kstate-image.h | 2 + kernel/kstate/kstate-object.c | 3 +- kernel/kstate/kstate-task.c | 53 +++++++++++++++++++++++++++++++++++----- 3 files changed, 50 insertions(+), 8 deletions(-)
include/linux/kstate-image.h +2 -0
@@ -60,6 +60,8 @@ struct kstate_object_header {struct kstate_image_task_struct {struct kstate_object_header hdr; +kstate_ref_t ref_real_parent; +kstate_ref_t ref_mm;__u8 comm[16 ];
kernel/kstate/kstate-object.c +2 -1
@@ -25,7 +25,8 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte obj->o_ref.pos =0 ;/* not yet dumped */ obj->o_ref.id =0 ;/* not yet assigned */ obj->o_obj = p; -list_add (&obj->o_list, &ctx->obj[type]); +/* task_struct collecting relies on "_tail" part. */ +list_add_tail (&obj->o_list, &ctx->obj[type]);switch (type) {case KSTATE_CTX_FILE :
kernel/kstate/kstate-task.c +46 -7
78 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 20/38 C/R: i386 support
In reply to a message not in the archiveSegment registers are abstracted to allow i386 => x86_64 migration (BTW, I'm not so sure if just making 32-bit selectors the same will achieve same effect)
--- arch/x86/include/asm/unistd_32.h | 2 + arch/x86/kernel/syscall_table_32.S | 2 + include/linux/kstate-image.h | 30 ++++ include/linux/kstate.h | 2 +- kernel/kstate/Makefile | 1 + kernel/kstate/kstate-x86_32.c | 294 ++++++++++++++++++++++++++++++++++++ 6 files changed, 330 insertions(+), 1 deletions(-) create mode 100644 kernel/kstate/kstate-x86_32.c
arch/x86/include/asm/unistd_32.h +2 -0
@@ -340,6 +340,8 @@#define __NR_inotify_init1 332#define __NR_preadv 333#define __NR_pwritev 334 +#define __NR_checkpoint 335 +#define __NR_restart 336#ifdef __KERNEL__
arch/x86/kernel/syscall_table_32.S +2 -0
@@ -334,3 +334,5 @@ ENTRY(sys_call_table) .long sys_inotify_init1 .long sys_preadv .long sys_pwritev + .long sys_checkpoint /* 335 */ + .long sys_restart
include/linux/kstate-image.h +30 -0
@@ -27,6 +27,7 @@ struct kstate_image_header {/* Mutable part. */ /* Arch of the kernel which dumped the image. */ +#define KSTATE_ARCH_I386 1__le32 kernel_arch;/* * Distributions are expected to leave image version alone and
@@ -70,6 +71,35 @@ struct kstate_image_task_struct {__u32 tsk_arch; } __packed; +#define KSTATE_SEG_NULL 0 +#define KSTATE_SEG_USER32_CS 1 +#define KSTATE_SEG_USER32_DS 2 +#define KSTATE_SEG_TLS 0x4000/* 0100 0000 0000 00xx */ +#define KSTATE_SEG_LDT 0x8000/* 100x xxxx xxxx xxxx */ + +struct kstate_image_task_struct_i386 { +__u32 ebx; +__u32 ecx; +__u32 edx; +__u32 esi; +__u32 edi; +__u32 ebp; +__u32 eax; +__u32 orig_eax; +__u32 eip; +__u32 eflags; +__u32 esp; + +__u16 cs; +__u16 ds; +__u16 es; +__u16 fs; +__u16 gs; +__u16 ss; + +__u64 tls_array[3 ]; +} __packed; +struct kstate_image_mm_struct {struct kstate_object_header hdr;
include/linux/kstate.h +1 -1
@@ -67,7 +67,7 @@ int kstate_collect_all_file(struct kstate_context *ctx);int kstate_dump_all_file (struct kstate_context *ctx);int kstate_restore_file (struct kstate_context *ctx,kstate_ref_t *ref); -#if 0 +#if defined(CONFIG_X86_32 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/Makefile +1 -0
@@ -6,3 +6,4 @@ kstate-y += kstate-image.o kstate-y += kstate-mm.o kstate-y += kstate-object.o kstate-y += kstate-task.o +kstate-$(CONFIG_X86_32) += kstate-x86_32.o
kernel/kstate/kstate-x86_32.c new file +294 -0
294 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 21/38 C/R: i386 debug registers
In reply to a message not in the archiveMake extensive checks to not allow restoration of breakpoints inside kernel code.
--- arch/x86/include/asm/ptrace.h | 5 +++++ arch/x86/kernel/ptrace.c | 8 ++++---- include/linux/kstate-image.h | 7 +++++++ kernel/kstate/kstate-x86_32.c | 26 ++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 8 deletions(-)
arch/x86/include/asm/ptrace.h +5 -0
@@ -243,6 +243,11 @@ extern void x86_ptrace_fork(struct task_struct *child,#define arch_ptrace_untrace (tsk) x86_ptrace_untrace(tsk)#define arch_ptrace_fork (child, flags) x86_ptrace_fork(child, flags) +extern int ptrace_check_debugreg (int _32bit, +unsigned long dr0,unsigned long dr1, +unsigned long dr2,unsigned long dr3, +unsigned long dr6,unsigned long dr7); +#endif /* __KERNEL__ */ #endif /* !__ASSEMBLY__ */
arch/x86/kernel/ptrace.c +4 -4
@@ -465,10 +465,10 @@ static unsigned long ptrace_get_debugreg(struct task_struct *child, int n)return 0 ; } -static int ptrace_check_debugreg (int _32bit, -unsigned long dr0,unsigned long dr1, -unsigned long dr2,unsigned long dr3, -unsigned long dr6,unsigned long dr7) +int ptrace_check_debugreg (int _32bit, +unsigned long dr0,unsigned long dr1, +unsigned long dr2,unsigned long dr3, +unsigned long dr6,unsigned long dr7) {/* Breakpoint type: 00: --x, 01: -w-, 10: undefined, 11: rw- */ unsigned int rw[4 ];
include/linux/kstate-image.h +7 -0
@@ -97,6 +97,13 @@ struct kstate_image_task_struct_i386 {__u16 gs;__u16 ss; +__u32 dr0; +__u32 dr1; +__u32 dr2; +__u32 dr3; +__u32 dr6; +__u32 dr7; +__u64 tls_array[3 ]; } __packed;
kernel/kstate/kstate-x86_32.c +22 -4
@@ -106,6 +106,10 @@ int kstate_arch_check_image_task_struct(struct kstate_image_task_struct *tsk_i)if (rv <0 )return rv; + rv =ptrace_check_debugreg (1 , i->dr0, i->dr1, i->dr2, i->dr3, i->dr6, i->dr7); +if (rv <0 ) +return rv; +if (i->tls_array[0 ]) { rv =check_tls ((struct desc_struct *)&i->tls_array[0 ]);if (rv <0 )
@@ -138,10 +142,6 @@ int kstate_arch_check_task_struct(struct task_struct *tsk)WARN_ON (1 );return -EINVAL ; } -if (test_tsk_thread_flag (tsk,TIF_DEBUG )) { -WARN_ON (1 ); -return -EINVAL ; - } rb = &task_thread_info (tsk)->restart_block;if (rb->fn !=current_thread_info ()->restart_block.fn) {WARN (1 ,"rb->fn = %pF\n" , rb->fn);
@@ -226,6 +226,13 @@ int kstate_arch_dump_task_struct(struct kstate_context *ctx, struct task_struct i->gs =encode_segment (tsk->thread.gs); i->ss =encode_segment (regs->ss); + i->dr0 = tsk->thread.debugreg0; + i->dr1 = tsk->thread.debugreg1; + i->dr2 = tsk->thread.debugreg2; + i->dr3 = tsk->thread.debugreg3; + i->dr6 = tsk->thread.debugreg6; + i->dr7 = tsk->thread.debugreg7; +BUILD_BUG_ON (sizeof (tsk->thread.tls_array[0 ]) !=8 );BUILD_BUG_ON (sizeof (tsk->thread.tls_array) !=3 *8 );memcpy (i->tls_array, tsk->thread.tls_array,sizeof (i->tls_array));
@@ -261,6 +268,17 @@ static int restore_task_struct_i386(struct task_struct *tsk, struct kstate_image tsk->thread.gs =decode_segment (i->gs); regs->ss =decode_segment (i->ss); + tsk->thread.debugreg0 = i->dr0; + tsk->thread.debugreg1 = i->dr1; + tsk->thread.debugreg2 = i->dr2; + tsk->thread.debugreg3 = i->dr3; + tsk->thread.debugreg6 = i->dr6; + tsk->thread.debugreg7 = i->dr7; +if (i->dr7) +set_tsk_thread_flag (tsk,TIF_DEBUG ); +else +clear_tsk_thread_flag (tsk,TIF_DEBUG ); +memcpy (tsk->thread.tls_array, i->tls_array,3 *8 );return 0 ;
Signature · 1 line
1.5.6.5
PATCH 22/38 C/R: i386 xstate
In reply to a message not in the archiveThe only check is if xstate length doesn't match. This is insufficient, but posted anyway, because glibc manages to do FP calculations and create xstate which would prevent checkpointing.
--- include/linux/kstate-image.h | 3 ++ kernel/kstate/kstate-x86_32.c | 44 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-)
include/linux/kstate-image.h +3 -0
@@ -105,6 +105,9 @@ struct kstate_image_task_struct_i386 {__u32 dr7;__u64 tls_array[3 ]; + +__u32 len_xstate; +/* __u8 xstate[len_xstate]; */ } __packed;struct kstate_image_mm_struct {
kernel/kstate/kstate-x86_32.c +39 -5
97 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 23/38 C/R: x86_64 support
In reply to a message not in the archiveIn theory and in practice, x86_64 COMPAT=y kernel will restore i386 images and in other direction. There are small problems still and it doesn't work, but mentioning anyway.
Right now x86_64 kernel restores only x86_64 images and 64-bit tasks.
--- arch/x86/ia32/ia32entry.S | 2 + arch/x86/include/asm/unistd_64.h | 4 + include/linux/kstate-image.h | 36 ++++ include/linux/kstate.h | 2 +- kernel/kstate/Makefile | 1 + kernel/kstate/kstate-x86_64.c | 336 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 380 insertions(+), 1 deletions(-) create mode 100644 kernel/kstate/kstate-x86_64.c
arch/x86/ia32/ia32entry.S +2 -0
@@ -830,4 +830,6 @@ ia32_sys_call_table: .quad sys_inotify_init1 .quad compat_sys_preadv .quad compat_sys_pwritev + .quad sys_checkpoint /* 335 */ + .quad sys_restart ia32_syscall_end:
arch/x86/include/asm/unistd_64.h +4 -0
@@ -657,6 +657,10 @@ __SYSCALL(__NR_inotify_init1, sys_inotify_init1) __SYSCALL(__NR_preadv, sys_preadv)#define __NR_pwritev 296 __SYSCALL(__NR_pwritev, sys_pwritev) +#define __NR_checkpoint 297 +__SYSCALL(__NR_checkpoint, sys_checkpoint) +#define __NR_restart 298 +__SYSCALL(__NR_restart, sys_restart)#ifndef __NO_STUBS
include/linux/kstate-image.h +36 -0
@@ -28,6 +28,7 @@ struct kstate_image_header {/* Mutable part. */ /* Arch of the kernel which dumped the image. */ #define KSTATE_ARCH_I386 1 +#define KSTATE_ARCH_X86_64 2__le32 kernel_arch;/* * Distributions are expected to leave image version alone and
@@ -74,6 +75,8 @@ struct kstate_image_task_struct {#define KSTATE_SEG_NULL 0#define KSTATE_SEG_USER32_CS 1#define KSTATE_SEG_USER32_DS 2 +#define KSTATE_SEG_USER64_CS 3 +#define KSTATE_SEG_USER64_DS 4#define KSTATE_SEG_TLS 0x4000/* 0100 0000 0000 00xx */ #define KSTATE_SEG_LDT 0x8000/* 100x xxxx xxxx xxxx */
@@ -110,6 +113,39 @@ struct kstate_image_task_struct_i386 {/* __u8 xstate[len_xstate]; */ } __packed; +struct kstate_image_task_struct_x86_64 { +__u64 r15; +__u64 r14; +__u64 r13; +__u64 r12; +__u64 rbp; +__u64 rbx; +__u64 r11; +__u64 r10; +__u64 r9; +__u64 r8; +__u64 rax; +__u64 rcx; +__u64 rdx; +__u64 rsi; +__u64 rdi; +__u64 orig_rax; +__u64 rip; +__u64 rflags; +__u64 rsp; + +__u64 fs; +__u64 gs; +__u16 cs; +__u16 ds; +__u16 es; +__u16 fsindex; +__u16 gsindex; +__u16 ss; + +__u64 tls_array[3 ]; +} __packed; +struct kstate_image_mm_struct {struct kstate_object_header hdr;
include/linux/kstate.h +1 -1
@@ -67,7 +67,7 @@ int kstate_collect_all_file(struct kstate_context *ctx);int kstate_dump_all_file (struct kstate_context *ctx);int kstate_restore_file (struct kstate_context *ctx,kstate_ref_t *ref); -#if defined(CONFIG_X86_32 ) +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/Makefile +1 -0
@@ -7,3 +7,4 @@ kstate-y += kstate-mm.o kstate-y += kstate-object.o kstate-y += kstate-task.o kstate-$(CONFIG_X86_32) += kstate-x86_32.o +kstate-$(CONFIG_X86_64) += kstate-x86_64.o
kernel/kstate/kstate-x86_64.c new file +336 -0
336 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 24/38 C/R: x86_64 debug registers
In reply to a message not in the archive--- include/linux/kstate-image.h | 7 +++++++ kernel/kstate/kstate-x86_64.c | 26 ++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-)
include/linux/kstate-image.h +7 -0
@@ -143,6 +143,13 @@ struct kstate_image_task_struct_x86_64 {__u16 gsindex;__u16 ss; +__u64 dr0; +__u64 dr1; +__u64 dr2; +__u64 dr3; +__u64 dr6; +__u64 dr7; +__u64 tls_array[3 ]; } __packed;
kernel/kstate/kstate-x86_64.c +22 -4
@@ -109,6 +109,10 @@ static int check_image_task_struct_x86_64(struct kstate_image_task_struct *tsk_iif (rv <0 )return rv; + rv =ptrace_check_debugreg (0 , i->dr0, i->dr1, i->dr2, i->dr3, i->dr6, i->dr7); +if (rv <0 ) +return rv; +if (i->tls_array[0 ]) { rv =check_tls ((struct desc_struct *)&i->tls_array[0 ]);if (rv <0 )
@@ -150,10 +154,6 @@ int kstate_arch_check_task_struct(struct task_struct *tsk) return -EINVAL; }#endif -if (test_tsk_thread_flag (tsk,TIF_DEBUG )) { -WARN_ON (1 ); -return -EINVAL ; - }if (tsk->thread.xstate) {WARN_ON (1 );return -EINVAL ;
@@ -250,6 +250,13 @@ static int dump_task_struct_x86_64(struct kstate_context *ctx, struct task_struc i->gsindex =encode_segment (tsk->thread.gsindex); i->ss =encode_segment (regs->ss); + i->dr0 = tsk->thread.debugreg0; + i->dr1 = tsk->thread.debugreg1; + i->dr2 = tsk->thread.debugreg2; + i->dr3 = tsk->thread.debugreg3; + i->dr6 = tsk->thread.debugreg6; + i->dr7 = tsk->thread.debugreg7; +BUILD_BUG_ON (sizeof (tsk->thread.tls_array[0 ]) !=8 );BUILD_BUG_ON (sizeof (tsk->thread.tls_array) !=3 *8 );memcpy (i->tls_array, tsk->thread.tls_array,sizeof (i->tls_array));
@@ -299,6 +306,17 @@ static int restore_task_struct_x86_64(struct task_struct *tsk, struct kstate_ima tsk->thread.gsindex =decode_segment (i->gsindex); regs->ss =decode_segment (i->ss); + tsk->thread.debugreg0 = i->dr0; + tsk->thread.debugreg1 = i->dr1; + tsk->thread.debugreg2 = i->dr2; + tsk->thread.debugreg3 = i->dr3; + tsk->thread.debugreg6 = i->dr6; + tsk->thread.debugreg7 = i->dr7; +if (i->dr7) +set_tsk_thread_flag (tsk,TIF_DEBUG ); +else +clear_tsk_thread_flag (tsk,TIF_DEBUG ); +memcpy (tsk->thread.tls_array, i->tls_array,sizeof (i->tls_array));set_tsk_thread_flag (tsk,TIF_FORK );
Signature · 1 line
1.5.6.5
PATCH 25/38 C/R: x86_64 xstate
In reply to a message not in the archiveAgain, checks aren't enough on all counts.
--- include/linux/kstate-image.h | 3 ++ kernel/kstate/kstate-x86_64.c | 44 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-)
include/linux/kstate-image.h +3 -0
@@ -151,6 +151,9 @@ struct kstate_image_task_struct_x86_64 {__u64 dr7;__u64 tls_array[3 ]; + +__u8 len_xstate; +/* __u8 xstate[len_xstate]; */ } __packed;struct kstate_image_mm_struct {
kernel/kstate/kstate-x86_64.c +39 -5
98 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 26/38 C/R: nsproxy
In reply to a message not in the archiveIt can't be argued, that nsproxy shouldn't even be dumped, because pointers inside nsproxy are interesting. This is correct, however this creates addtitional code on restart and frankly more that several nsproxies are rare, so nobody cares.
Current algorithm is simplest:
- dump all namespaces
- dump nsproxy as KSTATE_OBJ_NSPROXY type filled with references
- on restore, read reference, read and restore namespace if needed, bump refcount, glue namespace to nsproxy.
--- include/linux/kstate-image.h | 6 ++ include/linux/kstate.h | 5 ++ kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 6 ++ kernel/kstate/kstate-object.c | 4 + kernel/kstate/kstate-task.c | 26 ++++++++ kernel/nsproxy.c | 129 +++++++++++++++++++++++++++++++++++++++- 7 files changed, 181 insertions(+), 1 deletions(-) create mode 100644 kernel/kstate/kstate-nsproxy.c
include/linux/kstate-image.h +6 -0
@@ -43,6 +43,7 @@ struct kstate_image_header {#define KSTATE_OBJ_FILE 3#define KSTATE_OBJ_VMA 4#define KSTATE_OBJ_PAGE 5 +#define KSTATE_OBJ_NSPROXY 6struct kstate_object_header {__u32 obj_type;
@@ -65,6 +66,7 @@ struct kstate_image_task_struct {kstate_ref_t ref_real_parent;kstate_ref_t ref_mm; +kstate_ref_t ref_nsproxy;__u8 comm[16 ];
@@ -203,4 +205,8 @@ struct kstate_image_file {__u32 name_len;/* including NUL */ /* __u8 name[name_len] */ } __packed; + +struct kstate_image_nsproxy { +struct kstate_object_header hdr; +} __packed;#endif
include/linux/kstate.h +5 -0
@@ -23,6 +23,7 @@ struct kstate_object {enum kstate_context_obj_type {KSTATE_CTX_FILE ,KSTATE_CTX_MM_STRUCT , +KSTATE_CTX_NSPROXY ,KSTATE_CTX_TASK_STRUCT ,NR_KSTATE_CTX_TYPES };
@@ -67,6 +68,10 @@ int kstate_collect_all_file(struct kstate_context *ctx);int kstate_dump_all_file (struct kstate_context *ctx);int kstate_restore_file (struct kstate_context *ctx,kstate_ref_t *ref); +int kstate_collect_all_nsproxy (struct kstate_context *ctx); +int kstate_dump_all_nsproxy (struct kstate_context *ctx); +int kstate_restore_nsproxy (struct kstate_context *ctx,kstate_ref_t *ref); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
@@ -65,6 +65,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_task_struct (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_nsproxy (ctx); +if (rv <0 ) +return rv; rv =kstate_collect_all_mm_struct (ctx);if (rv <0 )return rv;
@@ -127,6 +130,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_mm_struct (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_nsproxy (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_task_struct (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +6 -0
@@ -1,6 +1,7 @@/* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */ #include <linux/file.h> #include <linux/list.h> +#include <linux/nsproxy.h> #include <linux/sched.h> #include <linux/slab.h>
@@ -40,6 +41,11 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_NSPROXY ) { +put_nsproxy ((struct nsproxy *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_TASK_STRUCT ) {put_task_struct ((struct task_struct *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-nsproxy.c new file +0 -0
kernel/kstate/kstate-object.c +4 -0
@@ -1,6 +1,7 @@/* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */ #include <linux/fs.h> #include <linux/mm_types.h> +#include <linux/nsproxy.h> #include <linux/sched.h> #include <linux/slab.h>
@@ -35,6 +36,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_MM_STRUCT :atomic_inc (&((struct mm_struct *)obj->o_obj)->mm_users);break ; +case KSTATE_CTX_NSPROXY : +get_nsproxy ((struct nsproxy *)obj->o_obj); +break ;case KSTATE_CTX_TASK_STRUCT :get_task_struct ((struct task_struct *)obj->o_obj);break ;
kernel/kstate/kstate-task.c +26 -0
@@ -120,6 +120,9 @@ static int dump_task_struct(struct kstate_context *ctx, struct kstate_object *ob tmp =find_kstate_obj_by_ptr (ctx, tsk->mm,KSTATE_CTX_MM_STRUCT ); i->ref_mm = tmp->o_ref; + tmp =find_kstate_obj_by_ptr (ctx, tsk->nsproxy,KSTATE_CTX_NSPROXY ); + i->ref_nsproxy = tmp->o_ref; +BUILD_BUG_ON (sizeof (i->comm) !=sizeof (tsk->comm));strlcpy ((char *)i->comm, (const char *)tsk->comm,sizeof (i->comm));
@@ -208,6 +211,26 @@ static int restore_mm(struct kstate_context *ctx, kstate_ref_t *ref)return 0 ; } +static int restore_nsproxy (struct kstate_context *ctx,kstate_ref_t *ref) +{ +struct nsproxy *nsproxy; +struct kstate_object *tmp; +int rv; + + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_NSPROXY ); +if (!tmp) { + rv =kstate_restore_nsproxy (ctx, ref); +if (rv <0 ) +return rv; + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_NSPROXY ); + } + nsproxy = tmp->o_obj; + +get_nsproxy (nsproxy); +switch_task_namespaces (current, nsproxy); +return 0 ; +} +struct task_struct_restore_context {struct kstate_context *ctx;struct kstate_image_task_struct *i;
@@ -253,6 +276,9 @@ static int task_struct_restorer(void *_tsk_ctx) rv =restore_mm (ctx, &i->ref_mm);if (rv <0 ) goto out; + rv =restore_nsproxy (ctx, &i->ref_nsproxy); +if (rv <0 ) + goto out; out: tsk_ctx->rv = rv;
kernel/nsproxy.c +128 -1
143 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 27/38 C/R: checkpoint/restore struct uts_namespace
In reply to a message not in the archiveThe simplest thing.
Note, no locking is done, because we know:
a) tasks are frozen and thus can't change it
b) number of collected references is correct, so nobody else is using uts_namespace and thus can't change it under dump
If live checkpointing will be done, code will be changed to something like:
if (ctx->dump_live) down_read(&uts_sem); ... if (ctx->dump_live) up_read(&uts_sem);
--- include/linux/kstate-image.h | 14 +++++ include/linux/kstate.h | 5 ++ kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 6 ++ kernel/kstate/kstate-object.c | 4 ++ kernel/nsproxy.c | 33 +++++++++++-- kernel/utsname.c | 106 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 170 insertions(+), 4 deletions(-) delete mode 100644 kernel/kstate/kstate-nsproxy.c create mode 100644 kernel/kstate/kstate-uts_ns.c
include/linux/kstate-image.h +14 -0
@@ -44,6 +44,7 @@ struct kstate_image_header {#define KSTATE_OBJ_VMA 4#define KSTATE_OBJ_PAGE 5#define KSTATE_OBJ_NSPROXY 6 +#define KSTATE_OBJ_UTS_NS 7struct kstate_object_header {__u32 obj_type;
@@ -208,5 +209,18 @@ struct kstate_image_file {struct kstate_image_nsproxy {struct kstate_object_header hdr; + +kstate_ref_t ref_uts_ns; +} __packed; + +struct kstate_image_uts_ns { +struct kstate_object_header hdr; + +__u8 sysname[64 ]; +__u8 nodename[64 ]; +__u8 release[64 ]; +__u8 version[64 ]; +__u8 machine[64 ]; +__u8 domainname[64 ]; } __packed;#endif
include/linux/kstate.h +5 -0
@@ -25,6 +25,7 @@ enum kstate_context_obj_type {KSTATE_CTX_MM_STRUCT ,KSTATE_CTX_NSPROXY ,KSTATE_CTX_TASK_STRUCT , +KSTATE_CTX_UTS_NS , NR_KSTATE_CTX_TYPES };
@@ -72,6 +73,10 @@ int kstate_collect_all_nsproxy(struct kstate_context *ctx);int kstate_dump_all_nsproxy (struct kstate_context *ctx);int kstate_restore_nsproxy (struct kstate_context *ctx,kstate_ref_t *ref); +int kstate_collect_all_uts_ns (struct kstate_context *ctx); +int kstate_dump_all_uts_ns (struct kstate_context *ctx); +int kstate_restore_uts_ns (struct kstate_context *ctx,kstate_ref_t *ref); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
@@ -68,6 +68,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_nsproxy (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_uts_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_collect_all_mm_struct (ctx);if (rv <0 )return rv;
@@ -130,6 +133,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_mm_struct (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_uts_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_nsproxy (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +6 -0
@@ -4,6 +4,7 @@#include <linux/nsproxy.h> #include <linux/sched.h> #include <linux/slab.h> +#include <linux/utsname.h> #include <linux/kstate.h>
@@ -51,5 +52,10 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_UTS_NS ) { +put_uts_ns ((struct uts_namespace *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }kfree (ctx); }
kernel/kstate/kstate-nsproxy.c deleted +0 -0
kernel/kstate/kstate-object.c +4 -0
@@ -4,6 +4,7 @@#include <linux/nsproxy.h> #include <linux/sched.h> #include <linux/slab.h> +#include <linux/utsname.h> #include <linux/kstate.h> #include <linux/kstate-image.h>
@@ -42,6 +43,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_TASK_STRUCT :get_task_struct ((struct task_struct *)obj->o_obj);break ; +case KSTATE_CTX_UTS_NS : +get_uts_ns ((struct uts_namespace *)obj->o_obj); +break ;default :BUG (); }
kernel/kstate/kstate-uts_ns.c new file +0 -0
kernel/nsproxy.c +29 -4
@@ -271,12 +271,16 @@ static int dump_nsproxy(struct kstate_context *ctx, struct kstate_object *obj) {struct nsproxy *nsproxy = obj->o_obj;struct kstate_image_nsproxy *i; +struct kstate_object *tmp;int rv; i =kstate_prepare_image (KSTATE_OBJ_NSPROXY ,sizeof (*i));if (!i)return -ENOMEM ; + tmp =find_kstate_obj_by_ptr (ctx, nsproxy->uts_ns,KSTATE_CTX_UTS_NS ); + i->ref_uts_ns = tmp->o_ref; + rv =kstate_write_image (ctx, i,sizeof (*i), obj);kfree (i);pr_debug ("dump nsproxy %p: ref {%llu, %u}, rv %d\n" , nsproxy, (unsigned long long )obj->o_ref.pos, obj->o_ref.id, rv);
@@ -296,11 +300,30 @@ int kstate_dump_all_nsproxy(struct kstate_context *ctx)return 0 ; } +static int restore_uts_ns (struct kstate_context *ctx,kstate_ref_t *ref,struct nsproxy *nsproxy) +{ +struct uts_namespace *uts_ns; +struct kstate_object *tmp; +int rv; + + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_UTS_NS ); +if (!tmp) { + rv =kstate_restore_uts_ns (ctx, ref); +if (rv <0 ) +return rv; + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_UTS_NS ); + } + uts_ns = tmp->o_obj; + +get_uts_ns (uts_ns); + nsproxy->uts_ns = uts_ns; +return 0 ; +} +int kstate_restore_nsproxy (struct kstate_context *ctx,kstate_ref_t *ref) {struct kstate_image_nsproxy *i;struct nsproxy *nsproxy; -struct uts_namespace *uts_ns;#ifdef CONFIG_IPC_NS struct ipc_namespace *ipc_ns;#endif
@@ -321,9 +344,9 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref) goto out_free_image; } - uts_ns = ctx->init_tsk->nsproxy->uts_ns; -get_uts_ns (uts_ns); - nsproxy->uts_ns = uts_ns; + rv =restore_uts_ns (ctx, &i->ref_uts_ns, nsproxy); +if (rv <0 ) + goto out_uts_ns;#ifdef CONFIG_IPC_NS ipc_ns = ctx->init_tsk->nsproxy->ipc_ns;
@@ -349,6 +372,8 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref)pr_debug ("restore nsproxy %p, ref {%llu, %u}, rv %d\n" , nsproxy, (unsigned long long )ref->pos, ref->id, rv);return rv; +out_uts_ns: +kmem_cache_free (nsproxy_cachep, nsproxy); out_free_image:kfree (i);pr_debug ("%s: return %d, ref {%llu, %u}\n" , __func__, rv, (unsigned long long )ref->pos, ref->id);
kernel/utsname.c +106 -0
114 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 28/38 C/R: formally checkpoint/restore struct ipc_namespace
In reply to a message not in the archiveNo IPC objects are done yet, only struct ipc_namespace itself and tsk->nsproxy->ipc_ns skeleton.
--- include/linux/ipc_namespace.h | 3 + include/linux/kstate-image.h | 6 ++ include/linux/kstate.h | 19 ++++++++ ipc/namespace.c | 101 +++++++++++++++++++++++++++++++++++++++- kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 8 +++ kernel/kstate/kstate-object.c | 6 ++ kernel/nsproxy.c | 66 +++++++++++++++++++++++--- 8 files changed, 206 insertions(+), 9 deletions(-)
include/linux/ipc_namespace.h +3 -0
@@ -94,6 +94,7 @@ static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }#endif #if defined(CONFIG_IPC_NS ) +extern struct ipc_namespace *create_ipc_ns (void );extern struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns);static inline struct ipc_namespace *get_ipc_ns (struct ipc_namespace *ns)
@@ -105,6 +106,8 @@ static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)extern void put_ipc_ns (struct ipc_namespace *ns);#else +#include <linux/sched.h> +static inline struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns) {
include/linux/kstate-image.h +6 -0
@@ -45,6 +45,7 @@ struct kstate_image_header {#define KSTATE_OBJ_PAGE 5#define KSTATE_OBJ_NSPROXY 6#define KSTATE_OBJ_UTS_NS 7 +#define KSTATE_OBJ_IPC_NS 8struct kstate_object_header {__u32 obj_type;
@@ -211,6 +212,7 @@ struct kstate_image_nsproxy {struct kstate_object_header hdr;kstate_ref_t ref_uts_ns; +kstate_ref_t ref_ipc_ns;/* KSTATE_REF_UNDEF if IPC_NS=n */ } __packed;struct kstate_image_uts_ns {
@@ -223,4 +225,8 @@ struct kstate_image_uts_ns {__u8 machine[64 ]; __u8 domainname[64]; } __packed; + +struct kstate_image_ipc_ns { +struct kstate_object_header hdr; +} __packed;#endif
include/linux/kstate.h +19 -0
@@ -22,6 +22,9 @@ struct kstate_object {/* Not visible to userspace! */ enum kstate_context_obj_type {KSTATE_CTX_FILE , +#ifdef CONFIG_IPC_NS +KSTATE_CTX_IPC_NS , +#endif KSTATE_CTX_MM_STRUCT ,KSTATE_CTX_NSPROXY ,KSTATE_CTX_TASK_STRUCT ,
@@ -77,6 +80,22 @@ int kstate_collect_all_uts_ns(struct kstate_context *ctx);int kstate_dump_all_uts_ns (struct kstate_context *ctx);int kstate_restore_uts_ns (struct kstate_context *ctx,kstate_ref_t *ref); +#ifdef CONFIG_IPC_NS +int kstate_collect_all_ipc_ns (struct kstate_context *ctx); +int kstate_dump_all_ipc_ns (struct kstate_context *ctx); +int kstate_restore_ipc_ns (struct kstate_context *ctx,kstate_ref_t *ref); +#else +static inline int kstate_collect_all_ipc_ns (struct kstate_context *ctx) +{ +return 0 ; +} + +static inline int kstate_dump_all_ipc_ns (struct kstate_context *ctx) +{ +return 0 ; +} +#endif +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
ipc/namespace.c +100 -1
116 lines not on this page · raw message
kernel/kstate/cpt-sys.c +6 -0
@@ -71,6 +71,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_uts_ns (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_ipc_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_collect_all_mm_struct (ctx);if (rv <0 )return rv;
@@ -133,6 +136,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_mm_struct (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_ipc_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_uts_ns (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +8 -0
@@ -1,5 +1,6 @@/* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */ #include <linux/file.h> +#include <linux/ipc_namespace.h> #include <linux/list.h> #include <linux/nsproxy.h> #include <linux/sched.h>
@@ -37,6 +38,13 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +#ifdef CONFIG_IPC_NS +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_IPC_NS ) { +put_ipc_ns ((struct ipc_namespace *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + } +#endif for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_MM_STRUCT ) {mmput ((struct mm_struct *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-object.c +6 -0
@@ -1,5 +1,6 @@/* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */ #include <linux/fs.h> +#include <linux/ipc_namespace.h> #include <linux/mm_types.h> #include <linux/nsproxy.h> #include <linux/sched.h>
@@ -34,6 +35,11 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_FILE :get_file ((struct file *)obj->o_obj);break ; +#ifdef CONFIG_IPC_NS +case KSTATE_CTX_IPC_NS : +get_ipc_ns ((struct ipc_namespace *)obj->o_obj); +break ; +#endif case KSTATE_CTX_MM_STRUCT :atomic_inc (&((struct mm_struct *)obj->o_obj)->mm_users);break ;
kernel/nsproxy.c +58 -8
94 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 29/38 C/R: formally checkpoint/restore struct mnt_namespace
In reply to a message not in the archive--- fs/namespace.c | 70 ++++++++++++++++++++++++++++++++++++++++ include/linux/kstate-image.h | 6 +++ include/linux/kstate.h | 4 ++ kernel/kstate/cpt-sys.c | 6 +++ kernel/kstate/kstate-context.c | 6 +++ kernel/kstate/kstate-object.c | 4 ++ kernel/nsproxy.c | 24 +++++++++++--- 7 files changed, 115 insertions(+), 5 deletions(-)
fs/namespace.c +70 -0
@@ -3,6 +3,7 @@* * (C) Copyright Al Viro 2000, 2001 * Released under GPL v2. +* Copyright (C) 2000-2009 Parallels Holdings, Ltd. * * Based on code from fs/super.c, copyright Linus Torvalds and others. * Heavily rewritten.
@@ -2309,3 +2310,72 @@ void __put_mnt_ns(struct mnt_namespace *ns)release_mounts (&umount_list);kfree (ns); } + +#ifdef CONFIG_CHECKPOINT +#include <linux/kstate.h> +#include <linux/kstate-image.h> + +static int collect_mnt_ns (struct kstate_context *ctx,struct mnt_namespace *mnt_ns) +{ +int rv; + + rv =kstate_collect_object (ctx, mnt_ns,KSTATE_CTX_MNT_NS ); +pr_debug ("collect mnt_ns %p: rv %d\n" , mnt_ns, rv); +return rv; +} + +int kstate_collect_all_mnt_ns (struct kstate_context *ctx) +{ +struct kstate_object *obj; +int rv; + +for_each_kstate_object (ctx, obj,KSTATE_CTX_NSPROXY ) { +struct nsproxy *nsproxy = obj->o_obj; + + rv =collect_mnt_ns (ctx, nsproxy->mnt_ns); +if (rv <0 ) +return rv; + } +for_each_kstate_object (ctx, obj,KSTATE_CTX_MNT_NS ) { +struct mnt_namespace *mnt_ns = obj->o_obj; +unsigned int cnt =atomic_read (&mnt_ns->count); + +if (obj->o_count +1 != cnt) { +pr_err ("mnt_ns %p has external references %lu:%u\n" , mnt_ns, obj->o_count, cnt); +return -EINVAL ; + } + } +return 0 ; +} + +static int dump_mnt_ns (struct kstate_context *ctx,struct kstate_object *obj) +{ +struct mnt_namespace *mnt_ns = obj->o_obj; +struct kstate_image_mnt_ns *i; +int rv; + + i =kstate_prepare_image (KSTATE_OBJ_MNT_NS ,sizeof (*i)); +if (!i) +return -ENOMEM ; + + rv =kstate_write_image (ctx, i,sizeof (*i), obj); +kfree (i); +pr_debug ("dump mnt_ns %p: ref {%llu, %u}, rv %d\n" , mnt_ns, (unsigned long long )obj->o_ref.pos, obj->o_ref.id, rv); +return rv; +} + +int kstate_dump_all_mnt_ns (struct kstate_context *ctx) +{ +struct kstate_object *obj; +int rv; + +for_each_kstate_object (ctx, obj,KSTATE_CTX_MNT_NS ) { + rv =dump_mnt_ns (ctx, obj); +if (rv <0 ) +return rv; + } +return 0 ; +} + +/* FIXME kstate_restore_mnt_ns() */ +#endif
include/linux/kstate-image.h +6 -0
@@ -46,6 +46,7 @@ struct kstate_image_header {#define KSTATE_OBJ_NSPROXY 6#define KSTATE_OBJ_UTS_NS 7#define KSTATE_OBJ_IPC_NS 8 +#define KSTATE_OBJ_MNT_NS 9struct kstate_object_header {__u32 obj_type;
@@ -213,6 +214,7 @@ struct kstate_image_nsproxy {kstate_ref_t ref_uts_ns;kstate_ref_t ref_ipc_ns;/* KSTATE_REF_UNDEF if IPC_NS=n */ +kstate_ref_t ref_mnt_ns; } __packed;struct kstate_image_uts_ns {
@@ -229,4 +231,8 @@ struct kstate_image_uts_ns {struct kstate_image_ipc_ns {struct kstate_object_header hdr; } __packed; + +struct kstate_image_mnt_ns { +struct kstate_object_header hdr; +} __packed;#endif
include/linux/kstate.h +4 -0
@@ -26,6 +26,7 @@ enum kstate_context_obj_type {KSTATE_CTX_IPC_NS , #endifKSTATE_CTX_MM_STRUCT , +KSTATE_CTX_MNT_NS ,KSTATE_CTX_NSPROXY ,KSTATE_CTX_TASK_STRUCT , KSTATE_CTX_UTS_NS,
@@ -96,6 +97,9 @@ static inline int kstate_dump_all_ipc_ns(struct kstate_context *ctx) }#endif +int kstate_collect_all_mnt_ns (struct kstate_context *ctx); +int kstate_dump_all_mnt_ns (struct kstate_context *ctx); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
@@ -74,6 +74,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_ipc_ns (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_mnt_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_collect_all_mm_struct (ctx);if (rv <0 )return rv;
@@ -136,6 +139,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_mm_struct (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_mnt_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_ipc_ns (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +6 -0
@@ -2,6 +2,7 @@#include <linux/file.h> #include <linux/ipc_namespace.h> #include <linux/list.h> +#include <linux/mnt_namespace.h> #include <linux/nsproxy.h> #include <linux/sched.h> #include <linux/slab.h>
@@ -50,6 +51,11 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_MNT_NS ) { +put_mnt_ns ((struct mnt_namespace *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_NSPROXY ) {put_nsproxy ((struct nsproxy *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-object.c +4 -0
@@ -2,6 +2,7 @@#include <linux/fs.h> #include <linux/ipc_namespace.h> #include <linux/mm_types.h> +#include <linux/mnt_namespace.h> #include <linux/nsproxy.h> #include <linux/sched.h> #include <linux/slab.h>
@@ -43,6 +44,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_MM_STRUCT :atomic_inc (&((struct mm_struct *)obj->o_obj)->mm_users);break ; +case KSTATE_CTX_MNT_NS : +get_mnt_ns ((struct mnt_namespace *)obj->o_obj); +break ;case KSTATE_CTX_NSPROXY :get_nsproxy ((struct nsproxy *)obj->o_obj);break ;
kernel/nsproxy.c +19 -5
@@ -286,6 +286,8 @@ static int dump_nsproxy(struct kstate_context *ctx, struct kstate_object *obj)#else i->ref_ipc_ns =KSTATE_REF_UNDEF ;#endif + tmp =find_kstate_obj_by_ptr (ctx, nsproxy->mnt_ns,KSTATE_CTX_MNT_NS ); + i->ref_mnt_ns = tmp->o_ref; rv =kstate_write_image (ctx, i,sizeof (*i), obj);kfree (i);
@@ -373,11 +375,22 @@ static int restore_ipc_ns(struct kstate_context *ctx, kstate_ref_t *ref, struct }#endif +static int restore_mnt_ns (struct kstate_context *ctx,kstate_ref_t *ref,struct nsproxy *nsproxy) +{ +struct mnt_namespace *mnt_ns; + +/* FIXME */ + mnt_ns = ctx->init_tsk->nsproxy->mnt_ns; + +get_mnt_ns (mnt_ns); + nsproxy->mnt_ns = mnt_ns; +return 0 ; +} +int kstate_restore_nsproxy (struct kstate_context *ctx,kstate_ref_t *ref) {struct kstate_image_nsproxy *i;struct nsproxy *nsproxy; -struct mnt_namespace *mnt_ns;struct pid_namespace *pid_ns;#ifdef CONFIG_NET_NS struct net *net_ns;
@@ -400,10 +413,9 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref) rv =restore_ipc_ns (ctx, &i->ref_ipc_ns, nsproxy);if (rv <0 ) goto out_ipc_ns; - - mnt_ns = ctx->init_tsk->nsproxy->mnt_ns; -get_mnt_ns (mnt_ns); - nsproxy->mnt_ns = mnt_ns; + rv =restore_mnt_ns (ctx, &i->ref_mnt_ns, nsproxy); +if (rv <0 ) + goto out_mnt_ns; pid_ns = ctx->init_tsk->nsproxy->pid_ns; nsproxy->pid_ns =get_pid_ns (pid_ns);
@@ -420,6 +432,8 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref)pr_debug ("restore nsproxy %p, ref {%llu, %u}, rv %d\n" , nsproxy, (unsigned long long )ref->pos, ref->id, rv);return rv; +out_mnt_ns: +put_ipc_ns (nsproxy->ipc_ns); out_ipc_ns:put_uts_ns (nsproxy->uts_ns); out_uts_ns:
Signature · 1 line
1.5.6.5
PATCH 30/38 C/R: checkpoint/restore struct pid_namespace
In reply to a message not in the archivepidns are hierarchical, so we dump parent pidns first. On restore, parent task is restored first and restores parent pidns for itself, which means that when child restores its pidns, parent pidns already exists.
This fullfills loop protection and, given, every pidns has init task which pins it even works reliably. :-)
--- include/linux/kstate-image.h | 9 ++ include/linux/kstate.h | 5 + kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 6 ++ kernel/kstate/kstate-object.c | 4 + kernel/nsproxy.c | 30 ++++++- kernel/pid_namespace.c | 168 +++++++++++++++++++++++++++++++++++++++- 7 files changed, 223 insertions(+), 5 deletions(-)
include/linux/kstate-image.h +9 -0
@@ -47,6 +47,7 @@ struct kstate_image_header {#define KSTATE_OBJ_UTS_NS 7#define KSTATE_OBJ_IPC_NS 8#define KSTATE_OBJ_MNT_NS 9 +#define KSTATE_OBJ_PID_NS 10struct kstate_object_header {__u32 obj_type;
@@ -215,6 +216,7 @@ struct kstate_image_nsproxy {kstate_ref_t ref_uts_ns;kstate_ref_t ref_ipc_ns;/* KSTATE_REF_UNDEF if IPC_NS=n */ kstate_ref_t ref_mnt_ns; +kstate_ref_t ref_pid_ns; } __packed;struct kstate_image_uts_ns {
@@ -235,4 +237,11 @@ struct kstate_image_ipc_ns {struct kstate_image_mnt_ns {struct kstate_object_header hdr; } __packed; + +struct kstate_image_pid_ns { +struct kstate_object_header hdr; + +kstate_ref_t ref_parent;/* KSTATE_REF_UNDEF if root pid_ns */ +__u32 last_pid; +} __packed;#endif
include/linux/kstate.h +5 -0
@@ -28,6 +28,7 @@ enum kstate_context_obj_type {KSTATE_CTX_MM_STRUCT ,KSTATE_CTX_MNT_NS ,KSTATE_CTX_NSPROXY , +KSTATE_CTX_PID_NS ,KSTATE_CTX_TASK_STRUCT ,KSTATE_CTX_UTS_NS ,NR_KSTATE_CTX_TYPES
@@ -100,6 +101,10 @@ static inline int kstate_dump_all_ipc_ns(struct kstate_context *ctx)int kstate_collect_all_mnt_ns (struct kstate_context *ctx);int kstate_dump_all_mnt_ns (struct kstate_context *ctx); +int kstate_collect_all_pid_ns (struct kstate_context *ctx); +int kstate_dump_all_pid_ns (struct kstate_context *ctx); +int kstate_restore_pid_ns (struct kstate_context *ctx,kstate_ref_t *ref); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
@@ -77,6 +77,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_mnt_ns (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_pid_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_collect_all_mm_struct (ctx);if (rv <0 )return rv;
@@ -133,6 +136,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_image_header (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_pid_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_file (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +6 -0
@@ -4,6 +4,7 @@#include <linux/list.h> #include <linux/mnt_namespace.h> #include <linux/nsproxy.h> +#include <linux/pid_namespace.h> #include <linux/sched.h> #include <linux/slab.h> #include <linux/utsname.h>
@@ -61,6 +62,11 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_PID_NS ) { +put_pid_ns ((struct pid_namespace *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_TASK_STRUCT ) {put_task_struct ((struct task_struct *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-object.c +4 -0
@@ -4,6 +4,7 @@#include <linux/mm_types.h> #include <linux/mnt_namespace.h> #include <linux/nsproxy.h> +#include <linux/pid_namespace.h> #include <linux/sched.h> #include <linux/slab.h> #include <linux/utsname.h>
@@ -50,6 +51,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_NSPROXY :get_nsproxy ((struct nsproxy *)obj->o_obj);break ; +case KSTATE_CTX_PID_NS : +get_pid_ns ((struct pid_namespace *)obj->o_obj); +break ;case KSTATE_CTX_TASK_STRUCT :get_task_struct ((struct task_struct *)obj->o_obj);break ;
kernel/nsproxy.c +26 -4
@@ -288,6 +288,8 @@ static int dump_nsproxy(struct kstate_context *ctx, struct kstate_object *obj)#endif tmp =find_kstate_obj_by_ptr (ctx, nsproxy->mnt_ns,KSTATE_CTX_MNT_NS ); i->ref_mnt_ns = tmp->o_ref; + tmp =find_kstate_obj_by_ptr (ctx, nsproxy->pid_ns,KSTATE_CTX_PID_NS ); + i->ref_pid_ns = tmp->o_ref; rv =kstate_write_image (ctx, i,sizeof (*i), obj);kfree (i);
@@ -387,11 +389,29 @@ static int restore_mnt_ns(struct kstate_context *ctx, kstate_ref_t *ref, structreturn 0 ; } +static int restore_pid_ns (struct kstate_context *ctx,kstate_ref_t *ref,struct nsproxy *nsproxy) +{ +struct pid_namespace *pid_ns; +struct kstate_object *tmp; +int rv; + + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_PID_NS ); +if (!tmp) { + rv =kstate_restore_pid_ns (ctx, ref); +if (rv <0 ) +return rv; + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_PID_NS ); + } + pid_ns = tmp->o_obj; + + nsproxy->pid_ns =get_pid_ns (pid_ns); +return 0 ; +} +int kstate_restore_nsproxy (struct kstate_context *ctx,kstate_ref_t *ref) {struct kstate_image_nsproxy *i;struct nsproxy *nsproxy; -struct pid_namespace *pid_ns;#ifdef CONFIG_NET_NS struct net *net_ns;#endif
@@ -416,9 +436,9 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref) rv =restore_mnt_ns (ctx, &i->ref_mnt_ns, nsproxy);if (rv <0 ) goto out_mnt_ns; - - pid_ns = ctx->init_tsk->nsproxy->pid_ns; - nsproxy->pid_ns =get_pid_ns (pid_ns); + rv =restore_pid_ns (ctx, &i->ref_pid_ns, nsproxy); +if (rv <0 ) + goto out_pid_ns;#ifdef CONFIG_NET_NS net_ns = ctx->init_tsk->nsproxy->net_ns;
@@ -432,6 +452,8 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref)pr_debug ("restore nsproxy %p, ref {%llu, %u}, rv %d\n" , nsproxy, (unsigned long long )ref->pos, ref->id, rv);return rv; +out_pid_ns: +put_mnt_ns (nsproxy->mnt_ns); out_mnt_ns:put_ipc_ns (nsproxy->ipc_ns); out_ipc_ns:
kernel/pid_namespace.c +167 -1
181 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 31/38 C/R: formally checkpoint/restore struct net_namespace
In reply to a message not in the archive--- include/linux/kstate-image.h | 6 ++ include/linux/kstate.h | 19 +++++++ include/net/net_namespace.h | 1 + kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 8 +++ kernel/kstate/kstate-object.c | 6 ++ kernel/nsproxy.c | 66 +++++++++++++++++++++++--- net/core/net_namespace.c | 102 +++++++++++++++++++++++++++++++++++++++- 8 files changed, 205 insertions(+), 9 deletions(-)
include/linux/kstate-image.h +6 -0
@@ -48,6 +48,7 @@ struct kstate_image_header {#define KSTATE_OBJ_IPC_NS 8#define KSTATE_OBJ_MNT_NS 9#define KSTATE_OBJ_PID_NS 10 +#define KSTATE_OBJ_NET_NS 11struct kstate_object_header {__u32 obj_type;
@@ -217,6 +218,7 @@ struct kstate_image_nsproxy {kstate_ref_t ref_ipc_ns;/* KSTATE_REF_UNDEF if IPC_NS=n */ kstate_ref_t ref_mnt_ns;kstate_ref_t ref_pid_ns; +kstate_ref_t ref_net_ns;/* KSTATE_REF_UNDEF if NET_NS=n */ } __packed;struct kstate_image_uts_ns {
@@ -244,4 +246,8 @@ struct kstate_image_pid_ns {kstate_ref_t ref_parent;/* KSTATE_REF_UNDEF if root pid_ns */ __u32 last_pid; } __packed; + +struct kstate_image_net_ns { +struct kstate_object_header hdr; +} __packed;#endif
include/linux/kstate.h +19 -0
@@ -27,6 +27,9 @@ enum kstate_context_obj_type {#endif KSTATE_CTX_MM_STRUCT, KSTATE_CTX_MNT_NS, +#ifdef CONFIG_NET_NS +KSTATE_CTX_NET_NS , +#endifKSTATE_CTX_NSPROXY ,KSTATE_CTX_PID_NS , KSTATE_CTX_TASK_STRUCT,
@@ -105,6 +108,22 @@ int kstate_collect_all_pid_ns(struct kstate_context *ctx);int kstate_dump_all_pid_ns (struct kstate_context *ctx);int kstate_restore_pid_ns (struct kstate_context *ctx,kstate_ref_t *ref); +#ifdef CONFIG_NET_NS +int kstate_collect_all_net_ns (struct kstate_context *ctx); +int kstate_dump_all_net_ns (struct kstate_context *ctx); +int kstate_restore_net_ns (struct kstate_context *ctx,kstate_ref_t *ref); +#else +static inline int kstate_collect_all_net_ns (struct kstate_context *ctx) +{ +return 0 ; +} + +static inline int kstate_dump_all_net_ns (struct kstate_context *ctx) +{ +return 0 ; +} +#endif +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
include/net/net_namespace.h +1 -0
@@ -107,6 +107,7 @@ static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)extern struct list_head net_namespace_list;#ifdef CONFIG_NET_NS +extern struct net *net_create (void );extern void __put_net (struct net *net);static inline struct net *get_net (struct net *net)
kernel/kstate/cpt-sys.c +6 -0
@@ -80,6 +80,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_pid_ns (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_net_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_collect_all_mm_struct (ctx);if (rv <0 )return rv;
@@ -145,6 +148,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_mm_struct (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_net_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_mnt_ns (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +8 -0
@@ -8,6 +8,7 @@#include <linux/sched.h> #include <linux/slab.h> #include <linux/utsname.h> +#include <net/net_namespace.h> #include <linux/kstate.h>
@@ -57,6 +58,13 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +#ifdef CONFIG_NET_NS +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_NET_NS ) { +put_net ((struct net *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + } +#endif for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_NSPROXY ) {put_nsproxy ((struct nsproxy *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-object.c +6 -0
@@ -8,6 +8,7 @@#include <linux/sched.h> #include <linux/slab.h> #include <linux/utsname.h> +#include <net/net_namespace.h> #include <linux/kstate.h> #include <linux/kstate-image.h>
@@ -48,6 +49,11 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_MNT_NS :get_mnt_ns ((struct mnt_namespace *)obj->o_obj);break ; +#ifdef CONFIG_NET_NS +case KSTATE_CTX_NET_NS : +get_net ((struct net *)obj->o_obj); +break ; +#endif case KSTATE_CTX_NSPROXY :get_nsproxy ((struct nsproxy *)obj->o_obj);break ;
kernel/nsproxy.c +58 -8
94 lines not on this page · raw message
net/core/net_namespace.c +101 -1
119 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 32/38 C/R: checkpoint/restore struct cred
In reply to a message not in the archive->group_info, ->user will be done in next patches
FIXME: insufficient checks for capabilities at least.
--- include/linux/kstate-image.h | 25 ++++++ include/linux/kstate.h | 5 + kernel/cred.c | 164 ++++++++++++++++++++++++++++++++++++++++ kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 5 + kernel/kstate/kstate-file.c | 30 +++++++ kernel/kstate/kstate-object.c | 3 + kernel/kstate/kstate-task.c | 55 +++++++++++++ 8 files changed, 293 insertions(+), 0 deletions(-)
include/linux/kstate-image.h +25 -0
@@ -49,6 +49,7 @@ struct kstate_image_header {#define KSTATE_OBJ_MNT_NS 9#define KSTATE_OBJ_PID_NS 10#define KSTATE_OBJ_NET_NS 11 +#define KSTATE_OBJ_CRED 12struct kstate_object_header {__u32 obj_type;
@@ -73,6 +74,9 @@ struct kstate_image_task_struct {kstate_ref_t ref_mm;kstate_ref_t ref_nsproxy; +kstate_ref_t ref_real_cred; +kstate_ref_t ref_cred; +__u8 comm[16 ];/* Native arch of task, one of KSTATE_ARCH_*. */
@@ -207,6 +211,7 @@ struct kstate_image_file {__u32 i_mode;__u32 f_flags;__u64 f_pos; +kstate_ref_t ref_f_cred;__u32 name_len;/* including NUL */ /* __u8 name[name_len] */ } __packed;
@@ -250,4 +255,24 @@ struct kstate_image_pid_ns {struct kstate_image_net_ns {struct kstate_object_header hdr; } __packed; + +typedef __u64 kstate_cap_t ; +struct kstate_image_cred { +struct kstate_object_header hdr; + +__u32 uid; +__u32 gid; +__u32 suid; +__u32 sgid; +__u32 euid; +__u32 egid; +__u32 fsuid; +__u32 fsgid; +__u32 securebits; + +kstate_cap_t cap_inheritable; +kstate_cap_t cap_permitted; +kstate_cap_t cap_effective; +kstate_cap_t cap_bset; +} __packed;#endif
include/linux/kstate.h +5 -0
@@ -21,6 +21,7 @@ struct kstate_object {/* Not visible to userspace! */ enum kstate_context_obj_type { +KSTATE_CTX_CRED ,KSTATE_CTX_FILE ,#ifdef CONFIG_IPC_NS KSTATE_CTX_IPC_NS ,
@@ -124,6 +125,10 @@ static inline int kstate_dump_all_net_ns(struct kstate_context *ctx) }#endif +int kstate_collect_all_cred (struct kstate_context *ctx); +int kstate_dump_all_cred (struct kstate_context *ctx); +int kstate_restore_cred (struct kstate_context *ctx,kstate_ref_t *ref); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/cred.c +164 -0
173 lines not on this page · raw message
kernel/kstate/cpt-sys.c +6 -0
@@ -89,6 +89,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_file (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_cred (ctx); +if (rv <0 ) +return rv;return 0 ; }
@@ -142,6 +145,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_pid_ns (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_cred (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_file (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +5 -0
@@ -36,6 +36,11 @@ void kstate_context_destroy(struct kstate_context *ctx) {struct kstate_object *obj, *tmp; +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_CRED ) { +put_cred ((struct cred *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_FILE ) {fput ((struct file *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-file.c +30 -0
@@ -86,6 +86,7 @@ int generic_file_checkpoint(struct file *file, struct kstate_context *ctx) {struct kstate_object *obj;struct kstate_image_file *i; +struct kstate_object *tmp;struct kstat stat;char *buf, *name;int rv;
@@ -102,6 +103,9 @@ int generic_file_checkpoint(struct file *file, struct kstate_context *ctx)/* Assume seeking over file doesn't have history. */ i->f_pos = file->f_pos; + tmp =find_kstate_obj_by_ptr (ctx, file->f_cred,KSTATE_CTX_CRED ); + i->ref_f_cred = tmp->o_ref; + buf =kmalloc (PAGE_SIZE ,GFP_KERNEL );if (!buf) { rv = -ENOMEM ;
@@ -154,6 +158,28 @@ int kstate_dump_all_file(struct kstate_context *ctx)return 0 ; } +static int file_restore_cred (struct kstate_context *ctx,kstate_ref_t *ref,struct file *file) +{ +struct cred *cred; +const struct cred *old_cred; +struct kstate_object *tmp; +int rv; + + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_CRED ); +if (!tmp) { + rv =kstate_restore_cred (ctx, ref); +if (rv <0 ) +return rv; + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_CRED ); + } + cred = tmp->o_obj; + + old_cred = file->f_cred; +rcu_assign_pointer (file->f_cred,get_cred (cred)); +put_cred (old_cred); +return 0 ; +} +int kstate_restore_file (struct kstate_context *ctx,kstate_ref_t *ref) {struct kstate_image_file *i;
@@ -182,6 +208,10 @@ int kstate_restore_file(struct kstate_context *ctx, kstate_ref_t *ref) rv = -EINVAL ; goto out_fput; } + + rv =file_restore_cred (ctx, &i->ref_f_cred, file); +if (rv <0 ) + goto out_fput;/* Assume seeking over file doesn't have history. */ if (vfs_llseek (file, i->f_pos,SEEK_SET ) != i->f_pos) { rv = -EINVAL ;
kernel/kstate/kstate-object.c +3 -0
@@ -35,6 +35,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contelist_add_tail (&obj->o_list, &ctx->obj[type]);switch (type) { +case KSTATE_CTX_CRED : +get_cred ((struct cred *)obj->o_obj); +break ;case KSTATE_CTX_FILE :get_file ((struct file *)obj->o_obj);break ;
kernel/kstate/kstate-task.c +55 -0
73 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 33/38 C/R: checkpoint/restore aux groups (structy group_info)
In reply to a message not in the archive--- include/linux/kstate-image.h | 10 +++ include/linux/kstate.h | 5 ++ kernel/cred.c | 30 +++++++++- kernel/groups.c | 125 ++++++++++++++++++++++++++++++++++++++++ kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 5 ++ kernel/kstate/kstate-object.c | 3 + 7 files changed, 182 insertions(+), 2 deletions(-)
include/linux/kstate-image.h +10 -0
@@ -50,6 +50,7 @@ struct kstate_image_header {#define KSTATE_OBJ_PID_NS 10#define KSTATE_OBJ_NET_NS 11#define KSTATE_OBJ_CRED 12 +#define KSTATE_OBJ_GROUP_INFO 13struct kstate_object_header {__u32 obj_type;
@@ -274,5 +275,14 @@ struct kstate_image_cred {kstate_cap_t cap_permitted;kstate_cap_t cap_effective;kstate_cap_t cap_bset; + + kstate_ref_t ref_group_info; +} __packed; + +struct kstate_image_group_info { +struct kstate_object_header hdr; + +__u32 ngroups; +/* __u32 gid[ngroups]; */ } __packed;#endif
include/linux/kstate.h +5 -0
@@ -23,6 +23,7 @@ struct kstate_object {enum kstate_context_obj_type {KSTATE_CTX_CRED ,KSTATE_CTX_FILE , +KSTATE_CTX_GROUP_INFO ,#ifdef CONFIG_IPC_NS KSTATE_CTX_IPC_NS ,#endif
@@ -129,6 +130,10 @@ int kstate_collect_all_cred(struct kstate_context *ctx);int kstate_dump_all_cred (struct kstate_context *ctx);int kstate_restore_cred (struct kstate_context *ctx,kstate_ref_t *ref); +int kstate_collect_all_group_info (struct kstate_context *ctx); +int kstate_dump_all_group_info (struct kstate_context *ctx); +int kstate_restore_group_info (struct kstate_context *ctx,kstate_ref_t *ref); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/cred.c +28 -2
@@ -662,6 +662,7 @@ static int dump_cred(struct kstate_context *ctx, struct kstate_object *obj) {struct cred *cred = obj->o_obj;struct kstate_image_cred *i; +struct kstate_object *tmp;int rv; i =kstate_prepare_image (KSTATE_OBJ_CRED ,sizeof (*i));
@@ -684,6 +685,9 @@ static int dump_cred(struct kstate_context *ctx, struct kstate_object *obj)memcpy (&i->cap_effective, &cred->cap_effective,sizeof (kstate_cap_t));memcpy (&i->cap_bset, &cred->cap_bset,sizeof (kstate_cap_t)); + tmp =find_kstate_obj_by_ptr (ctx, cred->group_info,KSTATE_CTX_GROUP_INFO ); + i->ref_group_info = tmp->o_ref; + rv =kstate_write_image (ctx, i,sizeof (*i), obj);kfree (i);pr_debug ("dump cred %p: ref {%llu, %u}, rv %d\n" , cred, (unsigned long long )obj->o_ref.pos, obj->o_ref.id, rv);
@@ -703,6 +707,25 @@ int kstate_dump_all_cred(struct kstate_context *ctx)return 0 ; } +static int restore_group_info (struct kstate_context *ctx,kstate_ref_t *ref,struct cred *cred) +{ +struct group_info *gi; +struct kstate_object *tmp; +int rv; + + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_GROUP_INFO ); +if (!tmp) { + rv =kstate_restore_group_info (ctx, ref); +if (rv <0 ) +return rv; + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_GROUP_INFO ); + } + gi = tmp->o_obj; + + cred->group_info =get_group_info (gi); +return 0 ; +} +int kstate_restore_cred (struct kstate_context *ctx,kstate_ref_t *ref) {struct kstate_image_cred *i;
@@ -735,8 +758,9 @@ int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref)memcpy (&cred->cap_effective, &i->cap_effective,sizeof (i->cap_effective));memcpy (&cred->cap_bset, &i->cap_bset,sizeof (i->cap_bset)); -/* FIXME */ - cred->group_info =get_group_info (&init_groups); + rv =restore_group_info (ctx, &i->ref_group_info, cred); +if (rv <0 ) + goto out_group_info;/* FIXME */ cred->user =get_uid (&root_user);kfree (i);
@@ -747,6 +771,8 @@ int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref)pr_debug ("restore cred %p: ref {%llu, %u}, rv %d\n" , cred, (unsigned long long )ref->pos, ref->id, rv);return rv; +out_group_info: +kmem_cache_free (cred_jar, cred); out_free_image:kfree (i);pr_debug ("%s: return %d, ref {%llu, %u}\n" , __func__, rv, (unsigned long long )ref->pos, ref->id);
kernel/groups.c +125 -0
133 lines not on this page · raw message
kernel/kstate/cpt-sys.c +6 -0
@@ -92,6 +92,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_cred (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_group_info (ctx); +if (rv <0 ) +return rv;return 0 ; }
@@ -145,6 +148,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_pid_ns (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_group_info (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_cred (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +5 -0
@@ -46,6 +46,11 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_GROUP_INFO ) { +put_group_info ((struct group_info *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }#ifdef CONFIG_IPC_NS for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_IPC_NS ) {put_ipc_ns ((struct ipc_namespace *)obj->o_obj);
kernel/kstate/kstate-object.c +3 -0
@@ -41,6 +41,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_FILE :get_file ((struct file *)obj->o_obj);break ; +case KSTATE_CTX_GROUP_INFO : +get_group_info ((struct group_info *)obj->o_obj); +break ;#ifdef CONFIG_IPC_NS case KSTATE_CTX_IPC_NS :get_ipc_ns ((struct ipc_namespace *)obj->o_obj);
Signature · 1 line
1.5.6.5
PATCH 34/38 C/R: checkpoint/restore struct user
In reply to a message not in the archiveNote, user_namespace is in next patch as well as ->creator loop issue.
--- include/linux/kstate-image.h | 8 +++ include/linux/kstate.h | 5 ++ kernel/cred.c | 28 +++++++++- kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 5 ++ kernel/kstate/kstate-object.c | 3 + kernel/user.c | 121 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 174 insertions(+), 2 deletions(-)
include/linux/kstate-image.h +8 -0
@@ -51,6 +51,7 @@ struct kstate_image_header {#define KSTATE_OBJ_NET_NS 11#define KSTATE_OBJ_CRED 12#define KSTATE_OBJ_GROUP_INFO 13 +#define KSTATE_OBJ_USER_STRUCT 14struct kstate_object_header {__u32 obj_type;
@@ -277,6 +278,7 @@ struct kstate_image_cred {kstate_cap_t cap_bset;kstate_ref_t ref_group_info; +kstate_ref_t ref_user; } __packed;struct kstate_image_group_info {
@@ -285,4 +287,10 @@ struct kstate_image_group_info {__u32 ngroups; /* __u32 gid[ngroups]; */ } __packed; + +struct kstate_image_user_struct { +struct kstate_object_header hdr; + +__u32 uid; +} __packed;#endif
include/linux/kstate.h +5 -0
@@ -35,6 +35,7 @@ enum kstate_context_obj_type {KSTATE_CTX_NSPROXY ,KSTATE_CTX_PID_NS ,KSTATE_CTX_TASK_STRUCT , +KSTATE_CTX_USER_STRUCT ,KSTATE_CTX_UTS_NS , NR_KSTATE_CTX_TYPES };
@@ -134,6 +135,10 @@ int kstate_collect_all_group_info(struct kstate_context *ctx);int kstate_dump_all_group_info (struct kstate_context *ctx);int kstate_restore_group_info (struct kstate_context *ctx,kstate_ref_t *ref); +int kstate_collect_all_user_struct (struct kstate_context *ctx); +int kstate_dump_all_user_struct (struct kstate_context *ctx); +int kstate_restore_user_struct (struct kstate_context *ctx,kstate_ref_t *ref); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/cred.c +26 -2
@@ -687,6 +687,8 @@ static int dump_cred(struct kstate_context *ctx, struct kstate_object *obj) tmp =find_kstate_obj_by_ptr (ctx, cred->group_info,KSTATE_CTX_GROUP_INFO ); i->ref_group_info = tmp->o_ref; + tmp =find_kstate_obj_by_ptr (ctx, cred->user,KSTATE_CTX_USER_STRUCT ); + i->ref_user = tmp->o_ref; rv =kstate_write_image (ctx, i,sizeof (*i), obj);kfree (i);
@@ -726,6 +728,25 @@ static int restore_group_info(struct kstate_context *ctx, kstate_ref_t *ref, strreturn 0 ; } +static int restore_user (struct kstate_context *ctx,kstate_ref_t *ref,struct cred *cred) +{ +struct user_struct *user; +struct kstate_object *tmp; +int rv; + + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_USER_STRUCT ); +if (!tmp) { + rv =kstate_restore_user_struct (ctx, ref); +if (rv <0 ) +return rv; + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_USER_STRUCT ); + } + user = tmp->o_obj; + + cred->user =get_uid (user); +return 0 ; +} +int kstate_restore_cred (struct kstate_context *ctx,kstate_ref_t *ref) {struct kstate_image_cred *i;
@@ -761,8 +782,9 @@ int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref) rv =restore_group_info (ctx, &i->ref_group_info, cred);if (rv <0 ) goto out_group_info; -/* FIXME */ - cred->user =get_uid (&root_user); + rv =restore_user (ctx, &i->ref_user, cred); +if (rv <0 ) + goto out_user;kfree (i); rv =kstate_restore_object (ctx, cred,KSTATE_CTX_CRED , ref);
@@ -771,6 +793,8 @@ int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref)pr_debug ("restore cred %p: ref {%llu, %u}, rv %d\n" , cred, (unsigned long long )ref->pos, ref->id, rv);return rv; +out_user: +put_group_info (cred->group_info); out_group_info:kmem_cache_free (cred_jar, cred); out_free_image:
kernel/kstate/cpt-sys.c +6 -0
@@ -95,6 +95,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_group_info (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_user_struct (ctx); +if (rv <0 ) +return rv;return 0 ; }
@@ -148,6 +151,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_pid_ns (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_user_struct (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_group_info (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +5 -0
@@ -90,6 +90,11 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_USER_STRUCT ) { +free_uid ((struct user_struct *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_UTS_NS ) {put_uts_ns ((struct uts_namespace *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-object.c +3 -0
@@ -69,6 +69,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_TASK_STRUCT :get_task_struct ((struct task_struct *)obj->o_obj);break ; +case KSTATE_CTX_USER_STRUCT : +get_uid ((struct user_struct *)obj->o_obj); +break ;case KSTATE_CTX_UTS_NS :get_uts_ns ((struct uts_namespace *)obj->o_obj);break ;
kernel/user.c +121 -0
130 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 35/38 C/R: checkpoint/restore struct user_namespace
In reply to a message not in the archiveWe have first loop -- user->user_ns->creator (which is struct user_struct)
user_ns image references ->creator image but only partially because user_namespaces are dumped before user_structs.
--- include/linux/kstate-image.h | 12 +++ include/linux/kstate.h | 5 ++ kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 6 ++ kernel/kstate/kstate-object.c | 4 + kernel/user.c | 21 +++++- kernel/user_namespace.c | 146 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 198 insertions(+), 2 deletions(-) delete mode 100644 kernel/kstate/kstate-uts_ns.c
include/linux/kstate-image.h +12 -0
@@ -52,6 +52,7 @@ struct kstate_image_header {#define KSTATE_OBJ_CRED 12#define KSTATE_OBJ_GROUP_INFO 13#define KSTATE_OBJ_USER_STRUCT 14 +#define KSTATE_OBJ_USER_NS 15struct kstate_object_header {__u32 obj_type;
@@ -291,6 +292,17 @@ struct kstate_image_group_info {struct kstate_image_user_struct {struct kstate_object_header hdr; +kstate_ref_t ref_user_ns;__u32 uid; } __packed; + +struct kstate_image_user_ns { +struct kstate_object_header hdr; + +/* +* KSTATE_REF_UNDEF if user_ns creator user was outside of container, +* otherwise partial {0, id} reference. +*/ +kstate_ref_t ref_creator; +} __packed;#endif
include/linux/kstate.h +5 -0
@@ -35,6 +35,7 @@ enum kstate_context_obj_type {KSTATE_CTX_NSPROXY ,KSTATE_CTX_PID_NS ,KSTATE_CTX_TASK_STRUCT , +KSTATE_CTX_USER_NS ,KSTATE_CTX_USER_STRUCT ,KSTATE_CTX_UTS_NS ,NR_KSTATE_CTX_TYPES
@@ -139,6 +140,10 @@ int kstate_collect_all_user_struct(struct kstate_context *ctx);int kstate_dump_all_user_struct (struct kstate_context *ctx);int kstate_restore_user_struct (struct kstate_context *ctx,kstate_ref_t *ref); +int kstate_collect_all_user_ns (struct kstate_context *ctx); +int kstate_dump_all_user_ns (struct kstate_context *ctx); +int kstate_restore_user_ns (struct kstate_context *ctx,kstate_ref_t *ref); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
@@ -98,6 +98,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_user_struct (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_user_ns (ctx); +if (rv <0 ) +return rv;return 0 ; }
@@ -151,6 +154,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_pid_ns (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_user_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_user_struct (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +6 -0
@@ -7,6 +7,7 @@#include <linux/pid_namespace.h> #include <linux/sched.h> #include <linux/slab.h> +#include <linux/user_namespace.h> #include <linux/utsname.h> #include <net/net_namespace.h>
@@ -90,6 +91,11 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_USER_NS ) { +put_user_ns ((struct user_namespace *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_USER_STRUCT ) {free_uid ((struct user_struct *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-object.c +4 -0
@@ -7,6 +7,7 @@#include <linux/pid_namespace.h> #include <linux/sched.h> #include <linux/slab.h> +#include <linux/user_namespace.h> #include <linux/utsname.h> #include <net/net_namespace.h>
@@ -69,6 +70,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_TASK_STRUCT :get_task_struct ((struct task_struct *)obj->o_obj);break ; +case KSTATE_CTX_USER_NS : +get_user_ns ((struct user_namespace *)obj->o_obj); +break ;case KSTATE_CTX_USER_STRUCT :get_uid ((struct user_struct *)obj->o_obj);break ;
kernel/kstate/kstate-uts_ns.c deleted +0 -0
kernel/user.c +19 -2
@@ -554,6 +554,10 @@ int kstate_collect_all_user_struct(struct kstate_context *ctx)if (rv <0 )return rv; } +/* +* Don't check refcounts here, user_ns->creator references weren't +* accounted yet, it will fire every time CLONE_NEWUSER is used. +*/ return 0 ; }
@@ -561,12 +565,15 @@ static int dump_user_struct(struct kstate_context *ctx, struct kstate_object *ob {struct user_struct *user = obj->o_obj;struct kstate_image_user_struct *i; +struct kstate_object *tmp;int rv; i =kstate_prepare_image (KSTATE_OBJ_USER_STRUCT ,sizeof (*i));if (!i)return -ENOMEM ; + tmp =find_kstate_obj_by_ptr (ctx, user->user_ns,KSTATE_CTX_USER_NS ); + i->ref_user_ns = tmp->o_ref; i->uid = user->uid; rv =kstate_write_image (ctx, i,sizeof (*i), obj);
@@ -592,14 +599,24 @@ int kstate_restore_user_struct(struct kstate_context *ctx, kstate_ref_t *ref) {struct kstate_image_user_struct *i;struct user_struct *user; +struct user_namespace *user_ns; +struct kstate_object *tmp;int rv; i =kstate_read_image (ctx, ref,KSTATE_OBJ_USER_STRUCT ,sizeof (*i));if (IS_ERR (i))return PTR_ERR (i); -/* FIXME */ - user =alloc_uid (&init_user_ns, i->uid); + tmp =find_kstate_obj_by_ref (ctx, &i->ref_user_ns,KSTATE_CTX_USER_NS ); +if (!tmp) { + rv =kstate_restore_user_ns (ctx, &i->ref_user_ns); +if (rv <0 ) + goto out_free_image; + tmp =find_kstate_obj_by_ref (ctx, &i->ref_user_ns,KSTATE_CTX_USER_NS ); + } + user_ns = tmp->o_obj; + + user =alloc_uid (user_ns, i->uid);if (!user) { rv = -ENOMEM ; goto out_free_image;
kernel/user_namespace.c +146 -0
153 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 36/38 C/R: checkpoint/restore struct pid
In reply to a message not in the archiveDeal with struct pid in general and task pids in particular.
Guess what, references to outside pids are banned which means that if child is created with simple CLONE_NEWPID, it's PIDTYPE_PGID and PIDTYPE_SID will be outside of newborn pidns.
On restore we don't know to where glue them and they weren't saved at all. So abort checkpointing in this case.
New-born container inits should use setpgrp(2) and setsid(2)!
--- include/linux/kstate-image.h | 13 +++ include/linux/kstate.h | 5 + include/linux/pid.h | 2 +- kernel/fork.c | 2 +- kernel/kstate/cpt-sys.c | 6 + kernel/kstate/kstate-context.c | 5 + kernel/kstate/kstate-object.c | 3 + kernel/kstate/kstate-task.c | 80 ++++++++++++++++ kernel/pid.c | 199 +++++++++++++++++++++++++++++++++++++++- 9 files changed, 308 insertions(+), 7 deletions(-)
include/linux/kstate-image.h +13 -0
@@ -53,6 +53,7 @@ struct kstate_image_header {#define KSTATE_OBJ_GROUP_INFO 13#define KSTATE_OBJ_USER_STRUCT 14#define KSTATE_OBJ_USER_NS 15 +#define KSTATE_OBJ_PID 16struct kstate_object_header {__u32 obj_type;
@@ -80,6 +81,10 @@ struct kstate_image_task_struct {kstate_ref_t ref_real_cred;kstate_ref_t ref_cred; +kstate_ref_t ref_pid; +kstate_ref_t ref_pgid; +kstate_ref_t ref_sid; +__u8 comm[16 ];/* Native arch of task, one of KSTATE_ARCH_*. */
@@ -305,4 +310,12 @@ struct kstate_image_user_ns {*/ kstate_ref_t ref_creator; } __packed; + +struct kstate_image_pid { +struct kstate_object_header hdr; + +kstate_ref_t ref_pid_ns;/* last-level pid_ns */ +__u32 level; +__u32 nr[1 ]; +} __packed;#endif
include/linux/kstate.h +5 -0
@@ -33,6 +33,7 @@ enum kstate_context_obj_type {KSTATE_CTX_NET_NS , #endifKSTATE_CTX_NSPROXY , +KSTATE_CTX_PID ,KSTATE_CTX_PID_NS ,KSTATE_CTX_TASK_STRUCT , KSTATE_CTX_USER_NS,
@@ -144,6 +145,10 @@ int kstate_collect_all_user_ns(struct kstate_context *ctx);int kstate_dump_all_user_ns (struct kstate_context *ctx);int kstate_restore_user_ns (struct kstate_context *ctx,kstate_ref_t *ref); +int kstate_collect_all_pid (struct kstate_context *ctx); +int kstate_dump_all_pid (struct kstate_context *ctx); +int kstate_restore_pid (struct kstate_context *ctx,kstate_ref_t *ref); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
include/linux/pid.h +1 -1
@@ -119,7 +119,7 @@ extern struct pid *find_get_pid(int nr);extern struct pid *find_ge_pid (int nr,struct pid_namespace *);int next_pidmap (struct pid_namespace *pid_ns,int last); -extern struct pid *alloc_pid (struct pid_namespace *ns); +extern struct pid *alloc_pid (struct pid_namespace *ns,int *nr,unsigned int level);extern void free_pid (struct pid *pid);/*
kernel/fork.c +1 -1
@@ -1117,7 +1117,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,if (pid != &init_struct_pid) { retval = -ENOMEM ; - pid =alloc_pid (p->nsproxy->pid_ns); + pid =alloc_pid (p->nsproxy->pid_ns,NULL ,0 );if (!pid) goto bad_fork_cleanup_io;
kernel/kstate/cpt-sys.c +6 -0
@@ -101,6 +101,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_user_ns (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_pid (ctx); +if (rv <0 ) +return rv;return 0 ; }
@@ -154,6 +157,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_pid_ns (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_pid (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_user_ns (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +5 -0
@@ -81,6 +81,11 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_PID ) { +put_pid ((struct pid *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_PID_NS ) {put_pid_ns ((struct pid_namespace *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-object.c +3 -0
@@ -64,6 +64,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_NSPROXY :get_nsproxy ((struct nsproxy *)obj->o_obj);break ; +case KSTATE_CTX_PID : +get_pid ((struct pid *)obj->o_obj); +break ;case KSTATE_CTX_PID_NS :get_pid_ns ((struct pid_namespace *)obj->o_obj);break ;
kernel/kstate/kstate-task.c +80 -0
98 lines not on this page · raw message
kernel/pid.c +194 -5
231 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 37/38 C/R: checkpoint/restore opened files
In reply to a message not in the archiveFile descriptor is dumped as formally an object, despite it can't be shared by itself, only files_struct can.
Opening is done, veryfying that we opened right file, restoration of file position and nothing more.
--- include/linux/kstate-image.h | 16 +++ include/linux/kstate.h | 6 + kernel/kstate/cpt-sys.c | 6 + kernel/kstate/kstate-context.c | 6 + kernel/kstate/kstate-file.c | 201 ++++++++++++++++++++++++++++++++++++++++ kernel/kstate/kstate-object.c | 4 + kernel/kstate/kstate-task.c | 54 +++++++++++ 7 files changed, 293 insertions(+), 0 deletions(-)
include/linux/kstate-image.h +16 -0
@@ -54,6 +54,8 @@ struct kstate_image_header {#define KSTATE_OBJ_USER_STRUCT 14#define KSTATE_OBJ_USER_NS 15#define KSTATE_OBJ_PID 16 +#define KSTATE_OBJ_FILES_STRUCT 17 +#define KSTATE_OBJ_FD 18struct kstate_object_header {__u32 obj_type;
@@ -77,6 +79,7 @@ struct kstate_image_task_struct {kstate_ref_t ref_mm;kstate_ref_t ref_nsproxy; +kstate_ref_t ref_files;kstate_ref_t ref_real_cred;kstate_ref_t ref_cred;
@@ -318,4 +321,17 @@ struct kstate_image_pid {__u32 level; __u32 nr[1]; } __packed; + +struct kstate_image_files_struct { +struct kstate_object_header hdr; +} __packed; + +struct kstate_image_fd { +struct kstate_object_header hdr; + +kstate_ref_t ref_file; +__u32 fd; +#define KSTATE_FD_FLAGS_CLOEXEC (1 << 0) +__u32 fd_flags; +} __packed;#endif
include/linux/kstate.h +6 -0
@@ -23,6 +23,7 @@ struct kstate_object {enum kstate_context_obj_type {KSTATE_CTX_CRED ,KSTATE_CTX_FILE , +KSTATE_CTX_FILES_STRUCT ,KSTATE_CTX_GROUP_INFO ,#ifdef CONFIG_IPC_NS KSTATE_CTX_IPC_NS ,
@@ -149,6 +150,11 @@ int kstate_collect_all_pid(struct kstate_context *ctx);int kstate_dump_all_pid (struct kstate_context *ctx);int kstate_restore_pid (struct kstate_context *ctx,kstate_ref_t *ref); +int kstate_collect_all_files_struct (struct kstate_context *ctx); +int kstate_dump_all_files_struct (struct kstate_context *ctx); +int kstate_restore_files_struct (struct kstate_context *ctx,kstate_ref_t *ref); +int kstate_restore_fd (struct kstate_context *ctx,kstate_pos_t pos); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
@@ -86,6 +86,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_mm_struct (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_files_struct (ctx); +if (rv <0 ) +return rv; rv =kstate_collect_all_file (ctx);if (rv <0 )return rv;
@@ -175,6 +178,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_file (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_files_struct (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_mm_struct (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +6 -0
@@ -1,4 +1,5 @@/* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */ +#include <linux/fdtable.h> #include <linux/file.h> #include <linux/ipc_namespace.h> #include <linux/list.h>
@@ -47,6 +48,11 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_FILES_STRUCT ) { +put_files_struct ((struct files_struct *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_GROUP_INFO ) {put_group_info ((struct group_info *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-file.c +201 -0
210 lines not on this page · raw message
kernel/kstate/kstate-object.c +4 -0
@@ -1,4 +1,5 @@/* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */ +#include <linux/fdtable.h> #include <linux/fs.h> #include <linux/ipc_namespace.h> #include <linux/mm_types.h>
@@ -42,6 +43,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_FILE :get_file ((struct file *)obj->o_obj);break ; +case KSTATE_CTX_FILES_STRUCT : +atomic_inc (&((struct files_struct *)obj->o_obj)->count); +break ;case KSTATE_CTX_GROUP_INFO :get_group_info ((struct group_info *)obj->o_obj);break ;
kernel/kstate/kstate-task.c +54 -0
76 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 38/38 C/R: checkpoint/restart struct sighand_struct
In reply to a message not in the archive--- arch/x86/include/asm/signal.h | 2 + include/linux/kstate-image.h | 17 +++++ include/linux/kstate.h | 29 ++++++++ kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 5 ++ kernel/kstate/kstate-object.c | 3 + kernel/kstate/kstate-task.c | 32 +++++++++ kernel/signal.c | 140 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 234 insertions(+), 0 deletions(-)
arch/x86/include/asm/signal.h +2 -0
@@ -140,6 +140,7 @@ struct sigaction {__sigrestore_t sa_restorer;sigset_t sa_mask;/* mask last for extensibility */ }; +#define sa_restorer sa_restorerstruct k_sigaction {struct sigaction sa;
@@ -170,6 +171,7 @@ struct sigaction {__sigrestore_t sa_restorer;sigset_t sa_mask;/* mask last for extensibility */ }; +#define sa_restorer sa_restorerstruct k_sigaction {struct sigaction sa;
include/linux/kstate-image.h +17 -0
@@ -18,6 +18,9 @@ static inline int kstate_ref_undefined(kstate_ref_t *ref)return ref->pos ==0 && ref->id ==0 ; } +typedef __u8 kstate_sigset_t [16 ]; +typedef __u64 kstate_ptr_t ; +struct kstate_image_header {/* Immutable part except version bumps. */ #define KSTATE_IMAGE_MAGIC "LinuxC/R"
@@ -56,6 +59,7 @@ struct kstate_image_header {#define KSTATE_OBJ_PID 16#define KSTATE_OBJ_FILES_STRUCT 17#define KSTATE_OBJ_FD 18 +#define KSTATE_OBJ_SIGHAND_STRUCT 19struct kstate_object_header {__u32 obj_type;
@@ -88,6 +92,8 @@ struct kstate_image_task_struct {kstate_ref_t ref_pgid;kstate_ref_t ref_sid; +kstate_ref_t ref_sighand; +__u8 comm[16 ];/* Native arch of task, one of KSTATE_ARCH_*. */
@@ -334,4 +340,15 @@ struct kstate_image_fd {#define KSTATE_FD_FLAGS_CLOEXEC (1 << 0) __u32 fd_flags; } __packed; + +struct kstate_image_sighand_struct { +struct kstate_object_header hdr; + +struct { +kstate_ptr_t sa_handler; +__u64 sa_flags; +kstate_ptr_t sa_restorer; +kstate_sigset_t sa_mask; + } sa[128 ]; +} __packed;#endif
include/linux/kstate.h +29 -0
@@ -1,7 +1,9 @@/* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */ #ifndef __INCLUDE_LINUX_KSTATE_H#define __INCLUDE_LINUX_KSTATE_H +#include <linux/compiler.h> #include <linux/list.h> +#include <asm/signal.h> #include <linux/kstate-image.h>
@@ -36,6 +38,7 @@ enum kstate_context_obj_type {KSTATE_CTX_NSPROXY ,KSTATE_CTX_PID ,KSTATE_CTX_PID_NS , +KSTATE_CTX_SIGHAND_STRUCT ,KSTATE_CTX_TASK_STRUCT ,KSTATE_CTX_USER_NS , KSTATE_CTX_USER_STRUCT,
@@ -70,6 +73,28 @@ void *kstate_prepare_image(__u32 type, unsigned int len);void *kstate_read_image (struct kstate_context *ctx,kstate_ref_t *ref,__u32 type,unsigned int len);int kstate_write_image (struct kstate_context *ctx,void *i,unsigned int len,struct kstate_object *obj); +static inline kstate_ptr_t kstate_export_ptr (const void __user *ptr) +{ +BUILD_BUG_ON (sizeof (kstate_ptr_t) <sizeof (ptr)); +return (unsigned long )ptr; +} + +static inline const void __user *kstate_import_ptr (kstate_ptr_t i) +{ +return (const void __user *)(unsigned long )i; +} + +static inline void kstate_dump_sigset (kstate_sigset_t *i,sigset_t *sig) +{ +BUILD_BUG_ON (sizeof (sigset_t) >sizeof (kstate_sigset_t)); +memcpy (i, sig,sizeof (sigset_t)); +} + +static inline void kstate_restore_sigset (sigset_t *sig,kstate_sigset_t *i) +{ +memcpy (sig, i,sizeof (sigset_t)); +} +int kstate_collect_all_task_struct (struct kstate_context *ctx);int kstate_dump_all_task_struct (struct kstate_context *ctx);int kstate_restore_task_struct (struct kstate_context *ctx,kstate_ref_t *ref);
@@ -155,6 +180,10 @@ int kstate_dump_all_files_struct(struct kstate_context *ctx);int kstate_restore_files_struct (struct kstate_context *ctx,kstate_ref_t *ref);int kstate_restore_fd (struct kstate_context *ctx,kstate_pos_t pos); +int kstate_collect_all_sighand_struct (struct kstate_context *ctx); +int kstate_dump_all_sighand_struct (struct kstate_context *ctx); +int kstate_restore_sighand_struct (struct kstate_context *ctx,kstate_ref_t *ref); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
@@ -104,6 +104,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_user_ns (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_sighand_struct (ctx); +if (rv <0 ) +return rv; rv =kstate_collect_all_pid (ctx);if (rv <0 )return rv;
@@ -163,6 +166,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_pid (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_sighand_struct (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_user_ns (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +5 -0
@@ -97,6 +97,11 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_SIGHAND_STRUCT ) { +__cleanup_sighand ((struct sighand_struct *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_TASK_STRUCT ) {put_task_struct ((struct task_struct *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-object.c +3 -0
@@ -74,6 +74,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_PID_NS :get_pid_ns ((struct pid_namespace *)obj->o_obj);break ; +case KSTATE_CTX_SIGHAND_STRUCT : +atomic_inc (&((struct sighand_struct *)obj->o_obj)->count); +break ;case KSTATE_CTX_TASK_STRUCT :get_task_struct ((struct task_struct *)obj->o_obj);break ;
kernel/kstate/kstate-task.c +32 -0
@@ -139,6 +139,9 @@ static int dump_task_struct(struct kstate_context *ctx, struct kstate_object *ob tmp =find_kstate_obj_by_ptr (ctx, tsk->files,KSTATE_CTX_FILES_STRUCT ); i->ref_files = tmp->o_ref; + tmp =find_kstate_obj_by_ptr (ctx, tsk->sighand,KSTATE_CTX_SIGHAND_STRUCT ); + i->ref_sighand = tmp->o_ref; +BUILD_BUG_ON (sizeof (i->comm) !=sizeof (tsk->comm));strlcpy ((char *)i->comm, (const char *)tsk->comm,sizeof (i->comm));
@@ -402,6 +405,32 @@ static int restore_files(struct kstate_context *ctx, kstate_ref_t *ref)return 0 ; } +static int restore_sighand (struct kstate_context *ctx,kstate_ref_t *ref) +{ +struct sighand_struct *sighand; +struct kstate_object *tmp; +struct sighand_struct *old_sighand; +unsigned long flags; +int rv; + + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_SIGHAND_STRUCT ); +if (!tmp) { + rv =kstate_restore_sighand_struct (ctx, ref); +if (rv <0 ) +return rv; + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_SIGHAND_STRUCT ); + } + sighand = tmp->o_obj; + +atomic_inc (&sighand->count); + old_sighand = current->sighand; +spin_lock_irqsave (&old_sighand->siglock, flags); + current->sighand = sighand; +spin_unlock_irqrestore (&old_sighand->siglock, flags); +__cleanup_sighand (old_sighand); +return 0 ; +} +struct task_struct_restore_context {struct kstate_context *ctx;struct kstate_image_task_struct *i;
@@ -468,6 +497,9 @@ static int task_struct_restorer(void *_tsk_ctx) rv =restore_files (ctx, &i->ref_files);if (rv <0 ) goto out; + rv =restore_sighand (ctx, &i->ref_sighand); +if (rv <0 ) + goto out; out: tsk_ctx->rv = rv;
kernel/signal.c +140 -0
149 lines not on this page · raw message
Signature · 1 line
1.5.6.5
More patches before "[PATCH 18/38] C/R: core stuff" were already sent via usual channels and some are already in -next. There are being repeated to maintain clean series against mainline.
I forgot to mention that ->checkpoint hook was not added to vDSO mapping for several reasons so if someone want to test, boot with vdso=0 for now.
PATCH 2/38 utsns: extract create_uts_ns()
In reply to Alexey Dobriyancreate_uts_ns() will be used by C/R to create fresh uts_ns.
--- kernel/utsname.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-)
kernel/utsname.c +11 -2
@@ -15,6 +15,16 @@#include <linux/err.h> #include <linux/slab.h> +static struct uts_namespace *create_uts_ns (void ) +{ +struct uts_namespace *uts_ns; + + uts_ns =kmalloc (sizeof (struct uts_namespace ),GFP_KERNEL ); +if (uts_ns) +kref_init (&uts_ns->kref); +return uts_ns; +} +/* * Clone a new ns copying an original utsname, setting refcount to 1 * @old_ns: namespace to clone
@@ -24,14 +34,13 @@ static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns) {struct uts_namespace *ns; - ns =kmalloc (sizeof (struct uts_namespace ),GFP_KERNEL ); + ns =create_uts_ns ();if (!ns)return ERR_PTR (-ENOMEM );down_read (&uts_sem);memcpy (&ns->name, &old_ns->name,sizeof (ns->name));up_read (&uts_sem); -kref_init (&ns->kref);return ns; }
Signature · 1 line
1.5.6.5
Re: [PATCH 02/38] utsns: extract create_uts_ns()
Quoted 3 lines · Alexey Dobriyan
create_uts_ns()will be used by C/R to create freshuts_ns.Signed-off-by Alexey Dobriyan <[email protected]>
Quoted 48 lines
--- kernel/utsname.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-)kernel/utsname.c +11
-2@@ -15,6 +15,16 @@#include <linux/err.h> #include <linux/slab.h> +static struct uts_namespace *create_uts_ns (void ) +{ +struct uts_namespace *uts_ns; + + uts_ns =kmalloc (sizeof (struct uts_namespace ),GFP_KERNEL ); +if (uts_ns) +kref_init (&uts_ns->kref); +return uts_ns; +} +/* * Clone a new ns copying an original utsname, setting refcount to 1 * @old_ns: namespace to clone @@ -24,14 +34,13 @@ static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns) {struct uts_namespace *ns; - ns =kmalloc (sizeof (struct uts_namespace ),GFP_KERNEL ); + ns =create_uts_ns ();if (!ns)return ERR_PTR (-ENOMEM );down_read (&uts_sem);memcpy (&ns->name, &old_ns->name,sizeof (ns->name));up_read (&uts_sem); -kref_init (&ns->kref);return ns; }Signature · 6 lines
1.5.6.5 _______________________________________________ Containers mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/containers
PATCH 3/38 ipcns 1/4: remove useless get/put while CLONE_NEWIPC
In reply to Alexey Dobriyancopy_ipcs() doesn't actually copy anything. If new ipcns is created, it's created from scratch, in this case get/put on old ipcns isn't needed.
--- ipc/namespace.c | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-)
ipc/namespace.c +1 -5
@@ -50,15 +50,11 @@ struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns) {struct ipc_namespace *new_ns; -BUG_ON (!ns); -get_ipc_ns (ns); -if (!(flags &CLONE_NEWIPC )) -return ns; +return get_ipc_ns (ns); new_ns =clone_ipc_ns (ns); -put_ipc_ns (ns);return new_ns; }
Signature · 1 line
1.5.6.5
Re: [PATCH 03/38] ipcns 1/4: remove useless get/put while CLONE_NEWIPC
Quoted 5 lines · Alexey Dobriyan
copy_ipcs()doesn't actually copy anything. If new ipcns is created, it's created from scratch, in this case get/put on old ipcns isn't needed.Signed-off-by Alexey Dobriyan <[email protected]>Acked-by Serge Hallyn <[email protected]>
Looks good to me!
Quoted 33 lines
---
ipc/namespace.c| 6 +-----1 files changed, 1 insertions(+), 5 deletions(-)ipc/namespace.c +1
-5@@ -50,15 +50,11 @@ struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns) {struct ipc_namespace *new_ns; -BUG_ON (!ns); -get_ipc_ns (ns); -if (!(flags &CLONE_NEWIPC )) -return ns; +return get_ipc_ns (ns); new_ns =clone_ipc_ns (ns); -put_ipc_ns (ns);return new_ns; }Signature · 7 lines
1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
A message that is not in the archive (sent off-list or not yet received): 1242968132-1044-3-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Amerigo Wang
Reviewed-byRe: [PATCH 03/38] ipcns 1/4: remove useless get/put while CLONE_NEWIPC
Quoted 5 lines · Alexey Dobriyan
copy_ipcs()doesn't actually copy anything. If new ipcns is created, it's created from scratch, in this case get/put on old ipcns isn't needed.Signed-off-by Alexey Dobriyan <[email protected]>
Looks good to me!
Quoted 33 lines
---
ipc/namespace.c| 6 +-----1 files changed, 1 insertions(+), 5 deletions(-)ipc/namespace.c +1
-5@@ -50,15 +50,11 @@ struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns) {struct ipc_namespace *new_ns; -BUG_ON (!ns); -get_ipc_ns (ns); -if (!(flags &CLONE_NEWIPC )) -return ns; +return get_ipc_ns (ns); new_ns =clone_ipc_ns (ns); -put_ipc_ns (ns);return new_ns; }Signature · 7 lines
1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
PATCH 4/38 ipcns 2/4: extract create_ipc_ns()
In reply to Alexey Dobriyanclone_ipc_ns() is misnamed, it doesn't clone anything and doesn't use passed parameter. Rename it.
create_ipc_ns() will be used by C/R to create fresh ipcns.
--- ipc/namespace.c | 9 ++------- 1 files changed, 2 insertions(+), 7 deletions(-)
ipc/namespace.c +2 -7
@@ -14,7 +14,7 @@#include "util.h" -static struct ipc_namespace *clone_ipc_ns (struct ipc_namespace *old_ns) +static struct ipc_namespace *create_ipc_ns (void ) {struct ipc_namespace *ns;int err;
@@ -48,14 +48,9 @@ static struct ipc_namespace *clone_ipc_ns(struct ipc_namespace *old_ns)struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns) { -struct ipc_namespace *new_ns; -if (!(flags &CLONE_NEWIPC ))return get_ipc_ns (ns); - - new_ns =clone_ipc_ns (ns); - -return new_ns; +return create_ipc_ns (); }/*
Signature · 1 line
1.5.6.5
Re: [PATCH 04/38] ipcns 2/4: extract create_ipc_ns()
Quoted 16 lines · Alexey Dobriyan
clone_ipc_ns()is misnamed, it doesn't clone anything and doesn't use passed parameter. Rename it.
create_ipc_ns()will be used by C/R to create fresh ipcns.Signed-off-by Alexey Dobriyan <[email protected]>Acked-by Serge Hallyn <[email protected]>---
ipc/namespace.c| 9 ++-------1 files changed, 2 insertions(+), 7 deletions(-)ipc/namespace.c +0
-0
ipc/namespace.c line 17
Quoted 5 lines
ipc/namespace.c +1
-1@@ -14,7 +14,7 @@#include "util.h" -static struct ipc_namespace *clone_ipc_ns (struct ipc_namespace *old_ns) +static struct ipc_namespace *create_ipc_ns (void )
Great!! I am wondering why nobody else found this... :)
Quoted 27 lines
ipc/namespace.c +1
-6{struct ipc_namespace *ns;int err;@@ -48,14 +48,9 @@ static struct ipc_namespace *clone_ipc_ns(struct ipc_namespace *old_ns)struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns) { -struct ipc_namespace *new_ns; -if (!(flags &CLONE_NEWIPC ))return get_ipc_ns (ns); - - new_ns =clone_ipc_ns (ns); - -return new_ns; +return create_ipc_ns (); }/* Signature · 7 lines
1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
PATCH 5/38 ipcns 3/4: make free_ipc_ns() static
In reply to Alexey Dobriyan--- include/linux/ipc_namespace.h | 1 - ipc/namespace.c | 48 ++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 25 deletions(-)
include/linux/ipc_namespace.h +0 -1
@@ -94,7 +94,6 @@ static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }#endif #if defined(CONFIG_IPC_NS ) -extern void free_ipc_ns (struct ipc_namespace *ns);extern struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns); extern void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
ipc/namespace.c +24 -24
57 lines not on this page · raw message
Signature · 1 line
1.5.6.5
Re: [PATCH 05/38] ipcns 3/4: make free_ipc_ns() static
Quoted 1 line · Alexey Dobriyan
Signed-off-by Alexey Dobriyan <[email protected]>
A message that is not in the archive (sent off-list or not yet received): 1242968132-1044-5-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Serge E. Hallyn
Acked-by Serge HallynRe: [PATCH 05/38] ipcns 3/4: make free_ipc_ns() static
Quoted 1 line · Alexey Dobriyan
Signed-off-by Alexey Dobriyan <[email protected]>
PATCH 6/38 ipcns 4/2: move free_ipcs() proto
In reply to Alexey DobriyanFunction is really private to ipc/ and avoid struct kern_ipc_perm forward declaration.
--- include/linux/ipc_namespace.h | 4 ---- ipc/util.h | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-)
include/linux/ipc_namespace.h +0 -4
@@ -96,10 +96,6 @@ static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }#if defined(CONFIG_IPC_NS )extern struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns); -extern void free_ipcs (struct ipc_namespace *ns,struct ipc_ids *ids, -void (*free)(struct ipc_namespace *, -struct kern_ipc_perm *)); -static inline struct ipc_namespace *get_ipc_ns (struct ipc_namespace *ns) {if (ns)
ipc/util.h +2 -1
@@ -171,5 +171,6 @@ static inline void ipc_unlock(struct kern_ipc_perm *perm)struct kern_ipc_perm *ipc_lock_check (struct ipc_ids *ids,int id);int ipcget (struct ipc_namespace *ns,struct ipc_ids *ids,struct ipc_ops *ops,struct ipc_params *params); - +void free_ipcs (struct ipc_namespace *ns,struct ipc_ids *ids, +void (*free)(struct ipc_namespace *,struct kern_ipc_perm *));#endif
Signature · 1 line
1.5.6.5
Re: [PATCH 06/38] ipcns 4/2: move free_ipcs() proto
Quoted 4 lines · Alexey Dobriyan
Function is really private to
ipc/and avoid structkern_ipc_permforward declaration.Signed-off-by Alexey Dobriyan <[email protected]>
Quoted 39 lines
--- include/linux/ipc_namespace.h | 4 ---- ipc/util.h | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-)include/linux/ipc_namespace.h +0
-4@@ -96,10 +96,6 @@ static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }#if defined(CONFIG_IPC_NS )extern struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns); -extern void free_ipcs (struct ipc_namespace *ns,struct ipc_ids *ids, -void (*free)(struct ipc_namespace *, -struct kern_ipc_perm *)); -static inline struct ipc_namespace *get_ipc_ns (struct ipc_namespace *ns) {if (ns)ipc/util.h +2
-1@@ -171,5 +171,6 @@ static inline void ipc_unlock(struct kern_ipc_perm *perm)struct kern_ipc_perm *ipc_lock_check (struct ipc_ids *ids,int id);int ipcget (struct ipc_namespace *ns,struct ipc_ids *ids,struct ipc_ops *ops,struct ipc_params *params); - +void free_ipcs (struct ipc_namespace *ns,struct ipc_ids *ids, +void (*free)(struct ipc_namespace *,struct kern_ipc_perm *));#endif Signature · 6 lines
1.5.6.5 _______________________________________________ Containers mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/containers
A message that is not in the archive (sent off-list or not yet received): 1242968132-1044-6-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Serge E. Hallyn
Reviewed-by Serge HallynRe: [PATCH 06/38] ipcns 4/2: move free_ipcs() proto
Quoted 4 lines · Alexey Dobriyan
Function is really private to
ipc/and avoid structkern_ipc_permforward declaration.Signed-off-by Alexey Dobriyan <[email protected]>
Quoted 39 lines
--- include/linux/ipc_namespace.h | 4 ---- ipc/util.h | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-)include/linux/ipc_namespace.h +0
-4@@ -96,10 +96,6 @@ static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }#if defined(CONFIG_IPC_NS )extern struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns); -extern void free_ipcs (struct ipc_namespace *ns,struct ipc_ids *ids, -void (*free)(struct ipc_namespace *, -struct kern_ipc_perm *)); -static inline struct ipc_namespace *get_ipc_ns (struct ipc_namespace *ns) {if (ns)ipc/util.h +2
-1@@ -171,5 +171,6 @@ static inline void ipc_unlock(struct kern_ipc_perm *perm)struct kern_ipc_perm *ipc_lock_check (struct ipc_ids *ids,int id);int ipcget (struct ipc_namespace *ns,struct ipc_ids *ids,struct ipc_ops *ops,struct ipc_params *params); - +void free_ipcs (struct ipc_namespace *ns,struct ipc_ids *ids, +void (*free)(struct ipc_namespace *,struct kern_ipc_perm *));#endif Signature · 6 lines
1.5.6.5 _______________________________________________ Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org https://lists.linux-foundation.org/mailman/listinfo/containers
PATCH 7/38 pidns 1/2: make create_pid_namespace() accept parent pidns
In reply to Alexey Dobriyancreate_pid_namespace() creates everything, but caller has to assign parent pidns by hand, which is unnatural. At the moment of call new ->level has to be taken from somewhere and parent pidns is already available.
--- kernel/pid_namespace.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
kernel/pid_namespace.c +4 -4
@@ -67,9 +67,10 @@ err_alloc:return NULL ; } -static struct pid_namespace *create_pid_namespace (unsigned int level) +static struct pid_namespace *create_pid_namespace (struct pid_namespace *parent_pid_ns) {struct pid_namespace *ns; +unsigned int level = parent_pid_ns->level +1 ;int i; ns =kmem_cache_zalloc (pid_ns_cachep,GFP_KERNEL );
@@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_namespace(unsigned int level)kref_init (&ns->kref); ns->level = level; + ns->parent =get_pid_ns (parent_pid_ns);set_bit (0 , ns->pidmap[0 ].page);atomic_set (&ns->pidmap[0 ].nr_free,BITS_PER_PAGE -1 );
@@ -125,9 +127,7 @@ struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *oldif (flags &CLONE_THREAD ) goto out_put; - new_ns =create_pid_namespace (old_ns->level +1 ); -if (!IS_ERR (new_ns)) - new_ns->parent =get_pid_ns (old_ns); + new_ns =create_pid_namespace (old_ns); out_put:put_pid_ns (old_ns);
Signature · 1 line
1.5.6.5
Re: [PATCH 07/38] pidns 1/2: make create_pid_namespace() accept parent pidns
Quoted 5 lines · Alexey Dobriyan
create_pid_namespace()creates everything, but caller has to assign parent pidns by hand, which is unnatural. At the moment of call new ->level has to be taken from somewhere and parent pidns is already available.Signed-off-by Alexey Dobriyan <[email protected]>
Nice cleanup!
Quoted 47 lines
---
kernel/pid_namespace.c| 8 ++++----1 files changed, 4 insertions(+), 4 deletions(-)kernel/pid_namespace.c +4
-4@@ -67,9 +67,10 @@ err_alloc:return NULL ; } -static struct pid_namespace *create_pid_namespace (unsigned int level) +static struct pid_namespace *create_pid_namespace (struct pid_namespace *parent_pid_ns) {struct pid_namespace *ns; +unsigned int level = parent_pid_ns->level +1 ;int i; ns =kmem_cache_zalloc (pid_ns_cachep,GFP_KERNEL );@@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_namespace(unsigned int level)kref_init (&ns->kref); ns->level = level; + ns->parent =get_pid_ns (parent_pid_ns);set_bit (0 , ns->pidmap[0 ].page);atomic_set (&ns->pidmap[0 ].nr_free,BITS_PER_PAGE -1 );@@ -125,9 +127,7 @@ struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *oldif (flags &CLONE_THREAD ) goto out_put; - new_ns =create_pid_namespace (old_ns->level +1 ); -if (!IS_ERR (new_ns)) - new_ns->parent =get_pid_ns (old_ns); + new_ns =create_pid_namespace (old_ns);
out_put:put_pid_ns(old_ns);Signature · 7 lines
1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
A message that is not in the archive (sent off-list or not yet received): 1242968132-1044-7-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Amerigo Wang
Reviewed-byRe: [PATCH 07/38] pidns 1/2: make create_pid_namespace() accept parent pidns
Quoted 5 lines · Alexey Dobriyan
create_pid_namespace()creates everything, but caller has to assign parent pidns by hand, which is unnatural. At the moment of call new ->level has to be taken from somewhere and parent pidns is already available.Signed-off-by Alexey Dobriyan <[email protected]>
Nice cleanup!
Quoted 47 lines
---
kernel/pid_namespace.c| 8 ++++----1 files changed, 4 insertions(+), 4 deletions(-)kernel/pid_namespace.c +4
-4@@ -67,9 +67,10 @@ err_alloc:return NULL ; } -static struct pid_namespace *create_pid_namespace (unsigned int level) +static struct pid_namespace *create_pid_namespace (struct pid_namespace *parent_pid_ns) {struct pid_namespace *ns; +unsigned int level = parent_pid_ns->level +1 ;int i; ns =kmem_cache_zalloc (pid_ns_cachep,GFP_KERNEL );@@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_namespace(unsigned int level)kref_init (&ns->kref); ns->level = level; + ns->parent =get_pid_ns (parent_pid_ns);set_bit (0 , ns->pidmap[0 ].page);atomic_set (&ns->pidmap[0 ].nr_free,BITS_PER_PAGE -1 );@@ -125,9 +127,7 @@ struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *oldif (flags &CLONE_THREAD ) goto out_put; - new_ns =create_pid_namespace (old_ns->level +1 ); -if (!IS_ERR (new_ns)) - new_ns->parent =get_pid_ns (old_ns); + new_ns =create_pid_namespace (old_ns);
out_put:put_pid_ns(old_ns);Signature · 7 lines
1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Serge E. Hallyn
Reviewed-by Serge HallynRe: [PATCH 07/38] pidns 1/2: make create_pid_namespace() accept parent pidns
In reply to a message not in the archiveQuoted 5 lines · Alexey Dobriyan
create_pid_namespace()creates everything, but caller has to assign parent pidns by hand, which is unnatural. At the moment of call new ->level has to be taken from somewhere and parent pidns is already available.Signed-off-by Alexey Dobriyan <[email protected]>
(I actually did so on both this and the next one, which are both quite nice, on May 08)
Quoted 46 lines
--- kernel/pid_namespace.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)kernel/pid_namespace.c +4
-4@@ -67,9 +67,10 @@ err_alloc:return NULL ; } -static struct pid_namespace *create_pid_namespace (unsigned int level) +static struct pid_namespace *create_pid_namespace (struct pid_namespace *parent_pid_ns) {struct pid_namespace *ns; +unsigned int level = parent_pid_ns->level +1 ;int i; ns =kmem_cache_zalloc (pid_ns_cachep,GFP_KERNEL );@@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_namespace(unsigned int level)kref_init (&ns->kref); ns->level = level; + ns->parent =get_pid_ns (parent_pid_ns);set_bit (0 , ns->pidmap[0 ].page);atomic_set (&ns->pidmap[0 ].nr_free,BITS_PER_PAGE -1 );@@ -125,9 +127,7 @@ struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *oldif (flags &CLONE_THREAD ) goto out_put; - new_ns =create_pid_namespace (old_ns->level +1 ); -if (!IS_ERR (new_ns)) - new_ns->parent =get_pid_ns (old_ns); + new_ns =create_pid_namespace (old_ns); out_put:put_pid_ns (old_ns);Signature · 6 lines
1.5.6.5 _______________________________________________ Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org https://lists.linux-foundation.org/mailman/listinfo/containers
Sukadev Bhattiprolu
Acked-byRe: [PATCH 07/38] pidns 1/2: make create_pid_namespace() accept parent pidns
In reply to a message not in the archiveQuoted 5 lines · Alexey Dobriyan
create_pid_namespace()creates everything, but caller has to assign parent pidns by hand, which is unnatural. At the moment of call new ->level has to be taken from somewhere and parent pidns is already available.Signed-off-by Alexey Dobriyan <[email protected]>
Quoted 39 lines
--- kernel/pid_namespace.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)kernel/pid_namespace.c +4
-4@@ -67,9 +67,10 @@ err_alloc:return NULL ; } -static struct pid_namespace *create_pid_namespace (unsigned int level) +static struct pid_namespace *create_pid_namespace (struct pid_namespace *parent_pid_ns) {struct pid_namespace *ns; +unsigned int level = parent_pid_ns->level +1 ;int i; ns =kmem_cache_zalloc (pid_ns_cachep,GFP_KERNEL );@@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_namespace(unsigned int level)kref_init (&ns->kref); ns->level = level; + ns->parent =get_pid_ns (parent_pid_ns);set_bit (0 , ns->pidmap[0 ].page);atomic_set (&ns->pidmap[0 ].nr_free,BITS_PER_PAGE -1 );@@ -125,9 +127,7 @@ struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *oldif (flags &CLONE_THREAD ) goto out_put; - new_ns =create_pid_namespace (old_ns->level +1 ); -if (!IS_ERR (new_ns)) - new_ns->parent =get_pid_ns (old_ns); + new_ns =create_pid_namespace (old_ns); out_put:put_pid_ns (old_ns);
Re: [PATCH 07/38] pidns 1/2: make create_pid_namespace() accept parent pidns
In reply to Alexey DobriyanQuoted 5 lines · Alexey Dobriyan
create_pid_namespace()creates everything, but caller has to assign parent pidns by hand, which is unnatural. At the moment of call new ->level has to be taken from somewhere and parent pidns is already available.Signed-off-by Alexey Dobriyan <[email protected]>
(I actually did so on both this and the next one, which are both quite nice, on May 08)
Quoted 46 lines
--- kernel/pid_namespace.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)kernel/pid_namespace.c +4
-4@@ -67,9 +67,10 @@ err_alloc:return NULL ; } -static struct pid_namespace *create_pid_namespace (unsigned int level) +static struct pid_namespace *create_pid_namespace (struct pid_namespace *parent_pid_ns) {struct pid_namespace *ns; +unsigned int level = parent_pid_ns->level +1 ;int i; ns =kmem_cache_zalloc (pid_ns_cachep,GFP_KERNEL );@@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_namespace(unsigned int level)kref_init (&ns->kref); ns->level = level; + ns->parent =get_pid_ns (parent_pid_ns);set_bit (0 , ns->pidmap[0 ].page);atomic_set (&ns->pidmap[0 ].nr_free,BITS_PER_PAGE -1 );@@ -125,9 +127,7 @@ struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *oldif (flags &CLONE_THREAD ) goto out_put; - new_ns =create_pid_namespace (old_ns->level +1 ); -if (!IS_ERR (new_ns)) - new_ns->parent =get_pid_ns (old_ns); + new_ns =create_pid_namespace (old_ns); out_put:put_pid_ns (old_ns);Signature · 6 lines
1.5.6.5 _______________________________________________ Containers mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [PATCH 07/38] pidns 1/2: make create_pid_namespace() accept parent pidns
In reply to Alexey DobriyanQuoted 5 lines · Alexey Dobriyan
create_pid_namespace()creates everything, but caller has to assign parent pidns by hand, which is unnatural. At the moment of call new ->level has to be taken from somewhere and parent pidns is already available.Signed-off-by Alexey Dobriyan <[email protected]>
Quoted 39 lines
--- kernel/pid_namespace.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)kernel/pid_namespace.c +4
-4@@ -67,9 +67,10 @@ err_alloc:return NULL ; } -static struct pid_namespace *create_pid_namespace (unsigned int level) +static struct pid_namespace *create_pid_namespace (struct pid_namespace *parent_pid_ns) {struct pid_namespace *ns; +unsigned int level = parent_pid_ns->level +1 ;int i; ns =kmem_cache_zalloc (pid_ns_cachep,GFP_KERNEL );@@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_namespace(unsigned int level)kref_init (&ns->kref); ns->level = level; + ns->parent =get_pid_ns (parent_pid_ns);set_bit (0 , ns->pidmap[0 ].page);atomic_set (&ns->pidmap[0 ].nr_free,BITS_PER_PAGE -1 );@@ -125,9 +127,7 @@ struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *oldif (flags &CLONE_THREAD ) goto out_put; - new_ns =create_pid_namespace (old_ns->level +1 ); -if (!IS_ERR (new_ns)) - new_ns->parent =get_pid_ns (old_ns); + new_ns =create_pid_namespace (old_ns); out_put:put_pid_ns (old_ns);
PATCH 8/38 pidns 2/2: rewrite copy_pid_ns()
In reply to Alexey Dobriyancopy_pid_ns() is a perfect example of a case where unwinding leads to more code and makes it less clear. Watch the diffstat.
--- kernel/pid_namespace.c | 18 +++--------------- 1 files changed, 3 insertions(+), 15 deletions(-)
kernel/pid_namespace.c +3 -15
@@ -116,23 +116,11 @@ static void destroy_pid_namespace(struct pid_namespace *ns)struct pid_namespace *copy_pid_ns (unsigned long flags,struct pid_namespace *old_ns) { -struct pid_namespace *new_ns; - -BUG_ON (!old_ns); - new_ns =get_pid_ns (old_ns);if (!(flags &CLONE_NEWPID )) - goto out; - - new_ns =ERR_PTR (-EINVAL ); +return get_pid_ns (old_ns);if (flags &CLONE_THREAD ) - goto out_put; - - new_ns =create_pid_namespace (old_ns); - -out_put: -put_pid_ns (old_ns); -out: -return new_ns; +return ERR_PTR (-EINVAL ); +return create_pid_namespace (old_ns); }void free_pid_ns (struct kref *kref)
Signature · 1 line
1.5.6.5
Re: [PATCH 08/38] pidns 2/2: rewrite copy_pid_ns()
Quoted 3 lines · Alexey Dobriyan
copy_pid_ns()is a perfect example of a case where unwinding leads to more code and makes it less clear. Watch the diffstat.
Fully agreed...
Quoted 1 line
Signed-off-by Alexey Dobriyan <[email protected]>
Btw, which tree is this patch against? Looks like not linus-tree.
Quoted 43 lines
---
kernel/pid_namespace.c| 18 +++---------------1 files changed, 3 insertions(+), 15 deletions(-)kernel/pid_namespace.c +3
-15@@ -116,23 +116,11 @@ static void destroy_pid_namespace(struct pid_namespace *ns)struct pid_namespace *copy_pid_ns (unsigned long flags,struct pid_namespace *old_ns) { -struct pid_namespace *new_ns; - -BUG_ON (!old_ns); - new_ns =get_pid_ns (old_ns);if (!(flags &CLONE_NEWPID )) - goto out; - - new_ns =ERR_PTR (-EINVAL ); +return get_pid_ns (old_ns);if (flags &CLONE_THREAD ) - goto out_put; - - new_ns =create_pid_namespace (old_ns); - -out_put: -put_pid_ns (old_ns); -out: -return new_ns; +return ERR_PTR (-EINVAL ); +return create_pid_namespace (old_ns); }void free_pid_ns (struct kref *kref)Signature · 7 lines
1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
A message that is not in the archive (sent off-list or not yet received): 1242968132-1044-8-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Amerigo Wang
Reviewed-byRe: [PATCH 08/38] pidns 2/2: rewrite copy_pid_ns()
Quoted 3 lines · Alexey Dobriyan
copy_pid_ns()is a perfect example of a case where unwinding leads to more code and makes it less clear. Watch the diffstat.
Fully agreed...
Quoted 1 line
Signed-off-by Alexey Dobriyan <[email protected]>
Btw, which tree is this patch against? Looks like not linus-tree.
Quoted 43 lines
---
kernel/pid_namespace.c| 18 +++---------------1 files changed, 3 insertions(+), 15 deletions(-)kernel/pid_namespace.c +3
-15@@ -116,23 +116,11 @@ static void destroy_pid_namespace(struct pid_namespace *ns)struct pid_namespace *copy_pid_ns (unsigned long flags,struct pid_namespace *old_ns) { -struct pid_namespace *new_ns; - -BUG_ON (!old_ns); - new_ns =get_pid_ns (old_ns);if (!(flags &CLONE_NEWPID )) - goto out; - - new_ns =ERR_PTR (-EINVAL ); +return get_pid_ns (old_ns);if (flags &CLONE_THREAD ) - goto out_put; - - new_ns =create_pid_namespace (old_ns); - -out_put: -put_pid_ns (old_ns); -out: -return new_ns; +return ERR_PTR (-EINVAL ); +return create_pid_namespace (old_ns); }void free_pid_ns (struct kref *kref)Signature · 7 lines
1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Serge E. Hallyn
Reviewed-by Serge HallynRe: [PATCH 08/38] pidns 2/2: rewrite copy_pid_ns()
In reply to a message not in the archiveQuoted 4 lines · Alexey Dobriyan
copy_pid_ns()is a perfect example of a case where unwinding leads to more code and makes it less clear. Watch the diffstat.Signed-off-by Alexey Dobriyan <[email protected]>
Quoted 42 lines
--- kernel/pid_namespace.c | 18 +++--------------- 1 files changed, 3 insertions(+), 15 deletions(-)kernel/pid_namespace.c +3
-15@@ -116,23 +116,11 @@ static void destroy_pid_namespace(struct pid_namespace *ns)struct pid_namespace *copy_pid_ns (unsigned long flags,struct pid_namespace *old_ns) { -struct pid_namespace *new_ns; - -BUG_ON (!old_ns); - new_ns =get_pid_ns (old_ns);if (!(flags &CLONE_NEWPID )) - goto out; - - new_ns =ERR_PTR (-EINVAL ); +return get_pid_ns (old_ns);if (flags &CLONE_THREAD ) - goto out_put; - - new_ns =create_pid_namespace (old_ns); - -out_put: -put_pid_ns (old_ns); -out: -return new_ns; +return ERR_PTR (-EINVAL ); +return create_pid_namespace (old_ns); }void free_pid_ns (struct kref *kref)Signature · 6 lines
1.5.6.5 _______________________________________________ Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org https://lists.linux-foundation.org/mailman/listinfo/containers
Sukadev Bhattiprolu
Acked-byRe: [PATCH 08/38] pidns 2/2: rewrite copy_pid_ns()
In reply to a message not in the archiveQuoted 4 lines · Alexey Dobriyan
copy_pid_ns()is a perfect example of a case where unwinding leads to more code and makes it less clear. Watch the diffstat.Signed-off-by Alexey Dobriyan <[email protected]>
Quoted 35 lines
--- kernel/pid_namespace.c | 18 +++--------------- 1 files changed, 3 insertions(+), 15 deletions(-)kernel/pid_namespace.c +3
-15@@ -116,23 +116,11 @@ static void destroy_pid_namespace(struct pid_namespace *ns)struct pid_namespace *copy_pid_ns (unsigned long flags,struct pid_namespace *old_ns) { -struct pid_namespace *new_ns; - -BUG_ON (!old_ns); - new_ns =get_pid_ns (old_ns);if (!(flags &CLONE_NEWPID )) - goto out; - - new_ns =ERR_PTR (-EINVAL ); +return get_pid_ns (old_ns);if (flags &CLONE_THREAD ) - goto out_put; - - new_ns =create_pid_namespace (old_ns); - -out_put: -put_pid_ns (old_ns); -out: -return new_ns; +return ERR_PTR (-EINVAL ); +return create_pid_namespace (old_ns); }void free_pid_ns (struct kref *kref)
Re: [PATCH 08/38] pidns 2/2: rewrite copy_pid_ns()
In reply to Alexey DobriyanQuoted 4 lines · Alexey Dobriyan
copy_pid_ns()is a perfect example of a case where unwinding leads to more code and makes it less clear. Watch the diffstat.Signed-off-by Alexey Dobriyan <[email protected]>
Quoted 42 lines
--- kernel/pid_namespace.c | 18 +++--------------- 1 files changed, 3 insertions(+), 15 deletions(-)kernel/pid_namespace.c +3
-15@@ -116,23 +116,11 @@ static void destroy_pid_namespace(struct pid_namespace *ns)struct pid_namespace *copy_pid_ns (unsigned long flags,struct pid_namespace *old_ns) { -struct pid_namespace *new_ns; - -BUG_ON (!old_ns); - new_ns =get_pid_ns (old_ns);if (!(flags &CLONE_NEWPID )) - goto out; - - new_ns =ERR_PTR (-EINVAL ); +return get_pid_ns (old_ns);if (flags &CLONE_THREAD ) - goto out_put; - - new_ns =create_pid_namespace (old_ns); - -out_put: -put_pid_ns (old_ns); -out: -return new_ns; +return ERR_PTR (-EINVAL ); +return create_pid_namespace (old_ns); }void free_pid_ns (struct kref *kref)Signature · 6 lines
1.5.6.5 _______________________________________________ Containers mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [PATCH 08/38] pidns 2/2: rewrite copy_pid_ns()
In reply to Alexey DobriyanQuoted 4 lines · Alexey Dobriyan
copy_pid_ns()is a perfect example of a case where unwinding leads to more code and makes it less clear. Watch the diffstat.Signed-off-by Alexey Dobriyan <[email protected]>
Quoted 35 lines
--- kernel/pid_namespace.c | 18 +++--------------- 1 files changed, 3 insertions(+), 15 deletions(-)kernel/pid_namespace.c +3
-15@@ -116,23 +116,11 @@ static void destroy_pid_namespace(struct pid_namespace *ns)struct pid_namespace *copy_pid_ns (unsigned long flags,struct pid_namespace *old_ns) { -struct pid_namespace *new_ns; - -BUG_ON (!old_ns); - new_ns =get_pid_ns (old_ns);if (!(flags &CLONE_NEWPID )) - goto out; - - new_ns =ERR_PTR (-EINVAL ); +return get_pid_ns (old_ns);if (flags &CLONE_THREAD ) - goto out_put; - - new_ns =create_pid_namespace (old_ns); - -out_put: -put_pid_ns (old_ns); -out: -return new_ns; +return ERR_PTR (-EINVAL ); +return create_pid_namespace (old_ns); }void free_pid_ns (struct kref *kref)
PATCH 9/38 netns 1/2: don't get/put old netns on CLONE_NEWNET
In reply to Alexey Dobriyancopy_net_ns() doesn't copy anything, it creates fresh netns, so get/put of old netns isn't needed.
--- net/core/net_namespace.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)
net/core/net_namespace.c +1 -4
@@ -120,10 +120,8 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net)struct net *new_net =NULL ;int err; -get_net (old_net); -if (!(flags &CLONE_NEWNET )) -return old_net; +return get_net (old_net); err = -ENOMEM ; new_net =net_alloc ();
@@ -142,7 +140,6 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net)if (err) goto out_free; out: -put_net (old_net);return new_net; out_free:
Signature · 1 line
1.5.6.5
A message that is not in the archive (sent off-list or not yet received): 1242968132-1044-9-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
David Miller
Acked-byRe: [PATCH 09/38] netns 1/2: don't get/put old netns on CLONE_NEWNET
From: Alexey Dobriyan <[email protected]>
Date: Fri, 22 May 2009 08:55:03 +0400
Quoted 5 lines
copy_net_ns()doesn't copy anything, it creates fresh netns, so get/put of old netns isn't needed.Signed-off-by Alexey Dobriyan <[email protected]>
Re: [PATCH 09/38] netns 1/2: don't get/put old netns on CLONE_NEWNET
In reply to Alexey DobriyanFrom: Alexey Dobriyan <[email protected]>
Date: Fri, 22 May 2009 08:55:03 +0400
Quoted 5 lines
copy_net_ns()doesn't copy anything, it creates fresh netns, so get/put of old netns isn't needed.Signed-off-by Alexey Dobriyan <[email protected]>Acked-by Serge Hallyn <[email protected]>
PATCH 10/38 netns 2/2: extract net_create()
In reply to Alexey Dobriyannet_create() will be used by C/R to create fresh netns on restart.
--- net/core/net_namespace.c | 44 ++++++++++++++++++++------------------------ 1 files changed, 20 insertions(+), 24 deletions(-)
net/core/net_namespace.c +20 -24
@@ -115,38 +115,34 @@ static void net_free(struct net *net)kmem_cache_free (net_cachep, net); } -struct net *copy_net_ns (unsigned long flags,struct net *old_net) +static struct net *net_create (void ) { -struct net *new_net =NULL ; -int err; - -if (!(flags &CLONE_NEWNET )) -return get_net (old_net); - - err = -ENOMEM ; - new_net =net_alloc (); -if (!new_net) - goto out_err; +struct net *net; +int rv; + net =net_alloc (); +if (!net) +return ERR_PTR (-ENOMEM );mutex_lock (&net_mutex); - err =setup_net (new_net); -if (!err) { + rv =setup_net (net); +if (rv ==0 ) {rtnl_lock (); -list_add_tail (&new_net->list, &net_namespace_list); +list_add_tail (&net->list, &net_namespace_list);rtnl_unlock (); }mutex_unlock (&net_mutex); +if (rv <0 ) { +net_free (net); +return ERR_PTR (rv); + } +return net; +} -if (err) - goto out_free; -out: -return new_net; - -out_free: -net_free (new_net); -out_err: - new_net =ERR_PTR (err); - goto out; +struct net *copy_net_ns (unsigned long flags,struct net *old_net) +{ +if (!(flags &CLONE_NEWNET )) +return get_net (old_net); +return net_create (); }static void cleanup_net (struct work_struct *work)
Signature · 1 line
1.5.6.5
Re: [PATCH 10/38] netns 2/2: extract net_create()
From: Alexey Dobriyan <[email protected]>
Date: Fri, 22 May 2009 08:55:04 +0400
Quoted 4 lines
net_create()will be used by C/R to create fresh netns on restart.Signed-off-by Alexey Dobriyan <[email protected]>
PATCH 11/38 nsproxy: extract create_nsproxy()
In reply to Alexey Dobriyanclone_nsproxy() does useless copying of old nsproxy -- every pointer will be rewritten to new ns or to old ns. Remove copying, rename clone_nsproxy(), create_nsproxy() will be used by C/R code to create fresh nsproxy on restart.
--- kernel/nsproxy.c | 19 +++++++------------ 1 files changed, 7 insertions(+), 12 deletions(-)
kernel/nsproxy.c +7 -12
@@ -26,19 +26,14 @@ static struct kmem_cache *nsproxy_cachep;struct nsproxy init_nsproxy =INIT_NSPROXY (init_nsproxy); -/* -* creates a copy of "orig" with refcount 1. -*/ -static inline struct nsproxy *clone_nsproxy (struct nsproxy *orig) +static inline struct nsproxy *create_nsproxy (void ) { -struct nsproxy *ns; +struct nsproxy *nsproxy; - ns =kmem_cache_alloc (nsproxy_cachep,GFP_KERNEL ); -if (ns) { -memcpy (ns, orig,sizeof (struct nsproxy )); -atomic_set (&ns->count,1 ); - } -return ns; + nsproxy =kmem_cache_alloc (nsproxy_cachep,GFP_KERNEL ); +if (nsproxy) +atomic_set (&nsproxy->count,1 ); +return nsproxy; }/*
@@ -52,7 +47,7 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,struct nsproxy *new_nsp;int err; - new_nsp =clone_nsproxy (tsk->nsproxy); + new_nsp =create_nsproxy ();if (!new_nsp)return ERR_PTR (-ENOMEM );
Signature · 1 line
1.5.6.5
PATCH 12/38 i386: ifdef out struct thread_struct::fs
In reply to Alexey DobriyanAfter commit 464d1a78fbf8cf6c7fd970e7b3e2db50a320ce28 aka "[PATCH] i386: Convert i386 PDA code to use %fs"
%fs saved during context switch moved from thread_struct to pt_regs and value on thread_struct became unused.
I don't understand why .fs (OK, .gs first) initializer was added, kernel clearly stopped touching it after the patch.
--- arch/x86/include/asm/processor.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/include/asm/processor.h +2 -1
@@ -428,7 +428,9 @@ struct thread_struct {unsigned short gsindex;#endif unsigned long ip; +#ifdef CONFIG_X86_64 unsigned long fs; +#endif unsigned long gs;/* Hardware debugging registers: */ unsigned long debugreg0;
@@ -874,7 +876,6 @@ static inline void spin_lock_prefetch(const void *x) .vm86_info = NULL, \ .sysenter_cs = __KERNEL_CS, \ .io_bitmap_ptr = NULL, \ - .fs = __KERNEL_PERCPU, \ }/*
Signature · 1 line
1.5.6.5
PATCH 13/38 x86_64: ifdef out struct thread_struct::ip
In reply to Alexey Dobriyanstruct thread_struct::ip isn't used on x86_64, struct pt_regs::ip is used instead.
kgdb should be reading 0 always, but I can't check it.
--- arch/x86/include/asm/processor.h | 2 ++ arch/x86/kernel/kgdb.c | 2 +- 2 files changed, 3 insertions(+), 1 deletions(-)
arch/x86/include/asm/processor.h +2 -0
@@ -427,7 +427,9 @@ struct thread_struct {unsigned short fsindex;unsigned short gsindex;#endif +#ifdef CONFIG_X86_32 unsigned long ip; +#endif #ifdef CONFIG_X86_64 unsigned long fs;#endif
arch/x86/kernel/kgdb.c +1 -1
@@ -142,7 +142,7 @@ void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p) gdb_regs32[GDB_PS ] = *(unsigned long *)(p->thread.sp +8 ); gdb_regs32[GDB_CS ] = __KERNEL_CS; gdb_regs32[GDB_SS ] = __KERNEL_DS; - gdb_regs[GDB_PC ] = p->thread.ip; + gdb_regs[GDB_PC ] =0 ; gdb_regs[GDB_R8 ] =0 ; gdb_regs[GDB_R9 ] =0 ; gdb_regs[GDB_R10 ] =0 ;
Signature · 1 line
1.5.6.5
PATCH 14/38 Remove struct mm_struct::exe_file et al
In reply to Alexey DobriyanCommit 925d1c401fa6cfd0df5d2e37da8981494ccdec07 aka "procfs task exe symlink". introduced struct mm_struct::exe_file and struct mm_struct::num_exe_file_vmas.
The rationale is weak: unifying MMU and no-MMU version of /proc/*/exe code. For this a) struct mm_struct becomes bigger, b) mmap/munmap/exit become slower,
c) patch adds more code than removes in fact.
After commit 8feae13110d60cc6287afabc2887366b0eb226c2 aka "NOMMU: Make VMAs per MM as for MMU-mode linux" no-MMU kernels also maintain list of VMAs in ->mmap, so we can switch back for MMU version of /proc/*/exe.
This also helps C/R, no need to save and restore ->exe_file and to count additional references to check if there is a leak of struct file outside group of checkpointed resources.
--- fs/exec.c | 2 - fs/proc/base.c | 105 +++++++++++++--------------------------------- include/linux/mm.h | 12 ----- include/linux/mm_types.h | 6 --- include/linux/proc_fs.h | 20 --------- kernel/fork.c | 3 - mm/mmap.c | 22 ++-------- mm/nommu.c | 16 +------ 8 files changed, 36 insertions(+), 150 deletions(-)
fs/exec.c +0 -2
@@ -938,8 +938,6 @@ int flush_old_exec(struct linux_binprm * bprm)if (retval) goto out; -set_mm_exe_file (bprm->mm, bprm->file); -/* * Release all of the old mmap stuff */
fs/proc/base.c +30 -75
117 lines not on this page · raw message
include/linux/mm.h +0 -12
@@ -1121,18 +1121,6 @@ extern void exit_mmap(struct mm_struct *);extern int mm_take_all_locks (struct mm_struct *mm);extern void mm_drop_all_locks (struct mm_struct *mm); -#ifdef CONFIG_PROC_FS -/* From fs/proc/base.c. callers must _not_ hold the mm's exe_file_lock */ -extern void added_exe_file_vma (struct mm_struct *mm); -extern void removed_exe_file_vma (struct mm_struct *mm); -#else -static inline void added_exe_file_vma (struct mm_struct *mm) -{} - -static inline void removed_exe_file_vma (struct mm_struct *mm) -{} -#endif /* CONFIG_PROC_FS */ -extern int may_expand_vm (struct mm_struct *mm,unsigned long npages); extern int install_special_mapping(struct mm_struct *mm, unsigned long addr, unsigned long len,
include/linux/mm_types.h +0 -6
@@ -269,12 +269,6 @@ struct mm_struct {*/ struct task_struct *owner;#endif - -#ifdef CONFIG_PROC_FS -/* store ref to file /proc/<pid>/exe symlink points to */ -struct file *exe_file; -unsigned long num_exe_file_vmas; -#endif #ifdef CONFIG_MMU_NOTIFIER struct mmu_notifier_mm *mmu_notifier_mm;#endif
include/linux/proc_fs.h +0 -20
@@ -188,12 +188,6 @@ extern void proc_net_remove(struct net *net, const char *name);extern struct proc_dir_entry *proc_net_mkdir (struct net *net,const char *name,struct proc_dir_entry *parent); -/* While the {get|set|dup}_mm_exe_file functions are for mm_structs, they are -* only needed to implement /proc/<pid>|self/exe so we define them here. */ -extern void set_mm_exe_file (struct mm_struct *mm,struct file *new_exe_file); -extern struct file *get_mm_exe_file (struct mm_struct *mm); -extern void dup_mm_exe_file (struct mm_struct *oldmm,struct mm_struct *newmm); -#else #define proc_net_fops_create (net, name, mode, fops) ({ (void)(mode), NULL; })
@@ -240,20 +234,6 @@ static inline int pid_ns_prepare_proc(struct pid_namespace *ns)static inline void pid_ns_release_proc (struct pid_namespace *ns) { } - -static inline void set_mm_exe_file (struct mm_struct *mm, -struct file *new_exe_file) -{} - -static inline struct file *get_mm_exe_file (struct mm_struct *mm) -{ -return NULL ; -} - -static inline void dup_mm_exe_file (struct mm_struct *oldmm, -struct mm_struct *newmm) -{} -#endif /* CONFIG_PROC_FS */ #if !defined(CONFIG_PROC_KCORE )
kernel/fork.c +0 -3
@@ -488,7 +488,6 @@ void mmput(struct mm_struct *mm)if (atomic_dec_and_test (&mm->mm_users)) {exit_aio (mm);exit_mmap (mm); -set_mm_exe_file (mm,NULL );if (!list_empty (&mm->mmlist)) {spin_lock (&mmlist_lock);list_del (&mm->mmlist);
@@ -611,8 +610,6 @@ struct mm_struct *dup_mm(struct task_struct *tsk)if (init_new_context (tsk, mm)) goto fail_nocontext; -dup_mm_exe_file (oldmm, mm); - err =dup_mmap (mm, oldmm);if (err) goto free_pt;
mm/mmap.c +4 -18
@@ -232,11 +232,8 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)might_sleep ();if (vma->vm_ops && vma->vm_ops->close) vma->vm_ops->close (vma); -if (vma->vm_file) { +if (vma->vm_file)fput (vma->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -removed_exe_file_vma (vma->vm_mm); - }mpol_put (vma_policy (vma));kmem_cache_free (vm_area_cachep, vma);return next;
@@ -633,11 +630,8 @@ again: remove_next = 1 + (end > next->vm_end);spin_unlock (&mapping->i_mmap_lock);if (remove_next) { -if (file) { +if (file)fput (file); -if (next->vm_flags &VM_EXECUTABLE ) -removed_exe_file_vma (mm); - } mm->map_count--;mpol_put (vma_policy (next));kmem_cache_free (vm_area_cachep, next);
@@ -1192,8 +1186,6 @@ munmap_back: error = file->f_op->mmap (file, vma);if (error) goto unmap_and_free_vma; -if (vm_flags &VM_EXECUTABLE ) -added_exe_file_vma (mm); }else if (vm_flags &VM_SHARED ) { error =shmem_zero_setup (vma);if (error)
@@ -1849,11 +1841,8 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma, }vma_set_policy (new, pol); -if (new->vm_file) { +if (new->vm_file)get_file (new->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -added_exe_file_vma (mm); - }if (new->vm_ops && new->vm_ops->open) new->vm_ops->open (new);
@@ -2200,11 +2189,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, new_vma->vm_start = addr; new_vma->vm_end = addr + len; new_vma->vm_pgoff = pgoff; -if (new_vma->vm_file) { +if (new_vma->vm_file)get_file (new_vma->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -added_exe_file_vma (mm); - }if (new_vma->vm_ops && new_vma->vm_ops->open) new_vma->vm_ops->open (new_vma);vma_link (mm, new_vma, prev, rb_link, rb_parent);
mm/nommu.c +2 -14
@@ -721,11 +721,8 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)kenter ("%p" , vma);if (vma->vm_ops && vma->vm_ops->close) vma->vm_ops->close (vma); -if (vma->vm_file) { +if (vma->vm_file)fput (vma->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -removed_exe_file_vma (mm); - }put_nommu_region (vma->vm_region);kmem_cache_free (vm_area_cachep, vma); }
@@ -1218,10 +1215,6 @@ unsigned long do_mmap_pgoff(struct file *file,get_file (file); vma->vm_file = file;get_file (file); -if (vm_flags &VM_EXECUTABLE ) { -added_exe_file_vma (current->mm); - vma->vm_mm = current->mm; - } }down_write (&nommu_region_sem);
@@ -1359,11 +1352,8 @@ share: error_put_region:__put_nommu_region (region);if (vma) { -if (vma->vm_file) { +if (vma->vm_file)fput (vma->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -removed_exe_file_vma (vma->vm_mm); - }kmem_cache_free (vm_area_cachep, vma); }kleave (" = %d [pr]" , ret);
@@ -1375,8 +1365,6 @@ error:fput (region->vm_file);kmem_cache_free (vm_region_jar, region);fput (vma->vm_file); -if (vma->vm_flags &VM_EXECUTABLE ) -removed_exe_file_vma (vma->vm_mm);kmem_cache_free (vm_area_cachep, vma);kleave (" = %d" , ret);return ret;
Signature · 1 line
1.5.6.5
PATCH 15/38 dcache: extract and use d_unlinked()
In reply to Alexey Dobriyand_unlinked() will be used in middle-term to ban checkpointing when opened but unlinked file is detected, and in long term, to detect such situation and special case on it.
--- fs/dcache.c | 7 +++---- fs/namespace.c | 8 ++++---- include/linux/dcache.h | 5 +++++ 3 files changed, 12 insertions(+), 8 deletions(-)
fs/dcache.c +3 -4
@@ -1910,7 +1910,7 @@ char *__d_path(const struct path *path, struct path *root,spin_lock (&vfsmount_lock);prepend (&end, &buflen,"\0" ,1 ); -if (!IS_ROOT (dentry) &&d_unhashed (dentry) && +if (d_unlinked (dentry) && (prepend (&end, &buflen," (deleted)" ,10 ) !=0 )) goto Elong;
@@ -2035,7 +2035,7 @@ char *dentry_path(struct dentry *dentry, char *buf, int buflen)spin_lock (&dcache_lock);prepend (&end, &buflen,"\0" ,1 ); -if (!IS_ROOT (dentry) &&d_unhashed (dentry) && +if (d_unlinked (dentry) && (prepend (&end, &buflen,"//deleted" ,9 ) !=0 )) goto Elong;if (buflen <1 )
@@ -2097,9 +2097,8 @@ SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size)read_unlock (¤t->fs->lock); error = -ENOENT ; -/* Has the current directory has been unlinked? */ spin_lock (&dcache_lock); -if (IS_ROOT (pwd.dentry) || !d_unhashed (pwd.dentry)) { +if (!d_unlinked (pwd.dentry)) {unsigned long len;struct path tmp = root;char * cwd;
fs/namespace.c +4 -4
@@ -1430,7 +1430,7 @@ static int graft_tree(struct vfsmount *mnt, struct path *path) goto out_unlock; err = -ENOENT ; -if (IS_ROOT (path->dentry) || !d_unhashed (path->dentry)) +if (!d_unlinked (path->dentry)) err =attach_recursive_mnt (mnt, path,NULL ); out_unlock:mutex_unlock (&path->dentry->d_inode->i_mutex);
@@ -1612,7 +1612,7 @@ static int do_move_mount(struct path *path, char *old_name)if (IS_DEADDIR (path->dentry->d_inode)) goto out1; -if (!IS_ROOT (path->dentry) &&d_unhashed (path->dentry)) +if (d_unlinked (path->dentry)) goto out1; err = -EINVAL ;
@@ -2175,9 +2175,9 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, error = -ENOENT ;if (IS_DEADDIR (new.dentry->d_inode)) goto out2; -if (d_unhashed (new.dentry) && !IS_ROOT (new.dentry)) +if (d_unlinked (new.dentry)) goto out2; -if (d_unhashed (old.dentry) && !IS_ROOT (old.dentry)) +if (d_unlinked (old.dentry)) goto out2; error = -EBUSY ; if (new.mnt == root.mnt ||
include/linux/dcache.h +5 -0
@@ -351,6 +351,11 @@ static inline int d_unhashed(struct dentry *dentry)return (dentry->d_flags &DCACHE_UNHASHED ); } +static inline int d_unlinked (struct dentry *dentry) +{ +return d_unhashed (dentry) && !IS_ROOT (dentry); +} +static inline struct dentry *dget_parent (struct dentry *dentry) {struct dentry *ret;
Signature · 1 line
1.5.6.5
PATCH 16/38 x86: ptrace debugreg checks rewrite
In reply to Alexey DobriyanThis is a mess.
Pre unified-x86 code did check for breakpoint addr
to be "< TASK_SIZE - 3 (or 7)". This was fine from security POV, but banned valid breakpoint usage when address is close to TASK_SIZE. E. g. 1-byte breakpoint at TASK_SIZE - 1 should be allowed, but it wasn't.
Then came commit 84929801e14d968caeb84795bfbb88f04283fbd9 ("[PATCH] x86_64: TASK_SIZE fixes for compatibility mode processes") which for some reason touched ptrace as well and made effective TASK_SIZE of 32-bit process depending on IA32_PAGE_OFFSET which is not a constant!:
#define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? 0xc0000000 : 0xFFFFe000) ^^^^^^^
Maximum addr for breakpoint became dependent on personality of ptracer.
Commit also relaxed danger zone for 32-bit processes from 8 bytes to 4 not taking into account that 8-byte wide breakpoints are possible even for 32-bit processes. This was fine, however, because 64-bit kernel addresses are too far from 32-bit ones.
Then came utrace with commit 2047b08be67b70875d8765fc81d34ce28041bec3 ("x86: x86 ptrace getreg/putreg merge") which copy-pasted and ifdeffed 32-bit part of TASK_SIZE_OF() leaving 8-byte issue as-is.
So, what patch fixes?
1) Too strict logic near TASK_SIZE boundary -- as long as we don't cross TASK_SIZE_MAX, we're fine.
2) Too smart logic of using breakpoints over non-existent kernel boundary -- we should only protect against setting up after TASK_SIZE_MAX, the rest is none of kernel business. This fixes IA32_PAGE_OFFSET beartrap as well.
As a bonus, remove uberhack and big comment determining DR7 validness, rewrite with clear algorithm when it's obvious what's going on.
Make DR validness checker suitable for C/R. On restart DR registers must be checked the same way they are checked on PTRACE_POKEUSR.
Question 1: TIF_DEBUG can set even if none of breakpoints is turned on, should this be optimized?
Question 2: Breakpoints are allowed to be globally enabled, is this a security risk?
--- arch/x86/kernel/ptrace.c | 175 +++++++++++++++++++++++++++------------------- 1 files changed, 103 insertions(+), 72 deletions(-)
arch/x86/kernel/ptrace.c +103 -72
@@ -135,11 +135,6 @@ static int set_segment_reg(struct task_struct *task, return 0; } -static unsigned long debugreg_addr_limit (struct task_struct *task) -{ -return TASK_SIZE -3 ; -} -#else /* CONFIG_X86_64 */ #define FLAG_MASK (FLAG_MASK_32 | X86_EFLAGS_NT)
@@ -263,16 +258,6 @@ static int set_segment_reg(struct task_struct *task, return 0; } - -static unsigned long debugreg_addr_limit (struct task_struct *task) -{ -#ifdef CONFIG_IA32_EMULATION -if (test_tsk_thread_flag (task,TIF_IA32 )) -return IA32_PAGE_OFFSET -3 ; -#endif -return TASK_SIZE_MAX -7 ; -} -#endif /* CONFIG_X86_32 */ static unsigned long get_flags (struct task_struct *task)
@@ -480,77 +465,123 @@ static unsigned long ptrace_get_debugreg(struct task_struct *child, int n)return 0 ; } +static int ptrace_check_debugreg (int _32bit, +unsigned long dr0,unsigned long dr1, +unsigned long dr2,unsigned long dr3, +unsigned long dr6,unsigned long dr7) +{ +/* Breakpoint type: 00: --x, 01: -w-, 10: undefined, 11: rw- */ +unsigned int rw[4 ]; +/* Breakpoint length: 00: 1 byte, 01: 2 bytes, 10: 8 bytes, 11: 4 bytes */ +unsigned int len[4 ]; +int n; + +if (dr0 >=TASK_SIZE_MAX ) +return -EINVAL ; +if (dr1 >=TASK_SIZE_MAX ) +return -EINVAL ; +if (dr2 >=TASK_SIZE_MAX ) +return -EINVAL ; +if (dr3 >=TASK_SIZE_MAX ) +return -EINVAL ; + +for (n =0 ; n <4 ; n++) { + rw[n] = (dr7 >> (16 + n *4 )) &0x3 ; + len[n] = (dr7 >> (16 + n *4 +2 )) &0x3 ; + +if (rw[n] ==0x2 ) +return -EINVAL ; +if (rw[n] ==0x0 && len[n] !=0x0 ) +return -EINVAL ; +if (_32bit && len[n] ==0x2 ) +return -EINVAL ; + +if (len[n] ==0x0 ) + len[n] =1 ; +else if (len[n] ==0x1 ) + len[n] =2 ; +else if (len[n] ==0x2 ) + len[n] =8 ; +else if (len[n] ==0x3 ) + len[n] =4 ; +/* From now breakpoint length is in bytes. */ + } + +if (dr6 & ~0xFFFFFFFFUL ) +return -EINVAL ; +if (dr7 & ~0xFFFFFFFFUL ) +return -EINVAL ; + +if (dr7 ==0 ) +return 0 ; + +if (dr0 + len[0 ] >TASK_SIZE_MAX ) +return -EINVAL ; +if (dr1 + len[1 ] >TASK_SIZE_MAX ) +return -EINVAL ; +if (dr2 + len[2 ] >TASK_SIZE_MAX ) +return -EINVAL ; +if (dr3 + len[3 ] >TASK_SIZE_MAX ) +return -EINVAL ; + +return 0 ; +} +static int ptrace_set_debugreg (struct task_struct *child,int n,unsigned long data) { -int i; +unsigned long dr0, dr1, dr2, dr3, dr6, dr7; +int _32bit;if (unlikely (n ==4 || n ==5 ))return -EIO ; -if (n <4 &&unlikely (data >=debugreg_addr_limit (child))) -return -EIO ; - + dr0 = child->thread.debugreg0; + dr1 = child->thread.debugreg1; + dr2 = child->thread.debugreg2; + dr3 = child->thread.debugreg3; + dr6 = child->thread.debugreg6; + dr7 = child->thread.debugreg7;switch (n) { -case 0 : child->thread.debugreg0 = data;break ; -case 1 : child->thread.debugreg1 = data;break ; -case 2 : child->thread.debugreg2 = data;break ; -case 3 : child->thread.debugreg3 = data;break ; - +case 0 : + dr0 = data; +break ; +case 1 : + dr1 = data; +break ; +case 2 : + dr2 = data; +break ; +case 3 : + dr3 = data; +break ;case 6 : -if ((data & ~0xffffffffUL ) !=0 ) -return -EIO ; - child->thread.debugreg6 = data; + dr6 = data;break ; -case 7 : -/* -* Sanity-check data. Take one half-byte at once with -* check = (val >> (16 + 4*i)) & 0xf. It contains the -* R/Wi and LENi bits; bits 0 and 1 are R/Wi, and bits -* 2 and 3 are LENi. Given a list of invalid values, -* we do mask |= 1 << invalid_value, so that -* (mask >> check) & 1 is a correct test for invalid -* values. -* -* R/Wi contains the type of the breakpoint / -* watchpoint, LENi contains the length of the watched -* data in the watchpoint case. -* -* The invalid values are: -* - LENi == 0x10 (undefined), so mask |= 0x0f00. [32-bit] -* - R/Wi == 0x10 (break on I/O reads or writes), so -* mask |= 0x4444. -* - R/Wi == 0x00 && LENi != 0x00, so we have mask |= -* 0x1110. -* -* Finally, mask = 0x0f00 | 0x4444 | 0x1110 == 0x5f54. -* -* See the Intel Manual "System Programming Guide", -* 15.2.4 -* -* Note that LENi == 0x10 is defined on x86_64 in long -* mode (i.e. even for 32-bit userspace software, but -* 64-bit kernel), so the x86_64 mask value is 0x5454. -* See the AMD manual no. 24593 (AMD64 System Programming) -*/ -#ifdef CONFIG_X86_32 -#define DR7_MASK 0x5f54 -#else -#define DR7_MASK 0x5554 -#endif - data &= ~DR_CONTROL_RESERVED ; -for (i =0 ; i <4 ; i++) -if ((DR7_MASK >> ((data >> (16 +4 *i)) &0xf )) &1 ) -return -EIO ; - child->thread.debugreg7 = data; -if (data) -set_tsk_thread_flag (child,TIF_DEBUG ); -else -clear_tsk_thread_flag (child,TIF_DEBUG ); + dr7 = data & ~DR_CONTROL_RESERVED ;break ; } + _32bit = (sizeof (unsigned long ) ==4 ); +#ifdef CONFIG_COMPAT +if (test_tsk_thread_flag (child,TIF_IA32 )) + _32bit =1 ; +#endif +if (ptrace_check_debugreg (_32bit, dr0, dr1, dr2, dr3, dr6, dr7)) +return -EIO ; + + child->thread.debugreg0 = dr0; + child->thread.debugreg1 = dr1; + child->thread.debugreg2 = dr2; + child->thread.debugreg3 = dr3; + child->thread.debugreg6 = dr6; + child->thread.debugreg7 = dr7; +if (dr7) +set_tsk_thread_flag (child,TIF_DEBUG ); +else +clear_tsk_thread_flag (child,TIF_DEBUG ); +return 0 ; }
Signature · 1 line
1.5.6.5
A message that is not in the archive (sent off-list or not yet received): 1242968132-1044-16-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 16/38] x86: ptrace debugreg checks rewrite
Quoted 1 line · On Fri, 22 May 2009 08:55:10 +0400 Alexey Dobriyan…
This is a mess.
heh. I'm going to treat it as Ingo's mess :)
Andrew Morton
maintainerRe: [PATCH 16/38] x86: ptrace debugreg checks rewrite
In reply to Alexey DobriyanQuoted 1 line · On Fri, 22 May 2009 08:55:10 +0400 Alexey Dobriyan <[email protected]> wrote:
This is a mess.
heh. I'm going to treat it as Ingo's mess :)
PATCH 17/38 groups: move code to kernel/groups.c
In reply to Alexey DobriyanMove supplementary groups implementation to kernel/groups.c . kernel/sys.c already accumulated quite a few random stuff.
Do strictly copy/paste + add required headers to compile. Compile-tested on many configs and archs.
--- kernel/Makefile | 1 + kernel/groups.c | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/sys.c | 283 ------------------------------------------------------ 3 files changed, 289 insertions(+), 283 deletions(-) create mode 100644 kernel/groups.c
kernel/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o \ hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \ async.o +obj-y += groups.o ifdef CONFIG_FUNCTION_TRACER # Do not trace debug files and internal ftrace files
kernel/groups.c new file +288 -0
288 lines not on this page · raw message
kernel/sys.c +0 -283
289 lines not on this page · raw message
Signature · 1 line
1.5.6.5
Re: [PATCH 17/38] groups: move code to kernel/groups.c
Quoted 7 lines · Alexey Dobriyan
Move supplementary groups implementation to
kernel/groups.c.kernel/sys.calready accumulated quite a few random stuff.Do strictly copy/paste + add required headers to compile. Compile-tested on many configs and archs.
Signed-off-by Alexey Dobriyan <[email protected]>
Agreed, I was thinking I'd do the same thing for groups c/r with Oren's set.
Quoted 614 lines
--- kernel/Makefile | 1 + kernel/groups.c | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/sys.c | 283 ------------------------------------------------------ 3 files changed, 289 insertions(+), 283 deletions(-) create mode 100644 kernel/groups.ckernel/Makefile +1
-0@@ -11,6 +11,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o \ hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \ async.o +obj-y += groups.o ifdef CONFIG_FUNCTION_TRACER # Do not trace debug files and internal ftrace fileskernel/groups.c new file +288
-0@@ -0,0 +1,288 @@ +/* +* Supplementary group IDs +*/ +#include <linux/cred.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/security.h> +#include <linux/syscalls.h> +#include <asm/uaccess.h> + +/* init to 2 - one for init_task, one to ensure it is never freed */ +struct group_info init_groups = { .usage =ATOMIC_INIT (2 ) }; + +struct group_info *groups_alloc (int gidsetsize) +{ +struct group_info *group_info; +int nblocks; +int i; + + nblocks = (gidsetsize +NGROUPS_PER_BLOCK -1 ) /NGROUPS_PER_BLOCK ; +/* Make sure we always allocate at least one indirect block pointer */ + nblocks = nblocks ? :1 ; + group_info =kmalloc (sizeof (*group_info) + nblocks*sizeof (gid_t *),GFP_USER ); +if (!group_info) +return NULL ; + group_info->ngroups = gidsetsize; + group_info->nblocks = nblocks; +atomic_set (&group_info->usage,1 ); + +if (gidsetsize <=NGROUPS_SMALL ) + group_info->blocks[0 ] = group_info->small_block; +else { +for (i =0 ; i < nblocks; i++) { +gid_t *b; + b = (void *)__get_free_page (GFP_USER ); +if (!b) + goto out_undo_partial_alloc; + group_info->blocks[i] = b; + } + } +return group_info; + +out_undo_partial_alloc: +while (--i >=0 ) { +free_page ((unsigned long )group_info->blocks[i]); + } +kfree (group_info); +return NULL ; +} + +EXPORT_SYMBOL (groups_alloc); + +void groups_free (struct group_info *group_info) +{ +if (group_info->blocks[0 ] != group_info->small_block) { +int i; +for (i =0 ; i < group_info->nblocks; i++) +free_page ((unsigned long )group_info->blocks[i]); + } +kfree (group_info); +} + +EXPORT_SYMBOL (groups_free); + +/* export the group_info to a user-space array */ +static int groups_to_user (gid_t __user *grouplist, +const struct group_info *group_info) +{ +int i; +unsigned int count = group_info->ngroups; + +for (i =0 ; i < group_info->nblocks; i++) { +unsigned int cp_count =min (NGROUPS_PER_BLOCK , count); +unsigned int len = cp_count *sizeof (*grouplist); + +if (copy_to_user (grouplist, group_info->blocks[i], len)) +return -EFAULT ; + + grouplist +=NGROUPS_PER_BLOCK ; + count -= cp_count; + } +return 0 ; +} + +/* fill a group_info from a user-space array - it must be allocated already */ +static int groups_from_user (struct group_info *group_info, +gid_t __user *grouplist) +{ +int i; +unsigned int count = group_info->ngroups; + +for (i =0 ; i < group_info->nblocks; i++) { +unsigned int cp_count =min (NGROUPS_PER_BLOCK , count); +unsigned int len = cp_count *sizeof (*grouplist); + +if (copy_from_user (group_info->blocks[i], grouplist, len)) +return -EFAULT ; + + grouplist +=NGROUPS_PER_BLOCK ; + count -= cp_count; + } +return 0 ; +} + +/* a simple Shell sort */ +static void groups_sort (struct group_info *group_info) +{ +int base, max, stride; +int gidsetsize = group_info->ngroups; + +for (stride =1 ; stride < gidsetsize; stride =3 * stride +1 ) + ;/* nothing */ + stride /=3 ; + +while (stride) { + max = gidsetsize - stride; +for (base =0 ; base < max; base++) { +int left = base; +int right = left + stride; +gid_t tmp =GROUP_AT (group_info, right); + +while (left >=0 &&GROUP_AT (group_info, left) > tmp) { +GROUP_AT (group_info, right) = +GROUP_AT (group_info, left); + right = left; + left -= stride; + } +GROUP_AT (group_info, right) = tmp; + } + stride /=3 ; + } +} + +/* a simple bsearch */ +int groups_search (const struct group_info *group_info,gid_t grp) +{ +unsigned int left, right; + +if (!group_info) +return 0 ; + + left =0 ; + right = group_info->ngroups; +while (left < right) { +unsigned int mid = (left+right)/2 ; +int cmp = grp -GROUP_AT (group_info, mid); +if (cmp >0 ) + left = mid +1 ; +else if (cmp <0 ) + right = mid; +else +return 1 ; + } +return 0 ; +} + +/** +* set_groups - Change a group subscription in a set of credentials +* @new: The newly prepared set of credentials to alter +* @group_info: The group list to install +* +* Validate a group subscription and, if valid, insert it into a set +* of credentials. +*/ +int set_groups (struct cred *new,struct group_info *group_info) +{ +int retval; + + retval =security_task_setgroups (group_info); +if (retval) +return retval; + +put_group_info (new->group_info); +groups_sort (group_info); +get_group_info (group_info); + new->group_info = group_info; +return 0 ; +} + +EXPORT_SYMBOL (set_groups); + +/** +* set_current_groups - Change current's group subscription +* @group_info: The group list to impose +* +* Validate a group subscription and, if valid, impose it upon current's task +* security record. +*/ +int set_current_groups (struct group_info *group_info) +{ +struct cred *new; +int ret; + + new =prepare_creds (); +if (!new) +return -ENOMEM ; + + ret =set_groups (new, group_info); +if (ret <0 ) { +abort_creds (new); +return ret; + } + +return commit_creds (new); +} + +EXPORT_SYMBOL (set_current_groups); + +SYSCALL_DEFINE2(getgroups, int, gidsetsize, gid_t __user *, grouplist) +{ +const struct cred *cred =current_cred (); +int i; + +if (gidsetsize <0 ) +return -EINVAL ; + +/* no need to grab task_lock here; it cannot change */ + i = cred->group_info->ngroups; +if (gidsetsize) { +if (i > gidsetsize) { + i = -EINVAL ; + goto out; + } +if (groups_to_user (grouplist, cred->group_info)) { + i = -EFAULT ; + goto out; + } + } +out: +return i; +} + +/* +* SMP: Our groups are copy-on-write. We can set them safely +* without another task interfering. +*/ + +SYSCALL_DEFINE2(setgroups, int, gidsetsize, gid_t __user *, grouplist) +{ +struct group_info *group_info; +int retval; + +if (!capable (CAP_SETGID )) +return -EPERM ; +if ((unsigned )gidsetsize >NGROUPS_MAX ) +return -EINVAL ; + + group_info =groups_alloc (gidsetsize); +if (!group_info) +return -ENOMEM ; + retval =groups_from_user (group_info, grouplist); +if (retval) { +put_group_info (group_info); +return retval; + } + + retval =set_current_groups (group_info); +put_group_info (group_info); + +return retval; +} + +/* +* Check whether we're fsgid/egid or in the supplemental group.. +*/ +int in_group_p (gid_t grp) +{ +const struct cred *cred =current_cred (); +int retval =1 ; + +if (grp != cred->fsgid) + retval =groups_search (cred->group_info, grp); +return retval; +} + +EXPORT_SYMBOL (in_group_p); + +int in_egroup_p (gid_t grp) +{ +const struct cred *cred =current_cred (); +int retval =1 ; + +if (grp != cred->egid) + retval =groups_search (cred->group_info, grp); +return retval; +} + +EXPORT_SYMBOL (in_egroup_p);kernel/sys.c +0
-283@@ -1112,289 +1112,6 @@ out:return err; } -/* -* Supplementary group IDs -*/ - -/* init to 2 - one for init_task, one to ensure it is never freed */ -struct group_info init_groups = { .usage =ATOMIC_INIT (2 ) }; - -struct group_info *groups_alloc (int gidsetsize) -{ -struct group_info *group_info; -int nblocks; -int i; - - nblocks = (gidsetsize +NGROUPS_PER_BLOCK -1 ) /NGROUPS_PER_BLOCK ; -/* Make sure we always allocate at least one indirect block pointer */ - nblocks = nblocks ? :1 ; - group_info =kmalloc (sizeof (*group_info) + nblocks*sizeof (gid_t *),GFP_USER ); -if (!group_info) -return NULL ; - group_info->ngroups = gidsetsize; - group_info->nblocks = nblocks; -atomic_set (&group_info->usage,1 ); - -if (gidsetsize <=NGROUPS_SMALL ) - group_info->blocks[0 ] = group_info->small_block; -else { -for (i =0 ; i < nblocks; i++) { -gid_t *b; - b = (void *)__get_free_page (GFP_USER ); -if (!b) - goto out_undo_partial_alloc; - group_info->blocks[i] = b; - } - } -return group_info; - -out_undo_partial_alloc: -while (--i >=0 ) { -free_page ((unsigned long )group_info->blocks[i]); - } -kfree (group_info); -return NULL ; -} - -EXPORT_SYMBOL (groups_alloc); - -void groups_free (struct group_info *group_info) -{ -if (group_info->blocks[0 ] != group_info->small_block) { -int i; -for (i =0 ; i < group_info->nblocks; i++) -free_page ((unsigned long )group_info->blocks[i]); - } -kfree (group_info); -} - -EXPORT_SYMBOL (groups_free); - -/* export the group_info to a user-space array */ -static int groups_to_user (gid_t __user *grouplist, -const struct group_info *group_info) -{ -int i; -unsigned int count = group_info->ngroups; - -for (i =0 ; i < group_info->nblocks; i++) { -unsigned int cp_count =min (NGROUPS_PER_BLOCK , count); -unsigned int len = cp_count *sizeof (*grouplist); - -if (copy_to_user (grouplist, group_info->blocks[i], len)) -return -EFAULT ; - - grouplist +=NGROUPS_PER_BLOCK ; - count -= cp_count; - } -return 0 ; -} - -/* fill a group_info from a user-space array - it must be allocated already */ -static int groups_from_user (struct group_info *group_info, -gid_t __user *grouplist) -{ -int i; -unsigned int count = group_info->ngroups; - -for (i =0 ; i < group_info->nblocks; i++) { -unsigned int cp_count =min (NGROUPS_PER_BLOCK , count); -unsigned int len = cp_count *sizeof (*grouplist); - -if (copy_from_user (group_info->blocks[i], grouplist, len)) -return -EFAULT ; - - grouplist +=NGROUPS_PER_BLOCK ; - count -= cp_count; - } -return 0 ; -} - -/* a simple Shell sort */ -static void groups_sort (struct group_info *group_info) -{ -int base, max, stride; -int gidsetsize = group_info->ngroups; - -for (stride =1 ; stride < gidsetsize; stride =3 * stride +1 ) - ;/* nothing */ - stride /=3 ; - -while (stride) { - max = gidsetsize - stride; -for (base =0 ; base < max; base++) { -int left = base; -int right = left + stride; -gid_t tmp =GROUP_AT (group_info, right); - -while (left >=0 &&GROUP_AT (group_info, left) > tmp) { -GROUP_AT (group_info, right) = -GROUP_AT (group_info, left); - right = left; - left -= stride; - } -GROUP_AT (group_info, right) = tmp; - } - stride /=3 ; - } -} - -/* a simple bsearch */ -int groups_search (const struct group_info *group_info,gid_t grp) -{ -unsigned int left, right; - -if (!group_info) -return 0 ; - - left =0 ; - right = group_info->ngroups; -while (left < right) { -unsigned int mid = (left+right)/2 ; -int cmp = grp -GROUP_AT (group_info, mid); -if (cmp >0 ) - left = mid +1 ; -else if (cmp <0 ) - right = mid; -else -return 1 ; - } -return 0 ; -} - -/** -* set_groups - Change a group subscription in a set of credentials -* @new: The newly prepared set of credentials to alter -* @group_info: The group list to install -* -* Validate a group subscription and, if valid, insert it into a set -* of credentials. -*/ -int set_groups (struct cred *new,struct group_info *group_info) -{ -int retval; - - retval =security_task_setgroups (group_info); -if (retval) -return retval; - -put_group_info (new->group_info); -groups_sort (group_info); -get_group_info (group_info); - new->group_info = group_info; -return 0 ; -} - -EXPORT_SYMBOL (set_groups); - -/** -* set_current_groups - Change current's group subscription -* @group_info: The group list to impose -* -* Validate a group subscription and, if valid, impose it upon current's task -* security record. -*/ -int set_current_groups (struct group_info *group_info) -{ -struct cred *new; -int ret; - - new =prepare_creds (); -if (!new) -return -ENOMEM ; - - ret =set_groups (new, group_info); -if (ret <0 ) { -abort_creds (new); -return ret; - } - -return commit_creds (new); -} - -EXPORT_SYMBOL (set_current_groups); - -SYSCALL_DEFINE2(getgroups, int, gidsetsize, gid_t __user *, grouplist) -{ -const struct cred *cred =current_cred (); -int i; - -if (gidsetsize <0 ) -return -EINVAL ; - -/* no need to grab task_lock here; it cannot change */ - i = cred->group_info->ngroups; -if (gidsetsize) { -if (i > gidsetsize) { - i = -EINVAL ; - goto out; - } -if (groups_to_user (grouplist, cred->group_info)) { - i = -EFAULT ; - goto out; - } - } -out: -return i; -} - -/* -* SMP: Our groups are copy-on-write. We can set them safely -* without another task interfering. -*/ - -SYSCALL_DEFINE2(setgroups, int, gidsetsize, gid_t __user *, grouplist) -{ -struct group_info *group_info; -int retval; - -if (!capable (CAP_SETGID )) -return -EPERM ; -if ((unsigned )gidsetsize >NGROUPS_MAX ) -return -EINVAL ; - - group_info =groups_alloc (gidsetsize); -if (!group_info) -return -ENOMEM ; - retval =groups_from_user (group_info, grouplist); -if (retval) { -put_group_info (group_info); -return retval; - } - - retval =set_current_groups (group_info); -put_group_info (group_info); - -return retval; -} - -/* -* Check whether we're fsgid/egid or in the supplemental group.. -*/ -int in_group_p (gid_t grp) -{ -const struct cred *cred =current_cred (); -int retval =1 ; - -if (grp != cred->fsgid) - retval =groups_search (cred->group_info, grp); -return retval; -} - -EXPORT_SYMBOL (in_group_p); - -int in_egroup_p (gid_t grp) -{ -const struct cred *cred =current_cred (); -int retval =1 ; - -if (grp != cred->egid) - retval =groups_search (cred->group_info, grp); -return retval; -} - -EXPORT_SYMBOL (in_egroup_p); -DECLARE_RWSEM (uts_sem); SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name)Signature · 6 lines
1.5.6.5 _______________________________________________ Containers mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/containers
A message that is not in the archive (sent off-list or not yet received): 1242968132-1044-17-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Serge E. Hallyn
Acked-by Serge HallynRe: [PATCH 17/38] groups: move code to kernel/groups.c
Quoted 7 lines · Alexey Dobriyan
Move supplementary groups implementation to
kernel/groups.c.kernel/sys.calready accumulated quite a few random stuff.Do strictly copy/paste + add required headers to compile. Compile-tested on many configs and archs.
Signed-off-by Alexey Dobriyan <[email protected]>
Agreed, I was thinking I'd do the same thing for groups c/r with Oren's set.
Quoted 614 lines
--- kernel/Makefile | 1 + kernel/groups.c | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/sys.c | 283 ------------------------------------------------------ 3 files changed, 289 insertions(+), 283 deletions(-) create mode 100644 kernel/groups.ckernel/Makefile +1
-0@@ -11,6 +11,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o \ hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \ async.o +obj-y += groups.o ifdef CONFIG_FUNCTION_TRACER # Do not trace debug files and internal ftrace fileskernel/groups.c new file +288
-0@@ -0,0 +1,288 @@ +/* +* Supplementary group IDs +*/ +#include <linux/cred.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/security.h> +#include <linux/syscalls.h> +#include <asm/uaccess.h> + +/* init to 2 - one for init_task, one to ensure it is never freed */ +struct group_info init_groups = { .usage =ATOMIC_INIT (2 ) }; + +struct group_info *groups_alloc (int gidsetsize) +{ +struct group_info *group_info; +int nblocks; +int i; + + nblocks = (gidsetsize +NGROUPS_PER_BLOCK -1 ) /NGROUPS_PER_BLOCK ; +/* Make sure we always allocate at least one indirect block pointer */ + nblocks = nblocks ? :1 ; + group_info =kmalloc (sizeof (*group_info) + nblocks*sizeof (gid_t *),GFP_USER ); +if (!group_info) +return NULL ; + group_info->ngroups = gidsetsize; + group_info->nblocks = nblocks; +atomic_set (&group_info->usage,1 ); + +if (gidsetsize <=NGROUPS_SMALL ) + group_info->blocks[0 ] = group_info->small_block; +else { +for (i =0 ; i < nblocks; i++) { +gid_t *b; + b = (void *)__get_free_page (GFP_USER ); +if (!b) + goto out_undo_partial_alloc; + group_info->blocks[i] = b; + } + } +return group_info; + +out_undo_partial_alloc: +while (--i >=0 ) { +free_page ((unsigned long )group_info->blocks[i]); + } +kfree (group_info); +return NULL ; +} + +EXPORT_SYMBOL (groups_alloc); + +void groups_free (struct group_info *group_info) +{ +if (group_info->blocks[0 ] != group_info->small_block) { +int i; +for (i =0 ; i < group_info->nblocks; i++) +free_page ((unsigned long )group_info->blocks[i]); + } +kfree (group_info); +} + +EXPORT_SYMBOL (groups_free); + +/* export the group_info to a user-space array */ +static int groups_to_user (gid_t __user *grouplist, +const struct group_info *group_info) +{ +int i; +unsigned int count = group_info->ngroups; + +for (i =0 ; i < group_info->nblocks; i++) { +unsigned int cp_count =min (NGROUPS_PER_BLOCK , count); +unsigned int len = cp_count *sizeof (*grouplist); + +if (copy_to_user (grouplist, group_info->blocks[i], len)) +return -EFAULT ; + + grouplist +=NGROUPS_PER_BLOCK ; + count -= cp_count; + } +return 0 ; +} + +/* fill a group_info from a user-space array - it must be allocated already */ +static int groups_from_user (struct group_info *group_info, +gid_t __user *grouplist) +{ +int i; +unsigned int count = group_info->ngroups; + +for (i =0 ; i < group_info->nblocks; i++) { +unsigned int cp_count =min (NGROUPS_PER_BLOCK , count); +unsigned int len = cp_count *sizeof (*grouplist); + +if (copy_from_user (group_info->blocks[i], grouplist, len)) +return -EFAULT ; + + grouplist +=NGROUPS_PER_BLOCK ; + count -= cp_count; + } +return 0 ; +} + +/* a simple Shell sort */ +static void groups_sort (struct group_info *group_info) +{ +int base, max, stride; +int gidsetsize = group_info->ngroups; + +for (stride =1 ; stride < gidsetsize; stride =3 * stride +1 ) + ;/* nothing */ + stride /=3 ; + +while (stride) { + max = gidsetsize - stride; +for (base =0 ; base < max; base++) { +int left = base; +int right = left + stride; +gid_t tmp =GROUP_AT (group_info, right); + +while (left >=0 &&GROUP_AT (group_info, left) > tmp) { +GROUP_AT (group_info, right) = +GROUP_AT (group_info, left); + right = left; + left -= stride; + } +GROUP_AT (group_info, right) = tmp; + } + stride /=3 ; + } +} + +/* a simple bsearch */ +int groups_search (const struct group_info *group_info,gid_t grp) +{ +unsigned int left, right; + +if (!group_info) +return 0 ; + + left =0 ; + right = group_info->ngroups; +while (left < right) { +unsigned int mid = (left+right)/2 ; +int cmp = grp -GROUP_AT (group_info, mid); +if (cmp >0 ) + left = mid +1 ; +else if (cmp <0 ) + right = mid; +else +return 1 ; + } +return 0 ; +} + +/** +* set_groups - Change a group subscription in a set of credentials +* @new: The newly prepared set of credentials to alter +* @group_info: The group list to install +* +* Validate a group subscription and, if valid, insert it into a set +* of credentials. +*/ +int set_groups (struct cred *new,struct group_info *group_info) +{ +int retval; + + retval =security_task_setgroups (group_info); +if (retval) +return retval; + +put_group_info (new->group_info); +groups_sort (group_info); +get_group_info (group_info); + new->group_info = group_info; +return 0 ; +} + +EXPORT_SYMBOL (set_groups); + +/** +* set_current_groups - Change current's group subscription +* @group_info: The group list to impose +* +* Validate a group subscription and, if valid, impose it upon current's task +* security record. +*/ +int set_current_groups (struct group_info *group_info) +{ +struct cred *new; +int ret; + + new =prepare_creds (); +if (!new) +return -ENOMEM ; + + ret =set_groups (new, group_info); +if (ret <0 ) { +abort_creds (new); +return ret; + } + +return commit_creds (new); +} + +EXPORT_SYMBOL (set_current_groups); + +SYSCALL_DEFINE2(getgroups, int, gidsetsize, gid_t __user *, grouplist) +{ +const struct cred *cred =current_cred (); +int i; + +if (gidsetsize <0 ) +return -EINVAL ; + +/* no need to grab task_lock here; it cannot change */ + i = cred->group_info->ngroups; +if (gidsetsize) { +if (i > gidsetsize) { + i = -EINVAL ; + goto out; + } +if (groups_to_user (grouplist, cred->group_info)) { + i = -EFAULT ; + goto out; + } + } +out: +return i; +} + +/* +* SMP: Our groups are copy-on-write. We can set them safely +* without another task interfering. +*/ + +SYSCALL_DEFINE2(setgroups, int, gidsetsize, gid_t __user *, grouplist) +{ +struct group_info *group_info; +int retval; + +if (!capable (CAP_SETGID )) +return -EPERM ; +if ((unsigned )gidsetsize >NGROUPS_MAX ) +return -EINVAL ; + + group_info =groups_alloc (gidsetsize); +if (!group_info) +return -ENOMEM ; + retval =groups_from_user (group_info, grouplist); +if (retval) { +put_group_info (group_info); +return retval; + } + + retval =set_current_groups (group_info); +put_group_info (group_info); + +return retval; +} + +/* +* Check whether we're fsgid/egid or in the supplemental group.. +*/ +int in_group_p (gid_t grp) +{ +const struct cred *cred =current_cred (); +int retval =1 ; + +if (grp != cred->fsgid) + retval =groups_search (cred->group_info, grp); +return retval; +} + +EXPORT_SYMBOL (in_group_p); + +int in_egroup_p (gid_t grp) +{ +const struct cred *cred =current_cred (); +int retval =1 ; + +if (grp != cred->egid) + retval =groups_search (cred->group_info, grp); +return retval; +} + +EXPORT_SYMBOL (in_egroup_p);kernel/sys.c +0
-283@@ -1112,289 +1112,6 @@ out:return err; } -/* -* Supplementary group IDs -*/ - -/* init to 2 - one for init_task, one to ensure it is never freed */ -struct group_info init_groups = { .usage =ATOMIC_INIT (2 ) }; - -struct group_info *groups_alloc (int gidsetsize) -{ -struct group_info *group_info; -int nblocks; -int i; - - nblocks = (gidsetsize +NGROUPS_PER_BLOCK -1 ) /NGROUPS_PER_BLOCK ; -/* Make sure we always allocate at least one indirect block pointer */ - nblocks = nblocks ? :1 ; - group_info =kmalloc (sizeof (*group_info) + nblocks*sizeof (gid_t *),GFP_USER ); -if (!group_info) -return NULL ; - group_info->ngroups = gidsetsize; - group_info->nblocks = nblocks; -atomic_set (&group_info->usage,1 ); - -if (gidsetsize <=NGROUPS_SMALL ) - group_info->blocks[0 ] = group_info->small_block; -else { -for (i =0 ; i < nblocks; i++) { -gid_t *b; - b = (void *)__get_free_page (GFP_USER ); -if (!b) - goto out_undo_partial_alloc; - group_info->blocks[i] = b; - } - } -return group_info; - -out_undo_partial_alloc: -while (--i >=0 ) { -free_page ((unsigned long )group_info->blocks[i]); - } -kfree (group_info); -return NULL ; -} - -EXPORT_SYMBOL (groups_alloc); - -void groups_free (struct group_info *group_info) -{ -if (group_info->blocks[0 ] != group_info->small_block) { -int i; -for (i =0 ; i < group_info->nblocks; i++) -free_page ((unsigned long )group_info->blocks[i]); - } -kfree (group_info); -} - -EXPORT_SYMBOL (groups_free); - -/* export the group_info to a user-space array */ -static int groups_to_user (gid_t __user *grouplist, -const struct group_info *group_info) -{ -int i; -unsigned int count = group_info->ngroups; - -for (i =0 ; i < group_info->nblocks; i++) { -unsigned int cp_count =min (NGROUPS_PER_BLOCK , count); -unsigned int len = cp_count *sizeof (*grouplist); - -if (copy_to_user (grouplist, group_info->blocks[i], len)) -return -EFAULT ; - - grouplist +=NGROUPS_PER_BLOCK ; - count -= cp_count; - } -return 0 ; -} - -/* fill a group_info from a user-space array - it must be allocated already */ -static int groups_from_user (struct group_info *group_info, -gid_t __user *grouplist) -{ -int i; -unsigned int count = group_info->ngroups; - -for (i =0 ; i < group_info->nblocks; i++) { -unsigned int cp_count =min (NGROUPS_PER_BLOCK , count); -unsigned int len = cp_count *sizeof (*grouplist); - -if (copy_from_user (group_info->blocks[i], grouplist, len)) -return -EFAULT ; - - grouplist +=NGROUPS_PER_BLOCK ; - count -= cp_count; - } -return 0 ; -} - -/* a simple Shell sort */ -static void groups_sort (struct group_info *group_info) -{ -int base, max, stride; -int gidsetsize = group_info->ngroups; - -for (stride =1 ; stride < gidsetsize; stride =3 * stride +1 ) - ;/* nothing */ - stride /=3 ; - -while (stride) { - max = gidsetsize - stride; -for (base =0 ; base < max; base++) { -int left = base; -int right = left + stride; -gid_t tmp =GROUP_AT (group_info, right); - -while (left >=0 &&GROUP_AT (group_info, left) > tmp) { -GROUP_AT (group_info, right) = -GROUP_AT (group_info, left); - right = left; - left -= stride; - } -GROUP_AT (group_info, right) = tmp; - } - stride /=3 ; - } -} - -/* a simple bsearch */ -int groups_search (const struct group_info *group_info,gid_t grp) -{ -unsigned int left, right; - -if (!group_info) -return 0 ; - - left =0 ; - right = group_info->ngroups; -while (left < right) { -unsigned int mid = (left+right)/2 ; -int cmp = grp -GROUP_AT (group_info, mid); -if (cmp >0 ) - left = mid +1 ; -else if (cmp <0 ) - right = mid; -else -return 1 ; - } -return 0 ; -} - -/** -* set_groups - Change a group subscription in a set of credentials -* @new: The newly prepared set of credentials to alter -* @group_info: The group list to install -* -* Validate a group subscription and, if valid, insert it into a set -* of credentials. -*/ -int set_groups (struct cred *new,struct group_info *group_info) -{ -int retval; - - retval =security_task_setgroups (group_info); -if (retval) -return retval; - -put_group_info (new->group_info); -groups_sort (group_info); -get_group_info (group_info); - new->group_info = group_info; -return 0 ; -} - -EXPORT_SYMBOL (set_groups); - -/** -* set_current_groups - Change current's group subscription -* @group_info: The group list to impose -* -* Validate a group subscription and, if valid, impose it upon current's task -* security record. -*/ -int set_current_groups (struct group_info *group_info) -{ -struct cred *new; -int ret; - - new =prepare_creds (); -if (!new) -return -ENOMEM ; - - ret =set_groups (new, group_info); -if (ret <0 ) { -abort_creds (new); -return ret; - } - -return commit_creds (new); -} - -EXPORT_SYMBOL (set_current_groups); - -SYSCALL_DEFINE2(getgroups, int, gidsetsize, gid_t __user *, grouplist) -{ -const struct cred *cred =current_cred (); -int i; - -if (gidsetsize <0 ) -return -EINVAL ; - -/* no need to grab task_lock here; it cannot change */ - i = cred->group_info->ngroups; -if (gidsetsize) { -if (i > gidsetsize) { - i = -EINVAL ; - goto out; - } -if (groups_to_user (grouplist, cred->group_info)) { - i = -EFAULT ; - goto out; - } - } -out: -return i; -} - -/* -* SMP: Our groups are copy-on-write. We can set them safely -* without another task interfering. -*/ - -SYSCALL_DEFINE2(setgroups, int, gidsetsize, gid_t __user *, grouplist) -{ -struct group_info *group_info; -int retval; - -if (!capable (CAP_SETGID )) -return -EPERM ; -if ((unsigned )gidsetsize >NGROUPS_MAX ) -return -EINVAL ; - - group_info =groups_alloc (gidsetsize); -if (!group_info) -return -ENOMEM ; - retval =groups_from_user (group_info, grouplist); -if (retval) { -put_group_info (group_info); -return retval; - } - - retval =set_current_groups (group_info); -put_group_info (group_info); - -return retval; -} - -/* -* Check whether we're fsgid/egid or in the supplemental group.. -*/ -int in_group_p (gid_t grp) -{ -const struct cred *cred =current_cred (); -int retval =1 ; - -if (grp != cred->fsgid) - retval =groups_search (cred->group_info, grp); -return retval; -} - -EXPORT_SYMBOL (in_group_p); - -int in_egroup_p (gid_t grp) -{ -const struct cred *cred =current_cred (); -int retval =1 ; - -if (grp != cred->egid) - retval =groups_search (cred->group_info, grp); -return retval; -} - -EXPORT_SYMBOL (in_egroup_p); -DECLARE_RWSEM (uts_sem); SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name)Signature · 6 lines
1.5.6.5 _______________________________________________ Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [PATCH 17/38] groups: move code to kernel/groups.c
In reply to a message not in the archiveQuoted 7 lines · Alexey Dobriyan
Move supplementary groups implementation to
kernel/groups.c.kernel/sys.calready accumulated quite a few random stuff.Do strictly copy/paste + add required headers to compile. Compile-tested on many configs and archs.
Signed-off-by Alexey Dobriyan <[email protected]>
Actually I needed the following change:
From 81e683ae07cfe24d98d6df384bbd37f1f7f80c38 Mon Sep 17 00:00:00 2001
From: Serge E. Hallyn <serue-r/[email protected]>
Date: Tue, 26 May 2009 10:39:47 -0400
Subject: [PATCH 1/1] groups: allow compilation on s390x
--- kernel/groups.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
kernel/groups.c +1 -0
@@ -1,6 +1,7 @@/* * Supplementary group IDs */ +#include <linux/init.h> #include <linux/cred.h> #include <linux/module.h> #include <linux/slab.h>
Signature · 1 line
1.6.1
Re: [PATCH 17/38] groups: move code to kernel/groups.c
In reply to Alexey DobriyanQuoted 7 lines · Alexey Dobriyan
Move supplementary groups implementation to
kernel/groups.c.kernel/sys.calready accumulated quite a few random stuff.Do strictly copy/paste + add required headers to compile. Compile-tested on many configs and archs.
Signed-off-by Alexey Dobriyan <[email protected]>
Actually I needed the following change:
Quoted 1 line
From
81e683ae07cfe24d98d6df384bbd37f1f7f80c38Mon Sep 17 00:00:00 2001
From: Serge E. Hallyn <[email protected]>
Date: Tue, 26 May 2009 10:39:47 -0400
Subject: [PATCH 1/1] groups: allow compilation on s390x
--- kernel/groups.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
kernel/groups.c +1 -0
@@ -1,6 +1,7 @@/* * Supplementary group IDs */ +#include <linux/init.h> #include <linux/cred.h> #include <linux/module.h> #include <linux/slab.h>
Signature · 1 line
1.6.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 17/38] groups: move code to kernel/groups.c
Quoted 10 lines · Serge E. Hallyn
Quoted 7 lines · Alexey Dobriyan
Move supplementary groups implementation to
kernel/groups.c.kernel/sys.calready accumulated quite a few random stuff.Do strictly copy/paste + add required headers to compile. Compile-tested on many configs and archs.
Signed-off-by Alexey Dobriyan <[email protected]>Actually I needed the following change:
This is dealt by first patch:
"[PATCH 01/38] cred: #include init.h in cred.h"
which is in -mm already.
kernel/groups.c line 4
Quoted 7 lines
kernel/groups.c +1
-0@@ -1,6 +1,7 @@/* * Supplementary group IDs */ +#include <linux/init.h>
Wrong, groups.c doesn't use __init at all.
Re: [PATCH 17/38] groups: move code to kernel/groups.c
In reply to Serge E. HallynQuoted 10 lines · Serge E. Hallyn
Quoted 7 lines · Alexey Dobriyan
Move supplementary groups implementation to
kernel/groups.c.kernel/sys.calready accumulated quite a few random stuff.Do strictly copy/paste + add required headers to compile. Compile-tested on many configs and archs.
Signed-off-by Alexey Dobriyan <[email protected]>Actually I needed the following change:
This is dealt by first patch:
"[PATCH 01/38] cred: #include init.h in cred.h"
which is in -mm already.
kernel/groups.c line 4
Quoted 7 lines
kernel/groups.c +1
-0@@ -1,6 +1,7 @@/* * Supplementary group IDs */ +#include <linux/init.h>
Wrong, groups.c doesn't use __init at all.
Re: [PATCH 17/38] groups: move code to kernel/groups.c
Quoted 16 lines · Alexey Dobriyan
Quoted 10 lines · Serge E. Hallyn
Quoted 7 lines · Alexey Dobriyan
Move supplementary groups implementation to
kernel/groups.c.kernel/sys.calready accumulated quite a few random stuff.Do strictly copy/paste + add required headers to compile. Compile-tested on many configs and archs.
Signed-off-by Alexey Dobriyan <[email protected]>Actually I needed the following change:
This is dealt by first patch:
"[PATCH 01/38] cred: #includeinit.hincred.h"
which is in -mm already.
Quoted 9 lines
kernel/groups.c line 4
Quoted 7 lines
kernel/groups.c +1
-0@@ -1,6 +1,7 @@/* * Supplementary group IDs */ +#include <linux/init.h> Wrong,
groups.cdoesn't use__initat all.
Right you are.
thanks,
-serge
PATCH 18/38 C/R: core stuff
In reply to Alexey DobriyanIntroduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
How C/R works
-------------
User passes to system call pid of process which is the root of process hierarchy to be saved. Hierarchy is formed wrt ->real_parent.
Processes which belong to this hierarchy are frozen.
C/R code walks in-kernel datastructures starting from task_structs and collects references to them in one place for a dump. This includes at least mm_struct, nsproxy and it's belongings, opened files, CPU registers, etc. More or less anything which is userspace-visible must be dumped on one form or another.
Collected data structures are checked for sanity wrt several things:
- still unsupported features (hugetlb mappings) in which case checkpointing is aborted
- structure "leaks" to outside of selected group of processes.
This is done by maintaining mirror refcount from structures collected and comparing it with real refcount. If discrepancy is noticed, structure is used by someone else who is not frozen and thus we're trying to checkpoint live data structure. Depending on what data structure is dumping live data structure can be pretty easy (uts_namespace requires only uts_sem) to pretty hard (net_namespace sockets requires... actually nobody knows what net_namespace will require).
Note! There re multiple levels of correct operation implied:
- kernel shouldn't oops by dumping live data structure
- kernel shouldn't write inconsistent state by dumping live data structure
If all checks for all data structures are OK, C/R code walks collected references in certain order and does actual serializing and writes image to passed file descriptor.
This results in a file which is believed to contain enough information to restore group of process to exactly same user-visible state as before checkpointing module inevitable issues like time.
Image format design
-------------------
Image consists of image header, object images one after another and terminator which is formally an object.
Image header consists of magic ("LinuxC/R") and image version (__le32). This is immutable part of an image. The rest is defined strictly by image version even the rest of image header.
Nobody is making guarantees that image format is immutable!
Once again, image format will change, however it's guaranteed that magic+version part will remain and image version will be bumped.
So far, image header consists of
a) arch of kernel which dumped image to signalize that you can't restore powerpc image on i386 kernel and hint code in case of restoring i386 image on x86_64 kernel.
b) kernel version as found in utsname.
This is done for distributions who eventually may want to support C/R. While the expected way to maintain migrating from older kernels is to write userspace converter which knows everything about two image formats, distro kernels may want to maintain all backward-caompat code in kernel which can be small or big depending on the amount of changes they pull into their kernel.
Just image version isn't realistically sufficient, distributions are expected to leave image version alone and demultiplex backward-compat code depending on utsname which is in case of distro kernels is pretty well known.
Object image
------------
Object images are direct projection of in-kernel data structures which can be shared inside kernel to disk :-) Example: struct mm_struct is dumped to an object of KSTATE_OBJ_MM_STRUCT type, struct cred is dumped to KSTATE_OBJ_CRED type.
There are so far 3 exceptions: VMA, page content and fd. These are formal objects with type and length to simplify reading and restoration of VMAs and file descriptors, respectively. VMA and pages attributed are even variable-sized.
Any object image starts with object header which is object type, object lenth including header and globally unique object id (per-image, of course). Type and length are used in verifying that image is not malformed and object id is used in references of objects to another objects and also verifying.
VMA, pages and file descriptors don't get object id, because they aren't directly collected. But this is fine, as they get invalid object id (0) which is not checked.
Relations in image
------------------
To serialize reference of object A to object B (task_struct::mm) image of object a gets a field of kstate_ref_t type:
struct kstate_image_a {
struct kstate_object_header hdr;
kstate_ref_t ref_b;
};which corresponds to a->b pointer.
Reference consists of position in a dumpfile (if it's known by the time B is dumped and object id of B (which _is_ known).
If there is a loop in pointers A => B => A, position is dumped as 0 and attention is required at restore time. In each loop case it will be dealt individually. (so far, there is one loop: user->user_ns->creator)
C/R dump code tries hard to maintaint streamable property of dump process -- if dumpfile is opened with O_APPEND, it should work).
Changes in kernel internals:
- add struct file_operations::checkpoint hook
Code which operated file knows better what information needs to be saved to allow successful restoration. For usual files on on-disk filesystem add generic_file_checkpoint().
Add ext3 opened regular files and directories for start.
If opened or references file doesn't have ->checkpoint hook, checkpointing is aborted -- this is deny-by-default policy.
- add struct vm_operations_struct::checkpoint
Same as for files. Will be used more by vDSO code.
checkpoint(2), restart(2)
-------------------------
Exact number and semantics of system calls is WIP, it was correctly noticed, that 'freeze' and 'dump' parts needs to be split apart to allow filesystem sync after freeze. For now leave 2 syscalls for people to play with.
Splitting freeze/dump implies persistent C/R context state BTW which is not the case now.
Checkpoint semantics
--------------------
Checkpointing is done on per-container level without "leaks" to outside. In this kernel can provide promises to dump coherent start and to do it without major games with data structures locking.
Works to allow reliable checkpoint on live data structures has been started however it's unclear what the result will be because of even more thing one has to keep inside head simultaneously.
As a semi-direct consequence checkpkointing is not allowed for ordinary users. While it's a nice feature to allow it, they formally can't even create container for themselves (CAP_SYS_ADMIN during nsproxy tweaks).
Regadless, once enabled this will present several security risks:
- anything in image is controlled by untrusted user who will try to check how well checking code on restart(2) is written.
And, yes, nobody is hiding that restart(2) involves honest parsing of slightly more complex that string file format inside kernel.
- user who effectively can turn off ASLR randomization, because he controls VMA boundaries.
These two directions (checkpointing live and restart(2) for everyone) aren't explored in this patchset because they are artificially not independent right now and each one is hard enough for already hard C/R work.
Sorry.
However, code is kept good enough to add each of feature later.
--- fs/ext3/dir.c | 3 + fs/ext3/file.c | 3 + include/linux/Kbuild | 1 + include/linux/fs.h | 12 +- include/linux/kstate-image.h | 118 +++++++++ include/linux/kstate.h | 144 ++++++++++ include/linux/mm.h | 4 + include/linux/syscalls.h | 3 + init/Kconfig | 2 + kernel/Makefile | 1 + kernel/kstate/Kconfig | 7 + kernel/kstate/Makefile | 8 + kernel/kstate/cpt-sys.c | 196 ++++++++++++++ kernel/kstate/kstate-context.c | 49 ++++ kernel/kstate/kstate-file.c | 204 +++++++++++++++ kernel/kstate/kstate-image.c | 116 ++++++++ kernel/kstate/kstate-mm.c | 563 ++++++++++++++++++++++++++++++++++++++++ kernel/kstate/kstate-object.c | 100 +++++++ kernel/kstate/kstate-task.c | 287 ++++++++++++++++++++ kernel/kstate/rst-sys.c | 91 +++++++ kernel/sys_ni.c | 3 + mm/filemap.c | 3 + 22 files changed, 1916 insertions(+), 2 deletions(-) create mode 100644 include/linux/kstate-image.h create mode 100644 include/linux/kstate.h create mode 100644 kernel/kstate/Kconfig create mode 100644 kernel/kstate/Makefile create mode 100644 kernel/kstate/cpt-sys.c create mode 100644 kernel/kstate/kstate-context.c create mode 100644 kernel/kstate/kstate-file.c create mode 100644 kernel/kstate/kstate-image.c create mode 100644 kernel/kstate/kstate-mm.c create mode 100644 kernel/kstate/kstate-object.c create mode 100644 kernel/kstate/kstate-task.c create mode 100644 kernel/kstate/rst-sys.c
fs/ext3/dir.c +3 -0
@@ -48,6 +48,9 @@ const struct file_operations ext3_dir_operations = {#endif .fsync = ext3_sync_file, /* BKL held */ .release = ext3_release_dir, +#ifdef CONFIG_CHECKPOINT + .checkpoint = generic_file_checkpoint, +#endif };
fs/ext3/file.c +3 -0
@@ -126,6 +126,9 @@ const struct file_operations ext3_file_operations = { .fsync = ext3_sync_file, .splice_read = generic_file_splice_read, .splice_write = generic_file_splice_write, +#ifdef CONFIG_CHECKPOINT + .checkpoint = generic_file_checkpoint, +#endif };const struct inode_operations ext3_file_inode_operations = {
include/linux/Kbuild +1 -0
@@ -50,6 +50,7 @@ header-y += coff.h header-y += comstats.h header-y += const.h header-y += cgroupstats.h +header-y += kstate-image.h header-y += cramfs_fs.h header-y += cycx_cfm.h header-y += dcbnl.h
include/linux/fs.h +10 -2
@@ -387,6 +387,7 @@ struct poll_table_struct;struct kstatfs ;struct vm_area_struct ;struct vfsmount ; +struct kstate_context ;struct cred ;extern void __init inode_init (void );
@@ -1508,6 +1509,9 @@ struct file_operations {ssize_t (*splice_write)(struct pipe_inode_info *,struct file *,loff_t *,size_t ,unsigned int );ssize_t (*splice_read)(struct file *,loff_t *,struct pipe_inode_info *,size_t ,unsigned int );int (*setlease)(struct file *,long ,struct file_lock **); +#ifdef CONFIG_CHECKPOINT +int (*checkpoint)(struct file *file,struct kstate_context *ctx); +#endif };struct inode_operations {
@@ -2079,7 +2083,9 @@ extern int __filemap_fdatawrite_range(struct address_space *mapping, loff_t start, loff_t end, int sync_mode);extern int filemap_fdatawrite_range (struct address_space *mapping,loff_t start,loff_t end); - +#ifdef CONFIG_CHECKPOINT +int filemap_checkpoint (struct vm_area_struct *vma,struct kstate_context *ctx); +#endif extern int vfs_fsync (struct file *file,struct dentry *dentry,int datasync);extern void sync_supers (void );extern void sync_filesystems (int wait);
@@ -2201,7 +2207,9 @@ extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, lofextern ssize_t do_sync_write (struct file *filp,const char __user *buf,size_t len,loff_t *ppos);extern int generic_segment_checks (const struct iovec *iov,unsigned long *nr_segs,size_t *count,int access_flags); - +#ifdef CONFIG_CHECKPOINT +int generic_file_checkpoint (struct file *file,struct kstate_context *ctx); +#endif /* fs/splice.c */ extern ssize_t generic_file_splice_read (struct file *,loff_t *,struct pipe_inode_info *,size_t ,unsigned int );
include/linux/kstate-image.h new file +118 -0
118 lines not on this page · raw message
include/linux/kstate.h new file +144 -0
144 lines not on this page · raw message
include/linux/mm.h +4 -0
@@ -16,6 +16,7 @@struct mempolicy ;struct anon_vma ; +struct kstate_context ;struct file_ra_state ;struct user_struct ;struct writeback_control ;
@@ -220,6 +221,9 @@ struct vm_operations_struct {int (*migrate)(struct vm_area_struct *vma,const nodemask_t *from,const nodemask_t *to,unsigned long flags);#endif +#ifdef CONFIG_CHECKPOINT +int (*checkpoint)(struct vm_area_struct *vma,struct kstate_context *ctx); +#endif };struct mmu_gather ;
include/linux/syscalls.h +3 -0
@@ -753,6 +753,9 @@ asmlinkage long sys_ppoll(struct pollfd __user *, unsigned int,asmlinkage long sys_pipe2 (int __user *,int );asmlinkage long sys_pipe (int __user *); +asmlinkage long sys_checkpoint (pid_t pid,int fd,int flags); +asmlinkage long sys_restart (int fd,int flags); +int kernel_execve (const char *filename,char *const argv[],char *const envp[]);#endif
init/Kconfig +2 -0
@@ -608,6 +608,8 @@ config CGROUP_MEM_RES_CTLR_SWAP endif # CGROUPS +source "kernel/kstate/Kconfig" + config MM_OWNER bool
kernel/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_FREEZER) += power/ obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o +obj-$(CONFIG_CHECKPOINT) += kstate/ obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_CGROUPS) += cgroup.o obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o
kernel/kstate/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config CHECKPOINT + bool "Container checkpoint/restart" + select FREEZER + help + Container checkpoint/restart. + + Say N.
kernel/kstate/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +obj-$(CONFIG_CHECKPOINT) += kstate.o +kstate-y := cpt-sys.o rst-sys.o +kstate-y += kstate-context.o +kstate-y += kstate-file.o +kstate-y += kstate-image.o +kstate-y += kstate-mm.o +kstate-y += kstate-object.o +kstate-y += kstate-task.o
kernel/kstate/cpt-sys.c new file +196 -0
196 lines not on this page · raw message
kernel/kstate/kstate-context.c new file +49 -0
49 lines not on this page · raw message
kernel/kstate/kstate-file.c new file +204 -0
204 lines not on this page · raw message
kernel/kstate/kstate-image.c new file +116 -0
116 lines not on this page · raw message
kernel/kstate/kstate-mm.c new file +563 -0
563 lines not on this page · raw message
kernel/kstate/kstate-object.c new file +100 -0
100 lines not on this page · raw message
kernel/kstate/kstate-task.c new file +287 -0
287 lines not on this page · raw message
kernel/kstate/rst-sys.c new file +91 -0
91 lines not on this page · raw message
kernel/sys_ni.c +3 -0
@@ -175,3 +175,6 @@ cond_syscall(compat_sys_timerfd_settime);cond_syscall (compat_sys_timerfd_gettime);cond_syscall (sys_eventfd);cond_syscall (sys_eventfd2); + +cond_syscall (sys_checkpoint); +cond_syscall (sys_restart);
mm/filemap.c +3 -0
@@ -1627,6 +1627,9 @@ EXPORT_SYMBOL(filemap_fault);struct vm_operations_struct generic_file_vm_ops = { .fault = filemap_fault, +#ifdef CONFIG_CHECKPOINT + .checkpoint = filemap_checkpoint, +#endif };/* This is used for a general mmap of a disk file */
Signature · 1 line
1.5.6.5
Re: [PATCH 18/38] C/R: core stuff
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.
Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Hi Alexey,
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists - or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot. *Why* are you spending your time on this instead of helping with Oren's set? The code really isn't all that different... Maybe you just think that two independently written patchsets will expose more gotchas that we'll need to catch, so you're continuing on this effort under the expectation that eventualy we'll merge the two sets?
Honestly, I have great respect for your coding abilities. And if 'voices from on high' tell us to base upon your code, I'd be fine with that, I have no real problems with what I see on yet another cursory look. But given the amount of collective time that's been spent developing, reviewing, and testing Oren's set, it wouldn't make any sense to just jump. So I'd still just like to know how you see this proceeding.
thanks,
-serge
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 18/38] C/R: core stuff
Quoted 15 lines · Serge E. Hallyn
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Quoted 7 lines
Hi Alexey,
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists
Is this a requirement? Everybody following topic already knows about Oren's patchset.
Quoted 4 lines
- or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot.
There are differences. And they're not small like you're trying to describe but pretty big compared the scale of the problem.
Quoted 1 line
*Why* are you spending your time on this instead of helping with Oren's set?
Because we disagree with some core directions Oren chose. ANK literally said: "I don't know how to dump live netns".
So, partly patchset was created so that absolutely nobody will tell us to shut up and show the code.
The other part, is that I looked at Oren patchset, found quite a lot of suspicious, broken and unclean places and decided that it'd be faster to start from scratch because sending patches will overhaul like 85% of the code.
One example, is why CKPT_HDR_CPU and CKPT_RESTART_BLOCK exist at all? Should objects in image be only what sharable objects are in kernel (expect VMAs, pages and possibly file descriptors)? pt_regs don't exist by themselves after all.
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too. Because history shows, that once something (especially user-visible, like restart syscall semantics) is in kernel it's nearly impossible to cut it out, so it's very-very important to get it right from the very beginning.
Now here goes second version, with prefixes fixed (kstate_") like Ingo suggested and so Linus could look at the code and with C/R code moved close to usual code and with more checks added (which you should have already!) to not restore null selector in %cs for example.
Quoted 5 lines
The code really isn't all that different...
Maybe you just think that two independently written patchsets will expose more gotchas that we'll need to catch, so you're continuing on this effort under the expectation that eventualy we'll merge the two sets?
Well, it already exposes. Just print both, and watch for differences.
Quoted 6 lines
Honestly, I have great respect for your coding abilities. And if 'voices from on high' tell us to base upon your code, I'd be fine with that, I have no real problems with what I see on yet another cursory look. But given the amount of collective time that's been spent developing, reviewing, and testing Oren's set, it wouldn't make any sense to just jump. So I'd still just like to know how you see this proceeding.
Yes, please, someone decide on "checkpoint semi-live container" issue.
Re: [PATCH 18/38] C/R: core stuff
In reply to Serge E. HallynQuoted 15 lines · Serge E. Hallyn
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Quoted 7 lines
Hi Alexey,
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists
Is this a requirement? Everybody following topic already knows about Oren's patchset.
Quoted 4 lines
- or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot.
There are differences. And they're not small like you're trying to describe but pretty big compared the scale of the problem.
Quoted 1 line
*Why* are you spending your time on this instead of helping with Oren's set?
Because we disagree with some core directions Oren chose. ANK literally said: "I don't know how to dump live netns".
So, partly patchset was created so that absolutely nobody will tell us to shut up and show the code.
The other part, is that I looked at Oren patchset, found quite a lot of suspicious, broken and unclean places and decided that it'd be faster to start from scratch because sending patches will overhaul like 85% of the code.
One example, is why CKPT_HDR_CPU and CKPT_RESTART_BLOCK exist at all? Should objects in image be only what sharable objects are in kernel (expect VMAs, pages and possibly file descriptors)? pt_regs don't exist by themselves after all.
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too. Because history shows, that once something (especially user-visible, like restart syscall semantics) is in kernel it's nearly impossible to cut it out, so it's very-very important to get it right from the very beginning.
Now here goes second version, with prefixes fixed (kstate_") like Ingo suggested and so Linus could look at the code and with C/R code moved close to usual code and with more checks added (which you should have already!) to not restore null selector in %cs for example.
Quoted 5 lines
The code really isn't all that different...
Maybe you just think that two independently written patchsets will expose more gotchas that we'll need to catch, so you're continuing on this effort under the expectation that eventualy we'll merge the two sets?
Well, it already exposes. Just print both, and watch for differences.
Quoted 6 lines
Honestly, I have great respect for your coding abilities. And if 'voices from on high' tell us to base upon your code, I'd be fine with that, I have no real problems with what I see on yet another cursory look. But given the amount of collective time that's been spent developing, reviewing, and testing Oren's set, it wouldn't make any sense to just jump. So I'd still just like to know how you see this proceeding.
Yes, please, someone decide on "checkpoint semi-live container" issue.
Re: [PATCH 18/38] C/R: core stuff
Quoted 9 lines · Alexey Dobriyan
Quoted 6 lines · Serge E. Hallyn
Honestly, I have great respect for your coding abilities. And if 'voices from on high' tell us to base upon your code, I'd be fine with that, I have no real problems with what I see on yet another cursory look. But given the amount of collective time that's been spent developing, reviewing, and testing Oren's set, it wouldn't make any sense to just jump. So I'd still just like to know how you see this proceeding.
Yes, please, someone decide on "checkpoint semi-live container" issue.
Well, *I* for one did decide :) I decided that checkpointing a semi-live container will not bother the kernel, and so the user gets to decide by passing a flag into sys_checkpoint() whether he is ok with a checkpoint if the container was semi-live.
BTW - it looks like your ISP is causing your emails to be flagged as spam by several servers? Several people don't seem to be receiving your patchsets.
-serge
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 18/38] C/R: core stuff
Quoted 9 lines · Alexey Dobriyan
Quoted 6 lines · Serge E. Hallyn
Honestly, I have great respect for your coding abilities. And if 'voices from on high' tell us to base upon your code, I'd be fine with that, I have no real problems with what I see on yet another cursory look. But given the amount of collective time that's been spent developing, reviewing, and testing Oren's set, it wouldn't make any sense to just jump. So I'd still just like to know how you see this proceeding.
Yes, please, someone decide on "checkpoint semi-live container" issue.
Well, *I* for one did decide :) I decided that checkpointing a semi-live container will not bother the kernel, and so the user gets to decide by passing a flag into sys_checkpoint() whether he is ok with a checkpoint if the container was semi-live.
BTW - it looks like your ISP is causing your emails to be flagged as spam by several servers? Several people don't seem to be receiving your patchsets.
-serge
Re: [PATCH 18/38] C/R: core stuff
In reply to a message not in the archiveQuoted 2 lines · Alexey Dobriyan
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too.
Can you rephrase here? I have no idea what you mean by 'drag every single idea'
Quoted 4 lines
Because history shows, that once something (especially user-visible, like restart syscall semantics) is in kernel it's nearly impossible to cut it out, so it's very-very important to get it right from the very beginning.
Absolutely agree (at least in terms of the API for sys_restart() and sys_checkpoint(), not for inane other stuff like whether there is a CKPT_OBJ_RESTART_BLOCK). That is why 6 months ago we were trying to get to an agreement with Andrey Mirkin about a precise API that would definately suit both approaches (in-kernel and userspace task recreation at sys_restart). That way the basics could go upstream and the rest could get settled later as we see the fallout from either decision.
-serge
Re: [PATCH 18/38] C/R: core stuff
In reply to a message not in the archiveQuoted 4 lines · Alexey Dobriyan
The other part, is that I looked at Oren patchset, found quite a lot of suspicious, broken and unclean places and decided that it'd be faster to start from scratch because sending patches will overhaul like 85% of the code.
I know the feeling. I get sudden urges to rewrite the whole patch set, but I'm working on getting past them too. :)
As long as we have two patch sets, *nobody* is going to get their patches in, that's virtually guaranteed. Just look at the poor I/O controller.
The OpenVZ users are almost certainly the most important container and c/r users out there today. Meeting their needs with whatever we come up with should be a top priority and I know I'm counting on you to help us do that.
But, I'm having a really hard time culling the OpenVZ user needs from your patch set. If we really need to rewrite 85% of Oren's stuff to meet the OpenVZ needs, then by all means let's do it. I'm even willing to help you. But, I honestly don't know what you need.
Can we talk about specifics?
-- Dave
Re: [PATCH 18/38] C/R: core stuff
In reply to a message not in the archiveQuoted 4 lines · Alexey Dobriyan
The other part, is that I looked at Oren patchset, found quite a lot of suspicious, broken and unclean places and decided that it'd be faster to start from scratch because sending patches will overhaul like 85% of the code.
I know the feeling. I get sudden urges to rewrite the whole patch set, but I'm working on getting past them too. :)
As long as we have two patch sets, *nobody* is going to get their patches in, that's virtually guaranteed. Just look at the poor I/O controller.
The OpenVZ users are almost certainly the most important container and c/r users out there today. Meeting their needs with whatever we come up with should be a top priority and I know I'm counting on you to help us do that.
But, I'm having a really hard time culling the OpenVZ user needs from your patch set. If we really need to rewrite 85% of Oren's stuff to meet the OpenVZ needs, then by all means let's do it. I'm even willing to help you. But, I honestly don't know what you need.
Can we talk about specifics?
-- Dave
Re: [PATCH 18/38] C/R: core stuff
In reply to a message not in the archiveQuoted 17 lines · Alexey Dobriyan
Quoted 16 lines · Serge E. Hallyn
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Hi Alexey,
Quoted 8 lines
Quoted 5 lines
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists
Is this a requirement? Everybody following topic already knows about Oren's patchset.
Some people do ack other people's work. See for example patches #1 and #24 in my recent post. You're welcome.
Quoted 8 lines
Quoted 5 lines
- or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot.
There are differences. And they're not small like you're trying to describe but pretty big compared the scale of the problem.
I've asked before, and I repeat now: can you enumerate these "big" scary differences that make it such a "big" problem ?
So far, we identified two main "design" issues -
1) Whether or not allow c/r of sub-container (partial hierarchy)
2) Creation of restarting process hierarchy in kernel or in userspace
As for #1, you are the _only_ one who advocates restricting c/r to a full container only. I guess you have your reasons, but I'm unsure what they may be.
On the other hand, there has been a handful of use-cases and opinions in favor of allowing both capabilities to co-exist. Not the mention that nearly no additional code is necessary, on the contrary.
As for #2, you didn't even bother to reply to the discussion that I had started about it. This decision is important to allow future flexibility of the mechanism, and to address the needs of several potential users, as seen in that discussion and others. Here, too, you are the _only_ one that advocates that direction.
And the funniest thing -- *both* decisions can be *easily* overturned in my patchset. In fact, regarding #2 - either way can be easily done in it.
So I wonder, what are the "big" issues that bother you so much ? "if there is a will, there is a way".
Quoted 5 lines
Quoted 2 lines
*Why* are you spending your time on this instead of helping with Oren's set?
Because we disagree with some core directions Oren chose. ANK literally said: "I don't know how to dump live netns".
Eh... and you have it all sorted out ? (yeah, I do, but not in this patchset).
Quoted 3 lines
So, partly patchset was created so that absolutely nobody will tell us to shut up and show the code.
Oh well ... "the" code meaning "your" code I suppose.
Quoted 5 lines
The other part, is that I looked at Oren patchset, found quite a lot of suspicious, broken and unclean places and decided that it'd be faster to start from scratch because sending patches will overhaul like 85% of the code.
So you actually took the time to read and review. And then you spent even more time in .... calculating this number ! Feedback appreciated.
If you looked closely you would have seen that we do address your concerns over time.
Quoted 5 lines
One example, is why
CKPT_HDR_CPUandCKPT_RESTART_BLOCKexist at all? Should objects in image be only what sharable objects are in kernel (expect VMAs, pages and possibly file descriptors)?pt_regsdon't exist by themselves after all.
A good reason to break it into small pieces is for ease of maintenance and debugging, as well as in the future easier transition between incompatible kernel versions. I think it's better than a few-pages-long single struct. And it encourages more naming of things.
But ... I'm confused ... is this your "big" concern ? Oh well, if that's what stands in your way, we could even rework that (~1.3% of the code ? I reckon...).
Quoted 8 lines
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too. Because history shows, that once something (especially user-visible, like restart syscall semantics) is in kernel it's nearly impossible to cut it out, so it's very-very important to get it right from the very beginning.
Yes. Let's indeed talk about how to get it "right". Please do participate in the public discussions and efforts. Working together would be better for everyone.
Quoted 4 lines
Now here goes second version, with prefixes fixed (
kstate_") like Ingo suggested and so Linus could look at the code and with C/R code moved close to usual code and with more checks added (which you should have already!) to not restore null selector in %cs for example.
It is far from perfect. In fact, it's even clearly commented as such, and exactly there. It would have been helpful if you pointed that out in a review, or even - god forbid - sent a patch to improve it.
But it works, and it lets people play with a more-than-a-toy implementation and provide us with important feedback. Oh, and by the way, it doesn't require that people use containers to try it out. Pretty handy, don't you think ?
Quoted 9 lines
Quoted 6 lines
The code really isn't all that different...
Maybe you just think that two independently written patchsets will expose more gotchas that we'll need to catch, so you're continuing on this effort under the expectation that eventualy we'll merge the two sets?
Well, it already exposes. Just print both, and watch for differences.
Quoted 8 lines
Quoted 6 lines
Honestly, I have great respect for your coding abilities. And if 'voices from on high' tell us to base upon your code, I'd be fine with that, I have no real problems with what I see on yet another cursory look. But given the amount of collective time that's been spent developing, reviewing, and testing Oren's set, it wouldn't make any sense to just jump. So I'd still just like to know how you see this proceeding.
Yes, please, someone decide on "checkpoint semi-live container" issue.
Have you not yet read enough opinion of users that would like to see this capability ? What would be enough to convince you ? And really, why not ?
Cheers,
Oren.
Re: [PATCH 18/38] C/R: core stuff
In reply to Alexey DobriyanQuoted 2 lines · Alexey Dobriyan
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too.
Can you rephrase here? I have no idea what you mean by 'drag every single idea'
Quoted 4 lines
Because history shows, that once something (especially user-visible, like restart syscall semantics) is in kernel it's nearly impossible to cut it out, so it's very-very important to get it right from the very beginning.
Absolutely agree (at least in terms of the API for sys_restart() and sys_checkpoint(), not for inane other stuff like whether there is a CKPT_OBJ_RESTART_BLOCK). That is why 6 months ago we were trying to get to an agreement with Andrey Mirkin about a precise API that would definately suit both approaches (in-kernel and userspace task recreation at sys_restart). That way the basics could go upstream and the rest could get settled later as we see the fallout from either decision.
-serge
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 18/38] C/R: core stuff
Quoted 6 lines · Serge E. Hallyn
Quoted 2 lines · Alexey Dobriyan
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too.
Can you rephrase here? I have no idea what you mean by 'drag every single idea'
complexity
+-|------------------------------------------------|----------------------|-->
hypervisor C/R in-kernel C/R C/R for unpriviledged
C/R with "leaks"
I personally thought in-kernel C/R will be rejected outright, but it wasn't. This in theory doesn't mean other two issues should be accepted.
Re: [PATCH 18/38] C/R: core stuff
In reply to Serge E. HallynQuoted 6 lines · Serge E. Hallyn
Quoted 2 lines · Alexey Dobriyan
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too.
Can you rephrase here? I have no idea what you mean by 'drag every single idea'
complexity
+-|------------------------------------------------|----------------------|-->
hypervisor C/R in-kernel C/R C/R for unpriviledged
C/R with "leaks"
I personally thought in-kernel C/R will be rejected outright, but it wasn't. This in theory doesn't mean other two issues should be accepted.
Re: [PATCH 18/38] C/R: core stuff
Quoted 8 lines · Alexey Dobriyan
Quoted 6 lines · Serge E. Hallyn
Quoted 2 lines · Alexey Dobriyan
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too.
Can you rephrase here? I have no idea what you mean by 'drag every single idea'
Quoted 7 lines
complexity
+-|------------------------------------------------|----------------------|-->
hypervisor C/R in-kernel C/R C/R for unpriviledged
C/R with "leaks"I personally thought in-kernel C/R will be rejected outright, but it wasn't. This in theory doesn't mean other two issues should be accepted.
Note again that leaving c/R unprivileged was suggested (By Arnd) as a way to keep us on our toes. When it actually goes upstream I would prefer it be under a new CAP_CHECKPOINT_RESTART capability, not CAP_SYS_ADMIN.
-serge
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 18/38] C/R: core stuff
Quoted 8 lines · Alexey Dobriyan
Quoted 6 lines · Serge E. Hallyn
Quoted 2 lines · Alexey Dobriyan
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too.
Can you rephrase here? I have no idea what you mean by 'drag every single idea'
Quoted 7 lines
complexity
+-|------------------------------------------------|----------------------|-->
hypervisor C/R in-kernel C/R C/R for unpriviledged
C/R with "leaks"I personally thought in-kernel C/R will be rejected outright, but it wasn't. This in theory doesn't mean other two issues should be accepted.
Note again that leaving c/R unprivileged was suggested (By Arnd) as a way to keep us on our toes. When it actually goes upstream I would prefer it be under a new CAP_CHECKPOINT_RESTART capability, not CAP_SYS_ADMIN.
-serge
Re: [PATCH 18/38] C/R: core stuff
In reply to a message not in the archiveQuoted 8 lines · Alexey Dobriyan
Quoted 6 lines · Serge E. Hallyn
Quoted 2 lines · Alexey Dobriyan
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too.
Can you rephrase here? I have no idea what you mean by 'drag every single idea'
Quoted 7 lines
complexity
+-|------------------------------------------------|----------------------|-->
hypervisor C/R in-kernel C/R C/R for unpriviledged
C/R with "leaks"I personally thought in-kernel C/R will be rejected outright, but it wasn't. This in theory doesn't mean other two issues should be accepted.
Note again that leaving c/R unprivileged was suggested (By Arnd) as a way to keep us on our toes. When it actually goes upstream I would prefer it be under a new CAP_CHECKPOINT_RESTART capability, not CAP_SYS_ADMIN.
-serge
Re: [PATCH 18/38] C/R: core stuff
In reply to a message not in the archiveQuoted 8 lines · Alexey Dobriyan
Quoted 6 lines · Serge E. Hallyn
Quoted 2 lines · Alexey Dobriyan
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too.
Can you rephrase here? I have no idea what you mean by 'drag every single idea'
Quoted 7 lines
complexity
+-|------------------------------------------------|----------------------|-->
hypervisor C/R in-kernel C/R C/R for unpriviledged
C/R with "leaks"I personally thought in-kernel C/R will be rejected outright, but it wasn't. This in theory doesn't mean other two issues should be accepted.
Note again that leaving c/R unprivileged was suggested (By Arnd) as a way to keep us on our toes. When it actually goes upstream I would prefer it be under a new CAP_CHECKPOINT_RESTART capability, not CAP_SYS_ADMIN.
-serge
Re: [PATCH 18/38] C/R: core stuff
In reply to a message not in the archiveQuoted 4 lines · Alexey Dobriyan
Quoted 3 lines · Serge E. Hallyn
Quoted 2 lines · Alexey Dobriyan
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too.
Quoted 8 lines
Quoted 2 lines
Can you rephrase here? I have no idea what you mean by 'drag every single idea'
complexity
+-|------------------------------------------------|----------------------|-->
hypervisor C/R in-kernel C/R C/R for unpriviledged
C/R with "leaks"
c/r for unprivileged users is indeed more complex - requires more care. Keep in mind, however, that most of that are sanity checks that we would like to have in the code anyway.
c/r with "leaks" is actually a subset of the code that prevents leaks:
simply comment out the leak detection :)
Oren.
Quoted 7 lines
I personally thought in-kernel C/R will be rejected outright, but it wasn't. This in theory doesn't mean other two issues should be accepted.
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [PATCH 18/38] C/R: core stuff
In reply to Alexey DobriyanQuoted 4 lines · Alexey Dobriyan
Quoted 3 lines · Serge E. Hallyn
Quoted 2 lines · Alexey Dobriyan
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too.
Quoted 8 lines
Quoted 2 lines
Can you rephrase here? I have no idea what you mean by 'drag every single idea'
complexity
+-|------------------------------------------------|----------------------|-->
hypervisor C/R in-kernel C/R C/R for unpriviledged
C/R with "leaks"
c/r for unprivileged users is indeed more complex - requires more care. Keep in mind, however, that most of that are sanity checks that we would like to have in the code anyway.
c/r with "leaks" is actually a subset of the code that prevents leaks:
simply comment out the leak detection :)
Oren.
Quoted 7 lines
I personally thought in-kernel C/R will be rejected outright, but it wasn't. This in theory doesn't mean other two issues should be accepted.
_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [PATCH 18/38] C/R: core stuff
In reply to Alexey DobriyanQuoted 4 lines · Alexey Dobriyan
The other part, is that I looked at Oren patchset, found quite a lot of suspicious, broken and unclean places and decided that it'd be faster to start from scratch because sending patches will overhaul like 85% of the code.
I know the feeling. I get sudden urges to rewrite the whole patch set, but I'm working on getting past them too. :)
As long as we have two patch sets, *nobody* is going to get their patches in, that's virtually guaranteed. Just look at the poor I/O controller.
The OpenVZ users are almost certainly the most important container and c/r users out there today. Meeting their needs with whatever we come up with should be a top priority and I know I'm counting on you to help us do that.
But, I'm having a really hard time culling the OpenVZ user needs from your patch set. If we really need to rewrite 85% of Oren's stuff to meet the OpenVZ needs, then by all means let's do it. I'm even willing to help you. But, I honestly don't know what you need.
Can we talk about specifics?
-- Dave
Re: [PATCH 18/38] C/R: core stuff
In reply to Alexey DobriyanQuoted 17 lines · Alexey Dobriyan
Quoted 16 lines · Serge E. Hallyn
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Hi Alexey,
Quoted 8 lines
Quoted 5 lines
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists
Is this a requirement? Everybody following topic already knows about Oren's patchset.
Some people do ack other people's work. See for example patches #1 and #24 in my recent post. You're welcome.
Quoted 8 lines
Quoted 5 lines
- or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot.
There are differences. And they're not small like you're trying to describe but pretty big compared the scale of the problem.
I've asked before, and I repeat now: can you enumerate these "big" scary differences that make it such a "big" problem ?
So far, we identified two main "design" issues -
1) Whether or not allow c/r of sub-container (partial hierarchy)
2) Creation of restarting process hierarchy in kernel or in userspace
As for #1, you are the _only_ one who advocates restricting c/r to a full container only. I guess you have your reasons, but I'm unsure what they may be.
On the other hand, there has been a handful of use-cases and opinions in favor of allowing both capabilities to co-exist. Not the mention that nearly no additional code is necessary, on the contrary.
As for #2, you didn't even bother to reply to the discussion that I had started about it. This decision is important to allow future flexibility of the mechanism, and to address the needs of several potential users, as seen in that discussion and others. Here, too, you are the _only_ one that advocates that direction.
And the funniest thing -- *both* decisions can be *easily* overturned in my patchset. In fact, regarding #2 - either way can be easily done in it.
So I wonder, what are the "big" issues that bother you so much ? "if there is a will, there is a way".
Quoted 5 lines
Quoted 2 lines
*Why* are you spending your time on this instead of helping with Oren's set?
Because we disagree with some core directions Oren chose. ANK literally said: "I don't know how to dump live netns".
Eh... and you have it all sorted out ? (yeah, I do, but not in this patchset).
Quoted 3 lines
So, partly patchset was created so that absolutely nobody will tell us to shut up and show the code.
Oh well ... "the" code meaning "your" code I suppose.
Quoted 5 lines
The other part, is that I looked at Oren patchset, found quite a lot of suspicious, broken and unclean places and decided that it'd be faster to start from scratch because sending patches will overhaul like 85% of the code.
So you actually took the time to read and review. And then you spent even more time in .... calculating this number ! Feedback appreciated.
If you looked closely you would have seen that we do address your concerns over time.
Quoted 5 lines
One example, is why
CKPT_HDR_CPUandCKPT_RESTART_BLOCKexist at all? Should objects in image be only what sharable objects are in kernel (expect VMAs, pages and possibly file descriptors)?pt_regsdon't exist by themselves after all.
A good reason to break it into small pieces is for ease of maintenance and debugging, as well as in the future easier transition between incompatible kernel versions. I think it's better than a few-pages-long single struct. And it encourages more naming of things.
But ... I'm confused ... is this your "big" concern ? Oh well, if that's what stands in your way, we could even rework that (~1.3% of the code ? I reckon...).
Quoted 8 lines
And since you guys showed that just idea of in-kernel checkpointing is not rejected outright, it doesn't mean that you can drag every single idea too. Because history shows, that once something (especially user-visible, like restart syscall semantics) is in kernel it's nearly impossible to cut it out, so it's very-very important to get it right from the very beginning.
Yes. Let's indeed talk about how to get it "right". Please do participate in the public discussions and efforts. Working together would be better for everyone.
Quoted 4 lines
Now here goes second version, with prefixes fixed (
kstate_") like Ingo suggested and so Linus could look at the code and with C/R code moved close to usual code and with more checks added (which you should have already!) to not restore null selector in %cs for example.
It is far from perfect. In fact, it's even clearly commented as such, and exactly there. It would have been helpful if you pointed that out in a review, or even - god forbid - sent a patch to improve it.
But it works, and it lets people play with a more-than-a-toy implementation and provide us with important feedback. Oh, and by the way, it doesn't require that people use containers to try it out. Pretty handy, don't you think ?
Quoted 9 lines
Quoted 6 lines
The code really isn't all that different...
Maybe you just think that two independently written patchsets will expose more gotchas that we'll need to catch, so you're continuing on this effort under the expectation that eventualy we'll merge the two sets?
Well, it already exposes. Just print both, and watch for differences.
Quoted 8 lines
Quoted 6 lines
Honestly, I have great respect for your coding abilities. And if 'voices from on high' tell us to base upon your code, I'd be fine with that, I have no real problems with what I see on yet another cursory look. But given the amount of collective time that's been spent developing, reviewing, and testing Oren's set, it wouldn't make any sense to just jump. So I'd still just like to know how you see this proceeding.
Yes, please, someone decide on "checkpoint semi-live container" issue.
Have you not yet read enough opinion of users that would like to see this capability ? What would be enough to convince you ? And really, why not ?
Cheers,
Oren.
Re: [PATCH 18/38] C/R: core stuff
Quoted 36 lines · Oren Laadan
Quoted 17 lines · Alexey Dobriyan
Quoted 16 lines · Serge E. Hallyn
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Hi Alexey,
Quoted 8 lines
Quoted 5 lines
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists
Is this a requirement? Everybody following topic already knows about Oren's patchset.
Some people do ack other people's work. See for example patches #1 and #24 in my recent post. You're welcome.
Quoted 6 lines
Quoted 5 lines
- or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot.
Quoted 7 lines
Quoted 2 lines
There are differences. And they're not small like you're trying to describe but pretty big compared the scale of the problem.
I've asked before, and I repeat now: can you enumerate these "big" scary differences that make it such a "big" problem ?
So far, we identified two main "design" issues -
Why in "? Yes, they are high-level design issues.
Quoted 7 lines
1) Whether or not allow c/r of sub-container (partial hierarchy)
2) Creation of restarting process hierarchy in kernel or in userspace
As for #1, you are the _only_ one who advocates restricting c/r to a full container only. I guess you have your reasons, but I'm unsure what they may be.
The reason is that checkpointing half-frozen, half-live container is essentially equivalent to live container which adds much complexity to code fundamentally preventing kernel from taking coherent snapshot.
In such situations kernel will do its job badly.
Manpage will be filled with strings like "if $FOO is shared then $BAR is not guaranteed".
What to do if user simply doesn't know if container is bounded? Checkpoint and to hell with consequences?
If two tasks share mm_struct you can't even detect that pages you dump aren't filled with garbage meanwhile from second task.
If two tasks share mm_struct, other task can issue AIO indefinitely preventing from taking even coherent filesystem snapshot.
That's why I raise this issue again to hear from people what they think and these people shouldn't be containers and C/R people, because the latter already made up their minds.
This is super-important issue to get right from the beginning.
Quoted 9 lines
On the other hand, there has been a handful of use-cases and opinions in favor of allowing both capabilities to co-exist. Not the mention that nearly no additional code is necessary, on the contrary.
As for #2, you didn't even bother to reply to the discussion that I had started about it. This decision is important to allow future flexibility of the mechanism, and to address the needs of several potential users, as seen in that discussion and others. Here, too, you are the _only_ one that advocates that direction.
Are you going to fork to-become-zombies, make them call restart(2) and zombify?
Quoted 6 lines
And the funniest thing -- *both* decisions can be *easily* overturned in my patchset. In fact, regarding #2 - either way can be easily done in it.
So I wonder, what are the "big" issues that bother you so much ? "if there is a will, there is a way".
Oren, don't you really understand?
Users want millions of things, but every thing has price.
Some think hardlinking of directories should be implemented. You can ask VFS guys how hard would it be and how hard would it be to do reliably without races/deadlocks et al.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 18/38] C/R: core stuff
Quoted 23 lines · On Thu, 28 May 2009 02:17:53 +0400 Alexey Dobriyan…
Quoted 7 lines
1) Whether or not allow c/r of sub-container (partial hierarchy)
2) Creation of restarting process hierarchy in kernel or in userspace
As for #1, you are the _only_ one who advocates restricting c/r to a full container only. I guess you have your reasons, but I'm unsure what they may be.
The reason is that checkpointing half-frozen, half-live container is essentially equivalent to live container which adds much complexity to code fundamentally preventing kernel from taking coherent snapshot.
In such situations kernel will do its job badly.
Manpage will be filled with strings like "if $FOO is shared then $BAR is not guaranteed".
What to do if user simply doesn't know if container is bounded? Checkpoint and to hell with consequences?
If two tasks share
mm_structyou can't even detect that pages you dump aren't filled with garbage meanwhile from second task.
Quoted 8 lines
If two tasks share
mm_struct, other task can issue AIO indefinitely preventing from taking even coherent filesystem snapshot.That's why I raise this issue again to hear from people what they think and these people shouldn't be containers and C/R people, because the latter already made up their minds.
This is super-important issue to get right from the beginning.
<pipes up>
yeah, checkpointing a partial hierarchy at this stage sounds like overreach. Get full-container working usably first, think about sub-containers in version 2.
<pipes down again>
Re: [PATCH 18/38] C/R: core stuff
In reply to a message not in the archiveQuoted 33 lines · Alexey Dobriyan
Quoted 32 lines · Oren Laadan
Quoted 17 lines · Alexey Dobriyan
Quoted 16 lines · Serge E. Hallyn
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Hi Alexey,
Quoted 7 lines
Quoted 5 lines
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists
Is this a requirement? Everybody following topic already knows about Oren's patchset.
Some people do ack other people's work. See for example patches #1 and #24 in my recent post. You're welcome.
Quoted 4 lines
Quoted 4 lines
- or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
There are differences. And they're not small like you're trying to describe but pretty big compared the scale of the problem.
I've asked before, and I repeat now: can you enumerate these "big" scary differences that make it such a "big" problem ?
So far, we identified two main "design" issues -
Why in "? Yes, they are high-level design issues.
In quotes, because I argued further on that, although my patchset takes a stand on both issues, it can be easily reverted _within_ that patchset. Moreover, I argue that they can co-exist.
Quoted 8 lines
Quoted 7 lines
1) Whether or not allow c/r of sub-container (partial hierarchy)
2) Creation of restarting process hierarchy in kernel or in userspace
As for #1, you are the _only_ one who advocates restricting c/r to a full container only. I guess you have your reasons, but I'm unsure what they may be.
Quoted 5 lines
The reason is that checkpointing half-frozen, half-live container is essentially equivalent to live container which adds much complexity to code fundamentally preventing kernel from taking coherent snapshot.
In such situations kernel will do its job badly.
In such situation the kernel will do a bad job if the user is asking for a bad job. Just like checkpointing without snapshotting the file system and expecting it to always work.
But if the user is a bit more careful (and even then, not that much), she can enjoy the wonderful benefits of c/r without the wonderful benefits of containers.
If useful, it's easy to pass a flag to checkpoint() that will ask to enforce, say, shared memory "leaks" but not nsproxy or file "leaks".
In fact, even shared memory "leaks" may be useful for some users (e.g. what the guys from kerlabs pointed out).
Quoted 10 lines
Manpage will be filled with strings like "if $FOO is shared then $BAR is not guaranteed".
What to do if user simply doesn't know if container is bounded? Checkpoint and to hell with consequences?
If two tasks share
mm_structyou can't even detect that pages you dump aren't filled with garbage meanwhile from second task.
Quoted 6 lines
If two tasks share
mm_struct, other task can issue AIO indefinitely preventing from taking even coherent filesystem snapshot.That's why I raise this issue again to hear from people what they think and these people shouldn't be containers and C/R people, because the latter already made up their minds.
Lol .. and disagreement persists among us :)
And indeed, I have heard and seen already a few opinions in favor of permitting non-container checkpoint. From potential users (not c/r people).
Quoted 7 lines
This is super-important issue to get right from the beginning.
Quoted 4 lines
On the other hand, there has been a handful of use-cases and opinions in favor of allowing both capabilities to co-exist. Not the mention that nearly no additional code is necessary, on the contrary.
Quoted 8 lines
Quoted 5 lines
As for #2, you didn't even bother to reply to the discussion that I had started about it. This decision is important to allow future flexibility of the mechanism, and to address the needs of several potential users, as seen in that discussion and others. Here, too, you are the _only_ one that advocates that direction.
Are you going to fork to-become-zombies, make them call restart(2) and zombify?
Yes.
Quoted 11 lines
Quoted 7 lines
And the funniest thing -- *both* decisions can be *easily* overturned in my patchset. In fact, regarding #2 - either way can be easily done in it.
So I wonder, what are the "big" issues that bother you so much ? "if there is a will, there is a way".
Oren, don't you really understand?
Users want millions of things, but every thing has price.
I beg to differ: there is marginal price to support both -- in fact, enforcing the container requirement (e.g. leaks detection - which, btw, is imperfect and cannot be made race-free) *adds* code over the non-container case. So in a sense, we get the no-container case for free.
Oren.
Andrew Morton
maintainerRe: [PATCH 18/38] C/R: core stuff
In reply to Alexey DobriyanQuoted 23 lines · On Thu, 28 May 2009 02:17:53 +0400 Alexey Dobriyan <[email protected]> wrote:
Quoted 7 lines
1) Whether or not allow c/r of sub-container (partial hierarchy)
2) Creation of restarting process hierarchy in kernel or in userspace
As for #1, you are the _only_ one who advocates restricting c/r to a full container only. I guess you have your reasons, but I'm unsure what they may be.
The reason is that checkpointing half-frozen, half-live container is essentially equivalent to live container which adds much complexity to code fundamentally preventing kernel from taking coherent snapshot.
In such situations kernel will do its job badly.
Manpage will be filled with strings like "if $FOO is shared then $BAR is not guaranteed".
What to do if user simply doesn't know if container is bounded? Checkpoint and to hell with consequences?
If two tasks share
mm_structyou can't even detect that pages you dump aren't filled with garbage meanwhile from second task.
Quoted 8 lines
If two tasks share
mm_struct, other task can issue AIO indefinitely preventing from taking even coherent filesystem snapshot.That's why I raise this issue again to hear from people what they think and these people shouldn't be containers and C/R people, because the latter already made up their minds.
This is super-important issue to get right from the beginning.
<pipes up>
yeah, checkpointing a partial hierarchy at this stage sounds like overreach. Get full-container working usably first, think about sub-containers in version 2.
<pipes down again>
Re: [PATCH 18/38] C/R: core stuff
In reply to Alexey DobriyanQuoted 33 lines · Alexey Dobriyan
Quoted 32 lines · Oren Laadan
Quoted 17 lines · Alexey Dobriyan
Quoted 16 lines · Serge E. Hallyn
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Hi Alexey,
Quoted 7 lines
Quoted 5 lines
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists
Is this a requirement? Everybody following topic already knows about Oren's patchset.
Some people do ack other people's work. See for example patches #1 and #24 in my recent post. You're welcome.
Quoted 4 lines
Quoted 4 lines
- or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
There are differences. And they're not small like you're trying to describe but pretty big compared the scale of the problem.
I've asked before, and I repeat now: can you enumerate these "big" scary differences that make it such a "big" problem ?
So far, we identified two main "design" issues -
Why in "? Yes, they are high-level design issues.
In quotes, because I argued further on that, although my patchset takes a stand on both issues, it can be easily reverted _within_ that patchset. Moreover, I argue that they can co-exist.
Quoted 8 lines
Quoted 7 lines
1) Whether or not allow c/r of sub-container (partial hierarchy)
2) Creation of restarting process hierarchy in kernel or in userspace
As for #1, you are the _only_ one who advocates restricting c/r to a full container only. I guess you have your reasons, but I'm unsure what they may be.
Quoted 5 lines
The reason is that checkpointing half-frozen, half-live container is essentially equivalent to live container which adds much complexity to code fundamentally preventing kernel from taking coherent snapshot.
In such situations kernel will do its job badly.
In such situation the kernel will do a bad job if the user is asking for a bad job. Just like checkpointing without snapshotting the file system and expecting it to always work.
But if the user is a bit more careful (and even then, not that much), she can enjoy the wonderful benefits of c/r without the wonderful benefits of containers.
If useful, it's easy to pass a flag to checkpoint() that will ask to enforce, say, shared memory "leaks" but not nsproxy or file "leaks".
In fact, even shared memory "leaks" may be useful for some users (e.g. what the guys from kerlabs pointed out).
Quoted 10 lines
Manpage will be filled with strings like "if $FOO is shared then $BAR is not guaranteed".
What to do if user simply doesn't know if container is bounded? Checkpoint and to hell with consequences?
If two tasks share
mm_structyou can't even detect that pages you dump aren't filled with garbage meanwhile from second task.
Quoted 6 lines
If two tasks share
mm_struct, other task can issue AIO indefinitely preventing from taking even coherent filesystem snapshot.That's why I raise this issue again to hear from people what they think and these people shouldn't be containers and C/R people, because the latter already made up their minds.
Lol .. and disagreement persists among us :)
And indeed, I have heard and seen already a few opinions in favor of permitting non-container checkpoint. From potential users (not c/r people).
Quoted 7 lines
This is super-important issue to get right from the beginning.
Quoted 4 lines
On the other hand, there has been a handful of use-cases and opinions in favor of allowing both capabilities to co-exist. Not the mention that nearly no additional code is necessary, on the contrary.
Quoted 8 lines
Quoted 5 lines
As for #2, you didn't even bother to reply to the discussion that I had started about it. This decision is important to allow future flexibility of the mechanism, and to address the needs of several potential users, as seen in that discussion and others. Here, too, you are the _only_ one that advocates that direction.
Are you going to fork to-become-zombies, make them call restart(2) and zombify?
Yes.
Quoted 11 lines
Quoted 7 lines
And the funniest thing -- *both* decisions can be *easily* overturned in my patchset. In fact, regarding #2 - either way can be easily done in it.
So I wonder, what are the "big" issues that bother you so much ? "if there is a will, there is a way".
Oren, don't you really understand?
Users want millions of things, but every thing has price.
I beg to differ: there is marginal price to support both -- in fact, enforcing the container requirement (e.g. leaks detection - which, btw, is imperfect and cannot be made race-free) *adds* code over the non-container case. So in a sense, we get the no-container case for free.
Oren.
Re: [PATCH 18/38] C/R: core stuff
Quoted 56 lines · Oren Laadan
Quoted 33 lines · Alexey Dobriyan
Quoted 32 lines · Oren Laadan
Quoted 17 lines · Alexey Dobriyan
Quoted 16 lines · Serge E. Hallyn
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Hi Alexey,
Quoted 7 lines
Quoted 5 lines
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists
Is this a requirement? Everybody following topic already knows about Oren's patchset.
Some people do ack other people's work. See for example patches #1 and #24 in my recent post. You're welcome.
Quoted 4 lines
Quoted 4 lines
- or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
There are differences. And they're not small like you're trying to describe but pretty big compared the scale of the problem.
I've asked before, and I repeat now: can you enumerate these "big" scary differences that make it such a "big" problem ?
So far, we identified two main "design" issues -
Why in "? Yes, they are high-level design issues.
In quotes, because I argued further on that, although my patchset takes a stand on both issues, it can be easily reverted _within_ that patchset. Moreover, I argue that they can co-exist.
Quoted 8 lines
Quoted 7 lines
1) Whether or not allow c/r of sub-container (partial hierarchy)
2) Creation of restarting process hierarchy in kernel or in userspace
As for #1, you are the _only_ one who advocates restricting c/r to a full container only. I guess you have your reasons, but I'm unsure what they may be.
Quoted 8 lines
Quoted 5 lines
The reason is that checkpointing half-frozen, half-live container is essentially equivalent to live container which adds much complexity to code fundamentally preventing kernel from taking coherent snapshot.
In such situations kernel will do its job badly.
In such situation the kernel will do a bad job if the user is asking for a bad job.
User doesn't even understand why we're discussing this issue so hard.
Quoted 2 lines
Just like checkpointing without snapshotting the file system and expecting it to always work.
This is different.
Kernel can't do anything about not-synced fs. Because nodoby is advocating that kernel should sync fs. Consequently, screwup in fs sync is clearly user failure. Any (yours, mine) in-kernel C/R has this failure mode, so we skip it and discuss what's left.
Now, kernel CAN do something about tasks and other data structures because it easily controls them.
Your procedure for checkpointing starts with "kill -STOP".
To make anything reliable, you have to ban "kill -CONT" for the duration of checkpointing. Is this done BTW? I don't remember new flags added in task_struct. Or this is going to be skipped on grounds that it's user screwup (potentially oopsable).
That's why, OpenVZ relies on suspend-to-ram freezer solely, because userspace can't arbitrarily send suspend and freeze notifications. We only need to protect against untimely STR unfreeze which only adds code in C/R code not in task_struct.
But you aren't going to stop with task_struct, and add such flags all over the place. Or you're going to declare that it's all user fault.
Quoted 56 lines
But if the user is a bit more careful (and even then, not that much), she can enjoy the wonderful benefits of c/r without the wonderful benefits of containers.
If useful, it's easy to pass a flag to
checkpoint()that will ask to enforce, say, shared memory "leaks" but not nsproxy or file "leaks".In fact, even shared memory "leaks" may be useful for some users (e.g. what the guys from kerlabs pointed out).
Quoted 10 lines
Manpage will be filled with strings like "if $FOO is shared then $BAR is not guaranteed".
What to do if user simply doesn't know if container is bounded? Checkpoint and to hell with consequences?
If two tasks share
mm_structyou can't even detect that pages you dump aren't filled with garbage meanwhile from second task.Quoted 6 lines
If two tasks share
mm_struct, other task can issue AIO indefinitely preventing from taking even coherent filesystem snapshot.That's why I raise this issue again to hear from people what they think and these people shouldn't be containers and C/R people, because the latter already made up their minds.
Lol .. and disagreement persists among us :)
And indeed, I have heard and seen already a few opinions in favor of permitting non-container checkpoint. From potential users (not c/r people).
Quoted 7 lines
This is super-important issue to get right from the beginning.
Quoted 4 lines
On the other hand, there has been a handful of use-cases and opinions in favor of allowing both capabilities to co-exist. Not the mention that nearly no additional code is necessary, on the contrary.
Quoted 8 lines
Quoted 5 lines
As for #2, you didn't even bother to reply to the discussion that I had started about it. This decision is important to allow future flexibility of the mechanism, and to address the needs of several potential users, as seen in that discussion and others. Here, too, you are the _only_ one that advocates that direction.
Are you going to fork to-become-zombies, make them call restart(2) and zombify?
Yes.
Quoted 5 lines
Quoted 5 lines
And the funniest thing -- *both* decisions can be *easily* overturned in my patchset. In fact, regarding #2 - either way can be easily done in it.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
So I wonder, what are the "big" issues that bother you so much ? "if there is a will, there is a way".
Oren, don't you really understand?
Users want millions of things, but every thing has price.
I beg to differ: there is marginal price to support both --
Wrong, try to do netns with sockets without deadlocks.
Price in loose case is strictly bigger than price in strict case because set of loose states is strict superset of set of strict cases.
Quoted 2 lines
in fact, enforcing the container requirement (e.g. leaks detection - which, btw, is imperfect and cannot be made race-free)
It'll only generate false positives when say /proc/$PID/maps is being read from outside, so mm->mm_users is elevated. I can return -EAGAIN.
If file is opened via /proc/*/fd, proc_fd_access_allowed() is only needed to be tweaked and use task_struct field, not new struct file field.
->mmap_sem is taken only for reading in /proc, so fine.
/proc/*/mem -- tweak mem_open().
struct pid, itself -- refcount can be elevated because someone chdir'ed into /proc/*, but I don't do refcount checks on struct pid, because it's hard (inode in memory pins struct pid) and pids numbers themselves don't change once taken. So, if struct pid is somehow leaked to outside, there will be NO incoherency in image and no problems with locking or whatever.
For netns elevated refcount, get_proc_task_net() will also reject open(2) request based on task_struct field, not netns field!
I'm sorry, but all bases re refcount checks are pretty well covered and are easily closed with tiny bit of code.
Please show counter-examples where after all data structures are collected and tasks being frozen and refcount checks passed, userspace can still access one of them for writing.
Quoted 1 line
*adds* code over the non-container case.
Whole 8 lines per data-structure:
for_each_kstate_object(ctx, obj, KSTATE_CTX_MM_STRUCT) {
struct mm_struct *mm = obj->o_obj;
unsigned int cnt = atomic_read(&mm->mm_users);
if (obj->o_count + 1 != cnt) {
pr_err("mm_struct %p has external references %lu:%u\n", mm, obj->o_count, cnt);
return -EINVAL;
}
}No locking, no nothing, just counting refcounts.
Quoted 1 line
So in a sense, we get the no-container case for free.
Not for free definitely.
Re: [PATCH 18/38] C/R: core stuff
Quoted 74 lines · Alexey Dobriyan
Quoted 53 lines · Oren Laadan
Quoted 33 lines · Alexey Dobriyan
Quoted 32 lines · Oren Laadan
Quoted 17 lines · Alexey Dobriyan
Quoted 16 lines · Serge E. Hallyn
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Hi Alexey,
Quoted 7 lines
Quoted 5 lines
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists
Is this a requirement? Everybody following topic already knows about Oren's patchset.
Some people do ack other people's work. See for example patches #1 and #24 in my recent post. You're welcome.
Quoted 4 lines
Quoted 4 lines
- or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
There are differences. And they're not small like you're trying to describe but pretty big compared the scale of the problem.
I've asked before, and I repeat now: can you enumerate these "big" scary differences that make it such a "big" problem ?
So far, we identified two main "design" issues -
Why in "? Yes, they are high-level design issues.
In quotes, because I argued further on that, although my patchset takes a stand on both issues, it can be easily reverted _within_ that patchset. Moreover, I argue that they can co-exist.
Quoted 7 lines
Quoted 7 lines
1) Whether or not allow c/r of sub-container (partial hierarchy)
2) Creation of restarting process hierarchy in kernel or in userspace
As for #1, you are the _only_ one who advocates restricting c/r to a full container only. I guess you have your reasons, but I'm unsure what they may be.
Quoted 7 lines
Quoted 5 lines
The reason is that checkpointing half-frozen, half-live container is essentially equivalent to live container which adds much complexity to code fundamentally preventing kernel from taking coherent snapshot.
In such situations kernel will do its job badly.
In such situation the kernel will do a bad job if the user is asking for a bad job.
User doesn't even understand why we're discussing this issue so hard.
Quoted 2 lines
Just like checkpointing without snapshotting the file system and expecting it to always work.
This is different.
Kernel can't do anything about not-synced fs. Because nodoby is advocating that kernel should sync fs. Consequently, screwup in fs sync is clearly user failure. Any (yours, mine) in-kernel C/R has this failure mode, so we skip it and discuss what's left.
Quoted 4 lines
Now, kernel CAN do something about tasks and other data structures because it easily controls them.
Your procedure for checkpointing starts with "kill -STOP".
Wrong. It requires the processes to be frozen.
Quoted 9 lines
To make anything reliable, you have to ban "kill -CONT" for the duration of checkpointing. Is this done BTW? I don't remember new flags added in
task_struct. Or this is going to be skipped on grounds that it's user screwup (potentially oopsable).That's why, OpenVZ relies on suspend-to-ram freezer solely, because userspace can't arbitrarily send suspend and freeze notifications. We only need to protect against untimely STR unfreeze which only adds code in C/R code not in
task_struct.
Same principle for both patchsets: tasks may *not* be permitted to execute while being checkpointed.
For this I suggested a CHECKPOINTING freezer state: transition to/from this state is done _only_ by sys_checkpoint(), so that checkpointed processes cannot be unfrozen. Matt Helseley already posted a patch to implement this.
Quoted 3 lines
But you aren't going to stop with
task_struct, and add such flags all over the place. Or you're going to declare that it's all user fault.
I'm unsure what sort of flags you have in mind, or what's the problem that alleged flags would solve ? So far I didn't plan any.
Quoted 51 lines
Quoted 51 lines
But if the user is a bit more careful (and even then, not that much), she can enjoy the wonderful benefits of c/r without the wonderful benefits of containers.
If useful, it's easy to pass a flag to
checkpoint()that will ask to enforce, say, shared memory "leaks" but not nsproxy or file "leaks".In fact, even shared memory "leaks" may be useful for some users (e.g. what the guys from kerlabs pointed out).
Quoted 9 lines
Manpage will be filled with strings like "if $FOO is shared then $BAR is not guaranteed".
What to do if user simply doesn't know if container is bounded? Checkpoint and to hell with consequences?
If two tasks share
mm_structyou can't even detect that pages you dump aren't filled with garbage meanwhile from second task.Quoted 6 lines
If two tasks share
mm_struct, other task can issue AIO indefinitely preventing from taking even coherent filesystem snapshot.That's why I raise this issue again to hear from people what they think and these people shouldn't be containers and C/R people, because the latter already made up their minds.
Lol .. and disagreement persists among us :)
And indeed, I have heard and seen already a few opinions in favor of permitting non-container checkpoint. From potential users (not c/r people).
Quoted 6 lines
This is super-important issue to get right from the beginning.
Quoted 4 lines
On the other hand, there has been a handful of use-cases and opinions in favor of allowing both capabilities to co-exist. Not the mention that nearly no additional code is necessary, on the contrary.
Quoted 7 lines
Quoted 5 lines
As for #2, you didn't even bother to reply to the discussion that I had started about it. This decision is important to allow future flexibility of the mechanism, and to address the needs of several potential users, as seen in that discussion and others. Here, too, you are the _only_ one that advocates that direction.
Are you going to fork to-become-zombies, make them call restart(2) and zombify?
Yes.
Quoted 4 lines
Quoted 4 lines
And the funniest thing -- *both* decisions can be *easily* overturned in my patchset. In fact, regarding #2 - either way can be easily done in it.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
So I wonder, what are the "big" issues that bother you so much ? "if there is a will, there is a way".
Oren, don't you really understand?
Users want millions of things, but every thing has price.
I beg to differ: there is marginal price to support both --
Wrong, try to do netns with sockets without deadlocks.
Let's indeed discuss netns - that's an important issue. But it's also huge - "do netns" may mean different things to different people. How about you start a new thread explaining why it will be such a problem ?
Quoted 3 lines
Price in loose case is strictly bigger than price in strict case because set of loose states is strict superset of set of strict cases.
The code to enforce full-container approach is a *superset* of the code without this requirement.
If you can checkpoint a full container, surely you can checkpoint a sub-hierarchy of processes.
We both agree that the sub-hierarchy case is not idiot-proof: it's garbage in, garbage out. In the worst case, the restart will simply fail, but no other harm done.
(And if you are concerned about security, well - that's a different topic - and one can disable c/r for non privileged users).
Quoted 25 lines
Quoted 3 lines
in fact, enforcing the container requirement (e.g. leaks detection - which, btw, is imperfect and cannot be made race-free)
It'll only generate false positives when say
/proc/$PID/mapsis being read from outside, somm->mm_usersis elevated. I can return-EAGAIN.If file is opened via
/proc/*/fd,proc_fd_access_allowed()is only needed to be tweaked and usetask_structfield, not new struct file field.->mmap_sem is taken only for reading in /proc, so fine.
/proc/*/mem-- tweakmem_open().struct pid, itself -- refcount can be elevated because someone chdir'ed into
/proc/*, but I don't do refcount checks on struct pid, because it's hard (inode in memory pins struct pid) and pids numbers themselves don't change once taken. So, if struct pid is somehow leaked to outside, there will be NO incoherency in image and no problems with locking or whatever.For netns elevated refcount,
get_proc_task_net()will also reject open(2) request based ontask_structfield, not netns field!
Quoted 6 lines
I'm sorry, but all bases re refcount checks are pretty well covered and are easily closed with tiny bit of code.
Please show counter-examples where after all data structures are collected and tasks being frozen and refcount checks passed, userspace can still access one of them for writing.
ptrace ? (sure, can also be "tweaked" to disallow access while task a checkpointing. Everything can :)
Quoted 15 lines
Quoted 2 lines
*adds* code over the non-container case.
Whole 8 lines per data-structure:
for_each_kstate_object(ctx, obj, KSTATE_CTX_MM_STRUCT) { struct mm_struct *mm = obj->o_obj; unsigned int cnt = atomic_read(&mm->mm_users); if (obj->o_count + 1 != cnt) { pr_err("mm_struct %p has external references %lu:%u\n", mm, obj->o_count, cnt); return -EINVAL; } }
Quoted 6 lines
No locking, no nothing, just counting refcounts.
Quoted 1 line
So in a sense, we get the no-container case for free.
Not for free definitely.
s/Not// :)
If you take out (or simply skip) the isolation/coherency tests for a full-container, you are left with ... sub-hierarchy support. Voila.
Oren.
Re: [PATCH 18/38] C/R: core stuff
Quoted 94 lines · Oren Laadan
Quoted 74 lines · Alexey Dobriyan
Quoted 53 lines · Oren Laadan
Quoted 33 lines · Alexey Dobriyan
Quoted 32 lines · Oren Laadan
Quoted 17 lines · Alexey Dobriyan
Quoted 16 lines · Serge E. Hallyn
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Hi Alexey,
Quoted 7 lines
Quoted 5 lines
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists
Is this a requirement? Everybody following topic already knows about Oren's patchset.
Some people do ack other people's work. See for example patches #1 and #24 in my recent post. You're welcome.
Quoted 4 lines
Quoted 4 lines
- or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
There are differences. And they're not small like you're trying to describe but pretty big compared the scale of the problem.
I've asked before, and I repeat now: can you enumerate these "big" scary differences that make it such a "big" problem ?
So far, we identified two main "design" issues -
Why in "? Yes, they are high-level design issues.
In quotes, because I argued further on that, although my patchset takes a stand on both issues, it can be easily reverted _within_ that patchset. Moreover, I argue that they can co-exist.
Quoted 7 lines
Quoted 7 lines
1) Whether or not allow c/r of sub-container (partial hierarchy)
2) Creation of restarting process hierarchy in kernel or in userspace
As for #1, you are the _only_ one who advocates restricting c/r to a full container only. I guess you have your reasons, but I'm unsure what they may be.
Quoted 7 lines
Quoted 5 lines
The reason is that checkpointing half-frozen, half-live container is essentially equivalent to live container which adds much complexity to code fundamentally preventing kernel from taking coherent snapshot.
In such situations kernel will do its job badly.
In such situation the kernel will do a bad job if the user is asking for a bad job.
User doesn't even understand why we're discussing this issue so hard.
Quoted 2 lines
Just like checkpointing without snapshotting the file system and expecting it to always work.
This is different.
Kernel can't do anything about not-synced fs. Because nodoby is advocating that kernel should sync fs. Consequently, screwup in fs sync is clearly user failure. Any (yours, mine) in-kernel C/R has this failure mode, so we skip it and discuss what's left.
Quoted 4 lines
Now, kernel CAN do something about tasks and other data structures because it easily controls them.
Your procedure for checkpointing starts with "kill -STOP".
Wrong. It requires the processes to be frozen.
Quoted 9 lines
To make anything reliable, you have to ban "kill -CONT" for the duration of checkpointing. Is this done BTW? I don't remember new flags added in
task_struct. Or this is going to be skipped on grounds that it's user screwup (potentially oopsable).That's why, OpenVZ relies on suspend-to-ram freezer solely, because userspace can't arbitrarily send suspend and freeze notifications. We only need to protect against untimely STR unfreeze which only adds code in C/R code not in
task_struct.
Quoted 7 lines
Same principle for both patchsets: tasks may *not* be permitted to execute while being checkpointed.
For this I suggested a CHECKPOINTING freezer state: transition to/from this state is done _only_ by
sys_checkpoint(), so that checkpointed processes cannot be unfrozen. Matt Helseley already posted a patch to implement this.
In case it helps, here's the patch and some feedback Oren gave me:
https://lists.linux-foundation.org/pipermail/containers/2009-May/017586.html
Cheers,
-Matt Helsley
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 18/38] C/R: core stuff
Quoted 9 lines · Oren Laadan
Quoted 2 lines · Alexey Dobriyan
Price in loose case is strictly bigger than price in strict case because set of loose states is strict superset of set of strict cases.
The code to enforce full-container approach is a *superset* of the code without this requirement.
If you can checkpoint a full container, surely you can checkpoint a sub-hierarchy of processes.
No!
To checkpoint uts_ns reliably, in strict case, one doesn't even need uts_sem.
In loose case, one needs uts_sem.
static int dump_uts_ns(struct kstate_context *ctx, struct kstate_object *obj)
{
struct uts_namespace *uts_ns = obj->o_obj;
struct kstate_image_uts_ns *i;
int rv;
i = kstate_prepare_image(KSTATE_OBJ_UTS_NS, sizeof(*i));
if (!i)
return -ENOMEM;
if (ctx->dump_live)
down_read(&uts_sem);
strncpy(i->sysname, (const char *)uts_ns->name.sysname, 64);
strncpy(i->nodename, (const char *)uts_ns->name.nodename, 64);
strncpy(i->release, (const char *)uts_ns->name.release, 64);
strncpy(i->version, (const char *)uts_ns->name.version, 64);
strncpy(i->machine, (const char *)uts_ns->name.machine, 64);
strncpy(i->domainname, (const char *)uts_ns->name.domainname, 64);
if (ctx->dump_live)
up_read(&uts_sem);
rv = kstate_write_image(ctx, i, sizeof(*i), obj);
kfree(i);
return rv;
}Re: [PATCH 18/38] C/R: core stuff
In reply to Oren LaadanQuoted 9 lines · Oren Laadan
Quoted 2 lines · Alexey Dobriyan
Price in loose case is strictly bigger than price in strict case because set of loose states is strict superset of set of strict cases.
The code to enforce full-container approach is a *superset* of the code without this requirement.
If you can checkpoint a full container, surely you can checkpoint a sub-hierarchy of processes.
No!
To checkpoint uts_ns reliably, in strict case, one doesn't even need uts_sem.
In loose case, one needs uts_sem.
static int dump_uts_ns(struct kstate_context *ctx, struct kstate_object *obj)
{
struct uts_namespace *uts_ns = obj->o_obj;
struct kstate_image_uts_ns *i;
int rv;
i = kstate_prepare_image(KSTATE_OBJ_UTS_NS, sizeof(*i));
if (!i)
return -ENOMEM;
if (ctx->dump_live)
down_read(&uts_sem);
strncpy(i->sysname, (const char *)uts_ns->name.sysname, 64);
strncpy(i->nodename, (const char *)uts_ns->name.nodename, 64);
strncpy(i->release, (const char *)uts_ns->name.release, 64);
strncpy(i->version, (const char *)uts_ns->name.version, 64);
strncpy(i->machine, (const char *)uts_ns->name.machine, 64);
strncpy(i->domainname, (const char *)uts_ns->name.domainname, 64);
if (ctx->dump_live)
up_read(&uts_sem);
rv = kstate_write_image(ctx, i, sizeof(*i), obj);
kfree(i);
return rv;
}A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 18/38] C/R: core stuff
Quoted 10 lines · Alexey Dobriyan
if (ctx->dump_live)
down_read(&uts_sem);
strncpy(i->sysname, (const char *)uts_ns->name.sysname, 64);
strncpy(i->nodename, (const char *)uts_ns->name.nodename, 64);
strncpy(i->release, (const char *)uts_ns->name.release, 64);
strncpy(i->version, (const char *)uts_ns->name.version, 64);
strncpy(i->machine, (const char *)uts_ns->name.machine, 64);
strncpy(i->domainname, (const char *)uts_ns->name.domainname, 64);
if (ctx->dump_live)
up_read(&uts_sem);Doesn't this turn a minor bug (like a task getting accidentally unfrozen) into a oopsable bug?
I mean, doing this without a lock is nice and all, but it adds code to make it selectable. What's the purpose of avoiding the semaphore anyway? Performance?
-- Dave
Re: [PATCH 18/38] C/R: core stuff
In reply to Alexey DobriyanQuoted 10 lines · Alexey Dobriyan
if (ctx->dump_live)
down_read(&uts_sem);
strncpy(i->sysname, (const char *)uts_ns->name.sysname, 64);
strncpy(i->nodename, (const char *)uts_ns->name.nodename, 64);
strncpy(i->release, (const char *)uts_ns->name.release, 64);
strncpy(i->version, (const char *)uts_ns->name.version, 64);
strncpy(i->machine, (const char *)uts_ns->name.machine, 64);
strncpy(i->domainname, (const char *)uts_ns->name.domainname, 64);
if (ctx->dump_live)
up_read(&uts_sem);Doesn't this turn a minor bug (like a task getting accidentally unfrozen) into a oopsable bug?
I mean, doing this without a lock is nice and all, but it adds code to make it selectable. What's the purpose of avoiding the semaphore anyway? Performance?
-- Dave
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 18/38] C/R: core stuff
Quoted 8 lines · Oren Laadan
Quoted 4 lines
Now here goes second version, with prefixes fixed (
kstate_") like Ingo suggested and so Linus could look at the code and with C/R code moved close to usual code and with more checks added (which you should have already!) to not restore null selector in %cs for example.It is far from perfect. In fact, it's even clearly commented as such, and exactly there. It would have been helpful if you pointed that out in a review, or even - god forbid - sent a patch to improve it.
This is ridiculous.
First, you declare that restart(2) should be allowed for anyone(!). and then send patchset for inclusion in -mm which doesn't even check if selectors are right!
Quoted 3 lines
But it works, and it lets people play with a more-than-a-toy implementation and provide us with important feedback. Oh, and by the way, it doesn't require that people use containers to try it out.
Setting up container for playing is not hard:
CLONE_NEWUTS=y
CLONE_NEWIPC=y
CLONE_NEWPID=y
CLONE_NEWUSER=y
CLONE_NEWNET=y
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#define CLONE_NEWNS 0x00020000
#define CLONE_NEWUTS 0x04000000
#define CLONE_NEWIPC 0x08000000
#define CLONE_NEWUSER 0x10000000
#define CLONE_NEWPID 0x20000000
#define CLONE_NEWNET 0x40000000
static int fn(void *_argv)
{
char **argv = (char **)_argv;
setsid();
setpgid(getpid(), getpid());
execve(argv[0], argv, __environ);
return 1;
}int main(int argc, char *argv[])
{
unsigned long flags = 0;
int status;
pid_t pid;
void *p;
flags |= CLONE_NEWNS;
flags |= CLONE_NEWUTS;
flags |= CLONE_NEWIPC;
flags |= CLONE_NEWUSER;
flags |= CLONE_NEWPID;
flags |= CLONE_NEWNET;
p = malloc(4 * 4096);
if (!p)
return 1;
argv++;
pid = clone(fn, p + 4 * 4096, flags, (void *)argv);
fprintf(stderr, "pid = %d\n", pid);
if (pid == -1)
return 1;
waitpid(pid, &status, __WALL);
return 0;
}Re: [PATCH 18/38] C/R: core stuff
In reply to Oren LaadanQuoted 8 lines · Oren Laadan
Quoted 4 lines
Now here goes second version, with prefixes fixed (
kstate_") like Ingo suggested and so Linus could look at the code and with C/R code moved close to usual code and with more checks added (which you should have already!) to not restore null selector in %cs for example.It is far from perfect. In fact, it's even clearly commented as such, and exactly there. It would have been helpful if you pointed that out in a review, or even - god forbid - sent a patch to improve it.
This is ridiculous.
First, you declare that restart(2) should be allowed for anyone(!). and then send patchset for inclusion in -mm which doesn't even check if selectors are right!
Quoted 3 lines
But it works, and it lets people play with a more-than-a-toy implementation and provide us with important feedback. Oh, and by the way, it doesn't require that people use containers to try it out.
Setting up container for playing is not hard:
CLONE_NEWUTS=y
CLONE_NEWIPC=y
CLONE_NEWPID=y
CLONE_NEWUSER=y
CLONE_NEWNET=y
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#define CLONE_NEWNS 0x00020000
#define CLONE_NEWUTS 0x04000000
#define CLONE_NEWIPC 0x08000000
#define CLONE_NEWUSER 0x10000000
#define CLONE_NEWPID 0x20000000
#define CLONE_NEWNET 0x40000000
static int fn(void *_argv)
{
char **argv = (char **)_argv;
setsid();
setpgid(getpid(), getpid());
execve(argv[0], argv, __environ);
return 1;
}int main(int argc, char *argv[])
{
unsigned long flags = 0;
int status;
pid_t pid;
void *p;
flags |= CLONE_NEWNS;
flags |= CLONE_NEWUTS;
flags |= CLONE_NEWIPC;
flags |= CLONE_NEWUSER;
flags |= CLONE_NEWPID;
flags |= CLONE_NEWNET;
p = malloc(4 * 4096);
if (!p)
return 1;
argv++;
pid = clone(fn, p + 4 * 4096, flags, (void *)argv);
fprintf(stderr, "pid = %d\n", pid);
if (pid == -1)
return 1;
waitpid(pid, &status, __WALL);
return 0;
}A message that is not in the archive (sent off-list or not yet received): 1242968132-1044-18-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 18/38] C/R: core stuff
Quoted 6 lines · Alexey Dobriyan
Introduction
------------
Checkpoint/restart (C/R from now) allows to dump group of processes to disk for various reasons like saving process state in case of box failure or restoration of group of processes on another or same machine later.
Quoted 7 lines
Unlike, let's say, hypervisor C/R style which only needs to freeze guest kernel and dump more or less raw pages, proposed C/R doesn't require hypervisor. For that C/R code needs to know about all little and big intimate kernel details.
The good thing is that not all details needs to be serialized and saved like, say, readahead state. The bad things is still quite a few things need to be.
Hi Alexey,
the last time you posted this, I went through and tried to discern the meaningful differences between yours and Oren's patchsets. Then I sent some patches to Oren to make his set configurable to act more like yours. And Oren took them! But now you resend this patchset with no real changelog, no acknowledgment that Oren's set even exists - or is much farther along and pretty widely reviewed and tested (which is only because he started earlier and, when we asked for your counterpatches at an earlier stage, you would never reply) - or, most importantly, what it is that you think your patchset does that his does not and cannot. *Why* are you spending your time on this instead of helping with Oren's set? The code really isn't all that different... Maybe you just think that two independently written patchsets will expose more gotchas that we'll need to catch, so you're continuing on this effort under the expectation that eventualy we'll merge the two sets?
Honestly, I have great respect for your coding abilities. And if 'voices from on high' tell us to base upon your code, I'd be fine with that, I have no real problems with what I see on yet another cursory look. But given the amount of collective time that's been spent developing, reviewing, and testing Oren's set, it wouldn't make any sense to just jump. So I'd still just like to know how you see this proceeding.
thanks,
-serge
Re: [PATCH 18/38] C/R: core stuff
In reply to a message not in the archiveQuoted 5 lines · Alexey Dobriyan
(quoted diff) +5
-0+static int task_struct_restorer(void *_tsk_ctx) +{ + struct task_struct_restore_context *tsk_ctx = _tsk_ctx; + struct kstate_image_task_struct *i = tsk_ctx->i; + struct kstate_context *ctx = tsk_ctx->ctx;
Review
Quoted 10 lines
(quoted diff) +10
-0+ /* In the name of symmetry. */ + struct task_struct *tsk = current, *real_parent; + int rv; + + pr_debug("%s: ENTER tsk %p/%s\n", __func__, tsk, tsk->comm); + + write_lock_irq(&tasklist_lock); + real_parent = ctx->init_tsk->nsproxy->pid_ns->child_reaper; + tsk->real_parent = tsk->parent = real_parent; + list_move_tail(&tsk->sibling, &tsk->real_parent->sibling);
^^^^^^^
Review
Quoted 1 line
(quoted diff) +1
-0+ write_unlock_irq(&tasklist_lock);
Eek, what a stupid bug here
commit 2c4b5f5d606a1892b702d95a0e4d29f207685381
Author: Alexey Dobriyan <[email protected]> Date: Wed May 27 20:21:59 2009 +0400
C/R: fix stupid bug in reparenting
Child process should be added to ->children list of course
kernel/kstate/kstate-task.c +1 -1
@@ -490,7 +490,7 @@ static int task_struct_restorer(void *_tsk_ctx) real_parent = tmp->o_obj; } tsk->real_parent = tsk->parent = real_parent; -list_move_tail (&tsk->sibling, &tsk->real_parent->sibling); +list_move_tail (&tsk->sibling, &tsk->real_parent->children);write_unlock_irq (&tasklist_lock); rv =restore_mm (ctx, &i->ref_mm);
Re: [PATCH 18/38] C/R: core stuff
In reply to Alexey DobriyanQuoted 5 lines · Alexey Dobriyan
(quoted diff) +5
-0+static int task_struct_restorer(void *_tsk_ctx) +{ + struct task_struct_restore_context *tsk_ctx = _tsk_ctx; + struct kstate_image_task_struct *i = tsk_ctx->i; + struct kstate_context *ctx = tsk_ctx->ctx;
Review
Quoted 10 lines
(quoted diff) +10
-0+ /* In the name of symmetry. */ + struct task_struct *tsk = current, *real_parent; + int rv; + + pr_debug("%s: ENTER tsk %p/%s\n", __func__, tsk, tsk->comm); + + write_lock_irq(&tasklist_lock); + real_parent = ctx->init_tsk->nsproxy->pid_ns->child_reaper; + tsk->real_parent = tsk->parent = real_parent; + list_move_tail(&tsk->sibling, &tsk->real_parent->sibling);
^^^^^^^
Review
Quoted 1 line
(quoted diff) +1
-0+ write_unlock_irq(&tasklist_lock);
Eek, what a stupid bug here
commit 2c4b5f5d606a1892b702d95a0e4d29f207685381
Author: Alexey Dobriyan <[email protected]> Date: Wed May 27 20:21:59 2009 +0400
C/R: fix stupid bug in reparenting
Child process should be added to ->children list of course
kernel/kstate/kstate-task.c +1 -1
@@ -490,7 +490,7 @@ static int task_struct_restorer(void *_tsk_ctx) real_parent = tmp->o_obj; } tsk->real_parent = tsk->parent = real_parent; -list_move_tail (&tsk->sibling, &tsk->real_parent->sibling); +list_move_tail (&tsk->sibling, &tsk->real_parent->children);write_unlock_irq (&tasklist_lock); rv =restore_mm (ctx, &i->ref_mm);
PATCH 19/38 C/R: multiple tasks
In reply to Alexey DobriyanRestore task hierarchy wrt ->real_parent.
First thing soon-to-be-restored task does after birth is to find ->real_parent and glue itself to parent lists.
For this parent is dumped first and restored first, so that at the time child starts restoration, parent is already up and running as task_struct, and we get cheap loop-prevention check.
--- include/linux/kstate-image.h | 2 + kernel/kstate/kstate-object.c | 3 +- kernel/kstate/kstate-task.c | 53 +++++++++++++++++++++++++++++++++++----- 3 files changed, 50 insertions(+), 8 deletions(-)
include/linux/kstate-image.h +2 -0
@@ -60,6 +60,8 @@ struct kstate_object_header {struct kstate_image_task_struct {struct kstate_object_header hdr; +kstate_ref_t ref_real_parent; +kstate_ref_t ref_mm;__u8 comm[16 ];
kernel/kstate/kstate-object.c +2 -1
@@ -25,7 +25,8 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte obj->o_ref.pos =0 ;/* not yet dumped */ obj->o_ref.id =0 ;/* not yet assigned */ obj->o_obj = p; -list_add (&obj->o_list, &ctx->obj[type]); +/* task_struct collecting relies on "_tail" part. */ +list_add_tail (&obj->o_list, &ctx->obj[type]);switch (type) {case KSTATE_CTX_FILE :
kernel/kstate/kstate-task.c +46 -7
78 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 20/38 C/R: i386 support
In reply to Alexey DobriyanSegment registers are abstracted to allow i386 => x86_64 migration (BTW, I'm not so sure if just making 32-bit selectors the same will achieve same effect)
--- arch/x86/include/asm/unistd_32.h | 2 + arch/x86/kernel/syscall_table_32.S | 2 + include/linux/kstate-image.h | 30 ++++ include/linux/kstate.h | 2 +- kernel/kstate/Makefile | 1 + kernel/kstate/kstate-x86_32.c | 294 ++++++++++++++++++++++++++++++++++++ 6 files changed, 330 insertions(+), 1 deletions(-) create mode 100644 kernel/kstate/kstate-x86_32.c
arch/x86/include/asm/unistd_32.h +2 -0
@@ -340,6 +340,8 @@#define __NR_inotify_init1 332#define __NR_preadv 333#define __NR_pwritev 334 +#define __NR_checkpoint 335 +#define __NR_restart 336#ifdef __KERNEL__
arch/x86/kernel/syscall_table_32.S +2 -0
@@ -334,3 +334,5 @@ ENTRY(sys_call_table) .long sys_inotify_init1 .long sys_preadv .long sys_pwritev + .long sys_checkpoint /* 335 */ + .long sys_restart
include/linux/kstate-image.h +30 -0
@@ -27,6 +27,7 @@ struct kstate_image_header {/* Mutable part. */ /* Arch of the kernel which dumped the image. */ +#define KSTATE_ARCH_I386 1__le32 kernel_arch;/* * Distributions are expected to leave image version alone and
@@ -70,6 +71,35 @@ struct kstate_image_task_struct {__u32 tsk_arch; } __packed; +#define KSTATE_SEG_NULL 0 +#define KSTATE_SEG_USER32_CS 1 +#define KSTATE_SEG_USER32_DS 2 +#define KSTATE_SEG_TLS 0x4000/* 0100 0000 0000 00xx */ +#define KSTATE_SEG_LDT 0x8000/* 100x xxxx xxxx xxxx */ + +struct kstate_image_task_struct_i386 { +__u32 ebx; +__u32 ecx; +__u32 edx; +__u32 esi; +__u32 edi; +__u32 ebp; +__u32 eax; +__u32 orig_eax; +__u32 eip; +__u32 eflags; +__u32 esp; + +__u16 cs; +__u16 ds; +__u16 es; +__u16 fs; +__u16 gs; +__u16 ss; + +__u64 tls_array[3 ]; +} __packed; +struct kstate_image_mm_struct {struct kstate_object_header hdr;
include/linux/kstate.h +1 -1
@@ -67,7 +67,7 @@ int kstate_collect_all_file(struct kstate_context *ctx);int kstate_dump_all_file (struct kstate_context *ctx);int kstate_restore_file (struct kstate_context *ctx,kstate_ref_t *ref); -#if 0 +#if defined(CONFIG_X86_32 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/Makefile +1 -0
@@ -6,3 +6,4 @@ kstate-y += kstate-image.o kstate-y += kstate-mm.o kstate-y += kstate-object.o kstate-y += kstate-task.o +kstate-$(CONFIG_X86_32) += kstate-x86_32.o
kernel/kstate/kstate-x86_32.c new file +294 -0
294 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 21/38 C/R: i386 debug registers
In reply to Alexey DobriyanMake extensive checks to not allow restoration of breakpoints inside kernel code.
--- arch/x86/include/asm/ptrace.h | 5 +++++ arch/x86/kernel/ptrace.c | 8 ++++---- include/linux/kstate-image.h | 7 +++++++ kernel/kstate/kstate-x86_32.c | 26 ++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 8 deletions(-)
arch/x86/include/asm/ptrace.h +5 -0
@@ -243,6 +243,11 @@ extern void x86_ptrace_fork(struct task_struct *child,#define arch_ptrace_untrace (tsk) x86_ptrace_untrace(tsk)#define arch_ptrace_fork (child, flags) x86_ptrace_fork(child, flags) +extern int ptrace_check_debugreg (int _32bit, +unsigned long dr0,unsigned long dr1, +unsigned long dr2,unsigned long dr3, +unsigned long dr6,unsigned long dr7); +#endif /* __KERNEL__ */ #endif /* !__ASSEMBLY__ */
arch/x86/kernel/ptrace.c +4 -4
@@ -465,10 +465,10 @@ static unsigned long ptrace_get_debugreg(struct task_struct *child, int n)return 0 ; } -static int ptrace_check_debugreg (int _32bit, -unsigned long dr0,unsigned long dr1, -unsigned long dr2,unsigned long dr3, -unsigned long dr6,unsigned long dr7) +int ptrace_check_debugreg (int _32bit, +unsigned long dr0,unsigned long dr1, +unsigned long dr2,unsigned long dr3, +unsigned long dr6,unsigned long dr7) {/* Breakpoint type: 00: --x, 01: -w-, 10: undefined, 11: rw- */ unsigned int rw[4 ];
include/linux/kstate-image.h +7 -0
@@ -97,6 +97,13 @@ struct kstate_image_task_struct_i386 {__u16 gs;__u16 ss; +__u32 dr0; +__u32 dr1; +__u32 dr2; +__u32 dr3; +__u32 dr6; +__u32 dr7; +__u64 tls_array[3 ]; } __packed;
kernel/kstate/kstate-x86_32.c +22 -4
@@ -106,6 +106,10 @@ int kstate_arch_check_image_task_struct(struct kstate_image_task_struct *tsk_i)if (rv <0 )return rv; + rv =ptrace_check_debugreg (1 , i->dr0, i->dr1, i->dr2, i->dr3, i->dr6, i->dr7); +if (rv <0 ) +return rv; +if (i->tls_array[0 ]) { rv =check_tls ((struct desc_struct *)&i->tls_array[0 ]);if (rv <0 )
@@ -138,10 +142,6 @@ int kstate_arch_check_task_struct(struct task_struct *tsk)WARN_ON (1 );return -EINVAL ; } -if (test_tsk_thread_flag (tsk,TIF_DEBUG )) { -WARN_ON (1 ); -return -EINVAL ; - } rb = &task_thread_info (tsk)->restart_block;if (rb->fn !=current_thread_info ()->restart_block.fn) {WARN (1 ,"rb->fn = %pF\n" , rb->fn);
@@ -226,6 +226,13 @@ int kstate_arch_dump_task_struct(struct kstate_context *ctx, struct task_struct i->gs =encode_segment (tsk->thread.gs); i->ss =encode_segment (regs->ss); + i->dr0 = tsk->thread.debugreg0; + i->dr1 = tsk->thread.debugreg1; + i->dr2 = tsk->thread.debugreg2; + i->dr3 = tsk->thread.debugreg3; + i->dr6 = tsk->thread.debugreg6; + i->dr7 = tsk->thread.debugreg7; +BUILD_BUG_ON (sizeof (tsk->thread.tls_array[0 ]) !=8 );BUILD_BUG_ON (sizeof (tsk->thread.tls_array) !=3 *8 );memcpy (i->tls_array, tsk->thread.tls_array,sizeof (i->tls_array));
@@ -261,6 +268,17 @@ static int restore_task_struct_i386(struct task_struct *tsk, struct kstate_image tsk->thread.gs =decode_segment (i->gs); regs->ss =decode_segment (i->ss); + tsk->thread.debugreg0 = i->dr0; + tsk->thread.debugreg1 = i->dr1; + tsk->thread.debugreg2 = i->dr2; + tsk->thread.debugreg3 = i->dr3; + tsk->thread.debugreg6 = i->dr6; + tsk->thread.debugreg7 = i->dr7; +if (i->dr7) +set_tsk_thread_flag (tsk,TIF_DEBUG ); +else +clear_tsk_thread_flag (tsk,TIF_DEBUG ); +memcpy (tsk->thread.tls_array, i->tls_array,3 *8 );return 0 ;
Signature · 1 line
1.5.6.5
PATCH 22/38 C/R: i386 xstate
In reply to Alexey DobriyanThe only check is if xstate length doesn't match. This is insufficient, but posted anyway, because glibc manages to do FP calculations and create xstate which would prevent checkpointing.
--- include/linux/kstate-image.h | 3 ++ kernel/kstate/kstate-x86_32.c | 44 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-)
include/linux/kstate-image.h +3 -0
@@ -105,6 +105,9 @@ struct kstate_image_task_struct_i386 {__u32 dr7;__u64 tls_array[3 ]; + +__u32 len_xstate; +/* __u8 xstate[len_xstate]; */ } __packed;struct kstate_image_mm_struct {
kernel/kstate/kstate-x86_32.c +39 -5
97 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 23/38 C/R: x86_64 support
In reply to Alexey DobriyanIn theory and in practice, x86_64 COMPAT=y kernel will restore i386 images and in other direction. There are small problems still and it doesn't work, but mentioning anyway.
Right now x86_64 kernel restores only x86_64 images and 64-bit tasks.
--- arch/x86/ia32/ia32entry.S | 2 + arch/x86/include/asm/unistd_64.h | 4 + include/linux/kstate-image.h | 36 ++++ include/linux/kstate.h | 2 +- kernel/kstate/Makefile | 1 + kernel/kstate/kstate-x86_64.c | 336 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 380 insertions(+), 1 deletions(-) create mode 100644 kernel/kstate/kstate-x86_64.c
arch/x86/ia32/ia32entry.S +2 -0
@@ -830,4 +830,6 @@ ia32_sys_call_table: .quad sys_inotify_init1 .quad compat_sys_preadv .quad compat_sys_pwritev + .quad sys_checkpoint /* 335 */ + .quad sys_restart ia32_syscall_end:
arch/x86/include/asm/unistd_64.h +4 -0
@@ -657,6 +657,10 @@ __SYSCALL(__NR_inotify_init1, sys_inotify_init1) __SYSCALL(__NR_preadv, sys_preadv)#define __NR_pwritev 296 __SYSCALL(__NR_pwritev, sys_pwritev) +#define __NR_checkpoint 297 +__SYSCALL(__NR_checkpoint, sys_checkpoint) +#define __NR_restart 298 +__SYSCALL(__NR_restart, sys_restart)#ifndef __NO_STUBS
include/linux/kstate-image.h +36 -0
@@ -28,6 +28,7 @@ struct kstate_image_header {/* Mutable part. */ /* Arch of the kernel which dumped the image. */ #define KSTATE_ARCH_I386 1 +#define KSTATE_ARCH_X86_64 2__le32 kernel_arch;/* * Distributions are expected to leave image version alone and
@@ -74,6 +75,8 @@ struct kstate_image_task_struct {#define KSTATE_SEG_NULL 0#define KSTATE_SEG_USER32_CS 1#define KSTATE_SEG_USER32_DS 2 +#define KSTATE_SEG_USER64_CS 3 +#define KSTATE_SEG_USER64_DS 4#define KSTATE_SEG_TLS 0x4000/* 0100 0000 0000 00xx */ #define KSTATE_SEG_LDT 0x8000/* 100x xxxx xxxx xxxx */
@@ -110,6 +113,39 @@ struct kstate_image_task_struct_i386 {/* __u8 xstate[len_xstate]; */ } __packed; +struct kstate_image_task_struct_x86_64 { +__u64 r15; +__u64 r14; +__u64 r13; +__u64 r12; +__u64 rbp; +__u64 rbx; +__u64 r11; +__u64 r10; +__u64 r9; +__u64 r8; +__u64 rax; +__u64 rcx; +__u64 rdx; +__u64 rsi; +__u64 rdi; +__u64 orig_rax; +__u64 rip; +__u64 rflags; +__u64 rsp; + +__u64 fs; +__u64 gs; +__u16 cs; +__u16 ds; +__u16 es; +__u16 fsindex; +__u16 gsindex; +__u16 ss; + +__u64 tls_array[3 ]; +} __packed; +struct kstate_image_mm_struct {struct kstate_object_header hdr;
include/linux/kstate.h +1 -1
@@ -67,7 +67,7 @@ int kstate_collect_all_file(struct kstate_context *ctx);int kstate_dump_all_file (struct kstate_context *ctx);int kstate_restore_file (struct kstate_context *ctx,kstate_ref_t *ref); -#if defined(CONFIG_X86_32 ) +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/Makefile +1 -0
@@ -7,3 +7,4 @@ kstate-y += kstate-mm.o kstate-y += kstate-object.o kstate-y += kstate-task.o kstate-$(CONFIG_X86_32) += kstate-x86_32.o +kstate-$(CONFIG_X86_64) += kstate-x86_64.o
kernel/kstate/kstate-x86_64.c new file +336 -0
336 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 24/38 C/R: x86_64 debug registers
In reply to Alexey Dobriyan--- include/linux/kstate-image.h | 7 +++++++ kernel/kstate/kstate-x86_64.c | 26 ++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-)
include/linux/kstate-image.h +7 -0
@@ -143,6 +143,13 @@ struct kstate_image_task_struct_x86_64 {__u16 gsindex;__u16 ss; +__u64 dr0; +__u64 dr1; +__u64 dr2; +__u64 dr3; +__u64 dr6; +__u64 dr7; +__u64 tls_array[3 ]; } __packed;
kernel/kstate/kstate-x86_64.c +22 -4
@@ -109,6 +109,10 @@ static int check_image_task_struct_x86_64(struct kstate_image_task_struct *tsk_iif (rv <0 )return rv; + rv =ptrace_check_debugreg (0 , i->dr0, i->dr1, i->dr2, i->dr3, i->dr6, i->dr7); +if (rv <0 ) +return rv; +if (i->tls_array[0 ]) { rv =check_tls ((struct desc_struct *)&i->tls_array[0 ]);if (rv <0 )
@@ -150,10 +154,6 @@ int kstate_arch_check_task_struct(struct task_struct *tsk) return -EINVAL; }#endif -if (test_tsk_thread_flag (tsk,TIF_DEBUG )) { -WARN_ON (1 ); -return -EINVAL ; - }if (tsk->thread.xstate) {WARN_ON (1 );return -EINVAL ;
@@ -250,6 +250,13 @@ static int dump_task_struct_x86_64(struct kstate_context *ctx, struct task_struc i->gsindex =encode_segment (tsk->thread.gsindex); i->ss =encode_segment (regs->ss); + i->dr0 = tsk->thread.debugreg0; + i->dr1 = tsk->thread.debugreg1; + i->dr2 = tsk->thread.debugreg2; + i->dr3 = tsk->thread.debugreg3; + i->dr6 = tsk->thread.debugreg6; + i->dr7 = tsk->thread.debugreg7; +BUILD_BUG_ON (sizeof (tsk->thread.tls_array[0 ]) !=8 );BUILD_BUG_ON (sizeof (tsk->thread.tls_array) !=3 *8 );memcpy (i->tls_array, tsk->thread.tls_array,sizeof (i->tls_array));
@@ -299,6 +306,17 @@ static int restore_task_struct_x86_64(struct task_struct *tsk, struct kstate_ima tsk->thread.gsindex =decode_segment (i->gsindex); regs->ss =decode_segment (i->ss); + tsk->thread.debugreg0 = i->dr0; + tsk->thread.debugreg1 = i->dr1; + tsk->thread.debugreg2 = i->dr2; + tsk->thread.debugreg3 = i->dr3; + tsk->thread.debugreg6 = i->dr6; + tsk->thread.debugreg7 = i->dr7; +if (i->dr7) +set_tsk_thread_flag (tsk,TIF_DEBUG ); +else +clear_tsk_thread_flag (tsk,TIF_DEBUG ); +memcpy (tsk->thread.tls_array, i->tls_array,sizeof (i->tls_array));set_tsk_thread_flag (tsk,TIF_FORK );
Signature · 1 line
1.5.6.5
PATCH 25/38 C/R: x86_64 xstate
In reply to Alexey DobriyanAgain, checks aren't enough on all counts.
--- include/linux/kstate-image.h | 3 ++ kernel/kstate/kstate-x86_64.c | 44 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-)
include/linux/kstate-image.h +3 -0
@@ -151,6 +151,9 @@ struct kstate_image_task_struct_x86_64 {__u64 dr7;__u64 tls_array[3 ]; + +__u8 len_xstate; +/* __u8 xstate[len_xstate]; */ } __packed;struct kstate_image_mm_struct {
kernel/kstate/kstate-x86_64.c +39 -5
98 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 26/38 C/R: nsproxy
In reply to Alexey DobriyanIt can't be argued, that nsproxy shouldn't even be dumped, because pointers inside nsproxy are interesting. This is correct, however this creates addtitional code on restart and frankly more that several nsproxies are rare, so nobody cares.
Current algorithm is simplest:
- dump all namespaces
- dump nsproxy as KSTATE_OBJ_NSPROXY type filled with references
- on restore, read reference, read and restore namespace if needed, bump refcount, glue namespace to nsproxy.
--- include/linux/kstate-image.h | 6 ++ include/linux/kstate.h | 5 ++ kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 6 ++ kernel/kstate/kstate-object.c | 4 + kernel/kstate/kstate-task.c | 26 ++++++++ kernel/nsproxy.c | 129 +++++++++++++++++++++++++++++++++++++++- 7 files changed, 181 insertions(+), 1 deletions(-) create mode 100644 kernel/kstate/kstate-nsproxy.c
include/linux/kstate-image.h +6 -0
@@ -43,6 +43,7 @@ struct kstate_image_header {#define KSTATE_OBJ_FILE 3#define KSTATE_OBJ_VMA 4#define KSTATE_OBJ_PAGE 5 +#define KSTATE_OBJ_NSPROXY 6struct kstate_object_header {__u32 obj_type;
@@ -65,6 +66,7 @@ struct kstate_image_task_struct {kstate_ref_t ref_real_parent;kstate_ref_t ref_mm; +kstate_ref_t ref_nsproxy;__u8 comm[16 ];
@@ -203,4 +205,8 @@ struct kstate_image_file {__u32 name_len;/* including NUL */ /* __u8 name[name_len] */ } __packed; + +struct kstate_image_nsproxy { +struct kstate_object_header hdr; +} __packed;#endif
include/linux/kstate.h +5 -0
@@ -23,6 +23,7 @@ struct kstate_object {enum kstate_context_obj_type {KSTATE_CTX_FILE ,KSTATE_CTX_MM_STRUCT , +KSTATE_CTX_NSPROXY ,KSTATE_CTX_TASK_STRUCT ,NR_KSTATE_CTX_TYPES };
@@ -67,6 +68,10 @@ int kstate_collect_all_file(struct kstate_context *ctx);int kstate_dump_all_file (struct kstate_context *ctx);int kstate_restore_file (struct kstate_context *ctx,kstate_ref_t *ref); +int kstate_collect_all_nsproxy (struct kstate_context *ctx); +int kstate_dump_all_nsproxy (struct kstate_context *ctx); +int kstate_restore_nsproxy (struct kstate_context *ctx,kstate_ref_t *ref); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
@@ -65,6 +65,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_task_struct (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_nsproxy (ctx); +if (rv <0 ) +return rv; rv =kstate_collect_all_mm_struct (ctx);if (rv <0 )return rv;
@@ -127,6 +130,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_mm_struct (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_nsproxy (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_task_struct (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +6 -0
@@ -1,6 +1,7 @@/* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */ #include <linux/file.h> #include <linux/list.h> +#include <linux/nsproxy.h> #include <linux/sched.h> #include <linux/slab.h>
@@ -40,6 +41,11 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_NSPROXY ) { +put_nsproxy ((struct nsproxy *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_TASK_STRUCT ) {put_task_struct ((struct task_struct *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-nsproxy.c new file +0 -0
kernel/kstate/kstate-object.c +4 -0
@@ -1,6 +1,7 @@/* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */ #include <linux/fs.h> #include <linux/mm_types.h> +#include <linux/nsproxy.h> #include <linux/sched.h> #include <linux/slab.h>
@@ -35,6 +36,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_MM_STRUCT :atomic_inc (&((struct mm_struct *)obj->o_obj)->mm_users);break ; +case KSTATE_CTX_NSPROXY : +get_nsproxy ((struct nsproxy *)obj->o_obj); +break ;case KSTATE_CTX_TASK_STRUCT :get_task_struct ((struct task_struct *)obj->o_obj);break ;
kernel/kstate/kstate-task.c +26 -0
@@ -120,6 +120,9 @@ static int dump_task_struct(struct kstate_context *ctx, struct kstate_object *ob tmp =find_kstate_obj_by_ptr (ctx, tsk->mm,KSTATE_CTX_MM_STRUCT ); i->ref_mm = tmp->o_ref; + tmp =find_kstate_obj_by_ptr (ctx, tsk->nsproxy,KSTATE_CTX_NSPROXY ); + i->ref_nsproxy = tmp->o_ref; +BUILD_BUG_ON (sizeof (i->comm) !=sizeof (tsk->comm));strlcpy ((char *)i->comm, (const char *)tsk->comm,sizeof (i->comm));
@@ -208,6 +211,26 @@ static int restore_mm(struct kstate_context *ctx, kstate_ref_t *ref)return 0 ; } +static int restore_nsproxy (struct kstate_context *ctx,kstate_ref_t *ref) +{ +struct nsproxy *nsproxy; +struct kstate_object *tmp; +int rv; + + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_NSPROXY ); +if (!tmp) { + rv =kstate_restore_nsproxy (ctx, ref); +if (rv <0 ) +return rv; + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_NSPROXY ); + } + nsproxy = tmp->o_obj; + +get_nsproxy (nsproxy); +switch_task_namespaces (current, nsproxy); +return 0 ; +} +struct task_struct_restore_context {struct kstate_context *ctx;struct kstate_image_task_struct *i;
@@ -253,6 +276,9 @@ static int task_struct_restorer(void *_tsk_ctx) rv =restore_mm (ctx, &i->ref_mm);if (rv <0 ) goto out; + rv =restore_nsproxy (ctx, &i->ref_nsproxy); +if (rv <0 ) + goto out; out: tsk_ctx->rv = rv;
kernel/nsproxy.c +128 -1
143 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 27/38 C/R: checkpoint/restore struct uts_namespace
In reply to Alexey DobriyanThe simplest thing.
Note, no locking is done, because we know:
a) tasks are frozen and thus can't change it
b) number of collected references is correct, so nobody else is using uts_namespace and thus can't change it under dump
If live checkpointing will be done, code will be changed to something like:
if (ctx->dump_live) down_read(&uts_sem); ... if (ctx->dump_live) up_read(&uts_sem);
--- include/linux/kstate-image.h | 14 +++++ include/linux/kstate.h | 5 ++ kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 6 ++ kernel/kstate/kstate-object.c | 4 ++ kernel/nsproxy.c | 33 +++++++++++-- kernel/utsname.c | 106 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 170 insertions(+), 4 deletions(-) delete mode 100644 kernel/kstate/kstate-nsproxy.c create mode 100644 kernel/kstate/kstate-uts_ns.c
include/linux/kstate-image.h +14 -0
@@ -44,6 +44,7 @@ struct kstate_image_header {#define KSTATE_OBJ_VMA 4#define KSTATE_OBJ_PAGE 5#define KSTATE_OBJ_NSPROXY 6 +#define KSTATE_OBJ_UTS_NS 7struct kstate_object_header {__u32 obj_type;
@@ -208,5 +209,18 @@ struct kstate_image_file {struct kstate_image_nsproxy {struct kstate_object_header hdr; + +kstate_ref_t ref_uts_ns; +} __packed; + +struct kstate_image_uts_ns { +struct kstate_object_header hdr; + +__u8 sysname[64 ]; +__u8 nodename[64 ]; +__u8 release[64 ]; +__u8 version[64 ]; +__u8 machine[64 ]; +__u8 domainname[64 ]; } __packed;#endif
include/linux/kstate.h +5 -0
@@ -25,6 +25,7 @@ enum kstate_context_obj_type {KSTATE_CTX_MM_STRUCT ,KSTATE_CTX_NSPROXY ,KSTATE_CTX_TASK_STRUCT , +KSTATE_CTX_UTS_NS , NR_KSTATE_CTX_TYPES };
@@ -72,6 +73,10 @@ int kstate_collect_all_nsproxy(struct kstate_context *ctx);int kstate_dump_all_nsproxy (struct kstate_context *ctx);int kstate_restore_nsproxy (struct kstate_context *ctx,kstate_ref_t *ref); +int kstate_collect_all_uts_ns (struct kstate_context *ctx); +int kstate_dump_all_uts_ns (struct kstate_context *ctx); +int kstate_restore_uts_ns (struct kstate_context *ctx,kstate_ref_t *ref); +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
@@ -68,6 +68,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_nsproxy (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_uts_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_collect_all_mm_struct (ctx);if (rv <0 )return rv;
@@ -130,6 +133,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_mm_struct (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_uts_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_nsproxy (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +6 -0
@@ -4,6 +4,7 @@#include <linux/nsproxy.h> #include <linux/sched.h> #include <linux/slab.h> +#include <linux/utsname.h> #include <linux/kstate.h>
@@ -51,5 +52,10 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_UTS_NS ) { +put_uts_ns ((struct uts_namespace *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + }kfree (ctx); }
kernel/kstate/kstate-nsproxy.c deleted +0 -0
kernel/kstate/kstate-object.c +4 -0
@@ -4,6 +4,7 @@#include <linux/nsproxy.h> #include <linux/sched.h> #include <linux/slab.h> +#include <linux/utsname.h> #include <linux/kstate.h> #include <linux/kstate-image.h>
@@ -42,6 +43,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_TASK_STRUCT :get_task_struct ((struct task_struct *)obj->o_obj);break ; +case KSTATE_CTX_UTS_NS : +get_uts_ns ((struct uts_namespace *)obj->o_obj); +break ;default :BUG (); }
kernel/kstate/kstate-uts_ns.c new file +0 -0
kernel/nsproxy.c +29 -4
@@ -271,12 +271,16 @@ static int dump_nsproxy(struct kstate_context *ctx, struct kstate_object *obj) {struct nsproxy *nsproxy = obj->o_obj;struct kstate_image_nsproxy *i; +struct kstate_object *tmp;int rv; i =kstate_prepare_image (KSTATE_OBJ_NSPROXY ,sizeof (*i));if (!i)return -ENOMEM ; + tmp =find_kstate_obj_by_ptr (ctx, nsproxy->uts_ns,KSTATE_CTX_UTS_NS ); + i->ref_uts_ns = tmp->o_ref; + rv =kstate_write_image (ctx, i,sizeof (*i), obj);kfree (i);pr_debug ("dump nsproxy %p: ref {%llu, %u}, rv %d\n" , nsproxy, (unsigned long long )obj->o_ref.pos, obj->o_ref.id, rv);
@@ -296,11 +300,30 @@ int kstate_dump_all_nsproxy(struct kstate_context *ctx)return 0 ; } +static int restore_uts_ns (struct kstate_context *ctx,kstate_ref_t *ref,struct nsproxy *nsproxy) +{ +struct uts_namespace *uts_ns; +struct kstate_object *tmp; +int rv; + + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_UTS_NS ); +if (!tmp) { + rv =kstate_restore_uts_ns (ctx, ref); +if (rv <0 ) +return rv; + tmp =find_kstate_obj_by_ref (ctx, ref,KSTATE_CTX_UTS_NS ); + } + uts_ns = tmp->o_obj; + +get_uts_ns (uts_ns); + nsproxy->uts_ns = uts_ns; +return 0 ; +} +int kstate_restore_nsproxy (struct kstate_context *ctx,kstate_ref_t *ref) {struct kstate_image_nsproxy *i;struct nsproxy *nsproxy; -struct uts_namespace *uts_ns;#ifdef CONFIG_IPC_NS struct ipc_namespace *ipc_ns;#endif
@@ -321,9 +344,9 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref) goto out_free_image; } - uts_ns = ctx->init_tsk->nsproxy->uts_ns; -get_uts_ns (uts_ns); - nsproxy->uts_ns = uts_ns; + rv =restore_uts_ns (ctx, &i->ref_uts_ns, nsproxy); +if (rv <0 ) + goto out_uts_ns;#ifdef CONFIG_IPC_NS ipc_ns = ctx->init_tsk->nsproxy->ipc_ns;
@@ -349,6 +372,8 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref)pr_debug ("restore nsproxy %p, ref {%llu, %u}, rv %d\n" , nsproxy, (unsigned long long )ref->pos, ref->id, rv);return rv; +out_uts_ns: +kmem_cache_free (nsproxy_cachep, nsproxy); out_free_image:kfree (i);pr_debug ("%s: return %d, ref {%llu, %u}\n" , __func__, rv, (unsigned long long )ref->pos, ref->id);
kernel/utsname.c +106 -0
114 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 28/38 C/R: formally checkpoint/restore struct ipc_namespace
In reply to Alexey DobriyanNo IPC objects are done yet, only struct ipc_namespace itself and tsk->nsproxy->ipc_ns skeleton.
--- include/linux/ipc_namespace.h | 3 + include/linux/kstate-image.h | 6 ++ include/linux/kstate.h | 19 ++++++++ ipc/namespace.c | 101 +++++++++++++++++++++++++++++++++++++++- kernel/kstate/cpt-sys.c | 6 ++ kernel/kstate/kstate-context.c | 8 +++ kernel/kstate/kstate-object.c | 6 ++ kernel/nsproxy.c | 66 +++++++++++++++++++++++--- 8 files changed, 206 insertions(+), 9 deletions(-)
include/linux/ipc_namespace.h +3 -0
@@ -94,6 +94,7 @@ static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }#endif #if defined(CONFIG_IPC_NS ) +extern struct ipc_namespace *create_ipc_ns (void );extern struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns);static inline struct ipc_namespace *get_ipc_ns (struct ipc_namespace *ns)
@@ -105,6 +106,8 @@ static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)extern void put_ipc_ns (struct ipc_namespace *ns);#else +#include <linux/sched.h> +static inline struct ipc_namespace *copy_ipcs (unsigned long flags,struct ipc_namespace *ns) {
include/linux/kstate-image.h +6 -0
@@ -45,6 +45,7 @@ struct kstate_image_header {#define KSTATE_OBJ_PAGE 5#define KSTATE_OBJ_NSPROXY 6#define KSTATE_OBJ_UTS_NS 7 +#define KSTATE_OBJ_IPC_NS 8struct kstate_object_header {__u32 obj_type;
@@ -211,6 +212,7 @@ struct kstate_image_nsproxy {struct kstate_object_header hdr;kstate_ref_t ref_uts_ns; +kstate_ref_t ref_ipc_ns;/* KSTATE_REF_UNDEF if IPC_NS=n */ } __packed;struct kstate_image_uts_ns {
@@ -223,4 +225,8 @@ struct kstate_image_uts_ns {__u8 machine[64 ]; __u8 domainname[64]; } __packed; + +struct kstate_image_ipc_ns { +struct kstate_object_header hdr; +} __packed;#endif
include/linux/kstate.h +19 -0
@@ -22,6 +22,9 @@ struct kstate_object {/* Not visible to userspace! */ enum kstate_context_obj_type {KSTATE_CTX_FILE , +#ifdef CONFIG_IPC_NS +KSTATE_CTX_IPC_NS , +#endif KSTATE_CTX_MM_STRUCT ,KSTATE_CTX_NSPROXY ,KSTATE_CTX_TASK_STRUCT ,
@@ -77,6 +80,22 @@ int kstate_collect_all_uts_ns(struct kstate_context *ctx);int kstate_dump_all_uts_ns (struct kstate_context *ctx);int kstate_restore_uts_ns (struct kstate_context *ctx,kstate_ref_t *ref); +#ifdef CONFIG_IPC_NS +int kstate_collect_all_ipc_ns (struct kstate_context *ctx); +int kstate_dump_all_ipc_ns (struct kstate_context *ctx); +int kstate_restore_ipc_ns (struct kstate_context *ctx,kstate_ref_t *ref); +#else +static inline int kstate_collect_all_ipc_ns (struct kstate_context *ctx) +{ +return 0 ; +} + +static inline int kstate_dump_all_ipc_ns (struct kstate_context *ctx) +{ +return 0 ; +} +#endif +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_64 )extern const __u32 kstate_kernel_arch;int kstate_arch_check_image_header (struct kstate_image_header *i);
ipc/namespace.c +100 -1
116 lines not on this page · raw message
kernel/kstate/cpt-sys.c +6 -0
@@ -71,6 +71,9 @@ static int kstate_collect(struct kstate_context *ctx) rv =kstate_collect_all_uts_ns (ctx);if (rv <0 )return rv; + rv =kstate_collect_all_ipc_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_collect_all_mm_struct (ctx);if (rv <0 )return rv;
@@ -133,6 +136,9 @@ static int kstate_dump(struct kstate_context *ctx) rv =kstate_dump_all_mm_struct (ctx);if (rv <0 )return rv; + rv =kstate_dump_all_ipc_ns (ctx); +if (rv <0 ) +return rv; rv =kstate_dump_all_uts_ns (ctx);if (rv <0 )return rv;
kernel/kstate/kstate-context.c +8 -0
@@ -1,5 +1,6 @@/* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */ #include <linux/file.h> +#include <linux/ipc_namespace.h> #include <linux/list.h> #include <linux/nsproxy.h> #include <linux/sched.h>
@@ -37,6 +38,13 @@ void kstate_context_destroy(struct kstate_context *ctx)list_del (&obj->o_list);kfree (obj); } +#ifdef CONFIG_IPC_NS +for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_IPC_NS ) { +put_ipc_ns ((struct ipc_namespace *)obj->o_obj); +list_del (&obj->o_list); +kfree (obj); + } +#endif for_each_kstate_object_safe (ctx, obj, tmp,KSTATE_CTX_MM_STRUCT ) {mmput ((struct mm_struct *)obj->o_obj);list_del (&obj->o_list);
kernel/kstate/kstate-object.c +6 -0
@@ -1,5 +1,6 @@/* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */ #include <linux/fs.h> +#include <linux/ipc_namespace.h> #include <linux/mm_types.h> #include <linux/nsproxy.h> #include <linux/sched.h>
@@ -34,6 +35,11 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_contecase KSTATE_CTX_FILE :get_file ((struct file *)obj->o_obj);break ; +#ifdef CONFIG_IPC_NS +case KSTATE_CTX_IPC_NS : +get_ipc_ns ((struct ipc_namespace *)obj->o_obj); +break ; +#endif case KSTATE_CTX_MM_STRUCT :atomic_inc (&((struct mm_struct *)obj->o_obj)->mm_users);break ;
kernel/nsproxy.c +58 -8
94 lines not on this page · raw message
Signature · 1 line
1.5.6.5