[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-id: <20140715095539.2086.44482.stgit@buzz>
Date: Tue, 15 Jul 2014 13:55:39 +0400
From: Konstantin Khlebnikov <k.khlebnikov@...sung.com>
To: linux-mm@...ck.org, Hugh Dickins <hughd@...gle.com>,
linux-kernel@...r.kernel.org, Sasha Levin <sasha.levin@...cle.com>
Cc: Ingo Korb <ingo.korb@...dortmund.de>,
"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
Dave Jones <davej@...hat.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Ning Qu <quning@...gle.com>,
Konstantin Khlebnikov <koct9i@...il.com>
Subject: [PATCH] mm: fix faulting range in do_fault_around
From: Konstantin Khlebnikov <koct9i@...il.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@...il.com>
Reported-by: "Ingo Korb" <ingo.korb@...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 majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists