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

2016-10-04 Thread Rik van Riel
On Tue, 2016-10-04 at 08:35 +0200, Ingo Molnar wrote: > * Andy Lutomirski wrote: >  > > > We can get rid of fpu.counter, since nobody uses it > > > any more. > > > > We should definitely do this. > > > > Maybe getting in some cleanups first (my lazy fpu deletion, > >

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

2016-10-04 Thread Rik van Riel
On Tue, 2016-10-04 at 08:35 +0200, Ingo Molnar wrote: > * Andy Lutomirski wrote: >  > > > We can get rid of fpu.counter, since nobody uses it > > > any more. > > > > We should definitely do this. > > > > Maybe getting in some cleanups first (my lazy fpu deletion, > > fpu.counter removal, etc)

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

2016-10-04 Thread Ingo Molnar
* Andy Lutomirski wrote: > > Running the task in user space, would have to ensure > > "registers valid" is true, and make "memory valid" > > false, because userspace could write to the registers. > > > > Doing a ptrace fpstate_read would make "memory valid" > > true, but

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

2016-10-04 Thread Ingo Molnar
* Andy Lutomirski wrote: > > Running the task in user space, would have to ensure > > "registers valid" is true, and make "memory valid" > > false, because userspace could write to the registers. > > > > Doing a ptrace fpstate_read would make "memory valid" > > true, but does not need to

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

2016-10-03 Thread Andy Lutomirski
On Mon, Oct 3, 2016 at 7:47 PM, Rik van Riel wrote: > On Mon, 2016-10-03 at 19:09 -0700, Andy Lutomirski wrote: > >> > Having two separate status booleans for "registers valid" >> > and "memory valid" may make more sense. >> >> I have no problem with the concept of "owner_ctx",

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

2016-10-03 Thread Andy Lutomirski
On Mon, Oct 3, 2016 at 7:47 PM, Rik van Riel wrote: > On Mon, 2016-10-03 at 19:09 -0700, Andy Lutomirski wrote: > >> > Having two separate status booleans for "registers valid" >> > and "memory valid" may make more sense. >> >> I have no problem with the concept of "owner_ctx", and I think it's a

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

2016-10-03 Thread Andy Lutomirski
On Oct 3, 2016 7:11 PM, "Rik van Riel" wrote: > > On Mon, 2016-10-03 at 14:36 -0700, Andy Lutomirski wrote: > > > > Anything else that tries to read task xstate from memory, i.e. MPX > > and > > PKRU. (Although if we switch to eager-switched PKRU, then PKRU stops > > mattering

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

2016-10-03 Thread Andy Lutomirski
On Oct 3, 2016 7:11 PM, "Rik van Riel" wrote: > > On Mon, 2016-10-03 at 14:36 -0700, Andy Lutomirski wrote: > > > > Anything else that tries to read task xstate from memory, i.e. MPX > > and > > PKRU. (Although if we switch to eager-switched PKRU, then PKRU stops > > mattering for this purpose.)

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

2016-10-03 Thread Rik van Riel
On Mon, 2016-10-03 at 19:09 -0700, Andy Lutomirski wrote: > > Having two separate status booleans for "registers valid" > > and "memory valid" may make more sense. > > I have no problem with the concept of "owner_ctx", and I think it's a > perfectly reasonable data structure.  My problem with it

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

2016-10-03 Thread Rik van Riel
On Mon, 2016-10-03 at 19:09 -0700, Andy Lutomirski wrote: > > Having two separate status booleans for "registers valid" > > and "memory valid" may make more sense. > > I have no problem with the concept of "owner_ctx", and I think it's a > perfectly reasonable data structure.  My problem with it

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

2016-10-03 Thread Rik van Riel
On Mon, 2016-10-03 at 14:36 -0700, Andy Lutomirski wrote: >  > Anything else that tries to read task xstate from memory, i.e. MPX > and > PKRU.  (Although if we switch to eager-switched PKRU, then PKRU stops > mattering for this purpose.) > > Actually, I don't see any way your patches can be

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

2016-10-03 Thread Rik van Riel
On Mon, 2016-10-03 at 14:36 -0700, Andy Lutomirski wrote: >  > Anything else that tries to read task xstate from memory, i.e. MPX > and > PKRU.  (Although if we switch to eager-switched PKRU, then PKRU stops > mattering for this purpose.) > > Actually, I don't see any way your patches can be

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

2016-10-03 Thread Andy Lutomirski
On Mon, Oct 3, 2016 at 6:29 PM, Rik van Riel wrote: > On Mon, 2016-10-03 at 14:36 -0700, Andy Lutomirski wrote: >> On Mon, Oct 3, 2016 at 2:21 PM, Rik van Riel wrote: >> > >> > > >> > > One of my objections to the current code structure is that I find >> > > it

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

2016-10-03 Thread Andy Lutomirski
On Mon, Oct 3, 2016 at 6:29 PM, Rik van Riel wrote: > On Mon, 2016-10-03 at 14:36 -0700, Andy Lutomirski wrote: >> On Mon, Oct 3, 2016 at 2:21 PM, Rik van Riel wrote: >> > >> > > >> > > One of my objections to the current code structure is that I find >> > > it >> > > quite hard to keep track of

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

2016-10-03 Thread Rik van Riel
On Mon, 2016-10-03 at 14:36 -0700, Andy Lutomirski wrote: > On Mon, Oct 3, 2016 at 2:21 PM, Rik van Riel wrote: > >  > > > > > > One of my objections to the current code structure is that I find > > > it > > > quite hard to keep track of all of the possible states of the fpu > >

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

2016-10-03 Thread Rik van Riel
On Mon, 2016-10-03 at 14:36 -0700, Andy Lutomirski wrote: > On Mon, Oct 3, 2016 at 2:21 PM, Rik van Riel wrote: > >  > > > > > > One of my objections to the current code structure is that I find > > > it > > > quite hard to keep track of all of the possible states of the fpu > > > that > > > we

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

2016-10-03 Thread Andy Lutomirski
On Mon, Oct 3, 2016 at 2:21 PM, Rik van Riel wrote: > On Mon, 2016-10-03 at 13:54 -0700, Andy Lutomirski wrote: >> On Sat, Oct 1, 2016 at 5:08 PM, Rik van Riel wrote: >> > >> > On Sat, 2016-10-01 at 16:44 -0700, Andy Lutomirski wrote: >> > > >> > > On Sat, Oct

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

2016-10-03 Thread Andy Lutomirski
On Mon, Oct 3, 2016 at 2:21 PM, Rik van Riel wrote: > On Mon, 2016-10-03 at 13:54 -0700, Andy Lutomirski wrote: >> On Sat, Oct 1, 2016 at 5:08 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, wrote: >> > >

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

2016-10-03 Thread Rik van Riel
On Mon, 2016-10-03 at 13:54 -0700, Andy Lutomirski wrote: > On Sat, Oct 1, 2016 at 5:08 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,   wrote: > > > > > > > > > > > >  

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

2016-10-03 Thread Rik van Riel
On Mon, 2016-10-03 at 13:54 -0700, Andy Lutomirski wrote: > On Sat, Oct 1, 2016 at 5:08 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,   wrote: > > > > > > > > > > > >  #define CREATE_TRACE_POINTS > > > >  

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

2016-10-03 Thread Andy Lutomirski
On Sat, Oct 1, 2016 at 5:08 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, wrote: >> > >> > #define CREATE_TRACE_POINTS >> > #include >> > @@ -197,6 +198,9 @@ __visible inline void >> >

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

2016-10-03 Thread Andy Lutomirski
On Sat, Oct 1, 2016 at 5:08 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, wrote: >> > >> > #define CREATE_TRACE_POINTS >> > #include >> > @@ -197,6 +198,9 @@ __visible inline void >> > prepare_exit_to_usermode(struct

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

2016-10-03 Thread Dave Hansen
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, wrote: >>> > > +static inline void switch_fpu_finish(void) >>> > > { >>> > > + set_thread_flag(TIF_LOAD_FPU); >>> > > } >> > >> >

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

2016-10-03 Thread Dave Hansen
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, wrote: >>> > > +static inline void switch_fpu_finish(void) >>> > > { >>> > > + set_thread_flag(TIF_LOAD_FPU); >>> > > } >> > >> > I can imagine

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

2016-10-01 Thread Rik van Riel
On Sat, 2016-10-01 at 16:44 -0700, Andy Lutomirski wrote: > On Sat, Oct 1, 2016 at 1:31 PM,   wrote: > >  > > > > +static inline void switch_fpu_finish(void) > >  { > > +   set_thread_flag(TIF_LOAD_FPU); > >  } > > I can imagine this causing problems with kernel code that

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

2016-10-01 Thread Rik van Riel
On Sat, 2016-10-01 at 16:44 -0700, Andy Lutomirski wrote: > On Sat, Oct 1, 2016 at 1:31 PM,   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 >

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

2016-10-01 Thread Rik van Riel
On Sat, 2016-10-01 at 16:44 -0700, Andy Lutomirski wrote: > On Sat, Oct 1, 2016 at 1:31 PM,   wrote: > >  > >  #define CREATE_TRACE_POINTS > >  #include > > @@ -197,6 +198,9 @@ __visible inline void > > prepare_exit_to_usermode(struct pt_regs *regs) > > if

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

2016-10-01 Thread Rik van Riel
On Sat, 2016-10-01 at 16:44 -0700, Andy Lutomirski wrote: > On Sat, Oct 1, 2016 at 1:31 PM,   wrote: > >  > >  #define CREATE_TRACE_POINTS > >  #include > > @@ -197,6 +198,9 @@ __visible inline void > > prepare_exit_to_usermode(struct pt_regs *regs) > > if (unlikely(cached_flags &

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

2016-10-01 Thread Andy Lutomirski
On Sat, Oct 1, 2016 at 1:31 PM, wrote: > From: Rik van Riel > > Delay the loading of FPU registers until a process switches back to > userspace. This allows us to skip FPU saving & restoring for kernel > threads, the idle task, and tasks that are spinning in

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

2016-10-01 Thread Andy Lutomirski
On Sat, Oct 1, 2016 at 1:31 PM, wrote: > From: Rik van Riel > > Delay the loading of FPU registers until a process switches back to > userspace. This allows us to skip FPU saving & restoring for kernel > threads, the idle task, and tasks that are spinning in kernel space. > > It also allows us

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

2016-10-01 Thread riel
From: Rik van Riel Delay the loading of FPU registers until a process switches back to userspace. This allows us to skip FPU saving & restoring for kernel threads, the idle task, and tasks that are spinning in kernel space. It also allows us to not repeatedly save & restore the

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

2016-10-01 Thread riel
From: Rik van Riel Delay the loading of FPU registers until a process switches back to userspace. This allows us to skip FPU saving & restoring for kernel threads, the idle task, and tasks that are spinning in kernel space. It also allows us to not repeatedly save & restore the userspace FPU