All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yong LIU <yongliu@cs.uit.no>
To: xen-devel@lists.xensource.com
Subject: Re: how to transfer virtual address into pyhsical	address
Date: Thu, 16 Feb 2006 09:30:12 +0100	[thread overview]
Message-ID: <1140078612.3154.5.camel@Yong> (raw)
In-Reply-To: <E1F9YYf-0006gv-DR@host-192-168-0-1-bcn-london>

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

       reply	other threads:[~2006-02-16  8:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1F9YYf-0006gv-DR@host-192-168-0-1-bcn-london>
2006-02-16  8:30 ` Yong LIU [this message]
2006-02-15 11:53 how to transfer virtual address into pyhsical address Yong LIU
2006-02-15 13:13 ` Mathieu Ropert
     [not found] ` <20060215162147.GQ26802@cc.gatech.edu>
2006-02-15 16:55   ` Yong LIU

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1140078612.3154.5.camel@Yong \
    --to=yongliu@cs.uit.no \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.