Received: by 10.223.176.46 with SMTP id f43csp306869wra; Thu, 18 Jan 2018 17:54:28 -0800 (PST) X-Google-Smtp-Source: ACJfBot72xyf/P47f0LYJ4xDrXA0dMox063C5HvSPOSZgVuH0HN6wLJqIAXw83Sd58rM9Voj7Byq X-Received: by 10.101.69.7 with SMTP id n7mr9635273pgq.62.1516326868664; Thu, 18 Jan 2018 17:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516326868; cv=none; d=google.com; s=arc-20160816; b=qPeZdPwHhgT7b6JuY6qfv4KP+Q8hOj5fYNVOVWTdmKxYbrvVdzTDQnmwpTGO5/5Dfn qmowR6aVmkx2qMYZJ4ztdSFDPzVLACaPyXpnjjdrjDVpOh/pO/zVbQUGmyLB2V7JOMyd LEgbfJ9HOFp1r135y4KNTogHrcLvcowqteW5O3PBm7R0+fRCIns5q9ll/ltCHdi+ydNe uUMqllqT3d1sFPR4Wenp1eJqkc4B2X51BaqFNqF3UEQA3eCiTTr/5GzytM0a18F2+Mpc qmptocLAe1ZLeAPUG2WMsA9kPoWmvzATMSz7u35QHHJb4sDIhae9JOQg/2XIakfngjQd 3Geg== 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=d21vS/S3f/p9dIidcG1eUEgIhVwgEVil7I00SYtNwX0=; b=GS0GxlacQ6TB8lL3JpMqbOGW5x5Vxo3uCfjHS6S0ik2+u72d6+Fszgmg7qGWvvJBzU fUT5i3MJxsY73HLbs7CfWdJRSX+rWHmm2+P/mf+VnoTZJwSs4E8BkUoXGkFtdeI8F+9P qCU5CiUcGi5mcsXn4k6jtnJy5RJWD59uOMhKuQZrpo2g1eLTWzC9PL/Je1ddteCBp33I vTsQzb7bjiHerhiyUNHQGGlr6O76n+gwrzqAkERJKYta1T0uvaa9kkPOhunlwZROC2fJ eJ8I6yHrCHySjJVCXyFV3mukXC5FzuT6h7Wmoig+RyIKW5i5q0QeXELYpEeyd2GWtfOw ev3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=bV5ic1mV; 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 m23si7364091pgc.438.2018.01.18.17.54.14; Thu, 18 Jan 2018 17:54:28 -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=bV5ic1mV; 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 S1755763AbeASBwm (ORCPT + 99 others); Thu, 18 Jan 2018 20:52:42 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:39260 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755502AbeASBwA (ORCPT ); Thu, 18 Jan 2018 20:52:00 -0500 Received: by mail-qt0-f195.google.com with SMTP id f4so438848qtj.6; Thu, 18 Jan 2018 17:51:59 -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=d21vS/S3f/p9dIidcG1eUEgIhVwgEVil7I00SYtNwX0=; b=bV5ic1mVy58i681dkaZ6YacV2aJ5L8AsFoBzlhVQpsldoj565H0u2X1JbDwdi7qIOX qA7Pwkl65LrKsWw2GMFDf2NchPygkS6msKTsScpMrtyKeerjdAVXcHNEzKJrLv61+EFv zCfnlun48Wg+UttTN+yMT8yqZYJgQDjF1jzfiDFfxUx2xhtCTqv7siWQo10ojegLVlvM zM/mLx4+1fz0Fhbz18XPI5bIYNPsNnavltXVMrNAkTMaOS3GvzNJ4K+qF4aY0THv4sFN xpRZnqsAf2jEXnRnBtKKdr0hUkgPX/iGW7RXS2l9E6algWwblAVDXbKWtJmdWAvQz9vU svog== 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=d21vS/S3f/p9dIidcG1eUEgIhVwgEVil7I00SYtNwX0=; b=TV86Et6Aydme+Md2/1NcNsW2CTGNrLICxEb+as795UIaj74JY3wa5NJUhH3tNdt/qT CeU0RFr5slD3VIKequD+9/ragnZ85u7qC/w9NrlzaSfMhTvW7R8HlB2y8tztDrHNld2z uL9hX4PNeTMFfswCIHMqzlyAGUORKyW4EL00sYl4t6icOaMiXOq/fwySXVzfCW4eeLLD 6HRSrp3E3geCSYy64XEgd5XglHLVfgjufPPTO/JtYie005E4Oy/T8FfY8SCYLtyebl6l wm0Tsky31lHVZmbXvVu7ejYrlV1/RbeCmxM6sYVQ7EHNx3eE4ouGiKnzrHaraxBtIRdl bY1w== X-Gm-Message-State: AKwxytdZSErf+hb6eBiZ4H8dxer8V3SyujuwcI4G+ysHMtbP1XZ6nypi A1x14gF25eI1kdVlA5wQRFs= X-Received: by 10.55.52.201 with SMTP id b192mr46011057qka.188.1516326719464; Thu, 18 Jan 2018 17:51:59 -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.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 17:51:59 -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 07/27] powerpc: cleanup AMR, IAMR when a key is allocated or freed Date: Thu, 18 Jan 2018 17:50:28 -0800 Message-Id: <1516326648-22775-8-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 Cleanup the bits corresponding to a key in the AMR, and IAMR register, when the key is newly allocated/activated or is freed. We dont want some residual bits cause the hardware enforce unintended behavior when the key is activated or freed. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Ram Pai --- arch/powerpc/include/asm/pkeys.h | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index 1e8cef2..9964b46 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -69,6 +69,8 @@ static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) __mm_pkey_is_allocated(mm, pkey)); } +extern void __arch_activate_pkey(int pkey); +extern void __arch_deactivate_pkey(int pkey); /* * Returns a positive, 5-bit key on success, or -1 on failure. * Relies on the mmap_sem to protect against concurrency in mm_pkey_alloc() and @@ -96,6 +98,12 @@ static inline int mm_pkey_alloc(struct mm_struct *mm) ret = ffz((u32)mm_pkey_allocation_map(mm)); __mm_pkey_allocated(mm, ret); + + /* + * Enable the key in the hardware + */ + if (ret > 0) + __arch_activate_pkey(ret); return ret; } @@ -107,6 +115,10 @@ static inline int mm_pkey_free(struct mm_struct *mm, int pkey) if (!mm_pkey_is_allocated(mm, pkey)) return -EINVAL; + /* + * Disable the key in the hardware + */ + __arch_deactivate_pkey(pkey); __mm_pkey_free(mm, pkey); return 0; -- 1.7.1