Skip to content
  • David Herrmann's avatar
    shm: wait for pins to be released when sealing · 05f65b5c
    David Herrmann authored
    
    
    If we set SEAL_WRITE on a file, we must make sure there cannot be any
    ongoing write-operations on the file.  For write() calls, we simply lock
    the inode mutex, for mmap() we simply verify there're no writable
    mappings.  However, there might be pages pinned by AIO, Direct-IO and
    similar operations via GUP.  We must make sure those do not write to the
    memfd file after we set SEAL_WRITE.
    
    As there is no way to notify GUP users to drop pages or to wait for them
    to be done, we implement the wait ourself: When setting SEAL_WRITE, we
    check all pages for their ref-count.  If it's bigger than 1, we know
    there's some user of the page.  We then mark the page and wait for up to
    150ms for those ref-counts to be dropped.  If the ref-counts are not
    dropped in time, we refuse the seal operation.
    
    Signed-off-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
    Acked-by: default avatarHugh Dickins <hughd@google.com>
    Cc: Michael Kerrisk <mtk.manpages@gmail.com>
    Cc: Ryan Lortie <desrt@desrt.ca>
    Cc: Lennart Poettering <lennart@poettering.net>
    Cc: Daniel Mack <zonque@gmail.com>
    Cc: Andy Lutomirski <luto@amacapital.net>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    05f65b5c