[CRIU] [PATCH 09/14] restore: Restore FPU state

Pavel Emelyanov xemul at parallels.com
Wed Dec 19 15:28:22 EST 2012


On 12/19/2012 08:31 PM, Cyrill Gorcunov wrote:
> 
> Since at moment we stick with sigreturn restore
> we need to form a proper FPU frame and set a pointer
> to it inside sigreturn frame.
> 
> For this sake we read the FPU image and here are two
> cases are possible
> 
>  - xsave frame is present but the host cpu supports only
>    fxsave instruction: we refuse to continue, since it means
>    there are no ymm registers on the machine where we're trying
>    to restore
> 
>  - fxsave frame is present but the host cpu has xsave feature:
>    at moment we refuse to continue, requiring complete match
>    between "checkpoint and restore hosts", but in real we could
>    extend logic and form complete xsave frame from fxsave and
>    continue processing
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  cr-restore.c   | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  pie/restorer.c |  18 ++++++++
>  2 files changed, 160 insertions(+)
> 
> +static void show_rt_xsave_frame(struct xsave_struct *x)
> +{
> +	struct fpx_sw_bytes *fpx = (void *)&x->i387.sw_reserved;
> +	struct xsave_hdr_struct *xsave_hdr = &x->xsave_hdr;
> +	struct i387_fxsave_struct *i387 = &x->i387;
> +	struct ymmh_struct *ymmh = &x->ymmh;
> +
> +	unsigned int i;
> +
> +	(void)i;
> +	(void)ymmh;

Garbage?

> +
> +	pr_debug("xsave runtime structure\n");
> +	pr_debug("-----------------------\n");
> +
> +	pr_debug("cwd:%x swd:%x twd:%x fop:%x mxcsr:%x mxcsr_mask:%x\n",
> +		 (int)i387->cwd, (int)i387->swd, (int)i387->twd,
> +		 (int)i387->fop, (int)i387->mxcsr, (int)i387->mxcsr_mask);
> +
> +	pr_debug("magic1:%x extended_size:%x xstate_bv:%lx xstate_size:%x\n",
> +		 fpx->magic1, fpx->extended_size, fpx->xstate_bv, fpx->xstate_size);
> +
> +	pr_debug("xstate_bv: %lx\n", xsave_hdr->xstate_bv);
> +
> +	pr_debug("-----------------------\n");
> +}



> +static int sigreturn_prep_xsave_frame(struct thread_restore_args *args, CoreEntry *core)
> +{
> +	struct xsave_struct *x = &args->xsave;
> +
> +	/*
> +	 * If no FPU information provided -- we're restoring
> +	 * old image which has no FPU support, or the dump simply
> +	 * has no FPU support at all.
> +	 */
> +	if (!core->thread_info->fpregs) {
> +		args->has_fpu = false;
> +		return 0;
> +	}
> +
> +	if (!valid_xsave_frame(core))
> +		return -1;
> +
> +	args->has_fpu = true;
> +
> +#define assign_reg(dst, src, e)		do { dst.e = (__typeof__(dst.e))src->e; } while (0)
> +#define assign_array(dst, src, e)	memcpy(dst.e, (src)->e, sizeof(dst.e))

Don't we have too many of this assignment helpers already?

> +
> +	*x = (struct xsave_struct) { };

What for?

> +
> +	assign_reg(x->i387, core->thread_info->fpregs, cwd);
> +	assign_reg(x->i387, core->thread_info->fpregs, swd);
> +	assign_reg(x->i387, core->thread_info->fpregs, twd);
> +	assign_reg(x->i387, core->thread_info->fpregs, fop);



More information about the CRIU mailing list