linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] mm/vma: some more minor changes
@ 2020-02-26  4:50 Anshuman Khandual
  2020-02-26  4:50 ` [PATCH 1/3] mm/vma: Move VM_NO_KHUGEPAGED into generic header Anshuman Khandual
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Anshuman Khandual @ 2020-02-26  4:50 UTC (permalink / raw)
  To: linux-mm
  Cc: Anshuman Khandual, Paul Mackerras, Michael Ellerman,
	Thomas Gleixner, Ingo Molnar, Andrew Morton, x86, linuxppc-dev,
	linux-kernel

The motivation here is to consolidate VMA flags and helpers in generic
memory header and reduce code duplication when ever applicable. If there
are other possible similar instances which might be missing here, please
do let me me know. I will be happy to incorporate them.

This series is based on v5.6-rc3. This series has been build tested on
multiple platforms but boot tested only on arm64 and x86.

Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: x86@kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org

Anshuman Khandual (3):
  mm/vma: Move VM_NO_KHUGEPAGED into generic header
  mm/vma: Make vma_is_foreign() available for general use
  mm/vma: Make is_vma_temporary_stack() available for general use

 arch/powerpc/mm/book3s64/pkeys.c   | 12 ------------
 arch/x86/include/asm/mmu_context.h | 15 ---------------
 include/linux/huge_mm.h            |  2 --
 include/linux/mm.h                 | 28 +++++++++++++++++++++++++++-
 mm/khugepaged.c                    |  2 --
 mm/rmap.c                          | 14 --------------
 6 files changed, 27 insertions(+), 46 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] mm/vma: Move VM_NO_KHUGEPAGED into generic header
  2020-02-26  4:50 [PATCH 0/3] mm/vma: some more minor changes Anshuman Khandual
@ 2020-02-26  4:50 ` Anshuman Khandual
  2020-02-26 11:34   ` Vlastimil Babka
  2020-02-26  4:50 ` [PATCH 2/3] mm/vma: Make vma_is_foreign() available for general use Anshuman Khandual
  2020-02-26  4:50 ` [PATCH 3/3] mm/vma: Make is_vma_temporary_stack() " Anshuman Khandual
  2 siblings, 1 reply; 9+ messages in thread
From: Anshuman Khandual @ 2020-02-26  4:50 UTC (permalink / raw)
  To: linux-mm; +Cc: Anshuman Khandual, Andrew Morton, linux-kernel

Move VM_NO_KHUGEPAGED into generic header (include/linux/mm.h). This just
makes sure that no VMA flag is scattered in individual function files any
longer. While at this, fix an old comment which is no longer valid.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 include/linux/mm.h | 3 ++-
 mm/khugepaged.c    | 2 --
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 52269e56c514..6f7e400e6ea3 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -287,6 +287,8 @@ extern unsigned int kobjsize(const void *objp);
 #define VM_NOHUGEPAGE	0x40000000	/* MADV_NOHUGEPAGE marked this vma */
 #define VM_MERGEABLE	0x80000000	/* KSM may merge identical pages */
 
+#define VM_NO_KHUGEPAGED (VM_SPECIAL | VM_HUGETLB)
+
 #ifdef CONFIG_ARCH_USES_HIGH_VMA_FLAGS
 #define VM_HIGH_ARCH_BIT_0	32	/* bit only usable on 64-bit architectures */
 #define VM_HIGH_ARCH_BIT_1	33	/* bit only usable on 64-bit architectures */
@@ -356,7 +358,6 @@ extern unsigned int kobjsize(const void *objp);
 
 /*
  * Special vmas that are non-mergable, non-mlock()able.
- * Note: mm/huge_memory.c VM_NO_THP depends on this definition.
  */
 #define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP)
 
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index b679908743cb..494443628850 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -308,8 +308,6 @@ struct attribute_group khugepaged_attr_group = {
 };
 #endif /* CONFIG_SYSFS */
 
-#define VM_NO_KHUGEPAGED (VM_SPECIAL | VM_HUGETLB)
-
 int hugepage_madvise(struct vm_area_struct *vma,
 		     unsigned long *vm_flags, int advice)
 {
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] mm/vma: Make vma_is_foreign() available for general use
  2020-02-26  4:50 [PATCH 0/3] mm/vma: some more minor changes Anshuman Khandual
  2020-02-26  4:50 ` [PATCH 1/3] mm/vma: Move VM_NO_KHUGEPAGED into generic header Anshuman Khandual
@ 2020-02-26  4:50 ` Anshuman Khandual
  2020-02-26 13:59   ` Vlastimil Babka
  2020-02-26  4:50 ` [PATCH 3/3] mm/vma: Make is_vma_temporary_stack() " Anshuman Khandual
  2 siblings, 1 reply; 9+ messages in thread
From: Anshuman Khandual @ 2020-02-26  4:50 UTC (permalink / raw)
  To: linux-mm
  Cc: Anshuman Khandual, Paul Mackerras, Michael Ellerman,
	Thomas Gleixner, Ingo Molnar, Andrew Morton, x86, linuxppc-dev,
	linux-kernel

Idea of a foreign VMA with respect to the present context is very generic.
But currently there are two identical definitions for this in powerpc and
x86 platforms. Lets consolidate those redundant definitions while making
vma_is_foreign() available for general use later. This should not cause
any functional change.

Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: x86@kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/powerpc/mm/book3s64/pkeys.c   | 12 ------------
 arch/x86/include/asm/mmu_context.h | 15 ---------------
 include/linux/mm.h                 | 11 +++++++++++
 3 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index 59e0ebbd8036..07527f1ed108 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c
@@ -381,18 +381,6 @@ bool arch_pte_access_permitted(u64 pte, bool write, bool execute)
  * So do not enforce things if the VMA is not from the current mm, or if we are
  * in a kernel thread.
  */
-static inline bool vma_is_foreign(struct vm_area_struct *vma)
-{
-	if (!current->mm)
-		return true;
-
-	/* if it is not our ->mm, it has to be foreign */
-	if (current->mm != vma->vm_mm)
-		return true;
-
-	return false;
-}
-
 bool arch_vma_access_permitted(struct vm_area_struct *vma, bool write,
 			       bool execute, bool foreign)
 {
diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
index b538d9ddee9c..4e55370e48e8 100644
--- a/arch/x86/include/asm/mmu_context.h
+++ b/arch/x86/include/asm/mmu_context.h
@@ -213,21 +213,6 @@ static inline void arch_unmap(struct mm_struct *mm, unsigned long start,
  * So do not enforce things if the VMA is not from the current
  * mm, or if we are in a kernel thread.
  */
-static inline bool vma_is_foreign(struct vm_area_struct *vma)
-{
-	if (!current->mm)
-		return true;
-	/*
-	 * Should PKRU be enforced on the access to this VMA?  If
-	 * the VMA is from another process, then PKRU has no
-	 * relevance and should not be enforced.
-	 */
-	if (current->mm != vma->vm_mm)
-		return true;
-
-	return false;
-}
-
 static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
 		bool write, bool execute, bool foreign)
 {
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 6f7e400e6ea3..2fd4b9bec4be 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -27,6 +27,7 @@
 #include <linux/memremap.h>
 #include <linux/overflow.h>
 #include <linux/sizes.h>
+#include <linux/sched.h>
 
 struct mempolicy;
 struct anon_vma;
@@ -542,6 +543,16 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma)
 	return !vma->vm_ops;
 }
 
+static inline bool vma_is_foreign(struct vm_area_struct *vma)
+{
+	if (!current->mm)
+		return true;
+
+	if (current->mm != vma->vm_mm)
+		return true;
+
+	return false;
+}
 #ifdef CONFIG_SHMEM
 /*
  * The vma_is_shmem is not inline because it is used only by slow
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] mm/vma: Make is_vma_temporary_stack() available for general use
  2020-02-26  4:50 [PATCH 0/3] mm/vma: some more minor changes Anshuman Khandual
  2020-02-26  4:50 ` [PATCH 1/3] mm/vma: Move VM_NO_KHUGEPAGED into generic header Anshuman Khandual
  2020-02-26  4:50 ` [PATCH 2/3] mm/vma: Make vma_is_foreign() available for general use Anshuman Khandual
@ 2020-02-26  4:50 ` Anshuman Khandual
  2020-02-26 14:03   ` Vlastimil Babka
  2 siblings, 1 reply; 9+ messages in thread
From: Anshuman Khandual @ 2020-02-26  4:50 UTC (permalink / raw)
  To: linux-mm; +Cc: Anshuman Khandual, Andrew Morton, linux-kernel

Currently the declaration and definition for is_vma_temporary_stack() are
scattered. Lets make is_vma_temporary_stack() helper available for general
use and also drop the declaration from (include/linux/huge_mm.h) which is
no longer required. This should not cause any functional change.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 include/linux/huge_mm.h |  2 --
 include/linux/mm.h      | 14 ++++++++++++++
 mm/rmap.c               | 14 --------------
 3 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 5aca3d1bdb32..87f46b11efe8 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -87,8 +87,6 @@ extern struct kobj_attribute shmem_enabled_attr;
 #define HPAGE_PUD_SIZE	((1UL) << HPAGE_PUD_SHIFT)
 #define HPAGE_PUD_MASK	(~(HPAGE_PUD_SIZE - 1))
 
-extern bool is_vma_temporary_stack(struct vm_area_struct *vma);
-
 extern unsigned long transparent_hugepage_flags;
 
 /*
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 2fd4b9bec4be..3bbd9c06171b 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -543,6 +543,20 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma)
 	return !vma->vm_ops;
 }
 
+static inline bool is_vma_temporary_stack(struct vm_area_struct *vma)
+{
+	int maybe_stack = vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP);
+
+	if (!maybe_stack)
+		return false;
+
+	if ((vma->vm_flags & VM_STACK_INCOMPLETE_SETUP) ==
+						VM_STACK_INCOMPLETE_SETUP)
+		return true;
+
+	return false;
+}
+
 static inline bool vma_is_foreign(struct vm_area_struct *vma)
 {
 	if (!current->mm)
diff --git a/mm/rmap.c b/mm/rmap.c
index b3e381919835..3d9d5e372710 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1696,20 +1696,6 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
 	return ret;
 }
 
-bool is_vma_temporary_stack(struct vm_area_struct *vma)
-{
-	int maybe_stack = vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP);
-
-	if (!maybe_stack)
-		return false;
-
-	if ((vma->vm_flags & VM_STACK_INCOMPLETE_SETUP) ==
-						VM_STACK_INCOMPLETE_SETUP)
-		return true;
-
-	return false;
-}
-
 static bool invalid_migration_vma(struct vm_area_struct *vma, void *arg)
 {
 	return is_vma_temporary_stack(vma);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] mm/vma: Move VM_NO_KHUGEPAGED into generic header
  2020-02-26  4:50 ` [PATCH 1/3] mm/vma: Move VM_NO_KHUGEPAGED into generic header Anshuman Khandual
@ 2020-02-26 11:34   ` Vlastimil Babka
  2020-02-27  0:06     ` Anshuman Khandual
  0 siblings, 1 reply; 9+ messages in thread
From: Vlastimil Babka @ 2020-02-26 11:34 UTC (permalink / raw)
  To: Anshuman Khandual, linux-mm; +Cc: Andrew Morton, linux-kernel

On 2/26/20 5:50 AM, Anshuman Khandual wrote:
> Move VM_NO_KHUGEPAGED into generic header (include/linux/mm.h). This just
> makes sure that no VMA flag is scattered in individual function files any
> longer. While at this, fix an old comment which is no longer valid.
> 
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
>  include/linux/mm.h | 3 ++-
>  mm/khugepaged.c    | 2 --
>  2 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 52269e56c514..6f7e400e6ea3 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -287,6 +287,8 @@ extern unsigned int kobjsize(const void *objp);
>  #define VM_NOHUGEPAGE	0x40000000	/* MADV_NOHUGEPAGE marked this vma */
>  #define VM_MERGEABLE	0x80000000	/* KSM may merge identical pages */
>  
> +#define VM_NO_KHUGEPAGED (VM_SPECIAL | VM_HUGETLB)

While the preprocessor doesn't mind that VM_SPECIAL is only defined later, I
would have moved this below VM_SPECIAL definition anyway, where it fits better,
and add a comment like other defines there do?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] mm/vma: Make vma_is_foreign() available for general use
  2020-02-26  4:50 ` [PATCH 2/3] mm/vma: Make vma_is_foreign() available for general use Anshuman Khandual
@ 2020-02-26 13:59   ` Vlastimil Babka
  0 siblings, 0 replies; 9+ messages in thread
From: Vlastimil Babka @ 2020-02-26 13:59 UTC (permalink / raw)
  To: Anshuman Khandual, linux-mm
  Cc: Paul Mackerras, Michael Ellerman, Thomas Gleixner, Ingo Molnar,
	Andrew Morton, x86, linuxppc-dev, linux-kernel

On 2/26/20 5:50 AM, Anshuman Khandual wrote:
> Idea of a foreign VMA with respect to the present context is very generic.
> But currently there are two identical definitions for this in powerpc and
> x86 platforms. Lets consolidate those redundant definitions while making
> vma_is_foreign() available for general use later. This should not cause
> any functional change.
> 
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: x86@kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-mm@kvack.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>

Some comment for the function wouln't hurt, but perhaps it is self-explanatory
enough.

Acked-by: Vlastimil Babka <vbabka@suse.cz>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] mm/vma: Make is_vma_temporary_stack() available for general use
  2020-02-26  4:50 ` [PATCH 3/3] mm/vma: Make is_vma_temporary_stack() " Anshuman Khandual
@ 2020-02-26 14:03   ` Vlastimil Babka
  2020-02-27  0:08     ` Anshuman Khandual
  0 siblings, 1 reply; 9+ messages in thread
From: Vlastimil Babka @ 2020-02-26 14:03 UTC (permalink / raw)
  To: Anshuman Khandual, linux-mm; +Cc: Andrew Morton, linux-kernel

On 2/26/20 5:50 AM, Anshuman Khandual wrote:
> Currently the declaration and definition for is_vma_temporary_stack() are
> scattered. Lets make is_vma_temporary_stack() helper available for general
> use and also drop the declaration from (include/linux/huge_mm.h) which is
> no longer required. This should not cause any functional change.
> 
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-mm@kvack.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>

The move made it plainly visible that the is_vma_* name differs from all the
other vma_is_* names. So this is a good chance to unify it?

Thanks,
Vlastimil

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] mm/vma: Move VM_NO_KHUGEPAGED into generic header
  2020-02-26 11:34   ` Vlastimil Babka
@ 2020-02-27  0:06     ` Anshuman Khandual
  0 siblings, 0 replies; 9+ messages in thread
From: Anshuman Khandual @ 2020-02-27  0:06 UTC (permalink / raw)
  To: Vlastimil Babka, linux-mm; +Cc: Andrew Morton, linux-kernel



On 02/26/2020 05:04 PM, Vlastimil Babka wrote:
> On 2/26/20 5:50 AM, Anshuman Khandual wrote:
>> Move VM_NO_KHUGEPAGED into generic header (include/linux/mm.h). This just
>> makes sure that no VMA flag is scattered in individual function files any
>> longer. While at this, fix an old comment which is no longer valid.
>>
>> Cc: Andrew Morton <akpm@linux-foundation.org>
>> Cc: linux-mm@kvack.org
>> Cc: linux-kernel@vger.kernel.org
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>> ---
>>  include/linux/mm.h | 3 ++-
>>  mm/khugepaged.c    | 2 --
>>  2 files changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/linux/mm.h b/include/linux/mm.h
>> index 52269e56c514..6f7e400e6ea3 100644
>> --- a/include/linux/mm.h
>> +++ b/include/linux/mm.h
>> @@ -287,6 +287,8 @@ extern unsigned int kobjsize(const void *objp);
>>  #define VM_NOHUGEPAGE	0x40000000	/* MADV_NOHUGEPAGE marked this vma */
>>  #define VM_MERGEABLE	0x80000000	/* KSM may merge identical pages */
>>  
>> +#define VM_NO_KHUGEPAGED (VM_SPECIAL | VM_HUGETLB)
> 
> While the preprocessor doesn't mind that VM_SPECIAL is only defined later, I
> would have moved this below VM_SPECIAL definition anyway, where it fits better,
> and add a comment like other defines there do?

Sure, will do.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] mm/vma: Make is_vma_temporary_stack() available for general use
  2020-02-26 14:03   ` Vlastimil Babka
@ 2020-02-27  0:08     ` Anshuman Khandual
  0 siblings, 0 replies; 9+ messages in thread
From: Anshuman Khandual @ 2020-02-27  0:08 UTC (permalink / raw)
  To: Vlastimil Babka, linux-mm; +Cc: Andrew Morton, linux-kernel



On 02/26/2020 07:33 PM, Vlastimil Babka wrote:
> On 2/26/20 5:50 AM, Anshuman Khandual wrote:
>> Currently the declaration and definition for is_vma_temporary_stack() are
>> scattered. Lets make is_vma_temporary_stack() helper available for general
>> use and also drop the declaration from (include/linux/huge_mm.h) which is
>> no longer required. This should not cause any functional change.
>>
>> Cc: Andrew Morton <akpm@linux-foundation.org>
>> Cc: linux-kernel@vger.kernel.org
>> Cc: linux-mm@kvack.org
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> 
> The move made it plainly visible that the is_vma_* name differs from all the
> other vma_is_* names. So this is a good chance to unify it?

Yes, we can unify it while moving. Will change.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-02-27  0:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26  4:50 [PATCH 0/3] mm/vma: some more minor changes Anshuman Khandual
2020-02-26  4:50 ` [PATCH 1/3] mm/vma: Move VM_NO_KHUGEPAGED into generic header Anshuman Khandual
2020-02-26 11:34   ` Vlastimil Babka
2020-02-27  0:06     ` Anshuman Khandual
2020-02-26  4:50 ` [PATCH 2/3] mm/vma: Make vma_is_foreign() available for general use Anshuman Khandual
2020-02-26 13:59   ` Vlastimil Babka
2020-02-26  4:50 ` [PATCH 3/3] mm/vma: Make is_vma_temporary_stack() " Anshuman Khandual
2020-02-26 14:03   ` Vlastimil Babka
2020-02-27  0:08     ` Anshuman Khandual

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).