Re: Sharing memory between user and kernel spaces [Re: copy_to/from_user and a bottom half]

From: Andi Kleen (ak@suse.de)
Date: Fri May 19 2000 - 03:57:22 EST


On Fri, May 19, 2000 at 01:12:53AM -0400, Alex Ivchenko wrote:
> 1. App allocates memory in user space (page-aligned).
> (BTW, I didn't find the way of doing it on Linux beside to allocate
> memory with malloc() and then align it to the page boundaries).

mmap()

>
> 2. Inform driver about start address and size.
>
> 3. Driver translates user-space address into its virtual address
> and locks pages into physical memory.
> Now we have two handles (addresses) (kernel and user) to the same
> piece of memory.
>
> 4. Then one can translate kernel-space virtual address into physical
> one to supply to scater-gather BM-capable hardware.
>
> Is it any way to do this with Linux?

The traditional linux way is to implement mmap for your character device,
vmalloc the memory in kernel and supply it to the user process via mmap.

2.3 and some patched 2.2 kernels also offer a way to do this directly
(usion kiovecs and map_user_kiobuf()). This is not in standard 2.2 kernel
though.

It is possible to lock the pages using tricks and map them by hand, but
that is not recommended (and could break under later kernels)

-Andi

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue May 23 2000 - 21:00:16 EST