Kernel Space Memory Allocation

Kostik Belousov kostikbel at
Thu Oct 27 09:20:55 UTC 2011

On Thu, Oct 27, 2011 at 10:31:43AM +0200, Daniel Grech wrote:
> Hi,
> I am allocating memory from a device driver in the kernel and passing it on
> to another driver. In the other driver it is neccessary for me to determine
> whether the address passed is from user space or kernel space as this driver
> can also be called from user space. I am currently using the following check
> to determine if the address is in kernel space or userspace :
> if ( ( (char *) VM_MIN_KERNEL_ADDRESS <= address) &&  (address <= (char *)
> {
>         KERNEL SPACE
> }
> else
> {
>        USER SPACE
> }
> However, this does not always work. Sometimes although I allocate memory in
> the kernel using the malloc macro, this returns an address which is not in
> the above range. Is there any workaround for this problem?
> Thanks in advance for your help.
Generally, you cannot determine the ownership of the address by its value.
There are architectures that use separate kernel/user address spaces, e.g.
Even for i386, there were a patch that switched page tables on the kernel
entry, allowing the kernel to use whole 4GB of the address space.

The proper way to do what you want is to supply explicit indicator of the
address space referenced by the address. Read uio(9), in particular, look
at the uio_seg.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url :

More information about the freebsd-hackers mailing list