Discussion:
/dev/mem contains physical memory addresses?
Daniel Rodrick
2006-07-06 09:36:29 UTC
Permalink
Hi list,

I read that the /dev/mem represents the memory of the system.

1) Does that mean I can if start reading from /dev/mem, I can read any
portion of the memory?

2) If I read at offset "n" in the file /dev/mem, would I be reading
contents of the PHYSICAL memory address "n", or the VIRTUAL memory
addtress "n"?

Thanks,

Dan.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Arjan van de Ven
2006-07-06 09:44:59 UTC
Permalink
Post by Daniel Rodrick
Hi list,
I read that the /dev/mem represents the memory of the system.
1) Does that mean I can if start reading from /dev/mem, I can read any
portion of the memory?
depends on your kernel; several distributions apply security patches
that prevent rootkits from doing evil things in /dev/mem; with those you
can only access non-kernel memory via /dev/mem
Post by Daniel Rodrick
2) If I read at offset "n" in the file /dev/mem, would I be reading
contents of the PHYSICAL memory address "n", or the VIRTUAL memory
addtress "n"?
PHYSICAL. if you want virutal you need to use /dev/kmem.


-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
George Zhim
2006-07-06 17:51:12 UTC
Permalink
Hi!
Post by Arjan van de Ven
PHYSICAL. if you want virutal you need to use /dev/kmem.
isn't /dev/kmem some sort of core file with structures resembling core files ?
how does that relate to virtual memory (isn't virtual memory unique
per process) ?


(btw is there any documentation regarding /dev/kmem ? couldn't really find...)

thanks,
George.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Arjan van de Ven
2006-07-06 18:07:47 UTC
Permalink
Post by George Zhim
Hi!
Post by Arjan van de Ven
PHYSICAL. if you want virutal you need to use /dev/kmem.
isn't /dev/kmem some sort of core file with structures resembling core files ?
no that's /proc/kcore
Post by George Zhim
how does that relate to virtual memory (isn't virtual memory unique
per process) ?
it's the kernels view of its virtual memory




-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Om.
2006-07-07 04:37:10 UTC
Permalink
Hi!
Post by Arjan van de Ven
PHYSICAL. if you want virutal you need to use /dev/kmem.
How about peripheral memory mapped to some addresses? Assuming I have
a PCI device and a on board flash PROM, would I be able to see them in
/proc/mem

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Om.
2006-07-07 04:45:19 UTC
Permalink
Hi!
Post by Arjan van de Ven
PHYSICAL. if you want virutal you need to use /dev/kmem.
How about peripheral memory mapped to some addresses? Assuming I have
a PCI device and a on board flash PROM, would I be able to see them in
/proc/(k)mem ? I feel not. Am I correct?

Regards,
om.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Arjan van de Ven
2006-07-07 05:36:59 UTC
Permalink
Post by Om.
Hi!
Post by Arjan van de Ven
PHYSICAL. if you want virutal you need to use /dev/kmem.
How about peripheral memory mapped to some addresses? Assuming I have
a PCI device and a on board flash PROM, would I be able to see them in
/proc/(k)mem ? I feel not. Am I correct?
/dev/mem yes

HOWEVER, there is a much nicer way to mmap a PCI device's resources, and
that is sysfs.
/sys/bus/pci/devices/0000:00:02.0/resource0
for example is the first resource of a PCI device on my system.
No need to muck about with the dangerous /dev/mem; this one is at least
well defined and portable across systems, including virtualization etc
etc


-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Daniel Rodrick
2006-07-07 05:58:54 UTC
Permalink
Post by Arjan van de Ven
Post by Om.
How about peripheral memory mapped to some addresses? Assuming I have
a PCI device and a on board flash PROM, would I be able to see them in
/proc/(k)mem ? I feel not. Am I correct?
/dev/mem yes
HOWEVER, there is a much nicer way to mmap a PCI device's resources, and
that is sysfs.
/sys/bus/pci/devices/0000:00:02.0/resource0
for example is the first resource of a PCI device on my system.
No need to muck about with the dangerous /dev/mem; this one is at least
well defined and portable across systems, including virtualization etc
etc
So you mean to say that if I have a device whose registers are are
memory mapped to say physical addresses "0x20020000 - 0x20020010".
Then the file /sys/bus/pci/devices/0000:00:02.0/resource0 will contain
thsi memory range as its contents?

Thanks,

Dan

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Arjan van de Ven
2006-07-07 06:03:41 UTC
Permalink
Post by Daniel Rodrick
Post by Arjan van de Ven
Post by Om.
How about peripheral memory mapped to some addresses? Assuming I have
a PCI device and a on board flash PROM, would I be able to see them in
/proc/(k)mem ? I feel not. Am I correct?
/dev/mem yes
HOWEVER, there is a much nicer way to mmap a PCI device's resources, and
that is sysfs.
/sys/bus/pci/devices/0000:00:02.0/resource0
for example is the first resource of a PCI device on my system.
No need to muck about with the dangerous /dev/mem; this one is at least
well defined and portable across systems, including virtualization etc
etc
So you mean to say that if I have a device whose registers are are
memory mapped to say physical addresses "0x20020000 - 0x20020010".
Then the file /sys/bus/pci/devices/0000:00:02.0/resource0 will contain
thsi memory range as its contents?
well assuming the device is 00:02.0 on the bus (obviously you need to
find the right device) and that it's the first resource of the device,
then yes. (and you have to mmap it, not "read"/"write")

lspci -v is your friend in finding out which resource and which device
it is...


Greetings,
Arjan van de Ven


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/

Jinesh K J
2006-07-06 09:49:45 UTC
Permalink
Post by Daniel Rodrick
Hi list,
I read that the /dev/mem represents the memory of the system.
1) Does that mean I can if start reading from /dev/mem, I can read any
portion of the memory?
2) If I read at offset "n" in the file /dev/mem, would I be reading
contents of the PHYSICAL memory address "n", or the VIRTUAL memory
addtress "n"?
You'll be accessing only PHYSICAL since VIRTUAL addresses are not
unique and global. But, its possible that the physical memory that
you're accessing is a part of the virtual address space of some user
program running in the system.

Jinesh.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Continue reading on narkive:
Loading...