Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Mar 2012 12:23:24 +0000
From:      Eric Saint-Etienne <eric.saintetienne@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: malloc pages map to user space
Message-ID:  <CACJX%2B535YeOwWZodE1w8jiECKbDgyBbZgYDd=M31NwyTMTx83g@mail.gmail.com>
In-Reply-To: <CACJX%2B52DPPYea5k6QxQ6WQ62GEA9YHGr4y=ETUpPArNL83kh5w@mail.gmail.com>
References:  <CACJX%2B52DPPYea5k6QxQ6WQ62GEA9YHGr4y=ETUpPArNL83kh5w@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
I've refined the behaviour I observe, which isn't consistent depending
on the size one mallocates.
(see interleaved comments)

> In my driver, I need to map some malloc-ed memory, obtained from
> another module, into userspace.
>
> The problem: on the smaller mallocs, as well as on some bigeer ones
> (8k seems fine, 64k fails): vm_map_lookup() fails finding the
> underlying vm object.

In the current implementation I'm calling vm_map_lookup() against the kmem_map.
As a result it either return the kmem_object, or fails at all (for
smaller or larger mallocs.)

> Do somebody know how (or better, have a piece of code!) to retrieve
> the vm_object associated with malloc-ed memory? (small and big ones)
>
> As far as I can see in the vm code, there isn't any object associated
> with the slabs (the smaller mallocs), it seems that a huge chunk of
> virtual space is used "as is", so I presume the virtual addresses
> where the SLABs are have some remarkable property, with respect to
> physical addresses, that could allow creating an object from scratch?

By using kernel_map instead of kmem_map, vm_map_lookup() now always
return a vm_object. That's a big progress.
As expected, when this object is kmem_object, the user mapping works
fine (for smaller or larger mallocs.)

Otherwise that object doesn't match kernel_object. It's an anonymous
object to me.
Using that "anonymous" vm_object for mapping into user map (using
vm_map_find()) doesn't directly fail,
it does provide a virtual address in the user map. However I read
zeros at that address, from within the user process.

Any help would be highly appreciated.
Thanks!
Eric



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACJX%2B535YeOwWZodE1w8jiECKbDgyBbZgYDd=M31NwyTMTx83g>