[CRIU] [PATCH 09/11] x86: cpu -- Add ability to ignore xsaves

Cyrill Gorcunov gorcunov at gmail.com
Thu Jun 14 20:27:28 MSK 2018


Currently even if kernel supports compact xsave frame a user
can disable it by passing noxsaves argument as a boot option.
Thus cpuid instruction will report its presence but in real
it gonna be masked from kernel pov. Lets do the same and
allow a user to mask it via --cpu-cap=noxsaves option
(valid for x86 only).

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 criu/arch/aarch64/cpu.c |  5 +++++
 criu/arch/arm/cpu.c     |  5 +++++
 criu/arch/ppc64/cpu.c   |  5 +++++
 criu/arch/s390/cpu.c    |  5 +++++
 criu/arch/x86/cpu.c     | 24 ++++++++++++++++++++++++
 criu/crtools.c          |  5 +++++
 criu/include/cpu.h      |  1 +
 7 files changed, 50 insertions(+)

diff --git a/criu/arch/aarch64/cpu.c b/criu/arch/aarch64/cpu.c
index 34313fb1569b..ef339f2f1f78 100644
--- a/criu/arch/aarch64/cpu.c
+++ b/criu/arch/aarch64/cpu.c
@@ -38,3 +38,8 @@ int cpuinfo_check(void)
 {
 	return -ENOTSUP;
 }
+
+int cpu_parse_option(const char *opt)
+{
+	return -ENOTSUP;
+}
diff --git a/criu/arch/arm/cpu.c b/criu/arch/arm/cpu.c
index 34313fb1569b..ef339f2f1f78 100644
--- a/criu/arch/arm/cpu.c
+++ b/criu/arch/arm/cpu.c
@@ -38,3 +38,8 @@ int cpuinfo_check(void)
 {
 	return -ENOTSUP;
 }
+
+int cpu_parse_option(const char *opt)
+{
+	return -ENOTSUP;
+}
diff --git a/criu/arch/ppc64/cpu.c b/criu/arch/ppc64/cpu.c
index 4fcfb065a75d..cdee8c72fed8 100644
--- a/criu/arch/ppc64/cpu.c
+++ b/criu/arch/ppc64/cpu.c
@@ -140,3 +140,8 @@ int cpuinfo_check(void)
 
 	return 0;
 }
+
+int cpu_parse_option(const char *opt)
+{
+	return -1;
+}
diff --git a/criu/arch/s390/cpu.c b/criu/arch/s390/cpu.c
index f93666ed68a3..5f6b83f70a40 100644
--- a/criu/arch/s390/cpu.c
+++ b/criu/arch/s390/cpu.c
@@ -156,3 +156,8 @@ int cpuinfo_check(void)
 		return 1;
 	return 0;
 }
+
+int cpu_parse_option(const char *opt)
+{
+	return -1;
+}
diff --git a/criu/arch/x86/cpu.c b/criu/arch/x86/cpu.c
index c7def88834c3..e424fa0f6bc6 100644
--- a/criu/arch/x86/cpu.c
+++ b/criu/arch/x86/cpu.c
@@ -416,3 +416,27 @@ int cpuinfo_check(void)
 
 	return 0;
 }
+
+int cpu_parse_option(const char *opt)
+{
+	static struct {
+		const char	*name;
+		unsigned int	feature;
+	} filters[] = {
+		{
+			.name		= "noxsaves",
+			.feature	= X86_FEATURE_XSAVES,
+		},
+	};
+
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(filters); i++) {
+		if (strncmp(opt, filters[i].name, strlen(filters[i].name)))
+			continue;
+		compel_cpu_clear_feature(filters[i].feature);
+		return strlen(filters[i].name);
+	}
+
+	return -1;
+}
diff --git a/criu/crtools.c b/criu/crtools.c
index 4ff7a9f245d8..f7b7864cab7e 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -151,6 +151,11 @@ static int parse_cpu_cap(struct cr_options *opts, const char *optarg)
 		} else if (!strncmp(optarg, "ins", 3)) {
 			____cpu_set_cap(opts, CPU_CAP_INS, inverse);
 			optarg += 3;
+		} else if (!strncmp(optarg, "op=", 3)) {
+			int pos = cpu_parse_option(&optarg[3]);
+			if (pos <= 0)
+				goto Esyntax;
+			optarg += pos + 3;
 		} else
 			goto Esyntax;
 	}
diff --git a/criu/include/cpu.h b/criu/include/cpu.h
index e30696790e72..09b3c789980b 100644
--- a/criu/include/cpu.h
+++ b/criu/include/cpu.h
@@ -8,5 +8,6 @@ extern int cpu_dump_cpuinfo(void);
 extern int cpu_validate_cpuinfo(void);
 extern int cpuinfo_dump(void);
 extern int cpuinfo_check(void);
+extern int cpu_parse_option(const char *opt);
 
 #endif /* __CR_CPU_H__ */
-- 
2.14.4



More information about the CRIU mailing list