Received: by 10.223.176.46 with SMTP id f43csp310046wra; Thu, 18 Jan 2018 17:58:30 -0800 (PST) X-Google-Smtp-Source: ACJfBouMCkN5CVASilMyimepSSGRBD1DeXyp/mtOAQ1pE152VfyHvBLZqyOFkE+P/KKIV8QtAGpk X-Received: by 10.99.168.76 with SMTP id i12mr17917572pgp.119.1516327109913; Thu, 18 Jan 2018 17:58:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516327109; cv=none; d=google.com; s=arc-20160816; b=RsSpUZ+brHLLv+iX1vjd6k1o/cvWq15ME+OK5ZJcGHI+w4xchpzcjBB9+QeUNvrnhl xu/yIAxafNtqjAp0reWp+4Yd7DY1In742fVn/kFL0o+vm8ItRqe8/2hu9542QllV3Ihx d721fTzoEG/zJDAM6JAE5qoRqEGDE6yjoJ1eg4HBr//VKH/oWK/OC1+jHZvCon+YABvP QUbspqKnpXUIQjIGpvN9S+XuAyPq/yEwVZUblJg+PfZoSOVZSJE7sUmWiM8w4cgqW98L zpNDCsaw10GukitQIVHd003Axvlh9enJbWxFKh6ZJVA6qljAr21P3UzrfJVpoJmFeqgt EjSw== 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=GjVyEtDqgGCbzi0fEuXPiceJTNc3WBGk0zHf4Lcv8Xc=; b=Brs59yShXjNmxKA7FYZw6bpOw7zg85402Su1zpi5KMzaAxe2a28OMgO7sx5U1pKSQQ lqSpcgoRjfbQNO856hEA62vawAFQxBGvQjvs1XE3MgDE95lgsL8SlRi0PMNW4NhsX0El ct7JCjRnDS4c2+0prgM5uG9tTIDsnGtBw2m/MaW6EU40U9du0nAJspoSnMiLi4gru+M3 1cwpeikQnBymIw34lgMAzq07mBxSyU/Xvv2oJlEAQNCt2DCD3IUlQNrwAppSYrmfW4Z/ 1AC78Wi75q1CIsxwy/7xp92fx8jQ5JcB1Ez6bBWiZ3Jlu9+Syu8W5t+lbkkkD4Anw6i6 KWbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=nXUx86D3; 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 a9si7321849pgn.474.2018.01.18.17.58.16; Thu, 18 Jan 2018 17:58: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=nXUx86D3; 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 S1755614AbeASBwT (ORCPT + 99 others); Thu, 18 Jan 2018 20:52:19 -0500 Received: from mail-qt0-f194.google.com ([209.85.216.194]:44952 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754833AbeASBvt (ORCPT ); Thu, 18 Jan 2018 20:51:49 -0500 Received: by mail-qt0-f194.google.com with SMTP id m59so417881qte.11; Thu, 18 Jan 2018 17:51:48 -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=GjVyEtDqgGCbzi0fEuXPiceJTNc3WBGk0zHf4Lcv8Xc=; b=nXUx86D3s251Ddp40FR/iU/ys8Gs2xip5skG6xBzC4Obsal7A5O3sK9w2oyiWkeG+W Ad1jQsffsC6la5opzVRR/xJdMS2pvZXnHHg/ibq9Vgq1JsNkpY4jtavdt5S2KzbOjWR/ SSPnOqgcq+Vjh1d5PSxpXy0fGogJzr7TNz263RQe0Nhd6yTNS0losO1tkUUFq75CsUy6 yFdPkphDdz87VfCjJzMClyy7RXfb4wr4FH4tIXtuvMFKjNjs7ibe2ju3jx2KOSWmGYVS QIy4Qe7BwUv3isV0V4/zs3eU3uFZa7NCQc29zckNXUIsbS+q1bNCs/yrOC35gzMWQCDT hlaw== 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=GjVyEtDqgGCbzi0fEuXPiceJTNc3WBGk0zHf4Lcv8Xc=; b=torBl3KOfu0CFe9ugQul4r6h7YBZhdfnKY1yfwwol30nRCc11yO73nLLuKZAenXyUs yrlx1P7VfzyN9Dj228Xxg9GHcHQpbB/ZX2hqG8R8M9bL7Cah5Xq0k2VsDWDqqiOI7CmY OJeqhCtm2j/b32OBJ35hGCKonjGjqRya9yeqrpOZcHe9I/BY6SG1IauDDe9aTjl3qXh2 x7sAt71utsp6Rq9QYZg5T5eqUtwjG55RCkVcdN/oTPyjFjSyEOgog3uSW5XK6BVRJhlb OzglK0GdCMdRyEtkpiadPhTTMyedzwMLIs9I2d8bNlOFYn27h96e4LtHXYLqw4vV2V8A CxWA== X-Gm-Message-State: AKwxytcRHOtAzTjSuXIPi0hsRbDGO4hFR73MPRvkLTshXJABrUR2POl6 vpJwkPfPpVEN3t6D84S2G6Q= X-Received: by 10.55.132.5 with SMTP id g5mr24886585qkd.257.1516326708274; Thu, 18 Jan 2018 17:51:48 -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.51.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 17:51:47 -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 03/27] powerpc: initial pkey plumbing Date: Thu, 18 Jan 2018 17:50:24 -0800 Message-Id: <1516326648-22775-4-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 Basic plumbing to initialize the pkey system. Nothing is enabled yet. A later patch will enable it once all the infrastructure is in place. Signed-off-by: Ram Pai --- arch/powerpc/Kconfig | 15 +++++++++ arch/powerpc/include/asm/mmu_context.h | 1 + arch/powerpc/include/asm/pkeys.h | 55 ++++++++++++++++++++++++++++++++ arch/powerpc/mm/Makefile | 1 + arch/powerpc/mm/hash_utils_64.c | 1 + arch/powerpc/mm/pkeys.c | 33 +++++++++++++++++++ 6 files changed, 106 insertions(+), 0 deletions(-) create mode 100644 arch/powerpc/include/asm/pkeys.h create mode 100644 arch/powerpc/mm/pkeys.c diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index c51e6ce..c9660a1 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -867,6 +867,21 @@ config SECCOMP If unsure, say Y. Only embedded should say N here. +config PPC_MEM_KEYS + prompt "PowerPC Memory Protection Keys" + def_bool y + depends on PPC_BOOK3S_64 + select ARCH_USES_HIGH_VMA_FLAGS + select ARCH_HAS_PKEYS + help + Memory Protection Keys provides a mechanism for enforcing + page-based protections, but without requiring modification of the + page tables when an application changes protection domains. + + For details, see Documentation/vm/protection-keys.txt + + If unsure, say y. + endmenu config ISA_DMA_API diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h index 6177d43..fb5e6a3 100644 --- a/arch/powerpc/include/asm/mmu_context.h +++ b/arch/powerpc/include/asm/mmu_context.h @@ -192,5 +192,6 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, /* by default, allow everything */ return true; } + #endif /* __KERNEL__ */ #endif /* __ASM_POWERPC_MMU_CONTEXT_H */ diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h new file mode 100644 index 0000000..1280b35 --- /dev/null +++ b/arch/powerpc/include/asm/pkeys.h @@ -0,0 +1,55 @@ +/* + * PowerPC Memory Protection Keys management + * Copyright (c) 2017, IBM Corporation. + * Author: Ram Pai + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef _ASM_POWERPC_KEYS_H +#define _ASM_POWERPC_KEYS_H + +#include + +DECLARE_STATIC_KEY_TRUE(pkey_disabled); +#define ARCH_VM_PKEY_FLAGS 0 + +static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) +{ + return false; +} + +static inline int mm_pkey_alloc(struct mm_struct *mm) +{ + return -1; +} + +static inline int mm_pkey_free(struct mm_struct *mm, int pkey) +{ + return -EINVAL; +} + +/* + * Try to dedicate one of the protection keys to be used as an + * execute-only protection key. + */ +static inline int execute_only_pkey(struct mm_struct *mm) +{ + return 0; +} + +static inline int arch_override_mprotect_pkey(struct vm_area_struct *vma, + int prot, int pkey) +{ + return 0; +} + +static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, + unsigned long init_val) +{ + return 0; +} +#endif /*_ASM_POWERPC_KEYS_H */ diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile index 76a6b05..181166d 100644 --- a/arch/powerpc/mm/Makefile +++ b/arch/powerpc/mm/Makefile @@ -44,3 +44,4 @@ obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.o obj-$(CONFIG_SPAPR_TCE_IOMMU) += mmu_context_iommu.o obj-$(CONFIG_PPC_PTDUMP) += dump_linuxpagetables.o obj-$(CONFIG_PPC_HTDUMP) += dump_hashpagetable.o +obj-$(CONFIG_PPC_MEM_KEYS) += pkeys.o diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c index 0c802de..8bd841a 100644 --- a/arch/powerpc/mm/hash_utils_64.c +++ b/arch/powerpc/mm/hash_utils_64.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c new file mode 100644 index 0000000..de7dc48 --- /dev/null +++ b/arch/powerpc/mm/pkeys.c @@ -0,0 +1,33 @@ +/* + * PowerPC Memory Protection Keys management + * Copyright (c) 2017, IBM Corporation. + * Author: Ram Pai + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include + +DEFINE_STATIC_KEY_TRUE(pkey_disabled); +bool pkey_execute_disable_supported; + +int pkey_initialize(void) +{ + /* + * Disable the pkey system till everything is in place. A subsequent + * patch will enable it. + */ + static_branch_enable(&pkey_disabled); + + /* + * Disable execute_disable support for now. A subsequent patch will + * enable it. + */ + pkey_execute_disable_supported = false; + return 0; +} + +arch_initcall(pkey_initialize); -- 1.7.1