Received: by 10.223.185.116 with SMTP id b49csp1286496wrg; Wed, 21 Feb 2018 15:54:18 -0800 (PST) X-Google-Smtp-Source: AH8x225Do0tfqulWTAwXVS6s+mRSSSS7CyUz6slv95WgfFF/TXIkLMsXNIKiv+YZmHC+Nwtd19w9 X-Received: by 10.99.111.196 with SMTP id k187mr3979955pgc.360.1519257257946; Wed, 21 Feb 2018 15:54:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519257257; cv=none; d=google.com; s=arc-20160816; b=HXJ/O+harOaZpWeNd3gvS0XdDVY9PAe6Hf1NFPtsshJ0aPMprqCxwcJUNW/Uq5Qflb iqcwxS9B7E+zaQ7NZaBz/+pRcJ4eS5BiXjDjyZ0YtNI5xKNVejLFsC/TQhoV0wlZ6r+b hGOkB/CivJPm5qfNT9FM5wvULmXIl32vJwFg10b2fV0WvIfpo9BSbK1tQbdA0wnhRYUx x4HGP3z+0Og07N4Mv0AmF/g8Vl0be81lzsYJx5+W+SX3u2L9CXWOSfsqEL7z44XjFp/W litBW3XuECbr4VrJNfuyrXi83pkydTbzwwjTOqpgDf2Iu4ElFPvCsyh9noh6vIfdprEi pkvw== 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=sra53Tt7ExbQjIXtI+GCBSRazE+x5zx5SXrD7qrQQ44=; b=FwikHkxpD2Id/79Oy+H2ZA6KRtDfT9T95/zg9umEWjWb53CuK5jCeOMIA4jyW+Vnt3 9AfK9ZLbFtz5Int+mrsg312Bs7nfWVH124G5CulzKBzWuyTsQyTQxi8dhohwzW0S++Is 8zb5l8gx21/n27+q/8Y6MTisXP5y7D7FRXH512a7YFJrtUE80UEAIPPZHHm7J0n9iH+n KtQG/gBx1i625fOnJDUiqVzFtjvqJzkv60aDMNzFgWdTJPMYRfIaQb/8xZj0TImQw8mD Wv7Ry55I7xb8tCFro64U16ACjpMtWf6mF6WB8JDdg6OCcD63mBOexWtudKkjYS2SLsiE GxtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=I3KciERb; 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 q25si489202pge.457.2018.02.21.15.54.03; Wed, 21 Feb 2018 15:54:17 -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=I3KciERb; 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 S1751494AbeBUXxV (ORCPT + 99 others); Wed, 21 Feb 2018 18:53:21 -0500 Received: from mail-qk0-f194.google.com ([209.85.220.194]:44167 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751453AbeBUXxM (ORCPT ); Wed, 21 Feb 2018 18:53:12 -0500 Received: by mail-qk0-f194.google.com with SMTP id v124so4321640qkh.11; Wed, 21 Feb 2018 15:53:12 -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=sra53Tt7ExbQjIXtI+GCBSRazE+x5zx5SXrD7qrQQ44=; b=I3KciERbOm9xyPijecwnyWZ1iM6C1cfzq7s2rBtSVlpLcYDIKoHizzV4vKWhkMW10J UeNCQ1JK7bu9eNNWfsNig+4ya/hRSkdzWZSXQQW5vU9d1UPtYc6tiTmdhJoq5fnWNuVL hI0yhGSZSoO/ZPKKEPoVAuqsBrycvo+rKDjuBploBxCdNNNe3GctuIaEZ0Dcr2qpliw/ Pxjn+JcYKtrEKO1l3GlOxGXRk4TjASyIf1HZ0AnQKe77OuinQl3beqk8B3Ybua5I6UI1 q+hGrR3uCo7D4nwDR6cQ6FuCxZvST3jJCbzGjM1Rs20oxvp2Npx28p0iSVuthfG+s2OB G0bA== 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=sra53Tt7ExbQjIXtI+GCBSRazE+x5zx5SXrD7qrQQ44=; b=cx64iq0uZbABkRPXLoWmI0hpo1+CSx155cf04I5d4JU9ibz1EHZkxgfcFfsRnzhKcD PctH230SxiIB2wPGHro91hXeThDk5hln2zmcSZxzySBJDVF4NbN0SK5aIpgtDKuK14yF oxJDgt6w+gNLmAJN/IoExnS0MDFEfXXKL81qykafYcAC6jBFX4EZa8mxeQinnK36xqGk dMHIGByB3KVlsvlbFoz/Jv6OE9zPz4gxgH9BxYNYt9pJILPHOzTiFUyG+CK7x9HnkbDd ItTnndptYobbewxmkxVZ48SyksKdmaR/Zx+49NKGa+dW4f+T0sgP8oo6emi6qN+2t+Kb wLUg== X-Gm-Message-State: APf1xPDcNX8Ss08NWxI5eZ3s47zLF7DDbUdmFLcLpq+PzG+DDVoc4VhU GmQ+51KPDfiR2QWq/WU3TOs= X-Received: by 10.55.19.232 with SMTP id 101mr8005831qkt.198.1519257191860; Wed, 21 Feb 2018 15:53:11 -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 b25sm3804881qte.40.2018.02.21.15.53.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 15:53:11 -0800 (PST) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org Cc: linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@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, corbet@lwn.net, arnd@arndb.de, fweimer@redhat.com, msuchanek@suse.com Subject: [PATCH v12 3/3] mm, x86, powerpc: display pkey in smaps only if arch supports pkeys Date: Wed, 21 Feb 2018 15:52:18 -0800 Message-Id: <1519257138-23797-4-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1519257138-23797-1-git-send-email-linuxram@us.ibm.com> References: <1519257138-23797-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 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: Dave Hansen cc: Michael Ellermen cc: Benjamin Herrenschmidt cc: Andrew Morton 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 c931b88..134f3a0 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -294,11 +294,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 1ae67e9..d0539e3 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -1314,11 +1314,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) { } -- 1.7.1