From: Frederic Beck Subject: converting pfn to mfns Date: Fri, 27 Feb 2009 12:35:11 +0100 Message-ID: <20090227123511.3e0ff9ee@hobbes.loria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.comxen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Hello I'm trying to use paging mechanisms to find my PID, but i'm getting confused with guest context and addresses, which means i do not really understand in do_guest_trap from traps.c what modifications i have to do to the adresses i see. Here is what i'm doing: i get the CPU user registers and 3rd control register: user_regs = guest_cpu_user_regs(); cr3 = read_cr3(); My first question here: should i read cr3 with v->arch.guest_context.ctrlreg[3] ? I then determine the base address for the info relative to my process with base_addr = (user_regs->esp & 0xFFFFE000); If i'm not wrong, this should be the virtual address i have to translate. What i was thinking of doing was determine the physical address with the formula paddr = (cr3 & 0xFFFFFFE0) + (vaddr >> 30) * PAGE_SIZE The page frame number would then be pfn = paddr >> PAGE_SHIFT and the offset in that page offset = (PAGE_SIZE - 1) & paddr Then i have to map the pfn into an mfn. I'm looking on that now. But what surprised me, is that when digging into the hypervisor code, i found a primitive xen_cr3_to_pfn that uses only the cr3 register. What is the right approach ? Is there a similar primitive to map the pfn into mfn ? I did not look much on that for now, but it seems that there are some tables in different structures to do so. Can someone clarify that ? Thanks Fred