From owner-freebsd-hackers@FreeBSD.ORG Sat Jan 26 01:22:24 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6EB4C16A41A for ; Sat, 26 Jan 2008 01:22:24 +0000 (UTC) (envelope-from john.giacomoni@colorado.edu) Received: from suburban.colorado.edu (suburban.colorado.edu [128.138.189.14]) by mx1.freebsd.org (Postfix) with ESMTP id 3504013C45A for ; Sat, 26 Jan 2008 01:22:24 +0000 (UTC) (envelope-from john.giacomoni@colorado.edu) Received: from localhost (suburban.colorado.edu [127.0.0.1]) by suburban.colorado.edu (8.13.1/8.13.1) with ESMTP id m0PMSFM6009765 for ; Fri, 25 Jan 2008 17:28:15 -0500 Message-Id: <50CFFC1C-1831-442A-A430-79E99D54B2EF@colorado.edu> From: John Giacomoni To: freebsd-hackers@freebsd.org Content-Type: multipart/mixed; boundary=Apple-Mail-123--334955921 Mime-Version: 1.0 (Apple Message framework v915) Date: Fri, 25 Jan 2008 18:22:23 -0700 X-Mailer: Apple Mail (2.915) X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: how to map a vm_object the same vm address in user and kernel space? 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, 26 Jan 2008 01:22:24 -0000 --Apple-Mail-123--334955921 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit I'm trying to share memory between the kernel and userspace so that I can communicate between kernel threads and userspace threads with concurrent lock-free data structures. I can do this if I use different virtual addresses in the kernel and addresses in userspace. However, this requires that I swizzle any pointers stored in the shared memory region. Is there a way to fix the virtual address as a kernel address but permit userspace threads to dereference it without triggering a segmentation fault? This is a sketch of the code that I'm trying to use to map the object into userspace addresses. struct proc *p = td->td_proc; vm_map_t map = &p->p_vmspace->vm_map; // setup *addr to bind to the premapped kernel address space *addr = kernel_addr_for_obj // circumvent the address range checks *ugly and probably wrong* map->max_offset = kernel_map->max_offset; vm_object_reference(obj); err = vm_map_find(map,obj,0,(vm_offset_t*)addr, size, 0, prot, prot, 0); err = vm_map_wire(map, (vm_offset_t) *addr, (vm_offset_t) *addr + size, VM_MAP_WIRE_USER); At this point the virtual addresses are the same and the virtual address points to the same physical address. pmap_extract(map->pmap, (vm_offset_t)*addr) However, when the userspace thread attempt to dereference the first page, it causes a segfault. looking at the U/S bit in the PTE for the first page, the U bit is cleared. pte = pmap_pte(map->pmap, (vm_offset_t) *addr); How do I set this cleanly for all the pages used to back the object? Thanks John Giacomoni -- John.Giacomoni@colorado.edu University of Colorado at Boulder Department of Computer Science Engineering Center, ECCR 1B50 430 UCB Boulder, CO 80303-0430 USA --Apple-Mail-123--334955921 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit --Apple-Mail-123--334955921--