Re: [PATCH RFC 2/5] x86,fpu: delay FPU register loading until switch to userspace

From: Dave Hansen
Date: Mon Oct 03 2016 - 12:23:36 EST


On 10/01/2016 05:42 PM, Rik van Riel wrote:
> On Sat, 2016-10-01 at 16:44 -0700, Andy Lutomirski wrote:
>> > On Sat, Oct 1, 2016 at 1:31 PM, <riel@xxxxxxxxxx> wrote:
>>> > > +static inline void switch_fpu_finish(void)
>>> > > {
>>> > > + set_thread_flag(TIF_LOAD_FPU);
>>> > > }
>> >
>> > I can imagine this causing problems with kernel code that accesses
>> > current's FPU state, e.g. get_xsave_field_ptr().
> That makes me wonder, what test programs do people have
> to verify the correctness of the FPU switching code?

The MPX testing code in selftests/ goes off the rails pretty quickly
when the FP/XSAVE state gets corrupt. It has found quite a few bugs in
the last few years. The protection keys code in there also keeps a
shadow copy of the "PKRU" register in software which also makes it
notice pretty quickly if something goes awry.

That said, I'd _love_ to see more formal FPU testing done. We've had
lots of bugs in there, and they tend to hit the newer features and newer
CPUs. Let me know if you find something. :)