Received: by 10.223.176.46 with SMTP id f43csp306311wra; Thu, 18 Jan 2018 17:53:48 -0800 (PST) X-Google-Smtp-Source: ACJfBoszHlgxdHTD7oSqKiMW2YO3x3jJa1oczyZc2LILWx0evge9ioC1ijGiNZnrwsv4cpDgr2jQ X-Received: by 10.101.73.131 with SMTP id r3mr15772889pgs.76.1516326828512; Thu, 18 Jan 2018 17:53:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516326828; cv=none; d=google.com; s=arc-20160816; b=sgY33iZUkqszmYt9Lv+EF3JTbkrVJzbenZMZkgZhN0PnGCuz+UQBT2+6hp8BMxnJBt 2c1GbrzkNh6lQWTIZGoedvM2xqB1HgHduI6E29OgtS92V6g6ui70Kp6c5/k/X8ppbjL6 GBNZnqQUGBXURBYvTCO3VIDdE2XjT4MWSs4KuCtVaRCif5QQB6oUzT1YzC7qLRmu5a0e A/gQ14mr3Bg4/LiqKb6zUd0EMboDEOQshm+uqHUtI3sJOhJ2wExITw8/fUGW8RjlUzyp MvxwoEhrTGV9Yk4KTMgVF2JWfZbG8op8/J714BFo+so0nir+2s9QVrBLxqEQJNbyWeZW LUWQ== 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=osHUnUn4ONGHmWqAbw3FCZSTDrjGtA8O7rLbvvtkwbg=; b=tWIO0FRgt1tQ5/ciI457mkIy2eQNss+jTePf2z+cfT5Md3roIWEReFd92NSl3H9o+O TnKUfHnd5kscWHTmsAIJoSQtZTgfzx2vttD1oK08y63RiGGroHQJ/W0ZKrDd+A8D98Is raw4SfGPCUxvUkONasCNNoq2Fs3TjitzFwBs7HjFPuErlDXh7+uVTMCgwllojNA6Je0h rMCT+IRLnQlliaFBOPONo7C+hnKEjfmsETtaYOBLhOtVtZcdO0CCTSa6LYIusPmgSMSa onOpdM2OxH/pBzZAlf/8USOnRBS4NUjytTnxRepuT3CMFyGqvNo25sFT+Kq1KenfGGXE QEZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=slEfgeAq; 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 x124si7228367pgb.437.2018.01.18.17.53.34; Thu, 18 Jan 2018 17:53:48 -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=slEfgeAq; 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 S932635AbeASBxR (ORCPT + 99 others); Thu, 18 Jan 2018 20:53:17 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:40129 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755490AbeASBv5 (ORCPT ); Thu, 18 Jan 2018 20:51:57 -0500 Received: by mail-qt0-f196.google.com with SMTP id s39so438919qth.7; Thu, 18 Jan 2018 17:51:56 -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=osHUnUn4ONGHmWqAbw3FCZSTDrjGtA8O7rLbvvtkwbg=; b=slEfgeAq2ZvmYxhAyI6peeljIALmi+TV5dhM6sNdXEy3KqctdP8W26f+UJKSsgYSHy LhS+jbciZ/JIfSw5sr78vNIaKAe6HxV4onGsr2Wd/FP0m31cQI3q4LVAGoUG8IvC+yCw aMFAP9ZXDbxRgREFKPYz9t8dmV7MKg2/pGbPQc0SjprrA9y/oBOGG0Nylm8u2U1sfO5z 62WdfO1OtokFeLIZTEWKKeirYABgIfXChp5Hd1A27MP4xS14comwpHioKZbtOu2F1pra U8mtiJqc1A07v4E+lieioNY3P1L415E1n2Lb8ZcXoCAdugw5BGEfSX+45UqsRQ+0uiKI BT/Q== 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=osHUnUn4ONGHmWqAbw3FCZSTDrjGtA8O7rLbvvtkwbg=; b=ZpHeln8xPWe0ODN1tx+XM14C8ybNCsUlVMag27Ev7MkNsJIuYVt2G6S7X1KErofco9 owlw0z3d1uIpd1E9iY+ewW0oNOceNpHws6P29DPosizmRpavttbkIClzVEOIJ3AEGrfl vl6xdBLPiKl0IsGcMlws4QinyRxfxJxYxLtNoa7r9TiTzpIBUvL9NbuQ7u9iXB93Ba+m pu0jDnsVfMI9XNTYnVJNfGSI+CNWUmbcE68iUg4MZo5YbggByjfTJRC4VKEmt05Hv+U1 P56s0JBFILiZHpwsKfE9NonGXvpHRBgeR/kcsZSD7lrsTAKAxxg91uw2i44jaVdKQ97B hThg== X-Gm-Message-State: AKwxytd0U5Fox3ppVBPp+f0SlxWqshedZO1HFG2BwPUcYbpdHAsQFtwo QjLhM51KplNp6Url3QnlKlQ= X-Received: by 10.55.147.130 with SMTP id v124mr2710687qkd.94.1516326716582; Thu, 18 Jan 2018 17:51:56 -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.51.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 17:51:56 -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 06/27] powerpc: helper functions to initialize AMR, IAMR and UAMOR registers Date: Thu, 18 Jan 2018 17:50:27 -0800 Message-Id: <1516326648-22775-7-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 Introduce helper functions that can initialize the bits in the AMR, IAMR and UAMOR register; the bits that correspond to the given pkey. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Ram Pai --- arch/powerpc/mm/pkeys.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c index 6e8df6e..e1dc45b 100644 --- a/arch/powerpc/mm/pkeys.c +++ b/arch/powerpc/mm/pkeys.c @@ -16,6 +16,10 @@ int pkeys_total; /* Total pkeys as per device tree */ u32 initial_allocation_mask; /* Bits set for reserved keys */ +#define AMR_BITS_PER_PKEY 2 +#define PKEY_REG_BITS (sizeof(u64)*8) +#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey+1) * AMR_BITS_PER_PKEY)) + int pkey_initialize(void) { int os_reserved, i; @@ -107,3 +111,46 @@ static inline void write_uamor(u64 value) { mtspr(SPRN_UAMOR, value); } + +static inline void init_amr(int pkey, u8 init_bits) +{ + u64 new_amr_bits = (((u64)init_bits & 0x3UL) << pkeyshift(pkey)); + u64 old_amr = read_amr() & ~((u64)(0x3ul) << pkeyshift(pkey)); + + write_amr(old_amr | new_amr_bits); +} + +static inline void init_iamr(int pkey, u8 init_bits) +{ + u64 new_iamr_bits = (((u64)init_bits & 0x1UL) << pkeyshift(pkey)); + u64 old_iamr = read_iamr() & ~((u64)(0x1ul) << pkeyshift(pkey)); + + write_iamr(old_iamr | new_iamr_bits); +} + +static void pkey_status_change(int pkey, bool enable) +{ + u64 old_uamor; + + /* Reset the AMR and IAMR bits for this key */ + init_amr(pkey, 0x0); + init_iamr(pkey, 0x0); + + /* Enable/disable key */ + old_uamor = read_uamor(); + if (enable) + old_uamor |= (0x3ul << pkeyshift(pkey)); + else + old_uamor &= ~(0x3ul << pkeyshift(pkey)); + write_uamor(old_uamor); +} + +void __arch_activate_pkey(int pkey) +{ + pkey_status_change(pkey, true); +} + +void __arch_deactivate_pkey(int pkey) +{ + pkey_status_change(pkey, false); +} -- 1.7.1