[PATCH] mm: call pte_unmap() against a proper pte (Re: [PATCH 7/9] swap_info: swap count continuations)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Daisuke Nishimura
Date: Thursday, October 15, 2009 - 11:30 pm

Hi.

It isn't the fault of only this patch, but I think breaking the loop without incrementing
dst_pte(and src_pte) would be bad behavior because we do unmap_pte(dst_pte - 1) later.
(current copy_pte_range() already does it though... and this is only problematic
when we break the first loop, IIUC.)


I've searched other places where we break a similar loop and do pte_unmap(pte - 1).
Current copy_pte_range() and apply_to_pte_range() has the same problem.

How about a patch like this ?
===
From: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>

There are some places where we do like:

	pte = pte_map();
	do {
		(do break in some conditions)
	} while (pte++, ...);
	pte_unmap(pte - 1);

But if the loop breaks at the first loop, pte_unmap() unmaps invalid pte.

This patch is a fix for this problem.

Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
---
 mm/memory.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 72a2494..492de38 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -641,6 +641,7 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 		pmd_t *dst_pmd, pmd_t *src_pmd, struct vm_area_struct *vma,
 		unsigned long addr, unsigned long end)
 {
+	pte_t *orig_src_pte, *orig_dst_pte;
 	pte_t *src_pte, *dst_pte;
 	spinlock_t *src_ptl, *dst_ptl;
 	int progress = 0;
@@ -654,6 +655,8 @@ again:
 	src_pte = pte_offset_map_nested(src_pmd, addr);
 	src_ptl = pte_lockptr(src_mm, src_pmd);
 	spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
+	orig_src_pte = src_pte;
+	orig_dst_pte = dst_pte;
 	arch_enter_lazy_mmu_mode();
 
 	do {
@@ -677,9 +680,9 @@ again:
 
 	arch_leave_lazy_mmu_mode();
 	spin_unlock(src_ptl);
-	pte_unmap_nested(src_pte - 1);
+	pte_unmap_nested(orig_src_pte);
 	add_mm_rss(dst_mm, rss[0], rss[1]);
-	pte_unmap_unlock(dst_pte - 1, dst_ptl);
+	pte_unmap_unlock(orig_dst_pte, dst_ptl);
 	cond_resched();
 	if (addr != end)
 		goto again;
@@ -1822,10 +1825,10 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd,
 	token = pmd_pgtable(*pmd);
 
 	do {
-		err = fn(pte, token, addr, data);
+		err = fn(pte++, token, addr, data);
 		if (err)
 			break;
-	} while (pte++, addr += PAGE_SIZE, addr != end);
+	} while (addr += PAGE_SIZE, addr != end);
 
 	arch_leave_lazy_mmu_mode();
 
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/9] swap_info and swap_map patches, Hugh Dickins, (Wed Oct 14, 5:44 pm)
[PATCH 1/9] swap_info: private to swapfile.c, Hugh Dickins, (Wed Oct 14, 5:46 pm)
[PATCH 2/9] swap_info: change to array of pointers, Hugh Dickins, (Wed Oct 14, 5:48 pm)
[PATCH 3/9] swap_info: include first_swap_extent, Hugh Dickins, (Wed Oct 14, 5:49 pm)
[PATCH 4/9] swap_info: miscellaneous minor cleanups, Hugh Dickins, (Wed Oct 14, 5:50 pm)
[PATCH 5/9] swap_info: SWAP_HAS_CACHE cleanups, Hugh Dickins, (Wed Oct 14, 5:52 pm)
[PATCH 6/9] swap_info: swap_map of chars not shorts, Hugh Dickins, (Wed Oct 14, 5:53 pm)
[PATCH 7/9] swap_info: swap count continuations, Hugh Dickins, (Wed Oct 14, 5:56 pm)
[PATCH 8/9] swap_info: note SWAP_MAP_SHMEM, Hugh Dickins, (Wed Oct 14, 5:57 pm)
[PATCH 9/9] swap_info: reorder its fields, Hugh Dickins, (Wed Oct 14, 5:58 pm)
Re: [PATCH 2/9] swap_info: change to array of pointers, KAMEZAWA Hiroyuki, (Wed Oct 14, 7:11 pm)
Re: [PATCH 4/9] swap_info: miscellaneous minor cleanups, KAMEZAWA Hiroyuki, (Wed Oct 14, 7:19 pm)
Re: [PATCH 5/9] swap_info: SWAP_HAS_CACHE cleanups, KAMEZAWA Hiroyuki, (Wed Oct 14, 7:37 pm)
Re: [PATCH 6/9] swap_info: swap_map of chars not shorts, KAMEZAWA Hiroyuki, (Wed Oct 14, 7:44 pm)
Re: [PATCH 7/9] swap_info: swap count continuations, KAMEZAWA Hiroyuki, (Wed Oct 14, 8:30 pm)
Re: [PATCH 8/9] swap_info: note SWAP_MAP_SHMEM, KAMEZAWA Hiroyuki, (Wed Oct 14, 8:32 pm)
Re: [PATCH 1/9] swap_info: private to swapfile.c, Rik van Riel, (Thu Oct 15, 7:57 am)
Re: [PATCH 2/9] swap_info: change to array of pointers, Rik van Riel, (Thu Oct 15, 8:02 am)
Re: [PATCH 7/9] swap_info: swap count continuations, Andrew Morton, (Thu Oct 15, 12:45 pm)
Re: [PATCH 7/9] swap_info: swap count continuations, David Rientjes, (Thu Oct 15, 2:17 pm)
Re: [PATCH 4/9] swap_info: miscellaneous minor cleanups, Hugh Dickins, (Thu Oct 15, 3:01 pm)
Re: [PATCH 5/9] swap_info: SWAP_HAS_CACHE cleanups, Hugh Dickins, (Thu Oct 15, 3:08 pm)
Re: [PATCH 6/9] swap_info: swap_map of chars not shorts, Hugh Dickins, (Thu Oct 15, 3:17 pm)
Re: [PATCH 8/9] swap_info: note SWAP_MAP_SHMEM, Hugh Dickins, (Thu Oct 15, 3:23 pm)
Re: [PATCH 2/9] swap_info: change to array of pointers, Hugh Dickins, (Thu Oct 15, 3:41 pm)
Re: [PATCH 2/9] swap_info: change to array of pointers, Hugh Dickins, (Thu Oct 15, 4:04 pm)
Re: [PATCH 1/9] swap_info: private to swapfile.c, Nigel Cunningham, (Thu Oct 15, 4:10 pm)
Re: [PATCH 2/9] swap_info: change to array of pointers, KAMEZAWA Hiroyuki, (Thu Oct 15, 4:46 pm)
Re: [PATCH 2/9] swap_info: change to array of pointers, KAMEZAWA Hiroyuki, (Thu Oct 15, 4:47 pm)
Re: [PATCH 6/9] swap_info: swap_map of chars not shorts, KAMEZAWA Hiroyuki, (Thu Oct 15, 4:52 pm)
Re: [PATCH 7/9] swap_info: swap count continuations, Hugh Dickins, (Thu Oct 15, 4:53 pm)
Re: [PATCH 8/9] swap_info: note SWAP_MAP_SHMEM, KAMEZAWA Hiroyuki, (Thu Oct 15, 5:04 pm)
Re: [PATCH 7/9] swap_info: swap count continuations, Hugh Dickins, (Thu Oct 15, 5:21 pm)
Re: [PATCH 1/9] swap_info: private to swapfile.c, Hugh Dickins, (Thu Oct 15, 5:28 pm)
[PATCH 4/9 v2] swap_info: miscellaneous minor cleanups, Hugh Dickins, (Thu Oct 15, 5:41 pm)
Re: [PATCH 7/9] swap_info: swap count continuations, KAMEZAWA Hiroyuki, (Thu Oct 15, 6:29 pm)
Re: [PATCH 7/9] swap_info: swap count continuations, Hugh Dickins, (Thu Oct 15, 7:24 pm)
Re: [PATCH 7/9] swap_info: swap count continuations, KAMEZAWA Hiroyuki, (Thu Oct 15, 9:06 pm)
Re: [PATCH 7/9] swap_info: swap count continuations, Nitin Gupta, (Thu Oct 15, 9:49 pm)
[PATCH] mm: call pte_unmap() against a proper pte (Re: [PA ..., Daisuke Nishimura, (Thu Oct 15, 11:30 pm)
Re: [PATCH] mm: call pte_unmap() against a proper pte (Re: ..., KAMEZAWA Hiroyuki, (Fri Oct 16, 1:01 am)