lkml.org 
[lkml]   [2014]   [Jul]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH] mm: fix faulting range in do_fault_around
From
Date
From: Konstantin Khlebnikov <koct9i@gmail.com>

do_fault_around shoudn't cross pmd boundaries.

This patch does calculation in terms of addresses rather than pgoff.
It looks much cleaner in this way. Probably it's worth to replace
vmf->max_pgoff with vmf->end_address as well.

Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Reported-by: "Ingo Korb" <ingo.korb@tu-dortmund.de>
---
mm/memory.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index d67fd9f..f27638a 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2831,33 +2831,29 @@ late_initcall(fault_around_debugfs);
static void do_fault_around(struct vm_area_struct *vma, unsigned long address,
pte_t *pte, pgoff_t pgoff, unsigned int flags)
{
- unsigned long start_addr;
+ unsigned long start_addr, end_addr;
pgoff_t max_pgoff;
struct vm_fault vmf;
int off;

- start_addr = max(address & fault_around_mask(), vma->vm_start);
- off = ((address - start_addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
+ start_addr = max3(vma->vm_start, address & PMD_MASK,
+ address & fault_around_mask());
+
+ end_addr = min3(vma->vm_end, ALIGN(address, PMD_SIZE),
+ start_addr + PAGE_ALIGN(fault_around_bytes));
+
+ off = (address - start_addr) >> PAGE_SHIFT;
pte -= off;
pgoff -= off;
-
- /*
- * max_pgoff is either end of page table or end of vma
- * or fault_around_pages() from pgoff, depending what is nearest.
- */
- max_pgoff = pgoff - ((start_addr >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) +
- PTRS_PER_PTE - 1;
- max_pgoff = min3(max_pgoff, vma_pages(vma) + vma->vm_pgoff - 1,
- pgoff + fault_around_pages() - 1);
+ max_pgoff = pgoff + ((end_addr - start_addr) >> PAGE_SHIFT) - 1;

/* Check if it makes any sense to call ->map_pages */
while (!pte_none(*pte)) {
- if (++pgoff > max_pgoff)
- return;
start_addr += PAGE_SIZE;
- if (start_addr >= vma->vm_end)
+ if (start_addr >= end_addr)
return;
pte++;
+ pgoff++;
}

vmf.virtual_address = (void __user *) start_addr;


\
 
 \ /
  Last update: 2014-07-15 12:41    [W:0.101 / U:0.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site