Skip to contentSkip to conversation

fix invalidate_inode_pages2() race

PATCH In review Andrew Morton 1 participant 1 message Jul 4, 2002

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 24/27 fix invalidate_inode_pages2() race

Fix a buglet in invalidate_list_pages2(): there is a small window in which writeback could start against the page before this function locks it.

The patch closes the race by performing the PageWriteback test inside PageLocked.

Testing PageWriteback inside PageLocked is "definitive" - when a page is locked, writeback cannot start against it.

 filemap.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
mm/filemap.c renamed from mm/filemap.c~invalidate-race +9 -7
@@ -367,16 +367,18 @@ static int invalidate_list_pages2(struct
 	while (curr != head) {
 		page = list_entry(curr, struct page, list);
 
-		if (PageWriteback(page)) {
-			write_unlock(&mapping->page_lock);
-			wait_on_page_writeback(page);
-			unlocked = 1;
-			write_lock(&mapping->page_lock);
-			goto restart;
-		}
 		if (!TestSetPageLocked(page)) {
 			int __unlocked;
 
+			if (PageWriteback(page)) {
+				write_unlock(&mapping->page_lock);
+				wait_on_page_writeback(page);
+				unlocked = 1;
+				write_lock(&mapping->page_lock);
+				unlock_page(page);
+				goto restart;
+			}
+
 			__unlocked = invalidate_this_page2(mapping, page, curr, head);
 			unlock_page(page);
 			unlocked |= __unlocked;

-