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: 10381739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3DE2960159 for ; Fri, 4 May 2018 22:00:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29E3929560 for ; Fri, 4 May 2018 22:00:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 284A2295B3; Fri, 4 May 2018 22:00:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E5DC295A8 for ; Fri, 4 May 2018 22:00:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E5C06B026B; Fri, 4 May 2018 18:00:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8974E6B026C; Fri, 4 May 2018 18:00:15 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 736CF6B026D; Fri, 4 May 2018 18:00:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f198.google.com (mail-qk0-f198.google.com [209.85.220.198]) by kanga.kvack.org (Postfix) with ESMTP id 401266B026B for ; Fri, 4 May 2018 18:00:15 -0400 (EDT) Received: by mail-qk0-f198.google.com with SMTP id c73so16857013qke.2 for ; Fri, 04 May 2018 15:00:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:sender:from:to:cc:subject:date :message-id:in-reply-to:references; bh=Ix7sXncWUTRFspCSYF42h51gvujyIEcCgpieUhOVwPY=; b=C9im18xtjzye6CngblrBJT/IYVhQGAPA2cbgfDvpqwbShbKGidFeGkBs5VbjpdBmQl dP+jNTZuXmPJBjppHF8ZuwhHkmCabRY6lp3nZjI2uh9KWMNMC+mAh3jfFUIozF4+Sr27 u51oWBOO90Cv7FW31Cn0IPbYzFW7Ly0cg7kxLoZhPqXS2CM2xJQiry1IeVNGhvMMFQHQ 6HM34P8M/nH9sSoWnNjhWFveTsUkH/5xBlncAt9FhArYu8z3B2GBKgwYw7KAD5g370gr sEp0JkyyRVycLc2wN5EhC016zhJKu1xE265/XpqX5QfFaL4RsCaZPxYNnceBSSuD9ufp qlsg== X-Gm-Message-State: ALQs6tC1l2tt43Y4AoljCqPgxgMOa+U3ivqjt/a2dA9AgpvVU651uDmN WdLXoOPygJgxT57Ol7mz/lThRro/0nBm3H2zaq5vwfSpWNZVVGPzcctzXAMegr4nOJA+EVg0FBb zxPiI5yaAyGoChjqvYu77g0cE+cxASGCtzSc903uXnmgALMMHPgn9KjAGbYk8ItexrlmfnP0vCJ yrFnLQ3M1q2qgTUxJ7tNaAVHQgMypZ8aMwmTF9gadK6+is5sv6GNGxjZ51+CapZT47nR26UOQiq Z6zLixNodl8X+x1/BIxfC+6pRUutRAZhQOTKPtjbg5khLHPsuUTJ0zioCmJ/BXEYlqZg1xqh/9J ge19M8gyuW5yr5pJDqKTl5u9We52Iz+R37cBvUNjejX4eu83qlEzxFqz3+P0hL27+KohaA1CeA= = X-Received: by 2002:ac8:3b49:: with SMTP id r9-v6mr7669463qtf.368.1525471214981; Fri, 04 May 2018 15:00:14 -0700 (PDT) X-Received: by 2002:ac8:3b49:: with SMTP id r9-v6mr7669399qtf.368.1525471214065; Fri, 04 May 2018 15:00:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525471214; cv=none; d=google.com; s=arc-20160816; b=MeuuUD25fHW7WdGtwRh4vYfhgEDplbsxCCYD+7NXA4WRfuVxgHnAJ/q1c1bODb5I0k 5U4GdUq0sDjWzLJattTaApeNmfxd2s3k29WWRB+uXunRbyr5MEkO8JZ7pjqxBKjRZQdJ 4GmtqfiJ11GdQL3LTZ1mTRSHEfvRXlvgGOmEIFQE3d5+vvIc9E3VqHGUJ+OrrjPaVbfv F0JrPPijh0sKyN9pT0iTorybX3euEPKit/KGX0wUVXDUXYqkfbUc69fqQ3PBCLB28DSM c4qD1AVE8kKzGsVxhUyEdUGNIbXEpqRM2YmK6QGkWbOOPhxpb72OGjMn8307kR36iZSO A1CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature:arc-authentication-results; bh=Ix7sXncWUTRFspCSYF42h51gvujyIEcCgpieUhOVwPY=; b=i06wSQwoMyqy2eqTOvrzJu6Unb8dsrL2vxMOUB5en+ZnkzfzBYiMd8DS7NcWkqRZaS 55AFWUPCWrxzStH99Yyiu0en6wsRKca7JJSlHl0m5n8oladYGXbiJMt+CAR/du225EGK lr3/KfH9PkcuOQMzPr0thNmxtUA1epLvLDeIs4MhcoBhvLtG4C+QKdtS4ozcilPmw1w4 fUXnpNG52SWZ/L9K/fvOE8DlPksBgxU2mvhVe29lbV9/qJD0pfKkHuslOupvRl6pUAhB u12MtyR6tkbnLYXeizDM0jddmhWRhtvE1D2Angb+ePNCTAWSi1vk7Fts5cRpYZKCasJ6 3o1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vIwxuqwE; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id g8sor5055124qka.33.2018.05.04.15.00.13 for (Google Transport Security); Fri, 04 May 2018 15:00:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vIwxuqwE; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com 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-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 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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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) { }