[CRIU] [PATCH 1/2] mem: add a guard page only if here is enough space for it

Andrey Vagin avagin at openvz.org
Mon May 5 03:50:27 PDT 2014


Currently we don't add a guard page to a second consecutive growsdonw vma,
even if here is enough space for it. It's wrong. Look at the following test
output:

Execute zdtm/live/static/grow_map03
./grow_map03 --pidfile=grow_map03.pid --outfile=grow_map03.out
Dump 3888
Restore
Test: zdtm/live/static/grow_map03, Result: FAIL
==================================== ERROR ====================================
Test: zdtm/live/static/grow_map03, Namespace:
Dump log   : /root/git/criu/test/dump/grow_map03/3888/1/dump.log
--------------------------------- grep Error ---------------------------------
------------------------------------- END -------------------------------------
Restore log: /root/git/criu/test/dump/grow_map03/3888/1/restore.log
--------------------------------- grep Error ---------------------------------
pie: Error (pie/restorer.c:465): Unable to remap 0x7f0da2c99000 -> 0x7f46425fc000
pie: Error (pie/restorer.c:969): Restorer fail 3888
(00.035621) Error (cr-restore.c:1590): Restoring FAILED.
------------------------------------- END -------------------------------------
================================= ERROR OVER =================================

strace:
mremap(0x7fc3de5b6000, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, 0x7f38dd4e0000) = -1 EINVAL (Invalid argument)

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 proc_parse.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/proc_parse.c b/proc_parse.c
index 26686d4..340ef7d 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -272,8 +272,7 @@ static char smaps_buf[PAGE_SIZE];
 int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_files)
 {
 	struct vma_area *vma_area = NULL;
-	unsigned long start, end, pgoff;
-	bool prev_growsdown = false;
+	unsigned long start, end, pgoff, prev_end = 0;
 	char r, w, x, s;
 	int ret = -1;
 	struct vma_file_info vfi;
@@ -327,10 +326,11 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_file
 		}
 
 		if (vma_area) {
-			/* If we've split the stack vma, only the lowest one has the guard page. */
-			if ((vma_area->e->flags & MAP_GROWSDOWN) && !prev_growsdown)
+			/* Add a guard page only if here is enough space for it */
+			if ((vma_area->e->flags & MAP_GROWSDOWN) &&
+			    prev_end < vma_area->e->start)
 				vma_area->e->start -= PAGE_SIZE; /* Guard page */
-			prev_growsdown = (bool)(vma_area->e->flags & MAP_GROWSDOWN);
+			prev_end = vma_area->e->end;
 
 			list_add_tail(&vma_area->list, &vma_area_list->h);
 			vma_area_list->nr++;
-- 
1.8.5.3



More information about the CRIU mailing list