From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: ACJfBosdOK01lrkh5kQyNskpFz1coQAN8m+mw2oTHOTpaOltvZkfWmZUBEBLWZjmEYkqL0ySxLAI ARC-Seal: i=1; a=rsa-sha256; t=1516326782; cv=none; d=google.com; s=arc-20160816; b=eMV2cbC8xY92v0I25iKgQGRb6kPc0fOzlnhqiztoU/hlFsjaW+YLZfakP2hq0oWPOH IX0lwEB7dUur/UfTDN7EzDdpJ+w4qIgy6vjZ3hBIYFRH/l3HPsKMvwALYj1TiB9F8NFb /72ZIqX+lztOvDGjTLZSXpR5cbj6qt82xvG1XAxol1wbQwWvYoAp1k8EiA4mudn/KpwA uKvhGlTm9lHItHGFkX+nrI2eThTcLtno6WrIP/W9MRe4OTZApDPrGQtD/MXuExT+gEMn 5jE/TGDz9kF0mOGQ+r7S9dU0821Vc149vL+jUA29vP+g8IA0Z1HDJXSDn9avjOEEuMal htAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=nMzLqniZKmu2OArkauT4sc4ppJ1brbWVFD1vwLmSMXU=; b=XQWW3L9mrxTuKVRJfxIjVceh4FbCRm+0l1g11CiOdEwdwhlK62ExMM1HV2ymZmcPPI yh87kv55mbT0+b2w674gC7khVjLq635pBkEBYJWfm0LeNSOYtrROtK439H6JCvYvn/vt WKCRd7Og/SOplI07f2JELhv7UsONuohwayHh0qlV9adJoyrTKgK8TqSjrq7c0ID85bhG bsZQTDih3il6fRwSmgyIf3YnhEUxruC7jyfdhfY9q32wd+0PVcTBA4mlvjSmrhnSgyAA muEBRIVTv8CPplQ6g0HPb32LRA9KbADiLKG3KOQNSDcLfYAAXz5ICiRUJTdJs3pgkKWh ivQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=pQjhadAU; spf=pass (google.com: best guess record for domain of linux-kselftest-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kselftest-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=pQjhadAU; spf=pass (google.com: best guess record for domain of linux-kselftest-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kselftest-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755869AbeASBxC (ORCPT ); Thu, 18 Jan 2018 20:53:02 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:44017 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755447AbeASBwf (ORCPT ); Thu, 18 Jan 2018 20:52:35 -0500 From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org, corbet@lwn.net, arnd@arndb.de Cc: linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, linuxram@us.ibm.com Subject: [PATCH v10 18/27] powerpc: implementation for arch_vma_access_permitted() Date: Thu, 18 Jan 2018 17:50:39 -0800 Message-Id: <1516326648-22775-19-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1516326648-22775-1-git-send-email-linuxram@us.ibm.com> References: <1516326648-22775-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kselftest-owner@vger.kernel.org X-Mailing-List: linux-kselftest@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1589983872283671809?= X-GMAIL-MSGID: =?utf-8?q?1589983872283671809?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: This patch provides the implementation for arch_vma_access_permitted(). Returns true if the requested access is allowed by pkey associated with the vma. Signed-off-by: Ram Pai --- arch/powerpc/include/asm/mmu_context.h | 5 +++- arch/powerpc/mm/pkeys.c | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletions(-) diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h index 209f127..cd2bd73 100644 --- a/arch/powerpc/include/asm/mmu_context.h +++ b/arch/powerpc/include/asm/mmu_context.h @@ -186,6 +186,10 @@ static inline void arch_bprm_mm_init(struct mm_struct *mm, { } +#ifdef CONFIG_PPC_MEM_KEYS +bool arch_vma_access_permitted(struct vm_area_struct *vma, bool write, + bool execute, bool foreign); +#else /* CONFIG_PPC_MEM_KEYS */ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, bool write, bool execute, bool foreign) { @@ -193,7 +197,6 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, return true; } -#ifndef CONFIG_PPC_MEM_KEYS #define pkey_mm_init(mm) #define thread_pkey_regs_save(thread) #define thread_pkey_regs_restore(new_thread, old_thread) diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c index 0e044ea..0701aa3 100644 --- a/arch/powerpc/mm/pkeys.c +++ b/arch/powerpc/mm/pkeys.c @@ -390,3 +390,37 @@ bool arch_pte_access_permitted(u64 pte, bool write, bool execute) return pkey_access_permitted(pte_to_pkey_bits(pte), write, execute); } + +/* + * We only want to enforce protection keys on the current thread because we + * effectively have no access to AMR/IAMR for other threads or any way to tell + * which AMR/IAMR in a threaded process we could use. + * + * So do not enforce things if the VMA is not from the current mm, or if we are + * in a kernel thread. + */ +static inline bool vma_is_foreign(struct vm_area_struct *vma) +{ + if (!current->mm) + return true; + + /* if it is not our ->mm, it has to be foreign */ + if (current->mm != vma->vm_mm) + return true; + + return false; +} + +bool arch_vma_access_permitted(struct vm_area_struct *vma, bool write, + bool execute, bool foreign) +{ + if (static_branch_likely(&pkey_disabled)) + return true; + /* + * Do not enforce our key-permissions on a foreign vma. + */ + if (foreign || vma_is_foreign(vma)) + return true; + + return pkey_access_permitted(vma_pkey(vma), write, execute); +} -- 1.7.1