From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Tue, 9 Apr 2002 10:08:38 +0100 From: "Stephen C. Tweedie" Subject: Re: Fwd: Re: How CPU(x86) resolve kernel address Message-ID: <20020409100838.C2807@redhat.com> References: <20020407025738.90777.qmail@web12307.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ; from sanket.rathi@cdac.ernet.in on Tue, Apr 09, 2002 at 10:59:12AM +0530 Sender: owner-linux-mm@kvack.org Return-Path: To: Sanket Rathi Cc: Ravi , linux-mm@kvack.org List-ID: 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/