From patchwork Fri Sep 8 22:44:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 811865 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xptFN4ryyz9sCZ for ; Sat, 9 Sep 2017 09:04:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pyYPqU1V"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xptFN3ZN0zDrVm for ; Sat, 9 Sep 2017 09:04:56 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pyYPqU1V"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c09::243; helo=mail-qk0-x243.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pyYPqU1V"; dkim-atps=neutral Received: from mail-qk0-x243.google.com (mail-qk0-x243.google.com [IPv6:2607:f8b0:400d:c09::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xpsrN5g8VzDrWB for ; Sat, 9 Sep 2017 08:46:44 +1000 (AEST) Received: by mail-qk0-x243.google.com with SMTP id i14so2311555qke.3 for ; Fri, 08 Sep 2017 15:46:44 -0700 (PDT) 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=Fu3AXF98rL+d5zSs3Im6uvBZdN9GOCmKQCwk6aYAGm4=; b=pyYPqU1VQkCBzs2X4TcYpe86mmXRIcG390tMgW2l3tMtJu1qdBwXL5+OJfPp0keSO4 1Q5HmtPBRG9ckz7QW7NEZ0fZKSOB3eqXQzx7oSW5XRyqDxbBqT2fMaIRJGbM7utSBfUv IecUb66OqK6RgLZBhSSfdMOhoKNaEN/cJHV15Ee5SF8mdYKC+GEUjNcUwmDl0I6y6glK P+RcGE41IwkLQ8qzjdNM2xITvFC0+MnBWWjx/kCgTuLOcw+JH9CWFSiJ55rIp61UokDd UcnIv2s8f37khJDzWCeeT+iivc9F/EXKdw/+9VRFyZdOjPBwI1/LgY7GDcvtRt0YemHX +MBQ== 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=Fu3AXF98rL+d5zSs3Im6uvBZdN9GOCmKQCwk6aYAGm4=; b=oY8vEyA5oo7eJffYoSdEqdmRQFzJhEnqJjyXjAoydMBqWAd4lYdBTVOMjUYMmDiAgk MLc1Bwjn7Kws2PKZHmjnYAzoCbMreyAXEZ5sxtogn5S+3/77ZNpqkE0xV7mUSvWAK25v i/mB2PWKjgF4qOm+cyXNr0dFBo4f4CjhQx2iVNAELQ6+9u2OBUJPOXUl+rGrpbghNQ1k cCwG9x1FPwM6kX1lZ6U6HGPPAahUmOzzM8F8ftFIon46OULiuXZgpHsQAp1gvJV1WeyU OL4PmFdN3IyKNnxrvJxH5/YafjDKFz4FL8N6XjnV8l1AtUpQ2HmNYG2R6jFQLmwcRkmC cWDw== X-Gm-Message-State: AHPjjUh3sA2ZGnBv4PJZ9zPH1kT94oMF42IF9/e6PA2s/UAAD/Fk9fyE 5ELXs+K+1GjBHxjp X-Google-Smtp-Source: AOwi7QB1HoqCtrdzDuhNQY2sgJC0cVFBCPPbBhRVm2qxip4LASzEyE7CFva3arHHjTyYMgs3zb94sQ== X-Received: by 10.55.217.155 with SMTP id q27mr5564240qkl.323.1504910802498; Fri, 08 Sep 2017 15:46:42 -0700 (PDT) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id x124sm2033726qka.85.2017.09.08.15.46.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Sep 2017 15:46:42 -0700 (PDT) From: Ram Pai To: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org Subject: [PATCH 01/25] powerpc: initial pkey plumbing Date: Fri, 8 Sep 2017 15:44:49 -0700 Message-Id: <1504910713-7094-10-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1504910713-7094-1-git-send-email-linuxram@us.ibm.com> References: <1504910713-7094-1-git-send-email-linuxram@us.ibm.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ebiederm@xmission.com, linuxram@us.ibm.com, mhocko@kernel.org, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, bauerman@linux.vnet.ibm.com, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Basic plumbing to initialize the pkey system. Nothing is enabled yet. A later patch will enable it ones all the infrastructure is in place. Signed-off-by: Ram Pai --- arch/powerpc/Kconfig | 16 +++++++++++ arch/powerpc/include/asm/mmu_context.h | 5 +++ arch/powerpc/include/asm/pkeys.h | 45 ++++++++++++++++++++++++++++++++ arch/powerpc/kernel/setup_64.c | 4 +++ arch/powerpc/mm/Makefile | 1 + arch/powerpc/mm/hash_utils_64.c | 1 + arch/powerpc/mm/pkeys.c | 33 +++++++++++++++++++++++ 7 files changed, 105 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 9fc3c0b..a4cd210 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -864,6 +864,22 @@ config SECCOMP If unsure, say Y. Only embedded should say N here. +config PPC64_MEMORY_PROTECTION_KEYS + prompt "PowerPC Memory Protection Keys" + def_bool y + # Note: only available in 64-bit mode + depends on PPC64 + 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 3095925..7badf29 100644 --- a/arch/powerpc/include/asm/mmu_context.h +++ b/arch/powerpc/include/asm/mmu_context.h @@ -141,5 +141,10 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, /* by default, allow everything */ return true; } + +#ifndef CONFIG_PPC64_MEMORY_PROTECTION_KEYS +#define pkey_initialize() +#endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */ + #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..c02305a --- /dev/null +++ b/arch/powerpc/include/asm/pkeys.h @@ -0,0 +1,45 @@ +#ifndef _ASM_PPC64_PKEYS_H +#define _ASM_PPC64_PKEYS_H + +extern bool pkey_inited; +extern bool pkey_execute_disable_support; +#define ARCH_VM_PKEY_FLAGS 0 + +static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) +{ + return (pkey == 0); +} + +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; +} + +extern void pkey_initialize(void); +#endif /*_ASM_PPC64_PKEYS_H */ diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index b89c6aa..3b67014 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -316,6 +317,9 @@ void __init early_setup(unsigned long dt_ptr) /* Initialize the hash table or TLB handling */ early_init_mmu(); + /* initialize the key subsystem */ + pkey_initialize(); + /* * At this point, we can let interrupts switch to virtual mode * (the MMU has been setup), so adjust the MSR in the PACA to diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile index fb844d2..927620a 100644 --- a/arch/powerpc/mm/Makefile +++ b/arch/powerpc/mm/Makefile @@ -43,3 +43,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_PPC64_MEMORY_PROTECTION_KEYS) += pkeys.o diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c index 0dff57b..67f62b5 100644 --- a/arch/powerpc/mm/hash_utils_64.c +++ b/arch/powerpc/mm/hash_utils_64.c @@ -35,6 +35,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..418a05b --- /dev/null +++ b/arch/powerpc/mm/pkeys.c @@ -0,0 +1,33 @@ +/* + * PowerPC Memory Protection Keys management + * Copyright (c) 2015, Intel Corporation. + * Copyright (c) 2017, IBM Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ +#include /* PKEY_* */ + +bool pkey_inited; +bool pkey_execute_disable_support; + +void __init pkey_initialize(void) +{ + /* disable the pkey system till everything + * is in place. A patch further down the + * line will enable it. + */ + pkey_inited = false; + + /* + * disable execute_disable support for now. + * A patch further down will enable it. + */ + pkey_execute_disable_support = false; +}