[CRIU] [PATCH] rst: Lock rst memory allocations earlier

Pavel Emelyanov xemul at parallels.com
Thu Jun 25 07:06:51 PDT 2015


After we got the total remapable rst memory size, we no longer
can allocate from it, otherwise the bootstrap area will not
have enough size.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cr-restore.c         |  9 +++++----
 include/rst-malloc.h |  2 +-
 rst-malloc.c         | 12 +++++++++---
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index dd23488..31980bc 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -2640,6 +2640,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 	long ret;
 
 	long restore_bootstrap_len;
+	long rst_mem_size;
 
 	struct task_restore_args *task_args;
 	struct thread_restore_args *thread_args;
@@ -2735,8 +2736,8 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 	if (ret < 0)
 		goto err;
 
-	restore_bootstrap_len = restorer_len + args_len +
-				rst_mem_remap_size();
+	rst_mem_size = rst_mem_lock();
+	restore_bootstrap_len = restorer_len + args_len + rst_mem_size;
 
 #ifdef CONFIG_VDSO
 	/*
@@ -2856,7 +2857,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 	task_args->task_entries = rst_mem_remap_ptr(task_entries_pos, RM_SHREMAP);
 
 	task_args->rst_mem = mem;
-	task_args->rst_mem_size = rst_mem_remap_size();
+	task_args->rst_mem_size = rst_mem_size;
 
 	task_args->bootstrap_start = (void *)exec_mem_hint;
 	task_args->bootstrap_len = restore_bootstrap_len;
@@ -2973,7 +2974,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 	 * since we need it being accessible even when own
 	 * self-vmas are unmaped.
 	 */
-	mem += rst_mem_remap_size();
+	mem += rst_mem_size;
 	task_args->vdso_rt_parked_at = (unsigned long)mem + vdso_rt_delta;
 	task_args->vdso_sym_rt = vdso_sym_rt;
 	task_args->vdso_rt_size = vdso_rt_size;
diff --git a/include/rst-malloc.h b/include/rst-malloc.h
index 75d0d3f..8c48f27 100644
--- a/include/rst-malloc.h
+++ b/include/rst-malloc.h
@@ -62,7 +62,7 @@ extern void rst_mem_free_last(int type);
 /*
  * Routines to remap SHREMAP and PRIVATE into restorer address space
  */
-extern unsigned long rst_mem_remap_size(void);
+extern unsigned long rst_mem_lock(void);
 extern int rst_mem_remap(void *to);
 
 #endif /* __CR_RST_MALLOC__H__ */
diff --git a/rst-malloc.c b/rst-malloc.c
index aecefea..215290f 100644
--- a/rst-malloc.c
+++ b/rst-malloc.c
@@ -169,8 +169,15 @@ void rst_mem_free_last(int type)
 	t->last = 0; /* next free_last would be no-op */
 }
 
-unsigned long rst_mem_remap_size(void)
+unsigned long rst_mem_lock(void)
 {
+	/*
+	 * Don't allow further allocations from rst_mem since we're
+	 * going to get the bootstrap area and remap all the stuff
+	 * into it. The SHREMAP and SHARED should be already locked
+	 * in the rst_mem_switch_to_private().
+	 */
+	rst_mems[RM_PRIVATE].enabled = false;
 	return rst_mems[RM_PRIVATE].size + rst_mems[RM_SHREMAP].size;
 }
 
@@ -178,7 +185,7 @@ static int rst_mem_remap_one(struct rst_mem_type_s *t, void *to)
 {
 	void *aux;
 
-	BUG_ON(!t->remapable);
+	BUG_ON(!t->remapable || t->enabled);
 
 	if (!t->buf)
 		/*
@@ -196,7 +203,6 @@ static int rst_mem_remap_one(struct rst_mem_type_s *t, void *to)
 	}
 
 	t->buf = aux;
-	t->enabled = false;
 	return 0;
 }
 
-- 
1.9.3



More information about the CRIU mailing list