mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chip Coldwell <coldwell@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@osdl.org
Subject: direct IO regression in 2.6.18
Date: Tue, 3 Oct 2006 13:51:49 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0610031330400.31975@localhost.localdomain> (raw)

Hi,

The following commit caused a regression in direct IO:

commit 016eb4a0ed06a3677d67a584da901f0e9a63c666
Author: Andrew Morton <akpm@osdl.org>
Date:   Fri Sep 8 09:48:38 2006 -0700

     [PATCH] invalidate_complete_page() race fix

     If a CPU faults this page into pagetables after invalidate_mapping_pages()
     checked page_mapped(), invalidate_complete_page() will still proceed to remove
     the page from pagecache.  This leaves the page-faulting process with a
     detached page.  If it was MAP_SHARED then file data loss will ensue.

     Fix that up by checking the page's refcount after taking tree_lock.

     Cc: Nick Piggin <nickpiggin@yahoo.com.au>
     Cc: Hugh Dickins <hugh@veritas.com>
     Cc: <stable@kernel.org>
     Signed-off-by: Andrew Morton <akpm@osdl.org>
     Signed-off-by: Linus Torvalds <torvalds@osdl.org>

diff --git a/mm/truncate.c b/mm/truncate.c
index cf1b015..c6ab55e 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -68,10 +68,10 @@ invalidate_complete_page(struct address_
  		return 0;

  	write_lock_irq(&mapping->tree_lock);
-	if (PageDirty(page)) {
-		write_unlock_irq(&mapping->tree_lock);
-		return 0;
-	}
+	if (PageDirty(page))
+		goto failed;
+	if (page_count(page) != 2)	/* caller's ref + pagecache ref */
+		goto failed;

  	BUG_ON(PagePrivate(page));
  	__remove_from_page_cache(page);
@@ -79,6 +79,9 @@ invalidate_complete_page(struct address_
  	ClearPageUptodate(page);
  	page_cache_release(page);	/* pagecache ref */
  	return 1;
+failed:
+	write_unlock_irq(&mapping->tree_lock);
+	return 0;
  }

  /**


The issue is that invalidate_complete_page is in two different code
paths, the normal one (prune_icache calls invalidate_inode_pages calls
invalidate_mapping_pages calls invalidate_complete_page) and also via
direct IO (generic_file_direct_write calls generic_file_direct_IO
calls invalidate_inode_pages2_range calls invalidate_complete_page).
In the latter case, the page is (usually) not even in the page cache
and the refcount can legitimately != 2.

Chip

-- 
Charles M. "Chip" Coldwell
Senior Software Engineer
Red Hat, Inc
978-392-2426


             reply	other threads:[~2006-10-03 17:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-03 17:51 Chip Coldwell [this message]
2006-10-03 18:03 ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0610031330400.31975@localhost.localdomain \
    --to=coldwell@redhat.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®