Skip to contentSkip to conversation

c/r: Add s390 support

PATCH In review Dan Smith 5 participants 18 messages Mar 3, 2009 – Mar 18, 2009

Subsystems (3)
lore
Share & tools
lore

Dan Smith

author
#0 lore raw

cover c/r: Add s390 support

This set adds checkpoint/restart support for s390. It is to be applied on top of Oren's ckpt-v13 set[1] and has been tested with the single and multi- process tests in user-cr.

1: http://lkml.org/lkml/2009/1/27/227

author
#1 lore raw

PATCH 1/3 s390: Expose a constant for the number of words representing the CRs

We need to use this value in the checkpoint/restart code and would like to have a constant instead of a magic '3'.

---
 arch/s390/include/asm/ptrace.h   |    2 ++
 arch/s390/kernel/compat_ptrace.h |    3 ++-
 2 files changed, 4 insertions(+), 1 deletions(-)
arch/s390/include/asm/ptrace.h +2 -0
index 5396f9f..d5b0781 100644
@@ -172,6 +172,8 @@
 #define NUM_CRS		16
 #define NUM_ACRS	16
 
+#define NUM_CR_WORDS	3
+
 #define FPR_SIZE	8
 #define FPC_SIZE	4
 #define FPC_PAD_SIZE	4 /* gcc insists on aligning the fpregs */
arch/s390/kernel/compat_ptrace.h +2 -1
index a2be3a9..123dd66 100644
@@ -1,10 +1,11 @@
 #ifndef _PTRACE32_H
 #define _PTRACE32_H
 
+#include <asm/ptrace.h>    /* needed for NUM_CR_WORDS */
 #include "compat_linux.h"  /* needed for psw_compat_t */
 
 typedef struct {
-	__u32 cr[3];
+	__u32 cr[NUM_CR_WORDS];
 } per_cr_words32;
 
 typedef struct {
Signature · 1 line
1.6.1
#2 lore raw

Re: [PATCH 1/3] s390: Expose a constant for the number of words representing the CRs

Quoted 2 lines · Dan Smith

We need to use this value in the checkpoint/restart code and would like to have a constant instead of a magic '3'.

This doesn't do a lot of good unless it gets used in the base s390 code. Otherwise, why not just define it near its use in the c/r code?

-- Dave

author
#3 lore raw

Re: [PATCH 1/3] s390: Expose a constant for the number of words representing the CRs

DH> This doesn't do a lot of good unless it gets used in the base s390 DH> code. Otherwise, why not just define it near its use in the c/r DH> code?

I intended to replace all uses, but I just found one place I missed, but I think that's it. If you know of other places that it's used in the s390 code, other than in compat_ptrace.h and ptrace.h please point them out.

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: [email protected]
#4 lore raw

Re: [PATCH 1/3] s390: Expose a constant for the number of words representing the CRs

Quoted 8 lines · Dan Smith

DH> This doesn't do a lot of good unless it gets used in the base s390 DH> code. Otherwise, why not just define it near its use in the c/r DH> code?

I intended to replace all uses, but I just found one place I missed, but I think that's it. If you know of other places that it's used in the s390 code, other than in compat_ptrace.h and ptrace.h please point them out.

My only knowledge of where else it was used came from you. :)

-- Dave

author
#5 lore raw

PATCH 2/3 c/r: Add CR_COPY() macro (v3)

In reply to Dan Smith

As suggested by Dave[1], this provides us a way to make the copy-in and copy-out processes symmetric. CR_COPY_ARRAY() provides us a way to do the same thing but for arrays. It's not critical, but it helps us unify the checkpoint and restart paths for some things.

Changelog:
Feb 27:
. Changed CR_COPY() to use assignment, eliminating the need
for the CR_COPY_BIT() macro
. Add CR_COPY_ARRAY() macro to help copying register arrays,
etc
. Move the macro definitions inside the CR #ifdef
Feb 25:
. Changed WARN_ON() to BUILD_BUG_ON()

1: https://lists.linux-foundation.org/pipermail/containers/2009-February/015821.html (all the way at the bottom)

---
 include/linux/checkpoint.h |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
include/linux/checkpoint.h +20 -0
index 217cf6e..735668f 100644
@@ -142,6 +142,26 @@ static inline void __task_deny_checkpointing(struct task_struct *task,
 #define task_deny_checkpointing(p)  \
 	__task_deny_checkpointing(p, __FILE__, __LINE__)
 
+#define CR_CPT 1
+#define CR_RST 2
+
+#define CR_COPY(op, a, b)				        \
+	do {							\
+		if (op == CR_CPT)				\
+			a = b;					\
+		else						\
+			b = a;					\
+	} while (0);
+
+#define CR_COPY_ARRAY(op, a, b, count)				\
+	do {							\
+		BUILD_BUG_ON(sizeof(*a) != sizeof(*b));		\
+		if (op == CR_CPT)				\
+			memcpy(a, b, count * sizeof(*a));	\
+		else						\
+			memcpy(b, a, count * sizeof(*a));	\
+	} while (0);
+
 #else
 
 static inline void task_deny_checkpointing(struct task_struct *task) {}
Signature · 1 line
1.6.1
#6 lore raw

Re: [PATCH 2/3] c/r: Add CR_COPY() macro (v3)

Quoted 4 lines · Dan Smith

As suggested by Dave[1], this provides us a way to make the copy-in and copy-out processes symmetric. CR_COPY_ARRAY() provides us a way to do the same thing but for arrays. It's not critical, but it helps us unify the checkpoint and restart paths for some things.

Did you convince Nathan that this ends up being a good idea?

-- Dave

author
#7 lore raw

Re: [PATCH 2/3] c/r: Add CR_COPY() macro (v3)

DH> Did you convince Nathan that this ends up being a good idea?

Technically he hasn't seen this version, but my hopes are not high that he will change his mind. If the feedback is that they're not liked, I'll happily remove them.

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: [email protected]
#8 lore raw

Re: [PATCH 2/3] c/r: Add CR_COPY() macro (v3)

Quoted 5 lines · Dan Smith

DH> Did you convince Nathan that this ends up being a good idea?

Technically he hasn't seen this version, but my hopes are not high that he will change his mind. If the feedback is that they're not liked, I'll happily remove them.

I just figure if Nathan feels that strongly that we'll encounter more people who feel even more so. So, I was curious if he changed his mind somehow.

-- Dave

#9 lore raw

Re: [PATCH 2/3] c/r: Add CR_COPY() macro (v3)

Quoted 10 lines · Dave Hansen
Quoted 5 lines · Dan Smith

DH> Did you convince Nathan that this ends up being a good idea?

Technically he hasn't seen this version, but my hopes are not high that he will change his mind. If the feedback is that they're not liked, I'll happily remove them.

I just figure if Nathan feels that strongly that we'll encounter more people who feel even more so. So, I was curious if he changed his mind somehow.

I maintain however that two strong advantages of moving the checkpoint and restart of simple registers etc into a single function are:

1. we won't forget to add (or accidentally lose) one or the other
2. any actual special handling at checkpoint or restart, like the loading of access registers at restart on s390x, stand out

-serge

#10 lore raw

Re: [PATCH 2/3] c/r: Add CR_COPY() macro (v3)

Quoted 11 lines · Serge E. Hallyn
Quoted 9 lines · Dave Hansen
Quoted 5 lines · Dan Smith

DH> Did you convince Nathan that this ends up being a good idea?

Technically he hasn't seen this version, but my hopes are not high that he will change his mind. If the feedback is that they're not liked, I'll happily remove them.

I just figure if Nathan feels that strongly that we'll encounter more people who feel even more so. So, I was curious if he changed his mind somehow.

Quoted 9 lines

I maintain however that two strong advantages of moving the checkpoint and restart of simple registers etc into a single function are:

1. we won't forget to add (or accidentally lose) one or the other
2. any actual special handling at checkpoint or restart, like the loading of access registers at restart on s390x, stand out

I, too, think that this scheme is elegant, and at the same time I, too, think that it obfuscates the code. Since I only touch arch-dependent code only if I really really must, I don't have strong opinion about it ;)

However, a problem with this scheme is that checkpoint and restart are not fully symmetric -- on restart we must sanitize the input data before restoring the registers to that data. I'm not familiar with s390, but it is likely that by not doing so we create a security issue.

Oren.

#11 lore raw

Re: [PATCH 2/3] c/r: Add CR_COPY() macro (v3)

Quoted 28 lines · Oren Laadan
Quoted 11 lines · Serge E. Hallyn
Quoted 9 lines · Dave Hansen
Quoted 5 lines · Dan Smith

DH> Did you convince Nathan that this ends up being a good idea?

Technically he hasn't seen this version, but my hopes are not high that he will change his mind. If the feedback is that they're not liked, I'll happily remove them.

I just figure if Nathan feels that strongly that we'll encounter more people who feel even more so. So, I was curious if he changed his mind somehow.

Quoted 9 lines

I maintain however that two strong advantages of moving the checkpoint and restart of simple registers etc into a single function are:

1. we won't forget to add (or accidentally lose) one or the other
2. any actual special handling at checkpoint or restart, like the loading of access registers at restart on s390x, stand out

I, too, think that this scheme is elegant, and at the same time I, too, think that it obfuscates the code. Since I only touch arch-dependent code only if I really really must, I don't have strong opinion about it ;)

Quoted 6 lines

However, a problem with this scheme is that checkpoint and restart are not fully symmetric -- on restart we must sanitize the input data before restoring the registers to that data. I'm not familiar with s390, but it is likely that by not doing so we create a security issue.

Oren.

But that's exactly why I think CR_COPY() helps - the sanitation is explicit next to some boring CR_COPY()s. It becomes clearer that it is being done.

Anyway we've got plenty of other, bigger hurdles to clear, so while I do have a strong opinion, I'm not planning on pushing hard either way.

thanks,
-serge

#12 lore raw

Re: [PATCH 2/3] c/r: Add CR_COPY() macro (v3)

In reply to Dave Hansen
Quoted 10 lines · On Tue, 03 Mar 2009 17:00:37 -0800 Dave Hansen <[email protected]> wrote:
Quoted 5 lines · Dan Smith

DH> Did you convince Nathan that this ends up being a good idea?

Technically he hasn't seen this version, but my hopes are not high that he will change his mind. If the feedback is that they're not liked, I'll happily remove them.

I just figure if Nathan feels that strongly that we'll encounter more people who feel even more so. So, I was curious if he changed his mind somehow.

No, not really, sorry.

I understand why it's nice for the developer to have this sort of helper, but I don't think it's nice for someone trying to review or debug the code.

Surely discussing these macros has already consumed more developer time than they would ever save? :)

#13 lore raw

Re: [PATCH 2/3] c/r: Add CR_COPY() macro (v3)

Quoted 14 lines · Nathan Lynch
Quoted 10 lines · On Tue, 03 Mar 2009 17:00:37 -0800 Dave Hansen <[email protected]> wrote:
Quoted 5 lines · Dan Smith

DH> Did you convince Nathan that this ends up being a good idea?

Technically he hasn't seen this version, but my hopes are not high that he will change his mind. If the feedback is that they're not liked, I'll happily remove them.

I just figure if Nathan feels that strongly that we'll encounter more people who feel even more so. So, I was curious if he changed his mind somehow.

Quoted 5 lines

No, not really, sorry.

I understand why it's nice for the developer to have this sort of helper, but I don't think it's nice for someone trying to review or debug the code.

That's funny. I've only reviewed and debugged these things, but I don't think I've actually written any code that would have used these macros! As someone trying to debug and review, I love how this looks.

It gets the point across much more clearly about what is going on to me as a reviewer and I appreciate that. memcpy()s contain a lot of gunk that my brain can't parse easily, but this is rather clean, and it *HALVES* the number of lines of code I have to look at.

Quoted 2 lines

Surely discussing these macros has already consumed more developer time than they would ever save? :)

That's exactly my point. We're not trying to save development time here at all. My argument is that this reduces the maintenance and review burden.

-- Dave

#14 lore raw

Re: [PATCH 2/3] c/r: Add CR_COPY() macro (v3)

In reply to Dan Smith

Hi Dan.

include/linux/checkpoint.h static inline void __task_deny_checkpointing(struct task_struct *task, · line 154

Quoted 10 lines · Dan Smith
include/linux/checkpoint.h +10 -0
+#define CR_CPT 1
+#define CR_RST 2
+
+#define CR_COPY(op, a, b)				        \
+	do {							\
+		if (op == CR_CPT)				\
+			a = b;					\
+		else						\
+			b = a;					\
+	} while (0);

Drop the semicolon ^

include/linux/checkpoint.h static inline void __task_deny_checkpointing(struct task_struct *task, · line 164

Quoted 10 lines
include/linux/checkpoint.h +10 -0
+
+#define CR_COPY_ARRAY(op, a, b, count)				\
+	do {							\
+		BUILD_BUG_ON(sizeof(*a) != sizeof(*b));		\
+		if (op == CR_CPT)				\
+			memcpy(a, b, count * sizeof(*a));	\
+		else						\
+			memcpy(b, a, count * sizeof(*a));	\
+	} while (0);
+

You might want to employ __must_be_array() or similar to catch misuse.

Misuse might also be prevented by providing some documentation :)

author
#15 lore raw

Re: [PATCH 2/3] c/r: Add CR_COPY() macro (v3)

NL> Drop the semicolon ^

Thanks.

NL> You might want to employ __must_be_array() or similar to catch NL> misuse.

Ooh, nice.

NL> Misuse might also be prevented by providing some documentation :)

Agreed.

Thanks!

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: [email protected]
author
#16 lore raw

PATCH 3/3 c/r: define s390-specific checkpoint-restart code (v7)

In reply to Dan Smith

Implement the s390 arch-specific checkpoint/restart helpers. This is on top of Oren Laadan's c/r code.

With these, I am able to checkpoint and restart simple programs as per Oren's patch intro. While on x86 I never had to freeze a single task to checkpoint it, on s390 I do need to. That is a prereq for consistent snapshots (esp with multiple processes) anyway so I don't see that as a problem.

Changelog:
Feb 27:
. Add checkpoint_s390.h
. Fixed up save and restore of PSW, with the non-address bits
properly masked out
Feb 25:
. Make checkpoint_hdr.h safe for inclusion in userspace . Replace comment about vsdo code
. Add comment about restoring access registers
. Write and read an empty cr_hdr_head_arch record to appease
code (mktree) that expects it to be there
. Utilize NUM_CR_WORDS in checkpoint_hdr.h
Feb 24:
. Use CR_COPY() to unify the un/loading of cpu and mm state . Fix fprs definition in cr_hdr_cpu
. Remove debug WARN_ON() from checkpoint.c
Feb 23:
. Macro-ize the un/packing of trace flags
. Fix the crash when externally-linked
. Break out the restart functions into restart.c . Remove unneeded s390_enable_sie() call
Jan 30:
. Switched types in cr_hdr_cpu to __u64 etc.
(Per Oren suggestion)
. Replaced direct inclusion of structs in
cr_hdr_cpu with the struct members.
(Per Oren suggestion)
. Also ended up adding a bunch of new things
into restart (mm_segment, ksp, etc) in vain attempt to get code using fpu to not segfault after restart.

---
 arch/s390/include/asm/checkpoint_hdr.h |   88 ++++++++++++++++++++++
 arch/s390/include/asm/unistd.h         |    4 +-
 arch/s390/kernel/compat_wrapper.S      |   12 +++
 arch/s390/kernel/syscalls.S            |    2 +
 arch/s390/mm/Makefile                  |    1 +
 arch/s390/mm/checkpoint.c              |  125 ++++++++++++++++++++++++++++++++
 arch/s390/mm/checkpoint_s390.h         |   22 ++++++
 arch/s390/mm/restart.c                 |   81 +++++++++++++++++++++
 checkpoint/Kconfig                     |    2 +-
 9 files changed, 335 insertions(+), 2 deletions(-)
 create mode 100644 arch/s390/include/asm/checkpoint_hdr.h
 create mode 100644 arch/s390/mm/checkpoint.c
 create mode 100644 arch/s390/mm/checkpoint_s390.h
 create mode 100644 arch/s390/mm/restart.c
arch/s390/include/asm/checkpoint_hdr.h new file +88 -0
new file mode 100644
index 0000000..0a405c2
@@ -0,0 +1,88 @@
+#ifndef __ASM_S390_CKPT_HDR_H
+#define __ASM_S390_CKPT_HDR_H
+/*
+ *  Checkpoint/restart - architecture specific headers s/390
+ *
+ *  Copyright IBM Corp. 2009
+ *
+ *  This file is subject to the terms and conditions of the GNU General Public
+ *  License.  See the file COPYING in the main directory of the Linux
+ *  distribution for more details.
+ */
+
+#include <linux/types.h>
+#include <asm/ptrace.h>
+
+#ifdef __KERNEL__
+#include <asm/processor.h>
+#else
+#include <sys/user.h>
+#endif
+
+#ifdef __s390x__
+
+/*
+ * Notes
+ * NUM_GPRS defined in <asm/ptrace.h> to be 16
+ * NUM_FPRS defined in <asm/ptrace.h> to be 16
+ * NUM_APRS defined in <asm/ptrace.h> to be 16
+ * NUM_CR_WORDS defined in <asm/ptrace.h> to be 3
+ */
+struct cr_hdr_cpu {
+	__u64 args[1];
+	__u64 gprs[NUM_GPRS];
+	__u64 orig_gpr2;
+	__u16 svcnr;
+	__u16 ilc;
+	__u32 acrs[NUM_ACRS];
+	__u64 ieee_instruction_pointer;
+
+	/* psw_t */
+	__u64 psw_t_mask;
+	__u64 psw_t_addr;
+
+	/* s390_fp_regs_t */
+	__u32 fpc;
+	union {
+		float f;
+		double d;
+		__u64 ui;
+		struct {
+			__u32 fp_hi;
+			__u32 fp_lo;
+		} fp;
+	} fprs[NUM_FPRS];
+
+	/* per_struct */
+	__u64 per_control_regs[NUM_CR_WORDS];
+	__u64 starting_addr;
+	__u64 ending_addr;
+	__u64 address;
+	__u16 perc_atmid;
+	__u8 access_id;
+	__u8 single_step;
+	__u8 instruction_fetch;
+};
+
+struct cr_hdr_mm_context {
+	unsigned long vdso_base;
+	int noexec;
+	int has_pgste;
+	int alloc_pgste;
+	unsigned long asce_bits;
+	unsigned long asce_limit;
+};
+
+struct cr_hdr_head_arch {
+};
+
+#ifdef __KERNEL__
+/* Functions for copying to/from the header structs */
+extern void cr_s390_regs(int op, struct cr_hdr_cpu *hh, struct task_struct *t);
+extern void cr_s390_mm(int op, struct cr_hdr_mm_context *hh,
+		       struct mm_struct *mm);
+#endif
+
+#endif /* __s390x__ */
+
+#endif /* __ASM_S390_CKPT_HDR__H */
arch/s390/include/asm/unistd.h +3 -1
index c8ad350..ffe64a0 100644
@@ -265,7 +265,9 @@
 #define __NR_pipe2		325
 #define __NR_dup3		326
 #define __NR_epoll_create1	327
-#define NR_syscalls 328
+#define __NR_checkpoint		328
+#define __NR_restart		329
+#define NR_syscalls 330
 
 /* 
  * There are some system calls that are not present on 64 bit, some
arch/s390/kernel/compat_wrapper.S +12 -0
index fc2c971..9546a81 100644
@@ -1767,3 +1767,15 @@ sys_dup3_wrapper:
 sys_epoll_create1_wrapper:
 	lgfr	%r2,%r2			# int
 	jg	sys_epoll_create1	# branch to system call
+
+	.globl sys_checkpoint_wrapper
+sys_checkpoint_wrapper:
+	lgfr	%r2,%r2			# pid_t
+	lgfr	%r3,%r3			# int
+	llgfr	%r4,%r4			# unsigned long
+
+	.globl sys_restart_wrapper
+sys_restart_wrapper:
+	lgfr	%r2,%r2			# int
+	lgfr	%r3,%r3			# int
+	llgfr	%r4,%r4			# unsigned long
arch/s390/kernel/syscalls.S +2 -0
index 2d61787..54316c8 100644
@@ -336,3 +336,5 @@ SYSCALL(sys_inotify_init1,sys_inotify_init1,sys_inotify_init1_wrapper)
 SYSCALL(sys_pipe2,sys_pipe2,sys_pipe2_wrapper) /* 325 */
 SYSCALL(sys_dup3,sys_dup3,sys_dup3_wrapper)
 SYSCALL(sys_epoll_create1,sys_epoll_create1,sys_epoll_create1_wrapper)
+SYSCALL(sys_checkpoint,sys_checkpoint,sys_checkpoint_wrapper)
+SYSCALL(sys_restart,sys_restart,sys_restart_wrapper)
arch/s390/mm/Makefile +1 -0
index 2a74581..040fbb7 100644
@@ -6,3 +6,4 @@ obj-y	 := init.o fault.o extmem.o mmap.o vmem.o pgtable.o
 obj-$(CONFIG_CMM) += cmm.o
 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
 obj-$(CONFIG_PAGE_STATES) += page-states.o
+obj-$(CONFIG_CHECKPOINT_RESTART) += checkpoint.o restart.o
arch/s390/mm/checkpoint.c new file +125 -0

125 lines not on this page · raw message

arch/s390/mm/checkpoint_s390.h new file +22 -0
new file mode 100644
index 0000000..52a5e6f
@@ -0,0 +1,22 @@
+/*
+ *  Checkpoint/restart - architecture specific support for s390
+ *
+ *  Copyright IBM Corp. 2009
+ *
+ *  This file is subject to the terms and conditions of the GNU General Public
+ *  License.  See the file COPYING in the main directory of the Linux
+ *  distribution for more details.
+ */
+
+#ifndef _S390_CHECKPOINT_H
+#define _S390_CHECKPOINT_H
+
+#include <linux/checkpoint_hdr.h>
+#include <linux/sched.h>
+#include <linux/mm_types.h>
+
+extern void cr_s390_regs(int op, struct cr_hdr_cpu *hh, struct task_struct *t);
+extern void cr_s390_mm(int op, struct cr_hdr_mm_context *hh,
+		       struct mm_struct *mm);
+
+#endif /* _S390_CHECKPOINT_H */
arch/s390/mm/restart.c new file +81 -0

81 lines not on this page · raw message

checkpoint/Kconfig +1 -1
index ffaa635..cb1d29d 100644
@@ -1,7 +1,7 @@
 config CHECKPOINT_RESTART
 	prompt "Enable checkpoint/restart (EXPERIMENTAL)"
 	def_bool n
-	depends on X86_32 && EXPERIMENTAL
+	depends on (X86_32 || (S390 && 64BIT)) && EXPERIMENTAL
 	help
 	  Application checkpoint/restart is the ability to save the
 	  state of a running application so that it can later resume
Signature · 1 line
1.6.1
#17 lore raw

Re: [PATCH 3/3] c/r: define s390-specific checkpoint-restart code (v7)

Quoted 2 lines · Dan Smith

Implement the s390 arch-specific checkpoint/restart helpers. This is on top of Oren Laadan's c/r code.

Working nicely for me, thanks.

-serge