Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-18 Thread Dave Hansen
On 07/09/2016 01:37 AM, Ingo Molnar wrote: > - There are 16 pkey indices on x86 currently. We already use index 15 for > the >true PROT_EXEC implementation. Let's set aside another pkey index for the >kernel's potential future use (index 14), and clear it explicitly in the >FPU con

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-18 Thread Dave Hansen
On 07/09/2016 01:37 AM, Ingo Molnar wrote: >I.e. this pattern: > > ret = pkey_mprotect(NULL, PAGE_SIZE, real_prot, pkey); > >... would validate the pkey and we'd return -EOPNOTSUPP for pkey that is > not >available? This would allow maximum future flexibility as it would not >

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-18 Thread Ingo Molnar
* Andy Lutomirski wrote: > On Thu, Jul 14, 2016 at 1:07 AM, Ingo Molnar wrote: > > > > * Andy Lutomirski wrote: > > > >> On Wed, Jul 13, 2016 at 12:56 AM, Ingo Molnar wrote: > >> > > >> > * Andy Lutomirski wrote: > >> > > >> >> > If we push a PKRU value into a thread between the rdpkru() and

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-17 Thread Andy Lutomirski
On Thu, Jul 14, 2016 at 1:07 AM, Ingo Molnar wrote: > > * Andy Lutomirski wrote: > >> On Wed, Jul 13, 2016 at 12:56 AM, Ingo Molnar wrote: >> > >> > * Andy Lutomirski wrote: >> > >> >> > If we push a PKRU value into a thread between the rdpkru() and >> >> > wrpkru(), we'll >> >> > lose the con

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-14 Thread Ingo Molnar
* Andy Lutomirski wrote: > On Wed, Jul 13, 2016 at 12:56 AM, Ingo Molnar wrote: > > > > * Andy Lutomirski wrote: > > > >> > If we push a PKRU value into a thread between the rdpkru() and wrpkru(), > >> > we'll > >> > lose the content of that "push". I'm not sure there's any way to > >> > gu

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-13 Thread Andy Lutomirski
On Wed, Jul 13, 2016 at 12:56 AM, Ingo Molnar wrote: > > * Andy Lutomirski wrote: > >> > If we push a PKRU value into a thread between the rdpkru() and wrpkru(), >> > we'll >> > lose the content of that "push". I'm not sure there's any way to guarantee >> > this with a user-controlled register.

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-13 Thread Ingo Molnar
* Andy Lutomirski wrote: > > If we push a PKRU value into a thread between the rdpkru() and wrpkru(), > > we'll > > lose the content of that "push". I'm not sure there's any way to guarantee > > this with a user-controlled register. > > We could try to insist that user code uses some vsysca

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-12 Thread Andy Lutomirski
On Tue, Jul 12, 2016 at 10:12 AM, Dave Hansen wrote: > On 07/12/2016 09:32 AM, Andy Lutomirski wrote: >> I think it's more or less impossible to get sensible behavior passing >> pkey != 0 data to legacy functions. If you call: >> >> void frob(struct foo *p); >> >> If frob in turn passes p to a th

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-12 Thread Dave Hansen
On 07/12/2016 09:32 AM, Andy Lutomirski wrote: > I think it's more or less impossible to get sensible behavior passing > pkey != 0 data to legacy functions. If you call: > > void frob(struct foo *p); > > If frob in turn passes p to a thread, what PKRU is it supposed to use? The thread inheritan

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-12 Thread Andy Lutomirski
On Jul 11, 2016 8:48 AM, "Dave Hansen" wrote: > > On 07/11/2016 07:45 AM, Andy Lutomirski wrote: > > On Mon, Jul 11, 2016 at 7:34 AM, Dave Hansen wrote: > >> Should we instead just recommend to userspace that they lock down access > >> to keys by default in all threads as a best practice? > > > >

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-12 Thread Dave Hansen
On 07/12/2016 12:13 AM, Ingo Molnar wrote: >> > Remember, PKRU is just a *bitmap*. The only place keys are stored is in >> > the >> > page tables. > A pkey is an index *and* a protection mask. So by representing it as a > bitmask we > lose per thread information. This is what I meant by 'incom

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-12 Thread Ingo Molnar
* Dave Hansen wrote: > On 07/11/2016 12:35 AM, Ingo Molnar wrote: > > * Andy Lutomirski wrote: > > mprotect_pkey()'s effects are per MM, but the system calls related to > > managing the > > keys (alloc/free/get/set) are fundamentally per CPU. > > > > Here's an example of how this could matte

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-11 Thread Dave Hansen
On 07/11/2016 07:45 AM, Andy Lutomirski wrote: > On Mon, Jul 11, 2016 at 7:34 AM, Dave Hansen wrote: >> Should we instead just recommend to userspace that they lock down access >> to keys by default in all threads as a best practice? > > Is that really better than doing it in-kernel? My concern

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-11 Thread Andy Lutomirski
On Mon, Jul 11, 2016 at 12:35 AM, Ingo Molnar wrote: > > * Andy Lutomirski wrote: > >> On Jul 9, 2016 1:37 AM, "Ingo Molnar" wrote: >> > >> > >> > * Dave Hansen wrote: >> > >> > > On 07/08/2016 12:18 AM, Ingo Molnar wrote: >> > > >> > > > So the question is, what is user-space going to do? Do a

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-11 Thread Andy Lutomirski
On Mon, Jul 11, 2016 at 7:34 AM, Dave Hansen wrote: > On 07/10/2016 09:25 PM, Andy Lutomirski wrote: >> 2. When thread A allocates a pkey, how does it lock down thread B? >> >> #2 could be addressed by using fully-locked-down as the initial state >> post-exec() and copying the state on clone(). D

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-11 Thread Dave Hansen
On 07/10/2016 09:25 PM, Andy Lutomirski wrote: > 2. When thread A allocates a pkey, how does it lock down thread B? > > #2 could be addressed by using fully-locked-down as the initial state > post-exec() and copying the state on clone(). Dave, are there any > cases in practice where one thread wo

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-11 Thread Dave Hansen
On 07/11/2016 12:35 AM, Ingo Molnar wrote: > * Andy Lutomirski wrote: > mprotect_pkey()'s effects are per MM, but the system calls related to > managing the > keys (alloc/free/get/set) are fundamentally per CPU. > > Here's an example of how this could matter to applications: > > - 'writer thr

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-11 Thread Ingo Molnar
* Andy Lutomirski wrote: > On Jul 9, 2016 1:37 AM, "Ingo Molnar" wrote: > > > > > > * Dave Hansen wrote: > > > > > On 07/08/2016 12:18 AM, Ingo Molnar wrote: > > > > > > > So the question is, what is user-space going to do? Do any glibc patches > > > > exist? How are the user-space library sid

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-10 Thread Andy Lutomirski
On Jul 9, 2016 1:37 AM, "Ingo Molnar" wrote: > > > * Dave Hansen wrote: > > > On 07/08/2016 12:18 AM, Ingo Molnar wrote: > > > > > So the question is, what is user-space going to do? Do any glibc patches > > > exist? How are the user-space library side APIs going to look like? > > > > My goal at

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-09 Thread Ingo Molnar
* Dave Hansen wrote: > On 07/08/2016 12:18 AM, Ingo Molnar wrote: > > > So the question is, what is user-space going to do? Do any glibc patches > > exist? How are the user-space library side APIs going to look like? > > My goal at the moment is to get folks enabled to the point that they can

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-08 Thread Dave Hansen
On 07/08/2016 12:18 AM, Ingo Molnar wrote: > So my hope was that we'd also grow some debugging features: such as a > periodic > watchdog timer clearing all non-allocated pkeys of a task and re-setting them > to > their (kernel-)known values and thus forcing user-space to coordinate key > alloc

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-08 Thread Dave Hansen
On 07/08/2016 12:18 AM, Ingo Molnar wrote: > So the question is, what is user-space going to do? Do any glibc > patches exist? How are the user-space library side APIs going to look > like? My goal at the moment is to get folks enabled to the point that they can start modifying apps to use pkeys w

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-08 Thread Mel Gorman
On Thu, Jul 07, 2016 at 10:33:00AM -0700, Dave Hansen wrote: > On 07/07/2016 07:45 AM, Mel Gorman wrote: > > On Thu, Jul 07, 2016 at 05:47:28AM -0700, Dave Hansen wrote: > >> > > >> > From: Dave Hansen > >> > > >> > This establishes two more system calls for protection key management: > >> > >

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-08 Thread Ingo Molnar
* Dave Hansen wrote: > > Applications that frequently get called will get hammed into the ground > > with > > serialisation on mmap_sem not to mention the cost of the syscall entry/exit. > > I think we can do both of them without mmap_sem, as long as we resign > ourselves > to this just bein

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-07 Thread Dave Hansen
On 07/07/2016 07:45 AM, Mel Gorman wrote: > On Thu, Jul 07, 2016 at 05:47:28AM -0700, Dave Hansen wrote: >> > >> > From: Dave Hansen >> > >> > This establishes two more system calls for protection key management: >> > >> >unsigned long pkey_get(int pkey); >> >int pkey_set(int pkey, unsi

Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls

2016-07-07 Thread Mel Gorman
On Thu, Jul 07, 2016 at 05:47:28AM -0700, Dave Hansen wrote: > > From: Dave Hansen > > This establishes two more system calls for protection key management: > > unsigned long pkey_get(int pkey); > int pkey_set(int pkey, unsigned long access_rights); > > The return value from pkey_g