Received: by 10.223.176.46 with SMTP id f43csp307635wra; Thu, 18 Jan 2018 17:55:22 -0800 (PST) X-Google-Smtp-Source: ACJfBouL/RYaSRxu2xRINYIEQCFZJrmxtj4eHX2ngvAmnM8LzjT3ZBo5ThpN1UwAp+x8WCPf7vkF X-Received: by 10.99.38.6 with SMTP id m6mr39442304pgm.12.1516326922810; Thu, 18 Jan 2018 17:55:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516326922; cv=none; d=google.com; s=arc-20160816; b=EQkCFYrPqNNXb3vp208TfT0ZfkKTZv7yItFBkyCI4no6PWoRzKIUMcuHRGi3OIjh9G eOCnp/NegbA0QA5f2rvD4FbXwQCJ3ePPJ1aUt0jo4itYhiw4ojH3fthADLz44M7uHgKV x7JEz4WHEKP7PujCJEZdmgIw42NM+BnmYB94UANX5nOtudkSjG0x4zixQkWkAjWnZbQS Ew4yKo3aRBOyJvgGd+3wW61BMZXVU1YUjr0UyFif8CBiq4OZV3iTMXCfYQEU6gMyRS2Z 0hjbDfd1KoXMN7Rym0xo1IRR9ZWDLGzNOwgWI5piEdcZ8GxXax9WD7PIoW4q4+e+c0CI zDrg== 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=c3bLShvPscs3RzOIlK13xa+AfxSKigld6/vuX+uGzY0=; b=qMKAfl7H8vE91YKCl6aEjXStCU99fhd3gYiEl1P0ISZH/bIlIvo2zeqYYf3xlTGrR4 38jpJfKAn/A1QGnjJqwUDeY259j3ePwrwfH0rUONT69DfvUAcpceirzs2zon5wdlNVra LMQDEY46/Lb/gT2UXxtxpKTIrNzRS+CD4BTLwICONmSNivdWM83VKC073QOa+guYFg5q JGtUT1bl1xEprKrN6wHUZ3PaXtCOcqexT0vtyVEOmQQRmFiIM1Se4JF3EExp7XyIjmzn faWTihn+0+2vs1c3HUlzUZxEQgfR70Wytlk9EfMFDxUDdTLlymX+baDScdyGUFax6J4w oNSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=YNDTexF/; 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 m8si7335688pgn.343.2018.01.18.17.55.09; Thu, 18 Jan 2018 17:55:22 -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=YNDTexF/; 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 S932863AbeASBxh (ORCPT + 99 others); Thu, 18 Jan 2018 20:53:37 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:37921 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755754AbeASBwl (ORCPT ); Thu, 18 Jan 2018 20:52:41 -0500 Received: by mail-qt0-f193.google.com with SMTP id z10so444310qti.5; Thu, 18 Jan 2018 17:52:41 -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=c3bLShvPscs3RzOIlK13xa+AfxSKigld6/vuX+uGzY0=; b=YNDTexF/opxSaejH16pSXgEC08kQm/RmIAWHCKEpShoChUiAX/wPTitxD1ou4zrzM4 DyZXbaGTC0Uv3luT1rpT2KQMHzW4NfVM2/4vtFulopyhzT5wOhVNLcEEzHeW5z3fnFqg ppTyf09C5spRDSz4aodt1w3dMk1CfNTP4VzJZk9lEmJUmodl60NVyOyYqL6xbgMQTIas KKivuUkZ9dWFoDczhxqhNj2Bc3NmakFKpccJW+j26rxGHjFCy0fWDcE8qRjqYtTnTuMT PZQK+YL4Pu6GTN+MDZj8TDmZnMt9QrqqP+t6tGCaBz0dawb7MU4zM7xohsXysJ270qRI vJmg== 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=c3bLShvPscs3RzOIlK13xa+AfxSKigld6/vuX+uGzY0=; b=IgBrLcB1i3g4306vNl1TPVkjv2DAjJAWADNcI6wLzmB/oZCQGjZEGj9a8tqXm2M8H9 gtqhzoFYF/ypwWE4Tt4KAwIdIS1dyWgHQjiTzf8c21cr3qgFx4Od0/yFNiMFLkcAg666 kmQhhu+hZakT8Mr9fVJC6bAryv/7YsVh/uJG+FSm6g8jV/mS1BHULZRO2JMcDxjTM/9P XWgFOXrNnPkyOQnXhCuauWgrBpNEKN7y3G3LACfgrDx71Ynrv6nHEaGSoz4G23mu2IvP 4EugMtiFMH0XvAK9IfUFis4Us4rf7g+Y6Cl0oQinrc0qX1+9uXsRsxUA+XGv5tzuIUmO EFmw== X-Gm-Message-State: AKwxytcHBjJh40SxZAf869MQ3vkakdDFlFQxToBwLH1LoWRjAUu3m3IA bM+7vL42XIEplufr25ceK6iRTYbf X-Received: by 10.200.47.130 with SMTP id l2mr38066161qta.277.1516326760452; Thu, 18 Jan 2018 17:52:40 -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.52.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 17:52:40 -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 20/27] powerpc: introduce get_mm_addr_key() helper Date: Thu, 18 Jan 2018 17:50:41 -0800 Message-Id: <1516326648-22775-21-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 get_mm_addr_key() helper returns the pkey associated with an address corresponding to a given mm_struct. Signed-off-by: Ram Pai --- arch/powerpc/include/asm/mmu.h | 9 +++++++++ arch/powerpc/mm/hash_utils_64.c | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h index 6364f5c..bb38312 100644 --- a/arch/powerpc/include/asm/mmu.h +++ b/arch/powerpc/include/asm/mmu.h @@ -260,6 +260,15 @@ static inline bool early_radix_enabled(void) } #endif +#ifdef CONFIG_PPC_MEM_KEYS +extern u16 get_mm_addr_key(struct mm_struct *mm, unsigned long address); +#else +static inline u16 get_mm_addr_key(struct mm_struct *mm, unsigned long address) +{ + return 0; +} +#endif /* CONFIG_PPC_MEM_KEYS */ + #endif /* !__ASSEMBLY__ */ /* The kernel use the constants below to index in the page sizes array. diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c index dc0f76e..1e1c03b 100644 --- a/arch/powerpc/mm/hash_utils_64.c +++ b/arch/powerpc/mm/hash_utils_64.c @@ -1573,6 +1573,30 @@ void hash_preload(struct mm_struct *mm, unsigned long ea, local_irq_restore(flags); } +#ifdef CONFIG_PPC_MEM_KEYS +/* + * Return the protection key associated with the given address and the + * mm_struct. + */ +u16 get_mm_addr_key(struct mm_struct *mm, unsigned long address) +{ + pte_t *ptep; + u16 pkey = 0; + unsigned long flags; + + if (!mm || !mm->pgd) + return 0; + + local_irq_save(flags); + ptep = find_linux_pte(mm->pgd, address, NULL, NULL); + if (ptep) + pkey = pte_to_pkey_bits(pte_val(READ_ONCE(*ptep))); + local_irq_restore(flags); + + return pkey; +} +#endif /* CONFIG_PPC_MEM_KEYS */ + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM static inline void tm_flush_hash_page(int local) { -- 1.7.1