[CRIU] [RFC 2/3] Use run-time page_size() for mremap

Christopher Covington cov at codeaurora.org
Thu Jul 23 04:59:49 PDT 2015


The old and new address parameters passed to the mremap system
call must be page size aligned. On AArch64, the page size can
only be correctly determined at run time. This fixes the following
errors for CRIU on AArch64 kernels with CONFIG_ARM64_64K_PAGES=y.

      call mremap(0x3ffb7d50000, 8192, 8192, MAYMOVE | FIXED, 0x2a000)
  Error (rst-malloc.c:201): Can't mremap rst mem: Invalid argument

      call mremap(0x3ffb7d90000, 8192, 8192, MAYMOVE | FIXED, 0x32000)
  Error (rst-malloc.c:201): Can't mremap rst mem: Invalid argument

Signed-off-by: Christopher Covington <cov at codeaurora.org>
---
 arch/aarch64/include/asm/page.h |  2 ++
 cr-restore.c                    |  2 +-
 rst-malloc.c                    | 12 ++++++------
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/aarch64/include/asm/page.h b/arch/aarch64/include/asm/page.h
index c16f467..de1fe54 100644
--- a/arch/aarch64/include/asm/page.h
+++ b/arch/aarch64/include/asm/page.h
@@ -1,6 +1,8 @@
 #ifndef __CR_ASM_PAGE_H__
 #define __CR_ASM_PAGE_H__
 
+#include <unistd.h>
+
 #ifndef PAGE_SHIFT
 # define PAGE_SHIFT	12
 #endif
diff --git a/cr-restore.c b/cr-restore.c
index 54e35ce..64388df 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -2673,7 +2673,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 	BUILD_BUG_ON(sizeof(struct task_restore_args) & 1);
 	BUILD_BUG_ON(sizeof(struct thread_restore_args) & 1);
 
-	args_len = round_up(sizeof(*task_args) + sizeof(*thread_args) * current->nr_threads, PAGE_SIZE);
+	args_len = round_up(sizeof(*task_args) + sizeof(*thread_args) * current->nr_threads, page_size());
 	pr_info("%d threads require %ldK of memory\n",
 			current->nr_threads, KBYTES(args_len));
 
diff --git a/rst-malloc.c b/rst-malloc.c
index 215290f..14e0b41 100644
--- a/rst-malloc.c
+++ b/rst-malloc.c
@@ -18,15 +18,15 @@ struct rst_mem_type_s {
 	unsigned long size;
 };
 
-#define RST_MEM_BATCH	(2 * PAGE_SIZE)
-
 static inline unsigned long rst_mem_grow(unsigned long need_size)
 {
-	need_size = round_up(need_size, PAGE_SIZE);
-	if (likely(need_size < RST_MEM_BATCH))
-		need_size = RST_MEM_BATCH;
+	int rst_mem_batch = 2 * page_size();
+
+	need_size = round_up(need_size, page_size());
+	if (likely(need_size < rst_mem_batch))
+		need_size = rst_mem_batch;
 	else
-		pr_debug("Growing rst memory %lu pages\n", need_size / PAGE_SIZE);
+		pr_debug("Growing rst memory %lu pages\n", need_size / page_size());
 	return need_size;
 }
 
-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



More information about the CRIU mailing list