From owner-freebsd-hackers@FreeBSD.ORG Mon Jul 31 21:17:42 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org 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 46C4416A4E2; Mon, 31 Jul 2006 21:17:42 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (66-23-211-162.clients.speedfactory.net [66.23.211.162]) by mx1.FreeBSD.org (Postfix) with ESMTP id E918343D46; Mon, 31 Jul 2006 21:17:39 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.13.4/8.13.4) with ESMTP id k6VLHVZI073824; Mon, 31 Jul 2006 17:17:33 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Mon, 31 Jul 2006 16:39:24 -0400 User-Agent: KMail/1.9.1 References: <20060730105731.GA64955@stud.fit.vutbr.cz> <20060730200354.GA82547@stud.fit.vutbr.cz> <3bbf2fe10607311115ua9b7b9axd9d3e6dcff2c1daf@mail.gmail.com> In-Reply-To: <3bbf2fe10607311115ua9b7b9axd9d3e6dcff2c1daf@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200607311639.24810.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Mon, 31 Jul 2006 17:17:34 -0400 (EDT) X-Virus-Scanned: ClamAV 0.87.1/1627/Sun Jul 30 19:34:54 2006 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.0 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on server.baldwin.cx Cc: Attilio Rao , Divacky Roman Subject: Re: VM question related to faults 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: Mon, 31 Jul 2006 21:17:42 -0000 On Monday 31 July 2006 14:15, Attilio Rao wrote: > 2006/7/30, Divacky Roman : > > On Sun, Jul 30, 2006 at 12:57:32PM +0200, Divacky Roman wrote: > > > hi, > > > > > > while working on SoC linuxolator project I am in a need of this: > > > > > > I need to do some operation on memory like mem1 = mem1 + mem2 etc. > > > where the mem1/mem2 access can trigger fault. (memory not mapped or something) > > > > to make it clear.. I am trying to access user-space memory from kernel. > > This needs to be atomic (its an implementation of linux futexes) > > > > I need to check from kernel if some memory is accessible and then perform an > > operation on this memory. All atomically. > > > > hence I need two things - function which checks wheter the memory is accessible > > and something which makes it atomic (some mutex/something which prevents other > > process to enter VM to unmap/etc. the memory in question) > > > > hope its a bit more clear now > > You would use something like: > > #include > #include > #include > #include > #include > #include > #include > > #include > > ... > int > lock_and_fetch(const void* mem1, const void *mem2) > { > > mtx_lock(&vm_page_queue_mtx); > if (fubyte(mem1) == -1 || fubyte(mem2) == -1) { > mtx_unlock(&vm_page_queue_mtx); > return(EINVAL); > } > /* Operations... */ > mtx_unlock(&vm_page_queue_mtx); > > return(0); > } > > It prevents to virtual pages to be passed through queues. Erm, but if fubyte() had to page the file in from disk you would have to sleep while holding the vm_page_queue_mtx, and that's not allowed. -- John Baldwin