vserver 2.0 rc7
[linux-2.6.git] / Documentation / nommu-mmap.txt
index fcf1c08..b88ebe4 100644 (file)
@@ -36,20 +36,35 @@ and it's also much more restricted in the latter case:
        In the MMU case: VM regions backed by pages read from file; changes to
        the underlying file are reflected in the mapping; copied across fork.
 
-       In the no-MMU case: VM regions backed by arbitrary contiguous runs of
-       pages into which the appropriate bit of the file is read; any remaining
-       bit of the mapping is cleared; such mappings are shared if possible;
-       writes to the file do not affect the mapping; writes to the mapping are
-       visible in other processes (no MMU protection), but should not happen.
+       In the no-MMU case:
+
+         - If one exists, the kernel will re-use an existing mapping to the
+           same segment of the same file if that has compatible permissions,
+           even if this was created by another process.
+
+         - If possible, the file mapping will be directly on the backing device
+           if the backing device has the BDI_CAP_MAP_DIRECT capability and
+           appropriate mapping protection capabilities. Ramfs, romfs, cramfs
+           and mtd might all permit this.
+
+        - If the backing device device can't or won't permit direct sharing,
+           but does have the BDI_CAP_MAP_COPY capability, then a copy of the
+           appropriate bit of the file will be read into a contiguous bit of
+           memory and any extraneous space beyond the EOF will be cleared
+
+        - Writes to the file do not affect the mapping; writes to the mapping
+          are visible in other processes (no MMU protection), but should not
+          happen.
 
  (*) File, MAP_PRIVATE, PROT_READ / PROT_EXEC, PROT_WRITE
 
        In the MMU case: like the non-PROT_WRITE case, except that the pages in
        question get copied before the write actually happens. From that point
-       on writes to that page in the file no longer get reflected into the
-       mapping's backing pages.
+       on writes to the file underneath that page no longer get reflected into
+       the mapping's backing pages. The page is then backed by swap instead.
 
-       In the no-MMU case: works exactly as for the non-PROT_WRITE case.
+       In the no-MMU case: works much like the non-PROT_WRITE case, except
+       that a copy is always taken and never shared.
 
  (*) Regular file / blockdev, MAP_SHARED, PROT_READ / PROT_EXEC / PROT_WRITE
 
@@ -70,6 +85,15 @@ and it's also much more restricted in the latter case:
        as for the MMU case. If the filesystem does not provide any such
        support, then the mapping request will be denied.
 
+ (*) Memory backed blockdev, MAP_SHARED, PROT_READ / PROT_EXEC / PROT_WRITE
+
+       In the MMU case: As for ordinary regular files.
+
+       In the no-MMU case: As for memory backed regular files, but the
+       blockdev must be able to provide a contiguous run of pages without
+       truncate being called. The ramdisk driver could do this if it allocated
+       all its memory as a contiguous array upfront.
+
  (*) Memory backed chardev, MAP_SHARED, PROT_READ / PROT_EXEC / PROT_WRITE
 
        In the MMU case: As for ordinary regular files.
@@ -95,12 +119,12 @@ FURTHER NOTES ON NO-MMU MMAP
  (*) Supplying MAP_FIXED or a requesting a particular mapping address will
      result in an error.
 
- (*) Files mapped privately must have a read method provided by the driver or
-     filesystem so that the contents can be read into the memory allocated. An
+ (*) Files mapped privately usually have to have a read method provided by the
+     driver or filesystem so that the contents can be read into the memory
+     allocated if mmap() chooses not to map the backing device directly. An
      error will result if they don't. This is most likely to be encountered
      with character device files, pipes, fifos and sockets.
 
-
 ============================================
 PROVIDING SHAREABLE CHARACTER DEVICE SUPPORT
 ============================================
@@ -111,6 +135,15 @@ to get a proposed address for the mapping. This may return an error if it
 doesn't wish to honour the mapping because it's too long, at a weird offset,
 under some unsupported combination of flags or whatever.
 
+The driver should also provide backing device information with capabilities set
+to indicate the permitted types of mapping on such devices. The default is
+assumed to be readable and writable, not executable, and only shareable
+directly (can't be copied).
+
+The file->f_op->mmap() operation will be called to actually inaugurate the
+mapping. It can be rejected at that point. Returning the ENOSYS error will
+cause the mapping to be copied instead if BDI_CAP_MAP_COPY is specified.
+
 The vm_ops->close() routine will be invoked when the last mapping on a chardev
 is removed. An existing mapping will be shared, partially or not, if possible
 without notifying the driver.
@@ -120,7 +153,22 @@ return -ENOSYS. This will be taken to mean that this operation just doesn't
 want to handle it, despite the fact it's got an operation. For instance, it
 might try directing the call to a secondary driver which turns out not to
 implement it. Such is the case for the framebuffer driver which attempts to
-direct the call to the device-specific driver.
+direct the call to the device-specific driver. Under such circumstances, the
+mapping request will be rejected if BDI_CAP_MAP_COPY is not specified, and a
+copy mapped otherwise.
+
+IMPORTANT NOTE:
+
+       Some types of device may present a different appearance to anyone
+       looking at them in certain modes. Flash chips can be like this; for
+       instance if they're in programming or erase mode, you might see the
+       status reflected in the mapping, instead of the data.
+
+       In such a case, care must be taken lest userspace see a shared or a
+       private mapping showing such information when the driver is busy
+       controlling the device. Remember especially: private executable
+       mappings may still be mapped directly off the device under some
+       circumstances!
 
 
 ==============================================
@@ -139,3 +187,12 @@ memory.
 
 Memory backed devices are indicated by the mapping's backing device info having
 the memory_backed flag set.
+
+
+========================================
+PROVIDING SHAREABLE BLOCK DEVICE SUPPORT
+========================================
+
+Provision of shared mappings on block device files is exactly the same as for
+character devices. If there isn't a real device underneath, then the driver
+should allocate sufficient contiguous memory to honour any supported mapping.