Re: [PATCH 02/19] x86, fpu: wrap get_xsave_addr() to make it safer

Thomas Gleixner
2015-05-18T19:38:01Z

On Fri, 8 May 2015, Dave Hansen wrote:
> The MPX code appears to be saving off the FPU in an unsafe
> way. It does not disable preemption or ensure that the
> FPU state has been allocated.
>
> This patch introduces a new helper which will do both of
> those things internally.

This changelog does not really match the implementation. Unless I'm
missing something I can't find anything preemption related.

> +
> +/*
> + * This wraps up the common operations that need to occur when retrieving
> + * data from xsave state. It first ensures that the current task was
> + * using the FPU and retrieves the data in to a buffer. It then calculates
> + * the offset of the requested field in the buffer.
> + *
> + * This function is safe to call whether the FPU is in use or not.
> + *
> + * Note that this only works on the current task.
> + *
> + * Inputs:
> + * @xsave_field: state which is defined in xsave.h (e.g. XSTATE_FP,
> + * XSTATE_SSE, etc...)
> + * Output:
> + * address of the state in the xsave area.

or NULL in case of .....

> + */
> +void *get_xsave_field(int xsave_field)
> +{
> + union thread_xstate *xstate;
> +
> + if (!tsk_used_math(current))
> + return NULL;
> + /*
> + * unlazy_fpu() is poorly named and will actually
> + * save the xstate off in to the memory buffer.
> + */
> + unlazy_fpu(current);
> + xstate = current->thread.fpu.state;
> +
> + return get_xsave_addr(&xstate->xsave, xsave_field);
> +}

Thanks,

tglx