linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Neil Brown <neilb@suse.de>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Nick Piggin <npiggin@suse.de>,
	David Woodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH] Fix race between callers of read_cache_page_async and invalidate_inode_pages.
Date: Sun, 26 Apr 2009 22:37:44 -0700	[thread overview]
Message-ID: <20090426223744.72edc7f4.akpm@linux-foundation.org> (raw)
In-Reply-To: <18933.16534.862316.787808@notabene.brown>

On Mon, 27 Apr 2009 15:20:22 +1000 Neil Brown <neilb@suse.de> wrote:

> 
> 
> 
> Callers of read_cache_page_async typically wait for the page to become
> unlocked (wait_on_page_locked) and then test PageUptodate to see if
> the read was successful, or if there was an error.
> 
> This is wrong.
> 
> invalidate_inode_pages can cause an unlocked page to lose its
> PageUptodate flag at any time without implying a read error.

ow.

> As any read error will cause PageError to be set, it is much safer,
> and more idiomatic to test "PageError" than to test "!PageUptodate".
> 
> ...
>
> diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
> index dd3634e..573d582 100644
> --- a/fs/cramfs/inode.c
> +++ b/fs/cramfs/inode.c
> @@ -180,7 +180,7 @@ static void *cramfs_read(struct super_block *sb, unsigned int offset, unsigned i
>  		struct page *page = pages[i];
>  		if (page) {
>  			wait_on_page_locked(page);
> -			if (!PageUptodate(page)) {
> +			if (PageError(page)) {
>  				/* asynchronous error */
>  				page_cache_release(page);
>  				pages[i] = NULL;
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 379ff0b..9ff8093 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -1770,7 +1770,7 @@ struct page *read_cache_page(struct address_space *mapping,
>  	if (IS_ERR(page))
>  		goto out;
>  	wait_on_page_locked(page);
> -	if (!PageUptodate(page)) {
> +	if (!PageError(page)) {
>  		page_cache_release(page);
>  		page = ERR_PTR(-EIO);
>  	}

hrm.  And where is it written that PageError() will remain inviolable
after it has been set?

A safer and more formal (albeit somewhat slower) fix would be to lock
the page and check its state under the lock.

y:/usr/src/linux-2.6.30-rc3> grep -r ClearPageError . | wc -l
21

?

--
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>

  reply	other threads:[~2009-04-27  5:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-27  5:20 [PATCH] Fix race between callers of read_cache_page_async and invalidate_inode_pages Neil Brown
2009-04-27  5:37 ` Andrew Morton [this message]
2009-04-27  7:46   ` Neil Brown

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=20090426223744.72edc7f4.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=neilb@suse.de \
    --cc=npiggin@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).