Re: mapping user space buffer to kernel address space

From: Malcolm Beattie (
Date: Fri Oct 13 2000 - 06:30:49 EST writes:
> I have a user buffer and i want to map it to kernel address space
> can anyone tell how to do this like in AIX we have xmattach

In 2.2, you're better off providing a fake character device driver
which allocates the memory in kernel space and lets the user mmap it.
In 2.4, you could try out kiobufs which, if my reading of the section
marked "#ifdef HACKING", "case BTTV_JUST_HACKING" and also
   /* playing with kiobufs and dma-to-userspace */
is correct, goes (modulo error handling) roughly like:

    struct kiobuf *iobuf;
    alloc_kiovec(1, &iobuf); /* allocate a(n array of one) kiobuf */
    map_user_kiobuf(READ, iobuf, va, len); /* userland vaddr and length */
                                           /* s/READ/WRITE/ for write */
    /* now you have an iobuf containing pinned down user pages */
    lock_kiovec(1, &iobuf, 1); /* Lock pages down for I/O */
                               /* first 1 is vector count */
                               /* second means wait for lock */
    .. /* do I/O on it */
    free_kiovec(1, &iobuf); /* does an implicit unlock_kiovec */

It doesn't do an unmap_kiobuf(iobuf) so I don't understand where
the per-page map->count that map_user_kiobuf incremented gets
decremented again. Anyone? Lowlevel I/O on a kiovec can be done
with something like an ll_rw_kiovec which sct said was going to get
put in but since I haven't read anything more recent than
2.4.0-test5 at the moment, I can't say if it's there or what it
looks like.


Malcolm Beattie <>
Unix Systems Programmer
Oxford University Computing Services
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

This archive was generated by hypermail 2b29 : Sun Oct 15 2000 - 21:00:24 EST