From patchwork Fri May 4 21:59:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 909068 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40d5kv4C4rz9s2k for ; Sat, 5 May 2018 08:08:55 +1000 (AEST) 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="vIwxuqwE"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40d5kv2XbVzDrj5 for ; Sat, 5 May 2018 08:08:55 +1000 (AEST) 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="vIwxuqwE"; 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:c09::244; helo=mail-qk0-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="vIwxuqwE"; dkim-atps=neutral Received: from mail-qk0-x244.google.com (mail-qk0-x244.google.com [IPv6:2607:f8b0:400d:c09::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 40d5Xw0z33zDr4K for ; Sat, 5 May 2018 08:00:15 +1000 (AEST) Received: by mail-qk0-x244.google.com with SMTP id p186so17811300qkd.1 for ; Fri, 04 May 2018 15:00:15 -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=V7Zk5H7ifkOMEuT2GI8f7JeiTqbYjoIa7B1JyxhBY227SOLdbRUJ7fBE3urbMVxluu n4hHg5rOKVSrRYpyi1Ls2Xenm2BLpStsobFTQLQnzk9mT7Qd5wjet8OiGl1sHBNkUC1l zvmPEEEchOgDhGi/Yyw6w9jH26C6/QCxNDCBDPVXYAbWioCu5cj7fdTUd37WILQ6M1Kp bSQRCwOstPyew99QQYfp2rG+MyYdZvDMTJ30Kh2aHvJa0dhRnDiXsqVqioyVFFAmVkBg 9YNS/S+10ia5xMqj0ncr+j0orYHUOnMMI2R0EJY53IH3CNjGdbayhnpCj8Ue850BsYya ypOw== X-Gm-Message-State: ALQs6tCsjwY+EGSuhHH5oeGEISGbR8FE9xKBu9E/U5PfWtPnLRZuvdbI 6v3Aj2k0xF8VHiWsR/xcIWM= X-Google-Smtp-Source: AB8JxZqR0c2Wi3pmeMC5jvyWg0/aDVy0hjRRtVibR3RjNwoW3sV3V16cxqW2J1Zjvh7gDHkksmB70A== 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 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> 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, dave.hansen@intel.com, x86@kernel.org, linuxram@us.ibm.com, linux-kernel@vger.kernel.org, mhocko@kernel.org, linux-mm@kvack.org, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, 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 | 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) { }