[CRIU] [PATCH 6/9] x86: cpu -- Use special bit for image manipulation

Cyrill Gorcunov gorcunov at gmail.com
Tue Aug 7 19:35:14 MSK 2018


Current scheme of when to write and verify cpuinfo
images is unclear: we define default mode to 'fpu'
and this implies that no cpuinfo image get written
on dump and read on restore. In turn if 'cpu' or
'ins' mode specified in command line we write and
verify this image.

This is all wrong -- we need to produce image if
any mode ecxept 'none' is specified. The 'none'
mode is designed exactly for skipping cpuinfo
image production or verification.

Because any non-default mode requires explicit
--cpu-cap option to be passed we can use this
and setup new CPU_CAP_IMAGE telling criu to
write or read this image.

Note the default mode doesn't break backward
compatibility because by default we don't
write or read the image at all.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 criu/config.c             | 4 ++++
 criu/cr-dump.c            | 2 +-
 criu/cr-restore.c         | 2 +-
 criu/cr-service.c         | 4 +++-
 criu/include/cr_options.h | 1 +
 5 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/criu/config.c b/criu/config.c
index 84d6aad14ac4..bf89c74748f9 100644
--- a/criu/config.c
+++ b/criu/config.c
@@ -289,6 +289,7 @@ static int parse_cpu_cap(struct cr_options *opts, const char *optarg)
 
 	if (!optarg) {
 		____cpu_set_cap(opts, CPU_CAP_ALL, false);
+		____cpu_set_cap(opts, CPU_CAP_IMAGE, false);
 		return 0;
 	}
 
@@ -324,6 +325,9 @@ static int parse_cpu_cap(struct cr_options *opts, const char *optarg)
 		} else
 			goto Esyntax;
 	}
+
+	if (opts->cpu_cap != CPU_CAP_NONE)
+		____cpu_set_cap(opts, CPU_CAP_IMAGE, false);
 #undef ____cpu_set_cap
 
 	return 0;
diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 65967939c341..30dd661f4200 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -1806,7 +1806,7 @@ int cr_dump_tasks(pid_t pid)
 	if (prepare_inventory(&he))
 		goto err;
 
-	if (opts.cpu_cap & (CPU_CAP_CPU | CPU_CAP_INS)) {
+	if (opts.cpu_cap & CPU_CAP_IMAGE) {
 		if (cpu_dump_cpuinfo())
 			goto err;
 	}
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 87a4754f0635..5a044cafa824 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -2365,7 +2365,7 @@ int cr_restore_tasks(void)
 	if (vdso_init_restore())
 		goto err;
 
-	if (opts.cpu_cap & (CPU_CAP_INS | CPU_CAP_CPU)) {
+	if (opts.cpu_cap & CPU_CAP_IMAGE) {
 		if (cpu_validate_cpuinfo())
 			goto err;
 	}
diff --git a/criu/cr-service.c b/criu/cr-service.c
index 643aba9cf355..165d544a4288 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -509,8 +509,10 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
 			goto err;
 	}
 
-	if (req->has_cpu_cap)
+	if (req->has_cpu_cap) {
 		opts.cpu_cap = req->cpu_cap;
+		opts.cpu_cap |= CPU_CAP_IMAGE;
+	}
 
 	/*
 	 * FIXME: For backward compatibility we setup
diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h
index 4de777be655e..8f2a9e8633cf 100644
--- a/criu/include/cr_options.h
+++ b/criu/include/cr_options.h
@@ -28,6 +28,7 @@
 #define CPU_CAP_FPU		(1u << 0)	/* Only FPU capability required */
 #define CPU_CAP_CPU		(1u << 1)	/* Strict CPU capability required */
 #define CPU_CAP_INS		(1u << 2)	/* Instructions CPU capability */
+#define CPU_CAP_IMAGE		(1u << 3)	/* Write capability on dump and read on restore*/
 #define CPU_CAP_ALL		(CPU_CAP_FPU | CPU_CAP_CPU | CPU_CAP_INS)
 #define CPU_CAP_DEFAULT		(CPU_CAP_FPU)
 
-- 
2.14.4



More information about the CRIU mailing list