From patchwork Mon Nov 6 08:56:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 834533 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 3yVnTd1Nf9z9s5L for ; Mon, 6 Nov 2017 20:35:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="A69y9+ae"; 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 3yVnTd03MlzDrKg for ; Mon, 6 Nov 2017 20:35:01 +1100 (AEDT) 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="A69y9+ae"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c0d::241; helo=mail-qt0-x241.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="A69y9+ae"; dkim-atps=neutral Received: from mail-qt0-x241.google.com (mail-qt0-x241.google.com [IPv6:2607:f8b0:400d:c0d::241]) (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 3yVmgf4TN5zDr5T for ; Mon, 6 Nov 2017 19:58:38 +1100 (AEDT) Received: by mail-qt0-x241.google.com with SMTP id f8so10006652qta.5 for ; Mon, 06 Nov 2017 00:58:38 -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=b/XSdxbYrx2uwXj55hkVL3Fq2C7hJBZlUQXqfPu7PuCPoF1w+MwUSc+mfUnTxvhJ0X 13WTyBywmyG1WyUizo04f7ItOda2fn8h/lh+KAcVfqnAIQNWkeGOi7gu0tynRbfIi0hG JkQIu5PGE5E7yyojXk3L+W4wMqcO3j3Th0M9ARxRwllaYbeekDNmCGIp4aCJzVvWCpdS fIBraWNaH9ga3MlpZXZHhi5rb83tVmo0sCmDa9FvKLO+SalxHlhKVsN912BRqdOKf1aQ 4wOO+uYlLmMbfEvYIU8suu3b40e8aSnYdx9amLZ2RsIdAjMakGPh8d4fDDqgfYDy5Mh6 7taw== X-Gm-Message-State: AMCzsaWKFsAjbOUrUo8CMrJy++I76TkljWrOHbqiDSIaVbYa8tFOrd4e L/D/sariBJGWjlHqKqWtCwk= X-Google-Smtp-Source: ABhQp+Qzxa+Knx4+sG8GbsNERXgdgAPV+k5lZg/5teOdj7ZSlz3Hb+3ldf9Odfm49v6HdVteYOTJqg== 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 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> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, ebiederm@xmission.com, linux-doc@vger.kernel.org, x86@kernel.org, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linuxram@us.ibm.com, mhocko@kernel.org, linux-mm@kvack.org, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, linux-kselftest@vger.kernel.org, bauerman@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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); +}