public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Walking all the physical memory in an x86 system
@ 2004-11-30 15:41 Hanson, Jonathan M
  2004-11-30 15:55 ` Jan Engelhardt
  0 siblings, 1 reply; 19+ messages in thread
From: Hanson, Jonathan M @ 2004-11-30 15:41 UTC (permalink / raw)
  To: linux-kernel

	I've written a 2.4 kernel module where I'm trying to walk and
record all of the physical memory contents in an x86 system. I have the
following code fragment that does it but I suspect I'm missing a portion
of the memory:

unsigned long memory_address = PAGE_OFFSET;
struct sysinfo RC_sys_info;

si_meminfo(&RC_sys_info);

while (__pa(memory_address) < RC_sys_info.totalram * PAGE_SIZE)
{
	/* Read and record memory contents here. */
	memory_address += 4;
}

Is there a better way to record all of the contents of physical memory
since what I have above doesn't seem to get everything?


^ permalink raw reply	[flat|nested] 19+ messages in thread
* RE: Walking all the physical memory in an x86 system
@ 2004-11-30 16:09 Hanson, Jonathan M
  2004-11-30 16:10 ` Jan Engelhardt
  2004-11-30 16:12 ` Jan Engelhardt
  0 siblings, 2 replies; 19+ messages in thread
From: Hanson, Jonathan M @ 2004-11-30 16:09 UTC (permalink / raw)
  To: jengelh; +Cc: linux-kernel



-----Original Message-----
From: Jan Engelhardt [mailto:jengelh@linux01.gwdg.de] 
Sent: Tuesday, November 30, 2004 8:55 AM
To: Hanson, Jonathan M
Cc: linux-kernel@vger.kernel.org
Subject: Re: Walking all the physical memory in an x86 system

>	I've written a 2.4 kernel module where I'm trying to walk and
>record all of the physical memory contents in an x86 system. I have the
>following code fragment that does it but I suspect I'm missing a
portion
>of the memory:
>
>Is there a better way to record all of the contents of physical memory
>since what I have above doesn't seem to get everything?

Maybe something userspace based?

dd_rescue /dev/mem copyofmem


[Jon M. Hanson] I'm not sure what dd_rescue is as I've never heard of
it. However, I don't think such an operation can be done from userspace
because I need the physical addresses of memory not the virtual ones.


^ permalink raw reply	[flat|nested] 19+ messages in thread
* RE: Walking all the physical memory in an x86 system
@ 2004-11-30 21:16 Hanson, Jonathan M
  2004-11-30 21:26 ` linux-os
  2004-11-30 21:28 ` Jan Engelhardt
  0 siblings, 2 replies; 19+ messages in thread
From: Hanson, Jonathan M @ 2004-11-30 21:16 UTC (permalink / raw)
  To: jengelh; +Cc: linux-kernel



-----Original Message-----
From: linux-kernel-owner@vger.kernel.org
[mailto:linux-kernel-owner@vger.kernel.org] On Behalf Of Jan Engelhardt
Sent: Tuesday, November 30, 2004 9:10 AM
To: Hanson, Jonathan M
Cc: linux-kernel@vger.kernel.org
Subject: RE: Walking all the physical memory in an x86 system

>>dd_rescue /dev/mem copyofmem
>
>I'm not sure what dd_rescue is as I've never heard of
>it. However, I don't think such an operation can be done from userspace
>because I need the physical addresses of memory not the virtual ones.

/dev/mem *is* physical.

[Jon M. Hanson] I can read /dev/mem from a userspace application as root
with no problems and print out what it sees. However, things are not so
simple from a kernel module as I just can't call open() and read() on
/dev/mem because no such functions are exported from the kernel. Is
there a way to read the contents of /dev/mem from a kernel module?



^ permalink raw reply	[flat|nested] 19+ messages in thread
* RE: Walking all the physical memory in an x86 system
@ 2004-11-30 21:36 Hanson, Jonathan M
  0 siblings, 0 replies; 19+ messages in thread
From: Hanson, Jonathan M @ 2004-11-30 21:36 UTC (permalink / raw)
  To: jengelh; +Cc: linux-kernel



-----Original Message-----
From: Jan Engelhardt [mailto:jengelh@linux01.gwdg.de] 
Sent: Tuesday, November 30, 2004 2:28 PM
To: Hanson, Jonathan M
Cc: linux-kernel@vger.kernel.org
Subject: RE: Walking all the physical memory in an x86 system

>[Jon M. Hanson] I can read /dev/mem from a userspace application as
root
>with no problems and print out what it sees. However, things are not so
>simple from a kernel module as I just can't call open() and read() on
>/dev/mem because no such functions are exported from the kernel. Is
>there a way to read the contents of /dev/mem from a kernel module?

You can use filp_open().


Jan Engelhardt
-- 
ENOSPC

[Jon M. Hanson] I tried the filp_open() approach like this:

struct file *mem_fd;

mem_fd = filp_open("/dev/mem", O_RDONLY | O_LARGEFILE, 0);

I then have a check if IS_ERR(mem_fd) is true immediately afterwards
along with a printk saying it failed. This condition is true when I ran
it.



^ permalink raw reply	[flat|nested] 19+ messages in thread
* RE: Walking all the physical memory in an x86 system
@ 2004-11-30 23:24 Hanson, Jonathan M
  2004-12-01  8:37 ` Jan Engelhardt
  0 siblings, 1 reply; 19+ messages in thread
From: Hanson, Jonathan M @ 2004-11-30 23:24 UTC (permalink / raw)
  To: jengelh; +Cc: linux-kernel


-----Original Message-----
From: Jan Engelhardt [mailto:jengelh@linux01.gwdg.de] 
Sent: Tuesday, November 30, 2004 2:28 PM
To: Hanson, Jonathan M
Cc: linux-kernel@vger.kernel.org
Subject: RE: Walking all the physical memory in an x86 system

>[Jon M. Hanson] I can read /dev/mem from a userspace application as
root
>with no problems and print out what it sees. However, things are not so
>simple from a kernel module as I just can't call open() and read() on
>/dev/mem because no such functions are exported from the kernel. Is
>there a way to read the contents of /dev/mem from a kernel module?

You can use filp_open().


Jan Engelhardt
-- 
ENOSPC

[Jon M. Hanson] I tried the filp_open() approach like this:

struct file *mem_fd;

mem_fd = filp_open("/dev/mem", O_RDONLY | O_LARGEFILE, 0);

I then have a check if IS_ERR(mem_fd) is true immediately afterwards
along with a printk saying it failed. This condition is true when I ran
it. It seems to fail with -EACCES (permission denied) as the error code.

I can see the exact code that's causing the -EACCES in open_namei(). It
makes a check if the thing being opened is a character device and
returns the -EACCES, so obviously filp_open() can't do this.

I can run a program as root and open /dev/mem and read it without any
problems. Surely there is a way to do the same thing within a kernel
module.




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

end of thread, other threads:[~2004-12-01  8:38 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-30 15:41 Walking all the physical memory in an x86 system Hanson, Jonathan M
2004-11-30 15:55 ` Jan Engelhardt
2004-11-30 16:01   ` P
2004-11-30 16:10     ` linux-os
  -- strict thread matches above, loose matches on Subject: below --
2004-11-30 16:09 Hanson, Jonathan M
2004-11-30 16:10 ` Jan Engelhardt
2004-11-30 16:12 ` Jan Engelhardt
2004-11-30 17:17   ` Erik Mouw
     [not found]   ` <41ACADD3.2030206@draigBrady.com>
2004-11-30 17:34     ` Jan Engelhardt
2004-11-30 18:50       ` Alan Cox
2004-11-30 20:25         ` linux-os
2004-11-30 20:46           ` Jan Engelhardt
2004-11-30 20:28             ` Alan Cox
2004-11-30 21:16 Hanson, Jonathan M
2004-11-30 21:26 ` linux-os
2004-11-30 21:28 ` Jan Engelhardt
2004-11-30 21:36 Hanson, Jonathan M
2004-11-30 23:24 Hanson, Jonathan M
2004-12-01  8:37 ` Jan Engelhardt

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