Date: Wed, 29 Jul 2015 15:26:46 -0700 From: Laurie Jennings <laurie_jennings_1977@yahoo.com> To: John Baldwin <jhb@freebsd.org> Cc: freebsd-net@freebsd.org Subject: Locking Memory Question Message-ID: <1438208806.66724.YahooMailBasic@web141505.mail.bf1.yahoo.com> In-Reply-To: <201310151521.25231.jhb@freebsd.org>
index | next in thread | previous in thread | raw e-mail
I have a problem and I can't quite figure out where to look. This is what Im doing:
I have an IOCTL to read a block of data, but the data is too large to return via ioctl. So to get the data,
I allocate a block in a kernel module:
foo = malloc(1024000,M_DEVBUF,M_WAITOK);
I pass up a pointer and in user space map it using /dev/kmem:
fd = open("/dev/kmem",O_RDWR);
if (fd > 0){
memp = mmap(0,1024000,PROT_READ,MAP_SHARED,fd,p);
and then grab the data from memp (It's a stringified object).
The problem is that sometimes it's garbage. 95% of the time it works fine. I figured that the memory wasn't wired and I've been trying to wire
it but not having much success. kmem_alloc() and kmem_malloc() panic in vm_map_lock, so Im guessing that you can't do this in an IOCTL call?
So my questions:
1) Shouldn't kmem mapped memory be wired? how else could you reliable read kernel memory?
2) Why does kmem_alloc() panic
kmem_alloc(kernel_map, 1024000);
3) is there a function to allocate and free a wired block?
4) how could I reliably wire a block allocated with malloc. Can it be done somehow with vm_map_wire()? I can't
get it to work.
5) What does MAP_PREFAULT_READ do and would it solve this problem?
Thanks,
Laurie
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1438208806.66724.YahooMailBasic>
