Received: by 10.223.164.202 with SMTP id h10csp14809wrb; Mon, 6 Nov 2017 01:36:03 -0800 (PST) X-Google-Smtp-Source: ABhQp+THFnXKam3tpfa/hucvnr5XXQs6tXL/GhjqF3/6hEqhvSpXe7XCHeUm6O8fy6PkPo6Ib5P8 X-Received: by 10.84.131.34 with SMTP id 31mr14285306pld.449.1509960963581; Mon, 06 Nov 2017 01:36:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509960963; cv=none; d=google.com; s=arc-20160816; b=S9v2KaP3kif5Acy9inKUe92DJe0eiZ6d1/3s3CMDuaWYg7z3PqHJdZnPf7bF5oGNtj Aln8RPfYHZ0OsHpiqJjNa5v9nZ2o3MOeKnp6OsQjwjpmjl2PEjykdVJeVx+2sXpb6b5J pOWu6+SXTuhb6qjeL7u1LUhz3VEkXkDT6AoVCvAn2WiLkF7I20yNJTwbn0xybDXBAK+D ERzsNk5hj7A0QZrDtoogUIRms2c1XEylwR9Ykt2qSmXPoNoguZxh0QlyitfNd+wYHj2I Ne8Yaz7ja3k15F/xRPvp2qkH7YXcVQRqF5ENI1iJq59Zhzk9G/SipnV46PsQ0a9VK5MJ nc3w== 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=KRQhyBIC5gpdQsbMn7mqsk48vEVgnx2aIl5zVRJ/1bY=; b=wKSSbJ22RCdSHQU9Xu1RYy/dzu+FmqPa7tDXDlycc+5Ml0VItShXxogzeaIJcA1wPP 8CwwuGpEyEzLIIBDWMZG8g5s9JtFt+70jicWTkBvqYjyJiPaPamfGE1cR1jtHbtsyLYJ KQP6GQeQcKpUbYKh9T/NwQKs04Ka9yi2zluCmmZM4hE8R20xTYj6hw00udsKY0qgarLU BwC506nmpTcEs1YDNktBxoIuMuQfblP9wUcyEmbxbELNJDbC8CoODF3CyXQwqBHtvTYn aE2qundTVq66aU3fVDpx9FxGYHorO06uVYLZUnk2tQqguu+hIaClzp/ogHtODTOQ4ise TuFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=MOmsXjqO; 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 n189si10806727pga.205.2017.11.06.01.35.49; Mon, 06 Nov 2017 01:36:03 -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=MOmsXjqO; 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 S1752266AbdKFI7G (ORCPT + 98 others); Mon, 6 Nov 2017 03:59:06 -0500 Received: from mail-qt0-f194.google.com ([209.85.216.194]:56710 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752117AbdKFI67 (ORCPT ); Mon, 6 Nov 2017 03:58:59 -0500 Received: by mail-qt0-f194.google.com with SMTP id z28so9973953qtz.13; Mon, 06 Nov 2017 00:58:58 -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=KRQhyBIC5gpdQsbMn7mqsk48vEVgnx2aIl5zVRJ/1bY=; b=MOmsXjqOW4l+o59ld6lW20JnR0v5WoQyra2owTKU0eaCc4TLw0b9qHuC0N/IcWtqcU wKeO6kKBZJcXmQzVclQJ0SDcueZbBkJSXbVAk+hHU/fXVfUUcJ3sxinTjVcSzAxKM8Vh kg1odV4roiX6n6nD9DaaBOSCxWKydJ2HieKa1Ka9JrRGBGU85Mn7eecOzJ4Xhb3VRU/3 tjJH0MTNI92PgqqStp6FSg5I/N5y+wA1ipRvXKR5SNZq/BfxgFOwoKzkdgAvl90ojVKF KIuSb0jsUbygY8WYLAuj5yxHpKd/4MFamu9GKbrJps8gdor6WFfZwE+58oOC9h2dFfsx 9n9A== 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=KRQhyBIC5gpdQsbMn7mqsk48vEVgnx2aIl5zVRJ/1bY=; b=YeYvqt2WMsBYpJJyuX7z/wqqvMsJhxpho3bn5VIza6P+tO3Zsw+ZMt+pDlg4pKPdvL QwP2pE1zlP8QnFU81fP1UP8F2WYmaexY5+8P9u3XBvJo/xwyWdmYqfuPNhrLPkvkf8/d qNvkcm9PfxNjAL/+oTFFCkngVfDYy3Grdcnn0Be9ouVWmuSlUzObT9Uvbg86iYduHjH6 OmDvNlpaWvzi7WffNbUgZw+J1BR6ebbZBQ4EeZyy3ITIZPFRZ0ZncFf9Cn6FB4XzELqt Kuf8G4r4iwtWyr3UIP2Y4Tx/x53PEQAKV64cwVigvGTFBQ+w3q3jXhHp383GFG+Zh+Os e/mg== X-Gm-Message-State: AMCzsaU7TDV/Q6++t0Kpry8cGJUsQZ8KMjmxLdMvxxwsa8byV3GR7KrE oYc56J+yZQaXhdC9aAYbXTQ= X-Received: by 10.237.62.153 with SMTP id n25mr20792898qtf.124.1509958738512; Mon, 06 Nov 2017 00:58:58 -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.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:58:58 -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 14/51] powerpc: map vma key-protection bits to pte key bits. Date: Mon, 6 Nov 2017 00:57:06 -0800 Message-Id: <1509958663-18737-15-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 Map the key protection bits of the vma to the pkey bits in the PTE. The PTE bits used for pkey are 3,4,5,6 and 57. The first four bits are the same four bits that were freed up initially in this patch series. remember? :-) Without those four bits this patch wouldn't be possible. BUT, on 4k kernel, bit 3, and 4 could not be freed up. remember? Hence we have to be satisfied with 5, 6 and 7. Signed-off-by: Ram Pai --- arch/powerpc/include/asm/book3s/64/pgtable.h | 25 ++++++++++++++++++++++++- arch/powerpc/include/asm/mman.h | 6 ++++++ arch/powerpc/include/asm/pkeys.h | 12 ++++++++++++ 3 files changed, 42 insertions(+), 1 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index 9a677cd..4c1ee6e 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -39,6 +39,7 @@ #define _RPAGE_RSV2 0x0800000000000000UL #define _RPAGE_RSV3 0x0400000000000000UL #define _RPAGE_RSV4 0x0200000000000000UL +#define _RPAGE_RSV5 0x00040UL #define _PAGE_PTE 0x4000000000000000UL /* distinguishes PTEs from pointers */ #define _PAGE_PRESENT 0x8000000000000000UL /* pte contains a translation */ @@ -58,6 +59,25 @@ /* Max physical address bit as per radix table */ #define _RPAGE_PA_MAX 57 +#ifdef CONFIG_PPC_MEM_KEYS +#ifdef CONFIG_PPC_64K_PAGES +#define H_PTE_PKEY_BIT0 _RPAGE_RSV1 +#define H_PTE_PKEY_BIT1 _RPAGE_RSV2 +#else /* CONFIG_PPC_64K_PAGES */ +#define H_PTE_PKEY_BIT0 0 /* _RPAGE_RSV1 is not available */ +#define H_PTE_PKEY_BIT1 0 /* _RPAGE_RSV2 is not available */ +#endif /* CONFIG_PPC_64K_PAGES */ +#define H_PTE_PKEY_BIT2 _RPAGE_RSV3 +#define H_PTE_PKEY_BIT3 _RPAGE_RSV4 +#define H_PTE_PKEY_BIT4 _RPAGE_RSV5 +#else /* CONFIG_PPC_MEM_KEYS */ +#define H_PTE_PKEY_BIT0 0 +#define H_PTE_PKEY_BIT1 0 +#define H_PTE_PKEY_BIT2 0 +#define H_PTE_PKEY_BIT3 0 +#define H_PTE_PKEY_BIT4 0 +#endif /* CONFIG_PPC_MEM_KEYS */ + /* * Max physical address bit we will use for now. * @@ -121,13 +141,16 @@ #define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \ _PAGE_ACCESSED | _PAGE_SPECIAL | _PAGE_PTE | \ _PAGE_SOFT_DIRTY) + +#define H_PTE_PKEY (H_PTE_PKEY_BIT0 | H_PTE_PKEY_BIT1 | H_PTE_PKEY_BIT2 | \ + H_PTE_PKEY_BIT3 | H_PTE_PKEY_BIT4) /* * Mask of bits returned by pte_pgprot() */ #define PAGE_PROT_BITS (_PAGE_SAO | _PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT | \ H_PAGE_4K_PFN | _PAGE_PRIVILEGED | _PAGE_ACCESSED | \ _PAGE_READ | _PAGE_WRITE | _PAGE_DIRTY | _PAGE_EXEC | \ - _PAGE_SOFT_DIRTY) + _PAGE_SOFT_DIRTY | H_PTE_PKEY) /* * We define 2 sets of base prot bits, one for basic pages (ie, * cacheable kernel and user pages) and one for non cacheable diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h index 2999478..07e3f54 100644 --- a/arch/powerpc/include/asm/mman.h +++ b/arch/powerpc/include/asm/mman.h @@ -33,7 +33,13 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags) { +#ifdef CONFIG_PPC_MEM_KEYS + return (vm_flags & VM_SAO) ? + __pgprot(_PAGE_SAO | vmflag_to_pte_pkey_bits(vm_flags)) : + __pgprot(0 | vmflag_to_pte_pkey_bits(vm_flags)); +#else return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0); +#endif } #define arch_vm_get_page_prot(vm_flags) arch_vm_get_page_prot(vm_flags) diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index 441bbf3..cfe61a9 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -52,6 +52,18 @@ static inline u64 pkey_to_vmflag_bits(u16 pkey) return (((u64)pkey << VM_PKEY_SHIFT) & ARCH_VM_PKEY_FLAGS); } +static inline u64 vmflag_to_pte_pkey_bits(u64 vm_flags) +{ + if (static_branch_likely(&pkey_disabled)) + return 0x0UL; + + return (((vm_flags & VM_PKEY_BIT0) ? H_PTE_PKEY_BIT4 : 0x0UL) | + ((vm_flags & VM_PKEY_BIT1) ? H_PTE_PKEY_BIT3 : 0x0UL) | + ((vm_flags & VM_PKEY_BIT2) ? H_PTE_PKEY_BIT2 : 0x0UL) | + ((vm_flags & VM_PKEY_BIT3) ? H_PTE_PKEY_BIT1 : 0x0UL) | + ((vm_flags & VM_PKEY_BIT4) ? H_PTE_PKEY_BIT0 : 0x0UL)); +} + static inline int vma_pkey(struct vm_area_struct *vma) { if (static_branch_likely(&pkey_disabled)) -- 1.7.1 From 1582968573385220927@xxx Thu Nov 02 15:27:52 +0000 2017 X-GM-THRID: 1582968573385220927 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread