Locking Memory Question

Laurie Jennings laurie_jennings_1977 at yahoo.com
Wed Jul 29 22:26:54 UTC 2015


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


More information about the freebsd-net mailing list