[CRIU] [PATCH] util: return aligned pointers from shmalloc()

Andrey Vagin avagin at openvz.org
Fri Apr 1 10:40:59 PDT 2016


From: Andrew Vagin <avagin at virtuozzo.com>

Atomic operations doesn't work for non-aligned pointers.

=[log]=> dump/zdtm/static/autofs/30/2/restore.log
------------------------ grep Error ------------------------
(00.185037)      5: Error (/root/git/criu/criu/include/lock.h:78): BUG at /root/git/criu/criu/include/lock.h:78
(00.207193) Error (cr-restore.c:1407): 100 killed by signal 9: Killed
(00.219187) Error (cr-restore.c:2237): Restoring FAILED.
------------------------ ERROR OVER ------------------------

4339  futex(0x7fa79c1561da, FUTEX_WAKE, 2147483647 <unfinished ...>
4339  <... futex resumed> )             = -1 EINVAL (Invalid argument)

Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 criu/rst-malloc.c | 11 +++++++++--
 criu/util.c       |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/criu/rst-malloc.c b/criu/rst-malloc.c
index 2702efd..b6e0572 100644
--- a/criu/rst-malloc.c
+++ b/criu/rst-malloc.c
@@ -124,15 +124,22 @@ void rst_mem_switch_to_private(void)
 	rst_mems[RM_PRIVATE].enabled = true;
 }
 
-unsigned long rst_mem_align_cpos(int type)
+void rst_mem_align(int type)
 {
 	struct rst_mem_type_s *t = &rst_mems[type];
-	BUG_ON(!t->remapable || !t->enabled);
 	void *ptr;
 
 	ptr = (void *) round_up((unsigned long)t->free_mem, sizeof(void *));
 	t->free_bytes -= (ptr - t->free_mem);
 	t->free_mem = ptr;
+}
+
+unsigned long rst_mem_align_cpos(int type)
+{
+	struct rst_mem_type_s *t = &rst_mems[type];
+	BUG_ON(!t->remapable || !t->enabled);
+
+	rst_mem_align(type);
 
 	return t->free_mem - t->buf;
 }
diff --git a/criu/util.c b/criu/util.c
index e11d07e..df3fea7 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -560,6 +560,7 @@ int is_anon_link_type(char *link, char *type)
 
 void *shmalloc(size_t bytes)
 {
+	rst_mem_align(RM_SHARED);
 	return rst_mem_alloc(bytes, RM_SHARED);
 }
 
-- 
2.5.0



More information about the CRIU mailing list