From owner-freebsd-hackers@freebsd.org Mon Feb 20 10:09:16 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DD4BACE5036 for ; Mon, 20 Feb 2017 10:09:16 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5DAA41FF6 for ; Mon, 20 Feb 2017 10:09:16 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id v1KA99WK022953 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 20 Feb 2017 12:09:09 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua v1KA99WK022953 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id v1KA9849022952; Mon, 20 Feb 2017 12:09:08 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 20 Feb 2017 12:09:08 +0200 From: Konstantin Belousov To: Chuck Tuffli Cc: freebsd-hackers@freebsd.org Subject: Re: how to map kernel memory to user space Message-ID: <20170220100908.GA2092@kib.kiev.ua> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.2 (2016-11-26) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Feb 2017 10:09:17 -0000 On Sun, Feb 19, 2017 at 03:59:24PM -0800, Chuck Tuffli wrote: > I'm trying to work around a problem by mapping the data from a kernel > allocated buffer into a user space application. There was a post some > time back with a possible way to do this [1], but while this creates a > valid buffer in the user space application, the contents is all zeros > instead of containing the expected data. Is this approach not > possible? Does anything obviously stick out below? TIA. You generally cannot map arbitrary kernel data into userspace and expect things not to break. We have shm_map(9)/shm_unmap(9) functions which allow to map posix shared object into the KVA. Userspace would map object by a file descriptor, either allocated by userspace and then passed to kernel, or allocated by kernel and returned to userspace. In any case, such setup requires coordination between kernel and userspace, and using a specific memory for this to work. Code below is not functional. > > --chuck > > rc = vm_map_lookup(&kernel_map, kaddr, VM_PROT_ALL, > &entry, &obj, &pindex, > &prot, &is_wired); > > vm_map_lookup_done(kernel_map, entry); > if (rc) printf("%s: vm_map_lookup() = %d\n", __func__, rc); > > PROC_LOCK(p); > uaddr = round_page((vm_offset_t)vms->vm_daddr + lim_max(td, RLIMIT_DATA)); > PROC_UNLOCK(p); > > objoff = kaddr - (entry->start + entry->offset); > > vm_object_reference(obj); > rc = vm_map_find(map, > obj, > objoff, > &uaddr, > sizeof(struct nvme_controller_data), > 0, > VMFS_OPTIMAL_SPACE, > VM_PROT_RW, > VM_PROT_RW, > MAP_INHERIT_SHARE); > > [1] http://markmail.org/message/ph5yuonevqjhhbig > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"