Re: virt to physical addr...

Christopher W. Boyd (cboyd@pobox.com)
Wed, 04 Aug 1999 11:33:49 -0500


At 08:34 AM 8/4/99 -0700, you wrote:
>Hi.
>
>Iam trying to find a way to get the physical addr given the user >virtual
addr.
>i thought the following would get the virtual to physical mapping but
>what i find is current->mm is NULL all the time.

current->mm cannot be NULL (else the kernel would
oops all over the place, since it would be dereferencing
a NULL pointer to get at the processes memory).
Most likely, you are either trying to use this from
inside an interrupt (outside of the context of a task),
or you tried to compile a module and install it in an
SMP kernel, but you forgot to define __SMP__. You can
do the latter by adding -D__SMP__:

gcc -D__SMP__ ....

Don't feel too bad. I had this same problem too :-)

>
>user program obtains memory using malloc()
>
>addr = malloc(size);
>
>then passes this to a kernel module for translation to physical addr
>
>pgd = pgd_offset(current->mm, addr);
>pmd = pmd_offset(pgd, addr);
>pte = pte_offset(pmd, addr);
>
>if (pte_present(*pte))
> page = pte_page(*pte);
>
>i have seen that always the current->mm is NULL.

This should be correct. In 2.2.9 there is a character
driver (bttv???) that have a static function uvirt_to_phys.
You might snag it. I think it does what you want to do.
virt_to_phys, AFAICT, converts a kernel virtual address
to a physical. There is a difference between kernel
virtual and user virtual, since with the latter, you have
to do a page table lookup. Make sure you mlock the buffer, as
it might not be present when you go to write/read on it ...

Hope this is helpful.

Regards,
Christopher Boyd

---
Chrisotopher W. Boyd <cboyd@pobox.com>
Web Page: http://www.pobox.com/~cboyd/
University of Texas at Austin
PGP Key ID 0x18037059
ICQ UIN# 13185314
My views don't necessarily reflect those of anybody else.

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/