All of lore.kernel.org
 help / color / mirror / Atom feed
* On virt_to_phys doubts.
@ 2014-09-13  8:02 mind entropy
  2014-09-13  8:31 ` Miles MH Chen
  0 siblings, 1 reply; 7+ messages in thread
From: mind entropy @ 2014-09-13  8:02 UTC (permalink / raw)
  To: kernelnewbies

Hi,

  I want to know the physical address [just for debugging and info.Not
for DMA etc] of a particular virtual address allocated via kmalloc.

   I am running the below code on S3C2440 with 64MB of RAM. The
/proc/meminfo returns

MemTotal:          59164 kB
MemFree:           35884 kB
MemAvailable:      47148 kB


  I run the following module for printing the addresses. [This module
is only for test. So excuse if I have cut corners].

------------------------------------------------

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/printk.h>
#include <linux/module.h>
#include <linux/gfp.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/mm_types.h>
#include <linux/slab.h>

static int vm_mem_test_init(void)
{

    void *km;

    printk(KERN_ALERT "vm mem test init\n");

    km = kmalloc(1,GFP_KERNEL);

    if(km == NULL) {
        printk(KERN_ALERT "Could not kmalloc\n");
        return -1;
    } else {
        printk(KERN_ALERT "Allocated\n");
        printk(KERN_ALERT "Virtual addr : %x\n",(unsigned int)km);
        printk(KERN_ALERT "Kernel physical addr : 0x%x\n",virt_to_phys(km));
        kfree(km);
    }

  return 0;

}


The output for the following is:

Virtual addr : c2c080e0
Kernel physical addr : 0x32c080e0

-----------------------------------------------------------

The kernel physical address is wrong as I only have 64MB. Should I be
doing a kernel page table walk to get the associated physical address?

Thanks
Gautam.

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

* On virt_to_phys doubts.
  2014-09-13  8:02 On virt_to_phys doubts mind entropy
@ 2014-09-13  8:31 ` Miles MH Chen
  2014-09-13 12:59   ` mind entropy
  0 siblings, 1 reply; 7+ messages in thread
From: Miles MH Chen @ 2014-09-13  8:31 UTC (permalink / raw)
  To: kernelnewbies

Hi,

Do you know the value of PHYS_OFFSET of your platform?
PHYS_OFFSET defines the starting physical address of your DRAM.

physical address = kmalloc'ed address - PAGE_OFFSET + PHYS_OFFSET

MH

On Sat, Sep 13, 2014 at 4:02 PM, mind entropy <mindentropy@gmail.com> wrote:

> Hi,
>
>   I want to know the physical address [just for debugging and info.Not
> for DMA etc] of a particular virtual address allocated via kmalloc.
>
>    I am running the below code on S3C2440 with 64MB of RAM. The
> /proc/meminfo returns
>
> MemTotal:          59164 kB
> MemFree:           35884 kB
> MemAvailable:      47148 kB
>
>
>   I run the following module for printing the addresses. [This module
> is only for test. So excuse if I have cut corners].
>
> ------------------------------------------------
>
> #include <linux/init.h>
> #include <linux/kernel.h>
> #include <linux/printk.h>
> #include <linux/module.h>
> #include <linux/gfp.h>
> #include <linux/types.h>
> #include <linux/mm.h>
> #include <linux/mm_types.h>
> #include <linux/slab.h>
>
> static int vm_mem_test_init(void)
> {
>
>     void *km;
>
>     printk(KERN_ALERT "vm mem test init\n");
>
>     km = kmalloc(1,GFP_KERNEL);
>
>     if(km == NULL) {
>         printk(KERN_ALERT "Could not kmalloc\n");
>         return -1;
>     } else {
>         printk(KERN_ALERT "Allocated\n");
>         printk(KERN_ALERT "Virtual addr : %x\n",(unsigned int)km);
>         printk(KERN_ALERT "Kernel physical addr :
> 0x%x\n",virt_to_phys(km));
>         kfree(km);
>     }
>
>   return 0;
>
> }
>
>
> The output for the following is:
>
> Virtual addr : c2c080e0
> Kernel physical addr : 0x32c080e0
>
> -----------------------------------------------------------
>
> The kernel physical address is wrong as I only have 64MB. Should I be
> doing a kernel page table walk to get the associated physical address?
>
> Thanks
> Gautam.
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140913/342faf6a/attachment.html 

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

* On virt_to_phys doubts.
  2014-09-13  8:31 ` Miles MH Chen
@ 2014-09-13 12:59   ` mind entropy
  2014-09-13 13:43     ` Miles MH Chen
  0 siblings, 1 reply; 7+ messages in thread
From: mind entropy @ 2014-09-13 12:59 UTC (permalink / raw)
  To: kernelnewbies

On Sat, Sep 13, 2014 at 2:01 PM, Miles MH Chen <orca.chen@gmail.com> wrote:
> Hi,
>
> Do you know the value of PHYS_OFFSET of your platform?
> PHYS_OFFSET defines the starting physical address of your DRAM.
>
> physical address = kmalloc'ed address - PAGE_OFFSET + PHYS_OFFSET
>
> MH
>
> On Sat, Sep 13, 2014 at 4:02 PM, mind entropy <mindentropy@gmail.com> wrote:
>>
>> Hi,
>>
>>   I want to know the physical address [just for debugging and info.Not
>> for DMA etc] of a particular virtual address allocated via kmalloc.
>>
>>    I am running the below code on S3C2440 with 64MB of RAM. The
>> /proc/meminfo returns
>>
>> MemTotal:          59164 kB
>> MemFree:           35884 kB
>> MemAvailable:      47148 kB
>>
>>
>>   I run the following module for printing the addresses. [This module
>> is only for test. So excuse if I have cut corners].
>>
>> ------------------------------------------------
>>
>> #include <linux/init.h>
>> #include <linux/kernel.h>
>> #include <linux/printk.h>
>> #include <linux/module.h>
>> #include <linux/gfp.h>
>> #include <linux/types.h>
>> #include <linux/mm.h>
>> #include <linux/mm_types.h>
>> #include <linux/slab.h>
>>
>> static int vm_mem_test_init(void)
>> {
>>
>>     void *km;
>>
>>     printk(KERN_ALERT "vm mem test init\n");
>>
>>     km = kmalloc(1,GFP_KERNEL);
>>
>>     if(km == NULL) {
>>         printk(KERN_ALERT "Could not kmalloc\n");
>>         return -1;
>>     } else {
>>         printk(KERN_ALERT "Allocated\n");
>>         printk(KERN_ALERT "Virtual addr : %x\n",(unsigned int)km);
>>         printk(KERN_ALERT "Kernel physical addr :
>> 0x%x\n",virt_to_phys(km));
>>         kfree(km);
>>     }
>>
>>   return 0;
>>
>> }
>>
>>
>> The output for the following is:
>>
>> Virtual addr : c2c080e0
>> Kernel physical addr : 0x32c080e0
>>
>> -----------------------------------------------------------
>>
>> The kernel physical address is wrong as I only have 64MB. Should I be
>> doing a kernel page table walk to get the associated physical address?
>>
>> Thanks
>> Gautam.
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>

Miles,

  I tried printing it. The output is as follows:

Kernel physical addr : 0x32d01fe0
Platform phys offset : 0x30000000
Page offset : 0xc0553fb4

The S3C2440 is an ARM9TDMI processor.


-Gautam.

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

* On virt_to_phys doubts.
  2014-09-13 12:59   ` mind entropy
@ 2014-09-13 13:43     ` Miles MH Chen
  2014-09-13 13:52       ` mind entropy
  0 siblings, 1 reply; 7+ messages in thread
From: Miles MH Chen @ 2014-09-13 13:43 UTC (permalink / raw)
  To: kernelnewbies

Kernel physical addr : 0x32d01fe0
Platform phys offset : 0x30000000
Page offset : 0xc0553fb4

The page offset looks weird, since 32bit kernel has 2/2 or 3/1 or 1/3
user/kernel virtual address  split. It is not reasonable to have 0xc0553fb4
as page offset. You should c0000000 for 3/1 split.
2014/9/13 ??8:59 ? "mind entropy" <mindentropy@gmail.com> ???

> On Sat, Sep 13, 2014 at 2:01 PM, Miles MH Chen <orca.chen@gmail.com>
> wrote:
> > Hi,
> >
> > Do you know the value of PHYS_OFFSET of your platform?
> > PHYS_OFFSET defines the starting physical address of your DRAM.
> >
> > physical address = kmalloc'ed address - PAGE_OFFSET + PHYS_OFFSET
> >
> > MH
> >
> > On Sat, Sep 13, 2014 at 4:02 PM, mind entropy <mindentropy@gmail.com>
> wrote:
> >>
> >> Hi,
> >>
> >>   I want to know the physical address [just for debugging and info.Not
> >> for DMA etc] of a particular virtual address allocated via kmalloc.
> >>
> >>    I am running the below code on S3C2440 with 64MB of RAM. The
> >> /proc/meminfo returns
> >>
> >> MemTotal:          59164 kB
> >> MemFree:           35884 kB
> >> MemAvailable:      47148 kB
> >>
> >>
> >>   I run the following module for printing the addresses. [This module
> >> is only for test. So excuse if I have cut corners].
> >>
> >> ------------------------------------------------
> >>
> >> #include <linux/init.h>
> >> #include <linux/kernel.h>
> >> #include <linux/printk.h>
> >> #include <linux/module.h>
> >> #include <linux/gfp.h>
> >> #include <linux/types.h>
> >> #include <linux/mm.h>
> >> #include <linux/mm_types.h>
> >> #include <linux/slab.h>
> >>
> >> static int vm_mem_test_init(void)
> >> {
> >>
> >>     void *km;
> >>
> >>     printk(KERN_ALERT "vm mem test init\n");
> >>
> >>     km = kmalloc(1,GFP_KERNEL);
> >>
> >>     if(km == NULL) {
> >>         printk(KERN_ALERT "Could not kmalloc\n");
> >>         return -1;
> >>     } else {
> >>         printk(KERN_ALERT "Allocated\n");
> >>         printk(KERN_ALERT "Virtual addr : %x\n",(unsigned int)km);
> >>         printk(KERN_ALERT "Kernel physical addr :
> >> 0x%x\n",virt_to_phys(km));
> >>         kfree(km);
> >>     }
> >>
> >>   return 0;
> >>
> >> }
> >>
> >>
> >> The output for the following is:
> >>
> >> Virtual addr : c2c080e0
> >> Kernel physical addr : 0x32c080e0
> >>
> >> -----------------------------------------------------------
> >>
> >> The kernel physical address is wrong as I only have 64MB. Should I be
> >> doing a kernel page table walk to get the associated physical address?
> >>
> >> Thanks
> >> Gautam.
> >>
> >> _______________________________________________
> >> Kernelnewbies mailing list
> >> Kernelnewbies at kernelnewbies.org
> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
> >
>
> Miles,
>
>   I tried printing it. The output is as follows:
>
> Kernel physical addr : 0x32d01fe0
> Platform phys offset : 0x30000000
> Page offset : 0xc0553fb4
>
> The S3C2440 is an ARM9TDMI processor.
>
>
> -Gautam.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140913/e311f9d8/attachment.html 

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

* On virt_to_phys doubts.
  2014-09-13 13:43     ` Miles MH Chen
@ 2014-09-13 13:52       ` mind entropy
  2014-09-13 16:50         ` Miles MH Chen
  0 siblings, 1 reply; 7+ messages in thread
From: mind entropy @ 2014-09-13 13:52 UTC (permalink / raw)
  To: kernelnewbies

On Sat, Sep 13, 2014 at 7:13 PM, Miles MH Chen <orca.chen@gmail.com> wrote:
> Kernel physical addr : 0x32d01fe0
> Platform phys offset : 0x30000000
> Page offset : 0xc0553fb4
>
> The page offset looks weird, since 32bit kernel has 2/2 or 3/1 or 1/3
> user/kernel virtual address  split. It is not reasonable to have 0xc0553fb4
> as page offset. You should c0000000 for 3/1 split.
>

My fault. I had done "0x%llx" in printk. Now I just did a %x and it
shows as 0xc0000000.

-Gautam.

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

* On virt_to_phys doubts.
  2014-09-13 13:52       ` mind entropy
@ 2014-09-13 16:50         ` Miles MH Chen
  2014-09-29 17:08           ` mind entropy
  0 siblings, 1 reply; 7+ messages in thread
From: Miles MH Chen @ 2014-09-13 16:50 UTC (permalink / raw)
  To: kernelnewbies

ok, now we can say the virt_to_phys returns a correct physical address.
0x32d01fe0. It is a physical address, not a simple offset in dram. Your
64Mb dram has physical address within 0x30000000 ~ 0x34000000.

MH
2014/9/13 ??9:52 ? "mind entropy" <mindentropy@gmail.com> ???

> On Sat, Sep 13, 2014 at 7:13 PM, Miles MH Chen <orca.chen@gmail.com>
> wrote:
> > Kernel physical addr : 0x32d01fe0
> > Platform phys offset : 0x30000000
> > Page offset : 0xc0553fb4
> >
> > The page offset looks weird, since 32bit kernel has 2/2 or 3/1 or 1/3
> > user/kernel virtual address  split. It is not reasonable to have
> 0xc0553fb4
> > as page offset. You should c0000000 for 3/1 split.
> >
>
> My fault. I had done "0x%llx" in printk. Now I just did a %x and it
> shows as 0xc0000000.
>
> -Gautam.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140914/0ee29728/attachment.html 

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

* On virt_to_phys doubts.
  2014-09-13 16:50         ` Miles MH Chen
@ 2014-09-29 17:08           ` mind entropy
  0 siblings, 0 replies; 7+ messages in thread
From: mind entropy @ 2014-09-29 17:08 UTC (permalink / raw)
  To: kernelnewbies

Thanks. It set a byte in RAM and checked it using md.b in u-boot.

-Gautam.

On Sat, Sep 13, 2014 at 10:20 PM, Miles MH Chen <orca.chen@gmail.com> wrote:
> ok, now we can say the virt_to_phys returns a correct physical address.
> 0x32d01fe0. It is a physical address, not a simple offset in dram. Your 64Mb
> dram has physical address within 0x30000000 ~ 0x34000000.
>
> MH
>
> 2014/9/13 ??9:52 ? "mind entropy" <mindentropy@gmail.com> ???
>
>> On Sat, Sep 13, 2014 at 7:13 PM, Miles MH Chen <orca.chen@gmail.com>
>> wrote:
>> > Kernel physical addr : 0x32d01fe0
>> > Platform phys offset : 0x30000000
>> > Page offset : 0xc0553fb4
>> >
>> > The page offset looks weird, since 32bit kernel has 2/2 or 3/1 or 1/3
>> > user/kernel virtual address  split. It is not reasonable to have
>> > 0xc0553fb4
>> > as page offset. You should c0000000 for 3/1 split.
>> >
>>
>> My fault. I had done "0x%llx" in printk. Now I just did a %x and it
>> shows as 0xc0000000.
>>
>> -Gautam.

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

end of thread, other threads:[~2014-09-29 17:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-13  8:02 On virt_to_phys doubts mind entropy
2014-09-13  8:31 ` Miles MH Chen
2014-09-13 12:59   ` mind entropy
2014-09-13 13:43     ` Miles MH Chen
2014-09-13 13:52       ` mind entropy
2014-09-13 16:50         ` Miles MH Chen
2014-09-29 17:08           ` mind entropy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.