Re: mapping user space buffer to kernel address space

From: Linus Torvalds (torvalds@transmeta.com)
Date: Tue Oct 17 2000 - 23:26:07 EST


On Wed, 18 Oct 2000, Andrea Arcangeli wrote:

> On Tue, Oct 17, 2000 at 02:04:10PM -0700, Linus Torvalds wrote:
> > It so happens that the vmscan stuff won't ever remove a physical page
> > mapping, but that's simply because such a page CANNOT be swapped out. How
>
> So if I write a mechanism that allows those driver-private-pages that are used
> for DMA of a soundcard to be swapped out, then you would remove the
> PG_referenced bitflag from them too?

PG_referenced?

Maybe you mean PG_reserved?

Anyway, I didn't realize you were talking about the sound drivers use of
remap_page_range(). That's not the original reason for remap_page_range()
at all, and in fact it's the _ugly_ way to do things. It's simple and it
works, but it's not pretty.

Quite frankly, the way I'd conceptually prefer people do these kinds of
DMA buffers etc is to just have a "nopage()" function, and let that
nopage() function just fill in the page from the DMA buffer directly. This
would work fine, and would get rid of all the playing with PG_reserved
etc.

Obviously, such a page would never really get swapped out: you'd have a
"swapout()" function that would be a no-op (as the page would not truly be
swapped out: the page is actually held by the driver inside the kernel,
and the user mapping is just a _window_ into that kernel buffer).

Now, remap_page_range() ends up giving this same functionality without
sound drivers needing to have nopage() or swapout() functions at all, and
obviously it's trivial to do this way. But you should realize that this
use of remap_page_range() is very much a hack - the whole point of
remap_page_range() was always to do the PCI (and legacy ISA region)
mapping for things like the X server etc that access hardware directly.

I hated people mis-using it the way it's being done by the sound drivers,
but because I also realize that it allows for some simplifications I do
accept it - it's basically an ugly hack that doesn't really matter because
the exact same code _is_ needed for the real IO mapping case anyway, and
as far as the kernel is concerned the whole thing with PG_reserved is all
just a game to make the kernel VM subsystem think that some real RAM is
actually IO space and shouldn't be touched.

But for going the other way (ie moving a user space page into kernel
space, a la kiobuf mapping) is rather different, and I think it would be a
big ugly hairy lie to mark such a user space page be "PCI memory", because
that user space page might in fact be a page cache page etc. It's not at
all the same kind of controlled lie that the sound driver ugly hack is..

                Linus

-
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:12 EST