Date: Mon, 29 Jul 2019 11:00:29 -0700 From: John Baldwin <jhb@FreeBSD.org> To: Laurie Jennings <laurie_jennings_1977@yahoo.com>, FreeBSD Net <freebsd-net@freebsd.org> Cc: Konstantin Belousov <kostikbel@gmail.com> Subject: Re: mmap kernel chunk into user space Message-ID: <4e1e8544-6205-3a38-7267-ada19c862e62@FreeBSD.org> In-Reply-To: <2146491394.4652133.1563758485195@mail.yahoo.com> References: <2146491394.4652133.1563758485195.ref@mail.yahoo.com> <2146491394.4652133.1563758485195@mail.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 7/21/19 6:21 PM, Laurie Jennings wrote: > > Im wondering if there have been changes to the api since FreeBSD 9 as I can't get some code I'm porting to work. > I have a block of kernel memory wired down and I want to map it to user space. Its just a big structure that has stats and other volatile info. In 9.x I was able to simply do: > // kptr has the kernel address obtained from an ioctl call > > fd=open("/dev/kmem",O_RDWR);memp=mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,(off_t)kptr); > > And it just worked. In 11.3 it fails, and I havent been able to get ANYTHING to work with this method. I'm open to another method; I read something about mmap no longer supportinjgkmem. In which case, what can I do? Supporting arbitrary mmap of /dev/kmem is not safe as the user mappings weren't updated if the kernel mappings changed. To do what you want, you would create a dedicated device in /dev that you can mmap to access your data structure. The simplest way is to just have your device's d_mmap callback use the offset as an offset into your in-kernel pointer and then use pmap_kextract() to get the physical address to return. A fancier version would be to build an sglist describing your buffer and create an OBJT_SG VM object that you returned from the d_mmap_single callback, but if you only ever have a single object that is never freed, the simple version will work fine. -- John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4e1e8544-6205-3a38-7267-ada19c862e62>