How can I test if a physical address is already mapped or not.

Rajat Sharma fs.rajat at gmail.com
Wed Oct 19 01:48:00 EDT 2011


On Wed, Oct 19, 2011 at 6:46 AM, Jeff Haran <jharan at bytemobile.com> wrote:
>> -----Original Message-----
>> From: StephanT [mailto:stman937-linewbie at yahoo.com]
>> Sent: Tuesday, October 18, 2011 6:01 PM
>> To: Jeff Haran; kernelnewbies
>> Subject: Re: How can I test if a physical address is already mapped or not.
>>
>>
>>
>> >>  Yes you are right when you are in user space. However in a kernel
>> >>  module this would be physical address.
>> >
>> > Nope. Unless you are using some really strange processor that I am not
>> familiar
>> > with, a memory read is a memory read. *pReg is going to read what's at
>> > virtual address 0xc0000000 regardless of whether you are executing in user
>> or
>> > kernel context. I know it's going to work this way on a PC with an Intel x86
>> > processor.
>> >
>>
>>
>> OK, but how do you explain I can read 0xC0000000 and I get kicked out if
>> I try 0x00100000.
>
> I can only assume that there is nothing mapped to virtual address 0x00100000. On a 32 bit PC, the bottom 3 GB of virtual memory is by default mapped to user space, so if anything you are accessing memory in the current process' virtual memory.
>
>>
>> >>  The 0xC0000000 falls under PCI address range. I guess on a PC Linux
>> >>  just doesn't map this address range or it maps it one2one (phys==virt)
>> >>  I can dereference this address and I get something plausible.
>> >
>> > On most 32 bit Intel processors running "standard" Linux 0xC0000000 is
>> > the first address of kernel VM. This is a function of kernel configuration, but
>> > it's this way by default. It's still a virtual address. So yes, on your
>> > PC virtual address 0xC0000000 is mapped to physical RAM.
>> >
>>
>>
>> Would this mean by reading the 0xC0000000 I am reading the Linux code not
>> PCI registers?
>
> First part of the page table, I think. I don't really remember what the kernel maps down there but I don't think its code.
> Read the Gorman book. It's a lot to get through, but you'll likely learn a lot. There might even be something newer out there.
>
> Jeff Haran
>
>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

Stephan,

>From your post it looks like you are trying to simulate environment on
Embedded Linux board to your PC? Did you check if embedded Linux has
CONFIG_MMU kernel config option set? If that is the case then you
might be bypassing page-table translation on your board and CPU
assumes virtual address = physical address in that case. However same
may not be true on PC which uses page-tables.

"Understanding Linux Kernel" book is also a good reference for
understanding memory management in Linux.

One Advice: when shifting from one hardware to another, be ready for
surprises and open to unlearn things :)

Thanks,
Rajat



More information about the Kernelnewbies mailing list