[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fwd: Re: How CPU(x86) resolve kernel address
Hi,
On Tue, Apr 09, 2002 at 10:59:12AM +0530, Sanket Rathi wrote:
> but i tried. i allocate memory buffers in application and pass their
> address to driver. there i use the following
>
> if (pgd_none(*(pgd = pgd_offset(current->mm,virtAddress))) ||
>
> pmd_none(*(pmd = pmd_offset(pgd, virtAddress))) ||
>
> pte_none(*(pte = pte_offset(pmd, virtAddress))) )
> {
> printk("\nphysical address failed\n") ;
> return (-1) ;
> }
> phyAddress = pte_page(*pte) ;
> printk("\nphysical address is %x",(unsigned
> long)phyAddress) ;
You cannot do that. The physical memory used by the application can
get swapped out, and if you malloc() a page, all you get initially is
a copy-on-write instance of the zero page. You *must* use something
like map_user_kiobuf() or the ptrace address-poking code to access the
user buffer safely. Even safer is to allocate the buffer inside your
driver instead and then mmap that into user space.
Cheers,
Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/