Received: by 10.223.176.46 with SMTP id f43csp306877wra; Thu, 18 Jan 2018 17:54:29 -0800 (PST) X-Google-Smtp-Source: ACJfBotpH363VR6Lgqv0b9r3tgQrYeTCH6czFUFMrq5xGpnR94LWnL1MryrWdDFiAEbHMmgQIn0y X-Received: by 10.101.67.130 with SMTP id m2mr8228419pgp.301.1516326869270; Thu, 18 Jan 2018 17:54:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516326869; cv=none; d=google.com; s=arc-20160816; b=INyKBBlwS9HWqerOe8iAh+hmGEmu8c09JsvA77LE2EZfKjAUIWjXwjjz6BIOyliPXD PRSG8btUOHHQ2udVAYRTOevI0GLQkn1B40M6UxETjeTdjtja6X4KBZVdJ64O76umjafl O8OHOi+gfr3EMAjsEjxy3v/UaM6BbzNwkOHJp+7JTlC5YIcBPh6YwF9aG1FqhobjfbT4 l7YqBVjUUn7Vlcht+p3qhHbInGU31A2k7bmxb/yJCpEOs5qnNSRr68zTMfP/AMo001Du umeDO8yaICwNkzPxdml2e+tbGiDAO/8BcG37dnEpEH8FlBxNdAq+4qp1rDvnxMkESMpb +evg== 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=MyzLrYKN+4yb1SHSPuEC0ERPfu+hwKpqoaeD0VvtKd4=; b=zXYmogX8ZAHfVy1YnKoN9p5GWsep1IGKRel8n99Wy4y6UQQYVdIJiyLW7uImSI10gE OSrtXwoqnZf2Z94UL+SXjX56jZB91nvAzGCVov5Hwa59wbPVyytLQL1Eh/qKh9hknmJI 2pZDKpyXPqnE3vZNM1SM8wukScd4E1Nh9pDAeUENJB2pwnEA88tQPKp7GAd6uuOMv5KC mSPZWJxs+DgypPC+C9KyLFjmJ3/rrPhnPgQ6mYZV0ahwNFgBI5eG2tYOpGih45QMMavh lekQ3qGZPMuAT8ijcPq2M3O89/pE4cpIxez9W/3qFy/1Xrao88mF9Me+rcNF5Sr9l4Nb 4kWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=pQjhadAU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd7-v6si392039plb.637.2018.01.18.17.54.15; Thu, 18 Jan 2018 17:54:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=pQjhadAU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S932934AbeASBx4 (ORCPT + 99 others); Thu, 18 Jan 2018 20:53:56 -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 Received: by mail-qt0-f193.google.com with SMTP id s3so422499qtb.10; Thu, 18 Jan 2018 17:52:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=MyzLrYKN+4yb1SHSPuEC0ERPfu+hwKpqoaeD0VvtKd4=; b=pQjhadAUwXQEQXNSAroU9HPvoPU3OyYFa9LIGnbxUrMa1gG3+vNs7O200xavD4CHrF dfUQ8KQ24XML+39JNbI2V8EO5bCryaLBIO6kt/RclQAhBPwiutFbX1FW5q7JDlQw+uFm Qg2zZO4a1OXGZIyBN+0ibEKpkDhuABqw1lKZzl0VwVB19NnXxCycfRBK5S9BR7G+FazN 1BpEanW/mOYAt9xpFm7LK/mtarRWfPNuXjBwOtIUAtdJxnI1dr+uL7oGsS/C9Tbkuq9m sF5swTJlVVKKC7tAJS+fpRv5XicgmYda5s9KQbL8mUX4pB5AWEAL020Eq6U7oBeULW+/ VJvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=MyzLrYKN+4yb1SHSPuEC0ERPfu+hwKpqoaeD0VvtKd4=; b=chcz3MOWsDZXhyqjBgiXLTTFgySXo0/RjJ8WEPEoOZbBhlP7RPSUqAFxZMfBNu0csI rujgCTKZyNZj3GXpDakP9lkIiExuujfsVCqem9wbhQajrtEyz6OuicWkphFOQHFtXnQg 654Cuuuu5IYvi4iuQdpD+usAI+BZ0fui0HxcBs/yg2O8FHOd75X/fHjt/Q8dqQhVFIwn h9Xx6IuS4z+oFI4dB2Y7HI+ZwtkjjKaSnU8QwBjiQw72M9LQm1mTwtWAbT13liF58ziI oaBsddMaPLUNB8rN0pBHIuSVotC1bRtyMYsC/A17QP4EgAPfipBYshDZAyb3LUd4ldcB 6a/w== X-Gm-Message-State: AKwxytcxxoMG+e1L3IQ9TuU/S6scboR7G9081X5Wi2NTqzUA0tRgzmq9 1sksHMoTCEsLTQoSxw1azVw= X-Received: by 10.200.23.219 with SMTP id r27mr24274173qtk.314.1516326755074; Thu, 18 Jan 2018 17:52:35 -0800 (PST) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id c127sm5483161qke.78.2018.01.18.17.52.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 17:52:34 -0800 (PST) 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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