Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-19 Thread Andy Lutomirski
> On Sep 19, 2018, at 10:00 AM, Paolo Bonzini wrote: > >> On 19/09/2018 18:57, Sebastian Andrzej Siewior wrote: >>> On 2018-09-19 07:55:51 [+0200], Paolo Bonzini wrote: >>> A kthread can do use_mm/unuse_mm. >> >> indeed. The FPU struct for the kernel thread isn't valid / does not >> contain t

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-19 Thread Rik van Riel
> On Sep 19, 2018, at 1:00 PM, Paolo Bonzini wrote: > > On 19/09/2018 18:57, Sebastian Andrzej Siewior wrote: >> On 2018-09-19 07:55:51 [+0200], Paolo Bonzini wrote: >>> A kthread can do use_mm/unuse_mm. >> >> indeed. The FPU struct for the kernel thread isn't valid / does not >> contain the

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-19 Thread Sebastian Andrzej Siewior
On 2018-09-19 19:00:34 [+0200], Paolo Bonzini wrote: > On 19/09/2018 18:57, Sebastian Andrzej Siewior wrote: > > On 2018-09-19 07:55:51 [+0200], Paolo Bonzini wrote: > >> A kthread can do use_mm/unuse_mm. > > > > indeed. The FPU struct for the kernel thread isn't valid / does not > > contain the e

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-19 Thread Paolo Bonzini
On 19/09/2018 18:57, Sebastian Andrzej Siewior wrote: > On 2018-09-19 07:55:51 [+0200], Paolo Bonzini wrote: >> A kthread can do use_mm/unuse_mm. > > indeed. The FPU struct for the kernel thread isn't valid / does not > contain the expected PKRU value. So loading the pkru value from the > struct F

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-19 Thread Sebastian Andrzej Siewior
On 2018-09-19 07:55:51 [+0200], Paolo Bonzini wrote: > A kthread can do use_mm/unuse_mm. indeed. The FPU struct for the kernel thread isn't valid / does not contain the expected PKRU value. So loading the pkru value from the struct FPU does not work as expected. We could set it to 0 for a kernel t

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-18 Thread Paolo Bonzini
On 18/09/2018 19:29, Rik van Riel wrote: > On Tue, 2018-09-18 at 18:04 +0200, Sebastian Andrzej Siewior wrote: >> On 2018-09-18 17:29:52 [+0200], Paolo Bonzini wrote: I don't think it matters what the PKRU state is for kernel threads, since kernel PTEs should not be using protection

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-18 Thread Rik van Riel
On Tue, 2018-09-18 at 18:04 +0200, Sebastian Andrzej Siewior wrote: > On 2018-09-18 17:29:52 [+0200], Paolo Bonzini wrote: > > > I don't think it matters what the PKRU state is > > > for kernel threads, since kernel PTEs should not > > > be using protection keys anyway. > > > > What about copy_fro

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-18 Thread Sebastian Andrzej Siewior
On 2018-09-18 17:29:52 [+0200], Paolo Bonzini wrote: > > I don't think it matters what the PKRU state is > > for kernel threads, since kernel PTEs should not > > be using protection keys anyway. > > What about copy_from/to_user? This doesn't work for a kernel thread, does it? I mean they share th

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-18 Thread Paolo Bonzini
On 18/09/2018 17:11, Rik van Riel wrote: > On Tue, 2018-09-18 at 17:07 +0200, Paolo Bonzini wrote: >> On 18/09/2018 16:27, Sebastian Andrzej Siewior wrote: Likewise, move this to fpu__clear and outside "if (static_cpu_has(X86_FEATURE_FPU))"? >>> >>> okay. But if there is no FPU we did not

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-18 Thread Rik van Riel
On Tue, 2018-09-18 at 17:07 +0200, Paolo Bonzini wrote: > On 18/09/2018 16:27, Sebastian Andrzej Siewior wrote: > > > Likewise, move this to fpu__clear and outside "if > > > (static_cpu_has(X86_FEATURE_FPU))"? > > > > okay. But if there is no FPU we did not save/restore the pkru > > value. Is > >

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-18 Thread Paolo Bonzini
On 18/09/2018 16:27, Sebastian Andrzej Siewior wrote: >> Likewise, move this to fpu__clear and outside "if >> (static_cpu_has(X86_FEATURE_FPU))"? > okay. But if there is no FPU we did not save/restore the pkru value. Is > this supposed to be an improvement? Honestly it just seemed "more correct",

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-18 Thread Sebastian Andrzej Siewior
On 2018-09-17 10:37:20 [+0200], Paolo Bonzini wrote: > > . This is (again) > > untested since I have no box with this PKRU feature. This only available > > on Intel's Xeon Scalable, right? > > It is available on QEMU too (the slower JIT thing without KVM, i.e. use > /usr/bin/qemu-system-x86_64 ins

Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-17 Thread Paolo Bonzini
>> I think you can go a step further and exclude PKRU state from >> copy_kernel_to_fpregs altogether; you just use RDPKRU/WRPKRU. This also >> means you don't need to call __fpregs_* functions in write_pkru. > > something like this then? It looks like kvm excludes PKRU from > xsave/xrestore, too.

[RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state

2018-09-14 Thread Sebastian Andrzej Siewior
While most of a task's FPU state is only needed in user space, the protection keys need to be in place immediately after a context switch. The reason is that any accesses to userspace memory while running in kernel mode also need to abide by the memory permissions specified in the protection keys.