72332c
From 0f98ee4641458301a3bbe49c88df381edaea93dc Mon Sep 17 00:00:00 2001
72332c
From: Dmitry Safonov <dima@arista.com>
72332c
Date: Thu, 10 May 2018 19:14:44 +0100
72332c
Subject: [PATCH 4/8] compel/criu: Add ARCH_HAS_LONG_PAGES to PIE binaries
72332c
72332c
For architectures like aarch64/ppc64 it's needed to propagate the size
72332c
of page inside PIEs. For the parasite page size will be defined during
72332c
seizing, and for restorer during early initialization.
72332c
Afterward we can use PAGE_SIZE in PIEs like we did before.
72332c
72332c
Signed-off-by: Dmitry Safonov <dima@arista.com>
72332c
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
72332c
---
72332c
 compel/include/rpc-pie-priv.h          |  3 +++
72332c
 compel/plugins/std/infect.c            | 17 +++++++++++++++++
72332c
 compel/src/lib/infect.c                |  3 +++
72332c
 criu/cr-restore.c                      |  3 +++
72332c
 criu/include/restorer.h                |  3 +++
72332c
 criu/pie/restorer.c                    | 16 ++++++++++++++++
72332c
 include/common/arch/aarch64/asm/page.h |  9 +++++++++
72332c
 include/common/arch/ppc64/asm/page.h   |  9 +++++++++
72332c
 8 files changed, 63 insertions(+)
72332c
72332c
diff --git a/compel/include/rpc-pie-priv.h b/compel/include/rpc-pie-priv.h
72332c
index f25ca89eb..15f5b14ca 100644
72332c
--- a/compel/include/rpc-pie-priv.h
72332c
+++ b/compel/include/rpc-pie-priv.h
72332c
@@ -38,6 +38,9 @@ struct parasite_init_args {
72332c
 	uint64_t			sigreturn_addr;
72332c
 	uint64_t			sigframe; /* pointer to sigframe */
72332c
 	futex_t				daemon_connected;
72332c
+#ifdef ARCH_HAS_LONG_PAGES
72332c
+	uint32_t			page_size;
72332c
+#endif
72332c
 };
72332c
 
72332c
 struct parasite_unmap_args {
72332c
diff --git a/compel/plugins/std/infect.c b/compel/plugins/std/infect.c
72332c
index 2d3aa3df8..d5e1b4354 100644
72332c
--- a/compel/plugins/std/infect.c
72332c
+++ b/compel/plugins/std/infect.c
72332c
@@ -3,6 +3,7 @@
72332c
 #include "common/scm.h"
72332c
 #include "common/compiler.h"
72332c
 #include "common/lock.h"
72332c
+#include "common/page.h"
72332c
 
72332c
 #define pr_err(fmt, ...)	print_on_level(1, fmt, ##__VA_ARGS__)
72332c
 #define pr_info(fmt, ...)	print_on_level(3, fmt, ##__VA_ARGS__)
72332c
@@ -19,6 +20,19 @@ static int tsock = -1;
72332c
 
72332c
 static struct rt_sigframe *sigframe;
72332c
 
72332c
+#ifdef ARCH_HAS_LONG_PAGES
72332c
+/*
72332c
+ * XXX: Make it compel's std plugin global variable. Drop parasite_size().
72332c
+ * Hint: compel on aarch64 shall learn relocs for that.
72332c
+ */
72332c
+static unsigned __page_size;
72332c
+
72332c
+unsigned __attribute((weak)) page_size(void)
72332c
+{
72332c
+	return __page_size;
72332c
+}
72332c
+#endif
72332c
+
72332c
 int parasite_get_rpc_sock(void)
72332c
 {
72332c
 	return tsock;
72332c
@@ -142,6 +156,9 @@ static noinline __used int parasite_init_daemon(void *data)
72332c
 
72332c
 	args->sigreturn_addr = (uint64_t)(uintptr_t)fini_sigreturn;
72332c
 	sigframe = (void*)(uintptr_t)args->sigframe;
72332c
+#ifdef ARCH_HAS_LONG_PAGES
72332c
+	__page_size = args->page_size;
72332c
+#endif
72332c
 
72332c
 	ret = tsock = sys_socket(PF_UNIX, SOCK_SEQPACKET, 0);
72332c
 	if (tsock < 0) {
72332c
diff --git a/compel/src/lib/infect.c b/compel/src/lib/infect.c
72332c
index ecc6599b1..d51b8aa88 100644
72332c
--- a/compel/src/lib/infect.c
72332c
+++ b/compel/src/lib/infect.c
72332c
@@ -613,6 +613,9 @@ static int parasite_init_daemon(struct parasite_ctl *ctl)
72332c
 
72332c
 	args->sigframe = (uintptr_t)ctl->rsigframe;
72332c
 	args->log_level = compel_log_get_loglevel();
72332c
+#ifdef ARCH_HAS_LONG_PAGES
72332c
+	args->page_size = PAGE_SIZE;
72332c
+#endif
72332c
 
72332c
 	futex_set(&args->daemon_connected, 0);
72332c
 
72332c
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
72332c
index 54216b8ea..8a436cc98 100644
72332c
--- a/criu/cr-restore.c
72332c
+++ b/criu/cr-restore.c
72332c
@@ -3650,6 +3650,9 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns
72332c
 	task_args->premmapped_len = rsti(current)->premmapped_len;
72332c
 
72332c
 	task_args->task_size = kdat.task_size;
72332c
+#ifdef ARCH_HAS_LONG_PAGES
72332c
+	task_args->page_size = PAGE_SIZE;
72332c
+#endif
72332c
 
72332c
 	RST_MEM_FIXUP_PPTR(task_args->vmas);
72332c
 	RST_MEM_FIXUP_PPTR(task_args->rings);
72332c
diff --git a/criu/include/restorer.h b/criu/include/restorer.h
72332c
index 15307d9c0..70223be55 100644
72332c
--- a/criu/include/restorer.h
72332c
+++ b/criu/include/restorer.h
72332c
@@ -209,6 +209,9 @@ struct task_restore_args {
72332c
 	void				**breakpoint;
72332c
 
72332c
 	enum faults			fault_strategy;
72332c
+#ifdef ARCH_HAS_LONG_PAGES
72332c
+	unsigned			page_size;
72332c
+#endif
72332c
 } __aligned(64);
72332c
 
72332c
 /*
72332c
diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c
72332c
index 69f8504e3..da20f3298 100644
72332c
--- a/criu/pie/restorer.c
72332c
+++ b/criu/pie/restorer.c
72332c
@@ -36,6 +36,7 @@
72332c
 #include "uffd.h"
72332c
 
72332c
 #include "common/lock.h"
72332c
+#include "common/page.h"
72332c
 #include "restorer.h"
72332c
 #include "aio.h"
72332c
 #include "seccomp.h"
72332c
@@ -76,6 +77,18 @@ bool fault_injected(enum faults f)
72332c
 	return __fault_injected(f, fi_strategy);
72332c
 }
72332c
 
72332c
+#ifdef ARCH_HAS_LONG_PAGES
72332c
+/*
72332c
+ * XXX: Make it compel's std plugin global variable. Drop parasite_size().
72332c
+ * Hint: compel on aarch64 shall learn relocs for that.
72332c
+ */
72332c
+static unsigned __page_size;
72332c
+unsigned page_size(void)
72332c
+{
72332c
+	return __page_size;
72332c
+}
72332c
+#endif
72332c
+
72332c
 /*
72332c
  * These are stubs for std compel plugin.
72332c
  */
72332c
@@ -1230,6 +1243,9 @@ long __export_restore_task(struct task_restore_args *args)
72332c
 	zombies = args->zombies;
72332c
 	n_zombies = args->zombies_n;
72332c
 	*args->breakpoint = rst_sigreturn;
72332c
+#ifdef ARCH_HAS_LONG_PAGES
72332c
+	__page_size = args->page_size;
72332c
+#endif
72332c
 
72332c
 	ksigfillset(&act.rt_sa_mask);
72332c
 	act.rt_sa_handler = sigchld_handler;
72332c
diff --git a/include/common/arch/aarch64/asm/page.h b/include/common/arch/aarch64/asm/page.h
72332c
index de1fe5428..4126c8474 100644
72332c
--- a/include/common/arch/aarch64/asm/page.h
72332c
+++ b/include/common/arch/aarch64/asm/page.h
72332c
@@ -1,6 +1,9 @@
72332c
 #ifndef __CR_ASM_PAGE_H__
72332c
 #define __CR_ASM_PAGE_H__
72332c
 
72332c
+#define ARCH_HAS_LONG_PAGES
72332c
+
72332c
+#ifndef CR_NOGLIBC
72332c
 #include <unistd.h>
72332c
 
72332c
 #ifndef PAGE_SHIFT
72332c
@@ -18,4 +21,10 @@
72332c
 #define PAGE_PFN(addr)	((addr) / PAGE_SIZE)
72332c
 #define page_size()	sysconf(_SC_PAGESIZE)
72332c
 
72332c
+#else /* CR_NOGLIBC */
72332c
+
72332c
+extern unsigned page_size(void);
72332c
+#define PAGE_SIZE page_size()
72332c
+
72332c
+#endif /* CR_NOGLIBC */
72332c
 #endif /* __CR_ASM_PAGE_H__ */
72332c
diff --git a/include/common/arch/ppc64/asm/page.h b/include/common/arch/ppc64/asm/page.h
72332c
index 9d10455f1..a95af55ef 100644
72332c
--- a/include/common/arch/ppc64/asm/page.h
72332c
+++ b/include/common/arch/ppc64/asm/page.h
72332c
@@ -1,6 +1,9 @@
72332c
 #ifndef __CR_ASM_PAGE_H__
72332c
 #define __CR_ASM_PAGE_H__
72332c
 
72332c
+#define ARCH_HAS_LONG_PAGES
72332c
+
72332c
+#ifndef CR_NOGLIBC
72332c
 #include <unistd.h>
72332c
 
72332c
 /*
72332c
@@ -22,4 +25,10 @@
72332c
 #define PAGE_PFN(addr)	((addr) / PAGE_SIZE)
72332c
 #define page_size()	sysconf(_SC_PAGESIZE)
72332c
 
72332c
+#else /* CR_NOGLIBC */
72332c
+
72332c
+extern unsigned page_size(void);
72332c
+#define PAGE_SIZE page_size()
72332c
+
72332c
+#endif /* CR_NOGLIBC */
72332c
 #endif /* __CR_ASM_PAGE_H__ */
72332c
-- 
72332c
2.17.0
72332c