Re: mapping user space buffer to kernel address space

From: Jeff Garzik (jgarzik@mandrakesoft.com)
Date: Thu Oct 19 2000 - 16:16:14 EST


Linus Torvalds wrote:
> and quite frankly we should just change the damn "nopage()" arguments to
> be
>
> struct page * (*nopage)(struct vm_area_struct * area, unsigned long pgoff, int write_access);
>
> because the nopage() routine really shouldn't care about "address" at all
> (the VM layer cares, but "nopage()" should just return the proper page at
> the proper offset into the mapping).

fine with me, it makes my code even shorter. ;-) This new mmap
solution is really elegant. Excluding all the debug code and assertions
I stick in there, the guts of via audio mmap support went from ~50 lines
to ~10.

> > The first draft of code had only
> >
> > vma->vm_ops = &via_mm_ops;
> > vma->vm_private_data = card;
> >
> > and userspace apps segfaulted. I then added the two objectionable
> > lines, and things started working:
> >
> > vma->vm_flags |= VM_LOCKED | VM_SHM; /* Don't swap */
> > vma->vm_file = file;
> >
> > Have not yet checked any combinations in between...
>
> Ahh, I think I see why. You should do a "get_page()" on the page before
> you return it from your nopage() - otherwise your page counts will be
> completely wrong.
>
> Actually, as far as I can tell your page counts ended up being wrong
> anyway, but probably only at the end of the munmap() rather than at
> runtime.

Thanks, fixed.

I stole the last two lines from drivers/char/drm/vm.c, which might need
to be fixed up also.. He uses the vm_flags above and nevers calls
get_page, at the very least.

        Jeff

-- 
Jeff Garzik                    | The difference between laziness and
Building 1024                  | prioritization is the end result.
MandrakeSoft                   |
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/



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