From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: ACJfBoty2dmmTcoQH06aOh43SrjVF8ojPmUk2mG+fBcDudFzHTsmrUcE2TmLmSqNBcAtCfMod8f8 ARC-Seal: i=1; a=rsa-sha256; t=1516327072; cv=none; d=google.com; s=arc-20160816; b=nNZJcohT8nOziwJZptgbHliUcrSd75U+kWNDR31ehvOPaXGgFyoH2trW4Cce41+puP d/P0YAaF4bSXsM2Pjddk4hf7ouXFYQffJ0nZHeF/BxYQOV7OeVYjwuYvyBO0MubD7QL+ CeY9y3fCHHGgdDK77+q3ZXhvKxuFdJJzT0n7Qqx6BuBNh4GEOaeTq6W/10W90siPGlYR HaH+0HPB6BdJwYednqd7leucIbqxNtH8RasB4NCN71T1GYp2/l9Pezy3Zmv61i6MWcHN OnbVdIYJQAbhT23y1ju2dQcqotB/yk/74QHsJty9lDfG3jz2SFxn39ejW1rxnMpgeRfM GZ2Q== 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=YMt+5eR3rcjA/IA2qKOBu02Mjc+/DDMKbPdvrlxPv/U=; b=nM70sWOJ+v5padBNCzqzD8tUNELZhbVC2K3EF29DjdCrQiUOgbd4VvZ0XIqOMw2Ovo wCK6BLSJ04bXDPlFvQYRg/5nKP39GTfTPZhGoSzL7mheragFFR3pE7iLUWt6juh+FOsn vxULPR60yEmZmOSWg7wLK+kiBvTxK2W3v8upASDX4qRiDrFUZd3Z1YwaBXSnd+5jjRJo 3bp5r3TxXIQI/H2hHNqg9pj2HuKq7edbj3QMuc1mS7W58JfBty6fQuykYKKQV3n0Oma0 1zsvXEaLHud+IPM3iwCffmcccGucWL/Ow+Um8Sc/JxOC64O+e+GCHKgHJOx/hHJ5W+5g NyjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=VY4IiHbR; 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=VY4IiHbR; 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 S1755881AbeASB5j (ORCPT ); Thu, 18 Jan 2018 20:57:39 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:42265 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755621AbeASBwT (ORCPT ); Thu, 18 Jan 2018 20:52:19 -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 12/27] powerpc: ability to associate pkey to a vma Date: Thu, 18 Jan 2018 17:50:33 -0800 Message-Id: <1516326648-22775-13-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?1589984176561765846?= X-GMAIL-MSGID: =?utf-8?q?1589984176561765846?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: arch-independent code expects the arch to map a pkey into the vma's protection bit setting. The patch provides that ability. Signed-off-by: Ram Pai --- arch/powerpc/include/asm/mman.h | 7 ++++++- arch/powerpc/include/asm/pkeys.h | 11 +++++++++++ arch/powerpc/mm/pkeys.c | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletions(-) diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h index 30922f6..2999478 100644 --- a/arch/powerpc/include/asm/mman.h +++ b/arch/powerpc/include/asm/mman.h @@ -13,6 +13,7 @@ #include #include +#include #include /* @@ -22,7 +23,11 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, unsigned long pkey) { - return (prot & PROT_SAO) ? VM_SAO : 0; +#ifdef CONFIG_PPC_MEM_KEYS + return (((prot & PROT_SAO) ? VM_SAO : 0) | pkey_to_vmflag_bits(pkey)); +#else + return ((prot & PROT_SAO) ? VM_SAO : 0); +#endif } #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey) diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index 2b5bb35..c7cc433 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -41,6 +41,17 @@ #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | \ VM_PKEY_BIT3 | VM_PKEY_BIT4) +/* Override any generic PKEY permission defines */ +#define PKEY_DISABLE_EXECUTE 0x4 +#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS | \ + PKEY_DISABLE_WRITE | \ + PKEY_DISABLE_EXECUTE) + +static inline u64 pkey_to_vmflag_bits(u16 pkey) +{ + return (((u64)pkey << VM_PKEY_SHIFT) & ARCH_VM_PKEY_FLAGS); +} + #define arch_max_pkey() pkeys_total #define pkey_alloc_mask(pkey) (0x1 << pkey) diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c index b466a2c..ee31ab5 100644 --- a/arch/powerpc/mm/pkeys.c +++ b/arch/powerpc/mm/pkeys.c @@ -39,6 +39,14 @@ int pkey_initialize(void) (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE)); /* + * pkey_to_vmflag_bits() assumes that the pkey bits are contiguous + * in the vmaflag. Make sure that is really the case. + */ + BUILD_BUG_ON(__builtin_clzl(ARCH_VM_PKEY_FLAGS >> VM_PKEY_SHIFT) + + __builtin_popcountl(ARCH_VM_PKEY_FLAGS >> VM_PKEY_SHIFT) + != (sizeof(u64) * BITS_PER_BYTE)); + + /* * Disable the pkey system till everything is in place. A subsequent * patch will enable it. */ -- 1.7.1