• Andrew Morton's avatar
    [PATCH] invalidate_inode_pages2() mmap coherency fix · 918798e7
    Andrew Morton authored
    - When invalidating pages, take care to shoot down any ptes which map them
      as well.
    
      This ensures that the next mmap access to the page will generate a major
      fault, so NFS's server-side modifications are picked up.
    
      This also allows us to call invalidate_complete_page() on all pages, so
      filesytems such as ext3 get a chance to invalidate the buffer_heads.
    
    - Don't mark in-pagetable pages as non-uptodate any more.  That broke a
      previous guarantee that mapped-into-user-process pages are always uptodate.
    
    - Check the return value of invalidate_complete_page().  It can fail if
      someone redirties a page after generic_file_direct_IO() write it back.
    
    But we still have a problem.  If invalidate_inode_pages2() calls
    unmap_mapping_range(), that can cause zap_pte_range() to dirty the pagecache
    pages.  That will redirty the page's buffers and will cause
    invalidate_complete_page() to fail.
    
    So, in generic_file_direct_IO() we do a complete pte shootdown on the file
    up-front, prior to writing back dirty pagecache.  This is only done for
    O_DIRECT writes.  It _could_ be done for O_DIRECT reads too, providing full
    mmap-vs-direct-IO coherency for both O_DIRECT reads and O_DIRECT writes, but
    permitting the pte shootdown on O_DIRECT reads trivially allows people to nuke
    other people's mapped pagecache.
    
    NFS also uses invalidate_inode_pages2() for handling server-side modification
    notifications.  But in the NFS case the clear_page_dirty() in
    invalidate_inode_pages2() is sufficient, because NFS doesn't have to worry
    about the "dirty buffers against a clean page" problem. (I think)
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    918798e7
filemap.c 56.2 KB