[PATCH] mm/hugetlb: Release pages in the error path of COW

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If anon_vma is prepared unsuccessfully, new_page and old_page should be freed.

And due to that page_table_lock is re-acquired, race in updating page table
should also be check. If race does happen, our job is done.

All comments and ideas welcome.

Thanks

Signed-off-by: Hillf Danton <dhillf@xxxxxxxxx>
---

--- a/mm/hugetlb.c	Sat Aug 13 11:45:14 2011
+++ b/mm/hugetlb.c	Sat Oct 29 20:44:09 2011
@@ -2406,8 +2406,7 @@ retry_avoidcopy:
 			if (unmap_ref_private(mm, vma, old_page, address)) {
 				BUG_ON(page_count(old_page) != 1);
 				BUG_ON(huge_pte_none(pte));
-				spin_lock(&mm->page_table_lock);
-				goto retry_avoidcopy;
+				goto lock_and_check;
 			}
 			WARN_ON_ONCE(1);
 		}
@@ -2422,6 +2421,8 @@ retry_avoidcopy:
 	 * anon_vma prepared.
 	 */
 	if (unlikely(anon_vma_prepare(vma))) {
+		page_cache_release(new_page);
+		page_cache_release(old_page);
 		/* Caller expects lock to be held */
 		spin_lock(&mm->page_table_lock);
 		return VM_FAULT_OOM;
@@ -2455,6 +2456,14 @@ retry_avoidcopy:
 	}
 	page_cache_release(new_page);
 	page_cache_release(old_page);
+	return 0;
+
+lock_and_check:
+	spin_lock(&mm->page_table_lock);
+	ptep = huge_pte_offset(mm, address & huge_page_mask(h));
+	if (likely(pte_same(huge_ptep_get(ptep), pte)))
+		goto retry_avoidcopy;
+	/* else changes occured while taking page_table_lock, our job done */
 	return 0;
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]