From patchwork Sun Jul 16 03:56:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 789012 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 3x9D7r690cz9s4s for ; Sun, 16 Jul 2017 14:33:28 +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="E+ns7z/e"; 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 3x9D7r4rT1zDqnj for ; Sun, 16 Jul 2017 14:33:28 +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="E+ns7z/e"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-qk0-x242.google.com (mail-qk0-x242.google.com [IPv6:2607:f8b0:400d:c09::242]) (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 3x9CMn1Lp7zDqm7 for ; Sun, 16 Jul 2017 13:58:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="E+ns7z/e"; dkim-atps=neutral Received: by mail-qk0-x242.google.com with SMTP id a66so16022000qkb.0 for ; Sat, 15 Jul 2017 20:58:45 -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=eAIZx/w6kEYOUo8E0pv7FESdjsqd6frbxzD3yrFLtM8=; b=E+ns7z/euuRo63eggAcXaCJMcwXTO674NMG+PpkRm9uT5Rtuwxfqc8g3D6pGC4XOZM uvrPeXyv2ppgUdp00CMyN+ha9qB7Y8zcZLZrfyV+QaJDxDlKIcosF3YxROusEXuTnqRL TXKPByQ6PaJkB0Gx8xK5VzuyndKPm5v2j+5LREiqAa8gHcLsl5tJWouEfQf0LRNvMbVf iosoK1w+z26bui1D6NCRvbszyyS4fWlUIHlwkFvmGFMg3QNAbupIguI6zhLjBZMbf7lY AtZEg2PXm5omtwxP+VgUHoHV6owIZDF1gSX6c1d9rCJgLUEvufXG2qstGfwKDgVP/i0r ZG5Q== 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=eAIZx/w6kEYOUo8E0pv7FESdjsqd6frbxzD3yrFLtM8=; b=lk5Ev+EVY1hJkjuADo1zhzIWhT7n/oGMD8wUpQ3nxKhfFeQTYwm2uc3B/rhm4z9NxK H1WWm6iqx2jV/P5g5gAWoHnIL3rkU+LTQVgcBs9XsXh77v80YNmppCIuaMwpdLML1E/d oFuERUx9oi7V0GE3LFi/vVEZN8CLOiKAL3+kGFubPAJgvbhcArNebW6Ky39tiNtOH+AX NUZyBtx9hQ4r7vzsftaNH4E7MTHv8fNSirHJJi5KwqSJEN21Fs2tfpC2YDsgu+96OrgR X2ssfQgdQeBvoyVkuxQ+O35nbtZGvWaYIaa1+IZhQgSJtSLcNMbwOw+2HYHLlmtoPx60 dyOg== X-Gm-Message-State: AIVw110pn0FAQBOr+WwUmULPS5g9ewuszuK4wD6BAG36mwEquefvpmmC Y/qO/3IWRizLY771s4A= X-Received: by 10.55.152.71 with SMTP id a68mr18436167qke.210.1500177523216; Sat, 15 Jul 2017 20:58:43 -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 q46sm2290345qtc.54.2017.07.15.20.58.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Jul 2017 20:58:42 -0700 (PDT) From: Ram Pai To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC v6 17/62] powerpc: implementation for arch_set_user_pkey_access() Date: Sat, 15 Jul 2017 20:56:19 -0700 Message-Id: <1500177424-13695-18-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1500177424-13695-1-git-send-email-linuxram@us.ibm.com> References: <1500177424-13695-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: arnd@arndb.de, corbet@lwn.net, linuxram@us.ibm.com, mhocko@kernel.org, dave.hansen@intel.com, mingo@redhat.com, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, akpm@linux-foundation.org, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This patch provides the detailed implementation for a user to allocate a key and enable it in the hardware. It provides the plumbing, but it cannot be used till the system call is implemented. The next patch will do so. Signed-off-by: Ram Pai --- arch/powerpc/include/asm/pkeys.h | 10 +++++++++- arch/powerpc/mm/pkeys.c | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletions(-) diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index 7f5c21d..1943e6b 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -3,6 +3,10 @@ extern bool pkey_inited; #define arch_max_pkey() 32 +#define AMR_RD_BIT 0x1UL +#define AMR_WR_BIT 0x2UL +#define IAMR_EX_BIT 0x1UL +#define AMR_BITS_PER_PKEY 2 #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | \ VM_PKEY_BIT3 | VM_PKEY_BIT4) #define AMR_BITS_PER_PKEY 2 @@ -113,10 +117,14 @@ static inline int arch_override_mprotect_pkey(struct vm_area_struct *vma, return 0; } +extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey, + unsigned long init_val); static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsigned long init_val) { - return 0; + if (!pkey_inited) + return -1; + return __arch_set_user_pkey_access(tsk, pkey, init_val); } static inline void pkey_mm_init(struct mm_struct *mm) diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c index 04ee361..98d0391 100644 --- a/arch/powerpc/mm/pkeys.c +++ b/arch/powerpc/mm/pkeys.c @@ -17,6 +17,10 @@ bool pkey_inited; #define pkeyshift(pkey) ((arch_max_pkey()-pkey-1) * AMR_BITS_PER_PKEY) +static bool is_pkey_enabled(int pkey) +{ + return !!(read_uamor() & (0x3ul << pkeyshift(pkey))); +} static inline void init_amr(int pkey, u8 init_bits) { @@ -60,3 +64,26 @@ void __arch_deactivate_pkey(int pkey) { pkey_status_change(pkey, false); } + +/* + * set the access right in AMR IAMR and UAMOR register + * for @pkey to that specified in @init_val. + */ +int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey, + unsigned long init_val) +{ + u64 new_amr_bits = 0x0ul; + + if (!is_pkey_enabled(pkey)) + return -1; + + /* Set the bits we need in AMR: */ + if (init_val & PKEY_DISABLE_ACCESS) + new_amr_bits |= AMR_RD_BIT | AMR_WR_BIT; + else if (init_val & PKEY_DISABLE_WRITE) + new_amr_bits |= AMR_WR_BIT; + + init_amr(pkey, new_amr_bits); + + return 0; +}