From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752201AbcGLHNR (ORCPT ); Tue, 12 Jul 2016 03:13:17 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36143 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752090AbcGLHNL (ORCPT ); Tue, 12 Jul 2016 03:13:11 -0400 Date: Tue, 12 Jul 2016 09:13:05 +0200 From: Ingo Molnar To: Dave Hansen Cc: Andy Lutomirski , linux-arch , Thomas Gleixner , "linux-mm@kvack.org" , Mel Gorman , Linus Torvalds , Andrew Morton , Linux API , Arnd Bergmann , "linux-kernel@vger.kernel.org" , Al Viro , Peter Zijlstra , Hugh Dickins , "H. Peter Anvin" , X86 ML , Dave Hansen Subject: Re: [PATCH 6/9] x86, pkeys: add pkey set/get syscalls Message-ID: <20160712071305.GA13444@gmail.com> References: <20160707124719.3F04C882@viggo.jf.intel.com> <20160707124728.C1116BB1@viggo.jf.intel.com> <20160707144508.GZ11498@techsingularity.net> <577E924C.6010406@sr71.net> <20160708071810.GA27457@gmail.com> <577FD587.6050101@sr71.net> <20160709083715.GA29939@gmail.com> <20160711073534.GA19615@gmail.com> <5783AD25.8020303@sr71.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5783AD25.8020303@sr71.net> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * 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 matter to applications: > > > > - 'writer thread' gets a RW- key into index 1 to a specific data area > > - a pool of 'reader threads' may get the same pkey index 1 R-- to read the data > > area. > > > > Same page tables, same index, two protections and two purposes. > > > > With a global, per MM allocation of keys we'd have to use two indices: index 1 and 2. > > I'm not sure how this would work. A piece of data mapped at only one virtual > address can have only one key associated with it. Yeah, indeed, got myself confused there - but the actual protection bits are per CPU (per task). > 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 'incomplete shadowing' - for example the debug code couldn't work: if we cleared a pkey in a task we wouldn't know what to restore it to with the current data structures, right? Thanks, Ingo