From owner-freebsd-hackers@FreeBSD.ORG Sat Apr 12 23:53:07 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E9B681065678; Sat, 12 Apr 2008 23:53:07 +0000 (UTC) (envelope-from dillon@apollo.backplane.com) Received: from apollo.backplane.com (apollo.backplane.com [216.240.41.2]) by mx1.freebsd.org (Postfix) with ESMTP id AF0688FC13; Sat, 12 Apr 2008 23:53:07 +0000 (UTC) (envelope-from dillon@apollo.backplane.com) Received: from apollo.backplane.com (localhost [127.0.0.1]) by apollo.backplane.com (8.14.1/8.14.1) with ESMTP id m3CNr7aL066380; Sat, 12 Apr 2008 16:53:07 -0700 (PDT) Received: (from dillon@localhost) by apollo.backplane.com (8.14.1/8.13.4/Submit) id m3CNr7sR066379; Sat, 12 Apr 2008 16:53:07 -0700 (PDT) Date: Sat, 12 Apr 2008 16:53:07 -0700 (PDT) From: Matthew Dillon Message-Id: <200804122353.m3CNr7sR066379@apollo.backplane.com> To: "Kip Macy" References: <20080309212441.GA56523@porthos.spock.org> <200804122156.m3CLuot5065753@apollo.backplane.com> Cc: hackers@freebsd.org, Jonathan Chen Subject: Re: mlock & COW X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Apr 2008 23:53:08 -0000 :> 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