[CRIU] [PATCH 2/2] proc: use vma flags for determing vmas with MAP_GROWSDOWN

Andrey Vagin avagin at openvz.org
Tue May 21 06:37:53 EDT 2013


When a kernel didn't show vma flags, we set MAP_GROWSDOWN for stack
vmas, but it's not reliable. E.g. thread stacks are mapped without
MAP_GROWSDOWN.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c      |  2 --
 cr-restore.c   |  3 ---
 include/util.h |  2 --
 proc_parse.c   |  5 +++--
 util.c         | 20 --------------------
 5 files changed, 3 insertions(+), 29 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 3ef53e2..64f8dd1 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -694,8 +694,6 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
 	if (ret)
 		goto err_free;
 
-	mark_stack_vma(CORE_THREAD_ARCH_INFO(core)->gpregs->sp, &vma_area_list->h);
-
 	ret = get_task_futex_robust_list(pid, core->thread_core);
 	if (ret)
 		goto err_free;
diff --git a/cr-restore.c b/cr-restore.c
index c76eed8..f7ff81d 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1799,9 +1799,6 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 	if (ret < 0)
 		goto err;
 
-	/* required to unmap stack _with_ guard page */
-	mark_stack_vma((long) &self_vmas, &self_vmas.h);
-
 	self_vmas_len = round_up((self_vmas.nr + 1) * sizeof(VmaEntry), PAGE_SIZE);
 	vmas_len = round_up((rst_vmas.nr + 1) * sizeof(VmaEntry), PAGE_SIZE);
 
diff --git a/include/util.h b/include/util.h
index 1b466c0..e8d0231 100644
--- a/include/util.h
+++ b/include/util.h
@@ -133,8 +133,6 @@ extern void pr_vma(unsigned int loglevel, const struct vma_area *vma_area);
 		p__;						\
 	})
 
-extern void mark_stack_vma(unsigned long sp, struct list_head *vma_area_list);
-
 extern int move_img_fd(int *img_fd, int want_fd);
 extern int close_safe(int *fd);
 
diff --git a/proc_parse.c b/proc_parse.c
index 497d172..1c2ba2d 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -96,9 +96,10 @@ static int parse_vmflags(char *buf, struct vma_area *vma_area)
 
 	do {
 		/* mmap() block */
-		if (_vmflag_match(tok, "gd"))
+		if (_vmflag_match(tok, "gd")) {
 			vma_area->vma.flags |= MAP_GROWSDOWN;
-		else if (_vmflag_match(tok, "lo"))
+			vma_area->vma.start -= PAGE_SIZE; /* Guard page */
+		} else if (_vmflag_match(tok, "lo"))
 			vma_area->vma.flags |= MAP_LOCKED;
 		else if (_vmflag_match(tok, "nr"))
 			vma_area->vma.flags |= MAP_NORESERVE;
diff --git a/util.c b/util.c
index 3052d00..69ecf5d 100644
--- a/util.c
+++ b/util.c
@@ -36,26 +36,6 @@
 
 #include "crtools.h"
 
-/* /proc/PID/maps can contain not up to date information about stack */
-void mark_stack_vma(unsigned long sp, struct list_head *vma_area_list)
-{
-	struct vma_area *vma_area;
-	list_for_each_entry(vma_area, vma_area_list, list) {
-		if (in_vma_area(vma_area, sp)) {
-			vma_area->vma.status |= VMA_AREA_STACK;
-			vma_area->vma.flags  |= MAP_GROWSDOWN;
-
-			/*
-			 * The kernel doesn't show stack guard pages on
-			 * proc output, so add pages here by hands.
-			 */
-			vma_area->vma.start -= PAGE_SIZE;
-			return;
-		}
-	}
-	BUG();
-}
-
 #define VMA_OPT_LEN	128
 
 static void vma_opt_str(const struct vma_area *v, char *opt)
-- 
1.8.2



More information about the CRIU mailing list