[CRIU] [PATCH 1/9] parasite: Make parasite arguments variable size

Pavel Emelyanov xemul at parallels.com
Fri Mar 1 11:02:20 EST 2013


Sometimes we don't know the exact amount of data we would want
to send to parasite via args area (e.g. -- while draining fds).

Fix this, by moving the args area behind the parasite blob and
mmap-ing it with the run-time calculated size.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>

---
 arch/arm/parasite-head.S   |  2 --
 arch/x86/parasite-head.S   |  3 ---
 include/parasite-syscall.h |  1 +
 include/parasite.h         |  2 +-
 parasite-syscall.c         | 12 +++++++++---
 pie/gen-offsets.sh         |  2 +-
 pie/pie.lds.S.in           |  2 ++
 7 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/arch/arm/parasite-head.S b/arch/arm/parasite-head.S
index b4bffe6..74fd4cb 100644
--- a/arch/arm/parasite-head.S
+++ b/arch/arm/parasite-head.S
@@ -13,8 +13,6 @@ ENTRY(__export_parasite_head_start)
 __export_parasite_cmd:
 	.long 0
 __export_parasite_args:
-	.long 0
-	.space PARASITE_ARG_SIZE,0
 	.space PARASITE_STACK_SIZE,0
 
         .space 228, 0
diff --git a/arch/x86/parasite-head.S b/arch/x86/parasite-head.S
index 289672c..0b62750 100644
--- a/arch/x86/parasite-head.S
+++ b/arch/x86/parasite-head.S
@@ -15,9 +15,6 @@ ENTRY(__export_parasite_head_start)
 	.align 8
 __export_parasite_cmd:
 	.long 0
-__export_parasite_args:
-	.long 0
-	.space PARASITE_ARG_SIZE,0
 	.space PARASITE_STACK_SIZE,0
 __export_parasite_stack:
 	.long 0
diff --git a/include/parasite-syscall.h b/include/parasite-syscall.h
index 2f32d03..ee5743e 100644
--- a/include/parasite-syscall.h
+++ b/include/parasite-syscall.h
@@ -19,6 +19,7 @@ struct parasite_ctl {
 
 	unsigned int		*addr_cmd;				/* addr for command */
 	void			*addr_args;				/* address for arguments */
+	unsigned long		args_size;
 	int			tsock;					/* transport socket for transfering fds */
 };
 
diff --git a/include/parasite.h b/include/parasite.h
index 5d5b8df..66a559e 100644
--- a/include/parasite.h
+++ b/include/parasite.h
@@ -2,7 +2,7 @@
 #define __CR_PARASITE_H__
 
 #define PARASITE_STACK_SIZE	(16 << 10)
-#define PARASITE_ARG_SIZE	8196
+#define PARASITE_ARG_SIZE_MIN	( 1 << 13)
 
 #define PARASITE_MAX_SIZE	(64 << 10)
 
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 6cc6283..03b5546 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -184,12 +184,12 @@ err:
 
 static void *parasite_args_s(struct parasite_ctl *ctl, int args_size)
 {
-	BUG_ON(args_size > PARASITE_ARG_SIZE);
+	BUG_ON(args_size > ctl->args_size);
 	return ctl->addr_args;
 }
 
 #define parasite_args(ctl, type) ({				\
-		BUILD_BUG_ON(sizeof(type) > PARASITE_ARG_SIZE);	\
+		BUILD_BUG_ON(sizeof(type) > PARASITE_ARG_SIZE_MIN);\
 		ctl->addr_args;					\
 	})
 
@@ -794,6 +794,11 @@ int parasite_map_exchange(struct parasite_ctl *ctl, unsigned long size)
 	return 0;
 }
 
+static unsigned long parasite_args_size(void)
+{
+	return PARASITE_ARG_SIZE_MIN;
+}
+
 struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item, struct list_head *vma_area_list)
 {
 	int ret;
@@ -810,7 +815,8 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
 	 * without using ptrace at all.
 	 */
 
-	ret = parasite_map_exchange(ctl, parasite_size);
+	ctl->args_size = parasite_args_size();
+	ret = parasite_map_exchange(ctl, parasite_size + ctl->args_size);
 	if (ret)
 		goto err_restore;
 
diff --git a/pie/gen-offsets.sh b/pie/gen-offsets.sh
index 6383c6a..99af519 100644
--- a/pie/gen-offsets.sh
+++ b/pie/gen-offsets.sh
@@ -11,7 +11,7 @@ BLOB=${NAME}_blob
 OBJNAME=${FILE}.built-in.bin.o
 BINARY=${FILE}.built-in.bin
 
-AWK_CMD='$2 ~ /^[tT]$/ { print "#define '$PREFIX'" $3 " 0x" $1; }'
+AWK_CMD='$2 ~ /^[tTA]$/ { print "#define '$PREFIX'" $3 " 0x" $1; }'
 
 cat << EOF
 /* Autogenerated by $0, do not edit */
diff --git a/pie/pie.lds.S.in b/pie/pie.lds.S.in
index 29fef54..7be2eda 100644
--- a/pie/pie.lds.S.in
+++ b/pie/pie.lds.S.in
@@ -21,3 +21,5 @@ SECTIONS
 		*(*)
 	}
 }
+
+__export_parasite_args = .;
-- 
1.7.11.7


More information about the CRIU mailing list