[CRIU] [PATCH 05/18] x86: cpu -- Save xfeature on dump

Cyrill Gorcunov gorcunov at gmail.com
Thu Jul 19 15:47:33 MSK 2018


This feature will allow to catch incapability early
if present in image.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 criu/arch/x86/cpu.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/criu/arch/x86/cpu.c b/criu/arch/x86/cpu.c
index d5d879e79f7d..e9c24af846e9 100644
--- a/criu/arch/x86/cpu.c
+++ b/criu/arch/x86/cpu.c
@@ -97,6 +97,8 @@ int cpu_dump_cpuinfo(void)
 	cpu_x86_info.capability_ver = 2;
 	cpu_x86_info.n_capability = ARRAY_SIZE(rt_cpu_info.x86_capability);
 	cpu_x86_info.capability = (void *)rt_cpu_info.x86_capability;
+	cpu_x86_info.has_xfeatures_mask = true;
+	cpu_x86_info.xfeatures_mask = rt_cpu_info.xfeatures_mask;
 
 	if (rt_cpu_info.x86_model_id[0])
 		cpu_x86_info.model_id = rt_cpu_info.x86_model_id;
@@ -263,6 +265,17 @@ static int cpu_validate_features(compel_cpuinfo_t *cpu_info)
 #undef __mismatch_fpu_bit
 	}
 
+	/*
+	 * Make sure the xsave features are at least not less
+	 * than current cpu supports.
+	 */
+	if (cpu_info->xfeatures_mask > rt_cpu_info.xfeatures_mask) {
+		uint64_t m = cpu_info->xfeatures_mask & ~rt_cpu_info.xfeatures_mask;
+		pr_err("CPU xfeatures has unsupported bits (%#llx)\n",
+		       (unsigned long long)m);
+		return -1;
+	}
+
 	/*
 	 * Capability on instructions level only.
 	 */
@@ -353,6 +366,17 @@ static compel_cpuinfo_t *img_to_cpuinfo(CpuinfoX86Entry *img_x86_entry)
 	memcpy(cpu_info->x86_vendor_id, rt_cpu_info.x86_model_id, sizeof(cpu_info->x86_vendor_id));
 	strncpy(cpu_info->x86_model_id, img_x86_entry->model_id, sizeof(cpu_info->x86_model_id) - 1);
 
+	/*
+	 * For old images where no xfeatures_mask present we
+	 * simply fetch runtime cpu mask because later we will
+	 * do either instruction capability check, either strict
+	 * check for capabilities.
+	 */
+	if (!img_x86_entry->has_xfeatures_mask) {
+		cpu_info->xfeatures_mask = rt_cpu_info.xfeatures_mask;
+	} else
+		cpu_info->xfeatures_mask = img_x86_entry->xfeatures_mask;
+
 	return cpu_info;
 }
 
-- 
2.14.4



More information about the CRIU mailing list