• David Howells's avatar
    [PATCH] Permit nommu MAP_SHARED of memory backed files · f5f20ef0
    David Howells authored
    The attached patch applies some further fixes and extensions to the nommu mmap
    implementation:
    
     (1) /proc/maps distinguishes shareable private mappings and real shared
         mappings by marking the former with 's' and the latter with 'S'.
    
     (2) Rearrange and optimise the checking portion of do_mmap_pgoff() to make it
         easier to follow.
    
     (3) Only set VM_SHARED on MAP_SHARED mappings. Its presence indicates that the
         backing memory is supplied by the underlying file or chardev.
    
         VM_MAYSHARE indicates that a VMA may be shared if it's a private VMA. The
         memory for a private VMA is allocated by do_mmap_pgoff() from a kmalloc
         slab and then the file contents are read into it before returning.
    
     (4) Permit MAP_SHARED + PROT_WRITE on memory-backed files[*] and chardevs to
         indicate a contiguous area of memory when its get_unmapped_area() is
         called if the backing fs/chardev is willing.
    
         [*] file->f_mapping->backing_dev_info->memory_backed == 1
    
     (5) Require chardevs and files that support to provide a get_unmapped_area()
         file operation.
    
     (6) Made sure a private mapping of /dev/zero is possible. Shared mappings of
         /dev/zero are not currently supported because this'd need greater
         interaction of mmap with the chardev driver than is currently supported.
    
     (7) Add in some extra checks from mm/mmap.c: security, file having write
         access for a writable shared mapping, file not being in append mode.
    
     (8) Only account the mapping memory if it's allocated here; memory belonging
         to a shared chardev or file is not accounted.
    
    With this patch it should be possible to map contiguous flash files directly
    out of ROM simply by providing get_unmapped_area() for a read-only/shared
    mapping.
    
    I think that it might be worth splitting do_mmap_pgoff() up into smaller
    subfunctions: one to handle the checking, one to handle shared mappings and
    one to handle private mappings.
    Signed-Off-By: default avatarDavid Howells <dhowells@redhat.com>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    f5f20ef0
nommu.c 3.12 KB