From owner-freebsd-hackers@FreeBSD.ORG Tue Dec 7 16:51:48 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A66EE16A4CE for ; Tue, 7 Dec 2004 16:51:48 +0000 (GMT) Received: from ims-1.prv.ampira.com (ims-1.ampira.com [66.179.231.26]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2605543D70 for ; Tue, 7 Dec 2004 16:51:48 +0000 (GMT) (envelope-from kamalp@acm.org) Received: from [202.142.94.194] (helo=[172.16.3.26]) by ims-1.prv.ampira.com with asmtp (Exim 4.24) id 1CbiVn-00022M-Dr; Tue, 07 Dec 2004 11:48:28 -0500 Message-ID: <41B5DF9B.50501@acm.org> Date: Tue, 07 Dec 2004 22:21:39 +0530 From: "Kamal R. Prasad" User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: John-Mark Gurney References: <41B20B19.3090204@acm.org> <20041206025126.GO19624@funkthat.com> <41B3F24B.1000903@acm.org> <20041206074237.GP19624@funkthat.com> In-Reply-To: <20041206074237.GP19624@funkthat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-hackers@freebsd.org Subject: Re: mmap() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Dec 2004 16:51:48 -0000 John-Mark Gurney wrote: >Kamal R. Prasad wrote this message on Mon, Dec 06, 2004 at 11:16 +0530: > > >>John-Mark Gurney wrote: >> >> >> >>>Kamal R. Prasad wrote this message on Sun, Dec 05, 2004 at 00:38 +0530: >>> >>> >>> >>> >>>>I wrote an mmap() interface for a USB device. But when I made a call to >>>>it using mmap(), I saw that mmap interface is called 3-4 times. The >>>>calls are being made from within mmap() i.e. sys/vm/vm_mmap.c. Can >>>>someone tell me if there is something like a re-try going on for some >>>>reason? >>>> >>>> >>>>From userspace, I called it as >>> >>> >>>>addr = mmap(NULL, 1024, PROT_READ, MAP_SHARED, fd, 0); >>>>The version of OS is Freebsd 5.3(stable). >>>> >>>> >>>> >>>> >>>each mmap call will be called whenever the kernel needs to map that >>>specific page.. say you map 16k of your device... it won't map any >>>of the 16k until the first time it is accessed, then it will call the >>>mmap routine for each page as it is accessed... it is also possible that >>>memory for the mappings needs to be reclaimed, at which point those page >>>mappings will be reaped, and your mmap function will be called again when >>>they need to be accessed again.. >>> >>> >>> >>> >>> >>Thanks. But then, the mmap'ed() address was yet to be used by the user >>space and I don't see the need for multiple calls to my interface almost >>as if in a while loop. Is there any return value from the mmap() >>interface that could trigger another call? I am returning 0 after >>setting the param to vtophys(kernel virtual address). >> >> > >You are suppose to return 0 on success (that the permission are correct >and doable i.e. that you can write when the write bit is set) and put >the phys adder in paddr... > > > There was a bug in my interface routine which probably resulted in too many calls. Something like *paddr=vtophys(base) instead of *paddr=vtophys(base+offset) should result in lots of calls to the interface. >If you look at sys/vm/device_pager.c, you'll see that on line 139, it >makes sure that the permissions are correct for the entire mapping >(that the user doesn't try to map for writing a read-only mapping)... > >Then later at line 222, is when the actual mapping gets done.. > > > Thanks. My mmap interface is not strict about permissions [just denies PROT_EXEC]. regards -kamal