From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932487AbbJPPMv (ORCPT ); Fri, 16 Oct 2015 11:12:51 -0400 Received: from www.sr71.net ([198.145.64.142]:40735 "EHLO blackbird.sr71.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932393AbbJPPMu (ORCPT ); Fri, 16 Oct 2015 11:12:50 -0400 Subject: Re: [PATCH 26/26] x86, pkeys: Documentation To: Ingo Molnar References: <20150916174913.AF5FEA6D@viggo.jf.intel.com> <20150920085554.GA21906@gmail.com> <55FF88BA.6080006@sr71.net> <20150924094956.GA30349@gmail.com> <56044A88.7030203@sr71.net> <20151001111718.GA25333@gmail.com> <20151002062340.GB30051@gmail.com> <560EC3EC.2080803@sr71.net> <20151003072755.GA23524@gmail.com> Cc: Andy Lutomirski , Kees Cook , "x86@kernel.org" , LKML , Linux-MM , Linus Torvalds , Andrew Morton , Peter Zijlstra , Andy Lutomirski , Borislav Petkov From: Dave Hansen Message-ID: <562113F0.6060307@sr71.net> Date: Fri, 16 Oct 2015 08:12:48 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <20151003072755.GA23524@gmail.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/03/2015 12:27 AM, Ingo Molnar wrote: > - Along similar considerations, also add a sys_pkey_query() system call to query > the mapping of a specific pkey. (returns -EBADF or so if the key is not mapped > at the moment.) This too could be vDSO accelerated in the future. > > I.e. something like: > > unsigned long sys_pkey_alloc (unsigned long flags, unsigned long init_val) > unsigned long sys_pkey_set (int pkey, unsigned long new_val) > unsigned long sys_pkey_get (int pkey) > unsigned long sys_pkey_free (int pkey) The pkey_set() operation is going to get a wee bit interesting with signals. pkey_set() will modify the _current_ context's PKRU which includes the register itself and the kernel XSAVE buffer (if active). But, since the PKRU state is saved/restored with the XSAVE state, we will blow away any state set during the signal. I _think_ the right move here is to either keep a 'shadow' version of PKRU inside the kernel (for each thread) and always update the task's XSAVE PKRU state when returning from a signal handler. Or, _copy_ the signal's PKRU state in to the main process's PKRU state when returning from a signal.