diff mbox series

mm/vma: Append unlikely() while testing VMA access permissions

Message ID 1582525304-32113-1-git-send-email-anshuman.khandual@arm.com (mailing list archive)
State Mainlined
Commit 5093c5872be3a041917828b2b53e9f981d754768
Headers show
Series mm/vma: Append unlikely() while testing VMA access permissions | expand

Commit Message

Anshuman Khandual Feb. 24, 2020, 6:21 a.m. UTC
It is unlikely that an inaccessible VMA without required permission flags
will get a page fault. Hence lets just append unlikely() directive to such
checks in order to improve performance while also standardizing it across
various platforms.

Cc: Guo Ren <guoren@kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paul Burton <paulburton@kernel.org>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-m68k@lists.linux-m68k.org
Cc: linux-mips@vger.kernel.org
Cc: linux-csky@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
This patch applies on v5.6-rc3 along with the recent VMA series V2
(https://patchwork.kernel.org/cover/11399319/). This has only been
build tested for mips and m68k platforms.

 arch/csky/mm/fault.c | 2 +-
 arch/m68k/mm/fault.c | 2 +-
 arch/mips/mm/fault.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

Comments

Geert Uytterhoeven Feb. 24, 2020, 10:09 a.m. UTC | #1
Hi Anshuman,

Thanks for your patch!

On Mon, Feb 24, 2020 at 7:22 AM Anshuman Khandual
<anshuman.khandual@arm.com> wrote:
> It is unlikely that an inaccessible VMA without required permission flags
> will get a page fault. Hence lets just append unlikely() directive to such

Why? Isn't it the idea that you get a page fault when the page is not
accessible?

> checks in order to improve performance while also standardizing it across
> various platforms.

Does it make a difference to add these? Have you benchmarked this?
https://lwn.net/Articles/420019/

Gr{oetje,eeting}s,

                        Geert


--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@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
Anshuman Khandual Feb. 24, 2020, 1:19 p.m. UTC | #2
On 02/24/2020 03:39 PM, Geert Uytterhoeven wrote:
> Hi Anshuman,
> 
> Thanks for your patch!
> 
> On Mon, Feb 24, 2020 at 7:22 AM Anshuman Khandual
> <anshuman.khandual@arm.com> wrote:
>> It is unlikely that an inaccessible VMA without required permission flags
>> will get a page fault. Hence lets just append unlikely() directive to such
> 
> Why? Isn't it the idea that you get a page fault when the page is not
> accessible?

Yeah it is. But the point here is to have a directive indicating that it is
unlikely that such scenarios will exist frequently even though they are very
much possible.

> 
>> checks in order to improve performance while also standardizing it across
>> various platforms.
> 
> Does it make a difference to add these? Have you benchmarked this?
> https://lwn.net/Articles/420019/

I dont have access to these platforms. As I had noted down previously, this
was only build tested. The primary motivation was that the likeliness or
rather unlikeliness for page faults on inaccessible VMAs are more workload
specific. Hence should not be platform dependent and this change was just
trying to make it similar in some platforms.

> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@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
>
diff mbox series

Patch

diff --git a/arch/csky/mm/fault.c b/arch/csky/mm/fault.c
index 4b3511b8298d..01caae98c350 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_is_accessible(vma))
+		if (unlikely(!vma_is_accessible(vma)))
 			goto bad_area;
 	}
 
diff --git a/arch/m68k/mm/fault.c b/arch/m68k/mm/fault.c
index d5131ec5d923..d5dd75ed77f1 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_is_accessible(vma))
+			if (unlikely(!vma_is_accessible(vma)))
 				goto acc_err;
 	}
 
diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
index 5b9f947bfa32..db4b51a40c58 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_is_accessible(vma))
+			if (unlikely(!vma_is_accessible(vma)))
 				goto bad_area;
 		}
 	}