All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Ropert <mro@adviseo.fr>
To: yongliu@cs.uit.no
Cc: xen-devel@lists.xensource.com
Subject: Re: how to transfer virtual address into pyhsical address
Date: Wed, 15 Feb 2006 14:13:52 +0100	[thread overview]
Message-ID: <43F32910.8080302@adviseo.fr> (raw)
In-Reply-To: <1140004411.3083.13.camel@Yong>

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-15 13:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-15 11:53 how to transfer virtual address into pyhsical address Yong LIU
2006-02-15 13:13 ` Mathieu Ropert [this message]
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

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=43F32910.8080302@adviseo.fr \
    --to=mro@adviseo.fr \
    --cc=xen-devel@lists.xensource.com \
    --cc=yongliu@cs.uit.no \
    /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.