minix/etc
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
..
defaults Move all services to /service 2014-07-31 16:00:31 +02:00
devmand Much USB code for ARM USB support 2014-08-29 18:52:49 +02:00
fonts support for ukranian (charse koi8-u) contributed by Roman Ignatov. 2010-06-08 01:04:52 +00:00
mtree benchmarks: remove unixbench 2015-07-20 11:05:28 +00:00
rc.capes Move all services to /service 2014-07-31 16:00:31 +02:00
root Import NetBSD shell environment files 2014-11-10 16:48:56 +01:00
skel Import NetBSD shell environment files 2014-11-10 16:48:56 +01:00
usr Add PTYFS, Unix98 pseudo terminal support 2015-06-23 17:43:46 +00:00
boot.cfg.default some small changes 2014-08-28 18:49:03 +02:00
crontab version /usr/lib/crontab too 2007-04-02 16:18:46 +00:00
csh.cshrc Import NetBSD shell environment files 2014-11-10 16:48:56 +01:00
csh.login Import NetBSD shell environment files 2014-11-10 16:48:56 +01:00
csh.logout Import NetBSD shell environment files 2014-11-10 16:48:56 +01:00
gettytab big <utmp.h>-inspired netbsd switch 2014-03-01 09:05:02 +01:00
group Switch to NetBSD passwd format 2011-11-14 14:47:42 +00:00
hostname.file Made things a little more boot-cd friendly (specifically readonly /usr). 2005-05-03 08:56:01 +00:00
inet.conf Initial revision 2005-04-21 14:53:53 +00:00
Makefile etc: create system log files 2015-08-10 11:38:16 +00:00
Makefile.params Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC) 2014-07-28 17:05:06 +02:00
man.conf Update whatis/apropos database configuration 2015-03-23 11:11:49 +01:00
master.passwd Removing /home/bin 2014-08-07 14:01:30 +02:00
mk.conf mk.conf: workaround for pkgin sourcing it 2013-05-16 11:13:00 +00:00
motd Set the motd to point to a wiki page. 2014-09-13 23:56:50 +02:00
newfstab.sh mainstream-format fstab format 2011-11-14 14:47:28 +00:00
profile Import NetBSD shell environment files 2014-11-10 16:48:56 +01:00
protocols Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC) 2014-07-28 17:05:06 +02:00
rc Services move to /service fixes 2014-08-08 17:56:05 +02:00
rc.cd Don't do this here too 2006-04-05 11:27:25 +00:00
rc.conf Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC) 2014-07-28 17:05:06 +02:00
rc.daemons.dist Importing libexec/fingerd 2013-06-02 08:14:05 -04:00
rc.shutdown big <utmp.h>-inspired netbsd switch 2014-03-01 09:05:02 +01:00
rc.subr Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC) 2014-07-28 17:05:06 +02:00
resolv.conf add /etc/resolv.conf pointing to minix nonamed 2011-07-26 18:03:04 +02:00
rs.inet Move all services to /service 2014-07-31 16:00:31 +02:00
rs.single Removed args debugging line 2007-02-16 15:58:05 +00:00
services Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC) 2014-07-28 17:05:06 +02:00
shells Add /bin/false to /etc/shells 2014-07-28 17:05:22 +02:00
shrc Import NetBSD shell environment files 2014-11-10 16:48:56 +01:00
syslog.conf Import NetBSD syslogd(8) 2015-07-26 11:57:04 +00:00
system.conf libminixfs/VM: fix memory-mapped file corruption 2015-08-13 13:46:46 +00:00
termcap Remove revision IDs from files 2010-11-04 01:13:59 +00:00
termcap.big Remove revision IDs from files 2010-11-04 01:13:59 +00:00
ttys big <utmp.h>-inspired netbsd switch 2014-03-01 09:05:02 +01:00
utmp Initial revision 2005-04-21 14:53:53 +00:00