Skip to contentSkip to conversation

x86_86 support of checkpoint/restart (Re: Checkpoint / Restart)

RFC PATCH Nauman Rafique 7 participants 11 messages Feb 7, 2009 – Mar 20, 2009 7 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The patch sent by Masahiko assumes that all the user-space registers are saved on the kernel stack on a system call. This is not true for the majority of the system calls. The callee saved registers (as defined by x86_64 ABI) - rbx, rbp, r12, r13, r14, r15 - are saved only in some special cases. That means that these registers would not be available to checkpoint code. Moreover, the restore code would have no space in stack to restore those registers.

This patch partially solves that problem, but using a stub around checkpoint/restart system calls. This stub saves/restores those callee saved registers to/from the kernel stack. This solves the problem in the case of self checkpoint and restore.

In case of external checkpoint, there is no clean way to have access to these callee saved registers. We freeze or SIGSTOP the process that has to be checkpointed. The process could have entered the kernel space via any arbitrary code path before it was stopped or frozen. Thus the callee saved registers were not saved in pt_regs (i.e. the bottom of the kernel mode stack). They would be saved at some arbitrary place in the kernel mode stack. And when we want to checkpoint that process, we cannot find those registers and save them in the checkpoint.

Possible solutions to this external checkpointing problem include saving/restoring all registers (not feasible as it would have performance penalty for every code path), and overloading a signal for achieving external checkpointing. Any ideas?
---

 arch/x86/include/asm/unistd_64.h |    4 ++--
 arch/x86/kernel/entry_64.S       |   10 ++++++++++
 arch/x86/mm/checkpoint.c         |    3 +--
 arch/x86/mm/restart.c            |    5 ++---
 4 files changed, 15 insertions(+), 7 deletions(-)
arch/x86/include/asm/unistd_64.h +2 -2
index fe7174d..76aa903 100644
@@ -654,9 +654,9 @@ __SYSCALL(__NR_pipe2, sys_pipe2)
 #define __NR_inotify_init1			294
 __SYSCALL(__NR_inotify_init1, sys_inotify_init1)
 #define __NR_checkpoint				295
-__SYSCALL(__NR_checkpoint, sys_checkpoint)
+__SYSCALL(__NR_checkpoint, stub_checkpoint)
 #define __NR_restart				296
-__SYSCALL(__NR_restart, sys_restart)
+__SYSCALL(__NR_restart, stub_restart)
 
 
 #ifndef __NO_STUBS
arch/x86/kernel/entry_64.S +10 -0
index b86f332..0369267 100644
@@ -545,6 +545,14 @@ END(system_call)
 END(\label)
 	.endm
 
+	.macro FULLSTACKCALL label,func
+	.globl \label
+	\label:
+	leaq    \func(%rip),%rax
+	jmp     ptregscall_common
+	END(\label)
+	.endm
+	
 	CFI_STARTPROC
 
 	PTREGSCALL stub_clone, sys_clone, %r8
@@ -552,6 +560,8 @@ END(\label)
 	PTREGSCALL stub_vfork, sys_vfork, %rdi
 	PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx
 	PTREGSCALL stub_iopl, sys_iopl, %rsi
+	FULLSTACKCALL stub_restart, sys_restart
+	FULLSTACKCALL stub_checkpoint, sys_checkpoint
 
 ENTRY(ptregscall_common)
 	popq %r11
arch/x86/mm/checkpoint.c +1 -2
index 2514f14..a26332d 100644
@@ -75,10 +75,10 @@ static void cr_save_cpu_regs(struct cr_hdr_cpu *hh, struct task_struct *t)
 	hh->ip = regs->ip;
 	hh->cs = regs->cs;
 	hh->flags = regs->flags;
+	hh->sp = regs->sp;
 	hh->ss = regs->ss;
 
 #ifdef CONFIG_X86_64
-	hh->sp = read_pda (oldrsp);
 	hh->r8 = regs->r8;
 	hh->r9 = regs->r9;
 	hh->r10 = regs->r10;
@@ -90,7 +90,6 @@ static void cr_save_cpu_regs(struct cr_hdr_cpu *hh, struct task_struct *t)
 	hh->ds = thread->ds;
 	hh->es = thread->es;
 #else /* !CONFIG_X86_64 */
-	hh->sp = regs->sp;
 	hh->ds = regs->ds;
 	hh->es = regs->es;
 #endif /* CONFIG_X86_64 */
arch/x86/mm/restart.c +2 -3
index a10d63e..329f938 100644
@@ -111,15 +111,14 @@ static int cr_load_cpu_regs(struct cr_hdr_cpu *hh, struct task_struct *t)
 	regs->cs = hh->cs;
 	regs->flags = hh->flags;
 	regs->sp = hh->sp;
-	write_pda(oldrsp, hh->sp);
 	regs->ss = hh->ss;
 
-	thread->gs = hh->gs;
-	thread->fs = hh->fs;
 #ifdef CONFIG_X86_64
 	do_arch_prctl(t, ARCH_SET_FS, hh->fs);
 	do_arch_prctl(t, ARCH_SET_GS, hh->gs);
 #else
+	thread->gs = hh->gs;
+	thread->fs = hh->fs;
 	loadsegment(gs, hh->gs);
 	loadsegment(fs, hh->fs);
 #endif

A message that is not in the archive (sent off-list or not yet received): 20090207001609.8168.14884.stgit-AP77eCFSSktSzHKm+aFRNNkmqwFzkYv6@public.gmane.org

#2 lore raw

Any way to use a delayed checkpoint signal (perhaps somewhat non-deterministic, e.g. "do it now" really means "do it pretty soon") that is only taken on return to user space thus allowing a deterministic solution?
Jim

Quoted 144 lines · Nauman Rafique

The patch sent by Masahiko assumes that all the user-space registers are saved on
the kernel stack on a system call. This is not true for the majority of the system calls. The callee saved registers (as defined by x86_64 ABI) - rbx, rbp, r12, r13, r14, r15 - are saved only in some special cases. That means that these registers would not be available to checkpoint code. Moreover, the restore code would have no space in stack to restore those registers.

This patch partially solves that problem, but using a stub around checkpoint/restart system calls. This stub saves/restores those callee saved registers to/from the kernel stack. This solves the problem in the case of self checkpoint and restore.

In case of external checkpoint, there is no clean way to have access to these callee saved registers. We freeze or SIGSTOP the process that has to be checkpointed. The process could have entered the kernel space via any arbitrary code path before it was stopped or frozen. Thus the callee saved registers were not saved in pt_regs (i.e. the bottom of the kernel mode stack). They would be saved at some arbitrary place in the kernel mode stack. And when we want to checkpoint that process, we cannot find those registers and save them in the checkpoint.

Possible solutions to this external checkpointing problem include saving/restoring all registers (not feasible as it would have performance penalty for every code path), and overloading a signal for achieving external checkpointing. Any ideas?
---

 arch/x86/include/asm/unistd_64.h |    4 ++--
 arch/x86/kernel/entry_64.S       |   10 ++++++++++
 arch/x86/mm/checkpoint.c         |    3 +--
 arch/x86/mm/restart.c            |    5 ++---
 4 files changed, 15 insertions(+), 7 deletions(-)
arch/x86/include/asm/unistd_64.h +2 -2
index fe7174d..76aa903 100644
@@ -654,9 +654,9 @@ __SYSCALL(__NR_pipe2, sys_pipe2)
 #define __NR_inotify_init1                     294
 __SYSCALL(__NR_inotify_init1, sys_inotify_init1)
 #define __NR_checkpoint                                295
-__SYSCALL(__NR_checkpoint, sys_checkpoint)
+__SYSCALL(__NR_checkpoint, stub_checkpoint)
 #define __NR_restart                           296
-__SYSCALL(__NR_restart, sys_restart)
+__SYSCALL(__NR_restart, stub_restart)
 
 
 #ifndef __NO_STUBS
arch/x86/kernel/entry_64.S +10 -0
index b86f332..0369267 100644
@@ -545,6 +545,14 @@ END(system_call)
 END(\label)
       .endm
 
+       .macro FULLSTACKCALL label,func
+       .globl \label
+       \label:
+       leaq    \func(%rip),%rax
+       jmp     ptregscall_common
+       END(\label)
+       .endm
+
       CFI_STARTPROC
 
       PTREGSCALL stub_clone, sys_clone, %r8
@@ -552,6 +560,8 @@ END(\label)
       PTREGSCALL stub_vfork, sys_vfork, %rdi
       PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx
       PTREGSCALL stub_iopl, sys_iopl, %rsi
+       FULLSTACKCALL stub_restart, sys_restart
+       FULLSTACKCALL stub_checkpoint, sys_checkpoint
 
 ENTRY(ptregscall_common)
       popq %r11
arch/x86/mm/checkpoint.c +1 -1
index 2514f14..a26332d 100644
@@ -75,10 +75,10 @@ static void cr_save_cpu_regs(struct cr_hdr_cpu *hh,
 struct task_struct *t)
       hh->ip = regs->ip;
       hh->cs = regs->cs;
       hh->flags = regs->flags;
+       hh->sp = regs->sp;
       hh->ss = regs->ss;
 
 #ifdef CONFIG_X86_64
-       hh->sp = read_pda (oldrsp);
       hh->r8 = regs->r8;
       hh->r9 = regs->r9;
       hh->r10 = regs->r10;
arch/x86/mm/checkpoint.c +0 -1
@@ -90,7 +90,6 @@ static void cr_save_cpu_regs(struct cr_hdr_cpu *hh,
 struct task_struct *t)
       hh->ds = thread->ds;
       hh->es = thread->es;
 #else /* !CONFIG_X86_64 */
-       hh->sp = regs->sp;
       hh->ds = regs->ds;
       hh->es = regs->es;

#endif /* CONFIG_X86_64 */

arch/x86/mm/restart.c +2 -3
index a10d63e..329f938 100644
@@ -111,15 +111,14 @@ static int cr_load_cpu_regs(struct cr_hdr_cpu *hh,
 struct task_struct *t)
       regs->cs = hh->cs;
       regs->flags = hh->flags;
       regs->sp = hh->sp;
-       write_pda(oldrsp, hh->sp);
       regs->ss = hh->ss;
 
-       thread->gs = hh->gs;
-       thread->fs = hh->fs;
 #ifdef CONFIG_X86_64
       do_arch_prctl(t, ARCH_SET_FS, hh->fs);
       do_arch_prctl(t, ARCH_SET_GS, hh->gs);
 #else
+       thread->gs = hh->gs;
+       thread->fs = hh->fs;
       loadsegment(gs, hh->gs);
       loadsegment(fs, hh->fs);

#endif

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"kernel-live-migration" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to kernel-live-migration+unsubscribe-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org<kernel-live-migration%[email protected]> For more options, visit this group at
http://groups.google.com/a/google.com/group/kernel-live-migration?hl=en
-~----------~----~----~----~------~----~------~--~---

A message that is not in the archive (sent off-list or not yet received): f4192e520902090953x43a98134hfaa8443d586a32a6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw
Quoted 4 lines · Jim Winget

Any way to use a delayed checkpoint signal (perhaps somewhat non-deterministic, e.g. "do it now" really means "do it pretty soon") that is only taken on return to user space thus allowing a deterministic solution?

Ya, I'm thinking that a 'checkpoint' signal would be advisory, with the SIG_DFL action performing the checkpoint itself.

Considering that we'd need to cleanly get access to all registers, the checkpoint itself needs to be a well defined path from userland->kernelland. I'm wondering if sys_checkpoint could be this well-defined path using the PTREGSCALL stub macro.

For tasks that aren't checkpoint-aware, SIG_DFL could possibly be done by having the vsyscall page/vdso implement the userland sighandler that calls sys_checkpoint.

What this means though is that we won't be able to freeze or SIGSTOP tasks before checkpoint. Both of these paths can be entered via a variety of kernel entry points and unless we start dumping the full ptregs on each entry point, we'll never be able to reliably get access to all registers.

sys_checkpoint itself would have to have it's own method to quiesce all the tasks (basically wait for all tasks to enter sys_checkpoint so that a multi-task checkpoint is self-consistent). The nice thing about a signal too is that userland can block it and ignore it in a deterministic way. The failure logic for ignored or blocked-for-a-long time can be pushed back down to userland.

This is all a dramatic shift from the current way things are done, so we'd be best getting a better feel for our options though..

Quoted 151 lines

Jim

Quoted 132 lines · Nauman Rafique

The patch sent by Masahiko assumes that all the user-space registers are saved on
the kernel stack on a system call. This is not true for the majority of the system calls. The callee saved registers (as defined by x86_64 ABI) - rbx, rbp, r12, r13, r14, r15 - are saved only in some special cases. That means that these registers would not be available to checkpoint code. Moreover, the restore code would have no space in stack to restore those registers.

This patch partially solves that problem, but using a stub around checkpoint/restart system calls. This stub saves/restores those callee saved registers to/from the kernel stack. This solves the problem in the case of self checkpoint and restore.

In case of external checkpoint, there is no clean way to have access to these callee saved registers. We freeze or SIGSTOP the process that has to be checkpointed. The process could have entered the kernel space via any arbitrary code path before it was stopped or frozen. Thus the callee saved registers were not saved in pt_regs (i.e. the bottom of the kernel mode stack). They would be saved at some arbitrary place in the kernel mode stack. And when we want to checkpoint that process, we cannot find those registers and save them in the checkpoint.

Possible solutions to this external checkpointing problem include saving/restoring all registers (not feasible as it would have performance penalty for every code path), and overloading a signal for achieving external checkpointing. Any ideas?
---

 arch/x86/include/asm/unistd_64.h |    4 ++--
 arch/x86/kernel/entry_64.S       |   10 ++++++++++
 arch/x86/mm/checkpoint.c         |    3 +--
 arch/x86/mm/restart.c            |    5 ++---
 4 files changed, 15 insertions(+), 7 deletions(-)
arch/x86/include/asm/unistd_64.h +2 -2
index fe7174d..76aa903 100644
@@ -654,9 +654,9 @@ __SYSCALL(__NR_pipe2, sys_pipe2)
 #define __NR_inotify_init1                     294
 __SYSCALL(__NR_inotify_init1, sys_inotify_init1)
 #define __NR_checkpoint                                295
-__SYSCALL(__NR_checkpoint, sys_checkpoint)
+__SYSCALL(__NR_checkpoint, stub_checkpoint)
 #define __NR_restart                           296
-__SYSCALL(__NR_restart, sys_restart)
+__SYSCALL(__NR_restart, stub_restart)
 
 
 #ifndef __NO_STUBS
arch/x86/kernel/entry_64.S +10 -0
index b86f332..0369267 100644
@@ -545,6 +545,14 @@ END(system_call)
 END(\label)
       .endm
 
+       .macro FULLSTACKCALL label,func
+       .globl \label
+       \label:
+       leaq    \func(%rip),%rax
+       jmp     ptregscall_common
+       END(\label)
+       .endm
+
       CFI_STARTPROC
 
       PTREGSCALL stub_clone, sys_clone, %r8
@@ -552,6 +560,8 @@ END(\label)
       PTREGSCALL stub_vfork, sys_vfork, %rdi
       PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx
       PTREGSCALL stub_iopl, sys_iopl, %rsi
+       FULLSTACKCALL stub_restart, sys_restart
+       FULLSTACKCALL stub_checkpoint, sys_checkpoint
 
 ENTRY(ptregscall_common)
       popq %r11
arch/x86/mm/checkpoint.c +1 -1
index 2514f14..a26332d 100644
@@ -75,10 +75,10 @@ static void cr_save_cpu_regs(struct cr_hdr_cpu *hh,
 struct task_struct *t)
       hh->ip = regs->ip;
       hh->cs = regs->cs;
       hh->flags = regs->flags;
+       hh->sp = regs->sp;
       hh->ss = regs->ss;
 
 #ifdef CONFIG_X86_64
-       hh->sp = read_pda (oldrsp);
       hh->r8 = regs->r8;
       hh->r9 = regs->r9;
       hh->r10 = regs->r10;
arch/x86/mm/checkpoint.c +0 -1
@@ -90,7 +90,6 @@ static void cr_save_cpu_regs(struct cr_hdr_cpu *hh,
 struct task_struct *t)
       hh->ds = thread->ds;
       hh->es = thread->es;
 #else /* !CONFIG_X86_64 */
-       hh->sp = regs->sp;
       hh->ds = regs->ds;
       hh->es = regs->es;

#endif /* CONFIG_X86_64 */

arch/x86/mm/restart.c +2 -3
index a10d63e..329f938 100644
@@ -111,15 +111,14 @@ static int cr_load_cpu_regs(struct cr_hdr_cpu *hh,
 struct task_struct *t)
       regs->cs = hh->cs;
       regs->flags = hh->flags;
       regs->sp = hh->sp;
-       write_pda(oldrsp, hh->sp);
       regs->ss = hh->ss;
 
-       thread->gs = hh->gs;
-       thread->fs = hh->fs;
 #ifdef CONFIG_X86_64
       do_arch_prctl(t, ARCH_SET_FS, hh->fs);
       do_arch_prctl(t, ARCH_SET_GS, hh->gs);
 #else
+       thread->gs = hh->gs;
+       thread->fs = hh->fs;
       loadsegment(gs, hh->gs);
       loadsegment(fs, hh->fs);

#endif

Quoted 11 lines

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"kernel-live-migration" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to kernel-live-migration+unsubscribe-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org<kernel-live-migration%[email protected]> For more options, visit this group at
http://groups.google.com/a/google.com/group/kernel-live-migration?hl=en
-~----------~----~----~----~------~----~------~--~---

_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw
Quoted 14 lines · Mike Waychison
Quoted 4 lines · Jim Winget

Any way to use a delayed checkpoint signal (perhaps somewhat non-deterministic, e.g. "do it now" really means "do it pretty soon") that is only taken on return to user space thus allowing a deterministic solution?

Ya, I'm thinking that a 'checkpoint' signal would be advisory, with the SIG_DFL action performing the checkpoint itself.

Considering that we'd need to cleanly get access to all registers, the checkpoint itself needs to be a well defined path from userland->kernelland. I'm wondering if sys_checkpoint could be this well-defined path using the PTREGSCALL stub macro.

Quoted 6 lines

For tasks that aren't checkpoint-aware, SIG_DFL could possibly be done by having the vsyscall page/vdso implement the userland sighandler that calls sys_checkpoint.

What this means though is that we won't be able to freeze or SIGSTOP tasks before checkpoint.

the sys_checkpoint() in the userland sighandler you are proposing, is how you would freeze all the tasks of a container. Once all the tasks have entered sys_checkpoint() and are blocked on a wait queue, you can start gathering states.

This means that you need to count how many tasks should enter sys_checkpoint(). The cgroup fork callback can be used to signal new comers and maintain a coherent count of tasks. But we would also need an exit callback, which is not available.

Quoted 8 lines

Both of these paths can be entered via a
variety of kernel entry points and unless we start dumping the full ptregs on each entry point, we'll never be able to reliably get access to all registers.

sys_checkpoint itself would have to have it's own method to quiesce all the tasks (basically wait for all tasks to enter sys_checkpoint so that a multi-task checkpoint is self-consistent).

yes.

sys_restart() works the same, all the tasks are signalled in advance how many should enter the wait queue. once the task state is restored, you let each task restart from its signal handler using the cpu state that was saved on user stack at checkpoint time.

Quoted 2 lines

The nice thing about a signal too is that userland can block it and ignore it in a deterministic way.

yes and

The *very* nice thing about a signal handler is that you don't have to worry about your cpu state. I don't think it's a good idea to duplicate this code in the C/R framework. it is *very* arch dependent.

Quoted 5 lines

The failure logic for ignored or blocked-for-a-long time can be pushed back down to userland.

This is all a dramatic shift from the current way things are done, so we'd be best getting a better feel for our options though..

I think that the current way of doing things is work in progress and needs to be reviewed. The way checkpoint/restart is triggered has always been controversial among the stakeholders.

We've been maintaining a C/R solution on ppc32, ppc64, x86, x86_64, ia64, s390, s390x since 2002 working on the above principles you are describing. UNICOS and later IRIX used similar principles, following the POSIX draft on checkpoint/restart.

For the signal, we have 'hijacked' SIGSTOP but new signals SIGCKPT and SIGRESTART would definitely be a nicer solution for a mainline solution.

Cheers,

C.

A message that is not in the archive (sent off-list or not yet received): 49908EA0.2080901-NmTC/[email protected]

#8 lore raw

On 09/02/09 21:14 +0100, Cedric Le Goater wrote:

[...]

Quoted 11 lines

I think that the current way of doing things is work in progress and needs to be reviewed. The way checkpoint/restart is triggered has always been controversial among the stakeholders.

We've been maintaining a C/R solution on ppc32, ppc64, x86, x86_64, ia64, s390, s390x since 2002 working on the above principles you are describing. UNICOS and later IRIX used similar principles, following the POSIX draft on checkpoint/restart.

For the signal, we have 'hijacked' SIGSTOP but new signals SIGCKPT and SIGRESTART would definitely be a nicer solution for a mainline solution.

In Kerrighed we implemented a variant of signal handler, which is more transparent to userspace. Instead of using userspace signals (for instance SIGRTMIN), we send a signal with si_code = SI_KERRIGHED. When dequeuing such a signal, get_signal_to_deliver() calls the appropriate kernel callback (eg. task_checkpoint()), and then continues as if the signal were ignored.

This solution has two nice properties:
- no userspace signal is overloaded, so that applications can use whatever signals they want;
- every task will eventually handle the signal with the right callback, whether they use the VDSO page or not.

Of course there is the matching drawback: userspace cannot use the checkpoint signal to perform application-dependent control. However, this kind of thing could equally be done from the checkpoint callback setting up an application-defined signal handler.

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

#9 lore raw
In reply to a message not in the archive
Quoted 8 lines · Nauman Rafique

The patch sent by Masahiko assumes that all the user-space registers are saved on
the kernel stack on a system call. This is not true for the majority of the system calls. The callee saved registers (as defined by x86_64 ABI) - rbx, rbp, r12, r13, r14, r15 - are saved only in some special cases. That means that these registers would not be available to checkpoint code. Moreover, the restore code would have no space in stack to restore those registers.

According to this:

http://msdn.microsoft.com/en-us/library/6t169e9c(VS.80).aspx

Those registers all get clobbered on all function calls. I assume that userspace also considers them to get clobbered on system calls as well.

What are those special cases you are talking about? Certain special cases for entering the kernel where we do save those registers?

Signal handling and ptrace single stepping are two places I would imagine we have to enter the kernel and preserve those registers. Is that why you were suggesting overloading signal delivery?

Thanks for pointing out the problem, though. This one will be interesting. :)

-- Dave

#10 lore raw
Quoted 3 lines · Dave Hansen

Signal handling and ptrace single stepping are two places I would imagine we have to enter the kernel and preserve those registers. Is that why you were suggesting overloading signal delivery?

There is also, of course, good old interrupt handling. Even if the process is running and not making any system calls is timeslice has to expire sometime.

-- Dave

#11 lore raw
In reply to Dave Hansen
Quoted 12 lines · Dave Hansen
Quoted 8 lines · Nauman Rafique

The patch sent by Masahiko assumes that all the user-space registers are saved on
the kernel stack on a system call. This is not true for the majority of the system calls. The callee saved registers (as defined by x86_64 ABI) - rbx, rbp, r12, r13, r14, r15 - are saved only in some special cases. That means that these registers would not be available to checkpoint code. Moreover, the restore code would have no space in stack to restore those registers.

According to this:

Quoted 8 lines

http://msdn.microsoft.com/en-us/library/6t169e9c(VS.80).aspx

Those registers all get clobbered on all function calls. I assume that userspace also considers them to get clobbered on system calls as well.

What are those special cases you are talking about? Certain special cases for entering the kernel where we do save those registers?

There are the system calls the use the same stub that I have used to save the full stack (and thus all the registers).
sys_clone
sys_fork
sys_vfork
sys_sigaltstack
sys_iopl

Quoted 11 lines

Signal handling and ptrace single stepping are two places I would imagine we have to enter the kernel and preserve those registers. Is that why you were suggesting overloading signal delivery?

Thanks for pointing out the problem, though. This one will be interesting. :)

-- Dave

A message that is not in the archive (sent off-list or not yet received): e98e18940902101427i7459a7edke4fdd8404e2ef642-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#13 lore raw

Actually looking at the code in entry_64.S again closely, external checkpointing should work with my patch too. The callee save registers -- rbx, rbp, r12, r13, r14, r15 -- are saved on the kernel stack before calling signal handling code (i.e. right before switching from kernel to user mode). This signal handling code would be called whenever we are trying to checkpoint a process with SIGSTOP or cgroup freezer. Thus these registers would be on the kernel stack of checkpointed process. And we don't need any user level signal handling for external checkpointing to work in x86_64. Sorry for causing confusion.

Quoted 42 lines · Nauman Rafique
Quoted 12 lines · Dave Hansen
Quoted 8 lines · Nauman Rafique

The patch sent by Masahiko assumes that all the user-space registers are saved on
the kernel stack on a system call. This is not true for the majority of the system calls. The callee saved registers (as defined by x86_64 ABI) - rbx, rbp, r12, r13, r14, r15 - are saved only in some special cases. That means that these registers would not be available to checkpoint code. Moreover, the restore code would have no space in stack to restore those registers.

According to this:

Quoted 8 lines

http://msdn.microsoft.com/en-us/library/6t169e9c(VS.80).aspx

Those registers all get clobbered on all function calls. I assume that userspace also considers them to get clobbered on system calls as well.

What are those special cases you are talking about? Certain special cases for entering the kernel where we do save those registers?

There are the system calls the use the same stub that I have used to save the full stack (and thus all the registers).
sys_clone
sys_fork
sys_vfork
sys_sigaltstack
sys_iopl

Quoted 11 lines

Signal handling and ptrace single stepping are two places I would imagine we have to enter the kernel and preserve those registers. Is that why you were suggesting overloading signal delivery?

Thanks for pointing out the problem, though. This one will be interesting. :)

-- Dave

A message that is not in the archive (sent off-list or not yet received): e98e18940902101934o6f93230ag7226da6013afd20-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#15 lore raw

I was very confued byt he original post; there is no need for a special signal (handling) for checkpoint.

To checkpoint, we first freeze (or stop) the processes, meaning that they are kept with empty kernel stack before returning to user-mode.

We then rely on the fact that a process saves everything that it needs before entering a syscall - so whatever is on the stack when it enters the kernel must be preserved, the rest can be overwritten. Otherwise, processes wouldn't survive context switches while in syscalls ...

Oren.

Quoted 51 lines · Nauman Rafique

Actually looking at the code in entry_64.S again closely, external checkpointing should work with my patch too. The callee save registers -- rbx, rbp, r12, r13, r14, r15 -- are saved on the kernel stack before calling signal handling code (i.e. right before switching from kernel to user mode). This signal handling code would be called whenever we are trying to checkpoint a process with SIGSTOP or cgroup freezer. Thus these registers would be on the kernel stack of checkpointed process. And we don't need any user level signal handling for external checkpointing to work in x86_64. Sorry for causing confusion.

Quoted 38 lines · Nauman Rafique
Quoted 11 lines · Dave Hansen
Quoted 8 lines · Nauman Rafique

The patch sent by Masahiko assumes that all the user-space registers are saved on
the kernel stack on a system call. This is not true for the majority of the system calls. The callee saved registers (as defined by x86_64 ABI) - rbx, rbp, r12, r13, r14, r15 - are saved only in some special cases. That means that these registers would not be available to checkpoint code. Moreover, the restore code would have no space in stack to restore those registers.

According to this:

Quoted 8 lines

http://msdn.microsoft.com/en-us/library/6t169e9c(VS.80).aspx

Those registers all get clobbered on all function calls. I assume that userspace also considers them to get clobbered on system calls as well.

What are those special cases you are talking about? Certain special cases for entering the kernel where we do save those registers?

There are the system calls the use the same stub that I have used to save the full stack (and thus all the registers).
sys_clone
sys_fork
sys_vfork
sys_sigaltstack
sys_iopl

Quoted 10 lines

Signal handling and ptrace single stepping are two places I would imagine we have to enter the kernel and preserve those registers. Is that why you were suggesting overloading signal delivery?

Thanks for pointing out the problem, though. This one will be interesting. :)

-- Dave

A message that is not in the archive (sent off-list or not yet received): [email protected]

#17 lore raw
Quoted 11 lines · Oren Laadan

I was very confued byt he original post; there is no need for a special signal (handling) for checkpoint.

To checkpoint, we first freeze (or stop) the processes, meaning that they are kept with empty kernel stack before returning to user-mode.

We then rely on the fact that a process saves everything that it needs before entering a syscall - so whatever is on the stack when it enters the kernel must be preserved, the rest can be overwritten. Otherwise, processes wouldn't survive context switches while in syscalls ...

Well in x86_64, everything that process needs is not saved on the stack before entering the system call, for example, callee saved registers (rbx, rbp, r12, r13, r14, r15). If there registers are used anywhere in the kernel, they would be saved and restored from the stack. On context switch, these registers are explicitly clobbered, so that they are saved on the kernel stack of the outgoing process.

Anyways, with the stubs that I introduced in my patch, these registers are saved before entering the system call, so the problem is solved. I am now working on checkpointing/restoring 32-bit binaries on 64-bit kernel (i.e compatibility mode). It is working with internal checkpointing, but results in a seg fault in user mode after restore for external checkpoint. I will post the patches as soon as I nail it down.

Quoted 56 lines

Oren.

Quoted 51 lines · Nauman Rafique

Actually looking at the code in entry_64.S again closely, external checkpointing should work with my patch too. The callee save registers -- rbx, rbp, r12, r13, r14, r15 -- are saved on the kernel stack before calling signal handling code (i.e. right before switching from kernel to user mode). This signal handling code would be called whenever we are trying to checkpoint a process with SIGSTOP or cgroup freezer. Thus these registers would be on the kernel stack of checkpointed process. And we don't need any user level signal handling for external checkpointing to work in x86_64. Sorry for causing confusion.

Quoted 38 lines · Nauman Rafique
Quoted 11 lines · Dave Hansen
Quoted 8 lines · Nauman Rafique

The patch sent by Masahiko assumes that all the user-space registers are saved on
the kernel stack on a system call. This is not true for the majority of the system calls. The callee saved registers (as defined by x86_64 ABI) - rbx, rbp, r12, r13, r14, r15 - are saved only in some special cases. That means that these registers would not be available to checkpoint code. Moreover, the restore code would have no space in stack to restore those registers.

According to this:

Quoted 8 lines

http://msdn.microsoft.com/en-us/library/6t169e9c(VS.80).aspx

Those registers all get clobbered on all function calls.  I assume that userspace also considers them to get clobbered on system calls as well.

What are those special cases you are talking about?  Certain special cases for entering the kernel where we do save those registers?

There are the system calls the use the same stub that I have used to save the full stack (and thus all the registers). sys_clone
       sys_fork
       sys_vfork
       sys_sigaltstack
       sys_iopl

Quoted 10 lines

Signal handling and ptrace single stepping are two places I would imagine we have to enter the kernel and preserve those registers.  Is that why you were suggesting overloading signal delivery?

Thanks for pointing out the problem, though.  This one will be interesting. :)

-- Dave