From patchwork Tue Mar 27 09:09:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 891430 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 409QMT4mr7z9s1P for ; Tue, 27 Mar 2018 20:15:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eE+pTq7c"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 409QMT35PpzF21T for ; Tue, 27 Mar 2018 20:15:01 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com 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="eE+pTq7c"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c0d::242; helo=mail-qt0-x242.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eE+pTq7c"; dkim-atps=neutral Received: from mail-qt0-x242.google.com (mail-qt0-x242.google.com [IPv6:2607:f8b0:400d:c0d::242]) (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 409QFV4cNPzF29r for ; Tue, 27 Mar 2018 20:09:50 +1100 (AEDT) Received: by mail-qt0-x242.google.com with SMTP id s2so22956254qti.2 for ; Tue, 27 Mar 2018 02:09:50 -0700 (PDT) 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=lSzDUHNNLasWU37pZINGQ+GwumTv6j48e7e9QFEH4f0=; b=eE+pTq7cldBLZOqGrX4CJxAcXqF7Q0vHM2W1uj3Pu9q8b+hkQO2CtLlgCH+x3CDSlo c/2C8v7iaD+QqOo7b0LFLcgIVYMAg9OCJoJ+BzBsmCIdSyueqbZOH0wzLfX61d9kbTFE b6Hk0DycLlB423Kmu51VRPh5bftRI/6+cIc79tkq538XPy48XP2cfsnyMuAfg9Ubo2kp aa6kI5dmzUcOVTtM/CfgaEzx/u3AkHYhZajGV5uPY+CFhWgxBj0YiMPOJJMW70/ikfQw 7TcGxPZv+5XlyGJegfd6y92U0iN9ItWkacc44OShJB/PxWvqXEOlT6PQj72BUrVSp6eM ei/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=lSzDUHNNLasWU37pZINGQ+GwumTv6j48e7e9QFEH4f0=; b=O9s4bdFAFn2KEAWXYKVFD8R2/gw/OgHYBjG5NVXzj+kkBg8waFGG1dkJteIAL1apji ouMyIFMLoA7xLOy+QTxW71W+MZiY6Uo3AbgZbX0mGoe/xOQ/7RfNFQC9xTzuoxRaAkOt Z9hokC/oFu79bnxzClfXbfVG0LF+Mrl2uaANbAbbHQiNMSoXM71P8O7PGPnzYYIddT3D TXIDHLkFp6FmQHFtY0iv0Z4vOgDIYt0uz5RoQxgNvKzZXJ8Vw+/xmEGmwLJ5Bbvwu+nn ngBY3egVOo6I11P3fRkzOe04mUVk8UHden7cJp8yY68ESBEZ+dYxyrc2Lz/rxkQtwDIS LGBg== X-Gm-Message-State: AElRT7H0iFSFbIHky+FA403OSP1k/3ZI3SCx6EKH1ebzPOJwdlcyHtyq 5zUYVNC4R1y1THxJb+9I3LU= X-Google-Smtp-Source: AG47ELtneK+K6hBQqJWWw2yG5YBhZV3D4doz2xsoxACmQjOng75K7vZRGHOAIZsRunpo1K2TVtEN0A== X-Received: by 10.200.34.59 with SMTP id o56mr63269441qto.103.1522141784110; Tue, 27 Mar 2018 02:09:44 -0700 (PDT) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id r51sm557475qtr.23.2018.03.27.02.09.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 02:09:43 -0700 (PDT) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org Subject: [PATCH v13 1/3] mm, powerpc, x86: define VM_PKEY_BITx bits if CONFIG_ARCH_HAS_PKEYS is enabled Date: Tue, 27 Mar 2018 02:09:26 -0700 Message-Id: <1522141768-25485-2-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1522141768-25485-1-git-send-email-linuxram@us.ibm.com> References: <1522141768-25485-1-git-send-email-linuxram@us.ibm.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 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, corbet@lwn.net, ebiederm@xmission.com, arnd@arndb.de, 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" VM_PKEY_BITx are defined only if CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS is enabled. Powerpc also needs these bits. Hence lets define the VM_PKEY_BITx bits for any architecture that enables CONFIG_ARCH_HAS_PKEYS. cc: Michael Ellermen cc: Benjamin Herrenschmidt cc: Andrew Morton Reviewed-by: Dave Hansen Signed-off-by: Ram Pai Reviewed-by: Ingo Molnar Reviewed-by: Aneesh Kumar K.V --- arch/powerpc/include/asm/pkeys.h | 2 ++ fs/proc/task_mmu.c | 4 ++-- include/linux/mm.h | 9 +++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index 0d3c630..99344d7 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -26,6 +26,8 @@ # define VM_PKEY_BIT2 VM_HIGH_ARCH_2 # define VM_PKEY_BIT3 VM_HIGH_ARCH_3 # define VM_PKEY_BIT4 VM_HIGH_ARCH_4 +#elif !defined(VM_PKEY_BIT4) +# define VM_PKEY_BIT4 VM_HIGH_ARCH_4 #endif #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | \ diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index ec6d298..6b996d0 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -679,13 +679,13 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) [ilog2(VM_MERGEABLE)] = "mg", [ilog2(VM_UFFD_MISSING)]= "um", [ilog2(VM_UFFD_WP)] = "uw", -#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS +#ifdef CONFIG_ARCH_HAS_PKEYS /* These come out via ProtectionKey: */ [ilog2(VM_PKEY_BIT0)] = "", [ilog2(VM_PKEY_BIT1)] = "", [ilog2(VM_PKEY_BIT2)] = "", [ilog2(VM_PKEY_BIT3)] = "", -#endif +#endif /* CONFIG_ARCH_HAS_PKEYS */ }; size_t i; diff --git a/include/linux/mm.h b/include/linux/mm.h index ad06d42..ad207ad 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -228,15 +228,16 @@ extern int overcommit_kbytes_handler(struct ctl_table *, int, void __user *, #define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4) #endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */ -#if defined(CONFIG_X86) -# define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */ -#if defined (CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS) +#ifdef CONFIG_ARCH_HAS_PKEYS # define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0 # define VM_PKEY_BIT0 VM_HIGH_ARCH_0 /* A protection key is a 4-bit value */ # define VM_PKEY_BIT1 VM_HIGH_ARCH_1 # define VM_PKEY_BIT2 VM_HIGH_ARCH_2 # define VM_PKEY_BIT3 VM_HIGH_ARCH_3 -#endif +#endif /* CONFIG_ARCH_HAS_PKEYS */ + +#if defined(CONFIG_X86) +# define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */ #elif defined(CONFIG_PPC) # define VM_SAO VM_ARCH_1 /* Strong Access Ordering (powerpc) */ #elif defined(CONFIG_PARISC) From patchwork Tue Mar 27 09:09:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 891432 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 409QRJ2NSdz9s0m for ; Tue, 27 Mar 2018 20:18:20 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jWxmfNgQ"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 409QRJ05V8zF20s for ; Tue, 27 Mar 2018 20:18:20 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com 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="jWxmfNgQ"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.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; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jWxmfNgQ"; 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 409QFY2znyzF29V for ; Tue, 27 Mar 2018 20:09:53 +1100 (AEDT) Received: by mail-qt0-x241.google.com with SMTP id g5so11822609qth.7 for ; Tue, 27 Mar 2018 02:09:53 -0700 (PDT) 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=kerfeK2JoO7+oQrs2Rs90drlJqT4/y+dgPYmSKQcDZY=; b=jWxmfNgQyd8Yx05hgSKhoslediHVNu+0mVF/KvCud81pLdxYwYXSFuAD9xXUCpH9Il csmkmEPH8KUavZ8X/MUpG4F6dYeBUlXYRElYJ5h4MXT4+c7C9hvrF9tvcstaQGz/47Fj vFswmpgFvZF21X+4PU+b5Q8Tff5cSabuLePUrLhuatThHZUezBMwEHt33zFHQrnI7Ua2 qcWD57vmkY+77wEioHnuL2ZScGQb0Wjh5Zngyj6cnry3MIgOILmeOcPPWCcWcMPRXojo XTOPp9qoEnRSBVnVz9N3vsAYCytS4ZM0Av7gcICrjpYxeDl6HQ15jPX+8DCq85hs9ruQ NHLA== 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=kerfeK2JoO7+oQrs2Rs90drlJqT4/y+dgPYmSKQcDZY=; b=GoJ5hbz8APy9L8pOMhA+M5u/bG8vHRRKGHKP/5Wl3hyIY9HNW1FpXCo0uqDCNiOpT8 OLxsPvT0haT39EqP/nrDBnJDSQodqfxVBbvnAy8mAvP9/IHSD9tI6NJdQOrJsPXnDP8V 7xeeVUKmu51dbHzNeHcwp2H2Rx8pyppA3co4782HDT9B/EmIjy1dgQcy1cW9eeAP4PYW Uxc8vLQH4elh1UWiKEpFYPx2BWzLfy7RAe8Imys1QYjafqtpS3EVG2D+6tVVCn8VYnLM mLdNxdz/Gc2eMXXGVZYjsvMtdHW8i5cn855fk/aHnHMxDw05nIAm4n4Ngavkw1k+7e1J qTrQ== X-Gm-Message-State: AElRT7HZbAFh9+T2WEhXnzz/VsY+QDS9N5KwabigHrK/m0LC4FtnqGwU gQ+ziCBV2k9eB0iH6jnPymM= X-Google-Smtp-Source: AIpwx480/vPTNT29I0MFNOkBFW6odoqsuBrxGUTrfBRhNOY/EK/7CGRyd4jbKhbJzHItsDN2Wm+k4A== X-Received: by 10.200.57.117 with SMTP id t50mr18948853qtb.22.1522141791504; Tue, 27 Mar 2018 02:09:51 -0700 (PDT) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id r51sm557475qtr.23.2018.03.27.02.09.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 02:09:50 -0700 (PDT) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org Subject: [PATCH v13 2/3] mm, powerpc, x86: introduce an additional vma bit for powerpc pkey Date: Tue, 27 Mar 2018 02:09:27 -0700 Message-Id: <1522141768-25485-3-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1522141768-25485-1-git-send-email-linuxram@us.ibm.com> References: <1522141768-25485-1-git-send-email-linuxram@us.ibm.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 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, corbet@lwn.net, ebiederm@xmission.com, arnd@arndb.de, 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" Currently only 4bits are allocated in the vma flags to hold 16 keys. This is sufficient for x86. PowerPC supports 32 keys, which needs 5bits. This patch allocates an additional bit. cc: Dave Hansen cc: Michael Ellermen cc: Benjamin Herrenschmidt cc: Andrew Morton Reviewed-by: Ingo Molnar Acked-by: Balbir Singh Signed-off-by: Ram Pai --- fs/proc/task_mmu.c | 1 + include/linux/mm.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 6b996d0..6d83bb7 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -685,6 +685,7 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) [ilog2(VM_PKEY_BIT1)] = "", [ilog2(VM_PKEY_BIT2)] = "", [ilog2(VM_PKEY_BIT3)] = "", + [ilog2(VM_PKEY_BIT4)] = "", #endif /* CONFIG_ARCH_HAS_PKEYS */ }; size_t i; diff --git a/include/linux/mm.h b/include/linux/mm.h index ad207ad..d534f46 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -231,9 +231,10 @@ extern int overcommit_kbytes_handler(struct ctl_table *, int, void __user *, #ifdef CONFIG_ARCH_HAS_PKEYS # define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0 # define VM_PKEY_BIT0 VM_HIGH_ARCH_0 /* A protection key is a 4-bit value */ -# define VM_PKEY_BIT1 VM_HIGH_ARCH_1 +# define VM_PKEY_BIT1 VM_HIGH_ARCH_1 /* on x86 and 5-bit value on ppc64 */ # define VM_PKEY_BIT2 VM_HIGH_ARCH_2 # define VM_PKEY_BIT3 VM_HIGH_ARCH_3 +# define VM_PKEY_BIT4 VM_HIGH_ARCH_4 #endif /* CONFIG_ARCH_HAS_PKEYS */ #if defined(CONFIG_X86) From patchwork Tue Mar 27 09:09:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 891437 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 409QWW0P39z9s1R for ; Tue, 27 Mar 2018 20:21:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hMpTISIS"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 409QWV5YsBzF1vq for ; Tue, 27 Mar 2018 20:21:58 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com 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="hMpTISIS"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c0d::244; helo=mail-qt0-x244.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hMpTISIS"; dkim-atps=neutral Received: from mail-qt0-x244.google.com (mail-qt0-x244.google.com [IPv6:2607:f8b0:400d:c0d::244]) (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 409QFc1CY0zF28y for ; Tue, 27 Mar 2018 20:09:56 +1100 (AEDT) Received: by mail-qt0-x244.google.com with SMTP id j3so11462916qtn.9 for ; Tue, 27 Mar 2018 02:09:56 -0700 (PDT) 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=3Ol0KXySuS8B67zfSDDU9xuo4wjSsjHw8eQxbIAIi0s=; b=hMpTISIS21qZfE5sxJKO3pMrIFiUpHJeiqoATd0cxp9Ihjq2j6HARZXqjeQWIbKNMB L/6SGsmhWj91T0Zic1RBgkWm0N5LIA1iSW3QPZYH3BUdcXZavYMnsr9xVcWfsipcJ16b OU66oxc31v8ivY5wz948v/mw1zXj7575jrv8l+x4p5W6BbIYoXPTpBAgmstVRetmi9r5 +SxKkiRnpJDkoti0LK3X715sJMGZF4raeWL9cKYCI2VraSkunmhEMhp1RSQFsKbG7mUs RkIjcq1MtySYZ3MnBUmaRv7fMZ8I3fMoX1EcGIMh7CBGDUhki2yufKR4H5RYo/HOyl/7 lxww== 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=3Ol0KXySuS8B67zfSDDU9xuo4wjSsjHw8eQxbIAIi0s=; b=X2IHdT6WNf8H79i8V2kk6clhLP0b+9qkMi3I145xJcDUKF6T9lZ13+fJ0aT21dC9xA 2zyValEI27+0OSdfJ2Thm91fz+rWP9XuteeAa5DbiOKtM+qG7fW8cNyK67KdOUP/YM95 DsCC6FWNeGtG7D2I0uuW8010C77FNQXzQMNCg5SPq/tVgAmtmpGjK9kfSqqkNIsIRQgj gAkjafWGmftPgCzBEmjsv5G6d0XY1uKc3FayCb9DlQFY9fkEIM+ug7LU24RNXyW1iJ0J ya2aD4Gg1jARH+sgX+UB/gSo8dmwGUopgvJVxZP7lm9a4WpI8FSmPCeFXhruoJgIjBBy plRw== X-Gm-Message-State: AElRT7ENVzrFF+StYSyz3UiuACytYw5iA0jBymufr0bsPmMa6+9F7KE+ ZiwL17u7hj62+isGdsC5wiA= X-Google-Smtp-Source: AG47ELvsNo9Putt6Udh73gJ9sqJMuyJZe7ifDEfBRyAaAGHfCIViS6FIk1a4jM20WIghUiwxCwJCng== X-Received: by 10.237.44.100 with SMTP id f91mr63580095qtd.80.1522141794233; Tue, 27 Mar 2018 02:09:54 -0700 (PDT) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id r51sm557475qtr.23.2018.03.27.02.09.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 02:09:53 -0700 (PDT) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org Subject: [PATCH v13 3/3] mm, x86, powerpc: display pkey in smaps only if arch supports pkeys Date: Tue, 27 Mar 2018 02:09:28 -0700 Message-Id: <1522141768-25485-4-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1522141768-25485-1-git-send-email-linuxram@us.ibm.com> References: <1522141768-25485-1-git-send-email-linuxram@us.ibm.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 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, corbet@lwn.net, ebiederm@xmission.com, arnd@arndb.de, 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" Currently the architecture specific code is expected to display the protection keys in smap for a given vma. This can lead to redundant code and possibly to divergent formats in which the key gets displayed. This patch changes the implementation. It displays the pkey only if the architecture support pkeys, i.e arch_pkeys_enabled() returns true. This patch provides x86 implementation for arch_pkeys_enabled(). x86 arch_show_smap() function is not needed anymore. Deleting it. cc: Michael Ellermen cc: Benjamin Herrenschmidt cc: Andrew Morton Reviewed-by: Dave Hansen Signed-off-by: Thiago Jung Bauermann (fixed compilation errors for x86 configs) Acked-by: Michal Hocko Reviewed-by: Ingo Molnar Signed-off-by: Ram Pai --- arch/powerpc/include/asm/mmu_context.h | 5 ----- arch/x86/include/asm/mmu_context.h | 5 ----- arch/x86/include/asm/pkeys.h | 1 + arch/x86/kernel/fpu/xstate.c | 5 +++++ arch/x86/kernel/setup.c | 8 -------- fs/proc/task_mmu.c | 10 +++++----- include/linux/pkeys.h | 7 ++++++- 7 files changed, 17 insertions(+), 24 deletions(-) diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h index 051b3d6..566b3c2 100644 --- a/arch/powerpc/include/asm/mmu_context.h +++ b/arch/powerpc/include/asm/mmu_context.h @@ -203,11 +203,6 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, #define thread_pkey_regs_restore(new_thread, old_thread) #define thread_pkey_regs_init(thread) -static inline int vma_pkey(struct vm_area_struct *vma) -{ - return 0; -} - static inline u64 pte_to_hpte_pkey_bits(u64 pteflags) { return 0x0UL; diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index 1de72ce..e597d09 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -295,11 +295,6 @@ static inline int vma_pkey(struct vm_area_struct *vma) return (vma->vm_flags & vma_pkey_mask) >> VM_PKEY_SHIFT; } -#else -static inline int vma_pkey(struct vm_area_struct *vma) -{ - return 0; -} #endif /* diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h index a0ba1ff..f6c287b 100644 --- a/arch/x86/include/asm/pkeys.h +++ b/arch/x86/include/asm/pkeys.h @@ -6,6 +6,7 @@ extern int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsigned long init_val); +extern bool arch_pkeys_enabled(void); /* * Try to dedicate one of the protection keys to be used as an diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 87a57b7..4f566e9 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -945,6 +945,11 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, return 0; } + +bool arch_pkeys_enabled(void) +{ + return boot_cpu_has(X86_FEATURE_OSPKE); +} #endif /* ! CONFIG_ARCH_HAS_PKEYS */ /* diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 4c616be..117ed01 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -1307,11 +1307,3 @@ static int __init register_kernel_offset_dumper(void) return 0; } __initcall(register_kernel_offset_dumper); - -void arch_show_smap(struct seq_file *m, struct vm_area_struct *vma) -{ - if (!boot_cpu_has(X86_FEATURE_OSPKE)) - return; - - seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); -} diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 6d83bb7..70aa912 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -18,10 +18,12 @@ #include #include #include +#include #include #include #include +#include #include "internal.h" void task_mem(struct seq_file *m, struct mm_struct *mm) @@ -733,10 +735,6 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask, } #endif /* HUGETLB_PAGE */ -void __weak arch_show_smap(struct seq_file *m, struct vm_area_struct *vma) -{ -} - static int show_smap(struct seq_file *m, void *v, int is_pid) { struct proc_maps_private *priv = m->private; @@ -856,9 +854,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid) (unsigned long)(mss->pss >> (10 + PSS_SHIFT))); if (!rollup_mode) { - arch_show_smap(m, vma); + if (arch_pkeys_enabled()) + seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); show_smap_vma_flags(m, vma); } + m_cache_vma(m, vma); return ret; } diff --git a/include/linux/pkeys.h b/include/linux/pkeys.h index 0794ca7..49dff15 100644 --- a/include/linux/pkeys.h +++ b/include/linux/pkeys.h @@ -3,7 +3,6 @@ #define _LINUX_PKEYS_H #include -#include #ifdef CONFIG_ARCH_HAS_PKEYS #include @@ -13,6 +12,7 @@ #define arch_override_mprotect_pkey(vma, prot, pkey) (0) #define PKEY_DEDICATED_EXECUTE_ONLY 0 #define ARCH_VM_PKEY_FLAGS 0 +#define vma_pkey(vma) 0 static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) { @@ -35,6 +35,11 @@ static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, return 0; } +static inline bool arch_pkeys_enabled(void) +{ + return false; +} + static inline void copy_init_pkru_to_fpregs(void) { }