From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yong LIU Subject: Re: how to transfer virtual address into pyhsical address Date: Wed, 15 Feb 2006 17:55:22 +0100 Message-ID: <43F35CFA.3010708@cs.uit.no> References: <1140004411.3083.13.camel@Yong> <20060215162147.GQ26802@cc.gatech.edu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1590539894==" Return-path: In-Reply-To: <20060215162147.GQ26802@cc.gatech.edu> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Himanshu Raj Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --===============1590539894== Content-Type: multipart/alternative; boundary="------------000307000003050609040301" This is a multi-part message in MIME format. --------------000307000003050609040301 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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:[] 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: >> [] hello_init_module+0x1a/0x2d [hello] >> [] sys_init_module+0x145/0x1e1 >> [] syscall_call+0x7/0xb >>Code: Bad EIP value. >>------------------------------------------------------- >>here is the code. >>#include >>#include >>#include >> >>#include >>#include >> >>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 >> >> > > > --------------000307000003050609040301 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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
    

  

--------------000307000003050609040301-- --===============1590539894== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1590539894==--