Received: by 10.223.176.46 with SMTP id f43csp309712wra; Thu, 18 Jan 2018 17:58:05 -0800 (PST) X-Google-Smtp-Source: ACJfBos7s/93AC9SFpocxT36YN5VYU/n9nU1bsGLULiRKolNDVU6VLbfZakM37RODziRDnZw+1C4 X-Received: by 10.99.116.82 with SMTP id e18mr32816556pgn.3.1516327085751; Thu, 18 Jan 2018 17:58:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516327085; cv=none; d=google.com; s=arc-20160816; b=pOmdgCLc0FaRyogur0RmiwRglkTbtp2VoIM+3KuzYtBeTr3Jcpzgt+1lIph7fjg02t 1jvdclhE5rREbzJPov1T3iFNxrXlPACCq9aNs/53pUfkzYpwCYEYMdcaip/DTvD9Gecu LioV2VQIJp1oG+EgSUhX0ijD89RLI/hRxgTJ6h3ecfop+YXc+ysWL+ZqEfo8vL8KpKaf Rkjm3b43l7aFkQO17FXH2ASHxMc5T46iyBm6j2iK21ShMK1e1ktD6m8MYhEORzlAgmOf H/5oz7lLSO378bTK3XOP+8qNwF2qpUaihB4BJNr7Y2cfL5duCyO7I0/BwHw0i7KwxFF/ A8+w== 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=anFgSYtUCceF6+HVOgJWrwh4l9J89EjCBPclNUEamrs=; b=S9C5vO5go/VIgQyYszqztHbvsW9ZT4xCE3gkg+8k5/4XtLLsIv6Jczbu/0NbkhUmvE KK9nQkHkG2wPofp/CgxVimHt3iFQP9Tfj+PdXB6YiG2LBFSXH3Tp1TiIvIXN01rXY7J0 TnUKmEH2oXc4J7mX+Ob/Z/1ZBAcDh2HOJKpPERhjXxhTS9WUv8WTg9uCgS3uLEAFDCjX WksiwIMDbzhqv1G7PMv+wRwDLZejqBwGzJ7amw4obFpBFIWEUzPPuHweCBJDKZfsJ2gN MVT6gnEodWjhl81xV/TtfgYXfdtp2agxm8RCxP2Ulvv0Dhy28c6XRLsFij++vWlYotCv i3lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=iW/ivD0j; 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 v70si8246163pfa.405.2018.01.18.17.57.51; Thu, 18 Jan 2018 17:58:05 -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=iW/ivD0j; 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 S1755814AbeASB5P (ORCPT + 99 others); Thu, 18 Jan 2018 20:57:15 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:37283 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755652AbeASBw0 (ORCPT ); Thu, 18 Jan 2018 20:52:26 -0500 Received: by mail-qt0-f196.google.com with SMTP id d54so449643qtd.4; Thu, 18 Jan 2018 17:52:24 -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=anFgSYtUCceF6+HVOgJWrwh4l9J89EjCBPclNUEamrs=; b=iW/ivD0jeHKLVjzqnp0eo3OeRNCn2ENOQ6VNU2OX6Whj+SCcXazC1cP51u2WUZJD6G UemoPuGNWqK22xBF3wmcyFikr3DAwSkasLG9t4nYI9D+HdIdkhr7vKA1rvaclaTMf3VH uXTG8AE5kJiTnDaqWaGAhFPkvUn6PZBq8igC0raOgO3BHhxh1j57zm9wusLUspkecWDF I+EO5mVROs69T7/VugF9GSYn1+Ew6hwhpEsmdr5QPRIuaLCx7RVGQFaPsL7uz5K/1v0r TYVE2RBIPavgmQ8y5adkb3AlDo9VIca2/33f4DrLoWDkqUI4ekEyQdMInIZEDtqluN4+ GBnA== 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=anFgSYtUCceF6+HVOgJWrwh4l9J89EjCBPclNUEamrs=; b=MM1cH8VFaEyp9m+tQGT1bI/T/BAdAbNS8r0xJdN6L9Pax+RIeePjGVK9b3c2R9sKh+ ROfmdTz3K8u8DjsKig4exn3c/gO19HN82xi57g+8MsomhOyDfRB2sZfLIZJHklRJni4r yQoHI/6L1oMgDmPZo7O4JocNW5VvKGWzCenr9YiRI282zy+xoK8BLrqchCdgZA8tJ7yh GlZqF55/9kM0yToEC/MaRbbAqY7fyCxvHWegfvk0TnrTUR+9EExVJFpumE/3CCqCak+V QX5AnmrIETujz8/FUiX/r6IggR8Jr8wYEcS6nE7u9nNJ3cxRT1PNPQH5ObSJMJe8RFbe ZPbQ== X-Gm-Message-State: AKwxytdnnpZ9wWCc3pXngdgp18a1AYfX3nGktbGd5HoGWull7LXOXsQJ Soxfe88YIRyY/D6Y/Cbwm38= X-Received: by 10.200.24.174 with SMTP id s43mr47918230qtj.239.1516326744022; Thu, 18 Jan 2018 17:52:24 -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.52.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 17:52:23 -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 14/27] powerpc: map vma key-protection bits to pte key bits. Date: Thu, 18 Jan 2018 17:50:35 -0800 Message-Id: <1516326648-22775-15-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 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 4469781..e1a8bb6 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 0a643b8..f65dedd 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