Re: VFS?VM - mmap/write deadlock

Linus Torvalds (torvalds@transmeta.com)
Mon, 20 Dec 1999 23:11:54 -0800 (PST)


On Tue, 21 Dec 1999, Ben LaHaise wrote:
>
> We are talking about 2.4 -- right now one can deadlock by write()ing from
> an mmap()'d into the same file. The granularity of the lock is much
> smaller (it's the page lock), but it's still there.

Wait.. There was some reason this couldn't happen, we had this discussion
with Dave some time ago. Let's see..

[ think think think ]

Ok: in order to write() from the page, the page must have been paged in.

That page-in() will make sure that the page is first _read_. And that read
code does not care about the page lock, it only cares about the uptodate
bit. So it's ok to write from a locked page into a locked page, as long
as that page is marked up-to-date, because the page-in case won't care
about the lock.

So the solution comes down from verifying that the page is marked
up-to-date _before_ it is accessed and locked for the write. Which
automatically happens if the page is just marked up-to-date before we do
the "copy_from_user()" (at any time before that we don't care).

Ok, I think that was the solution I remember, but it's obviously broken.
It leaves a window of non-updated page contents that can be read. Ho
humm.. Your suggestion may be the way to go.

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/