All of lore.kernel.org
 help / color / mirror / Atom feed
* how to transfer virtual address into pyhsical address
@ 2006-02-15 11:53 Yong LIU
  2006-02-15 13:13 ` Mathieu Ropert
       [not found] ` <20060215162147.GQ26802@cc.gatech.edu>
  0 siblings, 2 replies; 5+ messages in thread
From: Yong LIU @ 2006-02-15 11:53 UTC (permalink / raw)
  To: xen-devel

I write a very simple module to test memory address translation.
When I install the module under xen 3.0, kernel panic. But when
I install it under xen3.0 & kernel 2.6.16-rc2, it can work well.

My question is: Is there a different way to translate virtual address
into physical address under Xen 3.0?
thanks for help. 

dmesg information.
--------------------------------------------------------
hello: module license 'unspecified' taints kernel.
Unable to handle kernel paging request at virtual address 3e0c5b0c
 printing eip:
f483c023
*pde = ma 00000000 pa 55555000
Oops: 0000 [#1]
SMP
Modules linked in: hello iptable_filter ip_tables video thermal
processor fan button battery ac
CPU:    1
EIP:    0061:[<f483c023>]    Tainted: P      VLI
EFLAGS: 00010206   (2.6.12.6-xen0-smp)
EIP is at kvirt_to_pa+0x23/0x3c [hello]
eax: 7e0c5000   ebx: f22c3000   ecx: 00000b0c   edx: 000003c8
esi: f2026000   edi: c0000000   ebp: f2026000   esp: f2027f90
ds: 007b   es: 007b   ss: 0069
Process insmod (pid: 4710, threadinfo=f2026000 task=f27c4520)
Stack: f483e01a f22c3000 f483c380 c013a1f8 c05a10a8 00000001 f483c380
0804a060
       b7fb3ff4 b7fb5538 c0109021 0804a060 00000dda 0804a050 b7fb3ff4
b7fb5538
       bffd6558 00000080 0000007b c010007b 00000080 b7f5667e 00000073
00010246
Call Trace:
 [<f483e01a>] hello_init_module+0x1a/0x2d [hello]
 [<c013a1f8>] sys_init_module+0x145/0x1e1
 [<c0109021>] syscall_call+0x7/0xb
Code:  Bad EIP value.
-------------------------------------------------------
here is the code.
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>

#include <asm/pgtable.h>
#include <asm/page.h>

static void kvirt_to_pa(void *vaddr)
{
        unsigned long addr=(unsigned long) vaddr;
        unsigned long pte_value;
        pgd_t *pgd=NULL;
        pmd_t *pmd=NULL;
        pte_t *pte=NULL;

        pgd=pgd_offset_k(addr);
        if(pgd_none(*pgd))
                goto hello_failed;
        pmd=pmd_offset(pgd, addr);
        if(pmd_none(*pmd))
                goto hello_failed;
        pte=pte_offset_kernel(pmd, addr);
        if(!pte_present(*pte))
                goto hello_failed;

        pte_value= pte_val(*pte) & PAGE_MASK | (addr & (PAGE_SIZE - 1));
        return;

hello_failed:
        printk(" failed\n");
        return;
}
static int __init hello_init_module(void)
{
        void * page=NULL;
        page=__get_free_pages(GFP_KERNEL, 0);
        kvirt_to_pa(page);
        free_page(page);
        return 1;
}


static void __exit hello_exit_module(void)
{
        printk(" say bye\n");
        return;
}
module_init(hello_init_module);
module_exit(hello_exit_module);

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

* Re: how to transfer virtual address into pyhsical address
  2006-02-15 11:53 how to transfer virtual address into pyhsical address Yong LIU
@ 2006-02-15 13:13 ` Mathieu Ropert
  2006-02-16  0:13   ` Himanshu Raj
       [not found] ` <20060215162147.GQ26802@cc.gatech.edu>
  1 sibling, 1 reply; 5+ messages in thread
From: Mathieu Ropert @ 2006-02-15 13:13 UTC (permalink / raw)
  To: yongliu; +Cc: xen-devel

Yong LIU wrote:
> I write a very simple module to test memory address translation.
> When I install the module under xen 3.0, kernel panic. But when
> I install it under xen3.0 & kernel 2.6.16-rc2, it can work well.
> 
> My question is: Is there a different way to translate virtual address
> into physical address under Xen 3.0?
> thanks for help. 
> 
> dmesg information.
> --------------------------------------------------------
> hello: module license 'unspecified' taints kernel.
> Unable to handle kernel paging request at virtual address 3e0c5b0c
>  printing eip:
> f483c023
> *pde = ma 00000000 pa 55555000
> Oops: 0000 [#1]
> SMP
> Modules linked in: hello iptable_filter ip_tables video thermal
> processor fan button battery ac
> CPU:    1
> EIP:    0061:[<f483c023>]    Tainted: P      VLI
> EFLAGS: 00010206   (2.6.12.6-xen0-smp)
> EIP is at kvirt_to_pa+0x23/0x3c [hello]
> eax: 7e0c5000   ebx: f22c3000   ecx: 00000b0c   edx: 000003c8
> esi: f2026000   edi: c0000000   ebp: f2026000   esp: f2027f90
> ds: 007b   es: 007b   ss: 0069
> Process insmod (pid: 4710, threadinfo=f2026000 task=f27c4520)
> Stack: f483e01a f22c3000 f483c380 c013a1f8 c05a10a8 00000001 f483c380
> 0804a060
>        b7fb3ff4 b7fb5538 c0109021 0804a060 00000dda 0804a050 b7fb3ff4
> b7fb5538
>        bffd6558 00000080 0000007b c010007b 00000080 b7f5667e 00000073
> 00010246
> Call Trace:
>  [<f483e01a>] hello_init_module+0x1a/0x2d [hello]
>  [<c013a1f8>] sys_init_module+0x145/0x1e1
>  [<c0109021>] syscall_call+0x7/0xb
> Code:  Bad EIP value.
> -------------------------------------------------------
> here is the code.
> #include <linux/init.h>
> #include <linux/kernel.h>
> #include <linux/module.h>
> 
> #include <asm/pgtable.h>
> #include <asm/page.h>
> 
> static void kvirt_to_pa(void *vaddr)
> {
>         unsigned long addr=(unsigned long) vaddr;
>         unsigned long pte_value;
>         pgd_t *pgd=NULL;
>         pmd_t *pmd=NULL;
>         pte_t *pte=NULL;
> 
>         pgd=pgd_offset_k(addr);
>         if(pgd_none(*pgd))
>                 goto hello_failed;
>         pmd=pmd_offset(pgd, addr);
>         if(pmd_none(*pmd))
>                 goto hello_failed;
>         pte=pte_offset_kernel(pmd, addr);
>         if(!pte_present(*pte))
>                 goto hello_failed;
> 
>         pte_value= pte_val(*pte) & PAGE_MASK | (addr & (PAGE_SIZE - 1));
>         return;
> 
> hello_failed:
>         printk(" failed\n");
>         return;
> }
> static int __init hello_init_module(void)
> {
>         void * page=NULL;
>         page=__get_free_pages(GFP_KERNEL, 0);
>         kvirt_to_pa(page);
>         free_page(page);
>         return 1;
> }
> 
> 
> static void __exit hello_exit_module(void)
> {
>         printk(" say bye\n");
>         return;
> }
> module_init(hello_init_module);
> module_exit(hello_exit_module);

__alloc_pages() returns a pointer to a page struct, not the virtual 
address of the allocated page. You can't use it directly like you do.
If you want the virtual address, either use page_address(page) or try 
some get_*_page function directly instead of alloc_pages().

Regards,
Mathieu

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

* Re: how to transfer virtual address into pyhsical address
       [not found] ` <20060215162147.GQ26802@cc.gatech.edu>
@ 2006-02-15 16:55   ` Yong LIU
  0 siblings, 0 replies; 5+ messages in thread
From: Yong LIU @ 2006-02-15 16:55 UTC (permalink / raw)
  To: Himanshu Raj; +Cc: xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 3436 bytes --]

You'r right. I forget ARCH=xen under 2.6.12.6, which is different from 
2.6.16-rc2.
I prepare to write a dma access.  But it often makes kernel panic. It 
seems to get an
error machine address. I have tried virt_to_bus.

Himanshu Raj wrote:

>Did you compile your module with ARCH=xen? virt_to_phys has completely different
>implementation for ARCH xen vs regular i386?
>
>-Himanshu
>
>On Wed, Feb 15, 2006 at 12:53:31PM +0100, Yong LIU wrote:
>  
>
>>I write a very simple module to test memory address translation.
>>When I install the module under xen 3.0, kernel panic. But when
>>I install it under xen3.0 & kernel 2.6.16-rc2, it can work well.
>>
>>My question is: Is there a different way to translate virtual address
>>into physical address under Xen 3.0?
>>thanks for help. 
>>
>>dmesg information.
>>--------------------------------------------------------
>>hello: module license 'unspecified' taints kernel.
>>Unable to handle kernel paging request at virtual address 3e0c5b0c
>> printing eip:
>>f483c023
>>*pde = ma 00000000 pa 55555000
>>Oops: 0000 [#1]
>>SMP
>>Modules linked in: hello iptable_filter ip_tables video thermal
>>processor fan button battery ac
>>CPU:    1
>>EIP:    0061:[<f483c023>]    Tainted: P      VLI
>>EFLAGS: 00010206   (2.6.12.6-xen0-smp)
>>EIP is at kvirt_to_pa+0x23/0x3c [hello]
>>eax: 7e0c5000   ebx: f22c3000   ecx: 00000b0c   edx: 000003c8
>>esi: f2026000   edi: c0000000   ebp: f2026000   esp: f2027f90
>>ds: 007b   es: 007b   ss: 0069
>>Process insmod (pid: 4710, threadinfo=f2026000 task=f27c4520)
>>Stack: f483e01a f22c3000 f483c380 c013a1f8 c05a10a8 00000001 f483c380
>>0804a060
>>       b7fb3ff4 b7fb5538 c0109021 0804a060 00000dda 0804a050 b7fb3ff4
>>b7fb5538
>>       bffd6558 00000080 0000007b c010007b 00000080 b7f5667e 00000073
>>00010246
>>Call Trace:
>> [<f483e01a>] hello_init_module+0x1a/0x2d [hello]
>> [<c013a1f8>] sys_init_module+0x145/0x1e1
>> [<c0109021>] syscall_call+0x7/0xb
>>Code:  Bad EIP value.
>>-------------------------------------------------------
>>here is the code.
>>#include <linux/init.h>
>>#include <linux/kernel.h>
>>#include <linux/module.h>
>>
>>#include <asm/pgtable.h>
>>#include <asm/page.h>
>>
>>static void kvirt_to_pa(void *vaddr)
>>{
>>        unsigned long addr=(unsigned long) vaddr;
>>        unsigned long pte_value;
>>        pgd_t *pgd=NULL;
>>        pmd_t *pmd=NULL;
>>        pte_t *pte=NULL;
>>
>>        pgd=pgd_offset_k(addr);
>>        if(pgd_none(*pgd))
>>                goto hello_failed;
>>        pmd=pmd_offset(pgd, addr);
>>        if(pmd_none(*pmd))
>>                goto hello_failed;
>>        pte=pte_offset_kernel(pmd, addr);
>>        if(!pte_present(*pte))
>>                goto hello_failed;
>>
>>        pte_value= pte_val(*pte) & PAGE_MASK | (addr & (PAGE_SIZE - 1));
>>        return;
>>
>>hello_failed:
>>        printk(" failed\n");
>>        return;
>>}
>>static int __init hello_init_module(void)
>>{
>>        void * page=NULL;
>>        page=__get_free_pages(GFP_KERNEL, 0);
>>        kvirt_to_pa(page);
>>        free_page(page);
>>        return 1;
>>}
>>
>>
>>static void __exit hello_exit_module(void)
>>{
>>        printk(" say bye\n");
>>        return;
>>}
>>module_init(hello_init_module);
>>module_exit(hello_exit_module);
>>
>>
>>
>>_______________________________________________
>>Xen-devel mailing list
>>Xen-devel@lists.xensource.com
>>http://lists.xensource.com/xen-devel
>>    
>>
>
>  
>


[-- Attachment #1.2: Type: text/html, Size: 3896 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

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

* Re: Re: how to transfer virtual address into pyhsical address
  2006-02-15 13:13 ` Mathieu Ropert
@ 2006-02-16  0:13   ` Himanshu Raj
  0 siblings, 0 replies; 5+ messages in thread
From: Himanshu Raj @ 2006-02-16  0:13 UTC (permalink / raw)
  To: Mathieu Ropert; +Cc: xen-devel

Related to this, can you tell me whether the memory allocated to a domain is
contiguous in machine RAM (given the calls to xen_create_contiguous, seems 
like it is not)? 

Thanks,
Himanshu

On Wed, Feb 15, 2006 at 02:13:52PM +0100, Mathieu Ropert wrote:
> Yong LIU wrote:
> >I write a very simple module to test memory address translation.
> >When I install the module under xen 3.0, kernel panic. But when
> >I install it under xen3.0 & kernel 2.6.16-rc2, it can work well.
> >
> >My question is: Is there a different way to translate virtual address
> >into physical address under Xen 3.0?
> >thanks for help. 
> >
> >dmesg information.
> >--------------------------------------------------------
> >hello: module license 'unspecified' taints kernel.
> >Unable to handle kernel paging request at virtual address 3e0c5b0c
> > printing eip:
> >f483c023
> >*pde = ma 00000000 pa 55555000
> >Oops: 0000 [#1]
> >SMP
> >Modules linked in: hello iptable_filter ip_tables video thermal
> >processor fan button battery ac
> >CPU:    1
> >EIP:    0061:[<f483c023>]    Tainted: P      VLI
> >EFLAGS: 00010206   (2.6.12.6-xen0-smp)
> >EIP is at kvirt_to_pa+0x23/0x3c [hello]
> >eax: 7e0c5000   ebx: f22c3000   ecx: 00000b0c   edx: 000003c8
> >esi: f2026000   edi: c0000000   ebp: f2026000   esp: f2027f90
> >ds: 007b   es: 007b   ss: 0069
> >Process insmod (pid: 4710, threadinfo=f2026000 task=f27c4520)
> >Stack: f483e01a f22c3000 f483c380 c013a1f8 c05a10a8 00000001 f483c380
> >0804a060
> >       b7fb3ff4 b7fb5538 c0109021 0804a060 00000dda 0804a050 b7fb3ff4
> >b7fb5538
> >       bffd6558 00000080 0000007b c010007b 00000080 b7f5667e 00000073
> >00010246
> >Call Trace:
> > [<f483e01a>] hello_init_module+0x1a/0x2d [hello]
> > [<c013a1f8>] sys_init_module+0x145/0x1e1
> > [<c0109021>] syscall_call+0x7/0xb
> >Code:  Bad EIP value.
> >-------------------------------------------------------
> >here is the code.
> >#include <linux/init.h>
> >#include <linux/kernel.h>
> >#include <linux/module.h>
> >
> >#include <asm/pgtable.h>
> >#include <asm/page.h>
> >
> >static void kvirt_to_pa(void *vaddr)
> >{
> >        unsigned long addr=(unsigned long) vaddr;
> >        unsigned long pte_value;
> >        pgd_t *pgd=NULL;
> >        pmd_t *pmd=NULL;
> >        pte_t *pte=NULL;
> >
> >        pgd=pgd_offset_k(addr);
> >        if(pgd_none(*pgd))
> >                goto hello_failed;
> >        pmd=pmd_offset(pgd, addr);
> >        if(pmd_none(*pmd))
> >                goto hello_failed;
> >        pte=pte_offset_kernel(pmd, addr);
> >        if(!pte_present(*pte))
> >                goto hello_failed;
> >
> >        pte_value= pte_val(*pte) & PAGE_MASK | (addr & (PAGE_SIZE - 1));
> >        return;
> >
> >hello_failed:
> >        printk(" failed\n");
> >        return;
> >}
> >static int __init hello_init_module(void)
> >{
> >        void * page=NULL;
> >        page=__get_free_pages(GFP_KERNEL, 0);
> >        kvirt_to_pa(page);
> >        free_page(page);
> >        return 1;
> >}
> >
> >
> >static void __exit hello_exit_module(void)
> >{
> >        printk(" say bye\n");
> >        return;
> >}
> >module_init(hello_init_module);
> >module_exit(hello_exit_module);
> 
> __alloc_pages() returns a pointer to a page struct, not the virtual 
> address of the allocated page. You can't use it directly like you do.
> If you want the virtual address, either use page_address(page) or try 
> some get_*_page function directly instead of alloc_pages().
> 
> Regards,
> Mathieu
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel

-- 
-------------------------------------------------------------------------
Himanshu Raj
PhD Student, GaTech (www.cc.gatech.edu/~rhim)
I prefer to receive attachments in an open, non-proprietary format.
-------------------------------------------------------------------------

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

* Re: how to transfer virtual address into pyhsical address
       [not found] <E1F9YYf-0006gv-DR@host-192-168-0-1-bcn-london>
@ 2006-02-16  8:30 ` Yong LIU
  0 siblings, 0 replies; 5+ messages in thread
From: Yong LIU @ 2006-02-16  8:30 UTC (permalink / raw)
  To: xen-devel

I use get_free_pages to get a contiguous virtual space, then get
physical address for DMA with virt_to_bus.
Regards
Yong. 
> Related to this, can you tell me whether the memory allocated to a domain is
> contiguous in machine RAM (given the calls to xen_create_contiguous, seems 
> like it is not)? 
> 
> Thanks,
> Himanshu
> 
> On Wed, Feb 15, 2006 at 02:13:52PM +0100, Mathieu Ropert wrote:
> > Yong LIU wrote:
> > >I write a very simple module to test memory address translation.
> > >When I install the module under xen 3.0, kernel panic. But when
> > >I install it under xen3.0 & kernel 2.6.16-rc2, it can work well.
> > >
> > >My question is: Is there a different way to translate virtual address
> > >into physical address under Xen 3.0?
> > >thanks for help. 
> > >
> > >dmesg information.
> > >--------------------------------------------------------
> > >hello: module license 'unspecified' taints kernel.
> > >Unable to handle kernel paging request at virtual address 3e0c5b0c
> > > printing eip:
> > >f483c023
> > >*pde = ma 00000000 pa 55555000
> > >Oops: 0000 [#1]
> > >SMP
> > >Modules linked in: hello iptable_filter ip_tables video thermal
> > >processor fan button battery ac
> > >CPU:    1
> > >EIP:    0061:[<f483c023>]    Tainted: P      VLI
> > >EFLAGS: 00010206   (2.6.12.6-xen0-smp)
> > >EIP is at kvirt_to_pa+0x23/0x3c [hello]
> > >eax: 7e0c5000   ebx: f22c3000   ecx: 00000b0c   edx: 000003c8
> > >esi: f2026000   edi: c0000000   ebp: f2026000   esp: f2027f90
> > >ds: 007b   es: 007b   ss: 0069
> > >Process insmod (pid: 4710, threadinfo=f2026000 task=f27c4520)
> > >Stack: f483e01a f22c3000 f483c380 c013a1f8 c05a10a8 00000001 f483c380
> > >0804a060
> > >       b7fb3ff4 b7fb5538 c0109021 0804a060 00000dda 0804a050 b7fb3ff4
> > >b7fb5538
> > >       bffd6558 00000080 0000007b c010007b 00000080 b7f5667e 00000073
> > >00010246
> > >Call Trace:
> > > [<f483e01a>] hello_init_module+0x1a/0x2d [hello]
> > > [<c013a1f8>] sys_init_module+0x145/0x1e1
> > > [<c0109021>] syscall_call+0x7/0xb
> > >Code:  Bad EIP value.
> > >-------------------------------------------------------
> > >here is the code.
> > >#include <linux/init.h>
> > >#include <linux/kernel.h>
> > >#include <linux/module.h>
> > >
> > >#include <asm/pgtable.h>
> > >#include <asm/page.h>
> > >
> > >static void kvirt_to_pa(void *vaddr)
> > >{
> > >        unsigned long addr=(unsigned long) vaddr;
> > >        unsigned long pte_value;
> > >        pgd_t *pgd=NULL;
> > >        pmd_t *pmd=NULL;
> > >        pte_t *pte=NULL;
> > >
> > >        pgd=pgd_offset_k(addr);
> > >        if(pgd_none(*pgd))
> > >                goto hello_failed;
> > >        pmd=pmd_offset(pgd, addr);
> > >        if(pmd_none(*pmd))
> > >                goto hello_failed;
> > >        pte=pte_offset_kernel(pmd, addr);
> > >        if(!pte_present(*pte))
> > >                goto hello_failed;
> > >
> > >        pte_value= pte_val(*pte) & PAGE_MASK | (addr & (PAGE_SIZE - 1));
> > >        return;
> > >
> > >hello_failed:
> > >        printk(" failed\n");
> > >        return;
> > >}
> > >static int __init hello_init_module(void)
> > >{
> > >        void * page=NULL;
> > >        page=__get_free_pages(GFP_KERNEL, 0);
> > >        kvirt_to_pa(page);
> > >        free_page(page);
> > >        return 1;
> > >}
> > >
> > >
> > >static void __exit hello_exit_module(void)
> > >{
> > >        printk(" say bye\n");
> > >        return;
> > >}
> > >module_init(hello_init_module);
> > >module_exit(hello_exit_module);
> > 
> > __alloc_pages() returns a pointer to a page struct, not the virtual 
> > address of the allocated page. You can't use it directly like you do.
> > If you want the virtual address, either use page_address(page) or try 
> > some get_*_page function directly instead of alloc_pages().
> > 
> > Regards,
> > Mathieu

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

end of thread, other threads:[~2006-02-16  8:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-15 11:53 how to transfer virtual address into pyhsical address Yong LIU
2006-02-15 13:13 ` Mathieu Ropert
2006-02-16  0:13   ` Himanshu Raj
     [not found] ` <20060215162147.GQ26802@cc.gatech.edu>
2006-02-15 16:55   ` Yong LIU
     [not found] <E1F9YYf-0006gv-DR@host-192-168-0-1-bcn-london>
2006-02-16  8:30 ` Yong LIU

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.