Received: by 10.223.164.202 with SMTP id h10csp17857wrb; Mon, 6 Nov 2017 01:39:58 -0800 (PST) X-Google-Smtp-Source: ABhQp+RfRzlLW01dVm9IhP2DfynfIiU1kQShfxYOFpr2K/ilLhpmS1krwIHMn2lINcesqgPH+vPr X-Received: by 10.84.241.65 with SMTP id u1mr14061792plm.262.1509961198424; Mon, 06 Nov 2017 01:39:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509961198; cv=none; d=google.com; s=arc-20160816; b=wueXhaNmkrtEfD9P2zSs5zIfuu6F0rCHar9FRwjVYxSM+XXdOlwU+OivTjr7vgDDIn DQ0d9sxPxMdpwMrQ+UGA04FQtiVyfd4tMJrcwsTd0bLMljl4Liij7WIX8RQG1G+3qbZk bCQzLeBfXPEuvwrtGdZC6ICF4SnTAL7ZgmwWvgfxpmZvAdPx6fLBZqKmkfB1wzk4KN4j IipYz5+NBczZN04PQa/y2YrgysUMX62XiC9ad2ATkQTyO5BgXx+BsTXbCRzVK2z1P97a PrDvvpIqJCs7hL1AToQq9k1Vks5DrYKxETlJug9wbE6whJZntH2NeSb/1kX+ZXFChWx+ Thgg== 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=6E2tnjbR/B8GkI8m2JVmKSGSD/DDRMTXTJfJjruiLQ8=; b=L6la33jneqC9s3y8Mc4c7ym6RtrCNRmJH8efu3NKQQuEL8D1NotcVjAitIJ4aOth7O IAUOTNx0GojLIfTvDWaUwP3dIMmDXVjWmArpexrE86HCAY0iJqYL6Zx4f+VmF8i+QAvy 09ruly4wpRvt4jeK2leCcTLyTfj7L0Tde4OSmAKCWyQjcES+0D1frZO+rGQ1+N2DXWj0 5KscUaNR6bnamgN3ilsj18tjNZzEcxcRS025X2eDpyAiAYCNMGoiClfYZ26Rt8EW9lLF p+SMmkmWAYDnCEQryezzzB8kW2Rh1sQORJXVMsaa9XzO5oJuES9sa4b9MaTB/WgTXZWE IWRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=A69y9+ae; 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 e12si10056301plj.256.2017.11.06.01.39.44; Mon, 06 Nov 2017 01:39:58 -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=A69y9+ae; 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 S1752150AbdKFI6m (ORCPT + 98 others); Mon, 6 Nov 2017 03:58:42 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:46267 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752117AbdKFI6h (ORCPT ); Mon, 6 Nov 2017 03:58:37 -0500 Received: by mail-qt0-f195.google.com with SMTP id 1so10020910qtn.3; Mon, 06 Nov 2017 00:58:37 -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=6E2tnjbR/B8GkI8m2JVmKSGSD/DDRMTXTJfJjruiLQ8=; b=A69y9+ae7GKGO8IB/jlcXeuroCFRXy3oD6WbuHOYb/RXaEkMkyRC3VqwKlTHjtu9vF j1ybQ/8PjTGul3lnzDlrl0hnu67HTkzDpHetWvhNk1JcTKUxPc+scar4CmqjiklCV80X ZWFp27NiY8XSNb5UjPINUSuOaYvMUVB8wLxFSRH8tOyif0PXOeF1Fl3c6BY6fZgooy3j ZGNGAuFVpaywSWgSUEY+oC+b18UvYCbIvOdt5wXxTy0jeSPEwsd24nYfHoj/HgwmQIma heHBexxs2UqCT1lvQScL/EHxCTTIjRFBpd8Nu/I0b16QutWAF1d+e8aQQ97Kw5l6rjrq 6z6w== 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=6E2tnjbR/B8GkI8m2JVmKSGSD/DDRMTXTJfJjruiLQ8=; b=U5RP7/bO5C8DmNKk4dXuTATMSwBmDfGK0sYocDJBu1W7ZGTPkniyUA4SglxgmLeGXh JeuYLBsf1zEvBYYdwvZ0IGdrwjCC25ywk8CkBhQEiJfe1n6tv2yiA8Q6Yt2vvbZpEcn0 eV7ZyCz4Ug0YzIpsyUWMnalN/vwDzwmQzmGb8vjLAdGotlaGDAIxuxV7ep2lSsyKOqyH r+D+MKk1QRYEIoCuSXhPRsOCSK7moYeGg73J1J5zgHxz3YCu68xYbyPX6ezZrnnGlEES JiEvAsqOcRJB81v/xWKZWTAI5SIeursMdb8j44bUmL6RKjkEKqwNM67Z4f2qICvuaA1/ bdIA== X-Gm-Message-State: AMCzsaWwFs6abKkug0d0So57CdyILbdDec0TTNiU6+wWPzGvSYVRYLVy 1Gb9TLEXBSd7pxXRWq/1Yek= X-Received: by 10.200.6.70 with SMTP id e6mr21485742qth.15.1509958716771; Mon, 06 Nov 2017 00:58:36 -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.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:58:36 -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 06/51] powerpc: helper functions to initialize AMR, IAMR and UAMOR registers Date: Mon, 6 Nov 2017 00:56:58 -0800 Message-Id: <1509958663-18737-7-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 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 b6bdfdf..f3bf661 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)) + void __init pkey_initialize(void) { int os_reserved, i; @@ -97,3 +101,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 From 1583349717722418994@xxx Mon Nov 06 20:25:59 +0000 2017 X-GM-THRID: 1583349717722418994 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread