linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] enforce proper tlb flush in unmap_hugepage_range
@ 2006-10-03  9:28 Chen, Kenneth W
  2006-10-03 11:52 ` Bill Irwin
  0 siblings, 1 reply; 2+ messages in thread
From: Chen, Kenneth W @ 2006-10-03  9:28 UTC (permalink / raw)
  To: 'Hugh Dickins', 'Andrew Morton', bill.irwin; +Cc: linux-mm

Spotted by Hugh that hugetlb page is free'ed back to global pool
before performing any TLB flush in unmap_hugepage_range(). This
potentially allow threads to abuse free-alloc race condition.


Signed-off-by: Ken Chen <kenneth.w.chen@intel.com>

---
The generic tlb gather code is unsuitable to use by hugetlb, I
just open coded a page gathering list and delayed put_page until
tlb flush is performed.  Huge, please sign-off if you are OK
with this patch.


--- ./mm/hugetlb.c.orig	2006-09-19 20:42:06.000000000 -0700
+++ ./mm/hugetlb.c	2006-10-03 00:04:11.000000000 -0700
@@ -363,12 +363,14 @@ void unmap_hugepage_range(struct vm_area
 	unsigned long address;
 	pte_t *ptep;
 	pte_t pte;
-	struct page *page;
+	struct page *page, *tmp;
+	struct list_head page_list;
 
 	WARN_ON(!is_vm_hugetlb_page(vma));
 	BUG_ON(start & ~HPAGE_MASK);
 	BUG_ON(end & ~HPAGE_MASK);
 
+	INIT_LIST_HEAD(&page_list);
 	spin_lock(&mm->page_table_lock);
 
 	/* Update high watermark before we lower rss */
@@ -384,12 +386,16 @@ void unmap_hugepage_range(struct vm_area
 			continue;
 
 		page = pte_page(pte);
-		put_page(page);
+		list_add(&page->lru, &page_list);
 		add_mm_counter(mm, file_rss, (int) -(HPAGE_SIZE / PAGE_SIZE));
 	}
 
 	spin_unlock(&mm->page_table_lock);
 	flush_tlb_range(vma, start, end);
+	list_for_each_entry_safe(page, tmp, &page_list, lru) {
+		list_del(&page->lru);
+		put_page(page);
+	}
 }
 
 static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch] enforce proper tlb flush in unmap_hugepage_range
  2006-10-03  9:28 [patch] enforce proper tlb flush in unmap_hugepage_range Chen, Kenneth W
@ 2006-10-03 11:52 ` Bill Irwin
  0 siblings, 0 replies; 2+ messages in thread
From: Bill Irwin @ 2006-10-03 11:52 UTC (permalink / raw)
  To: Chen, Kenneth W
  Cc: 'Hugh Dickins', 'Andrew Morton', bill.irwin, linux-mm

On Tue, Oct 03, 2006 at 02:28:37AM -0700, Chen, Kenneth W wrote:
> Spotted by Hugh that hugetlb page is free'ed back to global pool
> before performing any TLB flush in unmap_hugepage_range(). This
> potentially allow threads to abuse free-alloc race condition.
> Signed-off-by: Ken Chen <kenneth.w.chen@intel.com>

This seems terribly familiar. I should have gotten this cleaned up a
long time ago since I'm sure I knew this was an outstanding problem at
some point.

Good patch.

Signed-off-by: William Irwin <wli@holomorphy.com>


-- wli

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-10-03 11:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-03  9:28 [patch] enforce proper tlb flush in unmap_hugepage_range Chen, Kenneth W
2006-10-03 11:52 ` Bill Irwin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox