mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* What's the reason that /dev/mem can't map unreserved RAM?
@ 2003-04-17 18:21 Steven Rostedt
  2003-04-17 20:05 ` Hugh Dickins
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2003-04-17 18:21 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: srostedt

Hi all,

What's the rational behind /dev/mem not being able to map unreserved RAM?
It can't be for protecting the system, because if you have access to 
reserved RAM (kernel text) then you can modify the remap_pte_range to 
allow for mapping of ram.

I have a user program for debugging kernel modules and the like, and it 
uses /dev/mem to map ram and prints it out. But unless I take out the 
check in remap_pte_range, I can't see allocated pages.

I just want to know the rational behind this.

Thanks,

-- Steve



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: What's the reason that /dev/mem can't map unreserved RAM?
  2003-04-17 18:21 What's the reason that /dev/mem can't map unreserved RAM? Steven Rostedt
@ 2003-04-17 20:05 ` Hugh Dickins
  2003-04-17 20:45   ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Hugh Dickins @ 2003-04-17 20:05 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Linux Kernel Mailing List, srostedt

On Thu, 17 Apr 2003, Steven Rostedt wrote:
> 
> What's the rational behind /dev/mem not being able to map unreserved RAM?
> It can't be for protecting the system, because if you have access to 
> reserved RAM (kernel text) then you can modify the remap_pte_range to 
> allow for mapping of ram.
> 
> I have a user program for debugging kernel modules and the like, and it 
> uses /dev/mem to map ram and prints it out. But unless I take out the 
> check in remap_pte_range, I can't see allocated pages.
> 
> I just want to know the rational behind this.

I understand your surprise and frustration.

The reason is not a very good one, it's just that we haven't
yet done the work to allow unrestrained mapping of /dev/mem.

A mapping of /dev/mem is unlike the usual mapping of a shared file.
I can't explain this at all well: might one say, when you map a file,
you are mapping the pages for the data they currently contain; but
when you map /dev/mem, you are mapping the pages for their frames?

Think about the page->count, think about how in your mapping of
/dev/mem there may be pages which belong to (currently contain
data from) mapped files (and much else besides).

When you munmap your mapping of /dev/mem, that must not free the
pages you had mapped, you don't have any hold on them at all; yet
as things stand (if you were allowed to map unReserved pages),
it would decrement page->count, free unowned pages, cause havoc.

There should be a specific VM_RESERVED flag (there is already but
it's not used in quite this way) to forbid page->count manipulations
on vmas (mappings) of /dev/mem.  But that code is not in place,
so instead this rather ugly PageReserved stuff has hung around.

I did start out on eliminating PageReserved a few months ago,
but was persuaded to delay that until 2.7.  When that's done,
you will be able to mmap /dev/mem properly.

Hugh


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: What's the reason that /dev/mem can't map unreserved RAM?
  2003-04-17 20:05 ` Hugh Dickins
@ 2003-04-17 20:45   ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2003-04-17 20:45 UTC (permalink / raw)
  To: Hugh Dickins; +Cc: rostedt, linux-kernel, srostedt

Hugh Dickins <hugh@veritas.com> wrote:
>
> I did start out on eliminating PageReserved a few months ago,
> but was persuaded to delay that until 2.7.  When that's done,
> you will be able to mmap /dev/mem properly.

I think we can almost do it now.  Just a few things like get_user_pages(),
ptrace and core dumping may need to be taught about VM_RESERVED.

Or we could simply change mmap_mem() to set VM_IO if any of the pages aren't
valid.  That's probably an accurate reflection of what the app is trying to
do, too.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-04-17 20:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-17 18:21 What's the reason that /dev/mem can't map unreserved RAM? Steven Rostedt
2003-04-17 20:05 ` Hugh Dickins
2003-04-17 20:45   ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®