From patchwork Tue Nov 16 02:23:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 326912 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAG2NE0T023709 for ; Tue, 16 Nov 2010 02:23:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755383Ab0KPCXL (ORCPT ); Mon, 15 Nov 2010 21:23:11 -0500 Received: from mga11.intel.com ([192.55.52.93]:28931 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755256Ab0KPCXK (ORCPT ); Mon, 15 Nov 2010 21:23:10 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 15 Nov 2010 18:23:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.59,203,1288594800"; d="scan'208";a="627123228" Received: from yhuang-dev.sh.intel.com (HELO [10.239.13.2]) ([10.239.13.2]) by fmsmga002.fm.intel.com with ESMTP; 15 Nov 2010 18:23:08 -0800 Subject: [PATCH -v3] Monitor command: x-gpa2hva, translate guest physical address to host virtual address From: Huang Ying To: Avi Kivity , Anthony Liguori , Marcelo Tosatti , Andi Kleen , Dean Nelson , Luiz Capitulino Cc: "kvm@vger.kernel.org" , Max Asbock Date: Tue, 16 Nov 2010 10:23:07 +0800 Message-ID: <1289874187.8719.1127.camel@yhuang-dev> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 16 Nov 2010 02:23:15 +0000 (UTC) --- a/monitor.c +++ b/monitor.c @@ -2272,6 +2272,28 @@ static void do_inject_mce(Monitor *mon, } #endif +static void do_gpa2hva_print(Monitor *mon, const QObject *data) +{ + QInt *qint; + + qint = qobject_to_qint(data); + monitor_printf(mon, "0x%lx\n", (unsigned long)qint->value); +} + +static int do_gpa2hva(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + target_phys_addr_t paddr; + target_phys_addr_t size = TARGET_PAGE_SIZE; + void *vaddr; + + paddr = qdict_get_int(qdict, "addr"); + vaddr = cpu_physical_memory_map(paddr, &size, 0); + cpu_physical_memory_unmap(vaddr, size, 0, 0); + *ret_data = qobject_from_jsonf("%ld", (unsigned long)vaddr); + + return 0; +} + static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *fdname = qdict_get_str(qdict, "fdname"); --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -293,6 +293,21 @@ Start gdbserver session (default @var{po ETEXI { + .name = "x-gpa2hva", + .args_type = "fmt:/,addr:l", + .params = "/fmt addr", + .help = "translate guest physical 'addr' to host virtual address, only for debugging", + .user_print = do_gpa2hva_print, + .mhandler.cmd_new = do_gpa2hva, + }, + +STEXI +@item x-gpa2hva @var{addr} +@findex x-gpa2hva +Translate guest physical @var{addr} to host virtual address, only for debugging. +ETEXI + + { .name = "x", .args_type = "fmt:/,addr:l", .params = "/fmt addr",