Skip to content

Commit c1192f8

Browse files
hansendcIngo Molnar
authored andcommitted
x86/mm/pkeys: Dump pkey from VMA in /proc/pid/smaps
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 effectively get the same function as if we used the weak generic function. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Baoquan He <bhe@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Borislav Petkov <bp@suse.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave Hansen <dave@sr71.net> Cc: Dave Young <dyoung@redhat.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Jerome Marchand <jmarchan@redhat.com> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Joerg Roedel <jroedel@suse.de> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Konstantin Khlebnikov <koct9i@gmail.com> Cc: Laurent Dufour <ldufour@linux.vnet.ibm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mark Salter <msalter@redhat.com> Cc: Mark Williamson <mwilliamson@undo-software.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20160212210227.4F8EB3F8@viggo.jf.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent c0b17b5 commit c1192f8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

arch/x86/kernel/setup.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
#include <asm/alternative.h>
113113
#include <asm/prom.h>
114114
#include <asm/microcode.h>
115+
#include <asm/mmu_context.h>
115116

116117
/*
117118
* max_low_pfn_mapped: highest direct mapped pfn under 4GB
@@ -1282,3 +1283,11 @@ static int __init register_kernel_offset_dumper(void)
12821283
return 0;
12831284
}
12841285
__initcall(register_kernel_offset_dumper);
1286+
1287+
void arch_show_smap(struct seq_file *m, struct vm_area_struct *vma)
1288+
{
1289+
if (!boot_cpu_has(X86_FEATURE_OSPKE))
1290+
return;
1291+
1292+
seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma));
1293+
}

fs/proc/task_mmu.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,20 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
660660
[ilog2(VM_MERGEABLE)] = "mg",
661661
[ilog2(VM_UFFD_MISSING)]= "um",
662662
[ilog2(VM_UFFD_WP)] = "uw",
663+
#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
664+
/* These come out via ProtectionKey: */
665+
[ilog2(VM_PKEY_BIT0)] = "",
666+
[ilog2(VM_PKEY_BIT1)] = "",
667+
[ilog2(VM_PKEY_BIT2)] = "",
668+
[ilog2(VM_PKEY_BIT3)] = "",
669+
#endif
663670
};
664671
size_t i;
665672

666673
seq_puts(m, "VmFlags: ");
667674
for (i = 0; i < BITS_PER_LONG; i++) {
675+
if (!mnemonics[i][0])
676+
continue;
668677
if (vma->vm_flags & (1UL << i)) {
669678
seq_printf(m, "%c%c ",
670679
mnemonics[i][0], mnemonics[i][1]);
@@ -702,6 +711,10 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask,
702711
}
703712
#endif /* HUGETLB_PAGE */
704713

714+
void __weak arch_show_smap(struct seq_file *m, struct vm_area_struct *vma)
715+
{
716+
}
717+
705718
static int show_smap(struct seq_file *m, void *v, int is_pid)
706719
{
707720
struct vm_area_struct *vma = v;
@@ -783,6 +796,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
783796
(vma->vm_flags & VM_LOCKED) ?
784797
(unsigned long)(mss.pss >> (10 + PSS_SHIFT)) : 0);
785798

799+
arch_show_smap(m, vma);
786800
show_smap_vma_flags(m, vma);
787801
m_cache_vma(m, vma);
788802
return 0;

0 commit comments

Comments
 (0)