Re: [PATCH 2/5] mm/vma: Make vma_is_accessible() available for general use

2020-02-17 Thread Guo Ren
csky:

Acked-by: Guo Ren 


On Mon, Feb 17, 2020 at 1:04 PM Anshuman Khandual
 wrote:
>
> Lets move vma_is_accessible() helper to include/linux/mm.h which makes it
> available for general use. While here, this replaces all remaining open
> encodings for VMA access check with vma_is_accessible().
>
> Cc: Guo Ren 
> Cc: Geert Uytterhoeven  Cc: Ralf Baechle 
> Cc: Paul Burton 
> Cc: Benjamin Herrenschmidt 
> Cc: Paul Mackerras 
> Cc: Michael Ellerman 
> Cc: Yoshinori Sato 
> Cc: Rich Felker 
> Cc: Dave Hansen 
> Cc: Andy Lutomirski 
> Cc: Peter Zijlstra 
> Cc: Thomas Gleixner 
> Cc: Ingo Molnar 
> Cc: Andrew Morton 
> Cc: Steven Rostedt 
> Cc: Mel Gorman 
> Cc: linux-ker...@vger.kernel.org
> Cc: linux-m...@lists.linux-m68k.org
> Cc: linux-m...@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux...@vger.kernel.org
> Cc: linux...@kvack.org
> Signed-off-by: Anshuman Khandual 
> ---
>  arch/csky/mm/fault.c| 2 +-
>  arch/m68k/mm/fault.c| 2 +-
>  arch/mips/mm/fault.c| 2 +-
>  arch/powerpc/mm/fault.c | 2 +-
>  arch/sh/mm/fault.c  | 2 +-
>  arch/x86/mm/fault.c | 2 +-
>  include/linux/mm.h  | 5 +
>  kernel/sched/fair.c | 2 +-
>  mm/gup.c| 2 +-
>  mm/memory.c | 5 -
>  mm/mempolicy.c  | 3 +--
>  11 files changed, 14 insertions(+), 15 deletions(-)
>
> diff --git a/arch/csky/mm/fault.c b/arch/csky/mm/fault.c
> index f76618b630f9..4b3511b8298d 100644
> --- a/arch/csky/mm/fault.c
> +++ b/arch/csky/mm/fault.c
> @@ -137,7 +137,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, 
> unsigned long write,
> if (!(vma->vm_flags & VM_WRITE))
> goto bad_area;
> } else {
> -   if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)))
> +   if (!vma_is_accessible(vma))
> goto bad_area;
> }
>
> diff --git a/arch/m68k/mm/fault.c b/arch/m68k/mm/fault.c
> index e9b1d7585b43..d5131ec5d923 100644
> --- a/arch/m68k/mm/fault.c
> +++ b/arch/m68k/mm/fault.c
> @@ -125,7 +125,7 @@ int do_page_fault(struct pt_regs *regs, unsigned long 
> address,
> case 1: /* read, present */
> goto acc_err;
> case 0: /* read, not present */
> -   if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))
> +   if (!vma_is_accessible(vma))
> goto acc_err;
> }
>
> diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
> index 1e8d00793784..5b9f947bfa32 100644
> --- a/arch/mips/mm/fault.c
> +++ b/arch/mips/mm/fault.c
> @@ -142,7 +142,7 @@ static void __kprobes __do_page_fault(struct pt_regs 
> *regs, unsigned long write,
> goto bad_area;
> }
> } else {
> -   if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)))
> +   if (!vma_is_accessible(vma))
> goto bad_area;
> }
> }
> diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
> index 8db0507619e2..71a3658c516b 100644
> --- a/arch/powerpc/mm/fault.c
> +++ b/arch/powerpc/mm/fault.c
> @@ -314,7 +314,7 @@ static bool access_error(bool is_write, bool is_exec,
> return false;
> }
>
> -   if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE
> +   if (unlikely(!vma_is_accessible(vma)))
> return true;
> /*
>  * We should ideally do the vma pkey access check here. But in the
> diff --git a/arch/sh/mm/fault.c b/arch/sh/mm/fault.c
> index 5f51456f4fc7..a8c4253f37d7 100644
> --- a/arch/sh/mm/fault.c
> +++ b/arch/sh/mm/fault.c
> @@ -355,7 +355,7 @@ static inline int access_error(int error_code, struct 
> vm_area_struct *vma)
> return 1;
>
> /* read, not present: */
> -   if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE
> +   if (unlikely(!vma_is_accessible(vma)))
> return 1;
>
> return 0;
> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
> index fa4ea09593ab..c461eaab0306 100644
> --- a/arch/x86/mm/fault.c
> +++ b/arch/x86/mm/fault.c
> @@ -1200,7 +1200,7 @@ access_error(unsigned long error_code, struct 
> vm_area_struct *vma)
> return 1;
>
> /* read, not present: */
> -   if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE
> +   if (unlikely(!vma_is_accessible(vma)))
> return 1;
>
> return 0;
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 52269e56c514..b0e53ef13ff1 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -541,6 +541,11 @@ static inline bool vma_is_anonymous(struct 
> vm_area_struct *vma)
> return !vma->vm_ops;
>  }
>
> +static inline bool vma_is_accessible(struct vm_area_struct *vma)
> +{
> +   return vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC);

Re: [PATCH 2/5] mm/vma: Make vma_is_accessible() available for general use

2020-02-17 Thread Anshuman Khandual


On 02/17/2020 10:33 AM, Anshuman Khandual wrote:
> Lets move vma_is_accessible() helper to include/linux/mm.h which makes it
> available for general use. While here, this replaces all remaining open
> encodings for VMA access check with vma_is_accessible().
> 
> Cc: Guo Ren 
> Cc: Geert Uytterhoeven  Cc: Ralf Baechle 
> Cc: Paul Burton 
> Cc: Benjamin Herrenschmidt 
> Cc: Paul Mackerras 
> Cc: Michael Ellerman 
> Cc: Yoshinori Sato 
> Cc: Rich Felker 
> Cc: Dave Hansen 
> Cc: Andy Lutomirski 
> Cc: Peter Zijlstra 
> Cc: Thomas Gleixner 
> Cc: Ingo Molnar 
> Cc: Andrew Morton 
> Cc: Steven Rostedt 
> Cc: Mel Gorman 
> Cc: linux-ker...@vger.kernel.org
> Cc: linux-m...@lists.linux-m68k.org
> Cc: linux-m...@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux...@vger.kernel.org
> Cc: linux...@kvack.org
> Signed-off-by: Anshuman Khandual 
> ---
>  arch/csky/mm/fault.c| 2 +-
>  arch/m68k/mm/fault.c| 2 +-
>  arch/mips/mm/fault.c| 2 +-
>  arch/powerpc/mm/fault.c | 2 +-
>  arch/sh/mm/fault.c  | 2 +-
>  arch/x86/mm/fault.c | 2 +-
>  include/linux/mm.h  | 5 +
>  kernel/sched/fair.c | 2 +-
>  mm/gup.c| 2 +-
>  mm/memory.c | 5 -
>  mm/mempolicy.c  | 3 +--
>  11 files changed, 14 insertions(+), 15 deletions(-)

There are couple of places in mm/mmap.c which could use vma_is_accessible()
as well. Probably missed them, as the order of the VMA flags were different.
Will fold the following changes next time around.

diff --git a/mm/mmap.c b/mm/mmap.c
index 6756b8bb0033..9b9bb4031fd4 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2338,8 +2338,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned 
long address)
gap_addr = TASK_SIZE;
 
next = vma->vm_next;
-   if (next && next->vm_start < gap_addr &&
-   (next->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) {
+   if (next && next->vm_start < gap_addr && vma_is_accessible(next)) {
if (!(next->vm_flags & VM_GROWSUP))
return -ENOMEM;
/* Check that both stack segments have the same anon_vma? */
@@ -2420,7 +2419,7 @@ int expand_downwards(struct vm_area_struct *vma,
prev = vma->vm_prev;
/* Check that both stack segments have the same anon_vma? */
if (prev && !(prev->vm_flags & VM_GROWSDOWN) &&
-   (prev->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) {
+   vma_is_accessible(prev)) {
if (address - prev->vm_end < stack_guard_gap)
return -ENOMEM;
}


Re: [PATCH 2/5] mm/vma: Make vma_is_accessible() available for general use

2020-02-16 Thread Geert Uytterhoeven
On Mon, Feb 17, 2020 at 6:04 AM Anshuman Khandual
 wrote:
> Lets move vma_is_accessible() helper to include/linux/mm.h which makes it
> available for general use. While here, this replaces all remaining open
> encodings for VMA access check with vma_is_accessible().
>
> Cc: Guo Ren 
> Cc: Geert Uytterhoeven  Cc: Ralf Baechle 
> Cc: Paul Burton 
> Cc: Benjamin Herrenschmidt 
> Cc: Paul Mackerras 
> Cc: Michael Ellerman 
> Cc: Yoshinori Sato 
> Cc: Rich Felker 
> Cc: Dave Hansen 
> Cc: Andy Lutomirski 
> Cc: Peter Zijlstra 
> Cc: Thomas Gleixner 
> Cc: Ingo Molnar 
> Cc: Andrew Morton 
> Cc: Steven Rostedt 
> Cc: Mel Gorman 
> Cc: linux-ker...@vger.kernel.org
> Cc: linux-m...@lists.linux-m68k.org
> Cc: linux-m...@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux...@vger.kernel.org
> Cc: linux...@kvack.org
> Signed-off-by: Anshuman Khandual 

>  arch/m68k/mm/fault.c| 2 +-

For m68k:
Acked-by: Geert Uytterhoeven 

Gr{oetje,eeting}s,

Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


[PATCH 2/5] mm/vma: Make vma_is_accessible() available for general use

2020-02-16 Thread Anshuman Khandual
Lets move vma_is_accessible() helper to include/linux/mm.h which makes it
available for general use. While here, this replaces all remaining open
encodings for VMA access check with vma_is_accessible().

Cc: Guo Ren 
Cc: Geert Uytterhoeven 
Cc: Paul Burton 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: Yoshinori Sato 
Cc: Rich Felker 
Cc: Dave Hansen 
Cc: Andy Lutomirski 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Andrew Morton 
Cc: Steven Rostedt 
Cc: Mel Gorman 
Cc: linux-ker...@vger.kernel.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux...@vger.kernel.org
Cc: linux...@kvack.org
Signed-off-by: Anshuman Khandual 
---
 arch/csky/mm/fault.c| 2 +-
 arch/m68k/mm/fault.c| 2 +-
 arch/mips/mm/fault.c| 2 +-
 arch/powerpc/mm/fault.c | 2 +-
 arch/sh/mm/fault.c  | 2 +-
 arch/x86/mm/fault.c | 2 +-
 include/linux/mm.h  | 5 +
 kernel/sched/fair.c | 2 +-
 mm/gup.c| 2 +-
 mm/memory.c | 5 -
 mm/mempolicy.c  | 3 +--
 11 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/arch/csky/mm/fault.c b/arch/csky/mm/fault.c
index f76618b630f9..4b3511b8298d 100644
--- a/arch/csky/mm/fault.c
+++ b/arch/csky/mm/fault.c
@@ -137,7 +137,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, 
unsigned long write,
if (!(vma->vm_flags & VM_WRITE))
goto bad_area;
} else {
-   if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)))
+   if (!vma_is_accessible(vma))
goto bad_area;
}
 
diff --git a/arch/m68k/mm/fault.c b/arch/m68k/mm/fault.c
index e9b1d7585b43..d5131ec5d923 100644
--- a/arch/m68k/mm/fault.c
+++ b/arch/m68k/mm/fault.c
@@ -125,7 +125,7 @@ int do_page_fault(struct pt_regs *regs, unsigned long 
address,
case 1: /* read, present */
goto acc_err;
case 0: /* read, not present */
-   if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))
+   if (!vma_is_accessible(vma))
goto acc_err;
}
 
diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
index 1e8d00793784..5b9f947bfa32 100644
--- a/arch/mips/mm/fault.c
+++ b/arch/mips/mm/fault.c
@@ -142,7 +142,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, 
unsigned long write,
goto bad_area;
}
} else {
-   if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)))
+   if (!vma_is_accessible(vma))
goto bad_area;
}
}
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 8db0507619e2..71a3658c516b 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -314,7 +314,7 @@ static bool access_error(bool is_write, bool is_exec,
return false;
}
 
-   if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE
+   if (unlikely(!vma_is_accessible(vma)))
return true;
/*
 * We should ideally do the vma pkey access check here. But in the
diff --git a/arch/sh/mm/fault.c b/arch/sh/mm/fault.c
index 5f51456f4fc7..a8c4253f37d7 100644
--- a/arch/sh/mm/fault.c
+++ b/arch/sh/mm/fault.c
@@ -355,7 +355,7 @@ static inline int access_error(int error_code, struct 
vm_area_struct *vma)
return 1;
 
/* read, not present: */
-   if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE
+   if (unlikely(!vma_is_accessible(vma)))
return 1;
 
return 0;
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index fa4ea09593ab..c461eaab0306 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -1200,7 +1200,7 @@ access_error(unsigned long error_code, struct 
vm_area_struct *vma)
return 1;
 
/* read, not present: */
-   if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE
+   if (unlikely(!vma_is_accessible(vma)))
return 1;
 
return 0;
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 52269e56c514..b0e53ef13ff1 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -541,6 +541,11 @@ static inline bool vma_is_anonymous(struct vm_area_struct 
*vma)
return !vma->vm_ops;
 }
 
+static inline bool vma_is_accessible(struct vm_area_struct *vma)
+{
+   return vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC);
+}
+
 #ifdef CONFIG_SHMEM
 /*
  * The vma_is_shmem is not inline because it is used only by slow
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index fe4e0d775375..6ce54d57dd09 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2573,7 +2573,7 @@ static void task_numa_work(struct callback_head *work)
 * Skip inaccessible