OpenVZ kernel based checkpointing/restart (v2)
Subsystems (8)
cover OpenVZ kernel based checkpointing/restart (v2)
These patchset introduces kernel based checkpointing/restart as it is implemented in OpenVZ project. This version (v2) supports multiple processes with simple private memory and open files (regular files).
Todo:
- Create processes with the same PID during restart
- Add support for x86-64
- Add support for shared objects
Changelog:
18 Oct 2008 (v2):
- Add support for multiple processes
- Cleanup and bug fixes
--
This patchset introduces kernel based checkpointing/restart as it is implemented in OpenVZ project. This patchset has limited functionality and are able to checkpoint/restart only single process. Recently Oren Laaden sent another kernel based implementation of checkpoint/restart. The main differences between this patchset and Oren's patchset are:
* In this patchset checkpointing initiated not from the process (right now we do not have a container, only namespaces), Oren's patchset performs checkpointing from the process context.
* Restart in this patchset is initiated from process, which restarts a new process (in new namespaces) with saved state. Oren's patchset uses the same process from which restart was initiated and restore saved state over it.
* Checkpoint/restart functionality in this patchset is implemented as a kernel module
As checkpointing is initiated not from the process which state should be saved we should freeze a process before saving its state. Right now Container Freezer from Matt Helsley can be used for this.
This patchset introduce only a concept how kernel based checkpointing/restart can be implemented and are able to checkpoint/restart only a single process with simple VMAs.
I've tried to split my patchset in small patches to make review more easier.
PATCH 1/10 Introduce trivial sys_checkpoint and sys_restore system calls
In reply to a message not in the archiveRight now they just return -ENOSYS. Later they will provide functionality to checkpoint and restart a container.
Both syscalls take as arguments a file descriptor and flags. Also sys_checkpoint take as the first argument a PID of container's init (later it will be container ID); sys_restart takes as the first argument a container ID (right now it will not be used).
--- Makefile | 2 +- arch/x86/kernel/syscall_table_32.S | 2 + checkpoint/Makefile | 1 + checkpoint/sys_core.c | 38 ++++++++++++++++++++++++++++++++++++ include/asm-x86/unistd_32.h | 2 + 5 files changed, 44 insertions(+), 1 deletions(-) create mode 100644 checkpoint/Makefile create mode 100644 checkpoint/sys_core.c
Makefile +1 -1
@@ -619,7 +619,7 @@ export mod_strip_cmd ifeq ($(KBUILD_EXTMOD),) -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ checkpoint/ vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
arch/x86/kernel/syscall_table_32.S +2 -0
@@ -333,3 +333,5 @@ ENTRY(sys_call_table) .long sys_pipe2 .long sys_inotify_init1 .long sys_hijack + .long sys_checkpoint + .long sys_restart /* 335 */
checkpoint/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += sys_core.o
checkpoint/sys_core.c new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Author: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/fs.h> +#include <linux/file.h> + +/** +* sys_checkpoint - checkpoint a container from outside +* @pid: pid of the container init(1) process +* TODO: should switch to container id later +* @fd: file to which save the checkpoint image +* @flags: checkpoint operation flags +*/ +asmlinkage long sys_checkpoint (pid_t pid,int fd,unsigned long flags) +{ +return -ENOSYS ; +} + +/** +* sys_restart - restart a container +* @ctid: container id which should be used to restart a container +* @fd: file from which read the checkpoint image +* @flags: restart operation flags +*/ +asmlinkage long sys_restart (int ctid,int fd,unsigned long flags) +{ +return -ENOSYS ; +}
include/asm-x86/unistd_32.h +2 -0
@@ -339,6 +339,8 @@#define __NR_pipe2 331#define __NR_inotify_init1 332#define __NR_hijack 333 +#define __NR_checkpoint 334 +#define __NR_restart 335#ifdef __KERNEL__
Signature · 1 line
1.5.6
PATCH 2/10 Make checkpoint/restart functionality modular
In reply to Andrey MirkinA config option CONFIG_CHECKPOINT is introduced.
New structure cpt_operations is introduced to store pointers to checkpoint/restart functions from module.
--- checkpoint/Kconfig | 7 ++++++ checkpoint/Makefile | 4 +++ checkpoint/checkpoint.h | 19 ++++++++++++++++++ checkpoint/sys.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ checkpoint/sys_core.c | 29 ++++++++++++++++++++++++++- init/Kconfig | 2 + 6 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 checkpoint/Kconfig create mode 100644 checkpoint/checkpoint.h create mode 100644 checkpoint/sys.c
checkpoint/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config CHECKPOINT + tristate "Checkpoint & restart for containers" + depends on EXPERIMENTAL + default n + help + This option adds module "cptrst", which allow to save a running + container to a file and restart it later using this image file.
checkpoint/Makefile +4 -0
@@ -1 +1,5 @@ obj-y += sys_core.o + +obj-$(CONFIG_CHECKPOINT) += cptrst.o + +cptrst-objs := sys.o
checkpoint/checkpoint.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Author: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +struct cpt_operations +{ +struct module * owner; +int (*checkpoint)(pid_t pid,int fd,unsigned long flags); +int (*restart)(int ctid,int fd,unsigned long flags); +}; +extern struct cpt_operations cpt_ops;
checkpoint/sys.c new file +48 -0
48 lines not on this page · raw message
checkpoint/sys_core.c +27 -2
@@ -13,6 +13,13 @@#include <linux/sched.h> #include <linux/fs.h> #include <linux/file.h> +#include <linux/notifier.h> +#include <linux/module.h> + +#include "checkpoint.h" + +struct cpt_operations cpt_ops = {NULL ,NULL ,NULL }; +EXPORT_SYMBOL (cpt_ops);/** * sys_checkpoint - checkpoint a container from outside
@@ -23,7 +30,16 @@*/ asmlinkage long sys_checkpoint (pid_t pid,int fd,unsigned long flags) { -return -ENOSYS ; +int ret; + + ret = -ENOSYS ; + +if (try_module_get (cpt_ops.owner)) { +if (cpt_ops.checkpoint) + ret = cpt_ops.checkpoint (pid, fd, flags); +module_put (cpt_ops.owner); + } +return ret; }/**
@@ -34,5 +50,14 @@ asmlinkage long sys_checkpoint(pid_t pid, int fd, unsigned long flags)*/ asmlinkage long sys_restart (int ctid,int fd,unsigned long flags) { -return -ENOSYS ; +int ret; + + ret = -ENOSYS ; + +if (try_module_get (cpt_ops.owner)) { +if (cpt_ops.restart) + ret = cpt_ops.restart (ctid, fd, flags); +module_put (cpt_ops.owner); + } +return ret; }
init/Kconfig +2 -0
@@ -344,6 +344,8 @@ config CGROUP_FREEZER Provides a way to freeze and unfreeze all tasks in a cgroup +source "checkpoint/Kconfig" + config FAIR_GROUP_SCHED bool "Group scheduling for SCHED_OTHER" depends on GROUP_SCHED
Signature · 1 line
1.5.6
PATCH 3/10 Introduce context structure needed during checkpointing/restart
Add functions for context allocation/destroy.
Introduce functions to read/write image.
Introduce image header and object header.
--- checkpoint/checkpoint.h | 40 +++++++++++++++ checkpoint/cpt_image.h | 63 ++++++++++++++++++++++++ checkpoint/sys.c | 125 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 checkpoint/cpt_image.h
checkpoint/checkpoint.h +40 -0
@@ -10,6 +10,8 @@* */ +#include "cpt_image.h" +struct cpt_operations {struct module * owner;
@@ -17,3 +19,41 @@ struct cpt_operationsint (*restart)(int ctid,int fd,unsigned long flags); };extern struct cpt_operations cpt_ops; + +enum cpt_ctx_state +{ +CPT_CTX_ERROR =-1 , +CPT_CTX_IDLE =0 , +CPT_CTX_DUMPING , +CPT_CTX_UNDUMPING +}; + +typedef struct cpt_context +{ +pid_t pid;/* should be changed to ctid later */ +int ctx_id;/* context id */ +struct list_head ctx_list; +int refcount; +int ctx_state; +struct semaphore main_sem; + +int errno; + +struct file *file; +loff_t current_object; + +struct list_head object_array[CPT_OBJ_MAX ]; + +int (*write)(const void *addr,size_t count,struct cpt_context *ctx); +int (*read)(void *addr,size_t count,struct cpt_context *ctx); +}cpt_context_t ; + +extern int debug_level; + +#define cpt_printk(lvl, fmt, args...) do { \ + if (lvl <= debug_level) \ + printk(fmt, ##args); \ + } while (0) + +#define eprintk(a...) cpt_printk(1, "CPT ERR: " a) +#define dprintk(a...) cpt_printk(1, "CPT DBG: " a)
checkpoint/cpt_image.h new file +63 -0
63 lines not on this page · raw message
checkpoint/sys.c +122 -3
143 lines not on this page · raw message
Signature · 1 line
1.5.6
PATCH 4/10 Introduce container dump function
Actually right now we are going to dump only one process. Function for dumping head of image file are added.
--- checkpoint/Makefile | 2 +- checkpoint/checkpoint.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ checkpoint/checkpoint.h | 3 ++ checkpoint/sys.c | 3 +- kernel/fork.c | 2 + 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 checkpoint/checkpoint.c
checkpoint/Makefile +1 -1
@@ -2,4 +2,4 @@ obj-y += sys_core.o obj-$(CONFIG_CHECKPOINT) += cptrst.o -cptrst-objs := sys.o +cptrst-objs := sys.o checkpoint.o
checkpoint/checkpoint.c new file +79 -0
79 lines not on this page · raw message
checkpoint/checkpoint.h +3 -0
@@ -36,6 +36,7 @@ typedef struct cpt_contextint refcount;int ctx_state;struct semaphore main_sem; +struct nsproxy *nsproxy;int errno;
@@ -57,3 +58,5 @@ extern int debug_level; #define eprintk(a...) cpt_printk(1, "CPT ERR: " a) #define dprintk(a...) cpt_printk(1, "CPT DBG: " a) + +int dump_container (struct cpt_context *ctx);
checkpoint/sys.c +2 -1
@@ -107,9 +107,10 @@ static int checkpoint(pid_t pid, int fd, unsigned long flags) ctx->file = file; ctx->ctx_state =CPT_CTX_DUMPING ; + ctx->pid = pid;/* checkpoint */ - err = -ENOSYS ; + err =dump_container (ctx);context_put (ctx);
kernel/fork.c +2 -0
@@ -77,6 +77,7 @@ int max_threads; /* tunable limit on nr_threads */ DEFINE_PER_CPU(unsigned long, process_counts) = 0;__cacheline_aligned DEFINE_RWLOCK (tasklist_lock );/* outer */ +EXPORT_SYMBOL (tasklist_lock);int nr_processes (void ) {
@@ -153,6 +154,7 @@ void __put_task_struct(struct task_struct *tsk)if (!profile_handoff_task (tsk))free_task (tsk); } +EXPORT_SYMBOL (__put_task_struct);/* * macro override instead of weak attribute alias, to workaround
Signature · 1 line
1.5.6
PATCH 5/10 Introduce function to dump process
Functions to dump task struct, fpu state and registers are added. All IDs are saved from the POV of process (container) namespace.
--- checkpoint/Makefile | 2 +- checkpoint/checkpoint.c | 2 +- checkpoint/checkpoint.h | 1 + checkpoint/cpt_image.h | 123 ++++++++++++++++++++++++ checkpoint/cpt_process.c | 236 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 362 insertions(+), 2 deletions(-) create mode 100644 checkpoint/cpt_process.c
checkpoint/Makefile +1 -1
@@ -2,4 +2,4 @@ obj-y += sys_core.o obj-$(CONFIG_CHECKPOINT) += cptrst.o -cptrst-objs := sys.o checkpoint.o +cptrst-objs := sys.o checkpoint.o cpt_process.o
checkpoint/checkpoint.c +1 -1
@@ -70,7 +70,7 @@ int dump_container(struct cpt_context *ctx)/* Dump task here */ if (!err) - err = -ENOSYS ; + err =cpt_dump_task (root, ctx); out: ctx->nsproxy =NULL ;
checkpoint/checkpoint.h +1 -0
@@ -60,3 +60,4 @@ extern int debug_level; #define dprintk(a...) cpt_printk(1, "CPT DBG: " a)int dump_container (struct cpt_context *ctx); +int cpt_dump_task (struct task_struct *tsk,struct cpt_context *ctx);
checkpoint/cpt_image.h +123 -0
145 lines not on this page · raw message
checkpoint/cpt_process.c new file +236 -0
236 lines not on this page · raw message
Signature · 1 line
1.5.6
PATCH 6/10 Introduce functions to dump mm
Functions to dump mm struct, VMAs and mm context are added.
--- arch/x86/mm/hugetlbpage.c | 2 + checkpoint/Makefile | 2 +- checkpoint/checkpoint.h | 1 + checkpoint/cpt_image.h | 61 +++++++ checkpoint/cpt_mm.c | 434 +++++++++++++++++++++++++++++++++++++++++++++ checkpoint/cpt_process.c | 8 +- mm/memory.c | 1 + 7 files changed, 504 insertions(+), 5 deletions(-) create mode 100644 checkpoint/cpt_mm.c
arch/x86/mm/hugetlbpage.c +2 -0
@@ -12,6 +12,7 @@#include <linux/slab.h> #include <linux/err.h> #include <linux/sysctl.h> +#include <linux/module.h> #include <asm/mman.h> #include <asm/tlb.h> #include <asm/tlbflush.h>
@@ -221,6 +222,7 @@ int pmd_huge(pmd_t pmd) {return !!(pmd_val (pmd) & _PAGE_PSE); } +EXPORT_SYMBOL (pmd_huge);int pud_huge (pud_t pud) {
checkpoint/Makefile +1 -1
@@ -2,4 +2,4 @@ obj-y += sys_core.o obj-$(CONFIG_CHECKPOINT) += cptrst.o -cptrst-objs := sys.o checkpoint.o cpt_process.o +cptrst-objs := sys.o checkpoint.o cpt_process.o cpt_mm.o
checkpoint/checkpoint.h +1 -0
@@ -61,3 +61,4 @@ extern int debug_level;int dump_container (struct cpt_context *ctx);int cpt_dump_task (struct task_struct *tsk,struct cpt_context *ctx); +int cpt_dump_mm (struct task_struct *tsk,struct cpt_context *ctx);
checkpoint/cpt_image.h +61 -0
86 lines not on this page · raw message
checkpoint/cpt_mm.c new file +434 -0
434 lines not on this page · raw message
checkpoint/cpt_process.c +4 -4
@@ -225,12 +225,12 @@ int cpt_dump_task(struct task_struct *tsk, struct cpt_context *ctx) err =cpt_dump_task_struct (tsk, ctx); -/* Dump task mm */ -if (!err) -cpt_dump_fpustate (tsk, ctx); + err =cpt_dump_mm (tsk, ctx); +if (!err) + err =cpt_dump_fpustate (tsk, ctx);if (!err) -cpt_dump_registers (tsk, ctx); + err =cpt_dump_registers (tsk, ctx);return err; }
mm/memory.c +1 -0
@@ -481,6 +481,7 @@ struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, out:return pfn_to_page (pfn); } +EXPORT_SYMBOL (vm_normal_page);/* * copy one vm_area from one task to the other. Assumes the page tables
Signature · 1 line
1.5.6
PATCH 7/10 Introduce function for restarting a container
Actually, right now this function will restart only one process. Function to read head of dump file is introduced.
--- checkpoint/Makefile | 2 +- checkpoint/checkpoint.h | 1 + checkpoint/restart.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ checkpoint/sys.c | 2 +- 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 checkpoint/restart.c
checkpoint/Makefile +1 -1
@@ -2,4 +2,4 @@ obj-y += sys_core.o obj-$(CONFIG_CHECKPOINT) += cptrst.o -cptrst-objs := sys.o checkpoint.o cpt_process.o cpt_mm.o +cptrst-objs := sys.o checkpoint.o cpt_process.o cpt_mm.o restart.o
checkpoint/checkpoint.h +1 -0
@@ -62,3 +62,4 @@ extern int debug_level;int dump_container (struct cpt_context *ctx);int cpt_dump_task (struct task_struct *tsk,struct cpt_context *ctx);int cpt_dump_mm (struct task_struct *tsk,struct cpt_context *ctx); +int restart_container (struct cpt_context *ctx);
checkpoint/restart.c new file +87 -0
87 lines not on this page · raw message
checkpoint/sys.c +1 -1
@@ -140,7 +140,7 @@ static int restart(int ctid, int fd, unsigned long flags) ctx->ctx_state =CPT_CTX_UNDUMPING ;/* restart */ - err = -ENOSYS ; + err =restart_container (ctx);context_put (ctx);
Signature · 1 line
1.5.6
PATCH 8/10 Introduce functions to restart a process
In reply to a message not in the archiveFunctions to restart process, restore its state, fpu and registers are added.
--- arch/x86/kernel/entry_32.S | 21 +++ arch/x86/kernel/process_32.c | 3 + checkpoint/Makefile | 3 +- checkpoint/checkpoint.h | 2 + checkpoint/restart.c | 2 +- checkpoint/rst_process.c | 277 ++++++++++++++++++++++++++++++++++++++++++ kernel/sched.c | 1 + 7 files changed, 307 insertions(+), 2 deletions(-) create mode 100644 checkpoint/rst_process.c
arch/x86/kernel/entry_32.S +21 -0
@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl
@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eax + testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume) + /* * Return to user mode is not as complex as all this looks, * but we want the default path for a system call return to
arch/x86/kernel/process_32.c +3 -0
@@ -58,6 +58,9 @@#include <asm/kdebug.h> asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); +EXPORT_SYMBOL (ret_from_fork); +asmlinkage void i386_ret_from_resume(void) __asm__("i386_ret_from_resume"); +EXPORT_SYMBOL (i386_ret_from_resume); DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;EXPORT_PER_CPU_SYMBOL (current_task);
checkpoint/Makefile +2 -1
@@ -2,4 +2,5 @@ obj-y += sys_core.o obj-$(CONFIG_CHECKPOINT) += cptrst.o -cptrst-objs := sys.o checkpoint.o cpt_process.o cpt_mm.o restart.o +cptrst-objs := sys.o checkpoint.o cpt_process.o cpt_mm.o restart.o \ + rst_process.o
checkpoint/checkpoint.h +2 -0
@@ -63,3 +63,5 @@ int dump_container(struct cpt_context *ctx);int cpt_dump_task (struct task_struct *tsk,struct cpt_context *ctx);int cpt_dump_mm (struct task_struct *tsk,struct cpt_context *ctx);int restart_container (struct cpt_context *ctx); +int rst_get_object (int type,void *tmp,int size,struct cpt_context *ctx); +int rst_restart_process (struct cpt_context *ctx);
checkpoint/restart.c +1 -1
@@ -81,7 +81,7 @@ int restart_container(struct cpt_context *ctx)/* Restart process */ if (!err) - err = -ENOSYS ; + err =rst_restart_process (ctx);return err; }
checkpoint/rst_process.c new file +277 -0
277 lines not on this page · raw message
kernel/sched.c +1 -0
@@ -1970,6 +1970,7 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state)return ncsw; } +EXPORT_SYMBOL (wait_task_inactive);/*** * kick_process - kick a running thread to enter/exit the kernel
Signature · 1 line
1.5.6
PATCH 9/10 Introduce functions to restore mm
In reply to a message not in the archiveFunctions to restore mm, VMAs and mm context are added.
--- checkpoint/Makefile | 2 +- checkpoint/checkpoint.h | 1 + checkpoint/cpt_image.h | 5 + checkpoint/rst_mm.c | 320 ++++++++++++++++++++++++++++++++++++++++++++++ checkpoint/rst_process.c | 3 +- mm/mmap.c | 1 + mm/mprotect.c | 2 + 7 files changed, 332 insertions(+), 2 deletions(-) create mode 100644 checkpoint/rst_mm.c
checkpoint/Makefile +1 -1
@@ -3,4 +3,4 @@ obj-y += sys_core.o obj-$(CONFIG_CHECKPOINT) += cptrst.o cptrst-objs := sys.o checkpoint.o cpt_process.o cpt_mm.o restart.o \ - rst_process.o + rst_process.o rst_mm.o
checkpoint/checkpoint.h +1 -0
@@ -65,3 +65,4 @@ int cpt_dump_mm(struct task_struct *tsk, struct cpt_context *ctx);int restart_container (struct cpt_context *ctx);int rst_get_object (int type,void *tmp,int size,struct cpt_context *ctx);int rst_restart_process (struct cpt_context *ctx); +int rst_restore_mm (struct cpt_context *ctx);
checkpoint/cpt_image.h +5 -0
@@ -233,6 +233,11 @@ struct cpt_x86_regs__u32 cpt_ss; } __attribute__ ((aligned (8))); +static inline void __user *cpt_ptr_import (__u64 ptr) +{ +return (void *)(unsigned long )ptr; +} +static inline __u64 cpt_timespec_export (struct timespec *tv) {return (((u64 )tv->tv_sec) <<32 ) + tv->tv_nsec;
checkpoint/rst_mm.c new file +320 -0
320 lines not on this page · raw message
checkpoint/rst_process.c +2 -1
@@ -210,7 +210,8 @@ static int restart_thread(void *arg) err =rst_get_object (CPT_OBJ_TASK , ti,sizeof (*ti), ctx);if (!err) err =rst_restore_task_struct (current, ti, ctx); -/* Restore mm here */ +if (!err) + err =rst_restore_mm (ctx);if (!err) err =rst_restore_fpustate (current, ti, ctx);if (!err)
mm/mmap.c +1 -0
@@ -1858,6 +1858,7 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,return 0 ; } +EXPORT_SYMBOL (split_vma);/* Munmap is split into 2 main parts -- this part which finds * what needs doing, and the areas themselves, which do the
mm/mprotect.c +2 -0
@@ -22,6 +22,7 @@#include <linux/swap.h> #include <linux/swapops.h> #include <linux/mmu_notifier.h> +#include <linux/module.h> #include <asm/uaccess.h> #include <asm/pgtable.h> #include <asm/cacheflush.h>
@@ -317,3 +318,4 @@ out:up_write (¤t->mm->mmap_sem);return error; } +EXPORT_SYMBOL (sys_mprotect);
Signature · 1 line
1.5.6
PATCH 10/10 Add support for multiple processes
In reply to a message not in the archiveThe whole tree of processes can be checkpointed and restarted now. Shared objects are not supported yet.
--- checkpoint/cpt_image.h | 2 + checkpoint/cpt_process.c | 24 +++++++++++++ checkpoint/rst_process.c | 85 +++++++++++++++++++++++++++------------------- 3 files changed, 76 insertions(+), 35 deletions(-)
checkpoint/cpt_image.h +2 -0
@@ -128,6 +128,8 @@ struct cpt_task_image {__u64 cpt_nivcsw;__u64 cpt_min_flt;__u64 cpt_maj_flt; +__u32 cpt_children_num; +__u32 cpt_pad; } __attribute__ ((aligned (8)));struct cpt_mm_image {
checkpoint/cpt_process.c +24 -0
@@ -40,6 +40,19 @@ static unsigned int encode_task_flags(unsigned int task_flags) } +static int cpt_count_children (struct task_struct *tsk,struct cpt_context *ctx) +{ +int num =0 ; +struct task_struct *child; + +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + num++; + } +return num; +} +int cpt_dump_task_struct (struct task_struct *tsk,struct cpt_context *ctx) {struct cpt_task_image *t;
@@ -102,6 +115,7 @@ int cpt_dump_task_struct(struct task_struct *tsk, struct cpt_context *ctx) t->cpt_egid = tsk->egid; t->cpt_sgid = tsk->sgid; t->cpt_fsgid = tsk->fsgid; + t->cpt_children_num =cpt_count_children (tsk, ctx); err = ctx->write (t,sizeof (*t), ctx);
@@ -231,6 +245,16 @@ int cpt_dump_task(struct task_struct *tsk, struct cpt_context *ctx) err =cpt_dump_fpustate (tsk, ctx);if (!err) err =cpt_dump_registers (tsk, ctx); +if (!err) { +struct task_struct *child; +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + err =cpt_dump_task (child, ctx); +if (err) +break ; + } + }return err; }
checkpoint/rst_process.c +50 -35
131 lines not on this page · raw message
Signature · 1 line
1.5.6
PATCH 1/10 Introduce trivial sys_checkpoint and sys_restore system calls
In reply to Andrey MirkinRight now they just return -ENOSYS. Later they will provide functionality to checkpoint and restart a container.
Both syscalls take as arguments a file descriptor and flags. Also sys_checkpoint take as the first argument a PID of container's init (later it will be container ID); sys_restart takes as the first argument a container ID (right now it will not be used).
--- Makefile | 2 +- arch/x86/kernel/syscall_table_32.S | 2 + checkpoint/Makefile | 1 + checkpoint/sys_core.c | 38 ++++++++++++++++++++++++++++++++++++ include/asm-x86/unistd_32.h | 2 + 5 files changed, 44 insertions(+), 1 deletions(-) create mode 100644 checkpoint/Makefile create mode 100644 checkpoint/sys_core.c
Makefile +1 -1
@@ -619,7 +619,7 @@ export mod_strip_cmd ifeq ($(KBUILD_EXTMOD),) -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ checkpoint/ vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
arch/x86/kernel/syscall_table_32.S +2 -0
@@ -333,3 +333,5 @@ ENTRY(sys_call_table) .long sys_pipe2 .long sys_inotify_init1 .long sys_hijack + .long sys_checkpoint + .long sys_restart /* 335 */
checkpoint/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += sys_core.o
checkpoint/sys_core.c new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Author: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/fs.h> +#include <linux/file.h> + +/** +* sys_checkpoint - checkpoint a container from outside +* @pid: pid of the container init(1) process +* TODO: should switch to container id later +* @fd: file to which save the checkpoint image +* @flags: checkpoint operation flags +*/ +asmlinkage long sys_checkpoint (pid_t pid,int fd,unsigned long flags) +{ +return -ENOSYS ; +} + +/** +* sys_restart - restart a container +* @ctid: container id which should be used to restart a container +* @fd: file from which read the checkpoint image +* @flags: restart operation flags +*/ +asmlinkage long sys_restart (int ctid,int fd,unsigned long flags) +{ +return -ENOSYS ; +}
include/asm-x86/unistd_32.h +2 -0
@@ -339,6 +339,8 @@#define __NR_pipe2 331#define __NR_inotify_init1 332#define __NR_hijack 333 +#define __NR_checkpoint 334 +#define __NR_restart 335#ifdef __KERNEL__
Signature · 1 line
1.5.6
PATCH 8/10 Introduce functions to restart a process
In reply to Andrey MirkinFunctions to restart process, restore its state, fpu and registers are added.
--- arch/x86/kernel/entry_32.S | 21 +++ arch/x86/kernel/process_32.c | 3 + checkpoint/Makefile | 3 +- checkpoint/checkpoint.h | 2 + checkpoint/restart.c | 2 +- checkpoint/rst_process.c | 277 ++++++++++++++++++++++++++++++++++++++++++ kernel/sched.c | 1 + 7 files changed, 307 insertions(+), 2 deletions(-) create mode 100644 checkpoint/rst_process.c
arch/x86/kernel/entry_32.S +21 -0
@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl
@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eax + testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume) + /* * Return to user mode is not as complex as all this looks, * but we want the default path for a system call return to
arch/x86/kernel/process_32.c +3 -0
@@ -58,6 +58,9 @@#include <asm/kdebug.h> asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); +EXPORT_SYMBOL (ret_from_fork); +asmlinkage void i386_ret_from_resume(void) __asm__("i386_ret_from_resume"); +EXPORT_SYMBOL (i386_ret_from_resume); DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;EXPORT_PER_CPU_SYMBOL (current_task);
checkpoint/Makefile +2 -1
@@ -2,4 +2,5 @@ obj-y += sys_core.o obj-$(CONFIG_CHECKPOINT) += cptrst.o -cptrst-objs := sys.o checkpoint.o cpt_process.o cpt_mm.o restart.o +cptrst-objs := sys.o checkpoint.o cpt_process.o cpt_mm.o restart.o \ + rst_process.o
checkpoint/checkpoint.h +2 -0
@@ -63,3 +63,5 @@ int dump_container(struct cpt_context *ctx);int cpt_dump_task (struct task_struct *tsk,struct cpt_context *ctx);int cpt_dump_mm (struct task_struct *tsk,struct cpt_context *ctx);int restart_container (struct cpt_context *ctx); +int rst_get_object (int type,void *tmp,int size,struct cpt_context *ctx); +int rst_restart_process (struct cpt_context *ctx);
checkpoint/restart.c +1 -1
@@ -81,7 +81,7 @@ int restart_container(struct cpt_context *ctx)/* Restart process */ if (!err) - err = -ENOSYS ; + err =rst_restart_process (ctx);return err; }
checkpoint/rst_process.c new file +277 -0
277 lines not on this page · raw message
kernel/sched.c +1 -0
@@ -1970,6 +1970,7 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state)return ncsw; } +EXPORT_SYMBOL (wait_task_inactive);/*** * kick_process - kick a running thread to enter/exit the kernel
Signature · 1 line
1.5.6
PATCH 9/10 Introduce functions to restore mm
Functions to restore mm, VMAs and mm context are added.
--- checkpoint/Makefile | 2 +- checkpoint/checkpoint.h | 1 + checkpoint/cpt_image.h | 5 + checkpoint/rst_mm.c | 320 ++++++++++++++++++++++++++++++++++++++++++++++ checkpoint/rst_process.c | 3 +- mm/mmap.c | 1 + mm/mprotect.c | 2 + 7 files changed, 332 insertions(+), 2 deletions(-) create mode 100644 checkpoint/rst_mm.c
checkpoint/Makefile +1 -1
@@ -3,4 +3,4 @@ obj-y += sys_core.o obj-$(CONFIG_CHECKPOINT) += cptrst.o cptrst-objs := sys.o checkpoint.o cpt_process.o cpt_mm.o restart.o \ - rst_process.o + rst_process.o rst_mm.o
checkpoint/checkpoint.h +1 -0
@@ -65,3 +65,4 @@ int cpt_dump_mm(struct task_struct *tsk, struct cpt_context *ctx);int restart_container (struct cpt_context *ctx);int rst_get_object (int type,void *tmp,int size,struct cpt_context *ctx);int rst_restart_process (struct cpt_context *ctx); +int rst_restore_mm (struct cpt_context *ctx);
checkpoint/cpt_image.h +5 -0
@@ -233,6 +233,11 @@ struct cpt_x86_regs__u32 cpt_ss; } __attribute__ ((aligned (8))); +static inline void __user *cpt_ptr_import (__u64 ptr) +{ +return (void *)(unsigned long )ptr; +} +static inline __u64 cpt_timespec_export (struct timespec *tv) {return (((u64 )tv->tv_sec) <<32 ) + tv->tv_nsec;
checkpoint/rst_mm.c new file +320 -0
320 lines not on this page · raw message
checkpoint/rst_process.c +2 -1
@@ -210,7 +210,8 @@ static int restart_thread(void *arg) err =rst_get_object (CPT_OBJ_TASK , ti,sizeof (*ti), ctx);if (!err) err =rst_restore_task_struct (current, ti, ctx); -/* Restore mm here */ +if (!err) + err =rst_restore_mm (ctx);if (!err) err =rst_restore_fpustate (current, ti, ctx);if (!err)
mm/mmap.c +1 -0
@@ -1858,6 +1858,7 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,return 0 ; } +EXPORT_SYMBOL (split_vma);/* Munmap is split into 2 main parts -- this part which finds * what needs doing, and the areas themselves, which do the
mm/mprotect.c +2 -0
@@ -22,6 +22,7 @@#include <linux/swap.h> #include <linux/swapops.h> #include <linux/mmu_notifier.h> +#include <linux/module.h> #include <asm/uaccess.h> #include <asm/pgtable.h> #include <asm/cacheflush.h>
@@ -317,3 +318,4 @@ out:up_write (¤t->mm->mmap_sem);return error; } +EXPORT_SYMBOL (sys_mprotect);
Signature · 1 line
1.5.6
PATCH 10/10 Add support for multiple processes
The whole tree of processes can be checkpointed and restarted now. Shared objects are not supported yet.
--- checkpoint/cpt_image.h | 2 + checkpoint/cpt_process.c | 24 +++++++++++++ checkpoint/rst_process.c | 85 +++++++++++++++++++++++++++------------------- 3 files changed, 76 insertions(+), 35 deletions(-)
checkpoint/cpt_image.h +2 -0
@@ -128,6 +128,8 @@ struct cpt_task_image {__u64 cpt_nivcsw;__u64 cpt_min_flt;__u64 cpt_maj_flt; +__u32 cpt_children_num; +__u32 cpt_pad; } __attribute__ ((aligned (8)));struct cpt_mm_image {
checkpoint/cpt_process.c +24 -0
@@ -40,6 +40,19 @@ static unsigned int encode_task_flags(unsigned int task_flags) } +static int cpt_count_children (struct task_struct *tsk,struct cpt_context *ctx) +{ +int num =0 ; +struct task_struct *child; + +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + num++; + } +return num; +} +int cpt_dump_task_struct (struct task_struct *tsk,struct cpt_context *ctx) {struct cpt_task_image *t;
@@ -102,6 +115,7 @@ int cpt_dump_task_struct(struct task_struct *tsk, struct cpt_context *ctx) t->cpt_egid = tsk->egid; t->cpt_sgid = tsk->sgid; t->cpt_fsgid = tsk->fsgid; + t->cpt_children_num =cpt_count_children (tsk, ctx); err = ctx->write (t,sizeof (*t), ctx);
@@ -231,6 +245,16 @@ int cpt_dump_task(struct task_struct *tsk, struct cpt_context *ctx) err =cpt_dump_fpustate (tsk, ctx);if (!err) err =cpt_dump_registers (tsk, ctx); +if (!err) { +struct task_struct *child; +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + err =cpt_dump_task (child, ctx); +if (err) +break ; + } + }return err; }
checkpoint/rst_process.c +50 -35
131 lines not on this page · raw message
Signature · 1 line
1.5.6
Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Andrey MirkinHello Andrey !
Quoted 25 lines
arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eax
arch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)
Could you explain why you need to do this
call *%eax
is it related to the freezer code ?
C.
Re: [PATCH 05/10] Introduce function to dump process
In reply to a message not in the archiveHi,
Quoted 2 lines · Andrey Mirkin
Functions to dump task struct, fpu state and registers are added. All IDs are saved from the POV of process (container) namespace.
Just a couple of little comments, in case this series should keep on living.
[...]
Quoted 70 lines
checkpoint/cpt_process.c new file +64
-0@@ -0,0 +1,236 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Author: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/fs.h> +#include <linux/file.h> +#include <linux/version.h> +#include <linux/nsproxy.h> + +#include "checkpoint.h" +#include "cpt_image.h" + +static unsigned int encode_task_flags (unsigned int task_flags) +{ +unsigned int flags =0 ; + +if (task_flags &PF_EXITING ) + flags |= (1 <<CPT_PF_EXITING ); +if (task_flags &PF_FORKNOEXEC ) + flags |= (1 <<CPT_PF_FORKNOEXEC ); +if (task_flags &PF_SUPERPRIV ) + flags |= (1 <<CPT_PF_SUPERPRIV ); +if (task_flags &PF_DUMPCORE ) + flags |= (1 <<CPT_PF_DUMPCORE ); +if (task_flags &PF_SIGNALED ) + flags |= (1 <<CPT_PF_SIGNALED ); +if (task_flags &PF_USED_MATH ) + flags |= (1 <<CPT_PF_USED_MATH ); + +return flags; + +} + +int cpt_dump_task_struct (struct task_struct *tsk,struct cpt_context *ctx) +{ +struct cpt_task_image *t; +int i; +int err; + + t =kzalloc (sizeof (*t),GFP_KERNEL ); +if (!t) +return -ENOMEM ; + + t->cpt_len =sizeof (*t); + t->cpt_type =CPT_OBJ_TASK ; + t->cpt_hdrlen =sizeof (*t); + t->cpt_content =CPT_CONTENT_ARRAY ; + + t->cpt_state = tsk->state; + t->cpt_flags =encode_task_flags (tsk->flags); + t->cpt_exit_code = tsk->exit_code; + t->cpt_exit_signal = tsk->exit_signal; + t->cpt_pdeath_signal = tsk->pdeath_signal; + t->cpt_pid =task_pid_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_tgid =task_tgid_nr_ns (tsk, ctx->nsproxy->pid_ns);
checkpoint/cpt_process.c line 74
Quoted 10 lines
checkpoint/cpt_process.c new file +10
-0+ t->cpt_ppid = tsk->parent ? +task_pid_nr_ns (tsk->parent, ctx->nsproxy->pid_ns) :0 ; + t->cpt_rppid = tsk->real_parent ? +task_pid_nr_ns (tsk->real_parent, ctx->nsproxy->pid_ns) :0 ; + t->cpt_pgrp =task_pgrp_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_session =task_session_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_old_pgrp =0 ; +if (tsk->signal->tty_old_pgrp) + t->cpt_old_pgrp =pid_vnr (tsk->signal->tty_old_pgrp); + t->cpt_leader = tsk->group_leader ?task_pid_vnr (tsk->group_leader) :0 ;
Why pid_vnr() here, and task_*_nr_ns() above? According to the introducing comment, I'd expect something like pid_nr_ns(tsk->signal->tty_old_pgrp, tsk->nsproxy->pid_ns), and the same for tsk->group_leader.
IIUC, pid_vnr() is correct only if ctx->nsproxy->pid_ns == tsk->nsproxy->pid_ns == current->nsproxy->pid_ns, and I expect current to live in a different pid_ns.
Comments?
Quoted 51 lines
checkpoint/cpt_process.c new file +51
-0+ t->cpt_utime = tsk->utime; + t->cpt_stime = tsk->stime; + t->cpt_utimescaled = tsk->utimescaled; + t->cpt_stimescaled = tsk->stimescaled; + t->cpt_gtime = tsk->gtime; + t->cpt_prev_utime = tsk->prev_utime; + t->cpt_prev_stime = tsk->prev_stime; + t->cpt_nvcsw = tsk->nvcsw; + t->cpt_nivcsw = tsk->nivcsw; + t->cpt_start_time =cpt_timespec_export (&tsk->start_time); + t->cpt_real_start_time =cpt_timespec_export (&tsk->real_start_time); + t->cpt_min_flt = tsk->min_flt; + t->cpt_maj_flt = tsk->maj_flt; +memcpy (t->cpt_comm, tsk->comm,TASK_COMM_LEN ); +for (i =0 ; i <GDT_ENTRY_TLS_ENTRIES ; i++) { + t->cpt_tls[i] = (((u64 )tsk->thread.tls_array[i].b) <<32 ) + + tsk->thread.tls_array[i].a; + } +/* TODO: encode thread flags and status like task flags */ + t->cpt_thrflags =task_thread_info (tsk)->flags & ~(1 <<TIF_FREEZE ); + t->cpt_thrstatus =task_thread_info (tsk)->status; + t->cpt_user = tsk->user->uid; + t->cpt_uid = tsk->uid; + t->cpt_euid = tsk->euid; + t->cpt_suid = tsk->suid; + t->cpt_fsuid = tsk->fsuid; + t->cpt_gid = tsk->gid; + t->cpt_egid = tsk->egid; + t->cpt_sgid = tsk->sgid; + t->cpt_fsgid = tsk->fsgid; + + err = ctx->write (t,sizeof (*t), ctx); + +kfree (t); +return err; +} + +static int cpt_dump_fpustate (struct task_struct *tsk,struct cpt_context *ctx) +{ +struct cpt_obj_bits hdr; +int err; +int content; +unsigned long size; + + content =CPT_CONTENT_X86_FPUSTATE ; + size =sizeof (struct i387_fxsave_struct ); +#ifndef CONFIG_X86_64 +if (!cpu_has_fxsr) { + size =sizeof (struct i387_fsave_struct ); + content =CPT_CONTENT_X86_FPUSTATE_OLD ; + }
checkpoint/cpt_process.c line 135
Quoted 10 lines
checkpoint/cpt_process.c new file +10
-0+#endif + + hdr.cpt_len =sizeof (hdr) + size; + hdr.cpt_type =CPT_OBJ_BITS ; + hdr.cpt_hdrlen =sizeof (hdr); + hdr.cpt_content = content; + hdr.cpt_size = size; + err = ctx->write (&hdr,sizeof (hdr), ctx); +if (!err) + ctx->write (tsk->thread.xstate, size, ctx);
Should check the error code of the line above, right?
Quoted 86 lines
checkpoint/cpt_process.c new file +86
-0+return err; +} + +static u32 encode_segment (u32 segreg) +{ + segreg &=0xFFFF ; + +if (segreg ==0 ) +return CPT_SEG_ZERO ; +if ((segreg &3 ) !=3 ) { +eprintk ("Invalid RPL of a segment reg %x\n" , segreg); +return CPT_SEG_ZERO ; + } + +/* LDT descriptor, it is just an index to LDT array */ +if (segreg &4 ) +return CPT_SEG_LDT + (segreg >>3 ); + +/* TLS descriptor. */ +if ((segreg >>3 ) >=GDT_ENTRY_TLS_MIN && + (segreg >>3 ) <=GDT_ENTRY_TLS_MAX ) +return CPT_SEG_TLS1 + ((segreg>>3 ) -GDT_ENTRY_TLS_MIN ); + +/* One of standard desriptors */ +#ifdef CONFIG_X86_64 +if (segreg == __USER32_DS) +return CPT_SEG_USER32_DS ; +if (segreg == __USER32_CS) +return CPT_SEG_USER32_CS ; +if (segreg == __USER_DS) +return CPT_SEG_USER64_DS ; +if (segreg == __USER_CS) +return CPT_SEG_USER64_CS ; +#else +if (segreg == __USER_DS) +return CPT_SEG_USER32_DS ; +if (segreg == __USER_CS) +return CPT_SEG_USER32_CS ; +#endif +eprintk ("Invalid segment reg %x\n" , segreg); +return CPT_SEG_ZERO ; +} + +static int cpt_dump_registers (struct task_struct *tsk,struct cpt_context *ctx) +{ +struct cpt_x86_regs ri; +struct pt_regs *pt_regs; + + ri.cpt_len =sizeof (ri); + ri.cpt_type =CPT_OBJ_X86_REGS ; + ri.cpt_hdrlen =sizeof (ri); + ri.cpt_content =CPT_CONTENT_VOID ; + + ri.cpt_debugreg[0 ] = tsk->thread.debugreg0; + ri.cpt_debugreg[1 ] = tsk->thread.debugreg1; + ri.cpt_debugreg[2 ] = tsk->thread.debugreg2; + ri.cpt_debugreg[3 ] = tsk->thread.debugreg3; + ri.cpt_debugreg[4 ] =0 ; + ri.cpt_debugreg[5 ] =0 ; + ri.cpt_debugreg[6 ] = tsk->thread.debugreg6; + ri.cpt_debugreg[7 ] = tsk->thread.debugreg7; + + pt_regs =task_pt_regs (tsk); + + ri.cpt_fs =encode_segment (pt_regs->fs); + ri.cpt_gs =encode_segment (tsk->thread.gs); + + ri.cpt_bx = pt_regs->bx; + ri.cpt_cx = pt_regs->cx; + ri.cpt_dx = pt_regs->dx; + ri.cpt_si = pt_regs->si; + ri.cpt_di = pt_regs->di; + ri.cpt_bp = pt_regs->bp; + ri.cpt_ax = pt_regs->ax; + ri.cpt_ds =encode_segment (pt_regs->ds); + ri.cpt_es =encode_segment (pt_regs->es); + ri.cpt_orig_ax = pt_regs->orig_ax; + ri.cpt_ip = pt_regs->ip; + ri.cpt_cs =encode_segment (pt_regs->cs); + ri.cpt_flags = pt_regs->flags; + ri.cpt_sp = pt_regs->sp; + ri.cpt_ss =encode_segment (pt_regs->ss); + +return ctx->write (&ri,sizeof (ri), ctx); +} +
checkpoint/cpt_process.c line 231
Quoted 10 lines
checkpoint/cpt_process.c new file +10
-0+int cpt_dump_task (struct task_struct *tsk,struct cpt_context *ctx) +{ +int err; + + err =cpt_dump_task_struct (tsk, ctx); + +/* Dump task mm */ + +if (!err) +cpt_dump_fpustate (tsk, ctx);
error checking...
checkpoint/cpt_process.c line 233
Quoted 2 lines
checkpoint/cpt_process.c new file +2
-0+if (!err) +cpt_dump_registers (tsk, ctx);
error checking...
Quoted 11 lines
checkpoint/cpt_process.c new file +3
-0+ +return err; +}Signature · 7 lines
1.5.6 -- 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/
Louis
Signature · 4 lines
Dr Louis Rilling Kerlabs Skype: louis.rilling Batiment Germanium Phone: (+33|0) 6 80 89 08 23 80 avenue des Buttes de Coesmes http://www.kerlabs.com/ 35700 Rennes
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [PATCH 05/10] Introduce function to dump process
In reply to Andrey MirkinHi,
Quoted 2 lines · Andrey Mirkin
Functions to dump task struct, fpu state and registers are added. All IDs are saved from the POV of process (container) namespace.
Just a couple of little comments, in case this series should keep on living.
[...]
Quoted 70 lines
checkpoint/cpt_process.c new file +64
-0@@ -0,0 +1,236 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Author: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/fs.h> +#include <linux/file.h> +#include <linux/version.h> +#include <linux/nsproxy.h> + +#include "checkpoint.h" +#include "cpt_image.h" + +static unsigned int encode_task_flags (unsigned int task_flags) +{ +unsigned int flags =0 ; + +if (task_flags &PF_EXITING ) + flags |= (1 <<CPT_PF_EXITING ); +if (task_flags &PF_FORKNOEXEC ) + flags |= (1 <<CPT_PF_FORKNOEXEC ); +if (task_flags &PF_SUPERPRIV ) + flags |= (1 <<CPT_PF_SUPERPRIV ); +if (task_flags &PF_DUMPCORE ) + flags |= (1 <<CPT_PF_DUMPCORE ); +if (task_flags &PF_SIGNALED ) + flags |= (1 <<CPT_PF_SIGNALED ); +if (task_flags &PF_USED_MATH ) + flags |= (1 <<CPT_PF_USED_MATH ); + +return flags; + +} + +int cpt_dump_task_struct (struct task_struct *tsk,struct cpt_context *ctx) +{ +struct cpt_task_image *t; +int i; +int err; + + t =kzalloc (sizeof (*t),GFP_KERNEL ); +if (!t) +return -ENOMEM ; + + t->cpt_len =sizeof (*t); + t->cpt_type =CPT_OBJ_TASK ; + t->cpt_hdrlen =sizeof (*t); + t->cpt_content =CPT_CONTENT_ARRAY ; + + t->cpt_state = tsk->state; + t->cpt_flags =encode_task_flags (tsk->flags); + t->cpt_exit_code = tsk->exit_code; + t->cpt_exit_signal = tsk->exit_signal; + t->cpt_pdeath_signal = tsk->pdeath_signal; + t->cpt_pid =task_pid_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_tgid =task_tgid_nr_ns (tsk, ctx->nsproxy->pid_ns);
checkpoint/cpt_process.c line 74
Quoted 10 lines
checkpoint/cpt_process.c new file +10
-0+ t->cpt_ppid = tsk->parent ? +task_pid_nr_ns (tsk->parent, ctx->nsproxy->pid_ns) :0 ; + t->cpt_rppid = tsk->real_parent ? +task_pid_nr_ns (tsk->real_parent, ctx->nsproxy->pid_ns) :0 ; + t->cpt_pgrp =task_pgrp_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_session =task_session_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_old_pgrp =0 ; +if (tsk->signal->tty_old_pgrp) + t->cpt_old_pgrp =pid_vnr (tsk->signal->tty_old_pgrp); + t->cpt_leader = tsk->group_leader ?task_pid_vnr (tsk->group_leader) :0 ;
Why pid_vnr() here, and task_*_nr_ns() above? According to the introducing comment, I'd expect something like pid_nr_ns(tsk->signal->tty_old_pgrp, tsk->nsproxy->pid_ns), and the same for tsk->group_leader.
IIUC, pid_vnr() is correct only if ctx->nsproxy->pid_ns == tsk->nsproxy->pid_ns == current->nsproxy->pid_ns, and I expect current to live in a different pid_ns.
Comments?
Quoted 51 lines
checkpoint/cpt_process.c new file +51
-0+ t->cpt_utime = tsk->utime; + t->cpt_stime = tsk->stime; + t->cpt_utimescaled = tsk->utimescaled; + t->cpt_stimescaled = tsk->stimescaled; + t->cpt_gtime = tsk->gtime; + t->cpt_prev_utime = tsk->prev_utime; + t->cpt_prev_stime = tsk->prev_stime; + t->cpt_nvcsw = tsk->nvcsw; + t->cpt_nivcsw = tsk->nivcsw; + t->cpt_start_time =cpt_timespec_export (&tsk->start_time); + t->cpt_real_start_time =cpt_timespec_export (&tsk->real_start_time); + t->cpt_min_flt = tsk->min_flt; + t->cpt_maj_flt = tsk->maj_flt; +memcpy (t->cpt_comm, tsk->comm,TASK_COMM_LEN ); +for (i =0 ; i <GDT_ENTRY_TLS_ENTRIES ; i++) { + t->cpt_tls[i] = (((u64 )tsk->thread.tls_array[i].b) <<32 ) + + tsk->thread.tls_array[i].a; + } +/* TODO: encode thread flags and status like task flags */ + t->cpt_thrflags =task_thread_info (tsk)->flags & ~(1 <<TIF_FREEZE ); + t->cpt_thrstatus =task_thread_info (tsk)->status; + t->cpt_user = tsk->user->uid; + t->cpt_uid = tsk->uid; + t->cpt_euid = tsk->euid; + t->cpt_suid = tsk->suid; + t->cpt_fsuid = tsk->fsuid; + t->cpt_gid = tsk->gid; + t->cpt_egid = tsk->egid; + t->cpt_sgid = tsk->sgid; + t->cpt_fsgid = tsk->fsgid; + + err = ctx->write (t,sizeof (*t), ctx); + +kfree (t); +return err; +} + +static int cpt_dump_fpustate (struct task_struct *tsk,struct cpt_context *ctx) +{ +struct cpt_obj_bits hdr; +int err; +int content; +unsigned long size; + + content =CPT_CONTENT_X86_FPUSTATE ; + size =sizeof (struct i387_fxsave_struct ); +#ifndef CONFIG_X86_64 +if (!cpu_has_fxsr) { + size =sizeof (struct i387_fsave_struct ); + content =CPT_CONTENT_X86_FPUSTATE_OLD ; + }
checkpoint/cpt_process.c line 135
Quoted 10 lines
checkpoint/cpt_process.c new file +10
-0+#endif + + hdr.cpt_len =sizeof (hdr) + size; + hdr.cpt_type =CPT_OBJ_BITS ; + hdr.cpt_hdrlen =sizeof (hdr); + hdr.cpt_content = content; + hdr.cpt_size = size; + err = ctx->write (&hdr,sizeof (hdr), ctx); +if (!err) + ctx->write (tsk->thread.xstate, size, ctx);
Should check the error code of the line above, right?
Quoted 86 lines
checkpoint/cpt_process.c new file +86
-0+return err; +} + +static u32 encode_segment (u32 segreg) +{ + segreg &=0xFFFF ; + +if (segreg ==0 ) +return CPT_SEG_ZERO ; +if ((segreg &3 ) !=3 ) { +eprintk ("Invalid RPL of a segment reg %x\n" , segreg); +return CPT_SEG_ZERO ; + } + +/* LDT descriptor, it is just an index to LDT array */ +if (segreg &4 ) +return CPT_SEG_LDT + (segreg >>3 ); + +/* TLS descriptor. */ +if ((segreg >>3 ) >=GDT_ENTRY_TLS_MIN && + (segreg >>3 ) <=GDT_ENTRY_TLS_MAX ) +return CPT_SEG_TLS1 + ((segreg>>3 ) -GDT_ENTRY_TLS_MIN ); + +/* One of standard desriptors */ +#ifdef CONFIG_X86_64 +if (segreg == __USER32_DS) +return CPT_SEG_USER32_DS ; +if (segreg == __USER32_CS) +return CPT_SEG_USER32_CS ; +if (segreg == __USER_DS) +return CPT_SEG_USER64_DS ; +if (segreg == __USER_CS) +return CPT_SEG_USER64_CS ; +#else +if (segreg == __USER_DS) +return CPT_SEG_USER32_DS ; +if (segreg == __USER_CS) +return CPT_SEG_USER32_CS ; +#endif +eprintk ("Invalid segment reg %x\n" , segreg); +return CPT_SEG_ZERO ; +} + +static int cpt_dump_registers (struct task_struct *tsk,struct cpt_context *ctx) +{ +struct cpt_x86_regs ri; +struct pt_regs *pt_regs; + + ri.cpt_len =sizeof (ri); + ri.cpt_type =CPT_OBJ_X86_REGS ; + ri.cpt_hdrlen =sizeof (ri); + ri.cpt_content =CPT_CONTENT_VOID ; + + ri.cpt_debugreg[0 ] = tsk->thread.debugreg0; + ri.cpt_debugreg[1 ] = tsk->thread.debugreg1; + ri.cpt_debugreg[2 ] = tsk->thread.debugreg2; + ri.cpt_debugreg[3 ] = tsk->thread.debugreg3; + ri.cpt_debugreg[4 ] =0 ; + ri.cpt_debugreg[5 ] =0 ; + ri.cpt_debugreg[6 ] = tsk->thread.debugreg6; + ri.cpt_debugreg[7 ] = tsk->thread.debugreg7; + + pt_regs =task_pt_regs (tsk); + + ri.cpt_fs =encode_segment (pt_regs->fs); + ri.cpt_gs =encode_segment (tsk->thread.gs); + + ri.cpt_bx = pt_regs->bx; + ri.cpt_cx = pt_regs->cx; + ri.cpt_dx = pt_regs->dx; + ri.cpt_si = pt_regs->si; + ri.cpt_di = pt_regs->di; + ri.cpt_bp = pt_regs->bp; + ri.cpt_ax = pt_regs->ax; + ri.cpt_ds =encode_segment (pt_regs->ds); + ri.cpt_es =encode_segment (pt_regs->es); + ri.cpt_orig_ax = pt_regs->orig_ax; + ri.cpt_ip = pt_regs->ip; + ri.cpt_cs =encode_segment (pt_regs->cs); + ri.cpt_flags = pt_regs->flags; + ri.cpt_sp = pt_regs->sp; + ri.cpt_ss =encode_segment (pt_regs->ss); + +return ctx->write (&ri,sizeof (ri), ctx); +} +
checkpoint/cpt_process.c line 231
Quoted 10 lines
checkpoint/cpt_process.c new file +10
-0+int cpt_dump_task (struct task_struct *tsk,struct cpt_context *ctx) +{ +int err; + + err =cpt_dump_task_struct (tsk, ctx); + +/* Dump task mm */ + +if (!err) +cpt_dump_fpustate (tsk, ctx);
error checking...
checkpoint/cpt_process.c line 233
Quoted 2 lines
checkpoint/cpt_process.c new file +2
-0+if (!err) +cpt_dump_registers (tsk, ctx);
error checking...
Quoted 11 lines
checkpoint/cpt_process.c new file +3
-0+ +return err; +}Signature · 7 lines
1.5.6 -- 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/
Louis
Signature · 4 lines
Dr Louis Rilling Kerlabs Skype: louis.rilling Batiment Germanium Phone: (+33|0) 6 80 89 08 23 80 avenue des Buttes de Coesmes http://www.kerlabs.com/ 35700 Rennes
Re: [PATCH 06/10] Introduce functions to dump mm
In reply to Andrey MirkinQuoted 1 line · Andrey Mirkin
Functions to dump mm struct, VMAs and mm context are added.
Again, a few little comments.
[...]
Quoted 217 lines
checkpoint/cpt_mm.c new file +211
-0@@ -0,0 +1,434 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Authors: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/slab.h> +#include <linux/file.h> +#include <linux/mm.h> +#include <linux/errno.h> +#include <linux/major.h> +#include <linux/mman.h> +#include <linux/mnt_namespace.h> +#include <linux/mount.h> +#include <linux/namei.h> +#include <linux/pagemap.h> +#include <linux/hugetlb.h> +#include <asm/ldt.h> + +#include "checkpoint.h" +#include "cpt_image.h" + +struct page_area +{ +int type; +unsigned long start; +unsigned long end; +pgoff_t pgoff; +loff_t mm; +__u64 list[16 ]; +}; + +struct page_desc +{ +int type; +pgoff_t index; +loff_t mm; +int shared; +}; + +enum { +PD_ABSENT , +PD_COPY , +PD_FUNKEY , +}; + +/* 0: page can be obtained from backstore, or still not mapped anonymous page, +or something else, which does not requre copy. +1: page requires copy +2: page requres copy but its content is zero. Quite useless. +3: wp page is shared after fork(). It is to be COWed when modified. +4: page is something unsupported... We copy it right now. +*/ + +static void page_get_desc (struct vm_area_struct *vma,unsigned long addr, +struct page_desc *pdesc,cpt_context_t * ctx) +{ +struct mm_struct *mm = vma->vm_mm; +pgd_t *pgd; +pud_t *pud; +pmd_t *pmd; +pte_t *ptep, pte; +spinlock_t *ptl; +struct page *pg =NULL ; +pgoff_t linear_index = (addr - vma->vm_start)/PAGE_SIZE + vma->vm_pgoff; + + pdesc->index = linear_index; + pdesc->shared =0 ; + pdesc->mm =CPT_NULL ; + +if (vma->vm_flags &VM_IO ) { + pdesc->type =PD_ABSENT ; +return ; + } + + pgd =pgd_offset (mm, addr); +if (pgd_none (*pgd) ||unlikely (pgd_bad (*pgd))) + goto out_absent; + pud =pud_offset (pgd, addr); +if (pud_none (*pud) ||unlikely (pud_bad (*pud))) + goto out_absent; + pmd =pmd_offset (pud, addr); +if (pmd_none (*pmd) ||unlikely (pmd_bad (*pmd))) + goto out_absent; +#ifdef CONFIG_X86 +if (pmd_huge (*pmd)) { +eprintk ("page_huge\n" ); + goto out_unsupported; + } +#endif + ptep =pte_offset_map_lock (mm, pmd, addr, &ptl); + pte = *ptep; +pte_unmap (ptep); + +if (pte_none (pte)) + goto out_absent_unlock; + +if ((pg =vm_normal_page (vma, addr, pte)) ==NULL ) { + pdesc->type =PD_COPY ; + goto out_unlock; + } + +get_page (pg); +spin_unlock (ptl); + +if (pg->mapping && !PageAnon (pg)) { +if (vma->vm_file ==NULL ) { +eprintk ("pg->mapping!=NULL for fileless vma: %08lx\n" , addr); + goto out_unsupported; + } +if (vma->vm_file->f_mapping != pg->mapping) { +eprintk ("pg->mapping!=f_mapping: %08lx %p %p\n" , + addr, vma->vm_file->f_mapping, pg->mapping); + goto out_unsupported; + } + pdesc->index = (pg->index << (PAGE_CACHE_SHIFT -PAGE_SHIFT )); +/* Page is in backstore. For us it is like +* it is not present. +*/ + goto out_absent; + } + +if (PageReserved (pg)) { +/* Special case: ZERO_PAGE is used, when an +* anonymous page is accessed but not written. */ +if (pg ==ZERO_PAGE (addr)) { +if (pte_write (pte)) { +eprintk ("not funny already, writable ZERO_PAGE\n" ); + goto out_unsupported; + } +/* Just copy it for now */ + pdesc->type =PD_COPY ; + goto out_put; + } +eprintk ("reserved page %lu at %08lx\n" , pg->index, addr); + goto out_unsupported; + } + +if (!pg->mapping) { +eprintk ("page without mapping at %08lx\n" , addr); + goto out_unsupported; + } + + pdesc->type =PD_COPY ; + +out_put: +if (pg) +put_page (pg); +return ; + +out_unlock: +spin_unlock (ptl); + goto out_put; + +out_absent_unlock: +spin_unlock (ptl); + +out_absent: + pdesc->type =PD_ABSENT ; + goto out_put; + +out_unsupported: + pdesc->type =PD_FUNKEY ; + goto out_put; +} + +static int count_vma_pages (struct vm_area_struct *vma,struct cpt_context *ctx) +{ +unsigned long addr; +int page_num =0 ; + +for (addr = vma->vm_start; addr < vma->vm_end; addr +=PAGE_SIZE ) { +struct page_desc pd; + +page_get_desc (vma, addr, &pd, ctx); + +if (pd.type !=PD_COPY ) { +return -EINVAL ; + }else { + page_num +=1 ; + } + + } +return page_num; +} + +/* ATTN: We give "current" to get_user_pages(). This is wrong, but get_user_pages() +* does not really need this thing. It just stores some page fault stats there. +* +* BUG: some archs (f.e. sparc64, but not Intel*) require flush cache pages +* before accessing vma. +*/ +static int dump_pages (struct vm_area_struct *vma,unsigned long start, +unsigned long end,struct cpt_context *ctx) +{ +#define MAX_PAGE_BATCH 16 +struct page *pg[MAX_PAGE_BATCH ]; +int npages = (end - start)/PAGE_SIZE ; +int count =0 ; + +while (count < npages) { +int copy = npages - count; +int n; +
checkpoint/cpt_mm.c line 221
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+if (copy >MAX_PAGE_BATCH ) + copy =MAX_PAGE_BATCH ; + n =get_user_pages (current, vma->vm_mm, start, copy, +0 ,1 , pg,NULL ); +if (n == copy) { +int i; +for (i=0 ; i<n; i++) { +char *maddr =kmap (pg[i]); + ctx->write (maddr,PAGE_SIZE , ctx); +kunmap (pg[i]);
There is no error handling in this inner loop. Should be fixed imho.
Quoted 49 lines
checkpoint/cpt_mm.c new file +49
-0+ } + }else { +eprintk ("get_user_pages fault" ); +for ( ; n >0 ; n--) +page_cache_release (pg[n-1 ]); +return -EFAULT ; + } + start += n*PAGE_SIZE ; + count += n; +for ( ; n >0 ; n--) +page_cache_release (pg[n-1 ]); + } +return 0 ; +} + +static int dump_page_block (struct vm_area_struct *vma, +struct cpt_page_block *pgb, +struct cpt_context *ctx) +{ +int err; + pgb->cpt_len =sizeof (*pgb) + pgb->cpt_end - pgb->cpt_start; + pgb->cpt_type =CPT_OBJ_PAGES ; + pgb->cpt_hdrlen =sizeof (*pgb); + pgb->cpt_content =CPT_CONTENT_DATA ; + + err = ctx->write (pgb,sizeof (*pgb), ctx); +if (!err) + err =dump_pages (vma, pgb->cpt_start, pgb->cpt_end, ctx); + +return err; +} + +static int cpt_dump_dentry (struct path *p,cpt_context_t *ctx) +{ +int len; +char *path; +char *buf; +struct cpt_object_hdr o; + + buf = (char *)__get_free_page (GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + + path =d_path (p, buf,PAGE_SIZE ); + +if (IS_ERR (path)) { +free_page ((unsigned long )buf); +return PTR_ERR (path); + }
checkpoint/cpt_mm.c line 280
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+ + len = buf +PAGE_SIZE -1 - path; + o.cpt_len =sizeof (o) + len +1 ; + o.cpt_type =CPT_OBJ_NAME ; + o.cpt_hdrlen =sizeof (o); + o.cpt_content =CPT_CONTENT_NAME ; + path[len] =0 ; + + ctx->write (&o,sizeof (o), ctx); + ctx->write (path, len +1 , ctx);
Error handling?
Quoted 30 lines
checkpoint/cpt_mm.c new file +30
-0+free_page ((unsigned long )buf); + +return 0 ; +} + +static int dump_one_vma (struct mm_struct *mm, +struct vm_area_struct *vma,struct cpt_context *ctx) +{ +struct cpt_vma_image *v; +unsigned long addr; +int page_num; +int err; + + v =kzalloc (sizeof (*v),GFP_KERNEL ); +if (!v) +return -ENOMEM ; + + v->cpt_len =sizeof (*v); + v->cpt_type =CPT_OBJ_VMA ; + v->cpt_hdrlen =sizeof (*v); + v->cpt_content =CPT_CONTENT_ARRAY ; + + v->cpt_start = vma->vm_start; + v->cpt_end = vma->vm_end; + v->cpt_flags = vma->vm_flags; +if (vma->vm_flags &VM_HUGETLB ) { +eprintk ("huge TLB VMAs are still not supported\n" ); +kfree (v); +return -EINVAL ; + }
checkpoint/cpt_mm.c line 320
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+ v->cpt_pgprot = vma->vm_page_prot.pgprot; + v->cpt_pgoff = vma->vm_pgoff; + v->cpt_file =CPT_NULL ; + v->cpt_vma_type =CPT_VMA_TYPE_0 ; + + page_num =count_vma_pages (vma, ctx); +if (page_num <0 ) { +kfree (v); +return -EINVAL ; + }
AFAICS, since count_vma_pages only supports pages with PD_COPY, and since get_page_desc() tags text segment pages (file-mapped and not anonymous since not written to) as PD_ABSENT, no executable is checkpointable. So, where is the trick? Am I completely missing something about page mapping?
checkpoint/cpt_mm.c line 328
Quoted 8 lines
checkpoint/cpt_mm.c new file +8
-0+ v->cpt_page_num = page_num; + +if (vma->vm_file) { + v->cpt_file =0 ; + v->cpt_vma_type =CPT_VMA_FILE ; + } + + ctx->write (v,sizeof (*v), ctx);
Error handling?
Quoted 12 lines
checkpoint/cpt_mm.c new file +12
-0+kfree (v); + +if (vma->vm_file) { + err =cpt_dump_dentry (&vma->vm_file->f_path, ctx); +if (err <0 ) +return err; + } + +for (addr = vma->vm_start; addr < vma->vm_end; addr +=PAGE_SIZE ) { +struct page_desc pd; +struct cpt_page_block pgb; +
checkpoint/cpt_mm.c line 350
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+page_get_desc (vma, addr, &pd, ctx); + +if (pd.type ==PD_FUNKEY || pd.type ==PD_ABSENT ) { +eprintk ("dump_one_vma: funkey page\n" ); +return -EINVAL ; + } + + pgb.cpt_start = addr; + pgb.cpt_end = addr +PAGE_SIZE ; +dump_page_block (vma, &pgb, ctx);
Error handling?
Quoted 14 lines
checkpoint/cpt_mm.c new file +14
-0+ } + +return 0 ; +} + +static int cpt_dump_mm_context (struct mm_struct *mm,struct cpt_context *ctx) +{ +#ifdef CONFIG_X86 +if (mm->context.size) { +struct cpt_obj_bits b; +int size; + +mutex_lock (&mm->context.lock); +
checkpoint/cpt_mm.c line 374
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+ b.cpt_type =CPT_OBJ_BITS ; + b.cpt_len =sizeof (b); + b.cpt_content =CPT_CONTENT_MM_CONTEXT ; + b.cpt_size = mm->context.size *LDT_ENTRY_SIZE ; + + ctx->write (&b,sizeof (b), ctx); + + size = mm->context.size *LDT_ENTRY_SIZE ; + + ctx->write (mm->context.ldt, size, ctx);
Error handling?
Quoted 50 lines
checkpoint/cpt_mm.c new file +50
-0+ +mutex_unlock (&mm->context.lock); + } +#endif +return 0 ; +} + +int cpt_dump_mm (struct task_struct *tsk,struct cpt_context *ctx) +{ +struct mm_struct *mm = tsk->mm; +struct cpt_mm_image *v; +struct vm_area_struct *vma; +int err; + + v =kzalloc (sizeof (*v),GFP_KERNEL ); +if (!v) +return -ENOMEM ; + + v->cpt_len =sizeof (*v); + v->cpt_type =CPT_OBJ_MM ; + v->cpt_hdrlen =sizeof (*v); + v->cpt_content =CPT_CONTENT_ARRAY ; + +down_read (&mm->mmap_sem); + v->cpt_start_code = mm->start_code; + v->cpt_end_code = mm->end_code; + v->cpt_start_data = mm->start_data; + v->cpt_end_data = mm->end_data; + v->cpt_start_brk = mm->start_brk; + v->cpt_brk = mm->brk; + v->cpt_start_stack = mm->start_stack; + v->cpt_start_arg = mm->arg_start; + v->cpt_end_arg = mm->arg_end; + v->cpt_start_env = mm->env_start; + v->cpt_end_env = mm->env_end; + v->cpt_def_flags = mm->def_flags; + v->cpt_flags = mm->flags; + v->cpt_map_count = mm->map_count; + + err = ctx->write (v,sizeof (*v), ctx); +kfree (v); + +if (err) { +eprintk ("error during writing mm\n" ); + goto err_up; + } + +for (vma = mm->mmap; vma; vma = vma->vm_next) { +if ((err =dump_one_vma (mm, vma, ctx)) !=0 ) + goto err_up;
checkpoint/cpt_mm.c line 434
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+ } + + err =cpt_dump_mm_context (mm, ctx); + +err_up: +up_read (&mm->mmap_sem); + +return err; +} +
[...]
Louis
Signature · 4 lines
Dr Louis Rilling Kerlabs Skype: louis.rilling Batiment Germanium Phone: (+33|0) 6 80 89 08 23 80 avenue des Buttes de Coesmes http://www.kerlabs.com/ 35700 Rennes
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Andrey MirkinQuoted 1 line · Andrey Mirkin
Functions to restart process, restore its state, fpu and registers are added.
[...]
Quoted 229 lines
checkpoint/rst_process.c new file +223
-0@@ -0,0 +1,277 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Author: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/fs.h> +#include <linux/file.h> +#include <linux/version.h> +#include <linux/module.h> + +#include "checkpoint.h" +#include "cpt_image.h" + +#define HOOK_RESERVE 256 + +struct thr_context { +struct completion complete; +int error; +struct cpt_context *ctx; +struct task_struct *tsk; +}; + +int local_kernel_thread (int (*fn)(void *),void * arg,unsigned long flags,pid_t pid) +{ +pid_t ret; + +if (current->fs ==NULL ) { +/* do_fork_pid() hates processes without fs, oopses. */ +eprintk ("local_kernel_thread: current->fs==NULL\n" ); +return -EINVAL ; + } +if (!try_module_get (THIS_MODULE )) +return -EBUSY ; + ret =kernel_thread (fn, arg, flags); +if (ret <0 ) +module_put (THIS_MODULE ); +return ret; +} + +static unsigned int decode_task_flags (unsigned int task_flags) +{ +unsigned int flags =0 ; + +if (task_flags & (1 <<CPT_PF_EXITING )) + flags |=PF_EXITING ; +if (task_flags & (1 <<CPT_PF_FORKNOEXEC )) + flags |=PF_FORKNOEXEC ; +if (task_flags & (1 <<CPT_PF_SUPERPRIV )) + flags |=PF_SUPERPRIV ; +if (task_flags & (1 <<CPT_PF_DUMPCORE )) + flags |=PF_DUMPCORE ; +if (task_flags & (1 <<CPT_PF_SIGNALED )) + flags |=PF_SIGNALED ; + +return flags; + +} + +int rst_restore_task_struct (struct task_struct *tsk,struct cpt_task_image *ti, +struct cpt_context *ctx) +{ +int i; + +/* Restore only saved flags, comm and tls for now */ + tsk->flags =decode_task_flags (ti->cpt_flags); +clear_tsk_thread_flag (tsk,TIF_FREEZE ); +memcpy (tsk->comm, ti->cpt_comm,TASK_COMM_LEN ); +for (i =0 ; i <GDT_ENTRY_TLS_ENTRIES ; i++) { + tsk->thread.tls_array[i].a = ti->cpt_tls[i] &0xFFFFFFFF ; + tsk->thread.tls_array[i].b = ti->cpt_tls[i] >>32 ; + } + +return 0 ; +} + +static int rst_restore_fpustate (struct task_struct *tsk,struct cpt_task_image *ti, +struct cpt_context *ctx) +{ +struct cpt_obj_bits hdr; +int err; +char *buf; + +clear_stopped_child_used_math (tsk); + + err =rst_get_object (CPT_OBJ_BITS , &hdr,sizeof (hdr), ctx); +if (err <0 ) +return err; + + buf =kmalloc (hdr.cpt_size,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + + err = ctx->read (buf, hdr.cpt_size, ctx); +if (err) + goto out; + +if (hdr.cpt_content ==CPT_CONTENT_X86_FPUSTATE && cpu_has_fxsr) { +memcpy (&tsk->thread.xstate, buf, +sizeof (struct i387_fxsave_struct )); +if (ti->cpt_flags &CPT_PF_USED_MATH ) +set_stopped_child_used_math (tsk); + } +#ifndef CONFIG_X86_64 + else if (hdr.cpt_content == CPT_CONTENT_X86_FPUSTATE_OLD && + !cpu_has_fxsr) { +memcpy (&tsk->thread.xstate, buf, +sizeof (struct i387_fsave_struct )); +if (ti->cpt_flags &CPT_PF_USED_MATH ) +set_stopped_child_used_math (tsk); + } +#endif + +out: +kfree (buf); +return err; +} + +static u32 decode_segment (u32 segid) +{ +if (segid ==CPT_SEG_ZERO ) +return 0 ; + +/* TLS descriptors */ +if (segid <=CPT_SEG_TLS3 ) +return ((GDT_ENTRY_TLS_MIN + segid -CPT_SEG_TLS1 ) <<3 ) +3 ; + +/* LDT descriptor, it is just an index to LDT array */ +if (segid >=CPT_SEG_LDT ) +return ((segid -CPT_SEG_LDT ) <<3 ) |7 ; + +/* Check for one of standard descriptors */ +if (segid ==CPT_SEG_USER32_DS ) +return __USER_DS; +if (segid ==CPT_SEG_USER32_CS ) +return __USER_CS; + +eprintk ("Invalid segment reg %d\n" , segid); +return 0 ; +} + +static int rst_restore_registers (struct task_struct *tsk,struct cpt_context *ctx) +{ +struct cpt_x86_regs ri; +struct pt_regs *regs =task_pt_regs (tsk); +extern char i386_ret_from_resume; +int err; + + err =rst_get_object (CPT_OBJ_X86_REGS , &ri,sizeof (ri), ctx); +if (err <0 ) +return err; + + tsk->thread.sp = (unsigned long ) regs; + tsk->thread.sp0 = (unsigned long ) (regs+1 ); + tsk->thread.ip = (unsigned long ) &i386_ret_from_resume; + + tsk->thread.gs =decode_segment (ri.cpt_gs); + tsk->thread.debugreg0 = ri.cpt_debugreg[0 ]; + tsk->thread.debugreg1 = ri.cpt_debugreg[1 ]; + tsk->thread.debugreg2 = ri.cpt_debugreg[2 ]; + tsk->thread.debugreg3 = ri.cpt_debugreg[3 ]; + tsk->thread.debugreg6 = ri.cpt_debugreg[6 ]; + tsk->thread.debugreg7 = ri.cpt_debugreg[7 ]; + + regs->bx = ri.cpt_bx; + regs->cx = ri.cpt_cx; + regs->dx = ri.cpt_dx; + regs->si = ri.cpt_si; + regs->di = ri.cpt_di; + regs->bp = ri.cpt_bp; + regs->ax = ri.cpt_ax; + regs->orig_ax = ri.cpt_orig_ax; + regs->ip = ri.cpt_ip; + regs->flags = ri.cpt_flags; + regs->sp = ri.cpt_sp; + + regs->cs =decode_segment (ri.cpt_cs); + regs->ss =decode_segment (ri.cpt_ss); + regs->ds =decode_segment (ri.cpt_ds); + regs->es =decode_segment (ri.cpt_es); + regs->fs =decode_segment (ri.cpt_fs); + + tsk->thread.sp -=HOOK_RESERVE ; +memset ((void *)tsk->thread.sp,0 ,HOOK_RESERVE ); + +return 0 ; +} + +static int restart_thread (void *arg) +{ +struct thr_context *thr_ctx = arg; +struct cpt_context *ctx; +struct cpt_task_image *ti; +int err; + + current->state =TASK_UNINTERRUPTIBLE ; + + ctx = thr_ctx->ctx; + ti =kmalloc (sizeof (*ti),GFP_KERNEL ); +if (!ti) +return -ENOMEM ; + + err =rst_get_object (CPT_OBJ_TASK , ti,sizeof (*ti), ctx); +if (!err) + err =rst_restore_task_struct (current, ti, ctx); +/* Restore mm here */ +if (!err) + err =rst_restore_fpustate (current, ti, ctx); +if (!err) + err =rst_restore_registers (current, ctx); + + thr_ctx->error = err; +complete (&thr_ctx->complete); + +if (!err && (ti->cpt_state & (EXIT_ZOMBIE |EXIT_DEAD ))) { +do_exit (ti->cpt_exit_code);
checkpoint/rst_process.c line 233
Quoted 10 lines
checkpoint/rst_process.c new file +10
-0+ }else { +__set_current_state (TASK_UNINTERRUPTIBLE ); + } + +kfree (ti); +schedule (); + +eprintk ("leaked %d/%d %p\n" ,task_pid_nr (current),task_pid_vnr (current), current->mm); + +module_put (THIS_MODULE );
I'm sorry, I still do not understand what you are doing with this self-module pinning stuff. AFAICS, we should not get here unless there is a bug. So the checkpoint module ref count is never decreased, right?
Could you detail what is this self-module pinning for? As I already told you, this looks like a bogus solution to avoid unloading the checkpoint module during restart.
Thanks!
Louis
[...]
Signature · 4 lines
Dr Louis Rilling Kerlabs Skype: louis.rilling Batiment Germanium Phone: (+33|0) 6 80 89 08 23 80 avenue des Buttes de Coesmes http://www.kerlabs.com/ 35700 Rennes
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [PATCH 02/10] Make checkpoint/restart functionality modular
In reply to a message not in the archivecheckpoint/checkpoint.h line 18
Quoted 6 lines · Andrey Mirkin
checkpoint/checkpoint.h new file +6
-0+struct cpt_operations +{ +struct module * owner; +int (*checkpoint)(pid_t pid,int fd,unsigned long flags); +int (*restart)(int ctid,int fd,unsigned long flags); +};
I think this is pretty useless obfuscation. We're not going to have pluggable checkpoint/restart implementations, are we? So, why bother putting it in a module?
I can understand that it's easier to develop your code when it's in a module and you don't have to reboot the machine to load a new kernel each time. But, that's an individual developer thing, and doesn't belong in an upstream submission.
I know people have given you a hard time for this in the past. Why is it still here?
-- Dave
Re: [PATCH 02/10] Make checkpoint/restart functionality modular
In reply to Andrey Mirkincheckpoint/checkpoint.h line 18
Quoted 6 lines · Andrey Mirkin
checkpoint/checkpoint.h new file +6
-0+struct cpt_operations +{ +struct module * owner; +int (*checkpoint)(pid_t pid,int fd,unsigned long flags); +int (*restart)(int ctid,int fd,unsigned long flags); +};
I think this is pretty useless obfuscation. We're not going to have pluggable checkpoint/restart implementations, are we? So, why bother putting it in a module?
I can understand that it's easier to develop your code when it's in a module and you don't have to reboot the machine to load a new kernel each time. But, that's an individual developer thing, and doesn't belong in an upstream submission.
I know people have given you a hard time for this in the past. Why is it still here?
-- Dave
Re: [PATCH 02/10] Make checkpoint/restart functionality modular
In reply to a message not in the archiveQuoted 3 lines · Andrey Mirkin
A config option
CONFIG_CHECKPOINTis introduced.
New structurecpt_operationsis introduced to store pointers to checkpoint/restart functions from module.
I thought we had decided not to use a kernel module?
Louis' comments on your patch 8 regarding module pinning suggests that details about using a module will detract from proper review of the core c/r functionality...
-serge
Re: [PATCH 02/10] Make checkpoint/restart functionality modular
In reply to Andrey MirkinQuoted 3 lines · Andrey Mirkin
A config option
CONFIG_CHECKPOINTis introduced.
New structurecpt_operationsis introduced to store pointers to checkpoint/restart functions from module.
I thought we had decided not to use a kernel module?
Louis' comments on your patch 8 regarding module pinning suggests that details about using a module will detract from proper review of the core c/r functionality...
-serge
Re: [PATCH 03/10] Introduce context structure needed during checkpointing/restart
In reply to Andrey Mirkincheckpoint/checkpoint.h struct cpt_operations · line 38
Quoted 8 lines · Andrey Mirkin
checkpoint/checkpoint.h +8
-0+typedef struct cpt_context +{ + pid_t pid; /* should be changed to ctid later */ + int ctx_id; /* context id */ + struct list_head ctx_list; + int refcount; + int ctx_state; + struct semaphore main_sem;
Does this really need to be a semaphore or is a mutex OK?
checkpoint/checkpoint.h struct cpt_operations · line 40
Quoted 1 line
checkpoint/checkpoint.h +1
-0+int errno;
Could you hold off on adding these things to the struct until the patch where they're actually used? It's hard to judge this without seeing what you do with it.
checkpoint/checkpoint.h struct cpt_operations · line 49
Quoted 8 lines
checkpoint/checkpoint.h +8
-0+struct file *file; +loff_t current_object; + +struct list_head object_array[CPT_OBJ_MAX ]; + +int (*write)(const void *addr,size_t count,struct cpt_context *ctx); +int (*read)(void *addr,size_t count,struct cpt_context *ctx); +} cpt_context_t;
Man, this is hard to review. I was going to try and make sure that your refcounting was right and atomic, but there's no use of it in this patch except for the initialization and accessor functions. Darn.
Quoted 1 line
+extern int
debug_level;
I'm going to go out on a limb here and say that "debug_level" is probably a wee bit too generic of a variable name.
checkpoint/checkpoint.h struct cpt_operations · line 56
Quoted 4 lines
checkpoint/checkpoint.h +4
-0+#define cpt_printk(lvl, fmt, args...) do { \ + if (lvl <= debug_level) \ + printk(fmt, ##args); \ + } while (0)
I think you can use pr_debug() here, too, just like Oren did.
Quoted 55 lines
checkpoint/sys.c +52
-1+struct cpt_context *context_alloc (void ) +{ +struct cpt_context *ctx; +int i; + + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return NULL ; + +init_MUTEX (&ctx->main_sem); + ctx->refcount =1 ; + + ctx->current_object =-1 ; + ctx->write = file_write; + ctx->read = file_read; +for (i =0 ; i <CPT_OBJ_MAX ; i++) { +INIT_LIST_HEAD (&ctx->object_array[i]); + } + +return ctx; +} + +void context_release (struct cpt_context *ctx) +{ + ctx->ctx_state =CPT_CTX_ERROR ; + +kfree (ctx); +} + +static void context_put (struct cpt_context *ctx) +{ +if (!--ctx->refcount) +context_release (ctx); +} +static int checkpoint (pid_t pid,int fd,unsigned long flags) { -return -ENOSYS ; +struct file *file; +struct cpt_context *ctx; +int err; + + err = -EBADF ; + file =fget (fd); +if (!file) + goto out; + + err = -ENOMEM ; + ctx =context_alloc (); +if (!ctx) + goto out_file; + + ctx->file = file; + ctx->ctx_state =CPT_CTX_DUMPING ; +
checkpoint/sys.c line 120
Quoted 10 lines
checkpoint/sys.c +9
-0+/* checkpoint */ + err = -ENOSYS ; + +context_put (ctx); + +out_file: +fput (file); +out: +return err; }
So, where is context_get()? Is there only single-threaded access to the refcount? If so, why do we even need it? We should probably just use context_release() driectly.
If there is multithreaded access to context_put() or the refcount, then they're unsafe without additional locking.
-- Dave
Re: [PATCH 06/10] Introduce functions to dump mm
In reply to a message not in the archiveQuoted 26 lines · Andrey Mirkin
checkpoint/cpt_mm.c new file +26
-0+static void page_get_desc (struct vm_area_struct *vma,unsigned long addr, +struct page_desc *pdesc,cpt_context_t * ctx) +{ +struct mm_struct *mm = vma->vm_mm; +pgd_t *pgd; +pud_t *pud; +pmd_t *pmd; +pte_t *ptep, pte; +spinlock_t *ptl; +struct page *pg =NULL ; +pgoff_t linear_index = (addr - vma->vm_start)/PAGE_SIZE + vma->vm_pgoff; + + pdesc->index = linear_index; + pdesc->shared =0 ; + pdesc->mm =CPT_NULL ; + +if (vma->vm_flags &VM_IO ) { + pdesc->type =PD_ABSENT ; +return ; + } + + pgd =pgd_offset (mm, addr); +if (pgd_none (*pgd) ||unlikely (pgd_bad (*pgd))) + goto out_absent; + pud =pud_offset (pgd, addr); +if (pud_none (*pud) ||unlikely (pud_bad (*pud)))
checkpoint/cpt_mm.c line 97
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+ goto out_absent; + pmd =pmd_offset (pud, addr); +if (pmd_none (*pmd) ||unlikely (pmd_bad (*pmd))) + goto out_absent; +#ifdef CONFIG_X86 +if (pmd_huge (*pmd)) { +eprintk ("page_huge\n" ); + goto out_unsupported; + } +#endif
I take it you know that this breaks with the 1GB (x86_64) and 16GB (ppc) large pages.
Since you have the VMA, why not use is_vm_hugetlb_page()?
-- Dave
Re: [PATCH 06/10] Introduce functions to dump mm
In reply to Andrey MirkinQuoted 26 lines · Andrey Mirkin
checkpoint/cpt_mm.c new file +26
-0+static void page_get_desc (struct vm_area_struct *vma,unsigned long addr, +struct page_desc *pdesc,cpt_context_t * ctx) +{ +struct mm_struct *mm = vma->vm_mm; +pgd_t *pgd; +pud_t *pud; +pmd_t *pmd; +pte_t *ptep, pte; +spinlock_t *ptl; +struct page *pg =NULL ; +pgoff_t linear_index = (addr - vma->vm_start)/PAGE_SIZE + vma->vm_pgoff; + + pdesc->index = linear_index; + pdesc->shared =0 ; + pdesc->mm =CPT_NULL ; + +if (vma->vm_flags &VM_IO ) { + pdesc->type =PD_ABSENT ; +return ; + } + + pgd =pgd_offset (mm, addr); +if (pgd_none (*pgd) ||unlikely (pgd_bad (*pgd))) + goto out_absent; + pud =pud_offset (pgd, addr); +if (pud_none (*pud) ||unlikely (pud_bad (*pud)))
checkpoint/cpt_mm.c line 97
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+ goto out_absent; + pmd =pmd_offset (pud, addr); +if (pmd_none (*pmd) ||unlikely (pmd_bad (*pmd))) + goto out_absent; +#ifdef CONFIG_X86 +if (pmd_huge (*pmd)) { +eprintk ("page_huge\n" ); + goto out_unsupported; + } +#endif
I take it you know that this breaks with the 1GB (x86_64) and 16GB (ppc) large pages.
Since you have the VMA, why not use is_vm_hugetlb_page()?
-- Dave
Re: [PATCH 05/10] Introduce function to dump process
In reply to a message not in the archivecheckpoint/cpt_process.c line 104
Quoted 8 lines · Andrey Mirkin
checkpoint/cpt_process.c new file +8
-0+ t->cpt_uid = tsk->uid; + t->cpt_euid = tsk->euid; + t->cpt_suid = tsk->suid; + t->cpt_fsuid = tsk->fsuid; + t->cpt_gid = tsk->gid; + t->cpt_egid = tsk->egid; + t->cpt_sgid = tsk->sgid; + t->cpt_fsgid = tsk->fsgid;
I don't see where any of these are restored. (Obviously, I wanted to think about how you're verifying the restarter's authorization to do so)
thanks,
-serge
Re: [PATCH 05/10] Introduce function to dump process
In reply to Andrey Mirkincheckpoint/cpt_process.c line 104
Quoted 8 lines · Andrey Mirkin
checkpoint/cpt_process.c new file +8
-0+ t->cpt_uid = tsk->uid; + t->cpt_euid = tsk->euid; + t->cpt_suid = tsk->suid; + t->cpt_fsuid = tsk->fsuid; + t->cpt_gid = tsk->gid; + t->cpt_egid = tsk->egid; + t->cpt_sgid = tsk->sgid; + t->cpt_fsgid = tsk->fsgid;
I don't see where any of these are restored. (Obviously, I wanted to think about how you're verifying the restarter's authorization to do so)
thanks,
-serge
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 40 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
Quoted 3 lines
call *%eax
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Cedric Le GoaterQuoted 40 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
Quoted 3 lines
call *%eax
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.
Andrey
Re: [Devel] Re: [PATCH 06/10] Introduce functions to dump mm
In reply to a message not in the archiveQuoted 228 lines · On Monday 20 October 2008 16:25 Louis Rilling wrote:
Quoted 1 line · Andrey Mirkin
Functions to dump mm struct, VMAs and mm context are added.
Again, a few little comments.
[...]
Quoted 221 lines
checkpoint/cpt_mm.c new file +61
-0@@ -0,0 +1,434 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Authors: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/slab.h> +#include <linux/file.h> +#include <linux/mm.h> +#include <linux/errno.h> +#include <linux/major.h> +#include <linux/mman.h> +#include <linux/mnt_namespace.h> +#include <linux/mount.h> +#include <linux/namei.h> +#include <linux/pagemap.h> +#include <linux/hugetlb.h> +#include <asm/ldt.h> + +#include "checkpoint.h" +#include "cpt_image.h" + +struct page_area +{ +int type; +unsigned long start; +unsigned long end; +pgoff_t pgoff; +loff_t mm; +__u64 list[16 ]; +}; + +struct page_desc +{ +int type; +pgoff_t index; +loff_t mm; +int shared; +}; + +enum { +PD_ABSENT , +PD_COPY , +PD_FUNKEY , +}; + +/* 0: page can be obtained from backstore, or still not mapped anonymous page, + or something else, which does not requre copy. +1: page requires copy +2: page requres copy but its content is zero. Quite useless. +3: wp page is shared after fork(). It is to be COWed when modified. +4: page is something unsupported... We copy it right now. +*/ + +static void page_get_desc(struct vm_area_struct *vma, unsigned longaddr, + struct
page_desc*pdesc,cpt_context_t* ctx)checkpoint/cpt_mm.c new file +9
-0+{ +struct mm_struct *mm = vma->vm_mm; +pgd_t *pgd; +pud_t *pud; +pmd_t *pmd; +pte_t *ptep, pte; +spinlock_t *ptl; +struct page *pg =NULL ; + pgoff_t linear_index = (addr - vma->vm_start)/PAGE_SIZE +
vma->vm_pgoff; +checkpoint/cpt_mm.c new file +101
-0+ pdesc->index = linear_index; + pdesc->shared =0 ; + pdesc->mm =CPT_NULL ; + +if (vma->vm_flags &VM_IO ) { + pdesc->type =PD_ABSENT ; +return ; + } + + pgd =pgd_offset (mm, addr); +if (pgd_none (*pgd) ||unlikely (pgd_bad (*pgd))) + goto out_absent; + pud =pud_offset (pgd, addr); +if (pud_none (*pud) ||unlikely (pud_bad (*pud))) + goto out_absent; + pmd =pmd_offset (pud, addr); +if (pmd_none (*pmd) ||unlikely (pmd_bad (*pmd))) + goto out_absent; +#ifdef CONFIG_X86 +if (pmd_huge (*pmd)) { +eprintk ("page_huge\n" ); + goto out_unsupported; + } +#endif + ptep =pte_offset_map_lock (mm, pmd, addr, &ptl); + pte = *ptep; +pte_unmap (ptep); + +if (pte_none (pte)) + goto out_absent_unlock; + +if ((pg =vm_normal_page (vma, addr, pte)) ==NULL ) { + pdesc->type =PD_COPY ; + goto out_unlock; + } + +get_page (pg); +spin_unlock (ptl); + +if (pg->mapping && !PageAnon (pg)) { +if (vma->vm_file ==NULL ) { +eprintk ("pg->mapping!=NULL for fileless vma: %08lx\n" , addr); + goto out_unsupported; + } +if (vma->vm_file->f_mapping != pg->mapping) { +eprintk ("pg->mapping!=f_mapping: %08lx %p %p\n" , + addr, vma->vm_file->f_mapping, pg->mapping); + goto out_unsupported; + } + pdesc->index = (pg->index << (PAGE_CACHE_SHIFT -PAGE_SHIFT )); +/* Page is in backstore. For us it is like +* it is not present. +*/ + goto out_absent; + } + +if (PageReserved (pg)) { +/* Special case: ZERO_PAGE is used, when an +* anonymous page is accessed but not written. */ +if (pg ==ZERO_PAGE (addr)) { +if (pte_write (pte)) { +eprintk ("not funny already, writable ZERO_PAGE\n" ); + goto out_unsupported; + } +/* Just copy it for now */ + pdesc->type =PD_COPY ; + goto out_put; + } +eprintk ("reserved page %lu at %08lx\n" , pg->index, addr); + goto out_unsupported; + } + +if (!pg->mapping) { +eprintk ("page without mapping at %08lx\n" , addr); + goto out_unsupported; + } + + pdesc->type =PD_COPY ; + +out_put: +if (pg) +put_page (pg); +return ; + +out_unlock: +spin_unlock (ptl); + goto out_put; + +out_absent_unlock: +spin_unlock (ptl); + +out_absent: + pdesc->type =PD_ABSENT ; + goto out_put; + +out_unsupported: + pdesc->type =PD_FUNKEY ; + goto out_put; +} + +static int count_vma_pages(struct vm_area_struct *vma, struct
cpt_context*ctx) +{checkpoint/cpt_mm.c new file +19
-0+unsigned long addr; +int page_num =0 ; + +for (addr = vma->vm_start; addr < vma->vm_end; addr +=PAGE_SIZE ) { +struct page_desc pd; + +page_get_desc (vma, addr, &pd, ctx); + +if (pd.type !=PD_COPY ) { +return -EINVAL ; + }else { + page_num +=1 ; + } + + } +return page_num; +} + +/* ATTN: We give "current" to get_user_pages(). This is wrong, but
get_user_pages()+ * does not really need this thing. It just stores some page fault stats there. + *
+ * BUG: some archs (f.e. sparc64, but not Intel*) require flush cache pages + * before accessing vma.
+ */checkpoint/cpt_mm.c new file +16
-0+static int dump_pages (struct vm_area_struct *vma,unsigned long start, +unsigned long end,struct cpt_context *ctx) +{ +#define MAX_PAGE_BATCH 16 +struct page *pg[MAX_PAGE_BATCH ]; +int npages = (end - start)/PAGE_SIZE ; +int count =0 ; + +while (count < npages) { +int copy = npages - count; +int n; + +if (copy >MAX_PAGE_BATCH ) + copy =MAX_PAGE_BATCH ; + n =get_user_pages (current, vma->vm_mm, start, copy, +0 ,1 , pg,NULL );
Quoted 8 lines
checkpoint/cpt_mm.c line 221
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+if (n == copy) { +int i; +for (i=0 ; i<n; i++) { +char *maddr =kmap (pg[i]); + ctx->write (maddr,PAGE_SIZE , ctx); +kunmap (pg[i]);There is no error handling in this inner loop. Should be fixed imho.
Yes, you right. Already fixed in next version. I'll try to send it out shortly.
Quoted 54 lines
Quoted 54 lines
checkpoint/cpt_mm.c new file +53
-0+ } + }else { +eprintk ("get_user_pages fault" ); +for ( ; n >0 ; n--) +page_cache_release (pg[n-1 ]); +return -EFAULT ; + } + start += n*PAGE_SIZE ; + count += n; +for ( ; n >0 ; n--) +page_cache_release (pg[n-1 ]); + } +return 0 ; +} + +static int dump_page_block (struct vm_area_struct *vma, +struct cpt_page_block *pgb, +struct cpt_context *ctx) +{ +int err; + pgb->cpt_len =sizeof (*pgb) + pgb->cpt_end - pgb->cpt_start; + pgb->cpt_type =CPT_OBJ_PAGES ; + pgb->cpt_hdrlen =sizeof (*pgb); + pgb->cpt_content =CPT_CONTENT_DATA ; + + err = ctx->write (pgb,sizeof (*pgb), ctx); +if (!err) + err =dump_pages (vma, pgb->cpt_start, pgb->cpt_end, ctx); + +return err; +} + +static int cpt_dump_dentry (struct path *p,cpt_context_t *ctx) +{ +int len; +char *path; +char *buf; +struct cpt_object_hdr o; + + buf = (char *)__get_free_page (GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + + path =d_path (p, buf,PAGE_SIZE ); + +if (IS_ERR (path)) { +free_page ((unsigned long )buf); +return PTR_ERR (path); + } + + len = buf +PAGE_SIZE -1 - path; + o.cpt_len =sizeof (o) + len +1 ; + o.cpt_type =CPT_OBJ_NAME ;
Quoted 8 lines
checkpoint/cpt_mm.c line 280
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+ o.cpt_hdrlen =sizeof (o); + o.cpt_content =CPT_CONTENT_NAME ; + path[len] =0 ; + + ctx->write (&o,sizeof (o), ctx); + ctx->write (path, len +1 , ctx);Error handling?
Will fix it, thanks.
Quoted 38 lines
Quoted 38 lines
checkpoint/cpt_mm.c new file +37
-0+free_page ((unsigned long )buf); + +return 0 ; +} + +static int dump_one_vma (struct mm_struct *mm, +struct vm_area_struct *vma,struct cpt_context *ctx) +{ +struct cpt_vma_image *v; +unsigned long addr; +int page_num; +int err; + + v =kzalloc (sizeof (*v),GFP_KERNEL ); +if (!v) +return -ENOMEM ; + + v->cpt_len =sizeof (*v); + v->cpt_type =CPT_OBJ_VMA ; + v->cpt_hdrlen =sizeof (*v); + v->cpt_content =CPT_CONTENT_ARRAY ; + + v->cpt_start = vma->vm_start; + v->cpt_end = vma->vm_end; + v->cpt_flags = vma->vm_flags; +if (vma->vm_flags &VM_HUGETLB ) { +eprintk ("huge TLB VMAs are still not supported\n" ); +kfree (v); +return -EINVAL ; + } + v->cpt_pgprot = vma->vm_page_prot.pgprot; + v->cpt_pgoff = vma->vm_pgoff; + v->cpt_file =CPT_NULL ; + v->cpt_vma_type =CPT_VMA_TYPE_0 ; + + page_num =count_vma_pages (vma, ctx); +if (page_num <0 ) {
Quoted 8 lines
checkpoint/cpt_mm.c line 310
Quoted 3 lines
checkpoint/cpt_mm.c new file +3
-0+kfree (v); +return -EINVAL ; + }AFAICS, since
count_vma_pagesonly supports pages withPD_COPY, and sinceget_page_desc()tags text segment pages (file-mapped and not anonymous since not written to) asPD_ABSENT, no executable is checkpointable. So, where is the trick? Am I completely missing something about page mapping?
Oh, that's my fault, I have sent wrong version. I will send new patchset with correct page mapping today.
Quoted 11 lines
checkpoint/cpt_mm.c line 328
Quoted 9 lines
checkpoint/cpt_mm.c new file +8
-0+ v->cpt_page_num = page_num; + +if (vma->vm_file) { + v->cpt_file =0 ; + v->cpt_vma_type =CPT_VMA_FILE ; + } + + ctx->write (v,sizeof (*v), ctx);Error handling?
Yes, will add it.
Quoted 17 lines
Quoted 17 lines
checkpoint/cpt_mm.c new file +16
-0+kfree (v); + +if (vma->vm_file) { + err =cpt_dump_dentry (&vma->vm_file->f_path, ctx); +if (err <0 ) +return err; + } + +for (addr = vma->vm_start; addr < vma->vm_end; addr +=PAGE_SIZE ) { +struct page_desc pd; +struct cpt_page_block pgb; + +page_get_desc (vma, addr, &pd, ctx); + +if (pd.type ==PD_FUNKEY || pd.type ==PD_ABSENT ) { +eprintk ("dump_one_vma: funkey page\n" );
Quoted 8 lines
checkpoint/cpt_mm.c line 350
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+return -EINVAL ; + } + + pgb.cpt_start = addr; + pgb.cpt_end = addr +PAGE_SIZE ; +dump_page_block (vma, &pgb, ctx);Error handling?
Yeap, thanks.
Quoted 19 lines
Quoted 19 lines
checkpoint/cpt_mm.c new file +6
-0+ } + +return 0 ; +} + +static int cpt_dump_mm_context(struct mm_struct *mm, struct cpt_context*ctx) +{
checkpoint/cpt_mm.c new file +11
-0+#ifdef CONFIG_X86 +if (mm->context.size) { +struct cpt_obj_bits b; +int size; + +mutex_lock (&mm->context.lock); + + b.cpt_type =CPT_OBJ_BITS ; + b.cpt_len =sizeof (b); + b.cpt_content =CPT_CONTENT_MM_CONTEXT ; + b.cpt_size = mm->context.size *LDT_ENTRY_SIZE ;
Quoted 8 lines
checkpoint/cpt_mm.c line 374
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+ + ctx->write (&b,sizeof (b), ctx); + + size = mm->context.size *LDT_ENTRY_SIZE ; + + ctx->write (mm->context.ldt, size, ctx);Error handling?
Thanks again!
Quoted 65 lines
Quoted 51 lines
checkpoint/cpt_mm.c new file +50
-0+ +mutex_unlock (&mm->context.lock); + } +#endif +return 0 ; +} + +int cpt_dump_mm (struct task_struct *tsk,struct cpt_context *ctx) +{ +struct mm_struct *mm = tsk->mm; +struct cpt_mm_image *v; +struct vm_area_struct *vma; +int err; + + v =kzalloc (sizeof (*v),GFP_KERNEL ); +if (!v) +return -ENOMEM ; + + v->cpt_len =sizeof (*v); + v->cpt_type =CPT_OBJ_MM ; + v->cpt_hdrlen =sizeof (*v); + v->cpt_content =CPT_CONTENT_ARRAY ; + +down_read (&mm->mmap_sem); + v->cpt_start_code = mm->start_code; + v->cpt_end_code = mm->end_code; + v->cpt_start_data = mm->start_data; + v->cpt_end_data = mm->end_data; + v->cpt_start_brk = mm->start_brk; + v->cpt_brk = mm->brk; + v->cpt_start_stack = mm->start_stack; + v->cpt_start_arg = mm->arg_start; + v->cpt_end_arg = mm->arg_end; + v->cpt_start_env = mm->env_start; + v->cpt_end_env = mm->env_end; + v->cpt_def_flags = mm->def_flags; + v->cpt_flags = mm->flags; + v->cpt_map_count = mm->map_count; + + err = ctx->write (v,sizeof (*v), ctx); +kfree (v); + +if (err) { +eprintk ("error during writing mm\n" ); + goto err_up; + } + +for (vma = mm->mmap; vma; vma = vma->vm_next) { +if ((err =dump_one_vma (mm, vma, ctx)) !=0 ) + goto err_up;checkpoint/cpt_mm.c line 434
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+ } + + err =cpt_dump_mm_context (mm, ctx); + +err_up: +up_read (&mm->mmap_sem); + +return err; +} +[...]
Louis
Re: [Devel] Re: [PATCH 06/10] Introduce functions to dump mm
In reply to Louis RillingQuoted 228 lines · On Monday 20 October 2008 16:25 Louis Rilling wrote:
Quoted 1 line · Andrey Mirkin
Functions to dump mm struct, VMAs and mm context are added.
Again, a few little comments.
[...]
Quoted 221 lines
checkpoint/cpt_mm.c new file +61
-0@@ -0,0 +1,434 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Authors: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/slab.h> +#include <linux/file.h> +#include <linux/mm.h> +#include <linux/errno.h> +#include <linux/major.h> +#include <linux/mman.h> +#include <linux/mnt_namespace.h> +#include <linux/mount.h> +#include <linux/namei.h> +#include <linux/pagemap.h> +#include <linux/hugetlb.h> +#include <asm/ldt.h> + +#include "checkpoint.h" +#include "cpt_image.h" + +struct page_area +{ +int type; +unsigned long start; +unsigned long end; +pgoff_t pgoff; +loff_t mm; +__u64 list[16 ]; +}; + +struct page_desc +{ +int type; +pgoff_t index; +loff_t mm; +int shared; +}; + +enum { +PD_ABSENT , +PD_COPY , +PD_FUNKEY , +}; + +/* 0: page can be obtained from backstore, or still not mapped anonymous page, + or something else, which does not requre copy. +1: page requires copy +2: page requres copy but its content is zero. Quite useless. +3: wp page is shared after fork(). It is to be COWed when modified. +4: page is something unsupported... We copy it right now. +*/ + +static void page_get_desc(struct vm_area_struct *vma, unsigned longaddr, + struct
page_desc*pdesc,cpt_context_t* ctx)checkpoint/cpt_mm.c new file +9
-0+{ +struct mm_struct *mm = vma->vm_mm; +pgd_t *pgd; +pud_t *pud; +pmd_t *pmd; +pte_t *ptep, pte; +spinlock_t *ptl; +struct page *pg =NULL ; + pgoff_t linear_index = (addr - vma->vm_start)/PAGE_SIZE +
vma->vm_pgoff; +checkpoint/cpt_mm.c new file +101
-0+ pdesc->index = linear_index; + pdesc->shared =0 ; + pdesc->mm =CPT_NULL ; + +if (vma->vm_flags &VM_IO ) { + pdesc->type =PD_ABSENT ; +return ; + } + + pgd =pgd_offset (mm, addr); +if (pgd_none (*pgd) ||unlikely (pgd_bad (*pgd))) + goto out_absent; + pud =pud_offset (pgd, addr); +if (pud_none (*pud) ||unlikely (pud_bad (*pud))) + goto out_absent; + pmd =pmd_offset (pud, addr); +if (pmd_none (*pmd) ||unlikely (pmd_bad (*pmd))) + goto out_absent; +#ifdef CONFIG_X86 +if (pmd_huge (*pmd)) { +eprintk ("page_huge\n" ); + goto out_unsupported; + } +#endif + ptep =pte_offset_map_lock (mm, pmd, addr, &ptl); + pte = *ptep; +pte_unmap (ptep); + +if (pte_none (pte)) + goto out_absent_unlock; + +if ((pg =vm_normal_page (vma, addr, pte)) ==NULL ) { + pdesc->type =PD_COPY ; + goto out_unlock; + } + +get_page (pg); +spin_unlock (ptl); + +if (pg->mapping && !PageAnon (pg)) { +if (vma->vm_file ==NULL ) { +eprintk ("pg->mapping!=NULL for fileless vma: %08lx\n" , addr); + goto out_unsupported; + } +if (vma->vm_file->f_mapping != pg->mapping) { +eprintk ("pg->mapping!=f_mapping: %08lx %p %p\n" , + addr, vma->vm_file->f_mapping, pg->mapping); + goto out_unsupported; + } + pdesc->index = (pg->index << (PAGE_CACHE_SHIFT -PAGE_SHIFT )); +/* Page is in backstore. For us it is like +* it is not present. +*/ + goto out_absent; + } + +if (PageReserved (pg)) { +/* Special case: ZERO_PAGE is used, when an +* anonymous page is accessed but not written. */ +if (pg ==ZERO_PAGE (addr)) { +if (pte_write (pte)) { +eprintk ("not funny already, writable ZERO_PAGE\n" ); + goto out_unsupported; + } +/* Just copy it for now */ + pdesc->type =PD_COPY ; + goto out_put; + } +eprintk ("reserved page %lu at %08lx\n" , pg->index, addr); + goto out_unsupported; + } + +if (!pg->mapping) { +eprintk ("page without mapping at %08lx\n" , addr); + goto out_unsupported; + } + + pdesc->type =PD_COPY ; + +out_put: +if (pg) +put_page (pg); +return ; + +out_unlock: +spin_unlock (ptl); + goto out_put; + +out_absent_unlock: +spin_unlock (ptl); + +out_absent: + pdesc->type =PD_ABSENT ; + goto out_put; + +out_unsupported: + pdesc->type =PD_FUNKEY ; + goto out_put; +} + +static int count_vma_pages(struct vm_area_struct *vma, struct
cpt_context*ctx) +{checkpoint/cpt_mm.c new file +19
-0+unsigned long addr; +int page_num =0 ; + +for (addr = vma->vm_start; addr < vma->vm_end; addr +=PAGE_SIZE ) { +struct page_desc pd; + +page_get_desc (vma, addr, &pd, ctx); + +if (pd.type !=PD_COPY ) { +return -EINVAL ; + }else { + page_num +=1 ; + } + + } +return page_num; +} + +/* ATTN: We give "current" to get_user_pages(). This is wrong, but
get_user_pages()+ * does not really need this thing. It just stores some page fault stats there. + *
+ * BUG: some archs (f.e. sparc64, but not Intel*) require flush cache pages + * before accessing vma.
+ */checkpoint/cpt_mm.c new file +16
-0+static int dump_pages (struct vm_area_struct *vma,unsigned long start, +unsigned long end,struct cpt_context *ctx) +{ +#define MAX_PAGE_BATCH 16 +struct page *pg[MAX_PAGE_BATCH ]; +int npages = (end - start)/PAGE_SIZE ; +int count =0 ; + +while (count < npages) { +int copy = npages - count; +int n; + +if (copy >MAX_PAGE_BATCH ) + copy =MAX_PAGE_BATCH ; + n =get_user_pages (current, vma->vm_mm, start, copy, +0 ,1 , pg,NULL );
Quoted 8 lines
checkpoint/cpt_mm.c line 221
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+if (n == copy) { +int i; +for (i=0 ; i<n; i++) { +char *maddr =kmap (pg[i]); + ctx->write (maddr,PAGE_SIZE , ctx); +kunmap (pg[i]);There is no error handling in this inner loop. Should be fixed imho.
Yes, you right. Already fixed in next version. I'll try to send it out shortly.
Quoted 54 lines
Quoted 54 lines
checkpoint/cpt_mm.c new file +53
-0+ } + }else { +eprintk ("get_user_pages fault" ); +for ( ; n >0 ; n--) +page_cache_release (pg[n-1 ]); +return -EFAULT ; + } + start += n*PAGE_SIZE ; + count += n; +for ( ; n >0 ; n--) +page_cache_release (pg[n-1 ]); + } +return 0 ; +} + +static int dump_page_block (struct vm_area_struct *vma, +struct cpt_page_block *pgb, +struct cpt_context *ctx) +{ +int err; + pgb->cpt_len =sizeof (*pgb) + pgb->cpt_end - pgb->cpt_start; + pgb->cpt_type =CPT_OBJ_PAGES ; + pgb->cpt_hdrlen =sizeof (*pgb); + pgb->cpt_content =CPT_CONTENT_DATA ; + + err = ctx->write (pgb,sizeof (*pgb), ctx); +if (!err) + err =dump_pages (vma, pgb->cpt_start, pgb->cpt_end, ctx); + +return err; +} + +static int cpt_dump_dentry (struct path *p,cpt_context_t *ctx) +{ +int len; +char *path; +char *buf; +struct cpt_object_hdr o; + + buf = (char *)__get_free_page (GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + + path =d_path (p, buf,PAGE_SIZE ); + +if (IS_ERR (path)) { +free_page ((unsigned long )buf); +return PTR_ERR (path); + } + + len = buf +PAGE_SIZE -1 - path; + o.cpt_len =sizeof (o) + len +1 ; + o.cpt_type =CPT_OBJ_NAME ;
Quoted 8 lines
checkpoint/cpt_mm.c line 280
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+ o.cpt_hdrlen =sizeof (o); + o.cpt_content =CPT_CONTENT_NAME ; + path[len] =0 ; + + ctx->write (&o,sizeof (o), ctx); + ctx->write (path, len +1 , ctx);Error handling?
Will fix it, thanks.
Quoted 38 lines
Quoted 38 lines
checkpoint/cpt_mm.c new file +37
-0+free_page ((unsigned long )buf); + +return 0 ; +} + +static int dump_one_vma (struct mm_struct *mm, +struct vm_area_struct *vma,struct cpt_context *ctx) +{ +struct cpt_vma_image *v; +unsigned long addr; +int page_num; +int err; + + v =kzalloc (sizeof (*v),GFP_KERNEL ); +if (!v) +return -ENOMEM ; + + v->cpt_len =sizeof (*v); + v->cpt_type =CPT_OBJ_VMA ; + v->cpt_hdrlen =sizeof (*v); + v->cpt_content =CPT_CONTENT_ARRAY ; + + v->cpt_start = vma->vm_start; + v->cpt_end = vma->vm_end; + v->cpt_flags = vma->vm_flags; +if (vma->vm_flags &VM_HUGETLB ) { +eprintk ("huge TLB VMAs are still not supported\n" ); +kfree (v); +return -EINVAL ; + } + v->cpt_pgprot = vma->vm_page_prot.pgprot; + v->cpt_pgoff = vma->vm_pgoff; + v->cpt_file =CPT_NULL ; + v->cpt_vma_type =CPT_VMA_TYPE_0 ; + + page_num =count_vma_pages (vma, ctx); +if (page_num <0 ) {
Quoted 8 lines
checkpoint/cpt_mm.c line 310
Quoted 3 lines
checkpoint/cpt_mm.c new file +3
-0+kfree (v); +return -EINVAL ; + }AFAICS, since
count_vma_pagesonly supports pages withPD_COPY, and sinceget_page_desc()tags text segment pages (file-mapped and not anonymous since not written to) asPD_ABSENT, no executable is checkpointable. So, where is the trick? Am I completely missing something about page mapping?
Oh, that's my fault, I have sent wrong version. I will send new patchset with correct page mapping today.
Quoted 11 lines
checkpoint/cpt_mm.c line 328
Quoted 9 lines
checkpoint/cpt_mm.c new file +8
-0+ v->cpt_page_num = page_num; + +if (vma->vm_file) { + v->cpt_file =0 ; + v->cpt_vma_type =CPT_VMA_FILE ; + } + + ctx->write (v,sizeof (*v), ctx);Error handling?
Yes, will add it.
Quoted 17 lines
Quoted 17 lines
checkpoint/cpt_mm.c new file +16
-0+kfree (v); + +if (vma->vm_file) { + err =cpt_dump_dentry (&vma->vm_file->f_path, ctx); +if (err <0 ) +return err; + } + +for (addr = vma->vm_start; addr < vma->vm_end; addr +=PAGE_SIZE ) { +struct page_desc pd; +struct cpt_page_block pgb; + +page_get_desc (vma, addr, &pd, ctx); + +if (pd.type ==PD_FUNKEY || pd.type ==PD_ABSENT ) { +eprintk ("dump_one_vma: funkey page\n" );
Quoted 8 lines
checkpoint/cpt_mm.c line 350
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+return -EINVAL ; + } + + pgb.cpt_start = addr; + pgb.cpt_end = addr +PAGE_SIZE ; +dump_page_block (vma, &pgb, ctx);Error handling?
Yeap, thanks.
Quoted 19 lines
Quoted 19 lines
checkpoint/cpt_mm.c new file +6
-0+ } + +return 0 ; +} + +static int cpt_dump_mm_context(struct mm_struct *mm, struct cpt_context*ctx) +{
checkpoint/cpt_mm.c new file +11
-0+#ifdef CONFIG_X86 +if (mm->context.size) { +struct cpt_obj_bits b; +int size; + +mutex_lock (&mm->context.lock); + + b.cpt_type =CPT_OBJ_BITS ; + b.cpt_len =sizeof (b); + b.cpt_content =CPT_CONTENT_MM_CONTEXT ; + b.cpt_size = mm->context.size *LDT_ENTRY_SIZE ;
Quoted 8 lines
checkpoint/cpt_mm.c line 374
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+ + ctx->write (&b,sizeof (b), ctx); + + size = mm->context.size *LDT_ENTRY_SIZE ; + + ctx->write (mm->context.ldt, size, ctx);Error handling?
Thanks again!
Quoted 65 lines
Quoted 51 lines
checkpoint/cpt_mm.c new file +50
-0+ +mutex_unlock (&mm->context.lock); + } +#endif +return 0 ; +} + +int cpt_dump_mm (struct task_struct *tsk,struct cpt_context *ctx) +{ +struct mm_struct *mm = tsk->mm; +struct cpt_mm_image *v; +struct vm_area_struct *vma; +int err; + + v =kzalloc (sizeof (*v),GFP_KERNEL ); +if (!v) +return -ENOMEM ; + + v->cpt_len =sizeof (*v); + v->cpt_type =CPT_OBJ_MM ; + v->cpt_hdrlen =sizeof (*v); + v->cpt_content =CPT_CONTENT_ARRAY ; + +down_read (&mm->mmap_sem); + v->cpt_start_code = mm->start_code; + v->cpt_end_code = mm->end_code; + v->cpt_start_data = mm->start_data; + v->cpt_end_data = mm->end_data; + v->cpt_start_brk = mm->start_brk; + v->cpt_brk = mm->brk; + v->cpt_start_stack = mm->start_stack; + v->cpt_start_arg = mm->arg_start; + v->cpt_end_arg = mm->arg_end; + v->cpt_start_env = mm->env_start; + v->cpt_end_env = mm->env_end; + v->cpt_def_flags = mm->def_flags; + v->cpt_flags = mm->flags; + v->cpt_map_count = mm->map_count; + + err = ctx->write (v,sizeof (*v), ctx); +kfree (v); + +if (err) { +eprintk ("error during writing mm\n" ); + goto err_up; + } + +for (vma = mm->mmap; vma; vma = vma->vm_next) { +if ((err =dump_one_vma (mm, vma, ctx)) !=0 ) + goto err_up;checkpoint/cpt_mm.c line 434
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+ } + + err =cpt_dump_mm_context (mm, ctx); + +err_up: +up_read (&mm->mmap_sem); + +return err; +} +[...]
Louis
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 43 lines · Andrey Mirkin
Quoted 42 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
Quoted 7 lines
Quoted 1 line
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees -EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
Louis
Signature · 4 lines
Dr Louis Rilling Kerlabs Skype: louis.rilling Batiment Germanium Phone: (+33|0) 6 80 89 08 23 80 avenue des Buttes de Coesmes http://www.kerlabs.com/ 35700 Rennes
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Andrey MirkinQuoted 43 lines · Andrey Mirkin
Quoted 42 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
Quoted 7 lines
Quoted 1 line
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees -EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
Louis
Signature · 4 lines
Dr Louis Rilling Kerlabs Skype: louis.rilling Batiment Germanium Phone: (+33|0) 6 80 89 08 23 80 avenue des Buttes de Coesmes http://www.kerlabs.com/ 35700 Rennes
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 10 lines · Louis Rilling
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Louis
I don't know Kerrighed internals but I understand you perform checkpoint with a signal handler. Right ? This approach has a huge benefit: the signal handling code do all the arch dependant stuff to save registers in user memory.
Signature · 6 lines
Gregory Kurz gkurz-NmTC/[email protected] Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)534 638 479 Fax +33 (0)561 400 420 "Anarchy is about taking complete responsibility for yourself." Alan Moore.
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Louis RillingQuoted 10 lines · Louis Rilling
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Louis
I don't know Kerrighed internals but I understand you perform checkpoint with a signal handler. Right ? This approach has a huge benefit: the signal handling code do all the arch dependant stuff to save registers in user memory.
Signature · 6 lines
Gregory Kurz [email protected] Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)534 638 479 Fax +33 (0)561 400 420 "Anarchy is about taking complete responsibility for yourself." Alan Moore.
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Louis RillingQuoted 52 lines · On Wednesday 22 October 2008 13:25 Louis Rilling wrote:
Quoted 43 lines · Andrey Mirkin
Quoted 42 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
Quoted 7 lines
Quoted 1 line
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.
Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec.
Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 9 lines · Greg Kurz
Quoted 8 lines · Louis Rilling
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
Quoted 5 lines
Quoted 2 lines
Louis
I don't know Kerrighed internals but I understand you perform checkpoint with a signal handler. Right ?
Right. This is an kernel-internal-only signal, so all signals remain available for userspace.
Quoted 3 lines
This approach has a huge benefit: the
signal handling code do all the arch dependant stuff to save registers in user memory.
Hm, I'm not sure to understand what you mean here. We just rely on arch code that jumps to signal handling to correctly setup struct pt_regs, which is then passed to the checkpoint code. So yes, userspace registers are mostly saved by existing arch code. But in x86-64 for instance, segment registers still need to be saved by the checkpoint code (a bit like copy_thread() does), and I don't know arch-independent functions doing this.
Louis
Signature · 4 lines
Dr Louis Rilling Kerlabs Skype: louis.rilling Batiment Germanium Phone: (+33|0) 6 80 89 08 23 80 avenue des Buttes de Coesmes http://www.kerlabs.com/ 35700 Rennes
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Greg KurzQuoted 9 lines · Greg Kurz
Quoted 8 lines · Louis Rilling
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
Quoted 5 lines
Quoted 2 lines
Louis
I don't know Kerrighed internals but I understand you perform checkpoint with a signal handler. Right ?
Right. This is an kernel-internal-only signal, so all signals remain available for userspace.
Quoted 3 lines
This approach has a huge benefit: the
signal handling code do all the arch dependant stuff to save registers in user memory.
Hm, I'm not sure to understand what you mean here. We just rely on arch code that jumps to signal handling to correctly setup struct pt_regs, which is then passed to the checkpoint code. So yes, userspace registers are mostly saved by existing arch code. But in x86-64 for instance, segment registers still need to be saved by the checkpoint code (a bit like copy_thread() does), and I don't know arch-independent functions doing this.
Louis
Signature · 4 lines
Dr Louis Rilling Kerlabs Skype: louis.rilling Batiment Germanium Phone: (+33|0) 6 80 89 08 23 80 avenue des Buttes de Coesmes http://www.kerlabs.com/ 35700 Rennes
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 62 lines · Andrey Mirkin
Quoted 52 lines · On Wednesday 22 October 2008 13:25 Louis Rilling wrote:
Quoted 43 lines · Andrey Mirkin
Quoted 42 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
Quoted 7 lines
Quoted 1 line
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec.
Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
I guess you do that to avoid breaking application that are badly written and do not handle -EINTR correctly with interruptible syscalls. Right?
Louis
Signature · 4 lines
Dr Louis Rilling Kerlabs Skype: louis.rilling Batiment Germanium Phone: (+33|0) 6 80 89 08 23 80 avenue des Buttes de Coesmes http://www.kerlabs.com/ 35700 Rennes
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Andrey MirkinQuoted 62 lines · Andrey Mirkin
Quoted 52 lines · On Wednesday 22 October 2008 13:25 Louis Rilling wrote:
Quoted 43 lines · Andrey Mirkin
Quoted 42 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
Quoted 7 lines
Quoted 1 line
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec.
Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
I guess you do that to avoid breaking application that are badly written and do not handle -EINTR correctly with interruptible syscalls. Right?
Louis
Signature · 4 lines
Dr Louis Rilling Kerlabs Skype: louis.rilling Batiment Germanium Phone: (+33|0) 6 80 89 08 23 80 avenue des Buttes de Coesmes http://www.kerlabs.com/ 35700 Rennes
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 23 lines · Louis Rilling
Quoted 9 lines · Greg Kurz
Quoted 8 lines · Louis Rilling
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Quoted 5 lines
Quoted 2 lines
Louis
I don't know Kerrighed internals but I understand you perform checkpoint with a signal handler. Right ?
Right. This is an kernel-internal-only signal, so all signals remain available for userspace.
Quoted 3 lines
This approach has a huge benefit: the
signal handling code do all the arch dependant stuff to save registers in user memory.
Quoted 7 lines
Hm, I'm not sure to understand what you mean here. We just rely on arch code that jumps to signal handling to correctly setup struct
pt_regs, which is then passed to the checkpoint code. So yes, userspace registers are mostly saved by existing arch code. But in x86-64 for instance, segment registers still need to be saved by the checkpoint code (a bit likecopy_thread()does), and I don't know arch-independent functions doing this.
You're right, some segment registers need to be saved on x86 also... I should have written 'most of' in my previous mail.
Signature · 6 lines
Gregory Kurz gkurz-NmTC/[email protected] Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)534 638 479 Fax +33 (0)561 400 420 "Anarchy is about taking complete responsibility for yourself." Alan Moore.
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Louis RillingQuoted 23 lines · Louis Rilling
Quoted 9 lines · Greg Kurz
Quoted 8 lines · Louis Rilling
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Quoted 5 lines
Quoted 2 lines
Louis
I don't know Kerrighed internals but I understand you perform checkpoint with a signal handler. Right ?
Right. This is an kernel-internal-only signal, so all signals remain available for userspace.
Quoted 3 lines
This approach has a huge benefit: the
signal handling code do all the arch dependant stuff to save registers in user memory.
Quoted 7 lines
Hm, I'm not sure to understand what you mean here. We just rely on arch code that jumps to signal handling to correctly setup struct
pt_regs, which is then passed to the checkpoint code. So yes, userspace registers are mostly saved by existing arch code. But in x86-64 for instance, segment registers still need to be saved by the checkpoint code (a bit likecopy_thread()does), and I don't know arch-independent functions doing this.
You're right, some segment registers need to be saved on x86 also... I should have written 'most of' in my previous mail.
Signature · 6 lines
Gregory Kurz [email protected] Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)534 638 479 Fax +33 (0)561 400 420 "Anarchy is about taking complete responsibility for yourself." Alan Moore.
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 23 lines
Quoted 23 lines
Quoted 9 lines
arch/x86/kernel/entry_32.S +9
-0+ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
Quoted 7 lines
Quoted 1 line
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.
ok. I get it now. why 256 bytes of extra stack ? I'm sure it's not random.
Thanks,
C.
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Andrey MirkinQuoted 23 lines
Quoted 23 lines
Quoted 9 lines
arch/x86/kernel/entry_32.S +9
-0+ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
Quoted 7 lines
Quoted 1 line
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.
ok. I get it now. why 256 bytes of extra stack ? I'm sure it's not random.
Thanks,
C.
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Andrey MirkinQuoted 59 lines · Andrey Mirkin
Quoted 49 lines · On Wednesday 22 October 2008 13:25 Louis Rilling wrote:
Quoted 40 lines · Andrey Mirkin
Quoted 39 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
Quoted 8 lines
Quoted 3 lines
call *%eax
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec.
Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Can you please elaborate on this ? I don't recall having had issues with that.
Thanks,
Oren.
Quoted 6 lines
Andrey
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [Devel] Re: [PATCH 06/10] Introduce functions to dump mm
In reply to Dave HansenQuoted 41 lines · On Monday 20 October 2008 21:21 Dave Hansen wrote:
Quoted 26 lines · Andrey Mirkin
+static void page_get_desc(struct
vm_area_struct*vma, unsigned long
addr, + structpage_desc*pdesc,cpt_context_t*
ctx) +{checkpoint/cpt_mm.c new file +8
-0+struct mm_struct *mm = vma->vm_mm; +pgd_t *pgd; +pud_t *pud; +pmd_t *pmd; +pte_t *ptep, pte; +spinlock_t *ptl; +struct page *pg =NULL ; + pgoff_t linear_index = (addr - vma->vm_start)/PAGE_SIZE +
vma->vm_pgoff; +checkpoint/cpt_mm.c new file +14
-0+ pdesc->index = linear_index; + pdesc->shared =0 ; + pdesc->mm =CPT_NULL ; + +if (vma->vm_flags &VM_IO ) { + pdesc->type =PD_ABSENT ; +return ; + } + + pgd =pgd_offset (mm, addr); +if (pgd_none (*pgd) ||unlikely (pgd_bad (*pgd))) + goto out_absent; + pud =pud_offset (pgd, addr); +if (pud_none (*pud) ||unlikely (pud_bad (*pud)))checkpoint/cpt_mm.c line 97
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+ goto out_absent; + pmd =pmd_offset (pud, addr); +if (pmd_none (*pmd) ||unlikely (pmd_bad (*pmd))) + goto out_absent; +#ifdef CONFIG_X86 +if (pmd_huge (*pmd)) { +eprintk ("page_huge\n" ); + goto out_unsupported; + } +#endif I take it you know that this breaks with the 1GB (
x86_64) and 16GB (ppc) large pages.
Quoted 1 line
Since you have the VMA, why not use
is_vm_hugetlb_page()?
Right now I'm checking VM_HUGETLB flag on VMAs in dump_one_vma(). This checks were added for sanity purpose just to throw out all unsupported right now cases.
Andrey
Re: [Devel] Re: [PATCH 06/10] Introduce functions to dump mm
In reply to Dave HansenQuoted 41 lines · On Monday 20 October 2008 21:21 Dave Hansen wrote:
Quoted 26 lines · Andrey Mirkin
+static void page_get_desc(struct
vm_area_struct*vma, unsigned long
addr, + structpage_desc*pdesc,cpt_context_t*
ctx) +{checkpoint/cpt_mm.c new file +8
-0+struct mm_struct *mm = vma->vm_mm; +pgd_t *pgd; +pud_t *pud; +pmd_t *pmd; +pte_t *ptep, pte; +spinlock_t *ptl; +struct page *pg =NULL ; + pgoff_t linear_index = (addr - vma->vm_start)/PAGE_SIZE +
vma->vm_pgoff; +checkpoint/cpt_mm.c new file +14
-0+ pdesc->index = linear_index; + pdesc->shared =0 ; + pdesc->mm =CPT_NULL ; + +if (vma->vm_flags &VM_IO ) { + pdesc->type =PD_ABSENT ; +return ; + } + + pgd =pgd_offset (mm, addr); +if (pgd_none (*pgd) ||unlikely (pgd_bad (*pgd))) + goto out_absent; + pud =pud_offset (pgd, addr); +if (pud_none (*pud) ||unlikely (pud_bad (*pud)))checkpoint/cpt_mm.c line 97
Quoted 10 lines
checkpoint/cpt_mm.c new file +10
-0+ goto out_absent; + pmd =pmd_offset (pud, addr); +if (pmd_none (*pmd) ||unlikely (pmd_bad (*pmd))) + goto out_absent; +#ifdef CONFIG_X86 +if (pmd_huge (*pmd)) { +eprintk ("page_huge\n" ); + goto out_unsupported; + } +#endif I take it you know that this breaks with the 1GB (
x86_64) and 16GB (ppc) large pages.
Quoted 1 line
Since you have the VMA, why not use
is_vm_hugetlb_page()?
Right now I'm checking VM_HUGETLB flag on VMAs in dump_one_vma(). This checks were added for sanity purpose just to throw out all unsupported right now cases.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 63 lines · On Wednesday 22 October 2008 14:46 Louis Rilling wrote:
Quoted 62 lines · Andrey Mirkin
Quoted 60 lines · On Wednesday 22 October 2008 13:25 Louis Rilling wrote:
Quoted 43 lines · Andrey Mirkin
Quoted 42 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
(quoted diff) +0
-0
b/arch/x86/kernel/entry_32.Sindex 109792b..a4848a3 100644arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
Quoted 7 lines
Quoted 1 line
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec.
Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
Quoted 6 lines
Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
I guess you do that to avoid breaking application that are badly written and do not handle
-EINTRcorrectly with interruptible syscalls. Right?
Right, also this is needed to restart some syscalls (like pause) from kernel without returning to user space. Let me explain it in more details. There is a gap when process will be in user space just before entering syscall again. At this time a signal can be delivered to process and it even can be handled. So, we will miss a signal which must interrupt pause syscall.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Louis RillingQuoted 63 lines · On Wednesday 22 October 2008 14:46 Louis Rilling wrote:
Quoted 62 lines · Andrey Mirkin
Quoted 60 lines · On Wednesday 22 October 2008 13:25 Louis Rilling wrote:
Quoted 43 lines · Andrey Mirkin
Quoted 42 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
(quoted diff) +0
-0
b/arch/x86/kernel/entry_32.Sindex 109792b..a4848a3 100644arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
Quoted 7 lines
Quoted 1 line
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec.
Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
Quoted 6 lines
Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
I guess you do that to avoid breaking application that are badly written and do not handle
-EINTRcorrectly with interruptible syscalls. Right?
Right, also this is needed to restart some syscalls (like pause) from kernel without returning to user space. Let me explain it in more details. There is a gap when process will be in user space just before entering syscall again. At this time a signal can be delivered to process and it even can be handled. So, we will miss a signal which must interrupt pause syscall.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 63 lines · On Wednesday 22 October 2008 19:25 Oren Laadan wrote:
Quoted 62 lines · Andrey Mirkin
Quoted 60 lines · On Wednesday 22 October 2008 13:25 Louis Rilling wrote:
Quoted 43 lines · Andrey Mirkin
Quoted 42 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
Quoted 7 lines
Quoted 1 line
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec.
Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
Quoted 6 lines
Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Can you please elaborate on this ? I don't recall having had issues with that.
Right now in 2.6.18 kernel we restarts in such a way pause, rt_sigtimedwait and futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Oren LaadanQuoted 63 lines · On Wednesday 22 October 2008 19:25 Oren Laadan wrote:
Quoted 62 lines · Andrey Mirkin
Quoted 60 lines · On Wednesday 22 October 2008 13:25 Louis Rilling wrote:
Quoted 43 lines · Andrey Mirkin
Quoted 42 lines · On Monday 20 October 2008 13:23 Cedric Le Goater wrote:
Hello Andrey !
Quoted 25 lines
arch/x86/kernel/entry_32.S +10
-0@@ -225,6 +225,7 @@ ENTRY(ret_from_fork) GET_THREAD_INFO(%ebp) popl %eax CFI_ADJUST_CFA_OFFSET -4 +ret_from_fork_tail: pushl $0x0202 # Reset kernel eflags CFI_ADJUST_CFA_OFFSET 4 popfl@@ -233,6 +234,26 @@ ENTRY(ret_from_fork) CFI_ENDPROC END(ret_from_fork) +ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
Quoted 7 lines
Quoted 1 line
is it related to the freezer code ?
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec.
Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.
Quoted 6 lines
Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Can you please elaborate on this ? I don't recall having had issues with that.
Right now in 2.6.18 kernel we restarts in such a way pause, rt_sigtimedwait and futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 26 lines · On Wednesday 22 October 2008 16:47 Cedric Le Goater wrote:
Quoted 26 lines
Quoted 25 lines
Quoted 9 lines
arch/x86/kernel/entry_32.S +9
-0+ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
is it related to the freezer code ?
Quoted 7 lines
Quoted 5 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.ok. I get it now. why 256 bytes of extra stack ? I'm sure it's not random.
We are putting special structure on stack, which is used at the very end of the whole restart procedure to restore complex states (ptrace is one of such cases). Right now I don't need to use this structure as we have a deal with simple cases, but reservation of 256 bytes on stack is needed for future.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Cedric Le GoaterQuoted 26 lines · On Wednesday 22 October 2008 16:47 Cedric Le Goater wrote:
Quoted 26 lines
Quoted 25 lines
Quoted 9 lines
arch/x86/kernel/entry_32.S +9
-0+ENTRY(i386_ret_from_resume) + CFI_STARTPROC + pushl %eax + CFI_ADJUST_CFA_OFFSET 4 + call schedule_tail + GET_THREAD_INFO(%ebp) + popl %eax + CFI_ADJUST_CFA_OFFSET -4 + movl (%esp), %eaxarch/x86/kernel/entry_32.S ENTRY(ret_from_fork) · line 255
Quoted 10 lines
arch/x86/kernel/entry_32.S +10
-0+ testl %eax, %eax + jz 1f + pushl %esp + call *%eax + addl $4, %esp +1: + addl $256, %esp + jmp ret_from_fork_tail + CFI_ENDPROC +END(i386_ret_from_resume)Could you explain why you need to do this
call *%eax
is it related to the freezer code ?
Quoted 7 lines
Quoted 5 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.ok. I get it now. why 256 bytes of extra stack ? I'm sure it's not random.
We are putting special structure on stack, which is used at the very end of the whole restart procedure to restore complex states (ptrace is one of such cases). Right now I don't need to use this structure as we have a deal with simple cases, but reservation of 256 bytes on stack is needed for future.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Louis RillingQuoted 250 lines · On Monday 20 October 2008 17:25 Louis Rilling wrote:
Quoted 2 lines · Andrey Mirkin
Functions to restart process, restore its state, fpu and registers are added.
[...]
Quoted 238 lines
checkpoint/rst_process.c new file +31
-0@@ -0,0 +1,277 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Author: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/fs.h> +#include <linux/file.h> +#include <linux/version.h> +#include <linux/module.h> + +#include "checkpoint.h" +#include "cpt_image.h" + +#define HOOK_RESERVE 256 + +struct thr_context { +struct completion complete; +int error; +struct cpt_context *ctx; +struct task_struct *tsk; +}; + +int local_kernel_thread(int (*fn)(void *), void * arg, unsigned longflags,
pid_tpid) +{checkpoint/rst_process.c new file +35
-0+pid_t ret; + +if (current->fs ==NULL ) { +/* do_fork_pid() hates processes without fs, oopses. */ +eprintk ("local_kernel_thread: current->fs==NULL\n" ); +return -EINVAL ; + } +if (!try_module_get (THIS_MODULE )) +return -EBUSY ; + ret =kernel_thread (fn, arg, flags); +if (ret <0 ) +module_put (THIS_MODULE ); +return ret; +} + +static unsigned int decode_task_flags (unsigned int task_flags) +{ +unsigned int flags =0 ; + +if (task_flags & (1 <<CPT_PF_EXITING )) + flags |=PF_EXITING ; +if (task_flags & (1 <<CPT_PF_FORKNOEXEC )) + flags |=PF_FORKNOEXEC ; +if (task_flags & (1 <<CPT_PF_SUPERPRIV )) + flags |=PF_SUPERPRIV ; +if (task_flags & (1 <<CPT_PF_DUMPCORE )) + flags |=PF_DUMPCORE ; +if (task_flags & (1 <<CPT_PF_SIGNALED )) + flags |=PF_SIGNALED ; + +return flags; + +} + +int rst_restore_task_struct(struct task_struct *tsk, struct
cpt_task_image*ti, + structcpt_context*ctx)checkpoint/rst_process.c new file +16
-0+{ +int i; + +/* Restore only saved flags, comm and tls for now */ + tsk->flags =decode_task_flags (ti->cpt_flags); +clear_tsk_thread_flag (tsk,TIF_FREEZE ); +memcpy (tsk->comm, ti->cpt_comm,TASK_COMM_LEN ); +for (i =0 ; i <GDT_ENTRY_TLS_ENTRIES ; i++) { + tsk->thread.tls_array[i].a = ti->cpt_tls[i] &0xFFFFFFFF ; + tsk->thread.tls_array[i].b = ti->cpt_tls[i] >>32 ; + } + +return 0 ; +} + +static int rst_restore_fpustate(struct task_struct *tsk, struct
cpt_task_image*ti, + structcpt_context*ctx)checkpoint/rst_process.c new file +64
-0+{ +struct cpt_obj_bits hdr; +int err; +char *buf; + +clear_stopped_child_used_math (tsk); + + err =rst_get_object (CPT_OBJ_BITS , &hdr,sizeof (hdr), ctx); +if (err <0 ) +return err; + + buf =kmalloc (hdr.cpt_size,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + + err = ctx->read (buf, hdr.cpt_size, ctx); +if (err) + goto out; + +if (hdr.cpt_content ==CPT_CONTENT_X86_FPUSTATE && cpu_has_fxsr) { +memcpy (&tsk->thread.xstate, buf, +sizeof (struct i387_fxsave_struct )); +if (ti->cpt_flags &CPT_PF_USED_MATH ) +set_stopped_child_used_math (tsk); + } +#ifndef CONFIG_X86_64 + else if (hdr.cpt_content == CPT_CONTENT_X86_FPUSTATE_OLD && + !cpu_has_fxsr) { +memcpy (&tsk->thread.xstate, buf, +sizeof (struct i387_fsave_struct )); +if (ti->cpt_flags &CPT_PF_USED_MATH ) +set_stopped_child_used_math (tsk); + } +#endif + +out: +kfree (buf); +return err; +} + +static u32 decode_segment (u32 segid) +{ +if (segid ==CPT_SEG_ZERO ) +return 0 ; + +/* TLS descriptors */ +if (segid <=CPT_SEG_TLS3 ) +return ((GDT_ENTRY_TLS_MIN + segid -CPT_SEG_TLS1 ) <<3 ) +3 ; + +/* LDT descriptor, it is just an index to LDT array */ +if (segid >=CPT_SEG_LDT ) +return ((segid -CPT_SEG_LDT ) <<3 ) |7 ; + +/* Check for one of standard descriptors */ +if (segid ==CPT_SEG_USER32_DS ) +return __USER_DS; +if (segid ==CPT_SEG_USER32_CS ) +return __USER_CS; + +eprintk ("Invalid segment reg %d\n" , segid); +return 0 ; +} + +static int rst_restore_registers(struct task_struct *tsk, struct
cpt_context*ctx) +{checkpoint/rst_process.c new file +81
-0+struct cpt_x86_regs ri; +struct pt_regs *regs =task_pt_regs (tsk); +extern char i386_ret_from_resume; +int err; + + err =rst_get_object (CPT_OBJ_X86_REGS , &ri,sizeof (ri), ctx); +if (err <0 ) +return err; + + tsk->thread.sp = (unsigned long ) regs; + tsk->thread.sp0 = (unsigned long ) (regs+1 ); + tsk->thread.ip = (unsigned long ) &i386_ret_from_resume; + + tsk->thread.gs =decode_segment (ri.cpt_gs); + tsk->thread.debugreg0 = ri.cpt_debugreg[0 ]; + tsk->thread.debugreg1 = ri.cpt_debugreg[1 ]; + tsk->thread.debugreg2 = ri.cpt_debugreg[2 ]; + tsk->thread.debugreg3 = ri.cpt_debugreg[3 ]; + tsk->thread.debugreg6 = ri.cpt_debugreg[6 ]; + tsk->thread.debugreg7 = ri.cpt_debugreg[7 ]; + + regs->bx = ri.cpt_bx; + regs->cx = ri.cpt_cx; + regs->dx = ri.cpt_dx; + regs->si = ri.cpt_si; + regs->di = ri.cpt_di; + regs->bp = ri.cpt_bp; + regs->ax = ri.cpt_ax; + regs->orig_ax = ri.cpt_orig_ax; + regs->ip = ri.cpt_ip; + regs->flags = ri.cpt_flags; + regs->sp = ri.cpt_sp; + + regs->cs =decode_segment (ri.cpt_cs); + regs->ss =decode_segment (ri.cpt_ss); + regs->ds =decode_segment (ri.cpt_ds); + regs->es =decode_segment (ri.cpt_es); + regs->fs =decode_segment (ri.cpt_fs); + + tsk->thread.sp -=HOOK_RESERVE ; +memset ((void *)tsk->thread.sp,0 ,HOOK_RESERVE ); + +return 0 ; +} + +static int restart_thread (void *arg) +{ +struct thr_context *thr_ctx = arg; +struct cpt_context *ctx; +struct cpt_task_image *ti; +int err; + + current->state =TASK_UNINTERRUPTIBLE ; + + ctx = thr_ctx->ctx; + ti =kmalloc (sizeof (*ti),GFP_KERNEL ); +if (!ti) +return -ENOMEM ; + + err =rst_get_object (CPT_OBJ_TASK , ti,sizeof (*ti), ctx); +if (!err) + err =rst_restore_task_struct (current, ti, ctx); +/* Restore mm here */ +if (!err) + err =rst_restore_fpustate (current, ti, ctx); +if (!err) + err =rst_restore_registers (current, ctx); + + thr_ctx->error = err; +complete (&thr_ctx->complete); + +if (!err && (ti->cpt_state & (EXIT_ZOMBIE |EXIT_DEAD ))) { +do_exit (ti->cpt_exit_code); + }else { +__set_current_state (TASK_UNINTERRUPTIBLE ); + } + +kfree (ti); +schedule (); + + eprintk("leaked %d/%d %p\n", task_pid_nr(current),
task_pid_vnr(current),current->mm); +checkpoint/rst_process.c
Quoted 1 line
checkpoint/rst_process.c new file +1
-0+module_put (THIS_MODULE );I'm sorry, I still do not understand what you are doing with this self-module pinning stuff. AFAICS, we should not get here unless there is a bug. So the checkpoint module ref count is never decreased, right?
Quoted 3 lines
Could you detail what is this self-module pinning for? As I already told you, this looks like a bogus solution to avoid unloading the checkpoint module during restart.
Actually right now module ref count increase/decrease is not needed. But in some cases restore work should be done only after unfreezing the process. So, in this case we should grab ref count during process creation and put it after this special work is done.
I will rework this place and send it in next version to make it more clear how it will be used in future.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 250 lines · On Monday 20 October 2008 17:25 Louis Rilling wrote:
Quoted 2 lines · Andrey Mirkin
Functions to restart process, restore its state, fpu and registers are added.
[...]
Quoted 238 lines
checkpoint/rst_process.c new file +31
-0@@ -0,0 +1,277 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Author: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/fs.h> +#include <linux/file.h> +#include <linux/version.h> +#include <linux/module.h> + +#include "checkpoint.h" +#include "cpt_image.h" + +#define HOOK_RESERVE 256 + +struct thr_context { +struct completion complete; +int error; +struct cpt_context *ctx; +struct task_struct *tsk; +}; + +int local_kernel_thread(int (*fn)(void *), void * arg, unsigned longflags,
pid_tpid) +{checkpoint/rst_process.c new file +35
-0+pid_t ret; + +if (current->fs ==NULL ) { +/* do_fork_pid() hates processes without fs, oopses. */ +eprintk ("local_kernel_thread: current->fs==NULL\n" ); +return -EINVAL ; + } +if (!try_module_get (THIS_MODULE )) +return -EBUSY ; + ret =kernel_thread (fn, arg, flags); +if (ret <0 ) +module_put (THIS_MODULE ); +return ret; +} + +static unsigned int decode_task_flags (unsigned int task_flags) +{ +unsigned int flags =0 ; + +if (task_flags & (1 <<CPT_PF_EXITING )) + flags |=PF_EXITING ; +if (task_flags & (1 <<CPT_PF_FORKNOEXEC )) + flags |=PF_FORKNOEXEC ; +if (task_flags & (1 <<CPT_PF_SUPERPRIV )) + flags |=PF_SUPERPRIV ; +if (task_flags & (1 <<CPT_PF_DUMPCORE )) + flags |=PF_DUMPCORE ; +if (task_flags & (1 <<CPT_PF_SIGNALED )) + flags |=PF_SIGNALED ; + +return flags; + +} + +int rst_restore_task_struct(struct task_struct *tsk, struct
cpt_task_image*ti, + structcpt_context*ctx)checkpoint/rst_process.c new file +16
-0+{ +int i; + +/* Restore only saved flags, comm and tls for now */ + tsk->flags =decode_task_flags (ti->cpt_flags); +clear_tsk_thread_flag (tsk,TIF_FREEZE ); +memcpy (tsk->comm, ti->cpt_comm,TASK_COMM_LEN ); +for (i =0 ; i <GDT_ENTRY_TLS_ENTRIES ; i++) { + tsk->thread.tls_array[i].a = ti->cpt_tls[i] &0xFFFFFFFF ; + tsk->thread.tls_array[i].b = ti->cpt_tls[i] >>32 ; + } + +return 0 ; +} + +static int rst_restore_fpustate(struct task_struct *tsk, struct
cpt_task_image*ti, + structcpt_context*ctx)checkpoint/rst_process.c new file +64
-0+{ +struct cpt_obj_bits hdr; +int err; +char *buf; + +clear_stopped_child_used_math (tsk); + + err =rst_get_object (CPT_OBJ_BITS , &hdr,sizeof (hdr), ctx); +if (err <0 ) +return err; + + buf =kmalloc (hdr.cpt_size,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + + err = ctx->read (buf, hdr.cpt_size, ctx); +if (err) + goto out; + +if (hdr.cpt_content ==CPT_CONTENT_X86_FPUSTATE && cpu_has_fxsr) { +memcpy (&tsk->thread.xstate, buf, +sizeof (struct i387_fxsave_struct )); +if (ti->cpt_flags &CPT_PF_USED_MATH ) +set_stopped_child_used_math (tsk); + } +#ifndef CONFIG_X86_64 + else if (hdr.cpt_content == CPT_CONTENT_X86_FPUSTATE_OLD && + !cpu_has_fxsr) { +memcpy (&tsk->thread.xstate, buf, +sizeof (struct i387_fsave_struct )); +if (ti->cpt_flags &CPT_PF_USED_MATH ) +set_stopped_child_used_math (tsk); + } +#endif + +out: +kfree (buf); +return err; +} + +static u32 decode_segment (u32 segid) +{ +if (segid ==CPT_SEG_ZERO ) +return 0 ; + +/* TLS descriptors */ +if (segid <=CPT_SEG_TLS3 ) +return ((GDT_ENTRY_TLS_MIN + segid -CPT_SEG_TLS1 ) <<3 ) +3 ; + +/* LDT descriptor, it is just an index to LDT array */ +if (segid >=CPT_SEG_LDT ) +return ((segid -CPT_SEG_LDT ) <<3 ) |7 ; + +/* Check for one of standard descriptors */ +if (segid ==CPT_SEG_USER32_DS ) +return __USER_DS; +if (segid ==CPT_SEG_USER32_CS ) +return __USER_CS; + +eprintk ("Invalid segment reg %d\n" , segid); +return 0 ; +} + +static int rst_restore_registers(struct task_struct *tsk, struct
cpt_context*ctx) +{checkpoint/rst_process.c new file +81
-0+struct cpt_x86_regs ri; +struct pt_regs *regs =task_pt_regs (tsk); +extern char i386_ret_from_resume; +int err; + + err =rst_get_object (CPT_OBJ_X86_REGS , &ri,sizeof (ri), ctx); +if (err <0 ) +return err; + + tsk->thread.sp = (unsigned long ) regs; + tsk->thread.sp0 = (unsigned long ) (regs+1 ); + tsk->thread.ip = (unsigned long ) &i386_ret_from_resume; + + tsk->thread.gs =decode_segment (ri.cpt_gs); + tsk->thread.debugreg0 = ri.cpt_debugreg[0 ]; + tsk->thread.debugreg1 = ri.cpt_debugreg[1 ]; + tsk->thread.debugreg2 = ri.cpt_debugreg[2 ]; + tsk->thread.debugreg3 = ri.cpt_debugreg[3 ]; + tsk->thread.debugreg6 = ri.cpt_debugreg[6 ]; + tsk->thread.debugreg7 = ri.cpt_debugreg[7 ]; + + regs->bx = ri.cpt_bx; + regs->cx = ri.cpt_cx; + regs->dx = ri.cpt_dx; + regs->si = ri.cpt_si; + regs->di = ri.cpt_di; + regs->bp = ri.cpt_bp; + regs->ax = ri.cpt_ax; + regs->orig_ax = ri.cpt_orig_ax; + regs->ip = ri.cpt_ip; + regs->flags = ri.cpt_flags; + regs->sp = ri.cpt_sp; + + regs->cs =decode_segment (ri.cpt_cs); + regs->ss =decode_segment (ri.cpt_ss); + regs->ds =decode_segment (ri.cpt_ds); + regs->es =decode_segment (ri.cpt_es); + regs->fs =decode_segment (ri.cpt_fs); + + tsk->thread.sp -=HOOK_RESERVE ; +memset ((void *)tsk->thread.sp,0 ,HOOK_RESERVE ); + +return 0 ; +} + +static int restart_thread (void *arg) +{ +struct thr_context *thr_ctx = arg; +struct cpt_context *ctx; +struct cpt_task_image *ti; +int err; + + current->state =TASK_UNINTERRUPTIBLE ; + + ctx = thr_ctx->ctx; + ti =kmalloc (sizeof (*ti),GFP_KERNEL ); +if (!ti) +return -ENOMEM ; + + err =rst_get_object (CPT_OBJ_TASK , ti,sizeof (*ti), ctx); +if (!err) + err =rst_restore_task_struct (current, ti, ctx); +/* Restore mm here */ +if (!err) + err =rst_restore_fpustate (current, ti, ctx); +if (!err) + err =rst_restore_registers (current, ctx); + + thr_ctx->error = err; +complete (&thr_ctx->complete); + +if (!err && (ti->cpt_state & (EXIT_ZOMBIE |EXIT_DEAD ))) { +do_exit (ti->cpt_exit_code); + }else { +__set_current_state (TASK_UNINTERRUPTIBLE ); + } + +kfree (ti); +schedule (); + + eprintk("leaked %d/%d %p\n", task_pid_nr(current),
task_pid_vnr(current),current->mm); +checkpoint/rst_process.c
Quoted 1 line
checkpoint/rst_process.c new file +1
-0+module_put (THIS_MODULE );I'm sorry, I still do not understand what you are doing with this self-module pinning stuff. AFAICS, we should not get here unless there is a bug. So the checkpoint module ref count is never decreased, right?
Quoted 3 lines
Could you detail what is this self-module pinning for? As I already told you, this looks like a bogus solution to avoid unloading the checkpoint module during restart.
Actually right now module ref count increase/decrease is not needed. But in some cases restore work should be done only after unfreezing the process. So, in this case we should grab ref count during process creation and put it after this special work is done.
I will rework this place and send it in next version to make it more clear how it will be used in future.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 4 lines · Andrey Mirkin
We are putting special structure on stack, which is used at the very end of the whole restart procedure to restore complex states (ptrace is one of such cases). Right now I don't need to use this structure as we have a deal with simple cases, but reservation of 256 bytes on stack is needed for future.
Wow. So you're saying that, if this patch is accepted, we simply need to accept that anything being checkpointed will use an extra 256 bytes of stack? Seems like something to perhaps put in the changelog rather than some completely undocumented assembly nugget.
-- Dave
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Andrey MirkinQuoted 4 lines · Andrey Mirkin
We are putting special structure on stack, which is used at the very end of the whole restart procedure to restore complex states (ptrace is one of such cases). Right now I don't need to use this structure as we have a deal with simple cases, but reservation of 256 bytes on stack is needed for future.
Wow. So you're saying that, if this patch is accepted, we simply need to accept that anything being checkpointed will use an extra 256 bytes of stack? Seems like something to perhaps put in the changelog rather than some completely undocumented assembly nugget.
-- Dave
Re: [Devel] Re: [PATCH 06/10] Introduce functions to dump mm
In reply to a message not in the archiveQuoted 10 lines · Andrey Mirkin
Quoted 10 lines
checkpoint/cpt_mm.c line 97
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+#ifdef CONFIG_X86 +if (pmd_huge (*pmd)) { +eprintk ("page_huge\n" ); + goto out_unsupported; + } +#endif I take it you know that this breaks with the 1GB (
x86_64) and 16GB (ppc) large pages.
Quoted 4 lines
Quoted 1 line
Since you have the VMA, why not use
is_vm_hugetlb_page()?Right now I'm checking
VM_HUGETLBflag on VMAs indump_one_vma(). This checks were added for sanity purpose just to throw out all unsupported right now cases.
I'm telling you that it's no good. Not only should this path never be hit. But, if it is, you'll crash anyway in some cases.
It's a bad check. At best it misleads the reader to think that you've covered your bases.
-- Dave
Re: [Devel] Re: [PATCH 06/10] Introduce functions to dump mm
In reply to Andrey MirkinQuoted 10 lines · Andrey Mirkin
Quoted 10 lines
checkpoint/cpt_mm.c line 97
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+#ifdef CONFIG_X86 +if (pmd_huge (*pmd)) { +eprintk ("page_huge\n" ); + goto out_unsupported; + } +#endif I take it you know that this breaks with the 1GB (
x86_64) and 16GB (ppc) large pages.
Quoted 4 lines
Quoted 1 line
Since you have the VMA, why not use
is_vm_hugetlb_page()?Right now I'm checking
VM_HUGETLBflag on VMAs indump_one_vma(). This checks were added for sanity purpose just to throw out all unsupported right now cases.
I'm telling you that it's no good. Not only should this path never be hit. But, if it is, you'll crash anyway in some cases.
It's a bad check. At best it misleads the reader to think that you've covered your bases.
-- Dave
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 20 lines · Andrey Mirkin
Quoted 20 lines
Quoted 19 lines
Quoted 7 lines
Quoted 6 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec.
Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Quoted 6 lines
Quoted 2 lines
Can you please elaborate on this ? I don't recall having had issues with that.
Right now in 2.6.18 kernel we restarts in such a way pause,
rt_sigtimedwaitand futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.
Could you elaborate on this a bit?
If the futex syscall was reworked, perhaps we can do the same for rt_sigtimedwait() and get rid of this code completely.
-- Dave
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Andrey MirkinQuoted 20 lines · Andrey Mirkin
Quoted 20 lines
Quoted 19 lines
Quoted 7 lines
Quoted 6 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec.
Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Quoted 6 lines
Quoted 2 lines
Can you please elaborate on this ? I don't recall having had issues with that.
Right now in 2.6.18 kernel we restarts in such a way pause,
rt_sigtimedwaitand futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.
Could you elaborate on this a bit?
If the futex syscall was reworked, perhaps we can do the same for rt_sigtimedwait() and get rid of this code completely.
-- Dave
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
Quoted 23 lines · On Thursday 23 October 2008 17:57 Dave Hansen wrote:
Quoted 22 lines · Andrey Mirkin
Quoted 21 lines
Quoted 15 lines
Quoted 6 lines
Quoted 5 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Can you please elaborate on this ? I don't recall having had issues with that.
Quoted 8 lines
Quoted 3 lines
Right now in 2.6.18 kernel we restarts in such a way pause,
rt_sigtimedwaitand futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.Could you elaborate on this a bit?
If the futex syscall was reworked, perhaps we can do the same for
rt_sigtimedwait()and get rid of this code completely.
Well, we can try to rework rt_sigtimedwait(), but we will still need this code in the future to restart pause syscall from kernel without returning to user space. Also this code will be needed to restore some complex states. As concerns pause syscall I have already written to Louis about the problem we are trying to solve with this code. There is a gap when process will be in user space just before entering syscall again. At this time a signal can be delivered to process and it even can be handled. So, we will miss a signal which must interrupt pause syscall.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Dave HansenQuoted 23 lines · On Thursday 23 October 2008 17:57 Dave Hansen wrote:
Quoted 22 lines · Andrey Mirkin
Quoted 21 lines
Quoted 15 lines
Quoted 6 lines
Quoted 5 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Can you please elaborate on this ? I don't recall having had issues with that.
Quoted 8 lines
Quoted 3 lines
Right now in 2.6.18 kernel we restarts in such a way pause,
rt_sigtimedwaitand futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.Could you elaborate on this a bit?
If the futex syscall was reworked, perhaps we can do the same for
rt_sigtimedwait()and get rid of this code completely.
Well, we can try to rework rt_sigtimedwait(), but we will still need this code in the future to restart pause syscall from kernel without returning to user space. Also this code will be needed to restore some complex states. As concerns pause syscall I have already written to Louis about the problem we are trying to solve with this code. There is a gap when process will be in user space just before entering syscall again. At this time a signal can be delivered to process and it even can be handled. So, we will miss a signal which must interrupt pause syscall.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Dave HansenQuoted 11 lines · On Thursday 23 October 2008 17:49 Dave Hansen wrote:
Quoted 5 lines · Andrey Mirkin
We are putting special structure on stack, which is used at the very end of the whole restart procedure to restore complex states (ptrace is one of such cases). Right now I don't need to use this structure as we have a deal with simple cases, but reservation of 256 bytes on stack is needed for future.
Wow. So you're saying that, if this patch is accepted, we simply need to accept that anything being checkpointed will use an extra 256 bytes of stack? Seems like something to perhaps put in the changelog rather than some completely undocumented assembly nugget.
This 256 bytes will be used only during restart procedure and only by our module. As you can see in i386_ret_from_resume we are restoring it back. So, when process will return to user space it will not have extra 256 bytes reserved on stack already. I will add information about it to documentation and changelog.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Dave HansenQuoted 11 lines · On Thursday 23 October 2008 17:49 Dave Hansen wrote:
Quoted 5 lines · Andrey Mirkin
We are putting special structure on stack, which is used at the very end of the whole restart procedure to restore complex states (ptrace is one of such cases). Right now I don't need to use this structure as we have a deal with simple cases, but reservation of 256 bytes on stack is needed for future.
Wow. So you're saying that, if this patch is accepted, we simply need to accept that anything being checkpointed will use an extra 256 bytes of stack? Seems like something to perhaps put in the changelog rather than some completely undocumented assembly nugget.
This 256 bytes will be used only during restart procedure and only by our module. As you can see in i386_ret_from_resume we are restoring it back. So, when process will return to user space it will not have extra 256 bytes reserved on stack already. I will add information about it to documentation and changelog.
Andrey
Re: [Devel] Re: [PATCH 06/10] Introduce functions to dump mm
In reply to Dave HansenQuoted 17 lines · On Thursday 23 October 2008 17:51 Dave Hansen wrote:
Quoted 10 lines · Andrey Mirkin
Quoted 10 lines
checkpoint/cpt_mm.c line 97
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+#ifdef CONFIG_X86 +if (pmd_huge (*pmd)) { +eprintk ("page_huge\n" ); + goto out_unsupported; + } +#endif I take it you know that this breaks with the 1GB (
x86_64) and 16GB (ppc) large pages.Quoted 5 lines
Quoted 1 line
Since you have the VMA, why not use
is_vm_hugetlb_page()?Right now I'm checking
VM_HUGETLBflag on VMAs indump_one_vma(). This checks were added for sanity purpose just to throw out all unsupported right now cases.
Quoted 5 lines
I'm telling you that it's no good. Not only should this path never be hit. But, if it is, you'll crash anyway in some cases.
It's a bad check. At best it misleads the reader to think that you've covered your bases.
Agree, I will rework this.
Andrey
Re: [Devel] Re: [PATCH 06/10] Introduce functions to dump mm
In reply to Dave HansenQuoted 17 lines · On Thursday 23 October 2008 17:51 Dave Hansen wrote:
Quoted 10 lines · Andrey Mirkin
Quoted 10 lines
checkpoint/cpt_mm.c line 97
Quoted 6 lines
checkpoint/cpt_mm.c new file +6
-0+#ifdef CONFIG_X86 +if (pmd_huge (*pmd)) { +eprintk ("page_huge\n" ); + goto out_unsupported; + } +#endif I take it you know that this breaks with the 1GB (
x86_64) and 16GB (ppc) large pages.Quoted 5 lines
Quoted 1 line
Since you have the VMA, why not use
is_vm_hugetlb_page()?Right now I'm checking
VM_HUGETLBflag on VMAs indump_one_vma(). This checks were added for sanity purpose just to throw out all unsupported right now cases.
Quoted 5 lines
I'm telling you that it's no good. Not only should this path never be hit. But, if it is, you'll crash anyway in some cases.
It's a bad check. At best it misleads the reader to think that you've covered your bases.
Agree, I will rework this.
Andrey
Re: [Devel] Re: [PATCH 05/10] Introduce function to dump process
In reply to Louis RillingQuoted 97 lines · On Monday 20 October 2008 15:02 Louis Rilling wrote:
Hi,
Quoted 2 lines · Andrey Mirkin
Functions to dump task struct, fpu state and registers are added. All IDs are saved from the POV of process (container) namespace.
Just a couple of little comments, in case this series should keep on living.
[...]
Quoted 80 lines
checkpoint/cpt_process.c new file +43
-0@@ -0,0 +1,236 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Author: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/fs.h> +#include <linux/file.h> +#include <linux/version.h> +#include <linux/nsproxy.h> + +#include "checkpoint.h" +#include "cpt_image.h" + +static unsigned int encode_task_flags (unsigned int task_flags) +{ +unsigned int flags =0 ; + +if (task_flags &PF_EXITING ) + flags |= (1 <<CPT_PF_EXITING ); +if (task_flags &PF_FORKNOEXEC ) + flags |= (1 <<CPT_PF_FORKNOEXEC ); +if (task_flags &PF_SUPERPRIV ) + flags |= (1 <<CPT_PF_SUPERPRIV ); +if (task_flags &PF_DUMPCORE ) + flags |= (1 <<CPT_PF_DUMPCORE ); +if (task_flags &PF_SIGNALED ) + flags |= (1 <<CPT_PF_SIGNALED ); +if (task_flags &PF_USED_MATH ) + flags |= (1 <<CPT_PF_USED_MATH ); + +return flags; + +} + +int cpt_dump_task_struct(struct task_struct *tsk, struct cpt_context*ctx) +{
checkpoint/cpt_process.c new file +30
-0+struct cpt_task_image *t; +int i; +int err; + + t =kzalloc (sizeof (*t),GFP_KERNEL ); +if (!t) +return -ENOMEM ; + + t->cpt_len =sizeof (*t); + t->cpt_type =CPT_OBJ_TASK ; + t->cpt_hdrlen =sizeof (*t); + t->cpt_content =CPT_CONTENT_ARRAY ; + + t->cpt_state = tsk->state; + t->cpt_flags =encode_task_flags (tsk->flags); + t->cpt_exit_code = tsk->exit_code; + t->cpt_exit_signal = tsk->exit_signal; + t->cpt_pdeath_signal = tsk->pdeath_signal; + t->cpt_pid =task_pid_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_tgid =task_tgid_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_ppid = tsk->parent ? +task_pid_nr_ns (tsk->parent, ctx->nsproxy->pid_ns) :0 ; + t->cpt_rppid = tsk->real_parent ? +task_pid_nr_ns (tsk->real_parent, ctx->nsproxy->pid_ns) :0 ; + t->cpt_pgrp =task_pgrp_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_session =task_session_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_old_pgrp =0 ; +if (tsk->signal->tty_old_pgrp) + t->cpt_old_pgrp =pid_vnr (tsk->signal->tty_old_pgrp); + t->cpt_leader = tsk->group_leader ? task_pid_vnr(tsk->group_leader) :Quoted 1 line
0;
Why
pid_vnr()here, and task_*_nr_ns() above? According to the introducing comment, I'd expect something likepid_nr_ns(tsk->signal->tty_old_pgrp, tsk->nsproxy->pid_ns), and the same fortsk->group_leader.
Quoted 5 lines
IIUC,
pid_vnr()is correct only ifctx->nsproxy->pid_ns==tsk->nsproxy->pid_ns==current->nsproxy->pid_ns, and I expect current to live in a differentpid_ns.Comments?
Oh, you right here. I have already fixed it in my tree, but accidentally wrong patch were sent.
Quoted 56 lines
Quoted 56 lines
checkpoint/cpt_process.c new file +38
-0+ t->cpt_utime = tsk->utime; + t->cpt_stime = tsk->stime; + t->cpt_utimescaled = tsk->utimescaled; + t->cpt_stimescaled = tsk->stimescaled; + t->cpt_gtime = tsk->gtime; + t->cpt_prev_utime = tsk->prev_utime; + t->cpt_prev_stime = tsk->prev_stime; + t->cpt_nvcsw = tsk->nvcsw; + t->cpt_nivcsw = tsk->nivcsw; + t->cpt_start_time =cpt_timespec_export (&tsk->start_time); + t->cpt_real_start_time =cpt_timespec_export (&tsk->real_start_time); + t->cpt_min_flt = tsk->min_flt; + t->cpt_maj_flt = tsk->maj_flt; +memcpy (t->cpt_comm, tsk->comm,TASK_COMM_LEN ); +for (i =0 ; i <GDT_ENTRY_TLS_ENTRIES ; i++) { + t->cpt_tls[i] = (((u64 )tsk->thread.tls_array[i].b) <<32 ) + + tsk->thread.tls_array[i].a; + } +/* TODO: encode thread flags and status like task flags */ + t->cpt_thrflags =task_thread_info (tsk)->flags & ~(1 <<TIF_FREEZE ); + t->cpt_thrstatus =task_thread_info (tsk)->status; + t->cpt_user = tsk->user->uid; + t->cpt_uid = tsk->uid; + t->cpt_euid = tsk->euid; + t->cpt_suid = tsk->suid; + t->cpt_fsuid = tsk->fsuid; + t->cpt_gid = tsk->gid; + t->cpt_egid = tsk->egid; + t->cpt_sgid = tsk->sgid; + t->cpt_fsgid = tsk->fsgid; + + err = ctx->write (t,sizeof (*t), ctx); + +kfree (t); +return err; +} + +static int cpt_dump_fpustate(struct task_struct *tsk, struct cpt_context*ctx) +{
checkpoint/cpt_process.c new file +16
-0+struct cpt_obj_bits hdr; +int err; +int content; +unsigned long size; + + content =CPT_CONTENT_X86_FPUSTATE ; + size =sizeof (struct i387_fxsave_struct ); +#ifndef CONFIG_X86_64 +if (!cpu_has_fxsr) { + size =sizeof (struct i387_fsave_struct ); + content =CPT_CONTENT_X86_FPUSTATE_OLD ; + } +#endif + + hdr.cpt_len =sizeof (hdr) + size; + hdr.cpt_type =CPT_OBJ_BITS ;
Quoted 8 lines
checkpoint/cpt_process.c line 135
Quoted 6 lines
checkpoint/cpt_process.c new file +6
-0+ hdr.cpt_hdrlen =sizeof (hdr); + hdr.cpt_content = content; + hdr.cpt_size = size; + err = ctx->write (&hdr,sizeof (hdr), ctx); +if (!err) + ctx->write (tsk->thread.xstate, size, ctx);Should check the error code of the line above, right?
Right, thanks!
[...]
Quoted 13 lines
checkpoint/cpt_process.c line 231
Quoted 10 lines
checkpoint/cpt_process.c new file +10
-0+int cpt_dump_task (struct task_struct *tsk,struct cpt_context *ctx) +{ +int err; + + err =cpt_dump_task_struct (tsk, ctx); + +/* Dump task mm */ + +if (!err) +cpt_dump_fpustate (tsk, ctx);error checking...
Quoted 4 lines
checkpoint/cpt_process.c
Quoted 2 lines
checkpoint/cpt_process.c new file +2
-0+if (!err) +cpt_dump_registers (tsk, ctx);error checking...
Thanks again, will fix it.
Andrey
Re: [Devel] Re: [PATCH 05/10] Introduce function to dump process
In reply to a message not in the archiveQuoted 97 lines · On Monday 20 October 2008 15:02 Louis Rilling wrote:
Hi,
Quoted 2 lines · Andrey Mirkin
Functions to dump task struct, fpu state and registers are added. All IDs are saved from the POV of process (container) namespace.
Just a couple of little comments, in case this series should keep on living.
[...]
Quoted 80 lines
checkpoint/cpt_process.c new file +43
-0@@ -0,0 +1,236 @@ +/* +* Copyright (C) 2008 Parallels, Inc. +* +* Author: Andrey Mirkin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#include <linux/sched.h> +#include <linux/fs.h> +#include <linux/file.h> +#include <linux/version.h> +#include <linux/nsproxy.h> + +#include "checkpoint.h" +#include "cpt_image.h" + +static unsigned int encode_task_flags (unsigned int task_flags) +{ +unsigned int flags =0 ; + +if (task_flags &PF_EXITING ) + flags |= (1 <<CPT_PF_EXITING ); +if (task_flags &PF_FORKNOEXEC ) + flags |= (1 <<CPT_PF_FORKNOEXEC ); +if (task_flags &PF_SUPERPRIV ) + flags |= (1 <<CPT_PF_SUPERPRIV ); +if (task_flags &PF_DUMPCORE ) + flags |= (1 <<CPT_PF_DUMPCORE ); +if (task_flags &PF_SIGNALED ) + flags |= (1 <<CPT_PF_SIGNALED ); +if (task_flags &PF_USED_MATH ) + flags |= (1 <<CPT_PF_USED_MATH ); + +return flags; + +} + +int cpt_dump_task_struct(struct task_struct *tsk, struct cpt_context*ctx) +{
checkpoint/cpt_process.c new file +30
-0+struct cpt_task_image *t; +int i; +int err; + + t =kzalloc (sizeof (*t),GFP_KERNEL ); +if (!t) +return -ENOMEM ; + + t->cpt_len =sizeof (*t); + t->cpt_type =CPT_OBJ_TASK ; + t->cpt_hdrlen =sizeof (*t); + t->cpt_content =CPT_CONTENT_ARRAY ; + + t->cpt_state = tsk->state; + t->cpt_flags =encode_task_flags (tsk->flags); + t->cpt_exit_code = tsk->exit_code; + t->cpt_exit_signal = tsk->exit_signal; + t->cpt_pdeath_signal = tsk->pdeath_signal; + t->cpt_pid =task_pid_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_tgid =task_tgid_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_ppid = tsk->parent ? +task_pid_nr_ns (tsk->parent, ctx->nsproxy->pid_ns) :0 ; + t->cpt_rppid = tsk->real_parent ? +task_pid_nr_ns (tsk->real_parent, ctx->nsproxy->pid_ns) :0 ; + t->cpt_pgrp =task_pgrp_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_session =task_session_nr_ns (tsk, ctx->nsproxy->pid_ns); + t->cpt_old_pgrp =0 ; +if (tsk->signal->tty_old_pgrp) + t->cpt_old_pgrp =pid_vnr (tsk->signal->tty_old_pgrp); + t->cpt_leader = tsk->group_leader ? task_pid_vnr(tsk->group_leader) :Quoted 1 line
0;
Why
pid_vnr()here, and task_*_nr_ns() above? According to the introducing comment, I'd expect something likepid_nr_ns(tsk->signal->tty_old_pgrp, tsk->nsproxy->pid_ns), and the same fortsk->group_leader.
Quoted 5 lines
IIUC,
pid_vnr()is correct only ifctx->nsproxy->pid_ns==tsk->nsproxy->pid_ns==current->nsproxy->pid_ns, and I expect current to live in a differentpid_ns.Comments?
Oh, you right here. I have already fixed it in my tree, but accidentally wrong patch were sent.
Quoted 56 lines
Quoted 56 lines
checkpoint/cpt_process.c new file +38
-0+ t->cpt_utime = tsk->utime; + t->cpt_stime = tsk->stime; + t->cpt_utimescaled = tsk->utimescaled; + t->cpt_stimescaled = tsk->stimescaled; + t->cpt_gtime = tsk->gtime; + t->cpt_prev_utime = tsk->prev_utime; + t->cpt_prev_stime = tsk->prev_stime; + t->cpt_nvcsw = tsk->nvcsw; + t->cpt_nivcsw = tsk->nivcsw; + t->cpt_start_time =cpt_timespec_export (&tsk->start_time); + t->cpt_real_start_time =cpt_timespec_export (&tsk->real_start_time); + t->cpt_min_flt = tsk->min_flt; + t->cpt_maj_flt = tsk->maj_flt; +memcpy (t->cpt_comm, tsk->comm,TASK_COMM_LEN ); +for (i =0 ; i <GDT_ENTRY_TLS_ENTRIES ; i++) { + t->cpt_tls[i] = (((u64 )tsk->thread.tls_array[i].b) <<32 ) + + tsk->thread.tls_array[i].a; + } +/* TODO: encode thread flags and status like task flags */ + t->cpt_thrflags =task_thread_info (tsk)->flags & ~(1 <<TIF_FREEZE ); + t->cpt_thrstatus =task_thread_info (tsk)->status; + t->cpt_user = tsk->user->uid; + t->cpt_uid = tsk->uid; + t->cpt_euid = tsk->euid; + t->cpt_suid = tsk->suid; + t->cpt_fsuid = tsk->fsuid; + t->cpt_gid = tsk->gid; + t->cpt_egid = tsk->egid; + t->cpt_sgid = tsk->sgid; + t->cpt_fsgid = tsk->fsgid; + + err = ctx->write (t,sizeof (*t), ctx); + +kfree (t); +return err; +} + +static int cpt_dump_fpustate(struct task_struct *tsk, struct cpt_context*ctx) +{
checkpoint/cpt_process.c new file +16
-0+struct cpt_obj_bits hdr; +int err; +int content; +unsigned long size; + + content =CPT_CONTENT_X86_FPUSTATE ; + size =sizeof (struct i387_fxsave_struct ); +#ifndef CONFIG_X86_64 +if (!cpu_has_fxsr) { + size =sizeof (struct i387_fsave_struct ); + content =CPT_CONTENT_X86_FPUSTATE_OLD ; + } +#endif + + hdr.cpt_len =sizeof (hdr) + size; + hdr.cpt_type =CPT_OBJ_BITS ;
Quoted 8 lines
checkpoint/cpt_process.c line 135
Quoted 6 lines
checkpoint/cpt_process.c new file +6
-0+ hdr.cpt_hdrlen =sizeof (hdr); + hdr.cpt_content = content; + hdr.cpt_size = size; + err = ctx->write (&hdr,sizeof (hdr), ctx); +if (!err) + ctx->write (tsk->thread.xstate, size, ctx);Should check the error code of the line above, right?
Right, thanks!
[...]
Quoted 13 lines
checkpoint/cpt_process.c line 231
Quoted 10 lines
checkpoint/cpt_process.c new file +10
-0+int cpt_dump_task (struct task_struct *tsk,struct cpt_context *ctx) +{ +int err; + + err =cpt_dump_task_struct (tsk, ctx); + +/* Dump task mm */ + +if (!err) +cpt_dump_fpustate (tsk, ctx);error checking...
Quoted 4 lines
checkpoint/cpt_process.c
Quoted 2 lines
checkpoint/cpt_process.c new file +2
-0+if (!err) +cpt_dump_registers (tsk, ctx);error checking...
Thanks again, will fix it.
Andrey
Re: [Devel] Re: [PATCH 05/10] Introduce function to dump process
In reply to Serge E. HallynQuoted 13 lines · On Monday 20 October 2008 21:48 Serge E. Hallyn wrote:
checkpoint/cpt_process.c line 104
Quoted 8 lines · Andrey Mirkin
checkpoint/cpt_process.c new file +8
-0+ t->cpt_uid = tsk->uid; + t->cpt_euid = tsk->euid; + t->cpt_suid = tsk->suid; + t->cpt_fsuid = tsk->fsuid; + t->cpt_gid = tsk->gid; + t->cpt_egid = tsk->egid; + t->cpt_sgid = tsk->sgid; + t->cpt_fsgid = tsk->fsgid;I don't see where any of these are restored. (Obviously, I wanted to think about how you're verifying the restarter's authorization to do so)
Well, right now I don't use them during restore to simplify restart procedure and make it more clear for reviewers. In OpenVZ we are doing all restart procedure with root's privileges and relying on fact that all such IDs will be the same during restart (as we are restarting a container and its file system will be the same during restart).
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 28 lines · Andrey Mirkin
Quoted 19 lines · On Thursday 23 October 2008 17:57 Dave Hansen wrote:
Quoted 18 lines · Andrey Mirkin
Quoted 18 lines
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Can you please elaborate on this ? I don't recall having had issues with that.
Quoted 7 lines
Quoted 3 lines
Right now in 2.6.18 kernel we restarts in such a way pause,
rt_sigtimedwaitand futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.Could you elaborate on this a bit?
If the futex syscall was reworked, perhaps we can do the same for
rt_sigtimedwait()and get rid of this code completely.
Quoted 8 lines
Well, we can try to rework
rt_sigtimedwait(), but we will still need this code in the future to restart pause syscall from kernel without returning to user space. Also this code will be needed to restore some complex states. As concerns pause syscall I have already written to Louis about the problem we are trying to solve with this code. There is a gap when process will be in user space just before entering syscall again. At this time a signal can be delivered to process and it even can be handled. So, we will miss a signal which must interrupt pause syscall.
I'm not convinced that you a real race exists, and even if it does, I'm not convinced that hacking the assembly entry/exit code is the best way to do it.
Let me explain:
You are concerned about a race in which a signal is delivered to a task that resumes from restart to user space and is about to (re)invoke 'pause()' (because the restart so arranged its EIP and registers).
This almost always means that the user code is buggy and relies on specific scheduling, because you can usually find a scheduling (without the C/R) where the intended recipient of the signal was delayed and only calls pause() after the signal is delivered.
For instance, if the sequence of events is:
A calls pause() -> checkpoint -> restart -> B signals A -> A calls pause() (after restart), then the following sequence is possible(*) without C/R: B signals A -> A calls pause()
because normally B cannot assume anything about when A is actually, really, is suspended (which means the programmer did an imperfect job).
I said "almost always" and "usually", because there is one case where the alternative schedule: task B could, prior to sending the signal, "ensure" that task A is already sleeping within the 'pause()' syscall. While this is possible, it is definitely unusual, and in fact I never code that does that. And what if the sysadmin send SIGSTOP followed by SIGCONT ? In short, such code is simply broken.
More importantly, if you think about the operation and semantics of the freezer cgroup - similar behavior is to be expected when you freeze and then thaw a container.
Specifically, when you freeze the container that has a task in sys_pause(), then that task will abort the syscall become frozen. As soon as it becomes unfrozen, it will return to user space (with the EIP "rewinded") only to re-invoke the syscall. So the same "race" remains even if you only freeze and then thaw, regardless of C/R.
Moreover, I argue that basically when you return from a sys_restart(), the entire container should, by default, remain in frozen state - just like it is with sys_checkpoint(). An explicit thaw will make the container resume execution.
Therefore, there are two options: the first is to decide that this behavior
- going back to user space to re-invoke the syscall - is valid. In this case you don't need a special hack for returning from sys_restart(). The second option is to decide that it is broken, in which case you need to also fix the freezer code. Personally, I think that this behavior is valid and need not be fixed.
Finally, even if you do want to fix the behavior for this pathologic case, I don't see why you'd want to do it in this manner. Instead, you can add a simple test prior to returning from sys_restart(), something like this:
...
/* almost done: now handle special cases: */
if (our last syscall == __NR_pause) {
ret = sys_pause();
} else if (our last syscall == __NR_futex) {
do some stuff;
ret = sys_futex();
} else {
ret = what-we-want-to-return
}
/* finally, return to user space */
return ret;
}I'm not quite know what other "complex states" you refer to; but I wonder whether that code "needed to restore some complex states" could not be implemented along the same idea.
The upside is clear: the code is less obscure, simple to debug, and not architecture-dependent. (hehe .. it even runs faster because it saves a whole kernel->user->kernel switch, what do you know !).
Oren.
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Andrey MirkinQuoted 28 lines · Andrey Mirkin
Quoted 19 lines · On Thursday 23 October 2008 17:57 Dave Hansen wrote:
Quoted 18 lines · Andrey Mirkin
Quoted 18 lines
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Can you please elaborate on this ? I don't recall having had issues with that.
Quoted 7 lines
Quoted 3 lines
Right now in 2.6.18 kernel we restarts in such a way pause,
rt_sigtimedwaitand futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.Could you elaborate on this a bit?
If the futex syscall was reworked, perhaps we can do the same for
rt_sigtimedwait()and get rid of this code completely.
Quoted 8 lines
Well, we can try to rework
rt_sigtimedwait(), but we will still need this code in the future to restart pause syscall from kernel without returning to user space. Also this code will be needed to restore some complex states. As concerns pause syscall I have already written to Louis about the problem we are trying to solve with this code. There is a gap when process will be in user space just before entering syscall again. At this time a signal can be delivered to process and it even can be handled. So, we will miss a signal which must interrupt pause syscall.
I'm not convinced that you a real race exists, and even if it does, I'm not convinced that hacking the assembly entry/exit code is the best way to do it.
Let me explain:
You are concerned about a race in which a signal is delivered to a task that resumes from restart to user space and is about to (re)invoke 'pause()' (because the restart so arranged its EIP and registers).
This almost always means that the user code is buggy and relies on specific scheduling, because you can usually find a scheduling (without the C/R) where the intended recipient of the signal was delayed and only calls pause() after the signal is delivered.
For instance, if the sequence of events is:
A calls pause() -> checkpoint -> restart -> B signals A -> A calls pause() (after restart), then the following sequence is possible(*) without C/R: B signals A -> A calls pause()
because normally B cannot assume anything about when A is actually, really, is suspended (which means the programmer did an imperfect job).
I said "almost always" and "usually", because there is one case where the alternative schedule: task B could, prior to sending the signal, "ensure" that task A is already sleeping within the 'pause()' syscall. While this is possible, it is definitely unusual, and in fact I never code that does that. And what if the sysadmin send SIGSTOP followed by SIGCONT ? In short, such code is simply broken.
More importantly, if you think about the operation and semantics of the freezer cgroup - similar behavior is to be expected when you freeze and then thaw a container.
Specifically, when you freeze the container that has a task in sys_pause(), then that task will abort the syscall become frozen. As soon as it becomes unfrozen, it will return to user space (with the EIP "rewinded") only to re-invoke the syscall. So the same "race" remains even if you only freeze and then thaw, regardless of C/R.
Moreover, I argue that basically when you return from a sys_restart(), the entire container should, by default, remain in frozen state - just like it is with sys_checkpoint(). An explicit thaw will make the container resume execution.
Therefore, there are two options: the first is to decide that this behavior
- going back to user space to re-invoke the syscall - is valid. In this case you don't need a special hack for returning from sys_restart(). The second option is to decide that it is broken, in which case you need to also fix the freezer code. Personally, I think that this behavior is valid and need not be fixed.
Finally, even if you do want to fix the behavior for this pathologic case, I don't see why you'd want to do it in this manner. Instead, you can add a simple test prior to returning from sys_restart(), something like this:
...
/* almost done: now handle special cases: */
if (our last syscall == __NR_pause) {
ret = sys_pause();
} else if (our last syscall == __NR_futex) {
do some stuff;
ret = sys_futex();
} else {
ret = what-we-want-to-return
}
/* finally, return to user space */
return ret;
}I'm not quite know what other "complex states" you refer to; but I wonder whether that code "needed to restore some complex states" could not be implemented along the same idea.
The upside is clear: the code is less obscure, simple to debug, and not architecture-dependent. (hehe .. it even runs faster because it saves a whole kernel->user->kernel switch, what do you know !).
Oren.
Re: [PATCH 10/10] Add support for multiple processes
In reply to a message not in the archiveQuoted 34 lines · Andrey Mirkin
The whole tree of processes can be checkpointed and restarted now. Shared objects are not supported yet.
Signed-off-by Andrey Mirkin <[email protected]>--- checkpoint/cpt_image.h | 2 + checkpoint/cpt_process.c | 24 +++++++++++++ checkpoint/rst_process.c | 85 +++++++++++++++++++++++++++------------------- 3 files changed, 76 insertions(+), 35 deletions(-)checkpoint/cpt_image.h +2
-0@@ -128,6 +128,8 @@ struct cpt_task_image {__u64 cpt_nivcsw;__u64 cpt_min_flt;__u64 cpt_maj_flt; +__u32 cpt_children_num; +__u32 cpt_pad; } __attribute__ ((aligned (8)));struct cpt_mm_image {checkpoint/cpt_process.c +3
-0@@ -40,6 +40,19 @@ static unsigned int encode_task_flags(unsigned int task_flags) } +static int cpt_count_children (struct task_struct *tsk,struct cpt_context *ctx) +{ +int num =0 ;
checkpoint/cpt_process.c static unsigned int encode_task_flags(unsigned int task_flags) · line 55
Quoted 10 lines
checkpoint/cpt_process.c +10
-0+struct task_struct *child; + +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + num++; + } +return num; +} +
I noticed that don't take the appropriate locks when browsing through tasks lists (siblings, children, global list). Although I realize that the container should be frozen at this time, I keep wondering if this is indeed always safe.
For instance, are you protected against an OOM killer that might just occur uninvited and kill one of those tasks ?
Can the administrator force an un-freeze of the container ? Or perhaps some error condition if the kernel cause that ?
Quoted 13 lines
checkpoint/cpt_process.c +1
-0int cpt_dump_task_struct (struct task_struct *tsk,struct cpt_context *ctx) {struct cpt_task_image *t;@@ -102,6 +115,7 @@ int cpt_dump_task_struct(struct task_struct *tsk, struct cpt_context *ctx) t->cpt_egid = tsk->egid; t->cpt_sgid = tsk->sgid; t->cpt_fsgid = tsk->fsgid; + t->cpt_children_num =cpt_count_children (tsk, ctx); err = ctx->write (t,sizeof (*t), ctx);@@ -231,6 +245,16 @@ int cpt_dump_task(struct task_struct *tsk, struct cpt_context *ctx) err =cpt_dump_fpustate (tsk, ctx);
checkpoint/cpt_process.c int cpt_dump_task(struct task_struct *tsk, struct cpt_context *ctx) · line 255
Quoted 10 lines
checkpoint/cpt_process.c +8
-0if (!err) err =cpt_dump_registers (tsk, ctx); +if (!err) { +struct task_struct *child; +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + err =cpt_dump_task (child, ctx); +if (err) +break ;
Here too.
[...]
Oren.
Re: [PATCH 10/10] Add support for multiple processes
In reply to Andrey MirkinQuoted 34 lines · Andrey Mirkin
The whole tree of processes can be checkpointed and restarted now. Shared objects are not supported yet.
Signed-off-by Andrey Mirkin <[email protected]>--- checkpoint/cpt_image.h | 2 + checkpoint/cpt_process.c | 24 +++++++++++++ checkpoint/rst_process.c | 85 +++++++++++++++++++++++++++------------------- 3 files changed, 76 insertions(+), 35 deletions(-)checkpoint/cpt_image.h +2
-0@@ -128,6 +128,8 @@ struct cpt_task_image {__u64 cpt_nivcsw;__u64 cpt_min_flt;__u64 cpt_maj_flt; +__u32 cpt_children_num; +__u32 cpt_pad; } __attribute__ ((aligned (8)));struct cpt_mm_image {checkpoint/cpt_process.c +3
-0@@ -40,6 +40,19 @@ static unsigned int encode_task_flags(unsigned int task_flags) } +static int cpt_count_children (struct task_struct *tsk,struct cpt_context *ctx) +{ +int num =0 ;
checkpoint/cpt_process.c static unsigned int encode_task_flags(unsigned int task_flags) · line 55
Quoted 10 lines
checkpoint/cpt_process.c +10
-0+struct task_struct *child; + +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + num++; + } +return num; +} +
I noticed that don't take the appropriate locks when browsing through tasks lists (siblings, children, global list). Although I realize that the container should be frozen at this time, I keep wondering if this is indeed always safe.
For instance, are you protected against an OOM killer that might just occur uninvited and kill one of those tasks ?
Can the administrator force an un-freeze of the container ? Or perhaps some error condition if the kernel cause that ?
Quoted 13 lines
checkpoint/cpt_process.c +1
-0int cpt_dump_task_struct (struct task_struct *tsk,struct cpt_context *ctx) {struct cpt_task_image *t;@@ -102,6 +115,7 @@ int cpt_dump_task_struct(struct task_struct *tsk, struct cpt_context *ctx) t->cpt_egid = tsk->egid; t->cpt_sgid = tsk->sgid; t->cpt_fsgid = tsk->fsgid; + t->cpt_children_num =cpt_count_children (tsk, ctx); err = ctx->write (t,sizeof (*t), ctx);@@ -231,6 +245,16 @@ int cpt_dump_task(struct task_struct *tsk, struct cpt_context *ctx) err =cpt_dump_fpustate (tsk, ctx);
checkpoint/cpt_process.c int cpt_dump_task(struct task_struct *tsk, struct cpt_context *ctx) · line 255
Quoted 10 lines
checkpoint/cpt_process.c +8
-0if (!err) err =cpt_dump_registers (tsk, ctx); +if (!err) { +struct task_struct *child; +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + err =cpt_dump_task (child, ctx); +if (err) +break ;
Here too.
[...]
Oren.
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 43 lines · On Sunday 26 October 2008 01:10 Oren Laadan wrote:
Quoted 33 lines · Andrey Mirkin
Quoted 23 lines · On Thursday 23 October 2008 17:57 Dave Hansen wrote:
Quoted 22 lines · Andrey Mirkin
Quoted 21 lines
Quoted 15 lines
Quoted 6 lines
Quoted 5 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Can you please elaborate on this ? I don't recall having had issues with that.
Quoted 8 lines
Quoted 3 lines
Right now in 2.6.18 kernel we restarts in such a way pause,
rt_sigtimedwaitand futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.Could you elaborate on this a bit?
If the futex syscall was reworked, perhaps we can do the same for
rt_sigtimedwait()and get rid of this code completely.Quoted 8 lines
Well, we can try to rework
rt_sigtimedwait(), but we will still need this code in the future to restart pause syscall from kernel without returning to user space. Also this code will be needed to restore some complex states. As concerns pause syscall I have already written to Louis about the problem we are trying to solve with this code. There is a gap when process will be in user space just before entering syscall again. At this time a signal can be delivered to process and it even can be handled. So, we will miss a signal which must interrupt pause syscall.
Quoted 3 lines
I'm not convinced that you a real race exists, and even if it does, I'm not convinced that hacking the assembly entry/exit code is the best way to do it.
Well, as I already told pause() syscall is is not only one case why we need to do some additional job in that place.
Quoted 11 lines
Let me explain:
You are concerned about a race in which a signal is delivered to a task that resumes from restart to user space and is about to (re)invoke '
pause()' (because the restart so arranged its EIP and registers).This almost always means that the user code is buggy and relies on specific scheduling, because you can usually find a scheduling (without the C/R) where the intended recipient of the signal was delayed and only calls
pause()after the signal is delivered.
Quoted 7 lines
For instance, if the sequence of events is:
A calls pause() -> checkpoint -> restart -> B signals A -> A calls pause() (after restart), then the following sequence is possible(*) without C/R: B signals A -> A calls pause()because normally B cannot assume anything about when A is actually, really, is suspended (which means the programmer did an imperfect job).
You right here. Both sequences are possible in theory. You will be surprised but in practice we found out that probability to miss a signal in case of C/R is much higher then during ordinary execution.
Quoted 11 lines
I said "almost always" and "usually", because there is one case where the alternative schedule: task B could, prior to sending the signal, "ensure" that task A is already sleeping within the '
pause()' syscall. While this is possible, it is definitely unusual, and in fact I never code that does that. And what if the sysadmin send SIGSTOP followed by SIGCONT ? In short, such code is simply broken.More importantly, if you think about the operation and semantics of the freezer cgroup - similar behavior is to be expected when you freeze and then thaw a container.
Quoted 5 lines
Specifically, when you freeze the container that has a task in
sys_pause(), then that task will abort the syscall become frozen. As soon as it becomes unfrozen, it will return to user space (with the EIP "rewinded") only to re-invoke the syscall. So the same "race" remains even if you only freeze and then thaw, regardless of C/R.
Exactly. But during freeze/unfreeze probability to catch such situation is very low. In our tests we were tried to checkpoint/restart LTP tests. And this "race" were triggered during restart almost in 100% of tests.
Quoted 4 lines
Moreover, I argue that basically when you return from a
sys_restart(), the entire container should, by default, remain in frozen state - just like it is withsys_checkpoint(). An explicit thaw will make the container resume execution.
No doubt. That is how we do in OpenVZ, after restart the container remains frozen. And we need to thaw it to resume its execution.
Quoted 6 lines
Therefore, there are two options: the first is to decide that this behavior
- going back to user space to re-invoke the syscall - is valid. In this case you don't need a special hack for returning fromsys_restart(). The second option is to decide that it is broken, in which case you need to also fix the freezer code. Personally, I think that this behavior is valid and need not be fixed.
I still believe that we need to fix such behaviour during restart as in practice it is very easy to trigger it.
Quoted 4 lines
Finally, even if you do want to fix the behavior for this pathologic case, I don't see why you'd want to do it in this manner. Instead, you can add a simple test prior to returning from
sys_restart(), something like this:
Quoted 13 lines
...
/* almost done: now handle special cases: */
if (our last syscall == __NR_pause) {
ret = sys_pause();
} else if (our last syscall == __NR_futex) {
do some stuff;
ret = sys_futex();
} else {
ret = what-we-want-to-return
}
/* finally, return to user space */
return ret;
}This only works if we do not want to stay in frozen state after restart. Or am I missed something?
Quoted 3 lines
I'm not quite know what other "complex states" you refer to; but I wonder whether that code "needed to restore some complex states" could not be implemented along the same idea.
In the same manner we are restoring for instance ptrace.
Quoted 3 lines
The upside is clear: the code is less obscure, simple to debug, and not architecture-dependent. (hehe .. it even runs faster because it saves a whole
kernel->user->kernelswitch, what do you know !).
In our case we also do not need a switch and the code actually not very complicated.
Andrey
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Oren LaadanQuoted 43 lines · On Sunday 26 October 2008 01:10 Oren Laadan wrote:
Quoted 33 lines · Andrey Mirkin
Quoted 23 lines · On Thursday 23 October 2008 17:57 Dave Hansen wrote:
Quoted 22 lines · Andrey Mirkin
Quoted 21 lines
Quoted 15 lines
Quoted 6 lines
Quoted 5 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Can you please elaborate on this ? I don't recall having had issues with that.
Quoted 8 lines
Quoted 3 lines
Right now in 2.6.18 kernel we restarts in such a way pause,
rt_sigtimedwaitand futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.Could you elaborate on this a bit?
If the futex syscall was reworked, perhaps we can do the same for
rt_sigtimedwait()and get rid of this code completely.Quoted 8 lines
Well, we can try to rework
rt_sigtimedwait(), but we will still need this code in the future to restart pause syscall from kernel without returning to user space. Also this code will be needed to restore some complex states. As concerns pause syscall I have already written to Louis about the problem we are trying to solve with this code. There is a gap when process will be in user space just before entering syscall again. At this time a signal can be delivered to process and it even can be handled. So, we will miss a signal which must interrupt pause syscall.
Quoted 3 lines
I'm not convinced that you a real race exists, and even if it does, I'm not convinced that hacking the assembly entry/exit code is the best way to do it.
Well, as I already told pause() syscall is is not only one case why we need to do some additional job in that place.
Quoted 11 lines
Let me explain:
You are concerned about a race in which a signal is delivered to a task that resumes from restart to user space and is about to (re)invoke '
pause()' (because the restart so arranged its EIP and registers).This almost always means that the user code is buggy and relies on specific scheduling, because you can usually find a scheduling (without the C/R) where the intended recipient of the signal was delayed and only calls
pause()after the signal is delivered.
Quoted 7 lines
For instance, if the sequence of events is:
A calls pause() -> checkpoint -> restart -> B signals A -> A calls pause() (after restart), then the following sequence is possible(*) without C/R: B signals A -> A calls pause()because normally B cannot assume anything about when A is actually, really, is suspended (which means the programmer did an imperfect job).
You right here. Both sequences are possible in theory. You will be surprised but in practice we found out that probability to miss a signal in case of C/R is much higher then during ordinary execution.
Quoted 11 lines
I said "almost always" and "usually", because there is one case where the alternative schedule: task B could, prior to sending the signal, "ensure" that task A is already sleeping within the '
pause()' syscall. While this is possible, it is definitely unusual, and in fact I never code that does that. And what if the sysadmin send SIGSTOP followed by SIGCONT ? In short, such code is simply broken.More importantly, if you think about the operation and semantics of the freezer cgroup - similar behavior is to be expected when you freeze and then thaw a container.
Quoted 5 lines
Specifically, when you freeze the container that has a task in
sys_pause(), then that task will abort the syscall become frozen. As soon as it becomes unfrozen, it will return to user space (with the EIP "rewinded") only to re-invoke the syscall. So the same "race" remains even if you only freeze and then thaw, regardless of C/R.
Exactly. But during freeze/unfreeze probability to catch such situation is very low. In our tests we were tried to checkpoint/restart LTP tests. And this "race" were triggered during restart almost in 100% of tests.
Quoted 4 lines
Moreover, I argue that basically when you return from a
sys_restart(), the entire container should, by default, remain in frozen state - just like it is withsys_checkpoint(). An explicit thaw will make the container resume execution.
No doubt. That is how we do in OpenVZ, after restart the container remains frozen. And we need to thaw it to resume its execution.
Quoted 6 lines
Therefore, there are two options: the first is to decide that this behavior
- going back to user space to re-invoke the syscall - is valid. In this case you don't need a special hack for returning fromsys_restart(). The second option is to decide that it is broken, in which case you need to also fix the freezer code. Personally, I think that this behavior is valid and need not be fixed.
I still believe that we need to fix such behaviour during restart as in practice it is very easy to trigger it.
Quoted 4 lines
Finally, even if you do want to fix the behavior for this pathologic case, I don't see why you'd want to do it in this manner. Instead, you can add a simple test prior to returning from
sys_restart(), something like this:
Quoted 13 lines
...
/* almost done: now handle special cases: */
if (our last syscall == __NR_pause) {
ret = sys_pause();
} else if (our last syscall == __NR_futex) {
do some stuff;
ret = sys_futex();
} else {
ret = what-we-want-to-return
}
/* finally, return to user space */
return ret;
}This only works if we do not want to stay in frozen state after restart. Or am I missed something?
Quoted 3 lines
I'm not quite know what other "complex states" you refer to; but I wonder whether that code "needed to restore some complex states" could not be implemented along the same idea.
In the same manner we are restoring for instance ptrace.
Quoted 3 lines
The upside is clear: the code is less obscure, simple to debug, and not architecture-dependent. (hehe .. it even runs faster because it saves a whole
kernel->user->kernelswitch, what do you know !).
In our case we also do not need a switch and the code actually not very complicated.
Andrey
Re: [Devel] Re: [PATCH 03/10] Introduce context structure needed during checkpointing/restart
In reply to Dave HansenQuoted 11 lines · On Monday 20 October 2008 21:02 Dave Hansen wrote:
checkpoint/checkpoint.h struct cpt_operations · line 38
Quoted 8 lines · Andrey Mirkin
checkpoint/checkpoint.h +8
-0+typedef struct cpt_context +{ + pid_t pid; /* should be changed to ctid later */ + int ctx_id; /* context id */ + struct list_head ctx_list; + int refcount; + int ctx_state; + struct semaphore main_sem;Does this really need to be a semaphore or is a mutex OK?
Actually mutex is enough here.
Quoted 5 lines
checkpoint/checkpoint.h struct cpt_operations · line 40
Quoted 1 line
checkpoint/checkpoint.h +1
-0+int errno;Could you hold off on adding these things to the struct until the patch where they're actually used? It's hard to judge this without seeing what you do with it.
I will try not to introduce variables and functions which are not used in future.
Quoted 13 lines
checkpoint/checkpoint.h struct cpt_operations · line 49
Quoted 9 lines
checkpoint/checkpoint.h +8
-0+struct file *file; +loff_t current_object; + +struct list_head object_array[CPT_OBJ_MAX ]; + +int (*write)(const void *addr,size_t count,struct cpt_context *ctx); +int (*read)(void *addr,size_t count,struct cpt_context *ctx); +} cpt_context_t;Man, this is hard to review. I was going to try and make sure that your refcounting was right and atomic, but there's no use of it in this patch except for the initialization and accessor functions. Darn.
For simplicity I will throw out all this stuff completely.
Quoted 5 lines
Quoted 2 lines
+extern int
debug_level;I'm going to go out on a limb here and say that "
debug_level" is probably a wee bit too generic of a variable name.
I will change it to something else.
Quoted 7 lines
checkpoint/checkpoint.h struct cpt_operations · line 56
Quoted 5 lines
checkpoint/checkpoint.h +4
-0+#define cpt_printk(lvl, fmt, args...) do { \ + if (lvl <= debug_level) \ + printk(fmt, ##args); \ + } while (0)I think you can use
pr_debug()here, too, just like Oren did.
Will switch to pr_debug().
Quoted 62 lines
Quoted 62 lines
checkpoint/sys.c +58
-1+struct cpt_context *context_alloc (void ) +{ +struct cpt_context *ctx; +int i; + + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return NULL ; + +init_MUTEX (&ctx->main_sem); + ctx->refcount =1 ; + + ctx->current_object =-1 ; + ctx->write = file_write; + ctx->read = file_read; +for (i =0 ; i <CPT_OBJ_MAX ; i++) { +INIT_LIST_HEAD (&ctx->object_array[i]); + } + +return ctx; +} + +void context_release (struct cpt_context *ctx) +{ + ctx->ctx_state =CPT_CTX_ERROR ; + +kfree (ctx); +} + +static void context_put (struct cpt_context *ctx) +{ +if (!--ctx->refcount) +context_release (ctx); +} +static int checkpoint (pid_t pid,int fd,unsigned long flags) { -return -ENOSYS ; +struct file *file; +struct cpt_context *ctx; +int err; + + err = -EBADF ; + file =fget (fd); +if (!file) + goto out; + + err = -ENOMEM ; + ctx =context_alloc (); +if (!ctx) + goto out_file; + + ctx->file = file; + ctx->ctx_state =CPT_CTX_DUMPING ; + +/* checkpoint */ + err = -ENOSYS ; + +context_put (ctx); + +out_file:
Quoted 8 lines
checkpoint/sys.c line 120
Quoted 4 lines
checkpoint/sys.c +3
-0+fput (file); +out: +return err; }So, where is
context_get()? Is there only single-threaded access to the refcount? If so, why do we even need it? We should probably just usecontext_release()driectly.
The idea is that in future we should be able to keep a context for incremental checkpointing. That is why we need context get/put functions. Right now it is not used, so I will drop it.
Quoted 2 lines
If there is multithreaded access to
context_put()or the refcount, then they're unsafe without additional locking.
Access to refcount will be protected with context mutex.
Thanks for comments.
Actually I'm not sure if I will continue with my own patch set, but I will take into account all your comments during porting my functionality to Oren's tree.
Andrey
Re: [Devel] Re: [PATCH 03/10] Introduce context structure needed during checkpointing/restart
In reply to Dave HansenQuoted 11 lines · On Monday 20 October 2008 21:02 Dave Hansen wrote:
checkpoint/checkpoint.h struct cpt_operations · line 38
Quoted 8 lines · Andrey Mirkin
checkpoint/checkpoint.h +8
-0+typedef struct cpt_context +{ + pid_t pid; /* should be changed to ctid later */ + int ctx_id; /* context id */ + struct list_head ctx_list; + int refcount; + int ctx_state; + struct semaphore main_sem;Does this really need to be a semaphore or is a mutex OK?
Actually mutex is enough here.
Quoted 5 lines
checkpoint/checkpoint.h struct cpt_operations · line 40
Quoted 1 line
checkpoint/checkpoint.h +1
-0+int errno;Could you hold off on adding these things to the struct until the patch where they're actually used? It's hard to judge this without seeing what you do with it.
I will try not to introduce variables and functions which are not used in future.
Quoted 13 lines
checkpoint/checkpoint.h struct cpt_operations · line 49
Quoted 9 lines
checkpoint/checkpoint.h +8
-0+struct file *file; +loff_t current_object; + +struct list_head object_array[CPT_OBJ_MAX ]; + +int (*write)(const void *addr,size_t count,struct cpt_context *ctx); +int (*read)(void *addr,size_t count,struct cpt_context *ctx); +} cpt_context_t;Man, this is hard to review. I was going to try and make sure that your refcounting was right and atomic, but there's no use of it in this patch except for the initialization and accessor functions. Darn.
For simplicity I will throw out all this stuff completely.
Quoted 5 lines
Quoted 2 lines
+extern int
debug_level;I'm going to go out on a limb here and say that "
debug_level" is probably a wee bit too generic of a variable name.
I will change it to something else.
Quoted 7 lines
checkpoint/checkpoint.h struct cpt_operations · line 56
Quoted 5 lines
checkpoint/checkpoint.h +4
-0+#define cpt_printk(lvl, fmt, args...) do { \ + if (lvl <= debug_level) \ + printk(fmt, ##args); \ + } while (0)I think you can use
pr_debug()here, too, just like Oren did.
Will switch to pr_debug().
Quoted 62 lines
Quoted 62 lines
checkpoint/sys.c +58
-1+struct cpt_context *context_alloc (void ) +{ +struct cpt_context *ctx; +int i; + + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return NULL ; + +init_MUTEX (&ctx->main_sem); + ctx->refcount =1 ; + + ctx->current_object =-1 ; + ctx->write = file_write; + ctx->read = file_read; +for (i =0 ; i <CPT_OBJ_MAX ; i++) { +INIT_LIST_HEAD (&ctx->object_array[i]); + } + +return ctx; +} + +void context_release (struct cpt_context *ctx) +{ + ctx->ctx_state =CPT_CTX_ERROR ; + +kfree (ctx); +} + +static void context_put (struct cpt_context *ctx) +{ +if (!--ctx->refcount) +context_release (ctx); +} +static int checkpoint (pid_t pid,int fd,unsigned long flags) { -return -ENOSYS ; +struct file *file; +struct cpt_context *ctx; +int err; + + err = -EBADF ; + file =fget (fd); +if (!file) + goto out; + + err = -ENOMEM ; + ctx =context_alloc (); +if (!ctx) + goto out_file; + + ctx->file = file; + ctx->ctx_state =CPT_CTX_DUMPING ; + +/* checkpoint */ + err = -ENOSYS ; + +context_put (ctx); + +out_file:
Quoted 8 lines
checkpoint/sys.c line 120
Quoted 4 lines
checkpoint/sys.c +3
-0+fput (file); +out: +return err; }So, where is
context_get()? Is there only single-threaded access to the refcount? If so, why do we even need it? We should probably just usecontext_release()driectly.
The idea is that in future we should be able to keep a context for incremental checkpointing. That is why we need context get/put functions. Right now it is not used, so I will drop it.
Quoted 2 lines
If there is multithreaded access to
context_put()or the refcount, then they're unsafe without additional locking.
Access to refcount will be protected with context mutex.
Thanks for comments.
Actually I'm not sure if I will continue with my own patch set, but I will take into account all your comments during porting my functionality to Oren's tree.
Andrey
Re: [Devel] Re: [PATCH 10/10] Add support for multiple processes
In reply to Oren LaadanQuoted 44 lines · On Monday 27 October 2008 18:58 Oren Laadan wrote:
Quoted 43 lines · Andrey Mirkin
The whole tree of processes can be checkpointed and restarted now. Shared objects are not supported yet.
Signed-off-by Andrey Mirkin <[email protected]>--- checkpoint/cpt_image.h | 2 + checkpoint/cpt_process.c | 24 +++++++++++++ checkpoint/rst_process.c | 85+++++++++++++++++++++++++++------------------- 3 files changed, 76 insertions(+), 35 deletions(-)
checkpoint/cpt_image.h +2
-0@@ -128,6 +128,8 @@ struct cpt_task_image {__u64 cpt_nivcsw;__u64 cpt_min_flt;__u64 cpt_maj_flt; +__u32 cpt_children_num; +__u32 cpt_pad; } __attribute__ ((aligned (8)));struct cpt_mm_image {checkpoint/cpt_process.c +9
-0@@ -40,6 +40,19 @@ static unsigned int encode_task_flags(unsigned int task_flags) } +static int cpt_count_children (struct task_struct *tsk,struct cpt_context *ctx) +{ +int num =0 ; +struct task_struct *child; + +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + num++; + }
Quoted 8 lines
checkpoint/cpt_process.c static unsigned int encode_task_flags(unsigned int task_flags) · line 55
Quoted 3 lines
checkpoint/cpt_process.c +3
-0+return num; +} +I noticed that don't take the appropriate locks when browsing through tasks lists (siblings, children, global list). Although I realize that the container should be frozen at this time, I keep wondering if this is indeed always safe.
You right here. We need to take tasklist_lock to be sure that everything will be consistent.
Quoted 2 lines
For instance, are you protected against an OOM killer that might just occur uninvited and kill one of those tasks ?
OOM killer can't kill one of those tasks as all of them should be frozen at that time and be in uninterruptible state. So, we can just do not think about OOM at that time. But anyway you right and we need locking around browsing tasks list.
Quoted 2 lines
Can the administrator force an un-freeze of the container ? Or perhaps some error condition if the kernel cause that ?
The main idea is that context should be protected with a mutex and only one process can do some activity (freeze, dump, unfreeze, kill) with a container. Right now it is not implemented at all, but in future it will be added.
Andrey
Quoted 39 lines
Quoted 13 lines
checkpoint/cpt_process.c +0
-0int cpt_dump_task_struct(struct task_struct *tsk, struct cpt_context*ctx) {
checkpoint/cpt_process.c +1
-0struct cpt_task_image *t;@@ -102,6 +115,7 @@ int cpt_dump_task_struct(struct task_struct *tsk, struct cpt_context *ctx) t->cpt_egid = tsk->egid; t->cpt_sgid = tsk->sgid; t->cpt_fsgid = tsk->fsgid; + t->cpt_children_num =cpt_count_children (tsk, ctx); err = ctx->write (t,sizeof (*t), ctx);@@ -231,6 +245,16 @@ int cpt_dump_task(struct task_struct *tsk, struct cpt_context *ctx) err = cpt_dump_fpustate(tsk, ctx);checkpoint/cpt_process.c int cpt_dump_task(struct task_struct *tsk, struct · line 255
Quoted 10 lines
checkpoint/cpt_process.c +8
-0if (!err) err =cpt_dump_registers (tsk, ctx); +if (!err) { +struct task_struct *child; +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + err =cpt_dump_task (child, ctx); +if (err) +break ;Here too.
[...]
Oren.
_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers_______________________________________________
Devel mailing list
[email protected]
https://openvz.org/mailman/listinfo/devel
Re: [Devel] Re: [PATCH 10/10] Add support for multiple processes
In reply to a message not in the archiveQuoted 44 lines · On Monday 27 October 2008 18:58 Oren Laadan wrote:
Quoted 43 lines · Andrey Mirkin
The whole tree of processes can be checkpointed and restarted now. Shared objects are not supported yet.
Signed-off-by Andrey Mirkin <[email protected]>--- checkpoint/cpt_image.h | 2 + checkpoint/cpt_process.c | 24 +++++++++++++ checkpoint/rst_process.c | 85+++++++++++++++++++++++++++------------------- 3 files changed, 76 insertions(+), 35 deletions(-)
checkpoint/cpt_image.h +2
-0@@ -128,6 +128,8 @@ struct cpt_task_image {__u64 cpt_nivcsw;__u64 cpt_min_flt;__u64 cpt_maj_flt; +__u32 cpt_children_num; +__u32 cpt_pad; } __attribute__ ((aligned (8)));struct cpt_mm_image {checkpoint/cpt_process.c +9
-0@@ -40,6 +40,19 @@ static unsigned int encode_task_flags(unsigned int task_flags) } +static int cpt_count_children (struct task_struct *tsk,struct cpt_context *ctx) +{ +int num =0 ; +struct task_struct *child; + +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + num++; + }
Quoted 8 lines
checkpoint/cpt_process.c static unsigned int encode_task_flags(unsigned int task_flags) · line 55
Quoted 3 lines
checkpoint/cpt_process.c +3
-0+return num; +} +I noticed that don't take the appropriate locks when browsing through tasks lists (siblings, children, global list). Although I realize that the container should be frozen at this time, I keep wondering if this is indeed always safe.
You right here. We need to take tasklist_lock to be sure that everything will be consistent.
Quoted 2 lines
For instance, are you protected against an OOM killer that might just occur uninvited and kill one of those tasks ?
OOM killer can't kill one of those tasks as all of them should be frozen at that time and be in uninterruptible state. So, we can just do not think about OOM at that time. But anyway you right and we need locking around browsing tasks list.
Quoted 2 lines
Can the administrator force an un-freeze of the container ? Or perhaps some error condition if the kernel cause that ?
The main idea is that context should be protected with a mutex and only one process can do some activity (freeze, dump, unfreeze, kill) with a container. Right now it is not implemented at all, but in future it will be added.
Andrey
Quoted 39 lines
Quoted 13 lines
checkpoint/cpt_process.c +0
-0int cpt_dump_task_struct(struct task_struct *tsk, struct cpt_context*ctx) {
checkpoint/cpt_process.c +1
-0struct cpt_task_image *t;@@ -102,6 +115,7 @@ int cpt_dump_task_struct(struct task_struct *tsk, struct cpt_context *ctx) t->cpt_egid = tsk->egid; t->cpt_sgid = tsk->sgid; t->cpt_fsgid = tsk->fsgid; + t->cpt_children_num =cpt_count_children (tsk, ctx); err = ctx->write (t,sizeof (*t), ctx);@@ -231,6 +245,16 @@ int cpt_dump_task(struct task_struct *tsk, struct cpt_context *ctx) err = cpt_dump_fpustate(tsk, ctx);checkpoint/cpt_process.c int cpt_dump_task(struct task_struct *tsk, struct · line 255
Quoted 10 lines
checkpoint/cpt_process.c +8
-0if (!err) err =cpt_dump_registers (tsk, ctx); +if (!err) { +struct task_struct *child; +list_for_each_entry (child, &tsk->children, sibling) { +if (child->parent != tsk) +continue ; + err =cpt_dump_task (child, ctx); +if (err) +break ;Here too.
[...]
Oren.
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers_______________________________________________
Devel mailing list
[email protected]
https://openvz.org/mailman/listinfo/devel
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to a message not in the archiveQuoted 63 lines · Andrey Mirkin
Quoted 36 lines · On Sunday 26 October 2008 01:10 Oren Laadan wrote:
Quoted 27 lines · Andrey Mirkin
Quoted 19 lines · On Thursday 23 October 2008 17:57 Dave Hansen wrote:
Quoted 18 lines · Andrey Mirkin
Quoted 18 lines
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Can you please elaborate on this ? I don't recall having had issues with that.
Quoted 7 lines
Quoted 3 lines
Right now in 2.6.18 kernel we restarts in such a way pause,
rt_sigtimedwaitand futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.Could you elaborate on this a bit?
If the futex syscall was reworked, perhaps we can do the same for
rt_sigtimedwait()and get rid of this code completely.Quoted 8 lines
Well, we can try to rework
rt_sigtimedwait(), but we will still need this code in the future to restart pause syscall from kernel without returning to user space. Also this code will be needed to restore some complex states. As concerns pause syscall I have already written to Louis about the problem we are trying to solve with this code. There is a gap when process will be in user space just before entering syscall again. At this time a signal can be delivered to process and it even can be handled. So, we will miss a signal which must interrupt pause syscall.Quoted 3 lines
I'm not convinced that you a real race exists, and even if it does, I'm not convinced that hacking the assembly entry/exit code is the best way to do it.
Well, as I already told
pause()syscall is is not only one case why we need to do some additional job in that place.Quoted 11 lines
Let me explain:
You are concerned about a race in which a signal is delivered to a task that resumes from restart to user space and is about to (re)invoke '
pause()' (because the restart so arranged its EIP and registers).This almost always means that the user code is buggy and relies on specific scheduling, because you can usually find a scheduling (without the C/R) where the intended recipient of the signal was delayed and only calls
pause()after the signal is delivered.Quoted 7 lines
For instance, if the sequence of events is:
A calls pause() -> checkpoint -> restart -> B signals A -> A calls pause() (after restart), then the following sequence is possible(*) without C/R: B signals A -> A calls pause()because normally B cannot assume anything about when A is actually, really, is suspended (which means the programmer did an imperfect job).
Quoted 3 lines
You right here. Both sequences are possible in theory. You will be surprised but in practice we found out that probability to miss a signal in case of C/R is much higher then during ordinary execution.
The point is that "missing" a signal because of freeze/thaw (or stop/cont) is perfectly acceptable behavior. It is supposed to work that way. So I argue that we don't need a workaround.
Quoted 18 lines
Quoted 12 lines
I said "almost always" and "usually", because there is one case where the alternative schedule: task B could, prior to sending the signal, "ensure" that task A is already sleeping within the '
pause()' syscall. While this is possible, it is definitely unusual, and in fact I never code that does that. And what if the sysadmin send SIGSTOP followed by SIGCONT ? In short, such code is simply broken.More importantly, if you think about the operation and semantics of the freezer cgroup - similar behavior is to be expected when you freeze and then thaw a container.
Quoted 5 lines
Specifically, when you freeze the container that has a task in
sys_pause(), then that task will abort the syscall become frozen. As soon as it becomes unfrozen, it will return to user space (with the EIP "rewinded") only to re-invoke the syscall. So the same "race" remains even if you only freeze and then thaw, regardless of C/R.
Quoted 3 lines
Exactly. But during freeze/unfreeze probability to catch such situation is very low. In our tests we were tried to checkpoint/restart LTP tests. And this "race" were triggered during restart almost in 100% of tests.
Why is it the case ?
At the end of restart, the container remains frozen until you unfreeze it. So c/r effectively becomes freeze/unfreeze, except - possible - for page fault that are more likely to happen when thawing following the restart (and these may slow down the application and allow a signal to "slip in").
If it's nearly 100% of the tests, that it should be easily reproducible with merely freeze/thaw pairs, no ?
Still, arguing that LTP "breaks" here is like arguing that LTP "breaks" if we were to run it while sending SIGSTOP/SIGCONT to its processes...
Quoted 16 lines
Quoted 5 lines
Moreover, I argue that basically when you return from a
sys_restart(), the entire container should, by default, remain in frozen state - just like it is withsys_checkpoint(). An explicit thaw will make the container resume execution.No doubt. That is how we do in OpenVZ, after restart the container remains frozen. And we need to thaw it to resume its execution.
Quoted 6 lines
Therefore, there are two options: the first is to decide that this behavior
- going back to user space to re-invoke the syscall - is valid. In this case you don't need a special hack for returning fromsys_restart(). The second option is to decide that it is broken, in which case you need to also fix the freezer code. Personally, I think that this behavior is valid and need not be fixed.
Quoted 2 lines
I still believe that we need to fix such behaviour during restart as in practice it is very easy to trigger it.
did you see any problem outside LTP ? I never saw any such problems.
Quoted 8 lines
Quoted 8 lines
Finally, even if you do want to fix the behavior for this pathologic case, I don't see why you'd want to do it in this manner. Instead, you can add a simple test prior to returning from
sys_restart(), something like this:... /* almost done: now handle special cases: */ if (our last syscall == __NR_pause) {
do_freeze();
Quoted 3 lines
Quoted 3 lines
ret = sys_pause(); } else if (our last syscall == __NR_futex) { do some stuff;
do_freeze();
Quoted 10 lines
Quoted 7 lines
ret = sys_futex(); } else { ret = what-we-want-to-return } /* finally, return to user space */ return ret; }This only works if we do not want to stay in frozen state after restart. Or am I missed something?
Sure: see addition above.
Quoted 6 lines
Quoted 4 lines
I'm not quite know what other "complex states" you refer to; but I wonder whether that code "needed to restore some complex states" could not be implemented along the same idea.
In the same manner we are restoring for instance ptrace.
Yes, I mentioned that in the past. Can be addressed in the same manner.
Quoted 7 lines
Quoted 4 lines
The upside is clear: the code is less obscure, simple to debug, and not architecture-dependent. (hehe .. it even runs faster because it saves a whole
kernel->user->kernelswitch, what do you know !).In our case we also do not need a switch and the code actually not very complicated.
Fact is that people wondered what was going on there.
I prefer the arch-independent way, because it is, well, arch-independent, and because it makes the logic and the exception obvious to the reader, and it is easily extensible to handle additional special cases (like ptrace), and makes maintenance easier.
Do you object to doing it this way ?
Oren.
Re: [Devel] Re: [PATCH 08/10] Introduce functions to restart a process
In reply to Andrey MirkinQuoted 63 lines · Andrey Mirkin
Quoted 36 lines · On Sunday 26 October 2008 01:10 Oren Laadan wrote:
Quoted 27 lines · Andrey Mirkin
Quoted 19 lines · On Thursday 23 October 2008 17:57 Dave Hansen wrote:
Quoted 18 lines · Andrey Mirkin
Quoted 18 lines
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
It is not related to the freezer code actually.
That is needed to restart syscalls. Right now I don't have a code in my patchset which restarts a syscall, but later I plan to add it. In OpenVZ checkpointing we restart syscalls if process was caught in syscall during checkpointing.Quoted 8 lines
Do you checkpoint uninterruptible syscalls as well? If only interruptible syscalls are checkpointed, I'd say that either this syscall uses ERESTARTSYS or
ERESTART_RESTARTBLOCK, and then signal handling code already does the trick, or this syscall does not restart itself when interrupted, and well, this is life, userspace just sees-EINTR, which is allowed by the syscall spec. Actually this is how we checkpoint/migrate tasks in interruptible syscalls in Kerrighed and this works.Quoted 3 lines
We checkpoint only interruptible syscalls. Some syscalls do not restart themself, that is why after restarting a process we restart syscall to complete it.
Can you please elaborate on this ? I don't recall having had issues with that.
Quoted 7 lines
Quoted 3 lines
Right now in 2.6.18 kernel we restarts in such a way pause,
rt_sigtimedwaitand futex syscalls. Recently futex syscall was reworked and we will not need such hooks for it.Could you elaborate on this a bit?
If the futex syscall was reworked, perhaps we can do the same for
rt_sigtimedwait()and get rid of this code completely.Quoted 8 lines
Well, we can try to rework
rt_sigtimedwait(), but we will still need this code in the future to restart pause syscall from kernel without returning to user space. Also this code will be needed to restore some complex states. As concerns pause syscall I have already written to Louis about the problem we are trying to solve with this code. There is a gap when process will be in user space just before entering syscall again. At this time a signal can be delivered to process and it even can be handled. So, we will miss a signal which must interrupt pause syscall.Quoted 3 lines
I'm not convinced that you a real race exists, and even if it does, I'm not convinced that hacking the assembly entry/exit code is the best way to do it.
Well, as I already told
pause()syscall is is not only one case why we need to do some additional job in that place.Quoted 11 lines
Let me explain:
You are concerned about a race in which a signal is delivered to a task that resumes from restart to user space and is about to (re)invoke '
pause()' (because the restart so arranged its EIP and registers).This almost always means that the user code is buggy and relies on specific scheduling, because you can usually find a scheduling (without the C/R) where the intended recipient of the signal was delayed and only calls
pause()after the signal is delivered.Quoted 7 lines
For instance, if the sequence of events is:
A calls pause() -> checkpoint -> restart -> B signals A -> A calls pause() (after restart), then the following sequence is possible(*) without C/R: B signals A -> A calls pause()because normally B cannot assume anything about when A is actually, really, is suspended (which means the programmer did an imperfect job).
Quoted 3 lines
You right here. Both sequences are possible in theory. You will be surprised but in practice we found out that probability to miss a signal in case of C/R is much higher then during ordinary execution.
The point is that "missing" a signal because of freeze/thaw (or stop/cont) is perfectly acceptable behavior. It is supposed to work that way. So I argue that we don't need a workaround.
Quoted 18 lines
Quoted 12 lines
I said "almost always" and "usually", because there is one case where the alternative schedule: task B could, prior to sending the signal, "ensure" that task A is already sleeping within the '
pause()' syscall. While this is possible, it is definitely unusual, and in fact I never code that does that. And what if the sysadmin send SIGSTOP followed by SIGCONT ? In short, such code is simply broken.More importantly, if you think about the operation and semantics of the freezer cgroup - similar behavior is to be expected when you freeze and then thaw a container.
Quoted 5 lines
Specifically, when you freeze the container that has a task in
sys_pause(), then that task will abort the syscall become frozen. As soon as it becomes unfrozen, it will return to user space (with the EIP "rewinded") only to re-invoke the syscall. So the same "race" remains even if you only freeze and then thaw, regardless of C/R.
Quoted 3 lines
Exactly. But during freeze/unfreeze probability to catch such situation is very low. In our tests we were tried to checkpoint/restart LTP tests. And this "race" were triggered during restart almost in 100% of tests.
Why is it the case ?
At the end of restart, the container remains frozen until you unfreeze it. So c/r effectively becomes freeze/unfreeze, except - possible - for page fault that are more likely to happen when thawing following the restart (and these may slow down the application and allow a signal to "slip in").
If it's nearly 100% of the tests, that it should be easily reproducible with merely freeze/thaw pairs, no ?
Still, arguing that LTP "breaks" here is like arguing that LTP "breaks" if we were to run it while sending SIGSTOP/SIGCONT to its processes...
Quoted 16 lines
Quoted 5 lines
Moreover, I argue that basically when you return from a
sys_restart(), the entire container should, by default, remain in frozen state - just like it is withsys_checkpoint(). An explicit thaw will make the container resume execution.No doubt. That is how we do in OpenVZ, after restart the container remains frozen. And we need to thaw it to resume its execution.
Quoted 6 lines
Therefore, there are two options: the first is to decide that this behavior
- going back to user space to re-invoke the syscall - is valid. In this case you don't need a special hack for returning fromsys_restart(). The second option is to decide that it is broken, in which case you need to also fix the freezer code. Personally, I think that this behavior is valid and need not be fixed.
Quoted 2 lines
I still believe that we need to fix such behaviour during restart as in practice it is very easy to trigger it.
did you see any problem outside LTP ? I never saw any such problems.
Quoted 8 lines
Quoted 8 lines
Finally, even if you do want to fix the behavior for this pathologic case, I don't see why you'd want to do it in this manner. Instead, you can add a simple test prior to returning from
sys_restart(), something like this:... /* almost done: now handle special cases: */ if (our last syscall == __NR_pause) {
do_freeze();
Quoted 3 lines
Quoted 3 lines
ret = sys_pause(); } else if (our last syscall == __NR_futex) { do some stuff;
do_freeze();
Quoted 10 lines
Quoted 7 lines
ret = sys_futex(); } else { ret = what-we-want-to-return } /* finally, return to user space */ return ret; }This only works if we do not want to stay in frozen state after restart. Or am I missed something?
Sure: see addition above.
Quoted 6 lines
Quoted 4 lines
I'm not quite know what other "complex states" you refer to; but I wonder whether that code "needed to restore some complex states" could not be implemented along the same idea.
In the same manner we are restoring for instance ptrace.
Yes, I mentioned that in the past. Can be addressed in the same manner.
Quoted 7 lines
Quoted 4 lines
The upside is clear: the code is less obscure, simple to debug, and not architecture-dependent. (hehe .. it even runs faster because it saves a whole
kernel->user->kernelswitch, what do you know !).In our case we also do not need a switch and the code actually not very complicated.
Fact is that people wondered what was going on there.
I prefer the arch-independent way, because it is, well, arch-independent, and because it makes the logic and the exception obvious to the reader, and it is easily extensible to handle additional special cases (like ptrace), and makes maintenance easier.
Do you object to doing it this way ?
Oren.