Received: by 10.223.164.200 with SMTP id h8csp920802wrb; Mon, 6 Nov 2017 00:59:59 -0800 (PST) X-Google-Smtp-Source: ABhQp+SdbWuROvM8wnWrwYLfKN0PD92/8FaRvR8IDPPFp+A1NC3DoewxPrBV1KbjgTFr60iLf9rZ X-Received: by 10.84.233.131 with SMTP id l3mr14044149plk.448.1509958799399; Mon, 06 Nov 2017 00:59:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509958799; cv=none; d=google.com; s=arc-20160816; b=vQnBbV6PcLDqC8UZwzIBcZ6pOrZH6zUa1W8A+JqZk5iQ/9P1ttdtrSAXpmrT5JiXed FtmYqNXFYKGTLZI3aIeV+TYLsRfhtnaPvrpx1503HbpaP9NfDs1LqEffWibj/p+VUc8C yodBcZDPzic2U2C/T9P99pO0O6+QH5ZQJHw9ENkNhvdjgXjnarnIcIFsdY3NZZKK5w0V OJxeXiiO4o6bx4Wzq7WuKG0ha9J7o/aZlA336gLAEsfP0Fqapwh9kI1JY9O7AZ2GupgN yElPRmJv5oRDT0OBuj7Qp+yYazEYiHDu2Byf/9JTz5nA0AH1yR1OVy2RwsIOPaF66wI3 keNg== 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=CZu+B8iqY8vldWMImsjn/t3QX20+koQqeb2cUyhjIaw=; b=Ysfl34Ae1mZdmVw+pr9O8RO6zE+izJGZ1RxqDBiA00YEa7GUPF1wfP6pPTA+oIar22 0DyacblmPThlEjMsfZmztDctkKEUL40YZJ72CTLZuInlmsRmHIELuI2OAbugygjg0dRk L8HsB1z7uXBKK3zdp+2mfTG4LIRQsC36NAHfqKuon8XWFM2/QU1pw+MkIq4yNzk8AXG5 losi+OrKfIGvEgCe2hgk6Y+PBDtaj9Gc9HAPZT0gUznqLid3UAD2zaywOhxZY9qvTtx/ IYz32li/OwpkDzpyNUPqblNuNpB3oXWmOE70+Tu8vLIru+FzOh7PcQ+y44MIhpu3JM46 xtUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=SJNsi2GZ; 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 w8si11039653pgc.769.2017.11.06.00.59.45; Mon, 06 Nov 2017 00:59:59 -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=SJNsi2GZ; 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 S1752232AbdKFI66 (ORCPT + 98 others); Mon, 6 Nov 2017 03:58:58 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:46288 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752117AbdKFI6y (ORCPT ); Mon, 6 Nov 2017 03:58:54 -0500 Received: by mail-qt0-f196.google.com with SMTP id 1so10021563qtn.3; Mon, 06 Nov 2017 00:58:53 -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=CZu+B8iqY8vldWMImsjn/t3QX20+koQqeb2cUyhjIaw=; b=SJNsi2GZUdKbAvP70i/0fnJjM7Od9je1GI1FA6PGCI/FVSWe8McHUcySZgAXMcpXbU 3ACDEYbYyE6lYMziqvDg1YHeI5DGCA1iT3wvMTAOchCKqcfVDSYdjXL9inmvFoIBegrY 9FypLPPPHmFXDZLqq4Rfx4Nb/N2JI0EM+H6V6NO3r8ZPyqwbQRmIlcawhYeeYiUPyrLg A7fONZWw7o9bcCb6kv0ngqdJ4WoZ0QYMCDCVaOqMrP9kkblB6j6mUCHC8XUPpnsiV8na r/X3uDdgbms0q7lqp2qA76qZ7e7LhBuahOE2300A0utH35Yqt40I5RY9D1DPBdZAKHQP Dmqw== 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=CZu+B8iqY8vldWMImsjn/t3QX20+koQqeb2cUyhjIaw=; b=t1aw5f1Ytsrc99oJZ0/BQjGQbPIdHOI6eIoIo0ezWBhXQC57pyfwGJNoEGIsm3DM94 O85krtEp+pyFRoaYdZSdJB+2KSEI+fq0qikjiSIwhRiyMKw//BhcAzgh0nbJbvJCMVPe mfHagdLicEoQHP7fl4hJOwdhnpRZT8GDm4bnOptzW6RyKq3P3BKjY7/6tCm0oYWsO2r7 ki06WVH8rVLRj1kGkVORS1IfZoCbJjFYwVfhv6jQv2v8Hwx8pJ2+sjbnnAqPuzjDMM5k 0g1DHzU5eNzHWKCzcWcsbQVvr9PrNJpr7js7dXdxWtO4sQRL39YhCGMl4U3poIGr7BZZ kPBA== X-Gm-Message-State: AMCzsaU4pQJJcTKgb9PDU/2qmKOz2R88SrbD4+Qm69vdyslwiYsA04Jl IwiDdMzZudPhgnyIJ60sbToeDiIs X-Received: by 10.200.6.136 with SMTP id f8mr22273085qth.265.1509958733085; Mon, 06 Nov 2017 00:58:53 -0800 (PST) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id r26sm8001094qki.42.2017.11.06.00.58.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:58:52 -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 v9 12/51] powerpc: ability to associate pkey to a vma Date: Mon, 6 Nov 2017 00:57:04 -0800 Message-Id: <1509958663-18737-13-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> References: <1509958663-18737-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 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 20d1f0e..1bd41ef 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 5da94fe..4d704ea 100644 --- a/arch/powerpc/mm/pkeys.c +++ b/arch/powerpc/mm/pkeys.c @@ -39,6 +39,14 @@ void __init 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 From 1586063073694284458@xxx Wed Dec 06 19:13:37 +0000 2017 X-GM-THRID: 1585318318730453659 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread