Received: by 10.223.164.202 with SMTP id h10csp16677wrb; Mon, 6 Nov 2017 01:38:31 -0800 (PST) X-Google-Smtp-Source: ABhQp+ROe6lMYM3RADI/mXc0x5jr7sDPDkBVrJ53UmgfoOHBMx7xtAGA/U294oBV1yVbG8B4Vaxz X-Received: by 10.101.73.205 with SMTP id t13mr14803115pgs.289.1509961111330; Mon, 06 Nov 2017 01:38:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509961111; cv=none; d=google.com; s=arc-20160816; b=l2HoLbmaN7Rekh9Srl29SRrrJmuWJ5CNyBAFBeVebnBT4hx3h3wHb00so/SH7dyFDc yoCmJzLwmWduFcINMH9OkSQJoDNrlCzKW44wyqLPgNU3PT3YLDpNFK+VWYE6KNdOtbaY vySwcQW2KFvvMYhIiYlftohq1jzgV2B1z5jlS0yat4keL48kR3/YYEgTCPM91e38SdJZ at7Rnrf1peNUHbnUo80rQdggOuWZuVGBgTL0oMDm8xAhtwuXoyMFYlkbJX17440p3dTM DMzyincwTWt8U9RTZ/JFkaQX3AE1DmM5SS6XHQKHWN0vYgyegbkdemnIhLt3v5Ou73y6 8IuA== 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=oaDAb9W4Y2JhjPw1gmvx61RLMQNmuDC/xnFRK+FvJ3E=; b=lHge+Z+Ox1uLsKfD+GE00vXK0O2p8XO0PzPXpaEBeJVw8NRxKOL42ynGQsb2L8EbtQ cqiM7Yw4ghHHqWA7dEuQgPCLvV7V0tPRVnKuLRRxrzp7mkwtz1rRSfU49t2Ap0LdB3kJ 87qcgh7YPLJucCxYsWelmb7T8CVKgQ8zIIESdlT+f1JlXkMW4gY73HwfZ/lUPix6dnpb 6Gabw1oWyf+jRtxmQB8234mh8YTslOdOpNwJhzGpbOFi9C3Jn12FPXHpGkfskopuok6M pptlQ8Hh6pf78OTMlEIF2Pw7I6Tej0K3pLhruKds2gli2Bd1D59pV7cXzJdl3iXAW3xb ezSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=WkuJQPOf; 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 d127si10951267pgc.372.2017.11.06.01.38.17; Mon, 06 Nov 2017 01:38:31 -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=WkuJQPOf; 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 S1752183AbdKFI6q (ORCPT + 98 others); Mon, 6 Nov 2017 03:58:46 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:53541 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752117AbdKFI6n (ORCPT ); Mon, 6 Nov 2017 03:58:43 -0500 Received: by mail-qt0-f195.google.com with SMTP id n61so9983419qte.10; Mon, 06 Nov 2017 00:58:42 -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=oaDAb9W4Y2JhjPw1gmvx61RLMQNmuDC/xnFRK+FvJ3E=; b=WkuJQPOfOn7r7ga9n2HJs17lAt2YP/k+/tzzYX3DZ2kJuWgA8MswAPIPPf0E8W5/3H Wem4mmrhSp5V2HUe5pUKvlX9CgpTT4EA+akSziYBWGdAn1/X0c7G8eV8ufFY9/UWaSpO eYzVgKr3Z6MX4EhxKQNjTwiqbq+x4ElB3nSNQre7NuF8waheTJYP7ZQVhOui1kBSFTDj 1v5giuqmqYGVvYk6ldIFw24FfAcLrPImab/yB9hJGqIc8v2izuFuTyMy2NS0fck3saUI 3V8ObJF0eV65PF5EtqqjfqV5aRQFLo/PWM9+Pzpmegjy3tk0sRgTDtY4KK59ZVQwitx7 +g5g== 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=oaDAb9W4Y2JhjPw1gmvx61RLMQNmuDC/xnFRK+FvJ3E=; b=ReqLTKar92PDdCOSkZRa/Vflaq/CdkOHlU2DkpC0N/Ig9hfggKk1C3+KQ4KBpbd1AF t9d20uzHQfdLo1GK2iKVP5dJMzS5pLjxs9iCrzvafVO5ulr5/U//1P7nz7tfdqWdUaJ6 vneIlI6B6TFGYYHD/YgWUFTwtpVFRnKW6JGZrPkI+F75uXL9qcEsXhGVRupgJU8Y7spI cn4CsxnJYMMnUgj01Lo6wt8XDdivglN/vLiaHnN+VRQ5w+ha4rbywbtDjFfW4kYloToz K3KflAi3/BZkgm6VM4SPIkgK6tFPzqwhMpywCbFHMjcc06/SxvcFC/xj2eXd/s96w0Ti yTtg== X-Gm-Message-State: AMCzsaVxlBJUdD+caWhbatZVlOhOldEZfTYSYfY54UfMDfRIxXvqNw3g h5bDbZrCtFYsTcHJid6uAZk= X-Received: by 10.200.34.239 with SMTP id g44mr20537165qta.111.1509958722350; Mon, 06 Nov 2017 00:58:42 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:58:41 -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 08/51] powerpc: implementation for arch_set_user_pkey_access() Date: Mon, 6 Nov 2017 00:57:00 -0800 Message-Id: <1509958663-18737-9-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 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. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Ram Pai --- arch/powerpc/include/asm/pkeys.h | 6 ++++- arch/powerpc/mm/pkeys.c | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletions(-) diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index 0d00a54..652c750 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -139,10 +139,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 (static_branch_likely(&pkey_disabled)) + return -EINVAL; + 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 f3bf661..4a01c2f 100644 --- a/arch/powerpc/mm/pkeys.c +++ b/arch/powerpc/mm/pkeys.c @@ -9,6 +9,7 @@ * (at your option) any later version. */ +#include #include DEFINE_STATIC_KEY_TRUE(pkey_disabled); @@ -17,6 +18,9 @@ u32 initial_allocation_mask; /* Bits set for reserved keys */ #define AMR_BITS_PER_PKEY 2 +#define AMR_RD_BIT 0x1UL +#define AMR_WR_BIT 0x2UL +#define IAMR_EX_BIT 0x1UL #define PKEY_REG_BITS (sizeof(u64)*8) #define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey+1) * AMR_BITS_PER_PKEY)) @@ -102,6 +106,20 @@ static inline void write_uamor(u64 value) mtspr(SPRN_UAMOR, value); } +static bool is_pkey_enabled(int pkey) +{ + u64 uamor = read_uamor(); + u64 pkey_bits = 0x3ul << pkeyshift(pkey); + u64 uamor_pkey_bits = (uamor & pkey_bits); + + /* + * Both the bits in UAMOR corresponding to the key should be set or + * reset. + */ + WARN_ON(uamor_pkey_bits && (uamor_pkey_bits != pkey_bits)); + return !!(uamor_pkey_bits); +} + static inline void init_amr(int pkey, u8 init_bits) { u64 new_amr_bits = (((u64)init_bits & 0x3UL) << pkeyshift(pkey)); @@ -144,3 +162,25 @@ void __arch_deactivate_pkey(int pkey) { pkey_status_change(pkey, false); } + +/* + * Set the access rights in AMR IAMR and UAMOR registers 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 -EINVAL; + + /* 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; +} -- 1.7.1 From 1583309180487644457@xxx Mon Nov 06 09:41:40 +0000 2017 X-GM-THRID: 1583309180487644457 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread