72b139
From be37925cff8aaf43f14866bd0a60dca6068a8d97 Mon Sep 17 00:00:00 2001
72b139
From: Cyrill Gorcunov <gorcunov@openvz.org>
72b139
Date: Mon, 26 Jun 2017 23:55:29 +0300
72b139
Subject: [PATCH 2/2] mem: Don't assume guard page is returned in procfs with
72b139
 new kernels
72b139
72b139
If the guard page is not reported in show_map_vma we should
72b139
not ajust vma address neither we should call unmap_guard_pages
72b139
in restorer.
72b139
72b139
https://github.com/xemul/criu/issues/322
72b139
72b139
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
72b139
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
72b139
---
72b139
 criu/include/mem.h |  2 ++
72b139
 criu/mem.c         | 19 ++++++++++++++-----
72b139
 criu/proc_parse.c  |  3 ++-
72b139
 3 files changed, 18 insertions(+), 6 deletions(-)
72b139
72b139
diff --git a/criu/include/mem.h b/criu/include/mem.h
72b139
index 2fae797c6..2fc8e1e0e 100644
72b139
--- a/criu/include/mem.h
72b139
+++ b/criu/include/mem.h
72b139
@@ -9,11 +9,13 @@ struct parasite_ctl;
72b139
 struct vm_area_list;
72b139
 struct page_pipe;
72b139
 struct pstree_item;
72b139
+struct vma_area;
72b139
 
72b139
 struct mem_dump_ctl {
72b139
 	bool	pre_dump;
72b139
 };
72b139
 
72b139
+extern bool vma_has_guard_gap_hidden(struct vma_area *vma);
72b139
 extern bool page_in_parent(bool dirty);
72b139
 extern int prepare_mm_pid(struct pstree_item *i);
72b139
 extern int do_task_reset_dirty_track(int pid);
72b139
diff --git a/criu/mem.c b/criu/mem.c
72b139
index 2c4323d8c..cd41829b2 100644
72b139
--- a/criu/mem.c
72b139
+++ b/criu/mem.c
72b139
@@ -499,7 +499,7 @@ int prepare_mm_pid(struct pstree_item *i)
72b139
 
72b139
 		if (vma_area_is_private(vma, kdat.task_size)) {
72b139
 			ri->vmas.priv_size += vma_area_len(vma);
72b139
-			if (vma->e->flags & MAP_GROWSDOWN)
72b139
+			if (vma_has_guard_gap_hidden(vma))
72b139
 				ri->vmas.priv_size += PAGE_SIZE;
72b139
 		}
72b139
 
72b139
@@ -634,7 +634,7 @@ static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void
72b139
 	 * A grow-down VMA has a guard page, which protect a VMA below it.
72b139
 	 * So one more page is mapped here to restore content of the first page
72b139
 	 */
72b139
-	if (vma->e->flags & MAP_GROWSDOWN) {
72b139
+	if (vma_has_guard_gap_hidden(vma)) {
72b139
 		vma->e->start -= PAGE_SIZE;
72b139
 		if (paddr)
72b139
 			paddr -= PAGE_SIZE;
72b139
@@ -702,7 +702,7 @@ static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void
72b139
 	pr_debug("\tpremap %#016"PRIx64"-%#016"PRIx64" -> %016lx\n",
72b139
 		vma->e->start, vma->e->end, (unsigned long)addr);
72b139
 
72b139
-	if (vma->e->flags & MAP_GROWSDOWN) { /* Skip gurad page */
72b139
+	if (vma_has_guard_gap_hidden(vma)) { /* Skip gurad page */
72b139
 		vma->e->start += PAGE_SIZE;
72b139
 		vma->premmaped_addr += PAGE_SIZE;
72b139
 	}
72b139
@@ -1046,6 +1047,11 @@ out:
72b139
 	return ret;
72b139
 }
72b139
 
72b139
+bool vma_has_guard_gap_hidden(struct vma_area *vma)
72b139
+{
72b139
+	return kdat.stack_guard_gap_hidden && (vma->e->flags & MAP_GROWSDOWN);
72b139
+}
72b139
+
72b139
 /*
72b139
  * A gard page must be unmapped after restoring content and
72b139
  * forking children to restore COW memory.
72b139
@@ -1055,6 +1061,9 @@ int unmap_guard_pages(struct pstree_item *t)
72b139
 	struct vma_area *vma;
72b139
 	struct list_head *vmas = &rsti(t)->vmas.h;
72b139
 
72b139
+	if (!kdat.stack_guard_gap_hidden)
72b139
+		return 0;
72b139
+
72b139
 	list_for_each_entry(vma, vmas, list) {
72b139
 		if (!vma_area_is_private(vma, kdat.task_size))
72b139
 			continue;
72b139
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
72b139
index f1237cf9f..5e36db540 100644
72b139
--- a/criu/proc_parse.c
72b139
+++ b/criu/proc_parse.c
72b139
@@ -25,6 +25,7 @@
72b139
 #include "kerndat.h"
72b139
 #include "vdso.h"
72b139
 #include "vma.h"
72b139
+#include "mem.h"
72b139
 #include "bfd.h"
72b139
 #include "proc_parse.h"
72b139
 #include "fdinfo.h"
72b139
@@ -637,7 +638,7 @@ static int vma_list_add(struct vma_area *vma_area,
72b139
 	}
72b139
 
72b139
 	/* Add a guard page only if here is enough space for it */
72b139
-	if ((vma_area->e->flags & MAP_GROWSDOWN) &&
72b139
+	if (vma_has_guard_gap_hidden(vma_area) &&
72b139
 	    *prev_end < vma_area->e->start)
72b139
 		vma_area->e->start -= PAGE_SIZE; /* Guard page */
72b139
 	*prev_end = vma_area->e->end;
72b139
-- 
72b139
2.13.0
72b139