From: Konstantin Khlebnikov <koc...@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 <koc...@gmail.com>
Reported-by: "Ingo Korb" <ingo.k...@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;

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to