public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Karl Schendel <kschendel@datallegro.com>
To: linux-kernel@vger.kernel.org
Cc: torvalds@linux-foundation.org
Subject: [PATCH] Fix bad data from non-direct-io read after direct-io write
Date: Fri, 26 Oct 2007 17:12:21 -0400	[thread overview]
Message-ID: <47225835.4050309@datallegro.com> (raw)

This patch fixes a race between direct IO writes and non-direct IO
reads on the same file.  The symptom is a stale file page seen by
any non-direct-IO reader, which persists until the page is invalidated
somehow (e.g. page rewritten again, or memory pressure, or reboot).

An improper return test caused direct-IO's after-write page invalidations
to be skipped.  If we're writing page N, and the reader is reading
page N-x for small x, and the read code decides to readahead, it's
not too hard to cause a race that leaves an old, stale copy of the
page in the page cache.  Retval is usually +nonzero after the
mapping->a_ops->direct_IO call!

Signed-off-by: Karl Schendel <kschendel@datallegro.com>

---

By the way, I agree that the userland situation is stupid, and I'm
addressing that in the application (happens to be the Ingres DBMS).
However, the kernel shouldn't compound the stupidity.

I'll try to watch for replies, but it would be very useful to
cc me at kschendel@datallegro.com if any discussion is needed;
I'm not subscribed to lkml.


--- linux-2.6.23.1-base/mm/filemap.c	2007-10-12 12:43:44.000000000 -0400
+++ linux-2.6.23.1/mm/filemap.c	2007-10-26 16:12:08.000000000 -0400
@@ -2194,7 +2194,7 @@ generic_file_direct_IO(int rw, struct ki
 	}

 	retval = mapping->a_ops->direct_IO(rw, iocb, iov, offset, nr_segs);
-	if (retval)
+	if (retval < 0)
 		goto out;

 	/*

             reply	other threads:[~2007-10-26 21:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-26 21:12 Karl Schendel [this message]
2007-10-26 21:34 ` [PATCH] Fix bad data from non-direct-io read after direct-io write Linus Torvalds
2007-10-26 22:10   ` Karl Schendel
2007-10-26 22:30   ` Zach Brown
2007-10-26 22:41     ` Karl Schendel
2007-10-26 22:42     ` Linus Torvalds
2007-10-26 22:54       ` Zach Brown
2007-10-26 23:14         ` Linus Torvalds
2007-10-26 23:28           ` Karl Schendel
2007-10-30 18:45             ` Zach Brown
2007-10-30 19:11               ` Linus Torvalds
2007-10-26 23:38           ` Zach 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=47225835.4050309@datallegro.com \
    --to=kschendel@datallegro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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