Received: from eggs.gnu.org ([208.118.235.92]:48796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SB3CQ-0002Mo-6z for qemu-devel@nongnu.org; Fri, 23 Mar 2012 08:02:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SB3CG-0007kT-2Y for qemu-devel@nongnu.org; Fri, 23 Mar 2012 08:02:29 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:49789) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SB3CF-0007jA-Iu for qemu-devel@nongnu.org; Fri, 23 Mar 2012 08:02:20 -0400 Received: from m1.gw.fujitsu.co.jp (unknown [10.0.50.71]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id E50793EE0C0 for ; Fri, 23 Mar 2012 21:02:14 +0900 (JST) Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id CB25045DE5D for ; Fri, 23 Mar 2012 21:02:14 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id A899045DE5B for ; Fri, 23 Mar 2012 21:02:14 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 9C4EA1DB8051 for ; Fri, 23 Mar 2012 21:02:14 +0900 (JST) Received: from ml14.s.css.fujitsu.com (ml14.s.css.fujitsu.com [10.240.81.134]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 434C21DB8048 for ; Fri, 23 Mar 2012 21:02:14 +0900 (JST) Date: Fri, 23 Mar 2012 21:02:02 +0900 ( ) Message-Id: <20120323.210202.434298361.d.hatayama@jp.fujitsu.com> From: HATAYAMA Daisuke In-Reply-To: <4F67FEB6.8060705@cn.fujitsu.com> References: <4F67FEB6.8060705@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 05/11 v10] Add API to get memory mapping List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: wency@cn.fujitsu.com Cc: aliguori@us.ibm.com, jan.kiszka@siemens.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, anderson@redhat.com, eblake@redhat.com From: Wen Congyang Subject: [PATCH 05/11 v10] Add API to get memory mapping Date: Tue, 20 Mar 2012 11:51:18 +0800 > Add API to get all virtual address and physical address mapping. > If the guest doesn't use paging, the virtual address is equal to the phyical > address. The virtual address and physical address mapping is for gdb's user, and > it does not include the memory that is not referenced by the page table. So if > you want to use crash to anaylze the vmcore, please do not specify -p option. > the reason why the -p option is not default explicitly: guest machine in a > catastrophic state can have corrupted memory, which we cannot trust. > > Signed-off-by: Wen Congyang > --- > memory_mapping.c | 34 ++++++++++++++++++++++++++++++++++ > memory_mapping.h | 15 +++++++++++++++ > 2 files changed, 49 insertions(+), 0 deletions(-) > > diff --git a/memory_mapping.c b/memory_mapping.c > index 718f271..b92e2f6 100644 > --- a/memory_mapping.c > +++ b/memory_mapping.c > @@ -164,3 +164,37 @@ void memory_mapping_list_init(MemoryMappingList *list) > list->last_mapping = NULL; > QTAILQ_INIT(&list->head); > } > + > +#if defined(CONFIG_HAVE_GET_MEMORY_MAPPING) > +int qemu_get_guest_memory_mapping(MemoryMappingList *list) > +{ > + CPUArchState *env; > + RAMBlock *block; > + ram_addr_t offset, length; > + int ret; > + bool paging_mode; > + > + paging_mode = cpu_paging_enabled(first_cpu); > + if (paging_mode) { On SMP with (n)-CPUs, we can do this check at most (n)-times. On Linux, user-mode tasks have differnet page tables. If refering to one page table, we can get one user-mode task memory only. Considering as much memory as possible, it's best to reference all CPUs with paging enabled and walk all the page tables. A problem is that linear addresses for user-mode tasks can inherently conflicts. Different user-mode tasks can have the same linear address. So, tools need to distinguish each PT_LOAD entry based on a pair of linear address and physical address, not linear address only. I don't know whether gdb does this. > + for (env = first_cpu; env != NULL; env = env->next_cpu) { > + ret = cpu_get_memory_mapping(list, env); > + if (ret < 0) { > + return -1; > + } > + } > + return 0; > + } > + > + /* > + * If the guest doesn't use paging, the virtual address is equal to physical > + * address. > + */ IIRC, ACPI sleep state goes in real-mode. There might be another that can go in real-mode. If execution enters this path in such situation, linear addresses are meaningless. But this is really rare case. > + QLIST_FOREACH(block, &ram_list.blocks, next) { > + offset = block->offset; > + length = block->length; > + create_new_memory_mapping(list, offset, offset, length); > + } > + > + return 0; > +} Thanks. HATAYAMA, Daisuke