From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dave Hansen Subject: [PATCH 1/9] x86, pkeys: add fault handling for PF_PK page fault bit Date: Tue, 07 Jun 2016 13:47:14 -0700 Message-ID: <20160607204714.DBBB24D2@viggo.jf.intel.com> References: <20160607204712.594DE00A@viggo.jf.intel.com> Return-path: In-Reply-To: <20160607204712.594DE00A-LXbPSdftPKxrdx17CPfAsdBPR1lH4CV8@public.gmane.org> Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-arch-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org, akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org, Dave Hansen , dave.hansen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org List-Id: linux-api@vger.kernel.org From: Dave Hansen PF_PK means that a memory access violated the protection key access restrictions. It is unconditionally an access_error() because the permissions set on the VMA don't matter (the PKRU value overrides it), and we never "resolve" PK faults (like how a COW can "resolve write fault). Signed-off-by: Dave Hansen --- b/arch/x86/mm/fault.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff -puN arch/x86/mm/fault.c~pkeys-105-add-pk-to-fault arch/x86/mm/fault.c --- a/arch/x86/mm/fault.c~pkeys-105-add-pk-to-fault 2016-06-07 13:22:18.529937509 -0700 +++ b/arch/x86/mm/fault.c 2016-06-07 13:22:18.534937739 -0700 @@ -1112,6 +1112,15 @@ access_error(unsigned long error_code, s { /* This is only called for the current mm, so: */ bool foreign = false; + + /* + * Read or write was blocked by protection keys. This is + * always an unconditional error and can never result in + * a follow-up action to resolve the fault, like a COW. + */ + if (error_code & PF_PK) + return 1; + /* * Make sure to check the VMA so that we do not perform * faults just to hit a PF_PK as soon as we fill in a _