[CRIU] [PATCH] xsave: check for X86_FEATURE_OSXSAVE rather than for X86_FEATURE_XSAVE

Adrian Reber adrian at lisas.de
Thu Dec 15 06:30:44 PST 2016


From: Adrian Reber <areber at redhat.com>

Migrating a process between a system with the 'xsave' CPU flag and
another system without the 'xsave' CPU flags is not possible and
fails during restore. To avoid this situation it is possible to boot
the source system of the migration with 'noxsave' kernel command-line.

Unfortunately criu currently tries to detect the presence of 'xsave'
with the macro X86_FEATURE_XSAVE which represents the features of
the CPU without taking into account if the operating system has
disabled 'xsave'. Checking for 'xsave' availability with the macro
X86_FEATURE_OSXSAVE detects correctly if Linux has been booted
with disabled 'xsave' and thus migrating processes between hosts
with and without 'xsave' is possible if the kernel uses the flag
'noxsave'.

Signed-off-by: Adrian Reber <areber at redhat.com>
---
 compel/arch/x86/src/lib/infect.c |  2 +-
 criu/arch/x86/cpu.c              |  4 ++--
 criu/arch/x86/crtools.c          | 10 +++++-----
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/compel/arch/x86/src/lib/infect.c b/compel/arch/x86/src/lib/infect.c
index bf8c43a..be04399 100644
--- a/compel/arch/x86/src/lib/infect.c
+++ b/compel/arch/x86/src/lib/infect.c
@@ -173,7 +173,7 @@ int get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t save, void *ar
 
 	pr_info("Dumping GP/FPU registers for %d\n", pid);
 
-	if (cpu_has_feature(X86_FEATURE_XSAVE)) {
+	if (cpu_has_feature(X86_FEATURE_OSXSAVE)) {
 		iov.iov_base = &xsave;
 		iov.iov_len = sizeof(xsave);
 
diff --git a/criu/arch/x86/cpu.c b/criu/arch/x86/cpu.c
index 5113a29..9f8083d 100644
--- a/criu/arch/x86/cpu.c
+++ b/criu/arch/x86/cpu.c
@@ -51,7 +51,7 @@ int cpu_init(void)
 	pr_debug("fpu:%d fxsr:%d xsave:%d\n",
 		 !!cpu_has_feature(X86_FEATURE_FPU),
 		 !!cpu_has_feature(X86_FEATURE_FXSR),
-		 !!cpu_has_feature(X86_FEATURE_XSAVE));
+		 !!cpu_has_feature(X86_FEATURE_OSXSAVE));
 
 	return 0;
 }
@@ -225,7 +225,7 @@ static int cpu_validate_features(CpuinfoX86Entry *img_x86_entry)
 		 !cpu_has_feature(__bit))
 		if (__mismatch_fpu_bit(X86_FEATURE_FPU)		||
 		    __mismatch_fpu_bit(X86_FEATURE_FXSR)	||
-		    __mismatch_fpu_bit(X86_FEATURE_XSAVE)) {
+		    __mismatch_fpu_bit(X86_FEATURE_OSXSAVE)) {
 			pr_err("FPU feature required by image "
 			       "is not supported on host.\n");
 			return -1;
diff --git a/criu/arch/x86/crtools.c b/criu/arch/x86/crtools.c
index c842258..ba0145b 100644
--- a/criu/arch/x86/crtools.c
+++ b/criu/arch/x86/crtools.c
@@ -128,7 +128,7 @@ int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpre
 	assign_array(core->thread_info->fpregs, fpregs->i387, st_space);
 	assign_array(core->thread_info->fpregs, fpregs->i387, xmm_space);
 
-	if (cpu_has_feature(X86_FEATURE_XSAVE)) {
+	if (cpu_has_feature(X86_FEATURE_OSXSAVE)) {
 		BUG_ON(core->thread_info->fpregs->xsave->n_ymmh_space != ARRAY_SIZE(fpregs->ymmh.ymmh_space));
 
 		assign_reg(core->thread_info->fpregs->xsave, fpregs->xsave_hdr, xstate_bv);
@@ -168,7 +168,7 @@ int arch_alloc_thread_info(CoreEntry *core)
 		GDT_ENTRY_TLS_NUM*sizeof(UserDescT*);
 	if (with_fpu) {
 		sz += sizeof(UserX86FpregsEntry);
-		with_xsave = cpu_has_feature(X86_FEATURE_XSAVE);
+		with_xsave = cpu_has_feature(X86_FEATURE_OSXSAVE);
 		if (with_xsave)
 			sz += sizeof(UserX86XsaveEntry);
 	}
@@ -249,7 +249,7 @@ static bool valid_xsave_frame(CoreEntry *core)
 		return false;
 	}
 
-	if (cpu_has_feature(X86_FEATURE_XSAVE)) {
+	if (cpu_has_feature(X86_FEATURE_OSXSAVE)) {
 		if (core->thread_info->fpregs->xsave &&
 		    core->thread_info->fpregs->xsave->n_ymmh_space < ARRAY_SIZE(x->ymmh.ymmh_space)) {
 			pr_err("Corruption in FPU ymmh_space area "
@@ -261,7 +261,7 @@ static bool valid_xsave_frame(CoreEntry *core)
 	} else {
 		/*
 		 * If the image has xsave area present then CPU we're restoring
-		 * on must have X86_FEATURE_XSAVE feature until explicitly
+		 * on must have X86_FEATURE_OSXSAVE feature until explicitly
 		 * stated in options.
 		 */
 		if (core->thread_info->fpregs->xsave) {
@@ -335,7 +335,7 @@ int restore_fpu(struct rt_sigframe *sigframe, CoreEntry *core)
 	assign_array(x->i387, core->thread_info->fpregs, st_space);
 	assign_array(x->i387, core->thread_info->fpregs, xmm_space);
 
-	if (cpu_has_feature(X86_FEATURE_XSAVE)) {
+	if (cpu_has_feature(X86_FEATURE_OSXSAVE)) {
 		struct fpx_sw_bytes *fpx_sw = (void *)&x->i387.sw_reserved;
 		void *magic2;
 
-- 
2.9.3



More information about the CRIU mailing list