From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754809AbbIPSA0 (ORCPT ); Wed, 16 Sep 2015 14:00:26 -0400 Received: from mga02.intel.com ([134.134.136.20]:28070 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753641AbbIPRtK (ORCPT ); Wed, 16 Sep 2015 13:49:10 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,540,1437462000"; d="scan'208";a="791065152" Subject: [PATCH 17/26] x86, pkeys: dump PTE pkey in /proc/pid/smaps To: dave@sr71.net Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org From: Dave Hansen Date: Wed, 16 Sep 2015 10:49:08 -0700 References: <20150916174903.E112E464@viggo.jf.intel.com> In-Reply-To: <20150916174903.E112E464@viggo.jf.intel.com> Message-Id: <20150916174908.3A2FA837@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The protection key can now be just as important as read/write permissions on a VMA. We need some debug mechanism to help figure out if it is in play. smaps seems like a logical place to expose it. arch/x86/kernel/setup.c is a bit of a weirdo place to put this code, but it already had seq_file.h and there was not a much better existing place to put it. We also use no #ifdef. If protection keys is .config'd out we will get the same function as if we used the weak generic function. --- b/arch/x86/kernel/setup.c | 9 +++++++++ b/fs/proc/task_mmu.c | 5 +++++ 2 files changed, 14 insertions(+) diff -puN arch/x86/kernel/setup.c~pkeys-40-smaps arch/x86/kernel/setup.c --- a/arch/x86/kernel/setup.c~pkeys-40-smaps 2015-09-16 10:48:18.838309381 -0700 +++ b/arch/x86/kernel/setup.c 2015-09-16 10:48:18.844309653 -0700 @@ -111,6 +111,7 @@ #include #include #include +#include /* * max_low_pfn_mapped: highest direct mapped pfn under 4GB @@ -1264,3 +1265,11 @@ static int __init register_kernel_offset 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 -puN fs/proc/task_mmu.c~pkeys-40-smaps fs/proc/task_mmu.c --- a/fs/proc/task_mmu.c~pkeys-40-smaps 2015-09-16 10:48:18.840309472 -0700 +++ b/fs/proc/task_mmu.c 2015-09-16 10:48:18.844309653 -0700 @@ -625,6 +625,10 @@ static void show_smap_vma_flags(struct s seq_putc(m, '\n'); } +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 vm_area_struct *vma = v; @@ -674,6 +678,7 @@ static int show_smap(struct seq_file *m, (vma->vm_flags & VM_LOCKED) ? (unsigned long)(mss.pss >> (10 + PSS_SHIFT)) : 0); + arch_show_smap(m, vma); show_smap_vma_flags(m, vma); m_cache_vma(m, vma); return 0; _