From patchwork Fri Mar 2 10:18:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 144195 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DDF6F1007D7 for ; Fri, 2 Mar 2012 21:17:19 +1100 (EST) Received: from localhost ([::1]:58444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3PY5-0003xM-K6 for incoming@patchwork.ozlabs.org; Fri, 02 Mar 2012 05:17:17 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3PXx-0003xG-VX for qemu-devel@nongnu.org; Fri, 02 Mar 2012 05:17:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S3PXs-0006qG-VW for qemu-devel@nongnu.org; Fri, 02 Mar 2012 05:17:09 -0500 Received: from [222.73.24.84] (port=34289 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3PXs-0006q6-KD for qemu-devel@nongnu.org; Fri, 02 Mar 2012 05:17:04 -0500 X-IronPort-AV: E=Sophos;i="4.73,517,1325433600"; d="scan'208";a="4434169" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 02 Mar 2012 18:16:59 +0800 Received: from mailserver.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id q22AGxku027547; Fri, 2 Mar 2012 18:17:00 +0800 Received: from [10.167.225.226] ([10.167.225.226]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2012030218150926-854618 ; Fri, 2 Mar 2012 18:15:09 +0800 Message-ID: <4F509E6F.9060801@cn.fujitsu.com> Date: Fri, 02 Mar 2012 18:18:23 +0800 From: Wen Congyang User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: qemu-devel , Jan Kiszka , Dave Anderson , HATAYAMA Daisuke , Luiz Capitulino , Eric Blake References: <4F509A00.80207@cn.fujitsu.com> In-Reply-To: <4F509A00.80207@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2012-03-02 18:15:09, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2012-03-02 18:15:11, Serialize complete at 2012-03-02 18:15:11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Subject: [Qemu-devel] [RFC][PATCH 05/16 v8] Add API to get memory mapping X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add API to get all virtual address and physical address mapping. If there is no virtual address for some physical address, the virtual address is 0. Signed-off-by: Wen Congyang --- memory_mapping.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ memory_mapping.h | 8 +++++ 2 files changed, 96 insertions(+), 0 deletions(-) diff --git a/memory_mapping.c b/memory_mapping.c index 718f271..f74c5d0 100644 --- a/memory_mapping.c +++ b/memory_mapping.c @@ -164,3 +164,91 @@ void memory_mapping_list_init(MemoryMappingList *list) list->last_mapping = NULL; QTAILQ_INIT(&list->head); } + +int qemu_get_guest_memory_mapping(MemoryMappingList *list) +{ + CPUState *env; + MemoryMapping *memory_mapping; + RAMBlock *block; + ram_addr_t offset, length, m_length; + target_phys_addr_t m_phys_addr; + int ret; + bool paging_mode; + +#if defined(CONFIG_HAVE_GET_MEMORY_MAPPING) + paging_mode = cpu_paging_enabled(first_cpu); + if (paging_mode) { + for (env = first_cpu; env != NULL; env = env->next_cpu) { + ret = cpu_get_memory_mapping(list, env); + if (ret < 0) { + return -1; + } + } + } +#else + return -2; +#endif + + /* + * some memory may be not in the memory mapping's list: + * 1. the guest doesn't use paging + * 2. the guest is in 2nd kernel, and the memory used by 1st kernel is not + * in paging table + * add them into memory mapping's list + */ + QLIST_FOREACH(block, &ram_list.blocks, next) { + offset = block->offset; + length = block->length; + + if (!paging_mode) { + create_new_memory_mapping(list, offset, offset, length); + continue; + } + + QTAILQ_FOREACH(memory_mapping, &list->head, next) { + m_phys_addr = memory_mapping->phys_addr; + m_length = memory_mapping->length; + + if (offset + length <= m_phys_addr) { + /* + * memory_mapping's list does not conatin the region + * [offset, offset+length) + */ + create_new_memory_mapping(list, offset, 0, length); + length = 0; + break; + } + + if (m_phys_addr + m_length <= offset) { + continue; + } + + if (m_phys_addr > offset) { + /* + * memory_mapping's list does not conatin the region + * [offset, memory_mapping->phys_addr) + */ + create_new_memory_mapping(list, offset, 0, + m_phys_addr - offset); + } + + if (offset + length <= m_phys_addr + m_length) { + length = 0; + break; + } + + length -= m_phys_addr + m_length - offset; + offset = m_phys_addr + m_length; + } + + if (length > 0) { + /* + * memory_mapping's list does not conatin the region + * [offset, memory_mapping->phys_addr) + */ + create_new_memory_mapping(list, offset, 0, length); + } + } + + return 0; +} diff --git a/memory_mapping.h b/memory_mapping.h index 836b047..ebd7cf6 100644 --- a/memory_mapping.h +++ b/memory_mapping.h @@ -44,4 +44,12 @@ void memory_mapping_list_free(MemoryMappingList *list); void memory_mapping_list_init(MemoryMappingList *list); +/* + * Return value: + * 0: success + * -1: failed + * -2: unsupported + */ +int qemu_get_guest_memory_mapping(MemoryMappingList *list); + #endif