minix/minix
David van Moolenbroek e94f856b38 libminixfs/VM: fix memory-mapped file corruption
This patch employs one solution to resolve two independent but related
issues.  Both issues are the result of one fundamental aspect of the
way VM's memory mapping works: VM uses its cache to map in blocks for
memory-mapped file regions, and for blocks already in the VM cache, VM
does not go to the file system before mapping them in.  To preserve
consistency between the FS and VM caches, VM relies on being informed
about all updates to file contents through the block cache.  The two
issues are both the result of VM not being properly informed about
such updates:

 1. Once a file system provides libminixfs with an inode association
    (inode number + inode offset) for a disk block, this association
    is not broken until a new inode association is provided for it.
    If a block is freed and reallocated as a metadata (non-inode)
    block, its old association is maintained, and may be supplied to
    VM's secondary cache.  Due to reuse of inodes, it is possible
    that the same inode association becomes valid for an actual file
    block again.  In that case, when that new file is memory-mapped,
    under certain circumstances, VM may end up using the metadata
    block to satisfy a page fault on the file, due to the stale inode
    association.  The result is a corrupted memory mapping, with the
    application seeing data other than the current file contents
    mapped in at the file block.

 2. When a hole is created in a file, the underlying block is freed
    from the device, but VM is not informed of this update, and thus,
    if VM's cache contains the block with its previous inode
    association, this block will remain there.  As a result, if an
    application subsequently memory-maps the file, VM will map in the
    old block at the position of the hole, rather than an all-zeroes
    block.  Thus, again, the result is a corrupted memory mapping.

This patch resolves both issues by making the file system inform the
minixfs library about blocks being freed, so that libminixfs can
break the inode association for that block, both in its own cache and
in the VM cache.  Since libminixfs does not know whether VM has the
block in its cache or not, it makes a call to VM for each block being
freed.  Thus, this change introduces more calls to VM, but it solves
the correctness issues at hand; optimizations may be introduced
later.  On the upside, all freed blocks are now marked as clean,
which should result in fewer blocks being written back to the device,
and the blocks are removed from the caches entirely, which should
result in slightly better cache usage.

This patch is necessary but not sufficient to resolve the situation
with respect to memory mapping of file holes in general.  Therefore,
this patch extends test 74 with a (rather particular but effective)
test for the first issue, but not yet with a test for the second one.

This fixes #90.

Change-Id: Iad8b134d2f88a884f15d3fc303e463280749c467
2015-08-13 13:46:46 +00:00
..
bin New sources layout 2014-07-31 16:00:30 +02:00
commands libminixfs/VM: fix memory-mapped file corruption 2015-08-13 13:46:46 +00:00
drivers audio: use standard Makefile structure 2015-08-08 16:55:03 +00:00
fs libminixfs/VM: fix memory-mapped file corruption 2015-08-13 13:46:46 +00:00
include libminixfs/VM: fix memory-mapped file corruption 2015-08-13 13:46:46 +00:00
kernel Kernel: correctly set USE_ defines from Makefile 2015-08-08 16:56:37 +00:00
lib libminixfs/VM: fix memory-mapped file corruption 2015-08-13 13:46:46 +00:00
llvm minix/llvm/passes/Makefile.inc: Fix 2014-08-29 12:56:57 -04:00
man Import NetBSD syslogd(8) 2015-07-26 11:57:04 +00:00
net lwip: no need to retrieve own endpoint 2015-08-08 16:57:14 +00:00
sbin New sources layout 2014-07-31 16:00:30 +02:00
servers libminixfs/VM: fix memory-mapped file corruption 2015-08-13 13:46:46 +00:00
share New sources layout 2014-07-31 16:00:30 +02:00
tests libminixfs/VM: fix memory-mapped file corruption 2015-08-13 13:46:46 +00:00
usr.bin VFS: add support for F_DUPFD_CLOEXEC 2015-07-20 13:55:10 +00:00
usr.sbin mkfs.mfs: remove Linux mount check 2015-07-20 10:59:49 +00:00
Makefile benchmarks: remove unixbench 2015-07-20 11:05:28 +00:00
Makefile.inc New sources layout 2014-07-31 16:00:30 +02:00