[CRIU] [PATCH 1/6] compel: add APIs to get stack pointers

Mike Rapoport rppt at linux.vnet.ibm.com
Mon Aug 13 16:29:08 MSK 2018


We need to know what are stack pointers of every thread to ensure that the
current stack page will not be treated as lazy.

Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
 compel/arch/aarch64/src/lib/include/uapi/asm/infect-types.h |  1 +
 compel/arch/arm/src/lib/include/uapi/asm/infect-types.h     |  1 +
 compel/arch/ppc64/src/lib/include/uapi/asm/infect-types.h   |  1 +
 compel/arch/s390/src/lib/include/uapi/asm/infect-types.h    |  1 +
 compel/arch/x86/src/lib/include/uapi/asm/infect-types.h     |  1 +
 compel/include/uapi/infect.h                                |  3 +++
 compel/src/lib/infect.c                                     | 10 ++++++++++
 7 files changed, 18 insertions(+)

diff --git a/compel/arch/aarch64/src/lib/include/uapi/asm/infect-types.h b/compel/arch/aarch64/src/lib/include/uapi/asm/infect-types.h
index eeb68be..4662f76 100644
--- a/compel/arch/aarch64/src/lib/include/uapi/asm/infect-types.h
+++ b/compel/arch/aarch64/src/lib/include/uapi/asm/infect-types.h
@@ -20,6 +20,7 @@ typedef struct user_fpsimd_state	user_fpregs_struct_t;
 
 #define REG_RES(r)			((uint64_t)(r).regs[0])
 #define REG_IP(r)			((uint64_t)(r).pc)
+#define REG_SP(r)			((uint64_t)((r).sp))
 #define REG_SYSCALL_NR(r)		((uint64_t)(r).regs[8])
 
 #define user_regs_native(pregs)			true
diff --git a/compel/arch/arm/src/lib/include/uapi/asm/infect-types.h b/compel/arch/arm/src/lib/include/uapi/asm/infect-types.h
index 03442ee..b8286d4 100644
--- a/compel/arch/arm/src/lib/include/uapi/asm/infect-types.h
+++ b/compel/arch/arm/src/lib/include/uapi/asm/infect-types.h
@@ -54,6 +54,7 @@ struct user_vfp_exc {
 
 #define REG_RES(regs)		((regs).ARM_r0)
 #define REG_IP(regs)		((regs).ARM_pc)
+#define REG_SP(regs)		((regs).ARM_sp)
 #define REG_SYSCALL_NR(regs)	((regs).ARM_r7)
 
 #define user_regs_native(pregs)			true
diff --git a/compel/arch/ppc64/src/lib/include/uapi/asm/infect-types.h b/compel/arch/ppc64/src/lib/include/uapi/asm/infect-types.h
index 4b8a200..89fc4aa 100644
--- a/compel/arch/ppc64/src/lib/include/uapi/asm/infect-types.h
+++ b/compel/arch/ppc64/src/lib/include/uapi/asm/infect-types.h
@@ -74,6 +74,7 @@ typedef struct {
 
 #define REG_RES(regs)		((uint64_t)(regs).gpr[3])
 #define REG_IP(regs)		((uint64_t)(regs).nip)
+#define REG_SP(regs)		((uint64_t)(regs).gpr[1])
 #define REG_SYSCALL_NR(regs)	((uint64_t)(regs).gpr[0])
 
 #define user_regs_native(pregs)			true
diff --git a/compel/arch/s390/src/lib/include/uapi/asm/infect-types.h b/compel/arch/s390/src/lib/include/uapi/asm/infect-types.h
index 9386998..fddf65d 100644
--- a/compel/arch/s390/src/lib/include/uapi/asm/infect-types.h
+++ b/compel/arch/s390/src/lib/include/uapi/asm/infect-types.h
@@ -64,6 +64,7 @@ typedef struct {
 
 #define REG_RES(r)			((uint64_t)(r).prstatus.gprs[2])
 #define REG_IP(r)			((uint64_t)(r).prstatus.psw.addr)
+#define REG_SP(r)			((uint64_t)(r).prstatus.gprs[15])
 /*
  * We assume that REG_SYSCALL_NR() is only used for pie code where we
  * always use svc 0 with opcode in %r1.
diff --git a/compel/arch/x86/src/lib/include/uapi/asm/infect-types.h b/compel/arch/x86/src/lib/include/uapi/asm/infect-types.h
index af42461..e6d3949 100644
--- a/compel/arch/x86/src/lib/include/uapi/asm/infect-types.h
+++ b/compel/arch/x86/src/lib/include/uapi/asm/infect-types.h
@@ -111,6 +111,7 @@ typedef struct xsave_struct user_fpregs_struct_t;
 
 #define REG_RES(regs)		get_user_reg(&regs, ax)
 #define REG_IP(regs)		get_user_reg(&regs, ip)
+#define REG_SP(regs)		get_user_reg(&regs, sp)
 #define REG_SYSCALL_NR(regs)	get_user_reg(&regs, orig_ax)
 
 #define __NR(syscall, compat)	((compat) ? __NR32_##syscall : __NR_##syscall)
diff --git a/compel/include/uapi/infect.h b/compel/include/uapi/infect.h
index f087f21..3b98f2d 100644
--- a/compel/include/uapi/infect.h
+++ b/compel/include/uapi/infect.h
@@ -165,4 +165,7 @@ extern void compel_relocs_apply(void *mem, void *vbase, size_t size, compel_relo
 
 extern unsigned long compel_task_size(void);
 
+extern uint64_t compel_get_leader_sp(struct parasite_ctl *ctl);
+extern uint64_t compel_get_thread_sp(struct parasite_thread_ctl *tctl);
+
 #endif
diff --git a/compel/src/lib/infect.c b/compel/src/lib/infect.c
index d51b8aa..4648e39 100644
--- a/compel/src/lib/infect.c
+++ b/compel/src/lib/infect.c
@@ -1585,3 +1585,13 @@ struct parasite_blob_desc *compel_parasite_blob_desc(struct parasite_ctl *ctl)
 {
 	return &ctl->pblob;
 }
+
+uint64_t compel_get_leader_sp(struct parasite_ctl *ctl)
+{
+	return REG_SP(ctl->orig.regs);
+}
+
+uint64_t compel_get_thread_sp(struct parasite_thread_ctl *tctl)
+{
+	return REG_SP(tctl->th.regs);
+}
-- 
2.7.4



More information about the CRIU mailing list