Received: by 10.192.165.148 with SMTP id m20csp551099imm; Fri, 4 May 2018 15:00:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqyaJDgvuOPC0RiF1ygLL08dHxx6wYKtUJ1oANk9AX+HheQlPCcMIhlhq+UlomuxnCpnTlE X-Received: by 2002:a17:902:b184:: with SMTP id s4-v6mr21628559plr.359.1525471258069; Fri, 04 May 2018 15:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525471258; cv=none; d=google.com; s=arc-20160816; b=hqhEM6vT3sbPvd0FPG9NTlToL2TCxR7PKgWeeAUF5EhDwaHXX8Nl16XYKpCOMQrv9M P3SVzSAos3lYC2CqHHXgMoZa9DY+Vbt4PXZupyxGKEceKrPX0BLp7nVj2P3Gaz27937T eIuAckZkvBkCJIsbFpnZaRNcTUz9nH8J+LOXyzOdH2MZK/iqVTuDFk5zfFKitTJYx6EY 1d7o1n0ASkdEjfKggZujspbjgQ4XqXvxo26FfCy+S4B5nByBf0L8asDE7b2Pp0ld73FO pVO0KXgSIf7WpgPvfEv3OcKLkWFY4WDgBg6AAR77FrQ5SZODgHPRqMJOpNVSvrCWN2KL Maeg== 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=Ix7sXncWUTRFspCSYF42h51gvujyIEcCgpieUhOVwPY=; b=ArCJJMt0tLj5/s+X1Eg6VuN5bzD+LM0igJ8wXNWuy4jHNXunW1pJzZtQAdM31dXFor G8tPmeeUBYe8uYthaYn0wh/iuT7Z+l/KywqQ3ovZFmCTQANHGLX2Zz2LAXzSD9v0BXma x0l0eSMBnMvMUSlLKYOmGBKMdPOPajOvUVc/X1C50/jsxevkH/aONJ8Fa9EoPXTem6+h cxaL+xZPkRq3ybFF5U99XF5v/RAVw70zj4Ab9+Uqb+1gDf8b8gKxBbBuSbR6PWfT/BdG FvSGD58Im+i6xVeNm6i5wmPZbWdViuhFfPZeEXn6MZpk11wYmwNqZc6WuspRlr4K58vC ZvxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=vIwxuqwE; 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 31-v6si16804281plk.191.2018.05.04.15.00.43; Fri, 04 May 2018 15:00:58 -0700 (PDT) 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=vIwxuqwE; 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 S1751894AbeEDWA3 (ORCPT + 99 others); Fri, 4 May 2018 18:00:29 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:46200 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751841AbeEDWAO (ORCPT ); Fri, 4 May 2018 18:00:14 -0400 Received: by mail-qk0-f195.google.com with SMTP id s70so17800934qks.13; Fri, 04 May 2018 15:00:14 -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=Ix7sXncWUTRFspCSYF42h51gvujyIEcCgpieUhOVwPY=; b=vIwxuqwEqsMP3Bqyj3kCJXySe94iZPYnbDJx/NZYUA0YT/z/6eUJR1h1Q9cq+/vhd2 nDgBlHBMuneTTd+JvLDyXKglGPhuOEmWqGkQNz3iuHfCvQxf4Po1tLUCqOrmAgQTi6F9 tgib3RBkrDrl+bTejqpRtEz54IA8TDYou96BtIkRRsIrdKPWN0Wh4Hu0Fgj7AzxlKMGw 3zCIs+nVK8UvNMwFUE+Ble6gFANfihXi0G631Umd47OQksIXV788d/owJScQ3UZ9Ereo pZv4wVjBxwgEYYBHzw8UOcnjgw380JgIBW0S5hAx+zHnSnU0DzpJJLEgaURqQtt5lVMs 4enA== 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=Ix7sXncWUTRFspCSYF42h51gvujyIEcCgpieUhOVwPY=; b=JE+SzS+9jFpbc/TzsuFkABLRpbzTZxbJ8WrJyPqvkzyoSL5JyjDT4lx/QzqBAkUVfs eYNE3bPQcBToGIe8Ymr2DsMg11GxwR/1Ut7yWEZ4asESMdyT+s2sgQDRXHWmWOyYO65T 85WQLFan6wq+XQd45Ht7LUEQpmQmlkDf8BUSMYCTeaez7a/SPVVHDWJHcbOs+kYojVz1 3/Dp7l9XpKTpkWZ2YBADf3EcjnMIVUeKi4H0fSLSbOBKsyK+HmMmihbb00ZtNdbbhrrI F9XG4IVkdD9lqw9iakhlzHvmM1vy4mW8bPFebDNL0KVZjIwi9mJnolsoZ3ggJ/UdWpXg epfA== X-Gm-Message-State: ALQs6tD8KpUHdWVKliiSOesZkPT+Kgx8FoVMVAqFJYcZyitDCAPaZORc 1qjggjCWm1+HvbMficinRec= X-Received: by 10.55.221.71 with SMTP id n68mr23500665qki.395.1525471213731; Fri, 04 May 2018 15:00:13 -0700 (PDT) Received: from localhost.localdomain ([170.225.9.142]) by smtp.gmail.com with ESMTPSA id i45-v6sm15488910qta.12.2018.05.04.15.00.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 May 2018 15:00:13 -0700 (PDT) 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 Subject: [PATCH v11 3/3] mm, x86, powerpc: display pkey in smaps only if arch supports pkeys Date: Fri, 4 May 2018 14:59:43 -0700 Message-Id: <1525471183-21277-4-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1525471183-21277-1-git-send-email-linuxram@us.ibm.com> References: <1525471183-21277-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: 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 | 11 ++++++----- include/linux/pkeys.h | 7 ++++++- 7 files changed, 18 insertions(+), 24 deletions(-) diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h index 1835ca1..896efa5 100644 --- a/arch/powerpc/include/asm/mmu_context.h +++ b/arch/powerpc/include/asm/mmu_context.h @@ -250,11 +250,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 57e3785..3d748bd 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -296,11 +296,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 6285697..960dbab 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -1306,11 +1306,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 3ddddc7..9ce0097 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" #define SEQ_PUT_DEC(str, val) \ @@ -728,12 +730,9 @@ 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) -{ -} - #define SEQ_PUT_DEC(str, val) \ seq_put_decimal_ull_width(m, str, (val) >> 10, 8) + static int show_smap(struct seq_file *m, void *v, int is_pid) { struct proc_maps_private *priv = m->private; @@ -836,9 +835,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid) seq_puts(m, " kB\n"); } 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