Received: by 10.223.176.5 with SMTP id f5csp1387444wra; Wed, 31 Jan 2018 05:48:20 -0800 (PST) X-Google-Smtp-Source: AH8x226bGls8UtY7sA124WygtCGcDFgCCGeY3Pb7xthSwYZpNDDBE88p4PC5whrdnT1z6udcfY1d X-Received: by 10.98.214.7 with SMTP id r7mr34061334pfg.213.1517406499987; Wed, 31 Jan 2018 05:48:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517406499; cv=none; d=google.com; s=arc-20160816; b=WwD8h1P0NyTEiHfkwxY6+GHF2zTyUVdVdbYpM+vu3L6EbYvCeLP+OJnjRhtaWWPzvR X5Eky6zIzQ+MG7En0PVBeUv2Z27nrT65BsLdNff0hYK+CJRIC2iPG0AERKFdhEM4wpZY mqcQ68wDFjR0iKwLLz7hWf/26qK2AWQ4sgI8O1JLpAMppRx6/CgrlJaFgpMrxeDpr6VK uV8pOT8BiTOgNd7WoHodBIIsOTLuOT8ULU88UbA3Ix3Eb10wJ38Q1we48cqdrUR54BjH NmTgN383pcUuPkz0A9iKwbpsSIni+spNccFUlUH0RYBlvmreUWPsWF56+bQ/gX6AScB+ w/VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=O915QsInd7Vz+NRXH2x5esrbG6WnQvtIWOblTT4xA3s=; b=xEG0PSTFoHKKHhbLwcq6/LJmtyaRFUJgttIPni5PiXuBVXaiZKnL71BuLEWHt9k/aI QJTyiwCanuW16Bs7fLmER3BMsZKaPUlc69oAseIy4MncjVdsMGof3Gt8bVL1r930rx3L jeni6/GMnsp9J1yfLTZJ/OXX14LrF/IzbBzg0AaEPp7KEdhP8BNVXzns/uNkCaygA3Vk pVlhhcFhYDTS4WposZrbWYG3arUkdWj0uvXwwKOeb5YKQecdP6spUKJKd49/H+4a18gf AxhL55eq0zpRp7xavFDuDdNvSDoKFIOUyZWrLOYgy6gxlAkinuZGhn1JKkgKWvJndMns Trfg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1-v6si1864518plp.568.2018.01.31.05.48.05; Wed, 31 Jan 2018 05:48:19 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753488AbeAaNeZ (ORCPT + 99 others); Wed, 31 Jan 2018 08:34:25 -0500 Received: from mx2.suse.de ([195.135.220.15]:53906 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751581AbeAaNeW (ORCPT ); Wed, 31 Jan 2018 08:34:22 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D88A4ABF3; Wed, 31 Jan 2018 13:34:18 +0000 (UTC) Date: Wed, 31 Jan 2018 14:34:15 +0100 From: Michal Hocko To: Ram Pai Cc: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org, 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, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, corbet@lwn.net, arnd@arndb.de, fweimer@redhat.com, msuchanek@suse.com Subject: Re: [PATCH v11 3/3] mm, x86: display pkey in smaps only if arch supports pkeys Message-ID: <20180131133415.GV21609@dhcp22.suse.cz> References: <1517341452-11924-1-git-send-email-linuxram@us.ibm.com> <1517341452-11924-4-git-send-email-linuxram@us.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1517341452-11924-4-git-send-email-linuxram@us.ibm.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 30-01-18 11:44:12, Ram Pai wrote: > 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. Thanks for reworking this patch. Looks good to me. > Signed-off-by: Ram Pai Acked-by: Michal Hocko > --- > 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 | 9 ++++----- > include/linux/pkeys.h | 6 ++++++ > 5 files changed, 16 insertions(+), 13 deletions(-) > > 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 8af2e8d..ddf945a 100644 > --- a/arch/x86/kernel/setup.c > +++ b/arch/x86/kernel/setup.c > @@ -1326,11 +1326,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 0edd4da..6f9fbde 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -728,10 +729,6 @@ 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) > -{ > -} > - > static int show_smap(struct seq_file *m, void *v, int is_pid) > { > struct proc_maps_private *priv = m->private; > @@ -851,9 +848,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid) > (unsigned long)(mss->pss >> (10 + PSS_SHIFT))); > > 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..dfdc609 100644 > --- a/include/linux/pkeys.h > +++ b/include/linux/pkeys.h > @@ -13,6 +13,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 +36,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 -- Michal Hocko SUSE Labs