[CRIU] [PATCH 3/8] vdso: share the vDSO proxy initialization between all architectures

Alexander Kartashov alekskartashov at parallels.com
Mon Mar 10 01:51:23 PDT 2014


This patch splits the file arch/x86/vdso.c into machine-independent
and machine-dependent parts by moving the routine vdso_init()
from the file vdso.c. The routine seems to be suitable for all
architectures supporting the vDSO.

The ARM version of the routine is moved to the source vdso-stub.c
that is supposed to be the vDSO proxy stub implementation for
architectures that don't provide the vDSO. The build scripts are
adjusted as well to enable selection between the full-fledged
and stub vDSO proxy implementations.

Signed-off-by: Alexander Kartashov <alekskartashov at parallels.com>
Cc: Cyrill Gorcunov <gorcunov at openvz.org>
---
 Makefile         |    5 +++++
 Makefile.crtools |    1 +
 arch/arm/vdso.c  |    8 -------
 arch/x86/vdso.c  |   49 -----------------------------------------
 vdso-stub.c      |   23 ++++++++++++++++++++
 vdso.c           |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 93 insertions(+), 57 deletions(-)
 create mode 100644 vdso-stub.c
 create mode 100644 vdso.c

diff --git a/Makefile b/Makefile
index bda808d..99ea752 100644
--- a/Makefile
+++ b/Makefile
@@ -35,6 +35,8 @@ OBJCOPY		:= $(CROSS_COMPILE)objcopy
 
 CFLAGS		+= $(USERCFLAGS)
 
+VDSO_O		:= vdso.o
+
 #
 # Fetch ARCH from the uname if not yet set
 #
@@ -69,6 +71,8 @@ ifeq ($(shell echo $(ARCH) | sed -e 's/arm.*/arm/'),arm)
 	ifeq ($(ARMV),7)
 		USERCFLAGS += -march=armv7-a
 	endif
+
+	VDSO_O       := vdso-stub.o
 endif
 
 SRCARCH		?= $(ARCH)
@@ -117,6 +121,7 @@ CRIU-INC	:= lib/criu.h include/criu-plugin.h include/criu-log.h protobuf/rpc.pro
 export CC MAKE CFLAGS LIBS SRCARCH DEFINES MAKEFLAGS CRIU-SO
 export SRC_DIR SYSCALL-LIB SH RM ARCH_DIR OBJCOPY LDARCH LD
 export cflags-y
+export VDSO_O
 
 include Makefile.inc
 include Makefile.config
diff --git a/Makefile.crtools b/Makefile.crtools
index 6effc3e..619e9a0 100644
--- a/Makefile.crtools
+++ b/Makefile.crtools
@@ -62,6 +62,7 @@ obj-y	+= $(ARCH_DIR)/vdso.o
 obj-y	+= cr-service.o
 obj-y	+= sd-daemon.o
 obj-y	+= plugin.o
+obj-y	+= $(VDSO_O)
 
 ifneq ($(MAKECMDGOALS),clean)
 incdeps := y
diff --git a/arch/arm/vdso.c b/arch/arm/vdso.c
index eae846d..4d4e28a 100644
--- a/arch/arm/vdso.c
+++ b/arch/arm/vdso.c
@@ -13,14 +13,6 @@
 #endif
 #define LOG_PREFIX "vdso: "
 
-struct vdso_symtable vdso_sym_rt = VDSO_SYMTABLE_INIT;
-u64 vdso_pfn = VDSO_BAD_PFN;
-
-int vdso_init(void)
-{
-	return 0;
-}
-
 int parasite_fixup_vdso(struct parasite_ctl *ctl, pid_t pid,
 			struct vm_area_list *vma_area_list)
 {
diff --git a/arch/x86/vdso.c b/arch/x86/vdso.c
index 0a59e23..d240ba5 100644
--- a/arch/x86/vdso.c
+++ b/arch/x86/vdso.c
@@ -27,55 +27,6 @@
 #endif
 #define LOG_PREFIX "vdso: "
 
-struct vdso_symtable vdso_sym_rt = VDSO_SYMTABLE_INIT;
-u64 vdso_pfn = VDSO_BAD_PFN;
-
-static int vdso_fill_self_symtable(struct vdso_symtable *s)
-{
-	char buf[512];
-	int ret = -1;
-	FILE *maps;
-
-	VDSO_INIT_SYMTABLE(s);
-
-	maps = fopen("/proc/self/maps", "r");
-	if (!maps) {
-		pr_perror("Can't open self-vma");
-		return -1;
-	}
-
-	while (fgets(buf, sizeof(buf), maps)) {
-		unsigned long start, end;
-
-		if (strstr(buf, "[vdso]") == NULL)
-			continue;
-
-		ret = sscanf(buf, "%lx-%lx", &start, &end);
-		if (ret != 2) {
-			ret = -1;
-			pr_err("Can't find vDSO bounds\n");
-			break;
-		}
-
-		s->vma_start = start;
-		s->vma_end = end;
-
-		ret = vdso_fill_symtable((void *)start, end - start, s);
-		break;
-	}
-
-	fclose(maps);
-	return ret;
-}
-
-int vdso_init(void)
-{
-	if (vdso_fill_self_symtable(&vdso_sym_rt))
-		return -1;
-
-	return vaddr_to_pfn(vdso_sym_rt.vma_start, &vdso_pfn);
-}
-
 /*
  * Find out proxy vdso vma and drop it from the list. Also
  * fix vdso status on vmas if wrong status found.
diff --git a/vdso-stub.c b/vdso-stub.c
new file mode 100644
index 0000000..60aa72d
--- /dev/null
+++ b/vdso-stub.c
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "vdso.h"
+#include "log.h"
+#include "util.h"
+
+#ifdef LOG_PREFIX
+# undef LOG_PREFIX
+#endif
+#define LOG_PREFIX "vdso: "
+
+
+struct vdso_symtable vdso_sym_rt = VDSO_SYMTABLE_INIT;
+u64 vdso_pfn = VDSO_BAD_PFN;
+
+
+int vdso_init(void)
+{
+	return 0;
+}
diff --git a/vdso.c b/vdso.c
new file mode 100644
index 0000000..d887e78
--- /dev/null
+++ b/vdso.c
@@ -0,0 +1,64 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "vdso.h"
+#include "log.h"
+#include "util.h"
+
+#ifdef LOG_PREFIX
+# undef LOG_PREFIX
+#endif
+#define LOG_PREFIX "vdso: "
+
+
+struct vdso_symtable vdso_sym_rt = VDSO_SYMTABLE_INIT;
+u64 vdso_pfn = VDSO_BAD_PFN;
+
+static int vdso_fill_self_symtable(struct vdso_symtable *s)
+{
+	char buf[512];
+	int ret = -1;
+	FILE *maps;
+
+	VDSO_INIT_SYMTABLE(s);
+
+	maps = fopen("/proc/self/maps", "r");
+	if (!maps) {
+		pr_perror("Can't open self-vma");
+		return -1;
+	}
+
+	while (fgets(buf, sizeof(buf), maps)) {
+		unsigned long start, end;
+
+		if (strstr(buf, "[vdso]") == NULL)
+			continue;
+
+		ret = sscanf(buf, "%lx-%lx", &start, &end);
+		if (ret != 2) {
+			ret = -1;
+			pr_err("Can't find vDSO bounds\n");
+			break;
+		}
+
+		s->vma_start = start;
+		s->vma_end = end;
+
+		ret = vdso_fill_symtable((void *)start, end - start, s);
+		break;
+	}
+
+	fclose(maps);
+	return ret;
+}
+
+int vdso_init(void)
+{
+	if (vdso_fill_self_symtable(&vdso_sym_rt))
+		return -1;
+
+	return vaddr_to_pfn(vdso_sym_rt.vma_start, &vdso_pfn);
+}
+
-- 
1.7.9.5



More information about the CRIU mailing list