mlock & COW
Matthew Dillon
dillon at apollo.backplane.com
Sat Apr 12 23:53:08 UTC 2008
:> vm_map_lookup() line 3161 and line 3297 (FreeBSD current). Commenting
:> those out will allow the COW on the user-wired page:
:>
:> if ((entry->eflags & MAP_ENTRY_USER_WIRED) &&
:> (entry->eflags & MAP_ENTRY_COW) &&
:> (fault_type & VM_PROT_WRITE) &&
:> (fault_typea & VM_PROT_OVERRIDE_WRITE) == 0) {
:> RETURN(KERN_PROTECTION_FAILURE);
:> }
Ok, never mind on commenting out that code in vm_map_lookup(),
it won't work. In fact, it will crash the machine even faster.
It's messy both ways, but marginally less messy if you do it in the
vm_fault() code.
The problem with fixing it in the fault code is that the vm_fault()
routine is called by the wiring and unwiring code and also by code which
undoes failed wirings (where the entry flags do not reflect what the
caller wants vm_fault() to do), so vm_fault() can't just check the entry
flags and automatically user-wire.
To do it without rewriting the whole mess (and rewriting is not a bad
idea), the platform trap code needs to call vm_fault() with a new
flag VM_FAULT_AUTOWIRE, then vm_map_lookup() needs to set the contents
of &fs.wired whether it succeeds or fails, then vm_fault(), upon
seeing result == KERN_PROTECTION_FAILURE, must check whether
VM_FAULT_AUTOWIRE was specified and if so check fs.wired to see if the
mapping failed due to incompatible protections on a user wired
mapping, and THEN it can set VM_FAULT_USER_WIRE in fault_flags and
continue normally.
And on top of all of that I'm still not sure whether the originally
underlying read-only paged that was COW'd will be properly unwired.
As I said, messy.
-Matt
Matthew Dillon
<dillon at backplane.com>
More information about the freebsd-hackers
mailing list