From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f43.google.com (mail-pa0-f43.google.com [209.85.220.43]) by kanga.kvack.org (Postfix) with ESMTP id E3B8C6B0267 for ; Mon, 28 Sep 2015 15:18:39 -0400 (EDT) Received: by pablk4 with SMTP id lk4so85260246pab.3 for ; Mon, 28 Sep 2015 12:18:39 -0700 (PDT) Received: from mga01.intel.com (mga01.intel.com. [192.55.52.88]) by mx.google.com with ESMTP id pg2si30752755pbb.36.2015.09.28.12.18.23 for ; Mon, 28 Sep 2015 12:18:23 -0700 (PDT) Subject: [PATCH 13/25] mm: factor out VMA fault permission checking From: Dave Hansen Date: Mon, 28 Sep 2015 12:18:22 -0700 References: <20150928191817.035A64E2@viggo.jf.intel.com> In-Reply-To: <20150928191817.035A64E2@viggo.jf.intel.com> Message-Id: <20150928191822.DFCE608C@viggo.jf.intel.com> Sender: owner-linux-mm@kvack.org List-ID: To: dave@sr71.net Cc: borntraeger@de.ibm.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, dave.hansen@linux.intel.com From: Dave Hansen This code matches a fault condition up with the VMA and ensures that the VMA allows the fault to be handled instead of just erroring out. We will be extending this in a moment to comprehend protection keys. Signed-off-by: Dave Hansen --- b/mm/gup.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff -puN mm/gup.c~pkeys-10-pte-fault mm/gup.c --- a/mm/gup.c~pkeys-10-pte-fault 2015-09-28 11:39:46.790221164 -0700 +++ b/mm/gup.c 2015-09-28 11:39:46.794221345 -0700 @@ -554,6 +554,17 @@ next_page: } EXPORT_SYMBOL(__get_user_pages); +bool vma_permits_fault(struct vm_area_struct *vma, unsigned int fault_flags) +{ + vm_flags_t vm_flags = + (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ; + + if (!(vm_flags & vma->vm_flags)) + return false; + + return true; +} + /* * fixup_user_fault() - manually resolve a user page fault * @tsk: the task_struct to use for page fault accounting, or @@ -585,15 +596,13 @@ int fixup_user_fault(struct task_struct unsigned long address, unsigned int fault_flags) { struct vm_area_struct *vma; - vm_flags_t vm_flags; int ret; vma = find_extend_vma(mm, address); if (!vma || address < vma->vm_start) return -EFAULT; - vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ; - if (!(vm_flags & vma->vm_flags)) + if (!vma_permits_fault(vma, fault_flags)) return -EFAULT; ret = handle_mm_fault(mm, vma, address, fault_flags); _ -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org