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

Submitted by Cyrill Gorcunov on Aug. 7, 2018, 4:35 p.m.

Details

Message ID 20180807163517.21669-7-gorcunov@gmail.com
State New
Series "x86: cpu -- Rework feature testing"
Headers show

Commit Message

Cyrill Gorcunov Aug. 7, 2018, 4:35 p.m.
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@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(-)

Patch hide | download patch | download mbox

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)
 

Comments

Dmitry Safonov Aug. 20, 2018, 12:31 p.m.
2018-08-07 17:35 GMT+01:00 Cyrill Gorcunov <gorcunov@gmail.com>:
> 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@gmail.com>

Reviewed-by: Dmitry Safonov <0x7f454c46@gmaill.com>

Thanks,
             Dmitry