From owner-freebsd-hackers@FreeBSD.ORG Sat Apr 12 22:33:54 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 4C6F11065679 for ; Sat, 12 Apr 2008 22:33:54 +0000 (UTC) (envelope-from kip.macy@gmail.com) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.181]) by mx1.freebsd.org (Postfix) with ESMTP id 10B7E8FC28 for ; Sat, 12 Apr 2008 22:33:53 +0000 (UTC) (envelope-from kip.macy@gmail.com) Received: by wa-out-1112.google.com with SMTP id k17so1139751waf.3 for ; Sat, 12 Apr 2008 15:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=b4T96wudkYVNPdb4RySPBNCDAa4qlVMMZ4Lh+l8JFq4=; b=rrkbc0ukQZSvzBeZQyI9XMNkUh6+SlmFTFJSqihsxo/Dn0d4FeNTkGwk8zbA+Xr7DNObvWuU8eA914Hyscz4Df4uYXNY4/oCxbrGaQSnnbxM/mfp6Q9N0a6HOXgZbdeubi9yOJR5rtLLu+Sb3wkZbQhFx07V6gAU2/JSfRxJtnM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=wU9gNqgduOT4GI+sRBmEVKjV/xXbCL7ATmsZdzeGJEw99X7a7Ay3ys26zpk2jUwcFNxihMtE0IQyQemWbo4HCdesQmCGHccxSAIsWqJMxAYu4GXnjJ/zH0ymgQ35L3s39+jPMqfp6fmasPLaXX6exR3u00lTElKRFQOaX9O2vec= Received: by 10.114.151.13 with SMTP id y13mr5083302wad.148.1208039633847; Sat, 12 Apr 2008 15:33:53 -0700 (PDT) Received: by 10.114.255.16 with HTTP; Sat, 12 Apr 2008 15:33:53 -0700 (PDT) Message-ID: Date: Sat, 12 Apr 2008 15:33:53 -0700 From: "Kip Macy" To: "Matthew Dillon" In-Reply-To: <200804122156.m3CLuot5065753@apollo.backplane.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 22:33:54 -0000 On Sat, Apr 12, 2008 at 2:56 PM, Matthew Dillon wrote: > I've looked at it some more and it looks like it would be a real > mess to do it in the protection code. I think it may be best to > fix it in the fault code. That is, to explicitly allow a user-wired > page to be write-faulted. > > The primary protection check that is causing the segv is in > 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); > } > > BUT! This is going to cause a panic later on. There is one big gotcha > and that is the COW fault will cause the VM system to lose track of > the wiring of (I think) either the original page or the COW'd page, > and you will get a panic when it tries to unwire it later on. > > I will mess with it a bit in DragonFly to see if there's a simple > solution. For TCP offload I just have to ensure that the users pages have the right permissions and don't get re-allocated during DMA so I have the following fairly simple code: http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/sys/dev/cxgb/ulp/tom/cxgb_vm.c?rev=1.1;content-type=text%2Fplain The one bit that is interesting is that on receive I know in advance that I will be writing to the pages so I force the COW fault in advance before holding the page. This doesn't address the issue of mlock and cow in the general case, but its a good example of how knowing your application can greatly simplify the code. -Kip