Date: Mon, 20 Feb 2017 12:09:08 +0200 From: Konstantin Belousov <kostikbel@gmail.com> To: Chuck Tuffli <ctuffli@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: how to map kernel memory to user space Message-ID: <20170220100908.GA2092@kib.kiev.ua> In-Reply-To: <CAKAYmML%2B%2BPHotoQ-uupQUJUevKFPH6SZ-KEUwC_idL3TZp7p7A@mail.gmail.com> References: <CAKAYmML%2B%2BPHotoQ-uupQUJUevKFPH6SZ-KEUwC_idL3TZp7p7A@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170220100908.GA2092>