• Andrew Morton's avatar
    [PATCH] Fix vmtruncate race and distributed filesystem race · 3e63f0be
    Andrew Morton authored
    From: Dave McCracken <dmccr@us.ibm.com>
    
    This patch solves the race between truncate and page in which can cause stray
    anon pages to appear in the truncated region.
    
    The race occurs when a process is sleeping in pagein IO during the truncate:
    there's a window after checking i_size in which the paging-in process decides
    that the page was an OK one.
    
    This leaves an anon page in the pagetables, and if the file is subsequently
    extended we have an anon page floating about inside a file-backed mmap - user
    modifications will not be written out.
    
    Apparently this is also needed for the implementation of POSIX semantics for
    distributed filesystems.
    
    We use a generation counter in the address_space so the paging-in process can
    determine whether there was a truncate which might have shot the new page
    down.
    
    It's a bit grubby to be playing with files and inodes in do_no_page(), but we
    do need the page_table_lock coverage for this, and rearranging thngs to
    provide that coverage to filemap_nopage wasn't very nice either.
    3e63f0be
blkmtd.c 35.5 KB