Re: mmap oddness

Linus Torvalds (torvalds@transmeta.com)
Thu, 2 Apr 1998 11:10:38 -0800 (PST)


On Thu, 2 Apr 1998 yodaiken@chelm.cs.nmt.edu wrote:
>
> mmap does not map /dev/mem or /dev/kmem correctly or I don't understand
> what it is supposed to do.
>
> 1. insmod a module that kmallocs a page and writes an identifier
> on the page and then printks the virt_to_phys and address.
> 2. a user task opens /dev/mem or /dev/kmem and reads every page
> looking for the identifier -- the identifier is found at exactly
> the expected position.
> 3. a user task opens /dev/mem or /dev/kmem and mmaps the page with the
> identifier -- no identifier found.
> 4. the task in (3) is modified to try every page in mem or kmem -- no
> identifier found.
> 5. If the kernel buffer is allocated statically, everything works as
> expected.
>
> This is on 2.1.89, but is the same on a couple of other versions.

This is because the kernel will refuse any mmap access to any memory pages
that the kernel may be using. That includes all normal memory.

The _only_ way to get a mmap of memory is to mmap something that is
- outside the normal kernel range. This includes stuff like PCI frame
buffers etc, because the kernel knows that it is not trying to manage
that as memory.
- marked as reserved. This includes the 640k-1M region, and can be
expanded (as done by the sound driver).

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu